1 /**********************************************************************************************
3 * Filename : modalwindow.cpp
4 * Purpose : Allow a modalwindow like wxDialog but allowing menus and such.
5 * Author : John A. Mason
6 * Created : 8/27/2008 07:54:12 AM
7 * Copyright : Released under wxWidgets original license.
9 **********************************************************************************************/
11 #include "modalwindow.h"
13 IMPLEMENT_DYNAMIC_CLASS(wxModalWindow, wxFrame)
15 wxModalWindow::wxModalWindow()
20 wxModalWindow::wxModalWindow(wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style, const wxString& name)
21 : wxFrame(parent, id, title, pos, size, style, name) {
26 wxModalWindow::~wxModalWindow() {
31 void wxModalWindow::Init()
34 m_windowDisabler = NULL;
36 m_isShowingModal = false;
39 bool wxModalWindow::Show(bool show)
43 // if we had disabled other app windows, reenable them back now because
44 // if they stay disabled Windows will activate another window (one
45 // which is enabled, anyhow) and we will lose activation
46 if ( m_windowDisabler )
48 delete m_windowDisabler;
49 m_windowDisabler = NULL;
53 EndModal(wxID_CANCEL);
56 bool ret = wxFrame::Show(show);
58 //I don't think we need this. Since it is a wxFrame that we are extending,
59 // we don't need wxEVT_INIT_DIALOG firing off - that's what InitDialog does...
60 // and this would only make sense if we have a wxDialog and validators
67 bool wxModalWindow::IsModal() const {
68 return m_isShowingModal;
71 int wxModalWindow::ShowModal() {
74 wxFAIL_MSG( wxT("wxModalWindow:ShowModal called twice") );
75 return GetReturnCode();
78 // use the apps top level window as parent if none given unless explicitly
82 wxWindow *parent = wxTheApp->GetTopWindow();
83 if ( parent && parent != this )
91 m_isShowingModal = true;
93 wxASSERT_MSG( !m_windowDisabler, _T("disabling windows twice?") );
95 #if defined(__WXGTK__) || defined(__WXMGL__)
96 wxBusyCursorSuspender suspender;
97 // FIXME (FIXME_MGL) - make sure busy cursor disappears under MSW too
100 /* 20140919 Toshi Nagata */
101 #if defined(__WXMAC__)
102 /* --- OSX specific --- */
104 extern void MacRunModalForWindow(void *w); /* Defined in modalwindow_osx.mm */
105 WXWindow w = this->GetWXWindow();
106 MacRunModalForWindow(w);
110 /* --- The original code --- */
112 m_windowDisabler = new wxWindowDisabler(this);
114 m_eventLoop = new wxEventLoop;
119 /* End Toshi Nagata */
121 return GetReturnCode();
126 void wxModalWindow::EndModal(int retCode) {
128 /* 20140919 Toshi Nagata */
130 #if defined(__WXMAC__)
131 /* --- OSX specific --- */
133 extern void MacStopModal(void); /* Defined in modalwindow_osx.m */
134 SetReturnCode(retCode);
135 m_isShowingModal = false;
139 wxASSERT_MSG( m_eventLoop, _T("wxModalWindow is not modal") );
141 SetReturnCode(retCode);
145 wxFAIL_MSG( wxT("wxModalWindow:EndModal called twice") );
149 m_isShowingModal = false;
153 /* End Toshi Nagata */
159 void wxModalWindow::SetReturnCode(int retCode) {
160 m_returnCode=retCode;
164 int wxModalWindow::GetReturnCode() const {