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

Generated on Thu Apr 17 01:25:33 2014 for Hugintrunk by  doxygen 1.3.9.1