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

Generated on 27 Jul 2016 for Hugintrunk by  doxygen 1.4.7