]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/dialog.cpp
* Fixed a bug in notebook.tex
[wxWidgets.git] / src / gtk / dialog.cpp
... / ...
CommitLineData
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
20//-----------------------------------------------------------------------------
21
22extern wxList wxPendingDelete;
23
24//-----------------------------------------------------------------------------
25// "delete_event"
26//-----------------------------------------------------------------------------
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;
40}
41
42//-----------------------------------------------------------------------------
43// wxDialog
44//-----------------------------------------------------------------------------
45
46BEGIN_EVENT_TABLE(wxDialog,wxPanel)
47 EVT_BUTTON (wxID_OK, wxDialog::OnOK)
48 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
49 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
50 EVT_CLOSE (wxDialog::OnCloseWindow)
51END_EVENT_TABLE()
52
53IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel)
54
55wxDialog::wxDialog(void)
56{
57 m_title = "";
58 m_modalShowing = FALSE;
59 wxTopLevelWindows.Insert( this );
60}
61
62wxDialog::wxDialog( wxWindow *parent,
63 wxWindowID id, const wxString &title,
64 const wxPoint &pos, const wxSize &size,
65 long style, const wxString &name )
66{
67 m_modalShowing = FALSE;
68 wxTopLevelWindows.Insert( this );
69 Create( parent, id, title, pos, size, style, name );
70}
71
72bool wxDialog::Create( wxWindow *parent,
73 wxWindowID id, const wxString &title,
74 const wxPoint &pos, const wxSize &size,
75 long style, const wxString &name )
76{
77 m_needParent = FALSE;
78
79 PreCreation( parent, id, pos, size, style, name );
80
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
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
102 PostCreation();
103
104 return TRUE;
105}
106
107wxDialog::~wxDialog(void)
108{
109 wxTopLevelWindows.DeleteObject( this );
110 if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
111}
112
113void wxDialog::SetTitle(const wxString& title )
114{
115 m_title = title;
116 if (m_title.IsNull()) m_title = "";
117 gtk_window_set_title( GTK_WINDOW(m_widget), m_title );
118}
119
120wxString wxDialog::GetTitle(void) const
121{
122 return (wxString&)m_title;
123}
124
125void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
126{
127 if (Validate()) TransferDataFromWindow();
128}
129
130void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
131{
132 if (IsModal())
133 {
134 EndModal(wxID_CANCEL);
135 }
136 else
137 {
138 SetReturnCode(wxID_CANCEL);
139 this->Show(FALSE);
140 }
141}
142
143void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
144{
145 if ( Validate() && TransferDataFromWindow())
146 {
147 if (IsModal())
148 {
149 EndModal(wxID_OK);
150 }
151 else
152 {
153 SetReturnCode(wxID_OK);
154 this->Show(FALSE);
155 }
156 }
157}
158
159void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
160{
161 // yes
162}
163
164bool wxDialog::OnClose(void)
165{
166 static wxList closing;
167
168 if (closing.Member(this)) return FALSE; // no loops
169
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
180bool wxDialog::Destroy(void)
181{
182 if (!wxPendingDelete.Member(this))
183 wxPendingDelete.Append(this);
184
185 return TRUE;
186}
187
188void wxDialog::OnCloseWindow(wxCloseEvent& event)
189{
190 if (GetEventHandler()->OnClose() || event.GetForce())
191 {
192 this->Destroy();
193 }
194}
195
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
209bool wxDialog::Show( bool show )
210{
211 if (!show && IsModal())
212 {
213 EndModal( wxID_CANCEL );
214 }
215
216 wxWindow::Show( show );
217
218 if (show) InitDialog();
219
220 return TRUE;
221}
222
223bool wxDialog::IsModal(void) const
224{
225 return m_modalShowing;
226}
227
228void wxDialog::SetModal( bool WXUNUSED(flag) )
229{
230/*
231 if (flag)
232 m_windowStyle |= wxDIALOG_MODAL;
233 else
234 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
235*/
236 wxFAIL_MSG( "wxDialog:SetModal obsolete now" );
237}
238
239int wxDialog::ShowModal(void)
240{
241 if (IsModal())
242 {
243 wxFAIL_MSG( "wxDialog:ShowModal called twice" );
244 return GetReturnCode();
245 }
246
247 Show( TRUE );
248
249 m_modalShowing = TRUE;
250
251 gtk_grab_add( m_widget );
252 gtk_main();
253 gtk_grab_remove( m_widget );
254
255 return GetReturnCode();
256}
257
258void wxDialog::EndModal( int retCode )
259{
260 SetReturnCode( retCode );
261
262 if (!IsModal())
263 {
264 wxFAIL_MSG( "wxDialog:EndModal called twice" );
265 return;
266 }
267
268 m_modalShowing = FALSE;
269
270 gtk_main_quit();
271
272 Show( FALSE );
273}
274
275void wxDialog::InitDialog(void)
276{
277 wxWindow::InitDialog();
278}
279
280void wxDialog::SetIcon( const wxIcon &icon )
281{
282 m_icon = icon;
283 if (!icon.Ok()) return;
284
285 wxMask *mask = icon.GetMask();
286 GdkBitmap *bm = (GdkBitmap *) NULL;
287 if (mask) bm = mask->GetBitmap();
288
289 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
290}
291
292