Fixed crash on assistants and more tweaks to grid

Originally committed to SVN as r70.
This commit is contained in:
Rodrigo Braz Monteiro 2006-02-19 03:10:03 +00:00
parent f0351f6d27
commit b8c0e2e7f8
5 changed files with 44 additions and 19 deletions

View File

@ -129,6 +129,7 @@ void BaseGrid::BeginBatch() {
// End batch // End batch
void BaseGrid::EndBatch() { void BaseGrid::EndBatch() {
//Thaw(); //Thaw();
AdjustScrollbar();
} }
@ -147,8 +148,7 @@ void BaseGrid::MakeCellVisible(int row, int col) {
// Make visible // Make visible
if (forceCenter || row < minVis || row > maxVis) { if (forceCenter || row < minVis || row > maxVis) {
yPos = MID(0,row - h/lineHeight/2 + 1,GetRows()+2 - h/lineHeight); ScrollTo(row - h/lineHeight/2 + 1);
scrollBar->SetThumbPosition(yPos);
} }
} }
@ -223,7 +223,9 @@ void BaseGrid::OnPaint (wxPaintEvent &event) {
bool direct = false; bool direct = false;
if (direct) { if (direct) {
dc.BeginDrawing();
DrawImage(dc); DrawImage(dc);
dc.EndDrawing();
} }
else { else {
@ -509,9 +511,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
if (row > maxVis) delta = +1; if (row > maxVis) delta = +1;
// Scroll // Scroll
yPos = MID(0,yPos+delta*3,GetRows()+2 - h/lineHeight); ScrollTo(yPos+delta*3);
scrollBar->SetThumbPosition(yPos);
Refresh(false);
} }
// Click // Click
@ -566,9 +566,7 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
// Mouse wheel // Mouse wheel
if (event.GetWheelRotation() != 0) { if (event.GetWheelRotation() != 0) {
int step = 3 * event.GetWheelRotation() / event.GetWheelDelta(); int step = 3 * event.GetWheelRotation() / event.GetWheelDelta();
yPos = MID(0,yPos - step,GetRows()+2 - h/lineHeight); ScrollTo(yPos - step);
scrollBar->SetThumbPosition(yPos);
Refresh(false);
return; 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 // Adjust scrollbar
void BaseGrid::AdjustScrollbar() { void BaseGrid::AdjustScrollbar() {
// Set size // Variables
int w,h,sw,sh; int w,h,sw,sh;
GetClientSize(&w,&h); GetClientSize(&w,&h);
int drawPerScreen = h/lineHeight;
int rows = GetRows();
bool barToEnable = drawPerScreen < rows+2;
bool barEnabled = scrollBar->IsEnabled();
// Set size
scrollBar->Freeze(); scrollBar->Freeze();
scrollBar->GetSize(&sw,&sh); scrollBar->GetSize(&sw,&sh);
scrollBar->SetSize(w-sw,0,sw,h); scrollBar->SetSize(w-sw,0,sw,h);
// Set parameters // Set parameters
int drawPerScreen = h/lineHeight; if (barEnabled) {
int rows = GetRows(); scrollBar->SetScrollbar(yPos,drawPerScreen,rows+2,drawPerScreen-2,true);
scrollBar->SetScrollbar(yPos,drawPerScreen,rows+2,drawPerScreen-2,true); }
scrollBar->Enable(drawPerScreen < rows); if (barToEnable != barEnabled) scrollBar->Enable(barToEnable);
scrollBar->Thaw(); scrollBar->Thaw();
} }

View File

@ -61,7 +61,6 @@ class BaseGrid : public wxWindow {
private: private:
int lineHeight; int lineHeight;
int colWidth[16]; int colWidth[16];
int yPos;
int lastRow; int lastRow;
bool holding; bool holding;
wxFont font; wxFont font;
@ -73,12 +72,14 @@ private:
void OnScroll(wxScrollEvent &event); void OnScroll(wxScrollEvent &event);
void OnMouseEvent(wxMouseEvent &event); void OnMouseEvent(wxMouseEvent &event);
void AdjustScrollbar();
void DrawImage(wxDC &dc); void DrawImage(wxDC &dc);
protected: protected:
FrameMain *parentFrame; FrameMain *parentFrame;
virtual void OnPopupMenu() {} virtual void OnPopupMenu() {}
void AdjustScrollbar();
void ScrollTo(int y);
int yPos;
public: public:
SubsEditBox *editBox; SubsEditBox *editBox;

View File

@ -180,8 +180,9 @@ void DialogStyling::JumpToLine(int n) {
if (n == -1) return; if (n == -1) return;
// Get line // Get line
line = grid->GetDialogue(n); AssDialogue *nextLine = grid->GetDialogue(n);
if (!line) return; if (!nextLine) return;
line = nextLine;
// Set number // Set number
linen = n; linen = n;

View File

@ -134,12 +134,14 @@ DialogTranslation::DialogTranslation (wxWindow *parent,AssFile *_subs,SubtitlesG
// Jumps to line at block // Jumps to line at block
bool DialogTranslation::JumpToLine(int n,int block) { bool DialogTranslation::JumpToLine(int n,int block) {
using std::vector; using std::vector;
AssDialogue *nextLine;
try { try {
current = grid->GetDialogue(n); nextLine = grid->GetDialogue(n);
} catch (...) { } catch (...) {
return false; return false;
} }
if (!current) return false; if (!nextLine) return false;
current = nextLine;
// Count blocks // Count blocks
int nblocks = 0; int nblocks = 0;

View File

@ -814,6 +814,8 @@ void SubtitlesGrid::Clear () {
//if (GetNumberRows() > 0) DeleteRows(0,GetNumberRows()); //if (GetNumberRows() > 0) DeleteRows(0,GetNumberRows());
diagMap.clear(); diagMap.clear();
selMap.clear(); selMap.clear();
yPos = 0;
AdjustScrollbar();
} }
@ -869,6 +871,7 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif
// Finish setting layout // Finish setting layout
EndBatch(); EndBatch();
AdjustScrollbar();
// Commit // Commit
if (!AssFile::Popping) { if (!AssFile::Popping) {