From b8c0e2e7f89271fe067459c4131dd8a94d8990e7 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Sun, 19 Feb 2006 03:10:03 +0000 Subject: [PATCH] Fixed crash on assistants and more tweaks to grid Originally committed to SVN as r70. --- core/base_grid.cpp | 44 ++++++++++++++++++++++--------- core/base_grid.h | 5 ++-- core/dialog_styling_assistant.cpp | 5 ++-- core/dialog_translation.cpp | 6 +++-- core/subs_grid.cpp | 3 +++ 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/core/base_grid.cpp b/core/base_grid.cpp index bb58c128b..bf204bed9 100644 --- a/core/base_grid.cpp +++ b/core/base_grid.cpp @@ -129,6 +129,7 @@ void BaseGrid::BeginBatch() { // End batch void BaseGrid::EndBatch() { //Thaw(); + AdjustScrollbar(); } @@ -147,8 +148,7 @@ void BaseGrid::MakeCellVisible(int row, int col) { // Make visible if (forceCenter || row < minVis || row > maxVis) { - yPos = MID(0,row - h/lineHeight/2 + 1,GetRows()+2 - h/lineHeight); - scrollBar->SetThumbPosition(yPos); + ScrollTo(row - h/lineHeight/2 + 1); } } @@ -223,7 +223,9 @@ void BaseGrid::OnPaint (wxPaintEvent &event) { bool direct = false; if (direct) { + dc.BeginDrawing(); DrawImage(dc); + dc.EndDrawing(); } else { @@ -509,9 +511,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { if (row > maxVis) delta = +1; // Scroll - yPos = MID(0,yPos+delta*3,GetRows()+2 - h/lineHeight); - scrollBar->SetThumbPosition(yPos); - Refresh(false); + ScrollTo(yPos+delta*3); } // Click @@ -566,9 +566,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { // Mouse wheel if (event.GetWheelRotation() != 0) { int step = 3 * event.GetWheelRotation() / event.GetWheelDelta(); - yPos = MID(0,yPos - step,GetRows()+2 - h/lineHeight); - scrollBar->SetThumbPosition(yPos); - Refresh(false); + ScrollTo(yPos - step); return; } @@ -576,21 +574,41 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) { } +///////////// +// Scroll to +void BaseGrid::ScrollTo(int y) { + int w,h; + GetClientSize(&w,&h); + int nextY = MID(0,y,GetRows()+2 - h/lineHeight); + if (yPos != nextY) { + yPos = nextY; + if (scrollBar->IsEnabled()) scrollBar->SetThumbPosition(yPos); + Refresh(false); + } +} + + //////////////////// // Adjust scrollbar void BaseGrid::AdjustScrollbar() { - // Set size + // Variables int w,h,sw,sh; GetClientSize(&w,&h); + int drawPerScreen = h/lineHeight; + int rows = GetRows(); + bool barToEnable = drawPerScreen < rows+2; + bool barEnabled = scrollBar->IsEnabled(); + + // Set size scrollBar->Freeze(); scrollBar->GetSize(&sw,&sh); scrollBar->SetSize(w-sw,0,sw,h); // Set parameters - int drawPerScreen = h/lineHeight; - int rows = GetRows(); - scrollBar->SetScrollbar(yPos,drawPerScreen,rows+2,drawPerScreen-2,true); - scrollBar->Enable(drawPerScreen < rows); + if (barEnabled) { + scrollBar->SetScrollbar(yPos,drawPerScreen,rows+2,drawPerScreen-2,true); + } + if (barToEnable != barEnabled) scrollBar->Enable(barToEnable); scrollBar->Thaw(); } diff --git a/core/base_grid.h b/core/base_grid.h index f2be2096b..5fdc2e585 100644 --- a/core/base_grid.h +++ b/core/base_grid.h @@ -61,7 +61,6 @@ class BaseGrid : public wxWindow { private: int lineHeight; int colWidth[16]; - int yPos; int lastRow; bool holding; wxFont font; @@ -73,12 +72,14 @@ private: void OnScroll(wxScrollEvent &event); void OnMouseEvent(wxMouseEvent &event); - void AdjustScrollbar(); void DrawImage(wxDC &dc); protected: FrameMain *parentFrame; virtual void OnPopupMenu() {} + void AdjustScrollbar(); + void ScrollTo(int y); + int yPos; public: SubsEditBox *editBox; diff --git a/core/dialog_styling_assistant.cpp b/core/dialog_styling_assistant.cpp index 0b2f0a74e..199c5f1f6 100644 --- a/core/dialog_styling_assistant.cpp +++ b/core/dialog_styling_assistant.cpp @@ -180,8 +180,9 @@ void DialogStyling::JumpToLine(int n) { if (n == -1) return; // Get line - line = grid->GetDialogue(n); - if (!line) return; + AssDialogue *nextLine = grid->GetDialogue(n); + if (!nextLine) return; + line = nextLine; // Set number linen = n; diff --git a/core/dialog_translation.cpp b/core/dialog_translation.cpp index 8b0f4e122..e9e577c42 100644 --- a/core/dialog_translation.cpp +++ b/core/dialog_translation.cpp @@ -134,12 +134,14 @@ DialogTranslation::DialogTranslation (wxWindow *parent,AssFile *_subs,SubtitlesG // Jumps to line at block bool DialogTranslation::JumpToLine(int n,int block) { using std::vector; + AssDialogue *nextLine; try { - current = grid->GetDialogue(n); + nextLine = grid->GetDialogue(n); } catch (...) { return false; } - if (!current) return false; + if (!nextLine) return false; + current = nextLine; // Count blocks int nblocks = 0; diff --git a/core/subs_grid.cpp b/core/subs_grid.cpp index ef51e148e..07e13f698 100644 --- a/core/subs_grid.cpp +++ b/core/subs_grid.cpp @@ -814,6 +814,8 @@ void SubtitlesGrid::Clear () { //if (GetNumberRows() > 0) DeleteRows(0,GetNumberRows()); diagMap.clear(); selMap.clear(); + yPos = 0; + AdjustScrollbar(); } @@ -869,6 +871,7 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif // Finish setting layout EndBatch(); + AdjustScrollbar(); // Commit if (!AssFile::Popping) {