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"
17 #include "wx/toolbar.h"
18 #include "wx/statusbr.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
29 // ============================================================================
31 // ============================================================================
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
42 bool wxFrame::Create( wxWindow
*parent
,
44 const wxString
& title
,
46 const wxSize
& sizeOrig
,
48 const wxString
&name
)
50 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
55 m_isBeingDeleted
= true;
59 // ----------------------------------------------------------------------------
60 // overridden wxWindow methods
61 // ----------------------------------------------------------------------------
63 void wxFrame::DoGetClientSize( int *width
, int *height
) const
65 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
67 wxFrameBase::DoGetClientSize(width
, height
);
71 #if wxUSE_MENUS_NATIVE
73 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
76 gtk_widget_size_request(m_frameMenuBar
->m_widget
, &req
);
77 *height
-= req
.height
;
79 #endif // wxUSE_MENUS_NATIVE
83 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
84 *height
-= m_frameStatusBar
->m_height
;
85 #endif // wxUSE_STATUSBAR
90 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
93 gtk_widget_size_request(m_frameToolBar
->m_widget
, &req
);
94 if (m_frameToolBar
->IsVertical())
102 *height
-= req
.height
;
105 #endif // wxUSE_TOOLBAR
107 if (width
!= NULL
&& *width
< 0)
109 if (height
!= NULL
&& *height
< 0)
113 bool wxFrame::ShowFullScreen(bool show
, long style
)
115 if (!wxFrameBase::ShowFullScreen(show
, style
))
118 wxWindow
* const bar
[] = {
135 const long fsNoBar
[] = {
136 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
138 for (int i
= 0; i
< 3; i
++)
142 if (bar
[i
] && (style
& fsNoBar
[i
]))
144 if (bar
[i
]->IsShown())
147 style
&= ~fsNoBar
[i
];
152 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
157 m_fsSaveFlag
= style
;
162 void wxFrame::OnInternalIdle()
164 wxFrameBase::OnInternalIdle();
166 #if wxUSE_MENUS_NATIVE
167 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
168 #endif // wxUSE_MENUS_NATIVE
170 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
173 if (m_frameStatusBar
)
175 m_frameStatusBar
->OnInternalIdle();
177 // There may be controls in the status bar that
178 // need to be updated
179 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
181 node
= node
->GetNext() )
183 wxWindow
*child
= node
->GetData();
184 child
->OnInternalIdle();
190 // ----------------------------------------------------------------------------
191 // menu/tool/status bar stuff
192 // ----------------------------------------------------------------------------
194 #if wxUSE_MENUS_NATIVE
196 void wxFrame::DetachMenuBar()
198 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
199 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
201 if ( m_frameMenuBar
)
203 m_frameMenuBar
->UnsetInvokingWindow( this );
205 gtk_widget_ref( m_frameMenuBar
->m_widget
);
207 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
210 wxFrameBase::DetachMenuBar();
212 // make sure next size_allocate causes a wxSizeEvent
213 m_oldClientWidth
= 0;
216 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
218 wxFrameBase::AttachMenuBar(menuBar
);
222 m_frameMenuBar
->SetInvokingWindow( this );
224 m_frameMenuBar
->SetParent(this);
226 // menubar goes into top of vbox (m_mainWidget)
228 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
229 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
231 // disconnect wxWindowGTK "size_request" handler,
232 // it interferes with sizing of detached GtkHandleBox
233 gulong handler_id
= g_signal_handler_find(
235 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
236 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
237 0, NULL
, NULL
, menuBar
);
239 g_signal_handler_disconnect(menuBar
->m_widget
, handler_id
);
241 // reset size request to allow native sizing to work
242 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
244 gtk_widget_show( m_frameMenuBar
->m_widget
);
246 // make sure next size_allocate causes a wxSizeEvent
247 m_oldClientWidth
= 0;
249 #endif // wxUSE_MENUS_NATIVE
253 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
255 m_frameToolBar
= toolbar
;
258 if (toolbar
->IsVertical())
260 // Vertical toolbar and m_wxwindow go into an hbox, inside the
261 // vbox (m_mainWidget). hbox is created on demand.
262 GtkWidget
* hbox
= m_wxwindow
->parent
;
263 if (!GTK_IS_HBOX(hbox
))
265 hbox
= gtk_hbox_new(false, 0);
266 gtk_widget_show(hbox
);
267 gtk_container_add(GTK_CONTAINER(m_mainWidget
), hbox
);
268 gtk_widget_reparent(m_wxwindow
, hbox
);
270 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
271 gtk_box_set_child_packing(GTK_BOX(hbox
),
272 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
275 if (toolbar
->HasFlag(wxTB_RIGHT
))
277 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
281 // Horizontal toolbar goes into vbox (m_mainWidget)
282 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
283 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
284 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
288 pos
= 1; // below menubar
289 if (toolbar
->HasFlag(wxTB_BOTTOM
))
290 pos
+= 2; // below client area (m_wxwindow)
291 gtk_box_reorder_child(
292 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
295 // disconnect wxWindowGTK "size_request" handler,
296 // it interferes with sizing of detached GtkHandleBox
297 gulong handler_id
= g_signal_handler_find(
299 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
300 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
301 0, NULL
, NULL
, toolbar
);
303 g_signal_handler_disconnect(toolbar
->m_widget
, handler_id
);
305 // reset size request to allow native sizing to work
306 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
308 // make sure next size_allocate causes a wxSizeEvent
309 m_oldClientWidth
= 0;
312 #endif // wxUSE_TOOLBAR
316 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
318 m_frameStatusBar
= statbar
;
321 // statusbar goes into bottom of vbox (m_mainWidget)
322 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
323 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
324 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
325 // make sure next size_allocate on statusbar causes a size event
326 statbar
->m_oldClientWidth
= 0;
328 // make sure next size_allocate causes a wxSizeEvent
329 m_oldClientWidth
= 0;
331 #endif // wxUSE_STATUSBAR