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/
/// @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"
2012-01-14 02:40:21 +01:00
# include "command/command.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"
2012-10-08 16:32:51 +02:00
# include "scintilla_text_selection_controller.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"
2012-10-09 18:37:28 +02:00
# include "tooltip_manager.h"
2009-09-10 15:06:40 +02:00
# 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 ) { }
2012-10-11 04:01:31 +02:00
void operator ( ) ( AssDialogue * obj , T const & value ) {
2010-07-20 05:11:11 +02:00
obj - > * field = value ;
}
} ;
2012-01-20 06:14:44 +01:00
/// 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 ) ;
}
2012-05-15 15:40:00 +02:00
void time_edit_char_hook ( wxKeyEvent & event ) {
// Force a modified event on Enter
if ( event . GetKeyCode ( ) = = WXK_RETURN ) {
TimeEdit * edit = static_cast < TimeEdit * > ( event . GetEventObject ( ) ) ;
edit - > SetValue ( edit - > GetValue ( ) ) ;
}
else
event . Skip ( ) ;
}
2012-01-20 06:14:44 +01:00
}
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. " ) ) ;
2012-05-15 16:06:44 +02:00
# ifdef __WXGTK__
// Only supported in wxgtk
CommentBox - > SetCanFocus ( false ) ;
# endif
2012-01-20 06:14:44 +01:00
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-04-10 22:40:43 +02: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. " ) ) ;
2012-01-20 06:14:50 +01:00
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 ) ) ;
2012-10-20 16:34:55 +02:00
Effect = new Placeholder < wxComboBox > ( this , _ ( " Effect " ) , wxSize ( 80 , - 1 ) , wxCB_DROPDOWN | 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. " ) ) ;
2012-01-20 06:14:50 +01:00
Bind ( wxEVT_COMMAND_TEXT_UPDATED , & SubsEditBox : : OnEffectChange , this , Effect - > GetId ( ) ) ;
2012-10-20 16:34:55 +02:00
Bind ( wxEVT_COMMAND_COMBOBOX_SELECTED , & 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-10-09 04:07:54 +02:00
MakeButton ( " edit/style/bold " ) ;
MakeButton ( " edit/style/italic " ) ;
MakeButton ( " edit/style/underline " ) ;
MakeButton ( " edit/style/strikeout " ) ;
MakeButton ( " edit/font " ) ;
2012-01-20 06:14:44 +01:00
MiddleBotSizer - > AddSpacer ( 5 ) ;
2012-10-09 04:07:54 +02:00
MakeButton ( " edit/color/primary " ) ;
MakeButton ( " edit/color/secondary " ) ;
MakeButton ( " edit/color/outline " ) ;
MakeButton ( " edit/color/shadow " ) ;
2012-01-20 06:14:44 +01:00
MiddleBotSizer - > AddSpacer ( 5 ) ;
2012-10-09 04:07:54 +02:00
MakeButton ( " grid/line/next/create " ) ;
2008-03-09 23:31:16 +01:00
MiddleBotSizer - > AddSpacer ( 10 ) ;
2012-01-20 06:14:44 +01:00
2012-05-15 16:06:55 +02:00
ByTime = MakeRadio ( _ ( " T&ime " ) , true , _ ( " Time by h:mm:ss.cs " ) ) ;
2012-01-20 06:14:44 +01:00
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-04-27 21:07:49 +02:00
TextEdit - > Bind ( wxEVT_CHAR_HOOK , & SubsEditBox : : OnKeyDown , this ) ;
Bind ( wxEVT_CHAR_HOOK , & 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 ( ) ) ;
2012-10-09 04:07:54 +02:00
Bind ( wxEVT_COMMAND_SPINCTRL_UPDATED , & SubsEditBox : : OnLayerEnter , this , Layer - > GetId ( ) ) ;
2010-07-20 05:11:11 +02:00
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-12-28 22:27:22 +01:00
file_changed_slot = c - > ass - > AddCommitListener ( & SubsEditBox : : OnCommit , this ) ;
2012-10-05 05:22:54 +02:00
connections . push_back ( context - > videoController - > AddTimecodesListener ( & SubsEditBox : : UpdateFrameTiming , this ) ) ;
connections . push_back ( context - > selectionController - > AddActiveLineListener ( & SubsEditBox : : OnActiveLineChanged , this ) ) ;
connections . push_back ( context - > selectionController - > AddSelectionListener ( & SubsEditBox : : OnSelectedSetChanged , this ) ) ;
2012-10-08 16:32:51 +02:00
textSelectionController . reset ( new ScintillaTextSelectionController ( TextEdit ) ) ;
context - > textSelectionController = textSelectionController . get ( ) ;
TextEdit - > SetFocus ( ) ;
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 ( ) {
}
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 ( ) ) ;
2012-05-15 15:40:00 +02:00
ctrl - > Bind ( wxEVT_CHAR_HOOK , time_edit_char_hook ) ;
2012-01-20 06:14:44 +01:00
MiddleSizer - > Add ( ctrl , wxSizerFlags ( ) . Center ( ) ) ;
return ctrl ;
}
2012-10-09 04:07:54 +02:00
void SubsEditBox : : MakeButton ( const char * cmd_name ) {
cmd : : Command * command = cmd : : get ( cmd_name ) ;
wxBitmapButton * btn = new wxBitmapButton ( this , - 1 , command - > Icon ( 16 ) ) ;
2012-10-09 18:37:28 +02:00
ToolTipManager : : Bind ( btn , command - > StrHelp ( ) , " Subtitle Edit Box " , cmd_name ) ;
2012-01-20 06:14:44 +01:00
MiddleBotSizer - > Add ( btn , wxSizerFlags ( ) . Center ( ) . Expand ( ) ) ;
2012-10-11 04:01:31 +02:00
btn - > Bind ( wxEVT_COMMAND_BUTTON_CLICKED , std : : tr1 : : bind ( & SubsEditBox : : CallCommand , this , cmd_name ) ) ;
2012-01-20 06:14:44 +01:00
}
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
2012-05-03 00:42:25 +02:00
initialTimes . clear ( ) ;
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?
2012-10-20 16:34:55 +02:00
PopulateList ( Effect , & AssDialogue : : Effect ) ;
PopulateList ( ActorBox , & AssDialogue : : Actor ) ;
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 ) {
2012-10-25 17:13:13 +02:00
TextEdit - > SetValue ( 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 ) ) ;
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
2012-10-20 16:34:55 +02:00
PopulateList ( Effect , & AssDialogue : : Effect ) ;
Effect - > ChangeValue ( line - > Effect ) ;
Effect - > SetStringSelection ( line - > Effect ) ;
PopulateList ( ActorBox , & AssDialogue : : Actor ) ;
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
}
}
2012-10-20 16:34:55 +02:00
void SubsEditBox : : PopulateList ( wxComboBox * combo , wxString AssDialogue : : * field ) {
2011-12-22 22:30:32 +01:00
wxEventBlocker blocker ( this ) ;
2012-10-20 16:34:55 +02:00
std : : set < wxString > values ;
2011-10-19 06:05:09 +02:00
for ( entryIter it = c - > ass - > Line . begin ( ) ; it ! = c - > ass - > Line . end ( ) ; + + it ) {
if ( AssDialogue * diag = dynamic_cast < AssDialogue * > ( * it ) )
2012-10-20 16:34:55 +02:00
values . insert ( diag - > * field ) ;
2011-10-19 06:05:09 +02:00
}
2012-10-20 16:34:55 +02:00
values . erase ( " " ) ;
2011-10-19 06:05:09 +02:00
wxArrayString arrstr ;
2012-10-20 16:34:55 +02:00
arrstr . reserve ( values . size ( ) ) ;
copy ( values . begin ( ) , values . end ( ) , std : : back_inserter ( arrstr ) ) ;
2011-10-19 06:05:09 +02:00
2012-10-20 16:34:55 +02:00
combo - > Freeze ( ) ;
long pos = combo - > GetInsertionPoint ( ) ;
wxString value = combo - > GetValue ( ) ;
2011-10-19 06:05:09 +02:00
2012-10-20 16:34:55 +02:00
combo - > Set ( arrstr ) ;
combo - > ChangeValue ( value ) ;
combo - > SetStringSelection ( value ) ;
combo - > SetInsertionPoint ( pos ) ;
combo - > Thaw ( ) ;
2011-10-19 06:05:09 +02:00
}
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
}
2012-10-05 05:22:54 +02:00
void SubsEditBox : : OnSelectedSetChanged ( const SubtitleSelection & , const SubtitleSelection & ) {
2011-09-15 07:17:29 +02:00
sel = c - > selectionController - > GetSelectedSet ( ) ;
2012-05-03 00:42:25 +02:00
initialTimes . clear ( ) ;
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 ) ;
2012-10-10 04:49:57 +02:00
Duration - > 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-03-13 00:34:34 +01:00
hotkey : : check ( " Subtitle Edit Box " , c , event ) ;
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 : : 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 ;
2012-05-03 00:42:25 +02:00
lastTimeCommitType = - 1 ;
initialTimes . clear ( ) ;
2012-10-09 06:03:15 +02:00
undoTimer . Start ( 30000 , 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
}
2012-10-09 04:07:54 +02:00
void SubsEditBox : : CommitText ( wxString const & 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 ) {
2012-10-05 05:22:54 +02:00
for ( SubtitleSelection : : iterator cur = sel . begin ( ) ; cur ! = sel . end ( ) ; + + cur ) {
2011-12-22 22:30:22 +01:00
AssDialogue * d = * cur ;
2012-05-03 00:42:25 +02:00
if ( ! initialTimes . count ( d ) )
initialTimes [ d ] = std : : make_pair ( d - > Start , d - > End ) ;
2010-07-20 05:11:11 +02:00
switch ( field ) {
case TIME_START :
2012-05-03 00:42:25 +02:00
initialTimes [ d ] . first = d - > Start = StartTime - > GetTime ( ) ;
d - > End = std : : max ( d - > Start , initialTimes [ d ] . second ) ;
2010-07-20 05:11:11 +02:00
break ;
2012-05-03 00:42:25 +02:00
2010-07-20 05:11:11 +02:00
case TIME_END :
2012-05-03 00:42:25 +02:00
initialTimes [ d ] . second = d - > End = EndTime - > GetTime ( ) ;
d - > Start = std : : min ( d - > End , initialTimes [ d ] . first ) ;
2010-07-20 05:11:11 +02:00
break ;
2012-05-03 00:42:25 +02:00
2010-07-20 05:11:11 +02:00
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 ( ) ;
2012-05-03 00:42:25 +02:00
initialTimes [ d ] . second = d - > End ;
2010-07-20 05:11:11 +02:00
break ;
}
}
2012-05-03 00:42:25 +02:00
StartTime - > SetTime ( line - > Start ) ;
EndTime - > SetTime ( line - > End ) ;
if ( ByFrame - > GetValue ( ) )
Duration - > SetFrame ( EndTime - > GetFrame ( ) - StartTime - > GetFrame ( ) + 1 ) ;
else
Duration - > SetTime ( EndTime - > GetTime ( ) - StartTime - > GetTime ( ) ) ;
if ( field ! = lastTimeCommitType )
commitId = - 1 ;
lastTimeCommitType = field ;
file_changed_slot . Block ( ) ;
commitId = c - > ass - > Commit ( _ ( " modify times " ) , AssFile : : COMMIT_DIAG_TIME , commitId , sel . size ( ) = = 1 ? * sel . begin ( ) : 0 ) ;
file_changed_slot . Unblock ( ) ;
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 ) ;
2012-10-25 17:13:13 +02:00
TextEdit - > SetValue ( " " ) ;
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 ) ;
2012-10-20 16:34:55 +02:00
PopulateList ( ActorBox , & AssDialogue : : Actor ) ;
2006-01-16 22:02:54 +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 & ) {
CommitTimes ( TIME_START ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnEndTimeChange ( wxCommandEvent & ) {
CommitTimes ( TIME_END ) ;
2006-01-16 22:02:54 +01:00
}
2010-07-20 05:11:11 +02:00
void SubsEditBox : : OnDurationChange ( wxCommandEvent & ) {
CommitTimes ( TIME_DURATION ) ;
2006-01-16 22:02:54 +01:00
}
2012-10-09 04:07:54 +02: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
void SubsEditBox : : OnMarginVChange ( wxCommandEvent & ) {
2012-10-10 16:04:44 +02:00
SetSelectedRows ( std : : mem_fun ( & AssDialogue : : SetMarginString < 2 > ) , 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
}
2012-10-20 16:34:55 +02:00
void SubsEditBox : : OnEffectChange ( wxCommandEvent & evt ) {
bool amend = evt . GetEventType ( ) = = wxEVT_COMMAND_TEXT_UPDATED ;
SetSelectedRows ( & AssDialogue : : Effect , Effect - > GetValue ( ) , _ ( " effect change " ) , AssFile : : COMMIT_DIAG_META , amend ) ;
PopulateList ( Effect , & AssDialogue : : Effect ) ;
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
}
2012-10-11 04:01:31 +02:00
void SubsEditBox : : CallCommand ( const char * cmd_name ) {
cmd : : call ( cmd_name , c ) ;
TextEdit - > SetFocus ( ) ;
}