1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/frame.cpp
4 // Author: Robert Roebling
5 // Copyright: (c) 1998 Robert Roebling
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx.h".
10 #include "wx/wxprec.h"
16 #include "wx/toolbar.h"
17 #include "wx/statusbr.h"
21 #include "wx/gtk/private/gtk2-compat.h"
24 #include <hildon-widgets/hildon-window.h>
25 #endif // wxUSE_LIBHILDON
28 #include <hildon/hildon.h>
29 #endif // wxUSE_LIBHILDON2
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // ============================================================================
37 // ============================================================================
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
48 bool wxFrame::Create( wxWindow
*parent
,
50 const wxString
& title
,
52 const wxSize
& sizeOrig
,
54 const wxString
&name
)
56 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
66 // ----------------------------------------------------------------------------
67 // overridden wxWindow methods
68 // ----------------------------------------------------------------------------
70 void wxFrame::DoGetClientSize( int *width
, int *height
) const
72 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
74 wxFrameBase::DoGetClientSize(width
, height
);
76 if (m_useCachedClientSize
)
81 #if wxUSE_MENUS_NATIVE
83 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
86 gtk_widget_get_preferred_height(m_frameMenuBar
->m_widget
, NULL
, &h
);
87 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
91 #endif // wxUSE_MENUS_NATIVE
95 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
96 *height
-= m_frameStatusBar
->m_height
;
97 #endif // wxUSE_STATUSBAR
102 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
104 if (m_frameToolBar
->IsVertical())
109 gtk_widget_get_preferred_width(m_frameToolBar
->m_widget
, NULL
, &w
);
118 gtk_widget_get_preferred_height(m_frameToolBar
->m_widget
, NULL
, &h
);
123 #endif // wxUSE_TOOLBAR
125 if (width
!= NULL
&& *width
< 0)
127 if (height
!= NULL
&& *height
< 0)
131 #if wxUSE_MENUS && wxUSE_ACCEL
132 // Helper for wxCreateAcceleratorTableForMenuBar
133 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
136 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
138 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
139 if (item
->GetSubMenu())
141 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
143 else if (!item
->GetItemLabel().IsEmpty())
145 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
148 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
149 accelEntries
.Append((wxObject
*) entry
);
155 // Create an accelerator table consisting of all the accelerators
156 // from the menubar in the given menus
157 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
162 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
164 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
167 size_t n
= accelEntries
.GetCount();
170 return wxAcceleratorTable();
172 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
174 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
176 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
177 entries
[i
] = (*entry
);
182 wxAcceleratorTable
table(n
, entries
);
187 #endif // wxUSE_MENUS && wxUSE_ACCEL
189 bool wxFrame::ShowFullScreen(bool show
, long style
)
191 if (!wxFrameBase::ShowFullScreen(show
, style
))
194 #if wxUSE_MENUS && wxUSE_ACCEL
195 if (show
&& GetMenuBar())
197 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
199 SetAcceleratorTable(table
);
201 #endif // wxUSE_MENUS && wxUSE_ACCEL
203 wxWindow
* const bar
[] = {
220 const long fsNoBar
[] = {
221 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
223 for (int i
= 0; i
< 3; i
++)
227 if (bar
[i
] && (style
& fsNoBar
[i
]))
229 if (bar
[i
]->IsShown())
232 style
&= ~fsNoBar
[i
];
237 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
242 m_fsSaveFlag
= style
;
247 bool wxFrame::SendIdleEvents(wxIdleEvent
& event
)
249 bool needMore
= wxFrameBase::SendIdleEvents(event
);
252 if (m_frameMenuBar
&& m_frameMenuBar
->SendIdleEvents(event
))
256 if (m_frameToolBar
&& m_frameToolBar
->SendIdleEvents(event
))
260 if (m_frameStatusBar
&& m_frameStatusBar
->SendIdleEvents(event
))
267 // ----------------------------------------------------------------------------
268 // menu/tool/status bar stuff
269 // ----------------------------------------------------------------------------
271 #if wxUSE_MENUS_NATIVE
273 void wxFrame::DetachMenuBar()
275 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
276 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
278 if ( m_frameMenuBar
)
280 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
281 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
282 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
283 g_object_ref( m_frameMenuBar
->m_widget
);
285 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
286 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
289 wxFrameBase::DetachMenuBar();
291 // make sure next size_allocate causes a wxSizeEvent
292 m_useCachedClientSize
= false;
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_widget
));
305 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
307 // menubar goes into top of vbox (m_mainWidget)
309 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
310 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
312 // reset size request to allow native sizing to work
313 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
315 gtk_widget_show( m_frameMenuBar
->m_widget
);
316 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
318 // make sure next size_allocate causes a wxSizeEvent
319 m_useCachedClientSize
= false;
322 #endif // wxUSE_MENUS_NATIVE
326 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
328 m_frameToolBar
= toolbar
;
331 if (toolbar
->IsVertical())
333 // Vertical toolbar and m_wxwindow go into an hbox, inside the
334 // vbox (m_mainWidget). hbox is created on demand.
335 GtkWidget
* hbox
= gtk_widget_get_parent(m_wxwindow
);
336 if (hbox
== m_mainWidget
)
338 hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
339 gtk_widget_show(hbox
);
340 gtk_box_pack_start(GTK_BOX(m_mainWidget
), hbox
, true, true, 0);
341 gtk_widget_reparent(m_wxwindow
, hbox
);
343 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
344 gtk_box_set_child_packing(GTK_BOX(hbox
),
345 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
348 if (toolbar
->HasFlag(wxTB_RIGHT
))
350 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
354 // Horizontal toolbar goes into vbox (m_mainWidget)
355 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
356 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
357 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
361 pos
= 1; // below menubar
362 if (toolbar
->HasFlag(wxTB_BOTTOM
))
363 pos
+= 2; // below client area (m_wxwindow)
364 gtk_box_reorder_child(
365 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
367 // reset size request to allow native sizing to work
368 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
370 // make sure next size_allocate causes a wxSizeEvent
371 m_useCachedClientSize
= false;
375 #endif // wxUSE_TOOLBAR
379 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
381 m_frameStatusBar
= statbar
;
384 // statusbar goes into bottom of vbox (m_mainWidget)
385 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
386 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
387 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
388 // make sure next size_allocate on statusbar causes a size event
389 statbar
->m_useCachedClientSize
= false;
390 statbar
->m_clientWidth
= 0;
392 if (statbar
->m_wxwindow
)
394 // statusbar is not a native widget, need to set height request
395 h
= statbar
->m_height
;
397 gtk_widget_set_size_request(statbar
->m_widget
, -1, h
);
399 // make sure next size_allocate causes a wxSizeEvent
400 m_useCachedClientSize
= false;
403 #endif // wxUSE_STATUSBAR