tracking open modal dialogs

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2010-04-20 19:09:38 +00:00
parent bd23338782
commit 445e564f12
10 changed files with 43 additions and 5 deletions

View File

@@ -62,6 +62,10 @@ public:
// may be called to terminate the dialog with the given return code // may be called to terminate the dialog with the given return code
virtual void EndModal(int retCode); virtual void EndModal(int retCode);
static bool OSXHasModalDialogsOpen();
static void OSXBeginModalDialog();
static void OSXEndModalDialog();
// implementation // implementation
// -------------- // --------------

View File

@@ -59,7 +59,9 @@ int wxColourDialog::ShowModal()
info.theColor.color.rgb.red = currentColor.red ; info.theColor.color.rgb.red = currentColor.red ;
info.theColor.color.rgb.green = currentColor.green ; info.theColor.color.rgb.green = currentColor.green ;
info.theColor.color.rgb.blue = currentColor.blue ; info.theColor.color.rgb.blue = currentColor.blue ;
wxDialog::OSXBeginModalDialog();
err = NPickColor(&info); err = NPickColor(&info);
wxDialog::OSXEndModalDialog();
if ((err == noErr) && info.newColorChosen) if ((err == noErr) && info.newColorChosen)
{ {
currentColor.red = info.theColor.color.rgb.red ; currentColor.red = info.theColor.color.rgb.red ;

View File

@@ -141,6 +141,7 @@ int wxColourDialog::ShowModal()
// //
// Start the color panel modal loop // Start the color panel modal loop
// //
wxDialog::OSXBeginModalDialog();
NSModalSession session = [NSApp beginModalSessionForWindow:theColorPanel]; NSModalSession session = [NSApp beginModalSessionForWindow:theColorPanel];
for (;;) for (;;)
{ {
@@ -151,6 +152,7 @@ int wxColourDialog::ShowModal()
break; break;
} }
[NSApp endModalSession:session]; [NSApp endModalSession:session];
wxDialog::OSXEndModalDialog();
//free up the memory for the delegates - we don't need them anymore //free up the memory for the delegates - we don't need them anymore
[theColorPanel setDelegate:nil]; [theColorPanel setDelegate:nil];

View File

@@ -88,7 +88,9 @@ int wxDirDialog::ShowModal()
err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog); err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
if (err == noErr) if (err == noErr)
{ {
wxDialog::OSXBeginModalDialog();
err = NavDialogRun(dialog); err = NavDialogRun(dialog);
wxDialog::OSXEndModalDialog();
if ( err == noErr ) if ( err == noErr )
{ {
err = NavDialogGetReply(dialog, &reply); err = NavDialogGetReply(dialog, &reply);

View File

@@ -541,7 +541,11 @@ int wxFileDialog::ShowModal()
SetupExtraControls(NavDialogGetWindow(dialog)); SetupExtraControls(NavDialogGetWindow(dialog));
if (err == noErr) if (err == noErr)
{
wxDialog::OSXBeginModalDialog();
err = ::NavDialogRun(dialog); err = ::NavDialogRun(dialog);
wxDialog::OSXEndModalDialog();
}
// clean up filter related data, etc. // clean up filter related data, etc.
if (navFilterUPP) if (navFilterUPP)

View File

@@ -257,8 +257,9 @@ int wxFontDialog::ShowModal()
if ( !FPIsFontPanelVisible() ) if ( !FPIsFontPanelVisible() )
FPShowHideFontPanel(); FPShowHideFontPanel();
#endif #endif
wxDialog::OSXBeginModalDialog();
int retval = RunMixedFontDialog(this); int retval = RunMixedFontDialog(this);
wxDialog::OSXEndModalDialog();
#if wxOSX_USE_CARBON #if wxOSX_USE_CARBON
::RemoveEventHandler(handler); ::RemoveEventHandler(handler);
#endif #endif

View File

@@ -453,6 +453,7 @@ int wxFontDialog::ShowModal()
// the color panel until the color panel closes, switching // the color panel until the color panel closes, switching
// back to the font panel modal loop once it does close. // back to the font panel modal loop once it does close.
// //
wxDialog::OSXBeginModalDialog();
do do
{ {
// //
@@ -491,6 +492,7 @@ int wxFontDialog::ShowModal()
//out of its modal loop because the color panel was //out of its modal loop because the color panel was
//opened) return the font panel modal loop //opened) return the font panel modal loop
}while([theFPDelegate isClosed] == NO); }while([theFPDelegate isClosed] == NO);
wxDialog::OSXEndModalDialog();
//free up the memory for the delegates - we don't need them anymore //free up the memory for the delegates - we don't need them anymore
[theFPDelegate release]; [theFPDelegate release];

View File

@@ -216,7 +216,9 @@ int wxMessageDialog::ShowModal()
{ {
DialogRef alertRef; DialogRef alertRef;
CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef ); CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
wxDialog::OSXBeginModalDialog();
RunStandardAlert( alertRef, NULL, &result ); RunStandardAlert( alertRef, NULL, &result );
wxDialog::OSXEndModalDialog();
} }
else else
{ {

View File

@@ -39,8 +39,10 @@ int wxMacPrintDialog::ShowModal()
OSErr err = noErr; OSErr err = noErr;
Boolean accepted; Boolean accepted;
wxOSXPrintData* nativeData = (wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData(); wxOSXPrintData* nativeData = (wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData();
wxDialog::OSXBeginModalDialog();
err = PMSessionPrintDialog(nativeData->GetPrintSession(), nativeData->GetPrintSettings(), err = PMSessionPrintDialog(nativeData->GetPrintSession(), nativeData->GetPrintSettings(),
nativeData->GetPageFormat(), &accepted ); nativeData->GetPageFormat(), &accepted );
wxDialog::OSXEndModalDialog();
if ((err == noErr) && !accepted) if ((err == noErr) && !accepted)
{ {
@@ -80,8 +82,10 @@ int wxMacPageSetupDialog::ShowModal()
OSErr err = noErr; OSErr err = noErr;
Boolean accepted; Boolean accepted;
wxDialog::OSXBeginModalDialog();
err = PMSessionPageSetupDialog( nativeData->GetPrintSession(), nativeData->GetPageFormat(), err = PMSessionPageSetupDialog( nativeData->GetPrintSession(), nativeData->GetPageFormat(),
&accepted ); &accepted );
wxDialog::OSXEndModalDialog();
if ((err == noErr) && !accepted) if ((err == noErr) && !accepted)
{ {

View File

@@ -23,10 +23,23 @@
#include "wx/osx/private.h" #include "wx/osx/private.h"
// Lists to keep track of windows, so we can disable/enable them static int s_openDialogs = 0;
// for modal dialogs bool wxDialog::OSXHasModalDialogsOpen()
{
return s_openDialogs > 0;
}
void wxDialog::OSXBeginModalDialog()
{
s_openDialogs++;
}
void wxDialog::OSXEndModalDialog()
{
wxASSERT_MSG( s_openDialogs > 0, "incorrect internal modal dialog count");
s_openDialogs--;
}
wxList wxModalDialogs;
IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow)
@@ -130,7 +143,9 @@ int wxDialog::ShowModal()
wxModalEventLoop modalLoop(this); wxModalEventLoop modalLoop(this);
m_eventLoop = &modalLoop; m_eventLoop = &modalLoop;
wxDialog::OSXBeginModalDialog();
modalLoop.Run(); modalLoop.Run();
wxDialog::OSXEndModalDialog();
m_eventLoop = NULL; m_eventLoop = NULL;