]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/frame.cpp
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
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
);
78 #if wxUSE_MENUS_NATIVE
80 if (m_frameMenuBar
&& m_frameMenuBar
->IsShown())
83 gtk_widget_size_request(m_frameMenuBar
->m_widget
, &req
);
84 #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
85 *height
-= req
.height
;
88 #endif // wxUSE_MENUS_NATIVE
92 if (m_frameStatusBar
&& m_frameStatusBar
->IsShown())
93 *height
-= m_frameStatusBar
->m_height
;
94 #endif // wxUSE_STATUSBAR
99 if (m_frameToolBar
&& m_frameToolBar
->IsShown())
102 gtk_widget_size_request(m_frameToolBar
->m_widget
, &req
);
103 if (m_frameToolBar
->IsVertical())
111 *height
-= req
.height
;
114 #endif // wxUSE_TOOLBAR
116 if (width
!= NULL
&& *width
< 0)
118 if (height
!= NULL
&& *height
< 0)
122 #if wxUSE_MENUS && wxUSE_ACCEL
123 // Helper for wxCreateAcceleratorTableForMenuBar
124 static void wxAddAccelerators(wxList
& accelEntries
, wxMenu
* menu
)
127 for (i
= 0; i
< menu
->GetMenuItems().GetCount(); i
++)
129 wxMenuItem
* item
= (wxMenuItem
*) menu
->GetMenuItems().Item(i
)->GetData();
130 if (item
->GetSubMenu())
132 wxAddAccelerators(accelEntries
, item
->GetSubMenu());
134 else if (!item
->GetItemLabel().IsEmpty())
136 wxAcceleratorEntry
* entry
= wxAcceleratorEntry::Create(item
->GetItemLabel());
139 entry
->Set(entry
->GetFlags(), entry
->GetKeyCode(), item
->GetId());
140 accelEntries
.Append((wxObject
*) entry
);
146 // Create an accelerator table consisting of all the accelerators
147 // from the menubar in the given menus
148 static wxAcceleratorTable
wxCreateAcceleratorTableForMenuBar(wxMenuBar
* menuBar
)
153 for (i
= 0; i
< menuBar
->GetMenuCount(); i
++)
155 wxAddAccelerators(accelEntries
, menuBar
->GetMenu(i
));
158 size_t n
= accelEntries
.GetCount();
161 return wxAcceleratorTable();
163 wxAcceleratorEntry
* entries
= new wxAcceleratorEntry
[n
];
165 for (i
= 0; i
< accelEntries
.GetCount(); i
++)
167 wxAcceleratorEntry
* entry
= (wxAcceleratorEntry
*) accelEntries
.Item(i
)->GetData();
168 entries
[i
] = (*entry
);
173 wxAcceleratorTable
table(n
, entries
);
178 #endif // wxUSE_MENUS && wxUSE_ACCEL
180 bool wxFrame::ShowFullScreen(bool show
, long style
)
182 if (!wxFrameBase::ShowFullScreen(show
, style
))
185 #if wxUSE_MENUS && wxUSE_ACCEL
186 if (show
&& GetMenuBar())
188 wxAcceleratorTable
table(wxCreateAcceleratorTableForMenuBar(GetMenuBar()));
190 SetAcceleratorTable(table
);
192 #endif // wxUSE_MENUS && wxUSE_ACCEL
194 wxWindow
* const bar
[] = {
211 const long fsNoBar
[] = {
212 wxFULLSCREEN_NOMENUBAR
, wxFULLSCREEN_NOTOOLBAR
, wxFULLSCREEN_NOSTATUSBAR
214 for (int i
= 0; i
< 3; i
++)
218 if (bar
[i
] && (style
& fsNoBar
[i
]))
220 if (bar
[i
]->IsShown())
223 style
&= ~fsNoBar
[i
];
228 if (bar
[i
] && (m_fsSaveFlag
& fsNoBar
[i
]))
233 m_fsSaveFlag
= style
;
238 bool wxFrame::SendIdleEvents(wxIdleEvent
& event
)
240 bool needMore
= wxFrameBase::SendIdleEvents(event
);
243 if (m_frameMenuBar
&& m_frameMenuBar
->SendIdleEvents(event
))
247 if (m_frameToolBar
&& m_frameToolBar
->SendIdleEvents(event
))
251 if (m_frameStatusBar
&& m_frameStatusBar
->SendIdleEvents(event
))
258 // ----------------------------------------------------------------------------
259 // menu/tool/status bar stuff
260 // ----------------------------------------------------------------------------
262 #if wxUSE_MENUS_NATIVE
264 void wxFrame::DetachMenuBar()
266 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
267 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
269 if ( m_frameMenuBar
)
271 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
272 hildon_window_set_menu(HILDON_WINDOW(m_widget
), NULL
);
273 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
274 g_object_ref( m_frameMenuBar
->m_widget
);
276 gtk_container_remove( GTK_CONTAINER(m_mainWidget
), m_frameMenuBar
->m_widget
);
277 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
280 wxFrameBase::DetachMenuBar();
282 // make sure next size_allocate causes a wxSizeEvent
283 m_oldClientWidth
= 0;
286 void wxFrame::AttachMenuBar( wxMenuBar
*menuBar
)
288 wxFrameBase::AttachMenuBar(menuBar
);
292 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
293 hildon_window_set_menu(HILDON_WINDOW(m_widget
),
294 GTK_MENU(m_frameMenuBar
->m_menubar
));
295 #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
296 m_frameMenuBar
->SetParent(this);
298 // menubar goes into top of vbox (m_mainWidget)
300 GTK_BOX(m_mainWidget
), menuBar
->m_widget
, false, false, 0);
301 gtk_box_reorder_child(GTK_BOX(m_mainWidget
), menuBar
->m_widget
, 0);
303 // reset size request to allow native sizing to work
304 gtk_widget_set_size_request(menuBar
->m_widget
, -1, -1);
306 gtk_widget_show( m_frameMenuBar
->m_widget
);
307 #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
309 // make sure next size_allocate causes a wxSizeEvent
310 m_oldClientWidth
= 0;
312 #endif // wxUSE_MENUS_NATIVE
316 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
318 m_frameToolBar
= toolbar
;
321 if (toolbar
->IsVertical())
323 // Vertical toolbar and m_wxwindow go into an hbox, inside the
324 // vbox (m_mainWidget). hbox is created on demand.
325 GtkWidget
* hbox
= gtk_widget_get_parent(m_wxwindow
);
326 if (!GTK_IS_HBOX(hbox
))
328 hbox
= gtk_hbox_new(false, 0);
329 gtk_widget_show(hbox
);
330 gtk_container_add(GTK_CONTAINER(m_mainWidget
), hbox
);
331 gtk_widget_reparent(m_wxwindow
, hbox
);
333 gtk_widget_reparent(toolbar
->m_widget
, hbox
);
334 gtk_box_set_child_packing(GTK_BOX(hbox
),
335 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
338 if (toolbar
->HasFlag(wxTB_RIGHT
))
340 gtk_box_reorder_child(GTK_BOX(hbox
), toolbar
->m_widget
, pos
);
344 // Horizontal toolbar goes into vbox (m_mainWidget)
345 gtk_widget_reparent(toolbar
->m_widget
, m_mainWidget
);
346 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
347 toolbar
->m_widget
, false, false, 0, GTK_PACK_START
);
351 pos
= 1; // below menubar
352 if (toolbar
->HasFlag(wxTB_BOTTOM
))
353 pos
+= 2; // below client area (m_wxwindow)
354 gtk_box_reorder_child(
355 GTK_BOX(m_mainWidget
), toolbar
->m_widget
, pos
);
357 // reset size request to allow native sizing to work
358 gtk_widget_set_size_request(toolbar
->m_widget
, -1, -1);
360 // make sure next size_allocate causes a wxSizeEvent
361 m_oldClientWidth
= 0;
364 #endif // wxUSE_TOOLBAR
368 void wxFrame::SetStatusBar(wxStatusBar
*statbar
)
370 m_frameStatusBar
= statbar
;
373 // statusbar goes into bottom of vbox (m_mainWidget)
374 gtk_widget_reparent(statbar
->m_widget
, m_mainWidget
);
375 gtk_box_set_child_packing(GTK_BOX(m_mainWidget
),
376 statbar
->m_widget
, false, false, 0, GTK_PACK_END
);
377 // make sure next size_allocate on statusbar causes a size event
378 statbar
->m_oldClientWidth
= 0;
380 if (statbar
->m_wxwindow
)
382 // statusbar is not a native widget, need to set height request
383 h
= statbar
->m_height
;
385 gtk_widget_set_size_request(statbar
->m_widget
, -1, h
);
387 // make sure next size_allocate causes a wxSizeEvent
388 m_oldClientWidth
= 0;
390 #endif // wxUSE_STATUSBAR