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