OpenCPN Partial API docs
Loading...
Searching...
No Matches
base_platform.h
Go to the documentation of this file.
1/***************************************************************************
2 * Copyright (C) 2015 by David S. Register *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
16 **************************************************************************/
17
24#ifndef BASEPLATFORM_H
25#define BASEPLATFORM_H
26
27#include <stdio.h>
28#include <vector>
29
30#ifdef _WIN32
31#define NOMINMAX // Required to not interfere with std::max et. al. Sigh.
32#include <winsock2.h>
33#include <windows.h>
34#endif
35
36#include <wx/wxprec.h>
37
38#ifndef WX_PRECOMP
39#include <wx/wx.h>
40#endif // precompiled headers
41
42#include <wx/gdicmn.h>
43#include <wx/log.h>
44#include <wx/stdpaths.h>
45#include <wx/clrpicker.h>
46#include <wx/colourdata.h>
47#include <wx/colordlg.h>
48
49#define PLATFORM_CAP_PLUGINS 1
50#define PLATFORM_CAP_FASTPAN 2
51
52class BasePlatform; // forward
53
56
57typedef struct {
58 char tsdk[20];
59 char hn[20];
60 char msdk[20];
61} PlatSpec;
62
64 OCPN_OSDetail() {};
65 ~OCPN_OSDetail() {};
66
67 std::string osd_name;
68 std::string osd_version;
69 std::vector<std::string> osd_names_like;
70 std::string osd_arch;
71 std::string osd_ID;
72};
73
74void appendOSDirSlash(wxString* path);
75
76namespace platform {
77
82bool GetMemoryStatus(int* mem_total, int* mem_used);
83
84} // namespace platform
86public:
87 AbstractPlatform() = default;
88 virtual ~AbstractPlatform() = default;
89
91 wxString& GetPrivateDataDir();
92
94 wxString& DefaultPrivateDataDir();
95
96 wxString* GetPluginDirPtr();
97 wxString* GetSharedDataDirPtr();
98
100 wxString* GetPrivateDataDirPtr();
101
103 wxString& GetPluginDir();
104
107
108 wxStandardPaths& GetStdPaths();
109
114 wxString GetWinPluginBaseDir();
115
116 wxString& GetSharedDataDir();
117 wxString& GetExePath();
118 wxString& GetHomeDir();
119 wxString GetWritableDocumentsDir();
120
129 wxString GetPluginDataPath();
130
131 wxString& GetConfigFileName();
132 wxString& GetLogFileName() { return mlog_file; }
133
134 bool isFlatpacked() { return m_isFlatpacked; }
135
136 bool isPlatformCapable(int flag);
137 OCPN_OSDetail* GetOSDetail() { return m_osDetail; }
138
139 void CloseLogFile(void);
140 virtual bool InitializeLogFile(void) = 0;
141 wxString& GetLargeLogMessage(void) { return large_log_message; }
142 FILE* GetLogFilePtr() { return flog; }
143
144 wxString NormalizePath(const wxString& full_path);
145
146 virtual wxSize getDisplaySize() { return wxSize(); }
147 virtual double GetDisplaySizeMM() { return 1.0; }
148 virtual double GetDisplayDPmm() { return 1.0; }
149 virtual unsigned int GetSelectRadiusPix();
150
157 double GetDisplayDIPMult(wxWindow* win);
158
163 virtual int GetSvgStdIconSize(const wxWindow* w, bool touch) = 0;
164
165 static void ShowBusySpinner();
166 static void HideBusySpinner();
167
168protected:
169 bool DetectOSDetail(OCPN_OSDetail* detail);
170
171 wxString m_default_private_datadir;
172 wxString m_PrivateDataDir;
173 wxString m_PluginsDir;
174 bool m_isFlatpacked;
175 wxString m_homeDir;
176 wxString m_exePath;
177 wxString m_SData_Dir;
178 wxString m_config_file_name;
179 wxString m_pluginDataPath;
180 wxString mlog_file;
181
182 OCPN_OSDetail* m_osDetail;
183
184 FILE* flog;
185 wxLog* m_old_logger;
186 wxString large_log_message;
187
188 std::vector<int> m_displaySizeMMOverride;
189
190#ifdef _MSC_VER
191 bool GetWindowsMonitorSize(int* width, int* height);
192#endif
193 int m_monitorWidth, m_monitorHeight;
194 bool m_bdisableWindowsDisplayEnum;
195 static bool m_isBusy;
196};
197
199public:
200 BasePlatform();
202
203 bool InitializeLogFile() override;
204
205 wxSize getDisplaySize() override;
206 double GetDisplaySizeMM() override;
207 double GetDisplayDPmm() override;
208 int GetSvgStdIconSize(const wxWindow* w, bool touch) override;
209};
210
211#endif // BASEPLATFORM_H
BasePlatform * g_BasePlatform
points to g_platform, handles brain-dead MS linker.
wxString * GetPrivateDataDirPtr()
Legacy compatibility syntactic sugar for GetPrivateDataDir().
virtual int GetSvgStdIconSize(const wxWindow *w, bool touch)=0
Return icon size roughly corresponding to height of a char in w, tweaked to be "big enough" for touch...
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.
double GetDisplayDIPMult(wxWindow *win)
Get the display scaling factor for DPI-aware rendering.
wxString GetPluginDataPath()
Return ';'-separated list of base directories for plugin data.
wxString & GetPrivateDataDir()
Return dir path for opencpn.log, etc., respecting -c cli option.
wxString GetSupplementalLicenseString()
Android license details, otherwise "".
int GetSvgStdIconSize(const wxWindow *w, bool touch) override
Return icon size roughly corresponding to height of a char in w, tweaked to be "big enough" for touch...