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/
|
|
|
|
|
|
|
|
/// @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"
|
|
|
|
|
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"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2013-01-26 02:57:46 +01:00
|
|
|
#include "subs_controller.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
|
|
|
|
2012-11-05 17:20:58 +01:00
|
|
|
#include <libaegisub/of_type_adaptor.h>
|
|
|
|
|
2013-09-16 19:43:21 +02:00
|
|
|
#include <algorithm>
|
2013-09-16 21:02:17 +02:00
|
|
|
#include <boost/range/algorithm.hpp>
|
2013-09-16 19:43:21 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <iterator>
|
|
|
|
#include <numeric>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <wx/dcbuffer.h>
|
|
|
|
#include <wx/kbdstate.h>
|
|
|
|
#include <wx/menu.h>
|
2013-09-16 21:02:17 +02:00
|
|
|
#include <wx/scrolbar.h>
|
2013-09-16 19:43:21 +02:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2013-09-16 19:43:21 +02:00
|
|
|
namespace std {
|
|
|
|
template <typename T>
|
|
|
|
struct hash<boost::flyweight<T>> {
|
|
|
|
size_t operator()(boost::flyweight<T> const& ss) const {
|
|
|
|
return hash<const void*>()(&ss.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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)
|
2011-07-16 07:01:36 +02:00
|
|
|
, scrollBar(new wxScrollBar(this, GRID_SCROLLBAR, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL))
|
2012-11-13 17:51:01 +01:00
|
|
|
, seek_listener(context->videoController->AddSeekListener(std::bind(&BaseGrid::Refresh, this, false, nullptr)))
|
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);
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
auto scrollbarpositioner = new wxBoxSizer(wxHORIZONTAL);
|
2009-07-27 01:24:21 +02:00
|
|
|
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);
|
2013-01-26 02:57:46 +01:00
|
|
|
context->subsController->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, this);
|
|
|
|
context->subsController->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);
|
2012-11-13 17:51:01 +01:00
|
|
|
OPT_SUB("Subtitle/Grid/Hide Overrides", std::bind(&BaseGrid::Refresh, this, false, nullptr));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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()) {
|
2013-10-08 02:42:09 +02:00
|
|
|
int row = context->ass->GetUIStateAsInt("Active Line");
|
2012-01-25 20:07:36 +01:00
|
|
|
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
|
|
|
|
2013-10-08 02:42:09 +02:00
|
|
|
ScrollTo(context->ass->GetUIStateAsInt("Scroll Position"));
|
2012-01-25 20:07:36 +01:00
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
EndBatch();
|
|
|
|
SetColumnWidths();
|
|
|
|
}
|
|
|
|
|
2012-01-25 20:07:36 +01:00
|
|
|
void BaseGrid::OnSubtitlesSave() {
|
2013-10-08 02:42:09 +02:00
|
|
|
context->ass->SaveUIState("Scroll Position", std::to_string(yPos));
|
|
|
|
context->ass->SaveUIState("Active Line", std::to_string(GetDialogueIndex(active_line)));
|
2012-01-25 20:07:36 +01:00
|
|
|
}
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
|
|
|
|
int item = event.GetId() - MENU_SHOW_COL;
|
|
|
|
showCol[item] = !showCol[item];
|
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
std::vector<bool> map(std::begin(showCol), std::end(showCol));
|
2011-11-08 01:24:41 +01:00
|
|
|
OPT_SET("Subtitle/Grid/Column")->SetListBool(map);
|
|
|
|
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnHighlightVisibleChange(agi::OptionValue const& opt) {
|
2013-09-16 21:02:17 +02:00
|
|
|
if (opt.GetBool())
|
2011-11-08 01:24:41 +01:00
|
|
|
seek_listener.Unblock();
|
2013-09-16 21:02:17 +02:00
|
|
|
else
|
2011-11-08 01:24:41 +01:00
|
|
|
seek_listener.Block();
|
2007-01-04 00:29:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::UpdateStyle() {
|
2013-12-10 18:08:30 +01:00
|
|
|
wxString fontname = FontFace("Subtitle/Grid");
|
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;
|
2012-11-13 17:51:01 +01:00
|
|
|
dc.GetTextExtent("#TWFfgGhH", &fw, &fh, nullptr, nullptr, &font);
|
2011-07-15 06:05:43 +02:00
|
|
|
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);
|
2012-10-26 16:09:14 +02:00
|
|
|
rowColors[COLOR_DEFAULT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColor()));
|
|
|
|
rowColors[COLOR_HEADER].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Header")->GetColor()));
|
|
|
|
rowColors[COLOR_SELECTION].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
|
|
|
|
rowColors[COLOR_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColor()));
|
|
|
|
rowColors[COLOR_VISIBLE].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColor()));
|
|
|
|
rowColors[COLOR_SELECTED_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColor()));
|
|
|
|
rowColors[COLOR_LEFT_COL].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColor()));
|
2012-01-31 01:43:15 +01:00
|
|
|
|
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());
|
2013-09-16 21:02:17 +02:00
|
|
|
assert(column_array.size() == boost::size(showCol));
|
|
|
|
boost::copy(column_array, std::begin(showCol));
|
2006-02-18 22:55:58 +01:00
|
|
|
SetColumnWidths();
|
|
|
|
|
2007-01-04 00:29:03 +01:00
|
|
|
AdjustScrollbar();
|
2013-09-16 21:02:17 +02:00
|
|
|
Refresh(false);
|
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),
|
2012-09-25 03:15:20 +02:00
|
|
|
[this](AssDialogue *diag) { return GetDialogueIndex(diag); });
|
2010-07-13 07:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
index_line_map.clear();
|
|
|
|
line_index_map.clear();
|
|
|
|
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto curdiag : context->ass->Line | agi::of_type<AssDialogue>()) {
|
|
|
|
line_index_map[curdiag] = (int)index_line_map.size();
|
|
|
|
index_line_map.push_back(curdiag);
|
2013-09-16 21:02:17 +02:00
|
|
|
}
|
2010-07-13 07:29:08 +02:00
|
|
|
|
|
|
|
if (preserve_selected_rows) {
|
|
|
|
Selection sel;
|
|
|
|
|
|
|
|
// If the file shrank enough that no selected rows are left, select the
|
|
|
|
// last row
|
2012-11-04 04:53:03 +01:00
|
|
|
if (sel_rows.empty())
|
2010-07-13 07:29:08 +02:00
|
|
|
sel_rows.push_back(index_line_map.size() - 1);
|
2012-11-04 04:53:03 +01:00
|
|
|
else if (sel_rows[0] >= (int)index_line_map.size())
|
2010-07-13 07:29:08 +02:00
|
|
|
sel_rows[0] = index_line_map.size() - 1;
|
2012-11-04 04:53:03 +01:00
|
|
|
|
|
|
|
for (int row : sel_rows) {
|
|
|
|
if (row >= (int)index_line_map.size()) break;
|
|
|
|
sel.insert(index_line_map[row]);
|
2010-07-13 07:29:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The active line may have ceased to exist; pick a new one if so
|
2013-10-27 14:59:56 +01:00
|
|
|
if (line_index_map.size() && !line_index_map.count(active_line)) {
|
2013-09-16 21:02:17 +02:00
|
|
|
if (active_row < (int)index_line_map.size())
|
2010-07-13 07:29:08 +02:00
|
|
|
SetActiveLine(index_line_map[active_row]);
|
2013-09-16 21:02:17 +02:00
|
|
|
else if (preserve_selected_rows && !selection.empty())
|
2010-07-13 07:29:08 +02:00
|
|
|
SetActiveLine(index_line_map[sel_rows[0]]);
|
2013-09-16 21:02:17 +02:00
|
|
|
else
|
2010-07-13 07:29:08 +02:00
|
|
|
SetActiveLine(index_line_map.back());
|
|
|
|
}
|
|
|
|
|
2013-12-12 00:11:06 +01:00
|
|
|
if (selection.empty() && active_line)
|
|
|
|
SetSelectedSet({ active_line });
|
2010-07-13 07:29:08 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
void BaseGrid::MakeRowVisible(int row) {
|
2012-05-04 04:52:52 +02:00
|
|
|
int h = GetClientSize().GetHeight();
|
2006-02-19 00:00:09 +01:00
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
if (row < yPos + 1)
|
|
|
|
ScrollTo(row - 1);
|
|
|
|
else if (row > yPos + h/lineHeight - 3)
|
|
|
|
ScrollTo(row - h/lineHeight + 3);
|
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),
|
2012-09-25 01:35:27 +02:00
|
|
|
std::bind(&BaseGrid::GetDialogueIndex, this, std::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
|
|
|
}
|
|
|
|
|
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
|
2013-09-16 21:02:17 +02:00
|
|
|
bool paint_columns[11] = {0};
|
|
|
|
for (wxRegionIterator region(GetUpdateRegion()); region; ++region) {
|
2011-08-27 08:52:42 +02:00
|
|
|
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
|
2012-10-26 16:09:14 +02:00
|
|
|
wxColour text_standard(to_wx(OPT_GET("Colour/Subtitle Grid/Standard")->GetColor()));
|
|
|
|
wxColour text_selection(to_wx(OPT_GET("Colour/Subtitle Grid/Selection")->GetColor()));
|
|
|
|
wxColour text_collision(to_wx(OPT_GET("Colour/Subtitle Grid/Collision")->GetColor()));
|
2011-07-15 06:05:43 +02:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// First grid row
|
2012-10-26 16:09:14 +02:00
|
|
|
wxPen grid_pen(to_wx(OPT_GET("Colour/Subtitle Grid/Lines")->GetColor()));
|
2011-07-15 06:05:43 +02:00
|
|
|
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)
|
2012-12-23 00:18:38 +01:00
|
|
|
replace_char = to_wx(OPT_GET("Subtitle/Grid/Hide Overrides Char")->GetString());
|
2012-01-31 01:43:32 +01:00
|
|
|
|
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()) {
|
2012-10-26 16:09:14 +02:00
|
|
|
dc.SetPen(wxPen(to_wx(OPT_GET("Colour/Subtitle Grid/Active Border")->GetColor())));
|
2010-06-26 13:32:16 +02:00
|
|
|
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 {
|
2013-09-18 17:31:26 +02:00
|
|
|
if (paint_columns[0]) strings[0] = std::to_wstring(row + 1);
|
|
|
|
if (paint_columns[1]) strings[1] = std::to_wstring(line->Layer);
|
2011-11-08 01:24:53 +01:00
|
|
|
if (byFrame) {
|
2013-09-18 17:31:26 +02:00
|
|
|
if (paint_columns[2]) strings[2] = std::to_wstring(context->videoController->FrameAtTime(line->Start, agi::vfr::START));
|
|
|
|
if (paint_columns[3]) strings[3] = std::to_wstring(context->videoController->FrameAtTime(line->End, agi::vfr::END));
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-01-04 16:01:50 +01:00
|
|
|
if (paint_columns[2]) strings[2] = to_wx(line->Start.GetAssFormated());
|
|
|
|
if (paint_columns[3]) strings[3] = to_wx(line->End.GetAssFormated());
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
if (paint_columns[4]) strings[4] = to_wx(line->Style);
|
|
|
|
if (paint_columns[5]) strings[5] = to_wx(line->Actor);
|
|
|
|
if (paint_columns[6]) strings[6] = to_wx(line->Effect);
|
2014-01-05 17:10:08 +01:00
|
|
|
if (paint_columns[7]) strings[7] = line->Margin[0] ? wxString(std::to_wstring(line->Margin[0])) : wxString();
|
|
|
|
if (paint_columns[8]) strings[8] = line->Margin[1] ? wxString(std::to_wstring(line->Margin[1])) : wxString();
|
|
|
|
if (paint_columns[9]) strings[9] = line->Margin[2] ? wxString(std::to_wstring(line->Margin[2])) : wxString();
|
2011-11-08 01:24:53 +01:00
|
|
|
|
|
|
|
if (paint_columns[10]) {
|
|
|
|
strings[10].clear();
|
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
// Show overrides
|
|
|
|
if (!replace)
|
|
|
|
strings[10] = to_wx(line->Text);
|
2011-11-08 01:24:53 +01:00
|
|
|
// Hidden overrides
|
2013-09-16 21:02:17 +02:00
|
|
|
else {
|
2012-12-04 23:35:59 +01:00
|
|
|
strings[10].reserve(line->Text.get().size());
|
2011-11-08 01:24:53 +01:00
|
|
|
size_t start = 0, pos;
|
2013-01-04 16:01:50 +01:00
|
|
|
while ((pos = line->Text.get().find('{', start)) != std::string::npos) {
|
|
|
|
strings[10] += to_wx(line->Text.get().substr(start, pos - start));
|
2012-01-31 01:43:32 +01:00
|
|
|
strings[10] += rep_char;
|
2012-12-04 23:35:59 +01:00
|
|
|
start = line->Text.get().find('}', pos);
|
2013-01-04 16:01:50 +01:00
|
|
|
if (start != std::string::npos) ++start;
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
if (start != std::string::npos)
|
|
|
|
strings[10] += to_wx(line->Text.get().substr(start));
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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();
|
2013-09-16 19:26:41 +02:00
|
|
|
|
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
colWidth[10] = text_col_w = w - text_col_x;
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
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;
|
2013-09-16 21:02:17 +02:00
|
|
|
if (holding && !click)
|
|
|
|
row = mid(0, row, GetRows()-1);
|
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)
|
2013-09-16 21:02:17 +02:00
|
|
|
MakeRowVisible(row);
|
2012-05-04 04:52:52 +02:00
|
|
|
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;
|
2013-12-12 00:11:06 +01:00
|
|
|
for (int i = i1; i <= i2; i++)
|
2012-01-25 05:59:17 +01:00
|
|
|
newsel.insert(GetDialogue(i));
|
|
|
|
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);
|
2013-06-10 15:58:13 +02:00
|
|
|
menu::OpenPopupMenu(context_menu.get(), this);
|
2011-11-08 01:24:41 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const wxString strings[] = {
|
|
|
|
_("Line Number"),
|
|
|
|
_("Layer"),
|
|
|
|
_("Start"),
|
|
|
|
_("End"),
|
|
|
|
_("Style"),
|
|
|
|
_("Actor"),
|
|
|
|
_("Effect"),
|
|
|
|
_("Left"),
|
|
|
|
_("Right"),
|
|
|
|
_("Vert"),
|
|
|
|
};
|
|
|
|
|
|
|
|
wxMenu menu;
|
2013-09-16 21:02:17 +02:00
|
|
|
for (size_t i = 0; i < boost::size(showCol); ++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-10-20 17:26:38 +02:00
|
|
|
int nextY = mid(0, y, GetRows() - 1);
|
2006-02-19 04:10:03 +01:00
|
|
|
if (yPos != nextY) {
|
|
|
|
yPos = nextY;
|
2012-10-20 17:26:38 +02:00
|
|
|
scrollBar->SetThumbPosition(yPos);
|
2006-02-19 04:10:03 +01:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
void BaseGrid::AdjustScrollbar() {
|
2012-10-20 17:26:38 +02:00
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
wxSize scrollbarSize = scrollBar->GetSize();
|
2006-02-22 07:08:35 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
scrollBar->Freeze();
|
2012-10-20 17:26:38 +02:00
|
|
|
scrollBar->SetSize(clientSize.GetWidth() - scrollbarSize.GetWidth(), 0, scrollbarSize.GetWidth(), clientSize.GetHeight());
|
|
|
|
|
|
|
|
if (GetRows() <= 1) {
|
|
|
|
scrollBar->Enable(false);
|
|
|
|
scrollBar->Thaw();
|
|
|
|
return;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
if (!scrollBar->IsEnabled())
|
2012-10-20 17:26:38 +02:00
|
|
|
scrollBar->Enable(true);
|
|
|
|
|
|
|
|
int drawPerScreen = clientSize.GetHeight() / lineHeight;
|
|
|
|
int rows = GetRows();
|
|
|
|
|
|
|
|
yPos = mid(0, yPos, rows - 1);
|
|
|
|
|
|
|
|
scrollBar->SetScrollbar(yPos, drawPerScreen, rows + drawPerScreen - 1, drawPerScreen - 2, true);
|
2006-02-18 22:55:58 +01:00
|
|
|
scrollBar->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::SetColumnWidths() {
|
2011-10-01 20:35:06 +02:00
|
|
|
int w, h;
|
2013-09-16 21:02:17 +02:00
|
|
|
GetClientSize(&w, &h);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
2013-09-18 17:31:26 +02:00
|
|
|
int labelLen = dc.GetTextExtent(std::to_wstring(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)
|
2013-01-04 16:01:50 +01:00
|
|
|
startLen = endLen = dc.GetTextExtent(to_wx(AssTime().GetAssFormated())).GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2013-09-16 19:43:21 +02:00
|
|
|
std::unordered_map<boost::flyweight<std::string>, int> widths;
|
|
|
|
auto get_width = [&](boost::flyweight<std::string> const& str) -> int {
|
|
|
|
auto it = widths.find(str);
|
|
|
|
if (it != end(widths)) return it->second;
|
|
|
|
int width = dc.GetTextExtent(to_wx(str)).GetWidth();
|
|
|
|
widths[str] = width;
|
|
|
|
return width;
|
|
|
|
};
|
|
|
|
|
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);
|
2013-09-16 19:43:21 +02:00
|
|
|
actorLen = std::max(actorLen, get_width(curDiag->Actor));
|
|
|
|
styleLen = std::max(styleLen, get_width(curDiag->Style));
|
|
|
|
effectLen = std::max(effectLen, get_width(curDiag->Effect));
|
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
|
2013-09-18 17:31:26 +02:00
|
|
|
int layerLen = maxLayer ? dc.GetTextExtent(std::to_wstring(maxLayer)).GetWidth() : 0;
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish times
|
|
|
|
if (byFrame) {
|
2013-09-18 17:31:26 +02:00
|
|
|
startLen = dc.GetTextExtent(std::to_wstring(maxStart)).GetWidth();
|
|
|
|
endLen = dc.GetTextExtent(std::to_wstring(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
|
2013-09-16 21:02:17 +02:00
|
|
|
for (size_t i = 0; i < boost::size(showCol); ++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);
|
2013-09-16 19:26:41 +02:00
|
|
|
colWidth[10] = std::max(w - total, 0);
|
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 {
|
2013-11-21 18:13:36 +01:00
|
|
|
if (static_cast<size_t>(n) >= index_line_map.size()) return nullptr;
|
2010-06-26 09:26:27 +02:00
|
|
|
return index_line_map[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
int BaseGrid::GetDialogueIndex(AssDialogue *diag) const {
|
2013-09-16 21:02:17 +02:00
|
|
|
auto it = line_index_map.find(diag);
|
|
|
|
return it != line_index_map.end() ? it->second : -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();
|
2013-09-16 21:02:17 +02:00
|
|
|
return 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;
|
2013-09-16 21:02:17 +02:00
|
|
|
GetClientSize(&w, &h);
|
2006-02-22 04:38:23 +01:00
|
|
|
|
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
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
MakeRowVisible(next);
|
2012-04-27 21:07:49 +02:00
|
|
|
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) {
|
2013-11-21 18:13:36 +01:00
|
|
|
assert(new_line == nullptr || line_index_map.count(new_line));
|
2010-06-26 13:32:16 +02:00
|
|
|
active_line = new_line;
|
|
|
|
AnnounceActiveLineChanged(active_line);
|
2013-09-16 21:02:17 +02:00
|
|
|
MakeRowVisible(GetDialogueIndex(active_line));
|
2010-06-26 13:32:16 +02:00
|
|
|
Refresh(false);
|
|
|
|
}
|
2014-02-02 05:27:41 +01:00
|
|
|
// extendRow may not equal the active row if it was set via a shift-click,
|
|
|
|
// so update it even if the active line didn't change
|
|
|
|
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());
|
2013-12-12 00:11:06 +01:00
|
|
|
if (AssDialogue *prev_line = GetDialogue(cur_line_i-1))
|
|
|
|
SetSelectionAndActive({ prev_line }, prev_line);
|
2010-06-26 13:32:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::NextLine() {
|
|
|
|
int cur_line_i = GetDialogueIndex(GetActiveLine());
|
2013-12-12 00:11:06 +01:00
|
|
|
if (AssDialogue *next_line = GetDialogue(cur_line_i+1))
|
|
|
|
SetSelectionAndActive({ next_line }, next_line);
|
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
|
|
|
}
|
|
|
|
}
|