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

Generated on 30 Apr 2016 for Hugintrunk by  doxygen 1.4.7