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