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