1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 // For compilers that support precompilation, includes "wx.h".
19 #include "wx/wxprec.h"
24 #include "wx/dialog.h"
25 #include "wx/control.h"
29 #include "wx/toolbar.h"
32 #include "wx/statusbr.h"
34 #include "wx/dcclient.h"
37 #include "wx/gtk/private.h"
39 #include <gdk/gdkkeysyms.h>
42 #include "wx/gtk/win_gtk.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 const int wxSTATUS_HEIGHT
= 25;
49 const int wxPLACE_HOLDER
= 0;
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
57 // ============================================================================
59 // ============================================================================
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 #if wxUSE_MENUS_NATIVE
67 //-----------------------------------------------------------------------------
68 // "child_attached" of menu bar
69 //-----------------------------------------------------------------------------
72 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
74 if (!win
->m_hasVMT
) return;
76 win
->m_menuBarDetached
= false;
81 //-----------------------------------------------------------------------------
82 // "child_detached" of menu bar
83 //-----------------------------------------------------------------------------
86 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
89 wxapp_install_idle_handler();
91 if (!win
->m_hasVMT
) return;
93 // Raise the client area area
94 gdk_window_raise( win
->m_wxwindow
->window
);
96 win
->m_menuBarDetached
= true;
101 #endif // wxUSE_MENUS_NATIVE
104 //-----------------------------------------------------------------------------
105 // "child_attached" of tool bar
106 //-----------------------------------------------------------------------------
109 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
111 if (!win
->m_hasVMT
) return;
113 win
->m_toolBarDetached
= false;
114 win
->GtkUpdateSize();
118 //-----------------------------------------------------------------------------
119 // "child_detached" of tool bar
120 //-----------------------------------------------------------------------------
123 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
126 wxapp_install_idle_handler();
128 if (!win
->m_hasVMT
) return;
130 // Raise the client area area
131 gdk_window_raise( win
->m_wxwindow
->window
);
133 win
->m_toolBarDetached
= true;
134 win
->GtkUpdateSize();
137 #endif // wxUSE_TOOLBAR
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
144 //-----------------------------------------------------------------------------
145 // InsertChild for wxFrame
146 //-----------------------------------------------------------------------------
148 /* Callback for wxFrame. This very strange beast has to be used because
149 * C++ has no virtual methods in a constructor. We have to emulate a
150 * virtual function here as wxWidgets requires different ways to insert
151 * a child in container classes. */
153 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
155 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
157 if (!parent
->m_insertInClientArea
)
159 // These are outside the client area
160 wxFrame
* frame
= (wxFrame
*) parent
;
161 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
162 GTK_WIDGET(child
->m_widget
),
168 #if wxUSE_TOOLBAR_NATIVE
169 // We connect to these events for recalculating the client area
170 // space when the toolbar is floating
171 if (wxIS_KIND_OF(child
,wxToolBar
))
173 wxToolBar
*toolBar
= (wxToolBar
*) child
;
174 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
176 g_signal_connect (toolBar
->m_widget
, "child_attached",
177 G_CALLBACK (gtk_toolbar_attached_callback
),
179 g_signal_connect (toolBar
->m_widget
, "child_detached",
180 G_CALLBACK (gtk_toolbar_detached_callback
),
184 #endif // wxUSE_TOOLBAR
188 // These are inside the client area
189 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
190 GTK_WIDGET(child
->m_widget
),
197 // Resize on OnInternalIdle
198 parent
->GtkUpdateSize();
201 // ----------------------------------------------------------------------------
203 // ----------------------------------------------------------------------------
207 m_menuBarDetached
= false;
208 m_toolBarDetached
= false;
212 bool wxFrame::Create( wxWindow
*parent
,
214 const wxString
& title
,
216 const wxSize
& sizeOrig
,
218 const wxString
&name
)
220 bool rt
= wxTopLevelWindow::Create(parent
, id
, title
, pos
, sizeOrig
,
222 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
229 m_isBeingDeleted
= true;
233 // ----------------------------------------------------------------------------
234 // overridden wxWindow methods
235 // ----------------------------------------------------------------------------
237 void wxFrame::DoGetClientSize( int *width
, int *height
) const
239 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
241 wxTopLevelWindow::DoGetClientSize( width
, height
);
245 #if wxUSE_MENUS_NATIVE
249 if (!m_menuBarDetached
)
250 (*height
) -= m_menuBarHeight
;
252 (*height
) -= wxPLACE_HOLDER
;
254 #endif // wxUSE_MENUS_NATIVE
258 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
259 (*height
) -= wxSTATUS_HEIGHT
;
260 #endif // wxUSE_STATUSBAR
264 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
266 if (m_toolBarDetached
)
268 *height
-= wxPLACE_HOLDER
;
273 m_frameToolBar
->GetSize( &x
, &y
);
274 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
284 #endif // wxUSE_TOOLBAR
288 void wxFrame::DoSetClientSize( int width
, int height
)
290 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
292 #if wxUSE_MENUS_NATIVE
296 if (!m_menuBarDetached
)
297 height
+= m_menuBarHeight
;
299 height
+= wxPLACE_HOLDER
;
301 #endif // wxUSE_MENUS_NATIVE
305 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown()) height
+= wxSTATUS_HEIGHT
;
310 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
312 if (m_toolBarDetached
)
314 height
+= wxPLACE_HOLDER
;
319 m_frameToolBar
->GetSize( &x
, &y
);
320 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
332 wxTopLevelWindow::DoSetClientSize( width
, height
);
335 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
),
336 int width
, int height
)
338 // due to a bug in gtk, x,y are always 0
343 if (m_resizing
) return;
346 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
347 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
352 // space occupied by m_frameToolBar and m_frameMenuBar
353 int client_area_x_offset
= 0,
354 client_area_y_offset
= 0;
356 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
357 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
358 set in wxFrame::Create so it is used to check what kind of frame we
359 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
360 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
361 importantly) m_mainWidget */
363 int minWidth
= GetMinWidth(),
364 minHeight
= GetMinHeight(),
365 maxWidth
= GetMaxWidth(),
366 maxHeight
= GetMaxHeight();
368 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
369 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
370 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
371 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
376 gint flag
= 0; // GDK_HINT_POS;
377 if ((minWidth
!= -1) || (minHeight
!= -1)) flag
|= GDK_HINT_MIN_SIZE
;
378 if ((maxWidth
!= -1) || (maxHeight
!= -1)) flag
|= GDK_HINT_MAX_SIZE
;
380 geom
.min_width
= minWidth
;
381 geom
.min_height
= minHeight
;
382 geom
.max_width
= maxWidth
;
383 geom
.max_height
= maxHeight
;
384 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget
),
387 (GdkWindowHints
) flag
);
389 // I revert back to wxGTK's original behaviour. m_mainWidget holds
390 // the menubar, the toolbar and the client area, which is represented
392 // This hurts in the eye, but I don't want to call SetSize()
393 // because I don't want to call any non-native functions here.
395 #if wxUSE_MENUS_NATIVE
399 int yy
= m_miniEdge
+ m_miniTitle
;
400 int ww
= m_width
- 2*m_miniEdge
;
401 int hh
= m_menuBarHeight
;
402 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
403 m_frameMenuBar
->m_x
= xx
;
404 m_frameMenuBar
->m_y
= yy
;
405 m_frameMenuBar
->m_width
= ww
;
406 m_frameMenuBar
->m_height
= hh
;
407 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
408 m_frameMenuBar
->m_widget
,
410 client_area_y_offset
+= hh
;
412 #endif // wxUSE_MENUS_NATIVE
415 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
416 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
419 int yy
= m_miniEdge
+ m_miniTitle
;
420 #if wxUSE_MENUS_NATIVE
423 if (!m_menuBarDetached
)
424 yy
+= m_menuBarHeight
;
426 yy
+= wxPLACE_HOLDER
;
428 #endif // wxUSE_MENUS_NATIVE
430 m_frameToolBar
->m_x
= xx
;
431 m_frameToolBar
->m_y
= yy
;
433 // don't change the toolbar's reported height/width
435 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
437 ww
= m_toolBarDetached
? wxPLACE_HOLDER
438 : m_frameToolBar
->m_width
;
439 hh
= m_height
- 2*m_miniEdge
;
441 client_area_x_offset
+= ww
;
445 ww
= m_width
- 2*m_miniEdge
;
446 hh
= m_toolBarDetached
? wxPLACE_HOLDER
447 : m_frameToolBar
->m_height
;
449 client_area_y_offset
+= hh
;
452 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
453 m_frameToolBar
->m_widget
,
456 #endif // wxUSE_TOOLBAR
458 int client_x
= client_area_x_offset
+ m_miniEdge
;
459 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
460 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
461 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
462 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
464 client_x
, client_y
, client_w
, client_h
);
468 // If there is no m_mainWidget between m_widget and m_wxwindow there
469 // is no need to set the size or position of m_wxwindow.
473 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
475 int xx
= 0 + m_miniEdge
;
476 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
477 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
,
486 if (GTK_WIDGET_DRAWABLE (m_frameStatusBar
->m_widget
))
488 gtk_widget_queue_draw (m_frameStatusBar
->m_widget
);
489 // FIXME: Do we really want to force an immediate redraw?
490 gdk_window_process_updates (m_frameStatusBar
->m_widget
->window
, TRUE
);
493 #endif // wxUSE_STATUSBAR
497 // send size event to frame
498 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
499 event
.SetEventObject( this );
500 GetEventHandler()->ProcessEvent( event
);
503 // send size event to status bar
504 if (m_frameStatusBar
)
506 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
507 event2
.SetEventObject( m_frameStatusBar
);
508 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
510 #endif // wxUSE_STATUSBAR
515 void wxFrame::OnInternalIdle()
517 wxFrameBase::OnInternalIdle();
519 #if wxUSE_MENUS_NATIVE
520 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
521 #endif // wxUSE_MENUS_NATIVE
523 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
526 if (m_frameStatusBar
)
528 m_frameStatusBar
->OnInternalIdle();
530 // There may be controls in the status bar that
531 // need to be updated
532 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
534 node
= node
->GetNext() )
536 wxWindow
*child
= node
->GetData();
537 child
->OnInternalIdle();
543 // ----------------------------------------------------------------------------
544 // menu/tool/status bar stuff
545 // ----------------------------------------------------------------------------
547 #if wxUSE_MENUS_NATIVE
549 void wxFrame::DetachMenuBar()
551 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
552 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
554 if ( m_frameMenuBar
)
556 m_frameMenuBar
->UnsetInvokingWindow( this );
558 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
560 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
561 (gpointer
) gtk_menu_attached_callback
,
564 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
565 (gpointer
) gtk_menu_detached_callback
,
569 gtk_widget_ref( m_frameMenuBar
->m_widget
);
571 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
574 wxFrameBase::DetachMenuBar();
577 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
579 wxFrameBase::AttachMenuBar(menuBar
);
583 m_frameMenuBar
->SetInvokingWindow( this );
585 m_frameMenuBar
->SetParent(this);
586 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
587 m_frameMenuBar
->m_widget
,
590 m_frameMenuBar
->m_width
,
591 m_frameMenuBar
->m_height
);
593 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
595 g_signal_connect (menuBar
->m_widget
, "child_attached",
596 G_CALLBACK (gtk_menu_attached_callback
),
598 g_signal_connect (menuBar
->m_widget
, "child_detached",
599 G_CALLBACK (gtk_menu_detached_callback
),
603 gtk_widget_show( m_frameMenuBar
->m_widget
);
610 GtkUpdateSize(); // resize window in OnInternalIdle
614 void wxFrame::UpdateMenuBarSize()
621 // this is called after Remove with a NULL m_frameMenuBar
622 if ( m_frameMenuBar
)
623 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar
->m_widget
) )->size_request
)
624 (m_frameMenuBar
->m_widget
, &req
);
626 m_menuBarHeight
= req
.height
;
628 // resize window in OnInternalIdle
633 #endif // wxUSE_MENUS_NATIVE
637 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
639 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
641 m_insertInClientArea
= false;
643 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
645 m_insertInClientArea
= true;
649 return m_frameToolBar
;
652 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
654 bool hadTbar
= m_frameToolBar
!= NULL
;
656 wxFrameBase::SetToolBar(toolbar
);
658 if ( m_frameToolBar
)
660 // insert into toolbar area if not already there
661 if ((m_frameToolBar
->m_widget
->parent
) &&
662 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
664 GetChildren().DeleteObject( m_frameToolBar
);
666 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
670 else // toolbar unset
672 // still need to update size if it had been there before
680 #endif // wxUSE_TOOLBAR
684 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
687 const wxString
& name
)
689 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
691 // because it will change when toolbar is added
694 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
697 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
699 bool hadStatBar
= m_frameStatusBar
!= NULL
;
701 wxFrameBase::SetStatusBar(statbar
);
703 if (hadStatBar
&& !m_frameStatusBar
)
707 void wxFrame::PositionStatusBar()
709 if ( !m_frameStatusBar
)
714 #endif // wxUSE_STATUSBAR