2006-01-16 22:02:54 +01:00
// Copyright (c) 2005, Rodrigo Braz Monteiro, Niels Martin Hansen
// 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 frame_main.cpp
/// @brief Main window creation and control management
/// @ingroup main_ui
2006-01-16 22:02:54 +01:00
2009-01-04 07:31:48 +01:00
# include "config.h"
2011-07-15 06:05:49 +02:00
# include "frame_main.h"
2009-09-10 15:06:40 +02:00
# ifndef AGI_PRE
2011-01-08 13:10:40 +01:00
# include <wx/clipbrd.h>
2011-11-30 00:18:24 +01:00
# include <wx/dnd.h>
2006-01-16 22:02:54 +01:00
# include <wx/filename.h>
2006-12-27 21:16:47 +01:00
# include <wx/image.h>
2009-09-10 15:06:40 +02:00
# include <wx/mimetype.h>
2007-09-12 01:22:26 +02:00
# include <wx/statline.h>
2009-09-10 15:06:40 +02:00
# include <wx/sysopt.h>
# include <wx/tokenzr.h>
# endif
2008-01-16 19:29:29 +01:00
2011-01-16 08:16:33 +01:00
# include <libaegisub/access.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
# include <libaegisub/log.h>
2011-01-16 08:16:00 +01:00
# include "include/aegisub/context.h"
2011-01-05 19:40:37 +01:00
# include "include/aegisub/menu.h"
# include "include/aegisub/toolbar.h"
# include "include/aegisub/hotkey.h"
2009-09-10 15:06:40 +02:00
# include "ass_file.h"
2010-12-08 04:36:10 +01:00
# include "audio_controller.h"
2009-09-10 15:06:40 +02:00
# include "audio_box.h"
# include "auto4_base.h"
2010-05-21 03:13:36 +02:00
# include "compat.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
# include "command/command.h"
2006-01-16 22:02:54 +01:00
# include "dialog_search_replace.h"
2009-09-10 15:06:40 +02:00
# include "dialog_version_check.h"
# include "help_button.h"
2009-07-24 02:08:25 +02:00
# include "libresrc/libresrc.h"
2009-09-10 15:06:40 +02:00
# include "main.h"
# include "standard_paths.h"
# include "subs_edit_box.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 "text_file_reader.h"
# include "utils.h"
# include "version.h"
# include "video_box.h"
# include "video_context.h"
# include "video_display.h"
# include "video_provider_manager.h"
# include "video_slider.h"
2006-01-16 22:02:54 +01:00
2011-07-15 06:05:49 +02:00
enum {
ID_APP_TIMER_AUTOSAVE = 12001 ,
ID_APP_TIMER_STATUSCLEAR = 12002 ,
ID_SASH_MAIN_AUDIO = 14001
} ;
2009-06-12 18:59:53 +02:00
# ifdef WITH_STARTUPLOG
2011-07-15 06:05:49 +02:00
# define StartupLog(a) MessageBox(0, a, "Aegisub startup log", 0)
2009-06-12 18:59:53 +02:00
# else
# define StartupLog(a)
# endif
2010-12-07 20:09:15 +01:00
static void autosave_timer_changed ( wxTimer * timer , const agi : : OptionValue & opt ) ;
2010-08-26 20:38:44 +02:00
2011-11-30 00:18:24 +01:00
/// Handle files drag and dropped onto Aegisub
class AegisubFileDropTarget : public wxFileDropTarget {
FrameMain * parent ;
public :
AegisubFileDropTarget ( FrameMain * parent ) : parent ( parent ) { }
bool OnDropFiles ( wxCoord , wxCoord , const wxArrayString & filenames ) {
return parent - > LoadList ( filenames ) ;
}
} ;
2006-01-16 22:02:54 +01:00
FrameMain : : FrameMain ( wxArrayString args )
2011-07-15 06:05:49 +02:00
: wxFrame ( 0 , - 1 , " " , wxDefaultPosition , wxSize ( 920 , 700 ) , wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN )
2011-01-16 08:16:54 +01:00
, context ( new agi : : Context )
, showVideo ( true )
, showAudio ( true )
, blockVideoLoad ( false )
2006-01-16 22:02:54 +01:00
{
2011-01-16 08:16:54 +01:00
StartupLog ( " Entering FrameMain constructor " ) ;
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
2007-04-03 06:34:56 +02:00
# ifdef __WXGTK__
2011-11-25 20:27:19 +01:00
// XXX HACK XXX
// We need to set LC_ALL to "" here for input methods to work reliably.
setlocale ( LC_ALL , " " ) ;
// However LC_NUMERIC must be "C", otherwise some parsing fails.
2007-04-03 06:34:56 +02:00
setlocale ( LC_NUMERIC , " C " ) ;
# endif
2011-11-25 20:29:17 +01:00
# ifdef __APPLE__
// Apple's wprintf() and family breaks with CTYPE set to "C"
setlocale ( LC_CTYPE , " " ) ;
# endif
2007-04-03 06:34:56 +02:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Initializing context models " ) ;
AssFile : : top = context - > ass = new AssFile ;
2011-01-20 06:57:23 +01:00
context - > ass - > AddCommitListener ( & FrameMain : : UpdateTitle , this ) ;
2011-01-16 08:16:54 +01:00
context - > ass - > AddFileOpenListener ( & FrameMain : : OnSubtitlesOpen , this ) ;
context - > ass - > AddFileSaveListener ( & FrameMain : : UpdateTitle , this ) ;
2006-01-16 22:02:54 +01:00
2011-09-28 21:45:55 +02:00
context - > local_scripts = new Automation4 : : LocalScriptManager ( context . get ( ) ) ;
2006-12-27 21:16:47 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Initializing context controls " ) ;
2011-09-28 21:51:35 +02:00
context - > audioController = new AudioController ( context . get ( ) ) ;
2011-01-16 08:16:54 +01:00
context - > audioController - > AddAudioOpenListener ( & FrameMain : : OnAudioOpen , this ) ;
context - > audioController - > AddAudioCloseListener ( & FrameMain : : OnAudioClose , this ) ;
2010-06-26 16:16:59 +02:00
2011-01-16 08:17:02 +01:00
// Initialized later due to that the selection controller is currently the subtitles grid
context - > selectionController = 0 ;
2011-01-16 08:16:54 +01:00
context - > videoController = VideoContext : : Get ( ) ; // derp
context - > videoController - > AddVideoOpenListener ( & FrameMain : : OnVideoOpen , this ) ;
StartupLog ( " Initializing context frames " ) ;
context - > parent = this ;
context - > previousFocus = 0 ;
AegisubApp : : Get ( ) - > frame = this ;
# ifdef __WXMAC__
// Bind(FrameMain::OnAbout, &FrameMain::cmd_call, this, cmd::id("app/about"));
2007-12-31 07:46:22 +01:00
# endif
2006-12-28 23:31:33 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Install PNG handler " ) ;
wxImage : : AddHandler ( new wxPNGHandler ) ;
2011-11-25 20:29:17 +01:00
# ifndef __APPLE__
2011-01-16 08:16:54 +01:00
wxSafeYield ( ) ;
2011-11-25 20:29:17 +01:00
# endif
2010-12-08 04:36:10 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Apply saved Maximized state " ) ;
2010-05-21 03:13:36 +02:00
if ( OPT_GET ( " App/Maximized " ) - > GetBool ( ) ) Maximize ( true ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Initialize toolbar " ) ;
2006-01-16 22:02:54 +01:00
InitToolbar ( ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Initialize menu bar " ) ;
2011-08-27 08:29:36 +02:00
menu : : GetMenuBar ( " main " , this , context . get ( ) ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Create status bar " ) ;
2006-12-28 23:31:33 +01:00
CreateStatusBar ( 2 ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Set icon " ) ;
2010-12-11 17:47:03 +01:00
# ifdef _WIN32
2009-07-25 22:32:58 +02:00
SetIcon ( wxICON ( wxicon ) ) ;
# else
2009-07-25 22:07:07 +02:00
wxIcon icon ;
2011-01-11 18:00:11 +01:00
icon . CopyFromBitmap ( GETIMAGE ( wxicon ) ) ;
2009-07-25 22:07:07 +02:00
SetIcon ( icon ) ;
2009-07-25 22:32:58 +02:00
# endif
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Create views and inner main window controls " ) ;
context - > detachedVideo = 0 ;
context - > stylingAssistant = 0 ;
2006-01-16 22:02:54 +01:00
InitContents ( ) ;
2011-07-30 01:16:36 +02:00
OPT_SUB ( " Video/Detached/Enabled " , & FrameMain : : OnVideoDetach , this , agi : : signal : : _1 ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:17:08 +01:00
StartupLog ( " Complete context initialization " ) ;
context - > videoController - > SetContext ( context . get ( ) ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Set up Auto Save " ) ;
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
AutoSave . SetOwner ( this , ID_APP_TIMER_AUTOSAVE ) ;
2010-05-21 03:13:36 +02:00
int time = OPT_GET ( " App/Auto/Save Every Seconds " ) - > GetInt ( ) ;
2006-01-16 22:02:54 +01:00
if ( time > 0 ) {
AutoSave . Start ( time * 1000 ) ;
}
2010-12-07 20:09:15 +01:00
OPT_SUB ( " App/Auto/Save Every Seconds " , autosave_timer_changed , & AutoSave , agi : : signal : : _1 ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Set up drag/drop target " ) ;
2006-01-16 22:02:54 +01:00
SetDropTarget ( new AegisubFileDropTarget ( this ) ) ;
2006-12-26 04:32:48 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Load default file " ) ;
context - > ass - > LoadDefault ( ) ;
2011-09-30 22:43:04 +02:00
StartupLog ( " Display main window " ) ;
Show ( ) ;
SetDisplayMode ( 1 , 1 ) ;
2007-01-07 23:54:04 +01:00
// Version checker
2011-01-16 08:16:54 +01:00
StartupLog ( " Possibly perform automatic updates check " ) ;
2010-08-26 20:38:03 +02:00
if ( OPT_GET ( " App/First Start " ) - > GetBool ( ) ) {
OPT_SET ( " App/First Start " ) - > SetBool ( false ) ;
2007-01-07 23:54:04 +01:00
int result = wxMessageBox ( _ ( " Do you want Aegisub to check for updates whenever it starts? You can still do it manually via the Help menu. " ) , _ ( " Check for updates? " ) , wxYES_NO ) ;
2010-08-26 20:38:03 +02:00
OPT_SET ( " App/Auto/Check For Updates " ) - > SetBool ( result = = wxYES ) ;
2007-01-07 23:54:04 +01:00
}
Merge 3906,r3909,r3910,r3912,r3928,r3931,r3932,r3933,r3935,r3936: merge update checker from 2.1.8, this also needs to be documented for doxygen. closes #1084.
Originally committed to SVN as r4042.
2010-01-26 14:14:05 +01:00
PerformVersionCheck ( false ) ;
2008-01-13 06:57:09 +01:00
2011-09-30 22:43:04 +02:00
StartupLog ( " Load files specified on command line " ) ;
LoadList ( args ) ;
2010-06-26 16:16:59 +02:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Leaving FrameMain constructor " ) ;
2006-01-16 22:02:54 +01:00
}
FrameMain : : ~ FrameMain ( ) {
2011-07-30 01:16:46 +02:00
// Because the subs grid is the selection controller, it needs to stay
// alive significantly longer than the other child controls
SubsGrid - > Reparent ( 0 ) ;
SubsGrid - > Hide ( ) ;
2011-01-16 08:16:54 +01:00
context - > videoController - > SetVideo ( " " ) ;
context - > audioController - > CloseAudio ( ) ;
2011-07-30 01:16:46 +02:00
// Ensure the children get destroyed before the project context is destroyed
DestroyChildren ( ) ;
wxTheApp - > ProcessPendingEvents ( ) ;
2011-07-15 06:05:49 +02:00
delete context - > ass ;
HelpButton : : ClearPages ( ) ;
2011-01-16 08:16:54 +01:00
delete context - > audioController ;
delete context - > local_scripts ;
2011-07-30 01:16:46 +02:00
SubsGrid - > Destroy ( ) ;
2006-01-16 22:02:54 +01:00
}
2011-08-27 08:29:36 +02:00
/// @brief Initialize toolbar
2006-01-16 22:02:54 +01:00
void FrameMain : : InitToolbar ( ) {
2011-07-15 06:05:49 +02:00
wxSystemOptions : : SetOption ( " msw.remap " , 0 ) ;
2011-08-17 07:32:27 +02:00
toolbar : : AttachToolbar ( this , " main " , context . get ( ) , " Default " ) ;
2011-07-15 06:06:23 +02:00
GetToolBar ( ) - > Realize ( ) ;
2006-01-16 22:02:54 +01:00
}
void FrameMain : : InitContents ( ) {
2011-01-16 08:16:54 +01:00
StartupLog ( " Create background panel " ) ;
2011-11-30 00:18:42 +01:00
wxPanel * Panel = new wxPanel ( this , - 1 , wxDefaultPosition , wxDefaultSize , wxTAB_TRAVERSAL | wxCLIP_CHILDREN ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Create subtitles grid " ) ;
2011-01-16 08:17:36 +01:00
context - > subsGrid = SubsGrid = new SubtitlesGrid ( Panel , context . get ( ) , wxSize ( 600 , 100 ) , wxWANTS_CHARS | wxSUNKEN_BORDER , " Subs grid " ) ;
2011-01-16 08:17:02 +01:00
context - > selectionController = context - > subsGrid ;
2011-01-16 08:17:36 +01:00
Search . context = context . get ( ) ;
2006-01-16 22:02:54 +01:00
2011-11-04 06:11:24 +01:00
StartupLog ( " Create video box " ) ;
2011-11-12 02:23:18 +01:00
videoBox = new VideoBox ( Panel , false , context . get ( ) ) ;
2011-11-04 06:11:24 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Create audio box " ) ;
2011-09-29 07:33:04 +02:00
context - > audioBox = audioBox = new AudioBox ( Panel , context . get ( ) ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Create subtitle editing box " ) ;
2011-11-30 00:18:42 +01:00
SubsEditBox * EditBox = new SubsEditBox ( Panel , context . get ( ) ) ;
2011-09-15 07:17:07 +02:00
context - > editBox = EditBox - > TextEdit ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Arrange main sizers " ) ;
2010-12-08 04:36:10 +01:00
ToolsSizer = new wxBoxSizer ( wxVERTICAL ) ;
2011-09-29 07:33:04 +02:00
ToolsSizer - > Add ( audioBox , 0 , wxEXPAND ) ;
2010-12-08 04:36:10 +01:00
ToolsSizer - > Add ( EditBox , 1 , wxEXPAND ) ;
TopSizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2011-09-30 22:42:55 +02:00
TopSizer - > Add ( videoBox , 0 , wxEXPAND , 0 ) ;
2010-12-08 04:36:10 +01:00
TopSizer - > Add ( ToolsSizer , 1 , wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM , 5 ) ;
MainSizer = new wxBoxSizer ( wxVERTICAL ) ;
2007-07-07 05:21:52 +02:00
MainSizer - > Add ( new wxStaticLine ( Panel ) , 0 , wxEXPAND | wxALL , 0 ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Add ( TopSizer , 0 , wxEXPAND | wxALL , 0 ) ;
2010-12-08 04:36:10 +01:00
MainSizer - > Add ( SubsGrid , 1 , wxEXPAND | wxALL , 0 ) ;
2006-01-16 22:02:54 +01:00
Panel - > SetSizer ( MainSizer ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Perform layout " ) ;
2006-01-16 22:02:54 +01:00
Layout ( ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Set focus to edting box " ) ;
2007-07-03 03:09:39 +02:00
EditBox - > TextEdit - > SetFocus ( ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Leaving InitContents " ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:33 +01:00
void FrameMain : : LoadSubtitles ( wxString filename , wxString charset ) {
2011-01-16 08:16:54 +01:00
if ( context - > ass - > loaded ) {
2006-01-16 22:02:54 +01:00
if ( TryToCloseSubs ( ) = = wxCANCEL ) return ;
}
try {
2011-01-16 08:16:33 +01:00
// Make sure that file isn't actually a timecode file
try {
TextFileReader testSubs ( filename , charset ) ;
wxString cur = testSubs . ReadLineFromFile ( ) ;
2011-07-15 06:05:49 +02:00
if ( cur . Left ( 10 ) = = " # timecode " ) {
2011-01-16 08:16:54 +01:00
context - > videoController - > LoadTimecodes ( filename ) ;
2011-01-16 08:16:33 +01:00
return ;
2010-06-27 06:54:46 +02:00
}
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:33 +01:00
catch ( . . . ) {
// if trying to load the file as timecodes fails it's fairly
// safe to assume that it is in fact not a timecode file
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:33 +01:00
2011-01-16 08:16:54 +01:00
context - > ass - > Load ( filename , charset ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:33 +01:00
catch ( agi : : acs : : AcsNotFound const & ) {
2011-07-15 06:05:49 +02:00
wxMessageBox ( filename + " not found. " , " Error " , wxOK | wxICON_ERROR , NULL ) ;
2010-08-02 08:32:01 +02:00
config : : mru - > Remove ( " Subtitle " , STD_STR ( filename ) ) ;
return ;
}
2011-09-28 21:43:11 +02:00
catch ( const char * err ) {
2011-07-15 06:05:49 +02:00
wxMessageBox ( wxString ( err ) , " Error " , wxOK | wxICON_ERROR , NULL ) ;
2006-01-16 22:02:54 +01:00
return ;
}
2009-07-14 23:28:49 +02:00
catch ( wxString err ) {
2011-07-15 06:05:49 +02:00
wxMessageBox ( err , " Error " , wxOK | wxICON_ERROR , NULL ) ;
2009-07-14 23:28:49 +02:00
return ;
}
2006-01-16 22:02:54 +01:00
catch ( . . . ) {
2011-07-15 06:05:49 +02:00
wxMessageBox ( " Unknown error " , " Error " , wxOK | wxICON_ERROR , NULL ) ;
2006-01-16 22:02:54 +01:00
return ;
}
}
int FrameMain : : TryToCloseSubs ( bool enableCancel ) {
2011-01-16 08:16:54 +01:00
if ( context - > ass - > IsModified ( ) ) {
2006-01-16 22:02:54 +01:00
int flags = wxYES_NO ;
if ( enableCancel ) flags | = wxCANCEL ;
2011-11-16 22:58:58 +01:00
int result = wxMessageBox ( wxString : : Format ( _ ( " Do you want to save changes to %s? " ) , GetScriptFileName ( ) ) , _ ( " Unsaved changes " ) , flags , this ) ;
2006-01-16 22:02:54 +01:00
if ( result = = wxYES ) {
2011-01-20 06:57:15 +01:00
( * cmd : : get ( " subtitle/save " ) ) ( context . get ( ) ) ;
2006-01-16 22:02:54 +01:00
// If it fails saving, return cancel anyway
2011-01-20 06:57:15 +01:00
return context - > ass - > IsModified ( ) ? wxCANCEL : wxYES ;
2006-01-16 22:02:54 +01:00
}
return result ;
}
2011-01-20 06:57:15 +01:00
else {
return wxYES ;
}
2006-01-16 22:02:54 +01:00
}
2009-10-12 00:10:08 +02:00
void FrameMain : : SetDisplayMode ( int video , int audio ) {
if ( ! IsShownOnScreen ( ) ) return ;
bool sv = false , sa = false ;
if ( video = = - 1 ) sv = showVideo ;
2011-01-16 08:16:54 +01:00
else if ( video ) sv = context - > videoController - > IsLoaded ( ) & & ! context - > detachedVideo ;
2009-10-12 00:10:08 +02:00
if ( audio = = - 1 ) sa = showAudio ;
2011-01-16 08:16:54 +01:00
else if ( audio ) sa = context - > audioController - > IsAudioOpen ( ) ;
2006-01-16 22:02:54 +01:00
2007-01-23 05:42:08 +01:00
// See if anything changed
2009-10-12 00:10:08 +02:00
if ( sv = = showVideo & & sa = = showAudio ) return ;
showVideo = sv ;
showAudio = sa ;
2007-01-23 05:42:08 +01:00
2010-06-29 00:15:40 +02:00
bool didFreeze = ! IsFrozen ( ) ;
if ( didFreeze ) Freeze ( ) ;
2011-01-16 08:16:54 +01:00
context - > videoController - > Stop ( ) ;
2007-04-13 03:46:50 +02:00
2010-12-08 04:36:10 +01:00
TopSizer - > Show ( videoBox , showVideo , true ) ;
2011-09-29 07:33:04 +02:00
ToolsSizer - > Show ( audioBox , showAudio , true ) ;
2006-01-16 22:02:54 +01:00
2006-07-11 03:58:53 +02:00
MainSizer - > CalcMin ( ) ;
MainSizer - > RecalcSizes ( ) ;
2006-01-16 22:02:54 +01:00
MainSizer - > Layout ( ) ;
2006-05-05 20:52:09 +02:00
Layout ( ) ;
2010-06-29 00:15:40 +02:00
if ( didFreeze ) Thaw ( ) ;
2006-01-16 22:02:54 +01:00
}
void FrameMain : : UpdateTitle ( ) {
2011-01-16 08:16:33 +01:00
wxString newTitle ;
2011-07-15 06:05:49 +02:00
if ( context - > ass - > IsModified ( ) ) newTitle < < " * " ;
2011-11-16 22:58:58 +01:00
newTitle < < GetScriptFileName ( ) ;
2011-01-16 08:16:33 +01:00
# ifndef __WXMAC__
newTitle < < " - Aegisub " < < GetAegisubLongVersionString ( ) ;
2007-09-22 05:49:18 +02:00
# endif
2009-08-01 04:00:30 +02:00
2010-12-08 04:36:10 +01:00
# if defined(__WXMAC__) && !defined(__LP64__)
2007-09-22 05:07:16 +02:00
// On Mac, set the mark in the close button
2011-01-16 08:16:54 +01:00
OSXSetModified ( context - > ass - > IsModified ( ) ) ;
2007-09-22 05:07:16 +02:00
# endif
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:33 +01:00
if ( GetTitle ( ) ! = newTitle ) SetTitle ( newTitle ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:27 +01:00
void FrameMain : : OnVideoOpen ( ) {
2011-01-16 08:16:54 +01:00
if ( ! context - > videoController - > IsLoaded ( ) ) {
2011-01-16 08:16:27 +01:00
SetDisplayMode ( 0 , - 1 ) ;
return ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:27 +01:00
Freeze ( ) ;
2011-01-16 08:16:54 +01:00
int vidx = context - > videoController - > GetWidth ( ) ,
vidy = context - > videoController - > GetHeight ( ) ;
2011-01-16 08:16:27 +01:00
// Set zoom level based on video resolution and window size
2011-11-12 02:23:29 +01:00
double zoom = context - > videoDisplay - > GetZoom ( ) ;
2011-01-16 08:16:27 +01:00
wxSize windowSize = GetSize ( ) ;
if ( vidx * 3 * zoom > windowSize . GetX ( ) * 4 | | vidy * 4 * zoom > windowSize . GetY ( ) * 6 )
2011-11-12 02:23:29 +01:00
context - > videoDisplay - > SetZoom ( zoom * .25 ) ;
2011-01-16 08:16:27 +01:00
else if ( vidx * 3 * zoom > windowSize . GetX ( ) * 2 | | vidy * 4 * zoom > windowSize . GetY ( ) * 3 )
2011-11-12 02:23:29 +01:00
context - > videoDisplay - > SetZoom ( zoom * .5 ) ;
2011-01-16 08:16:27 +01:00
2009-10-12 00:10:08 +02:00
SetDisplayMode ( 1 , - 1 ) ;
2008-01-12 04:09:48 +01:00
2011-09-30 22:41:44 +02:00
if ( OPT_GET ( " Video/Detached/Enabled " ) - > GetBool ( ) & & ! context - > detachedVideo )
2011-07-30 01:16:36 +02:00
cmd : : call ( " video/detach " , context . get ( ) ) ;
2008-01-12 04:09:48 +01:00
Thaw ( ) ;
2006-01-16 22:02:54 +01:00
}
2011-07-30 01:16:36 +02:00
void FrameMain : : OnVideoDetach ( agi : : OptionValue const & opt ) {
if ( opt . GetBool ( ) )
SetDisplayMode ( 0 , - 1 ) ;
else if ( context - > videoController - > IsLoaded ( ) )
SetDisplayMode ( 1 , - 1 ) ;
2008-01-12 04:09:48 +01:00
}
2006-01-16 22:02:54 +01:00
void FrameMain : : StatusTimeout ( wxString text , int ms ) {
SetStatusText ( text , 1 ) ;
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
StatusClear . SetOwner ( this , ID_APP_TIMER_STATUSCLEAR ) ;
2006-01-16 22:02:54 +01:00
StatusClear . Start ( ms , true ) ;
}
bool FrameMain : : LoadList ( wxArrayString list ) {
wxArrayString List ;
for ( size_t i = 0 ; i < list . Count ( ) ; i + + ) {
wxFileName file ( list [ i ] ) ;
if ( file . IsRelative ( ) ) file . MakeAbsolute ( ) ;
if ( file . FileExists ( ) ) List . Add ( file . GetFullPath ( ) ) ;
}
// Video formats
wxArrayString videoList ;
2011-07-15 06:05:49 +02:00
videoList . Add ( " avi " ) ;
videoList . Add ( " mkv " ) ;
videoList . Add ( " mp4 " ) ;
videoList . Add ( " d2v " ) ;
videoList . Add ( " mpg " ) ;
videoList . Add ( " mpeg " ) ;
videoList . Add ( " ogm " ) ;
videoList . Add ( " avs " ) ;
videoList . Add ( " wmv " ) ;
videoList . Add ( " asf " ) ;
videoList . Add ( " mov " ) ;
videoList . Add ( " rm " ) ;
videoList . Add ( " y4m " ) ;
videoList . Add ( " yuv " ) ;
2006-01-16 22:02:54 +01:00
// Subtitle formats
wxArrayString subsList ;
2011-07-15 06:05:49 +02:00
subsList . Add ( " ass " ) ;
subsList . Add ( " ssa " ) ;
subsList . Add ( " srt " ) ;
subsList . Add ( " sub " ) ;
subsList . Add ( " txt " ) ;
subsList . Add ( " ttxt " ) ;
2006-01-16 22:02:54 +01:00
// Audio formats
wxArrayString audioList ;
2011-07-15 06:05:49 +02:00
audioList . Add ( " wav " ) ;
audioList . Add ( " mp3 " ) ;
audioList . Add ( " ogg " ) ;
audioList . Add ( " wma " ) ;
audioList . Add ( " ac3 " ) ;
audioList . Add ( " aac " ) ;
audioList . Add ( " mpc " ) ;
audioList . Add ( " ape " ) ;
audioList . Add ( " flac " ) ;
audioList . Add ( " mka " ) ;
audioList . Add ( " m4a " ) ;
2006-01-16 22:02:54 +01:00
// Scan list
2011-01-16 08:16:27 +01:00
wxString audio ;
wxString video ;
wxString subs ;
2006-01-16 22:02:54 +01:00
wxString ext ;
for ( size_t i = 0 ; i < List . Count ( ) ; i + + ) {
wxFileName file ( List [ i ] ) ;
ext = file . GetExt ( ) . Lower ( ) ;
2011-01-16 08:16:27 +01:00
if ( subs . empty ( ) & & subsList . Index ( ext ) ! = wxNOT_FOUND ) subs = List [ i ] ;
if ( video . empty ( ) & & videoList . Index ( ext ) ! = wxNOT_FOUND ) video = List [ i ] ;
if ( audio . empty ( ) & & audioList . Index ( ext ) ! = wxNOT_FOUND ) audio = List [ i ] ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:27 +01:00
blockVideoLoad = ! video . empty ( ) ;
2006-01-16 22:02:54 +01:00
// Load files
2011-01-16 08:16:27 +01:00
if ( subs . size ( ) ) {
2006-02-01 03:16:57 +01:00
LoadSubtitles ( subs ) ;
}
2006-01-16 22:02:54 +01:00
if ( blockVideoLoad ) {
blockVideoLoad = false ;
2011-01-16 08:16:54 +01:00
context - > videoController - > SetVideo ( video ) ;
2006-01-16 22:02:54 +01:00
}
2011-01-16 08:16:27 +01:00
if ( ! audio . empty ( ) )
2011-01-16 08:16:54 +01:00
context - > audioController - > OpenAudio ( audio ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:27 +01:00
return subs . size ( ) | | audio . size ( ) | | video . size ( ) ;
2006-01-16 22:02:54 +01:00
}
2007-01-26 01:47:42 +01:00
2010-12-07 20:09:15 +01:00
static void autosave_timer_changed ( wxTimer * timer , const agi : : OptionValue & opt ) {
2010-08-26 20:38:44 +02:00
int freq = opt . GetInt ( ) ;
if ( freq < = 0 ) {
2010-12-07 20:09:15 +01:00
timer - > Stop ( ) ;
2010-08-26 20:38:44 +02:00
}
else {
2010-12-07 20:09:15 +01:00
timer - > Start ( freq * 1000 ) ;
2010-08-26 20:38:44 +02:00
}
}
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
BEGIN_EVENT_TABLE ( FrameMain , wxFrame )
EVT_TIMER ( ID_APP_TIMER_AUTOSAVE , FrameMain : : OnAutoSave )
EVT_TIMER ( ID_APP_TIMER_STATUSCLEAR , FrameMain : : OnStatusClear )
EVT_CLOSE ( FrameMain : : OnCloseWindow )
EVT_KEY_DOWN ( FrameMain : : OnKeyDown )
2011-10-25 21:40:57 +02:00
EVT_MOUSEWHEEL ( FrameMain : : OnMouseWheel )
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
# ifdef __WXMAC__
2011-01-11 18:52:17 +01:00
// EVT_MENU(wxID_ABOUT, FrameMain::OnAbout)
// EVT_MENU(wxID_EXIT, FrameMain::OnExit)
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
# endif
END_EVENT_TABLE ( )
void FrameMain : : OnCloseWindow ( wxCloseEvent & event ) {
// Stop audio and video
2011-01-16 08:16:54 +01:00
context - > videoController - > Stop ( ) ;
context - > audioController - > Stop ( ) ;
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
// Ask user if he wants to save first
bool canVeto = event . CanVeto ( ) ;
int result = TryToCloseSubs ( canVeto ) ;
// Store maximization state
OPT_SET ( " App/Maximized " ) - > SetBool ( IsMaximized ( ) ) ;
// Abort/destroy
if ( canVeto ) {
if ( result = = wxCANCEL ) event . Veto ( ) ;
else Destroy ( ) ;
}
else Destroy ( ) ;
}
2011-07-15 06:05:49 +02:00
void FrameMain : : OnAutoSave ( wxTimerEvent & ) try {
2011-09-29 20:17:27 +02:00
wxString fn = context - > ass - > AutoSave ( ) ;
if ( ! fn . empty ( ) )
StatusTimeout ( wxString : : Format ( _ ( " File backup saved as \" %s \" . " ) , fn ) ) ;
2011-08-27 08:29:57 +02:00
}
catch ( const agi : : Exception & err ) {
StatusTimeout ( lagi_wxString ( " Exception when attempting to autosave file: " + err . GetMessage ( ) ) ) ;
}
catch ( wxString err ) {
2011-07-15 06:05:49 +02:00
StatusTimeout ( " Exception when attempting to autosave file: " + err ) ;
2011-08-27 08:29:57 +02:00
}
2011-09-28 21:43:11 +02:00
catch ( const char * err ) {
2011-07-15 06:05:49 +02:00
StatusTimeout ( " Exception when attempting to autosave file: " + wxString ( err ) ) ;
2011-08-27 08:29:57 +02:00
}
catch ( . . . ) {
2011-07-15 06:05:49 +02:00
StatusTimeout ( " Unhandled exception when attempting to autosave file. " ) ;
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
}
void FrameMain : : OnStatusClear ( wxTimerEvent & ) {
2011-07-15 06:05:49 +02:00
SetStatusText ( " " , 1 ) ;
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
}
2011-12-22 22:09:31 +01:00
void FrameMain : : OnAudioOpen ( AudioProvider * ) {
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
SetDisplayMode ( - 1 , 1 ) ;
}
2011-07-15 06:05:49 +02:00
void FrameMain : : OnAudioClose ( ) {
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
SetDisplayMode ( - 1 , 0 ) ;
}
2011-01-16 08:16:33 +01:00
void FrameMain : : OnSubtitlesOpen ( ) {
UpdateTitle ( ) ;
/// @todo figure out how to move this to the relevant controllers without
/// prompting for each file loaded/unloaded
// Load stuff from the new script
2011-01-16 08:16:54 +01:00
wxString curSubsVideo = DecodeRelativePath ( context - > ass - > GetScriptInfo ( " Video File " ) , context - > ass - > filename ) ;
wxString curSubsVFR = DecodeRelativePath ( context - > ass - > GetScriptInfo ( " VFR File " ) , context - > ass - > filename ) ;
wxString curSubsKeyframes = DecodeRelativePath ( context - > ass - > GetScriptInfo ( " Keyframes File " ) , context - > ass - > filename ) ;
wxString curSubsAudio = DecodeRelativePath ( context - > ass - > GetScriptInfo ( " Audio URI " ) , context - > ass - > filename ) ;
2011-01-16 08:16:33 +01:00
// Check if there is anything to change
int autoLoadMode = OPT_GET ( " App/Auto/Load Linked Files " ) - > GetInt ( ) ;
bool doLoad = false ;
2011-01-16 08:16:54 +01:00
if ( curSubsAudio ! = context - > audioController - > GetAudioURL ( ) | |
curSubsVFR ! = context - > videoController - > GetTimecodesName ( ) | |
2011-12-06 01:17:54 +01:00
curSubsVideo ! = context - > videoController - > GetVideoName ( ) | |
2011-01-16 08:16:54 +01:00
curSubsKeyframes ! = context - > videoController - > GetKeyFramesName ( )
2011-01-16 08:16:33 +01:00
)
{
if ( autoLoadMode = = 1 ) {
doLoad = true ;
}
else if ( autoLoadMode = = 2 ) {
doLoad = wxMessageBox ( _ ( " Do you want to load/unload the associated files? " ) , _ ( " (Un)Load files? " ) , wxYES_NO ) = = wxYES ;
}
}
if ( doLoad ) {
// Video
2011-12-06 01:17:54 +01:00
if ( ! blockVideoLoad & & curSubsVideo ! = context - > videoController - > GetVideoName ( ) ) {
2011-01-16 08:16:54 +01:00
context - > videoController - > SetVideo ( curSubsVideo ) ;
if ( context - > videoController - > IsLoaded ( ) ) {
2011-10-24 22:18:25 +02:00
context - > videoController - > JumpToFrame ( context - > ass - > GetScriptInfoAsInt ( " Video Position " ) ) ;
long videoAr = 0 ;
double videoArValue = 0. ;
wxString arString = context - > ass - > GetScriptInfo ( " Video Aspect Ratio " ) ;
if ( arString . Left ( 1 ) = = " c " ) {
videoAr = 4 ;
arString = arString . Mid ( 1 ) ;
arString . ToDouble ( & videoArValue ) ;
}
else if ( arString . IsNumber ( ) ) {
arString . ToLong ( & videoAr ) ;
}
2011-01-16 08:16:54 +01:00
context - > videoController - > SetAspectRatio ( videoAr , videoArValue ) ;
2011-10-24 22:18:25 +02:00
double videoZoom = 0. ;
if ( context - > ass - > GetScriptInfo ( " Video Zoom Percent " ) . ToDouble ( & videoZoom ) )
2011-11-12 02:23:29 +01:00
context - > videoDisplay - > SetZoom ( videoZoom ) ;
2011-01-16 08:16:33 +01:00
}
}
2011-01-16 08:16:54 +01:00
context - > videoController - > LoadTimecodes ( curSubsVFR ) ;
context - > videoController - > LoadKeyframes ( curSubsKeyframes ) ;
2011-01-16 08:16:33 +01:00
// Audio
2011-01-16 08:16:54 +01:00
if ( curSubsAudio ! = context - > audioController - > GetAudioURL ( ) ) {
2011-09-28 21:51:53 +02:00
if ( ! curSubsAudio )
context - > audioController - > CloseAudio ( ) ;
else
context - > audioController - > OpenAudio ( curSubsAudio ) ;
2011-01-16 08:16:33 +01:00
}
}
// Display
SetDisplayMode ( 1 , 1 ) ;
}
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
void FrameMain : : OnKeyDown ( wxKeyEvent & event ) {
2011-07-30 01:16:55 +02:00
if ( ! hotkey : : check ( " Main Frame " , context . get ( ) , event . GetKeyCode ( ) , event . GetUnicodeKey ( ) , event . GetModifiers ( ) ) )
2011-01-19 04:12:46 +01:00
event . Skip ( ) ;
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
}
2011-10-25 21:40:57 +02:00
void FrameMain : : OnMouseWheel ( wxMouseEvent & evt ) {
ForwardMouseWheelEvent ( this , evt ) ;
}
2011-11-16 22:58:58 +01:00
wxString FrameMain : : GetScriptFileName ( ) const {
if ( context - > ass - > filename . empty ( ) ) {
// Apple HIG says "untitled" should not be capitalised
// and the window is a document window, it shouldn't contain the app name
// (The app name is already present in the menu bar)
# ifndef __WXMAC__
return _ ( " Untitled " ) ;
# else
return _ ( " untitled " ) ;
# endif
}
else {
wxFileName file ( context - > ass - > filename ) ;
return file . GetFullName ( ) ;
}
}