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