// virtual bool Destroy();
virtual bool Show(bool show = true);
- void SetModal(bool flag);
+ // return true if we're showing the dialog modally
virtual bool IsModal() const;
- // For now, same as Show(TRUE) but returns return code
+ // show the dialog modally and return the value passed to EndModal()
virtual int ShowModal();
virtual void ShowWindowModal();
// implementation
// --------------
+ wxDialogModality GetModality() const;
+
+protected:
// show modal dialog and enter modal loop
void DoShowModal();
+
+ // show modal dialog and enter modal loop
+ void DoShowWindowModal();
-protected:
// mac also takes command-period as cancel
virtual bool IsEscapeKey(const wxKeyEvent& event);
private:
void Init();
- bool m_isModalStyle;
+ wxDialogModality m_modality;
};
#endif
#include "wx/osx/private.h"
#include "wx/evtloop.h"
-extern wxList wxModalDialogs;
-
void wxDialog::EndWindowModal()
{
// Nothing to do for now.
}
-void wxDialog::ShowWindowModal()
+void wxDialog::DoShowWindowModal()
{
// If someone wants to add support for this to wxOSX Carbon, here would
// be the place to start: http://trac.wxwidgets.org/ticket/9459
void wxDialog::DoShowModal()
{
- wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
-
- wxModalDialogs.Append(this);
SetFocus() ;
extern wxList wxModalDialogs;
-void wxDialog::ShowWindowModal()
+void wxDialog::DoShowWindowModal()
{
wxTopLevelWindow* parent = static_cast<wxTopLevelWindow*>(wxGetTopLevelParent(GetParent()));
NSWindow* parentWindow = parent->GetWXWindow();
NSWindow* theWindow = GetWXWindow();
-
- wxWindow::Show(true);
[NSApp beginSheet: theWindow
modalForWindow: parentWindow
void wxDialog::DoShowModal()
{
- wxCHECK_RET( !IsModal(), wxT("DoShowModal() called twice") );
-
// 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.
}
}
- wxModalDialogs.Append(this);
-
SetFocus() ;
/*
WindowGroupRef windowGroup;
void wxDialog::Init()
{
- m_isModalStyle = false;
+ m_modality = wxDIALOG_MODALITY_NONE;
}
bool wxDialog::Create( wxWindow *parent,
return true;
}
-void wxDialog::SetModal( bool flag )
-{
- if ( flag )
- {
- m_isModalStyle = true;
- }
- else
- {
- m_isModalStyle = false;
- }
-}
-
wxDialog::~wxDialog()
{
SendDestroyEvent();
bool wxDialog::IsModal() const
{
- return wxModalDialogs.Find((wxDialog *)this) != NULL; // const_cast
- // return m_isModalStyle;
+ return m_modality != wxDIALOG_MODALITY_NONE;
}
-
bool wxDialog::Show(bool show)
{
- if ( !wxDialogBase::Show(show) )
- // nothing to do
- return false;
+ if ( m_modality == wxDIALOG_MODALITY_WINDOW_MODAL )
+ {
+ if ( !wxWindow::Show(show) )
+ // nothing to do
+ return false;
+ }
+ else
+ {
+ if ( !wxDialogBase::Show(show) )
+ // nothing to do
+ return false;
+ }
if (show && CanDoLayoutAdaptation())
DoLayoutAdaptation();
// usually will result in TransferDataToWindow() being called
InitDialog();
- if ( m_isModalStyle )
+ if ( !show )
{
- if ( show )
- {
- DoShowModal();
- }
- else // end of modal dialog
+ switch( m_modality )
{
- // this will cause IsModalShowing() return false and our local
- // message loop will terminate
- wxModalDialogs.DeleteObject(this);
+ case wxDIALOG_MODALITY_WINDOW_MODAL:
+ EndWindowModal(); // OS X implementation method for cleanup
+ SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
+ break;
+ default:
+ break;
}
+ m_modality = wxDIALOG_MODALITY_NONE;
}
-
+
return true;
}
// Replacement for Show(true) for modal dialogs - returns return code
int wxDialog::ShowModal()
{
- if ( !m_isModalStyle )
- SetModal(true);
+ m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+
+ Show();
- if ( IsShown() )
- DoShowModal();
- else
- Show(true);
+ DoShowModal();
return GetReturnCode();
}
+void wxDialog::ShowWindowModal()
+{
+ m_modality = wxDIALOG_MODALITY_WINDOW_MODAL;
+
+ Show();
+
+ DoShowWindowModal();
+}
+
+wxDialogModality wxDialog::GetModality() const
+{
+ return m_modality;
+}
+
// NB: this function (surprisingly) 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);
- if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
- {
- EndWindowModal(); // OS X implementation method for cleanup
- SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
- }
}