2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, 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.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
////////////
// Includes
2006-12-24 05:54:35 +01:00
# include "setup.h"
# include <wx/colordlg.h>
# include <wx/fontdlg.h>
2006-01-16 22:02:54 +01:00
# include "subs_edit_box.h"
2006-12-24 18:42:09 +01:00
# include "subs_edit_ctrl.h"
2006-01-16 22:02:54 +01:00
# include "subs_grid.h"
# include "ass_file.h"
# include "ass_dialogue.h"
# include "ass_style.h"
# include "ass_override.h"
# include "timeedit_ctrl.h"
# include "vfr.h"
# include "options.h"
# include "audio_display.h"
# include "hilimod_textctrl.h"
# include "video_display.h"
# include "validators.h"
# include "dialog_colorpicker.h"
2006-02-19 05:55:10 +01:00
# include "main.h"
# include "frame_main.h"
# include "utils.h"
2006-03-05 21:42:38 +01:00
# include "dialog_search_replace.h"
2006-12-29 04:02:17 +01:00
# include "idle_field_event.h"
2006-03-05 21:42:38 +01:00
2006-01-16 22:02:54 +01:00
///////////////
// Constructor
SubsEditBox : : SubsEditBox ( wxWindow * parent , SubtitlesGrid * gridp ) : wxPanel ( parent , - 1 , wxDefaultPosition , wxDefaultSize , wxTAB_TRAVERSAL | wxRAISED_BORDER , _T ( " SubsEditBox " ) )
{
// Setup
audio = NULL ;
grid = gridp ;
grid - > editBox = this ;
enabled = false ;
textEditReady = true ;
controlState = true ;
2006-12-27 01:00:41 +01:00
setupDone = false ;
2006-01-16 22:02:54 +01:00
linen = - 2 ;
// Top controls
wxArrayString styles ;
styles . Add ( _T ( " " ) ) ;
CommentBox = new wxCheckBox ( this , COMMENT_CHECKBOX , _ ( " Comment " ) ) ;
CommentBox - > SetToolTip ( _ ( " Comment this line out. Commented lines don't show up on screen. " ) ) ;
2006-12-29 22:45:22 +01:00
StyleBox = new wxComboBox ( this , STYLE_COMBOBOX , _T ( " " ) , wxDefaultPosition , wxSize ( 110 , 25 ) , styles , wxCB_READONLY | wxTE_PROCESS_ENTER ) ;
2006-01-16 22:02:54 +01:00
StyleBox - > SetToolTip ( _ ( " Style for this line. " ) ) ;
2006-12-29 22:45:22 +01:00
ActorBox = new wxComboBox ( this , ACTOR_COMBOBOX , _T ( " " ) , wxDefaultPosition , wxSize ( 110 , 25 ) , styles , wxCB_DROPDOWN | wxTE_PROCESS_ENTER ) ;
2006-01-16 22:02:54 +01:00
ActorBox - > SetToolTip ( _ ( " Actor name for this speech. This is only for reference, and is mainly useless. " ) ) ;
2006-12-29 04:02:17 +01:00
ActorBox - > PushEventHandler ( new IdleFieldHandler ( ActorBox , _ ( " Actor " ) ) ) ;
2006-12-29 22:45:22 +01:00
Effect = new HiliModTextCtrl ( this , EFFECT_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 120 , 20 ) , wxTE_PROCESS_ENTER ) ;
2006-12-24 17:17:40 +01:00
Effect - > SetToolTip ( _ ( " Effect for this line. This can be used to store extra information for karaoke scripts, or for the effects supported by the renderer. " ) ) ;
2006-12-29 04:02:17 +01:00
Effect - > PushEventHandler ( new IdleFieldHandler ( Effect , _ ( " Effect " ) ) ) ;
2006-01-16 22:02:54 +01:00
// Middle controls
2006-12-29 22:45:22 +01:00
Layer = new HiliModTextCtrl ( this , LAYER_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 40 , 20 ) , wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-01-16 22:02:54 +01:00
Layer - > SetToolTip ( _ ( " Layer number " ) ) ;
2006-12-29 22:45:22 +01:00
StartTime = new TimeEdit ( this , STARTTIME_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 75 , 20 ) , wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-01-16 22:02:54 +01:00
StartTime - > SetToolTip ( _ ( " Start time " ) ) ;
StartTime - > showModified = true ;
2006-12-29 22:45:22 +01:00
EndTime = new TimeEdit ( this , ENDTIME_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 75 , 20 ) , wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-01-16 22:02:54 +01:00
EndTime - > SetToolTip ( _ ( " End time " ) ) ;
EndTime - > isEnd = true ;
EndTime - > showModified = true ;
2006-12-29 22:45:22 +01:00
Duration = new TimeEdit ( this , DURATION_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 75 , 20 ) , wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-01-16 22:02:54 +01:00
Duration - > SetToolTip ( _ ( " Line duration " ) ) ;
Duration - > showModified = true ;
2006-12-24 17:17:40 +01:00
MarginL = new HiliModTextCtrl ( this , MARGINL_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 40 , 20 ) , wxTE_CENTRE | wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-12-30 15:31:41 +01:00
MarginL - > SetToolTip ( _ ( " Left Margin (0 = default) " ) ) ;
MarginL - > SetMaxLength ( 4 ) ;
2006-12-24 17:17:40 +01:00
MarginR = new HiliModTextCtrl ( this , MARGINR_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 40 , 20 ) , wxTE_CENTRE | wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-12-30 15:31:41 +01:00
MarginR - > SetToolTip ( _ ( " Right Margin (0 = default) " ) ) ;
MarginR - > SetMaxLength ( 4 ) ;
2006-12-24 17:17:40 +01:00
MarginV = new HiliModTextCtrl ( this , MARGINV_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 40 , 20 ) , wxTE_CENTRE | wxTE_PROCESS_ENTER , NumValidator ( ) ) ;
2006-12-30 15:31:41 +01:00
MarginV - > SetToolTip ( _ ( " Vertical Margin (0 = default) " ) ) ;
MarginV - > SetMaxLength ( 4 ) ;
2006-01-16 22:02:54 +01:00
// Middle-bottom controls
Bold = new wxBitmapButton ( this , BUTTON_BOLD , wxBITMAP ( button_bold ) , wxDefaultPosition , wxSize ( 20 , 20 ) ) ;
Bold - > SetToolTip ( _ ( " Bold " ) ) ;
Italics = new wxBitmapButton ( this , BUTTON_ITALICS , wxBITMAP ( button_italics ) , wxDefaultPosition , wxSize ( 20 , 20 ) ) ;
Italics - > SetToolTip ( _ ( " Italics " ) ) ;
Underline = new wxBitmapButton ( this , BUTTON_UNDERLINE , wxBITMAP ( button_underline ) , wxDefaultPosition , wxSize ( 20 , 20 ) ) ;
Underline - > SetToolTip ( _ ( " Underline " ) ) ;
Strikeout = new wxBitmapButton ( this , BUTTON_STRIKEOUT , wxBITMAP ( button_strikeout ) , wxDefaultPosition , wxSize ( 20 , 20 ) ) ;
Strikeout - > SetToolTip ( _ ( " Strikeout " ) ) ;
FontName = new wxBitmapButton ( this , BUTTON_FONT_NAME , wxBITMAP ( button_fontname ) , wxDefaultPosition , wxSize ( 30 , 20 ) ) ;
FontName - > SetToolTip ( _ ( " Font Face Name " ) ) ;
Color1 = new wxBitmapButton ( this , BUTTON_COLOR1 , wxBITMAP ( button_color1 ) , wxDefaultPosition , wxSize ( 30 , 20 ) ) ;
Color1 - > SetToolTip ( _ ( " Primary color " ) ) ;
Color2 = new wxBitmapButton ( this , BUTTON_COLOR2 , wxBITMAP ( button_color2 ) , wxDefaultPosition , wxSize ( 30 , 20 ) ) ;
Color2 - > SetToolTip ( _ ( " Secondary color " ) ) ;
Color3 = new wxBitmapButton ( this , BUTTON_COLOR3 , wxBITMAP ( button_color3 ) , wxDefaultPosition , wxSize ( 30 , 20 ) ) ;
Color3 - > SetToolTip ( _ ( " Outline color " ) ) ;
Color4 = new wxBitmapButton ( this , BUTTON_COLOR4 , wxBITMAP ( button_color4 ) , wxDefaultPosition , wxSize ( 30 , 20 ) ) ;
Color4 - > SetToolTip ( _ ( " Shadow color " ) ) ;
2006-12-24 17:17:40 +01:00
ByTime = new wxRadioButton ( this , RADIO_TIME_BY_TIME , _ ( " Time " ) , wxDefaultPosition , wxDefaultSize , wxRB_GROUP ) ;
ByTime - > SetToolTip ( _ ( " Time by h:mm:ss.cs " ) ) ;
ByFrame = new wxRadioButton ( this , RADIO_TIME_BY_FRAME , _ ( " Frame " ) ) ;
ByFrame - > SetToolTip ( _ ( " Time by frame number " ) ) ;
2006-06-27 06:13:34 +02:00
// Top sizer
2006-12-27 01:00:41 +01:00
TopSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2006-06-27 06:13:34 +02:00
TopSizer - > Add ( CommentBox , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
2006-12-27 01:00:41 +01:00
TopSizer - > Add ( StyleBox , 1 , wxRIGHT , 5 ) ;
TopSizer - > Add ( ActorBox , 1 , wxRIGHT , 5 ) ;
TopSizer - > Add ( Effect , 1 , 0 , 0 ) ;
2006-06-27 06:13:34 +02:00
// Middle sizer
2006-12-27 01:00:41 +01:00
splitLineMode = true ;
MiddleSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2006-06-27 06:13:34 +02:00
MiddleSizer - > Add ( Layer , 0 , wxRIGHT , 5 ) ;
MiddleSizer - > Add ( StartTime , 0 , wxRIGHT , 0 ) ;
MiddleSizer - > Add ( EndTime , 0 , wxRIGHT , 5 ) ;
MiddleSizer - > Add ( Duration , 0 , wxRIGHT , 5 ) ;
MiddleSizer - > Add ( MarginL , 0 , 0 , 0 ) ;
MiddleSizer - > Add ( MarginR , 0 , 0 , 0 ) ;
MiddleSizer - > Add ( MarginV , 0 , 0 , 0 ) ;
2006-12-27 01:00:41 +01:00
MiddleSizer - > AddSpacer ( 5 ) ;
2006-01-16 22:02:54 +01:00
// Middle-bottom sizer
2006-12-27 01:00:41 +01:00
MiddleBotSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2006-01-16 22:02:54 +01:00
MiddleBotSizer - > Add ( Bold ) ;
MiddleBotSizer - > Add ( Italics ) ;
MiddleBotSizer - > Add ( Underline ) ;
MiddleBotSizer - > Add ( Strikeout ) ;
MiddleBotSizer - > Add ( FontName ) ;
MiddleBotSizer - > AddSpacer ( 5 ) ;
MiddleBotSizer - > Add ( Color1 ) ;
MiddleBotSizer - > Add ( Color2 ) ;
MiddleBotSizer - > Add ( Color3 ) ;
2006-06-27 06:13:34 +02:00
MiddleBotSizer - > Add ( Color4 , 0 , wxRIGHT , 10 ) ;
MiddleBotSizer - > Add ( ByTime , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
MiddleBotSizer - > Add ( ByFrame , 0 , wxRIGHT | wxALIGN_CENTER , 5 ) ;
2006-01-16 22:02:54 +01:00
// Text editor
2006-12-27 01:00:41 +01:00
TextEdit = new SubsTextEditCtrl ( this , EDIT_BOX , _T ( " " ) , wxDefaultPosition , wxSize ( 300 , 50 ) ) ;
2006-01-16 22:02:54 +01:00
TextEdit - > PushEventHandler ( new SubsEditBoxEvent ( this ) ) ;
TextEdit - > control = 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
2006-12-27 01:00:41 +01:00
MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Add ( TopSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxTOP , 3 ) ;
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 ) ;
// Set sizer
SetSizer ( MainSizer ) ;
MainSizer - > SetSizeHints ( this ) ;
// HACK: Fix colour of bg of editbox
origBgColour = TextEdit - > GetBackgroundColour ( ) ;
disabledBgColour = GetBackgroundColour ( ) ;
2006-12-27 01:00:41 +01:00
// Set split mode
setupDone = true ;
SetSplitLineMode ( ) ;
2006-02-19 01:54:35 +01:00
Update ( ) ;
2006-01-16 22:02:54 +01:00
}
2006-12-27 01:00:41 +01:00
/////////////////////////////////
// Set split or single line mode
void SubsEditBox : : SetSplitLineMode ( wxSize newSize ) {
// Widths
int topWidth ;
if ( newSize . GetWidth ( ) = = - 1 ) topWidth = TopSizer - > GetSize ( ) . GetWidth ( ) ;
else topWidth = newSize . GetWidth ( ) - GetSize ( ) . GetWidth ( ) + GetClientSize ( ) . GetWidth ( ) ;
int midMin = MiddleSizer - > GetMinSize ( ) . GetWidth ( ) ;
int botMin = MiddleBotSizer - > GetMinSize ( ) . GetWidth ( ) ;
// Currently split
if ( splitLineMode ) {
if ( topWidth > = midMin + botMin ) {
MainSizer - > Detach ( MiddleBotSizer ) ;
MiddleSizer - > Add ( MiddleBotSizer ) ;
Layout ( ) ;
splitLineMode = false ;
}
}
// Currently joined
else {
if ( topWidth < midMin ) {
MiddleSizer - > Detach ( MiddleBotSizer ) ;
MainSizer - > Insert ( 2 , MiddleBotSizer , 0 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 3 ) ;
Layout ( ) ;
splitLineMode = true ;
}
}
}
2006-01-16 22:02:54 +01:00
///////////////////
// Update function
void SubsEditBox : : Update ( bool timeOnly ) {
if ( enabled ) {
AssDialogue * curdiag = grid - > GetDialogue ( linen ) ;
if ( curdiag ) {
// Controls
SetControlsState ( true ) ;
int start = curdiag - > Start . GetMS ( ) ;
int end = curdiag - > End . GetMS ( ) ;
StartTime - > SetTime ( start ) ;
EndTime - > SetTime ( end ) ;
Duration - > SetTime ( end - start ) ;
if ( ! timeOnly ) {
2006-12-24 18:42:09 +01:00
TextEdit - > SetTextTo ( curdiag - > Text ) ;
2006-01-16 22:02:54 +01:00
Layer - > SetValue ( wxString : : Format ( _T ( " %i " ) , curdiag - > Layer ) ) ;
2006-12-30 15:31:41 +01:00
MarginL - > SetValue ( curdiag - > GetMarginString ( 1 , false ) ) ;
MarginR - > SetValue ( curdiag - > GetMarginString ( 2 , false ) ) ;
MarginV - > SetValue ( curdiag - > GetMarginString ( 3 , false ) ) ;
2006-06-27 06:13:34 +02:00
Effect - > SetValue ( curdiag - > Effect ) ;
2006-01-16 22:02:54 +01:00
CommentBox - > SetValue ( curdiag - > Comment ) ;
StyleBox - > Select ( StyleBox - > FindString ( curdiag - > Style ) ) ;
ActorBox - > SetValue ( curdiag - > Actor ) ;
ActorBox - > SetStringSelection ( curdiag - > Actor ) ;
2006-12-29 04:02:17 +01:00
// Force actor box to update its idle status
wxCommandEvent changeEvent ( wxEVT_COMMAND_TEXT_UPDATED , ActorBox - > GetId ( ) ) ;
ActorBox - > GetEventHandler ( ) - > AddPendingEvent ( changeEvent ) ;
2006-01-16 22:02:54 +01:00
}
// Audio
audio - > SetDialogue ( grid , curdiag , linen ) ;
// Video
video - > curLine = curdiag ;
video - > UpdateSubsRelativeTime ( ) ;
}
else enabled = false ;
}
else {
SetControlsState ( false ) ;
}
}
//////////////////
// Update globals
void SubsEditBox : : UpdateGlobals ( ) {
// Styles
StyleBox - > Clear ( ) ;
StyleBox - > Append ( grid - > ass - > GetStyles ( ) ) ;
// Actors
ActorBox - > Freeze ( ) ;
ActorBox - > Clear ( ) ;
int nrows = grid - > GetRows ( ) ;
wxString actor ;
for ( int i = 0 ; i < nrows ; i + + ) {
actor = grid - > GetDialogue ( i ) - > Actor ;
if ( ActorBox - > FindString ( actor ) = = wxNOT_FOUND ) {
ActorBox - > Append ( actor ) ;
}
}
ActorBox - > Thaw ( ) ;
// Set subs update
linen = - 2 ;
TextEdit - > SetSelection ( 0 , 0 ) ;
SetToLine ( grid - > GetFirstSelRow ( ) ) ;
}
//////////////////
// Jump to a line
void SubsEditBox : : SetToLine ( int n ) {
// Set to nothing
if ( n = = - 1 ) {
enabled = false ;
}
// Set line
else if ( grid - > GetDialogue ( n ) ) {
enabled = true ;
if ( n ! = linen ) {
linen = n ;
StartTime - > Update ( ) ;
EndTime - > Update ( ) ;
}
}
// Update controls
Update ( ) ;
// Set video
if ( video - > loaded ) {
2006-03-05 21:42:38 +01:00
wxString sync ;
if ( Search . hasFocus ) sync = _T ( " Find update video " ) ;
else sync = _T ( " Sync video with subs " ) ;
if ( Options . AsBool ( sync ) = = true ) {
2006-01-16 22:02:54 +01:00
video - > Stop ( ) ;
AssDialogue * cur = grid - > GetDialogue ( n ) ;
2006-02-24 17:45:10 +01:00
if ( cur ) video - > JumpToFrame ( VFR_Output . GetFrameAtTime ( cur - > Start . GetMS ( ) , true ) ) ;
2006-01-16 22:02:54 +01:00
}
}
}
///////////////
// Event table
BEGIN_EVENT_TABLE ( SubsEditBox , wxPanel )
2007-01-02 06:00:55 +01:00
EVT_SCI_MODIFIED ( EDIT_BOX , SubsEditBox : : OnEditText )
2006-12-24 05:54:35 +01:00
EVT_SCI_STYLENEEDED ( EDIT_BOX , SubsEditBox : : OnNeedStyle )
2006-12-24 17:17:40 +01:00
EVT_SCI_KEY ( EDIT_BOX , SubsEditBox : : OnKeyDown )
2007-01-02 06:00:55 +01:00
EVT_SCI_CHARADDED ( EDIT_BOX , SubsEditBox : : OnCharAdded )
2006-01-16 22:02:54 +01:00
EVT_CHECKBOX ( SYNTAX_BOX , SubsEditBox : : OnSyntaxBox )
EVT_RADIOBUTTON ( RADIO_TIME_BY_FRAME , SubsEditBox : : OnFrameRadio )
EVT_RADIOBUTTON ( RADIO_TIME_BY_TIME , SubsEditBox : : OnTimeRadio )
EVT_COMBOBOX ( STYLE_COMBOBOX , SubsEditBox : : OnStyleChange )
EVT_COMBOBOX ( ACTOR_COMBOBOX , SubsEditBox : : OnActorChange )
EVT_TEXT_ENTER ( ACTOR_COMBOBOX , SubsEditBox : : OnActorChange )
EVT_TEXT_ENTER ( LAYER_BOX , SubsEditBox : : OnLayerChange )
EVT_TEXT_ENTER ( STARTTIME_BOX , SubsEditBox : : OnStartTimeChange )
EVT_TEXT_ENTER ( ENDTIME_BOX , SubsEditBox : : OnEndTimeChange )
EVT_TEXT_ENTER ( DURATION_BOX , SubsEditBox : : OnDurationChange )
EVT_TEXT_ENTER ( MARGINL_BOX , SubsEditBox : : OnMarginLChange )
EVT_TEXT_ENTER ( MARGINR_BOX , SubsEditBox : : OnMarginRChange )
EVT_TEXT_ENTER ( MARGINV_BOX , SubsEditBox : : OnMarginVChange )
2006-06-27 06:13:34 +02:00
EVT_TEXT_ENTER ( EFFECT_BOX , SubsEditBox : : OnEffectChange )
2006-01-16 22:02:54 +01:00
EVT_CHECKBOX ( COMMENT_CHECKBOX , SubsEditBox : : OnCommentChange )
EVT_BUTTON ( BUTTON_COLOR1 , SubsEditBox : : OnButtonColor1 )
EVT_BUTTON ( BUTTON_COLOR2 , SubsEditBox : : OnButtonColor2 )
EVT_BUTTON ( BUTTON_COLOR3 , SubsEditBox : : OnButtonColor3 )
EVT_BUTTON ( BUTTON_COLOR4 , SubsEditBox : : OnButtonColor4 )
EVT_BUTTON ( BUTTON_FONT_NAME , SubsEditBox : : OnButtonFontFace )
EVT_BUTTON ( BUTTON_BOLD , SubsEditBox : : OnButtonBold )
EVT_BUTTON ( BUTTON_ITALICS , SubsEditBox : : OnButtonItalics )
EVT_BUTTON ( BUTTON_UNDERLINE , SubsEditBox : : OnButtonUnderline )
EVT_BUTTON ( BUTTON_STRIKEOUT , SubsEditBox : : OnButtonStrikeout )
2006-12-27 01:00:41 +01:00
EVT_SIZE ( SubsEditBox : : OnSize )
2006-01-16 22:02:54 +01:00
END_EVENT_TABLE ( )
2006-12-27 01:00:41 +01:00
///////////
// On size
void SubsEditBox : : OnSize ( wxSizeEvent & event ) {
if ( setupDone ) SetSplitLineMode ( event . GetSize ( ) ) ;
event . Skip ( ) ;
}
2006-01-16 22:02:54 +01:00
/////////////////////
// Text edited event
2006-12-24 05:54:35 +01:00
void SubsEditBox : : OnEditText ( wxScintillaEvent & event ) {
2007-01-02 06:00:55 +01:00
int modType = event . GetModificationType ( ) ;
if ( modType = = ( wxSCI_MOD_INSERTTEXT | wxSCI_PERFORMED_USER ) | | modType = = ( wxSCI_MOD_DELETETEXT | wxSCI_PERFORMED_USER ) ) {
//TextEdit->UpdateCallTip();
}
2006-12-24 05:54:35 +01:00
}
//////////////
// Need style
void SubsEditBox : : OnNeedStyle ( wxScintillaEvent & event ) {
// Check if it needs to fix text
wxString text = TextEdit - > GetText ( ) ;
if ( text . Contains ( _T ( " \n " ) ) | | text . Contains ( _T ( " \r " ) ) ) {
2006-12-24 18:42:09 +01:00
TextEdit - > SetTextTo ( TextEdit - > GetText ( ) ) ;
2006-01-16 22:02:54 +01:00
}
2006-12-24 05:54:35 +01:00
// Just update style
2006-12-24 18:42:09 +01:00
else TextEdit - > UpdateStyle ( ) ;
2006-01-16 22:02:54 +01:00
}
2007-01-02 06:00:55 +01:00
///////////////////
// Character added
void SubsEditBox : : OnCharAdded ( wxScintillaEvent & event ) {
int character = event . GetKey ( ) ;
}
2006-01-16 22:02:54 +01:00
/////////////////////////////
// Syntax highlight checkbox
void SubsEditBox : : OnSyntaxBox ( wxCommandEvent & event ) {
2006-12-24 18:42:09 +01:00
TextEdit - > UpdateStyle ( ) ;
2006-01-16 22:02:54 +01:00
Options . SetBool ( _T ( " Syntax Highlight Enabled " ) , SyntaxHighlight - > GetValue ( ) ) ;
Options . Save ( ) ;
event . Skip ( ) ;
}
//////////////////////////
// Time by frame radiobox
void SubsEditBox : : OnFrameRadio ( wxCommandEvent & event ) {
if ( ByFrame - > GetValue ( ) ) {
StartTime - > SetByFrame ( true ) ;
EndTime - > SetByFrame ( true ) ;
grid - > SetByFrame ( true ) ;
}
event . Skip ( ) ;
}
//////////////////////////
// Standard time radiobox
void SubsEditBox : : OnTimeRadio ( wxCommandEvent & event ) {
if ( ByTime - > GetValue ( ) ) {
StartTime - > SetByFrame ( false ) ;
EndTime - > SetByFrame ( false ) ;
grid - > SetByFrame ( false ) ;
}
event . Skip ( ) ;
}
////////////
// Key down
2006-12-24 17:17:40 +01:00
void SubsEditBox : : OnKeyDown ( wxScintillaEvent & event ) {
2006-01-16 22:02:54 +01:00
event . Skip ( ) ;
}
//////////////////////////////////////////////////
// Sets state (enabled/disabled) for all controls
void SubsEditBox : : SetControlsState ( bool state ) {
if ( state = = controlState ) return ;
controlState = state ;
// HACK: TextEdit workaround the stupid colour lock bug
2006-12-24 05:54:35 +01:00
TextEdit - > SetReadOnly ( ! state ) ;
2006-01-16 22:02:54 +01:00
if ( state ) TextEdit - > SetBackgroundColour ( origBgColour ) ;
else TextEdit - > SetBackgroundColour ( disabledBgColour ) ;
// Sets controls
StartTime - > Enable ( state ) ;
EndTime - > Enable ( state ) ;
Duration - > Enable ( state ) ;
Layer - > Enable ( state ) ;
MarginL - > Enable ( state ) ;
MarginR - > Enable ( state ) ;
MarginV - > Enable ( state ) ;
2006-06-27 06:13:34 +02:00
Effect - > Enable ( state ) ;
2006-01-16 22:02:54 +01:00
CommentBox - > Enable ( state ) ;
StyleBox - > Enable ( state ) ;
ActorBox - > Enable ( state ) ;
ByTime - > Enable ( state ) ;
2006-03-20 22:48:01 +01:00
//SyntaxHighlight->Enable(state);
2006-01-16 22:02:54 +01:00
Bold - > Enable ( state ) ;
Italics - > Enable ( state ) ;
Underline - > Enable ( state ) ;
Strikeout - > Enable ( state ) ;
Color1 - > Enable ( state ) ;
Color2 - > Enable ( state ) ;
Color3 - > Enable ( state ) ;
Color4 - > Enable ( state ) ;
FontName - > Enable ( state ) ;
UpdateFrameTiming ( ) ;
// Clear values if it's false
if ( state = = false ) {
2006-12-24 18:42:09 +01:00
TextEdit - > SetTextTo ( _T ( " " ) ) ;
2006-01-16 22:02:54 +01:00
StartTime - > SetTime ( 0 ) ;
EndTime - > SetTime ( 0 ) ;
Layer - > SetValue ( _T ( " " ) ) ;
MarginL - > SetValue ( _T ( " " ) ) ;
MarginR - > SetValue ( _T ( " " ) ) ;
MarginV - > SetValue ( _T ( " " ) ) ;
2006-06-27 06:13:34 +02:00
Effect - > SetValue ( _T ( " " ) ) ;
2006-01-16 22:02:54 +01:00
CommentBox - > SetValue ( false ) ;
}
}
////////////////////////////////////
// Disables or enables frame timing
void SubsEditBox : : UpdateFrameTiming ( ) {
2006-06-27 21:11:41 +02:00
if ( VFR_Output . IsLoaded ( ) ) ByFrame - > Enable ( enabled ) ;
2006-01-16 22:02:54 +01:00
else {
ByFrame - > Enable ( false ) ;
ByTime - > SetValue ( true ) ;
StartTime - > SetByFrame ( false ) ;
EndTime - > SetByFrame ( false ) ;
grid - > SetByFrame ( false ) ;
}
}
/////////////////
// Style changed
void SubsEditBox : : OnStyleChange ( wxCommandEvent & event ) {
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > Style = StyleBox - > GetValue ( ) ;
cur - > UpdateData ( ) ;
}
}
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
/////////////////
// Style changed
void SubsEditBox : : OnActorChange ( wxCommandEvent & event ) {
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
AssDialogue * cur ;
wxString actor = ActorBox - > GetValue ( ) ;
// Update rows
int n = sel . Count ( ) ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > Actor = actor ;
cur - > UpdateData ( ) ;
}
}
// Add actor to list
2006-02-20 22:32:58 +01:00
if ( ActorBox - > GetString ( 0 ) . IsEmpty ( ) ) ActorBox - > Delete ( 0 ) ;
2006-01-16 22:02:54 +01:00
if ( ActorBox - > FindString ( actor ) = = wxNOT_FOUND ) {
ActorBox - > Append ( actor ) ;
}
// Update grid
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
/////////////////
// Layer changed
void SubsEditBox : : OnLayerChange ( wxCommandEvent & event ) {
2006-12-30 15:31:41 +01:00
// Value
long temp ;
Layer - > GetValue ( ) . ToLong ( & temp ) ;
// Update
2006-01-16 22:02:54 +01:00
Layer - > Commited ( ) ;
grid - > BeginBatch ( ) ;
2006-12-30 15:31:41 +01:00
// Get selection
2006-01-16 22:02:54 +01:00
wxArrayInt sel = grid - > GetSelection ( ) ;
2006-12-30 15:31:41 +01:00
// Update
2006-01-16 22:02:54 +01:00
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > Layer = temp ;
cur - > UpdateData ( ) ;
}
}
2006-12-30 15:31:41 +01:00
// Done
Layer - > SetValue ( wxString : : Format ( _ ( " %i " ) , temp ) ) ;
2006-01-16 22:02:54 +01:00
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
//////////////////////
// Start time changed
void SubsEditBox : : OnStartTimeChange ( wxCommandEvent & event ) {
if ( StartTime - > time > EndTime - > time ) StartTime - > SetTime ( EndTime - > time . GetMS ( ) ) ;
2006-02-19 04:33:13 +01:00
bool join = Options . AsBool ( _T ( " Link Time Boxes Commit " ) ) & & EndTime - > HasBeenModified ( ) ;
2006-01-16 22:02:54 +01:00
StartTime - > Update ( ) ;
if ( join ) EndTime - > Update ( ) ;
2006-02-19 04:33:13 +01:00
CommitTimes ( true , join , true ) ;
2006-01-16 22:02:54 +01:00
}
////////////////////
// End time changed
void SubsEditBox : : OnEndTimeChange ( wxCommandEvent & event ) {
if ( StartTime - > time > EndTime - > time ) EndTime - > SetTime ( StartTime - > time . GetMS ( ) ) ;
2006-02-19 04:33:13 +01:00
bool join = Options . AsBool ( _T ( " Link Time Boxes Commit " ) ) & & StartTime - > HasBeenModified ( ) ;
2006-01-16 22:02:54 +01:00
EndTime - > Update ( ) ;
if ( join ) StartTime - > Update ( ) ;
2006-02-19 04:33:13 +01:00
CommitTimes ( join , true , false ) ;
2006-01-16 22:02:54 +01:00
}
////////////////////
// Duration changed
void SubsEditBox : : OnDurationChange ( wxCommandEvent & event ) {
EndTime - > SetTime ( StartTime - > time . GetMS ( ) + Duration - > time . GetMS ( ) ) ;
Duration - > Update ( ) ;
2006-02-19 04:33:13 +01:00
CommitTimes ( false , true , true ) ;
2006-01-16 22:02:54 +01:00
}
///////////////////////
// Commit time changes
2006-02-19 04:33:13 +01:00
void SubsEditBox : : CommitTimes ( bool start , bool end , bool fromStart ) {
2006-01-16 22:02:54 +01:00
// Get selection
if ( ! start & & ! end ) return ;
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
if ( n = = 0 ) return ;
AssDialogue * cur ;
Duration - > SetTime ( EndTime - > time . GetMS ( ) - StartTime - > time . GetMS ( ) ) ;
// Update lines
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
2006-02-19 04:33:13 +01:00
// Set times
2006-01-16 22:02:54 +01:00
if ( start ) cur - > Start = StartTime - > time ;
if ( end ) cur - > End = EndTime - > time ;
2006-02-19 04:33:13 +01:00
// Ensure that they have positive length
if ( cur - > Start > cur - > End ) {
if ( fromStart ) cur - > End = cur - > Start ;
else cur - > Start = cur - > End ;
}
// Update
2006-01-16 22:02:54 +01:00
cur - > UpdateData ( ) ;
}
}
// Commit
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
audio - > SetDialogue ( grid , grid - > GetDialogue ( sel [ 0 ] ) , sel [ 0 ] ) ;
video - > UpdateSubsRelativeTime ( ) ;
}
////////////////////
// Margin L changed
void SubsEditBox : : OnMarginLChange ( wxCommandEvent & event ) {
MarginL - > Commited ( ) ;
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > SetMarginString ( MarginL - > GetValue ( ) , 1 ) ;
cur - > UpdateData ( ) ;
}
}
2006-12-30 15:31:41 +01:00
MarginL - > SetValue ( cur - > GetMarginString ( 1 , false ) ) ;
2006-01-16 22:02:54 +01:00
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
////////////////////
// Margin R changed
void SubsEditBox : : OnMarginRChange ( wxCommandEvent & event ) {
MarginR - > Commited ( ) ;
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > SetMarginString ( MarginR - > GetValue ( ) , 2 ) ;
cur - > UpdateData ( ) ;
}
}
2006-12-30 15:31:41 +01:00
MarginR - > SetValue ( cur - > GetMarginString ( 2 , false ) ) ;
2006-01-16 22:02:54 +01:00
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
////////////////////
// Margin V changed
void SubsEditBox : : OnMarginVChange ( wxCommandEvent & event ) {
MarginV - > Commited ( ) ;
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > SetMarginString ( MarginV - > GetValue ( ) , 3 ) ;
cur - > UpdateData ( ) ;
}
}
2006-12-30 15:31:41 +01:00
MarginV - > SetValue ( cur - > GetMarginString ( 3 , false ) ) ;
2006-01-16 22:02:54 +01:00
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
2006-06-27 06:13:34 +02:00
//////////////////
// Effect changed
void SubsEditBox : : OnEffectChange ( wxCommandEvent & event ) {
Effect - > Commited ( ) ;
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > Effect = Effect - > GetValue ( ) ;
cur - > UpdateData ( ) ;
}
}
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
2006-01-16 22:02:54 +01:00
/////////////////////////
// Comment state changed
void SubsEditBox : : OnCommentChange ( wxCommandEvent & event ) {
grid - > BeginBatch ( ) ;
wxArrayInt sel = grid - > GetSelection ( ) ;
int n = sel . Count ( ) ;
AssDialogue * cur ;
for ( int i = 0 ; i < n ; i + + ) {
cur = grid - > GetDialogue ( sel [ i ] ) ;
if ( cur ) {
cur - > Comment = CommentBox - > GetValue ( ) ;
cur - > UpdateData ( ) ;
}
}
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
grid - > EndBatch ( ) ;
}
///////////////////////
// Event handler class
SubsEditBoxEvent : : SubsEditBoxEvent ( SubsEditBox * _control ) {
control = _control ;
}
BEGIN_EVENT_TABLE ( SubsEditBoxEvent , wxEvtHandler )
EVT_KEY_DOWN ( SubsEditBoxEvent : : OnKeyPress )
END_EVENT_TABLE ( )
void SubsEditBoxEvent : : OnKeyPress ( wxKeyEvent & event ) {
control - > KeyPress ( event ) ;
}
///////////////////////
// Actual text changed
void SubsEditBox : : KeyPress ( wxKeyEvent & event ) {
int key = event . GetKeyCode ( ) ;
if ( key = = WXK_RETURN | | key = = WXK_NUMPAD_ENTER ) {
if ( enabled ) {
// Update line
CommitText ( ) ;
// Next line if control is not held down
bool updated = false ;
if ( ! event . m_controlDown ) {
AssDialogue * cur = grid - > GetDialogue ( linen ) ;
int nrows = grid - > GetRows ( ) ;
int next = linen + 1 ;
if ( next > = nrows ) {
AssDialogue * newline = new AssDialogue ;
newline - > Start = cur - > End ;
newline - > End . SetMS ( cur - > End . GetMS ( ) + 5000 ) ;
newline - > Style = cur - > Style ;
newline - > UpdateData ( ) ;
grid - > InsertLine ( newline , next - 1 , true , true ) ;
updated = true ;
}
grid - > SelectRow ( next ) ;
grid - > MakeCellVisible ( next , 0 ) ;
SetToLine ( next ) ;
if ( next > = nrows ) return ;
}
// Update file
if ( ! updated ) {
grid - > ass - > FlagAsModified ( ) ;
grid - > CommitChanges ( ) ;
}
return ;
}
}
event . Skip ( ) ;
}
///////////////
// Commit text
void SubsEditBox : : CommitText ( ) {
AssDialogue * cur = grid - > GetDialogue ( linen ) ;
// Update line
if ( cur ) {
2006-12-24 05:54:35 +01:00
cur - > Text = TextEdit - > GetText ( ) ;
2006-02-21 04:13:35 +01:00
//cur->ParseASSTags();
2006-01-16 22:02:54 +01:00
cur - > UpdateData ( ) ;
2006-02-22 05:59:39 +01:00
grid - > Refresh ( false ) ;
2006-01-16 22:02:54 +01:00
audio - > SetDialogue ( grid , cur , linen ) ;
}
}
//////////////////////////////////////
// Gets block number at text position
int SubsEditBox : : BlockAtPos ( int pos ) {
// Prepare
int n = 0 ;
2006-12-24 05:54:35 +01:00
wxString text = TextEdit - > GetText ( ) ; ;
2006-01-16 22:02:54 +01:00
int max = text . Length ( ) - 1 ;
// Find block number at pos
for ( int i = 0 ; i < = pos ; i + + ) {
if ( i > 0 & & text [ i ] = = _T ( ' { ' ) ) n + + ;
if ( text [ i ] = = _T ( ' } ' ) & & i ! = max & & i ! = pos & & i ! = pos - 1 & & ( i + 1 = = max | | text [ i + 1 ] ! = _T ( ' { ' ) ) ) n + + ;
}
return n ;
}
2006-02-19 05:55:10 +01:00
////////////////
// Set override
void SubsEditBox : : SetOverride ( wxString tagname , wxString preValue , int forcePos ) {
2006-01-16 22:02:54 +01:00
// Selection
2006-12-24 05:54:35 +01:00
int selstart , selend ;
2006-01-16 22:02:54 +01:00
if ( forcePos ! = - 1 ) {
selstart = forcePos ;
selend = forcePos ;
}
else TextEdit - > GetSelection ( & selstart , & selend ) ;
2006-12-24 05:54:35 +01:00
int len = TextEdit - > GetText ( ) . Length ( ) ;
2006-02-19 05:55:10 +01:00
selstart = MID ( 0 , selstart , len ) ;
selend = MID ( 0 , selend , len ) ;
// Current tag name
wxString alttagname = tagname ;
if ( tagname = = _T ( " \\ 1c " ) ) tagname = _T ( " \\ c " ) ;
2006-01-16 22:02:54 +01:00
// Get block at start
size_t blockn = BlockAtPos ( selstart ) ;
AssDialogue * line = new AssDialogue ( ) ;
2006-12-24 05:54:35 +01:00
line - > Text = TextEdit - > GetText ( ) ;
2006-01-16 22:02:54 +01:00
line - > ParseASSTags ( ) ;
AssDialogueBlock * block = line - > Blocks . at ( blockn ) ;
2006-02-19 05:55:10 +01:00
// Insert variables
wxString insert ;
wxString insert2 ;
int shift ;
2006-07-13 04:10:19 +02:00
int nInserted = 1 ;
2006-01-16 22:02:54 +01:00
2006-02-19 05:55:10 +01:00
// Default value
wxColour startcolor ;
2006-02-21 23:46:18 +01:00
wxFont startfont ;
2006-01-16 22:02:54 +01:00
bool isColor = false ;
bool isFont = false ;
bool isPos = false ;
2006-02-19 05:55:10 +01:00
bool isFlag = false ;
bool state = false ;
2006-01-16 22:02:54 +01:00
AssStyle * style = AssFile : : top - > GetStyle ( grid - > GetDialogue ( linen ) - > Style ) ;
AssStyle defStyle ;
if ( style = = NULL ) style = & defStyle ;
2006-02-19 05:55:10 +01:00
if ( tagname = = _T ( " \\ b " ) ) {
state = style - > bold ;
isFlag = true ;
}
else if ( tagname = = _T ( " \\ i " ) ) {
state = style - > italic ;
isFlag = true ;
}
else if ( tagname = = _T ( " \\ u " ) ) {
state = style - > underline ;
isFlag = true ;
}
else if ( tagname = = _T ( " \\ s " ) ) {
state = style - > strikeout ;
isFlag = true ;
}
else if ( tagname = = _T ( " \\ fn " ) ) {
2006-02-21 23:46:18 +01:00
startfont . SetFaceName ( style - > font ) ;
startfont . SetPointSize ( style - > fontsize ) ;
startfont . SetWeight ( style - > bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL ) ;
startfont . SetStyle ( style - > italic ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL ) ;
startfont . SetUnderlined ( style - > underline ) ;
2006-02-19 05:55:10 +01:00
isFont = true ;
}
else if ( tagname = = _T ( " \\ c " ) ) {
2006-01-16 22:02:54 +01:00
startcolor = style - > primary . GetWXColor ( ) ;
isColor = true ;
}
else if ( tagname = = _T ( " \\ 2c " ) ) {
startcolor = style - > secondary . GetWXColor ( ) ;
isColor = true ;
}
else if ( tagname = = _T ( " \\ 3c " ) ) {
startcolor = style - > outline . GetWXColor ( ) ;
isColor = true ;
}
else if ( tagname = = _T ( " \\ 4c " ) ) {
startcolor = style - > shadow . GetWXColor ( ) ;
isColor = true ;
}
2006-02-23 21:08:31 +01:00
else if ( tagname = = _T ( " \\ pos " ) ) {
isPos = true ;
}
2006-02-19 05:55:10 +01:00
bool hasEnd = isFlag ;
2006-01-16 22:02:54 +01:00
2006-02-19 05:55:10 +01:00
// Find current value of style
2006-01-16 22:02:54 +01:00
AssDialogueBlockOverride * override ;
AssOverrideTag * tag ;
2006-02-19 05:55:10 +01:00
if ( isFont | | isColor | | isFlag ) {
2006-01-16 22:02:54 +01:00
for ( size_t i = 0 ; i < = blockn ; i + + ) {
override = AssDialogueBlock : : GetAsOverride ( line - > Blocks . at ( i ) ) ;
if ( override ) {
for ( size_t j = 0 ; j < override - > Tags . size ( ) ; j + + ) {
tag = override - > Tags . at ( j ) ;
2006-02-21 23:46:18 +01:00
if ( tag - > Name = = tagname | | tag - > Name = = alttagname | | tagname = = _T ( " \\ fn " ) ) {
2006-01-16 22:02:54 +01:00
if ( isColor ) startcolor = tag - > Params . at ( 0 ) - > AsColour ( ) ;
2006-02-21 23:46:18 +01:00
if ( isFlag ) state = tag - > Params . at ( 0 ) - > AsBool ( ) ;
2006-02-21 23:32:51 +01:00
if ( isFont ) {
2006-02-21 23:46:18 +01:00
if ( tag - > Name = = _T ( " \\ fn " ) ) startfont . SetFaceName ( tag - > Params . at ( 0 ) - > AsText ( ) ) ;
if ( tag - > Name = = _T ( " \\ fs " ) ) startfont . SetPointSize ( tag - > Params . at ( 0 ) - > AsInt ( ) ) ;
if ( tag - > Name = = _T ( " \\ b " ) ) startfont . SetWeight ( ( tag - > Params . at ( 0 ) - > AsInt ( ) > 0 ) ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL ) ;
if ( tag - > Name = = _T ( " \\ i " ) ) startfont . SetStyle ( tag - > Params . at ( 0 ) - > AsBool ( ) ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL ) ;
if ( tag - > Name = = _T ( " \\ u " ) ) startfont . SetUnderlined ( tag - > Params . at ( 0 ) - > AsBool ( ) ) ;
2006-02-21 23:32:51 +01:00
}
2006-01-16 22:02:54 +01:00
}
}
}
}
}
2006-02-19 05:55:10 +01:00
// Toggle value
if ( isFlag ) {
state = ! state ;
int stateval = 0 ;
if ( state ) stateval = 1 ;
// Generate insert string
insert = tagname + wxString : : Format ( _T ( " %i " ) , stateval ) ;
insert2 = tagname + wxString : : Format ( _T ( " %i " ) , 1 - stateval ) ;
}
2006-01-16 22:02:54 +01:00
// Choose color
if ( isColor ) {
// Pick from dialog
//wxColour color = wxGetColourFromUser(this,startcolor);
2006-02-19 05:55:10 +01:00
wxColour color = GetColorFromUser ( ( ( AegisubApp * ) wxTheApp ) - > frame , startcolor ) ;
2006-01-16 22:02:54 +01:00
if ( ! color . Ok ( ) | | color = = startcolor ) return ;
// Generate insert string
AssColor asscolor ( color ) ;
insert = tagname + asscolor . GetASSFormatted ( false ) ;
}
// Choose font
if ( isFont ) {
// Pick from dialog
2006-02-21 23:46:18 +01:00
wxFont font = wxGetFontFromUser ( this , startfont ) ;
2006-01-16 22:02:54 +01:00
if ( ! font . Ok ( ) ) return ;
// Generate insert string
2006-07-13 04:10:19 +02:00
nInserted = 0 ;
if ( font . GetFaceName ( ) ! = startfont . GetFaceName ( ) ) {
insert = _T ( " \\ fn " ) + font . GetFaceName ( ) ;
nInserted + + ;
}
if ( font . GetPointSize ( ) ! = startfont . GetPointSize ( ) ) {
insert + = _T ( " \\ fs " ) + wxString : : Format ( _T ( " %i " ) , font . GetPointSize ( ) ) ;
nInserted + + ;
}
if ( font . GetWeight ( ) ! = startfont . GetWeight ( ) ) {
insert + = _T ( " \\ b " ) + wxString : : Format ( _T ( " %i " ) , font . GetWeight ( ) = = wxFONTWEIGHT_BOLD ? 1 : 0 ) ;
nInserted + + ;
}
if ( font . GetStyle ( ) ! = startfont . GetStyle ( ) ) {
insert + = _T ( " \\ i " ) + wxString : : Format ( _T ( " %i " ) , font . GetStyle ( ) = = wxFONTSTYLE_ITALIC ? 1 : 0 ) ;
nInserted + + ;
}
if ( font . GetUnderlined ( ) ! = startfont . GetUnderlined ( ) ) {
insert + = _T ( " \\ u " ) + wxString : : Format ( _T ( " %i " ) , font . GetUnderlined ( ) ? 1 : 0 ) ;
nInserted + + ;
}
2006-02-21 23:32:51 +01:00
if ( insert . IsEmpty ( ) ) return ;
2006-01-16 22:02:54 +01:00
}
// Pos
if ( isPos ) {
insert = tagname + preValue ;
}
// Get current block as plain or override
AssDialogueBlockPlain * plain = AssDialogueBlock : : GetAsPlain ( block ) ;
override = AssDialogueBlock : : GetAsOverride ( block ) ;
// Plain
if ( plain ) {
// Insert in text
line - > Text = line - > Text . Left ( selstart ) + _T ( " { " ) + insert + _T ( " } " ) + line - > Text . Mid ( selstart ) ;
shift = 2 + insert . Length ( ) ;
line - > ParseASSTags ( ) ;
}
// Override
else if ( override ) {
// Insert new tag
override - > text + = insert ;
override - > ParseTags ( ) ;
shift = insert . Length ( ) ;
// Remove old of same
2006-07-13 04:10:19 +02:00
for ( size_t i = 0 ; i < override - > Tags . size ( ) - nInserted ; i + + ) {
if ( insert . Contains ( override - > Tags . at ( i ) - > Name ) ) {
2006-01-16 22:02:54 +01:00
shift - = override - > Tags . at ( i ) - > ToString ( ) . Length ( ) ;
override - > Tags . erase ( override - > Tags . begin ( ) + i ) ;
i - - ;
}
}
// Update line
line - > UpdateText ( ) ;
}
// End
if ( hasEnd & & selend ! = selstart ) {
// Prepare variables again
2006-02-19 06:10:57 +01:00
int origStart = selstart ;
selstart = selend + shift ;
2006-01-16 22:02:54 +01:00
insert = insert2 ;
2006-12-24 18:42:09 +01:00
TextEdit - > SetTextTo ( line - > Text ) ;
2006-02-19 06:10:57 +01:00
blockn = BlockAtPos ( selstart ) ;
2006-01-16 22:02:54 +01:00
block = line - > Blocks . at ( blockn ) ;
plain = AssDialogueBlock : : GetAsPlain ( block ) ;
override = AssDialogueBlock : : GetAsOverride ( block ) ;
// Plain
if ( plain ) {
// Insert in text
line - > Text = line - > Text . Left ( selstart ) + _T ( " { " ) + insert + _T ( " } " ) + line - > Text . Mid ( selstart ) ;
}
// Override
else if ( override ) {
// Insert new tag
override - > text + = insert ;
override - > ParseTags ( ) ;
// Remove old of same
2006-07-13 04:10:19 +02:00
for ( size_t i = 0 ; i < override - > Tags . size ( ) - nInserted ; i + + ) {
if ( insert . Contains ( override - > Tags . at ( i ) - > Name ) ) {
2006-01-16 22:02:54 +01:00
shift - = override - > Tags . at ( i ) - > ToString ( ) . Length ( ) ;
override - > Tags . erase ( override - > Tags . begin ( ) + i ) ;
i - - ;
}
}
// Update line
line - > UpdateText ( ) ;
}
// Shift selection
2006-02-19 05:55:10 +01:00
selstart = origStart ;
2006-12-26 02:20:58 +01:00
TextEdit - > SetSelectionU ( origStart + shift , selend + shift ) ;
2006-01-16 22:02:54 +01:00
}
2006-02-19 05:55:10 +01:00
// Commit changes and shift selection
2006-12-24 18:42:09 +01:00
TextEdit - > SetTextTo ( line - > Text ) ;
2006-02-21 04:13:35 +01:00
line - > ClearBlocks ( ) ;
2006-12-26 02:20:58 +01:00
TextEdit - > SetSelectionU ( selstart + shift , selend + shift ) ;
2006-01-16 22:02:54 +01:00
TextEdit - > SetFocus ( ) ;
}
/////////////////////
// Set primary color
void SubsEditBox : : OnButtonColor1 ( wxCommandEvent & event ) {
SetOverride ( _T ( " \\ 1c " ) ) ;
}
///////////////////////
// Set secondary color
void SubsEditBox : : OnButtonColor2 ( wxCommandEvent & event ) {
SetOverride ( _T ( " \\ 2c " ) ) ;
}
/////////////////////
// Set outline color
void SubsEditBox : : OnButtonColor3 ( wxCommandEvent & event ) {
SetOverride ( _T ( " \\ 3c " ) ) ;
}
////////////////////
// Set shadow color
void SubsEditBox : : OnButtonColor4 ( wxCommandEvent & event ) {
SetOverride ( _T ( " \\ 4c " ) ) ;
}
/////////////////
// Set font face
void SubsEditBox : : OnButtonFontFace ( wxCommandEvent & event ) {
SetOverride ( _T ( " \\ fn " ) ) ;
}
////////
// Bold
void SubsEditBox : : OnButtonBold ( wxCommandEvent & event ) {
2006-02-19 05:55:10 +01:00
SetOverride ( _T ( " \\ b " ) ) ;
2006-01-16 22:02:54 +01:00
}
///////////
// Italics
void SubsEditBox : : OnButtonItalics ( wxCommandEvent & event ) {
2006-02-19 05:55:10 +01:00
SetOverride ( _T ( " \\ i " ) ) ;
2006-01-16 22:02:54 +01:00
}
/////////////
// Underline
void SubsEditBox : : OnButtonUnderline ( wxCommandEvent & event ) {
2006-02-19 05:55:10 +01:00
SetOverride ( _T ( " \\ u " ) ) ;
2006-01-16 22:02:54 +01:00
}
/////////////
// Strikeout
void SubsEditBox : : OnButtonStrikeout ( wxCommandEvent & event ) {
2006-02-19 05:55:10 +01:00
SetOverride ( _T ( " \\ s " ) ) ;
2006-01-16 22:02:54 +01:00
}