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 extern void wxapp_install_idle_handler();
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 #if wxUSE_MENUS_NATIVE
74 //-----------------------------------------------------------------------------
75 // "child_attached" of menu bar
76 //-----------------------------------------------------------------------------
79 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
81 if (!win
->m_hasVMT
) return;
83 win
->m_menuBarDetached
= false;
88 //-----------------------------------------------------------------------------
89 // "child_detached" of menu bar
90 //-----------------------------------------------------------------------------
93 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
96 wxapp_install_idle_handler();
98 if (!win
->m_hasVMT
) return;
100 // Raise the client area area
101 gdk_window_raise( win
->m_wxwindow
->window
);
103 win
->m_menuBarDetached
= true;
104 win
->GtkUpdateSize();
108 #endif // wxUSE_MENUS_NATIVE
111 //-----------------------------------------------------------------------------
112 // "child_attached" of tool bar
113 //-----------------------------------------------------------------------------
116 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
118 if (!win
->m_hasVMT
) return;
120 win
->m_toolBarDetached
= false;
121 win
->GtkUpdateSize();
125 //-----------------------------------------------------------------------------
126 // "child_detached" of tool bar
127 //-----------------------------------------------------------------------------
130 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
133 wxapp_install_idle_handler();
135 if (!win
->m_hasVMT
) return;
137 // Raise the client area area
138 gdk_window_raise( win
->m_wxwindow
->window
);
140 win
->m_toolBarDetached
= true;
141 win
->GtkUpdateSize();
144 #endif // wxUSE_TOOLBAR
147 // ----------------------------------------------------------------------------
149 // ----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
152 // InsertChild for wxFrame
153 //-----------------------------------------------------------------------------
155 /* Callback for wxFrame. This very strange beast has to be used because
156 * C++ has no virtual methods in a constructor. We have to emulate a
157 * virtual function here as wxWidgets requires different ways to insert
158 * a child in container classes. */
160 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
162 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
164 if (!parent
->m_insertInClientArea
)
166 // These are outside the client area
167 wxFrame
* frame
= (wxFrame
*) parent
;
168 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
169 GTK_WIDGET(child
->m_widget
),
175 #if wxUSE_TOOLBAR_NATIVE
176 // We connect to these events for recalculating the client area
177 // space when the toolbar is floating
178 if (wxIS_KIND_OF(child
,wxToolBar
))
180 wxToolBar
*toolBar
= (wxToolBar
*) child
;
181 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
183 gtk_signal_connect( GTK_OBJECT(toolBar
->m_widget
), "child_attached",
184 GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback
), (gpointer
)parent
);
186 gtk_signal_connect( GTK_OBJECT(toolBar
->m_widget
), "child_detached",
187 GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback
), (gpointer
)parent
);
190 #endif // wxUSE_TOOLBAR
194 // These are inside the client area
195 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
196 GTK_WIDGET(child
->m_widget
),
203 // Resize on OnInternalIdle
204 parent
->GtkUpdateSize();
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
213 m_menuBarDetached
= false;
214 m_toolBarDetached
= false;
218 bool wxFrame::Create( wxWindow
*parent
,
220 const wxString
& title
,
222 const wxSize
& sizeOrig
,
224 const wxString
&name
)
226 bool rt
= wxTopLevelWindow::Create(parent
, id
, title
, pos
, sizeOrig
,
228 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
235 m_isBeingDeleted
= true;
239 // ----------------------------------------------------------------------------
240 // overridden wxWindow methods
241 // ----------------------------------------------------------------------------
243 void wxFrame::DoGetClientSize( int *width
, int *height
) const
245 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
247 wxTopLevelWindow::DoGetClientSize( width
, height
);
251 #if wxUSE_MENUS_NATIVE
255 if (!m_menuBarDetached
)
256 (*height
) -= m_menuBarHeight
;
258 (*height
) -= wxPLACE_HOLDER
;
260 #endif // wxUSE_MENUS_NATIVE
264 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
265 (*height
) -= wxSTATUS_HEIGHT
;
266 #endif // wxUSE_STATUSBAR
270 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
272 if (m_toolBarDetached
)
274 *height
-= wxPLACE_HOLDER
;
279 m_frameToolBar
->GetSize( &x
, &y
);
280 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
290 #endif // wxUSE_TOOLBAR
294 void wxFrame::DoSetClientSize( int width
, int height
)
296 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
298 #if wxUSE_MENUS_NATIVE
302 if (!m_menuBarDetached
)
303 height
+= m_menuBarHeight
;
305 height
+= wxPLACE_HOLDER
;
307 #endif // wxUSE_MENUS_NATIVE
311 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown()) height
+= wxSTATUS_HEIGHT
;
316 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
318 if (m_toolBarDetached
)
320 height
+= wxPLACE_HOLDER
;
325 m_frameToolBar
->GetSize( &x
, &y
);
326 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
338 wxTopLevelWindow::DoSetClientSize( width
, height
);
341 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
),
342 int width
, int height
)
344 // due to a bug in gtk, x,y are always 0
349 if (m_resizing
) return;
352 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
353 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
358 // space occupied by m_frameToolBar and m_frameMenuBar
359 int client_area_x_offset
= 0,
360 client_area_y_offset
= 0;
362 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
363 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
364 set in wxFrame::Create so it is used to check what kind of frame we
365 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
366 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
367 importantly) m_mainWidget */
369 int minWidth
= GetMinWidth(),
370 minHeight
= GetMinHeight(),
371 maxWidth
= GetMaxWidth(),
372 maxHeight
= GetMaxHeight();
374 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
375 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
376 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
377 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
382 gint flag
= 0; // GDK_HINT_POS;
383 if ((minWidth
!= -1) || (minHeight
!= -1)) flag
|= GDK_HINT_MIN_SIZE
;
384 if ((maxWidth
!= -1) || (maxHeight
!= -1)) flag
|= GDK_HINT_MAX_SIZE
;
386 geom
.min_width
= minWidth
;
387 geom
.min_height
= minHeight
;
388 geom
.max_width
= maxWidth
;
389 geom
.max_height
= maxHeight
;
390 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget
),
393 (GdkWindowHints
) flag
);
395 // I revert back to wxGTK's original behaviour. m_mainWidget holds
396 // the menubar, the toolbar and the client area, which is represented
398 // This hurts in the eye, but I don't want to call SetSize()
399 // because I don't want to call any non-native functions here.
401 #if wxUSE_MENUS_NATIVE
405 int yy
= m_miniEdge
+ m_miniTitle
;
406 int ww
= m_width
- 2*m_miniEdge
;
407 int hh
= m_menuBarHeight
;
408 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
409 m_frameMenuBar
->m_x
= xx
;
410 m_frameMenuBar
->m_y
= yy
;
411 m_frameMenuBar
->m_width
= ww
;
412 m_frameMenuBar
->m_height
= hh
;
413 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
414 m_frameMenuBar
->m_widget
,
416 client_area_y_offset
+= hh
;
418 #endif // wxUSE_MENUS_NATIVE
421 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
422 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
425 int yy
= m_miniEdge
+ m_miniTitle
;
426 #if wxUSE_MENUS_NATIVE
429 if (!m_menuBarDetached
)
430 yy
+= m_menuBarHeight
;
432 yy
+= wxPLACE_HOLDER
;
434 #endif // wxUSE_MENUS_NATIVE
436 m_frameToolBar
->m_x
= xx
;
437 m_frameToolBar
->m_y
= yy
;
439 // don't change the toolbar's reported height/width
441 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
443 ww
= m_toolBarDetached
? wxPLACE_HOLDER
444 : m_frameToolBar
->m_width
;
445 hh
= m_height
- 2*m_miniEdge
;
447 client_area_x_offset
+= ww
;
451 ww
= m_width
- 2*m_miniEdge
;
452 hh
= m_toolBarDetached
? wxPLACE_HOLDER
453 : m_frameToolBar
->m_height
;
455 client_area_y_offset
+= hh
;
458 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
459 m_frameToolBar
->m_widget
,
462 #endif // wxUSE_TOOLBAR
464 int client_x
= client_area_x_offset
+ m_miniEdge
;
465 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
466 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
467 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
468 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
470 client_x
, client_y
, client_w
, client_h
);
474 // If there is no m_mainWidget between m_widget and m_wxwindow there
475 // is no need to set the size or position of m_wxwindow.
479 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
481 int xx
= 0 + m_miniEdge
;
482 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
483 int ww
= m_width
- 2*m_miniEdge
;
484 int hh
= wxSTATUS_HEIGHT
;
485 m_frameStatusBar
->m_x
= xx
;
486 m_frameStatusBar
->m_y
= yy
;
487 m_frameStatusBar
->m_width
= ww
;
488 m_frameStatusBar
->m_height
= hh
;
489 gtk_pizza_set_size( GTK_PIZZA(m_wxwindow
),
490 m_frameStatusBar
->m_widget
,
492 gtk_widget_draw( m_frameStatusBar
->m_widget
, (GdkRectangle
*) NULL
);
494 #endif // wxUSE_STATUSBAR
498 // send size event to frame
499 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
500 event
.SetEventObject( this );
501 GetEventHandler()->ProcessEvent( event
);
504 // send size event to status bar
505 if (m_frameStatusBar
)
507 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
508 event2
.SetEventObject( m_frameStatusBar
);
509 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
511 #endif // wxUSE_STATUSBAR
516 void wxFrame::OnInternalIdle()
518 wxFrameBase::OnInternalIdle();
520 #if wxUSE_MENUS_NATIVE
521 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
522 #endif // wxUSE_MENUS_NATIVE
524 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
527 if (m_frameStatusBar
)
529 m_frameStatusBar
->OnInternalIdle();
531 // There may be controls in the status bar that
532 // need to be updated
533 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
535 node
= node
->GetNext() )
537 wxWindow
*child
= node
->GetData();
538 child
->OnInternalIdle();
544 // ----------------------------------------------------------------------------
545 // menu/tool/status bar stuff
546 // ----------------------------------------------------------------------------
548 #if wxUSE_MENUS_NATIVE
550 void wxFrame::DetachMenuBar()
552 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
553 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
555 if ( m_frameMenuBar
)
557 m_frameMenuBar
->UnsetInvokingWindow( this );
559 if (m_frameMenuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
561 gtk_signal_disconnect_by_func( GTK_OBJECT(m_frameMenuBar
->m_widget
),
562 GTK_SIGNAL_FUNC(gtk_menu_attached_callback
), (gpointer
)this );
564 gtk_signal_disconnect_by_func( GTK_OBJECT(m_frameMenuBar
->m_widget
),
565 GTK_SIGNAL_FUNC(gtk_menu_detached_callback
), (gpointer
)this );
568 gtk_widget_ref( m_frameMenuBar
->m_widget
);
570 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
573 wxFrameBase::DetachMenuBar();
576 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
578 wxFrameBase::AttachMenuBar(menuBar
);
582 m_frameMenuBar
->SetInvokingWindow( this );
584 m_frameMenuBar
->SetParent(this);
585 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
586 m_frameMenuBar
->m_widget
,
589 m_frameMenuBar
->m_width
,
590 m_frameMenuBar
->m_height
);
592 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
594 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_attached",
595 GTK_SIGNAL_FUNC(gtk_menu_attached_callback
), (gpointer
)this );
597 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_detached",
598 GTK_SIGNAL_FUNC(gtk_menu_detached_callback
), (gpointer
)this );
601 gtk_widget_show( m_frameMenuBar
->m_widget
);
608 GtkUpdateSize(); // resize window in OnInternalIdle
612 void wxFrame::UpdateMenuBarSize()
619 // this is called after Remove with a NULL m_frameMenuBar
620 if ( m_frameMenuBar
)
621 (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(m_frameMenuBar
->m_widget
) )->size_request
)
622 (m_frameMenuBar
->m_widget
, &req
);
624 m_menuBarHeight
= req
.height
;
626 // resize window in OnInternalIdle
631 #endif // wxUSE_MENUS_NATIVE
635 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
637 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
639 m_insertInClientArea
= false;
641 m_frameToolBar
= wxFrameBase::CreateToolBar( style
, id
, name
);
643 m_insertInClientArea
= true;
647 return m_frameToolBar
;
650 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
652 bool hadTbar
= m_frameToolBar
!= NULL
;
654 wxFrameBase::SetToolBar(toolbar
);
656 if ( m_frameToolBar
)
658 // insert into toolbar area if not already there
659 if ((m_frameToolBar
->m_widget
->parent
) &&
660 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
662 GetChildren().DeleteObject( m_frameToolBar
);
664 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
668 else // toolbar unset
670 // still need to update size if it had been there before
678 #endif // wxUSE_TOOLBAR
682 wxStatusBar
* wxFrame::CreateStatusBar(int number
,
685 const wxString
& name
)
687 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
689 // because it will change when toolbar is added
692 return wxFrameBase::CreateStatusBar( number
, style
, id
, name
);
695 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
697 bool hadStatBar
= m_frameStatusBar
!= NULL
;
699 wxFrameBase::SetStatusBar(statbar
);
701 if (hadStatBar
&& !m_frameStatusBar
)
705 void wxFrame::PositionStatusBar()
707 if ( !m_frameStatusBar
)
712 #endif // wxUSE_STATUSBAR