2006-02-18 22:55:58 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-02-18 22:55:58 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file base_grid.h
|
|
|
|
/// @see base_grid.cpp
|
|
|
|
/// @ingroup main_ui
|
|
|
|
///
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
|
2010-05-26 09:17:39 +02:00
|
|
|
#pragma once
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-08-03 00:14:11 +02:00
|
|
|
#include <map>
|
2006-02-18 22:55:58 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#include <wx/grid.h>
|
|
|
|
#include <wx/scrolbar.h>
|
|
|
|
#endif
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
#include <libaegisub/signal.h>
|
|
|
|
|
2010-06-25 03:49:12 +02:00
|
|
|
#include "selection_controller.h"
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
namespace agi {
|
|
|
|
struct Context;
|
|
|
|
class OptionValue;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
class AssDialogue;
|
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
|
|
|
|
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
|
|
|
typedef SelectionController<AssDialogue> SubtitleSelectionController;
|
|
|
|
typedef SelectionListener<AssDialogue> SubtitleSelectionListener;
|
2006-02-18 22:55:58 +01: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
|
|
|
|
|
|
|
/// DOCME
|
|
|
|
/// @class BaseGrid
|
|
|
|
/// @brief DOCME
|
|
|
|
///
|
|
|
|
/// DOCME
|
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
|
|
|
class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
|
2011-07-15 06:05:43 +02:00
|
|
|
int lineHeight; ///< Height of a line in pixels in the current font
|
|
|
|
int lastRow; ///< ?
|
|
|
|
bool holding; ///< Is a drag selection in process?
|
|
|
|
wxFont font; ///< Current grid font
|
|
|
|
wxScrollBar *scrollBar; ///< The grid's scrollbar
|
|
|
|
wxBitmap *bmp; ///< Back buffer which the grid is rendered into
|
|
|
|
bool byFrame; ///< Should times be displayed as frame numbers
|
|
|
|
/// Row from which the selection shrinks/grows from when selecting via the
|
|
|
|
/// keyboard. Equal to the active row except for when using shift+up/down.
|
2006-02-22 03:25:45 +01:00
|
|
|
int extendRow;
|
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:43 +02:00
|
|
|
Selection selection; ///< Currently selected lines
|
|
|
|
AssDialogue *active_line; ///< The currently active line or 0 if none
|
|
|
|
std::vector<AssDialogue*> index_line_map; ///< Row number -> dialogue line
|
|
|
|
std::map<AssDialogue*,int> line_index_map; ///< Dialogue line -> row number
|
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:43 +02:00
|
|
|
/// Selection batch nesting depth; changes are commited only when this
|
|
|
|
/// hits zero
|
|
|
|
int batch_level;
|
|
|
|
/// Has the active line been changed in the current batch?
|
|
|
|
bool batch_active_line_changed;
|
|
|
|
/// Lines which will be added to the selection when the current batch is
|
|
|
|
/// completed; should be disjoint from selection
|
|
|
|
Selection batch_selection_added;
|
|
|
|
/// Lines which will be removed from the selection when the current batch
|
|
|
|
/// is completed; should be a subset of selection
|
|
|
|
Selection batch_selection_removed;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
/// Connection for video seek event. Stored explicitly so that it can be
|
|
|
|
/// blocked if the relevant option is disabled
|
|
|
|
agi::signal::Connection seek_listener;
|
|
|
|
|
|
|
|
/// Cached grid body context menu
|
|
|
|
wxMenu *context_menu;
|
|
|
|
|
2011-08-31 06:17:37 +02:00
|
|
|
void OnContextMenu(wxContextMenuEvent &evt);
|
2011-11-08 01:24:41 +01:00
|
|
|
void OnHighlightVisibleChange(agi::OptionValue const& opt);
|
|
|
|
void OnKeyDown(wxKeyEvent &event);
|
|
|
|
void OnMouseEvent(wxMouseEvent &event);
|
2006-02-18 22:55:58 +01:00
|
|
|
void OnPaint(wxPaintEvent &event);
|
|
|
|
void OnScroll(wxScrollEvent &event);
|
2011-11-08 01:24:41 +01:00
|
|
|
void OnShowColMenu(wxCommandEvent &event);
|
|
|
|
void OnSize(wxSizeEvent &event);
|
|
|
|
void OnSubtitlesCommit(int type);
|
|
|
|
void OnSubtitlesOpen();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
void DrawImage(wxDC &dc, bool paint_columns[]);
|
2011-11-08 01:24:53 +01:00
|
|
|
void GetRowStrings(int row, AssDialogue *line, bool *paint_columns, wxString *strings) const;
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void ScrollTo(int y);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
int colWidth[16]; ///< Width in pixels of each column
|
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-09-15 07:16:32 +02:00
|
|
|
int time_cols_x; ///< Left edge of the times columns
|
|
|
|
int time_cols_w; ///< Width of the two times columns
|
|
|
|
int text_col_x; ///< Left edge of the text column
|
|
|
|
int text_col_w; ///< Width of the text column
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
static const int columns = 10; ///< Total number of columns
|
|
|
|
bool showCol[columns]; ///< Column visibility mask
|
2010-07-08 06:29:04 +02:00
|
|
|
|
2006-02-19 04:10:03 +01:00
|
|
|
int yPos;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void AdjustScrollbar();
|
|
|
|
void SetColumnWidths();
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
bool IsDisplayed(const AssDialogue *line) const;
|
|
|
|
|
2010-06-26 17:40:10 +02:00
|
|
|
// Re-implement functions from BaseSelectionController to add batching
|
|
|
|
void AnnounceActiveLineChanged(AssDialogue *new_line);
|
|
|
|
void AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed);
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
protected:
|
|
|
|
agi::Context *context; ///< Current project context
|
|
|
|
|
2010-06-25 03:49:12 +02:00
|
|
|
public:
|
|
|
|
// SelectionController implementation
|
2011-07-15 06:05:43 +02:00
|
|
|
void SetActiveLine(AssDialogue *new_line);
|
|
|
|
AssDialogue * GetActiveLine() const { return active_line; }
|
|
|
|
void SetSelectedSet(const Selection &new_selection);
|
|
|
|
void GetSelectedSet(Selection &res) const { res = selection; }
|
|
|
|
Selection const& GetSelectedSet() const { return selection; }
|
|
|
|
void NextLine();
|
|
|
|
void PrevLine();
|
2010-06-25 03:49:12 +02:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
void BeginBatch();
|
|
|
|
void EndBatch();
|
2011-07-15 06:05:43 +02:00
|
|
|
void SetByFrame(bool state);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void SelectRow(int row, bool addToSelected = false, bool select=true);
|
2010-05-26 09:17:34 +02:00
|
|
|
int GetFirstSelRow() const;
|
2011-07-15 06:05:22 +02:00
|
|
|
wxArrayInt GetSelection() const;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2010-06-26 09:26:27 +02:00
|
|
|
void ClearMaps();
|
2010-07-13 07:29:08 +02:00
|
|
|
/// @brief Update the row <-> AssDialogue mappings
|
|
|
|
/// @param preserve_selected_rows Try to keep the same rows selected rather
|
|
|
|
/// rather than the same lines
|
|
|
|
void UpdateMaps(bool preserve_selected_rows = false);
|
2007-01-04 00:29:03 +01:00
|
|
|
void UpdateStyle();
|
2006-02-22 06:30:09 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
int GetRows() const { return index_line_map.size(); }
|
2006-02-22 05:59:39 +01:00
|
|
|
void MakeCellVisible(int row, int col,bool center=true);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
/// @brief Get dialogue by index
|
|
|
|
/// @param n Index to look up
|
|
|
|
/// @return Subtitle dialogue line for index, or 0 if invalid index
|
2010-05-26 09:17:34 +02:00
|
|
|
AssDialogue *GetDialogue(int n) const;
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
/// @brief Get index by dialogue line
|
|
|
|
/// @param diag Dialogue line to look up
|
|
|
|
/// @return Subtitle index for object, or -1 if unknown subtitle
|
2010-06-26 09:26:27 +02:00
|
|
|
int GetDialogueIndex(AssDialogue *diag) const;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);
|
2006-02-18 22:55:58 +01:00
|
|
|
~BaseGrid();
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|