]> git.saurik.com Git - wxWidgets.git/commitdiff
simplifying modal event loop handling
authorStefan Csomor <csomor@advancedconcepts.ch>
Fri, 2 Apr 2010 14:52:08 +0000 (14:52 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Fri, 2 Apr 2010 14:52:08 +0000 (14:52 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63828 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/dialog.h
src/osx/carbon/dialog.cpp
src/osx/cocoa/dialog.mm
src/osx/dialog_osx.cpp

index 77427be8b4a2a05da66bdd56e07d564e340785f9..83dd07b8165000015f0314bab0b0ced6d3fb912f 100644 (file)
@@ -17,6 +17,7 @@
 WXDLLIMPEXP_DATA_CORE(extern const char) wxDialogNameStr[];
 
 class WXDLLIMPEXP_FWD_CORE wxMacToolTip ;
+class WXDLLIMPEXP_FWD_CORE wxModalEventLoop ;
 
 // Dialog boxes
 class WXDLLIMPEXP_CORE wxDialog : public wxDialogBase
@@ -71,19 +72,19 @@ public:
 #endif
 
 protected:
-    // show modal dialog and enter modal loop
-    void DoShowModal();
-    
-    // show modal dialog and enter modal loop
+    // show window modal dialog 
     void DoShowWindowModal();
 
+    // end window modal dialog.
+    void EndWindowModal();
+
     // mac also takes command-period as cancel
     virtual bool IsEscapeKey(const wxKeyEvent& event);
 
-    // needed for cleanup on the Cocoa side.
-    void EndWindowModal();
 
     wxDialogModality m_modality;
+    
+    wxModalEventLoop* m_eventLoop;
 
 private:
     void Init();
index 8b198abb76117715827708e9fae252a79f623316..20742be5e4ceea70329ef029db7ec6c29b4328cc 100644 (file)
@@ -39,39 +39,3 @@ void wxDialog::DoShowWindowModal()
     ShowModal();
     SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED  );
 }
-
-void wxDialog::DoShowModal()
-{
-
-    SetFocus() ;
-
-    WindowRef windowRef = (WindowRef) GetWXWindow();
-    WindowGroupRef windowGroup = NULL;
-    WindowGroupRef formerParentGroup = NULL;
-    bool resetGroupParent = false;
-
-    if ( GetParent() == NULL )
-    {
-        windowGroup = GetWindowGroup(windowRef) ;
-        if ( windowGroup != GetWindowGroupOfClass( kMovableModalWindowClass ) )
-        {
-            formerParentGroup = GetWindowGroupParent( windowGroup );
-            SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
-            resetGroupParent = true;
-        }
-    }
-    BeginAppModalStateForWindow(windowRef) ;
-
-#if wxUSE_CONSOLE_EVENTLOOP
-    wxEventLoopGuarantor ensureHasLoop;
-#endif
-    wxEventLoopBase * const loop = wxEventLoop::GetActive();
-    while ( IsModal() )
-        loop->Dispatch();
-
-    EndAppModalStateForWindow(windowRef) ;
-    if ( resetGroupParent )
-    {
-        SetWindowGroupParent( windowGroup , formerParentGroup );
-    }
-}
index d55449d1b517559bb9079616f5644483788c3826..51a4d7ea402bb38d2147876e2591216ed599d058 100644 (file)
@@ -45,71 +45,3 @@ void wxDialog::EndWindowModal()
     [NSApp endSheet: GetWXWindow()];
     [GetWXWindow() orderOut:GetWXWindow()];
 }
-
-void wxDialog::DoShowModal()
-{
-    // If the app hasn't started, flush the event queue
-    // If we don't do this, the Dock doesn't get the message that
-    // the app has started so will refuse to activate it.
-    NSApplication *theNSApp = [NSApplication sharedApplication];
-    if (![theNSApp isRunning])
-    {
-        wxMacAutoreleasePool pool;
-        while(NSEvent *event = [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSDefaultRunLoopMode dequeue:YES])
-        {
-            [theNSApp sendEvent:event];
-        }
-    }
-
-    SetFocus() ;
-/*
-    WindowGroupRef windowGroup;
-    WindowGroupRef formerParentGroup;
-    bool resetGroupParent = false;
-
-    if ( GetParent() == NULL )
-    {
-        windowGroup = GetWindowGroup(windowRef) ;
-        formerParentGroup = GetWindowGroupParent( windowGroup );
-        SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
-        resetGroupParent = true;
-    }
-*/
-    NSWindow* theWindow = GetWXWindow();
-
-    NSModalSession session = [NSApp beginModalSessionForWindow:theWindow];
-    while (IsModal())
-    {
-        wxMacAutoreleasePool autoreleasepool;
-        // we cannot break based on the return value, because nested
-        // alerts might set this to stopped as well, so it would be
-        // unsafe
-        [NSApp runModalSession:session];
-
-        // break if ended, perform no further idle processing
-        if (!IsModal())
-            break;
-
-        // do some idle processing
-        bool needMore = false;
-        if (wxTheApp)
-        {
-            wxTheApp->ProcessPendingEvents();
-            needMore = wxTheApp->ProcessIdle();
-        }
-        
-        if (!needMore)
-        {
-            // no more idle processing wanted - block until the next event
-            [theNSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:NO];
-        }
-    }
-    [NSApp endModalSession:session];
-
-/*
-    if ( resetGroupParent )
-    {
-        SetWindowGroupParent( windowGroup , formerParentGroup );
-    }
-*/
-}
index 1408ea0fb305cc43b64a0348e2a672897145e926..e605e95f3fa511ead9e4b5e98bfefe4a4191b3af 100644 (file)
@@ -12,6 +12,7 @@
 #include "wx/wxprec.h"
 
 #include "wx/dialog.h"
+#include "wx/evtloop.h"
 
 #ifndef WX_PRECOMP
     #include "wx/app.h"
@@ -22,7 +23,6 @@
 
 #include "wx/osx/private.h"
 
-
 // Lists to keep track of windows, so we can disable/enable them
 // for modal dialogs
 
@@ -33,6 +33,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
 void wxDialog::Init()
 {
     m_modality = wxDIALOG_MODALITY_NONE;
+    m_eventLoop = NULL;
 }
 
 bool wxDialog::Create( wxWindow *parent,
@@ -126,8 +127,13 @@ int wxDialog::ShowModal()
     
     Show();
 
-    DoShowModal();
-
+    wxModalEventLoop modalLoop(this);
+    m_eventLoop = &modalLoop;
+    
+    modalLoop.Run();
+    
+    m_eventLoop = NULL;
+    
     return GetReturnCode();
 }
 
@@ -149,6 +155,9 @@ wxDialogModality wxDialog::GetModality() const
 //     dialogs and should work for both of them
 void wxDialog::EndModal(int retCode)
 {
+    if ( m_eventLoop )
+        m_eventLoop->Exit(retCode);
+    
     SetReturnCode(retCode);
     Show(false);
 }