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"
13 // ============================================================================
15 // ============================================================================
17 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
25 #include "wx/dcclient.h"
27 #include "wx/dialog.h"
28 #include "wx/control.h"
29 #include "wx/toolbar.h"
30 #include "wx/statusbr.h"
34 #include "wx/gtk/private.h"
36 #include <gdk/gdkkeysyms.h>
39 #include "wx/gtk/win_gtk.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 const int wxSTATUS_HEIGHT
= 25;
46 const int wxPLACE_HOLDER
= 0;
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
54 // ============================================================================
56 // ============================================================================
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 #if wxUSE_MENUS_NATIVE
64 //-----------------------------------------------------------------------------
65 // "child_attached" of menu bar
66 //-----------------------------------------------------------------------------
69 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
71 if (!win
->m_hasVMT
) return;
73 win
->m_menuBarDetached
= false;
78 //-----------------------------------------------------------------------------
79 // "child_detached" of menu bar
80 //-----------------------------------------------------------------------------
83 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
86 wxapp_install_idle_handler();
88 if (!win
->m_hasVMT
) return;
90 // Raise the client area area
91 gdk_window_raise( win
->m_wxwindow
->window
);
93 win
->m_menuBarDetached
= true;
98 #endif // wxUSE_MENUS_NATIVE
101 //-----------------------------------------------------------------------------
102 // "child_attached" of tool bar
103 //-----------------------------------------------------------------------------
106 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
108 if (!win
->m_hasVMT
) return;
110 win
->m_toolBarDetached
= false;
111 win
->GtkUpdateSize();
115 //-----------------------------------------------------------------------------
116 // "child_detached" of tool bar
117 //-----------------------------------------------------------------------------
120 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
123 wxapp_install_idle_handler();
125 if (!win
->m_hasVMT
) return;
127 // Raise the client area area
128 gdk_window_raise( win
->m_wxwindow
->window
);
130 win
->m_toolBarDetached
= true;
131 win
->GtkUpdateSize();
134 #endif // wxUSE_TOOLBAR
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 //-----------------------------------------------------------------------------
142 // InsertChild for wxFrame
143 //-----------------------------------------------------------------------------
145 /* Callback for wxFrame. This very strange beast has to be used because
146 * C++ has no virtual methods in a constructor. We have to emulate a
147 * virtual function here as wxWidgets requires different ways to insert
148 * a child in container classes. */
150 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
152 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
154 if (!parent
->m_insertInClientArea
)
156 // These are outside the client area
157 wxFrame
* frame
= (wxFrame
*) parent
;
158 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
159 GTK_WIDGET(child
->m_widget
),
165 #if wxUSE_TOOLBAR_NATIVE
166 // We connect to these events for recalculating the client area
167 // space when the toolbar is floating
168 if (wxIS_KIND_OF(child
,wxToolBar
))
170 wxToolBar
*toolBar
= (wxToolBar
*) child
;
171 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
173 g_signal_connect (toolBar
->m_widget
, "child_attached",
174 G_CALLBACK (gtk_toolbar_attached_callback
),
176 g_signal_connect (toolBar
->m_widget
, "child_detached",
177 G_CALLBACK (gtk_toolbar_detached_callback
),
181 #endif // wxUSE_TOOLBAR
185 // These are inside the client area
186 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
187 GTK_WIDGET(child
->m_widget
),
195 // ----------------------------------------------------------------------------
197 // ----------------------------------------------------------------------------
201 m_menuBarDetached
= false;
202 m_toolBarDetached
= false;
206 bool wxFrame::Create( wxWindow
*parent
,
208 const wxString
& title
,
210 const wxSize
& sizeOrig
,
212 const wxString
&name
)
214 bool rt
= wxTopLevelWindow::Create(parent
, id
, title
, pos
, sizeOrig
,
216 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
223 m_isBeingDeleted
= true;
227 // ----------------------------------------------------------------------------
228 // overridden wxWindow methods
229 // ----------------------------------------------------------------------------
231 void wxFrame::DoGetClientSize( int *width
, int *height
) const
233 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
235 wxTopLevelWindow::DoGetClientSize( width
, height
);
239 #if wxUSE_MENUS_NATIVE
243 if (!m_menuBarDetached
)
244 (*height
) -= m_menuBarHeight
;
246 (*height
) -= wxPLACE_HOLDER
;
248 #endif // wxUSE_MENUS_NATIVE
252 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
253 (*height
) -= wxSTATUS_HEIGHT
;
254 #endif // wxUSE_STATUSBAR
258 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
260 if (m_toolBarDetached
)
262 *height
-= wxPLACE_HOLDER
;
267 m_frameToolBar
->GetSize( &x
, &y
);
268 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
278 #endif // wxUSE_TOOLBAR
284 void wxFrame::DoSetClientSize( int width
, int height
)
286 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
288 #if wxUSE_MENUS_NATIVE
292 if (!m_menuBarDetached
)
293 height
+= m_menuBarHeight
;
295 height
+= wxPLACE_HOLDER
;
297 #endif // wxUSE_MENUS_NATIVE
301 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown()) height
+= wxSTATUS_HEIGHT
;
306 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
308 if (m_toolBarDetached
)
310 height
+= wxPLACE_HOLDER
;
315 m_frameToolBar
->GetSize( &x
, &y
);
316 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
328 wxTopLevelWindow::DoSetClientSize( width
, height
);
331 void wxFrame::GtkOnSize()
334 if (m_resizing
) return;
337 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
338 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
340 // space occupied by m_frameToolBar and m_frameMenuBar
341 int client_area_x_offset
= 0,
342 client_area_y_offset
= 0;
344 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
345 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
346 set in wxFrame::Create so it is used to check what kind of frame we
347 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
348 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
349 importantly) m_mainWidget */
351 int minWidth
= GetMinWidth(),
352 minHeight
= GetMinHeight(),
353 maxWidth
= GetMaxWidth(),
354 maxHeight
= GetMaxHeight();
356 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
357 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
358 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
359 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
364 gint flag
= 0; // GDK_HINT_POS;
365 if ((minWidth
!= -1) || (minHeight
!= -1)) flag
|= GDK_HINT_MIN_SIZE
;
366 if ((maxWidth
!= -1) || (maxHeight
!= -1)) flag
|= GDK_HINT_MAX_SIZE
;
368 geom
.min_width
= minWidth
;
369 geom
.min_height
= minHeight
;
370 geom
.max_width
= maxWidth
;
371 geom
.max_height
= maxHeight
;
372 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget
),
375 (GdkWindowHints
) flag
);
377 // I revert back to wxGTK's original behaviour. m_mainWidget holds
378 // the menubar, the toolbar and the client area, which is represented
380 // This hurts in the eye, but I don't want to call SetSize()
381 // because I don't want to call any non-native functions here.
383 #if wxUSE_MENUS_NATIVE
387 int yy
= m_miniEdge
+ m_miniTitle
;
388 int ww
= m_width
- 2*m_miniEdge
;
391 int hh
= m_menuBarHeight
;
392 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
393 m_frameMenuBar
->m_x
= xx
;
394 m_frameMenuBar
->m_y
= yy
;
395 m_frameMenuBar
->m_width
= ww
;
396 m_frameMenuBar
->m_height
= hh
;
397 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
398 m_frameMenuBar
->m_widget
,
400 client_area_y_offset
+= hh
;
402 #endif // wxUSE_MENUS_NATIVE
405 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
406 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
409 int yy
= m_miniEdge
+ m_miniTitle
;
410 #if wxUSE_MENUS_NATIVE
413 if (!m_menuBarDetached
)
414 yy
+= m_menuBarHeight
;
416 yy
+= wxPLACE_HOLDER
;
418 #endif // wxUSE_MENUS_NATIVE
420 m_frameToolBar
->m_x
= xx
;
421 m_frameToolBar
->m_y
= yy
;
423 // don't change the toolbar's reported height/width
425 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
427 ww
= m_toolBarDetached
? wxPLACE_HOLDER
428 : m_frameToolBar
->m_width
;
429 hh
= m_height
- 2*m_miniEdge
;
433 client_area_x_offset
+= ww
;
437 ww
= m_width
- 2*m_miniEdge
;
438 hh
= m_toolBarDetached
? wxPLACE_HOLDER
439 : m_frameToolBar
->m_height
;
441 client_area_y_offset
+= hh
;
444 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
445 m_frameToolBar
->m_widget
,
448 #endif // wxUSE_TOOLBAR
450 int client_x
= client_area_x_offset
+ m_miniEdge
;
451 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
452 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
453 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
458 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
460 client_x
, client_y
, client_w
, client_h
);
464 // If there is no m_mainWidget between m_widget and m_wxwindow there
465 // is no need to set the size or position of m_wxwindow.
469 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
471 int xx
= 0 + m_miniEdge
;
472 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
473 int ww
= m_width
- 2*m_miniEdge
;
476 int hh
= wxSTATUS_HEIGHT
;
477 m_frameStatusBar
->m_x
= xx
;
478 m_frameStatusBar
->m_y
= yy
;
479 m_frameStatusBar
->m_width
= ww
;
480 m_frameStatusBar
->m_height
= hh
;
481 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
482 m_frameStatusBar
->m_widget
,
485 #endif // wxUSE_STATUSBAR
489 // send size event to frame
490 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
491 event
.SetEventObject( this );
492 GetEventHandler()->ProcessEvent( event
);
495 // send size event to status bar
496 if (m_frameStatusBar
)
498 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
499 event2
.SetEventObject( m_frameStatusBar
);
500 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
502 #endif // wxUSE_STATUSBAR
507 void wxFrame::OnInternalIdle()
509 wxFrameBase::OnInternalIdle();
511 #if wxUSE_MENUS_NATIVE
512 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
513 #endif // wxUSE_MENUS_NATIVE
515 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
518 if (m_frameStatusBar
)
520 m_frameStatusBar
->OnInternalIdle();
522 // There may be controls in the status bar that
523 // need to be updated
524 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
526 node
= node
->GetNext() )
528 wxWindow
*child
= node
->GetData();
529 child
->OnInternalIdle();
535 // ----------------------------------------------------------------------------
536 // menu/tool/status bar stuff
537 // ----------------------------------------------------------------------------
539 #if wxUSE_MENUS_NATIVE
541 void wxFrame::DetachMenuBar()
543 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
544 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
546 if ( m_frameMenuBar
)
548 m_frameMenuBar
->UnsetInvokingWindow( this );
550 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
552 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
553 (gpointer
) gtk_menu_attached_callback
,
556 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
557 (gpointer
) gtk_menu_detached_callback
,
561 gtk_widget_ref( m_frameMenuBar
->m_widget
);
563 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
566 wxFrameBase::DetachMenuBar();
569 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
571 wxFrameBase::AttachMenuBar(menuBar
);
575 m_frameMenuBar
->SetInvokingWindow( this );
577 m_frameMenuBar
->SetParent(this);
578 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
579 m_frameMenuBar
->m_widget
,
582 m_frameMenuBar
->m_width
,
583 m_frameMenuBar
->m_height
);
585 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
587 g_signal_connect (menuBar
->m_widget
, "child_attached",
588 G_CALLBACK (gtk_menu_attached_callback
),
590 g_signal_connect (menuBar
->m_widget
, "child_detached",
591 G_CALLBACK (gtk_menu_detached_callback
),
595 gtk_widget_show( m_frameMenuBar
->m_widget
);
602 GtkUpdateSize(); // resize window in OnInternalIdle
606 void wxFrame::UpdateMenuBarSize()
613 // this is called after Remove with a NULL m_frameMenuBar
614 if ( m_frameMenuBar
)
615 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar
->m_widget
) )->size_request
)
616 (m_frameMenuBar
->m_widget
, &req
);
618 m_menuBarHeight
= req
.height
;
620 // resize window in OnInternalIdle
625 #endif // wxUSE_MENUS_NATIVE
629 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
631 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
633 m_insertInClientArea
= false;
635 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
637 m_insertInClientArea
= true;
641 return m_frameToolBar
;
644 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
646 bool hadTbar
= m_frameToolBar
!= NULL
;
648 wxFrameBase::SetToolBar(toolbar
);
650 if ( m_frameToolBar
)
652 // insert into toolbar area if not already there
653 if ((m_frameToolBar
->m_widget
->parent
) &&
654 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
656 GetChildren().DeleteObject( m_frameToolBar
);
658 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
662 else // toolbar unset
664 // still need to update size if it had been there before
672 #endif // wxUSE_TOOLBAR
676 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
679 const wxString
& name
)
681 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
683 // because it will change when toolbar is added
686 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
689 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
691 bool hadStatBar
= m_frameStatusBar
!= NULL
;
693 wxFrameBase::SetStatusBar(statbar
);
695 if (hadStatBar
&& !m_frameStatusBar
)
699 void wxFrame::PositionStatusBar()
701 if ( !m_frameStatusBar
)
706 #endif // wxUSE_STATUSBAR