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