X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/968eb2ef396c78442ffea7a2463f3777ca6d1632..d5363f57fb8beb6638932cb2b02a69262ee60f82:/include/wx/utils.h diff --git a/include/wx/utils.h b/include/wx/utils.h index db44a049e6..b84f78f44f 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: utils.h +// Name: wx/utils.h // Purpose: Miscellaneous utilities // Author: Julian Smart // Modified by: @@ -16,28 +16,20 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) && !defined(__EMX__) -// Some older compilers (such as EMX) cannot handle -// #pragma interface/implementation correctly, iff -// #pragma implementation is used in _two_ translation -// units (as created by e.g. event.cpp compiled for -// libwx_base and event.cpp compiled for libwx_gui_core). -// So we must not use those pragmas for those compilers in -// such files. - #pragma interface "utils.h" -#endif - #include "wx/object.h" #include "wx/list.h" #include "wx/filefn.h" class WXDLLIMPEXP_BASE wxArrayString; +class WXDLLIMPEXP_BASE wxArrayInt; // need this for wxGetDiskSpace() as we can't, unfortunately, forward declare // wxLongLong #include "wx/longlong.h" -#ifdef __X__ +#ifdef __WATCOMC__ + #include +#elif defined(__X__) #include #include #endif @@ -61,16 +53,13 @@ class WXDLLIMPEXP_CORE wxPoint; #define wxMax(a,b) (((a) > (b)) ? (a) : (b)) #define wxMin(a,b) (((a) < (b)) ? (a) : (b)) -// wxGetFreeMemory can return huge amount of memory on 64-bit platforms -// define wxMemorySize according to the type which best fits your platform -#if wxUSE_LONGLONG && defined(__WIN64__) - // 64 bit Windowses have sizeof(long) only 32 bit long - // we need to use wxLongLong to express memory sizes - #define wxMemorySize wxLongLong +// 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 +// support it +#if wxUSE_LONGLONG + typedef wxLongLong wxMemorySize; #else - // 64 bit UNIX has sizeof(long) = 64 - // assume 32 bit platforms cannnot return more than 32bits of - #define wxMemorySize long + typedef long wxMemorySize; #endif // ---------------------------------------------------------------------------- @@ -112,6 +101,85 @@ WXDLLIMPEXP_BASE const wxChar *wxGetInstallPrefix(); // Return path to wxWin data (/usr/share/wx/%{version}) (Unices) WXDLLIMPEXP_BASE wxString wxGetDataDir(); +/* + * Class to make it easier to specify platform-dependent values + * + * Examples: + * 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: + * + * #define stPDA 100 + * #ifdef __WXWINCE__ + * wxPlatform::AddPlatform(stPDA); + * #endif + * + * long windowStyle = wxCAPTION | (long) wxPlatform::IfNot(stPDA, wxRESIZE_BORDER); + * + */ + +class WXDLLIMPEXP_BASE wxPlatform +{ +public: + wxPlatform() { Init(); } + wxPlatform(const wxPlatform& platform) { Copy(platform); } + void operator = (const wxPlatform& platform) { Copy(platform); } + void Copy(const wxPlatform& platform); + void Init() { m_longValue = 0; m_doubleValue = 0.0; } + + // 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; } + + 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); + 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; } + double GetDouble() const { return m_doubleValue; } + + operator int() const { return (int) GetInteger(); } + operator long() const { return GetInteger(); } + operator double() const { return GetDouble(); } + operator const wxString() const { return GetString(); } + operator const wxChar*() const { return (const wxChar*) GetString(); } + + static void AddPlatform(int platform); + static bool Is(int platform); + static void ClearPlatforms(); + +private: + long m_longValue; + double m_doubleValue; + wxString m_stringValue; + static wxArrayInt* sm_customPlatforms; +}; + +/// Function for testing current platform +inline bool wxPlatformIs(int platform) { return wxPlatform::Is(platform); } #if wxUSE_GUI @@ -126,6 +194,70 @@ WXDLLEXPORT bool wxGetKeyState(wxKeyCode key); // in wxMSW. WXDLLEXPORT bool wxSetDetectableAutoRepeat( bool flag ); + +// wxMouseState is used to hold information about button and modifier state +// and is what is returned from wxGetMouseState. +class WXDLLEXPORT wxMouseState +{ +public: + wxMouseState() + : m_x(0), m_y(0), + m_leftDown(false), m_middleDown(false), m_rightDown(false), + m_controlDown(false), m_shiftDown(false), m_altDown(false), + m_metaDown(false) + {} + + wxCoord GetX() { return m_x; } + wxCoord GetY() { return m_y; } + + 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() + { +#if defined(__WXMAC__) || defined(__WXCOCOA__) + return MetaDown(); +#else + return ControlDown(); +#endif + } + + void SetX(wxCoord x) { m_x = x; } + void SetY(wxCoord y) { m_y = y; } + + void SetLeftDown(bool down) { m_leftDown = down; } + void SetMiddleDown(bool down) { m_middleDown = down; } + void SetRightDown(bool down) { m_rightDown = down; } + + void SetControlDown(bool down) { m_controlDown = down; } + 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_controlDown; + bool m_shiftDown; + bool m_altDown; + bool m_metaDown; +}; + + +// Returns the current state of the mouse position, buttons and modifers +WXDLLEXPORT wxMouseState wxGetMouseState(); + + // ---------------------------------------------------------------------------- // Window ID management // ---------------------------------------------------------------------------- @@ -220,6 +352,13 @@ WXDLLIMPEXP_BASE long wxExecute(const wxString& command, wxArrayString& error, int flags = 0); +#if defined(__WXMSW__) && wxUSE_IPC +// ask a DDE server to execute the DDE request with given parameters +WXDLLIMPEXP_BASE bool wxExecuteDDE(const wxString& ddeServer, + const wxString& ddeTopic, + const wxString& ddeCommand); +#endif // __WXMSW__ && wxUSE_IPC + enum wxSignal { wxSIGNONE = 0, // verify if the process exists under Unix @@ -329,10 +468,14 @@ WXDLLIMPEXP_BASE bool wxHandleFatalExceptions(bool doit = true); #endif // wxUSE_ON_FATAL_EXCEPTION -#if wxABI_VERSION >= 20601 +// flags for wxLaunchDefaultBrowser +enum +{ + wxBROWSER_NEW_WINDOW = 1 +}; + // Launch url in the user's default internet browser -WXDLLIMPEXP_BASE bool wxLaunchDefaultBrowser(const wxString& url); -#endif +WXDLLIMPEXP_BASE bool wxLaunchDefaultBrowser(const wxString& url, int flags = 0); // ---------------------------------------------------------------------------- // Environment variables @@ -386,10 +529,16 @@ WXDLLIMPEXP_BASE const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptySt WXDLLIMPEXP_BASE wxChar* wxGetUserHome(const wxString& user = wxEmptyString); #endif +#if wxUSE_LONGLONG + typedef wxLongLong wxDiskspaceSize_t; +#else + typedef long wxDiskspaceSize_t; +#endif + // get number of total/free bytes on the disk where path belongs WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path, - wxLongLong *pTotal = NULL, - wxLongLong *pFree = NULL); + wxDiskspaceSize_t *pTotal = NULL, + wxDiskspaceSize_t *pFree = NULL); #if wxUSE_GUI // GUI only things from now on @@ -562,21 +711,5 @@ WXDLLIMPEXP_BASE bool wxYieldIfNeeded(); // Error message functions used by wxWidgets (deprecated, use wxLog) // ---------------------------------------------------------------------------- -#if WXWIN_COMPATIBILITY_2_2 - -// Format a message on the standard error (UNIX) or the debugging -// stream (Windows) -wxDEPRECATED( WXDLLIMPEXP_BASE void wxDebugMsg(const wxChar *fmt ...) ATTRIBUTE_PRINTF_1 ); - -// Non-fatal error (continues) -extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxInternalErrorStr; -wxDEPRECATED( WXDLLIMPEXP_BASE void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr) ); - -// Fatal error (exits) -extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxFatalErrorStr; -wxDEPRECATED( WXDLLIMPEXP_BASE void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr) ); - -#endif // WXWIN_COMPATIBILITY_2_2 - #endif // _WX_UTILSH__