]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
cleanup
[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 //-----------------------------------------------------------------------------
24 // global data
25 //-----------------------------------------------------------------------------
26
27 // Don't allow window closing if there are open dialogs
28 int g_openDialogs;
29
30 //-----------------------------------------------------------------------------
31 // wxDialog
32 //-----------------------------------------------------------------------------
33
34 IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
35
36 void wxDialog::Init()
37 {
38 m_returnCode = 0;
39 m_modalShowing = false;
40 m_themeEnabled = true;
41 }
42
43 wxDialog::wxDialog( wxWindow *parent,
44 wxWindowID id, const wxString &title,
45 const wxPoint &pos, const wxSize &size,
46 long style, const wxString &name )
47 {
48 Init();
49
50 (void)Create( parent, id, title, pos, size, style, name );
51 }
52
53 bool wxDialog::Create( wxWindow *parent,
54 wxWindowID id, const wxString &title,
55 const wxPoint &pos, const wxSize &size,
56 long style, const wxString &name )
57 {
58 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
59
60 // all dialogs should have tab traversal enabled
61 style |= wxTAB_TRAVERSAL;
62
63 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
64 }
65
66 bool wxDialog::Show( bool show )
67 {
68 if (!show && IsModal())
69 {
70 EndModal( wxID_CANCEL );
71 }
72
73 bool ret = wxWindow::Show( show );
74
75 if (show) InitDialog();
76
77 return ret;
78 }
79
80 bool wxDialog::IsModal() const
81 {
82 return m_modalShowing;
83 }
84
85 void wxDialog::SetModal( bool WXUNUSED(flag) )
86 {
87 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
88 }
89
90 int wxDialog::ShowModal()
91 {
92 if (IsModal())
93 {
94 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
95 return GetReturnCode();
96 }
97
98 // release the mouse if it's currently captured as the window having it
99 // will be disabled when this dialog is shown -- but will still keep the
100 // capture making it impossible to do anything in the modal dialog itself
101 wxWindow * const win = wxWindow::GetCapture();
102 if ( win )
103 win->GTKReleaseMouseAndNotify();
104
105 // use the apps top level window as parent if none given unless explicitly
106 // forbidden
107 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
108 {
109 wxWindow * const parent = GetParentForModalDialog();
110 if ( parent && parent != this )
111 {
112 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
113 GTK_WINDOW(parent->m_widget) );
114 }
115 }
116
117 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
118
119 Show( true );
120
121 m_modalShowing = true;
122
123 g_openDialogs++;
124
125 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
126 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
127
128 wxGUIEventLoop().Run();
129
130 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
131
132 g_openDialogs--;
133
134 return GetReturnCode();
135 }
136
137 void wxDialog::EndModal( int retCode )
138 {
139 SetReturnCode( retCode );
140
141 if (!IsModal())
142 {
143 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
144 return;
145 }
146
147 m_modalShowing = false;
148
149 gtk_main_quit();
150
151 Show( false );
152 }