-
-void wxDialog::SetModal( bool flag )
-{
- if ( flag )
- {
- m_isModalStyle = true;
-
- SetWindowModality( (WindowRef)MacGetWindowRef(), kWindowModalityAppModal, NULL ) ;
- }
- else
- {
- m_isModalStyle = false;
- }
-}
-
-wxDialog::~wxDialog()
-{
- m_isBeingDeleted = true;
-
- // if the dialog is modal, this will end its event loop
- Show(false);
-}
-
-// On mac command-stop does the same thing as Esc, let the base class know
-// about it
-bool wxDialog::IsEscapeKey(const wxKeyEvent& event)
-{
- if ( event.GetKeyCode() == '.' && event.GetModifiers() == wxMOD_CMD )
- return true;
-
- return wxDialogBase::IsEscapeKey(event);
-}
-
-bool wxDialog::IsModal() const
-{
- return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
- // return m_isModalStyle;
-}
-
-
-bool wxDialog::Show(bool show)
-{
- if ( !wxDialogBase::Show(show) )
- // nothing to do
- return false;
-
- if (show && CanDoLayoutAdaptation())
- DoLayoutAdaptation();
-
- if ( show )
- // usually will result in TransferDataToWindow() being called
- InitDialog();
-
- HiliteMenu(0);
-
- if ( m_isModalStyle )
- {
- if ( show )
- {
- DoShowModal();
- }
- else // end of modal dialog
- {
- // this will cause IsModalShowing() return false and our local
- // message loop will terminate
- wxModalDialogs.DeleteObject(this);
- }
- }
-
- return true;
-}
-
-void wxDialog::DoShowModal()
-{
- wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
-
- wxModalDialogs.Append(this);
-
- SetFocus() ;
-
- WindowRef windowRef = (WindowRef) MacGetWindowRef();
- WindowGroupRef windowGroup;
- WindowGroupRef formerParentGroup;
- bool resetGroupParent = false;
-
- if ( GetParent() == NULL )
- {
- windowGroup = GetWindowGroup(windowRef) ;
- formerParentGroup = GetWindowGroupParent( windowGroup );
- SetWindowGroupParent( windowGroup, GetWindowGroupOfClass( kMovableModalWindowClass ) );
- resetGroupParent = true;
- }
- BeginAppModalStateForWindow(windowRef) ;
-
- while ( IsModal() )
- {
- wxTheApp->MacDoOneEvent() ;
- // calls process idle itself
- }
-
- EndAppModalStateForWindow(windowRef) ;
- if ( resetGroupParent )
- {
- SetWindowGroupParent( windowGroup , formerParentGroup );
- }
-}
-
-
-// Replacement for Show(true) for modal dialogs - returns return code
-int wxDialog::ShowModal()
-{
- if ( !m_isModalStyle )
- SetModal(true);
-
- Show(true);
-
- return GetReturnCode();
-}
-
-// NB: this function (surprizingly) may be called for both modal and modeless
-// dialogs and should work for both of them
-void wxDialog::EndModal(int retCode)
-{
- SetReturnCode(retCode);
- Show(false);
- SetModal(false);
-}
-