]>
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 | |
bfafa628 VZ |
21 | #include "wx/ptr_scpd.h" |
22 | ||
071a2d78 | 23 | #include <gtk/gtk.h> |
5e014a0c | 24 | |
64c11164 VZ |
25 | // this is defined in src/gtk/toplevel.cpp |
26 | extern int wxOpenModalDialogsCount; | |
acfd422a | 27 | |
5c69ef61 | 28 | wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop) |
bfafa628 VZ |
29 | |
30 | ||
c801d85f KB |
31 | //----------------------------------------------------------------------------- |
32 | // wxDialog | |
33 | //----------------------------------------------------------------------------- | |
34 | ||
7d9f12f3 | 35 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow) |
c801d85f | 36 | |
68995f26 | 37 | void wxDialog::Init() |
c801d85f | 38 | { |
bfafa628 | 39 | m_modalLoop = NULL; |
f03fc89f | 40 | m_returnCode = 0; |
91af0895 WS |
41 | m_modalShowing = false; |
42 | m_themeEnabled = true; | |
c33c4050 | 43 | } |
c801d85f | 44 | |
2b854a32 | 45 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 46 | wxWindowID id, const wxString &title, |
2b854a32 | 47 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 48 | long style, const wxString &name ) |
c801d85f | 49 | { |
68995f26 VZ |
50 | Init(); |
51 | ||
82c9f85c | 52 | (void)Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 53 | } |
c801d85f KB |
54 | |
55 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 56 | wxWindowID id, const wxString &title, |
2b854a32 | 57 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 58 | long style, const wxString &name ) |
c801d85f | 59 | { |
21f4383a | 60 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
2b854a32 | 61 | |
82c9f85c VZ |
62 | // all dialogs should have tab traversal enabled |
63 | style |= wxTAB_TRAVERSAL; | |
64 | ||
7d9f12f3 | 65 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); |
c33c4050 | 66 | } |
c801d85f | 67 | |
debe6624 | 68 | bool wxDialog::Show( bool show ) |
c801d85f | 69 | { |
fb1585ae RR |
70 | if (!show && IsModal()) |
71 | { | |
de8113d9 | 72 | EndModal( wxID_CANCEL ); |
fb1585ae | 73 | } |
c801d85f | 74 | |
3aa8e4ea JS |
75 | if (show && CanDoLayoutAdaptation()) |
76 | DoLayoutAdaptation(); | |
77 | ||
8fb09a08 | 78 | bool ret = wxDialogBase::Show(show); |
e146b8c8 | 79 | |
a9efc294 VS |
80 | if (show) |
81 | InitDialog(); | |
2b854a32 | 82 | |
739730ca | 83 | return ret; |
c33c4050 RR |
84 | } |
85 | ||
a9efc294 VS |
86 | wxDialog::~wxDialog() |
87 | { | |
a9efc294 | 88 | // if the dialog is modal, this will end its event loop |
0af07cc2 VS |
89 | if ( IsModal() ) |
90 | EndModal(wxID_CANCEL); | |
a9efc294 VS |
91 | } |
92 | ||
43a18898 | 93 | bool wxDialog::IsModal() const |
e1e955e1 | 94 | { |
fb1585ae | 95 | return m_modalShowing; |
e1e955e1 RR |
96 | } |
97 | ||
98 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 99 | { |
223d09f6 | 100 | wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); |
c33c4050 | 101 | } |
c801d85f | 102 | |
43a18898 | 103 | int wxDialog::ShowModal() |
c801d85f | 104 | { |
4e2a3778 | 105 | wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" ); |
e146b8c8 | 106 | |
7738af59 VZ |
107 | // release the mouse if it's currently captured as the window having it |
108 | // will be disabled when this dialog is shown -- but will still keep the | |
109 | // capture making it impossible to do anything in the modal dialog itself | |
110 | wxWindow * const win = wxWindow::GetCapture(); | |
111 | if ( win ) | |
112 | win->GTKReleaseMouseAndNotify(); | |
113 | ||
b3daa5a3 VZ |
114 | // use the apps top level window as parent if none given unless explicitly |
115 | // forbidden | |
116 | if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
f6bcfd97 | 117 | { |
31fdb8d9 VZ |
118 | wxWindow * const parent = GetParentForModalDialog(); |
119 | if ( parent && parent != this ) | |
f6bcfd97 | 120 | { |
31fdb8d9 VZ |
121 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), |
122 | GTK_WINDOW(parent->m_widget) ); | |
f6bcfd97 BP |
123 | } |
124 | } | |
125 | ||
eebe4016 | 126 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
91af0895 WS |
127 | |
128 | Show( true ); | |
2b854a32 | 129 | |
91af0895 | 130 | m_modalShowing = true; |
2b854a32 | 131 | |
64c11164 | 132 | wxOpenModalDialogsCount++; |
304e5625 | 133 | |
f36630af VZ |
134 | // NOTE: gtk_window_set_modal internally calls gtk_grab_add() ! |
135 | gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE); | |
924b84ab | 136 | |
bfafa628 VZ |
137 | // Run modal dialog event loop. |
138 | { | |
139 | wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop()); | |
140 | m_modalLoop->Run(); | |
141 | } | |
924b84ab | 142 | |
f36630af | 143 | gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE); |
2b854a32 | 144 | |
64c11164 | 145 | wxOpenModalDialogsCount--; |
304e5625 | 146 | |
fb1585ae | 147 | return GetReturnCode(); |
c33c4050 | 148 | } |
c801d85f KB |
149 | |
150 | void wxDialog::EndModal( int retCode ) | |
151 | { | |
fb1585ae | 152 | SetReturnCode( retCode ); |
2b854a32 | 153 | |
fb1585ae RR |
154 | if (!IsModal()) |
155 | { | |
dc409d37 | 156 | wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" ); |
fb1585ae RR |
157 | return; |
158 | } | |
2b854a32 | 159 | |
91af0895 | 160 | m_modalShowing = false; |
2b854a32 | 161 | |
bfafa628 VZ |
162 | // Ensure Exit() is only called once. The dialog's event loop may be terminated |
163 | // externally due to an uncaught exception. | |
164 | if (m_modalLoop && m_modalLoop->IsRunning()) | |
165 | m_modalLoop->Exit(); | |
2b854a32 | 166 | |
91af0895 | 167 | Show( false ); |
c33c4050 | 168 | } |