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"
24 #include <hildon-widgets/hildon-window.h>
25 #endif // wxUSE_LIBHILDON
28 #include <hildon/hildon.h>
29 #endif // wxUSE_LIBHILDON2
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
37 // ============================================================================
39 // ============================================================================
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
50 bool wxFrame::Create( wxWindow
*parent
,
52 const wxString
& title
,
54 const wxSize
& sizeOrig
,
56 const wxString
&name
)
58 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
68 // ----------------------------------------------------------------------------
69 // overridden wxWindow methods
70 // ----------------------------------------------------------------------------
72 void wxFrame::DoGetClientSize( int *width
, int *height
) const
74 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
76 wxFrameBase::DoGetClientSize(width
, height
);
80 #if wxUSE_MENUS_NATIVE
82 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
85 gtk_widget_size_request(m_frameMenuBar
->m_widget
, &req
);
86 *height
-= req
.height
;
88 #endif // wxUSE_MENUS_NATIVE
92 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
93 *height
-= m_frameStatusBar
->m_height
;
94 #endif // wxUSE_STATUSBAR
99 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
102 gtk_widget_size_request(m_frameToolBar
->m_widget
, &req
);
103 if (m_frameToolBar
->IsVertical())
111 *height
-= req
.height
;
114 #endif // wxUSE_TOOLBAR
116 if (width
!= NULL
&& *width
< 0)
118 if (height
!= NULL
&& *height
< 0)
122 #if wxUSE_MENUS && wxUSE_ACCEL
123 // Helper for wxCreateAcceleratorTableForMenuBar
124 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
127 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
129 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
130 if (item
->GetSubMenu())
132 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
134 else if (!item
->GetItemLabel().IsEmpty())
136 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
139 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
140 accelEntries
.Append((wxObject
*) entry
);
146 // Create an accelerator table consisting of all the accelerators
147 // from the menubar in the given menus
148 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
153 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
155 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
158 size_t n
= accelEntries
.GetCount();
161 return wxAcceleratorTable();
163 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
165 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
167 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
168 entries
[i
] = (*entry
);
173 wxAcceleratorTable
table(n
, entries
);
178 #endif // wxUSE_MENUS && wxUSE_ACCEL
180 bool wxFrame::ShowFullScreen(bool show
, long style
)
182 if (!wxFrameBase::ShowFullScreen(show
, style
))
185 #if wxUSE_MENUS && wxUSE_ACCEL
186 if (show
&& GetMenuBar())
188 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
190 SetAcceleratorTable(table
);
192 #endif // wxUSE_MENUS && wxUSE_ACCEL
194 wxWindow
* const bar
[] = {
211 const long fsNoBar
[] = {
212 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
214 for (int i
= 0; i
< 3; i
++)
218 if (bar
[i
] && (style
& fsNoBar
[i
]))
220 if (bar
[i
]->IsShown())
223 style
&= ~fsNoBar
[i
];
228 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
233 m_fsSaveFlag
= style
;
238 void wxFrame::OnInternalIdle()
240 wxFrameBase::OnInternalIdle();
242 #if wxUSE_MENUS_NATIVE
243 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
244 #endif // wxUSE_MENUS_NATIVE
246 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
249 if (m_frameStatusBar
)
251 m_frameStatusBar
->OnInternalIdle();
253 // There may be controls in the status bar that
254 // need to be updated
255 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
257 node
= node
->GetNext() )
259 wxWindow
*child
= node
->GetData();
260 child
->OnInternalIdle();
266 // ----------------------------------------------------------------------------
267 // menu/tool/status bar stuff
268 // ----------------------------------------------------------------------------
270 #if wxUSE_MENUS_NATIVE
272 void wxFrame::DetachMenuBar()
274 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
275 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
277 if ( m_frameMenuBar
)
279 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
280 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
281 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
282 m_frameMenuBar
->UnsetInvokingWindow( this );
284 gtk_widget_ref( m_frameMenuBar
->m_widget
);
286 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
287 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
290 wxFrameBase::DetachMenuBar();
292 // make sure next size_allocate causes a wxSizeEvent
293 m_oldClientWidth
= 0;
296 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
298 wxFrameBase::AttachMenuBar(menuBar
);
302 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
303 hildon_window_set_menu(HILDON_WINDOW(m_widget
),
304 GTK_MENU(m_frameMenuBar
->m_menubar
));
305 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
306 m_frameMenuBar
->SetInvokingWindow( this );
308 m_frameMenuBar
->SetParent(this);
310 // menubar goes into top of vbox (m_mainWidget)
312 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
313 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
315 // disconnect wxWindowGTK "size_request" handler,
316 // it interferes with sizing of detached GtkHandleBox
317 gulong handler_id
= g_signal_handler_find(
319 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
320 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
321 0, NULL
, NULL
, menuBar
);
323 g_signal_handler_disconnect(menuBar
->m_widget
, handler_id
);
325 // reset size request to allow native sizing to work
326 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
328 gtk_widget_show( m_frameMenuBar
->m_widget
);
329 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
331 // make sure next size_allocate causes a wxSizeEvent
332 m_oldClientWidth
= 0;
334 #endif // wxUSE_MENUS_NATIVE
338 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
340 m_frameToolBar
= toolbar
;
343 if (toolbar
->IsVertical())
345 // Vertical toolbar and m_wxwindow go into an hbox, inside the
346 // vbox (m_mainWidget). hbox is created on demand.
347 GtkWidget
* hbox
= m_wxwindow
->parent
;
348 if (!GTK_IS_HBOX(hbox
))
350 hbox
= gtk_hbox_new(false, 0);
351 gtk_widget_show(hbox
);
352 gtk_container_add(GTK_CONTAINER(m_mainWidget
), hbox
);
353 gtk_widget_reparent(m_wxwindow
, hbox
);
355 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
356 gtk_box_set_child_packing(GTK_BOX(hbox
),
357 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
360 if (toolbar
->HasFlag(wxTB_RIGHT
))
362 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
366 // Horizontal toolbar goes into vbox (m_mainWidget)
367 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
368 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
369 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
373 pos
= 1; // below menubar
374 if (toolbar
->HasFlag(wxTB_BOTTOM
))
375 pos
+= 2; // below client area (m_wxwindow)
376 gtk_box_reorder_child(
377 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
380 // disconnect wxWindowGTK "size_request" handler,
381 // it interferes with sizing of detached GtkHandleBox
382 gulong handler_id
= g_signal_handler_find(
384 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
385 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
386 0, NULL
, NULL
, toolbar
);
388 g_signal_handler_disconnect(toolbar
->m_widget
, handler_id
);
390 // reset size request to allow native sizing to work
391 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
393 // make sure next size_allocate causes a wxSizeEvent
394 m_oldClientWidth
= 0;
397 #endif // wxUSE_TOOLBAR
401 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
403 m_frameStatusBar
= statbar
;
406 // statusbar goes into bottom of vbox (m_mainWidget)
407 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
408 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
409 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
410 // make sure next size_allocate on statusbar causes a size event
411 statbar
->m_oldClientWidth
= 0;
413 // make sure next size_allocate causes a wxSizeEvent
414 m_oldClientWidth
= 0;
416 #endif // wxUSE_STATUSBAR