X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2187eef5bb7a81ee3b2738a312f4ecfceb49bded..1fa29bdc254c03dd5026a4b72aa8312667178121:/src/motif/dialog.cpp

diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp
index ab5c7eeccc..393429dc1f 100644
--- a/src/motif/dialog.cpp
+++ b/src/motif/dialog.cpp
@@ -9,7 +9,7 @@
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
 #pragma implementation "dialog.h"
 #endif
 
@@ -305,8 +305,8 @@ bool wxDialog::Show( bool show )
         else
             XtUnmanageChild((Widget)m_mainWidget) ;
 
-        XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
-        XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE);
+        XFlush(XtDisplay((Widget)m_mainWidget));
+        XSync(XtDisplay((Widget)m_mainWidget), FALSE);
     }
 
     return TRUE;
@@ -319,6 +319,9 @@ int wxDialog::ShowModal()
 
     Show(TRUE);
 
+    // after the event loop ran, the widget might already have been destroyed
+    WXDisplay* display = (WXDisplay*)XtDisplay( (Widget)m_mainWidget );
+
     if (m_modalShowing)
         return 0;
     m_eventLoop = new wxEventLoop;
@@ -329,12 +332,7 @@ int wxDialog::ShowModal()
     m_eventLoop->Run();
 
     // Now process all events in case they get sent to a destroyed dialog
-    XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE);
-    while (m_eventLoop->Pending())
-    {
-        XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()));
-        m_eventLoop->Dispatch();
-    }
+    wxFlushEvents( display );
 
     delete m_eventLoop;
     m_eventLoop = NULL;
@@ -445,11 +443,11 @@ void wxDialog::ChangeFont(bool keepOriginalSize)
 void wxDialog::ChangeBackgroundColour()
 {
     if (GetMainWidget())
-        DoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
+        wxDoChangeBackgroundColour(GetMainWidget(), m_backgroundColour);
 }
 
 void wxDialog::ChangeForegroundColour()
 {
     if (GetMainWidget())
-        DoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
+        wxDoChangeForegroundColour(GetMainWidget(), m_foregroundColour);
 }