X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2461cfa0d9b786a26a783237bca38c920efecb51..76e7cfab8fdb0c7862fd07e427af54181717fc62:/src/os2/utilsgui.cpp diff --git a/src/os2/utilsgui.cpp b/src/os2/utilsgui.cpp index a48d2a0936..beea68483c 100644 --- a/src/os2/utilsgui.cpp +++ b/src/os2/utilsgui.cpp @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: os2/utilsgui.cpp +// Name: src/os2/utilsgui.cpp // Purpose: Various utility functions only available in GUI // Author: David Webster // Modified by: // Created: 20.08.2003 (extracted from os2/utils.cpp) -// RCS-ID: $Id$ // Copyright: (c) David Webster -// License: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -25,14 +24,16 @@ #endif #ifndef WX_PRECOMP - #include "wx/setup.h" #include "wx/utils.h" #include "wx/app.h" #include "wx/cursor.h" + #include "wx/font.h" + #include "wx/timer.h" #endif //WX_PRECOMP #include "wx/apptrait.h" -#include "wx/timer.h" +#include "wx/os2/private/timer.h" +#include "wx/evtloop.h" #include "wx/os2/private.h" // includes @@ -40,247 +41,29 @@ // implementation // ============================================================================ +// Emit a beeeeeep +void wxBell() +{ + DosBeep(1000,1000); // 1kHz during 1 sec. +} + // ---------------------------------------------------------------------------- // functions to work with .INI files // ---------------------------------------------------------------------------- // Sleep for nSecs seconds. Attempt a Windows implementation using timers. -static bool inTimer = FALSE; +static bool inTimer = false; class wxSleepTimer: public wxTimer { public: inline void Notify() { - inTimer = FALSE; + inTimer = false; Stop(); } }; -// Reading and writing resources (eg WIN.INI, .Xdefaults) -#if wxUSE_RESOURCES -bool wxWriteResource( - const wxString& rSection -, const wxString& rEntry -, const wxString& rValue -, const wxString& rFile -) -{ - HAB hab = 0; - HINI hIni = 0; - - if (rFile != "") - { - hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile); - if (hIni != 0L) - { - return (::PrfWriteProfileString( hIni - ,(PSZ)WXSTRINGCAST rSection - ,(PSZ)WXSTRINGCAST rEntry - ,(PSZ)WXSTRINGCAST rValue - )); - } - } - else - return (::PrfWriteProfileString( HINI_PROFILE - ,(PSZ)WXSTRINGCAST rSection - ,(PSZ)WXSTRINGCAST rEntry - ,(PSZ)WXSTRINGCAST rValue - )); - return FALSE; -} - -bool wxWriteResource( - const wxString& rSection -, const wxString& rEntry -, float fValue -, const wxString& rFile -) -{ - wxChar zBuf[50]; - - wxSprintf(zBuf, "%.4f", fValue); - return wxWriteResource( rSection - ,rEntry - ,zBuf - ,rFile - ); -} - -bool wxWriteResource( - const wxString& rSection -, const wxString& rEntry -, long lValue -, const wxString& rFile -) -{ - wxChar zBuf[50]; - - wxSprintf(zBuf, "%ld", lValue); - return wxWriteResource( rSection - ,rEntry - ,zBuf - ,rFile - ); -} - -bool wxWriteResource( - const wxString& rSection -, const wxString& rEntry -, int lValue -, const wxString& rFile -) -{ - wxChar zBuf[50]; - - wxSprintf(zBuf, "%d", lValue); - return wxWriteResource( rSection - ,rEntry - ,zBuf - ,rFile - ); -} - -bool wxGetResource( - const wxString& rSection -, const wxString& rEntry -, wxChar** ppValue -, const wxString& rFile -) -{ - HAB hab = 0; - HINI hIni = 0; - wxChar zDefunkt[] = _T("$$default"); - char zBuf[1000]; - - if (rFile != "") - { - hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST rFile); - if (hIni != 0L) - { - ULONG n = ::PrfQueryProfileString( hIni - ,(PSZ)WXSTRINGCAST rSection - ,(PSZ)WXSTRINGCAST rEntry - ,(PSZ)zDefunkt - ,(PVOID)zBuf - ,1000 - ); - if (zBuf == NULL) - return FALSE; - if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0) - return FALSE; - zBuf[n-1] = '\0'; - } - else - return FALSE; - } - else - { - ULONG n = ::PrfQueryProfileString( HINI_PROFILE - ,(PSZ)WXSTRINGCAST rSection - ,(PSZ)WXSTRINGCAST rEntry - ,(PSZ)zDefunkt - ,(PVOID)zBuf - ,1000 - ); - if (zBuf == NULL) - return FALSE; - if (n == 0L || wxStrcmp(zBuf, zDefunkt) == 0) - return FALSE; - zBuf[n-1] = '\0'; - } - strcpy((char*)*ppValue, zBuf); - return TRUE; -} - -bool wxGetResource( - const wxString& rSection -, const wxString& rEntry -, float* pValue -, const wxString& rFile -) -{ - wxChar* zStr = NULL; - - zStr = new wxChar[1000]; - bool bSucc = wxGetResource( rSection - ,rEntry - ,(wxChar **)&zStr - ,rFile - ); - - if (bSucc) - { - *pValue = (float)wxStrtod(zStr, NULL); - delete[] zStr; - return TRUE; - } - else - { - delete[] zStr; - return FALSE; - } -} - -bool wxGetResource( - const wxString& rSection -, const wxString& rEntry -, long* pValue -, const wxString& rFile -) -{ - wxChar* zStr = NULL; - - zStr = new wxChar[1000]; - bool bSucc = wxGetResource( rSection - ,rEntry - ,(wxChar **)&zStr - ,rFile - ); - - if (bSucc) - { - *pValue = wxStrtol(zStr, NULL, 10); - delete[] zStr; - return TRUE; - } - else - { - delete[] zStr; - return FALSE; - } -} - -bool wxGetResource( - const wxString& rSection -, const wxString& rEntry -, int* pValue -, const wxString& rFile -) -{ - wxChar* zStr = NULL; - - zStr = new wxChar[1000]; - bool bSucc = wxGetResource( rSection - ,rEntry - ,(wxChar **)&zStr - ,rFile - ); - - if (bSucc) - { - *pValue = (int)wxStrtol(zStr, NULL, 10); - delete[] zStr; - return TRUE; - } - else - { - delete[] zStr; - return FALSE; - } -} -#endif // wxUSE_RESOURCES - // --------------------------------------------------------------------------- // helper functions for showing a "busy" cursor // --------------------------------------------------------------------------- @@ -290,9 +73,7 @@ HCURSOR gs_wxBusyCursorOld = 0; // old cursor static int gs_wxBusyCursorCount = 0; // Set the cursor to the busy cursor for all windows -void wxBeginBusyCursor( - wxCursor* pCursor -) +void wxBeginBusyCursor(const wxCursor* pCursor) { if ( gs_wxBusyCursorCount++ == 0 ) { @@ -306,7 +87,7 @@ void wxBeginBusyCursor( void wxEndBusyCursor() { wxCHECK_RET( gs_wxBusyCursorCount > 0 - ,_T("no matching wxBeginBusyCursor() for wxEndBusyCursor()") + ,wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); if (--gs_wxBusyCursorCount == 0) @@ -316,7 +97,7 @@ void wxEndBusyCursor() } } -// TRUE if we're between the above two calls +// true if we're between the above two calls bool wxIsBusy() { return (gs_wxBusyCursorCount > 0); @@ -324,26 +105,24 @@ bool wxIsBusy() // Check whether this window wants to process messages, e.g. Stop button // in long calculations. -bool wxCheckForInterrupt( - wxWindow* pWnd -) +bool wxCheckForInterrupt( wxWindow* pWnd ) { if(pWnd) { - QMSG vMsg; - HAB hab = 0; - HWND hwndFilter = NULLHANDLE; + QMSG vMsg; + HAB hab = 0; + HWND hwndFilter = NULLHANDLE; while(::WinPeekMsg(hab, &vMsg, hwndFilter, 0, 0, PM_REMOVE)) { ::WinDispatchMsg(hab, &vMsg); } - return TRUE;//*** temporary? + return true;//*** temporary? } else { - wxFAIL_MSG(_T("pWnd==NULL !!!")); - return FALSE;//*** temporary? + wxFAIL_MSG(wxT("pWnd==NULL !!!")); + return false;//*** temporary? } } @@ -365,7 +144,7 @@ void wxGetMousePosition( *pY = vPt.y; }; -// Return TRUE if we have a colour display +// Return true if we have a colour display bool wxColourDisplay() { #if 0 @@ -380,7 +159,7 @@ bool wxColourDisplay() #else // I don't see how the PM display could not be color. Besides, this // was leaking DCs and PSs!!! MN - return TRUE; + return true; #endif } @@ -428,8 +207,10 @@ void wxDisplaySize( ::DevCloseDC(hdcScreen); ::WinReleasePS(hpsScreen); } - *pWidth = (int)lWidth; - *pHeight = (int)lHeight; + if (pWidth) + *pWidth = (int)lWidth; + if (pHeight) + *pHeight = (int)lHeight; } void wxDisplaySizeMM( @@ -480,74 +261,61 @@ void wxGUIAppTraits::TerminateGui(unsigned long ulHab) ::WinTerminate(ulHab); } -wxToolkitInfo & wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo vInfo; - ULONG ulSysInfo[QSV_MAX] = {0}; - APIRET ulrc; - - vInfo.shortName = _T("PM"); - vInfo.name = _T("wxOS2"); -#ifdef __WXUNIVERSAL__ - vInfo.shortName << _T("univ"); - vInfo.name << _T("/wxUniversal"); -#endif - ulrc = ::DosQuerySysInfo( 1L - ,QSV_MAX - ,(PVOID)ulSysInfo - ,sizeof(ULONG) * QSV_MAX - ); - if (ulrc == 0L) - { - vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10; - vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR]; - } - vInfo.os = wxOS2_PM; - return vInfo; + // How to get version of PM ? I guess, just reusing the OS version is OK. + (void) wxGetOsVersion(verMaj, verMin); + return wxPORT_OS2; +} + +wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer) +{ + return new wxOS2TimerImpl(timer); +} + +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() +{ + return new wxEventLoop; } // --------------------------------------------------------------------------- // window information functions // --------------------------------------------------------------------------- -wxString WXDLLEXPORT wxGetWindowText( - WXHWND hWnd -) +wxString WXDLLEXPORT wxGetWindowText( WXHWND hWnd ) { - wxString vStr; + wxString vStr; if ( hWnd ) { - long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1; - ::WinQueryWindowText((HWND)hWnd, lLen, wxStringBuffer(vStr, lLen)); + long lLen = ::WinQueryWindowTextLength((HWND)hWnd) + 1; + ::WinQueryWindowText((HWND)hWnd, lLen, (PSZ)(wxChar*)wxStringBuffer(vStr, lLen)); } return vStr; } -wxString WXDLLEXPORT wxGetWindowClass( - WXHWND hWnd -) +wxString WXDLLEXPORT wxGetWindowClass( WXHWND hWnd ) { - wxString vStr; + wxString vStr; if ( hWnd ) { - int nLen = 256; // some starting value - - for ( ;; ) - { - int nCount = ::WinQueryClassName((HWND)hWnd, nLen, wxStringBuffer(vStr, nLen)); - - if (nCount == nLen ) - { - // the class name might have been truncated, retry with larger - // buffer - nLen *= 2; - } - else - { - break; - } + int nLen = 256; // some starting value + + for ( ;; ) + { + int nCount = ::WinQueryClassName((HWND)hWnd, nLen, (PSZ)(wxChar*)wxStringBuffer(vStr, nLen)); + + if (nCount == nLen ) + { + // the class name might have been truncated, retry with larger + // buffer + nLen *= 2; + } + else + { + break; + } } } return vStr; @@ -939,7 +707,7 @@ wxBitmap wxDisableBitmap( int j; // - // Bitmap must be ina double-word alligned address so we may + // Bitmap must be in a double-word aligned address so we may // have some padding to worry about // if (nLineBoundary > 0) @@ -1096,7 +864,7 @@ wxBitmap wxDisableBitmap( ::GpiSetBitmap(hPS, NULLHANDLE); ::GpiDestroyPS(hPS); ::DevCloseDC(hDC); - if (vNewBmp.Ok()) + if (vNewBmp.IsOk()) return(vNewBmp); return(wxNullBitmap); } // end of wxDisableBitmap