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
#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();
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 );
- }
-}
[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 );
- }
-*/
-}
#include "wx/wxprec.h"
#include "wx/dialog.h"
+#include "wx/evtloop.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/osx/private.h"
-
// Lists to keep track of windows, so we can disable/enable them
// for modal dialogs
void wxDialog::Init()
{
m_modality = wxDIALOG_MODALITY_NONE;
+ m_eventLoop = NULL;
}
bool wxDialog::Create( wxWindow *parent,
Show();
- DoShowModal();
-
+ wxModalEventLoop modalLoop(this);
+ m_eventLoop = &modalLoop;
+
+ modalLoop.Run();
+
+ m_eventLoop = NULL;
+
return GetReturnCode();
}
// dialogs and should work for both of them
void wxDialog::EndModal(int retCode)
{
+ if ( m_eventLoop )
+ m_eventLoop->Exit(retCode);
+
SetReturnCode(retCode);
Show(false);
}