]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/thread.cpp
added wxTB_HORZ_TEXT (patch 713813); documented it; moved toolbar styles to toolbar.h
[wxWidgets.git] / src / msw / thread.cpp
index 92f34c9ca8b8914972b31ffd03b9be0b7aacc6f8..576f756780d69566bcec83e6f326cdb16c376c1c 100644 (file)
 #endif
 
 #ifndef WX_PRECOMP
-#    include "wx/wx.h"
+    #include "wx/intl.h"
+    #include "wx/app.h"
 #endif
 
 #if wxUSE_THREADS
 
+#include "wx/apptrait.h"
+
 #include "wx/msw/private.h"
 #include "wx/msw/missing.h"
 
@@ -629,6 +632,9 @@ void wxThreadInternal::SetPriority(unsigned int priority)
 
 bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize)
 {
+    wxASSERT_MSG( m_state == STATE_NEW && !m_hThread,
+                    _T("Create()ing thread twice?") );
+
     // for compilers which have it, we should use C RTL function for thread
     // creation instead of Win32 API one because otherwise we will have memory
     // leaks if the thread uses C RTL (and most threads do)
@@ -674,8 +680,6 @@ bool wxThreadInternal::Create(wxThread *thread, unsigned int stackSize)
         SetPriority(m_priority);
     }
 
-    m_state = STATE_NEW;
-
     return TRUE;
 }
 
@@ -999,10 +1003,11 @@ wxThreadError wxThread::Delete(ExitCode *pRc)
             m_internal->Cancel();
         }
 
-#if wxUSE_GUI
         // we can't just wait for the thread to terminate because it might be
         // calling some GUI functions and so it will never terminate before we
         // process the Windows messages that result from these functions
+        // (note that even in console applications we might have to process
+        // messages if we use wxExecute() or timers or ...)
         DWORD result = 0;       // suppress warnings from broken compilers
         do
         {
@@ -1040,12 +1045,17 @@ wxThreadError wxThread::Delete(ExitCode *pRc)
 
                 case WAIT_OBJECT_0 + 1:
                     // new message arrived, process it
-                    if ( !wxTheApp->DoMessage() )
                     {
-                        // WM_QUIT received: kill the thread
-                        Kill();
+                        wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits()
+                                                       : NULL;
+
+                        if ( traits && !traits->DoMessageFromThreadWait() )
+                        {
+                            // WM_QUIT received: kill the thread
+                            Kill();
 
-                        return wxTHREAD_KILLED;
+                            return wxTHREAD_KILLED;
+                        }
                     }
                     break;
 
@@ -1053,16 +1063,6 @@ wxThreadError wxThread::Delete(ExitCode *pRc)
                     wxFAIL_MSG(wxT("unexpected result of MsgWaitForMultipleObject"));
             }
         } while ( result != WAIT_OBJECT_0 );
-#else // !wxUSE_GUI
-        // simply wait for the thread to terminate
-        //
-        // OTOH, even console apps create windows (in wxExecute, for WinSock
-        // &c), so may be use MsgWaitForMultipleObject() too here?
-        if ( WaitForSingleObject(hThread, INFINITE) != WAIT_OBJECT_0 )
-        {
-            wxFAIL_MSG(wxT("unexpected result of WaitForSingleObject"));
-        }
-#endif // wxUSE_GUI/!wxUSE_GUI
 
         if ( IsMain() )
         {
@@ -1267,7 +1267,7 @@ void wxThreadModule::OnExit()
 // not a mutex, so the names are a bit confusing
 // ----------------------------------------------------------------------------
 
-void WXDLLEXPORT wxMutexGuiEnter()
+void WXDLLIMPEXP_BASE wxMutexGuiEnter()
 {
     // this would dead lock everything...
     wxASSERT_MSG( !wxThread::IsMain(),
@@ -1289,7 +1289,7 @@ void WXDLLEXPORT wxMutexGuiEnter()
     gs_critsectGui->Enter();
 }
 
-void WXDLLEXPORT wxMutexGuiLeave()
+void WXDLLIMPEXP_BASE wxMutexGuiLeave()
 {
     wxCriticalSectionLocker enter(*gs_critsectWaitingForGui);
 
@@ -1311,7 +1311,7 @@ void WXDLLEXPORT wxMutexGuiLeave()
     gs_critsectGui->Leave();
 }
 
-void WXDLLEXPORT wxMutexGuiLeaveOrEnter()
+void WXDLLIMPEXP_BASE wxMutexGuiLeaveOrEnter()
 {
     wxASSERT_MSG( wxThread::IsMain(),
                   wxT("only main thread may call wxMutexGuiLeaveOrEnter()!") );
@@ -1341,13 +1341,13 @@ void WXDLLEXPORT wxMutexGuiLeaveOrEnter()
     }
 }
 
-bool WXDLLEXPORT wxGuiOwnedByMainThread()
+bool WXDLLIMPEXP_BASE wxGuiOwnedByMainThread()
 {
     return gs_bGuiOwnedByMainThread;
 }
 
 // wake up the main thread if it's in ::GetMessage()
-void WXDLLEXPORT wxWakeUpMainThread()
+void WXDLLIMPEXP_BASE wxWakeUpMainThread()
 {
     // sending any message would do - hopefully WM_NULL is harmless enough
     if ( !::PostThreadMessage(gs_idMainThread, WM_NULL, 0, 0) )
@@ -1357,7 +1357,7 @@ void WXDLLEXPORT wxWakeUpMainThread()
     }
 }
 
-bool WXDLLEXPORT wxIsWaitingForThread()
+bool WXDLLIMPEXP_BASE wxIsWaitingForThread()
 {
     return gs_waitingForThread;
 }