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         wxString thePath = MacGetPathToBundledResourceFile(CFSTR("locale"));
00232         if(thePath != wxT(""))
00233             locale.AddCatalogLookupPathPrefix(thePath);
00234         else {
00235             wxMessageBox(_("Translations not found in bundle"), _("Fatal Error"));
00236             return false;
00237         }
00238     }
00239         
00240 #else
00241     // add the locale directory specified during configure
00242     m_xrcPrefix = wxT(INSTALL_XRC_DIR);
00243     m_DataDir = wxT(INSTALL_DATA_DIR);
00244     locale.AddCatalogLookupPathPrefix(wxT(INSTALL_LOCALE_DIR));
00245 #endif
00246 
00247     if ( ! wxFile::Exists(m_xrcPrefix + wxT("/main_frame.xrc")) ) {
00248         wxMessageBox(_("xrc directory not found, hugin needs to be properly installed\nTried Path:" + m_xrcPrefix ), _("Fatal Error"));
00249         return false;
00250     }
00251 
00252     // here goes and comes configuration
00253     wxConfigBase * config = wxConfigBase::Get();
00254     // do not record default values in the preferences file
00255     config->SetRecordDefaults(false);
00256 
00257     config->Flush();
00258 
00259     // initialize i18n
00260 #if defined _MSC_VER && defined Hugin_shared
00261     setlocale(LC_NUMERIC, "");
00262 #endif
00263     int localeID = config->Read(wxT("language"), (long) HUGIN_LANGUAGE);
00264     DEBUG_TRACE("localeID: " << localeID);
00265     {
00266         bool bLInit;
00267             bLInit = locale.Init(localeID);
00268             if (bLInit) {
00269                 DEBUG_TRACE("locale init OK");
00270                 DEBUG_TRACE("System Locale: " << locale.GetSysName().mb_str(wxConvLocal))
00271                 DEBUG_TRACE("Canonical Locale: " << locale.GetCanonicalName().mb_str(wxConvLocal))
00272         } else {
00273           DEBUG_TRACE("locale init failed");
00274         }
00275         }
00276         
00277     // set the name of locale recource to look for
00278     locale.AddCatalog(wxT("hugin"));
00279 
00280     // initialize image handlers
00281     wxInitAllImageHandlers();
00282 
00283     // Initialize all the XRC handlers.
00284     wxXmlResource::Get()->InitAllHandlers();
00285 
00286     // load all XRC files.
00287     #ifdef _INCLUDE_UI_RESOURCES
00288         InitXmlResource();
00289     #else
00290 
00291     // add custom XRC handlers
00292     wxXmlResource::Get()->AddHandler(new ImagesPanelXmlHandler());
00293     wxXmlResource::Get()->AddHandler(new CPEditorPanelXmlHandler());
00294     wxXmlResource::Get()->AddHandler(new CPImageCtrlXmlHandler());
00295     wxXmlResource::Get()->AddHandler(new CPImagesComboBoxXmlHandler());
00296     wxXmlResource::Get()->AddHandler(new MaskEditorPanelXmlHandler());
00297     wxXmlResource::Get()->AddHandler(new ImagesListMaskXmlHandler());
00298     wxXmlResource::Get()->AddHandler(new MaskImageCtrlXmlHandler());
00299     wxXmlResource::Get()->AddHandler(new OptimizePanelXmlHandler());
00300     wxXmlResource::Get()->AddHandler(new OptimizePhotometricPanelXmlHandler());
00301     wxXmlResource::Get()->AddHandler(new PanoPanelXmlHandler());
00302     wxXmlResource::Get()->AddHandler(new PreviewPanelXmlHandler());
00303     wxXmlResource::Get()->AddHandler(new HtmlWindowXmlHandler());
00304 #if wxCHECK_VERSION(2,9,0)
00305     wxXmlResource::Get()->AddHandler(new wxcode::wxTreeListCtrlXmlHandler());
00306 #else
00307     wxXmlResource::Get()->AddHandler(new wxTreeListCtrlXmlHandler());
00308 #endif
00309     wxXmlResource::Get()->AddHandler(new ImagesTreeCtrlXmlHandler());
00310     wxXmlResource::Get()->AddHandler(new CPListCtrlXmlHandler());
00311 
00312     // load XRC files
00313     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_list_frame.xrc"));
00314     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("preview_frame.xrc"));
00315     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("edit_script_dialog.xrc"));
00316     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_menu.xrc"));
00317     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_tool.xrc"));
00318     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("about.xrc"));
00319     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pref_dialog.xrc"));
00320     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cpdetector_dialog.xrc"));
00321     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("reset_dialog.xrc"));
00322     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_photo_panel.xrc"));
00323     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("cp_editor_panel.xrc"));
00324     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("images_panel.xrc"));
00325     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("main_frame.xrc"));
00326     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("optimize_panel.xrc"));
00327     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("pano_panel.xrc"));
00328     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("mask_editor_panel.xrc"));
00329     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("lensdb_dialogs.xrc"));
00330     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("image_variable_dlg.xrc"));
00331     wxXmlResource::Get()->Load(m_xrcPrefix + wxT("dlg_warning.xrc"));
00332 #endif
00333 
00334 #ifdef __WXMAC__
00335     // If hugin is starting with file opening AppleEvent, MacOpenFile will be called on first wxYield().
00336     // Those need to be initialised before first call of Yield which happens in Mainframe constructor.
00337     m_macInitDone=false;
00338     m_macOpenFileOnStart=false;
00339 #endif
00340     // read monitor profile
00341     HuginBase::Color::GetMonitorProfile(m_monitorProfileName, m_monitorProfile);
00342     // create main frame
00343     frame = new MainFrame(NULL, pano);
00344     SetTopWindow(frame);
00345 
00346     // setup main frame size, after it has been created.
00347     RestoreFramePosition(frame, wxT("MainFrame"));
00348 #ifdef __WXMSW__
00349     provider->SetHelpController(&frame->GetHelpController());
00350     frame->GetHelpController().Initialize(m_xrcPrefix+wxT("data/hugin_help_en_EN.chm"));
00351     frame->SendSizeEvent();
00352 #if wxCHECK_VERSION(3,1,0)
00353     wxTaskBarJumpList jumpList;
00354     wxFileName exeFile(wxStandardPaths::Get().GetExecutablePath());
00355     exeFile.SetName("PTBatcherGUI");
00356     wxTaskBarJumpListItem *item1 = new wxTaskBarJumpListItem(
00357         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Batch Processor"), exeFile.GetFullPath(), wxEmptyString,
00358         _("Opens PTBatcher, the batch processor for Hugin's project files"),
00359         exeFile.GetFullPath(), 0);
00360     jumpList.GetTasks().Append(item1);
00361     exeFile.SetName("calibrate_lens_gui");
00362     wxTaskBarJumpListItem *item2 = new wxTaskBarJumpListItem(
00363         NULL, wxTASKBAR_JUMP_LIST_TASK, _("Open Lens calibrate tool"), exeFile.GetFullPath(), wxEmptyString,
00364         _("Opens Calibrate_lens_gui, a simple GUI for lens calibration"),
00365         exeFile.GetFullPath(), 0);
00366     jumpList.GetTasks().Append(item2);
00367 #endif
00368 #endif
00369 
00370     // we are closing Hugin, if the top level window is deleted
00371     SetExitOnFrameDelete(true);
00372     // show the frame.
00373     if(frame->GetGuiLevel()==GUI_SIMPLE)
00374     {
00375         SetTopWindow(frame->getGLPreview());
00376     }
00377     else
00378     {
00379         frame->Show(TRUE);
00380     };
00381 
00382     wxString cwd = wxFileName::GetCwd();
00383 
00384     m_workDir = config->Read(wxT("tempDir"),wxT(""));
00385     // FIXME, make secure against some symlink attacks
00386     // get a temp dir
00387     if (m_workDir == wxT("")) {
00388 #if (defined __WXMSW__)
00389         DEBUG_DEBUG("figuring out windows temp dir");
00390         /* added by Yili Zhao */
00391         wxChar buffer[MAX_PATH];
00392         GetTempPath(MAX_PATH, buffer);
00393         m_workDir = buffer;
00394 #elif (defined __WXMAC__) && (defined MAC_SELF_CONTAINED_BUNDLE)
00395         DEBUG_DEBUG("temp dir on Mac");
00396         m_workDir = MacGetPathToUserDomainTempDir();
00397         if(m_workDir == wxT(""))
00398             m_workDir = wxT("/tmp");
00399 #else //UNIX
00400         DEBUG_DEBUG("temp dir on unix");
00401         // try to read environment variable
00402         if (!wxGetEnv(wxT("TMPDIR"), &m_workDir)) {
00403             // still no tempdir, use /tmp
00404             m_workDir = wxT("/tmp");
00405         }
00406 #endif
00407         
00408     }
00409 
00410     if (!wxFileName::DirExists(m_workDir)) {
00411         DEBUG_DEBUG("creating temp dir: " << m_workDir.mb_str(wxConvLocal));
00412         if (!wxMkdir(m_workDir)) {
00413             DEBUG_ERROR("Tempdir could not be created: " << m_workDir.mb_str(wxConvLocal));
00414         }
00415     }
00416     if (!wxSetWorkingDirectory(m_workDir)) {
00417         DEBUG_ERROR("could not change to temp. dir: " << m_workDir.mb_str(wxConvLocal));
00418     }
00419     DEBUG_DEBUG("using temp dir: " << m_workDir.mb_str(wxConvLocal));
00420 
00421     // set some suitable defaults
00422     PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::wxNewProjectCmd(pano));
00423     PanoCommand::GlobalCmdHist::getInstance().clear();
00424 
00425     // suppress tiff warnings
00426     TIFFSetWarningHandler(0);
00427 
00428     if (argc > 1)
00429     {
00430 #ifdef __WXMSW__
00431         //on Windows we need to update the fast preview first
00432         //otherwise there is an infinite loop when starting with a project file
00433         //and closed panorama editor aka mainframe
00434         if(frame->GetGuiLevel()==GUI_SIMPLE)
00435         {
00436             frame->getGLPreview()->Update();
00437         };
00438 #endif
00439         wxFileName file(argv[1]);
00440         // if the first file is a project file, open it
00441         if (file.GetExt().CmpNoCase(wxT("pto")) == 0 ||
00442             file.GetExt().CmpNoCase(wxT("pts")) == 0 ||
00443             file.GetExt().CmpNoCase(wxT("ptp")) == 0 )
00444         {
00445             if(file.IsRelative())
00446                 file.MakeAbsolute(cwd);
00447             // Loading the project file with set actualPath to its
00448             // parent directory.  (actualPath is used as starting
00449             // directory by many subsequent file selection dialogs.)
00450             frame->LoadProjectFile(file.GetFullPath());
00451         } else {
00452             std::vector<std::string> filesv;
00453             bool actualPathSet = false;
00454             for (int i=1; i< argc; i++) 
00455             {
00456 #if defined __WXMSW__
00457                 //expand wildcards
00458                 wxFileName fileList(argv[i]);
00459                 if(fileList.IsRelative())
00460                     fileList.MakeAbsolute(cwd);
00461                 wxDir dir;
00462                 wxString foundFile;
00463                 wxFileName file;
00464                 if(fileList.DirExists())
00465                     if(dir.Open(fileList.GetPath()))
00466                         if(dir.GetFirst(&foundFile,fileList.GetFullName(),wxDIR_FILES | wxDIR_HIDDEN))
00467                             do
00468                             {
00469                                 file=foundFile;
00470                                 file.MakeAbsolute(dir.GetName());
00471 #else
00472                 wxFileName file(argv[i]);
00473 #endif
00474                 if (file.GetExt().CmpNoCase(wxT("jpg")) == 0 ||
00475                     file.GetExt().CmpNoCase(wxT("jpeg")) == 0 ||
00476                     file.GetExt().CmpNoCase(wxT("tif")) == 0 ||
00477                     file.GetExt().CmpNoCase(wxT("tiff")) == 0 ||
00478                     file.GetExt().CmpNoCase(wxT("png")) == 0 ||
00479                     file.GetExt().CmpNoCase(wxT("bmp")) == 0 ||
00480                     file.GetExt().CmpNoCase(wxT("gif")) == 0 ||
00481                     file.GetExt().CmpNoCase(wxT("pnm")) == 0 ||
00482                     file.GetExt().CmpNoCase(wxT("sun")) == 0 ||
00483                     file.GetExt().CmpNoCase(wxT("hdr")) == 0 ||
00484                     file.GetExt().CmpNoCase(wxT("viff")) == 0 )
00485                 {
00486                     if(file.IsRelative())
00487                         file.MakeAbsolute(cwd);
00488                     if(!containsInvalidCharacters(file.GetFullPath()))
00489                     {
00490                         filesv.push_back((const char *)(file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)));
00491                     };
00492 
00493                     // Use the first filename to set actualPath.
00494                     if (! actualPathSet)
00495                     {
00496                         config->Write(wxT("/actualPath"), file.GetPath());
00497                         actualPathSet = true;
00498                     }
00499                 }
00500 #if defined __WXMSW__
00501                 } while (dir.GetNext(&foundFile));
00502 #endif
00503             }
00504             if(filesv.size()>0)
00505             {
00506                 std::vector<PanoCommand::PanoCommand*> cmds;
00507                 cmds.push_back(new PanoCommand::wxAddImagesCmd(pano,filesv));
00508                 cmds.push_back(new PanoCommand::DistributeImagesCmd(pano));
00509                 cmds.push_back(new PanoCommand::CenterPanoCmd(pano));
00510                 PanoCommand::GlobalCmdHist::getInstance().addCommand(new PanoCommand::CombinedPanoCommand(pano, cmds));
00511             }
00512         }
00513     }
00514 #ifdef __WXMAC__
00515     m_macInitDone = true;
00516     if(m_macOpenFileOnStart) {frame->LoadProjectFile(m_macFileNameToOpenOnStart);}
00517     m_macOpenFileOnStart = false;
00518 #endif
00519 
00520         //check for no tip switch, needed by PTBatcher
00521         wxString secondParam = argc > 2 ? wxString(argv[2]) : wxString();
00522         if(secondParam.Cmp(_T("-notips"))!=0)
00523         {
00524                 //load tip startup preferences (tips will be started after splash terminates)
00525                 int nValue = config->Read(wxT("/MainFrame/ShowStartTip"), 1l);
00526 
00527                 //show tips if needed now
00528                 if(nValue > 0)
00529                 {
00530                         wxCommandEvent dummy;
00531                         frame->OnTipOfDay(dummy);
00532                 }
00533         }
00534 
00535     DEBUG_TRACE("=========================== huginApp::OnInit() end ===================");
00536     return true;
00537 }
00538 
00539 int huginApp::OnExit()
00540 {
00541     DEBUG_TRACE("");
00542 #ifdef __WXMSW__    
00543     delete wxHelpProvider::Set(NULL);
00544 #endif
00545 
00546     return wxApp::OnExit();
00547 }
00548 
00549 huginApp * huginApp::Get()
00550 {
00551     if (m_this) {
00552         return m_this;
00553     } else {
00554         DEBUG_FATAL("huginApp not yet created");
00555         DEBUG_ASSERT(m_this);
00556         return 0;
00557     }
00558 }
00559 
00560 MainFrame* huginApp::getMainFrame()
00561 {
00562     if (m_this) {
00563         return m_this->frame;
00564     } else {
00565         return 0;
00566     }
00567 }
00568 
00569 void huginApp::relayImageLoaded(ImageReadyEvent & event)
00570 {
00571     ImageCache::getInstance().postEvent(event.request, event.entry);
00572 }
00573 
00574 void huginApp::imageLoadedAsync(ImageCache::RequestPtr request, ImageCache::EntryPtr entry)
00575 {
00576     ImageReadyEvent event(request, entry);
00577     // AddPendingEvent adds the event to the event queue and returns without
00578     // processing it. This is necessary since we are probably not in the
00579     // UI thread, but the event handler must be run in the UI thread since it
00580     // could update image views.
00581     Get()->AddPendingEvent(event);
00582 }
00583 
00584 #ifdef __WXMAC__
00585 void huginApp::MacOpenFile(const wxString &fileName)
00586 {
00587     if(!m_macInitDone)
00588     {
00589         m_macOpenFileOnStart=true;
00590         m_macFileNameToOpenOnStart = fileName;
00591         return;
00592     }
00593 
00594     if(frame) frame->MacOnOpenFile(fileName);
00595 }
00596 #endif
00597 
00598 #if wxUSE_ON_FATAL_EXCEPTION
00599 void huginApp::OnFatalException()
00600 {
00601     GenerateReport(wxDebugReport::Context_Exception);
00602 };
00603 #endif
00604 
00605 huginApp * huginApp::m_this = 0;
00606 
00607 
00608 // utility functions
00609 
00610 void RestoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00611 {
00612     DEBUG_TRACE(basename.mb_str(wxConvLocal));
00613 
00614     wxConfigBase * config = wxConfigBase::Get();
00615 
00616     // get display size
00617     int dx,dy;
00618     wxDisplaySize(&dx,&dy);
00619 
00620 #if ( __WXGTK__ )
00621 // restoring the splitter positions properly when maximising doesn't work.
00622 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00623         //size
00624         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00625         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00626         if (w > 0 && w <= dx) {
00627             frame->SetClientSize(w,h);
00628         } else {
00629             frame->Fit();
00630         }
00631         //position
00632         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00633         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00634         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00635             frame->Move(x, y);
00636         } else {
00637             frame->Move(0, 44);
00638         }
00639 #else
00640     bool maximized = config->Read(wxT("/") + basename + wxT("/maximized"), 0l) != 0;
00641     if (maximized) {
00642         frame->Maximize();
00643         } else {
00644         //size
00645         int w = config->Read(wxT("/") + basename + wxT("/width"),-1l);
00646         int h = config->Read(wxT("/") + basename + wxT("/height"),-1l);
00647         if (w > 0 && w <= dx) {
00648             frame->SetClientSize(w,h);
00649         } else {
00650             frame->Fit();
00651         }
00652         //position
00653         int x = config->Read(wxT("/") + basename + wxT("/positionX"),-1l);
00654         int y = config->Read(wxT("/") + basename + wxT("/positionY"),-1l);
00655         if ( y >= 0 && x >= 0 && x < dx && y < dy) {
00656             frame->Move(x, y);
00657         } else {
00658             frame->Move(0, 44);
00659         }
00660     }
00661 #endif
00662 }
00663 
00664 
00665 void StoreFramePosition(wxTopLevelWindow * frame, const wxString & basename)
00666 {
00667     DEBUG_TRACE(basename);
00668 
00669     wxConfigBase * config = wxConfigBase::Get();
00670 
00671 #if ( __WXGTK__ )
00672 // restoring the splitter positions properly when maximising doesn't work.
00673 // Disabling maximise on wxWidgets >= 2.6.0 and gtk
00674     
00675         wxSize sz = frame->GetClientSize();
00676         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00677         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00678         wxPoint ps = frame->GetPosition();
00679         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00680         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00681         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00682 #else
00683     if ( (! frame->IsMaximized()) && (! frame->IsIconized()) ) {
00684         wxSize sz = frame->GetClientSize();
00685         config->Write(wxT("/") + basename + wxT("/width"), sz.GetWidth());
00686         config->Write(wxT("/") + basename + wxT("/height"), sz.GetHeight());
00687         wxPoint ps = frame->GetPosition();
00688         config->Write(wxT("/") + basename + wxT("/positionX"), ps.x);
00689         config->Write(wxT("/") + basename + wxT("/positionY"), ps.y);
00690         config->Write(wxT("/") + basename + wxT("/maximized"), 0);
00691     } else if (frame->IsMaximized()){
00692         config->Write(wxT("/") + basename + wxT("/maximized"), 1l);
00693     }
00694 #endif
00695 }

Generated on 31 May 2016 for Hugintrunk by  doxygen 1.4.7