]>
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 | ||
2d68e1b4 | 33 | extern int g_openDialogs; |
acfd422a | 34 | |
c801d85f KB |
35 | //----------------------------------------------------------------------------- |
36 | // wxDialog | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
7d9f12f3 | 39 | IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow) |
c801d85f | 40 | |
68995f26 | 41 | void wxDialog::Init() |
c801d85f | 42 | { |
f03fc89f | 43 | m_returnCode = 0; |
91af0895 WS |
44 | m_sizeSet = false; |
45 | m_modalShowing = false; | |
46 | m_themeEnabled = true; | |
c33c4050 | 47 | } |
c801d85f | 48 | |
2b854a32 | 49 | wxDialog::wxDialog( wxWindow *parent, |
fb1585ae | 50 | wxWindowID id, const wxString &title, |
2b854a32 | 51 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 52 | long style, const wxString &name ) |
c801d85f | 53 | { |
68995f26 VZ |
54 | Init(); |
55 | ||
82c9f85c | 56 | (void)Create( parent, id, title, pos, size, style, name ); |
c33c4050 | 57 | } |
c801d85f KB |
58 | |
59 | bool wxDialog::Create( wxWindow *parent, | |
fb1585ae | 60 | wxWindowID id, const wxString &title, |
2b854a32 | 61 | const wxPoint &pos, const wxSize &size, |
fb1585ae | 62 | long style, const wxString &name ) |
c801d85f | 63 | { |
21f4383a | 64 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
2b854a32 | 65 | |
82c9f85c VZ |
66 | // all dialogs should have tab traversal enabled |
67 | style |= wxTAB_TRAVERSAL; | |
68 | ||
7d9f12f3 | 69 | return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name); |
c33c4050 | 70 | } |
c801d85f | 71 | |
debe6624 | 72 | bool wxDialog::Show( bool show ) |
c801d85f | 73 | { |
fb1585ae RR |
74 | if (!show && IsModal()) |
75 | { | |
de8113d9 | 76 | EndModal( wxID_CANCEL ); |
fb1585ae | 77 | } |
c801d85f | 78 | |
de8113d9 RR |
79 | if (show && !m_sizeSet) |
80 | { | |
81 | /* by calling GtkOnSize here, we don't have to call | |
82 | either after showing the frame, which would entail | |
83 | much ugly flicker nor from within the size_allocate | |
84 | handler, because GTK 1.1.X forbids that. */ | |
85 | ||
b5e31cc8 | 86 | GtkOnSize(); |
de8113d9 | 87 | } |
2b854a32 | 88 | |
739730ca | 89 | bool ret = wxWindow::Show( show ); |
e146b8c8 | 90 | |
fb1585ae | 91 | if (show) InitDialog(); |
2b854a32 | 92 | |
739730ca | 93 | return ret; |
c33c4050 RR |
94 | } |
95 | ||
43a18898 | 96 | bool wxDialog::IsModal() const |
e1e955e1 | 97 | { |
fb1585ae | 98 | return m_modalShowing; |
e1e955e1 RR |
99 | } |
100 | ||
101 | void wxDialog::SetModal( bool WXUNUSED(flag) ) | |
c33c4050 | 102 | { |
223d09f6 | 103 | wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") ); |
c33c4050 | 104 | } |
c801d85f | 105 | |
43a18898 | 106 | int wxDialog::ShowModal() |
c801d85f | 107 | { |
fb1585ae RR |
108 | if (IsModal()) |
109 | { | |
223d09f6 | 110 | wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") ); |
fb1585ae RR |
111 | return GetReturnCode(); |
112 | } | |
e146b8c8 | 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 | |
304e5625 RR |
132 | g_openDialogs++; |
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 VS |
136 | |
137 | wxEventLoop().Run(); | |
138 | ||
f36630af | 139 | gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE); |
2b854a32 | 140 | |
304e5625 RR |
141 | g_openDialogs--; |
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 | { | |
223d09f6 | 152 | wxFAIL_MSG( wxT("wxDialog:EndModal called twice") ); |
fb1585ae RR |
153 | return; |
154 | } | |
2b854a32 | 155 | |
91af0895 | 156 | m_modalShowing = false; |
2b854a32 | 157 | |
fb1585ae | 158 | gtk_main_quit(); |
2b854a32 | 159 | |
91af0895 | 160 | Show( false ); |
c33c4050 | 161 | } |