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