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