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