]>
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 | |
b3daa5a3 VZ |
115 | // use the apps top level window as parent if none given unless explicitly |
116 | // forbidden | |
117 | if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) ) | |
f6bcfd97 | 118 | { |
31fdb8d9 VZ |
119 | wxWindow * const parent = GetParentForModalDialog(); |
120 | if ( parent && parent != this ) | |
f6bcfd97 | 121 | { |
31fdb8d9 VZ |
122 | gtk_window_set_transient_for( GTK_WINDOW(m_widget), |
123 | GTK_WINDOW(parent->m_widget) ); | |
f6bcfd97 BP |
124 | } |
125 | } | |
126 | ||
eebe4016 | 127 | wxBusyCursorSuspender cs; // temporarily suppress the busy cursor |
91af0895 WS |
128 | |
129 | Show( true ); | |
2b854a32 | 130 | |
91af0895 | 131 | m_modalShowing = true; |
2b854a32 | 132 | |
304e5625 RR |
133 | g_openDialogs++; |
134 | ||
f36630af VZ |
135 | // NOTE: gtk_window_set_modal internally calls gtk_grab_add() ! |
136 | gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE); | |
924b84ab | 137 | |
b46b1d59 | 138 | wxGUIEventLoop().Run(); |
924b84ab | 139 | |
f36630af | 140 | gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE); |
2b854a32 | 141 | |
304e5625 RR |
142 | g_openDialogs--; |
143 | ||
fb1585ae | 144 | return GetReturnCode(); |
c33c4050 | 145 | } |
c801d85f KB |
146 | |
147 | void wxDialog::EndModal( int retCode ) | |
148 | { | |
fb1585ae | 149 | SetReturnCode( retCode ); |
2b854a32 | 150 | |
fb1585ae RR |
151 | if (!IsModal()) |
152 | { | |
223d09f6 | 153 | wxFAIL_MSG( wxT("wxDialog:EndModal called twice") ); |
fb1585ae RR |
154 | return; |
155 | } | |
2b854a32 | 156 | |
91af0895 | 157 | m_modalShowing = false; |
2b854a32 | 158 | |
fb1585ae | 159 | gtk_main_quit(); |
2b854a32 | 160 | |
91af0895 | 161 | Show( false ); |
c33c4050 | 162 | } |