X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/798a4529fe37bfd1864b4ed350e7de603bd40f2b..878711c01c1b9ad5b97d35f379a048b8ce1bfb49:/src/motif/dialog.cpp diff --git a/src/motif/dialog.cpp b/src/motif/dialog.cpp index bb4a45ea2f..ab5c7eeccc 100644 --- a/src/motif/dialog.cpp +++ b/src/motif/dialog.cpp @@ -24,6 +24,7 @@ #include "wx/utils.h" #include "wx/app.h" #include "wx/settings.h" +#include "wx/evtloop.h" #ifdef __VMS__ #pragma message disable nosimpint @@ -56,7 +57,7 @@ // A stack of modal_showing flags, since we can't rely // on accessing wxDialog::m_modalShowing within // wxDialog::Show in case a callback has deleted the wxDialog. -static wxList wxModalShowingStack; +// static wxList wxModalShowingStack; // Lists to keep track of windows, so we can disable/enable them // for modal dialogs @@ -81,6 +82,7 @@ END_EVENT_TABLE() wxDialog::wxDialog() { m_modalShowing = FALSE; + m_eventLoop = NULL; m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); } @@ -98,6 +100,7 @@ bool wxDialog::Create(wxWindow *parent, wxWindowID id, return FALSE; m_modalShowing = FALSE; + m_eventLoop = NULL; m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); m_foregroundColour = *wxBLACK; @@ -165,7 +168,8 @@ bool wxDialog::DoCreate( wxWindow* parent, wxWindowID id, XtSetArg (args[0], XmNdefaultPosition, False); XtSetArg (args[1], XmNautoUnmanage, False); Widget dialogShell = - XmCreateBulletinBoardDialog( parentWidget, (char*)name.c_str(), + XmCreateBulletinBoardDialog( parentWidget, + wxConstCast(name.c_str(), char), args, 2); m_mainWidget = (WXWidget) dialogShell; @@ -205,6 +209,8 @@ wxDialog::~wxDialog() { m_isBeingDeleted = TRUE; + delete m_eventLoop; + if (m_mainWidget) { XtRemoveEventHandler((Widget) m_mainWidget, ExposureMask, FALSE, @@ -216,6 +222,9 @@ wxDialog::~wxDialog() { XtUnmapWidget((Widget) m_mainWidget); } + + PreDestroy(); + DoDestroy(); } void wxDialog::DoDestroy() @@ -312,53 +321,24 @@ int wxDialog::ShowModal() if (m_modalShowing) return 0; - - wxModalShowingStack.Insert((wxObject *)TRUE); + m_eventLoop = new wxEventLoop; m_modalShowing = TRUE; XtAddGrab((Widget) m_mainWidget, TRUE, FALSE); - XEvent event; - - // Loop until we signal that the dialog should be closed - while ((wxModalShowingStack.Number() > 0) && ((int)(wxModalShowingStack.First()->Data()) != 0)) - { - // XtAppProcessEvent((XtAppContext) wxTheApp->GetAppContext(), XtIMAll); - - XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); - wxTheApp->ProcessXEvent((WXEvent*) &event); - - if (XtAppPending( (XtAppContext) wxTheApp->GetAppContext() ) == 0) - { - if (!wxTheApp->ProcessIdle()) - { -#if wxUSE_THREADS - // leave the main loop to give other threads a chance to - // perform their GUI work - wxMutexGuiLeave(); - wxUsleep(20); - wxMutexGuiEnter(); -#endif - } - } - } - - // Remove modal dialog flag from stack - wxNode *node = wxModalShowingStack.First(); - if (node) - delete node; + m_eventLoop->Run(); // Now process all events in case they get sent to a destroyed dialog XSync(XtDisplay((Widget) wxTheApp->GetTopLevelWidget()), FALSE); - while (XtAppPending((XtAppContext) wxTheApp->GetAppContext())) + while (m_eventLoop->Pending()) { - // MBN: is this necessary? why? - // XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); - XtAppNextEvent((XtAppContext) wxTheApp->GetAppContext(), &event); - - wxTheApp->ProcessXEvent((WXEvent*) &event); + XFlush(XtDisplay((Widget) wxTheApp->GetTopLevelWidget())); + m_eventLoop->Dispatch(); } + delete m_eventLoop; + m_eventLoop = NULL; + // TODO: is it safe to call this, if the dialog may have been deleted // by now? Probably only if we're using delayed deletion of dialogs. return GetReturnCode(); @@ -377,10 +357,7 @@ void wxDialog::EndModal(int retCode) Show(FALSE); m_modalShowing = FALSE; - - wxNode *node = wxModalShowingStack.First(); - if (node) - node->SetData((wxObject *)FALSE); + m_eventLoop->Exit(); } // Standard buttons