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
);
59 m_isBeingDeleted
= true;
63 // ----------------------------------------------------------------------------
64 // overridden wxWindow methods
65 // ----------------------------------------------------------------------------
67 void wxFrame::DoGetClientSize( int *width
, int *height
) const
69 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
71 wxFrameBase::DoGetClientSize(width
, height
);
75 #if wxUSE_MENUS_NATIVE
77 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
80 gtk_widget_size_request(m_frameMenuBar
->m_widget
, &req
);
81 *height
-= req
.height
;
83 #endif // wxUSE_MENUS_NATIVE
87 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
88 *height
-= m_frameStatusBar
->m_height
;
89 #endif // wxUSE_STATUSBAR
94 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
97 gtk_widget_size_request(m_frameToolBar
->m_widget
, &req
);
98 if (m_frameToolBar
->IsVertical())
106 *height
-= req
.height
;
109 #endif // wxUSE_TOOLBAR
111 if (width
!= NULL
&& *width
< 0)
113 if (height
!= NULL
&& *height
< 0)
117 #if wxUSE_MENUS && wxUSE_ACCEL
118 // Helper for wxCreateAcceleratorTableForMenuBar
119 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
122 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
124 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
125 if (item
->GetSubMenu())
127 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
129 else if (!item
->GetItemLabel().IsEmpty())
131 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
134 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
135 accelEntries
.Append((wxObject
*) entry
);
141 // Create an accelerator table consisting of all the accelerators
142 // from the menubar in the given menus
143 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
148 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
150 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
153 size_t n
= accelEntries
.GetCount();
156 return wxAcceleratorTable();
158 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
160 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
162 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
163 entries
[i
] = (*entry
);
168 wxAcceleratorTable
table(n
, entries
);
173 #endif // wxUSE_MENUS && wxUSE_ACCEL
175 bool wxFrame::ShowFullScreen(bool show
, long style
)
177 if (!wxFrameBase::ShowFullScreen(show
, style
))
180 #if wxUSE_MENUS && wxUSE_ACCEL
181 if (show
&& GetMenuBar())
183 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
185 SetAcceleratorTable(table
);
187 #endif // wxUSE_MENUS && wxUSE_ACCEL
189 wxWindow
* const bar
[] = {
206 const long fsNoBar
[] = {
207 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
209 for (int i
= 0; i
< 3; i
++)
213 if (bar
[i
] && (style
& fsNoBar
[i
]))
215 if (bar
[i
]->IsShown())
218 style
&= ~fsNoBar
[i
];
223 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
228 m_fsSaveFlag
= style
;
233 void wxFrame::OnInternalIdle()
235 wxFrameBase::OnInternalIdle();
237 #if wxUSE_MENUS_NATIVE
238 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
239 #endif // wxUSE_MENUS_NATIVE
241 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
244 if (m_frameStatusBar
)
246 m_frameStatusBar
->OnInternalIdle();
248 // There may be controls in the status bar that
249 // need to be updated
250 for ( wxWindowList::compatibility_iterator node
= m_frameStatusBar
->GetChildren().GetFirst();
252 node
= node
->GetNext() )
254 wxWindow
*child
= node
->GetData();
255 child
->OnInternalIdle();
261 // ----------------------------------------------------------------------------
262 // menu/tool/status bar stuff
263 // ----------------------------------------------------------------------------
265 #if wxUSE_MENUS_NATIVE
267 void wxFrame::DetachMenuBar()
269 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
270 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
272 if ( m_frameMenuBar
)
275 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
276 #else // !wxUSE_LIBHILDON
277 m_frameMenuBar
->UnsetInvokingWindow( this );
279 gtk_widget_ref( m_frameMenuBar
->m_widget
);
281 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
282 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
285 wxFrameBase::DetachMenuBar();
287 // make sure next size_allocate causes a wxSizeEvent
288 m_oldClientWidth
= 0;
291 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
293 wxFrameBase::AttachMenuBar(menuBar
);
298 hildon_window_set_menu(HILDON_WINDOW(m_widget
),
299 GTK_MENU(m_frameMenuBar
->m_menubar
));
300 #else // !wxUSE_LIBHILDON
301 m_frameMenuBar
->SetInvokingWindow( this );
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 // disconnect wxWindowGTK "size_request" handler,
311 // it interferes with sizing of detached GtkHandleBox
312 gulong handler_id
= g_signal_handler_find(
314 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
315 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
316 0, NULL
, NULL
, menuBar
);
318 g_signal_handler_disconnect(menuBar
->m_widget
, handler_id
);
320 // reset size request to allow native sizing to work
321 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
323 gtk_widget_show( m_frameMenuBar
->m_widget
);
324 #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON
326 // make sure next size_allocate causes a wxSizeEvent
327 m_oldClientWidth
= 0;
329 #endif // wxUSE_MENUS_NATIVE
333 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
335 m_frameToolBar
= toolbar
;
338 if (toolbar
->IsVertical())
340 // Vertical toolbar and m_wxwindow go into an hbox, inside the
341 // vbox (m_mainWidget). hbox is created on demand.
342 GtkWidget
* hbox
= m_wxwindow
->parent
;
343 if (!GTK_IS_HBOX(hbox
))
345 hbox
= gtk_hbox_new(false, 0);
346 gtk_widget_show(hbox
);
347 gtk_container_add(GTK_CONTAINER(m_mainWidget
), hbox
);
348 gtk_widget_reparent(m_wxwindow
, hbox
);
350 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
351 gtk_box_set_child_packing(GTK_BOX(hbox
),
352 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
355 if (toolbar
->HasFlag(wxTB_RIGHT
))
357 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
361 // Horizontal toolbar goes into vbox (m_mainWidget)
362 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
363 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
364 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
368 pos
= 1; // below menubar
369 if (toolbar
->HasFlag(wxTB_BOTTOM
))
370 pos
+= 2; // below client area (m_wxwindow)
371 gtk_box_reorder_child(
372 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
375 // disconnect wxWindowGTK "size_request" handler,
376 // it interferes with sizing of detached GtkHandleBox
377 gulong handler_id
= g_signal_handler_find(
379 GSignalMatchType(G_SIGNAL_MATCH_ID
| G_SIGNAL_MATCH_DATA
),
380 g_signal_lookup("size_request", GTK_TYPE_WIDGET
),
381 0, NULL
, NULL
, toolbar
);
383 g_signal_handler_disconnect(toolbar
->m_widget
, handler_id
);
385 // reset size request to allow native sizing to work
386 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
388 // make sure next size_allocate causes a wxSizeEvent
389 m_oldClientWidth
= 0;
392 #endif // wxUSE_TOOLBAR
396 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
398 m_frameStatusBar
= statbar
;
401 // statusbar goes into bottom of vbox (m_mainWidget)
402 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
403 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
404 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
405 // make sure next size_allocate on statusbar causes a size event
406 statbar
->m_oldClientWidth
= 0;
408 // make sure next size_allocate causes a wxSizeEvent
409 m_oldClientWidth
= 0;
411 #endif // wxUSE_STATUSBAR