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