simplifying modal event loop handling
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63828 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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,20 +72,20 @@ 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();
|
||||
};
|
||||
|
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
@@ -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 );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -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,7 +127,12 @@ 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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user