]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/frame.cpp
wxOS2 warning fixes after daily build log.
[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
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
7c0ea335
VZ
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
14f355c2
VS
18// For compilers that support precompilation, includes "wx.h".
19#include "wx/wxprec.h"
20
0c394212
VZ
21#include "wx/defs.h"
22
e1bf3ad3 23#include "wx/frame.h"
c801d85f
KB
24#include "wx/dialog.h"
25#include "wx/control.h"
26#include "wx/app.h"
cf4219e7 27#include "wx/menu.h"
dcf924a3 28#if wxUSE_TOOLBAR
7c0ea335 29 #include "wx/toolbar.h"
dcf924a3
RR
30#endif
31#if wxUSE_STATUSBAR
7c0ea335 32 #include "wx/statusbr.h"
dcf924a3 33#endif
362c6693 34#include "wx/dcclient.h"
83624f79 35
55703c91 36#include <glib.h>
9e691f46
VZ
37#include "wx/gtk/private.h"
38
55703c91
RR
39#include <gdk/gdkkeysyms.h>
40#include <gdk/gdkx.h>
41
c801d85f
KB
42#include "wx/gtk/win_gtk.h"
43
7c0ea335 44// ----------------------------------------------------------------------------
2f2aa628 45// constants
7c0ea335 46// ----------------------------------------------------------------------------
2f2aa628 47
c67daf87 48const int wxSTATUS_HEIGHT = 25;
41ca191f 49const int wxPLACE_HOLDER = 0;
c801d85f 50
7c0ea335 51// ----------------------------------------------------------------------------
acfd422a 52// idle system
7c0ea335 53// ----------------------------------------------------------------------------
acfd422a
RR
54
55extern void wxapp_install_idle_handler();
56extern bool g_isIdle;
57
7c0ea335
VZ
58// ----------------------------------------------------------------------------
59// event tables
60// ----------------------------------------------------------------------------
61
0d53fc34 62IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2e563988 63
7c0ea335
VZ
64// ============================================================================
65// implementation
66// ============================================================================
67
68// ----------------------------------------------------------------------------
69// GTK callbacks
70// ----------------------------------------------------------------------------
71
6522713c
VZ
72#if wxUSE_MENUS_NATIVE
73
16bcc879
RR
74//-----------------------------------------------------------------------------
75// "child_attached" of menu bar
76//-----------------------------------------------------------------------------
77
865bb325 78extern "C" {
0d53fc34 79static void gtk_menu_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 80{
a2053b27 81 if (!win->m_hasVMT) return;
88ac883a 82
91af0895 83 win->m_menuBarDetached = false;
5b8a521e 84 win->GtkUpdateSize();
16bcc879 85}
865bb325 86}
16bcc879
RR
87
88//-----------------------------------------------------------------------------
89// "child_detached" of menu bar
90//-----------------------------------------------------------------------------
91
865bb325 92extern "C" {
0d53fc34 93static void gtk_menu_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 94{
047ac72b
RR
95 if (g_isIdle)
96 wxapp_install_idle_handler();
97
a2053b27 98 if (!win->m_hasVMT) return;
88ac883a 99
047ac72b
RR
100 // Raise the client area area
101 gdk_window_raise( win->m_wxwindow->window );
102
91af0895 103 win->m_menuBarDetached = true;
5b8a521e 104 win->GtkUpdateSize();
16bcc879 105}
865bb325 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
865bb325 115extern "C" {
0d53fc34 116static void gtk_toolbar_attached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 117{
a2053b27 118 if (!win->m_hasVMT) return;
88ac883a 119
91af0895 120 win->m_toolBarDetached = false;
5b8a521e 121 win->GtkUpdateSize();
16bcc879 122}
865bb325 123}
16bcc879
RR
124
125//-----------------------------------------------------------------------------
126// "child_detached" of tool bar
127//-----------------------------------------------------------------------------
128
865bb325 129extern "C" {
0d53fc34 130static void gtk_toolbar_detached_callback( GtkWidget *WXUNUSED(widget), GtkWidget *WXUNUSED(child), wxFrame *win )
16bcc879 131{
88ac883a 132 if (g_isIdle)
801aa178 133 wxapp_install_idle_handler();
acfd422a 134
a2053b27 135 if (!win->m_hasVMT) return;
88ac883a 136
047ac72b
RR
137 // Raise the client area area
138 gdk_window_raise( win->m_wxwindow->window );
139
91af0895 140 win->m_toolBarDetached = true;
5b8a521e 141 win->GtkUpdateSize();
16bcc879 142}
865bb325 143}
88ac883a 144#endif // wxUSE_TOOLBAR
16bcc879 145
117247fd 146
7c0ea335 147// ----------------------------------------------------------------------------
0d53fc34 148// wxFrame itself
7c0ea335
VZ
149// ----------------------------------------------------------------------------
150
f362b96d 151//-----------------------------------------------------------------------------
0d53fc34 152// InsertChild for wxFrame
f362b96d
RR
153//-----------------------------------------------------------------------------
154
0d53fc34 155/* Callback for wxFrame. This very strange beast has to be used because
f362b96d 156 * C++ has no virtual methods in a constructor. We have to emulate a
77ffb593 157 * virtual function here as wxWidgets requires different ways to insert
f362b96d
RR
158 * a child in container classes. */
159
0d53fc34 160static void wxInsertChildInFrame( wxFrame* parent, wxWindow* child )
f362b96d 161{
5fd11f09 162 wxASSERT( GTK_IS_WIDGET(child->m_widget) );
7beba2fc 163
6bc8a1c8 164 if (!parent->m_insertInClientArea)
f362b96d 165 {
047ac72b 166 // These are outside the client area
0d53fc34 167 wxFrame* frame = (wxFrame*) parent;
da048e3d 168 gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget),
a2053b27
RR
169 GTK_WIDGET(child->m_widget),
170 child->m_x,
171 child->m_y,
172 child->m_width,
173 child->m_height );
91af0895 174
caf51f95 175#if wxUSE_TOOLBAR_NATIVE
047ac72b
RR
176 // We connect to these events for recalculating the client area
177 // space when the toolbar is floating
f03fc89f
VZ
178 if (wxIS_KIND_OF(child,wxToolBar))
179 {
180 wxToolBar *toolBar = (wxToolBar*) child;
181 if (toolBar->GetWindowStyle() & wxTB_DOCKABLE)
182 {
9fa72bd2
MR
183 g_signal_connect (toolBar->m_widget, "child_attached",
184 G_CALLBACK (gtk_toolbar_attached_callback),
185 parent);
186 g_signal_connect (toolBar->m_widget, "child_detached",
187 G_CALLBACK (gtk_toolbar_detached_callback),
188 parent);
f03fc89f
VZ
189 }
190 }
88ac883a 191#endif // wxUSE_TOOLBAR
f362b96d
RR
192 }
193 else
194 {
047ac72b 195 // These are inside the client area
da048e3d 196 gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
a2053b27
RR
197 GTK_WIDGET(child->m_widget),
198 child->m_x,
199 child->m_y,
200 child->m_width,
201 child->m_height );
f362b96d 202 }
91af0895 203
047ac72b 204 // Resize on OnInternalIdle
5b8a521e 205 parent->GtkUpdateSize();
f362b96d
RR
206}
207
7c0ea335 208// ----------------------------------------------------------------------------
0d53fc34 209// wxFrame creation
7c0ea335 210// ----------------------------------------------------------------------------
c801d85f 211
0d53fc34 212void wxFrame::Init()
c801d85f 213{
91af0895
WS
214 m_menuBarDetached = false;
215 m_toolBarDetached = false;
2b5f62a0 216 m_menuBarHeight = 2;
362c6693 217}
c801d85f 218
0d53fc34 219bool wxFrame::Create( wxWindow *parent,
7c0ea335 220 wxWindowID id,
ca8bf976
VZ
221 const wxString& title,
222 const wxPoint& pos,
223 const wxSize& sizeOrig,
7c0ea335
VZ
224 long style,
225 const wxString &name )
c801d85f 226{
7b4c2a06 227 bool rt = wxTopLevelWindow::Create(parent, id, title, pos, sizeOrig,
7d9f12f3 228 style, name);
6bc8a1c8 229 m_insertCallback = (wxInsertChildFunction) wxInsertChildInFrame;
91af0895 230
7d9f12f3 231 return rt;
362c6693 232}
c801d85f 233
0d53fc34 234wxFrame::~wxFrame()
c801d85f 235{
91af0895 236 m_isBeingDeleted = true;
7c0ea335 237 DeleteAllBars();
3d0c4d2e
RR
238}
239
7c0ea335
VZ
240// ----------------------------------------------------------------------------
241// overridden wxWindow methods
242// ----------------------------------------------------------------------------
243
0d53fc34 244void wxFrame::DoGetClientSize( int *width, int *height ) const
c801d85f 245{
223d09f6 246 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
7b4c2a06 247
7d9f12f3 248 wxTopLevelWindow::DoGetClientSize( width, height );
8bbe427f 249
fb1585ae 250 if (height)
46dc76ba 251 {
75c9da25 252#if wxUSE_MENUS_NATIVE
047ac72b 253 // menu bar
41ca191f 254 if (m_frameMenuBar)
f03fc89f 255 {
88ac883a 256 if (!m_menuBarDetached)
2b5f62a0 257 (*height) -= m_menuBarHeight;
f03fc89f
VZ
258 else
259 (*height) -= wxPLACE_HOLDER;
260 }
75c9da25 261#endif // wxUSE_MENUS_NATIVE
88ac883a 262
dcf924a3 263#if wxUSE_STATUSBAR
047ac72b 264 // status bar
7b4c2a06 265 if (m_frameStatusBar && m_frameStatusBar->IsShown())
7d9f12f3 266 (*height) -= wxSTATUS_HEIGHT;
93fa69f8 267#endif // wxUSE_STATUSBAR
88ac883a 268
dcf924a3 269#if wxUSE_TOOLBAR
047ac72b 270 // tool bar
fa755cf1 271 if (m_frameToolBar && m_frameToolBar->IsShown())
fb1585ae 272 {
93fa69f8 273 if (m_toolBarDetached)
f03fc89f 274 {
93fa69f8 275 *height -= wxPLACE_HOLDER;
f03fc89f
VZ
276 }
277 else
93fa69f8
VZ
278 {
279 int x, y;
280 m_frameToolBar->GetSize( &x, &y );
281 if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL )
282 {
283 *width -= x;
284 }
285 else
286 {
287 *height -= y;
288 }
289 }
fb1585ae 290 }
93fa69f8 291#endif // wxUSE_TOOLBAR
46dc76ba 292 }
362c6693 293}
c801d85f 294
0d53fc34 295void wxFrame::DoSetClientSize( int width, int height )
b593568e 296{
223d09f6 297 wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
8bbe427f 298
75c9da25 299#if wxUSE_MENUS_NATIVE
047ac72b 300 // menu bar
41ca191f 301 if (m_frameMenuBar)
f03fc89f 302 {
88ac883a 303 if (!m_menuBarDetached)
2b5f62a0 304 height += m_menuBarHeight;
f03fc89f
VZ
305 else
306 height += wxPLACE_HOLDER;
307 }
75c9da25 308#endif // wxUSE_MENUS_NATIVE
88ac883a 309
dcf924a3 310#if wxUSE_STATUSBAR
047ac72b 311 // status bar
fa755cf1 312 if (m_frameStatusBar && m_frameStatusBar->IsShown()) height += wxSTATUS_HEIGHT;
dcf924a3 313#endif
88ac883a 314
dcf924a3 315#if wxUSE_TOOLBAR
047ac72b 316 // tool bar
fa755cf1 317 if (m_frameToolBar && m_frameToolBar->IsShown())
41ca191f 318 {
93fa69f8 319 if (m_toolBarDetached)
f03fc89f 320 {
93fa69f8 321 height += wxPLACE_HOLDER;
f03fc89f
VZ
322 }
323 else
93fa69f8
VZ
324 {
325 int x, y;
326 m_frameToolBar->GetSize( &x, &y );
327 if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL )
328 {
329 width += x;
330 }
331 else
332 {
333 height += y;
334 }
335 }
41ca191f 336 }
dcf924a3 337#endif
88ac883a 338
7d9f12f3 339 wxTopLevelWindow::DoSetClientSize( width, height );
362c6693 340}
b593568e 341
0d53fc34 342void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y),
7c0ea335 343 int width, int height )
c801d85f 344{
f5368809
RR
345 // due to a bug in gtk, x,y are always 0
346 // m_x = x;
347 // m_y = y;
348
047ac72b 349 // avoid recursions
e52f60e6 350 if (m_resizing) return;
91af0895 351 m_resizing = true;
8bbe427f 352
047ac72b 353 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
223d09f6 354 wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") );
88ac883a 355
f5368809
RR
356 m_width = width;
357 m_height = height;
7beba2fc 358
047ac72b 359 // space occupied by m_frameToolBar and m_frameMenuBar
93fa69f8
VZ
360 int client_area_x_offset = 0,
361 client_area_y_offset = 0;
8bbe427f 362
0d53fc34 363 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
ab2b3dd4 364 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
0d53fc34 365 set in wxFrame::Create so it is used to check what kind of frame we
ab2b3dd4
RR
366 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
367 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
368 importantly) m_mainWidget */
88ac883a 369
e7dda1ff
VS
370 int minWidth = GetMinWidth(),
371 minHeight = GetMinHeight(),
372 maxWidth = GetMaxWidth(),
373 maxHeight = GetMaxHeight();
374
375 if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth;
376 if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight;
377 if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth;
378 if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight;
1f3c610d 379
ab2b3dd4 380 if (m_mainWidget)
f5368809 381 {
047ac72b 382 // set size hints
f6bcfd97 383 gint flag = 0; // GDK_HINT_POS;
e7dda1ff
VS
384 if ((minWidth != -1) || (minHeight != -1)) flag |= GDK_HINT_MIN_SIZE;
385 if ((maxWidth != -1) || (maxHeight != -1)) flag |= GDK_HINT_MAX_SIZE;
f6bcfd97 386 GdkGeometry geom;
e7dda1ff
VS
387 geom.min_width = minWidth;
388 geom.min_height = minHeight;
389 geom.max_width = maxWidth;
390 geom.max_height = maxHeight;
f6bcfd97
BP
391 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget),
392 (GtkWidget*) NULL,
393 &geom,
394 (GdkWindowHints) flag );
ab2b3dd4 395
047ac72b
RR
396 // I revert back to wxGTK's original behaviour. m_mainWidget holds
397 // the menubar, the toolbar and the client area, which is represented
398 // by m_wxwindow.
399 // This hurts in the eye, but I don't want to call SetSize()
400 // because I don't want to call any non-native functions here.
88ac883a 401
75c9da25 402#if wxUSE_MENUS_NATIVE
ab2b3dd4
RR
403 if (m_frameMenuBar)
404 {
405 int xx = m_miniEdge;
406 int yy = m_miniEdge + m_miniTitle;
407 int ww = m_width - 2*m_miniEdge;
2b5f62a0 408 int hh = m_menuBarHeight;
f03fc89f 409 if (m_menuBarDetached) hh = wxPLACE_HOLDER;
121a3581
RR
410 m_frameMenuBar->m_x = xx;
411 m_frameMenuBar->m_y = yy;
412 m_frameMenuBar->m_width = ww;
413 m_frameMenuBar->m_height = hh;
da048e3d 414 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
88ac883a 415 m_frameMenuBar->m_widget,
f03fc89f
VZ
416 xx, yy, ww, hh );
417 client_area_y_offset += hh;
ab2b3dd4 418 }
75c9da25 419#endif // wxUSE_MENUS_NATIVE
88ac883a 420
dcf924a3 421#if wxUSE_TOOLBAR
fa755cf1 422 if ((m_frameToolBar) && m_frameToolBar->IsShown() &&
7beba2fc 423 (m_frameToolBar->m_widget->parent == m_mainWidget))
ab2b3dd4
RR
424 {
425 int xx = m_miniEdge;
426 int yy = m_miniEdge + m_miniTitle;
75c9da25 427#if wxUSE_MENUS_NATIVE
41ca191f 428 if (m_frameMenuBar)
f03fc89f 429 {
88ac883a 430 if (!m_menuBarDetached)
2b5f62a0 431 yy += m_menuBarHeight;
88ac883a 432 else
f03fc89f
VZ
433 yy += wxPLACE_HOLDER;
434 }
75c9da25 435#endif // wxUSE_MENUS_NATIVE
93fa69f8 436
121a3581
RR
437 m_frameToolBar->m_x = xx;
438 m_frameToolBar->m_y = yy;
93fa69f8 439
047ac72b 440 // don't change the toolbar's reported height/width
93fa69f8
VZ
441 int ww, hh;
442 if ( m_frameToolBar->GetWindowStyle() & wxTB_VERTICAL )
443 {
444 ww = m_toolBarDetached ? wxPLACE_HOLDER
445 : m_frameToolBar->m_width;
446 hh = m_height - 2*m_miniEdge;
447
448 client_area_x_offset += ww;
449 }
450 else
451 {
452 ww = m_width - 2*m_miniEdge;
453 hh = m_toolBarDetached ? wxPLACE_HOLDER
454 : m_frameToolBar->m_height;
7b4c2a06 455
93fa69f8
VZ
456 client_area_y_offset += hh;
457 }
458
da048e3d 459 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
88ac883a 460 m_frameToolBar->m_widget,
f03fc89f 461 xx, yy, ww, hh );
ab2b3dd4 462 }
93fa69f8 463#endif // wxUSE_TOOLBAR
88ac883a 464
93fa69f8 465 int client_x = client_area_x_offset + m_miniEdge;
f03fc89f 466 int client_y = client_area_y_offset + m_miniEdge + m_miniTitle;
93fa69f8 467 int client_w = m_width - client_area_x_offset - 2*m_miniEdge;
f03fc89f 468 int client_h = m_height - client_area_y_offset- 2*m_miniEdge - m_miniTitle;
da048e3d 469 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget),
88ac883a 470 m_wxwindow,
f03fc89f 471 client_x, client_y, client_w, client_h );
32a95f9f
RR
472 }
473 else
474 {
047ac72b
RR
475 // If there is no m_mainWidget between m_widget and m_wxwindow there
476 // is no need to set the size or position of m_wxwindow.
f5368809 477 }
88ac883a 478
dcf924a3 479#if wxUSE_STATUSBAR
fa755cf1 480 if (m_frameStatusBar && m_frameStatusBar->IsShown())
f5368809 481 {
b2b3ccc5 482 int xx = 0 + m_miniEdge;
f362b96d 483 int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge - client_area_y_offset;
ac57418f
RR
484 int ww = m_width - 2*m_miniEdge;
485 int hh = wxSTATUS_HEIGHT;
121a3581
RR
486 m_frameStatusBar->m_x = xx;
487 m_frameStatusBar->m_y = yy;
488 m_frameStatusBar->m_width = ww;
489 m_frameStatusBar->m_height = hh;
da048e3d 490 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow),
7c0ea335
VZ
491 m_frameStatusBar->m_widget,
492 xx, yy, ww, hh );
b6fa52db 493 gtk_widget_draw( m_frameStatusBar->m_widget, (GdkRectangle*) NULL );
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