]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dialog.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
13 #include "wx/dialog.h"
16 #include "wx/cursor.h"
19 #include "wx/evtloop.h"
21 #include "wx/scopedptr.h"
22 #include "wx/testing.h"
26 // this is defined in src/gtk/toplevel.cpp
27 extern int wxOpenModalDialogsCount
;
29 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop
)
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
40 m_modalShowing
= false;
41 m_themeEnabled
= true;
44 wxDialog::wxDialog( wxWindow
*parent
,
45 wxWindowID id
, const wxString
&title
,
46 const wxPoint
&pos
, const wxSize
&size
,
47 long style
, const wxString
&name
)
51 (void)Create( parent
, id
, title
, pos
, size
, style
, name
);
54 bool wxDialog::Create( wxWindow
*parent
,
55 wxWindowID id
, const wxString
&title
,
56 const wxPoint
&pos
, const wxSize
&size
,
57 long style
, const wxString
&name
)
59 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG
);
61 // all dialogs should have tab traversal enabled
62 style
|= wxTAB_TRAVERSAL
;
64 return wxTopLevelWindow::Create(parent
, id
, title
, pos
, size
, style
, name
);
67 bool wxDialog::Show( bool show
)
69 if (!show
&& IsModal())
71 EndModal( wxID_CANCEL
);
74 if (show
&& CanDoLayoutAdaptation())
77 bool ret
= wxDialogBase::Show(show
);
87 // if the dialog is modal, this will end its event loop
89 EndModal(wxID_CANCEL
);
92 bool wxDialog::IsModal() const
94 return m_modalShowing
;
97 void wxDialog::SetModal( bool WXUNUSED(flag
) )
99 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
102 int wxDialog::ShowModal()
104 WX_TESTING_SHOW_MODAL_HOOK();
106 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
108 // release the mouse if it's currently captured as the window having it
109 // will be disabled when this dialog is shown -- but will still keep the
110 // capture making it impossible to do anything in the modal dialog itself
111 wxWindow
* const win
= wxWindow::GetCapture();
113 win
->GTKReleaseMouseAndNotify();
115 wxWindow
* const parent
= GetParentForModalDialog();
118 gtk_window_set_transient_for( GTK_WINDOW(m_widget
),
119 GTK_WINDOW(parent
->m_widget
) );
122 wxBusyCursorSuspender cs
; // temporarily suppress the busy cursor
126 m_modalShowing
= true;
128 wxOpenModalDialogsCount
++;
130 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
131 gtk_window_set_modal(GTK_WINDOW(m_widget
), TRUE
);
133 // Run modal dialog event loop.
135 wxGUIEventLoopTiedPtr
modal(&m_modalLoop
, new wxGUIEventLoop());
139 gtk_window_set_modal(GTK_WINDOW(m_widget
), FALSE
);
141 wxOpenModalDialogsCount
--;
143 return GetReturnCode();
146 void wxDialog::EndModal( int retCode
)
148 SetReturnCode( retCode
);
152 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
156 m_modalShowing
= false;
158 // Ensure Exit() is only called once. The dialog's event loop may be terminated
159 // externally due to an uncaught exception.
160 if (m_modalLoop
&& m_modalLoop
->IsRunning())