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
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 IMPLEMENT_DYNAMIC_CLASS(wxFrame
, wxTopLevelWindow
)
33 // ============================================================================
35 // ============================================================================
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
46 bool wxFrame::Create( wxWindow
*parent
,
48 const wxString
& title
,
50 const wxSize
& sizeOrig
,
52 const wxString
&name
)
54 return wxFrameBase::Create(parent
, id
, title
, pos
, sizeOrig
, style
, name
);
64 // ----------------------------------------------------------------------------
65 // overridden wxWindow methods
66 // ----------------------------------------------------------------------------
68 void wxFrame::DoGetClientSize( int *width
, int *height
) const
70 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
72 wxFrameBase::DoGetClientSize(width
, height
);
76 #if wxUSE_MENUS_NATIVE
78 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
81 gtk_widget_size_request(m_frameMenuBar
->m_widget
, &req
);
82 *height
-= req
.height
;
84 #endif // wxUSE_MENUS_NATIVE
88 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
89 *height
-= m_frameStatusBar
->m_height
;
90 #endif // wxUSE_STATUSBAR
95 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
98 gtk_widget_size_request(m_frameToolBar
->m_widget
, &req
);
99 if (m_frameToolBar
->IsVertical())
107 *height
-= req
.height
;
110 #endif // wxUSE_TOOLBAR
112 if (width
!= NULL
&& *width
< 0)
114 if (height
!= NULL
&& *height
< 0)
118 #if wxUSE_MENUS && wxUSE_ACCEL
119 // Helper for wxCreateAcceleratorTableForMenuBar
120 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
123 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
125 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
126 if (item
->GetSubMenu())
128 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
130 else if (!item
->GetItemLabel().IsEmpty())
132 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
135 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
136 accelEntries
.Append((wxObject
*) entry
);
142 // Create an accelerator table consisting of all the accelerators
143 // from the menubar in the given menus
144 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
149 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
151 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
154 size_t n
= accelEntries
.GetCount();
157 return wxAcceleratorTable();
159 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
161 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
163 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
164 entries
[i
] = (*entry
);
169 wxAcceleratorTable
table(n
, entries
);
174 #endif // wxUSE_MENUS && wxUSE_ACCEL
176 bool wxFrame::ShowFullScreen(bool show
, long style
)
178 if (!wxFrameBase::ShowFullScreen(show
, style
))
181 #if wxUSE_MENUS && wxUSE_ACCEL
182 if (show
&& GetMenuBar())
184 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
186 SetAcceleratorTable(table
);
188 #endif // wxUSE_MENUS && wxUSE_ACCEL
190 wxWindow
* const bar
[] = {
207 const long fsNoBar
[] = {
208 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
210 for (int i
= 0; i
< 3; i
++)
214 if (bar
[i
] && (style
& fsNoBar
[i
]))
216 if (bar
[i
]->IsShown())
219 style
&= ~fsNoBar
[i
];
224 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
229 m_fsSaveFlag
= style
;
234 void wxFrame::OnInternalIdle()
236 wxFrameBase::OnInternalIdle();
238 #if wxUSE_MENUS_NATIVE
239 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
240 #endif // wxUSE_MENUS_NATIVE
242 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
245 if (m_frameStatusBar
)
247 m_frameStatusBar
->OnInternalIdle();
249 // There may be controls in the status bar that
250 // need to be updated
251 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
253 node
= node
->GetNext() )
255 wxWindow
*child
= node
->GetData();
256 child
->OnInternalIdle();
262 // ----------------------------------------------------------------------------
263 // menu/tool/status bar stuff
264 // ----------------------------------------------------------------------------
266 #if wxUSE_MENUS_NATIVE
268 void wxFrame::DetachMenuBar()
270 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
271 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
273 if ( m_frameMenuBar
)
276 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
277 #else // !wxUSE_LIBHILDON
278 m_frameMenuBar
->UnsetInvokingWindow( this );
280 gtk_widget_ref( m_frameMenuBar
->m_widget
);
282 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
283 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
286 wxFrameBase::DetachMenuBar();
288 // make sure next size_allocate causes a wxSizeEvent
289 m_oldClientWidth
= 0;
292 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
294 wxFrameBase::AttachMenuBar(menuBar
);
299 hildon_window_set_menu(HILDON_WINDOW(m_widget
),
300 GTK_MENU(m_frameMenuBar
->m_menubar
));
301 #else // !wxUSE_LIBHILDON
302 m_frameMenuBar
->SetInvokingWindow( this );
304 m_frameMenuBar
->SetParent(this);
306 // menubar goes into top of vbox (m_mainWidget)
308 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
309 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
311 // disconnect wxWindowGTK "size_request" handler,
312 // it interferes with sizing of detached GtkHandleBox
313 gulong handler_id
= g_signal_handler_find(
315 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
316 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
317 0, NULL
, NULL
, menuBar
);
319 g_signal_handler_disconnect(menuBar
->m_widget
, handler_id
);
321 // reset size request to allow native sizing to work
322 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
324 gtk_widget_show( m_frameMenuBar
->m_widget
);
325 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
327 // make sure next size_allocate causes a wxSizeEvent
328 m_oldClientWidth
= 0;
330 #endif // wxUSE_MENUS_NATIVE
334 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
336 m_frameToolBar
= toolbar
;
339 if (toolbar
->IsVertical())
341 // Vertical toolbar and m_wxwindow go into an hbox, inside the
342 // vbox (m_mainWidget). hbox is created on demand.
343 GtkWidget
* hbox
= m_wxwindow
->parent
;
344 if (!GTK_IS_HBOX(hbox
))
346 hbox
= gtk_hbox_new(false, 0);
347 gtk_widget_show(hbox
);
348 gtk_container_add(GTK_CONTAINER(m_mainWidget
), hbox
);
349 gtk_widget_reparent(m_wxwindow
, hbox
);
351 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
352 gtk_box_set_child_packing(GTK_BOX(hbox
),
353 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
356 if (toolbar
->HasFlag(wxTB_RIGHT
))
358 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
362 // Horizontal toolbar goes into vbox (m_mainWidget)
363 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
364 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
365 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
369 pos
= 1; // below menubar
370 if (toolbar
->HasFlag(wxTB_BOTTOM
))
371 pos
+= 2; // below client area (m_wxwindow)
372 gtk_box_reorder_child(
373 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
376 // disconnect wxWindowGTK "size_request" handler,
377 // it interferes with sizing of detached GtkHandleBox
378 gulong handler_id
= g_signal_handler_find(
380 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
381 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
382 0, NULL
, NULL
, toolbar
);
384 g_signal_handler_disconnect(toolbar
->m_widget
, handler_id
);
386 // reset size request to allow native sizing to work
387 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
389 // make sure next size_allocate causes a wxSizeEvent
390 m_oldClientWidth
= 0;
393 #endif // wxUSE_TOOLBAR
397 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
399 m_frameStatusBar
= statbar
;
402 // statusbar goes into bottom of vbox (m_mainWidget)
403 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
404 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
405 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
406 // make sure next size_allocate on statusbar causes a size event
407 statbar
->m_oldClientWidth
= 0;
409 // make sure next size_allocate causes a wxSizeEvent
410 m_oldClientWidth
= 0;
412 #endif // wxUSE_STATUSBAR