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/
/// @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"
2013-01-04 16:01:50 +01:00
# include <libaegisub/fs.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>
2013-01-04 16:01:50 +01:00
# include <libaegisub/path.h>
# include <libaegisub/util.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
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"
2013-06-19 04:28:11 +02:00
# include "base_grid.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"
2012-03-09 01:23:41 +01:00
# include "dialog_detached_video.h"
# include "dialog_manager.h"
2009-09-10 15:06:40 +02:00
# include "dialog_version_check.h"
# include "help_button.h"
2012-10-12 01:46:53 +02:00
# include "initial_line_state.h"
2009-07-24 02:08:25 +02:00
# include "libresrc/libresrc.h"
2009-09-10 15:06:40 +02:00
# include "main.h"
2013-01-07 02:50:09 +01:00
# include "options.h"
2013-01-11 18:35:39 +01:00
# include "search_replace_engine.h"
2013-01-26 02:57:46 +01:00
# include "subs_controller.h"
2009-09-10 15:06:40 +02:00
# 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 "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
2013-01-04 16:01:50 +01:00
# include <boost/algorithm/string/predicate.hpp>
# include <wx/dnd.h>
# include <wx/filename.h>
# include <wx/image.h>
# include <wx/msgdlg.h>
# include <wx/statline.h>
# include <wx/sysopt.h>
2011-07-15 06:05:49 +02:00
enum {
2013-01-04 16:01:50 +01:00
ID_APP_TIMER_STATUSCLEAR = 12002
2011-07-15 06:05:49 +02:00
} ;
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
2011-12-22 22:30:40 +01:00
# define StartupLog(a) LOG_I("frame_main / init") << a
2009-06-12 18:59:53 +02:00
# endif
2012-08-04 18:31:44 +02:00
wxDEFINE_EVENT ( FILE_LIST_DROPPED , wxThreadEvent ) ;
2013-01-04 16:01:50 +01:00
static void get_files_to_load ( wxArrayString const & list , std : : string & subs , std : : string & audio , std : : string & video ) {
2012-08-04 18:31:44 +02:00
// Keep these lists sorted
// Video formats
const wxString videoList [ ] = {
" asf " ,
" avi " ,
" avs " ,
" d2v " ,
" m2ts " ,
2012-12-06 05:23:32 +01:00
" m4v " ,
2012-08-04 18:31:44 +02:00
" mkv " ,
" mov " ,
" mp4 " ,
" mpeg " ,
" mpg " ,
" ogm " ,
" rm " ,
" rmvb " ,
" ts " ,
" webm "
" wmv " ,
" y4m " ,
" yuv "
} ;
// Subtitle formats
const wxString subsList [ ] = {
" ass " ,
" srt " ,
" ssa " ,
" sub " ,
" ttxt " ,
" txt "
} ;
// Audio formats
const wxString audioList [ ] = {
" aac " ,
" ac3 " ,
" ape " ,
" dts " ,
" flac " ,
" m4a " ,
" mka " ,
" mp3 " ,
" ogg " ,
" w64 " ,
" wav " ,
" wma "
} ;
// Scan list
2012-11-04 04:53:03 +01:00
for ( wxFileName file : list ) {
2012-08-04 18:31:44 +02:00
if ( file . IsRelative ( ) ) file . MakeAbsolute ( ) ;
if ( ! file . FileExists ( ) ) continue ;
wxString ext = file . GetExt ( ) . Lower ( ) ;
2013-06-07 05:19:01 +02:00
if ( subs . empty ( ) & & std : : binary_search ( std : : begin ( subsList ) , std : : end ( subsList ) , ext ) )
2013-01-04 16:01:50 +01:00
subs = from_wx ( file . GetFullPath ( ) ) ;
2013-06-07 05:19:01 +02:00
if ( video . empty ( ) & & std : : binary_search ( std : : begin ( videoList ) , std : : end ( videoList ) , ext ) )
2013-01-04 16:01:50 +01:00
video = from_wx ( file . GetFullPath ( ) ) ;
2013-06-07 05:19:01 +02:00
if ( audio . empty ( ) & & std : : binary_search ( std : : begin ( audioList ) , std : : end ( audioList ) , ext ) )
2013-01-04 16:01:50 +01:00
audio = from_wx ( file . GetFullPath ( ) ) ;
2012-08-04 18:31: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 ) { }
2013-11-21 18:13:36 +01:00
bool OnDropFiles ( wxCoord , wxCoord , const wxArrayString & filenames ) override {
2013-01-04 16:01:50 +01:00
std : : string subs , audio , video ;
2012-08-04 18:31:44 +02:00
get_files_to_load ( filenames , subs , audio , video ) ;
2013-01-04 16:01:50 +01:00
if ( subs . empty ( ) & & audio . empty ( ) & & video . empty ( ) )
2012-08-04 18:31:44 +02:00
return false ;
2013-11-21 18:13:36 +01:00
auto evt = new wxThreadEvent ( FILE_LIST_DROPPED ) ;
2012-08-04 18:31:44 +02:00
evt - > SetPayload ( filenames ) ;
parent - > QueueEvent ( evt ) ;
return true ;
2011-11-30 00:18:24 +01:00
}
} ;
2013-02-05 16:52:24 +01:00
FrameMain : : FrameMain ( )
: wxFrame ( nullptr , - 1 , " " , wxDefaultPosition , wxSize ( 920 , 700 ) , wxDEFAULT_FRAME_STYLE | wxCLIP_CHILDREN )
2013-10-23 23:43:05 +02:00
, context ( agi : : util : : make_unique < agi : : Context > ( ) )
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__
2012-08-27 04:13:11 +02:00
// When run from an app bundle, LC_CTYPE defaults to "C", which breaks on
// anything involving unicode and in some cases number formatting.
// The right thing to do here would be to query CoreFoundation for the user's
// locale and add .UTF-8 to that, but :effort:
2013-11-21 18:13:36 +01:00
LOG_D ( " locale " ) < < setlocale ( LC_ALL , nullptr ) ;
2012-08-27 04:13:11 +02:00
setlocale ( LC_CTYPE , " en_US.UTF-8 " ) ;
2013-11-21 18:13:36 +01:00
LOG_D ( " locale " ) < < setlocale ( LC_ALL , nullptr ) ;
2011-11-25 20:29:17 +01:00
# endif
2007-04-03 06:34:56 +02:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Initializing context models " ) ;
2012-03-09 01:23:30 +01:00
memset ( context . get ( ) , 0 , sizeof ( * context ) ) ;
2013-01-26 02:57:46 +01:00
context - > ass = new AssFile ;
2006-12-27 21:16:47 +01:00
2011-01-16 08:16:54 +01:00
StartupLog ( " Initializing context controls " ) ;
2013-01-26 02:57:46 +01:00
context - > subsController = new SubsController ( context . get ( ) ) ;
context - > ass - > AddCommitListener ( & FrameMain : : UpdateTitle , this ) ;
context - > subsController - > AddFileOpenListener ( & FrameMain : : OnSubtitlesOpen , this ) ;
context - > subsController - > AddFileSaveListener ( & FrameMain : : UpdateTitle , this ) ;
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
2013-01-26 02:57:46 +01:00
context - > local_scripts = new Automation4 : : LocalScriptManager ( context . get ( ) ) ;
2011-01-16 08:17:02 +01:00
// Initialized later due to that the selection controller is currently the subtitles grid
2013-11-21 18:13:36 +01:00
context - > selectionController = nullptr ;
2011-01-16 08:17:02 +01:00
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 ;
2013-11-21 18:13:36 +01:00
context - > previousFocus = nullptr ;
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 ( ) ) ;
2012-03-25 06:05:06 +02: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 " ) ;
2012-03-09 01:23:41 +01:00
context - > dialog = new DialogManager ;
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 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 " ) ;
2013-01-26 02:57:46 +01:00
context - > subsController - > Close ( ) ;
2011-01-16 08:16:54 +01:00
2011-09-30 22:43:04 +02:00
StartupLog ( " Display main window " ) ;
2012-05-26 22:16:08 +02:00
AddFullScreenButton ( this ) ;
2011-09-30 22:43:04 +02:00
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 ) ;
2012-06-21 04:09:40 +02:00
# ifdef WITH_UPDATE_CHECKER
2012-03-29 01:59:19 +02: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 | wxCENTER ) ;
2010-08-26 20:38:03 +02:00
OPT_SET ( " App/Auto/Check For Updates " ) - > SetBool ( result = = wxYES ) ;
2014-03-18 22:03:36 +01:00
try {
config : : opt - > Flush ( ) ;
}
catch ( agi : : fs : : FileSystemError const & e ) {
wxMessageBox ( to_wx ( e . GetMessage ( ) ) , " Error saving config file " , wxOK | wxICON_ERROR | wxCENTER ) ;
}
2012-06-21 04:09:40 +02:00
# endif
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
2012-06-21 04:09:40 +02:00
# ifdef WITH_UPDATE_CHECKER
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 ) ;
2012-06-21 04:09:40 +02:00
# endif
2008-01-13 06:57:09 +01:00
2012-08-04 18:31:44 +02:00
Bind ( FILE_LIST_DROPPED , & FrameMain : : OnFilesDropped , this ) ;
2011-01-16 08:16:54 +01:00
StartupLog ( " Leaving FrameMain constructor " ) ;
2006-01-16 22:02:54 +01:00
}
2012-05-15 15:39:24 +02:00
/// @brief Delete everything but @a keep and its parents
/// @param window Root window to delete the children of
/// @param keep Window to keep alive
/// @return Was @a keep found?
static bool delete_children ( wxWindow * window , wxWindow * keep ) {
bool found = false ;
while ( window - > GetChildren ( ) . size ( ) > ( size_t ) found ) {
2012-12-23 00:35:13 +01:00
auto it = window - > GetChildren ( ) . begin ( ) ;
2012-05-15 15:39:24 +02:00
if ( * it = = keep )
found = true ;
if ( found ) {
if ( + + it ! = window - > GetChildren ( ) . end ( ) )
( * it ) - > wxWindowBase : : Destroy ( ) ;
}
else if ( ! delete_children ( * it , keep ) )
( * it ) - > wxWindowBase : : Destroy ( ) ;
else
found = true ;
}
return found ;
}
2011-07-30 01:16:46 +02:00
2012-05-15 15:39:24 +02:00
FrameMain : : ~ FrameMain ( ) {
2013-11-21 18:13:36 +01:00
wxGetApp ( ) . frame = nullptr ;
2012-05-16 16:23:16 +02:00
2011-01-16 08:16:54 +01:00
context - > videoController - > SetVideo ( " " ) ;
context - > audioController - > CloseAudio ( ) ;
2011-07-30 01:16:46 +02:00
2012-05-15 15:39:24 +02:00
// SubsGrid needs to be deleted last due to being the selection
// controller, but everything else needs to be deleted before the context
// is cleaned up
delete_children ( this , SubsGrid ) ;
2011-07-30 01:16:46 +02:00
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 ;
2006-01-16 22:02:54 +01:00
}
2012-01-23 00:44:24 +01:00
void FrameMain : : InitToolbar ( ) {
2011-07-15 06:05:49 +02:00
wxSystemOptions : : SetOption ( " msw.remap " , 0 ) ;
2012-01-23 00:44:24 +01:00
OPT_SUB ( " App/Show Toolbar " , & FrameMain : : EnableToolBar , this ) ;
EnableToolBar ( * OPT_GET ( " App/Show Toolbar " ) ) ;
}
void FrameMain : : EnableToolBar ( agi : : OptionValue const & opt ) {
if ( opt . GetBool ( ) ) {
if ( ! GetToolBar ( ) ) {
toolbar : : AttachToolbar ( this , " main " , context . get ( ) , " Default " ) ;
GetToolBar ( ) - > Realize ( ) ;
}
}
else if ( wxToolBar * old_tb = GetToolBar ( ) ) {
2013-11-21 18:13:36 +01:00
SetToolBar ( nullptr ) ;
2012-01-23 00:44:24 +01:00
delete old_tb ;
Layout ( ) ;
}
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 " ) ;
2013-06-19 04:28:11 +02:00
context - > subsGrid = SubsGrid = new BaseGrid ( Panel , context . get ( ) , wxDefaultSize , wxWANTS_CHARS | wxSUNKEN_BORDER ) ;
2011-01-16 08:17:02 +01:00
context - > selectionController = context - > subsGrid ;
2013-01-11 17:53:36 +01:00
context - > search = new SearchReplaceEngine ( context . get ( ) ) ;
2012-10-12 01:46:53 +02:00
context - > initialLineState = new InitialLineState ( 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 " ) ;
2013-11-21 18:13:36 +01:00
auto EditBox = new SubsEditBox ( Panel , context . get ( ) ) ;
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 ( " Leaving InitContents " ) ;
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 ;
2012-03-09 01:23:41 +01:00
else if ( video ) sv = context - > videoController - > IsLoaded ( ) & & ! context - > dialog - > Get < DialogDetachedVideo > ( ) ;
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 ;
2013-01-26 02:57:46 +01:00
if ( context - > subsController - > IsModified ( ) ) newTitle < < " * " ;
newTitle < < context - > subsController - > Filename ( ) . filename ( ) . wstring ( ) ;
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
2013-01-26 02:57:46 +01:00
OSXSetModified ( context - > subsController - > 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
2012-03-09 01:23:41 +01:00
if ( OPT_GET ( " Video/Detached/Enabled " ) - > GetBool ( ) & & ! context - > dialog - > Get < DialogDetachedVideo > ( ) )
2011-07-30 01:16:36 +02:00
cmd : : call ( " video/detach " , context . get ( ) ) ;
2008-01-12 04:09:48 +01:00
Thaw ( ) ;
2012-03-27 06:23:45 +02:00
2012-09-22 02:58:22 +02:00
if ( ! blockAudioLoad & & OPT_GET ( " Video/Open Audio " ) - > GetBool ( ) & & context - > audioController - > GetAudioURL ( ) ! = context - > videoController - > GetVideoName ( ) ) {
2012-03-27 06:23:45 +02:00
try {
context - > audioController - > OpenAudio ( context - > videoController - > GetVideoName ( ) ) ;
}
2012-04-03 19:38:38 +02:00
catch ( agi : : UserCancelException const & ) { }
2012-03-27 06:23:45 +02:00
// Opening a video with no audio data isn't an error, so just log
// and move on
2013-11-10 16:25:31 +01:00
catch ( agi : : fs : : FileSystemError const & ) {
2012-03-27 06:23:45 +02:00
LOG_D ( " video/open/audio " ) < < " File " < < context - > videoController - > GetVideoName ( ) < < " found by video provider but not audio provider " ;
}
catch ( agi : : AudioDataNotFoundError const & e ) {
LOG_D ( " video/open/audio " ) < < " File " < < context - > videoController - > GetVideoName ( ) < < " has no audio data: " < < e . GetChainedMessage ( ) ;
}
catch ( agi : : AudioOpenError const & err ) {
2012-12-23 00:18:38 +01:00
wxMessageBox ( to_wx ( err . GetMessage ( ) ) , " Error loading audio " , wxOK | wxICON_ERROR | wxCENTER ) ;
2012-03-27 06:23:45 +02:00
}
}
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 ) ;
}
2012-08-04 18:31:44 +02:00
void FrameMain : : OnFilesDropped ( wxThreadEvent & evt ) {
LoadList ( evt . GetPayload < wxArrayString > ( ) ) ;
}
2006-01-16 22:02:54 +01:00
2012-08-04 18:31:44 +02:00
bool FrameMain : : LoadList ( wxArrayString list ) {
2013-01-04 16:01:50 +01:00
std : : string audio , video , subs ;
2012-08-04 18:31:44 +02:00
get_files_to_load ( list , subs , audio , video ) ;
2006-01-16 22:02:54 +01:00
2011-01-16 08:16:27 +01:00
blockVideoLoad = ! video . empty ( ) ;
2012-03-27 06:23:45 +02:00
blockAudioLoad = ! audio . empty ( ) ;
2006-01-16 22:02:54 +01:00
// Load files
2012-03-27 06:23:45 +02:00
if ( subs . size ( ) )
2013-01-26 02:57:46 +01:00
context - > subsController - > Load ( subs ) ;
2012-03-27 06:23:45 +02:00
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
}
2012-03-27 06:23:45 +02:00
if ( blockAudioLoad ) {
blockAudioLoad = false ;
try {
context - > audioController - > OpenAudio ( audio ) ;
} catch ( agi : : UserCancelException const & ) { }
}
2006-01-16 22:02:54 +01:00
2012-02-15 22:24:00 +01:00
bool loaded_any = subs . size ( ) | | audio . size ( ) | | video . size ( ) ;
if ( loaded_any )
Refresh ( false ) ;
return loaded_any ;
2006-01-16 22:02:54 +01:00
}
2007-01-26 01:47:42 +01: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_STATUSCLEAR , FrameMain : : OnStatusClear )
EVT_CLOSE ( FrameMain : : OnCloseWindow )
2012-04-27 21:07:49 +02:00
EVT_CHAR_HOOK ( 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
END_EVENT_TABLE ( )
2013-01-26 02:57:46 +01:00
void FrameMain : : OnCloseWindow ( wxCloseEvent & event ) {
2013-10-17 00:40:17 +02:00
wxEventBlocker blocker ( this , wxEVT_CLOSE_WINDOW ) ;
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
2013-01-26 02:57:46 +01:00
if ( context - > subsController - > TryToClose ( event . CanVeto ( ) ) = = wxCANCEL ) {
2012-03-12 00:04:49 +01:00
event . Veto ( ) ;
return ;
}
delete context - > dialog ;
2013-01-26 02:57:46 +01:00
context - > dialog = nullptr ;
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
// Store maximization state
OPT_SET ( " App/Maximized " ) - > SetBool ( IsMaximized ( ) ) ;
2012-03-12 00:04:49 +01:00
Destroy ( ) ;
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 ( ) ;
2013-10-17 16:23:45 +02:00
auto vc = context - > videoController ;
2011-01-16 08:16:33 +01:00
/// @todo figure out how to move this to the relevant controllers without
/// prompting for each file loaded/unloaded
// Load stuff from the new script
2013-01-04 16:01:50 +01:00
auto video = config : : path - > MakeAbsolute ( context - > ass - > GetScriptInfo ( " Video File " ) , " ?script " ) ;
auto vfr = config : : path - > MakeAbsolute ( context - > ass - > GetScriptInfo ( " VFR File " ) , " ?script " ) ;
auto keyframes = config : : path - > MakeAbsolute ( context - > ass - > GetScriptInfo ( " Keyframes File " ) , " ?script " ) ;
auto audio = config : : path - > MakeAbsolute ( context - > ass - > GetScriptInfo ( " Audio URI " ) , " ?script " ) ;
2011-01-16 08:16:33 +01:00
2013-10-17 16:23:45 +02:00
bool videoChanged = ! blockVideoLoad & & video ! = vc - > GetVideoName ( ) ;
bool timecodesChanged = vfr ! = vc - > GetTimecodesName ( ) ;
bool keyframesChanged = keyframes ! = vc - > GetKeyFramesName ( ) ;
2013-01-04 16:01:50 +01:00
bool audioChanged = ! blockAudioLoad & & audio ! = context - > audioController - > GetAudioURL ( ) ;
2012-03-27 06:23:45 +02:00
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 ( ) ;
2012-03-27 06:23:45 +02:00
if ( autoLoadMode = = 0 | | ( ! videoChanged & & ! timecodesChanged & & ! keyframesChanged & & ! audioChanged ) ) {
SetDisplayMode ( 1 , 1 ) ;
return ;
}
if ( autoLoadMode = = 2 ) {
2012-03-28 01:14:42 +02:00
if ( wxMessageBox ( _ ( " Do you want to load/unload the associated files? " ) , _ ( " (Un)Load files? " ) , wxYES_NO | wxCENTRE , this ) ! = wxYES ) {
2012-03-27 06:23:45 +02:00
SetDisplayMode ( 1 , 1 ) ;
2013-10-17 16:23:45 +02:00
if ( vc - > IsLoaded ( ) & & vc - > GetProvider ( ) - > GetColorSpace ( ) ! = context - > ass - > GetScriptInfo ( " YCbCr Matrix " ) )
vc - > Reload ( ) ;
2012-03-27 06:23:45 +02:00
return ;
2011-01-16 08:16:33 +01:00
}
}
2012-07-24 04:40:29 +02:00
if ( audioChanged )
blockAudioLoad = true ;
2012-03-27 06:23:45 +02:00
// Video
if ( videoChanged ) {
2013-10-17 16:23:45 +02:00
vc - > SetVideo ( video ) ;
if ( vc - > IsLoaded ( ) ) {
vc - > JumpToFrame ( context - > ass - > GetUIStateAsInt ( " Video Position " ) ) ;
2012-03-27 06:23:45 +02:00
2013-10-08 02:42:09 +02:00
std : : string arString = context - > ass - > GetUIState ( " Video Aspect Ratio " ) ;
2013-01-04 16:01:50 +01:00
if ( boost : : starts_with ( arString , " c " ) ) {
2013-01-20 22:05:24 +01:00
double ar = 0. ;
agi : : util : : try_parse ( arString . substr ( 1 ) , & ar ) ;
2013-10-17 16:23:45 +02:00
vc - > SetAspectRatio ( ar ) ;
2013-01-20 22:05:24 +01:00
}
else {
int ar = 0 ;
2013-07-01 00:37:07 +02:00
if ( agi : : util : : try_parse ( arString , & ar ) & & ar > = 0 & & ar < 4 )
2013-10-17 16:23:45 +02:00
vc - > SetAspectRatio ( ( AspectRatio ) ar ) ;
2011-01-16 08:16:33 +01:00
}
2012-03-27 06:23:45 +02:00
double videoZoom = 0. ;
2013-10-08 02:42:09 +02:00
if ( agi : : util : : try_parse ( context - > ass - > GetUIState ( " Video Zoom Percent " ) , & videoZoom ) )
2012-03-27 06:23:45 +02:00
context - > videoDisplay - > SetZoom ( videoZoom ) ;
2011-01-16 08:16:33 +01:00
}
2012-03-27 06:23:45 +02:00
}
2013-10-17 16:23:45 +02:00
else if ( vc - > IsLoaded ( ) & & vc - > GetProvider ( ) - > GetColorSpace ( ) ! = context - > ass - > GetScriptInfo ( " YCbCr Matrix " ) )
vc - > Reload ( ) ;
2011-01-16 08:16:33 +01:00
2013-10-17 16:23:45 +02:00
vc - > LoadTimecodes ( vfr ) ;
vc - > LoadKeyframes ( keyframes ) ;
2011-01-16 08:16:33 +01:00
2012-03-27 06:23:45 +02:00
// Audio
if ( audioChanged ) {
2012-07-24 04:40:29 +02:00
blockAudioLoad = false ;
2012-03-27 06:23:45 +02:00
try {
2013-01-04 16:01:50 +01:00
if ( audio . empty ( ) )
2012-03-27 06:23:45 +02:00
context - > audioController - > CloseAudio ( ) ;
else
2013-01-04 16:01:50 +01:00
context - > audioController - > OpenAudio ( audio ) ;
2011-01-16 08:16:33 +01:00
}
2012-03-27 06:23:45 +02:00
catch ( agi : : UserCancelException const & ) { }
2013-01-04 16:01:50 +01:00
catch ( agi : : fs : : FileSystemError const & err ) {
2012-12-23 00:18:38 +01:00
wxMessageBox ( to_wx ( err . GetMessage ( ) ) , " Error opening audio " , wxOK | wxICON_ERROR | wxCENTER , this ) ;
2012-09-22 03:07:30 +02:00
}
2011-01-16 08:16:33 +01:00
}
2012-03-27 06:23:45 +02:00
SetDisplayMode ( 1 , 1 ) ;
2011-01-16 08:16:33 +01: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
void FrameMain : : OnKeyDown ( wxKeyEvent & event ) {
2012-03-13 00:34:34 +01:00
hotkey : : check ( " Main Frame " , context . get ( ) , event ) ;
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 ) ;
}