2006-02-18 22:55:58 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-02-18 22:55:58 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file base_grid.cpp
|
|
|
|
/// @brief Base for subtitle grid in main UI
|
|
|
|
/// @ingroup main_ui
|
|
|
|
///
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-05-26 09:17:34 +02:00
|
|
|
#include <algorithm>
|
2011-09-28 21:50:24 +02:00
|
|
|
#include <cmath>
|
2010-06-27 05:24:03 +02:00
|
|
|
#include <iterator>
|
2011-10-01 20:35:06 +02:00
|
|
|
#include <numeric>
|
2010-08-03 00:14:11 +02:00
|
|
|
|
2012-01-31 01:42:58 +01:00
|
|
|
#include <wx/dcbuffer.h>
|
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
|
|
|
#include <wx/kbdstate.h>
|
2011-11-08 01:24:41 +01:00
|
|
|
#include <wx/menu.h>
|
2009-07-27 01:24:21 +02:00
|
|
|
#include <wx/sizer.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
#include "base_grid.h"
|
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/hotkey.h"
|
2011-11-08 01:24:41 +01:00
|
|
|
#include "include/aegisub/menu.h"
|
2011-01-16 08:17:36 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2006-02-18 22:55:58 +01:00
|
|
|
#include "ass_style.h"
|
2012-02-08 00:17:26 +01:00
|
|
|
#include "audio_box.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "frame_main.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2007-01-21 18:01:22 +01:00
|
|
|
#include "video_context.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_slider.h"
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
enum {
|
2011-11-08 01:24:41 +01:00
|
|
|
GRID_SCROLLBAR = 1730,
|
|
|
|
MENU_SHOW_COL = 1250 // Needs 15 IDs after this
|
2011-07-15 06:05:43 +02:00
|
|
|
};
|
|
|
|
|
2011-11-08 01:24:53 +01:00
|
|
|
enum RowColor {
|
|
|
|
COLOR_DEFAULT = 0,
|
|
|
|
COLOR_HEADER,
|
|
|
|
COLOR_SELECTION,
|
|
|
|
COLOR_COMMENT,
|
|
|
|
COLOR_VISIBLE,
|
2012-01-31 01:43:15 +01:00
|
|
|
COLOR_SELECTED_COMMENT,
|
|
|
|
COLOR_LEFT_COL
|
2011-11-08 01:24:53 +01:00
|
|
|
};
|
|
|
|
|
2010-06-28 09:13:03 +02:00
|
|
|
template<class S1, class S2, class D>
|
|
|
|
static inline void set_difference(const S1 &src1, const S2 &src2, D &dst) {
|
|
|
|
std::set_difference(
|
|
|
|
src1.begin(), src1.end(), src2.begin(), src2.end(),
|
|
|
|
std::inserter(dst, dst.begin()));
|
|
|
|
}
|
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size, long style, const wxString& name)
|
|
|
|
: wxWindow(parent, -1, wxDefaultPosition, size, style, name)
|
|
|
|
, lineHeight(1) // non-zero to avoid div by 0
|
|
|
|
, holding(false)
|
2011-07-16 07:01:36 +02:00
|
|
|
, scrollBar(new wxScrollBar(this, GRID_SCROLLBAR, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL))
|
|
|
|
, byFrame(false)
|
|
|
|
, extendRow(-1)
|
2011-01-16 08:17:36 +01:00
|
|
|
, active_line(0)
|
|
|
|
, batch_level(0)
|
|
|
|
, batch_active_line_changed(false)
|
2011-11-08 01:24:41 +01:00
|
|
|
, seek_listener(context->videoController->AddSeekListener(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL)))
|
|
|
|
, context_menu(0)
|
2011-01-16 08:17:36 +01:00
|
|
|
, yPos(0)
|
2011-12-22 22:09:31 +01:00
|
|
|
, context(context)
|
2006-02-18 22:55:58 +01:00
|
|
|
{
|
2007-01-04 00:29:03 +01:00
|
|
|
scrollBar->SetScrollbar(0,10,100,10);
|
|
|
|
|
2009-07-27 01:24:21 +02:00
|
|
|
wxBoxSizer *scrollbarpositioner = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
scrollbarpositioner->AddStretchSpacer();
|
|
|
|
scrollbarpositioner->Add(scrollBar, 0, wxEXPAND, 0);
|
|
|
|
|
|
|
|
SetSizerAndFit(scrollbarpositioner);
|
|
|
|
|
2012-01-31 01:42:58 +01:00
|
|
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
|
|
|
|
2007-01-04 00:29:03 +01:00
|
|
|
UpdateStyle();
|
2011-11-08 01:24:41 +01:00
|
|
|
OnHighlightVisibleChange(*OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"));
|
2010-08-26 20:38:37 +02:00
|
|
|
|
2010-12-07 20:09:15 +01:00
|
|
|
OPT_SUB("Subtitle/Grid/Font Face", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Subtitle/Grid/Font Size", &BaseGrid::UpdateStyle, this);
|
2011-11-08 01:24:41 +01:00
|
|
|
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &BaseGrid::OnHighlightVisibleChange, this);
|
|
|
|
context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, this);
|
|
|
|
context->ass->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, this);
|
2012-01-25 20:07:36 +01:00
|
|
|
context->ass->AddFileSaveListener(&BaseGrid::OnSubtitlesSave, this);
|
2010-12-07 20:09:15 +01:00
|
|
|
|
2012-04-06 17:50:46 +02:00
|
|
|
OPT_SUB("Colour/Subtitle Grid/Active Border", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Background", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Comment", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Inframe", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Selection", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Collision", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Header", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Left Column", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Lines", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Selection", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Standard", &BaseGrid::UpdateStyle, this);
|
|
|
|
OPT_SUB("Subtitle/Grid/Hide Overrides", std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL));
|
2011-08-31 06:17:37 +02:00
|
|
|
|
|
|
|
Bind(wxEVT_CONTEXT_MENU, &BaseGrid::OnContextMenu, this);
|
2007-01-04 00:29:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BaseGrid::~BaseGrid() {
|
2010-06-26 09:26:27 +02:00
|
|
|
ClearMaps();
|
2011-11-08 01:24:41 +01:00
|
|
|
delete context_menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
|
|
|
|
EVT_PAINT(BaseGrid::OnPaint)
|
|
|
|
EVT_SIZE(BaseGrid::OnSize)
|
|
|
|
EVT_COMMAND_SCROLL(GRID_SCROLLBAR,BaseGrid::OnScroll)
|
|
|
|
EVT_MOUSE_EVENTS(BaseGrid::OnMouseEvent)
|
|
|
|
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
|
2012-04-27 21:07:49 +02:00
|
|
|
EVT_CHAR_HOOK(BaseGrid::OnCharHook)
|
2011-11-08 01:24:41 +01:00
|
|
|
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,BaseGrid::OnShowColMenu)
|
2011-12-28 22:27:06 +01:00
|
|
|
END_EVENT_TABLE()
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
void BaseGrid::OnSubtitlesCommit(int type) {
|
|
|
|
if (type == AssFile::COMMIT_NEW)
|
|
|
|
UpdateMaps(true);
|
|
|
|
else if (type & AssFile::COMMIT_ORDER || type & AssFile::COMMIT_DIAG_ADDREM)
|
|
|
|
UpdateMaps(false);
|
|
|
|
|
|
|
|
if (type & AssFile::COMMIT_DIAG_META) {
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (type & AssFile::COMMIT_DIAG_TIME)
|
2012-01-26 23:27:57 +01:00
|
|
|
Refresh(false);
|
|
|
|
//RefreshRect(wxRect(time_cols_x, 0, time_cols_w, GetClientSize().GetHeight()), false);
|
|
|
|
else if (type & AssFile::COMMIT_DIAG_TEXT)
|
2011-11-08 01:24:41 +01:00
|
|
|
RefreshRect(wxRect(text_col_x, 0, text_col_w, GetClientSize().GetHeight()), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnSubtitlesOpen() {
|
|
|
|
BeginBatch();
|
|
|
|
ClearMaps();
|
|
|
|
UpdateMaps();
|
|
|
|
|
|
|
|
if (GetRows()) {
|
2012-01-25 20:07:36 +01:00
|
|
|
int row = context->ass->GetScriptInfoAsInt("Active Line");
|
|
|
|
if (row < 0 || row >= GetRows())
|
|
|
|
row = 0;
|
|
|
|
|
|
|
|
SetActiveLine(GetDialogue(row));
|
|
|
|
SelectRow(row);
|
2011-11-08 01:24:41 +01:00
|
|
|
}
|
2012-01-25 20:07:36 +01:00
|
|
|
|
|
|
|
ScrollTo(context->ass->GetScriptInfoAsInt("Scroll Position"));
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
EndBatch();
|
|
|
|
SetColumnWidths();
|
|
|
|
}
|
|
|
|
|
2012-01-25 20:07:36 +01:00
|
|
|
void BaseGrid::OnSubtitlesSave() {
|
|
|
|
context->ass->SetScriptInfo("Scroll Position", wxString::Format("%d", yPos));
|
|
|
|
context->ass->SetScriptInfo("Active Line", wxString::Format("%d", GetDialogueIndex(active_line)));
|
|
|
|
}
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
|
|
|
|
int item = event.GetId() - MENU_SHOW_COL;
|
|
|
|
showCol[item] = !showCol[item];
|
|
|
|
|
|
|
|
std::vector<bool> map(showCol, showCol + columns);
|
|
|
|
OPT_SET("Subtitle/Grid/Column")->SetListBool(map);
|
|
|
|
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnHighlightVisibleChange(agi::OptionValue const& opt) {
|
|
|
|
if (opt.GetBool()) {
|
|
|
|
seek_listener.Unblock();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
seek_listener.Block();
|
|
|
|
}
|
2007-01-04 00:29:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::UpdateStyle() {
|
2010-05-21 03:13:36 +02:00
|
|
|
wxString fontname = lagi_wxString(OPT_GET("Subtitle/Grid/Font Face")->GetString());
|
2011-07-15 06:05:43 +02:00
|
|
|
if (fontname.empty()) fontname = "Tahoma";
|
2006-02-18 22:55:58 +01:00
|
|
|
font.SetFaceName(fontname);
|
2010-05-21 03:13:36 +02:00
|
|
|
font.SetPointSize(OPT_GET("Subtitle/Grid/Font Size")->GetInt());
|
2006-02-18 22:55:58 +01:00
|
|
|
font.SetWeight(wxFONTWEIGHT_NORMAL);
|
|
|
|
|
|
|
|
// Set line height
|
|
|
|
{
|
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.SetFont(font);
|
|
|
|
int fw,fh;
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.GetTextExtent("#TWFfgGhH", &fw, &fh, NULL, NULL, &font);
|
|
|
|
lineHeight = fh + 4;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 01:43:15 +01:00
|
|
|
// Set row brushes
|
|
|
|
assert(sizeof(rowColors) / sizeof(rowColors[0]) >= COLOR_LEFT_COL);
|
|
|
|
rowColors[COLOR_DEFAULT].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColour()));
|
|
|
|
rowColors[COLOR_HEADER].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Header")->GetColour()));
|
|
|
|
rowColors[COLOR_SELECTION].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour()));
|
|
|
|
rowColors[COLOR_COMMENT].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColour()));
|
|
|
|
rowColors[COLOR_VISIBLE].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColour()));
|
|
|
|
rowColors[COLOR_SELECTED_COMMENT].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColour()));
|
|
|
|
rowColors[COLOR_LEFT_COL].SetColour(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColour()));
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set column widths
|
2011-11-04 20:42:31 +01:00
|
|
|
std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
|
2011-12-28 22:27:06 +01:00
|
|
|
assert(column_array.size() == (size_t)columns);
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = 0; i < columns; ++i) showCol[i] = column_array[i];
|
2006-02-18 22:55:58 +01:00
|
|
|
SetColumnWidths();
|
|
|
|
|
2007-01-04 00:29:03 +01:00
|
|
|
// Update
|
|
|
|
AdjustScrollbar();
|
|
|
|
Refresh();
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
void BaseGrid::ClearMaps() {
|
|
|
|
Selection old_selection(selection);
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
index_line_map.clear();
|
|
|
|
line_index_map.clear();
|
|
|
|
selection.clear();
|
2006-02-22 06:30:09 +01:00
|
|
|
yPos = 0;
|
|
|
|
AdjustScrollbar();
|
2010-06-26 09:26:27 +02:00
|
|
|
|
|
|
|
AnnounceSelectedSetChanged(Selection(), old_selection);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2010-07-13 07:29:08 +02:00
|
|
|
void BaseGrid::UpdateMaps(bool preserve_selected_rows) {
|
|
|
|
BeginBatch();
|
|
|
|
int active_row = line_index_map[active_line];
|
|
|
|
|
|
|
|
std::vector<int> sel_rows;
|
|
|
|
if (preserve_selected_rows) {
|
|
|
|
sel_rows.reserve(selection.size());
|
2011-07-15 06:05:43 +02:00
|
|
|
transform(selection.begin(), selection.end(), back_inserter(sel_rows),
|
|
|
|
bind1st(std::mem_fun(&BaseGrid::GetDialogueIndex), this));
|
2010-07-13 07:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
index_line_map.clear();
|
|
|
|
line_index_map.clear();
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
for (entryIter cur = context->ass->Line.begin(); cur != context->ass->Line.end(); ++cur) {
|
|
|
|
if (AssDialogue *curdiag = dynamic_cast<AssDialogue*>(*cur)) {
|
2010-07-13 07:29:08 +02:00
|
|
|
line_index_map[curdiag] = (int)index_line_map.size();
|
|
|
|
index_line_map.push_back(curdiag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preserve_selected_rows) {
|
|
|
|
Selection sel;
|
|
|
|
|
|
|
|
// If the file shrank enough that no selected rows are left, select the
|
|
|
|
// last row
|
|
|
|
if (sel_rows.empty()) {
|
|
|
|
sel_rows.push_back(index_line_map.size() - 1);
|
|
|
|
}
|
|
|
|
else if (sel_rows[0] >= (int)index_line_map.size()) {
|
|
|
|
sel_rows[0] = index_line_map.size() - 1;
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < sel_rows.size(); i++) {
|
|
|
|
if (sel_rows[i] >= (int)index_line_map.size()) break;
|
|
|
|
sel.insert(index_line_map[sel_rows[i]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSelectedSet(sel);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Selection lines;
|
2011-07-15 06:05:43 +02:00
|
|
|
copy(index_line_map.begin(), index_line_map.end(), inserter(lines, lines.begin()));
|
2010-07-13 07:29:08 +02:00
|
|
|
Selection new_sel;
|
|
|
|
// Remove lines which no longer exist from the selection
|
|
|
|
set_intersection(selection.begin(), selection.end(),
|
|
|
|
lines.begin(), lines.end(),
|
2011-07-15 06:05:43 +02:00
|
|
|
inserter(new_sel, new_sel.begin()));
|
2010-07-13 07:29:08 +02:00
|
|
|
|
|
|
|
SetSelectedSet(new_sel);
|
|
|
|
}
|
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
// Force a reannounce of the active line if it hasn't changed, as it isn't
|
|
|
|
// safe to touch the active line while processing a commit event which would
|
|
|
|
// cause this function to be called
|
|
|
|
AssDialogue *line = active_line;
|
2011-07-15 06:05:43 +02:00
|
|
|
active_line = 0;
|
2010-12-07 20:09:28 +01:00
|
|
|
|
2010-07-13 07:29:08 +02:00
|
|
|
// The active line may have ceased to exist; pick a new one if so
|
2010-12-07 20:09:28 +01:00
|
|
|
if (line_index_map.size() && line_index_map.find(line) == line_index_map.end()) {
|
2010-07-13 07:29:08 +02:00
|
|
|
if (active_row < (int)index_line_map.size()) {
|
|
|
|
SetActiveLine(index_line_map[active_row]);
|
|
|
|
}
|
|
|
|
else if (preserve_selected_rows && !selection.empty()) {
|
|
|
|
SetActiveLine(index_line_map[sel_rows[0]]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetActiveLine(index_line_map.back());
|
|
|
|
}
|
|
|
|
}
|
2010-12-07 20:09:28 +01:00
|
|
|
else {
|
|
|
|
SetActiveLine(line);
|
|
|
|
}
|
2010-07-13 07:29:08 +02:00
|
|
|
|
|
|
|
if (selection.empty() && active_line) {
|
|
|
|
Selection sel;
|
|
|
|
sel.insert(active_line);
|
|
|
|
SetSelectedSet(sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
EndBatch();
|
|
|
|
|
2011-10-23 19:00:26 +02:00
|
|
|
SetColumnWidths();
|
2011-09-28 21:50:24 +02:00
|
|
|
|
2010-07-13 07:29:08 +02:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
void BaseGrid::BeginBatch() {
|
2010-06-26 17:40:10 +02:00
|
|
|
++batch_level;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::EndBatch() {
|
2010-06-26 17:40:10 +02:00
|
|
|
--batch_level;
|
|
|
|
assert(batch_level >= 0);
|
|
|
|
if (batch_level == 0) {
|
|
|
|
if (batch_active_line_changed)
|
|
|
|
AnnounceActiveLineChanged(active_line);
|
|
|
|
batch_active_line_changed = false;
|
|
|
|
if (!batch_selection_added.empty() || !batch_selection_removed.empty())
|
|
|
|
AnnounceSelectedSetChanged(batch_selection_added, batch_selection_removed);
|
|
|
|
batch_selection_added.clear();
|
|
|
|
batch_selection_removed.clear();
|
|
|
|
}
|
|
|
|
|
2006-02-19 04:10:03 +01:00
|
|
|
AdjustScrollbar();
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void BaseGrid::MakeCellVisible(int row, int col, bool center) {
|
2012-05-04 04:52:52 +02:00
|
|
|
int h = GetClientSize().GetHeight();
|
2006-02-19 00:00:09 +01:00
|
|
|
|
|
|
|
// Get min and max visible
|
|
|
|
int minVis = yPos+1;
|
|
|
|
int maxVis = yPos+h/lineHeight-3;
|
|
|
|
|
|
|
|
// Make visible
|
2011-07-15 06:05:43 +02:00
|
|
|
if (!center || row < minVis || row > maxVis) {
|
2006-02-22 03:25:45 +01:00
|
|
|
if (center) {
|
|
|
|
ScrollTo(row - h/lineHeight/2 + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (row < minVis) ScrollTo(row - 1);
|
|
|
|
if (row > maxVis) ScrollTo(row - h/lineHeight + 3);
|
|
|
|
}
|
2006-02-19 00:00:09 +01:00
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2006-02-22 06:30:09 +01:00
|
|
|
void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
|
2010-06-26 09:26:27 +02:00
|
|
|
if (row < 0 || (size_t)row >= index_line_map.size()) return;
|
|
|
|
|
|
|
|
AssDialogue *line = index_line_map[row];
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
|
|
|
|
if (!addToSelected) {
|
2010-06-28 09:13:03 +02:00
|
|
|
Selection sel;
|
|
|
|
if (select) sel.insert(line);
|
|
|
|
SetSelectedSet(sel);
|
2011-07-15 06:05:43 +02:00
|
|
|
return;
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
}
|
2010-05-26 09:17:34 +02:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
if (select && selection.find(line) == selection.end()) {
|
2010-06-26 09:26:27 +02:00
|
|
|
selection.insert(line);
|
|
|
|
|
|
|
|
Selection added;
|
|
|
|
added.insert(line);
|
|
|
|
|
|
|
|
AnnounceSelectedSetChanged(added, Selection());
|
|
|
|
}
|
|
|
|
else if (!select && selection.find(line) != selection.end()) {
|
|
|
|
selection.erase(line);
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
Selection removed;
|
|
|
|
removed.insert(line);
|
|
|
|
|
|
|
|
AnnounceSelectedSetChanged(Selection(), removed);
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
|
|
|
|
2012-05-04 04:52:52 +02:00
|
|
|
int w = GetClientSize().GetWidth();
|
2011-07-15 06:05:43 +02:00
|
|
|
RefreshRect(wxRect(0, (row + 1 - yPos) * lineHeight, w, lineHeight), false);
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-07-15 06:05:22 +02:00
|
|
|
wxArrayInt BaseGrid::GetSelection() const {
|
2011-09-28 21:50:41 +02:00
|
|
|
wxArrayInt res;
|
|
|
|
res.reserve(selection.size());
|
2011-07-15 06:05:43 +02:00
|
|
|
transform(selection.begin(), selection.end(), std::back_inserter(res),
|
|
|
|
bind(&BaseGrid::GetDialogueIndex, this, std::tr1::placeholders::_1));
|
2011-07-15 06:05:22 +02:00
|
|
|
std::sort(res.begin(), res.end());
|
2010-06-26 09:26:27 +02:00
|
|
|
return res;
|
2006-02-22 05:59:39 +01:00
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void BaseGrid::OnPaint(wxPaintEvent &) {
|
2011-07-15 06:05:43 +02:00
|
|
|
// Get size and pos
|
2011-11-08 01:24:53 +01:00
|
|
|
wxSize cs = GetClientSize();
|
|
|
|
cs.SetWidth(cs.GetWidth() - scrollBar->GetSize().GetWidth());
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
// Find which columns need to be repainted
|
|
|
|
bool paint_columns[11];
|
|
|
|
memset(paint_columns, 0, sizeof paint_columns);
|
|
|
|
for (wxRegionIterator region(GetUpdateRegion()); region; ++region)
|
|
|
|
{
|
|
|
|
wxRect updrect = region.GetRect();
|
|
|
|
int x = 0;
|
|
|
|
for (size_t i = 0; i < 11; ++i) {
|
2012-01-31 01:43:06 +01:00
|
|
|
if (updrect.x < x + colWidth[i] && updrect.x + updrect.width > x && colWidth[i])
|
2011-08-27 08:52:42 +02:00
|
|
|
paint_columns[i] = true;
|
|
|
|
x += colWidth[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 01:42:58 +01:00
|
|
|
wxAutoBufferedPaintDC dc(this);
|
|
|
|
DrawImage(dc, paint_columns);
|
2011-07-15 06:05:43 +02:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
|
2006-02-18 22:55:58 +01:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
GetClientSize(&w,&h);
|
2007-04-08 08:01:41 +02:00
|
|
|
w -= scrollBar->GetSize().GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
dc.SetFont(font);
|
|
|
|
|
2012-01-31 01:43:15 +01:00
|
|
|
dc.SetBackground(rowColors[COLOR_DEFAULT]);
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
// Draw labels
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2012-01-31 01:43:15 +01:00
|
|
|
dc.SetBrush(rowColors[COLOR_LEFT_COL]);
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.DrawRectangle(0,lineHeight,colWidth[0],h-lineHeight);
|
|
|
|
|
|
|
|
// Visible lines
|
|
|
|
int drawPerScreen = h/lineHeight + 1;
|
2010-12-31 22:03:03 +01:00
|
|
|
int nDraw = mid(0,drawPerScreen,GetRows()-yPos);
|
2006-02-18 22:55:58 +01:00
|
|
|
int maxH = (nDraw+1) * lineHeight;
|
|
|
|
|
|
|
|
// Row colors
|
2011-07-15 06:05:43 +02:00
|
|
|
wxColour text_standard(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Standard")->GetColour()));
|
2011-12-22 22:14:06 +01:00
|
|
|
wxColour text_selection(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Selection")->GetColour()));
|
2011-07-15 06:05:43 +02:00
|
|
|
wxColour text_collision(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Collision")->GetColour()));
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// First grid row
|
2011-07-15 06:05:43 +02:00
|
|
|
wxPen grid_pen(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Lines")->GetColour()));
|
|
|
|
dc.SetPen(grid_pen);
|
|
|
|
dc.DrawLine(0, 0, w, 0);
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-11-08 01:24:53 +01:00
|
|
|
wxString strings[] = {
|
|
|
|
_("#"), _("L"), _("Start"), _("End"), _("Style"), _("Actor"),
|
|
|
|
_("Effect"), _("Left"), _("Right"), _("Vert"), _("Text")
|
2011-08-27 08:52:42 +02:00
|
|
|
};
|
|
|
|
|
2012-01-31 01:43:32 +01:00
|
|
|
int override_mode = OPT_GET("Subtitle/Grid/Hide Overrides")->GetInt();
|
|
|
|
wxString replace_char;
|
|
|
|
if (override_mode == 1)
|
|
|
|
replace_char = lagi_wxString(OPT_GET("Subtitle/Grid/Hide Overrides Char")->GetString());
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = 0; i < nDraw + 1; i++) {
|
|
|
|
int curRow = i + yPos - 1;
|
2011-11-08 01:24:53 +01:00
|
|
|
RowColor curColor = COLOR_DEFAULT;
|
2006-02-20 23:54:23 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Header
|
|
|
|
if (i == 0) {
|
2011-11-08 01:24:53 +01:00
|
|
|
curColor = COLOR_HEADER;
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_standard);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
// Lines
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (AssDialogue *curDiag = GetDialogue(curRow)) {
|
2012-01-31 01:43:32 +01:00
|
|
|
GetRowStrings(curRow, curDiag, paint_columns, strings, !!override_mode, replace_char);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-09-15 07:17:36 +02:00
|
|
|
bool inSel = !!selection.count(curDiag);
|
2011-11-08 01:24:53 +01:00
|
|
|
if (inSel && curDiag->Comment)
|
|
|
|
curColor = COLOR_SELECTED_COMMENT;
|
|
|
|
else if (inSel)
|
|
|
|
curColor = COLOR_SELECTION;
|
|
|
|
else if (curDiag->Comment)
|
|
|
|
curColor = COLOR_COMMENT;
|
|
|
|
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag))
|
|
|
|
curColor = COLOR_VISIBLE;
|
|
|
|
else
|
|
|
|
curColor = COLOR_DEFAULT;
|
|
|
|
|
|
|
|
if (active_line != curDiag && curDiag->CollidesWith(active_line))
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_collision);
|
2011-11-08 01:24:53 +01:00
|
|
|
else if (inSel)
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_selection);
|
2011-11-08 01:24:53 +01:00
|
|
|
else
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_standard);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-08-27 08:52:42 +02:00
|
|
|
assert(false);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw row background color
|
|
|
|
if (curColor) {
|
|
|
|
dc.SetBrush(rowColors[curColor]);
|
|
|
|
dc.DrawRectangle((curColor == 1) ? 0 : colWidth[0],i*lineHeight+1,w,lineHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw text
|
2010-11-08 03:52:54 +01:00
|
|
|
int dx = 0;
|
|
|
|
int dy = i*lineHeight;
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int j = 0; j < 11; j++) {
|
2006-06-27 07:13:41 +02:00
|
|
|
if (colWidth[j] == 0) continue;
|
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[j]) {
|
|
|
|
wxSize ext = dc.GetTextExtent(strings[j]);
|
|
|
|
|
|
|
|
int left = dx + 4;
|
|
|
|
int top = dy + (lineHeight - ext.GetHeight()) / 2;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
// Centered columns
|
|
|
|
if (!(j == 4 || j == 5 || j == 6 || j == 10)) {
|
|
|
|
left += (colWidth[j] - 6 - ext.GetWidth()) / 2;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
dc.DrawText(strings[j], left, top);
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
dx += colWidth[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw grid
|
|
|
|
dc.DestroyClippingRegion();
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetPen(grid_pen);
|
|
|
|
dc.DrawLine(0,dy+lineHeight,w,dy+lineHeight);
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw grid columns
|
2011-07-15 06:05:43 +02:00
|
|
|
int dx = 0;
|
2012-01-31 01:43:15 +01:00
|
|
|
dc.SetPen(grid_pen);
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i=0;i<10;i++) {
|
|
|
|
dx += colWidth[i];
|
|
|
|
dc.DrawLine(dx,0,dx,maxH);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.DrawLine(0,0,0,maxH);
|
|
|
|
dc.DrawLine(w-1,0,w-1,maxH);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// Draw currently active line border
|
2010-06-26 13:32:16 +02:00
|
|
|
if (GetActiveLine()) {
|
|
|
|
dc.SetPen(wxPen(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Active Border")->GetColour())));
|
|
|
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
2010-11-08 03:52:54 +01:00
|
|
|
int dy = (line_index_map[GetActiveLine()]+1-yPos) * lineHeight;
|
2010-06-26 13:32:16 +02:00
|
|
|
dc.DrawRectangle(0,dy,w,lineHeight+1);
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 01:43:32 +01:00
|
|
|
void BaseGrid::GetRowStrings(int row, AssDialogue *line, bool *paint_columns, wxString *strings, bool replace, wxString const& rep_char) const {
|
2011-11-08 01:24:53 +01:00
|
|
|
if (paint_columns[0]) strings[0] = wxString::Format("%d", row + 1);
|
|
|
|
if (paint_columns[1]) strings[1] = wxString::Format("%d", line->Layer);
|
|
|
|
if (byFrame) {
|
2011-12-22 22:28:51 +01:00
|
|
|
if (paint_columns[2]) strings[2] = wxString::Format("%d", context->videoController->FrameAtTime(line->Start, agi::vfr::START));
|
|
|
|
if (paint_columns[3]) strings[3] = wxString::Format("%d", context->videoController->FrameAtTime(line->End, agi::vfr::END));
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (paint_columns[2]) strings[2] = line->Start.GetASSFormated();
|
|
|
|
if (paint_columns[3]) strings[3] = line->End.GetASSFormated();
|
|
|
|
}
|
|
|
|
if (paint_columns[4]) strings[4] = line->Style;
|
|
|
|
if (paint_columns[5]) strings[5] = line->Actor;
|
|
|
|
if (paint_columns[6]) strings[6] = line->Effect;
|
|
|
|
if (paint_columns[7]) strings[7] = line->GetMarginString(0);
|
|
|
|
if (paint_columns[8]) strings[8] = line->GetMarginString(1);
|
|
|
|
if (paint_columns[9]) strings[9] = line->GetMarginString(2);
|
|
|
|
|
|
|
|
if (paint_columns[10]) {
|
|
|
|
strings[10].clear();
|
|
|
|
|
|
|
|
// Hidden overrides
|
2012-01-31 01:43:32 +01:00
|
|
|
if (replace) {
|
2011-11-08 01:24:53 +01:00
|
|
|
strings[10].reserve(line->Text.size());
|
|
|
|
size_t start = 0, pos;
|
|
|
|
while ((pos = line->Text.find('{', start)) != wxString::npos) {
|
|
|
|
strings[10] += line->Text.Mid(start, pos - start);
|
2012-01-31 01:43:32 +01:00
|
|
|
strings[10] += rep_char;
|
2011-11-08 01:24:53 +01:00
|
|
|
start = line->Text.find('}', pos);
|
|
|
|
if (start != wxString::npos) ++start;
|
|
|
|
}
|
|
|
|
strings[10] += line->Text.Mid(start);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Show overrides
|
|
|
|
else
|
|
|
|
strings[10] = line->Text;
|
|
|
|
|
|
|
|
// Cap length and set text
|
|
|
|
if (strings[10].size() > 512)
|
|
|
|
strings[10] = strings[10].Left(512) + "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void BaseGrid::OnSize(wxSizeEvent &) {
|
2006-02-18 22:55:58 +01:00
|
|
|
AdjustScrollbar();
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnScroll(wxScrollEvent &event) {
|
|
|
|
int newPos = event.GetPosition();
|
|
|
|
if (yPos != newPos) {
|
|
|
|
yPos = newPos;
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
|
2012-05-04 04:52:52 +02:00
|
|
|
int h = GetClientSize().GetHeight();
|
2011-10-01 20:35:00 +02:00
|
|
|
bool shift = event.ShiftDown();
|
|
|
|
bool alt = event.AltDown();
|
|
|
|
bool ctrl = event.CmdDown();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// Row that mouse is over
|
2011-08-31 06:17:37 +02:00
|
|
|
bool click = event.LeftDown();
|
2006-03-01 05:32:00 +01:00
|
|
|
bool dclick = event.LeftDClick();
|
2012-05-04 04:52:52 +02:00
|
|
|
int row = event.GetY() / lineHeight + yPos - 1;
|
2006-02-18 23:44:12 +01:00
|
|
|
if (holding && !click) {
|
2010-12-31 22:03:03 +01:00
|
|
|
row = mid(0,row,GetRows()-1);
|
2006-02-18 23:44:12 +01:00
|
|
|
}
|
2010-06-26 13:32:16 +02:00
|
|
|
AssDialogue *dlg = GetDialogue(row);
|
|
|
|
if (!dlg) row = 0;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2012-05-04 04:52:52 +02:00
|
|
|
if (event.ButtonDown() && OPT_GET("Subtitle/Grid/Focus Allow")->GetBool())
|
|
|
|
SetFocus();
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2006-02-18 23:44:12 +01:00
|
|
|
if (holding) {
|
2012-05-04 04:52:52 +02:00
|
|
|
if (!event.LeftIsDown()) {
|
|
|
|
if (dlg)
|
|
|
|
MakeCellVisible(row, 0, false);
|
|
|
|
holding = false;
|
|
|
|
ReleaseMouse();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Only scroll if the mouse has moved to a different row to avoid
|
|
|
|
// scrolling on sloppy clicks
|
|
|
|
if (row != extendRow) {
|
|
|
|
if (row <= yPos)
|
|
|
|
ScrollTo(yPos - 3);
|
|
|
|
// When dragging down we give a 3 row margin to make it easier
|
|
|
|
// to see what's going on, but we don't want to scroll down if
|
|
|
|
// the user clicks on the bottom row and drags up
|
|
|
|
else if (row > yPos + h / lineHeight - (row > extendRow ? 3 : 1))
|
|
|
|
ScrollTo(yPos + 3);
|
2006-06-21 01:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
2006-02-18 23:44:12 +01:00
|
|
|
}
|
2012-05-04 04:52:52 +02:00
|
|
|
else if (click && dlg) {
|
|
|
|
holding = true;
|
|
|
|
CaptureMouse();
|
|
|
|
}
|
2006-02-18 23:44:12 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
if ((click || holding || dclick) && dlg) {
|
2012-01-25 05:59:17 +01:00
|
|
|
int old_extend = extendRow;
|
2012-05-04 04:52:52 +02:00
|
|
|
|
|
|
|
// SetActiveLine will scroll the grid if the row is only half-visible,
|
|
|
|
// but we don't want to scroll until the mouse moves or the button is
|
|
|
|
// released, to avoid selecting multiple lines on a click
|
|
|
|
int old_y_pos = yPos;
|
2012-01-25 05:59:17 +01:00
|
|
|
SetActiveLine(dlg);
|
2012-05-04 04:52:52 +02:00
|
|
|
ScrollTo(old_y_pos);
|
2012-01-25 05:59:17 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Toggle selected
|
2006-02-22 00:27:34 +01:00
|
|
|
if (click && ctrl && !shift && !alt) {
|
2011-09-15 07:17:36 +02:00
|
|
|
bool isSel = !!selection.count(dlg);
|
2010-06-27 06:55:19 +02:00
|
|
|
if (isSel && selection.size() == 1) return;
|
2012-01-25 05:59:17 +01:00
|
|
|
SelectRow(row, true, !isSel);
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal click
|
2006-03-01 05:32:00 +01:00
|
|
|
if ((click || dclick) && !shift && !ctrl && !alt) {
|
2012-02-08 00:17:26 +01:00
|
|
|
if (dclick) {
|
|
|
|
context->audioBox->ScrollToActiveLine();
|
|
|
|
context->videoController->JumpToTime(dlg->Start);
|
|
|
|
}
|
2012-01-25 05:59:17 +01:00
|
|
|
SelectRow(row, false);
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-25 05:59:17 +01:00
|
|
|
// Change active line only
|
2012-05-04 04:52:52 +02:00
|
|
|
if (click && !shift && !ctrl && alt)
|
2010-06-28 09:12:36 +02:00
|
|
|
return;
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Block select
|
2012-05-04 04:52:58 +02:00
|
|
|
if ((click && shift && !alt) || holding) {
|
2012-01-25 05:59:17 +01:00
|
|
|
extendRow = old_extend;
|
|
|
|
int i1 = row;
|
|
|
|
int i2 = extendRow;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2012-01-25 05:59:17 +01:00
|
|
|
if (i1 > i2)
|
|
|
|
std::swap(i1, i2);
|
|
|
|
|
|
|
|
// Toggle each
|
|
|
|
Selection newsel;
|
|
|
|
if (ctrl) newsel = selection;
|
|
|
|
for (int i = i1; i <= i2; i++) {
|
|
|
|
newsel.insert(GetDialogue(i));
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
2012-01-25 05:59:17 +01:00
|
|
|
SetSelectedSet(newsel);
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse wheel
|
|
|
|
if (event.GetWheelRotation() != 0) {
|
2011-10-25 21:40:45 +02:00
|
|
|
if (ForwardMouseWheelEvent(this, event)) {
|
2012-01-26 23:46:09 +01:00
|
|
|
int step = shift ? h / lineHeight - 2 : 3;
|
|
|
|
ScrollTo(yPos - step * event.GetWheelRotation() / event.GetWheelDelta());
|
2011-10-25 21:40:45 +02:00
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2011-08-31 06:17:37 +02:00
|
|
|
void BaseGrid::OnContextMenu(wxContextMenuEvent &evt) {
|
|
|
|
wxPoint pos = evt.GetPosition();
|
2011-11-08 01:24:41 +01:00
|
|
|
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight) {
|
|
|
|
if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
|
|
|
|
menu::OpenPopupMenu(context_menu, this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const wxString strings[] = {
|
|
|
|
_("Line Number"),
|
|
|
|
_("Layer"),
|
|
|
|
_("Start"),
|
|
|
|
_("End"),
|
|
|
|
_("Style"),
|
|
|
|
_("Actor"),
|
|
|
|
_("Effect"),
|
|
|
|
_("Left"),
|
|
|
|
_("Right"),
|
|
|
|
_("Vert"),
|
|
|
|
};
|
|
|
|
|
|
|
|
wxMenu menu;
|
2011-12-28 22:27:06 +01:00
|
|
|
for (int i = 0; i < columns; ++i)
|
2011-11-08 01:24:41 +01:00
|
|
|
menu.Append(MENU_SHOW_COL + i, strings[i], "", wxITEM_CHECK)->Check(showCol[i]);
|
|
|
|
PopupMenu(&menu);
|
|
|
|
}
|
2011-08-31 06:17:37 +02:00
|
|
|
}
|
|
|
|
|
2006-02-19 04:10:03 +01:00
|
|
|
void BaseGrid::ScrollTo(int y) {
|
2012-05-04 04:52:52 +02:00
|
|
|
int h = GetClientSize().GetHeight();
|
|
|
|
int nextY = mid(0, y, GetRows() + 2 - h / lineHeight);
|
2006-02-19 04:10:03 +01:00
|
|
|
if (yPos != nextY) {
|
|
|
|
yPos = nextY;
|
|
|
|
if (scrollBar->IsEnabled()) scrollBar->SetThumbPosition(yPos);
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
void BaseGrid::AdjustScrollbar() {
|
|
|
|
int w,h,sw,sh;
|
|
|
|
GetClientSize(&w,&h);
|
2006-02-19 04:10:03 +01:00
|
|
|
int drawPerScreen = h/lineHeight;
|
|
|
|
int rows = GetRows();
|
|
|
|
bool barToEnable = drawPerScreen < rows+2;
|
|
|
|
|
2010-12-31 22:03:03 +01:00
|
|
|
yPos = mid(0,yPos,rows - drawPerScreen);
|
2006-02-22 07:08:35 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
scrollBar->Freeze();
|
|
|
|
scrollBar->GetSize(&sw,&sh);
|
2006-02-19 01:54:35 +01:00
|
|
|
scrollBar->SetSize(w-sw,0,sw,h);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2010-08-03 22:21:13 +02:00
|
|
|
if (barToEnable != scrollBar->IsEnabled()) scrollBar->Enable(barToEnable);
|
|
|
|
if (barToEnable) {
|
2006-02-19 04:10:03 +01:00
|
|
|
scrollBar->SetScrollbar(yPos,drawPerScreen,rows+2,drawPerScreen-2,true);
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
scrollBar->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::SetColumnWidths() {
|
2009-07-27 01:24:21 +02:00
|
|
|
if (!IsShownOnScreen()) return;
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Width/height
|
2011-10-01 20:35:06 +02:00
|
|
|
int w, h;
|
2006-02-18 22:55:58 +01:00
|
|
|
GetClientSize(&w,&h);
|
|
|
|
|
|
|
|
// DC for text extents test
|
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.SetFont(font);
|
|
|
|
|
|
|
|
// O(1) widths
|
2011-10-01 20:35:06 +02:00
|
|
|
int marginLen = dc.GetTextExtent("0000").GetWidth();
|
|
|
|
|
|
|
|
int labelLen = dc.GetTextExtent(wxString::Format("%d", GetRows())).GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
int startLen = 0;
|
|
|
|
int endLen = 0;
|
2011-10-01 20:35:06 +02:00
|
|
|
if (!byFrame)
|
|
|
|
startLen = endLen = dc.GetTextExtent(AssTime().GetASSFormated()).GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// O(n) widths
|
2011-07-15 06:05:43 +02:00
|
|
|
bool showMargin[3] = { false, false, false };
|
2006-12-30 19:19:54 +01:00
|
|
|
int styleLen = 0;
|
2006-02-18 22:55:58 +01:00
|
|
|
int actorLen = 0;
|
|
|
|
int effectLen = 0;
|
2006-02-22 06:30:09 +01:00
|
|
|
int maxLayer = 0;
|
|
|
|
int maxStart = 0;
|
|
|
|
int maxEnd = 0;
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = 0; i < GetRows(); i++) {
|
|
|
|
AssDialogue *curDiag = GetDialogue(i);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-10-01 20:35:06 +02:00
|
|
|
maxLayer = std::max(maxLayer, curDiag->Layer);
|
|
|
|
actorLen = std::max(actorLen, dc.GetTextExtent(curDiag->Actor).GetWidth());
|
|
|
|
styleLen = std::max(styleLen, dc.GetTextExtent(curDiag->Style).GetWidth());
|
|
|
|
effectLen = std::max(effectLen, dc.GetTextExtent(curDiag->Effect).GetWidth());
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Margins
|
2011-10-01 20:35:06 +02:00
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
if (curDiag->Margin[j])
|
|
|
|
showMargin[j] = true;
|
2011-07-15 06:05:43 +02:00
|
|
|
}
|
2007-07-03 03:48:04 +02:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Times
|
|
|
|
if (byFrame) {
|
2011-12-22 22:28:51 +01:00
|
|
|
maxStart = std::max(maxStart, context->videoController->FrameAtTime(curDiag->Start, agi::vfr::START));
|
|
|
|
maxEnd = std::max(maxEnd, context->videoController->FrameAtTime(curDiag->End, agi::vfr::END));
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish layer
|
2011-10-01 20:35:06 +02:00
|
|
|
int layerLen = maxLayer ? dc.GetTextExtent(wxString::Format("%d", maxLayer)).GetWidth() : 0;
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish times
|
|
|
|
if (byFrame) {
|
2011-10-01 20:35:06 +02:00
|
|
|
startLen = dc.GetTextExtent(wxString::Format("%d", maxStart)).GetWidth();
|
|
|
|
endLen = dc.GetTextExtent(wxString::Format("%d", maxEnd)).GetWidth();
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set column widths
|
|
|
|
colWidth[0] = labelLen;
|
2011-07-15 06:05:43 +02:00
|
|
|
colWidth[1] = layerLen;
|
2006-02-18 22:55:58 +01:00
|
|
|
colWidth[2] = startLen;
|
|
|
|
colWidth[3] = endLen;
|
|
|
|
colWidth[4] = styleLen;
|
|
|
|
colWidth[5] = actorLen;
|
|
|
|
colWidth[6] = effectLen;
|
2011-10-01 20:35:06 +02:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
colWidth[i + 7] = showMargin[i] ? marginLen : 0;
|
2012-01-18 21:08:06 +01:00
|
|
|
colWidth[10] = 1;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2006-06-27 07:13:41 +02:00
|
|
|
// Hide columns
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = 0; i < columns; i++) {
|
2011-10-01 20:35:06 +02:00
|
|
|
if (!showCol[i])
|
|
|
|
colWidth[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString col_names[11] = {
|
|
|
|
_("#"),
|
|
|
|
_("L"),
|
|
|
|
_("Start"),
|
|
|
|
_("End"),
|
|
|
|
_("Style"),
|
|
|
|
_("Actor"),
|
|
|
|
_("Effect"),
|
|
|
|
_("Left"),
|
|
|
|
_("Right"),
|
|
|
|
_("Vert"),
|
|
|
|
_("Text")
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ensure every visible column is at least as big as its header
|
|
|
|
for (size_t i = 0; i < 11; ++i) {
|
|
|
|
if (colWidth[i])
|
|
|
|
colWidth[i] = std::max(colWidth[i], dc.GetTextExtent(col_names[i]).GetWidth());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add padding to all non-empty columns
|
|
|
|
for (size_t i = 0; i < 10; ++i) {
|
|
|
|
if (colWidth[i])
|
|
|
|
colWidth[i] += 10;
|
2006-06-27 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
2011-10-01 20:35:06 +02:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set size of last
|
2011-10-01 20:35:06 +02:00
|
|
|
int total = std::accumulate(colWidth, colWidth + 10, 0);
|
|
|
|
colWidth[10] = w - total;
|
2011-09-15 07:16:32 +02:00
|
|
|
|
2011-10-13 01:07:38 +02:00
|
|
|
time_cols_x = colWidth[0] + colWidth[1];
|
|
|
|
time_cols_w = colWidth[2] + colWidth[3];
|
2011-09-15 07:16:32 +02:00
|
|
|
text_col_x = total;
|
|
|
|
text_col_w = colWidth[10];
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2010-05-26 09:17:34 +02:00
|
|
|
AssDialogue *BaseGrid::GetDialogue(int n) const {
|
2011-07-15 06:05:43 +02:00
|
|
|
if (static_cast<size_t>(n) >= index_line_map.size()) return 0;
|
2010-06-26 09:26:27 +02:00
|
|
|
return index_line_map[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
int BaseGrid::GetDialogueIndex(AssDialogue *diag) const {
|
|
|
|
std::map<AssDialogue*,int>::const_iterator it = line_index_map.find(diag);
|
|
|
|
if (it != line_index_map.end()) return it->second;
|
2011-07-15 06:05:43 +02:00
|
|
|
return -1;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
2006-02-19 01:54:35 +01:00
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
bool BaseGrid::IsDisplayed(const AssDialogue *line) const {
|
|
|
|
if (!context->videoController->IsLoaded()) return false;
|
|
|
|
int frame = context->videoController->GetFrameN();
|
2010-07-20 05:11:11 +02:00
|
|
|
return
|
2011-12-22 22:28:51 +01:00
|
|
|
context->videoController->FrameAtTime(line->Start,agi::vfr::START) <= frame &&
|
|
|
|
context->videoController->FrameAtTime(line->End,agi::vfr::END) >= frame;
|
2006-02-19 01:54:35 +01:00
|
|
|
}
|
2006-02-21 03:01:42 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
void BaseGrid::OnCharHook(wxKeyEvent &event) {
|
2012-03-13 00:34:34 +01:00
|
|
|
if (hotkey::check("Subtitle Grid", context, event))
|
2011-01-19 04:12:46 +01:00
|
|
|
return;
|
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
int key = event.GetKeyCode();
|
|
|
|
|
|
|
|
if (key == WXK_UP || key == WXK_DOWN ||
|
|
|
|
key == WXK_PAGEUP || key == WXK_PAGEDOWN ||
|
|
|
|
key == WXK_HOME || key == WXK_END)
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hotkey::check("Audio", context, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnKeyDown(wxKeyEvent &event) {
|
2006-02-22 04:38:23 +01:00
|
|
|
int w,h;
|
|
|
|
GetClientSize(&w,&h);
|
|
|
|
|
2007-01-22 20:31:49 +01:00
|
|
|
int key = event.GetKeyCode();
|
2011-07-15 06:05:43 +02:00
|
|
|
bool ctrl = event.CmdDown();
|
|
|
|
bool alt = event.AltDown();
|
|
|
|
bool shift = event.ShiftDown();
|
2006-02-22 03:25:45 +01:00
|
|
|
|
|
|
|
int dir = 0;
|
2006-02-22 04:38:23 +01:00
|
|
|
int step = 1;
|
2006-02-22 03:25:45 +01:00
|
|
|
if (key == WXK_UP) dir = -1;
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_DOWN) dir = 1;
|
|
|
|
else if (key == WXK_PAGEUP) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = -1;
|
2011-07-15 06:05:43 +02:00
|
|
|
step = h / lineHeight - 2;
|
2006-02-22 04:38:23 +01:00
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_PAGEDOWN) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = 1;
|
2011-07-15 06:05:43 +02:00
|
|
|
step = h / lineHeight - 2;
|
2006-02-22 04:38:23 +01:00
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_HOME) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = -1;
|
|
|
|
step = GetRows();
|
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_END) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = 1;
|
|
|
|
step = GetRows();
|
|
|
|
}
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
if (!dir) {
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-06 05:53:38 +02:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
int old_extend = extendRow;
|
|
|
|
int next = mid(0, GetDialogueIndex(active_line) + dir * step, GetRows() - 1);
|
|
|
|
SetActiveLine(GetDialogue(next));
|
2012-01-25 05:59:17 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Move selection
|
|
|
|
if (!ctrl && !shift && !alt) {
|
|
|
|
SelectRow(next);
|
|
|
|
return;
|
|
|
|
}
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Move active only
|
|
|
|
if (alt && !shift && !ctrl) {
|
|
|
|
Refresh(false);
|
|
|
|
return;
|
|
|
|
}
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Shift-selection
|
|
|
|
if (shift && !ctrl && !alt) {
|
|
|
|
extendRow = old_extend;
|
|
|
|
// Set range
|
|
|
|
int begin = next;
|
|
|
|
int end = extendRow;
|
|
|
|
if (end < begin)
|
|
|
|
std::swap(begin, end);
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Select range
|
|
|
|
Selection newsel;
|
|
|
|
for (int i = begin; i <= end; i++)
|
|
|
|
newsel.insert(GetDialogue(i));
|
2012-01-25 05:59:17 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
SetSelectedSet(newsel);
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
MakeCellVisible(extendRow, 0, false);
|
|
|
|
return;
|
2006-02-22 03:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 05:59:39 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void BaseGrid::SetByFrame(bool state) {
|
2006-02-22 05:59:39 +01:00
|
|
|
if (byFrame == state) return;
|
|
|
|
byFrame = state;
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
void BaseGrid::SetSelectedSet(const Selection &new_selection) {
|
2011-07-15 06:05:43 +02:00
|
|
|
Selection inserted, removed;
|
2010-06-28 09:13:03 +02:00
|
|
|
set_difference(new_selection, selection, inserted);
|
|
|
|
set_difference(selection, new_selection, removed);
|
2010-06-26 09:26:27 +02:00
|
|
|
selection = new_selection;
|
2010-06-28 09:13:03 +02:00
|
|
|
AnnounceSelectedSetChanged(inserted, removed);
|
2010-06-26 13:32:16 +02:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::SetActiveLine(AssDialogue *new_line) {
|
|
|
|
if (new_line != active_line) {
|
2011-07-15 06:05:43 +02:00
|
|
|
assert(new_line == 0 || line_index_map.count(new_line));
|
2010-06-26 13:32:16 +02:00
|
|
|
active_line = new_line;
|
|
|
|
AnnounceActiveLineChanged(active_line);
|
2011-09-15 07:16:54 +02:00
|
|
|
MakeCellVisible(GetDialogueIndex(active_line), 0, false);
|
2010-06-26 13:32:16 +02:00
|
|
|
Refresh(false);
|
2011-07-15 06:05:43 +02:00
|
|
|
extendRow = GetDialogueIndex(new_line);
|
2010-06-26 13:32:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-05 04:11:03 +02:00
|
|
|
void BaseGrid::SetSelectionAndActive(Selection const& new_selection, AssDialogue *new_line) {
|
|
|
|
BeginBatch();
|
|
|
|
SetSelectedSet(new_selection);
|
|
|
|
SetActiveLine(new_line);
|
|
|
|
EndBatch();
|
|
|
|
}
|
|
|
|
|
2010-06-26 13:32:16 +02:00
|
|
|
void BaseGrid::PrevLine() {
|
|
|
|
int cur_line_i = GetDialogueIndex(GetActiveLine());
|
2011-07-15 06:05:43 +02:00
|
|
|
if (AssDialogue *prev_line = GetDialogue(cur_line_i-1)) {
|
2010-06-26 13:32:16 +02:00
|
|
|
SetActiveLine(prev_line);
|
|
|
|
Selection newsel;
|
|
|
|
newsel.insert(prev_line);
|
|
|
|
SetSelectedSet(newsel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::NextLine() {
|
|
|
|
int cur_line_i = GetDialogueIndex(GetActiveLine());
|
2011-07-15 06:05:43 +02:00
|
|
|
if (AssDialogue *next_line = GetDialogue(cur_line_i+1)) {
|
2010-06-26 13:32:16 +02:00
|
|
|
SetActiveLine(next_line);
|
|
|
|
Selection newsel;
|
|
|
|
newsel.insert(next_line);
|
|
|
|
SetSelectedSet(newsel);
|
|
|
|
}
|
2010-06-26 09:26:27 +02:00
|
|
|
}
|
|
|
|
|
2010-06-26 17:40:10 +02:00
|
|
|
void BaseGrid::AnnounceActiveLineChanged(AssDialogue *new_line) {
|
|
|
|
if (batch_level > 0)
|
|
|
|
batch_active_line_changed = true;
|
|
|
|
else
|
2012-10-05 05:22:54 +02:00
|
|
|
SubtitleSelectionController::AnnounceActiveLineChanged(new_line);
|
2010-06-26 17:40:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) {
|
|
|
|
if (batch_level > 0) {
|
|
|
|
// Remove all previously added lines that are now removed
|
2010-06-27 05:24:03 +02:00
|
|
|
Selection temp;
|
2010-06-28 09:13:03 +02:00
|
|
|
set_difference(batch_selection_added, lines_removed, temp);
|
2010-06-27 05:24:03 +02:00
|
|
|
std::swap(temp, batch_selection_added);
|
|
|
|
temp.clear();
|
|
|
|
|
2010-06-26 17:40:10 +02:00
|
|
|
// Remove all previously removed lines that are now added
|
2010-06-28 09:13:03 +02:00
|
|
|
set_difference(batch_selection_removed, lines_added, temp);
|
2010-06-27 05:24:03 +02:00
|
|
|
std::swap(temp, batch_selection_removed);
|
|
|
|
|
2010-06-26 17:40:10 +02:00
|
|
|
// Add new stuff to batch sets
|
|
|
|
batch_selection_added.insert(lines_added.begin(), lines_added.end());
|
|
|
|
batch_selection_removed.insert(lines_removed.begin(), lines_removed.end());
|
|
|
|
}
|
|
|
|
else {
|
2012-10-05 05:22:54 +02:00
|
|
|
SubtitleSelectionController::AnnounceSelectedSetChanged(lines_added, lines_removed);
|
2010-06-26 17:40:10 +02:00
|
|
|
}
|
|
|
|
}
|