]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/frame.cpp
Always use XPMs in this sample
[wxWidgets.git] / src / gtk / frame.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
01111366 6// Copyright: (c) 1998 Robert Roebling
19717c50 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
7c0ea335
VZ
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
14f355c2 18#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
fe4e9e6c 19 #pragma implementation "frame.h"
c801d85f
KB
20#endif
21
14f355c2
VS
22// For compilers that support precompilation, includes "wx.h".
23#include "wx/wxprec.h"
24
0c394212
VZ
25#include "wx/defs.h"
26
c801d85f
KB
27#include "wx/dialog.h"
28#include "wx/control.h"
29#include "wx/app.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
362c6693 37#include "wx/dcclient.h"
83624f79 38
55703c91 39#include <glib.h>
9e691f46
VZ
40#include "wx/gtk/private.h"
41
55703c91
RR
42#include <gdk/gdkkeysyms.h>
43#include <gdk/gdkx.h>
44
c801d85f
KB
45#include "wx/gtk/win_gtk.h"
46
7c0ea335 47// ----------------------------------------------------------------------------
2f2aa628 48// constants
7c0ea335 49// ----------------------------------------------------------------------------
2f2aa628 50
c67daf87 51const int wxSTATUS_HEIGHT = 25;
41ca191f 52const int wxPLACE_HOLDER = 0;
c801d85f 53
7c0ea335 54// ----------------------------------------------------------------------------
acfd422a 55// idle system
7c0ea335 56// ----------------------------------------------------------------------------
acfd422a
RR
57
58extern void wxapp_install_idle_handler();
59extern bool g_isIdle;
2d68e1b4 60extern int g_openDialogs;
acfd422a 61
7c0ea335
VZ
62// ----------------------------------------------------------------------------
63// event tables
64// ----------------------------------------------------------------------------
65
0d53fc34 66IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2e563988 67
7c0ea335
VZ
68// ============================================================================
69// implementation
70// ============================================================================
71
72// ----------------------------------------------------------------------------
73// GTK callbacks
74// ----------------------------------------------------------------------------
75
6522713c
VZ
76#if wxUSE_MENUS_NATIVE
77
16bcc879
RR
78//-----------------------------------------------------------------------------
79// "child_attached" of menu bar
80//-----------------------------------------------------------------------------
81
0d53fc34 82static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 83{
a2053b27 84 if (!win->m_hasVMT) return;
88ac883a 85
16bcc879 86 win->m_menuBarDetached = FALSE;
5b8a521e 87 win->GtkUpdateSize();
16bcc879
RR
88}
89
90//-----------------------------------------------------------------------------
91// "child_detached" of menu bar
92//-----------------------------------------------------------------------------
93
0d53fc34 94static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 95{
047ac72b
RR
96 if (g_isIdle)
97 wxapp_install_idle_handler();
98
a2053b27 99 if (!win->m_hasVMT) return;
88ac883a 100
047ac72b
RR
101 // Raise the client area area
102 gdk_window_raise( win->m_wxwindow->window );
103
16bcc879 104 win->m_menuBarDetached = TRUE;
5b8a521e 105 win->GtkUpdateSize();
16bcc879 106}
6522713c
VZ
107
108#endif // wxUSE_MENUS_NATIVE
16bcc879 109
88ac883a 110#if wxUSE_TOOLBAR
16bcc879
RR
111//-----------------------------------------------------------------------------
112// "child_attached" of tool bar
113//-----------------------------------------------------------------------------
114
0d53fc34 115static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 116{
a2053b27 117 if (!win->m_hasVMT) return;
88ac883a 118
16bcc879 119 win->m_toolBarDetached = FALSE;
5b8a521e 120 win->GtkUpdateSize();
16bcc879
RR
121}
122
123//-----------------------------------------------------------------------------
124// "child_detached" of tool bar
125//-----------------------------------------------------------------------------
126
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
16bcc879 137 win->m_toolBarDetached = TRUE;
5b8a521e 138 win->GtkUpdateSize();
16bcc879 139}
88ac883a 140#endif // wxUSE_TOOLBAR
16bcc879 141
117247fd 142
7c0ea335 143// ----------------------------------------------------------------------------
0d53fc34 144// wxFrame itself
7c0ea335
VZ
145// ----------------------------------------------------------------------------
146
f362b96d 147//-----------------------------------------------------------------------------
0d53fc34 148// InsertChild for wxFrame
f362b96d
RR
149//-----------------------------------------------------------------------------
150
0d53fc34 151/* Callback for wxFrame. This very strange beast has to be used because
f362b96d
RR
152 * C++ has no virtual methods in a constructor. We have to emulate a
153 * virtual function here as wxWindows requires different ways to insert
154 * a child in container classes. */
155
0d53fc34 156static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child )
f362b96d 157{
5fd11f09 158 wxASSERT( GTK_IS_WIDGET(child->m_widget) );
7beba2fc 159
6bc8a1c8 160 if (!parent->m_insertInClientArea)
f362b96d 161 {
047ac72b 162 // These are outside the client area
0d53fc34 163 wxFrame* frame = (wxFrame*) parent;
da048e3d 164 gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget),
a2053b27
RR
165 GTK_WIDGET(child->m_widget),
166 child->m_x,
167 child->m_y,
168 child->m_width,
169 child->m_height );
2b5f62a0 170
caf51f95 171#if wxUSE_TOOLBAR_NATIVE
047ac72b
RR
172 // We connect to these events for recalculating the client area
173 // space when the toolbar is floating
f03fc89f
VZ
174 if (wxIS_KIND_OF(child,wxToolBar))
175 {
176 wxToolBar *toolBar = (wxToolBar*) child;
177 if (toolBar->GetWindowStyle() & wxTB_DOCKABLE)
178 {
a2053b27 179 gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_attached",
41ca191f 180 GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback), (gpointer)parent );
88ac883a 181
a2053b27 182 gtk_signal_connect( GTK_OBJECT(toolBar->m_widget), "child_detached",
41ca191f 183 GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback), (gpointer)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 }
2b5f62a0 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{
16bcc879
RR
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;
2b5f62a0 225
7d9f12f3 226 return rt;
362c6693 227}
c801d85f 228
0d53fc34 229wxFrame::~wxFrame()
c801d85f 230{
31c6b4fc 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
RR
345 if (m_resizing) return;
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 );
b6fa52db 488 gtk_widget_draw( m_frameStatusBar->m_widget, (GdkRectangle*) NULL );
f5368809 489 }
1e6feb95 490#endif // wxUSE_STATUSBAR
8bbe427f 491
7b4c2a06 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
e52f60e6
RR
509 m_resizing = FALSE;
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
082b2798 523 if (m_frameStatusBar) m_frameStatusBar->OnInternalIdle();
dcf924a3 524#endif
362c6693 525}
c801d85f 526
7c0ea335
VZ
527// ----------------------------------------------------------------------------
528// menu/tool/status bar stuff
529// ----------------------------------------------------------------------------
c801d85f 530
6522713c 531#if wxUSE_MENUS_NATIVE
1e6feb95 532
0d53fc34 533void wxFrame::DetachMenuBar()
c801d85f 534{
223d09f6
KB
535 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
536 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
8bbe427f 537
6522713c 538 if ( m_frameMenuBar )
186baeb2
RR
539 {
540 m_frameMenuBar->UnsetInvokingWindow( this );
541
542 if (m_frameMenuBar->GetWindowStyle() & wxMB_DOCKABLE)
543 {
544 gtk_signal_disconnect_by_func( GTK_OBJECT(m_frameMenuBar->m_widget),
545 GTK_SIGNAL_FUNC(gtk_menu_attached_callback), (gpointer)this );
546
547 gtk_signal_disconnect_by_func( GTK_OBJECT(m_frameMenuBar->m_widget),
548 GTK_SIGNAL_FUNC(gtk_menu_detached_callback), (gpointer)this );
549 }
f6bcfd97 550
186baeb2 551 gtk_widget_ref( m_frameMenuBar->m_widget );
f283a575
RR
552
553 gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget );
186baeb2
RR
554 }
555
6522713c
VZ
556 wxFrameBase::DetachMenuBar();
557}
558
0d53fc34 559void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
6522713c
VZ
560{
561 wxFrameBase::AttachMenuBar(menuBar);
8bbe427f 562
f5368809 563 if (m_frameMenuBar)
30dea054 564 {
5bd9e519 565 m_frameMenuBar->SetInvokingWindow( this );
8bbe427f 566
186baeb2
RR
567 m_frameMenuBar->SetParent(this);
568 gtk_pizza_put( GTK_PIZZA(m_mainWidget),
88ac883a
VZ
569 m_frameMenuBar->m_widget,
570 m_frameMenuBar->m_x,
a2053b27
RR
571 m_frameMenuBar->m_y,
572 m_frameMenuBar->m_width,
573 m_frameMenuBar->m_height );
88ac883a 574
186baeb2
RR
575 if (menuBar->GetWindowStyle() & wxMB_DOCKABLE)
576 {
577 gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_attached",
578 GTK_SIGNAL_FUNC(gtk_menu_attached_callback), (gpointer)this );
7beba2fc 579
186baeb2
RR
580 gtk_signal_connect( GTK_OBJECT(menuBar->m_widget), "child_detached",
581 GTK_SIGNAL_FUNC(gtk_menu_detached_callback), (gpointer)this );
f5368809 582 }
2b5f62a0 583
186baeb2 584 m_frameMenuBar->Show( TRUE );
2b5f62a0
VZ
585
586 UpdateMenuBarSize();
716b7364 587 }
2b5f62a0
VZ
588 else
589 {
590 m_menuBarHeight = 2;
591 GtkUpdateSize(); // resize window in OnInternalIdle
592 }
593}
594
595void wxFrame::UpdateMenuBarSize()
596{
597 wxASSERT_MSG( m_frameMenuBar, _T("Updating non existant menubar?") );
598
599 GtkRequisition req;
600
601 req.width = 2;
602 req.height = 2;
603
604 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar->m_widget) )->size_request )
605 (m_frameMenuBar->m_widget, &req );
606
607 m_menuBarHeight = req.height;
608
609 // resize window in OnInternalIdle
8bbe427f 610
b8b7f03c 611 GtkUpdateSize();
362c6693 612}
c801d85f 613
6522713c 614#endif // wxUSE_MENUS_NATIVE
1e6feb95 615
88ac883a 616#if wxUSE_TOOLBAR
1e6feb95 617
0d53fc34 618wxToolBar* wxFrame::CreateToolBar( long style, wxWindowID id, const wxString& name )
46dc76ba 619{
223d09f6 620 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 621
6bc8a1c8 622 m_insertInClientArea = FALSE;
88ac883a 623
7c0ea335 624 m_frameToolBar = wxFrameBase::CreateToolBar( style, id, name );
8bbe427f 625
6bc8a1c8 626 m_insertInClientArea = TRUE;
8bbe427f 627
b8b7f03c 628 GtkUpdateSize();
8bbe427f 629
f5368809 630 return m_frameToolBar;
362c6693 631}
46dc76ba 632
0d53fc34 633void wxFrame::SetToolBar(wxToolBar *toolbar)
7beba2fc 634{
94f14509
VZ
635 bool hadTbar = m_frameToolBar != NULL;
636
7c0ea335
VZ
637 wxFrameBase::SetToolBar(toolbar);
638
94f14509 639 if ( m_frameToolBar )
307f16e8 640 {
f283a575 641 // insert into toolbar area if not already there
3017f78d
RR
642 if ((m_frameToolBar->m_widget->parent) &&
643 (m_frameToolBar->m_widget->parent != m_mainWidget))
307f16e8 644 {
3017f78d 645 GetChildren().DeleteObject( m_frameToolBar );
7beba2fc
VZ
646
647 gtk_widget_reparent( m_frameToolBar->m_widget, m_mainWidget );
5b8a521e 648 GtkUpdateSize();
7beba2fc 649 }
307f16e8 650 }
94f14509
VZ
651 else // toolbar unset
652 {
653 // still need to update size if it had been there before
654 if ( hadTbar )
655 {
656 GtkUpdateSize();
657 }
658 }
307f16e8
RR
659}
660
88ac883a 661#endif // wxUSE_TOOLBAR
46dc76ba 662
88ac883a 663#if wxUSE_STATUSBAR
8bbe427f 664
0d53fc34 665wxStatusBar* wxFrame::CreateStatusBar(int number,
7c0ea335
VZ
666 long style,
667 wxWindowID id,
668 const wxString& name)
c801d85f 669{
223d09f6 670 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 671
7c0ea335 672 // because it will change when toolbar is added
b8b7f03c 673 GtkUpdateSize();
c801d85f 674
7c0ea335 675 return wxFrameBase::CreateStatusBar( number, style, id, name );
362c6693
RR
676}
677
0d53fc34 678void wxFrame::PositionStatusBar()
8febdd39
RR
679{
680 if ( !m_frameStatusBar )
681 return;
682
b8b7f03c 683 GtkUpdateSize();
8febdd39 684}
88ac883a 685#endif // wxUSE_STATUSBAR
c801d85f 686