OpenCPN Partial API docs
base_platform.h
1 /***************************************************************************
2  *
3  * Project: OpenCPN
4  * Purpose: Basic platform specific support utilities without GUI deps.
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 BASEPLATFORM_H
27 #define BASEPLATFORM_H
28 
29 #include <stdio.h>
30 #include <vector>
31 
32 #include <wx/wxprec.h>
33 
34 #ifndef WX_PRECOMP
35 #include <wx/wx.h>
36 #endif // precompiled headers
37 
38 #include <wx/gdicmn.h>
39 #include <wx/log.h>
40 #include <wx/stdpaths.h>
41 #include <wx/clrpicker.h>
42 #include <wx/colourdata.h>
43 #include <wx/colordlg.h>
44 
45 
46 #define PLATFORM_CAP_PLUGINS 1
47 #define PLATFORM_CAP_FASTPAN 2
48 
49 class BasePlatform; // forward
50 
52 extern BasePlatform* g_BasePlatform;
53 
54 typedef struct {
55  char tsdk[20];
56  char hn[20];
57  char msdk[20];
58 } PlatSpec;
59 
60 void appendOSDirSlash(wxString* path);
61 
62 struct OCPN_OSDetail {
63  OCPN_OSDetail(){};
64  ~OCPN_OSDetail(){};
65 
66  std::string osd_name;
67  std::string osd_version;
68  std::vector<std::string> osd_names_like;
69  std::string osd_arch;
70  std::string osd_ID;
71 };
72 
74 public:
75  AbstractPlatform() = default;
76  virtual ~AbstractPlatform() = default;
77 
79  wxString& GetPrivateDataDir();
80 
82  wxString& DefaultPrivateDataDir();
83 
84 
85  wxString* GetPluginDirPtr();
86  wxString* GetSharedDataDirPtr();
87 
89  wxString* GetPrivateDataDirPtr();
90 
92  wxString& GetPluginDir();
93 
94  wxStandardPaths& GetStdPaths();
95 
100  wxString GetWinPluginBaseDir();
101 
102  wxString& GetSharedDataDir();
103  wxString& GetExePath();
104  wxString& GetHomeDir();
105  wxString GetWritableDocumentsDir();
106 
115  wxString GetPluginDataPath();
116 
117  wxString& GetConfigFileName();
118  wxString& GetLogFileName() { return mlog_file; }
119 
120  bool isFlatpacked() { return m_isFlatpacked; }
121 
122  bool isPlatformCapable(int flag);
123  OCPN_OSDetail* GetOSDetail() { return m_osDetail; }
124 
125  void CloseLogFile(void);
126  virtual bool InitializeLogFile(void) = 0;
127  wxString& GetLargeLogMessage(void) { return large_log_message; }
128  FILE* GetLogFilePtr() { return flog; }
129 
130  wxString NormalizePath(const wxString& full_path);
131 
132  virtual wxSize getDisplaySize() { return wxSize(); }
133  virtual double GetDisplaySizeMM() { return 1.0; }
134  virtual double GetDisplayDPmm() { return 1.0; }
135  virtual unsigned int GetSelectRadiusPix();
136  double GetDisplayDIPMult(wxWindow *win);
137 
138  static void ShowBusySpinner();
139  static void HideBusySpinner();
140 
141 protected:
142  bool DetectOSDetail(OCPN_OSDetail* detail);
143 
144  wxString m_default_private_datadir;
145  wxString m_PrivateDataDir;
146  wxString m_PluginsDir;
147  bool m_isFlatpacked;
148  wxString m_homeDir;
149  wxString m_exePath;
150  wxString m_SData_Dir;
151  wxString m_config_file_name;
152  wxString m_pluginDataPath;
153  wxString mlog_file;
154 
155  OCPN_OSDetail* m_osDetail;
156 
157  FILE* flog;
158  wxLog* m_old_logger;
159  wxString large_log_message;
160 
161  std::vector<int> m_displaySizeMMOverride;
162 
163 
164 #ifdef _MSC_VER
165  bool GetWindowsMonitorSize(int *width, int *height);
166 #endif
167  int m_monitorWidth, m_monitorHeight;
168  bool m_bdisableWindowsDisplayEnum;
169  static bool m_isBusy;
170 };
171 
173 public:
174  BasePlatform();
175  ~BasePlatform();
176 
177  bool InitializeLogFile() override;
178 
179  wxSize getDisplaySize() override;
180  double GetDisplaySizeMM() override;
181  double GetDisplayDPmm() override;
182 };
183 
184 #endif // BASEPLATFORM_H
wxString * GetPrivateDataDirPtr()
Legacy compatibility syntactic sugar for GetPrivateDataDir().
wxString & GetPluginDir()
The original in-tree plugin directory, sometimes not user-writable.
wxString GetWinPluginBaseDir()
Base directory for user writable windows plugins, reflects winPluginDir option, defaults to LOCALAPPD...
wxString & DefaultPrivateDataDir()
Return dir path for opencpn.log, etc., does not respect -c option.
wxString GetPluginDataPath()
Return ';'-separated list of base directories for plugin data.
wxString & GetPrivateDataDir()
Return dir path for opencpn.log, etc., respecting -c cli option.