]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dialog.cpp
Also account for EOL chars correctly in wxStyledTextCtrl::GetLineLength().
[wxWidgets.git] / src / gtk1 / dialog.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/gtk1/dialog.cpp
c801d85f
KB
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
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
c801d85f 13#include "wx/dialog.h"
670f9935
WS
14
15#ifndef WX_PRECOMP
16 #include "wx/app.h"
76b49cf4 17 #include "wx/frame.h"
c8326d64 18 #include "wx/cursor.h"
670f9935
WS
19#endif // WX_PRECOMP
20
924b84ab 21#include "wx/evtloop.h"
643e9cf9 22#include "wx/testing.h"
83624f79 23
071a2d78
RR
24#include <gdk/gdk.h>
25#include <gtk/gtk.h>
26#include <gdk/gdkkeysyms.h>
27
3cbab641 28#include "wx/gtk1/win_gtk.h"
5e014a0c 29
acfd422a 30//-----------------------------------------------------------------------------
91af0895 31// global data
acfd422a
RR
32//-----------------------------------------------------------------------------
33
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
68995f26 47void wxDialog::Init()
c801d85f 48{
f03fc89f 49 m_returnCode = 0;
91af0895
WS
50 m_sizeSet = false;
51 m_modalShowing = false;
52 m_themeEnabled = true;
c33c4050 53}
c801d85f 54
2b854a32 55wxDialog::wxDialog( wxWindow *parent,
fb1585ae 56 wxWindowID id, const wxString &title,
2b854a32 57 const wxPoint &pos, const wxSize &size,
fb1585ae 58 long style, const wxString &name )
c801d85f 59{
68995f26
VZ
60 Init();
61
82c9f85c 62 (void)Create( parent, id, title, pos, size, style, name );
c33c4050 63}
c801d85f
KB
64
65bool wxDialog::Create( wxWindow *parent,
fb1585ae 66 wxWindowID id, const wxString &title,
2b854a32 67 const wxPoint &pos, const wxSize &size,
fb1585ae 68 long style, const wxString &name )
c801d85f 69{
21f4383a 70 SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG);
2b854a32 71
82c9f85c
VZ
72 // all dialogs should have tab traversal enabled
73 style |= wxTAB_TRAVERSAL;
74
7d9f12f3 75 return wxTopLevelWindow::Create(parent, id, title, pos, size, style, name);
c33c4050 76}
c801d85f
KB
77
78void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
79{
82c9f85c
VZ
80 if (Validate())
81 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);
91af0895 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);
91af0895 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 );
937013e0 143 HandleWindowEvent(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
3aa8e4ea
JS
164 if (show && CanDoLayoutAdaptation())
165 DoLayoutAdaptation();
166
739730ca 167 bool ret = wxWindow::Show( show );
e146b8c8 168
fb1585ae 169 if (show) InitDialog();
2b854a32 170
739730ca 171 return ret;
c33c4050
RR
172}
173
43a18898 174bool wxDialog::IsModal() const
e1e955e1 175{
fb1585ae 176 return m_modalShowing;
e1e955e1
RR
177}
178
179void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 180{
223d09f6 181 wxFAIL_MSG( wxT("wxDialog:SetModal obsolete now") );
c33c4050 182}
c801d85f 183
43a18898 184int wxDialog::ShowModal()
c801d85f 185{
643e9cf9
VS
186 WX_TESTING_SHOW_MODAL_HOOK();
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
cdc48273
VZ
196 wxWindow * const parent = GetParentForModalDialog();
197 if ( parent )
f6bcfd97 198 {
cdc48273
VZ
199 m_parent = parent;
200 gtk_window_set_transient_for( GTK_WINDOW(m_widget), GTK_WINDOW(parent->m_widget) );
f6bcfd97
BP
201 }
202
eebe4016 203 wxBusyCursorSuspender cs; // temporarily suppress the busy cursor
91af0895
WS
204
205 Show( true );
2b854a32 206
91af0895 207 m_modalShowing = true;
2b854a32 208
304e5625
RR
209 g_openDialogs++;
210
fb1585ae 211 gtk_grab_add( m_widget );
924b84ab
VS
212
213 wxEventLoop().Run();
214
fb1585ae 215 gtk_grab_remove( m_widget );
2b854a32 216
304e5625
RR
217 g_openDialogs--;
218
fb1585ae 219 return GetReturnCode();
c33c4050 220}
c801d85f
KB
221
222void wxDialog::EndModal( int retCode )
223{
fb1585ae 224 SetReturnCode( retCode );
2b854a32 225
fb1585ae
RR
226 if (!IsModal())
227 {
223d09f6 228 wxFAIL_MSG( wxT("wxDialog:EndModal called twice") );
fb1585ae
RR
229 return;
230 }
2b854a32 231
91af0895 232 m_modalShowing = false;
2b854a32 233
fb1585ae 234 gtk_main_quit();
2b854a32 235
91af0895 236 Show( false );
c33c4050 237}