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/
|
|
|
|
|
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"
|
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"
|
2014-04-18 19:02:08 +02:00
|
|
|
#include "grid_column.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2014-03-25 01:15:14 +01:00
|
|
|
#include "selection_controller.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"
|
2014-04-18 19:02:08 +02:00
|
|
|
|
|
|
|
#include <libaegisub/util.h>
|
2006-02-18 22:55:58 +01:00
|
|
|
|
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 <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>
|
|
|
|
|
2014-05-12 17:02:56 +02:00
|
|
|
namespace {
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
class PaintDC : public wxBufferedDC {
|
|
|
|
wxPaintDC dc;
|
|
|
|
|
|
|
|
public:
|
|
|
|
PaintDC(wxWindow *window) : dc(window) {
|
|
|
|
dc.SetLayoutDirection(wxLayout_LeftToRight);
|
|
|
|
Init(&dc, window->GetClientSize(), 0);
|
|
|
|
if (window->GetLayoutDirection() == wxLayout_RightToLeft) {
|
|
|
|
SetLayoutDirection(wxLayout_RightToLeft);
|
|
|
|
SetLogicalOrigin(GetSize().GetWidth(), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~PaintDC() {
|
|
|
|
SetLayoutDirection(wxLayout_LeftToRight);
|
|
|
|
SetLogicalOrigin(0, 0);
|
|
|
|
UnMask();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear() {
|
|
|
|
auto origin = GetLogicalOrigin();
|
|
|
|
SetLogicalOrigin(0, 0);
|
|
|
|
wxBufferedDC::Clear();
|
|
|
|
SetLogicalOrigin(origin.x, origin.y);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
typedef wxAutoBufferedPaintDC PaintDC;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context)
|
|
|
|
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxSUNKEN_BORDER)
|
2011-07-16 07:01:36 +02:00
|
|
|
, scrollBar(new wxScrollBar(this, GRID_SCROLLBAR, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL))
|
2014-04-19 16:03:36 +02:00
|
|
|
, context(context)
|
2014-04-18 19:02:08 +02:00
|
|
|
, columns(GetGridColumns())
|
2014-04-21 16:50:19 +02:00
|
|
|
, columns_visible(OPT_GET("Subtitle/Grid/Column")->GetListBool())
|
2014-04-18 19:02:08 +02:00
|
|
|
, seek_listener(context->videoController->AddSeekListener([&] { Refresh(false); }))
|
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);
|
|
|
|
|
2014-04-21 16:50:19 +02:00
|
|
|
for (size_t i : agi::util::range(std::min(columns_visible.size(), columns.size()))) {
|
|
|
|
if (!columns_visible[i])
|
|
|
|
columns[i]->SetVisible(false);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
connections.push_back(context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, this));
|
|
|
|
connections.push_back(context->subsController->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, this));
|
|
|
|
connections.push_back(context->subsController->AddFileSaveListener(&BaseGrid::OnSubtitlesSave, this));
|
|
|
|
|
|
|
|
connections.push_back(context->selectionController->AddActiveLineListener(&BaseGrid::OnActiveLineChanged, this));
|
|
|
|
connections.push_back(context->selectionController->AddSelectionListener([&]{ Refresh(false); }));
|
|
|
|
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Font Face", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Font Size", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Active Border", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Background", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Comment", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Inframe", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Selection", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Collision", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Header", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Left Column", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Lines", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Selection", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Standard", &BaseGrid::UpdateStyle, this));
|
|
|
|
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &BaseGrid::OnHighlightVisibleChange, this));
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Hide Overrides", [&](agi::OptionValue const&) { Refresh(false); }));
|
2011-08-31 06:17:37 +02:00
|
|
|
|
|
|
|
Bind(wxEVT_CONTEXT_MENU, &BaseGrid::OnContextMenu, this);
|
2007-01-04 00:29:03 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 02:36:02 +01:00
|
|
|
BaseGrid::~BaseGrid() { }
|
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) {
|
2014-03-05 02:36:02 +01:00
|
|
|
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_ORDER || type & AssFile::COMMIT_DIAG_ADDREM)
|
|
|
|
UpdateMaps();
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
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);
|
2014-04-18 03:22:07 +02:00
|
|
|
else if (type & AssFile::COMMIT_DIAG_TEXT) {
|
2014-04-18 19:02:08 +02:00
|
|
|
for (auto const& rect : text_refresh_rects)
|
|
|
|
RefreshRect(rect, false);
|
2014-04-18 03:22:07 +02:00
|
|
|
}
|
2011-11-08 01:24:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnSubtitlesOpen() {
|
2013-10-08 02:42:09 +02:00
|
|
|
ScrollTo(context->ass->GetUIStateAsInt("Scroll Position"));
|
2011-11-08 01:24:41 +01:00
|
|
|
}
|
|
|
|
|
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));
|
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;
|
2014-04-21 16:50:19 +02:00
|
|
|
bool new_value = !columns_visible[item];
|
2011-11-08 01:24:41 +01:00
|
|
|
|
2014-04-21 20:01:39 +02:00
|
|
|
columns_visible.resize(columns.size(), true);
|
2014-04-21 16:50:19 +02:00
|
|
|
columns_visible[item] = new_value;
|
|
|
|
OPT_SET("Subtitle/Grid/Column")->SetListBool(columns_visible);
|
|
|
|
columns[item]->SetVisible(new_value);
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
SetColumnWidths();
|
2014-04-21 16:50:19 +02:00
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
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);
|
|
|
|
|
2014-04-18 02:57:29 +02:00
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.SetFont(font);
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set line height
|
2014-04-21 04:31:08 +02:00
|
|
|
lineHeight = dc.GetCharHeight() + 4;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2012-01-31 01:43:15 +01:00
|
|
|
// Set row brushes
|
2014-04-18 16:17:38 +02:00
|
|
|
row_colors.Default.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColor()));
|
|
|
|
row_colors.Header.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Header")->GetColor()));
|
|
|
|
row_colors.Selection.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
|
|
|
|
row_colors.Comment.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColor()));
|
|
|
|
row_colors.Visible.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColor()));
|
|
|
|
row_colors.SelectedComment.SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColor()));
|
|
|
|
row_colors.LeftCol.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
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-03-05 02:36:02 +01:00
|
|
|
void BaseGrid::UpdateMaps() {
|
2010-07-13 07:29:08 +02:00
|
|
|
index_line_map.clear();
|
|
|
|
|
2014-03-31 16:41:57 +02:00
|
|
|
for (auto& curdiag : context->ass->Events)
|
2014-03-07 19:58:51 +01:00
|
|
|
index_line_map.push_back(&curdiag);
|
2010-07-13 07:29:08 +02:00
|
|
|
|
2011-10-23 19:00:26 +02:00
|
|
|
SetColumnWidths();
|
2014-03-28 02:49:16 +01:00
|
|
|
AdjustScrollbar();
|
2010-07-13 07:29:08 +02:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
void BaseGrid::OnActiveLineChanged(AssDialogue *new_active) {
|
|
|
|
if (new_active) {
|
2014-03-31 16:41:57 +02:00
|
|
|
int row = new_active->Row;
|
2014-03-25 01:15:14 +01:00
|
|
|
MakeRowVisible(row);
|
|
|
|
extendRow = row;
|
|
|
|
Refresh(false);
|
2010-06-26 17:40:10 +02:00
|
|
|
}
|
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) {
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetSelectedSet(Selection{line});
|
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
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
bool selected = !!context->selectionController->GetSelectedSet().count(line);
|
|
|
|
if (select != selected) {
|
|
|
|
auto selection = context->selectionController->GetSelectedSet();
|
|
|
|
if (select)
|
|
|
|
selection.insert(line);
|
|
|
|
else
|
|
|
|
selection.erase(line);
|
|
|
|
context->selectionController->SetSelectedSet(std::move(selection));
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
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-12-22 22:09:31 +01:00
|
|
|
void BaseGrid::OnPaint(wxPaintEvent &) {
|
2011-08-27 08:52:42 +02:00
|
|
|
// Find which columns need to be repainted
|
2014-04-21 16:50:19 +02:00
|
|
|
std::vector<char> paint_columns;
|
|
|
|
paint_columns.resize(columns.size(), false);
|
|
|
|
bool any = false;
|
2013-09-16 21:02:17 +02:00
|
|
|
for (wxRegionIterator region(GetUpdateRegion()); region; ++region) {
|
2011-08-27 08:52:42 +02:00
|
|
|
wxRect updrect = region.GetRect();
|
|
|
|
int x = 0;
|
2014-04-18 19:02:08 +02:00
|
|
|
for (size_t i : agi::util::range(columns.size())) {
|
2014-04-21 16:50:19 +02:00
|
|
|
int width = columns[i]->Width();
|
|
|
|
if (width && updrect.x < x + width && updrect.x + updrect.width > x) {
|
|
|
|
paint_columns[i] = true;
|
|
|
|
any = true;
|
|
|
|
}
|
|
|
|
x += width;
|
2011-08-27 08:52:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-21 16:50:19 +02:00
|
|
|
if (!any) return;
|
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-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
|
|
|
|
2014-05-12 17:02:56 +02:00
|
|
|
PaintDC dc(this);
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.SetFont(font);
|
|
|
|
|
2014-04-18 16:17:38 +02:00
|
|
|
dc.SetBackground(row_colors.Default);
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
// Draw labels
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2014-04-18 16:17:38 +02:00
|
|
|
dc.SetBrush(row_colors.LeftCol);
|
2014-04-21 16:50:19 +02:00
|
|
|
dc.DrawRectangle(0, lineHeight, columns[0]->Width(), h-lineHeight);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-04-18 19:02:08 +02:00
|
|
|
auto paint_text = [&](wxString const& str, int x, int y, int col) {
|
|
|
|
int left = x + 4;
|
2014-04-21 04:31:08 +02:00
|
|
|
if (columns[col]->Centered()) {
|
|
|
|
wxSize ext = dc.GetTextExtent(str);
|
2014-04-21 16:50:19 +02:00
|
|
|
left += (columns[col]->Width() - 6 - ext.GetWidth()) / 2;
|
2014-04-21 04:31:08 +02:00
|
|
|
}
|
2014-04-18 19:02:08 +02:00
|
|
|
|
2014-04-21 04:31:08 +02:00
|
|
|
dc.DrawText(str, left, y + 2);
|
2014-04-18 19:02:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Paint header
|
|
|
|
{
|
|
|
|
dc.SetTextForeground(text_standard);
|
|
|
|
dc.SetBrush(row_colors.Header);
|
|
|
|
dc.DrawRectangle(0, 0, w, lineHeight);
|
|
|
|
|
|
|
|
int x = 0;
|
|
|
|
for (size_t i : agi::util::range(columns.size())) {
|
|
|
|
if (paint_columns[i])
|
|
|
|
paint_text(columns[i]->Header(), x, 0, i);
|
2014-04-21 16:50:19 +02:00
|
|
|
x += columns[i]->Width();
|
2014-04-18 19:02:08 +02:00
|
|
|
}
|
2011-08-27 08:52:42 +02:00
|
|
|
|
2014-04-18 19:02:08 +02:00
|
|
|
dc.SetPen(grid_pen);
|
|
|
|
dc.DrawLine(0, lineHeight, w, lineHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Paint the rows
|
2014-04-21 16:50:19 +02:00
|
|
|
const int drawPerScreen = h/lineHeight + 1;
|
|
|
|
const int nDraw = mid(0, drawPerScreen, GetRows() - yPos);
|
|
|
|
const int grid_x = columns[0]->Width();
|
2012-01-31 01:43:32 +01:00
|
|
|
|
2014-04-21 16:50:19 +02:00
|
|
|
const auto active_line = context->selectionController->GetActiveLine();
|
2014-03-25 01:15:14 +01:00
|
|
|
auto const& selection = context->selectionController->GetSelectedSet();
|
|
|
|
|
2014-04-18 19:02:08 +02:00
|
|
|
for (int i : agi::util::range(nDraw)) {
|
|
|
|
wxBrush color = row_colors.Default;
|
|
|
|
AssDialogue *curDiag = index_line_map[i + yPos];
|
|
|
|
|
|
|
|
bool inSel = !!selection.count(curDiag);
|
|
|
|
if (inSel && curDiag->Comment)
|
|
|
|
color = row_colors.SelectedComment;
|
|
|
|
else if (inSel)
|
|
|
|
color = row_colors.Selection;
|
|
|
|
else if (curDiag->Comment)
|
|
|
|
color = row_colors.Comment;
|
|
|
|
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag))
|
|
|
|
color = row_colors.Visible;
|
2014-04-21 19:47:20 +02:00
|
|
|
dc.SetBrush(color);
|
2014-04-18 19:02:08 +02:00
|
|
|
|
2014-04-21 16:50:19 +02:00
|
|
|
// Draw row background color
|
|
|
|
if (color != row_colors.Default) {
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
|
|
|
dc.DrawRectangle(grid_x, (i + 1) * lineHeight + 1, w, lineHeight);
|
|
|
|
}
|
|
|
|
|
2014-04-18 19:02:08 +02:00
|
|
|
if (active_line != curDiag && curDiag->CollidesWith(active_line))
|
|
|
|
dc.SetTextForeground(text_collision);
|
|
|
|
else if (inSel)
|
|
|
|
dc.SetTextForeground(text_selection);
|
|
|
|
else
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_standard);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// Draw text
|
2014-04-18 19:02:08 +02:00
|
|
|
int x = 0;
|
|
|
|
int y = (i + 1) * lineHeight;
|
|
|
|
for (size_t j : agi::util::range(columns.size())) {
|
|
|
|
if (paint_columns[j])
|
2014-04-21 19:47:20 +02:00
|
|
|
columns[j]->Paint(dc, x, y, curDiag, context);
|
2014-04-21 16:50:19 +02:00
|
|
|
x += columns[j]->Width();
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw grid
|
2014-04-21 04:39:48 +02:00
|
|
|
dc.SetPen(grid_pen);
|
|
|
|
dc.DrawLine(0, y + lineHeight, w , y + lineHeight);
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw grid columns
|
2014-04-18 19:02:08 +02:00
|
|
|
{
|
|
|
|
int maxH = (nDraw + 1) * lineHeight;
|
|
|
|
int x = 0;
|
|
|
|
dc.SetPen(grid_pen);
|
2014-04-21 16:50:19 +02:00
|
|
|
for (auto const& column : columns) {
|
|
|
|
x += column->Width();
|
2014-04-18 19:02:08 +02:00
|
|
|
if (x < w)
|
|
|
|
dc.DrawLine(x, 0, x, maxH);
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
2014-04-18 19:02:08 +02:00
|
|
|
dc.DrawLine(0, 0, 0, maxH);
|
2014-04-21 16:50:19 +02:00
|
|
|
dc.DrawLine(w, 0, w, maxH);
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
2014-04-21 16:50:19 +02:00
|
|
|
|
2014-04-21 04:39:48 +02:00
|
|
|
if (active_line && active_line->Row >= yPos && active_line->Row < yPos + nDraw) {
|
|
|
|
dc.SetPen(wxPen(to_wx(OPT_GET("Colour/Subtitle Grid/Active Border")->GetColor())));
|
|
|
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
dc.DrawRectangle(0, (active_line->Row - yPos + 1) * lineHeight, w, lineHeight + 1);
|
|
|
|
}
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void BaseGrid::OnSize(wxSizeEvent &) {
|
2006-02-18 22:55:58 +01:00
|
|
|
AdjustScrollbar();
|
|
|
|
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;
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetActiveLine(dlg);
|
2012-05-04 04:52:52 +02:00
|
|
|
ScrollTo(old_y_pos);
|
2014-03-25 01:15:14 +01:00
|
|
|
extendRow = row;
|
|
|
|
|
|
|
|
auto const& selection = context->selectionController->GetSelectedSet();
|
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));
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetSelectedSet(std::move(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 {
|
|
|
|
wxMenu menu;
|
2014-04-18 19:02:08 +02:00
|
|
|
for (size_t i : agi::util::range(columns.size())) {
|
|
|
|
if (columns[i]->CanHide())
|
2014-04-21 16:50:19 +02:00
|
|
|
menu.Append(MENU_SHOW_COL + i, columns[i]->Description(), "", wxITEM_CHECK)->Check(columns[i]->Visible());
|
2014-04-18 19:02:08 +02:00
|
|
|
}
|
2011-11-08 01:24:41 +01:00
|
|
|
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);
|
|
|
|
|
2014-04-18 19:02:08 +02:00
|
|
|
text_refresh_rects.clear();
|
|
|
|
int x = 0;
|
2014-04-21 16:50:19 +02:00
|
|
|
|
|
|
|
WidthHelper helper{dc, std::unordered_map<boost::flyweight<std::string>, int>{}};
|
|
|
|
for (auto const& column : columns) {
|
|
|
|
column->UpdateWidth(context, helper);
|
|
|
|
if (column->Width() && column->RefreshOnTextChange())
|
|
|
|
text_refresh_rects.emplace_back(x, 0, column->Width(), h);
|
|
|
|
x += column->Width();
|
2006-06-27 07:13:41 +02:00
|
|
|
}
|
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];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2014-03-31 16:41:57 +02:00
|
|
|
auto active_line = context->selectionController->GetActiveLine();
|
2012-04-27 21:07:49 +02:00
|
|
|
int old_extend = extendRow;
|
2014-03-31 16:41:57 +02:00
|
|
|
int next = mid(0, (active_line ? active_line->Row : 0) + dir * step, GetRows() - 1);
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->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
|
2014-03-25 01:15:14 +01:00
|
|
|
if (alt && !shift && !ctrl)
|
2012-04-27 21:07:49 +02:00
|
|
|
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
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetSelectedSet(std::move(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;
|
2014-04-19 15:57:17 +02:00
|
|
|
for (auto& column : columns)
|
|
|
|
column->SetByFrame(byFrame);
|
2006-02-22 05:59:39 +01:00
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|