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 // ----------------------------------------------------------------------------
22 #include "wx/dialog.h"
23 #include "wx/control.h"
27 #include "wx/toolbar.h"
30 #include "wx/statusbr.h"
32 #include "wx/dcclient.h"
35 #include "wx/gtk/private.h"
37 #include <gdk/gdkkeysyms.h>
40 #include "wx/gtk/win_gtk.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 const int wxSTATUS_HEIGHT
= 25;
47 const int wxPLACE_HOLDER
= 0;
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
55 // ============================================================================
57 // ============================================================================
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 #if wxUSE_MENUS_NATIVE
65 //-----------------------------------------------------------------------------
66 // "child_attached" of menu bar
67 //-----------------------------------------------------------------------------
70 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
72 if (!win
->m_hasVMT
) return;
74 win
->m_menuBarDetached
= false;
79 //-----------------------------------------------------------------------------
80 // "child_detached" of menu bar
81 //-----------------------------------------------------------------------------
84 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
87 wxapp_install_idle_handler();
89 if (!win
->m_hasVMT
) return;
91 // Raise the client area area
92 gdk_window_raise( win
->m_wxwindow
->window
);
94 win
->m_menuBarDetached
= true;
99 #endif // wxUSE_MENUS_NATIVE
102 //-----------------------------------------------------------------------------
103 // "child_attached" of tool bar
104 //-----------------------------------------------------------------------------
107 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
109 if (!win
->m_hasVMT
) return;
111 win
->m_toolBarDetached
= false;
112 win
->GtkUpdateSize();
116 //-----------------------------------------------------------------------------
117 // "child_detached" of tool bar
118 //-----------------------------------------------------------------------------
121 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
124 wxapp_install_idle_handler();
126 if (!win
->m_hasVMT
) return;
128 // Raise the client area area
129 gdk_window_raise( win
->m_wxwindow
->window
);
131 win
->m_toolBarDetached
= true;
132 win
->GtkUpdateSize();
135 #endif // wxUSE_TOOLBAR
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 //-----------------------------------------------------------------------------
143 // InsertChild for wxFrame
144 //-----------------------------------------------------------------------------
146 /* Callback for wxFrame. This very strange beast has to be used because
147 * C++ has no virtual methods in a constructor. We have to emulate a
148 * virtual function here as wxWidgets requires different ways to insert
149 * a child in container classes. */
151 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
153 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
155 if (!parent
->m_insertInClientArea
)
157 // These are outside the client area
158 wxFrame
* frame
= (wxFrame
*) parent
;
159 gtk_pizza_put( GTK_PIZZA(frame
->m_mainWidget
),
160 GTK_WIDGET(child
->m_widget
),
166 #if wxUSE_TOOLBAR_NATIVE
167 // We connect to these events for recalculating the client area
168 // space when the toolbar is floating
169 if (wxIS_KIND_OF(child
,wxToolBar
))
171 wxToolBar
*toolBar
= (wxToolBar
*) child
;
172 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
174 g_signal_connect (toolBar
->m_widget
, "child_attached",
175 G_CALLBACK (gtk_toolbar_attached_callback
),
177 g_signal_connect (toolBar
->m_widget
, "child_detached",
178 G_CALLBACK (gtk_toolbar_detached_callback
),
182 #endif // wxUSE_TOOLBAR
186 // These are inside the client area
187 gtk_pizza_put( GTK_PIZZA(parent
->m_wxwindow
),
188 GTK_WIDGET(child
->m_widget
),
195 // Resize on OnInternalIdle
196 parent
->GtkUpdateSize();
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
205 m_menuBarDetached
= false;
206 m_toolBarDetached
= false;
210 bool wxFrame::Create( wxWindow
*parent
,
212 const wxString
& title
,
214 const wxSize
& sizeOrig
,
216 const wxString
&name
)
218 bool rt
= wxTopLevelWindow::Create(parent
, id
, title
, pos
, sizeOrig
,
220 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
227 m_isBeingDeleted
= true;
231 // ----------------------------------------------------------------------------
232 // overridden wxWindow methods
233 // ----------------------------------------------------------------------------
235 void wxFrame::DoGetClientSize( int *width
, int *height
) const
237 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
239 wxTopLevelWindow::DoGetClientSize( width
, height
);
243 #if wxUSE_MENUS_NATIVE
247 if (!m_menuBarDetached
)
248 (*height
) -= m_menuBarHeight
;
250 (*height
) -= wxPLACE_HOLDER
;
252 #endif // wxUSE_MENUS_NATIVE
256 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
257 (*height
) -= wxSTATUS_HEIGHT
;
258 #endif // wxUSE_STATUSBAR
262 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
264 if (m_toolBarDetached
)
266 *height
-= wxPLACE_HOLDER
;
271 m_frameToolBar
->GetSize( &x
, &y
);
272 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
282 #endif // wxUSE_TOOLBAR
286 void wxFrame::DoSetClientSize( int width
, int height
)
288 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
290 #if wxUSE_MENUS_NATIVE
294 if (!m_menuBarDetached
)
295 height
+= m_menuBarHeight
;
297 height
+= wxPLACE_HOLDER
;
299 #endif // wxUSE_MENUS_NATIVE
303 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown()) height
+= wxSTATUS_HEIGHT
;
308 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
310 if (m_toolBarDetached
)
312 height
+= wxPLACE_HOLDER
;
317 m_frameToolBar
->GetSize( &x
, &y
);
318 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
330 wxTopLevelWindow::DoSetClientSize( width
, height
);
333 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
),
334 int width
, int height
)
336 // due to a bug in gtk, x,y are always 0
341 if (m_resizing
) return;
344 // this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow
345 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
350 // space occupied by m_frameToolBar and m_frameMenuBar
351 int client_area_x_offset
= 0,
352 client_area_y_offset
= 0;
354 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
355 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
356 set in wxFrame::Create so it is used to check what kind of frame we
357 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
358 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
359 importantly) m_mainWidget */
361 int minWidth
= GetMinWidth(),
362 minHeight
= GetMinHeight(),
363 maxWidth
= GetMaxWidth(),
364 maxHeight
= GetMaxHeight();
366 if ((minWidth
!= -1) && (m_width
< minWidth
)) m_width
= minWidth
;
367 if ((minHeight
!= -1) && (m_height
< minHeight
)) m_height
= minHeight
;
368 if ((maxWidth
!= -1) && (m_width
> maxWidth
)) m_width
= maxWidth
;
369 if ((maxHeight
!= -1) && (m_height
> maxHeight
)) m_height
= maxHeight
;
374 gint flag
= 0; // GDK_HINT_POS;
375 if ((minWidth
!= -1) || (minHeight
!= -1)) flag
|= GDK_HINT_MIN_SIZE
;
376 if ((maxWidth
!= -1) || (maxHeight
!= -1)) flag
|= GDK_HINT_MAX_SIZE
;
378 geom
.min_width
= minWidth
;
379 geom
.min_height
= minHeight
;
380 geom
.max_width
= maxWidth
;
381 geom
.max_height
= maxHeight
;
382 gtk_window_set_geometry_hints( GTK_WINDOW(m_widget
),
385 (GdkWindowHints
) flag
);
387 // I revert back to wxGTK's original behaviour. m_mainWidget holds
388 // the menubar, the toolbar and the client area, which is represented
390 // This hurts in the eye, but I don't want to call SetSize()
391 // because I don't want to call any non-native functions here.
393 #if wxUSE_MENUS_NATIVE
397 int yy
= m_miniEdge
+ m_miniTitle
;
398 int ww
= m_width
- 2*m_miniEdge
;
399 int hh
= m_menuBarHeight
;
400 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
401 m_frameMenuBar
->m_x
= xx
;
402 m_frameMenuBar
->m_y
= yy
;
403 m_frameMenuBar
->m_width
= ww
;
404 m_frameMenuBar
->m_height
= hh
;
405 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
406 m_frameMenuBar
->m_widget
,
408 client_area_y_offset
+= hh
;
410 #endif // wxUSE_MENUS_NATIVE
413 if ((m_frameToolBar
) && m_frameToolBar
->IsShown() &&
414 (m_frameToolBar
->m_widget
->parent
== m_mainWidget
))
417 int yy
= m_miniEdge
+ m_miniTitle
;
418 #if wxUSE_MENUS_NATIVE
421 if (!m_menuBarDetached
)
422 yy
+= m_menuBarHeight
;
424 yy
+= wxPLACE_HOLDER
;
426 #endif // wxUSE_MENUS_NATIVE
428 m_frameToolBar
->m_x
= xx
;
429 m_frameToolBar
->m_y
= yy
;
431 // don't change the toolbar's reported height/width
433 if ( m_frameToolBar
->GetWindowStyle() & wxTB_VERTICAL
)
435 ww
= m_toolBarDetached
? wxPLACE_HOLDER
436 : m_frameToolBar
->m_width
;
437 hh
= m_height
- 2*m_miniEdge
;
439 client_area_x_offset
+= ww
;
443 ww
= m_width
- 2*m_miniEdge
;
444 hh
= m_toolBarDetached
? wxPLACE_HOLDER
445 : m_frameToolBar
->m_height
;
447 client_area_y_offset
+= hh
;
450 gtk_pizza_set_size( GTK_PIZZA(m_mainWidget
),
451 m_frameToolBar
->m_widget
,
454 #endif // wxUSE_TOOLBAR
456 int client_x
= client_area_x_offset
+ m_miniEdge
;
457 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
458 int client_w
= m_width
- client_area_x_offset
- 2*m_miniEdge
;
459 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
;
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
,
484 if (GTK_WIDGET_DRAWABLE (m_frameStatusBar
->m_widget
))
486 gtk_widget_queue_draw (m_frameStatusBar
->m_widget
);
487 // FIXME: Do we really want to force an immediate redraw?
488 gdk_window_process_updates (m_frameStatusBar
->m_widget
->window
, TRUE
);
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 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
559 (gpointer
) gtk_menu_attached_callback
,
562 g_signal_handlers_disconnect_by_func (m_frameMenuBar
->m_widget
,
563 (gpointer
) gtk_menu_detached_callback
,
567 gtk_widget_ref( m_frameMenuBar
->m_widget
);
569 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
572 wxFrameBase::DetachMenuBar();
575 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
577 wxFrameBase::AttachMenuBar(menuBar
);
581 m_frameMenuBar
->SetInvokingWindow( this );
583 m_frameMenuBar
->SetParent(this);
584 gtk_pizza_put( GTK_PIZZA(m_mainWidget
),
585 m_frameMenuBar
->m_widget
,
588 m_frameMenuBar
->m_width
,
589 m_frameMenuBar
->m_height
);
591 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
593 g_signal_connect (menuBar
->m_widget
, "child_attached",
594 G_CALLBACK (gtk_menu_attached_callback
),
596 g_signal_connect (menuBar
->m_widget
, "child_detached",
597 G_CALLBACK (gtk_menu_detached_callback
),
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