]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/gtk/dialog.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
14f355c2 VS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
c801d85f | 13 | #include "wx/dialog.h" |
670f9935 WS |
14 | |
15 | #ifndef WX_PRECOMP | |
c8326d64 | 16 | #include "wx/cursor.h" |
670f9935 WS |
17 | #endif // WX_PRECOMP |
18 | ||
924b84ab | 19 | #include "wx/evtloop.h" |
83624f79 | 20 | |
664e1314 | 21 | #include "wx/scopedptr.h" |
643e9cf9 | 22 | #include "wx/testing.h" |
bfafa628 | 23 | |
071a2d78 | 24 | #include <gtk/gtk.h> |
5e014a0c | 25 | |
64c11164 VZ |
26 | // this is defined in src/gtk/toplevel.cpp |
27 | extern int wxOpenModalDialogsCount; | |
acfd422a | 28 | |
5c69ef61 | 29 | wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop) |
bfafa628 VZ |
30 | |
31 | ||
c801d85f KB |
32 | //----------------------------------------------------------------------------- |
33 | // wxDialog | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
68995f26 | 36 | void wxDialog::Init() |
c801d85f | 37 | { |
bfafa628 | 38 | m_modalLoop = NULL; |
f03fc89f | 39 | m_returnCode = 0; |
91af0895 WS |
40 | m_modalShowing = false; |
41 | m_themeEnabled = true; | |
c33c4050 | 42 | } |
c801d85f | 43 | |
2b854a32 | 44 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 45 | wxWindowID id, const wxString &title, |
2b854a32 | 46 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 47 | long style, const wxString &name ) |
c801d85f | 48 | { |
68995f26 VZ |
49 | Init(); |
50 | ||
82c9f85c | 51 | (void)Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 52 | } |
c801d85f KB |
53 | |
54 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 55 | wxWindowID id, const wxString &title, |
2b854a32 | 56 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 57 | long style, const wxString &name ) |
c801d85f | 58 | { |
21f4383a | 59 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
2b854a32 | 60 | |
82c9f85c VZ |
61 | // all dialogs should have tab traversal enabled |
62 | style |= wxTAB_TRAVERSAL; | |
63 | ||
7d9f12f3 | 64 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); |
c33c4050 | 65 | } |
c801d85f | 66 | |
debe6624 | 67 | bool wxDialog::Show( bool show ) |
c801d85f | 68 | { |
fb1585ae RR |
69 | if (!show && IsModal()) |
70 | { | |
de8113d9 | 71 | EndModal( wxID_CANCEL ); |
fb1585ae | 72 | } |
c801d85f | 73 | |
3aa8e4ea JS |
74 | if (show && CanDoLayoutAdaptation()) |
75 | DoLayoutAdaptation(); | |
76 | ||
8fb09a08 | 77 | bool ret = wxDialogBase::Show(show); |
e146b8c8 | 78 | |
a9efc294 VS |
79 | if (show) |
80 | InitDialog(); | |
2b854a32 | 81 | |
739730ca | 82 | return ret; |
c33c4050 RR |
83 | } |
84 | ||
a9efc294 VS |
85 | wxDialog::~wxDialog() |
86 | { | |
a9efc294 | 87 | // if the dialog is modal, this will end its event loop |
0af07cc2 VS |
88 | if ( IsModal() ) |
89 | EndModal(wxID_CANCEL); | |
a9efc294 VS |
90 | } |
91 | ||
43a18898 | 92 | bool wxDialog::IsModal() const |
e1e955e1 | 93 | { |
fb1585ae | 94 | return m_modalShowing; |
e1e955e1 RR |
95 | } |
96 | ||
97 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 98 | { |
223d09f6 | 99 | wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); |
c33c4050 | 100 | } |
c801d85f | 101 | |
43a18898 | 102 | int wxDialog::ShowModal() |
c801d85f | 103 | { |
643e9cf9 VS |
104 | WX_TESTING_SHOW_MODAL_HOOK(); |
105 | ||
4e2a3778 | 106 | wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" ); |
e146b8c8 | 107 | |
7738af59 VZ |
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(); | |
112 | if ( win ) | |
113 | win->GTKReleaseMouseAndNotify(); | |
114 | ||
cdc48273 | 115 | wxWindow * const parent = GetParentForModalDialog(); |
8bda0ec6 | 116 | if ( parent ) |
f6bcfd97 | 117 | { |
8bda0ec6 VZ |
118 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), |
119 | GTK_WINDOW(parent->m_widget) ); | |
f6bcfd97 BP |
120 | } |
121 | ||
eebe4016 | 122 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
91af0895 WS |
123 | |
124 | Show( true ); | |
2b854a32 | 125 | |
91af0895 | 126 | m_modalShowing = true; |
2b854a32 | 127 | |
64c11164 | 128 | wxOpenModalDialogsCount++; |
304e5625 | 129 | |
f36630af VZ |
130 | // NOTE: gtk_window_set_modal internally calls gtk_grab_add() ! |
131 | gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE); | |
924b84ab | 132 | |
bfafa628 VZ |
133 | // Run modal dialog event loop. |
134 | { | |
135 | wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop()); | |
136 | m_modalLoop->Run(); | |
137 | } | |
924b84ab | 138 | |
f36630af | 139 | gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE); |
2b854a32 | 140 | |
64c11164 | 141 | wxOpenModalDialogsCount--; |
304e5625 | 142 | |
fb1585ae | 143 | return GetReturnCode(); |
c33c4050 | 144 | } |
c801d85f KB |
145 | |
146 | void wxDialog::EndModal( int retCode ) | |
147 | { | |
fb1585ae | 148 | SetReturnCode( retCode ); |
2b854a32 | 149 | |
fb1585ae RR |
150 | if (!IsModal()) |
151 | { | |
dc409d37 | 152 | wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" ); |
fb1585ae RR |
153 | return; |
154 | } | |
2b854a32 | 155 | |
91af0895 | 156 | m_modalShowing = false; |
2b854a32 | 157 | |
bfafa628 VZ |
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()) | |
161 | m_modalLoop->Exit(); | |
2b854a32 | 162 | |
91af0895 | 163 | Show( false ); |
c33c4050 | 164 | } |