From 8ea92b4d7792987769774ac381685dae15c70454 Mon Sep 17 00:00:00 2001
From: =?utf8?q?W=C5=82odzimierz=20Skiba?= <abx@abx.art.pl>
Date: Thu, 20 Jan 2005 16:09:23 +0000
Subject: [PATCH] Simple wxBatteryPower API for the support in wxWinCE,
 wxPalmOS and any other mobile device with wxWidgets. Minor source cleaning.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31515 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/changes.txt           |  1 +
 docs/latex/wx/function.tex | 63 ++++++++++++++++++++++++++++----------
 include/wx/utils.h         | 20 ++++++++++++
 src/mac/carbon/utils.cpp   | 12 ++++++++
 src/mac/classic/utils.cpp  | 12 ++++++++
 src/msw/utils.cpp          | 12 ++++++++
 src/os2/utils.cpp          | 12 ++++++++
 src/palmos/utils.cpp       | 11 +++++++
 src/unix/utilsunx.cpp      | 17 ++++++++--
 9 files changed, 141 insertions(+), 19 deletions(-)

diff --git a/docs/changes.txt b/docs/changes.txt
index bb072e0318..962d473713 100644
--- a/docs/changes.txt
+++ b/docs/changes.txt
@@ -36,6 +36,7 @@ All:
 - The samples\db sample program now includes an optional example of using a BLOB
   datatype (if BLOB support is enabled and supported by the database)
 - added wxDynamicLibrary::ListLoaded()
+- wxGetPowerType() and wxGetBatteryState() addition
 
 All (GUI):
 
diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 852ce33397..4d40bb80ab 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -96,6 +96,7 @@ the corresponding topic.
 \helpref{wxFinite}{wxfinite}\\
 \helpref{wxGetActiveWindow}{wxgetactivewindow}\\
 \helpref{wxGetApp}{wxgetapp}\\
+\helpref{wxGetBatteryState}{wxgetbatterystate}\\
 \helpref{wxGetClipboardData}{wxgetclipboarddata}\\
 \helpref{wxGetClipboardFormatName}{wxgetclipboardformatname}\\
 \helpref{wxGetColourFromUser}{wxgetcolourfromuser}\\
@@ -123,6 +124,7 @@ the corresponding topic.
 \helpref{wxGetOsDescription}{wxgetosdescription}\\
 \helpref{wxGetOsVersion}{wxgetosversion}\\
 \helpref{wxGetPasswordFromUser}{wxgetpasswordfromuser}\\
+\helpref{wxGetPowerType}{wxgetpowertype}\\
 \helpref{wxGetPrinterCommand}{wxgetprintercommand}\\
 \helpref{wxGetPrinterFile}{wxgetprinterfile}\\
 \helpref{wxGetPrinterMode}{wxgetprintermode}\\
@@ -974,7 +976,7 @@ For example:
 
 \begin{verbatim}
   wxString f = wxFindFirstFile("/home/project/*.*");
