]>
Commit | Line | Data |
---|---|---|
ffecfa5a | 1 | ///////////////////////////////////////////////////////////////////////////// |
6929fe3a | 2 | // Name: src/palmos/utils.cpp |
ffecfa5a | 3 | // Purpose: Various utilities |
6929fe3a WS |
4 | // Author: William Osborne - minimal working wxPalmOS port |
5 | // Modified by: Wlodzimierz ABX Skiba - real functionality | |
ffecfa5a | 6 | // Created: 10/13/04 |
6929fe3a WS |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) William Osborne, Wlodzimierz Skiba | |
ffecfa5a JS |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // For compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/utils.h" | |
29 | #include "wx/app.h" | |
30 | #include "wx/intl.h" | |
31 | #include "wx/log.h" | |
c0badb70 | 32 | #include "wx/timer.h" |
ffecfa5a JS |
33 | #endif //WX_PRECOMP |
34 | ||
35 | #include "wx/apptrait.h" | |
36 | #include "wx/dynload.h" | |
d1df2399 | 37 | #include "wx/confbase.h" |
355debca | 38 | #include "wx/power.h" |
ffecfa5a | 39 | |
6afc1b46 | 40 | #include <PalmTypes.h> |
d1df2399 WS |
41 | #include <MemoryMgr.h> |
42 | #include <DLServer.h> | |
43 | #include <SoundMgr.h> | |
6afc1b46 | 44 | #include <SystemMgr.h> // SysDoze()... |
20bc5ad8 | 45 | #include <SysUtils.h> |
ffecfa5a | 46 | |
ae167594 | 47 | #ifdef __WXPALMOS6__ |
6afc1b46 VZ |
48 | extern void SysReset (void); |
49 | extern UInt32 SysTaskID (void); | |
50 | #endif | |
51 | ||
ffecfa5a JS |
52 | // ============================================================================ |
53 | // implementation | |
54 | // ============================================================================ | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // get host name and related | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | // Get hostname only (without domain name) | |
61 | bool wxGetHostName(wxChar *buf, int maxSize) | |
62 | { | |
63 | return false; | |
64 | } | |
65 | ||
66 | // get full hostname (with domain name if possible) | |
67 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
68 | { | |
69 | return false; | |
70 | } | |
71 | ||
72 | // Get user ID e.g. jacs | |
73 | bool wxGetUserId(wxChar *buf, int maxSize) | |
74 | { | |
d1df2399 | 75 | return wxGetUserName(buf, maxSize); |
ffecfa5a JS |
76 | } |
77 | ||
78 | // Get user name e.g. Julian Smart | |
79 | bool wxGetUserName(wxChar *buf, int maxSize) | |
80 | { | |
d1df2399 WS |
81 | *buf = wxT('\0'); |
82 | ||
83 | // buffer allocation | |
84 | MemHandle handle = MemHandleNew(maxSize-1); | |
85 | if( handle == NULL ) | |
86 | return false; | |
87 | ||
88 | // lock the buffer | |
89 | char *id = (char *)MemHandleLock(handle); | |
90 | if( id == NULL ) | |
91 | return false; | |
92 | ||
93 | // get user's name | |
94 | if( DlkGetSyncInfo(NULL, NULL, NULL, id, NULL, NULL) != errNone ) | |
95 | { | |
96 | MemPtrUnlock(id); | |
97 | return false; | |
98 | } | |
99 | ||
e408bf52 | 100 | wxStrlcpy(buf, wxSafeConvertMB2WX(id), maxSize); |
d1df2399 | 101 | |
9d8aca48 | 102 | // free the buffer |
d1df2399 WS |
103 | MemPtrUnlock(id); |
104 | ||
105 | return true; | |
ffecfa5a JS |
106 | } |
107 | ||
108 | const wxChar* wxGetHomeDir(wxString *pstr) | |
109 | { | |
6afc1b46 VZ |
110 | if (NULL != pstr) { |
111 | *pstr = "/palmos"; | |
112 | } | |
113 | return wxT("/palmos"); | |
ffecfa5a JS |
114 | } |
115 | ||
14d63513 | 116 | wxString wxGetUserHome(const wxString& WXUNUSED(user)) |
ffecfa5a | 117 | { |
6afc1b46 | 118 | return wxString("/palmos"); |
ffecfa5a JS |
119 | } |
120 | ||
7ba7c4e6 | 121 | bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) |
ffecfa5a JS |
122 | { |
123 | return false; | |
124 | } | |
125 | ||
126 | // ---------------------------------------------------------------------------- | |
127 | // env vars | |
128 | // ---------------------------------------------------------------------------- | |
129 | ||
130 | bool wxGetEnv(const wxString& var, wxString *value) | |
131 | { | |
132 | return false; | |
133 | } | |
134 | ||
e2fc40b4 | 135 | #if ! WXWIN_COMPATIBILITY_2_8 |
ffecfa5a JS |
136 | bool wxSetEnv(const wxString& var, const wxChar *value) |
137 | { | |
138 | return false; | |
139 | } | |
e2fc40b4 | 140 | #endif // ! WXWIN_COMPATIBILITY_2_8 |
ffecfa5a | 141 | |
90a77e64 VS |
142 | bool wxUnsetEnv(const wxString& var) |
143 | { | |
144 | return false; | |
145 | } | |
146 | ||
ffecfa5a JS |
147 | // ---------------------------------------------------------------------------- |
148 | // process management | |
149 | // ---------------------------------------------------------------------------- | |
150 | ||
e0f6b731 | 151 | int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags) |
ffecfa5a JS |
152 | { |
153 | return 0; | |
154 | } | |
155 | ||
156 | // Execute a program in an Interactive Shell | |
157 | bool wxShell(const wxString& command) | |
158 | { | |
159 | return false; | |
160 | } | |
161 | ||
162 | // Shutdown or reboot the PC | |
163 | bool wxShutdown(wxShutdownFlags wFlags) | |
164 | { | |
6afc1b46 VZ |
165 | switch (wFlags) { |
166 | case wxSHUTDOWN_POWEROFF: | |
167 | // TODO: turn off lamps | |
ae167594 | 168 | #ifdef __WXPALMOS6__ |
6afc1b46 VZ |
169 | //extern void SysReset (void); |
170 | //extern UInt32 SysTaskID (void); | |
171 | #define SysReset() | |
172 | #define SysTaskID() (0) | |
173 | SysSleep (); | |
174 | #else | |
175 | //SysSleep (false, false);// undocument API | |
176 | SysDoze (true); | |
177 | #endif | |
178 | break; | |
179 | case wxSHUTDOWN_REBOOT: | |
180 | SysReset (); | |
181 | break; | |
182 | } | |
ffecfa5a JS |
183 | return false; |
184 | } | |
185 | ||
355debca VZ |
186 | // ---------------------------------------------------------------------------- |
187 | // power management | |
188 | // ---------------------------------------------------------------------------- | |
189 | ||
8ea92b4d WS |
190 | wxPowerType wxGetPowerType() |
191 | { | |
6afc1b46 VZ |
192 | //SysBatteryKind kind; |
193 | //POS_SysBatteryInfo (false, NULL, NULL, NULL, NULL, NULL, &kind, NULL); | |
194 | //return wxPOWER_SOCKET; | |
8ea92b4d WS |
195 | return wxPOWER_BATTERY; |
196 | } | |
197 | ||
198 | wxBatteryState wxGetBatteryState() | |
199 | { | |
6afc1b46 VZ |
200 | //#include "SystemMgr.h" |
201 | UInt8 percent; | |
202 | POS_SysBatteryInfo (false, NULL, NULL, NULL, NULL, NULL, NULL, &percent); | |
203 | if (percent < 3) | |
204 | return wxBATTERY_SHUTDOWN_STATE; | |
205 | else if (percent < 5) | |
206 | return wxBATTERY_CRITICAL_STATE; | |
207 | else if (percent < 15) | |
208 | return wxBATTERY_LOW_STATE; | |
209 | //return wxBATTERY_UNKNOWN_STATE; | |
210 | return wxBATTERY_NORMAL_STATE; | |
8ea92b4d WS |
211 | } |
212 | ||
ffecfa5a JS |
213 | // ---------------------------------------------------------------------------- |
214 | // misc | |
215 | // ---------------------------------------------------------------------------- | |
216 | ||
217 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
9d8aca48 | 218 | wxMemorySize wxGetFreeMemory() |
ffecfa5a | 219 | { |
d1df2399 WS |
220 | uint32_t freeTotal = 0; |
221 | uint32_t freeHeap; | |
222 | uint32_t freeChunk; | |
223 | ||
224 | // executed twice: for the dynamic heap, and for the non-secure RAM storage heap | |
6afc1b46 | 225 | for ( uint16_t i = 0; i < POS_MemNumRAMHeaps(); i ++) |
d1df2399 WS |
226 | { |
227 | status_t err = MemHeapFreeBytes(i, &freeHeap, &freeChunk); | |
228 | if( err != errNone ) | |
229 | return -1; | |
230 | freeTotal+=freeHeap; | |
231 | } | |
232 | ||
9d8aca48 | 233 | return (wxMemorySize)freeTotal; |
ffecfa5a JS |
234 | } |
235 | ||
236 | unsigned long wxGetProcessId() | |
237 | { | |
6afc1b46 | 238 | return SysTaskID (); |
ffecfa5a JS |
239 | } |
240 | ||
241 | // Emit a beeeeeep | |
242 | void wxBell() | |
243 | { | |
d1df2399 | 244 | SndPlaySystemSound(sndWarning); |
ffecfa5a JS |
245 | } |
246 | ||
cdbce971 WS |
247 | bool wxIsPlatform64Bit() |
248 | { | |
249 | return false; | |
250 | } | |
251 | ||
ffecfa5a JS |
252 | wxString wxGetOsDescription() |
253 | { | |
9a83f860 | 254 | wxString strOS = wxT("PalmOS"); |
ffecfa5a | 255 | |
6afc1b46 VZ |
256 | //err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); |
257 | //if (romVersion >= 0x02000000) v20 = true; | |
cc2c11e2 WS |
258 | char *version = SysGetOSVersionString(); |
259 | if(version) | |
260 | { | |
261 | wxString str = wxString::FromAscii(version); | |
6929fe3a | 262 | MemPtrFree(version); |
cc2c11e2 WS |
263 | if(!str.empty()) |
264 | { | |
265 | strOS << _(" ") << str; | |
266 | } | |
267 | } | |
268 | ||
269 | return strOS; | |
ffecfa5a JS |
270 | } |
271 | ||
8bb6b2c0 | 272 | wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) |
ffecfa5a | 273 | { |
8bb6b2c0 | 274 | // TODO |
6afc1b46 | 275 | return wxOS_PALM_OS; |
ffecfa5a JS |
276 | } |
277 | ||
278 | // ---------------------------------------------------------------------------- | |
279 | // sleep functions | |
280 | // ---------------------------------------------------------------------------- | |
281 | ||
282 | void wxMilliSleep(unsigned long milliseconds) | |
283 | { | |
6afc1b46 VZ |
284 | UInt16 ticks_sec; |
285 | Int32 delay; | |
286 | ticks_sec = SysTicksPerSecond (); | |
287 | delay = milliseconds * ticks_sec / 1000; | |
288 | if (delay > 0) { | |
289 | SysTaskDelay (delay); | |
290 | } | |
ffecfa5a JS |
291 | } |
292 | ||
293 | void wxMicroSleep(unsigned long microseconds) | |
294 | { | |
6afc1b46 VZ |
295 | UInt16 ticks_sec; |
296 | Int32 delay; | |
297 | ticks_sec = SysTicksPerSecond (); | |
298 | delay = microseconds * ticks_sec / 1000000; | |
299 | if (delay > 0) { | |
300 | SysTaskDelay (delay); | |
301 | } | |
ffecfa5a JS |
302 | } |
303 | ||
304 | void wxSleep(int nSecs) | |
305 | { | |
6afc1b46 VZ |
306 | UInt16 ticks_sec; |
307 | Int32 delay; | |
308 | ticks_sec = SysTicksPerSecond (); | |
309 | delay = nSecs * ticks_sec; | |
310 | if (delay > 0) { | |
311 | SysTaskDelay (delay); | |
312 | } | |
ffecfa5a JS |
313 | } |
314 | ||
315 | // ---------------------------------------------------------------------------- | |
316 | // font encoding <-> Win32 codepage conversion functions | |
317 | // ---------------------------------------------------------------------------- | |
318 | ||
319 | extern WXDLLIMPEXP_BASE long wxEncodingToCharset(wxFontEncoding encoding) | |
320 | { | |
321 | return 0; | |
322 | } | |
323 | ||
324 | // we have 2 versions of wxCharsetToCodepage(): the old one which directly | |
325 | // looks up the vlaues in the registry and the new one which is more | |
326 | // politically correct and has more chances to work on other Windows versions | |
327 | // as well but the old version is still needed for !wxUSE_FONTMAP case | |
328 | #if wxUSE_FONTMAP | |
329 | ||
330 | #include "wx/fontmap.h" | |
331 | ||
332 | extern WXDLLIMPEXP_BASE long wxEncodingToCodepage(wxFontEncoding encoding) | |
333 | { | |
334 | return 0; | |
335 | } | |
336 | ||
337 | extern long wxCharsetToCodepage(const wxChar *name) | |
338 | { | |
339 | return 0; | |
340 | } | |
341 | ||
342 | #else // !wxUSE_FONTMAP | |
343 | ||
ffecfa5a JS |
344 | // this should work if Internet Exploiter is installed |
345 | extern long wxCharsetToCodepage(const wxChar *name) | |
346 | { | |
347 | return 0; | |
348 | } | |
349 | ||
350 | #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP |