]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/dialog.cpp
Changed setup.h so that global memory operators are switched off for GnuWin32;
[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
c801d85f
KB
7// Licence: wxWindows licence
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"
17#include "wx/gtk/win_gtk.h"
18
e2414cbe
RR
19//-----------------------------------------------------------------------------
20
21extern wxList wxPendingDelete;
22
c801d85f 23//-----------------------------------------------------------------------------
e1e955e1
RR
24// "delete_event"
25//-----------------------------------------------------------------------------
c801d85f
KB
26
27bool gtk_dialog_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxDialog *win )
28{
29/*
30 printf( "OnDelete from " );
31 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
32 printf( win->GetClassInfo()->GetClassName() );
33 printf( ".\n" );
34*/
35
36 win->Close();
37
38 return TRUE;
c33c4050 39}
c801d85f
KB
40
41//-----------------------------------------------------------------------------
42// wxDialog
43//-----------------------------------------------------------------------------
44
a60c99e6 45BEGIN_EVENT_TABLE(wxDialog,wxPanel)
903f689b 46 EVT_BUTTON (wxID_OK, wxDialog::OnOK)
c801d85f
KB
47 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
48 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
49 EVT_CLOSE (wxDialog::OnCloseWindow)
50END_EVENT_TABLE()
51
a60c99e6 52IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel)
c801d85f
KB
53
54wxDialog::wxDialog(void)
55{
56 m_title = "";
d355d3fe 57 m_modalShowing = FALSE;
c801d85f 58 wxTopLevelWindows.Insert( this );
c33c4050 59}
c801d85f
KB
60
61wxDialog::wxDialog( wxWindow *parent,
62 wxWindowID id, const wxString &title,
63 const wxPoint &pos, const wxSize &size,
debe6624 64 long style, const wxString &name )
c801d85f 65{
d355d3fe 66 m_modalShowing = FALSE;
c801d85f
KB
67 wxTopLevelWindows.Insert( this );
68 Create( parent, id, title, pos, size, style, name );
c33c4050 69}
c801d85f
KB
70
71bool wxDialog::Create( wxWindow *parent,
72 wxWindowID id, const wxString &title,
73 const wxPoint &pos, const wxSize &size,
debe6624 74 long style, const wxString &name )
c801d85f
KB
75{
76 m_needParent = FALSE;
77
78 PreCreation( parent, id, pos, size, style, name );
79
c801d85f
KB
80 m_widget = gtk_window_new( GTK_WINDOW_TOPLEVEL );
81 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
82
83 gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL);
84
85 gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event",
86 GTK_SIGNAL_FUNC(gtk_dialog_delete_callback), (gpointer)this );
87
88 m_wxwindow = gtk_myfixed_new();
89 gtk_widget_show( m_wxwindow );
90 GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
91
92 gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
93
94 SetTitle( title );
95
903f689b
RR
96 if ((m_x != -1) || (m_y != -1))
97 gtk_widget_set_uposition( m_widget, m_x, m_y );
98
99 gtk_widget_set_usize( m_widget, m_width, m_height );
100
6ca41e57
RR
101 if (m_parent) m_parent->AddChild( this );
102
103
c801d85f
KB
104 PostCreation();
105
106 return TRUE;
c33c4050 107}
c801d85f
KB
108
109wxDialog::~wxDialog(void)
110{
111 wxTopLevelWindows.DeleteObject( this );
112 if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
c33c4050 113}
c801d85f
KB
114
115void wxDialog::SetTitle(const wxString& title )
116{
117 m_title = title;
b6af8d80 118 if (m_title.IsNull()) m_title = "";
c801d85f 119 gtk_window_set_title( GTK_WINDOW(m_widget), m_title );
c33c4050 120}
c801d85f
KB
121
122wxString wxDialog::GetTitle(void) const
123{
124 return (wxString&)m_title;
c33c4050 125}
c801d85f
KB
126
127void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
128{
129 if (Validate()) TransferDataFromWindow();
c33c4050 130}
c801d85f
KB
131
132void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
133{
134 if (IsModal())
1a6944fd 135 {
c801d85f 136 EndModal(wxID_CANCEL);
1a6944fd 137 }
c801d85f
KB
138 else
139 {
140 SetReturnCode(wxID_CANCEL);
141 this->Show(FALSE);
c33c4050
RR
142 }
143}
c801d85f 144
903f689b 145void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
c801d85f
KB
146{
147 if ( Validate() && TransferDataFromWindow())
148 {
149 if (IsModal())
1a6944fd 150 {
c801d85f 151 EndModal(wxID_OK);
1a6944fd 152 }
c801d85f
KB
153 else
154 {
155 SetReturnCode(wxID_OK);
156 this->Show(FALSE);
c33c4050
RR
157 }
158 }
159}
c801d85f
KB
160
161void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
162{
163 // yes
c33c4050 164}
c801d85f
KB
165
166bool wxDialog::OnClose(void)
167{
168 static wxList closing;
169
170 if (closing.Member(this)) return FALSE; // no loops
1a6944fd 171
c801d85f
KB
172 closing.Append(this);
173
174 wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
175 cancelEvent.SetEventObject( this );
176 GetEventHandler()->ProcessEvent(cancelEvent);
177 closing.DeleteObject(this);
178
179 return FALSE;
180}
181
e2414cbe
RR
182bool wxDialog::Destroy(void)
183{
184 if (!wxPendingDelete.Member(this))
185 wxPendingDelete.Append(this);
186
187 return TRUE;
188}
189
c801d85f
KB
190void wxDialog::OnCloseWindow(wxCloseEvent& event)
191{
192 if (GetEventHandler()->OnClose() || event.GetForce())
193 {
194 this->Destroy();
c33c4050
RR
195 }
196}
c801d85f 197
903f689b
RR
198void wxDialog::ImplementSetPosition(void)
199{
200 if ((m_x != -1) || (m_y != -1))
201 gtk_widget_set_uposition( m_widget, m_x, m_y );
202}
203
204void wxDialog::Centre( int direction )
205{
206 if (direction & wxHORIZONTAL == wxHORIZONTAL) m_x = (gdk_screen_width () - m_width) / 2;
207 if (direction & wxVERTICAL == wxVERTICAL) m_y = (gdk_screen_height () - m_height) / 2;
208 ImplementSetPosition();
209}
210
debe6624 211bool wxDialog::Show( bool show )
c801d85f 212{
e1e955e1 213 if (!show && IsModal())
c801d85f
KB
214 {
215 EndModal( wxID_CANCEL );
c33c4050 216 }
c801d85f
KB
217
218 wxWindow::Show( show );
219
220 if (show) InitDialog();
221
c801d85f 222 return TRUE;
c33c4050
RR
223}
224
e1e955e1
RR
225bool wxDialog::IsModal(void) const
226{
227 return m_modalShowing;
228}
229
230void wxDialog::SetModal( bool WXUNUSED(flag) )
c33c4050 231{
e1e955e1 232/*
c33c4050
RR
233 if (flag)
234 m_windowStyle |= wxDIALOG_MODAL;
235 else
236 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
e1e955e1
RR
237*/
238 wxFAIL_MSG( "wxDialog:SetModal obsolete now" );
c33c4050 239}
c801d85f
KB
240
241int wxDialog::ShowModal(void)
242{
e1e955e1 243 if (IsModal())
5b011451
RR
244 {
245 wxFAIL_MSG( "wxDialog:ShowModal called twice" );
246 return GetReturnCode();
247 }
d355d3fe 248
c801d85f 249 Show( TRUE );
d355d3fe
RR
250
251 m_modalShowing = TRUE;
252
253 gtk_grab_add( m_widget );
254 gtk_main();
255 gtk_grab_remove( m_widget );
256
c801d85f 257 return GetReturnCode();
c33c4050 258}
c801d85f
KB
259
260void wxDialog::EndModal( int retCode )
261{
c801d85f 262 SetReturnCode( retCode );
d355d3fe 263
e1e955e1 264 if (!IsModal())
b6af8d80 265 {
5b011451 266 wxFAIL_MSG( "wxDialog:EndModal called twice" );
b6af8d80 267 return;
c33c4050 268 }
b6af8d80 269
d355d3fe
RR
270 m_modalShowing = FALSE;
271
e2414cbe 272 gtk_main_quit();
5b011451
RR
273
274 Show( FALSE );
c33c4050 275}
c801d85f
KB
276
277void wxDialog::InitDialog(void)
278{
279 wxWindow::InitDialog();
c33c4050
RR
280}
281
c33c4050
RR
282void wxDialog::SetIcon( const wxIcon &icon )
283{
284 m_icon = icon;
285 if (!icon.Ok()) return;
286
287 wxMask *mask = icon.GetMask();
c67daf87 288 GdkBitmap *bm = (GdkBitmap *) NULL;
c33c4050
RR
289 if (mask) bm = mask->GetBitmap();
290
c67daf87 291 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
c33c4050 292}