X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/230c90774f48fd3ba9a9f1c3af5354fbad94843f..e80edb8515cc574f8ad264f47bd9cfe9501cfc97:/include/wx/utils.h?ds=sidebyside diff --git a/include/wx/utils.h b/include/wx/utils.h index 9923ea9159..1141a3004e 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -19,6 +19,9 @@ #include "wx/object.h" #include "wx/list.h" #include "wx/filefn.h" +#if wxUSE_GUI + #include "wx/gdicmn.h" +#endif class WXDLLIMPEXP_BASE wxArrayString; class WXDLLIMPEXP_BASE wxArrayInt; @@ -44,7 +47,6 @@ class WXDLLIMPEXP_CORE wxProcess; class WXDLLIMPEXP_CORE wxFrame; class WXDLLIMPEXP_CORE wxWindow; class WXDLLIMPEXP_CORE wxWindowList; -class WXDLLIMPEXP_CORE wxPoint; // ---------------------------------------------------------------------------- // Macros @@ -52,6 +54,7 @@ class WXDLLIMPEXP_CORE wxPoint; #define wxMax(a,b) (((a) > (b)) ? (a) : (b)) #define wxMin(a,b) (((a) < (b)) ? (a) : (b)) +#define wxClip(a,b,c) (((a) < (b)) ? (b) : (((a) > (c)) ? (c) : (a))) // wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well // so to always use long long for its result type on all platforms which @@ -105,8 +108,8 @@ WXDLLIMPEXP_BASE wxString wxGetDataDir(); * Class to make it easier to specify platform-dependent values * * Examples: - * long val = wxPlatform(3).Is(wxMac, 1).Is(wxGTK, 2).Is(stPDA, 5); - * wxString strVal = wxPlatform(wxT("Hello")).Is(wxMac, wxT("Mac")).Is(wxMSW, wxT("MSW")); + * long val = wxPlatform::If(wxMac, 1).ElseIf(wxGTK, 2).ElseIf(stPDA, 5).Else(3); + * wxString strVal = wxPlatform::If(wxMac, wxT("Mac")).ElseIf(wxMSW, wxT("MSW")).Else(wxT("Other")); * * A custom platform symbol: * @@ -115,37 +118,47 @@ WXDLLIMPEXP_BASE wxString wxGetDataDir(); * wxPlatform::AddPlatform(stPDA); * #endif * - * long windowStyle = wxCAPTION | (long) wxPlatform().IsNot(stPDA, wxRESIZE_BORDER); + * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER); * */ class WXDLLIMPEXP_BASE wxPlatform { public: - wxPlatform() { m_longValue = 0; m_doubleValue = 0.0; } + wxPlatform() { Init(); } + wxPlatform(const wxPlatform& platform) { Copy(platform); } + void operator = (const wxPlatform& platform) { Copy(platform); } + void Copy(const wxPlatform& platform); // Specify an optional default value - wxPlatform(long defValue) { m_longValue = defValue; m_doubleValue = 0.0; } - wxPlatform(const wxString& defValue) { m_stringValue = defValue; m_longValue = 0; m_doubleValue = 0.0; } - wxPlatform(double defValue) { m_longValue = 0; m_doubleValue = defValue; } - - wxPlatform& Is(int platform, long value); - wxPlatform& IsNot(int platform, long value); - - wxPlatform& Is(int platform, int value) { return Is(platform, (long) value); } - wxPlatform& IsNot(int platform, int value) { return IsNot(platform, (long) value); } - - wxPlatform& Is(int platform, const wxString& value); - wxPlatform& IsNot(int platform, const wxString& value); - - wxPlatform& Is(int platform, double value); - wxPlatform& IsNot(int platform, double value); - - // This should be specified first to set the default value, or simply - // pass the value to the constructor - wxPlatform& Default(long value); - wxPlatform& Default(const wxString& value); - wxPlatform& Default(double value); + wxPlatform(int defValue) { Init(); m_longValue = (long)defValue; } + wxPlatform(long defValue) { Init(); m_longValue = defValue; } + wxPlatform(const wxString& defValue) { Init(); m_stringValue = defValue; } + wxPlatform(double defValue) { Init(); m_doubleValue = defValue; } + + static wxPlatform If(int platform, long value); + static wxPlatform IfNot(int platform, long value); + wxPlatform& ElseIf(int platform, long value); + wxPlatform& ElseIfNot(int platform, long value); + wxPlatform& Else(long value); + + static wxPlatform If(int platform, int value) { return If(platform, (long)value); } + static wxPlatform IfNot(int platform, int value) { return IfNot(platform, (long)value); } + wxPlatform& ElseIf(int platform, int value) { return ElseIf(platform, (long) value); } + wxPlatform& ElseIfNot(int platform, int value) { return ElseIfNot(platform, (long) value); } + wxPlatform& Else(int value) { return Else((long) value); } + + static wxPlatform If(int platform, double value); + static wxPlatform IfNot(int platform, double value); + wxPlatform& ElseIf(int platform, double value); + wxPlatform& ElseIfNot(int platform, double value); + wxPlatform& Else(double value); + + static wxPlatform If(int platform, const wxString& value); + static wxPlatform IfNot(int platform, const wxString& value); + wxPlatform& ElseIf(int platform, const wxString& value); + wxPlatform& ElseIfNot(int platform, const wxString& value); + wxPlatform& Else(const wxString& value); long GetInteger() const { return m_longValue; } const wxString& GetString() const { return m_stringValue; } @@ -158,10 +171,13 @@ public: operator const wxChar*() const { return (const wxChar*) GetString(); } static void AddPlatform(int platform); - static bool PlatformIs(int platform); + static bool Is(int platform); static void ClearPlatforms(); private: + + void Init() { m_longValue = 0; m_doubleValue = 0.0; } + long m_longValue; double m_doubleValue; wxString m_stringValue; @@ -169,7 +185,7 @@ private: }; /// Function for testing current platform -inline bool wxPlatformIs(int platform) { return wxPlatform::PlatformIs(platform); } +inline bool wxPlatformIs(int platform) { return wxPlatform::Is(platform); } #if wxUSE_GUI @@ -203,12 +219,12 @@ public: bool LeftDown() { return m_leftDown; } bool MiddleDown() { return m_middleDown; } bool RightDown() { return m_rightDown; } - + bool ControlDown() { return m_controlDown; } bool ShiftDown() { return m_shiftDown; } bool AltDown() { return m_altDown; } bool MetaDown() { return m_metaDown; } - bool CmdDown() + bool CmdDown() { #if defined(__WXMAC__) || defined(__WXCOCOA__) return MetaDown(); @@ -228,19 +244,19 @@ public: void SetShiftDown(bool down) { m_shiftDown = down; } void SetAltDown(bool down) { m_altDown = down; } void SetMetaDown(bool down) { m_metaDown = down; } - + private: wxCoord m_x; wxCoord m_y; - bool m_leftDown; - bool m_middleDown; - bool m_rightDown; + bool m_leftDown : 1; + bool m_middleDown : 1; + bool m_rightDown : 1; - bool m_controlDown; - bool m_shiftDown; - bool m_altDown; - bool m_metaDown; + bool m_controlDown : 1; + bool m_shiftDown : 1; + bool m_altDown : 1; + bool m_metaDown : 1; }; @@ -396,26 +412,6 @@ 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 // @@ -604,9 +600,7 @@ private: // ---------------------------------------------------------------------------- // Set the cursor to the busy cursor for all windows -class WXDLLEXPORT wxCursor; -extern WXDLLEXPORT_DATA(wxCursor*) wxHOURGLASS_CURSOR; -WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR); +WXDLLIMPEXP_CORE void wxBeginBusyCursor(const wxCursor *cursor = wxHOURGLASS_CURSOR); // Restore cursor to normal WXDLLEXPORT void wxEndBusyCursor(); @@ -618,7 +612,7 @@ WXDLLEXPORT bool wxIsBusy(); class WXDLLEXPORT wxBusyCursor { public: - wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR) + wxBusyCursor(const wxCursor* cursor = wxHOURGLASS_CURSOR) { wxBeginBusyCursor(cursor); } ~wxBusyCursor() { wxEndBusyCursor(); }