From: Stefan Csomor Date: Tue, 20 Apr 2010 19:09:38 +0000 (+0000) Subject: tracking open modal dialogs X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/445e564f120fb194a554ef70a6f2187b7ce693ed tracking open modal dialogs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/dialog.h b/include/wx/osx/dialog.h index 83dd07b816..9442b94373 100644 --- a/include/wx/osx/dialog.h +++ b/include/wx/osx/dialog.h @@ -61,6 +61,10 @@ public: // may be called to terminate the dialog with the given return code virtual void EndModal(int retCode); + + static bool OSXHasModalDialogsOpen(); + static void OSXBeginModalDialog(); + static void OSXEndModalDialog(); // implementation // -------------- diff --git a/src/osx/carbon/colordlg.cpp b/src/osx/carbon/colordlg.cpp index 6ec1b9e15a..c62b2ae5e4 100644 --- a/src/osx/carbon/colordlg.cpp +++ b/src/osx/carbon/colordlg.cpp @@ -59,7 +59,9 @@ int wxColourDialog::ShowModal() info.theColor.color.rgb.red = currentColor.red ; info.theColor.color.rgb.green = currentColor.green ; info.theColor.color.rgb.blue = currentColor.blue ; + wxDialog::OSXBeginModalDialog(); err = NPickColor(&info); + wxDialog::OSXEndModalDialog(); if ((err == noErr) && info.newColorChosen) { currentColor.red = info.theColor.color.rgb.red ; diff --git a/src/osx/carbon/colordlgosx.mm b/src/osx/carbon/colordlgosx.mm index 067e5b413c..0f75e74eef 100644 --- a/src/osx/carbon/colordlgosx.mm +++ b/src/osx/carbon/colordlgosx.mm @@ -141,6 +141,7 @@ int wxColourDialog::ShowModal() // // Start the color panel modal loop // + wxDialog::OSXBeginModalDialog(); NSModalSession session = [NSApp beginModalSessionForWindow:theColorPanel]; for (;;) { @@ -151,6 +152,7 @@ int wxColourDialog::ShowModal() break; } [NSApp endModalSession:session]; + wxDialog::OSXEndModalDialog(); //free up the memory for the delegates - we don't need them anymore [theColorPanel setDelegate:nil]; diff --git a/src/osx/carbon/dirdlg.cpp b/src/osx/carbon/dirdlg.cpp index c653e17e20..c8a97726f1 100644 --- a/src/osx/carbon/dirdlg.cpp +++ b/src/osx/carbon/dirdlg.cpp @@ -88,7 +88,9 @@ int wxDirDialog::ShowModal() err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog); if (err == noErr) { + wxDialog::OSXBeginModalDialog(); err = NavDialogRun(dialog); + wxDialog::OSXEndModalDialog(); if ( err == noErr ) { err = NavDialogGetReply(dialog, &reply); diff --git a/src/osx/carbon/filedlg.cpp b/src/osx/carbon/filedlg.cpp index 4fb787eacf..158846b529 100644 --- a/src/osx/carbon/filedlg.cpp +++ b/src/osx/carbon/filedlg.cpp @@ -541,7 +541,11 @@ int wxFileDialog::ShowModal() SetupExtraControls(NavDialogGetWindow(dialog)); if (err == noErr) + { + wxDialog::OSXBeginModalDialog(); err = ::NavDialogRun(dialog); + wxDialog::OSXEndModalDialog(); + } // clean up filter related data, etc. if (navFilterUPP) diff --git a/src/osx/carbon/fontdlg.cpp b/src/osx/carbon/fontdlg.cpp index 1e83fe0ee2..cf0aed1759 100644 --- a/src/osx/carbon/fontdlg.cpp +++ b/src/osx/carbon/fontdlg.cpp @@ -257,8 +257,9 @@ int wxFontDialog::ShowModal() if ( !FPIsFontPanelVisible() ) FPShowHideFontPanel(); #endif + wxDialog::OSXBeginModalDialog(); int retval = RunMixedFontDialog(this); - + wxDialog::OSXEndModalDialog(); #if wxOSX_USE_CARBON ::RemoveEventHandler(handler); #endif diff --git a/src/osx/carbon/fontdlgosx.mm b/src/osx/carbon/fontdlgosx.mm index bb8f35642a..a83b7d5e02 100644 --- a/src/osx/carbon/fontdlgosx.mm +++ b/src/osx/carbon/fontdlgosx.mm @@ -453,6 +453,7 @@ int wxFontDialog::ShowModal() // the color panel until the color panel closes, switching // back to the font panel modal loop once it does close. // + wxDialog::OSXBeginModalDialog(); do { // @@ -491,7 +492,8 @@ int wxFontDialog::ShowModal() //out of its modal loop because the color panel was //opened) return the font panel modal loop }while([theFPDelegate isClosed] == NO); - + wxDialog::OSXEndModalDialog(); + //free up the memory for the delegates - we don't need them anymore [theFPDelegate release]; [theCPDelegate release]; diff --git a/src/osx/carbon/msgdlg.cpp b/src/osx/carbon/msgdlg.cpp index a95138112e..bc410c3c03 100644 --- a/src/osx/carbon/msgdlg.cpp +++ b/src/osx/carbon/msgdlg.cpp @@ -216,7 +216,9 @@ int wxMessageDialog::ShowModal() { DialogRef alertRef; CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); + wxDialog::OSXBeginModalDialog(); RunStandardAlert( alertRef, NULL, &result ); + wxDialog::OSXEndModalDialog(); } else { diff --git a/src/osx/carbon/printdlg.cpp b/src/osx/carbon/printdlg.cpp index fae5551255..3f36361060 100644 --- a/src/osx/carbon/printdlg.cpp +++ b/src/osx/carbon/printdlg.cpp @@ -39,8 +39,10 @@ int wxMacPrintDialog::ShowModal() OSErr err = noErr; Boolean accepted; wxOSXPrintData* nativeData = (wxOSXPrintData*)m_printDialogData.GetPrintData().GetNativeData(); + wxDialog::OSXBeginModalDialog(); err = PMSessionPrintDialog(nativeData->GetPrintSession(), nativeData->GetPrintSettings(), nativeData->GetPageFormat(), &accepted ); + wxDialog::OSXEndModalDialog(); if ((err == noErr) && !accepted) { @@ -80,8 +82,10 @@ int wxMacPageSetupDialog::ShowModal() OSErr err = noErr; Boolean accepted; + wxDialog::OSXBeginModalDialog(); err = PMSessionPageSetupDialog( nativeData->GetPrintSession(), nativeData->GetPageFormat(), &accepted ); + wxDialog::OSXEndModalDialog(); if ((err == noErr) && !accepted) { diff --git a/src/osx/dialog_osx.cpp b/src/osx/dialog_osx.cpp index e605e95f3f..b1b50b980a 100644 --- a/src/osx/dialog_osx.cpp +++ b/src/osx/dialog_osx.cpp @@ -23,10 +23,23 @@ #include "wx/osx/private.h" -// Lists to keep track of windows, so we can disable/enable them -// for modal dialogs +static int s_openDialogs = 0; +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) @@ -130,7 +143,9 @@ int wxDialog::ShowModal() wxModalEventLoop modalLoop(this); m_eventLoop = &modalLoop; + wxDialog::OSXBeginModalDialog(); modalLoop.Run(); + wxDialog::OSXEndModalDialog(); m_eventLoop = NULL;