]>
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 | |
16 | #include "wx/app.h" | |
76b49cf4 | 17 | #include "wx/frame.h" |
c8326d64 | 18 | #include "wx/cursor.h" |
670f9935 WS |
19 | #endif // WX_PRECOMP |
20 | ||
924b84ab | 21 | #include "wx/evtloop.h" |
83624f79 | 22 | |
071a2d78 RR |
23 | #include <gdk/gdk.h> |
24 | #include <gtk/gtk.h> | |
25 | #include <gdk/gdkkeysyms.h> | |
26 | ||
c801d85f | 27 | #include "wx/gtk/win_gtk.h" |
5e014a0c | 28 | |
acfd422a | 29 | //----------------------------------------------------------------------------- |
91af0895 | 30 | // global data |
acfd422a RR |
31 | //----------------------------------------------------------------------------- |
32 | ||
b541538f PC |
33 | // Don't allow window closing if there are open dialogs |
34 | int g_openDialogs; | |
acfd422a | 35 | |
c801d85f KB |
36 | //----------------------------------------------------------------------------- |
37 | // wxDialog | |
38 | //----------------------------------------------------------------------------- | |
39 | ||
7d9f12f3 | 40 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow) |
c801d85f | 41 | |
68995f26 | 42 | void wxDialog::Init() |
c801d85f | 43 | { |
f03fc89f | 44 | m_returnCode = 0; |
91af0895 WS |
45 | m_sizeSet = false; |
46 | m_modalShowing = false; | |
47 | m_themeEnabled = true; | |
c33c4050 | 48 | } |
c801d85f | 49 | |
2b854a32 | 50 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 51 | wxWindowID id, const wxString &title, |
2b854a32 | 52 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 53 | long style, const wxString &name ) |
c801d85f | 54 | { |
68995f26 VZ |
55 | Init(); |
56 | ||
82c9f85c | 57 | (void)Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 58 | } |
c801d85f KB |
59 | |
60 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 61 | wxWindowID id, const wxString &title, |
2b854a32 | 62 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 63 | long style, const wxString &name ) |
c801d85f | 64 | { |
21f4383a | 65 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
2b854a32 | 66 | |
82c9f85c VZ |
67 | // all dialogs should have tab traversal enabled |
68 | style |= wxTAB_TRAVERSAL; | |
69 | ||
7d9f12f3 | 70 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); |
c33c4050 | 71 | } |
c801d85f | 72 | |
debe6624 | 73 | bool wxDialog::Show( bool show ) |
c801d85f | 74 | { |
fb1585ae RR |
75 | if (!show && IsModal()) |
76 | { | |
de8113d9 | 77 | EndModal( wxID_CANCEL ); |
fb1585ae | 78 | } |
c801d85f | 79 | |
de8113d9 RR |
80 | if (show && !m_sizeSet) |
81 | { | |
82 | /* by calling GtkOnSize here, we don't have to call | |
83 | either after showing the frame, which would entail | |
84 | much ugly flicker nor from within the size_allocate | |
85 | handler, because GTK 1.1.X forbids that. */ | |
86 | ||
b5e31cc8 | 87 | GtkOnSize(); |
de8113d9 | 88 | } |
2b854a32 | 89 | |
739730ca | 90 | bool ret = wxWindow::Show( show ); |
e146b8c8 | 91 | |
fb1585ae | 92 | if (show) InitDialog(); |
2b854a32 | 93 | |
739730ca | 94 | return ret; |
c33c4050 RR |
95 | } |
96 | ||
43a18898 | 97 | bool wxDialog::IsModal() const |
e1e955e1 | 98 | { |
fb1585ae | 99 | return m_modalShowing; |
e1e955e1 RR |
100 | } |
101 | ||
102 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 103 | { |
223d09f6 | 104 | wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); |
c33c4050 | 105 | } |
c801d85f | 106 | |
43a18898 | 107 | int wxDialog::ShowModal() |
c801d85f | 108 | { |
fb1585ae RR |
109 | if (IsModal()) |
110 | { | |
223d09f6 | 111 | wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") ); |
fb1585ae RR |
112 | return GetReturnCode(); |
113 | } | |
e146b8c8 | 114 | |
7738af59 VZ |
115 | // release the mouse if it's currently captured as the window having it |
116 | // will be disabled when this dialog is shown -- but will still keep the | |
117 | // capture making it impossible to do anything in the modal dialog itself | |
118 | wxWindow * const win = wxWindow::GetCapture(); | |
119 | if ( win ) | |
120 | win->GTKReleaseMouseAndNotify(); | |
121 | ||
b3daa5a3 VZ |
122 | // use the apps top level window as parent if none given unless explicitly |
123 | // forbidden | |
124 | if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
f6bcfd97 | 125 | { |
31fdb8d9 VZ |
126 | wxWindow * const parent = GetParentForModalDialog(); |
127 | if ( parent && parent != this ) | |
f6bcfd97 | 128 | { |
31fdb8d9 VZ |
129 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), |
130 | GTK_WINDOW(parent->m_widget) ); | |
f6bcfd97 BP |
131 | } |
132 | } | |
133 | ||
eebe4016 | 134 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
91af0895 WS |
135 | |
136 | Show( true ); | |
2b854a32 | 137 | |
91af0895 | 138 | m_modalShowing = true; |
2b854a32 | 139 | |
304e5625 RR |
140 | g_openDialogs++; |
141 | ||
f36630af VZ |
142 | // NOTE: gtk_window_set_modal internally calls gtk_grab_add() ! |
143 | gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE); | |
924b84ab | 144 | |
b46b1d59 | 145 | wxGUIEventLoop().Run(); |
924b84ab | 146 | |
f36630af | 147 | gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE); |
2b854a32 | 148 | |
304e5625 RR |
149 | g_openDialogs--; |
150 | ||
fb1585ae | 151 | return GetReturnCode(); |
c33c4050 | 152 | } |
c801d85f KB |
153 | |
154 | void wxDialog::EndModal( int retCode ) | |
155 | { | |
fb1585ae | 156 | SetReturnCode( retCode ); |
2b854a32 | 157 | |
fb1585ae RR |
158 | if (!IsModal()) |
159 | { | |
223d09f6 | 160 | wxFAIL_MSG( wxT("wxDialog:EndModal called twice") ); |
fb1585ae RR |
161 | return; |
162 | } | |
2b854a32 | 163 | |
91af0895 | 164 | m_modalShowing = false; |
2b854a32 | 165 | |
fb1585ae | 166 | gtk_main_quit(); |
2b854a32 | 167 | |
91af0895 | 168 | Show( false ); |
c33c4050 | 169 | } |