]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
a81258be | 5 | // Id: $Id$ |
01111366 | 6 | // Copyright: (c) 1998 Robert Roebling |
19717c50 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifdef __GNUG__ | |
fe4e9e6c | 11 | #pragma implementation "frame.h" |
c801d85f KB |
12 | #endif |
13 | ||
14 | #include "wx/frame.h" | |
15 | #include "wx/dialog.h" | |
16 | #include "wx/control.h" | |
17 | #include "wx/app.h" | |
cf4219e7 RR |
18 | #include "wx/menu.h" |
19 | #include "wx/toolbar.h" | |
20 | #include "wx/statusbr.h" | |
362c6693 | 21 | #include "wx/dcclient.h" |
83624f79 RR |
22 | |
23 | #include "glib.h" | |
24 | #include "gdk/gdk.h" | |
25 | #include "gtk/gtk.h" | |
c801d85f KB |
26 | #include "wx/gtk/win_gtk.h" |
27 | ||
2f2aa628 RR |
28 | //----------------------------------------------------------------------------- |
29 | // constants | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
907789a0 | 32 | const int wxMENU_HEIGHT = 27; |
c67daf87 | 33 | const int wxSTATUS_HEIGHT = 25; |
c801d85f | 34 | |
2f2aa628 RR |
35 | //----------------------------------------------------------------------------- |
36 | // data | |
37 | //----------------------------------------------------------------------------- | |
38 | ||
c801d85f KB |
39 | extern wxList wxTopLevelWindows; |
40 | extern wxList wxPendingDelete; | |
41 | ||
42 | //----------------------------------------------------------------------------- | |
2f2aa628 | 43 | // "size_allocate" |
c801d85f | 44 | //----------------------------------------------------------------------------- |
c801d85f | 45 | |
2f2aa628 | 46 | static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxFrame *win ) |
ed7a557b | 47 | { |
fb1585ae | 48 | if (!win->HasVMT()) return; |
8bbe427f | 49 | |
c801d85f | 50 | /* |
fb1585ae RR |
51 | printf( "OnFrameResize from " ); |
52 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
53 | printf( win->GetClassInfo()->GetClassName() ); | |
54 | printf( ".\n" ); | |
c801d85f | 55 | */ |
8bbe427f | 56 | |
e52f60e6 RR |
57 | if ((win->m_width != alloc->width) || (win->m_height != alloc->height)) |
58 | { | |
59 | win->m_sizeSet = FALSE; | |
60 | win->m_width = alloc->width; | |
61 | win->m_height = alloc->height; | |
62 | } | |
362c6693 | 63 | } |
c801d85f KB |
64 | |
65 | //----------------------------------------------------------------------------- | |
2f2aa628 RR |
66 | // "delete_event" |
67 | //----------------------------------------------------------------------------- | |
c801d85f | 68 | |
2f2aa628 | 69 | static gint gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget), GdkEvent *WXUNUSED(event), wxFrame *win ) |
ed7a557b | 70 | { |
c801d85f | 71 | /* |
fb1585ae RR |
72 | printf( "OnDelete from " ); |
73 | if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) | |
74 | printf( win->GetClassInfo()->GetClassName() ); | |
75 | printf( ".\n" ); | |
c801d85f | 76 | */ |
ed7a557b | 77 | |
fb1585ae | 78 | win->Close(); |
c801d85f | 79 | |
fb1585ae | 80 | return TRUE; |
362c6693 | 81 | } |
c801d85f | 82 | |
47908e25 | 83 | //----------------------------------------------------------------------------- |
2f2aa628 RR |
84 | // "configure_event" |
85 | //----------------------------------------------------------------------------- | |
47908e25 | 86 | |
2f2aa628 | 87 | static gint gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigure *event, wxFrame *win ) |
47908e25 | 88 | { |
fb1585ae | 89 | if (!win->HasVMT()) return FALSE; |
8bbe427f | 90 | |
fb1585ae RR |
91 | win->m_x = event->x; |
92 | win->m_y = event->y; | |
8bbe427f | 93 | |
36b3b54a RR |
94 | wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() ); |
95 | mevent.SetEventObject( win ); | |
96 | win->GetEventHandler()->ProcessEvent( mevent ); | |
97 | ||
fb1585ae | 98 | return FALSE; |
362c6693 | 99 | } |
47908e25 | 100 | |
2f2aa628 RR |
101 | //----------------------------------------------------------------------------- |
102 | // wxFrame | |
c801d85f KB |
103 | //----------------------------------------------------------------------------- |
104 | ||
105 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
fb1585ae | 106 | EVT_SIZE(wxFrame::OnSize) |
fe4e9e6c | 107 | EVT_CLOSE(wxFrame::OnCloseWindow) |
342b6a2f | 108 | EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) |
c801d85f KB |
109 | END_EVENT_TABLE() |
110 | ||
111 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
112 | ||
19717c50 | 113 | wxFrame::wxFrame() |
c801d85f | 114 | { |
fb1585ae | 115 | m_frameMenuBar = (wxMenuBar *) NULL; |
e27ce4e9 | 116 | m_mdiMenuBar = (wxMenuBar *) NULL; |
fb1585ae RR |
117 | m_frameStatusBar = (wxStatusBar *) NULL; |
118 | m_frameToolBar = (wxToolBar *) NULL; | |
119 | m_sizeSet = FALSE; | |
b2b3ccc5 RR |
120 | m_miniEdge = 0; |
121 | m_miniTitle = 0; | |
362c6693 | 122 | } |
c801d85f | 123 | |
ed7a557b | 124 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, |
debe6624 JS |
125 | const wxPoint &pos, const wxSize &size, |
126 | long style, const wxString &name ) | |
c801d85f | 127 | { |
fb1585ae | 128 | m_frameMenuBar = (wxMenuBar *) NULL; |
e27ce4e9 | 129 | m_mdiMenuBar = (wxMenuBar *) NULL; |
fb1585ae RR |
130 | m_frameStatusBar = (wxStatusBar *) NULL; |
131 | m_frameToolBar = (wxToolBar *) NULL; | |
132 | m_sizeSet = FALSE; | |
b2b3ccc5 RR |
133 | m_miniEdge = 0; |
134 | m_miniTitle = 0; | |
fb1585ae | 135 | Create( parent, id, title, pos, size, style, name ); |
362c6693 | 136 | } |
c801d85f | 137 | |
debe6624 | 138 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, |
c801d85f | 139 | const wxPoint &pos, const wxSize &size, |
debe6624 | 140 | long style, const wxString &name ) |
c801d85f | 141 | { |
a802c3a1 | 142 | wxTopLevelWindows.Append( this ); |
8bbe427f | 143 | |
fb1585ae | 144 | m_needParent = FALSE; |
ed7a557b | 145 | |
fb1585ae | 146 | PreCreation( parent, id, pos, size, style, name ); |
c801d85f | 147 | |
fb1585ae | 148 | m_title = title; |
ed7a557b | 149 | |
fb1585ae RR |
150 | GtkWindowType win_type = GTK_WINDOW_TOPLEVEL; |
151 | if (style & wxSIMPLE_BORDER) win_type = GTK_WINDOW_POPUP; | |
8bbe427f | 152 | |
fb1585ae | 153 | m_widget = gtk_window_new( win_type ); |
8bbe427f | 154 | |
fb1585ae RR |
155 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); |
156 | GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS ); | |
ed7a557b | 157 | |
f5eafd0e | 158 | gtk_window_set_policy( GTK_WINDOW(m_widget), 1, 1, 0 ); |
ed7a557b | 159 | |
fb1585ae RR |
160 | gtk_signal_connect( GTK_OBJECT(m_widget), "delete_event", |
161 | GTK_SIGNAL_FUNC(gtk_frame_delete_callback), (gpointer)this ); | |
ed7a557b | 162 | |
fb1585ae RR |
163 | m_wxwindow = gtk_myfixed_new(); |
164 | gtk_widget_show( m_wxwindow ); | |
165 | GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); | |
ed7a557b | 166 | |
fb1585ae | 167 | gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow ); |
ed7a557b | 168 | |
de8113d9 RR |
169 | if (m_parent) m_parent->AddChild( this ); |
170 | ||
171 | PostCreation(); | |
172 | ||
173 | gtk_widget_realize( m_widget ); | |
174 | ||
fb1585ae RR |
175 | gtk_signal_connect( GTK_OBJECT(m_widget), "size_allocate", |
176 | GTK_SIGNAL_FUNC(gtk_frame_size_callback), (gpointer)this ); | |
ed7a557b | 177 | |
fb1585ae RR |
178 | gtk_signal_connect( GTK_OBJECT(m_widget), "configure_event", |
179 | GTK_SIGNAL_FUNC(gtk_frame_configure_callback), (gpointer)this ); | |
8bbe427f | 180 | |
fb1585ae | 181 | return TRUE; |
362c6693 | 182 | } |
c801d85f | 183 | |
19717c50 | 184 | wxFrame::~wxFrame() |
c801d85f | 185 | { |
fb1585ae | 186 | if (m_frameMenuBar) delete m_frameMenuBar; |
e27ce4e9 RR |
187 | m_frameMenuBar = (wxMenuBar *) NULL; |
188 | ||
fb1585ae | 189 | if (m_frameStatusBar) delete m_frameStatusBar; |
e27ce4e9 RR |
190 | m_frameStatusBar = (wxStatusBar *) NULL; |
191 | ||
fb1585ae | 192 | if (m_frameToolBar) delete m_frameToolBar; |
e27ce4e9 | 193 | m_frameToolBar = (wxToolBar *) NULL; |
ed7a557b | 194 | |
fb1585ae | 195 | wxTopLevelWindows.DeleteObject( this ); |
2b854a32 | 196 | |
0d2a2b60 RR |
197 | if (wxTheApp->GetTopWindow() == this) |
198 | { | |
199 | wxTheApp->SetTopWindow( (wxWindow*) NULL ); | |
200 | } | |
2b854a32 | 201 | |
0d2a2b60 | 202 | if (wxTopLevelWindows.Number() == 0) |
2b854a32 | 203 | { |
0d2a2b60 RR |
204 | wxTheApp->ExitMainLoop(); |
205 | } | |
362c6693 | 206 | } |
ed7a557b | 207 | |
debe6624 | 208 | bool wxFrame::Show( bool show ) |
c801d85f | 209 | { |
fb1585ae | 210 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 211 | |
35178437 | 212 | if (show && !m_sizeSet) |
fb1585ae | 213 | { |
e27ce4e9 RR |
214 | /* by calling GtkOnSize here, we don't have to call |
215 | either after showing the frame, which would entail | |
216 | much ugly flicker nor from within the size_allocate | |
217 | handler, because GTK 1.1.X forbids that. */ | |
8bbe427f | 218 | |
35178437 | 219 | GtkOnSize( m_x, m_y, m_width, m_height ); |
fb1585ae | 220 | } |
8bbe427f | 221 | |
fb1585ae | 222 | return wxWindow::Show( show ); |
362c6693 | 223 | } |
c801d85f | 224 | |
19717c50 | 225 | bool wxFrame::Destroy() |
c801d85f | 226 | { |
fb1585ae | 227 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 228 | |
fb1585ae | 229 | if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); |
ed7a557b | 230 | |
fb1585ae | 231 | return TRUE; |
c801d85f KB |
232 | } |
233 | ||
6ca41e57 RR |
234 | wxPoint wxFrame::GetClientAreaOrigin() const |
235 | { | |
b2b3ccc5 | 236 | wxPoint pt( m_miniEdge, m_miniEdge + m_miniTitle ); |
fb1585ae RR |
237 | if (m_frameMenuBar) |
238 | { | |
239 | int h = 0; | |
240 | m_frameMenuBar->GetSize( (int*)NULL, &h ); | |
907789a0 | 241 | pt.y += h; |
fb1585ae RR |
242 | } |
243 | if (m_frameToolBar) | |
244 | { | |
245 | int h = 0; | |
246 | m_frameToolBar->GetSize( (int*)NULL, &h ); | |
247 | pt.y += h; | |
248 | } | |
249 | return pt; | |
6ca41e57 RR |
250 | } |
251 | ||
fb1585ae | 252 | void wxFrame::SetSize( int x, int y, int width, int height, int sizeFlags ) |
903f689b | 253 | { |
de8113d9 | 254 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 255 | |
de8113d9 | 256 | /* don't do anything for children of wxMDIChildFrame */ |
fb1585ae RR |
257 | if (!m_wxwindow) return; |
258 | ||
259 | if (m_resizing) return; // I don't like recursions | |
260 | m_resizing = TRUE; | |
261 | ||
262 | int old_x = m_x; | |
263 | int old_y = m_y; | |
264 | int old_width = m_width; | |
265 | int old_height = m_height; | |
8bbe427f | 266 | |
fb1585ae RR |
267 | if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) |
268 | { | |
269 | if (x != -1) m_x = x; | |
270 | if (y != -1) m_y = y; | |
271 | if (width != -1) m_width = width; | |
272 | if (height != -1) m_height = height; | |
273 | } | |
274 | else | |
275 | { | |
276 | m_x = x; | |
277 | m_y = y; | |
278 | m_width = width; | |
279 | m_height = height; | |
280 | } | |
281 | ||
282 | if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) | |
283 | { | |
284 | if (width == -1) m_width = 80; | |
285 | } | |
286 | ||
287 | if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) | |
288 | { | |
289 | if (height == -1) m_height = 26; | |
290 | } | |
8bbe427f | 291 | |
fb1585ae RR |
292 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
293 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
0c77152e RR |
294 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
295 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
fb1585ae RR |
296 | |
297 | if ((m_x != -1) || (m_y != -1)) | |
298 | { | |
8bbe427f | 299 | if ((m_x != old_x) || (m_y != old_y)) |
de8113d9 RR |
300 | { |
301 | /* m_sizeSet = FALSE; */ | |
302 | gtk_widget_set_uposition( m_widget, m_x, m_y ); | |
303 | } | |
fb1585ae | 304 | } |
8bbe427f | 305 | |
fb1585ae RR |
306 | if ((m_width != old_width) || (m_height != old_height)) |
307 | { | |
de8113d9 RR |
308 | /* we set the size in GtkOnSize */ |
309 | m_sizeSet = FALSE; | |
fb1585ae | 310 | } |
8bbe427f | 311 | |
fb1585ae | 312 | m_resizing = FALSE; |
903f689b RR |
313 | } |
314 | ||
43a18898 RR |
315 | void wxFrame::SetSize( int width, int height ) |
316 | { | |
317 | SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); | |
318 | } | |
319 | ||
903f689b RR |
320 | void wxFrame::Centre( int direction ) |
321 | { | |
fb1585ae | 322 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 323 | |
43a18898 RR |
324 | int x = 0; |
325 | int y = 0; | |
8bbe427f | 326 | |
f5eafd0e RR |
327 | if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2; |
328 | if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2; | |
8bbe427f | 329 | |
fb1585ae | 330 | Move( x, y ); |
903f689b RR |
331 | } |
332 | ||
c801d85f KB |
333 | void wxFrame::GetClientSize( int *width, int *height ) const |
334 | { | |
fb1585ae | 335 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 336 | |
fb1585ae RR |
337 | wxWindow::GetClientSize( width, height ); |
338 | if (height) | |
46dc76ba | 339 | { |
fb1585ae RR |
340 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; |
341 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
342 | if (m_frameToolBar) | |
343 | { | |
344 | int y = 0; | |
345 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
346 | (*height) -= y; | |
347 | } | |
b2b3ccc5 RR |
348 | (*height) -= m_miniEdge*2 + m_miniTitle; |
349 | } | |
350 | if (width) | |
351 | { | |
352 | (*width) -= m_miniEdge*2; | |
46dc76ba | 353 | } |
362c6693 | 354 | } |
c801d85f | 355 | |
de8113d9 | 356 | void wxFrame::SetClientSize( int width, int height ) |
b593568e | 357 | { |
f5368809 | 358 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 359 | |
f5368809 RR |
360 | int h = height; |
361 | if (m_frameMenuBar) h += wxMENU_HEIGHT; | |
362 | if (m_frameStatusBar) h += wxSTATUS_HEIGHT; | |
363 | if (m_frameToolBar) | |
364 | { | |
365 | int y = 0; | |
366 | m_frameToolBar->GetSize( (int *) NULL, &y ); | |
367 | h += y; | |
368 | } | |
b2b3ccc5 | 369 | wxWindow::SetClientSize( width + m_miniEdge*2, h + m_miniEdge*2 + m_miniTitle ); |
362c6693 | 370 | } |
b593568e | 371 | |
47908e25 | 372 | void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height ) |
c801d85f | 373 | { |
f5368809 RR |
374 | // due to a bug in gtk, x,y are always 0 |
375 | // m_x = x; | |
376 | // m_y = y; | |
377 | ||
e52f60e6 RR |
378 | if (m_resizing) return; |
379 | m_resizing = TRUE; | |
8bbe427f | 380 | |
f5368809 | 381 | if (!m_wxwindow) return; |
8bbe427f | 382 | |
f5368809 RR |
383 | m_width = width; |
384 | m_height = height; | |
8bbe427f | 385 | |
de8113d9 | 386 | /* check if size is in legal range */ |
f5368809 RR |
387 | if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; |
388 | if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; | |
0c77152e RR |
389 | if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; |
390 | if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; | |
f5368809 | 391 | |
de8113d9 RR |
392 | /* this emulates the new wxMSW behaviour of placing all |
393 | * frame-subwindows (menu, toolbar..) on one native window | |
394 | * this hurts in the eye, but I don't want to call SetSize() | |
395 | * because I don't want to call any non-native functions here. */ | |
8bbe427f | 396 | |
f5368809 RR |
397 | if (m_frameMenuBar) |
398 | { | |
907789a0 | 399 | int xx = m_miniEdge; |
ac57418f RR |
400 | int yy = m_miniEdge + m_miniTitle; |
401 | int ww = m_width - 2*m_miniEdge; | |
402 | int hh = wxMENU_HEIGHT; | |
b2b3ccc5 RR |
403 | m_frameMenuBar->m_x = xx; |
404 | m_frameMenuBar->m_y = yy; | |
405 | m_frameMenuBar->m_width = ww; | |
406 | m_frameMenuBar->m_height = hh; | |
8bbe427f | 407 | |
b2b3ccc5 RR |
408 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, xx, yy ); |
409 | gtk_widget_set_usize( m_frameMenuBar->m_widget, ww, hh ); | |
f5368809 | 410 | } |
e27ce4e9 | 411 | |
f5368809 RR |
412 | if (m_frameToolBar) |
413 | { | |
907789a0 | 414 | int xx = m_miniEdge; |
ac57418f | 415 | int yy = m_miniEdge + m_miniTitle; |
e27ce4e9 | 416 | if ((m_frameMenuBar) || (m_mdiMenuBar)) yy += wxMENU_HEIGHT; |
ac57418f | 417 | int ww = m_width - 2*m_miniEdge; |
b2b3ccc5 | 418 | int hh = m_frameToolBar->m_height; |
8bbe427f VZ |
419 | |
420 | m_frameToolBar->m_x = xx; | |
b2b3ccc5 RR |
421 | m_frameToolBar->m_y = yy; |
422 | m_frameToolBar->m_height = hh; | |
423 | m_frameToolBar->m_width = ww; | |
8bbe427f | 424 | |
b2b3ccc5 RR |
425 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, xx, yy ); |
426 | gtk_widget_set_usize( m_frameToolBar->m_widget, ww, hh ); | |
f5368809 | 427 | } |
8bbe427f | 428 | |
f5368809 RR |
429 | if (m_frameStatusBar) |
430 | { | |
b2b3ccc5 | 431 | int xx = 0 + m_miniEdge; |
ac57418f RR |
432 | int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge; |
433 | int ww = m_width - 2*m_miniEdge; | |
434 | int hh = wxSTATUS_HEIGHT; | |
8bbe427f | 435 | |
b2b3ccc5 RR |
436 | m_frameStatusBar->m_x = xx; |
437 | m_frameStatusBar->m_y = yy; | |
438 | m_frameStatusBar->m_width = ww; | |
439 | m_frameStatusBar->m_height = hh; | |
8bbe427f | 440 | |
b2b3ccc5 RR |
441 | gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, xx, yy ); |
442 | gtk_widget_set_usize( m_frameStatusBar->m_widget, ww, hh ); | |
f5368809 | 443 | } |
8bbe427f | 444 | |
de8113d9 RR |
445 | /* we actually set the size of a frame here and no-where else */ |
446 | gtk_widget_set_usize( m_widget, m_width, m_height ); | |
447 | ||
f5368809 | 448 | m_sizeSet = TRUE; |
8bbe427f | 449 | |
884470b1 | 450 | /* send size event to frame */ |
43a18898 RR |
451 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); |
452 | event.SetEventObject( this ); | |
e52f60e6 | 453 | GetEventHandler()->ProcessEvent( event ); |
8bbe427f | 454 | |
884470b1 | 455 | /* send size event to status bar */ |
5aa5e35a RR |
456 | if (m_frameStatusBar) |
457 | { | |
458 | wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() ); | |
459 | event2.SetEventObject( m_frameStatusBar ); | |
460 | m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 ); | |
461 | } | |
884470b1 | 462 | |
e52f60e6 RR |
463 | m_resizing = FALSE; |
464 | } | |
465 | ||
9390a202 | 466 | void wxFrame::OnInternalIdle() |
e52f60e6 RR |
467 | { |
468 | if (!m_sizeSet) | |
469 | GtkOnSize( m_x, m_y, m_width, m_height ); | |
8bbe427f | 470 | |
e52f60e6 | 471 | DoMenuUpdates(); |
362c6693 | 472 | } |
c801d85f | 473 | |
fe4e9e6c VZ |
474 | void wxFrame::OnCloseWindow( wxCloseEvent& event ) |
475 | { | |
476 | // close the window if it wasn't vetoed by the application | |
e3065973 JS |
477 | // if ( !event.GetVeto() ) // No, this isn't the interpretation of GetVeto. |
478 | Destroy(); | |
fe4e9e6c VZ |
479 | } |
480 | ||
c801d85f KB |
481 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) |
482 | { | |
f5368809 | 483 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 484 | |
f5368809 RR |
485 | if (GetAutoLayout()) |
486 | { | |
487 | Layout(); | |
488 | } | |
8bbe427f | 489 | else |
c801d85f | 490 | { |
de8113d9 | 491 | /* no child: go out ! */ |
db1b4961 | 492 | if (!GetChildren().First()) return; |
8bbe427f | 493 | |
de8113d9 | 494 | /* do we have exactly one child? */ |
f5368809 | 495 | wxWindow *child = (wxWindow *) NULL; |
db1b4961 | 496 | for(wxNode *node = GetChildren().First(); node; node = node->Next()) |
f5368809 RR |
497 | { |
498 | wxWindow *win = (wxWindow *)node->Data(); | |
de135918 | 499 | if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog) |
6ca41e57 | 500 | #if 0 // not in m_children anyway ? |
f5368809 RR |
501 | && (win != m_frameMenuBar) && |
502 | (win != m_frameToolBar) && | |
503 | (win != m_frameStatusBar) | |
ed7a557b | 504 | #endif |
f5368809 RR |
505 | ) |
506 | { | |
de8113d9 | 507 | /* it's the second one: do nothing */ |
f5368809 RR |
508 | if (child) return; |
509 | child = win; | |
510 | } | |
511 | } | |
ed7a557b | 512 | |
de8113d9 | 513 | /* yes: set it's size to fill all the frame */ |
f5368809 RR |
514 | int client_x, client_y; |
515 | GetClientSize( &client_x, &client_y ); | |
7be4c594 | 516 | child->SetSize( 1, 1, client_x-2, client_y-2 ); |
362c6693 | 517 | } |
362c6693 | 518 | } |
c801d85f | 519 | |
716b7364 | 520 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) |
c801d85f | 521 | { |
f5368809 RR |
522 | menu->SetInvokingWindow( win ); |
523 | wxNode *node = menu->m_items.First(); | |
524 | while (node) | |
525 | { | |
526 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
527 | if (menuitem->IsSubMenu()) | |
528 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
529 | node = node->Next(); | |
530 | } | |
362c6693 | 531 | } |
c801d85f KB |
532 | |
533 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
534 | { | |
f5368809 RR |
535 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
536 | wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" ); | |
8bbe427f | 537 | |
f5368809 | 538 | m_frameMenuBar = menuBar; |
8bbe427f | 539 | |
f5368809 | 540 | if (m_frameMenuBar) |
30dea054 | 541 | { |
f5368809 RR |
542 | wxNode *node = m_frameMenuBar->m_menus.First(); |
543 | while (node) | |
544 | { | |
545 | wxMenu *menu = (wxMenu*)node->Data(); | |
546 | SetInvokingWindow( menu, this ); | |
547 | node = node->Next(); | |
548 | } | |
8bbe427f | 549 | |
f5368809 RR |
550 | if (m_frameMenuBar->m_parent != this) |
551 | { | |
552 | m_frameMenuBar->m_parent = this; | |
553 | gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), | |
554 | m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y ); | |
e27ce4e9 RR |
555 | |
556 | /* an mdi child menu bar might be underneath */ | |
557 | if (m_mdiMenuBar) m_frameMenuBar->Show( FALSE ); | |
f5368809 | 558 | } |
716b7364 | 559 | } |
8bbe427f | 560 | |
5b077d48 | 561 | m_sizeSet = FALSE; |
362c6693 | 562 | } |
c801d85f | 563 | |
8bbe427f | 564 | wxMenuBar *wxFrame::GetMenuBar() const |
46dc76ba | 565 | { |
f5368809 | 566 | return m_frameMenuBar; |
362c6693 | 567 | } |
46dc76ba | 568 | |
342b6a2f RR |
569 | void wxFrame::OnMenuHighlight(wxMenuEvent& event) |
570 | { | |
571 | if (GetStatusBar()) | |
572 | { | |
573 | if (event.GetMenuId() == -1) | |
574 | { | |
575 | SetStatusText(""); | |
576 | } | |
577 | else | |
578 | { | |
579 | wxMenuBar *menuBar = GetMenuBar(); | |
580 | if (menuBar) | |
581 | { | |
582 | int menuId = event.GetMenuId(); | |
583 | wxString helpString; | |
584 | helpString = menuBar->GetHelpString(menuId); | |
585 | if (helpString != "") | |
586 | SetStatusText(helpString); | |
587 | } | |
588 | } | |
589 | } | |
590 | } | |
591 | ||
362c6693 | 592 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
46dc76ba | 593 | { |
f5368809 | 594 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 595 | |
f5368809 | 596 | wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" ); |
362c6693 | 597 | |
f5368809 | 598 | m_frameToolBar = OnCreateToolBar( style, id, name ); |
8bbe427f | 599 | |
db1b4961 | 600 | GetChildren().DeleteObject( m_frameToolBar ); |
8bbe427f | 601 | |
5b077d48 | 602 | m_sizeSet = FALSE; |
8bbe427f | 603 | |
f5368809 | 604 | return m_frameToolBar; |
362c6693 | 605 | } |
46dc76ba | 606 | |
362c6693 | 607 | wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name ) |
46dc76ba | 608 | { |
f5368809 | 609 | return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); |
362c6693 RR |
610 | } |
611 | ||
8bbe427f VZ |
612 | wxToolBar *wxFrame::GetToolBar() const |
613 | { | |
614 | return m_frameToolBar; | |
362c6693 | 615 | } |
46dc76ba | 616 | |
e3e65dac | 617 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) |
c801d85f | 618 | { |
f5368809 | 619 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 620 | |
f5368809 | 621 | wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, "recreating status bar in wxFrame" ); |
c801d85f | 622 | |
f5368809 | 623 | m_frameStatusBar = OnCreateStatusBar( number, style, id, name ); |
8bbe427f | 624 | |
5b077d48 | 625 | m_sizeSet = FALSE; |
8bbe427f | 626 | |
f5368809 | 627 | return m_frameStatusBar; |
362c6693 RR |
628 | } |
629 | ||
630 | wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
631 | { | |
f5368809 | 632 | wxStatusBar *statusBar = (wxStatusBar *) NULL; |
8bbe427f | 633 | |
f5368809 | 634 | statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name); |
8bbe427f | 635 | |
f5368809 RR |
636 | // Set the height according to the font and the border size |
637 | wxClientDC dc(statusBar); | |
8bbe427f | 638 | dc.SetFont( statusBar->GetFont() ); |
362c6693 | 639 | |
f5368809 RR |
640 | long x, y; |
641 | dc.GetTextExtent( "X", &x, &y ); | |
362c6693 | 642 | |
f5368809 | 643 | int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY()); |
362c6693 | 644 | |
f5368809 | 645 | statusBar->SetSize( -1, -1, 100, height ); |
362c6693 | 646 | |
f5368809 RR |
647 | statusBar->SetFieldsCount( number ); |
648 | return statusBar; | |
362c6693 | 649 | } |
c801d85f | 650 | |
362c6693 | 651 | void wxFrame::SetStatusText(const wxString& text, int number) |
c801d85f | 652 | { |
f5368809 | 653 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 654 | |
f5368809 | 655 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" ); |
c801d85f | 656 | |
f5368809 | 657 | m_frameStatusBar->SetStatusText(text, number); |
362c6693 RR |
658 | } |
659 | ||
660 | void wxFrame::SetStatusWidths(int n, const int widths_field[] ) | |
c801d85f | 661 | { |
f5368809 | 662 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 663 | |
f5368809 | 664 | wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" ); |
362c6693 | 665 | |
f5368809 | 666 | m_frameStatusBar->SetStatusWidths(n, widths_field); |
362c6693 | 667 | } |
c801d85f | 668 | |
8bbe427f | 669 | wxStatusBar *wxFrame::GetStatusBar() const |
c801d85f | 670 | { |
f5368809 | 671 | return m_frameStatusBar; |
362c6693 | 672 | } |
c801d85f | 673 | |
c801d85f KB |
674 | void wxFrame::SetTitle( const wxString &title ) |
675 | { | |
f5368809 | 676 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 677 | |
f5368809 RR |
678 | m_title = title; |
679 | if (m_title.IsNull()) m_title = ""; | |
680 | gtk_window_set_title( GTK_WINDOW(m_widget), title ); | |
362c6693 | 681 | } |
c801d85f | 682 | |
d355d3fe RR |
683 | void wxFrame::SetIcon( const wxIcon &icon ) |
684 | { | |
f5368809 | 685 | wxASSERT_MSG( (m_widget != NULL), "invalid frame" ); |
8bbe427f | 686 | |
f5368809 RR |
687 | m_icon = icon; |
688 | if (!icon.Ok()) return; | |
8bbe427f | 689 | |
f5368809 RR |
690 | wxMask *mask = icon.GetMask(); |
691 | GdkBitmap *bm = (GdkBitmap *) NULL; | |
692 | if (mask) bm = mask->GetBitmap(); | |
8bbe427f | 693 | |
f5368809 | 694 | gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm ); |
d355d3fe | 695 | } |
b2b3ccc5 | 696 |