OpenCPN Partial API docs
OCPNPlatform.h
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 <cstdio>
30 #include <string>
31 #include <vector>
32 
33 // if wxWidgets headers have not been included, include them now
34 #ifndef _WX_DEFS_H_
35 #include <wx/wxprec.h>
36 
37 #ifndef WX_PRECOMP
38 #include <wx/wx.h>
39 #endif // precompiled headers
40 
41 #endif // _WX_DEFS_H_
42 
43 #include <wx/bmpbuttn.h>
44 #include <wx/clrpicker.h>
45 #include <wx/colordlg.h>
46 #include <wx/colour.h>
47 #include <wx/colourdata.h>
48 #include <wx/dirdlg.h>
49 #include <wx/filedlg.h>
50 #include <wx/gdicmn.h>
51 #include <wx/stdpaths.h>
52 #include <wx/string.h>
53 #include <wx/validate.h>
54 #include <wx/window.h>
55 
56 #include "model/base_platform.h"
57 
58 class MyConfig;
59 class ArrayOfCDI;
60 
61 
62 //--------------------------------------------------------------------------
63 // Per-Platform Utility support
64 //--------------------------------------------------------------------------
65 
66 // #ifdef __WXQT__
67 // extern bool LoadQtStyleSheet(wxString &sheet_file);
68 // extern QString getQtStyleSheet( void );
69 // #endif
70 
71 class OCPNPlatform : public BasePlatform {
72 public:
73  OCPNPlatform();
74  virtual ~OCPNPlatform();
75 
76  // Internal Device Support
77  static bool hasInternalGPS(wxString profile = _T("")); // GPS
78 
79  static bool hasInternalBT(wxString profile = _T("")); // Bluetooth
80  bool startBluetoothScan();
81  wxArrayString getBluetoothScanResults();
82  bool stopBluetoothScan();
83 
84  // Per-Platform initialization support
85 
86  // Called from MyApp() immediately upon entry to MyApp::OnInit()
87  static void Initialize_1(void);
88 
89  // Called from MyApp() immediately before creation of MyFrame()
90  void Initialize_2(void);
91 
92  // Called from MyApp()::OnInit() just after gFrame is created, so gFrame is
93  // available
94  void Initialize_3(void);
95 
96  // Called from MyApp() just before end of MyApp::OnInit()
97  static void Initialize_4(void);
98 
99  static void OnExit_1(void);
100  static void OnExit_2(void);
101 
102  void SetDefaultOptions(void);
103  void SetUpgradeOptions(wxString vString, wxString vStringConfig);
104 
105  void applyExpertMode(bool mode);
106 
107  //--------------------------------------------------------------------------
108  // Platform Display Support
109  //--------------------------------------------------------------------------
110  virtual void ShowBusySpinner(void);
111  virtual void HideBusySpinner(void);
112  double getFontPointsperPixel(void);
113  wxSize getDisplaySize();
114  double GetDisplaySizeMM();
115  double GetDisplayAreaCM2();
116  virtual double GetDisplayDPmm();
117 
118  void SetDisplaySizeMM(size_t monitor, double size);
119  unsigned int GetSelectRadiusPix();
120  double GetToolbarScaleFactor(int GUIScaleFactor);
121  double GetCompassScaleFactor(int GUIScaleFactor);
122 
123  wxFileDialog *AdjustFileDialogFont(wxWindow *container, wxFileDialog *dlg);
124  wxDirDialog *AdjustDirDialogFont(wxWindow *container, wxDirDialog *dlg);
125 
126  void PositionAISAlert(wxWindow *alert_window);
127  float GetChartScaleFactorExp(float scale_linear);
128  float GetMarkScaleFactorExp(float scale_linear);
129  //float GetDIPScaleFactor();
130  int GetStatusBarFieldCount();
131  bool GetFullscreen();
132  bool SetFullscreen(bool bFull);
133  bool AllowAlertDialog(const wxString &class_name);
134  double GetDisplayDensityFactor();
135  double m_pt_per_pixel;
136  long GetDefaultToolbarOrientation();
137 
138  //--------------------------------------------------------------------------
139  // Per-Platform file/directory support
140  //--------------------------------------------------------------------------
141 
142  MyConfig *GetConfigObject();
143  wxString GetSupplementalLicenseString();
144 
145  int DoFileSelectorDialog(wxWindow *parent, wxString *file_spec,
146  wxString Title, wxString initDir,
147  wxString suggestedName, wxString wildcard);
148  int DoDirSelectorDialog(wxWindow *parent, wxString *file_spec, wxString Title,
149  wxString initDir, bool b_addFiles = true);
150 
151 
152  //--------------------------------------------------------------------------
153  // Per-Platform Utility support
154  //--------------------------------------------------------------------------
155  void setChartTypeMaskSel(int mask, wxString &indicator);
156  bool isPlatformCapable(int flag);
157  void LaunchLocalHelp();
158  void DoHelpDialog(void);
159 
160  int platformApplyPrivateSettingsString(wxString settings,
161  ArrayOfCDI *pDirArray);
162  void platformLaunchDefaultBrowser(wxString URL);
163 
164  void SetLocaleSearchPrefixes(void);
165  wxString GetDefaultSystemLocale();
166 
167 #if wxUSE_XLOCALE
168  wxString GetAdjustedAppLocale();
169  wxString ChangeLocale(wxString &newLocaleID, wxLocale *presentLocale,
170  wxLocale **newLocale);
171 #endif
172 
173  //--------------------------------------------------------------------------
174  // Per-Platform OpenGL support
175  //--------------------------------------------------------------------------
176  bool BuildGLCaps(void *pbuf);
177  bool IsGLCapable();
178 
179 private:
180  wxString m_SData_Dir;
181 
182 
183 };
184 
185 // Private colourPicker control
186 //--------------------------------------------------------------------------
187 
188 class OCPNColourPickerCtrl : public wxBitmapButton {
189 public:
191  OCPNColourPickerCtrl(wxWindow *parent, wxWindowID id,
192  const wxColour &initial = *wxBLACK,
193  const wxPoint &pos = wxDefaultPosition,
194  const wxSize &size = wxDefaultSize, long style = 0,
195  const wxValidator &validator = wxDefaultValidator,
196  const wxString &name = _T(""));
197 
198  bool Create(wxWindow *parent, wxWindowID id,
199  const wxColour &initial = *wxBLACK,
200  const wxPoint &pos = wxDefaultPosition,
201  const wxSize &size = wxDefaultSize, long style = 0,
202  const wxValidator &validator = wxDefaultValidator,
203  const wxString &name = _T(""));
204 
205  void OnButtonClick(wxCommandEvent &WXUNUSED(ev));
206  void InitColourData();
207  void SetColour(wxColour &c);
208  wxColour GetColour(void);
209 
210 protected:
211  virtual void UpdateColour();
212  wxSize DoGetBestSize() const;
213 
214  void OnPaint(wxPaintEvent &event);
215 
216  DECLARE_EVENT_TABLE();
217 
218 private:
219  wxBitmap m_bitmap;
220  wxColour m_colour;
221  wxColourData ms_data;
222 };
223 
224 #endif // guard