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