-  while ( !f.IsEmpty() )
+  while ( !f.empty() )
   {
     ...
     f = wxFindNextFile();
@@ -1606,7 +1608,7 @@ initialization.
 
 Here is an example which should make it more clear: suppose that you have a
 static array of strings containing the weekday names and which have to be
-translated (note that it is a bad example, really, as 
+translated (note that it is a bad example, really, as
 \helpref{wxDateTime}{wxdatetime} already can be used to get the localized week
 day names already). If you write
 
@@ -1649,7 +1651,7 @@ argument instead of arbitrary number of parameters.
 
 \func{const wxChar *}{\_}{\param{const char *}{s}}
 
-This macro expands into a call to \helpref{wxGetTranslation}{wxgettranslation} 
+This macro expands into a call to \helpref{wxGetTranslation}{wxgettranslation}
 function, so it marks the message for the extraction by {\tt xgettext} just as
 \helpref{wxTRANSLATE}{wxtranslate} does, but also returns the translation of
 the string for the current locale during execution.
@@ -2179,7 +2181,7 @@ checkbox which is shown in the tips dialog.}
 
 \func{int}{wxFinite}{\param{double }{x}}
 
-Returns a non-zero value if {\it x} is neither infinite or NaN (not a number), 
+Returns a non-zero value if {\it x} is neither infinite or NaN (not a number),
 returns 0 otherwise.
 
 
@@ -2596,7 +2598,7 @@ This macro returns the concatenation of two tokens \arg{x} and \arg{y}.
 
 \func{}{wxDYNLIB\_FUNCTION}{\param{}{type}, \param{}{name}, \param{}{dynlib}}
 
-When loading a function from a DLL you always have to cast the returned 
+When loading a function from a DLL you always have to cast the returned
 {\tt void *} pointer to the correct type and, even more annoyingly, you have to
 repeat this type twice if you want to declare and define a function pointer all
 in one line
@@ -2604,7 +2606,7 @@ in one line
 This macro makes this slightly less painful by allowing you to specify the
 type only once, as the first parameter, and creating a variable of this type
 named after the function but with {\tt pfn} prefix and initialized with the
-function \arg{name} from the \helpref{wxDynamicLibrary}{wxdynamiclibrary} 
+function \arg{name} from the \helpref{wxDynamicLibrary}{wxdynamiclibrary}
 \arg{dynlib}.
 
 \wxheading{Parameters}
@@ -2823,6 +2825,21 @@ Gets the currently active window (Windows only).
 <wx/windows.h>
 
 
+\membersection{::wxGetBatteryState}\label{wxgetbatterystate}
+
+\func{wxBatteryState}{wxGetBatteryState}{\void}
+
+Returns battery state as one of \texttt{wxBATTERY_NORMAL_STATE},
+\texttt{wxBATTERY_LOW_STATE}, \texttt{wxBATTERY_CRITICAL_STATE},
+\texttt{wxBATTERY_SHUTDOWN_STATE} or \texttt{wxBATTERY_UNKNOWN_STATE}.
+\texttt{wxBATTERY_UNKNOWN_STATE} is also the default on platforms where
+this feature is not implemented.
+
+\wxheading{Include files}
+
+<wx/utils.h>
+
+
 \membersection{::wxGetDisplayName}\label{wxgetdisplayname}
 
 \func{wxString}{wxGetDisplayName}{\void}
@@ -2834,6 +2851,20 @@ Under X only, returns the current display name. See also \helpref{wxSetDisplayNa
 <wx/utils.h>
 
 
+\membersection{::wxGetPowerType}\label{wxgetpowertype}
+
+\func{wxPowerType}{wxGetPowerType}{\void}
+
+Returns the type of power source as one of \texttt{wxPOWER_SOCKET},
+\texttt{wxPOWER_BATTERY} or \texttt{wxPOWER_UNKNOWN}.
+\texttt{wxPOWER_UNKNOWN} is also the default on platforms where this
+feature is not implemented.
+
+\wxheading{Include files}
+
+<wx/utils.h>
+
+
 \membersection{::wxGetMousePosition}\label{wxgetmouseposition}
 
 \func{wxPoint}{wxGetMousePosition}{\void}
@@ -3012,7 +3043,7 @@ which support it or its replacement for those that don't. It must be used to
 preserve the value of a \texttt{va\_list} object if you need to use it after
 passing it to another function because it can be modified by the latter.
 
-As with \texttt{va\_start}, each call to \texttt{wxVaCopy} must have a matching 
+As with \texttt{va\_start}, each call to \texttt{wxVaCopy} must have a matching
 \texttt{va\_end}.
 
 
@@ -3171,9 +3202,9 @@ class wxCommand: public wxObject
 
 \func{}{DECLARE\_APP}{className}
 
-This is used in headers to create a forward declaration of the 
-\helpref{wxGetApp}{wxgetapp} function implemented by 
-\helpref{IMPLEMENT\_APP}{implementapp}. It creates the declaration 
+This is used in headers to create a forward declaration of the
+\helpref{wxGetApp}{wxgetapp} function implemented by
+\helpref{IMPLEMENT\_APP}{implementapp}. It creates the declaration
 {\tt className\& wxGetApp(void)}.
 
 Example:
@@ -3458,7 +3489,7 @@ result of executing an equivalent of {\tt static\_cast<classname *>(ptr)}.
 
 \func{T}{wx\_const\_cast}{T, x}
 
-Same as \texttt{const\_cast<T>(x)} if the compiler supports const cast or 
+Same as \texttt{const\_cast<T>(x)} if the compiler supports const cast or
 \texttt{(T)x} for old compilers. Unlike \helpref{wxConstCast}{wxconstcast},
 the cast it to the type \arg{T} and not to \texttt{T *} and also the order of
 arguments is the same as for the standard cast.
@@ -3473,7 +3504,7 @@ arguments is the same as for the standard cast.
 
 \func{T}{wx\_reinterpret\_cast}{T, x}
 
-Same as \texttt{reinterpret\_cast<T>(x)} if the compiler supports reinterpret cast or 
+Same as \texttt{reinterpret\_cast<T>(x)} if the compiler supports reinterpret cast or
 \texttt{(T)x} for old compilers.
 
 \wxheading{See also}
@@ -3486,7 +3517,7 @@ Same as \texttt{reinterpret\_cast<T>(x)} if the compiler supports reinterpret ca
 
 \func{T}{wx\_static\_cast}{T, x}
 
-Same as \texttt{static\_cast<T>(x)} if the compiler supports static cast or 
+Same as \texttt{static\_cast<T>(x)} if the compiler supports static cast or
 \texttt{(T)x} for old compilers. Unlike \helpref{wxStaticCast}{wxstaticcast},
 there are no checks being done and the meaning of the macro arguments is exactly
 the same as for the standard static cast, i.e. \arg{T} is the full type name and
@@ -3933,7 +3964,7 @@ Returns the number of seconds since GMT 00:00:00 Jan 1st 1970.
 
 Sleeps for the specified number of microseconds. The microsecond resolution may
 not, in fact, be available on all platforms (currently only Unix platforms with
-nanosleep(2) may provide it) in which case this is the same as 
+nanosleep(2) may provide it) in which case this is the same as
 \helpref{wxMilliSleep}{wxmillisleep}(\arg{microseconds}$/1000$).
 
 \wxheading{Include files}
@@ -3994,8 +4025,8 @@ See also \helpref{wxTimer}{wxtimer}.
 \func{void}{wxUsleep}{\param{unsigned long}{ milliseconds}}
 
 This function is deprecated because its name is misleading: notice that the
-argument is in milliseconds, not microseconds. Please use either 
-\helpref{wxMilliSleep}{wxmillisleep} or \helpref{wxMicroSleep}{wxmicrosleep} 
+argument is in milliseconds, not microseconds. Please use either
+\helpref{wxMilliSleep}{wxmillisleep} or \helpref{wxMicroSleep}{wxmicrosleep}
 depending on the resolution you need.
 
 
diff --git a/include/wx/utils.h b/include/wx/utils.h
index 27b8400554..38bade0974 100644
--- a/include/wx/utils.h
+++ b/include/wx/utils.h
@@ -262,6 +262,26 @@ enum wxShutdownFlags
 // Shutdown or reboot the PC
 WXDLLIMPEXP_BASE bool wxShutdown(wxShutdownFlags wFlags);
 
+enum wxPowerType
+{
+    wxPOWER_SOCKET,
+    wxPOWER_BATTERY,
+    wxPOWER_UNKNOWN
+};
+
+WXDLLIMPEXP_BASE wxPowerType wxGetPowerType();
+
+enum wxBatteryState
+{
+    wxBATTERY_NORMAL_STATE,    // system is fully usable
+    wxBATTERY_LOW_STATE,       // start to worry
+    wxBATTERY_CRITICAL_STATE,  // save quickly
+    wxBATTERY_SHUTDOWN_STATE,  // too late
+    wxBATTERY_UNKNOWN_STATE
+};
+
+WXDLLIMPEXP_BASE wxBatteryState wxGetBatteryState();
+
 // send the given signal to the process (only NONE and KILL are supported under
 // Windows, all others mean TERM), return 0 if ok and -1 on error
 //
diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp
index 44e917e2a7..26b435433b 100644
--- a/src/mac/carbon/utils.cpp
+++ b/src/mac/carbon/utils.cpp
@@ -336,6 +336,18 @@ bool wxShutdown(wxShutdownFlags wFlags)
     return false;
 }
 
