]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/dialog.cpp
use wxEvent::ShouldPropagate() instead of its own propgation control mechanism in...
[wxWidgets.git] / src / os2 / dialog.cpp
index edc04a0d243b4f1b784df71baa9cd0e4683af43e..ff6cf0344b9e176a61fb680bd8c79a677cc43cec 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "wx/os2/private.h"
 #include "wx/log.h"
 
 #include "wx/os2/private.h"
 #include "wx/log.h"
+#include "wx/evtloop.h"
+#include "wx/ptr_scpd.h"
 
 #define wxDIALOG_DEFAULT_X 300
 #define wxDIALOG_DEFAULT_Y 300
 
 #define wxDIALOG_DEFAULT_X 300
 #define wxDIALOG_DEFAULT_Y 300
@@ -44,6 +46,41 @@ BEGIN_EVENT_TABLE(wxDialog, wxDialogBase)
     EVT_CLOSE(wxDialog::OnCloseWindow)
 END_EVENT_TABLE()
 
     EVT_CLOSE(wxDialog::OnCloseWindow)
 END_EVENT_TABLE()
 
+// ----------------------------------------------------------------------------
+// wxDialogModalData
+// ----------------------------------------------------------------------------
+
+// this is simply a container for any data we need to implement modality which
+// allows us to avoid changing wxDialog each time the implementation changes
+class wxDialogModalData
+{
+public:
+    wxDialogModalData(wxDialog *dialog) : m_evtLoop(dialog) { }
+
+    void RunLoop()
+    {
+        m_evtLoop.Run();
+    }
+
+    void ExitLoop()
+    {
+        m_evtLoop.Exit();
+    }
+
+private:
+    wxModalEventLoop m_evtLoop;
+};
+
+wxDEFINE_TIED_SCOPED_PTR_TYPE(wxDialogModalData);
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxDialog construction
+// ----------------------------------------------------------------------------
+
 void wxDialog::Init()
 {
     m_pOldFocus = (wxWindow *)NULL;
 void wxDialog::Init()
 {
     m_pOldFocus = (wxWindow *)NULL;
@@ -200,26 +237,31 @@ void wxDialog::DoShowModal()
     //
     wxASSERT_MSG(!m_pWindowDisabler, _T("disabling windows twice?"));
 
     //
     wxASSERT_MSG(!m_pWindowDisabler, _T("disabling windows twice?"));
 
-    m_pWindowDisabler = new wxWindowDisabler(this);
+    //
+    // Disables other app windows and window proc message processing
+    // until WinDismissDlg called
+    //
+    ::WinProcessDlg((HWND)GetHwnd());
 
     //
 
     //
-    // Enter the modal loop
+    // Before entering the modal loop, reset the "is in OnIdle()" flag (see
+    // comment in app.cpp)
     //
     //
-    while ( IsModalShowing() )
-    {
-#if wxUSE_THREADS
-        wxMutexGuiLeaveOrEnter();
-#endif // wxUSE_THREADS
+    extern bool                     gbInOnIdle;
+    bool                            bWasInOnIdle = gbInOnIdle;
 
 
-        while ( !wxTheApp->Pending() && wxTheApp->ProcessIdle() )
-            ;
+    gbInOnIdle = FALSE;
 
 
-        // a message came or no more idle processing to do
-        wxTheApp->DoMessage();
+    // enter the modal loop
+    {
+        wxDialogModalDataTiedPtr modalData(&m_modalData,
+                                           new wxDialogModalData(this));
+        modalData->RunLoop();
     }
     }
+    gbInOnIdle = bWasInOnIdle;
 
     //
 
     //
-    // Snd restore focus
+    // and restore focus
     // Note that this code MUST NOT access the dialog object's data
     // in case the object has been deleted (which will be the case
     // for a modal dialog that has been destroyed before calling EndModal).
     // Note that this code MUST NOT access the dialog object's data
     // in case the object has been deleted (which will be the case
     // for a modal dialog that has been destroyed before calling EndModal).
@@ -243,7 +285,8 @@ bool wxDialog::Show(
         //
         // If we had disabled other app windows, reenable them back now because
         // if they stay disabled Windows will activate another window (one
         //
         // If we had disabled other app windows, reenable them back now because
         // if they stay disabled Windows will activate another window (one
-        // which is enabled, anyhow) and we will lose activation
+        // which is enabled, anyhow) and we will lose activation.  We really don't
+        // do this in OS/2 since PM does this for us.
         //
         if (m_pWindowDisabler)
         {
         //
         if (m_pWindowDisabler)
         {
@@ -326,6 +369,7 @@ void wxDialog::EndModal(
 {
     SetReturnCode(nRetCode);
     Show(FALSE);
 {
     SetReturnCode(nRetCode);
     Show(FALSE);
+    ::WinDismissDlg((HWND)GetHwnd(), nRetCode);
 } // end of wxDialog::EndModal
 
 // ----------------------------------------------------------------------------
 } // end of wxDialog::EndModal
 
 // ----------------------------------------------------------------------------