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"
22 #include "wx/gtk/private/gtk2-compat.h"
25 #include <hildon-widgets/hildon-window.h>
26 #endif // wxUSE_LIBHILDON
29 #include <hildon/hildon.h>
30 #endif // wxUSE_LIBHILDON2
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 // ============================================================================
38 // ============================================================================
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
49 bool wxFrame::Create( wxWindow
*parent
,
51 const wxString
& title
,
53 const wxSize
& sizeOrig
,
55 const wxString
&name
)
57 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
67 // ----------------------------------------------------------------------------
68 // overridden wxWindow methods
69 // ----------------------------------------------------------------------------
71 void wxFrame::DoGetClientSize( int *width
, int *height
) const
73 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
75 wxFrameBase::DoGetClientSize(width
, height
);
77 if (m_useCachedClientSize
)
82 #if wxUSE_MENUS_NATIVE
84 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
87 gtk_widget_get_preferred_height(m_frameMenuBar
->m_widget
, NULL
, &h
);
88 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
92 #endif // wxUSE_MENUS_NATIVE
96 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
97 *height
-= m_frameStatusBar
->m_height
;
98 #endif // wxUSE_STATUSBAR
103 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
105 if (m_frameToolBar
->IsVertical())
110 gtk_widget_get_preferred_width(m_frameToolBar
->m_widget
, NULL
, &w
);
119 gtk_widget_get_preferred_height(m_frameToolBar
->m_widget
, NULL
, &h
);
124 #endif // wxUSE_TOOLBAR
126 if (width
!= NULL
&& *width
< 0)
128 if (height
!= NULL
&& *height
< 0)
132 #if wxUSE_MENUS && wxUSE_ACCEL
133 // Helper for wxCreateAcceleratorTableForMenuBar
134 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
137 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
139 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
140 if (item
->GetSubMenu())
142 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
144 else if (!item
->GetItemLabel().IsEmpty())
146 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
149 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
150 accelEntries
.Append((wxObject
*) entry
);
156 // Create an accelerator table consisting of all the accelerators
157 // from the menubar in the given menus
158 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
163 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
165 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
168 size_t n
= accelEntries
.GetCount();
171 return wxAcceleratorTable();
173 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
175 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
177 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
178 entries
[i
] = (*entry
);
183 wxAcceleratorTable
table(n
, entries
);
188 #endif // wxUSE_MENUS && wxUSE_ACCEL
190 bool wxFrame::ShowFullScreen(bool show
, long style
)
192 if (!wxFrameBase::ShowFullScreen(show
, style
))
195 #if wxUSE_MENUS && wxUSE_ACCEL
196 if (show
&& GetMenuBar())
198 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
200 SetAcceleratorTable(table
);
202 #endif // wxUSE_MENUS && wxUSE_ACCEL
204 wxWindow
* const bar
[] = {
221 const long fsNoBar
[] = {
222 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
224 for (int i
= 0; i
< 3; i
++)
228 if (bar
[i
] && (style
& fsNoBar
[i
]))
230 if (bar
[i
]->IsShown())
233 style
&= ~fsNoBar
[i
];
238 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
243 m_fsSaveFlag
= style
;
248 bool wxFrame::SendIdleEvents(wxIdleEvent
& event
)
250 bool needMore
= wxFrameBase::SendIdleEvents(event
);
253 if (m_frameMenuBar
&& m_frameMenuBar
->SendIdleEvents(event
))
257 if (m_frameToolBar
&& m_frameToolBar
->SendIdleEvents(event
))
261 if (m_frameStatusBar
&& m_frameStatusBar
->SendIdleEvents(event
))
268 // ----------------------------------------------------------------------------
269 // menu/tool/status bar stuff
270 // ----------------------------------------------------------------------------
272 #if wxUSE_MENUS_NATIVE
274 void wxFrame::DetachMenuBar()
276 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
277 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
279 if ( m_frameMenuBar
)
281 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
282 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
283 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
284 g_object_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_useCachedClientSize
= false;
297 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
299 wxFrameBase::AttachMenuBar(menuBar
);
303 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
304 hildon_window_set_menu(HILDON_WINDOW(m_widget
),
305 GTK_MENU(m_frameMenuBar
->m_widget
));
306 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
308 // menubar goes into top of vbox (m_mainWidget)
310 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
311 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
313 // reset size request to allow native sizing to work
314 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
316 gtk_widget_show( m_frameMenuBar
->m_widget
);
317 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
319 // make sure next size_allocate causes a wxSizeEvent
320 m_useCachedClientSize
= false;
323 #endif // wxUSE_MENUS_NATIVE
327 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
329 m_frameToolBar
= toolbar
;
332 if (toolbar
->IsVertical())
334 // Vertical toolbar and m_wxwindow go into an hbox, inside the
335 // vbox (m_mainWidget). hbox is created on demand.
336 GtkWidget
* hbox
= gtk_widget_get_parent(m_wxwindow
);
337 if (hbox
== m_mainWidget
)
339 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
340 gtk_widget_show(hbox
);
341 gtk_box_pack_start(GTK_BOX(m_mainWidget
), hbox
, true, true, 0);
342 gtk_widget_reparent(m_wxwindow
, hbox
);
344 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
345 gtk_box_set_child_packing(GTK_BOX(hbox
),
346 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
349 if (toolbar
->HasFlag(wxTB_RIGHT
))
351 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
355 // Horizontal toolbar goes into vbox (m_mainWidget)
356 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
357 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
358 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
362 pos
= 1; // below menubar
363 if (toolbar
->HasFlag(wxTB_BOTTOM
))
364 pos
+= 2; // below client area (m_wxwindow)
365 gtk_box_reorder_child(
366 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
368 // reset size request to allow native sizing to work
369 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
371 // make sure next size_allocate causes a wxSizeEvent
372 m_useCachedClientSize
= false;
376 #endif // wxUSE_TOOLBAR
380 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
382 m_frameStatusBar
= statbar
;
385 // statusbar goes into bottom of vbox (m_mainWidget)
386 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
387 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
388 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
389 // make sure next size_allocate on statusbar causes a size event
390 statbar
->m_useCachedClientSize
= false;
391 statbar
->m_clientWidth
= 0;
393 if (statbar
->m_wxwindow
)
395 // statusbar is not a native widget, need to set height request
396 h
= statbar
->m_height
;
398 gtk_widget_set_size_request(statbar
->m_widget
, -1, h
);
400 // make sure next size_allocate causes a wxSizeEvent
401 m_useCachedClientSize
= false;
404 #endif // wxUSE_STATUSBAR