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