]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/utils.cpp
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
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
35 #include "wx/apptrait.h"
36 #include "wx/dynload.h"
37 #include "wx/confbase.h"
40 #include <PalmTypes.h>
41 #include <MemoryMgr.h>
44 #include <SystemMgr.h> // SysDoze()...
48 extern void SysReset (void);
49 extern UInt32
SysTaskID (void);
52 // ============================================================================
54 // ============================================================================
56 // ----------------------------------------------------------------------------
57 // get host name and related
58 // ----------------------------------------------------------------------------
60 // Get hostname only (without domain name)
61 bool wxGetHostName(wxChar
*buf
, int maxSize
)
66 // get full hostname (with domain name if possible)
67 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
72 // Get user ID e.g. jacs
73 bool wxGetUserId(wxChar
*buf
, int maxSize
)
75 return wxGetUserName(buf
, maxSize
);
78 // Get user name e.g. Julian Smart
79 bool wxGetUserName(wxChar
*buf
, int maxSize
)
84 MemHandle handle
= MemHandleNew(maxSize
-1);
89 char *id
= (char *)MemHandleLock(handle
);
94 if( DlkGetSyncInfo(NULL
, NULL
, NULL
, id
, NULL
, NULL
) != errNone
)
100 wxStrncpy (buf
, wxSafeConvertMB2WX(id
), maxSize
- 1);
108 const wxChar
* wxGetHomeDir(wxString
*pstr
)
113 return wxT("/palmos");
116 wxString
wxGetUserHome(const wxString
& WXUNUSED(user
))
118 return wxString("/palmos");
121 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
130 bool wxGetEnv(const wxString
& var
, wxString
*value
)
135 #if ! WXWIN_COMPATIBILITY_2_8
136 bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
140 #endif // ! WXWIN_COMPATIBILITY_2_8
142 bool wxUnsetEnv(const wxString
& var
)
147 // ----------------------------------------------------------------------------
148 // process management
149 // ----------------------------------------------------------------------------
151 int wxKill(long pid
, wxSignal sig
, wxKillError
*krc
, int flags
)
156 // Execute a program in an Interactive Shell
157 bool wxShell(const wxString
& command
)
162 // Shutdown or reboot the PC
163 bool wxShutdown(wxShutdownFlags wFlags
)
166 case wxSHUTDOWN_POWEROFF
:
167 // TODO: turn off lamps
169 //extern void SysReset (void);
170 //extern UInt32 SysTaskID (void);
172 #define SysTaskID() (0)
175 //SysSleep (false, false);// undocument API
179 case wxSHUTDOWN_REBOOT
:
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
190 wxPowerType
wxGetPowerType()
192 //SysBatteryKind kind;
193 //POS_SysBatteryInfo (false, NULL, NULL, NULL, NULL, NULL, &kind, NULL);
194 //return wxPOWER_SOCKET;
195 return wxPOWER_BATTERY
;
198 wxBatteryState
wxGetBatteryState()
200 //#include "SystemMgr.h"
202 POS_SysBatteryInfo (false, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, &percent
);
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
;
213 // ----------------------------------------------------------------------------
215 // ----------------------------------------------------------------------------
217 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
218 wxMemorySize
wxGetFreeMemory()
220 uint32_t freeTotal
= 0;
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
++)
227 status_t err
= MemHeapFreeBytes(i
, &freeHeap
, &freeChunk
);
233 return (wxMemorySize
)freeTotal
;
236 unsigned long wxGetProcessId()
244 SndPlaySystemSound(sndWarning
);
247 bool wxIsPlatform64Bit()
252 wxString
wxGetOsDescription()
254 wxString strOS
= _T("PalmOS");
256 //err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion);
257 //if (romVersion >= 0x02000000) v20 = true;
258 char *version
= SysGetOSVersionString();
261 wxString str
= wxString::FromAscii(version
);
265 strOS
<< _(" ") << str
;
272 wxOperatingSystemId
wxGetOsVersion(int *verMaj
, int *verMin
)
278 // ----------------------------------------------------------------------------
280 // ----------------------------------------------------------------------------
282 void wxMilliSleep(unsigned long milliseconds
)
286 ticks_sec
= SysTicksPerSecond ();
287 delay
= milliseconds
* ticks_sec
/ 1000;
289 SysTaskDelay (delay
);
293 void wxMicroSleep(unsigned long microseconds
)
297 ticks_sec
= SysTicksPerSecond ();
298 delay
= microseconds
* ticks_sec
/ 1000000;
300 SysTaskDelay (delay
);
304 void wxSleep(int nSecs
)
308 ticks_sec
= SysTicksPerSecond ();
309 delay
= nSecs
* ticks_sec
;
311 SysTaskDelay (delay
);
315 // ----------------------------------------------------------------------------
316 // font encoding <-> Win32 codepage conversion functions
317 // ----------------------------------------------------------------------------
319 extern WXDLLIMPEXP_BASE
long wxEncodingToCharset(wxFontEncoding encoding
)
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
330 #include "wx/fontmap.h"
332 extern WXDLLIMPEXP_BASE
long wxEncodingToCodepage(wxFontEncoding encoding
)
337 extern long wxCharsetToCodepage(const wxChar
*name
)
342 #else // !wxUSE_FONTMAP
344 // this should work if Internet Exploiter is installed
345 extern long wxCharsetToCodepage(const wxChar
*name
)
350 #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP