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[];
|
WXDLLIMPEXP_DATA_CORE(extern const char) wxDialogNameStr[];
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxMacToolTip ;
|
class WXDLLIMPEXP_FWD_CORE wxMacToolTip ;
|
||||||
|
class WXDLLIMPEXP_FWD_CORE wxModalEventLoop ;
|
||||||
|
|
||||||
// Dialog boxes
|
// Dialog boxes
|
||||||
class WXDLLIMPEXP_CORE wxDialog : public wxDialogBase
|
class WXDLLIMPEXP_CORE wxDialog : public wxDialogBase
|
||||||
@@ -71,20 +72,20 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// show modal dialog and enter modal loop
|
// show window modal dialog
|
||||||
void DoShowModal();
|
|
||||||
|
|
||||||
// show modal dialog and enter modal loop
|
|
||||||
void DoShowWindowModal();
|
void DoShowWindowModal();
|
||||||
|
|
||||||
|
// end window modal dialog.
|
||||||
|
void EndWindowModal();
|
||||||
|
|
||||||
// mac also takes command-period as cancel
|
// mac also takes command-period as cancel
|
||||||
virtual bool IsEscapeKey(const wxKeyEvent& event);
|
virtual bool IsEscapeKey(const wxKeyEvent& event);
|
||||||
|
|
||||||
// needed for cleanup on the Cocoa side.
|
|
||||||
void EndWindowModal();
|
|
||||||
|
|
||||||
wxDialogModality m_modality;
|
wxDialogModality m_modality;
|
||||||
|
|
||||||
|
wxModalEventLoop* m_eventLoop;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init();
|
void Init();
|
||||||
};
|
};
|
||||||
|
@@ -39,39 +39,3 @@ void wxDialog::DoShowWindowModal()
|
|||||||
ShowModal();
|
ShowModal();
|
||||||
SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
|
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()];
|
[NSApp endSheet: GetWXWindow()];
|
||||||
[GetWXWindow() orderOut: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/wxprec.h"
|
||||||
|
|
||||||
#include "wx/dialog.h"
|
#include "wx/dialog.h"
|
||||||
|
#include "wx/evtloop.h"
|
||||||
|
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
@@ -22,7 +23,6 @@
|
|||||||
|
|
||||||
#include "wx/osx/private.h"
|
#include "wx/osx/private.h"
|
||||||
|
|
||||||
|
|
||||||
// Lists to keep track of windows, so we can disable/enable them
|
// Lists to keep track of windows, so we can disable/enable them
|
||||||
// for modal dialogs
|
// for modal dialogs
|
||||||
|
|
||||||
@@ -33,6 +33,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
|
|||||||
void wxDialog::Init()
|
void wxDialog::Init()
|
||||||
{
|
{
|
||||||
m_modality = wxDIALOG_MODALITY_NONE;
|
m_modality = wxDIALOG_MODALITY_NONE;
|
||||||
|
m_eventLoop = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxDialog::Create( wxWindow *parent,
|
bool wxDialog::Create( wxWindow *parent,
|
||||||
@@ -126,7 +127,12 @@ int wxDialog::ShowModal()
|
|||||||
|
|
||||||
Show();
|
Show();
|
||||||
|
|
||||||
DoShowModal();
|
wxModalEventLoop modalLoop(this);
|
||||||
|
m_eventLoop = &modalLoop;
|
||||||
|
|
||||||
|
modalLoop.Run();
|
||||||
|
|
||||||
|
m_eventLoop = NULL;
|
||||||
|
|
||||||
return GetReturnCode();
|
return GetReturnCode();
|
||||||
}
|
}
|
||||||
@@ -149,6 +155,9 @@ wxDialogModality wxDialog::GetModality() const
|
|||||||
// dialogs and should work for both of them
|
// dialogs and should work for both of them
|
||||||
void wxDialog::EndModal(int retCode)
|
void wxDialog::EndModal(int retCode)
|
||||||
{
|
{
|
||||||
|
if ( m_eventLoop )
|
||||||
|
m_eventLoop->Exit(retCode);
|
||||||
|
|
||||||
SetReturnCode(retCode);
|
SetReturnCode(retCode);
|
||||||
Show(false);
|
Show(false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user