]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/frame.cpp
Don't close arcs drawn in wxPostScriptDC.
[wxWidgets.git] / src / gtk / frame.cpp
CommitLineData
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 43void wxFrame::Init()
c801d85f 44{
1529bc41 45 m_fsSaveFlag = 0;
362c6693 46}
c801d85f 47
0d53fc34 48bool 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 59wxFrame::~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 70void 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
124static 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
148static 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
180bool 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 238bool 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 264void 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 286void 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 // disconnect wxWindowGTK "size_request" handler,
304 // it interferes with sizing of detached GtkHandleBox
305 gulong handler_id = g_signal_handler_find(
306 menuBar->m_widget,
307 GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
308 g_signal_lookup("size_request", GTK_TYPE_WIDGET),
309 0, NULL, NULL, menuBar);
310 if (handler_id != 0)
311 g_signal_handler_disconnect(menuBar->m_widget, handler_id);
2b5f62a0 312
cca410b3
PC
313 // reset size request to allow native sizing to work
314 gtk_widget_set_size_request(menuBar->m_widget, -1, -1);
91af0895 315
cca410b3 316 gtk_widget_show( m_frameMenuBar->m_widget );
426d19f1 317#endif // wxUSE_LIBHILDON || wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
8c70a789 318 }
cca410b3
PC
319 // make sure next size_allocate causes a wxSizeEvent
320 m_oldClientWidth = 0;
1d66b099 321}
6522713c 322#endif // wxUSE_MENUS_NATIVE
1e6feb95 323
88ac883a 324#if wxUSE_TOOLBAR
1e6feb95 325
0d53fc34 326void wxFrame::SetToolBar(wxToolBar *toolbar)
7beba2fc 327{
cca410b3
PC
328 m_frameToolBar = toolbar;
329 if (toolbar)
307f16e8 330 {
cca410b3 331 if (toolbar->IsVertical())
307f16e8 332 {
cca410b3
PC
333 // Vertical toolbar and m_wxwindow go into an hbox, inside the
334 // vbox (m_mainWidget). hbox is created on demand.
385e8575 335 GtkWidget* hbox = gtk_widget_get_parent(m_wxwindow);
cca410b3
PC
336 if (!GTK_IS_HBOX(hbox))
337 {
338 hbox = gtk_hbox_new(false, 0);
339 gtk_widget_show(hbox);
340 gtk_container_add(GTK_CONTAINER(m_mainWidget), hbox);
341 gtk_widget_reparent(m_wxwindow, hbox);
342 }
343 gtk_widget_reparent(toolbar->m_widget, hbox);
344 gtk_box_set_child_packing(GTK_BOX(hbox),
345 toolbar->m_widget, false, false, 0, GTK_PACK_START);
346
347 int pos = 0; // left
348 if (toolbar->HasFlag(wxTB_RIGHT))
349 pos = 1; // right
350 gtk_box_reorder_child(GTK_BOX(hbox), toolbar->m_widget, pos);
7beba2fc 351 }
cca410b3 352 else
94f14509 353 {
cca410b3
PC
354 // Horizontal toolbar goes into vbox (m_mainWidget)
355 gtk_widget_reparent(toolbar->m_widget, m_mainWidget);
356 gtk_box_set_child_packing(GTK_BOX(m_mainWidget),
357 toolbar->m_widget, false, false, 0, GTK_PACK_START);
358
359 int pos = 0; // top
360 if (m_frameMenuBar)
361 pos = 1; // below menubar
362 if (toolbar->HasFlag(wxTB_BOTTOM))
363 pos += 2; // below client area (m_wxwindow)
364 gtk_box_reorder_child(
365 GTK_BOX(m_mainWidget), toolbar->m_widget, pos);
94f14509 366 }
383144c7 367
cca410b3
PC
368 // disconnect wxWindowGTK "size_request" handler,
369 // it interferes with sizing of detached GtkHandleBox
370 gulong handler_id = g_signal_handler_find(
371 toolbar->m_widget,
372 GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA),
373 g_signal_lookup("size_request", GTK_TYPE_WIDGET),
374 0, NULL, NULL, toolbar);
375 if (handler_id != 0)
376 g_signal_handler_disconnect(toolbar->m_widget, handler_id);
377
378 // reset size request to allow native sizing to work
379 gtk_widget_set_size_request(toolbar->m_widget, -1, -1);
380 }
381 // make sure next size_allocate causes a wxSizeEvent
382 m_oldClientWidth = 0;
307f16e8
RR
383}
384
88ac883a 385#endif // wxUSE_TOOLBAR
46dc76ba 386
88ac883a 387#if wxUSE_STATUSBAR
8bbe427f 388
3851e479
RR
389void wxFrame::SetStatusBar(wxStatusBar *statbar)
390{
cca410b3
PC
391 m_frameStatusBar = statbar;
392 if (statbar)
393 {
394 // statusbar goes into bottom of vbox (m_mainWidget)
395 gtk_widget_reparent(statbar->m_widget, m_mainWidget);
396 gtk_box_set_child_packing(GTK_BOX(m_mainWidget),
397 statbar->m_widget, false, false, 0, GTK_PACK_END);
398 // make sure next size_allocate on statusbar causes a size event
399 statbar->m_oldClientWidth = 0;
400 }
401 // make sure next size_allocate causes a wxSizeEvent
402 m_oldClientWidth = 0;
8febdd39 403}
88ac883a 404#endif // wxUSE_STATUSBAR