]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/app.cpp
check that the version of __sync_sub_and_fetch that returns a value is supported...
[wxWidgets.git] / src / msw / app.cpp
index 854e0edced3605f0bdacb42086371d30ae658fee..ef5379e82b6e03d39e20da5fa3b8673dd571fb74 100644 (file)
@@ -25,6 +25,7 @@
 #endif
 
 #ifndef WX_PRECOMP
+    #include "wx/msw/wrapcctl.h"
     #include "wx/dynarray.h"
     #include "wx/frame.h"
     #include "wx/app.h"
     #include "wx/dialog.h"
     #include "wx/msgdlg.h"
     #include "wx/intl.h"
-    #include "wx/wxchar.h"
+    #include "wx/crt.h"
     #include "wx/log.h"
+    #include "wx/module.h"
 #endif
 
 #include "wx/apptrait.h"
 #include "wx/filename.h"
-#include "wx/module.h"
 #include "wx/dynlib.h"
 #include "wx/evtloop.h"
+#include "wx/thread.h"
 
 #include "wx/msw/private.h"
 #include "wx/msw/ole/oleutils.h"
+#include "wx/msw/private/timer.h"
 
 #if wxUSE_TOOLTIPS
     #include "wx/tooltip.h"
 #include <string.h>
 #include <ctype.h>
 
-#include "wx/msw/wrapcctl.h"
-
-// For MB_TASKMODAL
-#ifdef __WXWINCE__
-#include "wx/msw/wince/missing.h"
-#endif
+#include "wx/msw/missing.h"
 
 // instead of including <shlwapi.h> which is not part of the core SDK and not
 // shipped at all with other compilers, we always define the parts of it we
 // global variables
 // ---------------------------------------------------------------------------
 
-extern wxList WXDLLEXPORT wxPendingDelete;
-
 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
 extern void wxSetKeyboardHook(bool doIt);
 #endif
@@ -218,7 +214,7 @@ bool wxGUIAppTraits::DoMessageFromThreadWait()
 {
     // we should return false only if the app should exit, i.e. only if
     // Dispatch() determines that the main event loop should terminate
-    wxEventLoop *evtLoop = wxEventLoop::GetActive();
+    wxEventLoopBase * const evtLoop = wxEventLoop::GetActive();
     if ( !evtLoop || !evtLoop->Pending() )
     {
         // no events means no quit event
@@ -228,20 +224,61 @@ bool wxGUIAppTraits::DoMessageFromThreadWait()
     return evtLoop->Dispatch();
 }
 
-wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo()
+DWORD wxGUIAppTraits::WaitForThread(WXHANDLE hThread)
+{
+    // if we don't have a running event loop, we shouldn't wait for the
+    // messages as we never remove them from the message queue and so we enter
+    // an infinite loop as MsgWaitForMultipleObjects() keeps returning
+    // WAIT_OBJECT_0 + 1
+    if ( !wxEventLoop::GetActive() )
+        return DoSimpleWaitForThread(hThread);
+
+    return ::MsgWaitForMultipleObjects
+             (
+               1,                   // number of objects to wait for
+               (HANDLE *)&hThread,  // the objects
+               false,               // wait for any objects, not all
+               INFINITE,            // no timeout
+               QS_ALLINPUT |        // return as soon as there are any events
+               QS_ALLPOSTMESSAGE
+             );
+}
+
+wxPortId wxGUIAppTraits::GetToolkitVersion(int *majVer, int *minVer) const
 {
-    static wxToolkitInfo info;
-    wxToolkitInfo& baseInfo = wxAppTraits::GetToolkitInfo();
-    info.versionMajor = baseInfo.versionMajor;
-    info.versionMinor = baseInfo.versionMinor;
-    info.os = baseInfo.os;
-    info.shortName = _T("msw");
-    info.name = _T("wxMSW");
-#ifdef __WXUNIVERSAL__
-    info.shortName << _T("univ");
-    info.name << _T("/wxUniversal");
+    OSVERSIONINFO info;
+    wxZeroMemory(info);
+
+    // on Windows, the toolkit version is the same of the OS version
+    // as Windows integrates the OS kernel with the GUI toolkit.
+    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+    if ( ::GetVersionEx(&info) )
+    {
+        if ( majVer )
+            *majVer = info.dwMajorVersion;
+        if ( minVer )
+            *minVer = info.dwMinorVersion;
+    }
+
+#if defined(__WXHANDHELD__) || defined(__WXWINCE__)
+    return wxPORT_WINCE;
+#else
+    return wxPORT_MSW;
 #endif
-    return info;
+}
+
+#if wxUSE_TIMER
+
+wxTimerImpl *wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
+{
+    return new wxMSWTimerImpl(timer);
+}
+
+#endif // wxUSE_TIMER
+
+wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
+{
+    return new wxEventLoop;
 }
 
 // ===========================================================================
@@ -288,9 +325,9 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
 #ifdef __WXWINCE__
     wxString tmp = GetAppName();
     tmp += wxT("ClassName");
-    wxCanvasClassName = wxStrdup( tmp.c_str() );
+    wxCanvasClassName = wxStrdup( tmp.wc_str() );
     tmp += wxT("NR");
-    wxCanvasClassNameNR = wxStrdup( tmp.c_str() );
+    wxCanvasClassNameNR = wxStrdup( tmp.wc_str() );
     HWND hWnd = FindWindow( wxCanvasClassNameNR, NULL );
     if (hWnd)
     {
@@ -516,16 +553,14 @@ wxApp::~wxApp()
 // wxApp idle handling
 // ----------------------------------------------------------------------------
 
-void wxApp::OnIdle(wxIdleEvent& event)
+void wxApp::OnIdle(wxIdleEvent& WXUNUSED(event))
 {
-    wxAppBase::OnIdle(event);
-
 #if wxUSE_DC_CACHEING
     // automated DC cache management: clear the cached DCs and bitmap
     // if it's likely that the app has finished with them, that is, we
     // get an idle event and we're not dragging anything.
     if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON))
-        wxDC::ClearCache();
+        wxMSWDCImpl::ClearCache();
 #endif // wxUSE_DC_CACHEING
 }
 
