]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/thread/thread.cpp
Support using GetTextExtent() with empty string to get descent in wxOSX.
[wxWidgets.git] / samples / thread / thread.cpp
index 132795efa120d8bd62b8aacf21490a9011355bce..7948c35a473f92c83e452af84ec19c45ec5152ee 100644 (file)
@@ -6,7 +6,7 @@
 // Created:     06/16/98
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998-2009 wxWidgets team
 // Created:     06/16/98
 // RCS-ID:      $Id$
 // Copyright:   (c) 1998-2009 wxWidgets team
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
@@ -378,7 +378,7 @@ MyFrame::MyFrame(const wxString& title)
     wxMenu *menuHelp = new wxMenu;
     menuHelp->Append(THREAD_SHOWCPUS, wxT("&Show CPU count"));
     menuHelp->AppendSeparator();
     wxMenu *menuHelp = new wxMenu;
     menuHelp->Append(THREAD_SHOWCPUS, wxT("&Show CPU count"));
     menuHelp->AppendSeparator();
-    menuHelp->Append(THREAD_ABOUT, wxT("&About..."));
+    menuHelp->Append(THREAD_ABOUT, wxT("&About"));
     menuBar->Append(menuHelp, wxT("&Help"));
 
     SetMenuBar(menuBar);
     menuBar->Append(menuHelp, wxT("&Help"));
 
     SetMenuBar(menuBar);
@@ -479,7 +479,7 @@ MyFrame::DoLogRecord(wxLogLevel level,
         wxDateTime(info.timestamp).FormatISOTime(),
         info.threadId == wxThread::GetMainId()
             ? wxString("main")
         wxDateTime(info.timestamp).FormatISOTime(),
         info.threadId == wxThread::GetMainId()
             ? wxString("main")
-            : wxString::Format("%x", info.threadId),
+            : wxString::Format("%lx", info.threadId),
         msg + "\n"
     );
 }
         msg + "\n"
     );
 }
@@ -559,11 +559,11 @@ void MyFrame::OnStartThreads(wxCommandEvent& WXUNUSED(event) )
         // have the lowest priority, the second - the highest, all the rest
         // the normal one
         if ( n == 0 )
         // have the lowest priority, the second - the highest, all the rest
         // the normal one
         if ( n == 0 )
-            thr->SetPriority(WXTHREAD_MIN_PRIORITY);
+            thr->SetPriority(wxPRIORITY_MIN);
         else if ( n == 1 )
         else if ( n == 1 )
-            thr->SetPriority(WXTHREAD_MAX_PRIORITY);
+            thr->SetPriority(wxPRIORITY_MAX);
         else
         else
-            thr->SetPriority(WXTHREAD_DEFAULT_PRIORITY);
+            thr->SetPriority(wxPRIORITY_DEFAULT);
 
         threads.Add(thr);
     }
 
         threads.Add(thr);
     }
@@ -597,6 +597,8 @@ void MyFrame::OnStartThread(wxCommandEvent& WXUNUSED(event) )
 
 void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
 {
 
 void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
 {
+    wxThread* toDelete = NULL;
+    {
     wxCriticalSectionLocker enter(wxGetApp().m_critsect);
 
     // stop the last thread
     wxCriticalSectionLocker enter(wxGetApp().m_critsect);
 
     // stop the last thread
@@ -606,7 +608,15 @@ void MyFrame::OnStopThread(wxCommandEvent& WXUNUSED(event) )
     }
     else
     {
     }
     else
     {
-        wxGetApp().m_threads.Last()->Delete();
+        toDelete = wxGetApp().m_threads.Last();
+    }
+    }
+
+    if ( toDelete )
+    {
+        // This can still crash if the thread gets to delete itself
+        // in the mean time.
+        toDelete->Delete();
 
 #if wxUSE_STATUSBAR
         SetStatusText(wxT("Last thread stopped."), 1);
 
 #if wxUSE_STATUSBAR
         SetStatusText(wxT("Last thread stopped."), 1);
@@ -969,7 +979,7 @@ wxThread::ExitCode MyWorkerThread::Entry()
     if ( TestDestroy() )
         return NULL;
 
     if ( TestDestroy() )
         return NULL;
 
-    wxThreadEvent event( wxEVT_COMMAND_THREAD, WORKER_EVENT );
+    wxThreadEvent event( wxEVT_THREAD, WORKER_EVENT );
 
     event.SetInt( 50 );
     wxQueueEvent( m_frame, event.Clone() );
 
     event.SetInt( 50 );
     wxQueueEvent( m_frame, event.Clone() );
@@ -984,7 +994,7 @@ wxThread::ExitCode MyWorkerThread::Entry()
             break;
 
         // create any type of command event here
             break;
 
         // create any type of command event here
-        wxThreadEvent event( wxEVT_COMMAND_THREAD, WORKER_EVENT );
+        wxThreadEvent event( wxEVT_THREAD, WORKER_EVENT );
         event.SetInt( m_count );
 
         // send in a thread-safe way
         event.SetInt( m_count );
 
         // send in a thread-safe way
@@ -993,7 +1003,7 @@ wxThread::ExitCode MyWorkerThread::Entry()
         wxMilliSleep(200);
     }
 
         wxMilliSleep(200);
     }
 
-    wxThreadEvent event( wxEVT_COMMAND_THREAD, WORKER_EVENT );
+    wxThreadEvent event( wxEVT_THREAD, WORKER_EVENT );
     event.SetInt(-1); // that's all
     wxQueueEvent( m_frame, event.Clone() );
 #endif
     event.SetInt(-1); // that's all
     wxQueueEvent( m_frame, event.Clone() );
 #endif
@@ -1043,7 +1053,7 @@ wxThread::ExitCode MyGUIThread::Entry()
         wxMutexGuiLeave();
 
         // notify the dialog that another piece of our masterpiece is complete:
         wxMutexGuiLeave();
 
         // notify the dialog that another piece of our masterpiece is complete:
-        wxThreadEvent event( wxEVT_COMMAND_THREAD, GUITHREAD_EVENT );
+        wxThreadEvent event( wxEVT_THREAD, GUITHREAD_EVENT );
         event.SetInt(i+1);
         wxQueueEvent( m_dlg, event.Clone() );
 
         event.SetInt(i+1);
         wxQueueEvent( m_dlg, event.Clone() );