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