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