From 0b862d17272795d68238f6d03e9350988c72c955 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Wed, 22 Feb 2006 05:30:09 +0000 Subject: [PATCH] A few more tweaks, fixes and clean-ups Originally committed to SVN as r108. --- core/base_grid.cpp | 129 ++++++++++++++++++++----------- core/base_grid.h | 4 +- core/dialog_resample.cpp | 3 +- core/dialog_shift_times.cpp | 1 - core/dialog_timing_processor.cpp | 5 +- core/frame_main.cpp | 2 +- core/subs_edit_box.cpp | 3 - core/subs_grid.cpp | 43 +---------- core/subs_grid.h | 3 - 9 files changed, 92 insertions(+), 101 deletions(-) diff --git a/core/base_grid.cpp b/core/base_grid.cpp index 3918b01b3..9a2db8b32 100644 --- a/core/base_grid.cpp +++ b/core/base_grid.cpp @@ -96,27 +96,14 @@ BaseGrid::~BaseGrid() { } - -//////////////// -// Select a row -void BaseGrid::SelectRow(int row, bool addToSelected, bool select) { - if (!addToSelected) ClearSelection(); - try { - bool cur = selMap.at(row); - if (select != cur) { - selMap.at(row) = select; - - if (!addToSelected) Refresh(false); - - else { - int w = 0; - int h = 0; - GetClientSize(&w,&h); - RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false); - } - } - } - catch (...) {} +/////////////// +// Clears grid +void BaseGrid::Clear () { + diagMap.clear(); + diagPtrMap.clear(); + selMap.clear(); + yPos = 0; + AdjustScrollbar(); } @@ -162,6 +149,49 @@ void BaseGrid::MakeCellVisible(int row, int col,bool center) { } +//////////////// +// Select a row +void BaseGrid::SelectRow(int row, bool addToSelected, bool select) { + if (!addToSelected) ClearSelection(); + try { + bool cur = selMap.at(row); + if (select != cur) { + selMap.at(row) = select; + + if (!addToSelected) Refresh(false); + + else { + int w = 0; + int h = 0; + GetClientSize(&w,&h); + RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false); + } + } + } + catch (...) {} +} + + +///////////////////////// +// Selects visible lines +void BaseGrid::SelectVisible() { + int rows = GetRows(); + bool selectedOne = false; + for (int i=0;iLayer), &fw, &fh, NULL, NULL, &font); - if (fw > layerLen) layerLen = fw; + if (curDiag->Layer > maxLayer) maxLayer = curDiag->Layer; // Actor - dc.GetTextExtent(curDiag->Actor, &fw, &fh, NULL, NULL, &font); - if (fw > actorLen) actorLen = fw; + if (!curDiag->Actor.IsEmpty()) { + dc.GetTextExtent(curDiag->Actor, &fw, &fh, NULL, NULL, &font); + if (fw > actorLen) actorLen = fw; + } // Effect - dc.GetTextExtent(curDiag->Effect, &fw, &fh, NULL, NULL, &font); - if (fw > effectLen) effectLen = fw; + if (!curDiag->Effect.IsEmpty()) { + dc.GetTextExtent(curDiag->Effect, &fw, &fh, NULL, NULL, &font); + if (fw > effectLen) effectLen = fw; + } // Times if (byFrame) { - dc.GetTextExtent(wxString::Format(_T("%i"),VFR_Output.CorrectFrameAtTime(curDiag->Start.GetMS(),true)), &fw, &fh, NULL, NULL, &font); - if (fw > startLen) startLen = fw; - dc.GetTextExtent(wxString::Format(_T("%i"),VFR_Output.CorrectFrameAtTime(curDiag->End.GetMS(),true)), &fw, &fh, NULL, NULL, &font); - if (fw > endLen) endLen = fw; + int tmp = VFR_Output.CorrectFrameAtTime(curDiag->Start.GetMS(),true); + if (tmp > maxStart) maxStart = tmp; + tmp = VFR_Output.CorrectFrameAtTime(curDiag->End.GetMS(),true); + if (tmp > maxEnd) maxEnd = tmp; } } } - layerLen += 10; + + // Finish layer + dc.GetTextExtent(wxString::Format(_T("%i"),maxLayer), &fw, &fh, NULL, NULL, &font); + int layerLen = fw + 10; + + // Finish times + if (byFrame) { + dc.GetTextExtent(wxString::Format(_T("%i"),maxStart), &fw, &fh, NULL, NULL, &font); + startLen = fw + 10; + dc.GetTextExtent(wxString::Format(_T("%i"),maxEnd), &fw, &fh, NULL, NULL, &font); + endLen = fw + 10; + } + + // Finish actor/effect if (actorLen) actorLen += 10; if (effectLen) effectLen += 10; - startLen += 10; - endLen += 10; // Style length int styleLen = 0; diff --git a/core/base_grid.h b/core/base_grid.h index 3c9911826..291825c20 100644 --- a/core/base_grid.h +++ b/core/base_grid.h @@ -103,14 +103,16 @@ public: bool IsDisplayed(AssDialogue *line); int GetNumberSelection(); int GetFirstSelRow(); + void SelectVisible(); wxArrayInt GetSelection(bool *continuous=NULL); + void Clear(); void UpdateMaps(); + int GetRows() const; int GetNumberRows() const { return GetRows(); } void MakeCellVisible(int row, int col,bool center=true); - void AutoSizeColumn(int col, bool setAsMin = true); AssDialogue *GetDialogue(int n); BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); diff --git a/core/dialog_resample.cpp b/core/dialog_resample.cpp index 0b67ff988..850ef3e5e 100644 --- a/core/dialog_resample.cpp +++ b/core/dialog_resample.cpp @@ -225,7 +225,8 @@ void DialogResample::OnResample (wxCommandEvent &event) { subs->SetScriptInfo(_T("PlayResY"),wxString::Format(_T("%i"),y2)); // Flag as modified - grid->LoadFromAss(); + subs->FlagAsModified(); + grid->CommitChanges();; EndModal(0); } diff --git a/core/dialog_shift_times.cpp b/core/dialog_shift_times.cpp index 8244e40ac..ec0a17891 100644 --- a/core/dialog_shift_times.cpp +++ b/core/dialog_shift_times.cpp @@ -259,7 +259,6 @@ void DialogShiftTimes::OnOK(wxCommandEvent &event) { Options.Save(); // End dialog - //grid->LoadFromAss(NULL,true); grid->UpdateMaps(); EndModal(0); } diff --git a/core/dialog_timing_processor.cpp b/core/dialog_timing_processor.cpp index 92cb3d5e4..a3aa6ba97 100644 --- a/core/dialog_timing_processor.cpp +++ b/core/dialog_timing_processor.cpp @@ -511,7 +511,6 @@ void DialogTimingProcessor::Process() { } // Update grid - //grid->ass->FlagAsModified(); - //grid->CommitChanges(); - grid->LoadFromAss(NULL,true,false); + grid->ass->FlagAsModified(); + grid->CommitChanges(); } diff --git a/core/frame_main.cpp b/core/frame_main.cpp index 49ba37178..ea827fd01 100644 --- a/core/frame_main.cpp +++ b/core/frame_main.cpp @@ -910,7 +910,7 @@ void FrameMain::LoadVFR(wxString filename) { if (filename != _T("")) { try { VFR_Output.Load(filename); - SubsBox->LoadFromAss(NULL,true,true); + SubsBox->Refresh(false); } // Fail catch (wchar_t *error) { diff --git a/core/subs_edit_box.cpp b/core/subs_edit_box.cpp index 70342013e..92b8c1f8b 100644 --- a/core/subs_edit_box.cpp +++ b/core/subs_edit_box.cpp @@ -579,7 +579,6 @@ void SubsEditBox::OnStyleChange(wxCommandEvent &event) { cur->UpdateData(); } } - grid->AutoSizeColumn(3); grid->ass->FlagAsModified(); grid->CommitChanges(); grid->EndBatch(); @@ -611,7 +610,6 @@ void SubsEditBox::OnActorChange(wxCommandEvent &event) { } // Update grid - grid->AutoSizeColumn(4); grid->ass->FlagAsModified(); grid->CommitChanges(); grid->EndBatch(); @@ -635,7 +633,6 @@ void SubsEditBox::OnLayerChange(wxCommandEvent &event) { cur->UpdateData(); } } - grid->AutoSizeColumn(0); grid->ass->FlagAsModified(); grid->CommitChanges(); grid->EndBatch(); diff --git a/core/subs_grid.cpp b/core/subs_grid.cpp index ad8b70a7d..516d208d2 100644 --- a/core/subs_grid.cpp +++ b/core/subs_grid.cpp @@ -728,18 +728,6 @@ void SubtitlesGrid::LoadDefault (AssFile *_ass) { } -/////////////// -// Clears grid -void SubtitlesGrid::Clear () { - //if (GetNumberRows() > 0) DeleteRows(0,GetNumberRows()); - diagMap.clear(); - diagPtrMap.clear(); - selMap.clear(); - yPos = 0; - AdjustScrollbar(); -} - - ///////////////////////////////////// // Read data from ASS file structure void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModify) { @@ -769,8 +757,6 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif for (entryIter cur=ass->Line.begin();cur != ass->Line.end();cur++) { curdiag = AssEntry::GetAsDialogue(*cur); if (curdiag) { - //AppendRows(1); - //SetRowToLine(n,curdiag); diagMap.push_back(cur); diagPtrMap.push_back(curdiag); selMap.push_back(false); @@ -793,7 +779,6 @@ void SubtitlesGrid::LoadFromAss (AssFile *_ass,bool keepSelection,bool dontModif // Finish setting layout AdjustScrollbar(); - SetColumnWidths(); EndBatch(); // Commit @@ -924,11 +909,6 @@ void SubtitlesGrid::PasteLines(int n) { curdata.Trim(false); try { AssDialogue *curdiag = new AssDialogue(curdata); - //AssDialogue *curdiag = new AssDialogue; - //curdiag->data = curdata; - //curdiag->Parse(); - //curdiag->UpdateData(); - //InsertLine(curdiag,n,true,false); InsertLine(curdiag,n+inserted,false,false); inserted++; } @@ -1212,8 +1192,6 @@ void SubtitlesGrid::SplitLine(int n,int pos,int mode) { wxString orig = n1->Text; n1->Text = orig.Left(pos); n2->Text = orig.Mid(pos); - //n1->ParseASSTags(); - //n2->ParseASSTags(); // Modify time if (mode == 1) { @@ -1260,6 +1238,7 @@ void SubtitlesGrid::CommitChanges(bool force) { if (playing) video->Play(); } parentFrame->UpdateTitle(); + SetColumnWidths(); Refresh(false); } @@ -1275,26 +1254,6 @@ wxString SubtitlesGrid::GetTempWorkFile () { } -///////////////////////// -// Selects visible lines -void SubtitlesGrid::SelectVisible() { - int rows = GetRows(); - bool selectedOne = false; - for (int i=0;i