]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
rename g_openDialogs to wxOpenModalDialogsCount and define it in toplevel.cpp to...
[wxWidgets.git] / src / gtk / dialog.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/dialog.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #include "wx/dialog.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/cursor.h"
17 #endif // WX_PRECOMP
18
19 #include "wx/evtloop.h"
20
21 #include <gtk/gtk.h>
22
23 // this is defined in src/gtk/toplevel.cpp
24 extern int wxOpenModalDialogsCount;
25
26 //-----------------------------------------------------------------------------
27 // wxDialog
28 //-----------------------------------------------------------------------------
29
30 IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
31
32 void wxDialog::Init()
33 {
34 m_returnCode = 0;
35 m_modalShowing = false;
36 m_themeEnabled = true;
37 }
38
39 wxDialog::wxDialog( wxWindow *parent,
40 wxWindowID id, const wxString &title,
41 const wxPoint &pos, const wxSize &size,
42 long style, const wxString &name )
43 {
44 Init();
45
46 (void)Create( parent, id, title, pos, size, style, name );
47 }
48
49 bool wxDialog::Create( wxWindow *parent,
50 wxWindowID id, const wxString &title,
51 const wxPoint &pos, const wxSize &size,
52 long style, const wxString &name )
53 {
54 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
55
56 // all dialogs should have tab traversal enabled
57 style |= wxTAB_TRAVERSAL;
58
59 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
60 }
61
62 bool wxDialog::Show( bool show )
63 {
64 if (!show && IsModal())
65 {
66 EndModal( wxID_CANCEL );
67 }
68
69 bool ret = wxWindow::Show( show );
70
71 if (show) InitDialog();
72
73 return ret;
74 }
75
76 bool wxDialog::IsModal() const
77 {
78 return m_modalShowing;
79 }
80
81 void wxDialog::SetModal( bool WXUNUSED(flag) )
82 {
83 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
84 }
85
86 int wxDialog::ShowModal()
87 {
88 if (IsModal())
89 {
90 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
91 return GetReturnCode();
92 }
93
94 // release the mouse if it's currently captured as the window having it
95 // will be disabled when this dialog is shown -- but will still keep the
96 // capture making it impossible to do anything in the modal dialog itself
97 wxWindow * const win = wxWindow::GetCapture();
98 if ( win )
99 win->GTKReleaseMouseAndNotify();
100
101 // use the apps top level window as parent if none given unless explicitly
102 // forbidden
103 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
104 {
105 wxWindow * const parent = GetParentForModalDialog();
106 if ( parent && parent != this )
107 {
108 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
109 GTK_WINDOW(parent->m_widget) );
110 }
111 }
112
113 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
114
115 Show( true );
116
117 m_modalShowing = true;
118
119 wxOpenModalDialogsCount++;
120
121 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
122 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
123
124 wxGUIEventLoop().Run();
125
126 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
127
128 wxOpenModalDialogsCount--;
129
130 return GetReturnCode();
131 }
132
133 void wxDialog::EndModal( int retCode )
134 {
135 SetReturnCode( retCode );
136
137 if (!IsModal())
138 {
139 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
140 return;
141 }
142
143 m_modalShowing = false;
144
145 gtk_main_quit();
146
147 Show( false );
148 }