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
);
79 #if wxUSE_MENUS_NATIVE
81 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
84 gtk_widget_get_preferred_height(m_frameMenuBar
->m_widget
, NULL
, &h
);
85 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
89 #endif // wxUSE_MENUS_NATIVE
93 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
94 *height
-= m_frameStatusBar
->m_height
;
95 #endif // wxUSE_STATUSBAR
100 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
102 if (m_frameToolBar
->IsVertical())
107 gtk_widget_get_preferred_width(m_frameToolBar
->m_widget
, NULL
, &w
);
116 gtk_widget_get_preferred_height(m_frameToolBar
->m_widget
, NULL
, &h
);
121 #endif // wxUSE_TOOLBAR
123 if (width
!= NULL
&& *width
< 0)
125 if (height
!= NULL
&& *height
< 0)
129 #if wxUSE_MENUS && wxUSE_ACCEL
130 // Helper for wxCreateAcceleratorTableForMenuBar
131 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
134 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
136 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
137 if (item
->GetSubMenu())
139 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
141 else if (!item
->GetItemLabel().IsEmpty())
143 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
146 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
147 accelEntries
.Append((wxObject
*) entry
);
153 // Create an accelerator table consisting of all the accelerators
154 // from the menubar in the given menus
155 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
160 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
162 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
165 size_t n
= accelEntries
.GetCount();
168 return wxAcceleratorTable();
170 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
172 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
174 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
175 entries
[i
] = (*entry
);
180 wxAcceleratorTable
table(n
, entries
);
185 #endif // wxUSE_MENUS && wxUSE_ACCEL
187 bool wxFrame::ShowFullScreen(bool show
, long style
)
189 if (!wxFrameBase::ShowFullScreen(show
, style
))
192 #if wxUSE_MENUS && wxUSE_ACCEL
193 if (show
&& GetMenuBar())
195 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
197 SetAcceleratorTable(table
);
199 #endif // wxUSE_MENUS && wxUSE_ACCEL
201 wxWindow
* const bar
[] = {
218 const long fsNoBar
[] = {
219 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
221 for (int i
= 0; i
< 3; i
++)
225 if (bar
[i
] && (style
& fsNoBar
[i
]))
227 if (bar
[i
]->IsShown())
230 style
&= ~fsNoBar
[i
];
235 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
240 m_fsSaveFlag
= style
;
245 bool wxFrame::SendIdleEvents(wxIdleEvent
& event
)
247 bool needMore
= wxFrameBase::SendIdleEvents(event
);
250 if (m_frameMenuBar
&& m_frameMenuBar
->SendIdleEvents(event
))
254 if (m_frameToolBar
&& m_frameToolBar
->SendIdleEvents(event
))
258 if (m_frameStatusBar
&& m_frameStatusBar
->SendIdleEvents(event
))
265 // ----------------------------------------------------------------------------
266 // menu/tool/status bar stuff
267 // ----------------------------------------------------------------------------
269 #if wxUSE_MENUS_NATIVE
271 void wxFrame::DetachMenuBar()
273 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
274 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
276 if ( m_frameMenuBar
)
278 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
279 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
280 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
281 g_object_ref( m_frameMenuBar
->m_widget
);
283 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
284 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
287 wxFrameBase::DetachMenuBar();
289 // make sure next size_allocate causes a wxSizeEvent
290 m_oldClientWidth
= 0;
293 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
295 wxFrameBase::AttachMenuBar(menuBar
);
299 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
300 hildon_window_set_menu(HILDON_WINDOW(m_widget
),
301 GTK_MENU(m_frameMenuBar
->m_menubar
));
302 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
303 m_frameMenuBar
->SetParent(this);
305 // menubar goes into top of vbox (m_mainWidget)
307 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
308 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
310 // reset size request to allow native sizing to work
311 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
313 gtk_widget_show( m_frameMenuBar
->m_widget
);
314 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
316 // make sure next size_allocate causes a wxSizeEvent
317 m_oldClientWidth
= 0;
319 #endif // wxUSE_MENUS_NATIVE
323 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
325 m_frameToolBar
= toolbar
;
328 if (toolbar
->IsVertical())
330 // Vertical toolbar and m_wxwindow go into an hbox, inside the
331 // vbox (m_mainWidget). hbox is created on demand.
332 GtkWidget
* hbox
= gtk_widget_get_parent(m_wxwindow
);
333 if (hbox
== m_mainWidget
)
335 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
336 gtk_widget_show(hbox
);
337 gtk_box_pack_start(GTK_BOX(m_mainWidget
), hbox
, true, true, 0);
338 gtk_widget_reparent(m_wxwindow
, hbox
);
340 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
341 gtk_box_set_child_packing(GTK_BOX(hbox
),
342 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
345 if (toolbar
->HasFlag(wxTB_RIGHT
))
347 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
351 // Horizontal toolbar goes into vbox (m_mainWidget)
352 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
353 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
354 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
358 pos
= 1; // below menubar
359 if (toolbar
->HasFlag(wxTB_BOTTOM
))
360 pos
+= 2; // below client area (m_wxwindow)
361 gtk_box_reorder_child(
362 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
364 // reset size request to allow native sizing to work
365 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
367 // make sure next size_allocate causes a wxSizeEvent
368 m_oldClientWidth
= 0;
371 #endif // wxUSE_TOOLBAR
375 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
377 m_frameStatusBar
= statbar
;
380 // statusbar goes into bottom of vbox (m_mainWidget)
381 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
382 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
383 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
384 // make sure next size_allocate on statusbar causes a size event
385 statbar
->m_oldClientWidth
= 0;
387 if (statbar
->m_wxwindow
)
389 // statusbar is not a native widget, need to set height request
390 h
= statbar
->m_height
;
392 gtk_widget_set_size_request(statbar
->m_widget
, -1, h
);
394 // make sure next size_allocate causes a wxSizeEvent
395 m_oldClientWidth
= 0;
397 #endif // wxUSE_STATUSBAR