1 // -*- c-basic-offset: 4 -*-
2 
3 /** @file wxPlatform.cpp
4 *
5 *  @brief implementation of utility function
6 *
7 *  @author Pablo d'Angelo <pablo.dangelo@web.de>
8 */
9 
10 /*  This program is free software; you can redistribute it and/or
11 *  modify it under the terms of the GNU General Public
12 *  License as published by the Free Software Foundation; either
13 *  version 2 of the License, or (at your option) any later version.
14 *
15 *  This software is distributed in the hope that it will be useful,
16 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 *  General Public License for more details.
19 *
20 *  You should have received a copy of the GNU General Public
21 *  License along with this software. If not, see
22 *  <http://www.gnu.org/licenses/>.
23 *
24 */
25 
26 #include "wxPlatform.h"
27 #include <hugin_utils/utils.h>
28 
29 namespace hugin_utils
30 {
doubleTowxString(double d,int digits)31     wxString doubleTowxString(double d, int digits)
32     {
33         std::string t = hugin_utils::doubleToString(d, digits);
34         return wxString(t.c_str(), wxConvLocal);
35     }
36 
str2double(const wxString & s,double & d)37     bool str2double(const wxString& s, double & d)
38     {
39         if (!hugin_utils::stringToDouble(std::string(s.mb_str(wxConvLocal)), d))
40         {
41             return false;
42         }
43         return true;
44     }
45 
46 } // namespace
47 
48 #if defined __WXMSW__ && !wxCHECK_VERSION(3,1,1)
49   // workaround for wxWidgets bug 14888
50   // see: http://trac.wxwidgets.org/ticket/14888
51   // if this is fixed upstreams this workaround can be removed
DisplayHelpPage(const wxString & name)52 void HuginCHMHelpController::DisplayHelpPage(const wxString& name)
53 {
54     // instead of passing filename as dwData to HH_DISPLAY_TOPIC
55     // we pass chmFilename::filename to pszfile
56     wxString command(GetValidFilename());
57     command.Append(wxT("::"));
58     command.Append(name);
59     CallHtmlHelp(GetParentWindow(), command.t_str(), 0 /* =HH_DISPLAY_TOPIC */);
60 };
61 #endif
62 
63 #ifndef __WXMSW__
64 #include <wx/confbase.h>
65 #include <wx/gdicmn.h>
66 // check if the help window has correct position/size inside current display
67 // this is not done by wxWidgets
FixHelpSettings()68 WXIMPEX void FixHelpSettings()
69 {
70     wxConfigBase* config = wxConfigBase::Get();
71     int dw, dh;
72     wxDisplaySize(&dw, &dh);
73 
74     int x, y, w, h;
75     config->Read("/wxWindows/wxHtmlHelpController/hcX", &x, wxDefaultCoord);
76     config->Read("/wxWindows/wxHtmlHelpController/hcY", &y, wxDefaultCoord);
77     config->Read("/wxWindows/wxHtmlHelpController/hcW", &w, 700);
78     config->Read("/wxWindows/wxHtmlHelpController/hcH", &h, 480);
79     if (w > dw)
80     {
81         w = 700;
82         config->Write("/wxWindows/wxHtmlHelpController/hcW", w);
83     };
84     if (h > dh)
85     {
86         h = 480;
87         config->Write("/wxWindows/wxHtmlHelpController/hcH", h);
88     };
89     if (x<-1 || x>dw-100)
90     {
91         x = wxDefaultCoord;
92         config->Write("/wxWindows/wxHtmlHelpController/hcX", x);
93     };
94     if (y<-1 || y>dh - 100)
95     {
96         y = wxDefaultCoord;
97         config->Write("/wxWindows/wxHtmlHelpController/hcY", y);
98     };
99 }
100 #endif
101 
102 #if defined __WXGTK__ && wxCHECK_VERSION(3,1,1)
103 #include <wx/stdpaths.h>
104 #include <wx/app.h>
105 #include <wx/filename.h>
CheckConfigFilename()106 void CheckConfigFilename()
107 {
108     wxStandardPaths& paths = wxStandardPaths::Get();
109     // get config file name for old config filename
110     const wxFileName oldConfigFile (paths.GetUserConfigDir(), paths.MakeConfigFileName(wxTheApp->GetAppName(), wxStandardPaths::ConfigFileConv_Dot));
111     // now switch to XDG layout
112     paths.SetFileLayout(wxStandardPaths::FileLayout_XDG);
113     if (oldConfigFile.FileExists())
114     {
115         // get the new filename
116         const wxFileName newConfigFile(paths.GetUserConfigDir(), paths.MakeConfigFileName(wxTheApp->GetAppName(), wxStandardPaths::ConfigFileConv_Dot));
117         // if old file exists but not new file, move old config to new place
118         if (!newConfigFile.FileExists())
119         {
120             wxRenameFile(oldConfigFile.GetFullPath(), newConfigFile.GetFullPath());
121         };
122     };
123 };
124 #endif
125