1 /***************************************************************************
2  *
3  * Project:  OpenCPN
4  * Purpose:  OpenCPN Platform specific support utilities
5  * Author:   David Register
6  *
7  ***************************************************************************
8  *   Copyright (C) 2015 by David S. Register                               *
9  *                                                                         *
10  *   This program is free software; you can redistribute it and/or modify  *
11  *   it under the terms of the GNU General Public License as published by  *
12  *   the Free Software Foundation; either version 2 of the License, or     *
13  *   (at your option) any later version.                                   *
14  *                                                                         *
15  *   This program 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         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program; if not, write to the                         *
22  *   Free Software Foundation, Inc.,                                       *
23  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,  USA.         *
24  **************************************************************************/
25 
26 #ifndef OCPNPLATFORM_H
27 #define OCPNPLATFORM_H
28 
29 #include "wx/wxprec.h"
30 
31 #ifndef  WX_PRECOMP
32 #include "wx/wx.h"
33 #endif //precompiled headers
34 
35 #include <wx/log.h>
36 #include <wx/stdpaths.h>
37 #include <wx/clrpicker.h>
38 #include <wx/colourdata.h>
39 #include <wx/colordlg.h>
40 
41 #include <stdio.h>
42 #include <vector>
43 
44 class MyConfig;
45 class ArrayOfCDI;
46 
47 typedef struct {
48     char    tsdk[20];
49     char    hn[20];
50     char    msdk[20];
51 } PlatSpec;
52 
53 class OCPN_OSDetail
54 {
55 public:
OCPN_OSDetail()56     OCPN_OSDetail() {};
~OCPN_OSDetail()57     ~OCPN_OSDetail() {};
58 
59     std::string                 osd_name;
60     std::string                 osd_version;
61     std::vector<std::string>    osd_name_like;
62     std::string                 osd_arch;
63     std::string                 osd_ID;
64 
65 };
66 
67 
68 //--------------------------------------------------------------------------
69 //      Per-Platform Utility support
70 //--------------------------------------------------------------------------
71 
72 // #ifdef __WXQT__
73 // extern bool LoadQtStyleSheet(wxString &sheet_file);
74 // extern QString getQtStyleSheet( void );
75 // #endif
76 
77 
78 class OCPNPlatform
79 {
80 public:
81     OCPNPlatform();
82     ~OCPNPlatform();
83 
84 
85 //      Internal Device Support
86     static bool hasInternalGPS(wxString profile = _T(""));      // GPS
87 
88     static bool hasInternalBT(wxString profile = _T(""));       // Bluetooth
89     bool startBluetoothScan();
90     wxArrayString getBluetoothScanResults();
91     bool stopBluetoothScan();
92 
93 //  Per-Platform initialization support
94 
95     //  Called from MyApp() immediately upon entry to MyApp::OnInit()
96     static void Initialize_1( void );
97 
98     //  Called from MyApp() immediately before creation of MyFrame()
99     void Initialize_2( void );
100 
101     //  Called from MyApp()::OnInit() just after gFrame is created, so gFrame is available
102     void Initialize_3( void );
103 
104     //  Called from MyApp() just before end of MyApp::OnInit()
105     static void Initialize_4( void );
106 
107     static void OnExit_1( void );
108     static void OnExit_2( void );
109 
110 
111     void SetDefaultOptions( void );
112     void SetUpgradeOptions( wxString vString, wxString vStringConfig );
113 
114     void applyExpertMode(bool mode);
115     OCPN_OSDetail *GetOSDetail();
116 
117     bool DetectOSDetail( OCPN_OSDetail *detail);
118 
119 //--------------------------------------------------------------------------
120 //      Platform Display Support
121 //--------------------------------------------------------------------------
122     static void ShowBusySpinner( void );
123     static void HideBusySpinner( void );
124     double getFontPointsperPixel( void );
125     wxSize getDisplaySize();
126     double GetDisplaySizeMM();
127     double GetDisplayAreaCM2();
128 
129     void SetDisplaySizeMM( double size );
130     double GetDisplayDPmm();
131     unsigned int GetSelectRadiusPix();
132     double GetToolbarScaleFactor( int GUIScaleFactor );
133     double GetCompassScaleFactor( int GUIScaleFactor );
134 
135     wxFileDialog *AdjustFileDialogFont(wxWindow *container, wxFileDialog *dlg);
136     wxDirDialog  *AdjustDirDialogFont(wxWindow *container,  wxDirDialog *dlg);
137 
138     void PositionAISAlert( wxWindow *alert_window);
139     float getChartScaleFactorExp( float scale_linear );
140     int GetStatusBarFieldCount();
141     bool GetFullscreen();
142     bool SetFullscreen( bool bFull );
143     bool AllowAlertDialog(const wxString& class_name);
144     double GetDisplayDensityFactor();
145     double m_pt_per_pixel;
146     long GetDefaultToolbarOrientation();
147 
148 //--------------------------------------------------------------------------
149 //      Per-Platform file/directory support
150 //--------------------------------------------------------------------------
151 
152     wxStandardPaths& GetStdPaths();
153     wxString &GetHomeDir();
154     wxString &GetExePath();
155     wxString &GetSharedDataDir();
156     wxString &GetPrivateDataDir();
157     wxString GetWritableDocumentsDir();
158 
159     /** The original in-tree plugin directory, sometimes not user-writable.*/
160     wxString &GetPluginDir();
161 
162     /**
163      * Base directory for user writable windows plugins, reflects
164      * winPluginDir option, defaults to %LOCALAPPDATA%/opencpn.
165      **/
166      wxString GetWinPluginBaseDir();
167 
168     /**
169      * Return ';'-separated list of base directories for plugin data. The
170      * list always includes the main installation directory. Some platforms
171      * prepends this with user-writable path(s), each of which ending in
172      * "opencpn". All paths are guaranteed to exist.
173      *
174      * For Linux, return paths ending in .../share.
175      */
176     wxString GetPluginDataPath();
177 
178     /** Return true if ocpn is running in a flatpak sandbox. */
isFlatpacked()179     bool isFlatpacked() { return m_isFlatpacked; }
180 
181     wxString &GetConfigFileName();
182     wxString *GetPluginDirPtr();
183     wxString *GetSharedDataDirPtr();
184     wxString *GetPrivateDataDirPtr();
GetLogFileName()185     wxString &GetLogFileName(){ return mlog_file; }
186     MyConfig *GetConfigObject();
187     wxString GetSupplementalLicenseString();
188     wxString NormalizePath(const wxString &full_path); //Adapt for portable use
189 
190     int DoFileSelectorDialog( wxWindow *parent, wxString *file_spec, wxString Title, wxString initDir,
191                                 wxString suggestedName, wxString wildcard);
192     int DoDirSelectorDialog( wxWindow *parent, wxString *file_spec, wxString Title, wxString initDir, bool b_addFiles = true);
193 
194     bool InitializeLogFile( void );
195     void CloseLogFile( void );
GetLargeLogMessage(void)196     wxString    &GetLargeLogMessage( void ){ return large_log_message; }
GetLogFilePtr()197     FILE        *GetLogFilePtr(){ return flog; }
198 
199 
200 
201 //--------------------------------------------------------------------------
202 //      Per-Platform Utility support
203 //--------------------------------------------------------------------------
204     void setChartTypeMaskSel(int mask, wxString &indicator);
205     bool isPlatformCapable( int flag);
206 #define PLATFORM_CAP_PLUGINS   1
207 #define PLATFORM_CAP_FASTPAN   2
208     void LaunchLocalHelp();
209     void DoHelpDialog( void );
210 
211     int platformApplyPrivateSettingsString( wxString settings, ArrayOfCDI *pDirArray);
212     void platformLaunchDefaultBrowser( wxString URL );
213 
214     void SetLocaleSearchPrefixes( void );
215     wxString GetDefaultSystemLocale();
216 
217 #if wxUSE_XLOCALE
218     wxString GetAdjustedAppLocale();
219     wxString ChangeLocale(wxString &newLocaleID, wxLocale *presentLocale, wxLocale** newLocale);
220 #endif
221 
222 
223 //--------------------------------------------------------------------------
224 //      Per-Platform OpenGL support
225 //--------------------------------------------------------------------------
226     bool BuildGLCaps( void *pbuf );
227     bool IsGLCapable();
228 
229 private:
230     bool        GetWindowsMonitorSize( int *width, int *height);
231 
232     wxString    m_homeDir;
233     wxString    m_exePath;
234     wxString    m_SData_Dir;
235     wxString    m_PrivateDataDir;
236     wxString    m_PluginsDir;
237     wxString    m_config_file_name;
238     wxString    m_pluginDataPath;
239 
240     wxString    mlog_file;
241     FILE        *flog;
242     wxLog       *m_Oldlogger;
243     wxString    large_log_message;
244     wxSize      m_displaySize;
245     wxSize      m_displaySizeMM;
246     int         m_displaySizeMMOverride;
247 
248     int         m_monitorWidth, m_monitorHeight;
249     bool        m_bdisableWindowsDisplayEnum;
250     bool        m_isFlatpacked;
251     OCPN_OSDetail *m_osDetail;
252 
253 };
254 
255 
256 //--------------------------------------------------------------------------
257 //      Private colourPicker control
258 //--------------------------------------------------------------------------
259 
260 class OCPNColourPickerCtrl : public wxBitmapButton
261 {
262 public:
263     OCPNColourPickerCtrl();
264     OCPNColourPickerCtrl(wxWindow *parent,
265                    wxWindowID id,
266                    const wxColour& initial = *wxBLACK,
267                    const wxPoint& pos = wxDefaultPosition,
268                    const wxSize& size = wxDefaultSize,
269                    long style = 0,
270                    const wxValidator& validator = wxDefaultValidator,
271                    const wxString& name = _T(""));
272 
273     bool Create(wxWindow *parent,
274                 wxWindowID id,
275                 const wxColour& initial = *wxBLACK,
276                 const wxPoint& pos = wxDefaultPosition,
277                 const wxSize& size = wxDefaultSize,
278                 long style = 0,
279                 const wxValidator& validator = wxDefaultValidator,
280                 const wxString& name = _T(""));
281 
282     void OnButtonClick(wxCommandEvent& WXUNUSED(ev));
283     void InitColourData();
284     void SetColour( wxColour& c);
285     wxColour GetColour( void );
286 
287 protected:
288     virtual void UpdateColour();
289     wxSize DoGetBestSize() const;
290 
291     void OnPaint(wxPaintEvent &event) ;
292 
293     DECLARE_EVENT_TABLE() ;
294 
295 private:
296     wxBitmap m_bitmap;
297     wxColour m_colour;
298     wxColourData ms_data;
299 
300 };
301 
302 
303 
304 
305 
306 #endif          //guard
307