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 //-----------------------------------------------------------------------------
122 /* Callback for wxFrame. This very strange beast has to be used because
123 * C++ has no virtual methods in a constructor. We have to emulate a
124 * virtual function here as wxWidgets requires different ways to insert
125 * a child in container classes. */
127 static void wxInsertChildInFrame(wxWindow
* parent
, wxWindow
* child
)
129 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
131 // These are outside the client area
132 wxFrame
* frame
= wx_static_cast(wxFrame
*, parent
);
133 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
140 #if wxUSE_TOOLBAR_NATIVE
141 // We connect to these events for recalculating the client area
142 // space when the toolbar is floating
143 if (wxIS_KIND_OF(child
,wxToolBar
))
145 if (child
->HasFlag(wxTB_DOCKABLE
))
147 g_signal_connect (child
->m_widget
, "child_attached",
148 G_CALLBACK (gtk_toolbar_attached_callback
),
150 g_signal_connect (child
->m_widget
, "child_detached",
151 G_CALLBACK (gtk_toolbar_detached_callback
),
155 #endif // wxUSE_TOOLBAR
158 // ----------------------------------------------------------------------------
160 // ----------------------------------------------------------------------------
164 m_menuBarDetached
= false;
165 m_toolBarDetached
= false;
169 bool wxFrame::Create( wxWindow
*parent
,
171 const wxString
& title
,
173 const wxSize
& sizeOrig
,
175 const wxString
&name
)
177 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
182 m_isBeingDeleted
= true;
186 // ----------------------------------------------------------------------------
187 // overridden wxWindow methods
188 // ----------------------------------------------------------------------------
190 void wxFrame::DoGetClientSize( int *width
, int *height
) const
192 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
194 wxFrameBase::DoGetClientSize(width
, height
);
198 #if wxUSE_MENUS_NATIVE
200 if (m_frameMenuBar
&&
201 GTK_WIDGET_VISIBLE(m_frameMenuBar
->m_widget
) && !m_menuBarDetached
)
203 *height
-= m_menuBarHeight
;
205 #endif // wxUSE_MENUS_NATIVE
209 if (m_frameStatusBar
&& GTK_WIDGET_VISIBLE(m_frameStatusBar
->m_widget
))
210 *height
-= wxSTATUS_HEIGHT
;
211 #endif // wxUSE_STATUSBAR
216 if (m_frameToolBar
&&
217 GTK_WIDGET_VISIBLE(m_frameToolBar
->m_widget
) && !m_toolBarDetached
)
219 if (m_frameToolBar
->IsVertical())
222 *width
-= m_frameToolBar
->GetSize().x
;
227 *height
-= m_frameToolBar
->GetSize().y
;
230 #endif // wxUSE_TOOLBAR
232 if (width
!= NULL
&& *width
< 0)
234 if (height
!= NULL
&& *height
< 0)
238 void wxFrame::GtkOnSize()
241 if (m_resizing
) return;
244 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
245 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
247 // space occupied by m_frameToolBar and m_frameMenuBar
248 int client_area_x_offset
= 0,
249 client_area_y_offset
= 0;
251 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
252 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
253 set in wxFrame::Create so it is used to check what kind of frame we
254 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
255 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
256 importantly) m_mainWidget */
263 // Rewrite this terrible code to using GtkVBox
265 // m_mainWidget holds the menubar, the toolbar and the client
266 // area, which is represented by m_wxwindow.
268 #if wxUSE_MENUS_NATIVE
269 if (m_frameMenuBar
&& !(m_fsIsShowing
&& (m_fsSaveFlag
& wxFULLSCREEN_NOMENUBAR
) != 0))
271 if (!GTK_WIDGET_VISIBLE(m_frameMenuBar
->m_widget
))
272 gtk_widget_show( m_frameMenuBar
->m_widget
);
274 int yy
= m_miniEdge
+ m_miniTitle
;
275 int ww
= m_width
- 2*m_miniEdge
;
278 int hh
= m_menuBarHeight
;
279 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
280 m_frameMenuBar
->m_x
= xx
;
281 m_frameMenuBar
->m_y
= yy
;
282 m_frameMenuBar
->m_width
= ww
;
283 m_frameMenuBar
->m_height
= hh
;
284 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
285 m_frameMenuBar
->m_widget
,
287 client_area_y_offset
+= hh
;
293 if (GTK_WIDGET_VISIBLE(m_frameMenuBar
->m_widget
))
294 gtk_widget_hide( m_frameMenuBar
->m_widget
);
297 #endif // wxUSE_MENUS_NATIVE
300 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
301 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
304 int yy
= m_miniEdge
+ m_miniTitle
;
305 #if wxUSE_MENUS_NATIVE
308 if (!m_menuBarDetached
)
309 yy
+= m_menuBarHeight
;
311 yy
+= wxPLACE_HOLDER
;
313 #endif // wxUSE_MENUS_NATIVE
315 m_frameToolBar
->m_x
= xx
;
316 m_frameToolBar
->m_y
= yy
;
318 // don't change the toolbar's reported height/width
320 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
322 ww
= m_toolBarDetached
? wxPLACE_HOLDER
323 : m_frameToolBar
->m_width
;
324 hh
= m_height
- 2*m_miniEdge
;
326 client_area_x_offset
+= ww
;
328 else if( m_frameToolBar
->HasFlag(wxTB_RIGHT
) )
331 ww
= m_toolBarDetached
? wxPLACE_HOLDER
332 : m_frameToolBar
->m_width
;
333 xx
= GetClientSize().x
- 1;
334 hh
= m_height
- 2*m_miniEdge
;
339 else if( m_frameToolBar
->GetWindowStyle() & wxTB_BOTTOM
)
342 yy
= GetClientSize().y
;
343 #if wxUSE_MENUS_NATIVE
344 yy
+= m_menuBarHeight
;
345 #endif // wxUSE_MENU_NATIVE
346 m_frameToolBar
->m_x
= xx
;
347 m_frameToolBar
->m_y
= yy
;
348 ww
= m_width
- 2*m_miniEdge
;
349 hh
= m_toolBarDetached
? wxPLACE_HOLDER
350 : m_frameToolBar
->m_height
;
354 ww
= m_width
- 2*m_miniEdge
;
355 hh
= m_toolBarDetached
? wxPLACE_HOLDER
356 : m_frameToolBar
->m_height
;
358 client_area_y_offset
+= hh
;
365 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
366 m_frameToolBar
->m_widget
,
369 #endif // wxUSE_TOOLBAR
371 int client_x
= client_area_x_offset
+ m_miniEdge
;
372 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
373 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
374 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
379 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
381 client_x
, client_y
, client_w
, client_h
);
385 // If there is no m_mainWidget between m_widget and m_wxwindow there
386 // is no need to set the size or position of m_wxwindow.
390 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown() &&
391 !(m_fsIsShowing
&& (m_fsSaveFlag
& wxFULLSCREEN_NOSTATUSBAR
) != 0))
393 if (!GTK_WIDGET_VISIBLE(m_frameStatusBar
->m_widget
))
394 gtk_widget_show( m_frameStatusBar
->m_widget
);
396 int xx
= 0 + m_miniEdge
;
397 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
398 int ww
= m_width
- 2*m_miniEdge
;
401 int hh
= wxSTATUS_HEIGHT
;
402 m_frameStatusBar
->m_x
= xx
;
403 m_frameStatusBar
->m_y
= yy
;
404 m_frameStatusBar
->m_width
= ww
;
405 m_frameStatusBar
->m_height
= hh
;
406 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
407 m_frameStatusBar
->m_widget
,
412 if (m_frameStatusBar
)
414 if (GTK_WIDGET_VISIBLE(m_frameStatusBar
->m_widget
))
415 gtk_widget_hide( m_frameStatusBar
->m_widget
);
418 #endif // wxUSE_STATUSBAR
422 // send size event to frame
423 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
424 event
.SetEventObject( this );
425 GetEventHandler()->ProcessEvent( event
);
428 // send size event to status bar
429 if (m_frameStatusBar
)
431 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
432 event2
.SetEventObject( m_frameStatusBar
);
433 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
435 #endif // wxUSE_STATUSBAR
440 void wxFrame::OnInternalIdle()
442 wxFrameBase::OnInternalIdle();
444 #if wxUSE_MENUS_NATIVE
445 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
446 #endif // wxUSE_MENUS_NATIVE
448 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
451 if (m_frameStatusBar
)
453 m_frameStatusBar
->OnInternalIdle();
455 // There may be controls in the status bar that
456 // need to be updated
457 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
459 node
= node
->GetNext() )
461 wxWindow
*child
= node
->GetData();
462 child
->OnInternalIdle();
468 // ----------------------------------------------------------------------------
469 // menu/tool/status bar stuff
470 // ----------------------------------------------------------------------------
472 #if wxUSE_MENUS_NATIVE
474 void wxFrame::DetachMenuBar()
476 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
477 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
479 if ( m_frameMenuBar
)
481 m_frameMenuBar
->UnsetInvokingWindow( this );
483 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
485 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
486 (gpointer
) gtk_menu_attached_callback
,
489 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
490 (gpointer
) gtk_menu_detached_callback
,
494 gtk_widget_ref( m_frameMenuBar
->m_widget
);
496 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
499 wxFrameBase::DetachMenuBar();
502 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
504 wxFrameBase::AttachMenuBar(menuBar
);
508 m_frameMenuBar
->SetInvokingWindow( this );
510 m_frameMenuBar
->SetParent(this);
511 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
512 m_frameMenuBar
->m_widget
,
515 m_frameMenuBar
->m_width
,
516 m_frameMenuBar
->m_height
);
518 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
520 g_signal_connect (menuBar
->m_widget
, "child_attached",
521 G_CALLBACK (gtk_menu_attached_callback
),
523 g_signal_connect (menuBar
->m_widget
, "child_detached",
524 G_CALLBACK (gtk_menu_detached_callback
),
528 gtk_widget_show( m_frameMenuBar
->m_widget
);
535 GtkUpdateSize(); // resize window in OnInternalIdle
539 void wxFrame::UpdateMenuBarSize()
543 // this is called after Remove with a NULL m_frameMenuBar
544 if ( m_frameMenuBar
)
547 gtk_widget_ensure_style(m_frameMenuBar
->m_widget
);
548 // have to call class method directly because
549 // "size_request" signal is overridden by wx
550 GTK_WIDGET_GET_CLASS(m_frameMenuBar
->m_widget
)->size_request(
551 m_frameMenuBar
->m_widget
, &req
);
553 m_menuBarHeight
= req
.height
;
556 // resize window in OnInternalIdle
560 #endif // wxUSE_MENUS_NATIVE
564 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
566 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
568 InsertChildFunction save
= m_insertCallback
;
569 m_insertCallback
= wxInsertChildInFrame
;
570 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
571 m_insertCallback
= save
;
575 return m_frameToolBar
;
578 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
580 bool hadTbar
= m_frameToolBar
!= NULL
;
582 wxFrameBase::SetToolBar(toolbar
);
584 if ( m_frameToolBar
)
586 // insert into toolbar area if not already there
587 if ((m_frameToolBar
->m_widget
->parent
) &&
588 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
590 GetChildren().DeleteObject( m_frameToolBar
);
592 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
596 else // toolbar unset
598 // still need to update size if it had been there before
606 #endif // wxUSE_TOOLBAR
610 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
613 const wxString
& name
)
615 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
617 // because it will change when toolbar is added
620 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
623 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
625 bool hadStatBar
= m_frameStatusBar
!= NULL
;
627 wxFrameBase::SetStatusBar(statbar
);
629 if (hadStatBar
&& !m_frameStatusBar
)
633 void wxFrame::PositionStatusBar()
635 if ( !m_frameStatusBar
)
640 #endif // wxUSE_STATUSBAR