]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/dialog.cpp
Auto complete file names in the text controls of wx{File,Dir}PickerCtrl.
[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 "wx/scopedptr.h"
22
23 #include <gtk/gtk.h>
24
25 // this is defined in src/gtk/toplevel.cpp
26 extern int wxOpenModalDialogsCount;
27
28 wxDEFINE_TIED_SCOPED_PTR_TYPE(wxGUIEventLoop)
29
30
31 //-----------------------------------------------------------------------------
32 // wxDialog
33 //-----------------------------------------------------------------------------
34
35 void wxDialog::Init()
36 {
37 m_modalLoop = NULL;
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 if (show && CanDoLayoutAdaptation())
74 DoLayoutAdaptation();
75
76 bool ret = wxDialogBase::Show(show);
77
78 if (show)
79 InitDialog();
80
81 return ret;
82 }
83
84 wxDialog::~wxDialog()
85 {
86 // if the dialog is modal, this will end its event loop
87 if ( IsModal() )
88 EndModal(wxID_CANCEL);
89 }
90
91 bool wxDialog::IsModal() const
92 {
93 return m_modalShowing;
94 }
95
96 void wxDialog::SetModal( bool WXUNUSED(flag) )
97 {
98 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
99 }
100
101 int wxDialog::ShowModal()
102 {
103 wxASSERT_MSG( !IsModal(), "ShowModal() can't be called twice" );
104
105 // release the mouse if it's currently captured as the window having it
106 // will be disabled when this dialog is shown -- but will still keep the
107 // capture making it impossible to do anything in the modal dialog itself
108 wxWindow * const win = wxWindow::GetCapture();
109 if ( win )
110 win->GTKReleaseMouseAndNotify();
111
112 wxWindow * const parent = GetParentForModalDialog();
113 if ( parent )
114 {
115 gtk_window_set_transient_for( GTK_WINDOW(m_widget),
116 GTK_WINDOW(parent->m_widget) );
117 }
118
119 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
120
121 Show( true );
122
123 m_modalShowing = true;
124
125 wxOpenModalDialogsCount++;
126
127 // NOTE: gtk_window_set_modal internally calls gtk_grab_add() !
128 gtk_window_set_modal(GTK_WINDOW(m_widget), TRUE);
129
130 // Run modal dialog event loop.
131 {
132 wxGUIEventLoopTiedPtr modal(&m_modalLoop, new wxGUIEventLoop());
133 m_modalLoop->Run();
134 }
135
136 gtk_window_set_modal(GTK_WINDOW(m_widget), FALSE);
137
138 wxOpenModalDialogsCount--;
139
140 return GetReturnCode();
141 }
142
143 void wxDialog::EndModal( int retCode )
144 {
145 SetReturnCode( retCode );
146
147 if (!IsModal())
148 {
149 wxFAIL_MSG( "either wxDialog:EndModal called twice or ShowModal wasn't called" );
150 return;
151 }
152
153 m_modalShowing = false;
154
155 // Ensure Exit() is only called once. The dialog's event loop may be terminated
156 // externally due to an uncaught exception.
157 if (m_modalLoop && m_modalLoop->IsRunning())
158 m_modalLoop->Exit();
159
160 Show( false );
161 }