2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, Rodrigo Braz Monteiro
2010-07-20 05:11:11 +02:00
// Copyright (c) 2010, Thomas Goyne <plorkyeran@aegisub.org>
2006-01-16 22:02:54 +01:00
// 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-01-16 22:02:54 +01:00
//
2009-07-29 07:43:02 +02:00
// $Id$
/// @file subs_edit_box.cpp
/// @brief Main subtitle editing area, including toolbars around the text control
/// @ingroup main_ui
2006-01-16 22:02:54 +01:00
2009-01-04 07:31:48 +01:00
# include "config.h"
2009-09-10 15:06:40 +02:00
# ifndef AGI_PRE
2010-07-20 05:11:11 +02:00
# include <tr1/functional>
# include <wx/button.h>
# include <wx/checkbox.h>
2006-12-24 05:54:35 +01:00
# include <wx/colordlg.h>
2010-07-20 05:11:11 +02:00
# include <wx/combobox.h>
# include <wx/dcclient.h>
# include <wx/dcmemory.h>
2006-12-24 05:54:35 +01:00
# include <wx/fontdlg.h>
2010-07-20 05:11:11 +02:00
# include <wx/radiobut.h>
# include <wx/spinctrl.h>
2009-09-10 15:06:40 +02:00
# endif
2012-01-14 02:40:21 +01:00
# include "subs_edit_box.h"
Merge the dynamic menu, hotkey and toolbar branch to trunk. This doesn't include Windows support as vs2008 was being a major pain. This involves revisions r4921:4950, r4961:5002, r5005:5006, r5008:5056, r5062:5065, r5072, r5081:5082, r5087, r5096:5110, r5124:5125. Updates #1258.
Originally committed to SVN as r5126.
2011-01-05 14:00:46 +01:00
2006-01-16 22:02:54 +01:00
# include "ass_dialogue.h"
2009-09-10 15:06:40 +02:00
# include "ass_file.h"
2006-01-16 22:02:54 +01:00
# include "ass_override.h"
2009-09-10 15:06:40 +02:00
# include "ass_style.h"
2012-01-14 02:40:21 +01:00
# include "command/command.h"
2006-01-16 22:02:54 +01:00
# include "dialog_colorpicker.h"
2006-03-05 21:42:38 +01:00
# include "dialog_search_replace.h"
2011-01-16 08:17:36 +01:00
# include "include/aegisub/context.h"
2012-01-14 02:40:21 +01:00
# include "include/aegisub/hotkey.h"
2009-07-24 02:08:25 +02:00
# include "libresrc/libresrc.h"
2009-09-10 15:06:40 +02:00
# include "main.h"
2012-01-20 06:14:50 +01:00
# include "placeholder_ctrl.h"
2010-07-20 05:11:11 +02:00
# include "subs_edit_ctrl.h"
2009-09-10 15:06:40 +02:00
# include "subs_grid.h"
# include "timeedit_ctrl.h"
# include "tooltip_manager.h"
# include "utils.h"
# include "validators.h"
# include "video_context.h"
2006-01-16 22:02:54 +01:00
2012-01-20 06:14:44 +01:00
namespace {
2010-07-20 05:11:11 +02:00
template < class T >
struct field_setter : public std : : binary_function < AssDialogue * , T , void > {
T AssDialogue : : * field ;
field_setter ( T AssDialogue : : * field ) : field ( field ) { }
void operator ( ) ( AssDialogue * obj , T value ) {
obj - > * field = value ;
}
} ;
/// @brief Get the selection from a text edit
2012-01-20 06:14:44 +01:00
/// @return Pair of selection start and end positions
std : : pair < int , int > get_selection ( SubsTextEditCtrl * TextEdit ) {
int start , end ;
2010-07-20 05:11:11 +02:00
TextEdit - > GetSelection ( & start , & end ) ;
int len = TextEdit - > GetText ( ) . size ( ) ;
2012-01-20 06:14:44 +01:00
return std : : make_pair (
mid ( 0 , TextEdit - > GetReverseUnicodePosition ( start ) , len ) ,
mid ( 0 , TextEdit - > GetReverseUnicodePosition ( end ) , len ) ) ;
2010-07-20 05:11:11 +02:00
}
/// @brief Get the value of a tag at a specified position in a line
/// @param line Line to get the value from
/// @param blockn Block number in the line
/// @param initial Value from style to use if the tag does not exist
/// @param tag Tag to get the value of
/// @param alt Alternate name of the tag, if any
template < class T >
2012-01-31 01:44:43 +01:00
static T get_value ( AssDialogue const & line , int blockn , T initial , wxString tag , wxString alt = wxString ( ) ) {
2010-07-20 05:11:11 +02:00
for ( int i = blockn ; i > = 0 ; i - - ) {
AssDialogueBlockOverride * ovr = dynamic_cast < AssDialogueBlockOverride * > ( line . Blocks [ i ] ) ;
2010-10-08 08:06:44 +02:00
if ( ! ovr ) continue ;
for ( int j = ( int ) ovr - > Tags . size ( ) - 1 ; j > = 0 ; j - - ) {
if ( ovr - > Tags [ j ] - > Name = = tag | | ovr - > Tags [ j ] - > Name = = alt ) {
return ovr - > Tags [ j ] - > Params [ 0 ] - > Get < T > ( initial ) ;
2010-07-20 05:11:11 +02:00
}
}
}
return initial ;
}
2012-01-20 06:14:44 +01:00
/// Get the block index in the text of the position
int block_at_pos ( wxString const & text , int pos ) {
int n = 0 ;
int max = text . size ( ) - 1 ;
for ( int i = 0 ; i < = pos & & i < = max ; + + i ) {
if ( i > 0 & & text [ i ] = = ' { ' )
n + + ;
if ( text [ i ] = = ' } ' & & i ! = max & & i ! = pos & & i ! = pos - 1 & & ( i + 1 = = max | | text [ i + 1 ] ! = ' { ' ) )
n + + ;
}
return n ;
}
/// Work around wxGTK's fondness for generating events from ChangeValue
void change_value ( wxTextCtrl * ctrl , wxString const & value ) {
if ( value ! = ctrl - > GetValue ( ) )
ctrl - > ChangeValue ( value ) ;
}
}
2011-01-16 08:17:36 +01:00
SubsEditBox : : SubsEditBox ( wxWindow * parent , agi : : Context * context )
2010-07-20 05:11:11 +02:00
: wxPanel ( parent , - 1 , wxDefaultPosition , wxDefaultSize , wxTAB_TRAVERSAL | wxRAISED_BORDER , " SubsEditBox " )
2012-01-20 06:14:44 +01:00
, line ( 0 )
, splitLineMode ( true )
2010-07-20 05:11:11 +02:00
, controlState ( true )
2011-01-16 08:17:36 +01:00
, c ( context )
2011-12-22 22:31:09 +01:00
, commitId ( - 1 )
, undoTimer ( GetEventHandler ( ) )
2006-01-16 22:02:54 +01:00
{
2012-01-20 06:14:44 +01:00
using std : : tr1 : : bind ;
2006-01-16 22:02:54 +01:00
// Top controls
2012-01-20 06:14:44 +01:00
TopSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2010-07-20 05:11:11 +02:00
2012-01-20 06:14:44 +01:00
CommentBox = new wxCheckBox ( this , - 1 , _ ( " &Comment " ) ) ;
CommentBox - > SetToolTip ( _ ( " Comment this line out. Commented lines don't show up on screen. " ) ) ;
TopSizer - > Add ( CommentBox , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
2010-07-20 05:11:11 +02:00
2012-02-07 02:22:32 +01:00
StyleBox = MakeComboBox ( " Default " , wxCB_READONLY , & SubsEditBox : : OnStyleChange , _ ( " Style for this line " ) ) ;
2010-07-20 05:11:11 +02:00
2012-01-20 06:14:50 +01:00
ActorBox = new Placeholder < wxComboBox > ( this , " Actor " , wxSize ( 110 , - 1 ) , wxCB_DROPDOWN | wxTE_PROCESS_ENTER , _ ( " Actor name for this speech. This is only for reference, and is mainly useless. " ) ) ;
Bind ( wxEVT_COMMAND_TEXT_UPDATED , & SubsEditBox : : OnActorChange , this , ActorBox - > GetId ( ) ) ;
Bind ( wxEVT_COMMAND_COMBOBOX_SELECTED , & SubsEditBox : : OnActorChange , this , ActorBox - > GetId ( ) ) ;
TopSizer - > Add ( ActorBox , wxSizerFlags ( 2 ) . Center ( ) . Border ( wxRIGHT ) ) ;
Effect = new Placeholder < wxTextCtrl > ( this , " Effect " , wxSize ( 80 , - 1 ) , wxTE_PROCESS_ENTER , _ ( " Effect for this line. This can be used to store extra information for karaoke scripts, or for the effects supported by the renderer. " ) ) ;
Bind ( wxEVT_COMMAND_TEXT_UPDATED , & SubsEditBox : : OnEffectChange , this , Effect - > GetId ( ) ) ;
2012-01-20 06:14:44 +01:00
TopSizer - > Add ( Effect , 3 , wxALIGN_CENTER , 5 ) ;
2006-06-27 06:13:34 +02:00
2012-01-20 06:14:44 +01:00
// Middle controls
2006-12-27 01:00:41 +01:00
MiddleSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2012-01-20 06:14:44 +01:00
2012-01-27 20:23:35 +01:00
Layer = new wxSpinCtrl ( this , - 1 , " " , wxDefaultPosition , wxSize ( 50 , - 1 ) , wxSP_ARROW_KEYS | wxTE_PROCESS_ENTER , 0 , 0x7FFFFFFF , 0 ) ;
2012-01-20 06:14:44 +01:00
Layer - > SetToolTip ( _ ( " Layer number " ) ) ;
MiddleSizer - > Add ( Layer , wxSizerFlags ( ) . Center ( ) ) ;
2006-12-27 01:00:41 +01:00
MiddleSizer - > AddSpacer ( 5 ) ;
2006-01-16 22:02:54 +01:00
2012-01-20 06:14:44 +01:00
StartTime = MakeTimeCtrl ( false , _ ( " Start time " ) , & SubsEditBox : : OnStartTimeChange ) ;
2012-01-22 19:18:00 +01:00
EndTime = MakeTimeCtrl ( true , _ ( " End time " ) , & SubsEditBox : : OnEndTimeChange ) ;
2012-01-20 06:14:44 +01:00
MiddleSizer - > AddSpacer ( 5 ) ;
2012-01-22 19:18:00 +01:00
Duration = MakeTimeCtrl ( false , _ ( " Line duration " ) , & SubsEditBox : : OnDurationChange ) ;
2012-01-20 06:14:44 +01:00
MiddleSizer - > AddSpacer ( 5 ) ;
MarginL = MakeMarginCtrl ( _ ( " Left Margin (0 = default) " ) , & SubsEditBox : : OnMarginLChange ) ;
MarginR = MakeMarginCtrl ( _ ( " Right Margin (0 = default) " ) , & SubsEditBox : : OnMarginRChange ) ;
MarginV = MakeMarginCtrl ( _ ( " Vertical Margin (0 = default) " ) , & SubsEditBox : : OnMarginVChange ) ;
MiddleSizer - > AddSpacer ( 5 ) ;
// Middle-bottom controls
2006-12-27 01:00:41 +01:00
MiddleBotSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2012-01-20 06:14:44 +01:00
MakeButton ( GETIMAGE ( button_bold_16 ) , _ ( " Bold " ) , bind ( & SubsEditBox : : OnFlagButton , this , & AssStyle : : bold , " \\ b " , _ ( " toggle bold " ) ) ) ;
MakeButton ( GETIMAGE ( button_italics_16 ) , _ ( " Italics " ) , bind ( & SubsEditBox : : OnFlagButton , this , & AssStyle : : italic , " \\ i " , _ ( " toggle italic " ) ) ) ;
MakeButton ( GETIMAGE ( button_underline_16 ) , _ ( " Underline " ) , bind ( & SubsEditBox : : OnFlagButton , this , & AssStyle : : underline , " \\ u " , _ ( " toggle underline " ) ) ) ;
MakeButton ( GETIMAGE ( button_strikeout_16 ) , _ ( " Strikeout " ) , bind ( & SubsEditBox : : OnFlagButton , this , & AssStyle : : strikeout , " \\ s " , _ ( " toggle strikeout " ) ) ) ;
MakeButton ( GETIMAGE ( button_fontname_16 ) , _ ( " Font Face " ) , bind ( & SubsEditBox : : OnFontButton , this ) ) ;
MiddleBotSizer - > AddSpacer ( 5 ) ;
MakeButton ( GETIMAGE ( button_color_one_16 ) , _ ( " Primary color " ) , bind ( & SubsEditBox : : OnColorButton , this , & AssStyle : : primary , " \\ c " , " \\ 1c " ) ) ;
MakeButton ( GETIMAGE ( button_color_two_16 ) , _ ( " Secondary color " ) , bind ( & SubsEditBox : : OnColorButton , this , & AssStyle : : secondary , " \\ 2c " , " " ) ) ;
MakeButton ( GETIMAGE ( button_color_three_16 ) , _ ( " Outline color " ) , bind ( & SubsEditBox : : OnColorButton , this , & AssStyle : : outline , " \\ 3c " , " " ) ) ;
MakeButton ( GETIMAGE ( button_color_four_16 ) , _ ( " Shadow color " ) , bind ( & SubsEditBox : : OnColorButton , this , & AssStyle : : shadow , " \\ 4c " , " " ) ) ;
MiddleBotSizer - > AddSpacer ( 5 ) ;
MakeButton ( GETIMAGE ( button_audio_commit_16 ) , _ ( " Commits the text (Enter) " ) , bind ( & cmd : : call , " grid/line/next/create " , c ) ) ;
2008-03-09 23:31:16 +01:00
MiddleBotSizer - > AddSpacer ( 10 ) ;
2012-01-20 06:14:44 +01:00
ByTime = MakeRadio ( _ ( " &Time " ) , true , _ ( " Time by h:mm:ss.cs " ) ) ;
ByFrame = MakeRadio ( _ ( " F&rame " ) , false , _ ( " Time by frame number " ) ) ;
ByFrame - > Enable ( false ) ;
2006-01-16 22:02:54 +01:00
// Text editor
2012-01-11 20:19:30 +01:00
TextEdit = new SubsTextEditCtrl ( this , wxSize ( 300 , 50 ) , wxBORDER_SUNKEN , c ) ;
2012-01-28 00:35:31 +01:00
TextEdit - > Bind ( wxEVT_KEY_DOWN , & SubsEditBox : : OnKeyDown , this ) ;
2012-01-27 20:23:35 +01:00
Bind ( wxEVT_KEY_DOWN , & SubsEditBox : : OnKeyDown , this ) ;
2006-12-27 01:00:41 +01:00
BottomSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2006-01-16 22:02:54 +01:00
BottomSizer - > Add ( TextEdit , 1 , wxEXPAND , 0 ) ;
// Main sizer
2012-01-20 06:14:44 +01:00
wxSizer * MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
2008-03-09 23:31:16 +01:00
MainSizer - > Add ( TopSizer , 0 , wxEXPAND | wxALL , 3 ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Add ( MiddleSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 3 ) ;
MainSizer - > Add ( MiddleBotSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 3 ) ;
MainSizer - > Add ( BottomSizer , 1 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 3 ) ;
2011-12-22 22:31:09 +01:00
SetSizerAndFit ( MainSizer ) ;
2006-01-16 22:02:54 +01:00
2010-07-20 05:11:11 +02:00
TextEdit - > Bind ( wxEVT_STC_MODIFIED , & SubsEditBox : : OnChange , this ) ;
2012-01-26 23:13:39 +01:00
TextEdit - > SetModEventMask ( wxSTC_MOD_INSERTTEXT | wxSTC_MOD_DELETETEXT | wxSTC_STARTACTION ) ;
2009-05-18 07:33:49 +02:00
2010-07-20 05:11:11 +02:00
Bind ( wxEVT_COMMAND_TEXT_UPDATED , & SubsEditBox : : OnLayerEnter , this , Layer - > GetId ( ) ) ;
Bind ( wxEVT_COMMAND_SPINCTRL_UPDATED , & SubsEditBox : : OnLayerChange , this , Layer - > GetId ( ) ) ;
Bind ( wxEVT_COMMAND_CHECKBOX_CLICKED , & SubsEditBox : : OnCommentChange , this , CommentBox - > GetId ( ) ) ;
2006-12-27 01:00:41 +01:00
2010-07-20 05:11:11 +02:00
Bind ( wxEVT_SIZE , & SubsEditBox : : OnSize , this ) ;
2011-12-22 22:31:09 +01:00
Bind ( wxEVT_TIMER , & SubsEditBox : : OnUndoTimer , this ) ;
2006-12-27 01:00:41 +01:00
2010-07-20 05:11:11 +02:00
wxSizeEvent evt ;
OnSize ( evt ) ;
2006-12-27 01:00:41 +01:00
2011-09-15 07:17:29 +02:00
c - > selectionController - > AddSelectionListener ( this ) ;
2011-12-28 22:27:22 +01:00
file_changed_slot = c - > ass - > AddCommitListener ( & SubsEditBox : : OnCommit , this ) ;
2011-01-16 08:17:36 +01:00
context - > videoController - > AddTimecodesListener ( & SubsEditBox : : UpdateFrameTiming , this ) ;
2010-07-20 05:11:11 +02:00
}
2012-01-20 06:14:44 +01:00
2010-07-20 05:11:11 +02:00
SubsEditBox : : ~ SubsEditBox ( ) {
2011-09-15 07:17:29 +02:00
c - > selectionController - > RemoveSelectionListener ( this ) ;
2010-07-20 05:11:11 +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
2012-01-20 06:14:44 +01:00
wxTextCtrl * SubsEditBox : : MakeMarginCtrl ( wxString const & tooltip , void ( SubsEditBox : : * handler ) ( wxCommandEvent & ) ) {
wxTextCtrl * ctrl = new wxTextCtrl ( this , - 1 , " " , wxDefaultPosition , wxSize ( 40 , - 1 ) , wxTE_CENTRE | wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
ctrl - > SetMaxLength ( 4 ) ;
ctrl - > SetToolTip ( tooltip ) ;
Bind ( wxEVT_COMMAND_TEXT_UPDATED , handler , this , ctrl - > GetId ( ) ) ;
MiddleSizer - > Add ( ctrl , wxSizerFlags ( ) . Center ( ) ) ;
return ctrl ;
}
TimeEdit * SubsEditBox : : MakeTimeCtrl ( bool end , wxString const & tooltip , void ( SubsEditBox : : * handler ) ( wxCommandEvent & ) ) {
TimeEdit * ctrl = new TimeEdit ( this , - 1 , c , " " , wxSize ( 75 , - 1 ) , end ) ;
ctrl - > SetToolTip ( tooltip ) ;
Bind ( wxEVT_COMMAND_TEXT_UPDATED , handler , this , ctrl - > GetId ( ) ) ;
MiddleSizer - > Add ( ctrl , wxSizerFlags ( ) . Center ( ) ) ;
return ctrl ;
}
template < class Handler >
void SubsEditBox : : MakeButton ( wxBitmap const & icon , wxString const & tooltip , Handler const & handler ) {
wxBitmapButton * btn = new wxBitmapButton ( this , - 1 , icon ) ;
btn - > SetToolTip ( tooltip ) ;
MiddleBotSizer - > Add ( btn , wxSizerFlags ( ) . Center ( ) . Expand ( ) ) ;
Bind ( wxEVT_COMMAND_BUTTON_CLICKED , handler , btn - > GetId ( ) ) ;
}
wxComboBox * SubsEditBox : : MakeComboBox ( wxString const & initial_text , int style , void ( SubsEditBox : : * handler ) ( wxCommandEvent & ) , wxString const & tooltip ) {
wxString styles [ ] = { " Default " } ;
wxComboBox * ctrl = new wxComboBox ( this , - 1 , initial_text , wxDefaultPosition , wxSize ( 110 , - 1 ) , 1 , styles , style | wxTE_PROCESS_ENTER ) ;
ctrl - > SetToolTip ( tooltip ) ;
TopSizer - > Add ( ctrl , wxSizerFlags ( 2 ) . Center ( ) . Border ( wxRIGHT ) ) ;
Bind ( wxEVT_COMMAND_COMBOBOX_SELECTED , handler , this , ctrl - > GetId ( ) ) ;
return ctrl ;
}
wxRadioButton * SubsEditBox : : MakeRadio ( wxString const & text , bool start , wxString const & tooltip ) {
wxRadioButton * ctrl = new wxRadioButton ( this , - 1 , text , wxDefaultPosition , wxDefaultSize , start ? wxRB_GROUP : 0 ) ;
ctrl - > SetToolTip ( tooltip ) ;
Bind ( wxEVT_COMMAND_RADIOBUTTON_SELECTED , & SubsEditBox : : OnFrameTimeRadio , this , ctrl - > GetId ( ) ) ;
MiddleBotSizer - > Add ( ctrl , wxSizerFlags ( ) . Center ( ) . Expand ( ) . Border ( wxRIGHT ) ) ;
return ctrl ;
}
2011-12-28 22:27:22 +01:00
void SubsEditBox : : OnCommit ( int type ) {
2011-12-22 22:30:32 +01:00
wxEventBlocker blocker ( this ) ;
2011-09-15 07:16:32 +02:00
if ( type = = AssFile : : COMMIT_NEW | | type & AssFile : : COMMIT_STYLES ) {
2011-12-22 22:31:29 +01:00
wxString style = StyleBox - > GetValue ( ) ;
2010-12-07 20:09:28 +01:00
StyleBox - > Clear ( ) ;
2011-01-16 08:17:36 +01:00
StyleBox - > Append ( c - > ass - > GetStyles ( ) ) ;
2011-12-22 22:31:29 +01:00
StyleBox - > Select ( StyleBox - > FindString ( style ) ) ;
2011-09-15 07:16:32 +02:00
}
2010-12-07 20:09:28 +01:00
2011-09-15 07:16:32 +02:00
if ( type = = AssFile : : COMMIT_NEW ) {
/// @todo maybe preserve selection over undo?
2011-10-19 06:05:09 +02:00
PopulateActorList ( ) ;
2010-12-07 20:09:28 +01:00
TextEdit - > SetSelection ( 0 , 0 ) ;
return ;
}
2011-11-18 05:04:35 +01:00
else if ( type & AssFile : : COMMIT_STYLES )
StyleBox - > Select ( StyleBox - > FindString ( line - > Style ) ) ;
2011-09-15 07:16:32 +02:00
if ( ! ( type ^ AssFile : : COMMIT_ORDER ) ) return ;
2010-12-07 20:09:28 +01:00
2010-07-20 05:11:11 +02:00
SetControlsState ( ! ! line ) ;
2011-12-22 22:30:32 +01:00
if ( ! line ) return ;
2010-07-20 05:11:11 +02:00
2011-09-15 07:16:32 +02:00
if ( type & AssFile : : COMMIT_DIAG_TIME ) {
StartTime - > SetTime ( line - > Start ) ;
EndTime - > SetTime ( line - > End ) ;
2011-12-22 22:30:22 +01:00
Duration - > SetTime ( line - > End - line - > Start ) ;
2011-09-15 07:16:32 +02:00
}
if ( type & AssFile : : COMMIT_DIAG_TEXT ) {
2010-07-20 05:11:11 +02:00
TextEdit - > SetTextTo ( line - > Text ) ;
2011-09-15 07:16:32 +02:00
}
if ( type & AssFile : : COMMIT_DIAG_META ) {
2010-07-20 05:11:11 +02:00
Layer - > SetValue ( line - > Layer ) ;
2012-01-20 06:14:44 +01:00
change_value ( MarginL , line - > GetMarginString ( 0 , false ) ) ;
change_value ( MarginR , line - > GetMarginString ( 1 , false ) ) ;
change_value ( MarginV , line - > GetMarginString ( 2 , false ) ) ;
2012-01-20 06:14:50 +01:00
Effect - > ChangeValue ( line - > Effect ) ;
2010-07-20 05:11:11 +02:00
CommentBox - > SetValue ( line - > Comment ) ;
StyleBox - > Select ( StyleBox - > FindString ( line - > Style ) ) ;
2011-10-19 06:05:09 +02:00
PopulateActorList ( ) ;
2012-01-20 06:14:50 +01:00
ActorBox - > ChangeValue ( line - > Actor ) ;
2010-07-20 05:11:11 +02:00
ActorBox - > SetStringSelection ( line - > Actor ) ;
2006-01-16 22:02:54 +01:00
}
}
2011-10-19 06:05:09 +02:00
void SubsEditBox : : PopulateActorList ( ) {
2011-12-22 22:30:32 +01:00
wxEventBlocker blocker ( this ) ;
2011-10-19 06:05:09 +02:00
std : : set < wxString > actors ;
for ( entryIter it = c - > ass - > Line . begin ( ) ; it ! = c - > ass - > Line . end ( ) ; + + it ) {
if ( AssDialogue * diag = dynamic_cast < AssDialogue * > ( * it ) )
actors . insert ( diag - > Actor ) ;
}
# ifdef __APPLE__
// OSX doesn't like combo boxes that are empty.
actors . insert ( " Actor " ) ;
# endif
actors . erase ( " " ) ;
wxArrayString arrstr ;
arrstr . reserve ( actors . size ( ) ) ;
copy ( actors . begin ( ) , actors . end ( ) , std : : back_inserter ( arrstr ) ) ;
ActorBox - > Freeze ( ) ;
long pos = ActorBox - > GetInsertionPoint ( ) ;
wxString value = ActorBox - > GetValue ( ) ;
2012-01-20 06:14:44 +01:00
ActorBox - > Set ( arrstr ) ;
2011-10-19 06:05:09 +02:00
ActorBox - > ChangeValue ( value ) ;
ActorBox - > SetStringSelection ( value ) ;
ActorBox - > SetInsertionPoint ( pos ) ;
ActorBox - > Thaw ( ) ;
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnActiveLineChanged ( AssDialogue * new_line ) {
2011-12-22 22:30:32 +01:00
wxEventBlocker blocker ( this ) ;
2010-07-20 05:11:11 +02:00
line = new_line ;
2011-12-22 22:31:01 +01:00
commitId = - 1 ;
2006-01-16 22:02:54 +01:00
2011-12-28 22:27:22 +01:00
OnCommit ( AssFile : : COMMIT_DIAG_FULL ) ;
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
2010-07-20 05:11:11 +02:00
/// @todo VideoContext should be doing this
2011-01-16 08:17:36 +01:00
if ( c - > videoController - > IsLoaded ( ) ) {
2010-07-20 05:11:11 +02:00
bool sync ;
2011-12-22 22:14:32 +01:00
if ( Search . HasFocus ( ) ) sync = OPT_GET ( " Tool/Search Replace/Video Update " ) - > GetBool ( ) ;
2010-07-20 05:11:11 +02:00
else sync = OPT_GET ( " Video/Subtitle Sync " ) - > GetBool ( ) ;
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
2010-07-20 05:11:11 +02:00
if ( sync ) {
2011-01-16 08:17:36 +01:00
c - > videoController - > Stop ( ) ;
2011-12-22 22:28:51 +01:00
c - > videoController - > JumpToTime ( line - > Start ) ;
2010-07-20 05:11:11 +02:00
}
2007-01-02 06:00:55 +01:00
}
2010-07-20 05:11:11 +02:00
}
void SubsEditBox : : OnSelectedSetChanged ( const Selection & , const Selection & ) {
2011-09-15 07:17:29 +02:00
sel = c - > selectionController - > GetSelectedSet ( ) ;
2006-12-24 05:54:35 +01:00
}
2010-12-31 22:03:18 +01:00
void SubsEditBox : : UpdateFrameTiming ( agi : : vfr : : Framerate const & fps ) {
if ( fps . IsLoaded ( ) ) {
ByFrame - > Enable ( true ) ;
}
2010-07-20 05:11:11 +02:00
else {
ByFrame - > Enable ( false ) ;
ByTime - > SetValue ( true ) ;
StartTime - > SetByFrame ( false ) ;
EndTime - > SetByFrame ( false ) ;
2011-01-16 08:17:36 +01:00
c - > subsGrid - > SetByFrame ( false ) ;
2010-07-20 05:11:11 +02:00
}
2007-01-02 19:09:56 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnKeyDown ( wxKeyEvent & event ) {
2012-01-14 02:40:21 +01:00
if ( ! hotkey : : check ( " Subtitle Edit Box " , c , event . GetKeyCode ( ) , event . GetUnicodeKey ( ) , event . GetModifiers ( ) ) )
2010-07-20 05:11:11 +02:00
event . Skip ( ) ;
}
2007-01-02 19:09:56 +01:00
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnChange ( wxStyledTextEvent & event ) {
if ( line & & TextEdit - > GetText ( ) ! = line - > Text ) {
2012-01-26 23:13:39 +01:00
if ( event . GetModificationType ( ) & wxSTC_STARTACTION )
commitId = - 1 ;
CommitText ( _ ( " modify text " ) ) ;
2010-07-20 05:11:11 +02:00
}
2006-01-16 22:02:54 +01:00
}
2011-12-22 22:31:09 +01:00
void SubsEditBox : : OnUndoTimer ( wxTimerEvent & ) {
commitId = - 1 ;
}
2010-07-20 05:11:11 +02:00
template < class T , class setter >
2011-09-15 07:16:32 +02:00
void SubsEditBox : : SetSelectedRows ( setter set , T value , wxString desc , int type , bool amend ) {
2011-10-19 06:05:09 +02:00
for_each ( sel . begin ( ) , sel . end ( ) , bind ( set , std : : tr1 : : placeholders : : _1 , value ) ) ;
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-10-19 06:05:09 +02:00
file_changed_slot . Block ( ) ;
2011-09-28 21:44:24 +02:00
commitId = c - > ass - > Commit ( desc , type , ( amend & & desc = = lastCommitType ) ? commitId : - 1 , sel . size ( ) = = 1 ? * sel . begin ( ) : 0 ) ;
2011-10-19 06:05:09 +02:00
file_changed_slot . Unblock ( ) ;
2010-07-20 05:11:11 +02:00
lastCommitType = desc ;
2011-12-22 22:31:09 +01:00
undoTimer . Start ( 10000 , wxTIMER_ONE_SHOT ) ;
2007-01-02 06:00:55 +01:00
}
2010-07-20 05:11:11 +02:00
template < class T >
2011-09-15 07:16:32 +02:00
void SubsEditBox : : SetSelectedRows ( T AssDialogue : : * field , T value , wxString desc , int type , bool amend ) {
SetSelectedRows ( field_setter < T > ( field ) , value , desc , type , amend ) ;
2007-01-02 19:28:09 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : CommitText ( wxString desc ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( & AssDialogue : : Text , TextEdit - > GetText ( ) , desc , AssFile : : COMMIT_DIAG_TEXT , true ) ;
2010-07-20 05:11:11 +02:00
}
2007-01-02 19:28:09 +01:00
2010-07-20 05:11:11 +02:00
void SubsEditBox : : CommitTimes ( TimeField field ) {
2011-12-22 22:30:22 +01:00
if ( ByFrame - > GetValue ( ) )
Duration - > SetFrame ( EndTime - > GetFrame ( ) - StartTime - > GetFrame ( ) + 1 ) ;
else
Duration - > SetTime ( EndTime - > GetTime ( ) - StartTime - > GetTime ( ) ) ;
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
2010-07-20 05:11:11 +02:00
// Update lines
for ( Selection : : iterator cur = sel . begin ( ) ; cur ! = sel . end ( ) ; + + cur ) {
2011-12-22 22:30:22 +01:00
AssDialogue * d = * cur ;
2010-07-20 05:11:11 +02:00
switch ( field ) {
case TIME_START :
2011-12-22 22:30:22 +01:00
d - > Start = StartTime - > GetTime ( ) ;
if ( d - > Start > d - > End )
d - > End = d - > Start ;
2010-07-20 05:11:11 +02:00
break ;
case TIME_END :
2011-12-22 22:30:22 +01:00
d - > End = EndTime - > GetTime ( ) ;
if ( d - > Start > d - > End )
d - > Start = d - > End ;
2010-07-20 05:11:11 +02:00
break ;
case TIME_DURATION :
2011-12-22 22:30:22 +01:00
if ( ByFrame - > GetValue ( ) )
d - > End = c - > videoController - > TimeAtFrame ( c - > videoController - > FrameAtTime ( d - > Start , agi : : vfr : : START ) + Duration - > GetFrame ( ) , agi : : vfr : : END ) ;
else
d - > End = d - > Start + Duration - > GetTime ( ) ;
2010-07-20 05:11:11 +02:00
break ;
}
}
2011-09-28 21:44:24 +02:00
timeCommitId [ field ] = c - > ass - > Commit ( _ ( " modify times " ) , AssFile : : COMMIT_DIAG_TIME , timeCommitId [ field ] , sel . size ( ) = = 1 ? * sel . begin ( ) : 0 ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnSize ( wxSizeEvent & evt ) {
2012-01-13 21:18:29 +01:00
int availableWidth = GetVirtualSize ( ) . GetWidth ( ) ;
2010-07-20 05:11:11 +02:00
int midMin = MiddleSizer - > GetMinSize ( ) . GetWidth ( ) ;
int botMin = MiddleBotSizer - > GetMinSize ( ) . GetWidth ( ) ;
2006-01-16 22:02:54 +01:00
2010-07-20 05:11:11 +02:00
if ( splitLineMode ) {
2012-01-13 21:18:29 +01:00
if ( availableWidth > midMin + botMin ) {
2012-01-20 06:14:44 +01:00
GetSizer ( ) - > Detach ( MiddleBotSizer ) ;
2010-07-20 05:11:11 +02:00
MiddleSizer - > Add ( MiddleBotSizer , 0 , wxALIGN_CENTER_VERTICAL ) ;
splitLineMode = false ;
}
}
else {
2012-01-13 21:18:29 +01:00
if ( availableWidth < midMin ) {
2010-07-20 05:11:11 +02:00
MiddleSizer - > Detach ( MiddleBotSizer ) ;
2012-01-20 06:14:44 +01:00
GetSizer ( ) - > Insert ( 2 , MiddleBotSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 3 ) ;
2010-07-20 05:11:11 +02:00
splitLineMode = true ;
}
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
evt . Skip ( ) ;
}
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
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnFrameTimeRadio ( wxCommandEvent & event ) {
bool byFrame = ByFrame - > GetValue ( ) ;
StartTime - > SetByFrame ( byFrame ) ;
EndTime - > SetByFrame ( byFrame ) ;
Duration - > SetByFrame ( byFrame ) ;
2011-01-16 08:17:36 +01:00
c - > subsGrid - > SetByFrame ( byFrame ) ;
2010-07-20 05:11:11 +02:00
event . Skip ( ) ;
}
2006-01-16 22:02:54 +01:00
2010-07-20 05:11:11 +02:00
void SubsEditBox : : SetControlsState ( bool state ) {
2006-01-16 22:02:54 +01:00
if ( state = = controlState ) return ;
controlState = state ;
2012-01-20 06:14:44 +01:00
Enable ( state ) ;
2010-07-20 05:11:11 +02:00
if ( ! state ) {
2011-12-22 22:30:32 +01:00
wxEventBlocker blocker ( this ) ;
2010-07-20 05:11:11 +02:00
TextEdit - > SetTextTo ( " " ) ;
2006-01-16 22:02:54 +01:00
}
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnStyleChange ( wxCommandEvent & ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( & AssDialogue : : Style , StyleBox - > GetValue ( ) , _ ( " style change " ) , AssFile : : COMMIT_DIAG_META ) ;
2006-01-16 22:02:54 +01:00
}
2012-03-07 23:40:45 +01:00
void SubsEditBox : : OnActorChange ( wxCommandEvent & evt ) {
bool amend = evt . GetEventType ( ) = = wxEVT_COMMAND_TEXT_UPDATED ;
SetSelectedRows ( & AssDialogue : : Actor , ActorBox - > GetValue ( ) , _ ( " actor change " ) , AssFile : : COMMIT_DIAG_META , amend ) ;
2011-10-19 06:05:09 +02:00
PopulateActorList ( ) ;
2006-01-16 22:02:54 +01:00
}
2007-06-18 01:49:51 +02:00
void SubsEditBox : : OnLayerChange ( wxSpinEvent & event ) {
2010-07-20 05:11:11 +02:00
OnLayerEnter ( event ) ;
2007-10-29 16:30:04 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnLayerEnter ( wxCommandEvent & ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( & AssDialogue : : Layer , Layer - > GetValue ( ) , _ ( " layer change " ) , AssFile : : COMMIT_DIAG_META ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnStartTimeChange ( wxCommandEvent & ) {
2011-12-22 22:18:16 +01:00
if ( StartTime - > GetTime ( ) > EndTime - > GetTime ( ) ) EndTime - > SetTime ( StartTime - > GetTime ( ) ) ;
2010-07-20 05:11:11 +02:00
CommitTimes ( TIME_START ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnEndTimeChange ( wxCommandEvent & ) {
2011-12-22 22:18:16 +01:00
if ( StartTime - > GetTime ( ) > EndTime - > GetTime ( ) ) StartTime - > SetTime ( EndTime - > GetTime ( ) ) ;
2010-07-20 05:11:11 +02:00
CommitTimes ( TIME_END ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnDurationChange ( wxCommandEvent & ) {
2011-12-22 22:30:22 +01:00
if ( ByFrame - > GetValue ( ) )
EndTime - > SetFrame ( StartTime - > GetFrame ( ) + Duration - > GetFrame ( ) - 1 ) ;
else
EndTime - > SetTime ( StartTime - > GetTime ( ) + Duration - > GetTime ( ) ) ;
2010-07-20 05:11:11 +02:00
CommitTimes ( TIME_DURATION ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnMarginLChange ( wxCommandEvent & ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( std : : mem_fun ( & AssDialogue : : SetMarginString < 0 > ) , MarginL - > GetValue ( ) , _ ( " MarginL change " ) , AssFile : : COMMIT_DIAG_META ) ;
2012-01-20 06:14:44 +01:00
if ( line ) change_value ( MarginL , line - > GetMarginString ( 0 , false ) ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnMarginRChange ( wxCommandEvent & ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( std : : mem_fun ( & AssDialogue : : SetMarginString < 1 > ) , MarginR - > GetValue ( ) , _ ( " MarginR change " ) , AssFile : : COMMIT_DIAG_META ) ;
2012-01-20 06:14:44 +01:00
if ( line ) change_value ( MarginR , line - > GetMarginString ( 1 , false ) ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
static void set_margin_v ( AssDialogue * diag , wxString value ) {
diag - > SetMarginString ( value , 2 ) ;
diag - > SetMarginString ( value , 3 ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnMarginVChange ( wxCommandEvent & ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( set_margin_v , MarginV - > GetValue ( ) , _ ( " MarginV change " ) , AssFile : : COMMIT_DIAG_META ) ;
2012-01-20 06:14:44 +01:00
if ( line ) change_value ( MarginV , line - > GetMarginString ( 2 , false ) ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnEffectChange ( wxCommandEvent & ) {
2012-03-07 23:40:35 +01:00
SetSelectedRows ( & AssDialogue : : Effect , Effect - > GetValue ( ) , _ ( " effect change " ) , AssFile : : COMMIT_DIAG_META , true ) ;
2006-06-27 06:13:34 +02:00
}
2011-12-22 22:09:31 +01:00
void SubsEditBox : : OnCommentChange ( wxCommandEvent & ) {
2011-09-15 07:16:32 +02:00
SetSelectedRows ( & AssDialogue : : Comment , CommentBox - > GetValue ( ) , _ ( " comment change " ) , AssFile : : COMMIT_DIAG_META ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : SetTag ( wxString tag , wxString value , bool atEnd ) {
assert ( line ) ;
if ( line - > Blocks . empty ( ) )
line - > ParseASSTags ( ) ;
2006-01-16 22:02:54 +01:00
2012-01-20 06:14:44 +01:00
std : : pair < int , int > sel = get_selection ( TextEdit ) ;
int start = atEnd ? sel . second : sel . first ;
int blockn = block_at_pos ( line - > Text , start ) ;
2011-10-19 05:24:10 +02:00
2011-11-18 05:06:03 +01:00
AssDialogueBlockPlain * plain = 0 ;
AssDialogueBlockOverride * ovr = 0 ;
2011-10-19 05:24:10 +02:00
while ( blockn > = 0 ) {
AssDialogueBlock * block = line - > Blocks [ blockn ] ;
if ( dynamic_cast < AssDialogueBlockDrawing * > ( block ) )
- - blockn ;
2011-11-07 07:18:34 +01:00
else if ( ( plain = dynamic_cast < AssDialogueBlockPlain * > ( block ) ) ) {
2011-10-19 05:24:10 +02:00
// Cursor is in a comment block, so try the previous block instead
if ( plain - > GetText ( ) . StartsWith ( " { " ) ) {
- - blockn ;
start = line - > Text . rfind ( ' { ' , start ) ;
}
else
break ;
}
else {
ovr = dynamic_cast < AssDialogueBlockOverride * > ( block ) ;
assert ( ovr ) ;
break ;
}
2010-06-26 13:32:16 +02:00
}
2009-04-26 03:02:23 +02:00
2011-10-19 05:24:10 +02:00
// If we didn't hit a suitable block for inserting the override just put
// it at the beginning of the line
if ( blockn < 0 )
start = 0 ;
2010-07-20 05:11:11 +02:00
wxString insert = tag + value ;
int shift = insert . size ( ) ;
2011-10-19 05:24:10 +02:00
if ( plain | | blockn < 0 ) {
2010-07-20 05:11:11 +02:00
line - > Text = line - > Text . Left ( start ) + " { " + insert + " } " + line - > Text . Mid ( start ) ;
shift + = 2 ;
line - > ParseASSTags ( ) ;
2007-06-30 22:00:07 +02:00
}
2011-12-26 23:20:49 +01:00
else if ( ovr ) {
2010-07-20 05:11:11 +02:00
wxString alt ;
2011-09-28 21:43:11 +02:00
if ( tag = = " \\ c " ) alt = " \\ 1c " ;
2010-07-20 05:11:11 +02:00
// Remove old of same
bool found = false ;
for ( size_t i = 0 ; i < ovr - > Tags . size ( ) ; i + + ) {
wxString name = ovr - > Tags [ i ] - > Name ;
if ( tag = = name | | alt = = name ) {
shift - = ( ( wxString ) * ovr - > Tags [ i ] ) . size ( ) ;
if ( found ) {
delete ovr - > Tags [ i ] ;
ovr - > Tags . erase ( ovr - > Tags . begin ( ) + i ) ;
i - - ;
}
else {
ovr - > Tags [ i ] - > Params [ 0 ] - > Set ( value ) ;
2010-10-08 08:06:44 +02:00
ovr - > Tags [ i ] - > Params [ 0 ] - > omitted = false ;
2010-07-20 05:11:11 +02:00
found = true ;
}
2009-04-26 03:02:23 +02:00
}
}
2010-07-20 05:11:11 +02:00
if ( ! found ) {
ovr - > AddTag ( insert ) ;
2007-01-08 06:32:29 +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
2010-07-20 05:11:11 +02:00
line - > UpdateText ( ) ;
2006-01-16 22:02:54 +01:00
}
2011-12-26 23:20:49 +01:00
else
assert ( false ) ;
2010-07-20 05:11:11 +02:00
TextEdit - > SetTextTo ( line - > Text ) ;
2012-01-20 06:14:44 +01:00
if ( ! atEnd ) TextEdit - > SetSelectionU ( sel . first + shift , sel . second + shift ) ;
2010-07-20 05:11:11 +02:00
TextEdit - > SetFocus ( ) ;
2006-01-16 22:02:54 +01:00
}
2012-01-20 06:14:44 +01:00
void SubsEditBox : : OnFlagButton ( bool ( AssStyle : : * field ) , const char * tag , wxString const & undo_msg ) {
2011-01-16 08:17:36 +01:00
AssStyle * style = c - > ass - > GetStyle ( line - > Style ) ;
2012-01-20 06:14:44 +01:00
bool state = style ? style - > * field : AssStyle ( ) . * field ;
2006-01-16 22:02:54 +01:00
2010-07-20 05:11:11 +02:00
line - > ParseASSTags ( ) ;
2012-01-20 06:14:44 +01:00
std : : pair < int , int > sel = get_selection ( TextEdit ) ;
int blockn = block_at_pos ( line - > Text , sel . first ) ;
2007-01-15 20:44:48 +01:00
2012-01-20 06:14:44 +01:00
state = get_value ( * line , blockn , state , tag ) ;
2006-02-19 05:55:10 +01:00
2012-01-20 06:14:44 +01:00
SetTag ( tag , state ? " 0 " : " 1 " ) ;
if ( sel . first ! = sel . second )
SetTag ( tag , state ? " 1 " : " 0 " , true ) ;
2006-01-16 22:02:54 +01:00
2010-07-20 05:11:11 +02:00
line - > ClearBlocks ( ) ;
commitId = - 1 ;
2012-01-20 06:14:44 +01:00
CommitText ( undo_msg ) ;
2010-07-20 05:11:11 +02:00
}
2006-01-16 22:02:54 +01:00
2012-01-20 06:14:44 +01:00
void SubsEditBox : : OnFontButton ( ) {
2010-07-20 05:11:11 +02:00
line - > ParseASSTags ( ) ;
2012-01-20 06:14:44 +01:00
int blockn = block_at_pos ( line - > Text , get_selection ( TextEdit ) . first ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:17:36 +01:00
AssStyle * style = c - > ass - > GetStyle ( line - > Style ) ;
2010-07-20 05:11:11 +02:00
AssStyle defStyle ;
if ( ! style ) style = & defStyle ;
2006-01-16 22:02:54 +01:00
2012-01-20 06:14:44 +01:00
wxFont startfont (
get_value ( * line , blockn , ( int ) style - > fontsize , " \\ fs " ) ,
wxFONTFAMILY_DEFAULT ,
get_value ( * line , blockn , style - > italic , " \\ i " ) ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL ,
get_value ( * line , blockn , style - > bold , " \\ b " ) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL ,
get_value ( * line , blockn , style - > underline , " \\ u " ) ,
get_value ( * line , blockn , style - > font , " \\ fn " ) ) ;
2006-01-16 22:02:54 +01:00
2010-07-20 05:11:11 +02:00
wxFont font = wxGetFontFromUser ( this , startfont ) ;
if ( ! font . Ok ( ) | | font = = startfont ) {
line - > ClearBlocks ( ) ;
return ;
2006-01-16 22:02:54 +01:00
}
2012-01-20 06:14:44 +01:00
if ( font . GetFaceName ( ) ! = startfont . GetFaceName ( ) )
2011-09-28 21:43:11 +02:00
SetTag ( " \\ fn " , font . GetFaceName ( ) ) ;
2012-01-20 06:14:44 +01:00
if ( font . GetPointSize ( ) ! = startfont . GetPointSize ( ) )
SetTag ( " \\ fs " , wxString : : Format ( " %d " , font . GetPointSize ( ) ) ) ;
if ( font . GetWeight ( ) ! = startfont . GetWeight ( ) )
SetTag ( " \\ b " , wxString : : Format ( " %d " , font . GetWeight ( ) = = wxFONTWEIGHT_BOLD ) ) ;
if ( font . GetStyle ( ) ! = startfont . GetStyle ( ) )
SetTag ( " \\ i " , wxString : : Format ( " %d " , font . GetStyle ( ) = = wxFONTSTYLE_ITALIC ) ) ;
if ( font . GetUnderlined ( ) ! = startfont . GetUnderlined ( ) )
SetTag ( " \\ i " , wxString : : Format ( " %d " , font . GetUnderlined ( ) ) ) ;
2010-07-20 05:11:11 +02:00
line - > ClearBlocks ( ) ;
commitId = - 1 ;
CommitText ( _ ( " set font " ) ) ;
2007-06-30 22:00:07 +02:00
}
2012-01-20 06:14:44 +01:00
void SubsEditBox : : OnColorButton ( AssColor ( AssStyle : : * field ) , const char * tag , const char * alt ) {
2011-01-16 08:17:36 +01:00
AssStyle * style = c - > ass - > GetStyle ( line - > Style ) ;
2012-01-20 06:14:44 +01:00
wxColor color = ( style ? style - > * field : AssStyle ( ) . * field ) . GetWXColor ( ) ;
2010-06-26 13:32:16 +02:00
2012-01-20 06:14:44 +01:00
colorTag = tag ;
2010-07-20 05:11:11 +02:00
commitId = - 1 ;
2010-06-26 13:32:16 +02:00
2010-07-20 05:11:11 +02:00
line - > ParseASSTags ( ) ;
2012-01-20 06:14:44 +01:00
std : : pair < int , int > sel = get_selection ( TextEdit ) ;
int blockn = block_at_pos ( line - > Text , sel . first ) ;
2010-06-26 13:32:16 +02:00
2010-07-20 05:11:11 +02:00
color = get_value ( * line , blockn , color , colorTag , alt ) ;
wxString initialText = line - > Text ;
2011-01-16 08:17:36 +01:00
wxColor newColor = GetColorFromUser < SubsEditBox , & SubsEditBox : : SetColorCallback > ( c - > parent , color , this ) ;
2010-07-20 05:11:11 +02:00
if ( newColor = = color ) {
TextEdit - > SetTextTo ( initialText ) ;
2012-01-20 06:14:44 +01:00
TextEdit - > SetSelectionU ( sel . first , sel . second ) ;
2010-06-26 13:32:16 +02:00
}
2010-07-20 05:11:11 +02:00
line - > ClearBlocks ( ) ;
CommitText ( _ ( " set color " ) ) ;
2010-06-26 13:32:16 +02:00
}
2012-01-20 06:14:44 +01:00
2010-07-20 05:11:11 +02:00
void SubsEditBox : : SetColorCallback ( wxColor newColor ) {
if ( newColor . Ok ( ) ) {
SetTag ( colorTag , AssColor ( newColor ) . GetASSFormatted ( false ) ) ;
CommitText ( _ ( " set color " ) ) ;
}
2010-06-26 13:32:16 +02:00
}