]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/frame.cpp
warnings suppressed
[wxWidgets.git] / src / gtk / frame.cpp
CommitLineData
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 32const int wxMENU_HEIGHT = 27;
c67daf87 33const int wxSTATUS_HEIGHT = 25;
c801d85f 34
2f2aa628
RR
35//-----------------------------------------------------------------------------
36// data
37//-----------------------------------------------------------------------------
38
c801d85f
KB
39extern wxList wxTopLevelWindows;
40extern wxList wxPendingDelete;
41
42//-----------------------------------------------------------------------------
2f2aa628 43// "size_allocate"
c801d85f 44//-----------------------------------------------------------------------------
c801d85f 45
2f2aa628 46static 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 69static 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 87static 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
105BEGIN_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
109END_EVENT_TABLE()
110
111IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow)
112
19717c50 113wxFrame::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 124wxFrame::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 138bool 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 184wxFrame::~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 208bool 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 225bool 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
234wxPoint 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
bfc6fde4 252void wxFrame::DoSetSize( 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
315void wxFrame::Centre( int direction )
316{
fb1585ae 317 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 318
43a18898
RR
319 int x = 0;
320 int y = 0;
8bbe427f 321
f5eafd0e
RR
322 if ((direction & wxHORIZONTAL) == wxHORIZONTAL) x = (gdk_screen_width () - m_width) / 2;
323 if ((direction & wxVERTICAL) == wxVERTICAL) y = (gdk_screen_height () - m_height) / 2;
8bbe427f 324
fb1585ae 325 Move( x, y );
903f689b
RR
326}
327
c801d85f
KB
328void wxFrame::GetClientSize( int *width, int *height ) const
329{
fb1585ae 330 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 331
fb1585ae
RR
332 wxWindow::GetClientSize( width, height );
333 if (height)
46dc76ba 334 {
fb1585ae
RR
335 if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT;
336 if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT;
337 if (m_frameToolBar)
338 {
339 int y = 0;
340 m_frameToolBar->GetSize( (int *) NULL, &y );
341 (*height) -= y;
342 }
b2b3ccc5
RR
343 (*height) -= m_miniEdge*2 + m_miniTitle;
344 }
345 if (width)
346 {
347 (*width) -= m_miniEdge*2;
46dc76ba 348 }
362c6693 349}
c801d85f 350
bfc6fde4 351void wxFrame::DoSetClientSize( int width, int height )
b593568e 352{
f5368809 353 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 354
f5368809
RR
355 int h = height;
356 if (m_frameMenuBar) h += wxMENU_HEIGHT;
357 if (m_frameStatusBar) h += wxSTATUS_HEIGHT;
358 if (m_frameToolBar)
359 {
360 int y = 0;
361 m_frameToolBar->GetSize( (int *) NULL, &y );
362 h += y;
363 }
f76f940b 364 wxWindow::DoSetClientSize( width + m_miniEdge*2, h + m_miniEdge*2 + m_miniTitle );
362c6693 365}
b593568e 366
47908e25 367void wxFrame::GtkOnSize( int WXUNUSED(x), int WXUNUSED(y), int width, int height )
c801d85f 368{
f5368809
RR
369 // due to a bug in gtk, x,y are always 0
370 // m_x = x;
371 // m_y = y;
372
e52f60e6
RR
373 if (m_resizing) return;
374 m_resizing = TRUE;
8bbe427f 375
f5368809 376 if (!m_wxwindow) return;
8bbe427f 377
f5368809
RR
378 m_width = width;
379 m_height = height;
8bbe427f 380
de8113d9 381 /* check if size is in legal range */
f5368809
RR
382 if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
383 if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
0c77152e
RR
384 if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth;
385 if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight;
f5368809 386
de8113d9
RR
387 /* this emulates the new wxMSW behaviour of placing all
388 * frame-subwindows (menu, toolbar..) on one native window
389 * this hurts in the eye, but I don't want to call SetSize()
390 * because I don't want to call any non-native functions here. */
8bbe427f 391
f5368809
RR
392 if (m_frameMenuBar)
393 {
907789a0 394 int xx = m_miniEdge;
ac57418f
RR
395 int yy = m_miniEdge + m_miniTitle;
396 int ww = m_width - 2*m_miniEdge;
397 int hh = wxMENU_HEIGHT;
b2b3ccc5
RR
398 m_frameMenuBar->m_x = xx;
399 m_frameMenuBar->m_y = yy;
400 m_frameMenuBar->m_width = ww;
401 m_frameMenuBar->m_height = hh;
8bbe427f 402
b2b3ccc5
RR
403 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameMenuBar->m_widget, xx, yy );
404 gtk_widget_set_usize( m_frameMenuBar->m_widget, ww, hh );
f5368809 405 }
e27ce4e9 406
f5368809
RR
407 if (m_frameToolBar)
408 {
907789a0 409 int xx = m_miniEdge;
ac57418f 410 int yy = m_miniEdge + m_miniTitle;
e27ce4e9 411 if ((m_frameMenuBar) || (m_mdiMenuBar)) yy += wxMENU_HEIGHT;
ac57418f 412 int ww = m_width - 2*m_miniEdge;
b2b3ccc5 413 int hh = m_frameToolBar->m_height;
8bbe427f
VZ
414
415 m_frameToolBar->m_x = xx;
b2b3ccc5
RR
416 m_frameToolBar->m_y = yy;
417 m_frameToolBar->m_height = hh;
418 m_frameToolBar->m_width = ww;
8bbe427f 419
b2b3ccc5
RR
420 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameToolBar->m_widget, xx, yy );
421 gtk_widget_set_usize( m_frameToolBar->m_widget, ww, hh );
f5368809 422 }
8bbe427f 423
f5368809
RR
424 if (m_frameStatusBar)
425 {
b2b3ccc5 426 int xx = 0 + m_miniEdge;
ac57418f
RR
427 int yy = m_height - wxSTATUS_HEIGHT - m_miniEdge;
428 int ww = m_width - 2*m_miniEdge;
429 int hh = wxSTATUS_HEIGHT;
8bbe427f 430
b2b3ccc5
RR
431 m_frameStatusBar->m_x = xx;
432 m_frameStatusBar->m_y = yy;
433 m_frameStatusBar->m_width = ww;
434 m_frameStatusBar->m_height = hh;
8bbe427f 435
b2b3ccc5
RR
436 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow), m_frameStatusBar->m_widget, xx, yy );
437 gtk_widget_set_usize( m_frameStatusBar->m_widget, ww, hh );
f5368809 438 }
8bbe427f 439
de8113d9
RR
440 /* we actually set the size of a frame here and no-where else */
441 gtk_widget_set_usize( m_widget, m_width, m_height );
442
f5368809 443 m_sizeSet = TRUE;
8bbe427f 444
884470b1 445 /* send size event to frame */
43a18898
RR
446 wxSizeEvent event( wxSize(m_width,m_height), GetId() );
447 event.SetEventObject( this );
e52f60e6 448 GetEventHandler()->ProcessEvent( event );
8bbe427f 449
884470b1 450 /* send size event to status bar */
5aa5e35a
RR
451 if (m_frameStatusBar)
452 {
453 wxSizeEvent event2( wxSize(m_frameStatusBar->m_width,m_frameStatusBar->m_height), m_frameStatusBar->GetId() );
454 event2.SetEventObject( m_frameStatusBar );
455 m_frameStatusBar->GetEventHandler()->ProcessEvent( event2 );
456 }
884470b1 457
e52f60e6
RR
458 m_resizing = FALSE;
459}
460
9390a202 461void wxFrame::OnInternalIdle()
e52f60e6
RR
462{
463 if (!m_sizeSet)
464 GtkOnSize( m_x, m_y, m_width, m_height );
8bbe427f 465
e52f60e6 466 DoMenuUpdates();
362c6693 467}
c801d85f 468
fe4e9e6c
VZ
469void wxFrame::OnCloseWindow( wxCloseEvent& event )
470{
471 // close the window if it wasn't vetoed by the application
e3065973
JS
472// if ( !event.GetVeto() ) // No, this isn't the interpretation of GetVeto.
473 Destroy();
fe4e9e6c
VZ
474}
475
c801d85f
KB
476void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) )
477{
f5368809 478 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 479
f5368809
RR
480 if (GetAutoLayout())
481 {
482 Layout();
483 }
8bbe427f 484 else
c801d85f 485 {
de8113d9 486 /* no child: go out ! */
db1b4961 487 if (!GetChildren().First()) return;
8bbe427f 488
de8113d9 489 /* do we have exactly one child? */
f5368809 490 wxWindow *child = (wxWindow *) NULL;
db1b4961 491 for(wxNode *node = GetChildren().First(); node; node = node->Next())
f5368809
RR
492 {
493 wxWindow *win = (wxWindow *)node->Data();
de135918 494 if (!wxIS_KIND_OF(win,wxFrame) && !wxIS_KIND_OF(win,wxDialog)
6ca41e57 495#if 0 // not in m_children anyway ?
f5368809
RR
496 && (win != m_frameMenuBar) &&
497 (win != m_frameToolBar) &&
498 (win != m_frameStatusBar)
ed7a557b 499#endif
f5368809
RR
500 )
501 {
de8113d9 502 /* it's the second one: do nothing */
f5368809
RR
503 if (child) return;
504 child = win;
505 }
506 }
ed7a557b 507
de8113d9 508 /* yes: set it's size to fill all the frame */
f5368809
RR
509 int client_x, client_y;
510 GetClientSize( &client_x, &client_y );
7be4c594 511 child->SetSize( 1, 1, client_x-2, client_y-2 );
362c6693 512 }
362c6693 513}
c801d85f 514
716b7364 515static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
c801d85f 516{
f5368809
RR
517 menu->SetInvokingWindow( win );
518 wxNode *node = menu->m_items.First();
519 while (node)
520 {
521 wxMenuItem *menuitem = (wxMenuItem*)node->Data();
522 if (menuitem->IsSubMenu())
523 SetInvokingWindow( menuitem->GetSubMenu(), win );
524 node = node->Next();
525 }
362c6693 526}
c801d85f
KB
527
528void wxFrame::SetMenuBar( wxMenuBar *menuBar )
529{
f5368809
RR
530 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
531 wxASSERT_MSG( (m_wxwindow != NULL), "invalid frame" );
8bbe427f 532
f5368809 533 m_frameMenuBar = menuBar;
8bbe427f 534
f5368809 535 if (m_frameMenuBar)
30dea054 536 {
f5368809
RR
537 wxNode *node = m_frameMenuBar->m_menus.First();
538 while (node)
539 {
540 wxMenu *menu = (wxMenu*)node->Data();
541 SetInvokingWindow( menu, this );
542 node = node->Next();
543 }
8bbe427f 544
f5368809
RR
545 if (m_frameMenuBar->m_parent != this)
546 {
547 m_frameMenuBar->m_parent = this;
548 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow),
549 m_frameMenuBar->m_widget, m_frameMenuBar->m_x, m_frameMenuBar->m_y );
e27ce4e9
RR
550
551 /* an mdi child menu bar might be underneath */
552 if (m_mdiMenuBar) m_frameMenuBar->Show( FALSE );
f5368809 553 }
716b7364 554 }
8bbe427f 555
5b077d48 556 m_sizeSet = FALSE;
362c6693 557}
c801d85f 558
8bbe427f 559wxMenuBar *wxFrame::GetMenuBar() const
46dc76ba 560{
f5368809 561 return m_frameMenuBar;
362c6693 562}
46dc76ba 563
342b6a2f
RR
564void wxFrame::OnMenuHighlight(wxMenuEvent& event)
565{
566 if (GetStatusBar())
567 {
568 if (event.GetMenuId() == -1)
569 {
570 SetStatusText("");
571 }
572 else
573 {
574 wxMenuBar *menuBar = GetMenuBar();
575 if (menuBar)
576 {
577 int menuId = event.GetMenuId();
578 wxString helpString;
579 helpString = menuBar->GetHelpString(menuId);
580 if (helpString != "")
581 SetStatusText(helpString);
582 }
583 }
584 }
585}
586
362c6693 587wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
46dc76ba 588{
f5368809 589 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 590
f5368809 591 wxCHECK_MSG( m_frameToolBar == NULL, FALSE, "recreating toolbar in wxFrame" );
362c6693 592
f5368809 593 m_frameToolBar = OnCreateToolBar( style, id, name );
8bbe427f 594
db1b4961 595 GetChildren().DeleteObject( m_frameToolBar );
8bbe427f 596
5b077d48 597 m_sizeSet = FALSE;
8bbe427f 598
f5368809 599 return m_frameToolBar;
362c6693 600}
46dc76ba 601
362c6693 602wxToolBar* wxFrame::OnCreateToolBar( long style, wxWindowID id, const wxString& name )
46dc76ba 603{
f5368809 604 return new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name );
362c6693
RR
605}
606
8bbe427f
VZ
607wxToolBar *wxFrame::GetToolBar() const
608{
609 return m_frameToolBar;
362c6693 610}
46dc76ba 611
e3e65dac 612wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
c801d85f 613{
f5368809 614 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 615
f5368809 616 wxCHECK_MSG( m_frameStatusBar == NULL, FALSE, "recreating status bar in wxFrame" );
c801d85f 617
f5368809 618 m_frameStatusBar = OnCreateStatusBar( number, style, id, name );
8bbe427f 619
5b077d48 620 m_sizeSet = FALSE;
8bbe427f 621
f5368809 622 return m_frameStatusBar;
362c6693
RR
623}
624
625wxStatusBar *wxFrame::OnCreateStatusBar( int number, long style, wxWindowID id, const wxString& name )
626{
f5368809 627 wxStatusBar *statusBar = (wxStatusBar *) NULL;
8bbe427f 628
f5368809 629 statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20), style, name);
8bbe427f 630
f5368809
RR
631 // Set the height according to the font and the border size
632 wxClientDC dc(statusBar);
8bbe427f 633 dc.SetFont( statusBar->GetFont() );
362c6693 634
f5368809
RR
635 long x, y;
636 dc.GetTextExtent( "X", &x, &y );
362c6693 637
f5368809 638 int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
362c6693 639
f5368809 640 statusBar->SetSize( -1, -1, 100, height );
362c6693 641
f5368809
RR
642 statusBar->SetFieldsCount( number );
643 return statusBar;
362c6693 644}
c801d85f 645
362c6693 646void wxFrame::SetStatusText(const wxString& text, int number)
c801d85f 647{
f5368809 648 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 649
f5368809 650 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" );
c801d85f 651
f5368809 652 m_frameStatusBar->SetStatusText(text, number);
362c6693
RR
653}
654
655void wxFrame::SetStatusWidths(int n, const int widths_field[] )
c801d85f 656{
f5368809 657 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 658
f5368809 659 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" );
362c6693 660
f5368809 661 m_frameStatusBar->SetStatusWidths(n, widths_field);
362c6693 662}
c801d85f 663
8bbe427f 664wxStatusBar *wxFrame::GetStatusBar() const
c801d85f 665{
f5368809 666 return m_frameStatusBar;
362c6693 667}
c801d85f 668
c801d85f
KB
669void wxFrame::SetTitle( const wxString &title )
670{
f5368809 671 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 672
f5368809
RR
673 m_title = title;
674 if (m_title.IsNull()) m_title = "";
675 gtk_window_set_title( GTK_WINDOW(m_widget), title );
362c6693 676}
c801d85f 677
d355d3fe
RR
678void wxFrame::SetIcon( const wxIcon &icon )
679{
f5368809 680 wxASSERT_MSG( (m_widget != NULL), "invalid frame" );
8bbe427f 681
f5368809
RR
682 m_icon = icon;
683 if (!icon.Ok()) return;
8bbe427f 684
f5368809
RR
685 wxMask *mask = icon.GetMask();
686 GdkBitmap *bm = (GdkBitmap *) NULL;
687 if (mask) bm = mask->GetBitmap();
8bbe427f 688
f5368809 689 gdk_window_set_icon( m_widget->window, (GdkWindow *) NULL, icon.GetPixmap(), bm );
d355d3fe 690}
b2b3ccc5 691