]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/gtk/frame.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
65571936 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
93763ad5 WS |
10 | // For compilers that support precompilation, includes "wx.h". |
11 | #include "wx/wxprec.h" | |
12 | ||
e1bf3ad3 | 13 | #include "wx/frame.h" |
670f9935 WS |
14 | |
15 | #ifndef WX_PRECOMP | |
3b3dc801 | 16 | #include "wx/menu.h" |
4e3e485b | 17 | #include "wx/toolbar.h" |
7c0ea335 | 18 | #include "wx/statusbr.h" |
3304646d | 19 | #endif // WX_PRECOMP |
83624f79 | 20 | |
a1abca32 | 21 | #include <gtk/gtk.h> |
c801d85f | 22 | |
e2f3bc41 VZ |
23 | #if wxUSE_LIBHILDON |
24 | #include <hildon-widgets/hildon-window.h> | |
25 | #endif // wxUSE_LIBHILDON | |
26 | ||
7c0ea335 VZ |
27 | // ---------------------------------------------------------------------------- |
28 | // event tables | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
0d53fc34 | 31 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
2e563988 | 32 | |
7c0ea335 VZ |
33 | // ============================================================================ |
34 | // implementation | |
35 | // ============================================================================ | |
36 | ||
7c0ea335 | 37 | // ---------------------------------------------------------------------------- |
0d53fc34 | 38 | // wxFrame creation |
7c0ea335 | 39 | // ---------------------------------------------------------------------------- |
c801d85f | 40 | |
0d53fc34 | 41 | void wxFrame::Init() |
c801d85f | 42 | { |
1529bc41 | 43 | m_fsSaveFlag = 0; |
362c6693 | 44 | } |
c801d85f | 45 | |
0d53fc34 | 46 | bool wxFrame::Create( wxWindow *parent, |
7c0ea335 | 47 | wxWindowID id, |
ca8bf976 VZ |
48 | const wxString& title, |
49 | const wxPoint& pos, | |
50 | const wxSize& sizeOrig, | |
7c0ea335 VZ |
51 | long style, |
52 | const wxString &name ) | |
c801d85f | 53 | { |
c821db16 | 54 | return wxFrameBase::Create(parent, id, title, pos, sizeOrig, style, name); |
362c6693 | 55 | } |
c801d85f | 56 | |
0d53fc34 | 57 | wxFrame::~wxFrame() |
c801d85f | 58 | { |
c6212a0c VZ |
59 | SendDestroyEvent(); |
60 | ||
7c0ea335 | 61 | DeleteAllBars(); |
3d0c4d2e RR |
62 | } |
63 | ||
7c0ea335 VZ |
64 | // ---------------------------------------------------------------------------- |
65 | // overridden wxWindow methods | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
0d53fc34 | 68 | void wxFrame::DoGetClientSize( int *width, int *height ) const |
c801d85f | 69 | { |
223d09f6 | 70 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
7b4c2a06 | 71 | |
e36a8aff | 72 | wxFrameBase::DoGetClientSize(width, height); |
8bbe427f | 73 | |
fb1585ae | 74 | if (height) |
46dc76ba | 75 | { |
75c9da25 | 76 | #if wxUSE_MENUS_NATIVE |
047ac72b | 77 | // menu bar |
cca410b3 | 78 | if (m_frameMenuBar && m_frameMenuBar->IsShown()) |
f03fc89f | 79 | { |
cca410b3 PC |
80 | GtkRequisition req; |
81 | gtk_widget_size_request(m_frameMenuBar->m_widget, &req); | |
82 | *height -= req.height; | |
f03fc89f | 83 | } |
75c9da25 | 84 | #endif // wxUSE_MENUS_NATIVE |
88ac883a | 85 | |
dcf924a3 | 86 | #if wxUSE_STATUSBAR |
047ac72b | 87 | // status bar |
cca410b3 PC |
88 | if (m_frameStatusBar && m_frameStatusBar->IsShown()) |
89 | *height -= m_frameStatusBar->m_height; | |
93fa69f8 | 90 | #endif // wxUSE_STATUSBAR |
c1fa6f52 | 91 | } |
88ac883a | 92 | |
dcf924a3 | 93 | #if wxUSE_TOOLBAR |
c1fa6f52 | 94 | // tool bar |
cca410b3 | 95 | if (m_frameToolBar && m_frameToolBar->IsShown()) |
c1fa6f52 | 96 | { |
cca410b3 PC |
97 | GtkRequisition req; |
98 | gtk_widget_size_request(m_frameToolBar->m_widget, &req); | |
e36a8aff | 99 | if (m_frameToolBar->IsVertical()) |
fb1585ae | 100 | { |
e36a8aff | 101 | if (width) |
cca410b3 | 102 | *width -= req.width; |
c1fa6f52 PC |
103 | } |
104 | else | |
105 | { | |
e36a8aff | 106 | if (height) |
cca410b3 | 107 | *height -= req.height; |
fb1585ae | 108 | } |
46dc76ba | 109 | } |
c1fa6f52 PC |
110 | #endif // wxUSE_TOOLBAR |
111 | ||
112 | if (width != NULL && *width < 0) | |
113 | *width = 0; | |
114 | if (height != NULL && *height < 0) | |
115 | *height = 0; | |
362c6693 | 116 | } |
c801d85f | 117 | |
6c309653 | 118 | #if wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c JS |
119 | // Helper for wxCreateAcceleratorTableForMenuBar |
120 | static void wxAddAccelerators(wxList& accelEntries, wxMenu* menu) | |
121 | { | |
122 | size_t i; | |
123 | for (i = 0; i < menu->GetMenuItems().GetCount(); i++) | |
124 | { | |
125 | wxMenuItem* item = (wxMenuItem*) menu->GetMenuItems().Item(i)->GetData(); | |
126 | if (item->GetSubMenu()) | |
127 | { | |
128 | wxAddAccelerators(accelEntries, item->GetSubMenu()); | |
129 | } | |
130 | else if (!item->GetItemLabel().IsEmpty()) | |
131 | { | |
132 | wxAcceleratorEntry* entry = wxAcceleratorEntry::Create(item->GetItemLabel()); | |
133 | if (entry) | |
134 | { | |
135 | entry->Set(entry->GetFlags(), entry->GetKeyCode(), item->GetId()); | |
136 | accelEntries.Append((wxObject*) entry); | |
137 | } | |
138 | } | |
139 | } | |
140 | } | |
141 | ||
142 | // Create an accelerator table consisting of all the accelerators | |
143 | // from the menubar in the given menus | |
144 | static wxAcceleratorTable wxCreateAcceleratorTableForMenuBar(wxMenuBar* menuBar) | |
145 | { | |
146 | wxList accelEntries; | |
147 | ||
148 | size_t i; | |
149 | for (i = 0; i < menuBar->GetMenuCount(); i++) | |
150 | { | |
151 | wxAddAccelerators(accelEntries, menuBar->GetMenu(i)); | |
152 | } | |
153 | ||
154 | size_t n = accelEntries.GetCount(); | |
155 | ||
156 | if (n == 0) | |
157 | return wxAcceleratorTable(); | |
158 | ||
159 | wxAcceleratorEntry* entries = new wxAcceleratorEntry[n]; | |
160 | ||
161 | for (i = 0; i < accelEntries.GetCount(); i++) | |
162 | { | |
163 | wxAcceleratorEntry* entry = (wxAcceleratorEntry*) accelEntries.Item(i)->GetData(); | |
164 | entries[i] = (*entry); | |
165 | delete entry; | |
166 | ||
167 | } | |
168 | ||
169 | wxAcceleratorTable table(n, entries); | |
170 | delete[] entries; | |
171 | ||
172 | return table; | |
173 | } | |
6c309653 | 174 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c | 175 | |
1529bc41 PC |
176 | bool wxFrame::ShowFullScreen(bool show, long style) |
177 | { | |
178 | if (!wxFrameBase::ShowFullScreen(show, style)) | |
179 | return false; | |
180 | ||
6c309653 | 181 | #if wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c JS |
182 | if (show && GetMenuBar()) |
183 | { | |
184 | wxAcceleratorTable table(wxCreateAcceleratorTableForMenuBar(GetMenuBar())); | |
185 | if (table.IsOk()) | |
186 | SetAcceleratorTable(table); | |
187 | } | |
6c309653 | 188 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c | 189 | |
1529bc41 | 190 | wxWindow* const bar[] = { |
28fcfbfe VZ |
191 | #if wxUSE_MENUS |
192 | m_frameMenuBar, | |
193 | #else | |
194 | NULL, | |
195 | #endif | |
196 | #if wxUSE_TOOLBAR | |
197 | m_frameToolBar, | |
198 | #else | |
199 | NULL, | |
200 | #endif | |
201 | #if wxUSE_STATUSBAR | |
202 | m_frameStatusBar, | |
203 | #else | |
204 | NULL, | |
205 | #endif | |
1529bc41 PC |
206 | }; |
207 | const long fsNoBar[] = { | |
208 | wxFULLSCREEN_NOMENUBAR, wxFULLSCREEN_NOTOOLBAR, wxFULLSCREEN_NOSTATUSBAR | |
209 | }; | |
210 | for (int i = 0; i < 3; i++) | |
211 | { | |
212 | if (show) | |
213 | { | |
214 | if (bar[i] && (style & fsNoBar[i])) | |
215 | { | |
216 | if (bar[i]->IsShown()) | |
217 | bar[i]->Show(false); | |
218 | else | |
219 | style &= ~fsNoBar[i]; | |
220 | } | |
221 | } | |
222 | else | |
223 | { | |
224 | if (bar[i] && (m_fsSaveFlag & fsNoBar[i])) | |
225 | bar[i]->Show(true); | |
226 | } | |
227 | } | |
228 | if (show) | |
229 | m_fsSaveFlag = style; | |
230 | ||
231 | return true; | |
232 | } | |
233 | ||
0d53fc34 | 234 | void wxFrame::OnInternalIdle() |
e52f60e6 | 235 | { |
e39af974 | 236 | wxFrameBase::OnInternalIdle(); |
88ac883a | 237 | |
75c9da25 | 238 | #if wxUSE_MENUS_NATIVE |
082b2798 | 239 | if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle(); |
75c9da25 | 240 | #endif // wxUSE_MENUS_NATIVE |
dcf924a3 | 241 | #if wxUSE_TOOLBAR |
082b2798 | 242 | if (m_frameToolBar) m_frameToolBar->OnInternalIdle(); |
dcf924a3 RR |
243 | #endif |
244 | #if wxUSE_STATUSBAR | |
e4edaf5c JS |
245 | if (m_frameStatusBar) |
246 | { | |
247 | m_frameStatusBar->OnInternalIdle(); | |
248 | ||
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(); | |
252 | node; | |
253 | node = node->GetNext() ) | |
254 | { | |
255 | wxWindow *child = node->GetData(); | |
256 | child->OnInternalIdle(); | |
257 | } | |
258 | } | |
dcf924a3 | 259 | #endif |
362c6693 | 260 | } |
c801d85f | 261 | |
7c0ea335 VZ |
262 | // ---------------------------------------------------------------------------- |
263 | // menu/tool/status bar stuff | |
264 | // ---------------------------------------------------------------------------- | |
c801d85f | 265 | |
6522713c | 266 | #if wxUSE_MENUS_NATIVE |
1e6feb95 | 267 | |
0d53fc34 | 268 | void wxFrame::DetachMenuBar() |
c801d85f | 269 | { |
223d09f6 KB |
270 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
271 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); | |
8bbe427f | 272 | |
6522713c | 273 | if ( m_frameMenuBar ) |
186baeb2 | 274 | { |
e2f3bc41 VZ |
275 | #if wxUSE_LIBHILDON |
276 | hildon_window_set_menu(HILDON_WINDOW(m_widget), NULL); | |
277 | #else // !wxUSE_LIBHILDON | |
186baeb2 RR |
278 | m_frameMenuBar->UnsetInvokingWindow( this ); |
279 | ||
186baeb2 | 280 | gtk_widget_ref( m_frameMenuBar->m_widget ); |
f283a575 RR |
281 | |
282 | gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget ); | |
e2f3bc41 | 283 | #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON |
186baeb2 RR |
284 | } |
285 | ||
6522713c | 286 | wxFrameBase::DetachMenuBar(); |
cca410b3 PC |
287 | |
288 | // make sure next size_allocate causes a wxSizeEvent | |
289 | m_oldClientWidth = 0; | |
6522713c VZ |
290 | } |
291 | ||
0d53fc34 | 292 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) |
6522713c VZ |
293 | { |
294 | wxFrameBase::AttachMenuBar(menuBar); | |
8bbe427f | 295 | |
f5368809 | 296 | if (m_frameMenuBar) |
30dea054 | 297 | { |
e2f3bc41 VZ |
298 | #if wxUSE_LIBHILDON |
299 | hildon_window_set_menu(HILDON_WINDOW(m_widget), | |
300 | GTK_MENU(m_frameMenuBar->m_menubar)); | |
301 | #else // !wxUSE_LIBHILDON | |
5bd9e519 | 302 | m_frameMenuBar->SetInvokingWindow( this ); |
8bbe427f | 303 | |
186baeb2 | 304 | m_frameMenuBar->SetParent(this); |
91af0895 | 305 | |
cca410b3 PC |
306 | // menubar goes into top of vbox (m_mainWidget) |
307 | gtk_box_pack_start( | |
308 | GTK_BOX(m_mainWidget), menuBar->m_widget, false, false, 0); | |
309 | gtk_box_reorder_child(GTK_BOX(m_mainWidget), menuBar->m_widget, 0); | |
2b5f62a0 | 310 | |
cca410b3 PC |
311 | // disconnect wxWindowGTK "size_request" handler, |
312 | // it interferes with sizing of detached GtkHandleBox | |
313 | gulong handler_id = g_signal_handler_find( | |
314 | menuBar->m_widget, | |
315 | GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), | |
316 | g_signal_lookup("size_request", GTK_TYPE_WIDGET), | |
317 | 0, NULL, NULL, menuBar); | |
318 | if (handler_id != 0) | |
319 | g_signal_handler_disconnect(menuBar->m_widget, handler_id); | |
2b5f62a0 | 320 | |
cca410b3 PC |
321 | // reset size request to allow native sizing to work |
322 | gtk_widget_set_size_request(menuBar->m_widget, -1, -1); | |
91af0895 | 323 | |
cca410b3 | 324 | gtk_widget_show( m_frameMenuBar->m_widget ); |
e2f3bc41 | 325 | #endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON |
8c70a789 | 326 | } |
cca410b3 PC |
327 | // make sure next size_allocate causes a wxSizeEvent |
328 | m_oldClientWidth = 0; | |
1d66b099 | 329 | } |
6522713c | 330 | #endif // wxUSE_MENUS_NATIVE |
1e6feb95 | 331 | |
88ac883a | 332 | #if wxUSE_TOOLBAR |
1e6feb95 | 333 | |
0d53fc34 | 334 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
7beba2fc | 335 | { |
cca410b3 PC |
336 | m_frameToolBar = toolbar; |
337 | if (toolbar) | |
307f16e8 | 338 | { |
cca410b3 | 339 | if (toolbar->IsVertical()) |
307f16e8 | 340 | { |
cca410b3 PC |
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)) | |
345 | { | |
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); | |
350 | } | |
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); | |
354 | ||
355 | int pos = 0; // left | |
356 | if (toolbar->HasFlag(wxTB_RIGHT)) | |
357 | pos = 1; // right | |
358 | gtk_box_reorder_child(GTK_BOX(hbox), toolbar->m_widget, pos); | |
7beba2fc | 359 | } |
cca410b3 | 360 | else |
94f14509 | 361 | { |
cca410b3 PC |
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); | |
366 | ||
367 | int pos = 0; // top | |
368 | if (m_frameMenuBar) | |
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); | |
94f14509 | 374 | } |
383144c7 | 375 | |
cca410b3 PC |
376 | // disconnect wxWindowGTK "size_request" handler, |
377 | // it interferes with sizing of detached GtkHandleBox | |
378 | gulong handler_id = g_signal_handler_find( | |
379 | toolbar->m_widget, | |
380 | GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), | |
381 | g_signal_lookup("size_request", GTK_TYPE_WIDGET), | |
382 | 0, NULL, NULL, toolbar); | |
383 | if (handler_id != 0) | |
384 | g_signal_handler_disconnect(toolbar->m_widget, handler_id); | |
385 | ||
386 | // reset size request to allow native sizing to work | |
387 | gtk_widget_set_size_request(toolbar->m_widget, -1, -1); | |
388 | } | |
389 | // make sure next size_allocate causes a wxSizeEvent | |
390 | m_oldClientWidth = 0; | |
307f16e8 RR |
391 | } |
392 | ||
88ac883a | 393 | #endif // wxUSE_TOOLBAR |
46dc76ba | 394 | |
88ac883a | 395 | #if wxUSE_STATUSBAR |
8bbe427f | 396 | |
3851e479 RR |
397 | void wxFrame::SetStatusBar(wxStatusBar *statbar) |
398 | { | |
cca410b3 PC |
399 | m_frameStatusBar = statbar; |
400 | if (statbar) | |
401 | { | |
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; | |
408 | } | |
409 | // make sure next size_allocate causes a wxSizeEvent | |
410 | m_oldClientWidth = 0; | |
8febdd39 | 411 | } |
88ac883a | 412 | #endif // wxUSE_STATUSBAR |