1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/frame.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
17 #include "wx/toolbar.h"
18 #include "wx/statusbr.h"
22 #include "wx/gtk/win_gtk.h"
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
28 static const int wxSTATUS_HEIGHT
= 25;
29 static const int wxPLACE_HOLDER
= 0;
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
37 // ============================================================================
39 // ============================================================================
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 #if wxUSE_MENUS_NATIVE
47 //-----------------------------------------------------------------------------
48 // "child_attached" of menu bar
49 //-----------------------------------------------------------------------------
52 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
54 if (!win
->m_hasVMT
) return;
56 win
->m_menuBarDetached
= false;
61 //-----------------------------------------------------------------------------
62 // "child_detached" of menu bar
63 //-----------------------------------------------------------------------------
66 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
68 if (!win
->m_hasVMT
) return;
70 // Raise the client area area
71 gdk_window_raise( win
->m_wxwindow
->window
);
73 win
->m_menuBarDetached
= true;
78 #endif // wxUSE_MENUS_NATIVE
81 //-----------------------------------------------------------------------------
82 // "child_attached" of tool bar
83 //-----------------------------------------------------------------------------
86 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
88 if (!win
->m_hasVMT
) return;
90 win
->m_toolBarDetached
= false;
95 //-----------------------------------------------------------------------------
96 // "child_detached" of tool bar
97 //-----------------------------------------------------------------------------
100 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
102 if (!win
->m_hasVMT
) return;
104 // Raise the client area area
105 gdk_window_raise( win
->m_wxwindow
->window
);
107 win
->m_toolBarDetached
= true;
108 win
->GtkUpdateSize();
111 #endif // wxUSE_TOOLBAR
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 //-----------------------------------------------------------------------------
119 // InsertChild for wxFrame
120 //-----------------------------------------------------------------------------
124 /* Callback for wxFrame. This very strange beast has to be used because
125 * C++ has no virtual methods in a constructor. We have to emulate a
126 * virtual function here as wxWidgets requires different ways to insert
127 * a child in container classes. */
129 static void wxInsertChildInFrame(wxWindow
* parent
, wxWindow
* child
)
131 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
133 // These are outside the client area
134 wxFrame
* frame
= wx_static_cast(wxFrame
*, parent
);
135 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
142 #if wxUSE_TOOLBAR_NATIVE
143 // We connect to these events for recalculating the client area
144 // space when the toolbar is floating
145 if (wxIS_KIND_OF(child
,wxToolBar
))
147 if (child
->HasFlag(wxTB_DOCKABLE
))
149 g_signal_connect (child
->m_widget
, "child_attached",
150 G_CALLBACK (gtk_toolbar_attached_callback
),
152 g_signal_connect (child
->m_widget
, "child_detached",
153 G_CALLBACK (gtk_toolbar_detached_callback
),
157 #endif // wxUSE_TOOLBAR_NATIVE
160 #endif // wxUSE_TOOLBAR
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
168 m_menuBarDetached
= false;
169 m_toolBarDetached
= false;
174 bool wxFrame::Create( wxWindow
*parent
,
176 const wxString
& title
,
178 const wxSize
& sizeOrig
,
180 const wxString
&name
)
182 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
187 m_isBeingDeleted
= true;
191 // ----------------------------------------------------------------------------
192 // overridden wxWindow methods
193 // ----------------------------------------------------------------------------
195 void wxFrame::DoGetClientSize( int *width
, int *height
) const
197 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
199 wxFrameBase::DoGetClientSize(width
, height
);
203 #if wxUSE_MENUS_NATIVE
205 if (HasVisibleMenubar() && !m_menuBarDetached
)
207 *height
-= m_menuBarHeight
;
209 #endif // wxUSE_MENUS_NATIVE
213 if (m_frameStatusBar
&& GTK_WIDGET_VISIBLE(m_frameStatusBar
->m_widget
))
214 *height
-= wxSTATUS_HEIGHT
;
215 #endif // wxUSE_STATUSBAR
220 if (m_frameToolBar
&&
221 GTK_WIDGET_VISIBLE(m_frameToolBar
->m_widget
) && !m_toolBarDetached
)
223 if (m_frameToolBar
->IsVertical())
226 *width
-= m_frameToolBar
->GetSize().x
;
231 *height
-= m_frameToolBar
->GetSize().y
;
234 #endif // wxUSE_TOOLBAR
236 if (width
!= NULL
&& *width
< 0)
238 if (height
!= NULL
&& *height
< 0)
242 bool wxFrame::ShowFullScreen(bool show
, long style
)
244 if (!wxFrameBase::ShowFullScreen(show
, style
))
247 wxWindow
* const bar
[] = {
264 const long fsNoBar
[] = {
265 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
267 for (int i
= 0; i
< 3; i
++)
271 if (bar
[i
] && (style
& fsNoBar
[i
]))
273 if (bar
[i
]->IsShown())
276 style
&= ~fsNoBar
[i
];
281 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
286 m_fsSaveFlag
= style
;
291 void wxFrame::GtkOnSize()
294 if (m_resizing
) return;
297 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
298 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
300 // space occupied by m_frameToolBar and m_frameMenuBar
301 int client_area_x_offset
= 0,
302 client_area_y_offset
= 0;
304 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
305 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
306 set in wxFrame::Create so it is used to check what kind of frame we
307 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
308 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
309 importantly) m_mainWidget */
316 // Rewrite this terrible code to using GtkVBox
318 // m_mainWidget holds the menubar, the toolbar and the client
319 // area, which is represented by m_wxwindow.
321 int menubarHeight
= 0;
322 #if wxUSE_MENUS_NATIVE
323 if (HasVisibleMenubar())
326 int yy
= m_miniEdge
+ m_miniTitle
;
327 int ww
= m_width
- 2*m_miniEdge
;
330 menubarHeight
= m_menuBarHeight
;
331 if (m_menuBarDetached
) menubarHeight
= wxPLACE_HOLDER
;
332 m_frameMenuBar
->m_x
= xx
;
333 m_frameMenuBar
->m_y
= yy
;
334 m_frameMenuBar
->m_width
= ww
;
335 m_frameMenuBar
->m_height
= menubarHeight
;
336 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
337 m_frameMenuBar
->m_widget
,
338 xx
, yy
, ww
, menubarHeight
);
339 client_area_y_offset
+= menubarHeight
;
341 #endif // wxUSE_MENUS_NATIVE
344 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
345 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
348 int yy
= m_miniEdge
+ m_miniTitle
+ menubarHeight
;
350 m_frameToolBar
->m_x
= xx
;
351 m_frameToolBar
->m_y
= yy
;
353 // don't change the toolbar's reported height/width
355 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
357 ww
= m_toolBarDetached
? wxPLACE_HOLDER
358 : m_frameToolBar
->m_width
;
359 hh
= m_height
- 2*m_miniEdge
;
361 client_area_x_offset
+= ww
;
363 else if( m_frameToolBar
->HasFlag(wxTB_RIGHT
) )
366 ww
= m_toolBarDetached
? wxPLACE_HOLDER
367 : m_frameToolBar
->m_width
;
368 xx
= GetClientSize().x
- 1;
369 hh
= m_height
- 2*m_miniEdge
;
374 else if( m_frameToolBar
->GetWindowStyle() & wxTB_BOTTOM
)
377 yy
= GetClientSize().y
;
378 #if wxUSE_MENUS_NATIVE
379 yy
+= m_menuBarHeight
;
380 #endif // wxUSE_MENU_NATIVE
381 m_frameToolBar
->m_x
= xx
;
382 m_frameToolBar
->m_y
= yy
;
383 ww
= m_width
- 2*m_miniEdge
;
384 hh
= m_toolBarDetached
? wxPLACE_HOLDER
385 : m_frameToolBar
->m_height
;
389 ww
= m_width
- 2*m_miniEdge
;
390 hh
= m_toolBarDetached
? wxPLACE_HOLDER
391 : m_frameToolBar
->m_height
;
393 client_area_y_offset
+= hh
;
400 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
401 m_frameToolBar
->m_widget
,
404 #endif // wxUSE_TOOLBAR
406 int client_x
= client_area_x_offset
+ m_miniEdge
;
407 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
408 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
409 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
414 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
416 client_x
, client_y
, client_w
, client_h
);
420 // If there is no m_mainWidget between m_widget and m_wxwindow there
421 // is no need to set the size or position of m_wxwindow.
425 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
427 int xx
= 0 + m_miniEdge
;
428 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
429 int ww
= m_width
- 2*m_miniEdge
;
432 int hh
= wxSTATUS_HEIGHT
;
433 m_frameStatusBar
->m_x
= xx
;
434 m_frameStatusBar
->m_y
= yy
;
435 m_frameStatusBar
->m_width
= ww
;
436 m_frameStatusBar
->m_height
= hh
;
437 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
438 m_frameStatusBar
->m_widget
,
441 #endif // wxUSE_STATUSBAR
445 // send size event to frame
446 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
447 event
.SetEventObject( this );
448 GetEventHandler()->ProcessEvent( event
);
451 // send size event to status bar
452 if (m_frameStatusBar
)
454 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
455 event2
.SetEventObject( m_frameStatusBar
);
456 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
458 #endif // wxUSE_STATUSBAR
463 void wxFrame::OnInternalIdle()
465 wxFrameBase::OnInternalIdle();
467 #if wxUSE_MENUS_NATIVE
468 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
469 #endif // wxUSE_MENUS_NATIVE
471 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
474 if (m_frameStatusBar
)
476 m_frameStatusBar
->OnInternalIdle();
478 // There may be controls in the status bar that
479 // need to be updated
480 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
482 node
= node
->GetNext() )
484 wxWindow
*child
= node
->GetData();
485 child
->OnInternalIdle();
491 // ----------------------------------------------------------------------------
492 // menu/tool/status bar stuff
493 // ----------------------------------------------------------------------------
495 #if wxUSE_MENUS_NATIVE
497 void wxFrame::DetachMenuBar()
499 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
500 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
502 if ( m_frameMenuBar
)
504 m_frameMenuBar
->UnsetInvokingWindow( this );
506 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
508 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
509 (gpointer
) gtk_menu_attached_callback
,
512 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
513 (gpointer
) gtk_menu_detached_callback
,
517 gtk_widget_ref( m_frameMenuBar
->m_widget
);
519 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
522 wxFrameBase::DetachMenuBar();
525 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
527 wxFrameBase::AttachMenuBar(menuBar
);
531 m_frameMenuBar
->SetInvokingWindow( this );
533 m_frameMenuBar
->SetParent(this);
534 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
535 m_frameMenuBar
->m_widget
,
538 m_frameMenuBar
->m_width
,
539 m_frameMenuBar
->m_height
);
541 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
543 g_signal_connect (menuBar
->m_widget
, "child_attached",
544 G_CALLBACK (gtk_menu_attached_callback
),
546 g_signal_connect (menuBar
->m_widget
, "child_detached",
547 G_CALLBACK (gtk_menu_detached_callback
),
551 gtk_widget_show( m_frameMenuBar
->m_widget
);
558 GtkUpdateSize(); // resize window in OnInternalIdle
562 void wxFrame::UpdateMenuBarSize()
566 // this is called after Remove with a NULL m_frameMenuBar
567 if ( m_frameMenuBar
)
570 gtk_widget_ensure_style(m_frameMenuBar
->m_widget
);
571 // have to call class method directly because
572 // "size_request" signal is overridden by wx
573 GTK_WIDGET_GET_CLASS(m_frameMenuBar
->m_widget
)->size_request(
574 m_frameMenuBar
->m_widget
, &req
);
576 m_menuBarHeight
= req
.height
;
579 // resize window in OnInternalIdle
583 bool wxFrame::HasVisibleMenubar() const
585 return m_frameMenuBar
&& m_frameMenuBar
->IsShown();
587 #endif // wxUSE_MENUS_NATIVE
591 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
593 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
595 InsertChildFunction save
= m_insertCallback
;
596 m_insertCallback
= wxInsertChildInFrame
;
597 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
598 m_insertCallback
= save
;
602 return m_frameToolBar
;
605 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
607 bool hadTbar
= m_frameToolBar
!= NULL
;
609 wxFrameBase::SetToolBar(toolbar
);
611 if ( m_frameToolBar
)
613 // insert into toolbar area if not already there
614 if ((m_frameToolBar
->m_widget
->parent
) &&
615 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
617 GetChildren().DeleteObject( m_frameToolBar
);
619 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
623 else // toolbar unset
625 // still need to update size if it had been there before
633 #endif // wxUSE_TOOLBAR
637 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
640 const wxString
& name
)
642 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
644 // because it will change when toolbar is added
647 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
650 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
652 bool hadStatBar
= m_frameStatusBar
!= NULL
;
654 wxFrameBase::SetStatusBar(statbar
);
656 if (hadStatBar
&& !m_frameStatusBar
)
660 void wxFrame::PositionStatusBar()
662 if ( !m_frameStatusBar
)
667 #endif // wxUSE_STATUSBAR