]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/frame.cpp
Fixed [ 1556843 ] wxGTK FindFocus returns NULL when a wxListBox is focused
[wxWidgets.git] / src / gtk / frame.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/gtk/frame.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
93763ad5
WS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
e1bf3ad3 13#include "wx/frame.h"
670f9935
WS
14
15#ifndef WX_PRECOMP
3b3dc801 16 #include "wx/menu.h"
4e3e485b 17 #include "wx/toolbar.h"
7c0ea335 18 #include "wx/statusbr.h"
3304646d 19#endif // WX_PRECOMP
83624f79 20
9e691f46 21#include "wx/gtk/private.h"
c801d85f
KB
22#include "wx/gtk/win_gtk.h"
23
7c0ea335 24// ----------------------------------------------------------------------------
2f2aa628 25// constants
7c0ea335 26// ----------------------------------------------------------------------------
2f2aa628 27
c1fa6f52
PC
28static const int wxSTATUS_HEIGHT = 25;
29static const int wxPLACE_HOLDER = 0;
c801d85f 30
7c0ea335
VZ
31// ----------------------------------------------------------------------------
32// event tables
33// ----------------------------------------------------------------------------
34
0d53fc34 35IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2e563988 36
7c0ea335
VZ
37// ============================================================================
38// implementation
39// ============================================================================
40
41// ----------------------------------------------------------------------------
42// GTK callbacks
43// ----------------------------------------------------------------------------
44
6522713c
VZ
45#if wxUSE_MENUS_NATIVE
46
16bcc879
RR
47//-----------------------------------------------------------------------------
48// "child_attached" of menu bar
49//-----------------------------------------------------------------------------
50
865bb325 51extern "C" {
0d53fc34 52static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 53{
a2053b27 54 if (!win->m_hasVMT) return;
88ac883a 55
91af0895 56 win->m_menuBarDetached = false;
5b8a521e 57 win->GtkUpdateSize();
16bcc879 58}
865bb325 59}
16bcc879
RR
60
61//-----------------------------------------------------------------------------
62// "child_detached" of menu bar
63//-----------------------------------------------------------------------------
64
865bb325 65extern "C" {
0d53fc34 66static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 67{
047ac72b
RR
68 if (g_isIdle)
69 wxapp_install_idle_handler();
70
a2053b27 71 if (!win->m_hasVMT) return;
88ac883a 72
047ac72b
RR
73 // Raise the client area area
74 gdk_window_raise( win->m_wxwindow->window );
75
91af0895 76 win->m_menuBarDetached = true;
5b8a521e 77 win->GtkUpdateSize();
16bcc879 78}
865bb325 79}
6522713c
VZ
80
81#endif // wxUSE_MENUS_NATIVE
16bcc879 82
88ac883a 83#if wxUSE_TOOLBAR
16bcc879
RR
84//-----------------------------------------------------------------------------
85// "child_attached" of tool bar
86//-----------------------------------------------------------------------------
87
865bb325 88extern "C" {
0d53fc34 89static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 90{
a2053b27 91 if (!win->m_hasVMT) return;
88ac883a 92
91af0895 93 win->m_toolBarDetached = false;
5b8a521e 94 win->GtkUpdateSize();
16bcc879 95}
865bb325 96}
16bcc879
RR
97
98//-----------------------------------------------------------------------------
99// "child_detached" of tool bar
100//-----------------------------------------------------------------------------
101
865bb325 102extern "C" {
0d53fc34 103static void gtk_toolbar_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 104{
88ac883a 105 if (g_isIdle)
801aa178 106 wxapp_install_idle_handler();
acfd422a 107
a2053b27 108 if (!win->m_hasVMT) return;
88ac883a 109
047ac72b
RR
110 // Raise the client area area
111 gdk_window_raise( win->m_wxwindow->window );
112
91af0895 113 win->m_toolBarDetached = true;
5b8a521e 114 win->GtkUpdateSize();
16bcc879 115}
865bb325 116}
88ac883a 117#endif // wxUSE_TOOLBAR
16bcc879 118
117247fd 119
7c0ea335 120// ----------------------------------------------------------------------------
0d53fc34 121// wxFrame itself
7c0ea335
VZ
122// ----------------------------------------------------------------------------
123
f362b96d 124//-----------------------------------------------------------------------------
0d53fc34 125// InsertChild for wxFrame
f362b96d
RR
126//-----------------------------------------------------------------------------
127
0d53fc34 128/* Callback for wxFrame. This very strange beast has to be used because
f362b96d 129 * C++ has no virtual methods in a constructor. We have to emulate a
77ffb593 130 * virtual function here as wxWidgets requires different ways to insert
f362b96d
RR
131 * a child in container classes. */
132
0d53fc34 133static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child )
f362b96d 134{
5fd11f09 135 wxASSERT( GTK_IS_WIDGET(child->m_widget) );
7beba2fc 136
6bc8a1c8 137 if (!parent->m_insertInClientArea)
f362b96d 138 {
047ac72b 139 // These are outside the client area
0d53fc34 140 wxFrame* frame = (wxFrame*) parent;
da048e3d 141 gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget),
a2053b27
RR
142 GTK_WIDGET(child->m_widget),
143 child->m_x,
144 child->m_y,
145 child->m_width,
146 child->m_height );
91af0895 147
caf51f95 148#if wxUSE_TOOLBAR_NATIVE
047ac72b
RR
149 // We connect to these events for recalculating the client area
150 // space when the toolbar is floating
f03fc89f
VZ
151 if (wxIS_KIND_OF(child,wxToolBar))
152 {
153 wxToolBar *toolBar = (wxToolBar*) child;
154 if (toolBar->GetWindowStyle() & wxTB_DOCKABLE)
155 {
9fa72bd2
MR
156 g_signal_connect (toolBar->m_widget, "child_attached",
157 G_CALLBACK (gtk_toolbar_attached_callback),
158 parent);
159 g_signal_connect (toolBar->m_widget, "child_detached",
160 G_CALLBACK (gtk_toolbar_detached_callback),
161 parent);
f03fc89f
VZ
162 }
163 }
88ac883a 164#endif // wxUSE_TOOLBAR
f362b96d
RR
165 }
166 else
167 {
047ac72b 168 // These are inside the client area
da048e3d 169 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
a2053b27
RR
170 GTK_WIDGET(child->m_widget),
171 child->m_x,
172 child->m_y,
173 child->m_width,
174 child->m_height );
f362b96d 175 }
f362b96d
RR
176}
177
7c0ea335 178// ----------------------------------------------------------------------------
0d53fc34 179// wxFrame creation
7c0ea335 180// ----------------------------------------------------------------------------
c801d85f 181
0d53fc34 182void wxFrame::Init()
c801d85f 183{
91af0895
WS
184 m_menuBarDetached = false;
185 m_toolBarDetached = false;
2b5f62a0 186 m_menuBarHeight = 2;
362c6693 187}
c801d85f 188
0d53fc34 189bool wxFrame::Create( wxWindow *parent,
7c0ea335 190 wxWindowID id,
ca8bf976
VZ
191 const wxString& title,
192 const wxPoint& pos,
193 const wxSize& sizeOrig,
7c0ea335
VZ
194 long style,
195 const wxString &name )
c801d85f 196{
7b4c2a06 197 bool rt = wxTopLevelWindow::Create(parent, id, title, pos, sizeOrig,
7d9f12f3 198 style, name);
6bc8a1c8 199 m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame;
91af0895 200
7d9f12f3 201 return rt;
362c6693 202}
c801d85f 203
0d53fc34 204wxFrame::~wxFrame()
c801d85f 205{
91af0895 206 m_isBeingDeleted = true;
7c0ea335 207 DeleteAllBars();
3d0c4d2e
RR
208}
209
7c0ea335
VZ
210// ----------------------------------------------------------------------------
211// overridden wxWindow methods
212// ----------------------------------------------------------------------------
213
0d53fc34 214void wxFrame::DoGetClientSize( int *width, int *height ) const
c801d85f 215{
223d09f6 216 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
7b4c2a06 217
7d9f12f3 218 wxTopLevelWindow::DoGetClientSize( width, height );
8bbe427f 219
fb1585ae 220 if (height)
46dc76ba 221 {
75c9da25 222#if wxUSE_MENUS_NATIVE
047ac72b 223 // menu bar
41ca191f 224 if (m_frameMenuBar)
f03fc89f 225 {
88ac883a 226 if (!m_menuBarDetached)
2b5f62a0 227 (*height) -= m_menuBarHeight;
f03fc89f
VZ
228 else
229 (*height) -= wxPLACE_HOLDER;
230 }
75c9da25 231#endif // wxUSE_MENUS_NATIVE
88ac883a 232
dcf924a3 233#if wxUSE_STATUSBAR
047ac72b 234 // status bar
7b4c2a06 235 if (m_frameStatusBar && m_frameStatusBar->IsShown())
7d9f12f3 236 (*height) -= wxSTATUS_HEIGHT;
93fa69f8 237#endif // wxUSE_STATUSBAR
c1fa6f52 238 }
88ac883a 239
dcf924a3 240#if wxUSE_TOOLBAR
c1fa6f52
PC
241 // tool bar
242 if (m_frameToolBar && m_frameToolBar->IsShown())
243 {
244 if (m_toolBarDetached)
fb1585ae 245 {
c1fa6f52 246 if (height != NULL)
93fa69f8 247 *height -= wxPLACE_HOLDER;
c1fa6f52
PC
248 }
249 else
250 {
251 int x, y;
252 m_frameToolBar->GetSize( &x, &y );
253 if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL )
254 {
255 if (width != NULL)
256 *width -= x;
f03fc89f
VZ
257 }
258 else
93fa69f8 259 {
c1fa6f52 260 if (height != NULL)
93fa69f8 261 *height -= y;
93fa69f8 262 }
fb1585ae 263 }
46dc76ba 264 }
c1fa6f52
PC
265#endif // wxUSE_TOOLBAR
266
267 if (width != NULL && *width < 0)
268 *width = 0;
269 if (height != NULL && *height < 0)
270 *height = 0;
362c6693 271}
c801d85f 272
0d53fc34 273void wxFrame::DoSetClientSize( int width, int height )
b593568e 274{
223d09f6 275 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 276
75c9da25 277#if wxUSE_MENUS_NATIVE
047ac72b 278 // menu bar
41ca191f 279 if (m_frameMenuBar)
f03fc89f 280 {
88ac883a 281 if (!m_menuBarDetached)
2b5f62a0 282 height += m_menuBarHeight;
f03fc89f
VZ
283 else
284 height += wxPLACE_HOLDER;
285 }
75c9da25 286#endif // wxUSE_MENUS_NATIVE
88ac883a 287
dcf924a3 288#if wxUSE_STATUSBAR
047ac72b 289 // status bar
fa755cf1 290 if (m_frameStatusBar && m_frameStatusBar->IsShown()) height += wxSTATUS_HEIGHT;
dcf924a3 291#endif
88ac883a 292
dcf924a3 293#if wxUSE_TOOLBAR
047ac72b 294 // tool bar
fa755cf1 295 if (m_frameToolBar && m_frameToolBar->IsShown())
41ca191f 296 {
93fa69f8 297 if (m_toolBarDetached)
f03fc89f 298 {
93fa69f8 299 height += wxPLACE_HOLDER;
f03fc89f
VZ
300 }
301 else
93fa69f8
VZ
302 {
303 int x, y;
304 m_frameToolBar->GetSize( &x, &y );
305 if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL )
306 {
307 width += x;
308 }
309 else
310 {
311 height += y;
312 }
313 }
41ca191f 314 }
dcf924a3 315#endif
88ac883a 316
7d9f12f3 317 wxTopLevelWindow::DoSetClientSize( width, height );
362c6693 318}
b593568e 319
b5e31cc8 320void wxFrame::GtkOnSize()
c801d85f 321{
047ac72b 322 // avoid recursions
e52f60e6 323 if (m_resizing) return;
91af0895 324 m_resizing = true;
8bbe427f 325
047ac72b 326 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
223d09f6 327 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
88ac883a 328
047ac72b 329 // space occupied by m_frameToolBar and m_frameMenuBar
93fa69f8
VZ
330 int client_area_x_offset = 0,
331 client_area_y_offset = 0;
8bbe427f 332
0d53fc34 333 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
ab2b3dd4 334 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
0d53fc34 335 set in wxFrame::Create so it is used to check what kind of frame we
ab2b3dd4
RR
336 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
337 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
338 importantly) m_mainWidget */
88ac883a 339
e7dda1ff
VS
340 int minWidth = GetMinWidth(),
341 minHeight = GetMinHeight(),
342 maxWidth = GetMaxWidth(),
343 maxHeight = GetMaxHeight();
344
345 if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth;
346 if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight;
347 if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth;
348 if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight;
1f3c610d 349
ab2b3dd4 350 if (m_mainWidget)
f5368809 351 {
047ac72b 352 // set size hints
f6bcfd97 353 gint flag = 0; // GDK_HINT_POS;
e7dda1ff
VS
354 if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE;
355 if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE;
f6bcfd97 356 GdkGeometry geom;
e7dda1ff
VS
357 geom.min_width = minWidth;
358 geom.min_height = minHeight;
359 geom.max_width = maxWidth;
360 geom.max_height = maxHeight;
f6bcfd97
BP
361 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
362 (GtkWidget*) NULL,
363 &geom,
364 (GdkWindowHints) flag );
ab2b3dd4 365
047ac72b
RR
366 // I revert back to wxGTK's original behaviour. m_mainWidget holds
367 // the menubar, the toolbar and the client area, which is represented
368 // by m_wxwindow.
369 // This hurts in the eye, but I don't want to call SetSize()
370 // because I don't want to call any non-native functions here.
88ac883a 371
75c9da25 372#if wxUSE_MENUS_NATIVE
ab2b3dd4
RR
373 if (m_frameMenuBar)
374 {
375 int xx = m_miniEdge;
376 int yy = m_miniEdge + m_miniTitle;
377 int ww = m_width - 2*m_miniEdge;
9cf7a6c0
PC
378 if (ww < 0)
379 ww = 0;
2b5f62a0 380 int hh = m_menuBarHeight;
f03fc89f 381 if (m_menuBarDetached) hh = wxPLACE_HOLDER;
121a3581
RR
382 m_frameMenuBar->m_x = xx;
383 m_frameMenuBar->m_y = yy;
384 m_frameMenuBar->m_width = ww;
385 m_frameMenuBar->m_height = hh;
da048e3d 386 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
88ac883a 387 m_frameMenuBar->m_widget,
f03fc89f
VZ
388 xx, yy, ww, hh );
389 client_area_y_offset += hh;
ab2b3dd4 390 }
75c9da25 391#endif // wxUSE_MENUS_NATIVE
88ac883a 392
dcf924a3 393#if wxUSE_TOOLBAR
fa755cf1 394 if ((m_frameToolBar) && m_frameToolBar->IsShown() &&
7beba2fc 395 (m_frameToolBar->m_widget->parent == m_mainWidget))
ab2b3dd4
RR
396 {
397 int xx = m_miniEdge;
398 int yy = m_miniEdge + m_miniTitle;
75c9da25 399#if wxUSE_MENUS_NATIVE
41ca191f 400 if (m_frameMenuBar)
f03fc89f 401 {
88ac883a 402 if (!m_menuBarDetached)
2b5f62a0 403 yy += m_menuBarHeight;
88ac883a 404 else
f03fc89f
VZ
405 yy += wxPLACE_HOLDER;
406 }
75c9da25 407#endif // wxUSE_MENUS_NATIVE
93fa69f8 408
121a3581
RR
409 m_frameToolBar->m_x = xx;
410 m_frameToolBar->m_y = yy;
93fa69f8 411
047ac72b 412 // don't change the toolbar's reported height/width
93fa69f8
VZ
413 int ww, hh;
414 if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL )
415 {
416 ww = m_toolBarDetached ? wxPLACE_HOLDER
417 : m_frameToolBar->m_width;
418 hh = m_height - 2*m_miniEdge;
9cf7a6c0
PC
419 if (hh < 0)
420 hh = 0;
93fa69f8
VZ
421
422 client_area_x_offset += ww;
423 }
5b2acc3a
RR
424 else if( m_frameToolBar->GetWindowStyle() & wxTB_BOTTOM )
425 {
426 xx = m_miniEdge;
427 yy = GetClientSize().y;
428#if wxUSE_MENUS_NATIVE
429 yy += m_menuBarHeight;
430#endif // wxUSE_MENU_NATIVE
431 m_frameToolBar->m_x = xx;
432 m_frameToolBar->m_y = yy;
433 ww = m_width - 2*m_miniEdge;
434 hh = m_toolBarDetached ? wxPLACE_HOLDER
435 : m_frameToolBar->m_height;
436 }
93fa69f8
VZ
437 else
438 {
439 ww = m_width - 2*m_miniEdge;
440 hh = m_toolBarDetached ? wxPLACE_HOLDER
441 : m_frameToolBar->m_height;
7b4c2a06 442
93fa69f8
VZ
443 client_area_y_offset += hh;
444 }
445
da048e3d 446 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
88ac883a 447 m_frameToolBar->m_widget,
f03fc89f 448 xx, yy, ww, hh );
ab2b3dd4 449 }
93fa69f8 450#endif // wxUSE_TOOLBAR
88ac883a 451
93fa69f8 452 int client_x = client_area_x_offset + m_miniEdge;
f03fc89f 453 int client_y = client_area_y_offset + m_miniEdge + m_miniTitle;
93fa69f8 454 int client_w = m_width - client_area_x_offset - 2*m_miniEdge;
f03fc89f 455 int client_h = m_height - client_area_y_offset- 2*m_miniEdge - m_miniTitle;
9cf7a6c0
PC
456 if (client_w < 0)
457 client_w = 0;
458 if (client_h < 0)
459 client_h = 0;
da048e3d 460 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
88ac883a 461 m_wxwindow,
f03fc89f 462 client_x, client_y, client_w, client_h );
32a95f9f
RR
463 }
464 else
465 {
047ac72b
RR
466 // If there is no m_mainWidget between m_widget and m_wxwindow there
467 // is no need to set the size or position of m_wxwindow.
f5368809 468 }
88ac883a 469
dcf924a3 470#if wxUSE_STATUSBAR
fa755cf1 471 if (m_frameStatusBar && m_frameStatusBar->IsShown())
f5368809 472 {
b2b3ccc5 473 int xx = 0 + m_miniEdge;
f362b96d 474 int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge - client_area_y_offset;
ac57418f 475 int ww = m_width - 2*m_miniEdge;
9cf7a6c0
PC
476 if (ww < 0)
477 ww = 0;
ac57418f 478 int hh = wxSTATUS_HEIGHT;
121a3581
RR
479 m_frameStatusBar->m_x = xx;
480 m_frameStatusBar->m_y = yy;
481 m_frameStatusBar->m_width = ww;
482 m_frameStatusBar->m_height = hh;
da048e3d 483 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow),
7c0ea335
VZ
484 m_frameStatusBar->m_widget,
485 xx, yy, ww, hh );
f5368809 486 }
1e6feb95 487#endif // wxUSE_STATUSBAR
8bbe427f 488
91af0895 489 m_sizeSet = true;
7beba2fc 490
54517652 491 // send size event to frame
43a18898
RR
492 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
493 event.SetEventObject( this );
e52f60e6 494 GetEventHandler()->ProcessEvent( event );
8bbe427f 495
1e6feb95 496#if wxUSE_STATUSBAR
54517652 497 // send size event to status bar
5aa5e35a
RR
498 if (m_frameStatusBar)
499 {
a2053b27 500 wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() );
5aa5e35a
RR
501 event2.SetEventObject( m_frameStatusBar );
502 m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 );
503 }
1e6feb95 504#endif // wxUSE_STATUSBAR
884470b1 505
91af0895 506 m_resizing = false;
e52f60e6
RR
507}
508
0d53fc34 509void wxFrame::OnInternalIdle()
e52f60e6 510{
e39af974 511 wxFrameBase::OnInternalIdle();
88ac883a 512
75c9da25 513#if wxUSE_MENUS_NATIVE
082b2798 514 if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle();
75c9da25 515#endif // wxUSE_MENUS_NATIVE
dcf924a3 516#if wxUSE_TOOLBAR
082b2798 517 if (m_frameToolBar) m_frameToolBar->OnInternalIdle();
dcf924a3
RR
518#endif
519#if wxUSE_STATUSBAR
e4edaf5c
JS
520 if (m_frameStatusBar)
521 {
522 m_frameStatusBar->OnInternalIdle();
523
524 // There may be controls in the status bar that
525 // need to be updated
526 for ( wxWindowList::compatibility_iterator node = m_frameStatusBar->GetChildren().GetFirst();
527 node;
528 node = node->GetNext() )
529 {
530 wxWindow *child = node->GetData();
531 child->OnInternalIdle();
532 }
533 }
dcf924a3 534#endif
362c6693 535}
c801d85f 536
7c0ea335
VZ
537// ----------------------------------------------------------------------------
538// menu/tool/status bar stuff
539// ----------------------------------------------------------------------------
c801d85f 540
6522713c 541#if wxUSE_MENUS_NATIVE
1e6feb95 542
0d53fc34 543void wxFrame::DetachMenuBar()
c801d85f 544{
223d09f6
KB
545 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
546 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
8bbe427f 547
6522713c 548 if ( m_frameMenuBar )
186baeb2
RR
549 {
550 m_frameMenuBar->UnsetInvokingWindow( this );
551
552 if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
553 {
9fa72bd2
MR
554 g_signal_handlers_disconnect_by_func (m_frameMenuBar->m_widget,
555 (gpointer) gtk_menu_attached_callback,
556 this);
186baeb2 557
9fa72bd2
MR
558 g_signal_handlers_disconnect_by_func (m_frameMenuBar->m_widget,
559 (gpointer) gtk_menu_detached_callback,
560 this);
186baeb2 561 }
f6bcfd97 562
186baeb2 563 gtk_widget_ref( m_frameMenuBar->m_widget );
f283a575
RR
564
565 gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget );
186baeb2
RR
566 }
567
6522713c
VZ
568 wxFrameBase::DetachMenuBar();
569}
570
0d53fc34 571void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
6522713c
VZ
572{
573 wxFrameBase::AttachMenuBar(menuBar);
8bbe427f 574
f5368809 575 if (m_frameMenuBar)
30dea054 576 {
5bd9e519 577 m_frameMenuBar->SetInvokingWindow( this );
8bbe427f 578
186baeb2
RR
579 m_frameMenuBar->SetParent(this);
580 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
88ac883a
VZ
581 m_frameMenuBar->m_widget,
582 m_frameMenuBar->m_x,
a2053b27
RR
583 m_frameMenuBar->m_y,
584 m_frameMenuBar->m_width,
585 m_frameMenuBar->m_height );
88ac883a 586
186baeb2
RR
587 if (menuBar->GetWindowStyle() & wxMB_DOCKABLE)
588 {
9fa72bd2
MR
589 g_signal_connect (menuBar->m_widget, "child_attached",
590 G_CALLBACK (gtk_menu_attached_callback),
591 this);
592 g_signal_connect (menuBar->m_widget, "child_detached",
593 G_CALLBACK (gtk_menu_detached_callback),
594 this);
f5368809 595 }
91af0895 596
02a8e64c 597 gtk_widget_show( m_frameMenuBar->m_widget );
2b5f62a0
VZ
598
599 UpdateMenuBarSize();
716b7364 600 }
2b5f62a0
VZ
601 else
602 {
603 m_menuBarHeight = 2;
604 GtkUpdateSize(); // resize window in OnInternalIdle
605 }
606}
607
608void wxFrame::UpdateMenuBarSize()
609{
2b5f62a0
VZ
610 GtkRequisition req;
611
612 req.width = 2;
613 req.height = 2;
91af0895 614
e5894d19
CE
615 // this is called after Remove with a NULL m_frameMenuBar
616 if ( m_frameMenuBar )
0a164d4c
WS
617 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
618 (m_frameMenuBar->m_widget, &req );
2b5f62a0
VZ
619
620 m_menuBarHeight = req.height;
621
0a164d4c 622 // resize window in OnInternalIdle
8bbe427f 623
b8b7f03c 624 GtkUpdateSize();
362c6693 625}
c801d85f 626
6522713c 627#endif // wxUSE_MENUS_NATIVE
1e6feb95 628
88ac883a 629#if wxUSE_TOOLBAR
1e6feb95 630
0d53fc34 631wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name )
46dc76ba 632{
223d09f6 633 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 634
91af0895 635 m_insertInClientArea = false;
88ac883a 636
7c0ea335 637 m_frameToolBar = wxFrameBase::CreateToolBar( style, id, name );
8bbe427f 638
91af0895 639 m_insertInClientArea = true;
8bbe427f 640
b8b7f03c 641 GtkUpdateSize();
8bbe427f 642
f5368809 643 return m_frameToolBar;
362c6693 644}
46dc76ba 645
0d53fc34 646void wxFrame::SetToolBar(wxToolBar *toolbar)
7beba2fc 647{
94f14509
VZ
648 bool hadTbar = m_frameToolBar != NULL;
649
7c0ea335
VZ
650 wxFrameBase::SetToolBar(toolbar);
651
94f14509 652 if ( m_frameToolBar )
307f16e8 653 {
f283a575 654 // insert into toolbar area if not already there
3017f78d
RR
655 if ((m_frameToolBar->m_widget->parent) &&
656 (m_frameToolBar->m_widget->parent != m_mainWidget))
307f16e8 657 {
3017f78d 658 GetChildren().DeleteObject( m_frameToolBar );
7beba2fc
VZ
659
660 gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget );
5b8a521e 661 GtkUpdateSize();
7beba2fc 662 }
307f16e8 663 }
94f14509
VZ
664 else // toolbar unset
665 {
666 // still need to update size if it had been there before
667 if ( hadTbar )
668 {
669 GtkUpdateSize();
670 }
671 }
307f16e8
RR
672}
673
88ac883a 674#endif // wxUSE_TOOLBAR
46dc76ba 675
88ac883a 676#if wxUSE_STATUSBAR
8bbe427f 677
0d53fc34 678wxStatusBar* wxFrame::CreateStatusBar(int number,
7c0ea335
VZ
679 long style,
680 wxWindowID id,
681 const wxString& name)
c801d85f 682{
223d09f6 683 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 684
7c0ea335 685 // because it will change when toolbar is added
b8b7f03c 686 GtkUpdateSize();
c801d85f 687
7c0ea335 688 return wxFrameBase::CreateStatusBar( number, style, id, name );
362c6693
RR
689}
690
3851e479
RR
691void wxFrame::SetStatusBar(wxStatusBar *statbar)
692{
693 bool hadStatBar = m_frameStatusBar != NULL;
91af0895 694
3851e479 695 wxFrameBase::SetStatusBar(statbar);
91af0895
WS
696
697 if (hadStatBar && !m_frameStatusBar)
3851e479
RR
698 GtkUpdateSize();
699}
700
0d53fc34 701void wxFrame::PositionStatusBar()
8febdd39
RR
702{
703 if ( !m_frameStatusBar )
704 return;
705
b8b7f03c 706 GtkUpdateSize();
8febdd39 707}
88ac883a 708#endif // wxUSE_STATUSBAR