+wxPowerType wxGetPowerType()
+{
+    // TODO
+    return wxPOWER_UNKNOWN;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
+}
+
 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
 wxMemorySize wxGetFreeMemory()
 {
diff --git a/src/mac/classic/utils.cpp b/src/mac/classic/utils.cpp
index e290dc06e5..979ac71cb0 100644
--- a/src/mac/classic/utils.cpp
+++ b/src/mac/classic/utils.cpp
@@ -190,6 +190,18 @@ bool wxShutdown(wxShutdownFlags wFlags)
     return false;
 }
 
+wxPowerType wxGetPowerType()
+{
+    // TODO
+    return wxPOWER_UNKNOWN;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
+}
+
 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
 wxMemorySize wxGetFreeMemory()
 {
diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp
index 22c24572dc..d2238eaddb 100644
--- a/src/msw/utils.cpp
+++ b/src/msw/utils.cpp
@@ -1007,6 +1007,18 @@ bool wxShutdown(wxShutdownFlags wFlags)
 #endif // Win32/16
 }
 
+wxPowerType wxGetPowerType()
+{
+    // TODO
+    return wxPOWER_UNKNOWN;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
+}
+
 // ----------------------------------------------------------------------------
 // misc
 // ----------------------------------------------------------------------------
diff --git a/src/os2/utils.cpp b/src/os2/utils.cpp
index 678f7c0edc..f779879590 100644
--- a/src/os2/utils.cpp
+++ b/src/os2/utils.cpp
@@ -204,6 +204,18 @@ bool wxShutdown(wxShutdownFlags wFlags)
     return false;
 }
 
