]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
19717c50 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
11 | #pragma implementation "frame.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/frame.h" | |
15 | #include "wx/dialog.h" | |
16 | #include "wx/control.h" | |
17 | #include "wx/app.h" | |
cf4219e7 RR |
18 | #include "wx/menu.h" |
19 | #include "wx/toolbar.h" | |
20 | #include "wx/statusbr.h" | |
362c6693 | 21 | #include "wx/dcclient.h" |
83624f79 RR |
22 | |
23 | #include "glib.h" | |
24 | #include "gdk/gdk.h" | |
25 | #include "gtk/gtk.h" | |
c801d85f KB |
26 | #include "wx/gtk/win_gtk.h" |
27 | ||
2f2aa628 RR |
28 | //----------------------------------------------------------------------------- |
29 | // constants | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
907789a0 | 32 | const int wxMENU_HEIGHT = 27; |
c67daf87 | 33 | const int wxSTATUS_HEIGHT = 25; |
c801d85f | 34 | |
2f2aa628 RR |
35 | //----------------------------------------------------------------------------- |
36 | // data | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
c801d85f KB |
39 | extern wxList wxTopLevelWindows; |
40 | extern wxList wxPendingDelete; | |
41 | ||
42 | //----------------------------------------------------------------------------- | |
2f2aa628 | 43 | // "size_allocate" |
c801d85f | 44 | //----------------------------------------------------------------------------- |
c801d85f | 45 | |
2f2aa628 | 46 | static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) |
ed7a557b | 47 | { |
fb1585ae | 48 | if (!win->HasVMT()) return; |
8bbe427f | 49 | |
c801d85f | 50 | /* |
fb1585ae RR |
51 | printf( "OnFrameResize from " ); |
52 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
53 | printf( win->GetClassInfo()->GetClassName() ); | |
54 | printf( ".\n" ); | |
c801d85f | 55 | */ |
8bbe427f | 56 | |
e52f60e6 RR |
57 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) |
58 | { | |
59 | win->m_sizeSet = FALSE; | |
60 | win->m_width = alloc->width; | |
61 | win->m_height = alloc->height; | |
62 | } | |
362c6693 | 63 | } |
c801d85f KB |
64 | |
65 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
66 | // "delete_event" |
67 | //----------------------------------------------------------------------------- | |
c801d85f | 68 | |
2f2aa628 | 69 | static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) |
ed7a557b | 70 | { |
c801d85f | 71 | /* |
fb1585ae RR |
72 | printf( "OnDelete from " ); |
73 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
74 | printf( win->GetClassInfo()->GetClassName() ); | |
75 | printf( ".\n" ); | |
c801d85f | 76 | */ |
ed7a557b | 77 | |
fb1585ae | 78 | win->Close(); |
c801d85f | 79 | |
fb1585ae | 80 | return TRUE; |
362c6693 | 81 | } |
c801d85f | 82 | |
47908e25 | 83 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
84 | // "configure_event" |
85 | //----------------------------------------------------------------------------- | |
47908e25 | 86 | |
2f2aa628 | 87 | static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) |
47908e25 | 88 | { |
fb1585ae | 89 | if (!win->HasVMT()) return FALSE; |
8bbe427f | 90 | |
fb1585ae RR |
91 | win->m_x = event->x; |
92 | win->m_y = event->y; | |
8bbe427f | 93 | |
fb1585ae | 94 | return FALSE; |
362c6693 | 95 | } |
47908e25 | 96 | |
2f2aa628 RR |
97 | //----------------------------------------------------------------------------- |
98 | // wxFrame | |
c801d85f KB |
99 | //----------------------------------------------------------------------------- |
100 | ||
101 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
fb1585ae RR |
102 | EVT_SIZE(wxFrame::OnSize) |
103 | EVT_CLOSE(wxFrame::OnCloseWindow) | |
104 | EVT_IDLE(wxFrame::OnIdle) | |
c801d85f KB |
105 | END_EVENT_TABLE() |
106 | ||
107 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
108 | ||
19717c50 | 109 | wxFrame::wxFrame() |
c801d85f | 110 | { |
fb1585ae RR |
111 | m_frameMenuBar = (wxMenuBar *) NULL; |
112 | m_frameStatusBar = (wxStatusBar *) NULL; | |
113 | m_frameToolBar = (wxToolBar *) NULL; | |
114 | m_sizeSet = FALSE; | |
b2b3ccc5 RR |
115 | m_miniEdge = 0; |
116 | m_miniTitle = 0; | |
362c6693 | 117 | } |
c801d85f | 118 | |
ed7a557b | 119 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
120 | const wxPoint &pos, const wxSize &size, |
121 | long style, const wxString &name ) | |
c801d85f | 122 | { |
fb1585ae RR |
123 | m_frameMenuBar = (wxMenuBar *) NULL; |
124 | m_frameStatusBar = (wxStatusBar *) NULL; | |
125 | m_frameToolBar = (wxToolBar *) NULL; | |
126 | m_sizeSet = FALSE; | |
b2b3ccc5 RR |
127 | m_miniEdge = 0; |
128 | m_miniTitle = 0; | |
fb1585ae | 129 | Create( parent, id, title, pos, size, style, name ); |
362c6693 | 130 | } |
c801d85f | 131 | |
debe6624 | 132 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 133 | const wxPoint &pos, const wxSize &size, |
debe6624 | 134 | long style, const wxString &name ) |
c801d85f | 135 | { |
a802c3a1 | 136 | wxTopLevelWindows.Append( this ); |
8bbe427f | 137 | |
fb1585ae | 138 | m_needParent = FALSE; |
ed7a557b | 139 | |
fb1585ae | 140 | PreCreation( parent, id, pos, size, style, name ); |
c801d85f | 141 | |
fb1585ae | 142 | m_title = title; |
ed7a557b | 143 | |
fb1585ae RR |
144 | GtkWindowType win_type = GTK_WINDOW_TOPLEVEL; |
145 | if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP; | |
8bbe427f | 146 | |
fb1585ae | 147 | m_widget = gtk_window_new( win_type ); |
8bbe427f | 148 | |
b292e2f5 RR |
149 | #ifdef __WXDEBUG__ |
150 | debug_focus_in( m_widget, "wxFrame::m_widget", name ); | |
151 | #endif | |
152 | ||
fb1585ae RR |
153 | if ((size.x != -1) && (size.y != -1)) |
154 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
155 | if ((pos.x != -1) && (pos.y != -1)) | |
156 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
ed7a557b | 157 | |
fb1585ae RR |
158 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); |
159 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
ed7a557b | 160 | |
fb1585ae | 161 | gtk_widget_set( m_widget, "GtkWindow::allow_shrink", TRUE, NULL ); |
ed7a557b | 162 | |
fb1585ae RR |
163 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
164 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); | |
ed7a557b | 165 | |
fb1585ae RR |
166 | m_wxwindow = gtk_myfixed_new(); |
167 | gtk_widget_show( m_wxwindow ); | |
168 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 169 | |
b292e2f5 RR |
170 | #ifdef __WXDEBUG__ |
171 | debug_focus_in( m_wxwindow, "wxFrame::m_wxwindow", name ); | |
172 | #endif | |
173 | ||
fb1585ae | 174 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
ed7a557b | 175 | |
fb1585ae RR |
176 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", |
177 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); | |
ed7a557b | 178 | |
fb1585ae RR |
179 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
180 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
8bbe427f | 181 | |
fb1585ae | 182 | if (m_parent) m_parent->AddChild( this ); |
8bbe427f | 183 | |
fb1585ae | 184 | PostCreation(); |
8bbe427f | 185 | |
fb1585ae | 186 | return TRUE; |
362c6693 | 187 | } |
c801d85f | 188 | |
19717c50 | 189 | wxFrame::~wxFrame() |
c801d85f | 190 | { |
fb1585ae RR |
191 | if (m_frameMenuBar) delete m_frameMenuBar; |
192 | if (m_frameStatusBar) delete m_frameStatusBar; | |
193 | if (m_frameToolBar) delete m_frameToolBar; | |
ed7a557b | 194 | |
fb1585ae RR |
195 | wxTopLevelWindows.DeleteObject( this ); |
196 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
362c6693 | 197 | } |
ed7a557b | 198 | |
debe6624 | 199 | bool wxFrame::Show( bool show ) |
c801d85f | 200 | { |
fb1585ae | 201 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 202 | |
35178437 | 203 | if (show && !m_sizeSet) |
fb1585ae | 204 | { |
8bbe427f VZ |
205 | // by calling GtkOnSize here, we don't have to call |
206 | // either after showing the frame, which would entail | |
207 | // much ugly flicker nor from within the size_allocate | |
208 | // handler, because GTK 1.1.X forbids that. | |
209 | ||
35178437 | 210 | GtkOnSize( m_x, m_y, m_width, m_height ); |
fb1585ae | 211 | } |
8bbe427f | 212 | |
fb1585ae | 213 | return wxWindow::Show( show ); |
362c6693 | 214 | } |
c801d85f | 215 | |
716b7364 | 216 | void wxFrame::OnCloseWindow( wxCloseEvent &event ) |
c801d85f | 217 | { |
fb1585ae | 218 | if (GetEventHandler()->OnClose() || event.GetForce()) this->Destroy(); |
362c6693 | 219 | } |
c801d85f | 220 | |
19717c50 | 221 | bool wxFrame::Destroy() |
c801d85f | 222 | { |
fb1585ae | 223 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 224 | |
fb1585ae | 225 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); |
ed7a557b | 226 | |
fb1585ae | 227 | return TRUE; |
c801d85f KB |
228 | } |
229 | ||
6ca41e57 RR |
230 | wxPoint wxFrame::GetClientAreaOrigin() const |
231 | { | |
b2b3ccc5 | 232 | wxPoint pt( m_miniEdge, m_miniEdge + m_miniTitle ); |
fb1585ae RR |
233 | if (m_frameMenuBar) |
234 | { | |
235 | int h = 0; | |
236 | m_frameMenuBar->GetSize( (int*)NULL, &h ); | |
907789a0 | 237 | pt.y += h; |
fb1585ae RR |
238 | } |
239 | if (m_frameToolBar) | |
240 | { | |
241 | int h = 0; | |
242 | m_frameToolBar->GetSize( (int*)NULL, &h ); | |
243 | pt.y += h; | |
244 | } | |
245 | return pt; | |
6ca41e57 RR |
246 | } |
247 | ||
fb1585ae | 248 | void wxFrame::SetSize( int x, int y, int width, int height, int sizeFlags ) |
903f689b | 249 | { |
fb1585ae | 250 | wxASSERT_MSG( (m_widget != NULL), "invalid window" ); |
8bbe427f | 251 | |
fb1585ae RR |
252 | // Don't do anything for children of wxMDIChildFrame |
253 | if (!m_wxwindow) return; | |
254 | ||
255 | if (m_resizing) return; // I don't like recursions | |
256 | m_resizing = TRUE; | |
257 | ||
258 | int old_x = m_x; | |
259 | int old_y = m_y; | |
260 | int old_width = m_width; | |
261 | int old_height = m_height; | |
8bbe427f | 262 | |
fb1585ae RR |
263 | if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) |
264 | { | |
265 | if (x != -1) m_x = x; | |
266 | if (y != -1) m_y = y; | |
267 | if (width != -1) m_width = width; | |
268 | if (height != -1) m_height = height; | |
269 | } | |
270 | else | |
271 | { | |
272 | m_x = x; | |
273 | m_y = y; | |
274 | m_width = width; | |
275 | m_height = height; | |
276 | } | |
277 | ||
278 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) | |
279 | { | |
280 | if (width == -1) m_width = 80; | |
281 | } | |
282 | ||
283 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
284 | { | |
285 | if (height == -1) m_height = 26; | |
286 | } | |
8bbe427f | 287 | |
fb1585ae RR |
288 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
289 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
290 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; | |
291 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; | |
292 | ||
293 | if ((m_x != -1) || (m_y != -1)) | |
294 | { | |
8bbe427f | 295 | if ((m_x != old_x) || (m_y != old_y)) |
fb1585ae RR |
296 | gtk_widget_set_uposition( m_widget, m_x, m_y ); |
297 | } | |
8bbe427f | 298 | |
fb1585ae RR |
299 | if ((m_width != old_width) || (m_height != old_height)) |
300 | { | |
301 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
302 | } | |
8bbe427f | 303 | |
fb1585ae RR |
304 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
305 | event.SetEventObject( this ); | |
e52f60e6 | 306 | GetEventHandler()->ProcessEvent( event ); |
fb1585ae RR |
307 | |
308 | m_resizing = FALSE; | |
903f689b RR |
309 | } |
310 | ||
43a18898 RR |
311 | void wxFrame::SetSize( int width, int height ) |
312 | { | |
313 | SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); | |
314 | } | |
315 | ||
903f689b RR |
316 | void wxFrame::Centre( int direction ) |
317 | { | |
fb1585ae | 318 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 319 | |
43a18898 RR |
320 | int x = 0; |
321 | int y = 0; | |
8bbe427f | 322 | |
fb1585ae RR |
323 | if (direction & wxHORIZONTAL == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; |
324 | if (direction & wxVERTICAL == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
8bbe427f | 325 | |
fb1585ae | 326 | Move( x, y ); |
903f689b RR |
327 | } |
328 | ||
c801d85f KB |
329 | void wxFrame::GetClientSize( int *width, int *height ) const |
330 | { | |
fb1585ae | 331 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 332 | |
fb1585ae RR |
333 | wxWindow::GetClientSize( width, height ); |
334 | if (height) | |
46dc76ba | 335 | { |
fb1585ae RR |
336 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; |
337 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
338 | if (m_frameToolBar) | |
339 | { | |
340 | int y = 0; | |
341 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
342 | (*height) -= y; | |
343 | } | |
b2b3ccc5 RR |
344 | (*height) -= m_miniEdge*2 + m_miniTitle; |
345 | } | |
346 | if (width) | |
347 | { | |
348 | (*width) -= m_miniEdge*2; | |
46dc76ba | 349 | } |
362c6693 | 350 | } |
c801d85f | 351 | |
b593568e RR |
352 | void wxFrame::SetClientSize( int const width, int const height ) |
353 | { | |
f5368809 | 354 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 355 | |
f5368809 RR |
356 | int h = height; |
357 | if (m_frameMenuBar) h += wxMENU_HEIGHT; | |
358 | if (m_frameStatusBar) h += wxSTATUS_HEIGHT; | |
359 | if (m_frameToolBar) | |
360 | { | |
361 | int y = 0; | |
362 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
363 | h += y; | |
364 | } | |
b2b3ccc5 | 365 | wxWindow::SetClientSize( width + m_miniEdge*2, h + m_miniEdge*2 + m_miniTitle ); |
362c6693 | 366 | } |
b593568e | 367 | |
47908e25 | 368 | void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
c801d85f | 369 | { |
f5368809 RR |
370 | // due to a bug in gtk, x,y are always 0 |
371 | // m_x = x; | |
372 | // m_y = y; | |
373 | ||
e52f60e6 RR |
374 | if (m_resizing) return; |
375 | m_resizing = TRUE; | |
8bbe427f | 376 | |
f5368809 | 377 | if (!m_wxwindow) return; |
8bbe427f | 378 | |
f5368809 RR |
379 | m_width = width; |
380 | m_height = height; | |
8bbe427f | 381 | |
f5368809 RR |
382 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
383 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
384 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth; | |
385 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight; | |
386 | ||
7f985bd3 | 387 | gtk_widget_set_usize( m_widget, m_width, m_height ); |
8bbe427f | 388 | |
b2b3ccc5 RR |
389 | // this emulates the new wxMSW behaviour of placing all |
390 | // frame-subwindows (menu, toolbar..) on one native window | |
391 | // OK, this hurts in the eye, but I don't want to call SetSize() | |
392 | // because I don't want to call any non-native functions here. | |
8bbe427f | 393 | |
f5368809 RR |
394 | if (m_frameMenuBar) |
395 | { | |
907789a0 | 396 | int xx = m_miniEdge; |
ac57418f RR |
397 | int yy = m_miniEdge + m_miniTitle; |
398 | int ww = m_width - 2*m_miniEdge; | |
399 | int hh = wxMENU_HEIGHT; | |
b2b3ccc5 RR |
400 | m_frameMenuBar->m_x = xx; |
401 | m_frameMenuBar->m_y = yy; | |
402 | m_frameMenuBar->m_width = ww; | |
403 | m_frameMenuBar->m_height = hh; | |
8bbe427f | 404 | |
b2b3ccc5 RR |
405 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, xx, yy ); |
406 | gtk_widget_set_usize( m_frameMenuBar->m_widget, ww, hh ); | |
f5368809 RR |
407 | } |
408 | ||
409 | if (m_frameToolBar) | |
410 | { | |
907789a0 | 411 | int xx = m_miniEdge; |
ac57418f | 412 | int yy = m_miniEdge + m_miniTitle; |
b2b3ccc5 | 413 | if (m_frameMenuBar) yy += wxMENU_HEIGHT; |
ac57418f | 414 | int ww = m_width - 2*m_miniEdge; |
b2b3ccc5 | 415 | int hh = m_frameToolBar->m_height; |
8bbe427f VZ |
416 | |
417 | m_frameToolBar->m_x = xx; | |
b2b3ccc5 RR |
418 | m_frameToolBar->m_y = yy; |
419 | m_frameToolBar->m_height = hh; | |
420 | m_frameToolBar->m_width = ww; | |
8bbe427f | 421 | |
b2b3ccc5 RR |
422 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, xx, yy ); |
423 | gtk_widget_set_usize( m_frameToolBar->m_widget, ww, hh ); | |
f5368809 | 424 | } |
8bbe427f | 425 | |
f5368809 RR |
426 | if (m_frameStatusBar) |
427 | { | |
b2b3ccc5 | 428 | int xx = 0 + m_miniEdge; |
ac57418f RR |
429 | int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge; |
430 | int ww = m_width - 2*m_miniEdge; | |
431 | int hh = wxSTATUS_HEIGHT; | |
8bbe427f | 432 | |
b2b3ccc5 RR |
433 | m_frameStatusBar->m_x = xx; |
434 | m_frameStatusBar->m_y = yy; | |
435 | m_frameStatusBar->m_width = ww; | |
436 | m_frameStatusBar->m_height = hh; | |
8bbe427f | 437 | |
b2b3ccc5 RR |
438 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, xx, yy ); |
439 | gtk_widget_set_usize( m_frameStatusBar->m_widget, ww, hh ); | |
f5368809 | 440 | } |
8bbe427f | 441 | |
f5368809 | 442 | m_sizeSet = TRUE; |
8bbe427f | 443 | |
43a18898 RR |
444 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
445 | event.SetEventObject( this ); | |
e52f60e6 | 446 | GetEventHandler()->ProcessEvent( event ); |
8bbe427f | 447 | |
e52f60e6 RR |
448 | m_resizing = FALSE; |
449 | } | |
450 | ||
451 | void wxFrame::OnIdle(wxIdleEvent& WXUNUSED(event) ) | |
452 | { | |
453 | if (!m_sizeSet) | |
454 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
8bbe427f | 455 | |
e52f60e6 | 456 | DoMenuUpdates(); |
362c6693 | 457 | } |
c801d85f KB |
458 | |
459 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
460 | { | |
f5368809 | 461 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 462 | |
f5368809 RR |
463 | if (GetAutoLayout()) |
464 | { | |
465 | Layout(); | |
466 | } | |
8bbe427f | 467 | else |
c801d85f | 468 | { |
f5368809 | 469 | // no child: go out ! |
db1b4961 | 470 | if (!GetChildren().First()) return; |
8bbe427f | 471 | |
f5368809 RR |
472 | // do we have exactly one child? |
473 | wxWindow *child = (wxWindow *) NULL; | |
db1b4961 | 474 | for(wxNode *node = GetChildren().First(); node; node = node->Next()) |
f5368809 RR |
475 | { |
476 | wxWindow *win = (wxWindow *)node->Data(); | |
de135918 | 477 | if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) |
6ca41e57 | 478 | #if 0 // not in m_children anyway ? |
f5368809 RR |
479 | && (win != m_frameMenuBar) && |
480 | (win != m_frameToolBar) && | |
481 | (win != m_frameStatusBar) | |
ed7a557b | 482 | #endif |
f5368809 RR |
483 | ) |
484 | { | |
8bbe427f | 485 | // it's the second one: do nothing |
f5368809 RR |
486 | if (child) return; |
487 | child = win; | |
488 | } | |
489 | } | |
ed7a557b | 490 | |
f5368809 RR |
491 | // yes: set it's size to fill all the frame |
492 | int client_x, client_y; | |
493 | GetClientSize( &client_x, &client_y ); | |
7be4c594 | 494 | child->SetSize( 1, 1, client_x-2, client_y-2 ); |
362c6693 | 495 | } |
362c6693 | 496 | } |
c801d85f | 497 | |
716b7364 | 498 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
c801d85f | 499 | { |
f5368809 RR |
500 | menu->SetInvokingWindow( win ); |
501 | wxNode *node = menu->m_items.First(); | |
502 | while (node) | |
503 | { | |
504 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
505 | if (menuitem->IsSubMenu()) | |
506 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
507 | node = node->Next(); | |
508 | } | |
362c6693 | 509 | } |
c801d85f KB |
510 | |
511 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
512 | { | |
f5368809 RR |
513 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
514 | wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); | |
8bbe427f | 515 | |
f5368809 | 516 | m_frameMenuBar = menuBar; |
8bbe427f | 517 | |
f5368809 | 518 | if (m_frameMenuBar) |
30dea054 | 519 | { |
f5368809 RR |
520 | wxNode *node = m_frameMenuBar->m_menus.First(); |
521 | while (node) | |
522 | { | |
523 | wxMenu *menu = (wxMenu*)node->Data(); | |
524 | SetInvokingWindow( menu, this ); | |
525 | node = node->Next(); | |
526 | } | |
8bbe427f | 527 | |
f5368809 RR |
528 | if (m_frameMenuBar->m_parent != this) |
529 | { | |
530 | m_frameMenuBar->m_parent = this; | |
531 | gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), | |
532 | m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); | |
533 | } | |
716b7364 | 534 | } |
8bbe427f | 535 | |
7be4c594 | 536 | if (m_sizeSet) GtkOnSize( m_x, m_y, m_width, m_height ); |
362c6693 | 537 | } |
c801d85f | 538 | |
8bbe427f | 539 | wxMenuBar *wxFrame::GetMenuBar() const |
46dc76ba | 540 | { |
f5368809 | 541 | return m_frameMenuBar; |
362c6693 | 542 | } |
46dc76ba | 543 | |
362c6693 | 544 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
46dc76ba | 545 | { |
f5368809 | 546 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 547 | |
f5368809 | 548 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" ); |
362c6693 | 549 | |
f5368809 | 550 | m_frameToolBar = OnCreateToolBar( style, id, name ); |
8bbe427f | 551 | |
db1b4961 | 552 | GetChildren().DeleteObject( m_frameToolBar ); |
8bbe427f | 553 | |
7be4c594 | 554 | if (m_sizeSet) GtkOnSize( m_x, m_y, m_width, m_height ); |
8bbe427f | 555 | |
f5368809 | 556 | return m_frameToolBar; |
362c6693 | 557 | } |
46dc76ba | 558 | |
362c6693 | 559 | wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name ) |
46dc76ba | 560 | { |
f5368809 | 561 | return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); |
362c6693 RR |
562 | } |
563 | ||
8bbe427f VZ |
564 | wxToolBar *wxFrame::GetToolBar() const |
565 | { | |
566 | return m_frameToolBar; | |
362c6693 | 567 | } |
46dc76ba | 568 | |
e3e65dac | 569 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) |
c801d85f | 570 | { |
f5368809 | 571 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 572 | |
f5368809 | 573 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, "recreating status bar in wxFrame" ); |
c801d85f | 574 | |
f5368809 | 575 | m_frameStatusBar = OnCreateStatusBar( number, style, id, name ); |
8bbe427f | 576 | |
7be4c594 | 577 | if (m_sizeSet) GtkOnSize( m_x, m_y, m_width, m_height ); |
8bbe427f | 578 | |
f5368809 | 579 | return m_frameStatusBar; |
362c6693 RR |
580 | } |
581 | ||
582 | wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
583 | { | |
f5368809 | 584 | wxStatusBar *statusBar = (wxStatusBar *) NULL; |
8bbe427f | 585 | |
f5368809 | 586 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name); |
8bbe427f | 587 | |
f5368809 RR |
588 | // Set the height according to the font and the border size |
589 | wxClientDC dc(statusBar); | |
8bbe427f | 590 | dc.SetFont( statusBar->GetFont() ); |
362c6693 | 591 | |
f5368809 RR |
592 | long x, y; |
593 | dc.GetTextExtent( "X", &x, &y ); | |
362c6693 | 594 | |
f5368809 | 595 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); |
362c6693 | 596 | |
f5368809 | 597 | statusBar->SetSize( -1, -1, 100, height ); |
362c6693 | 598 | |
f5368809 RR |
599 | statusBar->SetFieldsCount( number ); |
600 | return statusBar; | |
362c6693 | 601 | } |
c801d85f | 602 | |
362c6693 | 603 | void wxFrame::SetStatusText(const wxString& text, int number) |
c801d85f | 604 | { |
f5368809 | 605 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 606 | |
f5368809 | 607 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); |
c801d85f | 608 | |
f5368809 | 609 | m_frameStatusBar->SetStatusText(text, number); |
362c6693 RR |
610 | } |
611 | ||
612 | void wxFrame::SetStatusWidths(int n, const int widths_field[] ) | |
c801d85f | 613 | { |
f5368809 | 614 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 615 | |
f5368809 | 616 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); |
362c6693 | 617 | |
f5368809 | 618 | m_frameStatusBar->SetStatusWidths(n, widths_field); |
362c6693 | 619 | } |
c801d85f | 620 | |
8bbe427f | 621 | wxStatusBar *wxFrame::GetStatusBar() const |
c801d85f | 622 | { |
f5368809 | 623 | return m_frameStatusBar; |
362c6693 | 624 | } |
c801d85f | 625 | |
c801d85f KB |
626 | void wxFrame::SetTitle( const wxString &title ) |
627 | { | |
f5368809 | 628 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 629 | |
f5368809 RR |
630 | m_title = title; |
631 | if (m_title.IsNull()) m_title = ""; | |
632 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
362c6693 | 633 | } |
c801d85f | 634 | |
d355d3fe RR |
635 | void wxFrame::SetIcon( const wxIcon &icon ) |
636 | { | |
f5368809 | 637 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 638 | |
f5368809 RR |
639 | m_icon = icon; |
640 | if (!icon.Ok()) return; | |
8bbe427f | 641 | |
f5368809 RR |
642 | wxMask *mask = icon.GetMask(); |
643 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
644 | if (mask) bm = mask->GetBitmap(); | |
8bbe427f | 645 | |
f5368809 | 646 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
d355d3fe | 647 | } |
b2b3ccc5 | 648 |