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;
170 bool wxFrame::Create( wxWindow
*parent
,
172 const wxString
& title
,
174 const wxSize
& sizeOrig
,
176 const wxString
&name
)
178 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
183 m_isBeingDeleted
= true;
187 // ----------------------------------------------------------------------------
188 // overridden wxWindow methods
189 // ----------------------------------------------------------------------------
191 void wxFrame::DoGetClientSize( int *width
, int *height
) const
193 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
195 wxFrameBase::DoGetClientSize(width
, height
);
199 #if wxUSE_MENUS_NATIVE
201 if (m_frameMenuBar
&&
202 GTK_WIDGET_VISIBLE(m_frameMenuBar
->m_widget
) && !m_menuBarDetached
)
204 *height
-= m_menuBarHeight
;
206 #endif // wxUSE_MENUS_NATIVE
210 if (m_frameStatusBar
&& GTK_WIDGET_VISIBLE(m_frameStatusBar
->m_widget
))
211 *height
-= wxSTATUS_HEIGHT
;
212 #endif // wxUSE_STATUSBAR
217 if (m_frameToolBar
&&
218 GTK_WIDGET_VISIBLE(m_frameToolBar
->m_widget
) && !m_toolBarDetached
)
220 if (m_frameToolBar
->IsVertical())
223 *width
-= m_frameToolBar
->GetSize().x
;
228 *height
-= m_frameToolBar
->GetSize().y
;
231 #endif // wxUSE_TOOLBAR
233 if (width
!= NULL
&& *width
< 0)
235 if (height
!= NULL
&& *height
< 0)
239 bool wxFrame::ShowFullScreen(bool show
, long style
)
241 if (!wxFrameBase::ShowFullScreen(show
, style
))
244 wxWindow
* const bar
[] = {
245 m_frameMenuBar
, m_frameToolBar
, m_frameStatusBar
247 const long fsNoBar
[] = {
248 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
250 for (int i
= 0; i
< 3; i
++)
254 if (bar
[i
] && (style
& fsNoBar
[i
]))
256 if (bar
[i
]->IsShown())
259 style
&= ~fsNoBar
[i
];
264 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
269 m_fsSaveFlag
= style
;
274 void wxFrame::GtkOnSize()
277 if (m_resizing
) return;
280 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
281 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
283 // space occupied by m_frameToolBar and m_frameMenuBar
284 int client_area_x_offset
= 0,
285 client_area_y_offset
= 0;
287 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
288 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
289 set in wxFrame::Create so it is used to check what kind of frame we
290 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
291 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
292 importantly) m_mainWidget */
299 // Rewrite this terrible code to using GtkVBox
301 // m_mainWidget holds the menubar, the toolbar and the client
302 // area, which is represented by m_wxwindow.
304 #if wxUSE_MENUS_NATIVE
305 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
308 int yy
= m_miniEdge
+ m_miniTitle
;
309 int ww
= m_width
- 2*m_miniEdge
;
312 int hh
= m_menuBarHeight
;
313 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
314 m_frameMenuBar
->m_x
= xx
;
315 m_frameMenuBar
->m_y
= yy
;
316 m_frameMenuBar
->m_width
= ww
;
317 m_frameMenuBar
->m_height
= hh
;
318 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
319 m_frameMenuBar
->m_widget
,
321 client_area_y_offset
+= hh
;
323 #endif // wxUSE_MENUS_NATIVE
326 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
327 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
330 int yy
= m_miniEdge
+ m_miniTitle
;
331 #if wxUSE_MENUS_NATIVE
334 if (!m_menuBarDetached
)
335 yy
+= m_menuBarHeight
;
337 yy
+= wxPLACE_HOLDER
;
339 #endif // wxUSE_MENUS_NATIVE
341 m_frameToolBar
->m_x
= xx
;
342 m_frameToolBar
->m_y
= yy
;
344 // don't change the toolbar's reported height/width
346 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
348 ww
= m_toolBarDetached
? wxPLACE_HOLDER
349 : m_frameToolBar
->m_width
;
350 hh
= m_height
- 2*m_miniEdge
;
352 client_area_x_offset
+= ww
;
354 else if( m_frameToolBar
->HasFlag(wxTB_RIGHT
) )
357 ww
= m_toolBarDetached
? wxPLACE_HOLDER
358 : m_frameToolBar
->m_width
;
359 xx
= GetClientSize().x
- 1;
360 hh
= m_height
- 2*m_miniEdge
;
365 else if( m_frameToolBar
->GetWindowStyle() & wxTB_BOTTOM
)
368 yy
= GetClientSize().y
;
369 #if wxUSE_MENUS_NATIVE
370 yy
+= m_menuBarHeight
;
371 #endif // wxUSE_MENU_NATIVE
372 m_frameToolBar
->m_x
= xx
;
373 m_frameToolBar
->m_y
= yy
;
374 ww
= m_width
- 2*m_miniEdge
;
375 hh
= m_toolBarDetached
? wxPLACE_HOLDER
376 : m_frameToolBar
->m_height
;
380 ww
= m_width
- 2*m_miniEdge
;
381 hh
= m_toolBarDetached
? wxPLACE_HOLDER
382 : m_frameToolBar
->m_height
;
384 client_area_y_offset
+= hh
;
391 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
392 m_frameToolBar
->m_widget
,
395 #endif // wxUSE_TOOLBAR
397 int client_x
= client_area_x_offset
+ m_miniEdge
;
398 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
399 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
400 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
405 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
407 client_x
, client_y
, client_w
, client_h
);
411 // If there is no m_mainWidget between m_widget and m_wxwindow there
412 // is no need to set the size or position of m_wxwindow.
416 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
418 int xx
= 0 + m_miniEdge
;
419 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
420 int ww
= m_width
- 2*m_miniEdge
;
423 int hh
= wxSTATUS_HEIGHT
;
424 m_frameStatusBar
->m_x
= xx
;
425 m_frameStatusBar
->m_y
= yy
;
426 m_frameStatusBar
->m_width
= ww
;
427 m_frameStatusBar
->m_height
= hh
;
428 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
429 m_frameStatusBar
->m_widget
,
432 #endif // wxUSE_STATUSBAR
436 // send size event to frame
437 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
438 event
.SetEventObject( this );
439 GetEventHandler()->ProcessEvent( event
);
442 // send size event to status bar
443 if (m_frameStatusBar
)
445 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
446 event2
.SetEventObject( m_frameStatusBar
);
447 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
449 #endif // wxUSE_STATUSBAR
454 void wxFrame::OnInternalIdle()
456 wxFrameBase::OnInternalIdle();
458 #if wxUSE_MENUS_NATIVE
459 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
460 #endif // wxUSE_MENUS_NATIVE
462 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
465 if (m_frameStatusBar
)
467 m_frameStatusBar
->OnInternalIdle();
469 // There may be controls in the status bar that
470 // need to be updated
471 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
473 node
= node
->GetNext() )
475 wxWindow
*child
= node
->GetData();
476 child
->OnInternalIdle();
482 // ----------------------------------------------------------------------------
483 // menu/tool/status bar stuff
484 // ----------------------------------------------------------------------------
486 #if wxUSE_MENUS_NATIVE
488 void wxFrame::DetachMenuBar()
490 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
491 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
493 if ( m_frameMenuBar
)
495 m_frameMenuBar
->UnsetInvokingWindow( this );
497 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
499 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
500 (gpointer
) gtk_menu_attached_callback
,
503 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
504 (gpointer
) gtk_menu_detached_callback
,
508 gtk_widget_ref( m_frameMenuBar
->m_widget
);
510 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
513 wxFrameBase::DetachMenuBar();
516 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
518 wxFrameBase::AttachMenuBar(menuBar
);
522 m_frameMenuBar
->SetInvokingWindow( this );
524 m_frameMenuBar
->SetParent(this);
525 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
526 m_frameMenuBar
->m_widget
,
529 m_frameMenuBar
->m_width
,
530 m_frameMenuBar
->m_height
);
532 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
534 g_signal_connect (menuBar
->m_widget
, "child_attached",
535 G_CALLBACK (gtk_menu_attached_callback
),
537 g_signal_connect (menuBar
->m_widget
, "child_detached",
538 G_CALLBACK (gtk_menu_detached_callback
),
542 gtk_widget_show( m_frameMenuBar
->m_widget
);
549 GtkUpdateSize(); // resize window in OnInternalIdle
553 void wxFrame::UpdateMenuBarSize()
557 // this is called after Remove with a NULL m_frameMenuBar
558 if ( m_frameMenuBar
)
561 gtk_widget_ensure_style(m_frameMenuBar
->m_widget
);
562 // have to call class method directly because
563 // "size_request" signal is overridden by wx
564 GTK_WIDGET_GET_CLASS(m_frameMenuBar
->m_widget
)->size_request(
565 m_frameMenuBar
->m_widget
, &req
);
567 m_menuBarHeight
= req
.height
;
570 // resize window in OnInternalIdle
574 #endif // wxUSE_MENUS_NATIVE
578 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
580 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
582 InsertChildFunction save
= m_insertCallback
;
583 m_insertCallback
= wxInsertChildInFrame
;
584 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
585 m_insertCallback
= save
;
589 return m_frameToolBar
;
592 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
594 bool hadTbar
= m_frameToolBar
!= NULL
;
596 wxFrameBase::SetToolBar(toolbar
);
598 if ( m_frameToolBar
)
600 // insert into toolbar area if not already there
601 if ((m_frameToolBar
->m_widget
->parent
) &&
602 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
604 GetChildren().DeleteObject( m_frameToolBar
);
606 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
610 else // toolbar unset
612 // still need to update size if it had been there before
620 #endif // wxUSE_TOOLBAR
624 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
627 const wxString
& name
)
629 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
631 // because it will change when toolbar is added
634 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
637 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
639 bool hadStatBar
= m_frameStatusBar
!= NULL
;
641 wxFrameBase::SetStatusBar(statbar
);
643 if (hadStatBar
&& !m_frameStatusBar
)
647 void wxFrame::PositionStatusBar()
649 if ( !m_frameStatusBar
)
654 #endif // wxUSE_STATUSBAR