]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/palmos/utils.cpp
Rename wxWebHistoryItem to wxWebViewHistoryItem.
[wxWidgets.git] / src / palmos / utils.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/palmos/utils.cpp
3// Purpose: Various utilities
4// Author: William Osborne - minimal working wxPalmOS port
5// Modified by: Wlodzimierz ABX Skiba - real functionality
6// Created: 10/13/04
7// RCS-ID: $Id$
8// Copyright: (c) William Osborne, Wlodzimierz Skiba
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"
32 #include "wx/timer.h"
33#endif //WX_PRECOMP
34
35#include "wx/apptrait.h"
36#include "wx/dynload.h"
37#include "wx/confbase.h"
38#include "wx/power.h"
39
40#include <PalmTypes.h>
41#include <MemoryMgr.h>
42#include <DLServer.h>
43#include <SoundMgr.h>
44#include <SystemMgr.h> // SysDoze()...
45#include <SysUtils.h>
46
47#ifdef __WXPALMOS6__
48extern void SysReset (void);
49extern UInt32 SysTaskID (void);
50#endif
51
52// ============================================================================
53// implementation
54// ============================================================================
55
56// ----------------------------------------------------------------------------
57// get host name and related
58// ----------------------------------------------------------------------------
59
60// Get hostname only (without domain name)
61bool wxGetHostName(wxChar *buf, int maxSize)
62{
63 return false;
64}
65
66// get full hostname (with domain name if possible)
67bool wxGetFullHostName(wxChar *buf, int maxSize)
68{
69 return false;
70}
71
72// Get user ID e.g. jacs
73bool wxGetUserId(wxChar *buf, int maxSize)
74{
75 return wxGetUserName(buf, maxSize);
76}
77
78// Get user name e.g. Julian Smart
79bool wxGetUserName(wxChar *buf, int maxSize)
80{
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
100 wxStrlcpy(buf, wxSafeConvertMB2WX(id), maxSize);
101
102 // free the buffer
103 MemPtrUnlock(id);
104
105 return true;
106}
107
108const wxChar* wxGetHomeDir(wxString *pstr)
109{
110 if (NULL != pstr) {
111 *pstr = "/palmos";
112 }
113 return wxT("/palmos");
114}
115
116wxString wxGetUserHome(const wxString& WXUNUSED(user))
117{
118 return wxString("/palmos");
119}
120
121bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree)
122{
123 return false;
124}
125
126// ----------------------------------------------------------------------------
127// env vars
128// ----------------------------------------------------------------------------
129
130bool wxGetEnv(const wxString& var, wxString *value)
131{
132 return false;
133}
134
135#if ! WXWIN_COMPATIBILITY_2_8
136bool wxSetEnv(const wxString& var, const wxChar *value)
137{
138 return false;
139}
140#endif // ! WXWIN_COMPATIBILITY_2_8
141
142bool wxUnsetEnv(const wxString& var)
143{
144 return false;
145}
146
147// ----------------------------------------------------------------------------
148// process management
149// ----------------------------------------------------------------------------
150
151int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
152{
153 return 0;
154}
155
156// Execute a program in an Interactive Shell
157bool wxShell(const wxString& command)
158{
159 return false;
160}
161
162// Shutdown or reboot the PC
163bool wxShutdown(wxShutdownFlags wFlags)
164{
165 switch (wFlags) {
166 case wxSHUTDOWN_POWEROFF:
167 // TODO: turn off lamps
168#ifdef __WXPALMOS6__
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 }
183 return false;
184}
185
186// ----------------------------------------------------------------------------
187// power management
188// ----------------------------------------------------------------------------
189
190wxPowerType wxGetPowerType()
191{
192 //SysBatteryKind kind;
193 //POS_SysBatteryInfo (false, NULL, NULL, NULL, NULL, NULL, &kind, NULL);
194 //return wxPOWER_SOCKET;
195 return wxPOWER_BATTERY;
196}
197
198wxBatteryState wxGetBatteryState()
199{
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;
211}
212
213// ----------------------------------------------------------------------------
214// misc
215// ----------------------------------------------------------------------------
216
217// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
218wxMemorySize wxGetFreeMemory()
219{
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
225 for ( uint16_t i = 0; i < POS_MemNumRAMHeaps(); i ++)
226 {
227 status_t err = MemHeapFreeBytes(i, &freeHeap, &freeChunk);
228 if( err != errNone )
229 return -1;
230 freeTotal+=freeHeap;
231 }
232
233 return (wxMemorySize)freeTotal;
234}
235
236unsigned long wxGetProcessId()
237{
238 return SysTaskID ();
239}
240
241// Emit a beeeeeep
242void wxBell()
243{
244 SndPlaySystemSound(sndWarning);
245}
246
247bool wxIsPlatform64Bit()
248{
249 return false;
250}
251
252wxString wxGetOsDescription()
253{
254 wxString strOS = wxT("PalmOS");
255
256 //err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
257 //if (romVersion >= 0x02000000) v20 = true;
258 char *version = SysGetOSVersionString();
259 if(version)
260 {
261 wxString str = wxString::FromAscii(version);
262 MemPtrFree(version);
263 if(!str.empty())
264 {
265 strOS << _(" ") << str;
266 }
267 }
268
269 return strOS;
270}
271
272wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
273{
274 // TODO
275 return wxOS_PALM_OS;
276}
277
278// ----------------------------------------------------------------------------
279// sleep functions
280// ----------------------------------------------------------------------------
281
282void wxMilliSleep(unsigned long milliseconds)
283{
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 }
291}
292
293void wxMicroSleep(unsigned long microseconds)
294{
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 }
302}
303
304void wxSleep(int nSecs)
305{
306 UInt16 ticks_sec;
307 Int32 delay;
308 ticks_sec = SysTicksPerSecond ();
309 delay = nSecs * ticks_sec;
310 if (delay > 0) {
311 SysTaskDelay (delay);
312 }
313}
314
315// ----------------------------------------------------------------------------
316// font encoding <-> Win32 codepage conversion functions
317// ----------------------------------------------------------------------------
318
319extern 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
332extern WXDLLIMPEXP_BASE long wxEncodingToCodepage(wxFontEncoding encoding)
333{
334 return 0;
335}
336
337extern long wxCharsetToCodepage(const wxChar *name)
338{
339 return 0;
340}
341
342#else // !wxUSE_FONTMAP
343
344// this should work if Internet Exploiter is installed
345extern long wxCharsetToCodepage(const wxChar *name)
346{
347 return 0;
348}
349
350#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP