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"
21 #include "wx/gtk/private.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
)
69 wxapp_install_idle_handler();
71 if (!win
->m_hasVMT
) return;
73 // Raise the client area area
74 gdk_window_raise( win
->m_wxwindow
->window
);
76 win
->m_menuBarDetached
= true;
81 #endif // wxUSE_MENUS_NATIVE
84 //-----------------------------------------------------------------------------
85 // "child_attached" of tool bar
86 //-----------------------------------------------------------------------------
89 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
91 if (!win
->m_hasVMT
) return;
93 win
->m_toolBarDetached
= false;
98 //-----------------------------------------------------------------------------
99 // "child_detached" of tool bar
100 //-----------------------------------------------------------------------------
103 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
106 wxapp_install_idle_handler();
108 if (!win
->m_hasVMT
) return;
110 // Raise the client area area
111 gdk_window_raise( win
->m_wxwindow
->window
);
113 win
->m_toolBarDetached
= true;
114 win
->GtkUpdateSize();
117 #endif // wxUSE_TOOLBAR
120 // ----------------------------------------------------------------------------
122 // ----------------------------------------------------------------------------
124 //-----------------------------------------------------------------------------
125 // InsertChild for wxFrame
126 //-----------------------------------------------------------------------------
128 /* Callback for wxFrame. This very strange beast has to be used because
129 * C++ has no virtual methods in a constructor. We have to emulate a
130 * virtual function here as wxWidgets requires different ways to insert
131 * a child in container classes. */
133 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
135 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
137 if (!parent
->m_insertInClientArea
)
139 // These are outside the client area
140 wxFrame
* frame
= (wxFrame
*) parent
;
141 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
142 GTK_WIDGET(child
->m_widget
),
148 #if wxUSE_TOOLBAR_NATIVE
149 // We connect to these events for recalculating the client area
150 // space when the toolbar is floating
151 if (wxIS_KIND_OF(child
,wxToolBar
))
153 wxToolBar
*toolBar
= (wxToolBar
*) child
;
154 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
156 g_signal_connect (toolBar
->m_widget
, "child_attached",
157 G_CALLBACK (gtk_toolbar_attached_callback
),
159 g_signal_connect (toolBar
->m_widget
, "child_detached",
160 G_CALLBACK (gtk_toolbar_detached_callback
),
164 #endif // wxUSE_TOOLBAR
168 // These are inside the client area
169 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
170 GTK_WIDGET(child
->m_widget
),
178 // ----------------------------------------------------------------------------
180 // ----------------------------------------------------------------------------
184 m_menuBarDetached
= false;
185 m_toolBarDetached
= false;
189 bool wxFrame::Create( wxWindow
*parent
,
191 const wxString
& title
,
193 const wxSize
& sizeOrig
,
195 const wxString
&name
)
197 bool rt
= wxTopLevelWindow::Create(parent
, id
, title
, pos
, sizeOrig
,
199 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
206 m_isBeingDeleted
= true;
210 // ----------------------------------------------------------------------------
211 // overridden wxWindow methods
212 // ----------------------------------------------------------------------------
214 void wxFrame::DoGetClientSize( int *width
, int *height
) const
216 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
218 wxTopLevelWindow::DoGetClientSize( width
, height
);
222 #if wxUSE_MENUS_NATIVE
226 if (!m_menuBarDetached
)
227 (*height
) -= m_menuBarHeight
;
229 (*height
) -= wxPLACE_HOLDER
;
231 #endif // wxUSE_MENUS_NATIVE
235 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
236 (*height
) -= wxSTATUS_HEIGHT
;
237 #endif // wxUSE_STATUSBAR
242 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
244 if (m_toolBarDetached
)
247 *height
-= wxPLACE_HOLDER
;
252 m_frameToolBar
->GetSize( &x
, &y
);
253 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
265 #endif // wxUSE_TOOLBAR
267 if (width
!= NULL
&& *width
< 0)
269 if (height
!= NULL
&& *height
< 0)
273 void wxFrame::DoSetClientSize( int width
, int height
)
275 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
277 #if wxUSE_MENUS_NATIVE
281 if (!m_menuBarDetached
)
282 height
+= m_menuBarHeight
;
284 height
+= wxPLACE_HOLDER
;
286 #endif // wxUSE_MENUS_NATIVE
290 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown()) height
+= wxSTATUS_HEIGHT
;
295 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
297 if (m_toolBarDetached
)
299 height
+= wxPLACE_HOLDER
;
304 m_frameToolBar
->GetSize( &x
, &y
);
305 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
317 wxTopLevelWindow::DoSetClientSize( width
, height
);
320 void wxFrame::GtkOnSize()
323 if (m_resizing
) return;
326 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
327 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
329 // space occupied by m_frameToolBar and m_frameMenuBar
330 int client_area_x_offset
= 0,
331 client_area_y_offset
= 0;
333 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
334 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
335 set in wxFrame::Create so it is used to check what kind of frame we
336 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
337 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
338 importantly) m_mainWidget */
340 int minWidth
= GetMinWidth(),
341 minHeight
= GetMinHeight(),
342 maxWidth
= GetMaxWidth(),
343 maxHeight
= GetMaxHeight();
345 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
346 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
347 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
348 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
353 gint flag
= 0; // GDK_HINT_POS;
354 if ((minWidth
!= -1) || (minHeight
!= -1)) flag
|= GDK_HINT_MIN_SIZE
;
355 if ((maxWidth
!= -1) || (maxHeight
!= -1)) flag
|= GDK_HINT_MAX_SIZE
;
357 geom
.min_width
= minWidth
;
358 geom
.min_height
= minHeight
;
359 geom
.max_width
= maxWidth
;
360 geom
.max_height
= maxHeight
;
361 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget
),
364 (GdkWindowHints
) flag
);
366 // I revert back to wxGTK's original behaviour. m_mainWidget holds
367 // the menubar, the toolbar and the client area, which is represented
369 // This hurts in the eye, but I don't want to call SetSize()
370 // because I don't want to call any non-native functions here.
372 #if wxUSE_MENUS_NATIVE
376 int yy
= m_miniEdge
+ m_miniTitle
;
377 int ww
= m_width
- 2*m_miniEdge
;
380 int hh
= m_menuBarHeight
;
381 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
382 m_frameMenuBar
->m_x
= xx
;
383 m_frameMenuBar
->m_y
= yy
;
384 m_frameMenuBar
->m_width
= ww
;
385 m_frameMenuBar
->m_height
= hh
;
386 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
387 m_frameMenuBar
->m_widget
,
389 client_area_y_offset
+= hh
;
391 #endif // wxUSE_MENUS_NATIVE
394 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
395 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
398 int yy
= m_miniEdge
+ m_miniTitle
;
399 #if wxUSE_MENUS_NATIVE
402 if (!m_menuBarDetached
)
403 yy
+= m_menuBarHeight
;
405 yy
+= wxPLACE_HOLDER
;
407 #endif // wxUSE_MENUS_NATIVE
409 m_frameToolBar
->m_x
= xx
;
410 m_frameToolBar
->m_y
= yy
;
412 // don't change the toolbar's reported height/width
414 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
416 ww
= m_toolBarDetached
? wxPLACE_HOLDER
417 : m_frameToolBar
->m_width
;
418 hh
= m_height
- 2*m_miniEdge
;
422 client_area_x_offset
+= ww
;
424 else if( m_frameToolBar
->GetWindowStyle() & wxTB_BOTTOM
)
427 yy
= GetClientSize().y
;
428 #if wxUSE_MENUS_NATIVE
429 yy
+= m_menuBarHeight
;
430 #endif // wxUSE_MENU_NATIVE
431 m_frameToolBar
->m_x
= xx
;
432 m_frameToolBar
->m_y
= yy
;
433 ww
= m_width
- 2*m_miniEdge
;
434 hh
= m_toolBarDetached
? wxPLACE_HOLDER
435 : m_frameToolBar
->m_height
;
439 ww
= m_width
- 2*m_miniEdge
;
440 hh
= m_toolBarDetached
? wxPLACE_HOLDER
441 : m_frameToolBar
->m_height
;
443 client_area_y_offset
+= hh
;
446 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
447 m_frameToolBar
->m_widget
,
450 #endif // wxUSE_TOOLBAR
452 int client_x
= client_area_x_offset
+ m_miniEdge
;
453 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
454 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
455 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
460 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
462 client_x
, client_y
, client_w
, client_h
);
466 // If there is no m_mainWidget between m_widget and m_wxwindow there
467 // is no need to set the size or position of m_wxwindow.
471 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
473 int xx
= 0 + m_miniEdge
;
474 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
475 int ww
= m_width
- 2*m_miniEdge
;
478 int hh
= wxSTATUS_HEIGHT
;
479 m_frameStatusBar
->m_x
= xx
;
480 m_frameStatusBar
->m_y
= yy
;
481 m_frameStatusBar
->m_width
= ww
;
482 m_frameStatusBar
->m_height
= hh
;
483 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
484 m_frameStatusBar
->m_widget
,
487 #endif // wxUSE_STATUSBAR
491 // send size event to frame
492 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
493 event
.SetEventObject( this );
494 GetEventHandler()->ProcessEvent( event
);
497 // send size event to status bar
498 if (m_frameStatusBar
)
500 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
501 event2
.SetEventObject( m_frameStatusBar
);
502 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
504 #endif // wxUSE_STATUSBAR
509 void wxFrame::OnInternalIdle()
511 wxFrameBase::OnInternalIdle();
513 #if wxUSE_MENUS_NATIVE
514 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
515 #endif // wxUSE_MENUS_NATIVE
517 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
520 if (m_frameStatusBar
)
522 m_frameStatusBar
->OnInternalIdle();
524 // There may be controls in the status bar that
525 // need to be updated
526 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
528 node
= node
->GetNext() )
530 wxWindow
*child
= node
->GetData();
531 child
->OnInternalIdle();
537 // ----------------------------------------------------------------------------
538 // menu/tool/status bar stuff
539 // ----------------------------------------------------------------------------
541 #if wxUSE_MENUS_NATIVE
543 void wxFrame::DetachMenuBar()
545 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
546 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
548 if ( m_frameMenuBar
)
550 m_frameMenuBar
->UnsetInvokingWindow( this );
552 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
554 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
555 (gpointer
) gtk_menu_attached_callback
,
558 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
559 (gpointer
) gtk_menu_detached_callback
,
563 gtk_widget_ref( m_frameMenuBar
->m_widget
);
565 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
568 wxFrameBase::DetachMenuBar();
571 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
573 wxFrameBase::AttachMenuBar(menuBar
);
577 m_frameMenuBar
->SetInvokingWindow( this );
579 m_frameMenuBar
->SetParent(this);
580 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
581 m_frameMenuBar
->m_widget
,
584 m_frameMenuBar
->m_width
,
585 m_frameMenuBar
->m_height
);
587 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
589 g_signal_connect (menuBar
->m_widget
, "child_attached",
590 G_CALLBACK (gtk_menu_attached_callback
),
592 g_signal_connect (menuBar
->m_widget
, "child_detached",
593 G_CALLBACK (gtk_menu_detached_callback
),
597 gtk_widget_show( m_frameMenuBar
->m_widget
);
604 GtkUpdateSize(); // resize window in OnInternalIdle
608 void wxFrame::UpdateMenuBarSize()
615 // this is called after Remove with a NULL m_frameMenuBar
616 if ( m_frameMenuBar
)
617 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar
->m_widget
) )->size_request
)
618 (m_frameMenuBar
->m_widget
, &req
);
620 m_menuBarHeight
= req
.height
;
622 // resize window in OnInternalIdle
627 #endif // wxUSE_MENUS_NATIVE
631 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
633 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
635 m_insertInClientArea
= false;
637 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
639 m_insertInClientArea
= true;
643 return m_frameToolBar
;
646 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
648 bool hadTbar
= m_frameToolBar
!= NULL
;
650 wxFrameBase::SetToolBar(toolbar
);
652 if ( m_frameToolBar
)
654 // insert into toolbar area if not already there
655 if ((m_frameToolBar
->m_widget
->parent
) &&
656 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
658 GetChildren().DeleteObject( m_frameToolBar
);
660 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
664 else // toolbar unset
666 // still need to update size if it had been there before
674 #endif // wxUSE_TOOLBAR
678 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
681 const wxString
& name
)
683 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
685 // because it will change when toolbar is added
688 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
691 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
693 bool hadStatBar
= m_frameStatusBar
!= NULL
;
695 wxFrameBase::SetStatusBar(statbar
);
697 if (hadStatBar
&& !m_frameStatusBar
)
701 void wxFrame::PositionStatusBar()
703 if ( !m_frameStatusBar
)
708 #endif // wxUSE_STATUSBAR