@@ -568,15 +603,42 @@ void wxApp::OnQueryEndSession(wxCloseEvent& event)
 }
 
 // ----------------------------------------------------------------------------
-// miscellaneous
+// system DLL versions
 // ----------------------------------------------------------------------------
 
+#if wxUSE_DYNLIB_CLASS
+
+namespace
+{
+
+// helper function: retrieve the DLL version by using DllGetVersion(), returns
+// 0 if the DLL doesn't export such function
+int CallDllGetVersion(wxDynamicLibrary& dll)
+{
+    // now check if the function is available during run-time
+    wxDYNLIB_FUNCTION( DLLGETVERSIONPROC, DllGetVersion, dll );
+    if ( !pfnDllGetVersion )
+        return 0;
+
+    DLLVERSIONINFO dvi;
+    dvi.cbSize = sizeof(dvi);
+
+    HRESULT hr = (*pfnDllGetVersion)(&dvi);
+    if ( FAILED(hr) )
+    {
+        wxLogApiError(_T("DllGetVersion"), hr);
+
+        return 0;
+    }
+
+    return 100*dvi.dwMajorVersion + dvi.dwMinorVersion;
+}
+
+} // anonymous namespace
+
 /* static */
 int wxApp::GetComCtl32Version()
 {
-#if defined(__WXMICROWIN__) || defined(__WXWINCE__)
-    return 0;
-#else
     // cache the result
     //
     // NB: this is MT-ok as in the worst case we'd compute s_verComCtl32 twice,
@@ -585,78 +647,103 @@ int wxApp::GetComCtl32Version()
 
     if ( s_verComCtl32 == -1 )
     {
-        // initally assume no comctl32.dll at all
-        s_verComCtl32 = 0;
-
         // we're prepared to handle the errors
         wxLogNull noLog;
 
-#if wxUSE_DYNLIB_CLASS
-        // do we have it?
+        // the DLL should really be available
         wxDynamicLibrary dllComCtl32(_T("comctl32.dll"), wxDL_VERBATIM);
+        if ( !dllComCtl32.IsLoaded() )
+        {
+            s_verComCtl32 = 0;
+            return 0;
+        }
+
+        // try DllGetVersion() for recent DLLs
+        s_verComCtl32 = CallDllGetVersion(dllComCtl32);
 
-        // if so, then we can check for the version
-        if ( dllComCtl32.IsLoaded() )
+        // if DllGetVersion() is unavailable either during compile or
+        // run-time, try to guess the version otherwise
+        if ( !s_verComCtl32 )
         {
-            // now check if the function is available during run-time
-            wxDYNLIB_FUNCTION( DLLGETVERSIONPROC, DllGetVersion, dllComCtl32 );
-            if ( pfnDllGetVersion )
+            // InitCommonControlsEx is unique to 4.70 and later
+            void *pfn = dllComCtl32.GetSymbol(_T("InitCommonControlsEx"));
+            if ( !pfn )
             {
-                DLLVERSIONINFO dvi;
-                dvi.cbSize = sizeof(dvi);
-
-                HRESULT hr = (*pfnDllGetVersion)(&dvi);
-                if ( FAILED(hr) )
-                {
-                    wxLogApiError(_T("DllGetVersion"), hr);
-                }
-                else
-                {
-                    // this is incompatible with _WIN32_IE values, but
-                    // compatible with the other values returned by
-                    // GetComCtl32Version()
-                    s_verComCtl32 = 100*dvi.dwMajorVersion +
-                                        dvi.dwMinorVersion;
-                }
+                // not found, must be 4.00
+                s_verComCtl32 = 400;
             }
-
-            // if DllGetVersion() is unavailable either during compile or
-            // run-time, try to guess the version otherwise
-            if ( !s_verComCtl32 )
+            else // 4.70+
             {
-                // InitCommonControlsEx is unique to 4.70 and later
-                void *pfn = dllComCtl32.GetSymbol(_T("InitCommonControlsEx"));
+                // many symbols appeared in comctl32 4.71, could use any of
+                // them except may be DllInstall()
+                pfn = dllComCtl32.GetSymbol(_T("InitializeFlatSB"));
                 if ( !pfn )
                 {
-                    // not found, must be 4.00
-                    s_verComCtl32 = 400;
+                    // not found, must be 4.70
+                    s_verComCtl32 = 470;
                 }
-                else // 4.70+
+                else
                 {
-                    // many symbols appeared in comctl32 4.71, could use any of
-                    // them except may be DllInstall()
-                    pfn = dllComCtl32.GetSymbol(_T("InitializeFlatSB"));
-                    if ( !pfn )
-                    {
-                        // not found, must be 4.70
-                        s_verComCtl32 = 470;
-                    }
-                    else
-                    {
-                        // found, must be 4.71 or later
-                        s_verComCtl32 = 471;
-                    }
+                    // found, must be 4.71 or later
+                    s_verComCtl32 = 471;
                 }
             }
         }
-#endif
     }
 
     return s_verComCtl32;
-#endif // Microwin/!Microwin
 }
 
