huginApp.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00027 #include <config.h>
00028 
00029 #include "panoinc_WX.h"
00030 
00031 #ifdef __WXMAC__
00032 #include <wx/sysopt.h>
00033 #include <wx/dir.h>
00034 #endif
00035 
00036 #include "panoinc.h"
00037 
00038 #include "hugin/config_defaults.h"
00039 #include "hugin/huginApp.h"
00040 #include "hugin/ImagesPanel.h"
00041 #include "hugin/MaskEditorPanel.h"
00042 #include "hugin/CPEditorPanel.h"
00043 #include "hugin/OptimizePhotometricPanel.h"
00044 #include "hugin/PanoPanel.h"
00045 #include "hugin/ImagesList.h"
00046 #include "hugin/CPListFrame.h"
00047 #include "hugin/PreviewPanel.h"
00048 #include "hugin/GLPreviewFrame.h"
00049 #include "base_wx/PTWXDlg.h"
00050 #include "base_wx/CommandHistory.h"
00051 #include "base_wx/wxcms.h"
00052 #include "base_wx/wxPanoCommand.h"
00053 #include "hugin/HtmlWindow.h"
00054 #include "hugin/treelistctrl.h"
00055 #include "hugin/ImagesTree.h"
00056 
00057 #include "base_wx/platform.h"
00058 #include "base_wx/huginConfig.h"
00059 #ifdef __WXMSW__
00060 #include <wx/dir.h>
00061 #include <wx/cshelp.h>
00062 #include <wx/stdpaths.h>
00063 #if wxCHECK_VERSION(3,1,0)
00064 #include <wx/taskbarbutton.h>
00065 #endif
00066 #endif
00067 
00068 #include <tiffio.h>
00069 
00070 #include "AboutDialog.h"
00071 
00072 //for natural sorting
00073 #include "hugin_utils/alphanum.h"
00074 #include "lensdb/LensDB.h"
00075 
00076 bool checkVersion(wxString v1, wxString v2)
00077 {
00078     return doj::alphanum_comp(std::string(v1.mb_str(wxConvLocal)),std::string(v2.mb_str(wxConvLocal))) < 0;
00079 };
00080 
00081 using namespace hugin_utils;
00082 
00083 wxString Components2Str(const HuginBase::CPComponents & comp)
00084 {
00085     wxString ret;
00086     for (unsigned i=0; i < comp.size(); i++) {
00087         ret = ret + wxT("[");
00088         HuginBase::CPComponents::value_type::const_iterator it;
00089         size_t c=0;
00090         for (it = comp[i].begin();
00091             it != comp[i].end();
00092             ++it) 
00093         {
00094             ret = ret + wxString::Format(wxT("%d"), (*it));
00095             if (c+1 != comp[i].size()) {
00096                 ret = ret + wxT(", ");
00097             }
00098             c++;
00099         }
00100         if (i+1 != comp.size())
00101             ret = ret + wxT("], ");
00102         else
00103             ret = ret + wxT("]");
00104     }
00105     return ret;
00106 }
00107 
00108 #if _WINDOWS && defined Hugin_shared
00109 DEFINE_LOCAL_EVENT_TYPE( EVT_IMAGE_READY )
00110 #else
00111 DEFINE_EVENT_TYPE( EVT_IMAGE_READY )
00112 #endif
00113 
00114 BEGIN_EVENT_TABLE(huginApp, wxApp)
00115     EVT_IMAGE_READY2(-1, huginApp::relayImageLoaded)
00116 END_EVENT_TABLE()
00117 
00118 // make wxwindows use this class as the main application
00119 IMPLEMENT_APP(huginApp)
00120 
00121 huginApp::huginApp()
00122 {
00123     DEBUG_TRACE("ctor");
00124     m_this=this;
00125     m_monitorProfile = NULL;
00126 #if wxUSE_ON_FATAL_EXCEPTION
00127     wxHandleFatalExceptions();
00128 #endif
00129 }
00130 
00131 huginApp::~huginApp()
00132 {
00133     DEBUG_TRACE("dtor");
00134     // delete temporary dir
00135 //    if (!wxRmdir(m_workDir)) {
00136 //        DEBUG_ERROR("Could not remove temporary directory");
00137 //    }
00138 
00139         // todo: remove all listeners from the panorama object
00140 
00141 //    delete frame;
00142     HuginBase::LensDB::LensDB::Clean();
00143     // delete monitor profile
00144     if (m_monitorProfile)
00145     {
00146         cmsCloseProfile(m_monitorProfile);
00147     };
00148     DEBUG_TRACE("dtor end");
00149 }
00150 
00151 bool huginApp::OnInit()
00152 {
00153     DEBUG_TRACE("=========================== huginApp::OnInit() begin ===================");
00154     SetAppName(wxT("hugin"));
00155     
00156     // Connect to ImageCache: we need to tell it when it is safe to handle UI events.
00157     ImageCache::getInstance().asyncLoadCompleteSignal = &huginApp::imageLoadedAsync;
00158 
00159 #ifdef __WXMAC__
00160     // do not use the native list control on OSX (it is very slow with the control point list window)
00161     wxSystemOptions::SetOption(wxT("mac.listctrl.always_use_generic"), 1);
00162 #endif
00163 
00164     // register our custom pano tools dialog handlers
00165     registerPTWXDlgFcn();
00166 
00167     // required by wxHtmlHelpController
00168     wxFileSystem::AddHandler(new wxZipFSHandler);
00169 
00170 
00171 #if defined __WXMSW__
00172     // initialize help provider
00173     wxHelpControllerHelpProvider* provider = new wxHelpControllerHelpProvider;
00174     wxHelpProvider::Set(provider);
00175 
00176     wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
00177     m_utilsBinDir = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
00178     exePath.RemoveLastDir();
00179     const wxString huginRoot=exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
00180     m_xrcPrefix = huginRoot + wxT("share\\hugin\\xrc\\");
00181     m_DataDir = huginRoot + wxT("share\\hugin\\data\\");
00182 
00183     // locale setup
00184     locale.AddCatalogLookupPathPrefix(huginRoot + wxT("share\\locale"));
00185 
00186 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
00187     // initialize paths
00188     {
00189         wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
00190         if (thePath == wxT("")) {
00191             wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
00192             return false;
00193         }
00194         m_xrcPrefix = thePath + wxT("/");
00195         m_DataDir = thePath + wxT("/");
00196     }
00197 
00198 #ifdef HUGIN_HSI
00199     // Set PYTHONHOME for the hsi module
00200     {
00201         wxString pythonHome = MacGetPathToBundledFrameworksDirectory() + wxT("/Python27.framework/Versions/Current");
00202         if(! wxDir::Exists(pythonHome)){
00203             wxMessageBox(wxString::Format(_("Directory '%s' does not exists"), pythonHome.c_str()));
00204         } else {
00205             wxUnsetEnv(wxT("PYTHONPATH"));
00206             if(! wxSetEnv(wxT("PYTHONHOME"), pythonHome)){
00207                 wxMessageBox(_("Could not set environment variable PYTHONHOME"));
00208             } else {
00209                 DEBUG_TRACE("PYTHONHOME set to " << pythonHome);
00210             }
00211         }
00212     }
00213 #endif
00214     {
00215         wxString thePath = MacGetPathToBundledResourceFile(CFSTR("locale"));
00216         if(thePath != wxT(""))
00217             locale.AddCatalogLookupPathPrefix(thePath);
00218         else {
00219             wxMessageBox(_("Translations not found in bundle"), _("Fatal Error"));
00220             return false;
00221         }
00222     }
00223         
00224 #else
00225     // add the locale directory specified during configure
00226     m_xrcPrefix = wxT(INSTALL_XRC_DIR);
00227     m_DataDir = wxT(INSTALL_DATA_DIR);
00228     locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
00229 #endif
00230 
00231     if ( ! wxFile::Exists(m_xrcPrefix + wxT("/main_frame.xrc")) ) {
00232         wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
00233         return false;
00234     }
00235 
00236     // here goes and comes configuration
00237     wxConfigBase * config = wxConfigBase::Get();
00238     // do not record default values in the preferences file
00239     config->SetRecordDefaults(false);
00240 
00241     config->Flush();
00242 
00243     // initialize i18n
00244     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00245     DEBUG_TRACE("localeID: " << localeID);
00246     {
00247         bool bLInit;
00248             bLInit = locale.Init(localeID);
00249             if (bLInit) {
00250                 DEBUG_TRACE("locale init OK");
00251                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00252                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00253         } else {
00254           DEBUG_TRACE("locale init failed");
00255         }
00256         }
00257         
00258     // set the name of locale recource to look for
00259     locale.AddCatalog(wxT("hugin"));
00260 
00261     // initialize image handlers
00262     wxInitAllImageHandlers();
00263 
00264     // Initialize all the XRC handlers.
00265     wxXmlResource::Get()->InitAllHandlers();
00266 
00267     // load all XRC files.
00268     #ifdef _INCLUDE_UI_RESOURCES
00269         InitXmlResource();
00270     #else
00271 
00272     // add custom XRC handlers
00273     wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
00274     wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
00275     wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
00276     wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
00277     wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
00278     wxXmlResource::Get()->AddHandler(new ImagesListMaskXmlHandler());
00279     wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
00280     wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
00281     wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
00282     wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
00283     wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
00284     wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
00285 #if wxCHECK_VERSION(2,9,0)
00286     wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
00287 #else
00288     wxXmlResource::Get()->AddHandler(new wxTreeListCtrlXmlHandler());
00289 #endif
00290     wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
00291     wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
00292 
00293     // load XRC files
00294     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
00295     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
00296     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
00297     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
00298     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
00299     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
00300     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
00301     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
00302     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
00303     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
00304     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
00305     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
00306     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
00307     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
00308     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
00309     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
00310     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00311     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
00312     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00313 #endif
00314 
00315 #ifdef __WXMAC__
00316     // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
00317     // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
00318     m_macInitDone=false;
00319     m_macOpenFileOnStart=false;
00320 #endif
00321     // read monitor profile
00322     HuginBase::Color::GetMonitorProfile(m_monitorProfileName, m_monitorProfile);
00323     // create main frame
00324     frame = new MainFrame(NULL, pano);
00325     SetTopWindow(frame);
00326 
00327     // setup main frame size, after it has been created.
00328     RestoreFramePosition(frame, wxT("MainFrame"));
00329 #ifdef __WXMSW__
00330     provider->SetHelpController(&frame->GetHelpController());
00331     frame->GetHelpController().Initialize(m_xrcPrefix+wxT("data/hugin_help_en_EN.chm"));
00332     frame->SendSizeEvent();
00333 #if wxCHECK_VERSION(3,1,0)
00334     wxTaskBarJumpList jumpList;
00335     wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
00336     exeFile.SetName("PTBatcherGUI");
00337     wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
00338         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
00339         _("Opens PTBatcher, the batch processor for Hugin's project files"),
00340         exeFile.GetFullPath(), 0);
00341     jumpList.GetTasks().Append(item1);
00342     exeFile.SetName("calibrate_lens_gui");
00343     wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem(
00344         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
00345         _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
00346         exeFile.GetFullPath(), 0);
00347     jumpList.GetTasks().Append(item2);
00348 #endif
00349 #endif
00350 
00351     // we are closing Hugin, if the top level window is deleted
00352     SetExitOnFrameDelete(true);
00353     // show the frame.
00354     if(frame->GetGuiLevel()==GUI_SIMPLE)
00355     {
00356         SetTopWindow(frame->getGLPreview());
00357     }
00358     else
00359     {
00360         frame->Show(TRUE);
00361     };
00362 
00363     wxString cwd = wxFileName::GetCwd();
00364 
00365     m_workDir = config->Read(wxT("tempDir"),wxT(""));
00366     // FIXME, make secure against some symlink attacks
00367     // get a temp dir
00368     if (m_workDir == wxT("")) {
00369 #if (defined __WXMSW__)
00370         DEBUG_DEBUG("figuring out windows temp dir");
00371         /* added by Yili Zhao */
00372         wxChar buffer[MAX_PATH];
00373         GetTempPath(MAX_PATH, buffer);
00374         m_workDir = buffer;
00375 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
00376         DEBUG_DEBUG("temp dir on Mac");
00377         m_workDir = MacGetPathToUserDomainTempDir();
00378         if(m_workDir == wxT(""))
00379             m_workDir = wxT("/tmp");
00380 #else //UNIX
00381         DEBUG_DEBUG("temp dir on unix");
00382         // try to read environment variable
00383         if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
00384             // still no tempdir, use /tmp
00385             m_workDir = wxT("/tmp");
00386         }
00387 #endif
00388         
00389     }
00390 
00391     if (!wxFileName::DirExists(m_workDir)) {
00392         DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
00393         if (!wxMkdir(m_workDir)) {
00394             DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
00395         }
00396     }
00397     if (!wxSetWorkingDirectory(m_workDir)) {
00398         DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
00399     }
00400     DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
00401 
00402     // set some suitable defaults
00403     PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxNewProjectCmd(pano));
00404     PanoCommand::GlobalCmdHist::getInstance().clear();
00405 
00406     // suppress tiff warnings
00407     TIFFSetWarningHandler(0);
00408 
00409     if (argc > 1)
00410     {
00411 #ifdef __WXMSW__
00412         //on Windows we need to update the fast preview first
00413         //otherwise there is an infinite loop when starting with a project file
00414         //and closed panorama editor aka mainframe
00415         if(frame->GetGuiLevel()==GUI_SIMPLE)
00416         {
00417             frame->getGLPreview()->Update();
00418         };
00419 #endif
00420         wxFileName file(argv[1]);
00421         // if the first file is a project file, open it
00422         if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
00423             file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
00424             file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
00425         {
00426             if(file.IsRelative())
00427                 file.MakeAbsolute(cwd);
00428             // Loading the project file with set actualPath to its
00429             // parent directory.  (actualPath is used as starting
00430             // directory by many subsequent file selection dialogs.)
00431             frame->LoadProjectFile(file.GetFullPath());
00432         } else {
00433             std::vector<std::string> filesv;
00434             bool actualPathSet = false;
00435             for (int i=1; i< argc; i++) 
00436             {
00437 #if defined __WXMSW__
00438                 //expand wildcards
00439                 wxFileName fileList(argv[i]);
00440                 if(fileList.IsRelative())
00441                     fileList.MakeAbsolute(cwd);
00442                 wxDir dir;
00443                 wxString foundFile;
00444                 wxFileName file;
00445                 if(fileList.DirExists())
00446                     if(dir.Open(fileList.GetPath()))
00447                         if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
00448                             do
00449                             {
00450                                 file=foundFile;
00451                                 file.MakeAbsolute(dir.GetName());
00452 #else
00453                 wxFileName file(argv[i]);
00454 #endif
00455                 if (file.GetExt().CmpNoCase(wxT("jpg")) == 0 ||
00456                     file.GetExt().CmpNoCase(wxT("jpeg")) == 0 ||
00457                     file.GetExt().CmpNoCase(wxT("tif")) == 0 ||
00458                     file.GetExt().CmpNoCase(wxT("tiff")) == 0 ||
00459                     file.GetExt().CmpNoCase(wxT("png")) == 0 ||
00460                     file.GetExt().CmpNoCase(wxT("bmp")) == 0 ||
00461                     file.GetExt().CmpNoCase(wxT("gif")) == 0 ||
00462                     file.GetExt().CmpNoCase(wxT("pnm")) == 0 ||
00463                     file.GetExt().CmpNoCase(wxT("sun")) == 0 ||
00464                     file.GetExt().CmpNoCase(wxT("hdr")) == 0 ||
00465                     file.GetExt().CmpNoCase(wxT("viff")) == 0 )
00466                 {
00467                     if(file.IsRelative())
00468                         file.MakeAbsolute(cwd);
00469                     if(!containsInvalidCharacters(file.GetFullPath()))
00470                     {
00471                         filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
00472                     };
00473 
00474                     // Use the first filename to set actualPath.
00475                     if (! actualPathSet)
00476                     {
00477                         config->Write(wxT("/actualPath"), file.GetPath());
00478                         actualPathSet = true;
00479                     }
00480                 }
00481 #if defined __WXMSW__
00482                 } while (dir.GetNext(&foundFile));
00483 #endif
00484             }
00485             if(filesv.size()>0)
00486             {
00487                 std::vector<PanoCommand::PanoCommand*> cmds;
00488                 cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
00489                 cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
00490                 cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
00491                 PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::CombinedPanoCommand(pano, cmds));
00492             }
00493         }
00494     }
00495 #ifdef __WXMAC__
00496     m_macInitDone = true;
00497     if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
00498     m_macOpenFileOnStart = false;
00499 #endif
00500 
00501         //check for no tip switch, needed by PTBatcher
00502         wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
00503         if(secondParam.Cmp(_T("-notips"))!=0)
00504         {
00505                 //load tip startup preferences (tips will be started after splash terminates)
00506                 int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
00507 
00508                 //show tips if needed now
00509                 if(nValue > 0)
00510                 {
00511                         wxCommandEvent dummy;
00512                         frame->OnTipOfDay(dummy);
00513                 }
00514         }
00515 
00516     DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
00517     return true;
00518 }
00519 
00520 int huginApp::OnExit()
00521 {
00522     DEBUG_TRACE("");
00523     return wxApp::OnExit();
00524 }
00525 
00526 huginApp * huginApp::Get()
00527 {
00528     if (m_this) {
00529         return m_this;
00530     } else {
00531         DEBUG_FATAL("huginApp not yet created");
00532         DEBUG_ASSERT(m_this);
00533         return 0;
00534     }
00535 }
00536 
00537 MainFrame* huginApp::getMainFrame()
00538 {
00539     if (m_this) {
00540         return m_this->frame;
00541     } else {
00542         return 0;
00543     }
00544 }
00545 
00546 void huginApp::relayImageLoaded(ImageReadyEvent & event)
00547 {
00548     ImageCache::getInstance().postEvent(event.request, event.entry);
00549 }
00550 
00551 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
00552 {
00553     ImageReadyEvent event(request, entry);
00554     // AddPendingEvent adds the event to the event queue and returns without
00555     // processing it. This is necessary since we are probably not in the
00556     // UI thread, but the event handler must be run in the UI thread since it
00557     // could update image views.
00558     Get()->AddPendingEvent(event);
00559 }
00560 
00561 #ifdef __WXMAC__
00562 void huginApp::MacOpenFile(const wxString &fileName)
00563 {
00564     if(!m_macInitDone)
00565     {
00566         m_macOpenFileOnStart=true;
00567         m_macFileNameToOpenOnStart = fileName;
00568         return;
00569     }
00570 
00571     if(frame) frame->MacOnOpenFile(fileName);
00572 }
00573 #endif
00574 
00575 #if wxUSE_ON_FATAL_EXCEPTION
00576 void huginApp::OnFatalException()
00577 {
00578     GenerateReport(wxDebugReport::Context_Exception);
00579 };
00580 #endif
00581 
00582 huginApp * huginApp::m_this = 0;
00583 
00584 
00585 // utility functions
00586 
00587 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00588 {
00589     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00590 
00591     wxConfigBase * config = wxConfigBase::Get();
00592 
00593     // get display size
00594     int dx,dy;
00595     wxDisplaySize(&dx,&dy);
00596 
00597 #if ( __WXGTK__ )
00598 // restoring the splitter positions properly when maximising doesn't work.
00599 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00600         //size
00601         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00602         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00603         if (w > 0 && w <= dx) {
00604             frame->SetClientSize(w,h);
00605         } else {
00606             frame->Fit();
00607         }
00608         //position
00609         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00610         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00611         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00612             frame->Move(x, y);
00613         } else {
00614             frame->Move(0, 44);
00615         }
00616 #else
00617     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00618     if (maximized) {
00619         frame->Maximize();
00620         } else {
00621         //size
00622         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00623         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00624         if (w > 0 && w <= dx) {
00625             frame->SetClientSize(w,h);
00626         } else {
00627             frame->Fit();
00628         }
00629         //position
00630         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00631         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00632         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00633             frame->Move(x, y);
00634         } else {
00635             frame->Move(0, 44);
00636         }
00637     }
00638 #endif
00639 }
00640 
00641 
00642 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00643 {
00644     DEBUG_TRACE(basename);
00645 
00646     wxConfigBase * config = wxConfigBase::Get();
00647 
00648 #if ( __WXGTK__ )
00649 // restoring the splitter positions properly when maximising doesn't work.
00650 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00651     
00652         wxSize sz = frame->GetClientSize();
00653         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00654         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00655         wxPoint ps = frame->GetPosition();
00656         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00657         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00658         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00659 #else
00660     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00661         wxSize sz = frame->GetClientSize();
00662         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00663         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00664         wxPoint ps = frame->GetPosition();
00665         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00666         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00667         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00668     } else if (frame->IsMaximized()){
00669         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00670     }
00671 #endif
00672 }

Generated on 28 Aug 2015 for Hugintrunk by  doxygen 1.4.7