X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e0f6b731a80035dab1c2d1224f8a2dea0c9de947..dc8c61bef78e406080de2be91bc6e8d746edb647:/src/palmos/utils.cpp diff --git a/src/palmos/utils.cpp b/src/palmos/utils.cpp index 934ab62e50..d52e90fb35 100644 --- a/src/palmos/utils.cpp +++ b/src/palmos/utils.cpp @@ -1,11 +1,11 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: palmos/utils.cpp +// Name: src/palmos/utils.cpp // Purpose: Various utilities -// Author: William Osborne -// Modified by: +// Author: William Osborne - minimal working wxPalmOS port +// Modified by: Wlodzimierz ABX Skiba - real functionality // Created: 10/13/04 -// RCS-ID: $Id: -// Copyright: (c) William Osborne +// RCS-ID: $Id$ +// Copyright: (c) William Osborne, Wlodzimierz Skiba // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -29,32 +29,25 @@ #include "wx/app.h" #include "wx/intl.h" #include "wx/log.h" + #include "wx/timer.h" #endif //WX_PRECOMP #include "wx/apptrait.h" #include "wx/dynload.h" - -#include "wx/confbase.h" // for wxExpandEnvVars() - -#include "wx/timer.h" - -// VZ: there is some code using NetXXX() functions to get the full user name: -// I don't think it's a good idea because they don't work under Win95 and -// seem to return the same as wxGetUserId() under NT. If you really want -// to use them, just #define USE_NET_API -#undef USE_NET_API - -#ifdef USE_NET_API - #include -#endif // USE_NET_API - -// ---------------------------------------------------------------------------- -// constants -// ---------------------------------------------------------------------------- - -// In the WIN.INI file -static const wxChar WX_SECTION[] = wxT("wxWindows"); -static const wxChar eUSERNAME[] = wxT("UserName"); +#include "wx/confbase.h" +#include "wx/power.h" + +#include +#include +#include +#include +#include // SysDoze()... +#include + +#ifdef __WXPALMOS6__ +extern void SysReset (void); +extern UInt32 SysTaskID (void); +#endif // ============================================================================ // implementation @@ -79,31 +72,53 @@ bool wxGetFullHostName(wxChar *buf, int maxSize) // Get user ID e.g. jacs bool wxGetUserId(wxChar *buf, int maxSize) { - return false; + return wxGetUserName(buf, maxSize); } // Get user name e.g. Julian Smart bool wxGetUserName(wxChar *buf, int maxSize) { - return false; -} + *buf = wxT('\0'); -const wxChar* wxGetHomeDir(wxString *pstr) -{ - return NULL; + // buffer allocation + MemHandle handle = MemHandleNew(maxSize-1); + if( handle == NULL ) + return false; + + // lock the buffer + char *id = (char *)MemHandleLock(handle); + if( id == NULL ) + return false; + + // get user's name + if( DlkGetSyncInfo(NULL, NULL, NULL, id, NULL, NULL) != errNone ) + { + MemPtrUnlock(id); + return false; + } + + wxStrlcpy(buf, wxSafeConvertMB2WX(id), maxSize); + + // free the buffer + MemPtrUnlock(id); + + return true; } -wxChar *wxGetUserHome(const wxString& WXUNUSED(user)) +const wxChar* wxGetHomeDir(wxString *pstr) { - return NULL; + if (NULL != pstr) { + *pstr = "/palmos"; + } + return wxT("/palmos"); } -bool wxDirExists(const wxString& dir) +wxString wxGetUserHome(const wxString& WXUNUSED(user)) { - return false; + return wxString("/palmos"); } -bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) +bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) { return false; } @@ -117,10 +132,17 @@ bool wxGetEnv(const wxString& var, wxString *value) return false; } +#if ! WXWIN_COMPATIBILITY_2_8 bool wxSetEnv(const wxString& var, const wxChar *value) { return false; } +#endif // ! WXWIN_COMPATIBILITY_2_8 + +bool wxUnsetEnv(const wxString& var) +{ + return false; +} // ---------------------------------------------------------------------------- // process management @@ -140,41 +162,117 @@ bool wxShell(const wxString& command) // Shutdown or reboot the PC bool wxShutdown(wxShutdownFlags wFlags) { + switch (wFlags) { + case wxSHUTDOWN_POWEROFF: + // TODO: turn off lamps +#ifdef __WXPALMOS6__ + //extern void SysReset (void); + //extern UInt32 SysTaskID (void); + #define SysReset() + #define SysTaskID() (0) + SysSleep (); +#else + //SysSleep (false, false);// undocument API + SysDoze (true); +#endif + break; + case wxSHUTDOWN_REBOOT: + SysReset (); + break; + } return false; } +// ---------------------------------------------------------------------------- +// power management +// ---------------------------------------------------------------------------- + +wxPowerType wxGetPowerType() +{ + //SysBatteryKind kind; + //POS_SysBatteryInfo (false, NULL, NULL, NULL, NULL, NULL, &kind, NULL); + //return wxPOWER_SOCKET; + return wxPOWER_BATTERY; +} + +wxBatteryState wxGetBatteryState() +{ + //#include "SystemMgr.h" + UInt8 percent; + POS_SysBatteryInfo (false, NULL, NULL, NULL, NULL, NULL, NULL, &percent); + if (percent < 3) + return wxBATTERY_SHUTDOWN_STATE; + else if (percent < 5) + return wxBATTERY_CRITICAL_STATE; + else if (percent < 15) + return wxBATTERY_LOW_STATE; + //return wxBATTERY_UNKNOWN_STATE; + return wxBATTERY_NORMAL_STATE; +} + // ---------------------------------------------------------------------------- // misc // ---------------------------------------------------------------------------- // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) -long wxGetFreeMemory() +wxMemorySize wxGetFreeMemory() { - return 0; + uint32_t freeTotal = 0; + uint32_t freeHeap; + uint32_t freeChunk; + + // executed twice: for the dynamic heap, and for the non-secure RAM storage heap + for ( uint16_t i = 0; i < POS_MemNumRAMHeaps(); i ++) + { + status_t err = MemHeapFreeBytes(i, &freeHeap, &freeChunk); + if( err != errNone ) + return -1; + freeTotal+=freeHeap; + } + + return (wxMemorySize)freeTotal; } unsigned long wxGetProcessId() { - return 0; + return SysTaskID (); } // Emit a beeeeeep void wxBell() { + SndPlaySystemSound(sndWarning); } -wxString wxGetOsDescription() +bool wxIsPlatform64Bit() { - wxString str; + return false; +} - return str; +wxString wxGetOsDescription() +{ + wxString strOS = wxT("PalmOS"); + + //err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); + //if (romVersion >= 0x02000000) v20 = true; + char *version = SysGetOSVersionString(); + if(version) + { + wxString str = wxString::FromAscii(version); + MemPtrFree(version); + if(!str.empty()) + { + strOS << _(" ") << str; + } + } + + return strOS; } -wxToolkitInfo& wxAppTraits::GetToolkitInfo() +wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin) { - static wxToolkitInfo info; - info.name = _T("wxBase"); - return info; + // TODO + return wxOS_PALM_OS; } // ---------------------------------------------------------------------------- @@ -183,14 +281,35 @@ wxToolkitInfo& wxAppTraits::GetToolkitInfo() void wxMilliSleep(unsigned long milliseconds) { + UInt16 ticks_sec; + Int32 delay; + ticks_sec = SysTicksPerSecond (); + delay = milliseconds * ticks_sec / 1000; + if (delay > 0) { + SysTaskDelay (delay); + } } void wxMicroSleep(unsigned long microseconds) { + UInt16 ticks_sec; + Int32 delay; + ticks_sec = SysTicksPerSecond (); + delay = microseconds * ticks_sec / 1000000; + if (delay > 0) { + SysTaskDelay (delay); + } } void wxSleep(int nSecs) { + UInt16 ticks_sec; + Int32 delay; + ticks_sec = SysTicksPerSecond (); + delay = nSecs * ticks_sec; + if (delay > 0) { + SysTaskDelay (delay); + } } // ---------------------------------------------------------------------------- @@ -222,8 +341,6 @@ extern long wxCharsetToCodepage(const wxChar *name) #else // !wxUSE_FONTMAP -#include "wx/palmos/registry.h" - // this should work if Internet Exploiter is installed extern long wxCharsetToCodepage(const wxChar *name) { @@ -231,4 +348,3 @@ extern long wxCharsetToCodepage(const wxChar *name) } #endif // wxUSE_FONTMAP/!wxUSE_FONTMAP -