1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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/gtk1/private.h"
36 #include <gdk/gdkkeysyms.h>
39 #include "wx/gtk1/win_gtk.h"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 const int wxSTATUS_HEIGHT
= 25;
46 const int wxPLACE_HOLDER
= 0;
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 extern void wxapp_install_idle_handler();
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
61 // ============================================================================
63 // ============================================================================
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 #if wxUSE_MENUS_NATIVE
71 //-----------------------------------------------------------------------------
72 // "child_attached" of menu bar
73 //-----------------------------------------------------------------------------
76 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
78 if (!win
->m_hasVMT
) return;
80 win
->m_menuBarDetached
= false;
85 //-----------------------------------------------------------------------------
86 // "child_detached" of menu bar
87 //-----------------------------------------------------------------------------
90 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
93 wxapp_install_idle_handler();
95 if (!win
->m_hasVMT
) return;
97 // Raise the client area area
98 gdk_window_raise( win
->m_wxwindow
->window
);
100 win
->m_menuBarDetached
= true;
101 win
->GtkUpdateSize();
105 #endif // wxUSE_MENUS_NATIVE
108 //-----------------------------------------------------------------------------
109 // "child_attached" of tool bar
110 //-----------------------------------------------------------------------------
113 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
115 if (!win
->m_hasVMT
) return;
117 win
->m_toolBarDetached
= false;
118 win
->GtkUpdateSize();
122 //-----------------------------------------------------------------------------
123 // "child_detached" of tool bar
124 //-----------------------------------------------------------------------------
127 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
130 wxapp_install_idle_handler();
132 if (!win
->m_hasVMT
) return;
134 // Raise the client area area
135 gdk_window_raise( win
->m_wxwindow
->window
);
137 win
->m_toolBarDetached
= true;
138 win
->GtkUpdateSize();
141 #endif // wxUSE_TOOLBAR
144 // ----------------------------------------------------------------------------
146 // ----------------------------------------------------------------------------
148 //-----------------------------------------------------------------------------
149 // InsertChild for wxFrame
150 //-----------------------------------------------------------------------------
152 /* Callback for wxFrame. This very strange beast has to be used because
153 * C++ has no virtual methods in a constructor. We have to emulate a
154 * virtual function here as wxWidgets requires different ways to insert
155 * a child in container classes. */
157 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
159 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
161 if (!parent
->m_insertInClientArea
)
163 // These are outside the client area
164 wxFrame
* frame
= (wxFrame
*) parent
;
165 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
166 GTK_WIDGET(child
->m_widget
),
172 #if wxUSE_TOOLBAR_NATIVE
173 // We connect to these events for recalculating the client area
174 // space when the toolbar is floating
175 if (wxIS_KIND_OF(child
,wxToolBar
))
177 wxToolBar
*toolBar
= (wxToolBar
*) child
;
178 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
180 gtk_signal_connect( GTK_OBJECT(toolBar
->m_widget
), "child_attached",
181 GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback
), (gpointer
)parent
);
183 gtk_signal_connect( GTK_OBJECT(toolBar
->m_widget
), "child_detached",
184 GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback
), (gpointer
)parent
);
187 #endif // wxUSE_TOOLBAR
191 // These are inside the client area
192 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
193 GTK_WIDGET(child
->m_widget
),
200 // Resize on OnInternalIdle
201 parent
->GtkUpdateSize();
204 // ----------------------------------------------------------------------------
206 // ----------------------------------------------------------------------------
210 m_menuBarDetached
= false;
211 m_toolBarDetached
= false;
215 bool wxFrame::Create( wxWindow
*parent
,
217 const wxString
& title
,
219 const wxSize
& sizeOrig
,
221 const wxString
&name
)
223 bool rt
= wxTopLevelWindow::Create(parent
, id
, title
, pos
, sizeOrig
,
225 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
232 m_isBeingDeleted
= true;
236 // ----------------------------------------------------------------------------
237 // overridden wxWindow methods
238 // ----------------------------------------------------------------------------
240 void wxFrame::DoGetClientSize( int *width
, int *height
) const
242 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
244 wxTopLevelWindow::DoGetClientSize( width
, height
);
248 #if wxUSE_MENUS_NATIVE
252 if (!m_menuBarDetached
)
253 (*height
) -= m_menuBarHeight
;
255 (*height
) -= wxPLACE_HOLDER
;
257 #endif // wxUSE_MENUS_NATIVE
261 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
262 (*height
) -= wxSTATUS_HEIGHT
;
263 #endif // wxUSE_STATUSBAR
267 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
269 if (m_toolBarDetached
)
271 *height
-= wxPLACE_HOLDER
;
276 m_frameToolBar
->GetSize( &x
, &y
);
277 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
287 #endif // wxUSE_TOOLBAR
291 void wxFrame::DoSetClientSize( int width
, int height
)
293 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
295 #if wxUSE_MENUS_NATIVE
299 if (!m_menuBarDetached
)
300 height
+= m_menuBarHeight
;
302 height
+= wxPLACE_HOLDER
;
304 #endif // wxUSE_MENUS_NATIVE
308 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown()) height
+= wxSTATUS_HEIGHT
;
313 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
315 if (m_toolBarDetached
)
317 height
+= wxPLACE_HOLDER
;
322 m_frameToolBar
->GetSize( &x
, &y
);
323 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
335 wxTopLevelWindow::DoSetClientSize( width
, height
);
338 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
),
339 int width
, int height
)
341 // due to a bug in gtk, x,y are always 0
346 if (m_resizing
) return;
349 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
350 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
355 // space occupied by m_frameToolBar and m_frameMenuBar
356 int client_area_x_offset
= 0,
357 client_area_y_offset
= 0;
359 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
360 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
361 set in wxFrame::Create so it is used to check what kind of frame we
362 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
363 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
364 importantly) m_mainWidget */
366 int minWidth
= GetMinWidth(),
367 minHeight
= GetMinHeight(),
368 maxWidth
= GetMaxWidth(),
369 maxHeight
= GetMaxHeight();
371 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
372 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
373 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
374 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
379 gint flag
= 0; // GDK_HINT_POS;
380 if ((minWidth
!= -1) || (minHeight
!= -1)) flag
|= GDK_HINT_MIN_SIZE
;
381 if ((maxWidth
!= -1) || (maxHeight
!= -1)) flag
|= GDK_HINT_MAX_SIZE
;
383 geom
.min_width
= minWidth
;
384 geom
.min_height
= minHeight
;
385 geom
.max_width
= maxWidth
;
386 geom
.max_height
= maxHeight
;
387 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget
),
390 (GdkWindowHints
) flag
);
392 // I revert back to wxGTK's original behaviour. m_mainWidget holds
393 // the menubar, the toolbar and the client area, which is represented
395 // This hurts in the eye, but I don't want to call SetSize()
396 // because I don't want to call any non-native functions here.
398 #if wxUSE_MENUS_NATIVE
402 int yy
= m_miniEdge
+ m_miniTitle
;
403 int ww
= m_width
- 2*m_miniEdge
;
404 int hh
= m_menuBarHeight
;
405 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
406 m_frameMenuBar
->m_x
= xx
;
407 m_frameMenuBar
->m_y
= yy
;
408 m_frameMenuBar
->m_width
= ww
;
409 m_frameMenuBar
->m_height
= hh
;
410 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
411 m_frameMenuBar
->m_widget
,
413 client_area_y_offset
+= hh
;
415 #endif // wxUSE_MENUS_NATIVE
418 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
419 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
422 int yy
= m_miniEdge
+ m_miniTitle
;
423 #if wxUSE_MENUS_NATIVE
426 if (!m_menuBarDetached
)
427 yy
+= m_menuBarHeight
;
429 yy
+= wxPLACE_HOLDER
;
431 #endif // wxUSE_MENUS_NATIVE
433 m_frameToolBar
->m_x
= xx
;
434 m_frameToolBar
->m_y
= yy
;
436 // don't change the toolbar's reported height/width
438 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
440 ww
= m_toolBarDetached
? wxPLACE_HOLDER
441 : m_frameToolBar
->m_width
;
442 hh
= m_height
- 2*m_miniEdge
;
444 client_area_x_offset
+= ww
;
448 ww
= m_width
- 2*m_miniEdge
;
449 hh
= m_toolBarDetached
? wxPLACE_HOLDER
450 : m_frameToolBar
->m_height
;
452 client_area_y_offset
+= hh
;
455 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
456 m_frameToolBar
->m_widget
,
459 #endif // wxUSE_TOOLBAR
461 int client_x
= client_area_x_offset
+ m_miniEdge
;
462 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
463 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
464 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
465 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
467 client_x
, client_y
, client_w
, client_h
);
471 // If there is no m_mainWidget between m_widget and m_wxwindow there
472 // is no need to set the size or position of m_wxwindow.
476 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
478 int xx
= 0 + m_miniEdge
;
479 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
480 int ww
= m_width
- 2*m_miniEdge
;
481 int hh
= wxSTATUS_HEIGHT
;
482 m_frameStatusBar
->m_x
= xx
;
483 m_frameStatusBar
->m_y
= yy
;
484 m_frameStatusBar
->m_width
= ww
;
485 m_frameStatusBar
->m_height
= hh
;
486 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
487 m_frameStatusBar
->m_widget
,
489 gtk_widget_draw( m_frameStatusBar
->m_widget
, (GdkRectangle
*) NULL
);
491 #endif // wxUSE_STATUSBAR
495 // send size event to frame
496 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
497 event
.SetEventObject( this );
498 GetEventHandler()->ProcessEvent( event
);
501 // send size event to status bar
502 if (m_frameStatusBar
)
504 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
505 event2
.SetEventObject( m_frameStatusBar
);
506 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
508 #endif // wxUSE_STATUSBAR
513 void wxFrame::OnInternalIdle()
515 wxFrameBase::OnInternalIdle();
517 #if wxUSE_MENUS_NATIVE
518 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
519 #endif // wxUSE_MENUS_NATIVE
521 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
524 if (m_frameStatusBar
)
526 m_frameStatusBar
->OnInternalIdle();
528 // There may be controls in the status bar that
529 // need to be updated
530 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
532 node
= node
->GetNext() )
534 wxWindow
*child
= node
->GetData();
535 child
->OnInternalIdle();
541 // ----------------------------------------------------------------------------
542 // menu/tool/status bar stuff
543 // ----------------------------------------------------------------------------
545 #if wxUSE_MENUS_NATIVE
547 void wxFrame::DetachMenuBar()
549 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
550 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
552 if ( m_frameMenuBar
)
554 m_frameMenuBar
->UnsetInvokingWindow( this );
556 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
558 gtk_signal_disconnect_by_func( GTK_OBJECT(m_frameMenuBar
->m_widget
),
559 GTK_SIGNAL_FUNC(gtk_menu_attached_callback
), (gpointer
)this );
561 gtk_signal_disconnect_by_func( GTK_OBJECT(m_frameMenuBar
->m_widget
),
562 GTK_SIGNAL_FUNC(gtk_menu_detached_callback
), (gpointer
)this );
565 gtk_widget_ref( m_frameMenuBar
->m_widget
);
567 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
570 wxFrameBase::DetachMenuBar();
573 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
575 wxFrameBase::AttachMenuBar(menuBar
);
579 m_frameMenuBar
->SetInvokingWindow( this );
581 m_frameMenuBar
->SetParent(this);
582 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
583 m_frameMenuBar
->m_widget
,
586 m_frameMenuBar
->m_width
,
587 m_frameMenuBar
->m_height
);
589 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
591 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_attached",
592 GTK_SIGNAL_FUNC(gtk_menu_attached_callback
), (gpointer
)this );
594 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_detached",
595 GTK_SIGNAL_FUNC(gtk_menu_detached_callback
), (gpointer
)this );
598 gtk_widget_show( m_frameMenuBar
->m_widget
);
605 GtkUpdateSize(); // resize window in OnInternalIdle
609 void wxFrame::UpdateMenuBarSize()
616 // this is called after Remove with a NULL m_frameMenuBar
617 if ( m_frameMenuBar
)
618 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar
->m_widget
) )->size_request
)
619 (m_frameMenuBar
->m_widget
, &req
);
621 m_menuBarHeight
= req
.height
;
623 // resize window in OnInternalIdle
628 #endif // wxUSE_MENUS_NATIVE
632 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
634 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
636 m_insertInClientArea
= false;
638 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
640 m_insertInClientArea
= true;
644 return m_frameToolBar
;
647 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
649 bool hadTbar
= m_frameToolBar
!= NULL
;
651 wxFrameBase::SetToolBar(toolbar
);
653 if ( m_frameToolBar
)
655 // insert into toolbar area if not already there
656 if ((m_frameToolBar
->m_widget
->parent
) &&
657 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
659 GetChildren().DeleteObject( m_frameToolBar
);
661 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
665 else // toolbar unset
667 // still need to update size if it had been there before
675 #endif // wxUSE_TOOLBAR
679 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
682 const wxString
& name
)
684 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
686 // because it will change when toolbar is added
689 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
692 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
694 bool hadStatBar
= m_frameStatusBar
!= NULL
;
696 wxFrameBase::SetStatusBar(statbar
);
698 if (hadStatBar
&& !m_frameStatusBar
)
702 void wxFrame::PositionStatusBar()
704 if ( !m_frameStatusBar
)
709 #endif // wxUSE_STATUSBAR