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