]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dialog.cpp
Tests for wxTE_PROCESS_TAB again in line with other ports
[wxWidgets.git] / src / gtk1 / dialog.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialog.cpp
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 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
c801d85f
KB
11#pragma implementation "dialog.h"
12#endif
13
14f355c2
VS
14// For compilers that support precompilation, includes "wx.h".
15#include "wx/wxprec.h"
16
c801d85f
KB
17#include "wx/dialog.h"
18#include "wx/frame.h"
19#include "wx/app.h"
69ffe1d2 20#include "wx/cursor.h"
83624f79 21
071a2d78
RR
22#include <gdk/gdk.h>
23#include <gtk/gtk.h>
24#include <gdk/gdkkeysyms.h>
25
c801d85f 26#include "wx/gtk/win_gtk.h"
5e014a0c 27
acfd422a
RR
28//-----------------------------------------------------------------------------
29// idle system
30//-----------------------------------------------------------------------------
31
32extern void wxapp_install_idle_handler();
33extern bool g_isIdle;
2d68e1b4 34extern int g_openDialogs;
acfd422a 35
c801d85f
KB
36//-----------------------------------------------------------------------------
37// wxDialog
38//-----------------------------------------------------------------------------
39
7d9f12f3 40BEGIN_EVENT_TABLE(wxDialog,wxDialogBase)
fb1585ae
RR
41 EVT_BUTTON (wxID_OK, wxDialog::OnOK)
42 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
43 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
44 EVT_CLOSE (wxDialog::OnCloseWindow)
c801d85f
KB
45END_EVENT_TABLE()
46
7d9f12f3 47IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxTopLevelWindow)
c801d85f 48
68995f26 49void wxDialog::Init()
c801d85f 50{
f03fc89f 51 m_returnCode = 0;
de8113d9 52 m_sizeSet = FALSE;
fb1585ae 53 m_modalShowing = FALSE;
a2d93e73 54 m_themeEnabled = TRUE;
c33c4050 55}
c801d85f 56
2b854a32 57wxDialog::wxDialog( wxWindow *parent,
fb1585ae 58 wxWindowID id, const wxString &title,
2b854a32 59 const wxPoint &pos, const wxSize &size,
fb1585ae 60 long style, const wxString &name )
c801d85f 61{
68995f26
VZ
62 Init();
63
82c9f85c 64 (void)Create( parent, id, title, pos, size, style, name );
c33c4050 65}
c801d85f
KB
66
67bool wxDialog::Create( wxWindow *parent,
fb1585ae 68 wxWindowID id, const wxString &title,
2b854a32 69 const wxPoint &pos, const wxSize &size,
fb1585ae 70 long style, const wxString &name )
c801d85f 71{
21f4383a 72 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
2b854a32 73
82c9f85c
VZ
74 // all dialogs should have tab traversal enabled
75 style |= wxTAB_TRAVERSAL;
76
7d9f12f3 77 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
c33c4050 78}
c801d85f
KB
79
80void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
81{
82c9f85c
VZ
82 if (Validate())
83 TransferDataFromWindow();
c33c4050 84}
c801d85f
KB
85
86void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
87{
fb1585ae
RR
88 if (IsModal())
89 {
90 EndModal(wxID_CANCEL);
91 }
92 else
93 {
94 SetReturnCode(wxID_CANCEL);
739730ca 95 Show(FALSE);
fb1585ae 96 }
c33c4050 97}
c801d85f 98
903f689b 99void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
c801d85f 100{
32ac755d 101 if (Validate() && TransferDataFromWindow())
1a6944fd 102 {
2b854a32 103 if (IsModal())
fb1585ae
RR
104 {
105 EndModal(wxID_OK);
106 }
107 else
108 {
109 SetReturnCode(wxID_OK);
f6bcfd97 110 Show(FALSE);
fb1585ae 111 }
1a6944fd 112 }
c33c4050 113}
c801d85f
KB
114
115void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
116{
2b854a32 117 // yes
c33c4050 118}
c801d85f 119
a492cb0f 120void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
c801d85f 121{
e3065973
JS
122 // We'll send a Cancel message by default,
123 // which may close the dialog.
124 // Check for looping if the Cancel event handler calls Close().
125
126 // Note that if a cancel button and handler aren't present in the dialog,
127 // nothing will happen when you close the dialog via the window manager, or
128 // via Close().
129 // We wouldn't want to destroy the dialog by default, since the dialog may have been
130 // created on the stack.
131 // However, this does mean that calling dialog->Close() won't delete the dialog
132 // unless the handler for wxID_CANCEL does so. So use Destroy() if you want to be
133 // sure to destroy the dialog.
134 // The default OnCancel (above) simply ends a modal dialog, and hides a modeless dialog.
135
ab2b3dd4 136 static wxList s_closing;
c801d85f 137
ab2b3dd4 138 if (s_closing.Member(this))
2b854a32
VZ
139 return; // no loops
140
ab2b3dd4 141 s_closing.Append(this);
c801d85f 142
fb1585ae
RR
143 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
144 cancelEvent.SetEventObject( this );
145 GetEventHandler()->ProcessEvent(cancelEvent);
ab2b3dd4 146 s_closing.DeleteObject(this);
c801d85f
KB
147}
148
debe6624 149bool wxDialog::Show( bool show )
c801d85f 150{
fb1585ae
RR
151 if (!show && IsModal())
152 {
de8113d9 153 EndModal( wxID_CANCEL );
fb1585ae 154 }
c801d85f 155
de8113d9
RR
156 if (show && !m_sizeSet)
157 {
158 /* by calling GtkOnSize here, we don't have to call
159 either after showing the frame, which would entail
160 much ugly flicker nor from within the size_allocate
161 handler, because GTK 1.1.X forbids that. */
162
163 GtkOnSize( m_x, m_y, m_width, m_height );
164 }
2b854a32 165
739730ca 166 bool ret = wxWindow::Show( show );
e146b8c8 167
fb1585ae 168 if (show) InitDialog();
2b854a32 169
739730ca 170 return ret;
c33c4050
RR
171}
172
43a18898 173bool wxDialog::IsModal() const
e1e955e1 174{
fb1585ae 175 return m_modalShowing;
e1e955e1
RR
176}
177
178void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 179{
223d09f6 180 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 181}
c801d85f 182
43a18898 183int wxDialog::ShowModal()
c801d85f 184{
fb1585ae
RR
185 if (IsModal())
186 {
223d09f6 187 wxFAIL_MSG( wxT("wxDialog:ShowModal called twice") );
fb1585ae
RR
188 return GetReturnCode();
189 }
e146b8c8 190
b3daa5a3
VZ
191 // use the apps top level window as parent if none given unless explicitly
192 // forbidden
193 if ( !GetParent() && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
f6bcfd97
BP
194 {
195 wxWindow *parent = wxTheApp->GetTopWindow();
39cc7a0b
VZ
196 if ( parent &&
197 parent != this &&
198 parent->IsBeingDeleted() &&
199 !(parent->GetExtraStyle() & wxWS_EX_TRANSIENT) )
f6bcfd97
BP
200 {
201 m_parent = parent;
202 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) );
203 }
204 }
205
eebe4016 206 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
2b5f62a0 207
fb1585ae 208 Show( TRUE );
2b854a32 209
2b5f62a0
VZ
210 SetFocus();
211
fb1585ae 212 m_modalShowing = TRUE;
2b854a32 213
304e5625
RR
214 g_openDialogs++;
215
fb1585ae
RR
216 gtk_grab_add( m_widget );
217 gtk_main();
218 gtk_grab_remove( m_widget );
2b854a32 219
304e5625
RR
220 g_openDialogs--;
221
fb1585ae 222 return GetReturnCode();
c33c4050 223}
c801d85f
KB
224
225void wxDialog::EndModal( int retCode )
226{
fb1585ae 227 SetReturnCode( retCode );
2b854a32 228
fb1585ae
RR
229 if (!IsModal())
230 {
223d09f6 231 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
fb1585ae
RR
232 return;
233 }
2b854a32 234
fb1585ae 235 m_modalShowing = FALSE;
2b854a32 236
fb1585ae 237 gtk_main_quit();
2b854a32 238
fb1585ae 239 Show( FALSE );
c33c4050 240}