+/* static */
+int wxApp::GetShell32Version()
+{
+    static int s_verShell32 = -1;
+    if ( s_verShell32 == -1 )
+    {
+        // we're prepared to handle the errors
+        wxLogNull noLog;
+
+        wxDynamicLibrary dllShell32(_T("shell32.dll"), wxDL_VERBATIM);
+        if ( dllShell32.IsLoaded() )
+        {
+            s_verShell32 = CallDllGetVersion(dllShell32);
+
+            if ( !s_verShell32 )
+            {
+                // there doesn't seem to be any way to distinguish between 4.00
+                // and 4.70 (starting from 4.71 we have DllGetVersion()) so
+                // just assume it is 4.0
+                s_verShell32 = 400;
+            }
+        }
+        else // failed load the DLL?
+        {
+            s_verShell32 = 0;
+        }
+    }
+
+    return s_verShell32;
+}
+
+#else // !wxUSE_DYNLIB_CLASS
+
+/* static */
+int wxApp::GetComCtl32Version()
+{
+    return 0;
+}
+
+/* static */
+int wxApp::GetShell32Version()
+{
+    return 0;
+}
+
+#endif // wxUSE_DYNLIB_CLASS/!wxUSE_DYNLIB_CLASS
+
+// ----------------------------------------------------------------------------
 // Yield to incoming messages
+// ----------------------------------------------------------------------------
 
 bool wxApp::Yield(bool onlyIfNeeded)
 {
@@ -748,30 +835,3 @@ terminate the program,\r\n\
 }
 
 #endif // wxUSE_EXCEPTIONS
-
-// ----------------------------------------------------------------------------
-// deprecated event loop functions
-// ----------------------------------------------------------------------------
-
-#if WXWIN_COMPATIBILITY_2_4
-
-void wxApp::DoMessage(WXMSG *pMsg)
-{
-    wxEventLoop *evtLoop = wxEventLoop::GetActive();
-    if ( evtLoop )
-        evtLoop->ProcessMessage(pMsg);
-}
-
-bool wxApp::DoMessage()
-{
-    wxEventLoop *evtLoop = wxEventLoop::GetActive();
-    return evtLoop ? evtLoop->Dispatch() : false;
-}
-
-bool wxApp::ProcessMessage(WXMSG* pMsg)
-{
-    wxEventLoop *evtLoop = wxEventLoop::GetActive();
-    return evtLoop && evtLoop->PreProcessMessage(pMsg);
-}
-
-#endif // WXWIN_COMPATIBILITY_2_4