]>
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 | ||
426d19f1 JS |
27 | #if wxUSE_LIBHILDON2 |
28 | #include <hildon/hildon.h> | |
29 | #endif // wxUSE_LIBHILDON2 | |
30 | ||
7c0ea335 VZ |
31 | // ---------------------------------------------------------------------------- |
32 | // event tables | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
7c0ea335 VZ |
35 | // ============================================================================ |
36 | // implementation | |
37 | // ============================================================================ | |
38 | ||
7c0ea335 | 39 | // ---------------------------------------------------------------------------- |
0d53fc34 | 40 | // wxFrame creation |
7c0ea335 | 41 | // ---------------------------------------------------------------------------- |
c801d85f | 42 | |
0d53fc34 | 43 | void wxFrame::Init() |
c801d85f | 44 | { |
1529bc41 | 45 | m_fsSaveFlag = 0; |
362c6693 | 46 | } |
c801d85f | 47 | |
0d53fc34 | 48 | bool wxFrame::Create( wxWindow *parent, |
7c0ea335 | 49 | wxWindowID id, |
ca8bf976 VZ |
50 | const wxString& title, |
51 | const wxPoint& pos, | |
52 | const wxSize& sizeOrig, | |
7c0ea335 VZ |
53 | long style, |
54 | const wxString &name ) | |
c801d85f | 55 | { |
c821db16 | 56 | return wxFrameBase::Create(parent, id, title, pos, sizeOrig, style, name); |
362c6693 | 57 | } |
c801d85f | 58 | |
0d53fc34 | 59 | wxFrame::~wxFrame() |
c801d85f | 60 | { |
c6212a0c VZ |
61 | SendDestroyEvent(); |
62 | ||
7c0ea335 | 63 | DeleteAllBars(); |
3d0c4d2e RR |
64 | } |
65 | ||
7c0ea335 VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // overridden wxWindow methods | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
0d53fc34 | 70 | void wxFrame::DoGetClientSize( int *width, int *height ) const |
c801d85f | 71 | { |
223d09f6 | 72 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
7b4c2a06 | 73 | |
e36a8aff | 74 | wxFrameBase::DoGetClientSize(width, height); |
8bbe427f | 75 | |
fb1585ae | 76 | if (height) |
46dc76ba | 77 | { |
75c9da25 | 78 | #if wxUSE_MENUS_NATIVE |
047ac72b | 79 | // menu bar |
cca410b3 | 80 | if (m_frameMenuBar && m_frameMenuBar->IsShown()) |
f03fc89f | 81 | { |
cca410b3 PC |
82 | GtkRequisition req; |
83 | gtk_widget_size_request(m_frameMenuBar->m_widget, &req); | |
4908591c | 84 | #if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
cca410b3 | 85 | *height -= req.height; |
4908591c | 86 | #endif |
f03fc89f | 87 | } |
75c9da25 | 88 | #endif // wxUSE_MENUS_NATIVE |
88ac883a | 89 | |
dcf924a3 | 90 | #if wxUSE_STATUSBAR |
047ac72b | 91 | // status bar |
cca410b3 PC |
92 | if (m_frameStatusBar && m_frameStatusBar->IsShown()) |
93 | *height -= m_frameStatusBar->m_height; | |
93fa69f8 | 94 | #endif // wxUSE_STATUSBAR |
c1fa6f52 | 95 | } |
88ac883a | 96 | |
dcf924a3 | 97 | #if wxUSE_TOOLBAR |
c1fa6f52 | 98 | // tool bar |
cca410b3 | 99 | if (m_frameToolBar && m_frameToolBar->IsShown()) |
c1fa6f52 | 100 | { |
cca410b3 PC |
101 | GtkRequisition req; |
102 | gtk_widget_size_request(m_frameToolBar->m_widget, &req); | |
e36a8aff | 103 | if (m_frameToolBar->IsVertical()) |
fb1585ae | 104 | { |
e36a8aff | 105 | if (width) |
cca410b3 | 106 | *width -= req.width; |
c1fa6f52 PC |
107 | } |
108 | else | |
109 | { | |
e36a8aff | 110 | if (height) |
cca410b3 | 111 | *height -= req.height; |
fb1585ae | 112 | } |
46dc76ba | 113 | } |
c1fa6f52 PC |
114 | #endif // wxUSE_TOOLBAR |
115 | ||
116 | if (width != NULL && *width < 0) | |
117 | *width = 0; | |
118 | if (height != NULL && *height < 0) | |
119 | *height = 0; | |
362c6693 | 120 | } |
c801d85f | 121 | |
6c309653 | 122 | #if wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c JS |
123 | // Helper for wxCreateAcceleratorTableForMenuBar |
124 | static void wxAddAccelerators(wxList& accelEntries, wxMenu* menu) | |
125 | { | |
126 | size_t i; | |
127 | for (i = 0; i < menu->GetMenuItems().GetCount(); i++) | |
128 | { | |
129 | wxMenuItem* item = (wxMenuItem*) menu->GetMenuItems().Item(i)->GetData(); | |
130 | if (item->GetSubMenu()) | |
131 | { | |
132 | wxAddAccelerators(accelEntries, item->GetSubMenu()); | |
133 | } | |
134 | else if (!item->GetItemLabel().IsEmpty()) | |
135 | { | |
136 | wxAcceleratorEntry* entry = wxAcceleratorEntry::Create(item->GetItemLabel()); | |
137 | if (entry) | |
138 | { | |
139 | entry->Set(entry->GetFlags(), entry->GetKeyCode(), item->GetId()); | |
140 | accelEntries.Append((wxObject*) entry); | |
141 | } | |
142 | } | |
143 | } | |
144 | } | |
145 | ||
146 | // Create an accelerator table consisting of all the accelerators | |
147 | // from the menubar in the given menus | |
148 | static wxAcceleratorTable wxCreateAcceleratorTableForMenuBar(wxMenuBar* menuBar) | |
149 | { | |
150 | wxList accelEntries; | |
151 | ||
152 | size_t i; | |
153 | for (i = 0; i < menuBar->GetMenuCount(); i++) | |
154 | { | |
155 | wxAddAccelerators(accelEntries, menuBar->GetMenu(i)); | |
156 | } | |
157 | ||
158 | size_t n = accelEntries.GetCount(); | |
159 | ||
160 | if (n == 0) | |
161 | return wxAcceleratorTable(); | |
162 | ||
163 | wxAcceleratorEntry* entries = new wxAcceleratorEntry[n]; | |
164 | ||
165 | for (i = 0; i < accelEntries.GetCount(); i++) | |
166 | { | |
167 | wxAcceleratorEntry* entry = (wxAcceleratorEntry*) accelEntries.Item(i)->GetData(); | |
168 | entries[i] = (*entry); | |
169 | delete entry; | |
03647350 | 170 | |
e41a1b1c JS |
171 | } |
172 | ||
173 | wxAcceleratorTable table(n, entries); | |
174 | delete[] entries; | |
175 | ||
176 | return table; | |
177 | } | |
6c309653 | 178 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c | 179 | |
1529bc41 PC |
180 | bool wxFrame::ShowFullScreen(bool show, long style) |
181 | { | |
182 | if (!wxFrameBase::ShowFullScreen(show, style)) | |
183 | return false; | |
184 | ||
6c309653 | 185 | #if wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c JS |
186 | if (show && GetMenuBar()) |
187 | { | |
188 | wxAcceleratorTable table(wxCreateAcceleratorTableForMenuBar(GetMenuBar())); | |
189 | if (table.IsOk()) | |
190 | SetAcceleratorTable(table); | |
191 | } | |
6c309653 | 192 | #endif // wxUSE_MENUS && wxUSE_ACCEL |
e41a1b1c | 193 | |
1529bc41 | 194 | wxWindow* const bar[] = { |
28fcfbfe VZ |
195 | #if wxUSE_MENUS |
196 | m_frameMenuBar, | |
197 | #else | |
198 | NULL, | |
199 | #endif | |
200 | #if wxUSE_TOOLBAR | |
201 | m_frameToolBar, | |
202 | #else | |
203 | NULL, | |
204 | #endif | |
205 | #if wxUSE_STATUSBAR | |
206 | m_frameStatusBar, | |
207 | #else | |
208 | NULL, | |
209 | #endif | |
1529bc41 PC |
210 | }; |
211 | const long fsNoBar[] = { | |
212 | wxFULLSCREEN_NOMENUBAR, wxFULLSCREEN_NOTOOLBAR, wxFULLSCREEN_NOSTATUSBAR | |
213 | }; | |
214 | for (int i = 0; i < 3; i++) | |
215 | { | |
216 | if (show) | |
217 | { | |
218 | if (bar[i] && (style & fsNoBar[i])) | |
219 | { | |
220 | if (bar[i]->IsShown()) | |
221 | bar[i]->Show(false); | |
222 | else | |
223 | style &= ~fsNoBar[i]; | |
224 | } | |
225 | } | |
226 | else | |
227 | { | |
228 | if (bar[i] && (m_fsSaveFlag & fsNoBar[i])) | |
229 | bar[i]->Show(true); | |
230 | } | |
231 | } | |
232 | if (show) | |
233 | m_fsSaveFlag = style; | |
234 | ||
235 | return true; | |
236 | } | |
237 | ||
0c3e2a5b | 238 | bool wxFrame::SendIdleEvents(wxIdleEvent& event) |
e52f60e6 | 239 | { |
0c3e2a5b | 240 | bool needMore = wxFrameBase::SendIdleEvents(event); |
88ac883a | 241 | |
0c3e2a5b PC |
242 | #if wxUSE_MENUS |
243 | if (m_frameMenuBar && m_frameMenuBar->SendIdleEvents(event)) | |
244 | needMore = true; | |
245 | #endif | |
dcf924a3 | 246 | #if wxUSE_TOOLBAR |
0c3e2a5b PC |
247 | if (m_frameToolBar && m_frameToolBar->SendIdleEvents(event)) |
248 | needMore = true; | |
dcf924a3 RR |
249 | #endif |
250 | #if wxUSE_STATUSBAR | |
0c3e2a5b PC |
251 | if (m_frameStatusBar && m_frameStatusBar->SendIdleEvents(event)) |
252 | needMore = true; | |
dcf924a3 | 253 | #endif |
0c3e2a5b PC |
254 | |
255 | return needMore; | |
362c6693 | 256 | } |
c801d85f | 257 | |
7c0ea335 VZ |
258 | // ---------------------------------------------------------------------------- |
259 | // menu/tool/status bar stuff | |
260 | // ---------------------------------------------------------------------------- | |
c801d85f | 261 | |
6522713c | 262 | #if wxUSE_MENUS_NATIVE |
1e6feb95 | 263 | |
0d53fc34 | 264 | void wxFrame::DetachMenuBar() |
c801d85f | 265 | { |
223d09f6 KB |
266 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
267 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); | |
8bbe427f | 268 | |
6522713c | 269 | if ( m_frameMenuBar ) |
186baeb2 | 270 | { |
426d19f1 | 271 | #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
e2f3bc41 | 272 | hildon_window_set_menu(HILDON_WINDOW(m_widget), NULL); |
426d19f1 | 273 | #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
80b8c88a | 274 | g_object_ref( m_frameMenuBar->m_widget ); |
f283a575 RR |
275 | |
276 | gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget ); | |
426d19f1 | 277 | #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
186baeb2 RR |
278 | } |
279 | ||
6522713c | 280 | wxFrameBase::DetachMenuBar(); |
cca410b3 PC |
281 | |
282 | // make sure next size_allocate causes a wxSizeEvent | |
283 | m_oldClientWidth = 0; | |
6522713c VZ |
284 | } |
285 | ||
0d53fc34 | 286 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) |
6522713c VZ |
287 | { |
288 | wxFrameBase::AttachMenuBar(menuBar); | |
8bbe427f | 289 | |
f5368809 | 290 | if (m_frameMenuBar) |
30dea054 | 291 | { |
426d19f1 | 292 | #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 |
e2f3bc41 VZ |
293 | hildon_window_set_menu(HILDON_WINDOW(m_widget), |
294 | GTK_MENU(m_frameMenuBar->m_menubar)); | |
426d19f1 | 295 | #else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
186baeb2 | 296 | m_frameMenuBar->SetParent(this); |
91af0895 | 297 | |
cca410b3 PC |
298 | // menubar goes into top of vbox (m_mainWidget) |
299 | gtk_box_pack_start( | |
300 | GTK_BOX(m_mainWidget), menuBar->m_widget, false, false, 0); | |
301 | gtk_box_reorder_child(GTK_BOX(m_mainWidget), menuBar->m_widget, 0); | |
2b5f62a0 | 302 | |
cca410b3 PC |
303 | // reset size request to allow native sizing to work |
304 | gtk_widget_set_size_request(menuBar->m_widget, -1, -1); | |
91af0895 | 305 | |
cca410b3 | 306 | gtk_widget_show( m_frameMenuBar->m_widget ); |
426d19f1 | 307 | #endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2 |
8c70a789 | 308 | } |
cca410b3 PC |
309 | // make sure next size_allocate causes a wxSizeEvent |
310 | m_oldClientWidth = 0; | |
1d66b099 | 311 | } |
6522713c | 312 | #endif // wxUSE_MENUS_NATIVE |
1e6feb95 | 313 | |
88ac883a | 314 | #if wxUSE_TOOLBAR |
1e6feb95 | 315 | |
0d53fc34 | 316 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
7beba2fc | 317 | { |
cca410b3 PC |
318 | m_frameToolBar = toolbar; |
319 | if (toolbar) | |
307f16e8 | 320 | { |
cca410b3 | 321 | if (toolbar->IsVertical()) |
307f16e8 | 322 | { |
cca410b3 PC |
323 | // Vertical toolbar and m_wxwindow go into an hbox, inside the |
324 | // vbox (m_mainWidget). hbox is created on demand. | |
385e8575 | 325 | GtkWidget* hbox = gtk_widget_get_parent(m_wxwindow); |
cca410b3 PC |
326 | if (!GTK_IS_HBOX(hbox)) |
327 | { | |
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); | |
332 | } | |
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); | |
336 | ||
337 | int pos = 0; // left | |
338 | if (toolbar->HasFlag(wxTB_RIGHT)) | |
339 | pos = 1; // right | |
340 | gtk_box_reorder_child(GTK_BOX(hbox), toolbar->m_widget, pos); | |
7beba2fc | 341 | } |
cca410b3 | 342 | else |
94f14509 | 343 | { |
cca410b3 PC |
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); | |
348 | ||
349 | int pos = 0; // top | |
350 | if (m_frameMenuBar) | |
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); | |
94f14509 | 356 | } |
cca410b3 PC |
357 | // reset size request to allow native sizing to work |
358 | gtk_widget_set_size_request(toolbar->m_widget, -1, -1); | |
359 | } | |
360 | // make sure next size_allocate causes a wxSizeEvent | |
361 | m_oldClientWidth = 0; | |
307f16e8 RR |
362 | } |
363 | ||
88ac883a | 364 | #endif // wxUSE_TOOLBAR |
46dc76ba | 365 | |
88ac883a | 366 | #if wxUSE_STATUSBAR |
8bbe427f | 367 | |
3851e479 RR |
368 | void wxFrame::SetStatusBar(wxStatusBar *statbar) |
369 | { | |
cca410b3 PC |
370 | m_frameStatusBar = statbar; |
371 | if (statbar) | |
372 | { | |
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; | |
3b7067a0 PC |
379 | int h = -1; |
380 | if (statbar->m_wxwindow) | |
381 | { | |
382 | // statusbar is not a native widget, need to set height request | |
383 | h = statbar->m_height; | |
384 | } | |
385 | gtk_widget_set_size_request(statbar->m_widget, -1, h); | |
cca410b3 PC |
386 | } |
387 | // make sure next size_allocate causes a wxSizeEvent | |
388 | m_oldClientWidth = 0; | |
8febdd39 | 389 | } |
88ac883a | 390 | #endif // wxUSE_STATUSBAR |