]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/dialog.cpp
Fixed resizing of wxTextCtrl
[wxWidgets.git] / src / gtk1 / dialog.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialog.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
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
19//-----------------------------------------------------------------------------
20
21extern wxList wxPendingDelete;
22
23//-----------------------------------------------------------------------------
24// "delete_event"
25//-----------------------------------------------------------------------------
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;
39}
40
41//-----------------------------------------------------------------------------
42// wxDialog
43//-----------------------------------------------------------------------------
44
45BEGIN_EVENT_TABLE(wxDialog,wxPanel)
46 EVT_BUTTON (wxID_OK, wxDialog::OnOK)
47 EVT_BUTTON (wxID_CANCEL, wxDialog::OnCancel)
48 EVT_BUTTON (wxID_APPLY, wxDialog::OnApply)
49 EVT_CLOSE (wxDialog::OnCloseWindow)
50END_EVENT_TABLE()
51
52IMPLEMENT_DYNAMIC_CLASS(wxDialog,wxPanel)
53
54wxDialog::wxDialog()
55{
56 m_title = "";
57 m_modalShowing = FALSE;
58 wxTopLevelWindows.Insert( this );
59}
60
61wxDialog::wxDialog( wxWindow *parent,
62 wxWindowID id, const wxString &title,
63 const wxPoint &pos, const wxSize &size,
64 long style, const wxString &name )
65{
66 m_modalShowing = FALSE;
67 wxTopLevelWindows.Insert( this );
68 Create( parent, id, title, pos, size, style, name );
69}
70
71bool wxDialog::Create( wxWindow *parent,
72 wxWindowID id, const wxString &title,
73 const wxPoint &pos, const wxSize &size,
74 long style, const wxString &name )
75{
76 m_needParent = FALSE;
77
78 PreCreation( parent, id, pos, size, style, name );
79
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
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
101 if (m_parent) m_parent->AddChild( this );
102
103
104 PostCreation();
105
106 return TRUE;
107}
108
109wxDialog::~wxDialog()
110{
111 wxTopLevelWindows.DeleteObject( this );
112 if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop();
113}
114
115void wxDialog::SetTitle( const wxString& title )
116{
117 m_title = title;
118 if (m_title.IsNull()) m_title = "";
119 gtk_window_set_title( GTK_WINDOW(m_widget), m_title );
120}
121
122wxString wxDialog::GetTitle() const
123{
124 return (wxString&)m_title;
125}
126
127void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
128{
129 if (Validate()) TransferDataFromWindow();
130}
131
132void wxDialog::OnCancel( wxCommandEvent &WXUNUSED(event) )
133{
134 if (IsModal())
135 {
136 EndModal(wxID_CANCEL);
137 }
138 else
139 {
140 SetReturnCode(wxID_CANCEL);
141 this->Show(FALSE);
142 }
143}
144
145void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
146{
147 if ( Validate() && TransferDataFromWindow())
148 {
149 if (IsModal())
150 {
151 EndModal(wxID_OK);
152 }
153 else
154 {
155 SetReturnCode(wxID_OK);
156 this->Show(FALSE);
157 }
158 }
159}
160
161void wxDialog::OnPaint( wxPaintEvent& WXUNUSED(event) )
162{
163 // yes
164}
165
166bool wxDialog::OnClose()
167{
168 static wxList closing;
169
170 if (closing.Member(this)) return FALSE; // no loops
171
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
182bool wxDialog::Destroy()
183{
184 if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this);
185
186 return TRUE;
187}
188
189void wxDialog::OnCloseWindow( wxCloseEvent& event )
190{
191 if (GetEventHandler()->OnClose() || event.GetForce())
192 {
193 this->Destroy();
194 }
195}
196
197void wxDialog::SetSize( int x, int y, int width, int height, int sizeFlags )
198{
199 wxASSERT_MSG( (m_widget != NULL), "invalid window" );
200
201 // Don't do anything for children of wxMDIChildFrame
202 if (!m_wxwindow) return;
203
204 if (m_resizing) return; // I don't like recursions
205 m_resizing = TRUE;
206
207 int old_x = m_x;
208 int old_y = m_y;
209 int old_width = m_width;
210 int old_height = m_height;
211
212 if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
213 {
214 if (x != -1) m_x = x;
215 if (y != -1) m_y = y;
216 if (width != -1) m_width = width;
217 if (height != -1) m_height = height;
218 }
219 else
220 {
221 m_x = x;
222 m_y = y;
223 m_width = width;
224 m_height = height;
225 }
226
227 if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
228 {
229 if (width == -1) m_width = 80;
230 }
231
232 if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
233 {
234 if (height == -1) m_height = 26;
235 }
236
237 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
238 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
239 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth;
240 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight;
241
242 if ((m_x != -1) || (m_y != -1))
243 {
244 if ((m_x != old_x) || (m_y != old_y))
245 gtk_widget_set_uposition( m_widget, m_x, m_y );
246 }
247
248 if ((m_width != old_width) || (m_height != old_height))
249 {
250 gtk_widget_set_usize( m_widget, m_width, m_height );
251 }
252
253 m_sizeSet = TRUE;
254
255 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
256 event.SetEventObject( this );
257 ProcessEvent( event );
258
259 m_resizing = FALSE;
260}
261
262void wxDialog::SetSize( int width, int height )
263{
264 SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING );
265}
266
267void wxDialog::Centre( int direction )
268{
269 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
270
271 int x = 0;
272 int y = 0;
273
274 if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
275 if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
276
277 Move( x, y );
278}
279
280bool wxDialog::Show( bool show )
281{
282 if (!show && IsModal())
283 {
284 EndModal( wxID_CANCEL );
285 }
286
287 wxWindow::Show( show );
288
289 if (show) InitDialog();
290
291 return TRUE;
292}
293
294bool wxDialog::IsModal() const
295{
296 return m_modalShowing;
297}
298
299void wxDialog::SetModal( bool WXUNUSED(flag) )
300{
301/*
302 if (flag)
303 m_windowStyle |= wxDIALOG_MODAL;
304 else
305 if (m_windowStyle & wxDIALOG_MODAL) m_windowStyle -= wxDIALOG_MODAL;
306*/
307 wxFAIL_MSG( "wxDialog:SetModal obsolete now" );
308}
309
310int wxDialog::ShowModal()
311{
312 if (IsModal())
313 {
314 wxFAIL_MSG( "wxDialog:ShowModal called twice" );
315 return GetReturnCode();
316 }
317
318 Show( TRUE );
319
320 m_modalShowing = TRUE;
321
322 gtk_grab_add( m_widget );
323 gtk_main();
324 gtk_grab_remove( m_widget );
325
326 return GetReturnCode();
327}
328
329void wxDialog::EndModal( int retCode )
330{
331 SetReturnCode( retCode );
332
333 if (!IsModal())
334 {
335 wxFAIL_MSG( "wxDialog:EndModal called twice" );
336 return;
337 }
338
339 m_modalShowing = FALSE;
340
341 gtk_main_quit();
342
343 Show( FALSE );
344}
345
346void wxDialog::InitDialog()
347{
348 wxWindow::InitDialog();
349}
350
351void wxDialog::SetIcon( const wxIcon &icon )
352{
353 m_icon = icon;
354 if (!icon.Ok()) return;
355
356 wxMask *mask = icon.GetMask();
357 GdkBitmap *bm = (GdkBitmap *) NULL;
358 if (mask) bm = mask->GetBitmap();
359
360 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
361}