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>
|
2010-06-27 05:24:03 +02:00
|
|
|
#include <iterator>
|
2010-08-03 00:14:11 +02:00
|
|
|
|
|
|
|
#include <wx/dcclient.h>
|
|
|
|
#include <wx/dcmemory.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>
|
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"
|
|
|
|
|
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"
|
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 {
|
|
|
|
GRID_SCROLLBAR = 1730
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
, lastRow(-1)
|
|
|
|
, holding(false)
|
2011-07-16 07:01:36 +02:00
|
|
|
, scrollBar(new wxScrollBar(this, GRID_SCROLLBAR, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL))
|
2011-01-16 08:17:36 +01:00
|
|
|
, bmp(0)
|
2011-07-16 07:01:36 +02:00
|
|
|
, byFrame(false)
|
|
|
|
, extendRow(-1)
|
2011-01-16 08:17:36 +01:00
|
|
|
, active_line(0)
|
|
|
|
, batch_level(0)
|
|
|
|
, batch_active_line_changed(false)
|
|
|
|
, context(context)
|
|
|
|
, yPos(0)
|
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);
|
|
|
|
|
2007-01-04 00:29:03 +01:00
|
|
|
UpdateStyle();
|
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);
|
|
|
|
|
|
|
|
std::tr1::function<void (agi::OptionValue const&)> Refresh(std::tr1::bind(&BaseGrid::Refresh, this, false, (wxRect*)NULL));
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Active Border", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Background", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Comment", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Inframe", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Background/Selection", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Collision", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Header", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Left Column", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Lines", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Selection", Refresh);
|
|
|
|
OPT_SUB("Colour/Subtitle Grid/Standard", Refresh);
|
|
|
|
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh);
|
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();
|
2007-01-04 00:29:03 +01:00
|
|
|
delete bmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Set column widths
|
2010-05-21 03:13:36 +02:00
|
|
|
std::vector<bool> column_array;
|
|
|
|
OPT_GET("Subtitle/Grid/Column")->GetListBool(column_array);
|
2010-06-22 02:03:22 +02:00
|
|
|
assert(column_array.size() == 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();
|
|
|
|
|
|
|
|
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) {
|
2009-04-26 03:02:23 +02:00
|
|
|
lastRow = row;
|
|
|
|
|
2006-02-19 00:00:09 +01:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
GetClientSize(&w,&h);
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
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
|
|
|
|
2006-02-22 06:30:09 +01:00
|
|
|
void BaseGrid::SelectVisible() {
|
2010-06-28 09:13:03 +02:00
|
|
|
Selection new_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
|
|
|
|
2006-02-22 06:30:09 +01:00
|
|
|
int rows = GetRows();
|
|
|
|
bool selectedOne = false;
|
|
|
|
for (int i=0;i<rows;i++) {
|
2010-06-28 09:13:03 +02:00
|
|
|
AssDialogue *diag = GetDialogue(i);
|
|
|
|
if (IsDisplayed(diag)) {
|
2006-02-22 06:30:09 +01:00
|
|
|
if (!selectedOne) {
|
|
|
|
MakeCellVisible(i,0);
|
|
|
|
selectedOne = true;
|
|
|
|
}
|
2010-06-28 09:13:03 +02:00
|
|
|
new_selection.insert(diag);
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
|
|
|
}
|
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-28 09:13:03 +02:00
|
|
|
SetSelectedSet(new_selection);
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
|
|
|
|
2010-05-26 09:17:34 +02:00
|
|
|
int BaseGrid::GetFirstSelRow() const {
|
2011-07-15 06:05:43 +02:00
|
|
|
if (selection.empty()) return -1;
|
2010-06-26 09:26:27 +02:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
Selection::const_iterator it = selection.begin();
|
2010-06-26 09:26:27 +02:00
|
|
|
|
|
|
|
int index = GetDialogueIndex(*it);
|
|
|
|
for (; it != selection.end(); ++it) {
|
|
|
|
int other_index = GetDialogueIndex(*it);
|
|
|
|
if (other_index < index) index = other_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
2006-02-22 05:59:39 +01:00
|
|
|
}
|
|
|
|
|
2011-07-15 06:05:22 +02:00
|
|
|
wxArrayInt BaseGrid::GetSelection() const {
|
|
|
|
wxArrayInt res(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
|
|
|
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)
|
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
|
|
|
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
|
2006-02-18 22:55:58 +01:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void BaseGrid::OnPaint(wxPaintEvent &event) {
|
|
|
|
// Get size and pos
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
GetClientSize(&w,&h);
|
|
|
|
w -= scrollBar->GetSize().GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Prepare bitmap
|
|
|
|
if (bmp) {
|
|
|
|
if (bmp->GetWidth() < w || bmp->GetHeight() < h) {
|
|
|
|
delete bmp;
|
|
|
|
bmp = 0;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
if (!bmp) bmp = new wxBitmap(w,h);
|
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) {
|
|
|
|
if (updrect.x < x + colWidth[i] && updrect.x + updrect.width > x)
|
|
|
|
paint_columns[i] = true;
|
|
|
|
x += colWidth[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Draw bitmap
|
|
|
|
wxMemoryDC bmpDC;
|
|
|
|
bmpDC.SelectObject(*bmp);
|
2011-08-27 08:52:42 +02:00
|
|
|
DrawImage(bmpDC, paint_columns);
|
|
|
|
|
|
|
|
wxPaintDC dc(this);
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.Blit(0,0,w,h,&bmpDC,0,0);
|
|
|
|
}
|
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);
|
|
|
|
|
2010-05-21 03:13:36 +02:00
|
|
|
dc.SetBackground(wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColour())));
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
// Draw labels
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2010-05-21 03:13:36 +02:00
|
|
|
dc.SetBrush(wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColour())));
|
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()));
|
|
|
|
wxColour text_selection(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Standard")->GetColour()));
|
|
|
|
wxColour text_collision(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Collision")->GetColour()));
|
|
|
|
|
|
|
|
wxBrush rowColors[] = {
|
|
|
|
wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColour())),
|
|
|
|
wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Header")->GetColour())),
|
|
|
|
wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColour())),
|
|
|
|
wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColour())),
|
|
|
|
wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColour())),
|
|
|
|
wxBrush(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->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
|
|
|
|
|
|
|
// Draw rows
|
2011-08-27 08:52:42 +02:00
|
|
|
wxString strings[11] = {
|
|
|
|
_("#"),
|
|
|
|
_("L"),
|
|
|
|
_("Start"),
|
|
|
|
_("End"),
|
|
|
|
_("Style"),
|
|
|
|
_("Actor"),
|
|
|
|
_("Effect"),
|
|
|
|
_("Left"),
|
|
|
|
_("Right"),
|
|
|
|
_("Vert"),
|
|
|
|
_("Text")
|
|
|
|
};
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = 0; i < nDraw + 1; i++) {
|
|
|
|
int curRow = i + yPos - 1;
|
2010-11-08 03:52:54 +01:00
|
|
|
int curColor = 0;
|
2006-02-20 23:54:23 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Header
|
|
|
|
if (i == 0) {
|
|
|
|
curColor = 1;
|
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)) {
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set fields
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[0]) strings[0] = wxString::Format("%i", curRow + 1);
|
|
|
|
if (paint_columns[1]) strings[1] = wxString::Format("%i", curDiag->Layer);
|
2006-02-19 01:54:35 +01:00
|
|
|
if (byFrame) {
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[2]) strings[2] = wxString::Format("%i", context->videoController->FrameAtTime(curDiag->Start.GetMS(), agi::vfr::START));
|
|
|
|
if (paint_columns[3]) strings[3] = wxString::Format("%i", context->videoController->FrameAtTime(curDiag->End.GetMS(), agi::vfr::END));
|
2006-02-19 01:54:35 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[2]) strings[2] = curDiag->Start.GetASSFormated();
|
|
|
|
if (paint_columns[3]) strings[3] = curDiag->End.GetASSFormated();
|
2006-02-19 01:54:35 +01:00
|
|
|
}
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[4]) strings[4] = curDiag->Style;
|
|
|
|
if (paint_columns[5]) strings[5] = curDiag->Actor;
|
|
|
|
if (paint_columns[6]) strings[6] = curDiag->Effect;
|
|
|
|
if (paint_columns[7]) strings[7] = curDiag->GetMarginString(0);
|
|
|
|
if (paint_columns[8]) strings[8] = curDiag->GetMarginString(1);
|
|
|
|
if (paint_columns[9]) strings[9] = curDiag->GetMarginString(2);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// Set text
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[10]) {
|
|
|
|
strings[10].clear();
|
|
|
|
int mode = OPT_GET("Subtitle/Grid/Hide Overrides")->GetInt();
|
|
|
|
|
|
|
|
// Hidden overrides
|
|
|
|
if (mode == 1 || mode == 2) {
|
|
|
|
wxString replaceWith = lagi_wxString(OPT_GET("Subtitle/Grid/Hide Overrides Char")->GetString());
|
|
|
|
strings[10].reserve(curDiag->Text.size());
|
|
|
|
size_t start = 0, pos;
|
|
|
|
while ((pos = curDiag->Text.find('{', start)) != wxString::npos) {
|
|
|
|
strings[10] += curDiag->Text.Mid(start, pos - start);
|
|
|
|
strings[10] += replaceWith;
|
|
|
|
start = curDiag->Text.find('}', pos);
|
|
|
|
if (start != wxString::npos) ++start;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
2011-08-27 08:52:42 +02:00
|
|
|
strings[10] += curDiag->Text.Mid(start);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
// Show overrides
|
|
|
|
else strings[10] = curDiag->Text;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
// Cap length and set text
|
|
|
|
if (strings[10].size() > 512) strings[10] = strings[10].Left(512) + "...";
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// Set color
|
|
|
|
curColor = 0;
|
2011-09-15 07:17:36 +02:00
|
|
|
bool inSel = !!selection.count(curDiag);
|
2006-02-21 00:12:08 +01:00
|
|
|
if (inSel && curDiag->Comment) curColor = 5;
|
|
|
|
else if (inSel) curColor = 2;
|
2006-02-19 01:54:35 +01:00
|
|
|
else if (curDiag->Comment) curColor = 3;
|
2010-05-21 03:13:36 +02:00
|
|
|
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag)) curColor = 4;
|
2010-11-08 03:52:54 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
if (active_line != curDiag && curDiag->CollidesWith(active_line)) {
|
|
|
|
dc.SetTextForeground(text_collision);
|
|
|
|
}
|
|
|
|
else if (inSel) {
|
|
|
|
dc.SetTextForeground(text_selection);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dc.SetTextForeground(text_standard);
|
2010-11-08 03:52:54 +01:00
|
|
|
}
|
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;
|
|
|
|
dc.SetPen(wxPen(lagi_wxColour(OPT_GET("Colour/Subtitle Grid/Lines")->GetColour())));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnSize(wxSizeEvent &event) {
|
|
|
|
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) {
|
|
|
|
int w,h;
|
|
|
|
GetClientSize(&w,&h);
|
|
|
|
|
|
|
|
// Modifiers
|
|
|
|
bool shift = event.m_shiftDown;
|
|
|
|
bool alt = event.m_altDown;
|
2007-09-22 00:56:44 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
bool ctrl = event.m_metaDown;
|
|
|
|
#else
|
2006-02-18 22:55:58 +01:00
|
|
|
bool ctrl = event.m_controlDown;
|
2007-09-22 00:56:44 +02:00
|
|
|
#endif
|
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();
|
2006-02-18 22:55:58 +01: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
|
|
|
|
2006-02-22 03:25:45 +01:00
|
|
|
// Get focus
|
|
|
|
if (event.ButtonDown()) {
|
2010-05-21 03:13:36 +02:00
|
|
|
if (OPT_GET("Subtitle/Grid/Focus Allow")->GetBool()) {
|
2006-02-22 03:25:45 +01:00
|
|
|
SetFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-18 23:44:12 +01:00
|
|
|
// Click type
|
2006-06-21 01:32:01 +02:00
|
|
|
bool startedHolding = false;
|
2011-07-15 06:05:43 +02:00
|
|
|
if (click && !holding && dlg) {
|
2006-02-18 23:44:12 +01:00
|
|
|
holding = true;
|
2006-06-21 01:32:01 +02:00
|
|
|
startedHolding = true;
|
2006-02-18 23:44:12 +01:00
|
|
|
CaptureMouse();
|
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
if (!event.LeftIsDown() && holding) {
|
2006-02-18 23:44:12 +01:00
|
|
|
holding = false;
|
|
|
|
ReleaseMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scroll to keep visible
|
|
|
|
if (holding) {
|
|
|
|
// Find direction
|
|
|
|
int minVis = yPos+1;
|
|
|
|
int maxVis = yPos+h/lineHeight-3;
|
|
|
|
int delta = 0;
|
|
|
|
if (row < minVis) delta = -1;
|
|
|
|
if (row > maxVis) delta = +1;
|
|
|
|
|
|
|
|
// Scroll
|
2006-06-21 01:32:01 +02:00
|
|
|
if (delta) {
|
|
|
|
ScrollTo(yPos+delta*3);
|
|
|
|
if (startedHolding) {
|
|
|
|
holding = false;
|
|
|
|
ReleaseMouse();
|
|
|
|
}
|
|
|
|
}
|
2006-02-18 23:44:12 +01:00
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Click
|
2011-07-15 06:05:43 +02:00
|
|
|
if ((click || holding || dclick) && dlg) {
|
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;
|
|
|
|
SelectRow(row,true,!isSel);
|
2010-06-27 06:55:14 +02:00
|
|
|
if (dlg == GetActiveLine()) {
|
|
|
|
SetActiveLine(GetDialogue(GetFirstSelRow()));
|
|
|
|
}
|
2010-06-27 06:55:03 +02:00
|
|
|
lastRow = row;
|
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) {
|
2010-06-26 13:32:16 +02:00
|
|
|
SetActiveLine(dlg);
|
2011-01-16 08:17:36 +01:00
|
|
|
if (dclick) context->videoController->JumpToTime(dlg->Start.GetMS());
|
2006-02-18 23:09:03 +01:00
|
|
|
SelectRow(row,false);
|
|
|
|
lastRow = row;
|
|
|
|
return;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2010-06-28 09:12:36 +02:00
|
|
|
// Keep selection
|
|
|
|
if (click && !shift && !ctrl && alt) {
|
|
|
|
SetActiveLine(dlg);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Block select
|
2010-06-27 06:55:08 +02:00
|
|
|
if ((click && shift && !alt) || (holding && !ctrl && !alt && !shift)) {
|
2006-02-18 22:55:58 +01:00
|
|
|
if (lastRow != -1) {
|
|
|
|
// Set boundaries
|
|
|
|
int i1 = row;
|
|
|
|
int i2 = lastRow;
|
|
|
|
if (i1 > i2) {
|
2010-06-26 13:32:16 +02:00
|
|
|
std::swap(i1, i2);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Toggle each
|
2010-06-26 13:32:16 +02:00
|
|
|
Selection newsel;
|
2010-06-27 06:55:08 +02:00
|
|
|
if (ctrl) newsel = selection;
|
2006-02-18 22:55:58 +01:00
|
|
|
for (int i=i1;i<=i2;i++) {
|
2010-06-26 13:32:16 +02:00
|
|
|
newsel.insert(GetDialogue(i));
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
2010-06-26 13:32:16 +02:00
|
|
|
SetSelectedSet(newsel);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse wheel
|
|
|
|
if (event.GetWheelRotation() != 0) {
|
|
|
|
int step = 3 * event.GetWheelRotation() / event.GetWheelDelta();
|
2006-02-19 04:10:03 +01:00
|
|
|
ScrollTo(yPos - step);
|
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();
|
|
|
|
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight)
|
|
|
|
OpenBodyContextMenu();
|
|
|
|
else
|
|
|
|
OpenHeaderContextMenu();
|
|
|
|
}
|
|
|
|
|
2006-02-19 04:10:03 +01:00
|
|
|
void BaseGrid::ScrollTo(int y) {
|
|
|
|
int w,h;
|
|
|
|
GetClientSize(&w,&h);
|
2010-12-31 22:03:03 +01:00
|
|
|
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
|
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
GetClientSize(&w,&h);
|
|
|
|
|
|
|
|
// DC for text extents test
|
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.SetFont(font);
|
|
|
|
int fw,fh;
|
|
|
|
|
|
|
|
// O(1) widths
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.GetTextExtent("0000", &fw, &fh, NULL, NULL, &font);
|
2006-02-18 22:55:58 +01:00
|
|
|
int marginLen = fw + 10;
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.GetTextExtent(wxString::Format("%i",GetRows()), &fw, &fh, NULL, NULL, &font);
|
2006-02-18 22:55:58 +01:00
|
|
|
int labelLen = fw + 10;
|
|
|
|
int startLen = 0;
|
|
|
|
int endLen = 0;
|
|
|
|
if (!byFrame) {
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.GetTextExtent(AssTime().GetASSFormated(), &fw, &fh, NULL, NULL, &font);
|
|
|
|
startLen = endLen = fw + 10;
|
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);
|
|
|
|
maxLayer = std::max(maxLayer, curDiag->Layer);
|
|
|
|
|
|
|
|
// Actor
|
|
|
|
if (!curDiag->Actor.empty()) {
|
|
|
|
dc.GetTextExtent(curDiag->Actor, &fw, &fh, NULL, NULL, &font);
|
|
|
|
if (fw > actorLen) actorLen = fw;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Style
|
|
|
|
if (!curDiag->Style.empty()) {
|
|
|
|
dc.GetTextExtent(curDiag->Style, &fw, &fh, NULL, NULL, &font);
|
|
|
|
if (fw > styleLen) styleLen = fw;
|
|
|
|
}
|
2006-12-30 19:19:54 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Effect
|
|
|
|
if (!curDiag->Effect.empty()) {
|
|
|
|
dc.GetTextExtent(curDiag->Effect, &fw, &fh, NULL, NULL, &font);
|
|
|
|
if (fw > effectLen) effectLen = fw;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Margins
|
|
|
|
for (int j=0;j<3;j++) {
|
|
|
|
if (curDiag->Margin[j]) showMargin[j] = true;
|
|
|
|
}
|
2007-07-03 03:48:04 +02:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Times
|
|
|
|
if (byFrame) {
|
|
|
|
maxStart = std::max(maxStart, context->videoController->FrameAtTime(curDiag->Start.GetMS(), agi::vfr::START));
|
|
|
|
maxEnd = std::max(maxEnd, context->videoController->FrameAtTime(curDiag->End.GetMS(), agi::vfr::END));
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish layer
|
2011-07-15 06:05:43 +02:00
|
|
|
int layerLen = 0;
|
|
|
|
if (maxLayer > 0) {
|
|
|
|
dc.GetTextExtent(wxString::Format("%i", maxLayer), &fw, &fh, NULL, NULL, &font);
|
|
|
|
layerLen = fw + 10;
|
|
|
|
}
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish times
|
|
|
|
if (byFrame) {
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.GetTextExtent(wxString::Format("%i", maxStart), &fw, &fh, NULL, NULL, &font);
|
2006-02-22 06:30:09 +01:00
|
|
|
startLen = fw + 10;
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.GetTextExtent(wxString::Format("%i", maxEnd), &fw, &fh, NULL, NULL, &font);
|
2006-02-22 06:30:09 +01:00
|
|
|
endLen = fw + 10;
|
|
|
|
}
|
|
|
|
|
2006-12-30 19:19:54 +01:00
|
|
|
// Finish actor/effect/style
|
|
|
|
if (actorLen) actorLen += 10;
|
|
|
|
if (effectLen) effectLen += 10;
|
|
|
|
if (styleLen) styleLen += 10;
|
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;
|
2007-07-03 03:48:04 +02:00
|
|
|
for (int i=0;i<3;i++) colWidth[i+7] = showMargin[i] ? marginLen : 0;
|
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++) {
|
2010-06-22 02:03:22 +02:00
|
|
|
if (!showCol[i]) colWidth[i] = 0;
|
2006-06-27 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set size of last
|
|
|
|
int total = 0;
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i=0;i<10;i++) total += colWidth[i];
|
2006-02-18 22:55:58 +01:00
|
|
|
colWidth[10] = w-total;
|
2011-09-15 07:16:32 +02:00
|
|
|
|
|
|
|
time_cols_x = labelLen + layerLen;
|
|
|
|
time_cols_w = startLen + endLen;
|
|
|
|
text_col_x = total;
|
|
|
|
text_col_w = colWidth[10];
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
/// @brief Get dialogue by index
|
|
|
|
/// @param n Index to look up
|
|
|
|
/// @return Subtitle dialogue line for index, or 0 if invalid index
|
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];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Get index by dialogue line
|
|
|
|
/// @param diag Dialogue line to look up
|
|
|
|
/// @return Subtitle index for object, or -1 if unknown subtitle
|
|
|
|
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-01-16 08:17:36 +01:00
|
|
|
context->videoController->FrameAtTime(line->Start.GetMS(),agi::vfr::START) <= frame &&
|
|
|
|
context->videoController->FrameAtTime(line->End.GetMS(),agi::vfr::END) >= frame;
|
2006-02-19 01:54:35 +01:00
|
|
|
}
|
2006-02-21 03:01:42 +01:00
|
|
|
|
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
|
|
|
void BaseGrid::OnKeyDown(wxKeyEvent &event) {
|
2011-01-19 04:12:46 +01:00
|
|
|
event.StopPropagation();
|
2011-07-30 01:16:55 +02:00
|
|
|
if (hotkey::check("Subtitle Grid", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
|
2011-01-19 04:12:46 +01:00
|
|
|
return;
|
|
|
|
|
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
|
|
|
|
|
|
|
// Moving
|
|
|
|
if (dir) {
|
|
|
|
// Move selection
|
|
|
|
if (!ctrl && !shift && !alt) {
|
2011-07-15 06:05:43 +02:00
|
|
|
int next = mid(0, extendRow + dir * step, GetRows() - 1);
|
2010-06-26 13:32:16 +02:00
|
|
|
SetActiveLine(GetDialogue(next));
|
2006-02-22 03:25:45 +01:00
|
|
|
SelectRow(next);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move active only
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (alt && !shift && !ctrl) {
|
|
|
|
int next = mid(0, GetDialogueIndex(GetActiveLine()) + dir * step, GetRows() - 1);
|
2010-06-26 13:32:16 +02:00
|
|
|
SetActiveLine(GetDialogue(next));
|
2006-02-22 03:25:45 +01:00
|
|
|
Refresh(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-22 04:38:23 +01:00
|
|
|
// Shift-selection
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (shift && !ctrl && !alt) {
|
|
|
|
extendRow = mid(0, extendRow + dir * step, GetRows() - 1);
|
2006-02-22 04:38:23 +01:00
|
|
|
|
|
|
|
// Set range
|
2011-07-15 06:05:43 +02:00
|
|
|
int begin = GetDialogueIndex(GetActiveLine());
|
|
|
|
int end = extendRow;
|
|
|
|
if (end < begin) {
|
|
|
|
std::swap(begin, end);
|
2006-02-22 03:25:45 +01:00
|
|
|
}
|
|
|
|
|
2006-02-22 04:38:23 +01:00
|
|
|
// Select range
|
2010-06-26 13:32:16 +02:00
|
|
|
Selection newsel;
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = begin; i <= end; i++) {
|
2010-06-26 13:32:16 +02:00
|
|
|
newsel.insert(GetDialogue(i));
|
2006-02-22 03:25:45 +01:00
|
|
|
}
|
2010-06-26 13:32:16 +02:00
|
|
|
SetSelectedSet(newsel);
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
MakeCellVisible(extendRow, 0, false);
|
2006-03-05 05:31:09 +01:00
|
|
|
return;
|
2006-02-22 03:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
2011-07-30 01:16:55 +02:00
|
|
|
else if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) {
|
2011-01-19 04:12:46 +01:00
|
|
|
event.Skip();
|
2006-03-05 05:31:09 +01:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2010-06-27 05:24:03 +02:00
|
|
|
BaseSelectionController<AssDialogue>::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 {
|
2010-06-27 05:24:03 +02:00
|
|
|
BaseSelectionController<AssDialogue>::AnnounceSelectedSetChanged(lines_added, lines_removed);
|
2010-06-26 17:40:10 +02:00
|
|
|
}
|
|
|
|
}
|