]>
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 | |
7c0ea335 VZ |
23 | // ---------------------------------------------------------------------------- |
24 | // event tables | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
0d53fc34 | 27 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
2e563988 | 28 | |
7c0ea335 VZ |
29 | // ============================================================================ |
30 | // implementation | |
31 | // ============================================================================ | |
32 | ||
7c0ea335 | 33 | // ---------------------------------------------------------------------------- |
0d53fc34 | 34 | // wxFrame creation |
7c0ea335 | 35 | // ---------------------------------------------------------------------------- |
c801d85f | 36 | |
0d53fc34 | 37 | void wxFrame::Init() |
c801d85f | 38 | { |
1529bc41 | 39 | m_fsSaveFlag = 0; |
362c6693 | 40 | } |
c801d85f | 41 | |
0d53fc34 | 42 | bool wxFrame::Create( wxWindow *parent, |
7c0ea335 | 43 | wxWindowID id, |
ca8bf976 VZ |
44 | const wxString& title, |
45 | const wxPoint& pos, | |
46 | const wxSize& sizeOrig, | |
7c0ea335 VZ |
47 | long style, |
48 | const wxString &name ) | |
c801d85f | 49 | { |
c821db16 | 50 | return wxFrameBase::Create(parent, id, title, pos, sizeOrig, style, name); |
362c6693 | 51 | } |
c801d85f | 52 | |
0d53fc34 | 53 | wxFrame::~wxFrame() |
c801d85f | 54 | { |
91af0895 | 55 | m_isBeingDeleted = true; |
7c0ea335 | 56 | DeleteAllBars(); |
3d0c4d2e RR |
57 | } |
58 | ||
7c0ea335 VZ |
59 | // ---------------------------------------------------------------------------- |
60 | // overridden wxWindow methods | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
0d53fc34 | 63 | void wxFrame::DoGetClientSize( int *width, int *height ) const |
c801d85f | 64 | { |
223d09f6 | 65 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
7b4c2a06 | 66 | |
e36a8aff | 67 | wxFrameBase::DoGetClientSize(width, height); |
8bbe427f | 68 | |
fb1585ae | 69 | if (height) |
46dc76ba | 70 | { |
75c9da25 | 71 | #if wxUSE_MENUS_NATIVE |
047ac72b | 72 | // menu bar |
cca410b3 | 73 | if (m_frameMenuBar && m_frameMenuBar->IsShown()) |
f03fc89f | 74 | { |
cca410b3 PC |
75 | GtkRequisition req; |
76 | gtk_widget_size_request(m_frameMenuBar->m_widget, &req); | |
77 | *height -= req.height; | |
f03fc89f | 78 | } |
75c9da25 | 79 | #endif // wxUSE_MENUS_NATIVE |
88ac883a | 80 | |
dcf924a3 | 81 | #if wxUSE_STATUSBAR |
047ac72b | 82 | // status bar |
cca410b3 PC |
83 | if (m_frameStatusBar && m_frameStatusBar->IsShown()) |
84 | *height -= m_frameStatusBar->m_height; | |
93fa69f8 | 85 | #endif // wxUSE_STATUSBAR |
c1fa6f52 | 86 | } |
88ac883a | 87 | |
dcf924a3 | 88 | #if wxUSE_TOOLBAR |
c1fa6f52 | 89 | // tool bar |
cca410b3 | 90 | if (m_frameToolBar && m_frameToolBar->IsShown()) |
c1fa6f52 | 91 | { |
cca410b3 PC |
92 | GtkRequisition req; |
93 | gtk_widget_size_request(m_frameToolBar->m_widget, &req); | |
e36a8aff | 94 | if (m_frameToolBar->IsVertical()) |
fb1585ae | 95 | { |
e36a8aff | 96 | if (width) |
cca410b3 | 97 | *width -= req.width; |
c1fa6f52 PC |
98 | } |
99 | else | |
100 | { | |
e36a8aff | 101 | if (height) |
cca410b3 | 102 | *height -= req.height; |
fb1585ae | 103 | } |
46dc76ba | 104 | } |
c1fa6f52 PC |
105 | #endif // wxUSE_TOOLBAR |
106 | ||
107 | if (width != NULL && *width < 0) | |
108 | *width = 0; | |
109 | if (height != NULL && *height < 0) | |
110 | *height = 0; | |
362c6693 | 111 | } |
c801d85f | 112 | |
1529bc41 PC |
113 | bool wxFrame::ShowFullScreen(bool show, long style) |
114 | { | |
115 | if (!wxFrameBase::ShowFullScreen(show, style)) | |
116 | return false; | |
117 | ||
118 | wxWindow* const bar[] = { | |
28fcfbfe VZ |
119 | #if wxUSE_MENUS |
120 | m_frameMenuBar, | |
121 | #else | |
122 | NULL, | |
123 | #endif | |
124 | #if wxUSE_TOOLBAR | |
125 | m_frameToolBar, | |
126 | #else | |
127 | NULL, | |
128 | #endif | |
129 | #if wxUSE_STATUSBAR | |
130 | m_frameStatusBar, | |
131 | #else | |
132 | NULL, | |
133 | #endif | |
1529bc41 PC |
134 | }; |
135 | const long fsNoBar[] = { | |
136 | wxFULLSCREEN_NOMENUBAR, wxFULLSCREEN_NOTOOLBAR, wxFULLSCREEN_NOSTATUSBAR | |
137 | }; | |
138 | for (int i = 0; i < 3; i++) | |
139 | { | |
140 | if (show) | |
141 | { | |
142 | if (bar[i] && (style & fsNoBar[i])) | |
143 | { | |
144 | if (bar[i]->IsShown()) | |
145 | bar[i]->Show(false); | |
146 | else | |
147 | style &= ~fsNoBar[i]; | |
148 | } | |
149 | } | |
150 | else | |
151 | { | |
152 | if (bar[i] && (m_fsSaveFlag & fsNoBar[i])) | |
153 | bar[i]->Show(true); | |
154 | } | |
155 | } | |
156 | if (show) | |
157 | m_fsSaveFlag = style; | |
158 | ||
159 | return true; | |
160 | } | |
161 | ||
0d53fc34 | 162 | void wxFrame::OnInternalIdle() |
e52f60e6 | 163 | { |
e39af974 | 164 | wxFrameBase::OnInternalIdle(); |
88ac883a | 165 | |
75c9da25 | 166 | #if wxUSE_MENUS_NATIVE |
082b2798 | 167 | if (m_frameMenuBar) m_frameMenuBar->OnInternalIdle(); |
75c9da25 | 168 | #endif // wxUSE_MENUS_NATIVE |
dcf924a3 | 169 | #if wxUSE_TOOLBAR |
082b2798 | 170 | if (m_frameToolBar) m_frameToolBar->OnInternalIdle(); |
dcf924a3 RR |
171 | #endif |
172 | #if wxUSE_STATUSBAR | |
e4edaf5c JS |
173 | if (m_frameStatusBar) |
174 | { | |
175 | m_frameStatusBar->OnInternalIdle(); | |
176 | ||
177 | // There may be controls in the status bar that | |
178 | // need to be updated | |
179 | for ( wxWindowList::compatibility_iterator node = m_frameStatusBar->GetChildren().GetFirst(); | |
180 | node; | |
181 | node = node->GetNext() ) | |
182 | { | |
183 | wxWindow *child = node->GetData(); | |
184 | child->OnInternalIdle(); | |
185 | } | |
186 | } | |
dcf924a3 | 187 | #endif |
362c6693 | 188 | } |
c801d85f | 189 | |
7c0ea335 VZ |
190 | // ---------------------------------------------------------------------------- |
191 | // menu/tool/status bar stuff | |
192 | // ---------------------------------------------------------------------------- | |
c801d85f | 193 | |
6522713c | 194 | #if wxUSE_MENUS_NATIVE |
1e6feb95 | 195 | |
0d53fc34 | 196 | void wxFrame::DetachMenuBar() |
c801d85f | 197 | { |
223d09f6 KB |
198 | wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") ); |
199 | wxASSERT_MSG( (m_wxwindow != NULL), wxT("invalid frame") ); | |
8bbe427f | 200 | |
6522713c | 201 | if ( m_frameMenuBar ) |
186baeb2 RR |
202 | { |
203 | m_frameMenuBar->UnsetInvokingWindow( this ); | |
204 | ||
186baeb2 | 205 | gtk_widget_ref( m_frameMenuBar->m_widget ); |
f283a575 RR |
206 | |
207 | gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget ); | |
186baeb2 RR |
208 | } |
209 | ||
6522713c | 210 | wxFrameBase::DetachMenuBar(); |
cca410b3 PC |
211 | |
212 | // make sure next size_allocate causes a wxSizeEvent | |
213 | m_oldClientWidth = 0; | |
6522713c VZ |
214 | } |
215 | ||
0d53fc34 | 216 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) |
6522713c VZ |
217 | { |
218 | wxFrameBase::AttachMenuBar(menuBar); | |
8bbe427f | 219 | |
f5368809 | 220 | if (m_frameMenuBar) |
30dea054 | 221 | { |
5bd9e519 | 222 | m_frameMenuBar->SetInvokingWindow( this ); |
8bbe427f | 223 | |
186baeb2 | 224 | m_frameMenuBar->SetParent(this); |
91af0895 | 225 | |
cca410b3 PC |
226 | // menubar goes into top of vbox (m_mainWidget) |
227 | gtk_box_pack_start( | |
228 | GTK_BOX(m_mainWidget), menuBar->m_widget, false, false, 0); | |
229 | gtk_box_reorder_child(GTK_BOX(m_mainWidget), menuBar->m_widget, 0); | |
2b5f62a0 | 230 | |
cca410b3 PC |
231 | // disconnect wxWindowGTK "size_request" handler, |
232 | // it interferes with sizing of detached GtkHandleBox | |
233 | gulong handler_id = g_signal_handler_find( | |
234 | menuBar->m_widget, | |
235 | GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), | |
236 | g_signal_lookup("size_request", GTK_TYPE_WIDGET), | |
237 | 0, NULL, NULL, menuBar); | |
238 | if (handler_id != 0) | |
239 | g_signal_handler_disconnect(menuBar->m_widget, handler_id); | |
2b5f62a0 | 240 | |
cca410b3 PC |
241 | // reset size request to allow native sizing to work |
242 | gtk_widget_set_size_request(menuBar->m_widget, -1, -1); | |
91af0895 | 243 | |
cca410b3 | 244 | gtk_widget_show( m_frameMenuBar->m_widget ); |
8c70a789 | 245 | } |
cca410b3 PC |
246 | // make sure next size_allocate causes a wxSizeEvent |
247 | m_oldClientWidth = 0; | |
1d66b099 | 248 | } |
6522713c | 249 | #endif // wxUSE_MENUS_NATIVE |
1e6feb95 | 250 | |
88ac883a | 251 | #if wxUSE_TOOLBAR |
1e6feb95 | 252 | |
0d53fc34 | 253 | void wxFrame::SetToolBar(wxToolBar *toolbar) |
7beba2fc | 254 | { |
cca410b3 PC |
255 | m_frameToolBar = toolbar; |
256 | if (toolbar) | |
307f16e8 | 257 | { |
cca410b3 | 258 | if (toolbar->IsVertical()) |
307f16e8 | 259 | { |
cca410b3 PC |
260 | // Vertical toolbar and m_wxwindow go into an hbox, inside the |
261 | // vbox (m_mainWidget). hbox is created on demand. | |
262 | GtkWidget* hbox = m_wxwindow->parent; | |
263 | if (!GTK_IS_HBOX(hbox)) | |
264 | { | |
265 | hbox = gtk_hbox_new(false, 0); | |
266 | gtk_widget_show(hbox); | |
267 | gtk_container_add(GTK_CONTAINER(m_mainWidget), hbox); | |
268 | gtk_widget_reparent(m_wxwindow, hbox); | |
269 | } | |
270 | gtk_widget_reparent(toolbar->m_widget, hbox); | |
271 | gtk_box_set_child_packing(GTK_BOX(hbox), | |
272 | toolbar->m_widget, false, false, 0, GTK_PACK_START); | |
273 | ||
274 | int pos = 0; // left | |
275 | if (toolbar->HasFlag(wxTB_RIGHT)) | |
276 | pos = 1; // right | |
277 | gtk_box_reorder_child(GTK_BOX(hbox), toolbar->m_widget, pos); | |
7beba2fc | 278 | } |
cca410b3 | 279 | else |
94f14509 | 280 | { |
cca410b3 PC |
281 | // Horizontal toolbar goes into vbox (m_mainWidget) |
282 | gtk_widget_reparent(toolbar->m_widget, m_mainWidget); | |
283 | gtk_box_set_child_packing(GTK_BOX(m_mainWidget), | |
284 | toolbar->m_widget, false, false, 0, GTK_PACK_START); | |
285 | ||
286 | int pos = 0; // top | |
287 | if (m_frameMenuBar) | |
288 | pos = 1; // below menubar | |
289 | if (toolbar->HasFlag(wxTB_BOTTOM)) | |
290 | pos += 2; // below client area (m_wxwindow) | |
291 | gtk_box_reorder_child( | |
292 | GTK_BOX(m_mainWidget), toolbar->m_widget, pos); | |
94f14509 | 293 | } |
383144c7 | 294 | |
cca410b3 PC |
295 | // disconnect wxWindowGTK "size_request" handler, |
296 | // it interferes with sizing of detached GtkHandleBox | |
297 | gulong handler_id = g_signal_handler_find( | |
298 | toolbar->m_widget, | |
299 | GSignalMatchType(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA), | |
300 | g_signal_lookup("size_request", GTK_TYPE_WIDGET), | |
301 | 0, NULL, NULL, toolbar); | |
302 | if (handler_id != 0) | |
303 | g_signal_handler_disconnect(toolbar->m_widget, handler_id); | |
304 | ||
305 | // reset size request to allow native sizing to work | |
306 | gtk_widget_set_size_request(toolbar->m_widget, -1, -1); | |
307 | } | |
308 | // make sure next size_allocate causes a wxSizeEvent | |
309 | m_oldClientWidth = 0; | |
307f16e8 RR |
310 | } |
311 | ||
88ac883a | 312 | #endif // wxUSE_TOOLBAR |
46dc76ba | 313 | |
88ac883a | 314 | #if wxUSE_STATUSBAR |
8bbe427f | 315 | |
3851e479 RR |
316 | void wxFrame::SetStatusBar(wxStatusBar *statbar) |
317 | { | |
cca410b3 PC |
318 | m_frameStatusBar = statbar; |
319 | if (statbar) | |
320 | { | |
321 | // statusbar goes into bottom of vbox (m_mainWidget) | |
322 | gtk_widget_reparent(statbar->m_widget, m_mainWidget); | |
323 | gtk_box_set_child_packing(GTK_BOX(m_mainWidget), | |
324 | statbar->m_widget, false, false, 0, GTK_PACK_END); | |
325 | // make sure next size_allocate on statusbar causes a size event | |
326 | statbar->m_oldClientWidth = 0; | |
327 | } | |
328 | // make sure next size_allocate causes a wxSizeEvent | |
329 | m_oldClientWidth = 0; | |
8febdd39 | 330 | } |
88ac883a | 331 | #endif // wxUSE_STATUSBAR |