]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/frame.cpp
Missing #includes to allow wx/mac/carbon/tooltip.h be included first by user.
[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"
670f9935
WS
26#endif // WX_PRECOMP
27
c801d85f
KB
28#include "wx/dialog.h"
29#include "wx/control.h"
cf4219e7 30#include "wx/menu.h"
dcf924a3 31#if wxUSE_TOOLBAR
7c0ea335 32 #include "wx/toolbar.h"
dcf924a3
RR
33#endif
34#if wxUSE_STATUSBAR
7c0ea335 35 #include "wx/statusbr.h"
dcf924a3 36#endif
83624f79 37
55703c91 38#include <glib.h>
9e691f46
VZ
39#include "wx/gtk/private.h"
40
55703c91
RR
41#include <gdk/gdkkeysyms.h>
42#include <gdk/gdkx.h>
43
c801d85f
KB
44#include "wx/gtk/win_gtk.h"
45
7c0ea335 46// ----------------------------------------------------------------------------
2f2aa628 47// constants
7c0ea335 48// ----------------------------------------------------------------------------
2f2aa628 49
c67daf87 50const int wxSTATUS_HEIGHT = 25;
41ca191f 51const int wxPLACE_HOLDER = 0;
c801d85f 52
7c0ea335
VZ
53// ----------------------------------------------------------------------------
54// event tables
55// ----------------------------------------------------------------------------
56
0d53fc34 57IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2e563988 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 {
9fa72bd2
MR
178 g_signal_connect (toolBar->m_widget, "child_attached",
179 G_CALLBACK (gtk_toolbar_attached_callback),
180 parent);
181 g_signal_connect (toolBar->m_widget, "child_detached",
182 G_CALLBACK (gtk_toolbar_detached_callback),
183 parent);
f03fc89f
VZ
184 }
185 }
88ac883a 186#endif // wxUSE_TOOLBAR
f362b96d
RR
187 }
188 else
189 {
047ac72b 190 // These are inside the client area
da048e3d 191 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
a2053b27
RR
192 GTK_WIDGET(child->m_widget),
193 child->m_x,
194 child->m_y,
195 child->m_width,
196 child->m_height );
f362b96d 197 }
91af0895 198
047ac72b 199 // Resize on OnInternalIdle
5b8a521e 200 parent->GtkUpdateSize();
f362b96d
RR
201}
202
7c0ea335 203// ----------------------------------------------------------------------------
0d53fc34 204// wxFrame creation
7c0ea335 205// ----------------------------------------------------------------------------
c801d85f 206
0d53fc34 207void wxFrame::Init()
c801d85f 208{
91af0895
WS
209 m_menuBarDetached = false;
210 m_toolBarDetached = false;
2b5f62a0 211 m_menuBarHeight = 2;
362c6693 212}
c801d85f 213
0d53fc34 214bool wxFrame::Create( wxWindow *parent,
7c0ea335 215 wxWindowID id,
ca8bf976
VZ
216 const wxString& title,
217 const wxPoint& pos,
218 const wxSize& sizeOrig,
7c0ea335
VZ
219 long style,
220 const wxString &name )
c801d85f 221{
7b4c2a06 222 bool rt = wxTopLevelWindow::Create(parent, id, title, pos, sizeOrig,
7d9f12f3 223 style, name);
6bc8a1c8 224 m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame;
91af0895 225
7d9f12f3 226 return rt;
362c6693 227}
c801d85f 228
0d53fc34 229wxFrame::~wxFrame()
c801d85f 230{
91af0895 231 m_isBeingDeleted = true;
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
BP
386 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
387 (GtkWidget*) NULL,
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 );
0857d1d6
MR
488 if (GTK_WIDGET_DRAWABLE (m_frameStatusBar->m_widget))
489 {
490 gtk_widget_queue_draw (m_frameStatusBar->m_widget);
491 // FIXME: Do we really want to force an immediate redraw?
492 gdk_window_process_updates (m_frameStatusBar->m_widget->window, TRUE);
493 }
f5368809 494 }
1e6feb95 495#endif // wxUSE_STATUSBAR
8bbe427f 496
91af0895 497 m_sizeSet = true;
7beba2fc 498
54517652 499 // send size event to frame
43a18898
RR
500 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
501 event.SetEventObject( this );
e52f60e6 502 GetEventHandler()->ProcessEvent( event );
8bbe427f 503
1e6feb95 504#if wxUSE_STATUSBAR
54517652 505 // send size event to status bar
5aa5e35a
RR
506 if (m_frameStatusBar)
507 {
a2053b27 508 wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() );
5aa5e35a
RR
509 event2.SetEventObject( m_frameStatusBar );
510 m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 );
511 }
1e6feb95 512#endif // wxUSE_STATUSBAR
884470b1 513
91af0895 514 m_resizing = false;
e52f60e6
RR
515}
516
0d53fc34 517void wxFrame::OnInternalIdle()
e52f60e6 518{
e39af974 519 wxFrameBase::OnInternalIdle();
88ac883a 520
75c9da25 521#if wxUSE_MENUS_NATIVE
082b2798 522 if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle();
75c9da25 523#endif // wxUSE_MENUS_NATIVE
dcf924a3 524#if wxUSE_TOOLBAR
082b2798 525 if (m_frameToolBar) m_frameToolBar->OnInternalIdle();
dcf924a3
RR
526#endif
527#if wxUSE_STATUSBAR
e4edaf5c
JS
528 if (m_frameStatusBar)
529 {
530 m_frameStatusBar->OnInternalIdle();
531
532 // There may be controls in the status bar that
533 // need to be updated
534 for ( wxWindowList::compatibility_iterator node = m_frameStatusBar->GetChildren().GetFirst();
535 node;
536 node = node->GetNext() )
537 {
538 wxWindow *child = node->GetData();
539 child->OnInternalIdle();
540 }
541 }
dcf924a3 542#endif
362c6693 543}
c801d85f 544
7c0ea335
VZ
545// ----------------------------------------------------------------------------
546// menu/tool/status bar stuff
547// ----------------------------------------------------------------------------
c801d85f 548
6522713c 549#if wxUSE_MENUS_NATIVE
1e6feb95 550
0d53fc34 551void wxFrame::DetachMenuBar()
c801d85f 552{
223d09f6
KB
553 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
554 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
8bbe427f 555
6522713c 556 if ( m_frameMenuBar )
186baeb2
RR
557 {
558 m_frameMenuBar->UnsetInvokingWindow( this );
559
560 if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
561 {
9fa72bd2
MR
562 g_signal_handlers_disconnect_by_func (m_frameMenuBar->m_widget,
563 (gpointer) gtk_menu_attached_callback,
564 this);
186baeb2 565
9fa72bd2
MR
566 g_signal_handlers_disconnect_by_func (m_frameMenuBar->m_widget,
567 (gpointer) gtk_menu_detached_callback,
568 this);
186baeb2 569 }
f6bcfd97 570
186baeb2 571 gtk_widget_ref( m_frameMenuBar->m_widget );
f283a575
RR
572
573 gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget );
186baeb2
RR
574 }
575
6522713c
VZ
576 wxFrameBase::DetachMenuBar();
577}
578
0d53fc34 579void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
6522713c
VZ
580{
581 wxFrameBase::AttachMenuBar(menuBar);
8bbe427f 582
f5368809 583 if (m_frameMenuBar)
30dea054 584 {
5bd9e519 585 m_frameMenuBar->SetInvokingWindow( this );
8bbe427f 586
186baeb2
RR
587 m_frameMenuBar->SetParent(this);
588 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
88ac883a
VZ
589 m_frameMenuBar->m_widget,
590 m_frameMenuBar->m_x,
a2053b27
RR
591 m_frameMenuBar->m_y,
592 m_frameMenuBar->m_width,
593 m_frameMenuBar->m_height );
88ac883a 594
186baeb2
RR
595 if (menuBar->GetWindowStyle() & wxMB_DOCKABLE)
596 {
9fa72bd2
MR
597 g_signal_connect (menuBar->m_widget, "child_attached",
598 G_CALLBACK (gtk_menu_attached_callback),
599 this);
600 g_signal_connect (menuBar->m_widget, "child_detached",
601 G_CALLBACK (gtk_menu_detached_callback),
602 this);
f5368809 603 }
91af0895 604
02a8e64c 605 gtk_widget_show( m_frameMenuBar->m_widget );
2b5f62a0
VZ
606
607 UpdateMenuBarSize();
716b7364 608 }
2b5f62a0
VZ
609 else
610 {
611 m_menuBarHeight = 2;
612 GtkUpdateSize(); // resize window in OnInternalIdle
613 }
614}
615
616void wxFrame::UpdateMenuBarSize()
617{
2b5f62a0
VZ
618 GtkRequisition req;
619
620 req.width = 2;
621 req.height = 2;
91af0895 622
e5894d19
CE
623 // this is called after Remove with a NULL m_frameMenuBar
624 if ( m_frameMenuBar )
0a164d4c
WS
625 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
626 (m_frameMenuBar->m_widget, &req );
2b5f62a0
VZ
627
628 m_menuBarHeight = req.height;
629
0a164d4c 630 // resize window in OnInternalIdle
8bbe427f 631
b8b7f03c 632 GtkUpdateSize();
362c6693 633}
c801d85f 634
6522713c 635#endif // wxUSE_MENUS_NATIVE
1e6feb95 636
88ac883a 637#if wxUSE_TOOLBAR
1e6feb95 638
0d53fc34 639wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name )
46dc76ba 640{
223d09f6 641 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 642
91af0895 643 m_insertInClientArea = false;
88ac883a 644
7c0ea335 645 m_frameToolBar = wxFrameBase::CreateToolBar( style, id, name );
8bbe427f 646
91af0895 647 m_insertInClientArea = true;
8bbe427f 648
b8b7f03c 649 GtkUpdateSize();
8bbe427f 650
f5368809 651 return m_frameToolBar;
362c6693 652}
46dc76ba 653
0d53fc34 654void wxFrame::SetToolBar(wxToolBar *toolbar)
7beba2fc 655{
94f14509
VZ
656 bool hadTbar = m_frameToolBar != NULL;
657
7c0ea335
VZ
658 wxFrameBase::SetToolBar(toolbar);
659
94f14509 660 if ( m_frameToolBar )
307f16e8 661 {
f283a575 662 // insert into toolbar area if not already there
3017f78d
RR
663 if ((m_frameToolBar->m_widget->parent) &&
664 (m_frameToolBar->m_widget->parent != m_mainWidget))
307f16e8 665 {
3017f78d 666 GetChildren().DeleteObject( m_frameToolBar );
7beba2fc
VZ
667
668 gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget );
5b8a521e 669 GtkUpdateSize();
7beba2fc 670 }
307f16e8 671 }
94f14509
VZ
672 else // toolbar unset
673 {
674 // still need to update size if it had been there before
675 if ( hadTbar )
676 {
677 GtkUpdateSize();
678 }
679 }
307f16e8
RR
680}
681
88ac883a 682#endif // wxUSE_TOOLBAR
46dc76ba 683
88ac883a 684#if wxUSE_STATUSBAR
8bbe427f 685
0d53fc34 686wxStatusBar* wxFrame::CreateStatusBar(int number,
7c0ea335
VZ
687 long style,
688 wxWindowID id,
689 const wxString& name)
c801d85f 690{
223d09f6 691 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 692
7c0ea335 693 // because it will change when toolbar is added
b8b7f03c 694 GtkUpdateSize();
c801d85f 695
7c0ea335 696 return wxFrameBase::CreateStatusBar( number, style, id, name );
362c6693
RR
697}
698
3851e479
RR
699void wxFrame::SetStatusBar(wxStatusBar *statbar)
700{
701 bool hadStatBar = m_frameStatusBar != NULL;
91af0895 702
3851e479 703 wxFrameBase::SetStatusBar(statbar);
91af0895
WS
704
705 if (hadStatBar && !m_frameStatusBar)
3851e479
RR
706 GtkUpdateSize();
707}
708
0d53fc34 709void wxFrame::PositionStatusBar()
8febdd39
RR
710{
711 if ( !m_frameStatusBar )
712 return;
713
b8b7f03c 714 GtkUpdateSize();
8febdd39 715}
88ac883a 716#endif // wxUSE_STATUSBAR