+wxPowerType wxGetPowerType()
+{
+    // TODO
+    return wxPOWER_UNKNOWN;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
+}
+
 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
 wxMemorySize wxGetFreeMemory()
 {
diff --git a/src/palmos/utils.cpp b/src/palmos/utils.cpp
index 02d4de0324..f0cb433e0e 100644
--- a/src/palmos/utils.cpp
+++ b/src/palmos/utils.cpp
@@ -151,6 +151,17 @@ bool wxShutdown(wxShutdownFlags wFlags)
     return false;
 }
 
+wxPowerType wxGetPowerType()
+{
+    return wxPOWER_BATTERY;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
+}
+
 // ----------------------------------------------------------------------------
 // misc
 // ----------------------------------------------------------------------------
diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp
index cf1cf1240a..0a9c8e538d 100644
--- a/src/unix/utilsunx.cpp
+++ b/src/unix/utilsunx.cpp
@@ -239,7 +239,7 @@ int wxKill(long pid, wxSignal sig, wxKillError *rc, int flags)
 
 long wxExecute( const wxString& command, int flags, wxProcess *process )
 {
-    wxCHECK_MSG( !command.IsEmpty(), 0, wxT("can't exec empty command") );
+    wxCHECK_MSG( !command.empty(), 0, wxT("can't exec empty command") );
 
 #if wxUSE_THREADS
     // fork() doesn't mix well with POSIX threads: on many systems the program
@@ -372,6 +372,17 @@ bool wxShutdown(wxShutdownFlags wFlags)
     return system(wxString::Format(_T("init %c"), level).mb_str()) == 0;
 }
 
+wxPowerType wxGetPowerType()
+{
+    // TODO
+    return wxPOWER_UNKNOWN;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
+}
 
 // ----------------------------------------------------------------------------
 // wxStream classes to support IO redirection in wxExecute
@@ -660,9 +671,9 @@ long wxExecute(wxChar **argv,
 
 const wxChar* wxGetHomeDir( wxString *home  )
 {
-    *home = wxGetUserHome( wxString() );
+    *home = wxGetUserHome( wxEmptyString );
     wxString tmp;
-    if ( home->IsEmpty() )
+    if ( home->empty() )
         *home = wxT("/");
 #ifdef __VMS
     tmp = *home;
-- 
2.50.0

