1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "frame.h"
15 #include "wx/dialog.h"
16 #include "wx/control.h"
19 #include "wx/toolbar.h"
20 #include "wx/statusbr.h"
21 #include "wx/dcclient.h"
26 #include "wx/gtk/win_gtk.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 const int wxMENU_HEIGHT
= 27;
33 const int wxSTATUS_HEIGHT
= 25;
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern wxList wxPendingDelete
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
45 static void gtk_frame_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxFrame
*win
)
47 if (!win
->HasVMT()) return;
50 printf( "OnFrameResize from " );
51 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
52 printf( win->GetClassInfo()->GetClassName() );
56 if ((win
->m_width
!= alloc
->width
) || (win
->m_height
!= alloc
->height
))
58 win
->m_sizeSet
= FALSE
;
59 win
->m_width
= alloc
->width
;
60 win
->m_height
= alloc
->height
;
64 //-----------------------------------------------------------------------------
66 //-----------------------------------------------------------------------------
68 static gint
gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxFrame
*win
)
71 printf( "OnDelete from " );
72 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
73 printf( win->GetClassInfo()->GetClassName() );
82 //-----------------------------------------------------------------------------
83 // "child_attached" of menu bar
84 //-----------------------------------------------------------------------------
86 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
88 if (!win
->HasVMT()) return;
90 win
->m_menuBarDetached
= FALSE
;
91 win
->m_sizeSet
= FALSE
;
94 //-----------------------------------------------------------------------------
95 // "child_detached" of menu bar
96 //-----------------------------------------------------------------------------
98 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
100 if (!win
->HasVMT()) return;
102 win
->m_menuBarDetached
= TRUE
;
103 win
->m_sizeSet
= FALSE
;
106 //-----------------------------------------------------------------------------
107 // "child_attached" of tool bar
108 //-----------------------------------------------------------------------------
110 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
112 if (!win
->HasVMT()) return;
114 win
->m_toolBarDetached
= FALSE
;
115 win
->m_sizeSet
= FALSE
;
118 //-----------------------------------------------------------------------------
119 // "child_detached" of tool bar
120 //-----------------------------------------------------------------------------
122 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
124 if (!win
->HasVMT()) return;
126 win
->m_toolBarDetached
= TRUE
;
127 win
->m_sizeSet
= FALSE
;
130 //-----------------------------------------------------------------------------
132 //-----------------------------------------------------------------------------
134 static gint
gtk_frame_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*event
, wxFrame
*win
)
136 if (!win
->HasVMT()) return FALSE
;
141 wxMoveEvent
mevent( wxPoint(win
->m_x
,win
->m_y
), win
->GetId() );
142 mevent
.SetEventObject( win
);
143 win
->GetEventHandler()->ProcessEvent( mevent
);
148 //-----------------------------------------------------------------------------
149 // InsertChild for wxFrame
150 //-----------------------------------------------------------------------------
152 /* Callback for wxFrame. This very strange beast has to be used because
153 * C++ has no virtual methods in a constructor. We have to emulate a
154 * virtual function here as wxWindows requires different ways to insert
155 * a child in container classes. */
157 static void wxInsertChildInFrame( wxWindow
* parent
, wxWindow
* child
)
159 if (wxIS_KIND_OF(child
,wxToolBar
) || wxIS_KIND_OF(child
,wxMenuBar
))
161 /* actually, menubars are never inserted here, but this
162 may change one day */
164 /* these are outside the client area */
165 wxFrame
* frame
= (wxFrame
*) parent
;
166 gtk_myfixed_put( GTK_MYFIXED(frame
->m_mainWidget
),
167 GTK_WIDGET(child
->m_widget
),
173 /* these are inside the client area */
174 gtk_myfixed_put( GTK_MYFIXED(parent
->m_wxwindow
),
175 GTK_WIDGET(child
->m_widget
),
180 gtk_widget_set_usize( GTK_WIDGET(child
->m_widget
),
184 /* resize on OnInternalIdle */
185 parent
->m_sizeSet
= FALSE
;
187 if (parent
->m_windowStyle
& wxTAB_TRAVERSAL
)
189 /* we now allow a window to get the focus as long as it
190 doesn't have any children. */
191 GTK_WIDGET_UNSET_FLAGS( parent
->m_wxwindow
, GTK_CAN_FOCUS
);
195 //-----------------------------------------------------------------------------
197 //-----------------------------------------------------------------------------
199 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
200 EVT_SIZE(wxFrame::OnSize
)
201 EVT_CLOSE(wxFrame::OnCloseWindow
)
202 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight
)
205 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
209 m_frameMenuBar
= (wxMenuBar
*) NULL
;
210 m_frameStatusBar
= (wxStatusBar
*) NULL
;
211 m_frameToolBar
= (wxToolBar
*) NULL
;
215 m_mainWidget
= (GtkWidget
*) NULL
;
216 m_menuBarDetached
= FALSE
;
217 m_toolBarDetached
= FALSE
;
220 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
221 const wxPoint
&pos
, const wxSize
&size
,
222 long style
, const wxString
&name
)
224 m_frameMenuBar
= (wxMenuBar
*) NULL
;
225 m_frameStatusBar
= (wxStatusBar
*) NULL
;
226 m_frameToolBar
= (wxToolBar
*) NULL
;
230 m_mainWidget
= (GtkWidget
*) NULL
;
231 m_menuBarDetached
= FALSE
;
232 m_toolBarDetached
= FALSE
;
233 Create( parent
, id
, title
, pos
, size
, style
, name
);
236 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
237 const wxPoint
&pos
, const wxSize
&size
,
238 long style
, const wxString
&name
)
240 wxTopLevelWindows
.Append( this );
242 m_needParent
= FALSE
;
244 PreCreation( parent
, id
, pos
, size
, style
, name
);
248 m_insertCallback
= wxInsertChildInFrame
;
250 GtkWindowType win_type
= GTK_WINDOW_TOPLEVEL
;
251 if (style
& wxSIMPLE_BORDER
) win_type
= GTK_WINDOW_POPUP
;
253 m_widget
= gtk_window_new( win_type
);
255 gtk_window_set_title( GTK_WINDOW(m_widget
), title
.mbc_str() );
256 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
259 gtk_window_set_policy( GTK_WINDOW(m_widget
), 1, 1, 0 );
261 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
262 GTK_SIGNAL_FUNC(gtk_frame_delete_callback
), (gpointer
)this );
264 /* m_mainWidget holds the toolbar, the menubar and the client area */
265 m_mainWidget
= gtk_myfixed_new();
266 gtk_widget_show( m_mainWidget
);
267 GTK_WIDGET_UNSET_FLAGS( m_mainWidget
, GTK_CAN_FOCUS
);
268 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWidget
);
269 gtk_widget_realize( m_mainWidget
);
271 /* m_wxwindow only represents the client area without toolbar and menubar */
272 m_wxwindow
= gtk_myfixed_new();
273 gtk_widget_show( m_wxwindow
);
274 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
275 gtk_container_add( GTK_CONTAINER(m_mainWidget
), m_wxwindow
);
277 if (m_parent
) m_parent
->AddChild( this );
281 gtk_widget_realize( m_widget
);
283 /* all this is for Motif Window Manager "hints" and is supposed to be
284 recognized by other WM as well. not tested. */
285 long decor
= (long) GDK_DECOR_ALL
;
286 long func
= (long) GDK_FUNC_ALL
;
288 if ((m_windowStyle
& wxCAPTION
) == 0)
289 decor
|= GDK_DECOR_TITLE
;
290 /* if ((m_windowStyle & wxMINIMIZE) == 0)
291 func |= GDK_FUNC_MINIMIZE;
292 if ((m_windowStyle & wxMAXIMIZE) == 0)
293 func |= GDK_FUNC_MAXIMIZE; */
294 if ((m_windowStyle
& wxSYSTEM_MENU
) == 0)
295 decor
|= GDK_DECOR_MENU
;
296 if ((m_windowStyle
& wxMINIMIZE_BOX
) == 0)
297 decor
|= GDK_DECOR_MINIMIZE
;
298 if ((m_windowStyle
& wxMAXIMIZE_BOX
) == 0)
299 decor
|= GDK_DECOR_MAXIMIZE
;
300 if ((m_windowStyle
& wxRESIZE_BORDER
) == 0)
301 func
|= GDK_FUNC_RESIZE
;
303 gdk_window_set_decorations(m_widget
->window
, (GdkWMDecoration
)decor
);
304 gdk_window_set_functions(m_widget
->window
, (GdkWMFunction
)func
);
306 /* the user resized the frame by dragging etc. */
307 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
308 GTK_SIGNAL_FUNC(gtk_frame_size_callback
), (gpointer
)this );
310 /* the only way to get the window size is to connect to this event */
311 gtk_signal_connect( GTK_OBJECT(m_widget
), "configure_event",
312 GTK_SIGNAL_FUNC(gtk_frame_configure_callback
), (gpointer
)this );
319 if (m_frameMenuBar
) delete m_frameMenuBar
;
320 m_frameMenuBar
= (wxMenuBar
*) NULL
;
322 if (m_frameStatusBar
) delete m_frameStatusBar
;
323 m_frameStatusBar
= (wxStatusBar
*) NULL
;
325 if (m_frameToolBar
) delete m_frameToolBar
;
326 m_frameToolBar
= (wxToolBar
*) NULL
;
328 wxTopLevelWindows
.DeleteObject( this );
330 if (wxTheApp
->GetTopWindow() == this)
331 wxTheApp
->SetTopWindow( (wxWindow
*) NULL
);
333 if (wxTopLevelWindows
.Number() == 0)
334 wxTheApp
->ExitMainLoop();
337 bool wxFrame::Show( bool show
)
339 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
341 if (show
&& !m_sizeSet
)
343 /* by calling GtkOnSize here, we don't have to call
344 either after showing the frame, which would entail
345 much ugly flicker or from within the size_allocate
346 handler, because GTK 1.1.X forbids that. */
348 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
351 return wxWindow::Show( show
);
354 bool wxFrame::Destroy()
356 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
358 if (!wxPendingDelete
.Member(this)) wxPendingDelete
.Append(this);
363 void wxFrame::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
365 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
367 /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */
368 wxASSERT_MSG( (m_wxwindow
!= NULL
), _T("invalid frame") );
370 /* avoid recursions */
371 if (m_resizing
) return;
376 int old_width
= m_width
;
377 int old_height
= m_height
;
379 if ((sizeFlags
& wxSIZE_USE_EXISTING
) == wxSIZE_USE_EXISTING
)
381 if (x
!= -1) m_x
= x
;
382 if (y
!= -1) m_y
= y
;
383 if (width
!= -1) m_width
= width
;
384 if (height
!= -1) m_height
= height
;
394 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
396 if (width
== -1) m_width
= 80;
399 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
401 if (height
== -1) m_height
= 26;
404 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
405 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
406 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_maxWidth
;
407 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_maxHeight
;
409 if ((m_x
!= -1) || (m_y
!= -1))
411 if ((m_x
!= old_x
) || (m_y
!= old_y
))
413 /* m_sizeSet = FALSE; */
414 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
418 if ((m_width
!= old_width
) || (m_height
!= old_height
))
420 /* we set the size in GtkOnSize, i.e. mostly the actual resizing is
421 done either directly before the frame is shown or in idle time
422 so that different calls to SetSize() don't lead to flicker. */
429 void wxFrame::Centre( int direction
)
431 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
436 if ((direction
& wxHORIZONTAL
) == wxHORIZONTAL
) x
= (gdk_screen_width () - m_width
) / 2;
437 if ((direction
& wxVERTICAL
) == wxVERTICAL
) y
= (gdk_screen_height () - m_height
) / 2;
442 void wxFrame::GetClientSize( int *width
, int *height
) const
444 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
446 wxWindow::GetClientSize( width
, height
);
449 if (m_frameMenuBar
&& !m_menuBarDetached
) (*height
) -= wxMENU_HEIGHT
;
450 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
454 m_frameToolBar
->GetSize( (int *) NULL
, &y
);
457 (*height
) -= m_miniEdge
*2 + m_miniTitle
;
461 (*width
) -= m_miniEdge
*2;
465 void wxFrame::DoSetClientSize( int width
, int height
)
467 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
470 if (m_frameMenuBar
&& !m_menuBarDetached
) h
+= wxMENU_HEIGHT
;
471 if (m_frameStatusBar
) h
+= wxSTATUS_HEIGHT
;
475 m_frameToolBar
->GetSize( (int *) NULL
, &y
);
478 wxWindow::DoSetClientSize( width
+ m_miniEdge
*2, h
+ m_miniEdge
*2 + m_miniTitle
);
481 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
), int width
, int height
)
483 // due to a bug in gtk, x,y are always 0
487 /* avoid recursions */
488 if (m_resizing
) return;
491 /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */
492 wxASSERT_MSG( (m_wxwindow
!= NULL
), _T("invalid frame") );
497 /* space occupied by m_frameToolBar and m_frameMenuBar */
498 int client_area_y_offset
= 0;
500 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
501 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
502 set in wxFrame::Create so it is used to check what kind of frame we
503 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
504 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
505 importantly) m_mainWidget */
509 /* check if size is in legal range */
510 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
511 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
512 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_maxWidth
;
513 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_maxHeight
;
515 /* I revert back to wxGTK's original behaviour. m_mainWidget holds the
516 * menubar, the toolbar and the client area, which is represented by
518 * this hurts in the eye, but I don't want to call SetSize()
519 * because I don't want to call any non-native functions here. */
524 int yy
= m_miniEdge
+ m_miniTitle
;
525 int ww
= m_width
- 2*m_miniEdge
;
527 if (!m_menuBarDetached
) hh
= wxMENU_HEIGHT
;
528 m_frameMenuBar
->m_x
= xx
;
529 m_frameMenuBar
->m_y
= yy
;
530 m_frameMenuBar
->m_width
= ww
;
531 m_frameMenuBar
->m_height
= hh
;
533 gtk_myfixed_move( GTK_MYFIXED(m_mainWidget
), m_frameMenuBar
->m_widget
, xx
, yy
);
534 gtk_widget_set_usize( m_frameMenuBar
->m_widget
, ww
, hh
);
536 client_area_y_offset
+= hh
;
542 int yy
= m_miniEdge
+ m_miniTitle
;
543 if (m_frameMenuBar
&& !m_menuBarDetached
) yy
+= wxMENU_HEIGHT
;
544 int ww
= m_width
- 2*m_miniEdge
;
545 int hh
= m_frameToolBar
->m_height
;
547 m_frameToolBar
->m_x
= xx
;
548 m_frameToolBar
->m_y
= yy
;
549 m_frameToolBar
->m_height
= hh
;
550 m_frameToolBar
->m_width
= ww
;
552 gtk_myfixed_move( GTK_MYFIXED(m_mainWidget
), m_frameToolBar
->m_widget
, xx
, yy
);
553 gtk_widget_set_usize( m_frameToolBar
->m_widget
, ww
, hh
);
555 client_area_y_offset
+= hh
;
558 int client_x
= m_miniEdge
;
559 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
560 gtk_myfixed_move( GTK_MYFIXED(m_mainWidget
), m_wxwindow
, client_x
, client_y
);
562 int client_w
= m_width
- 2*m_miniEdge
;
563 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
564 gtk_widget_set_usize( m_wxwindow
, client_w
, client_h
);
568 /* if there is no m_mainWidget between m_widget and m_wxwindow there
569 is no need to set the size or position of m_wxwindow. */
572 if (m_frameStatusBar
)
574 int xx
= 0 + m_miniEdge
;
575 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
576 int ww
= m_width
- 2*m_miniEdge
;
577 int hh
= wxSTATUS_HEIGHT
;
579 m_frameStatusBar
->m_x
= xx
;
580 m_frameStatusBar
->m_y
= yy
;
581 m_frameStatusBar
->m_width
= ww
;
582 m_frameStatusBar
->m_height
= hh
;
584 gtk_myfixed_move( GTK_MYFIXED(m_wxwindow
), m_frameStatusBar
->m_widget
, xx
, yy
);
585 gtk_widget_set_usize( m_frameStatusBar
->m_widget
, ww
, hh
);
588 /* we actually set the size of a frame here and no-where else */
589 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
593 /* send size event to frame */
594 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
595 event
.SetEventObject( this );
596 GetEventHandler()->ProcessEvent( event
);
598 /* send size event to status bar */
599 if (m_frameStatusBar
)
601 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
602 event2
.SetEventObject( m_frameStatusBar
);
603 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
609 void wxFrame::OnInternalIdle()
612 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
617 void wxFrame::OnCloseWindow( wxCloseEvent
& event
)
622 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
624 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
632 // do we have exactly one child?
633 wxWindow
*child
= (wxWindow
*)NULL
;
634 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
636 wxWindow
*win
= (wxWindow
*)node
->Data();
637 if ( !wxIS_KIND_OF(win
,wxFrame
) && !wxIS_KIND_OF(win
,wxDialog
) )
641 // it's the second one: do nothing
649 // no children at all?
652 // yes: set it's size to fill all the frame
653 int client_x
, client_y
;
654 GetClientSize( &client_x
, &client_y
);
655 child
->SetSize( 1, 1, client_x
-2, client_y
-2 );
660 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
662 menu
->SetInvokingWindow( win
);
663 wxNode
*node
= menu
->GetItems().First();
666 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
667 if (menuitem
->IsSubMenu())
668 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
673 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
675 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
676 wxASSERT_MSG( (m_wxwindow
!= NULL
), _T("invalid frame") );
678 m_frameMenuBar
= menuBar
;
682 wxNode
*node
= m_frameMenuBar
->GetMenus().First();
685 wxMenu
*menu
= (wxMenu
*)node
->Data();
686 SetInvokingWindow( menu
, this );
690 if (m_frameMenuBar
->m_parent
!= this)
692 m_frameMenuBar
->m_parent
= this;
693 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
),
694 m_frameMenuBar
->m_widget
, m_frameMenuBar
->m_x
, m_frameMenuBar
->m_y
);
696 if (menuBar
->m_windowStyle
& wxMB_DOCKABLE
)
698 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_attached",
699 GTK_SIGNAL_FUNC(gtk_menu_attached_callback
), (gpointer
)this );
701 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_detached",
702 GTK_SIGNAL_FUNC(gtk_menu_detached_callback
), (gpointer
)this );
710 wxMenuBar
*wxFrame::GetMenuBar() const
712 return m_frameMenuBar
;
715 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
719 // if no help string found, we will clear the status bar text
722 int menuId
= event
.GetMenuId();
725 wxMenuBar
*menuBar
= GetMenuBar();
728 helpString
= menuBar
->GetHelpString(menuId
);
732 SetStatusText(helpString
);
736 wxToolBar
* wxFrame::CreateToolBar(long style
, wxWindowID id
, const wxString
& name
)
738 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
740 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
, _T("recreating toolbar in wxFrame") );
742 m_frameToolBar
= OnCreateToolBar( style
, id
, name
);
744 GetChildren().DeleteObject( m_frameToolBar
);
748 return m_frameToolBar
;
751 wxToolBar
* wxFrame::OnCreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
753 return new wxToolBar( this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
756 wxToolBar
*wxFrame::GetToolBar() const
758 return m_frameToolBar
;
761 wxStatusBar
* wxFrame::CreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
763 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
765 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
, _T("recreating status bar in wxFrame") );
767 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
771 return m_frameStatusBar
;
774 wxStatusBar
*wxFrame::OnCreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
776 wxStatusBar
*statusBar
= (wxStatusBar
*) NULL
;
778 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20), style
, name
);
780 // Set the height according to the font and the border size
781 wxClientDC
dc(statusBar
);
782 dc
.SetFont( statusBar
->GetFont() );
785 dc
.GetTextExtent( "X", &x
, &y
);
787 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
789 statusBar
->SetSize( -1, -1, 100, height
);
791 statusBar
->SetFieldsCount( number
);
795 void wxFrame::Command( int id
)
797 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
798 commandEvent
.SetInt( id
);
799 commandEvent
.SetEventObject( this );
801 wxMenuBar
*bar
= GetMenuBar();
804 wxMenuItem
*item
= bar
->FindItemForId(id
) ;
805 if (item
&& item
->IsCheckable())
807 bar
->Check(id
,!bar
->Checked(id
)) ;
810 wxEvtHandler
* evtHandler
= GetEventHandler();
812 evtHandler
->ProcessEvent(commandEvent
);
815 void wxFrame::SetStatusText(const wxString
& text
, int number
)
817 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
819 wxCHECK_RET( m_frameStatusBar
!= NULL
, _T("no statusbar to set text for") );
821 m_frameStatusBar
->SetStatusText(text
, number
);
824 void wxFrame::SetStatusWidths(int n
, const int widths_field
[] )
826 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
828 wxCHECK_RET( m_frameStatusBar
!= NULL
, _T("no statusbar to set widths for") );
830 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
833 wxStatusBar
*wxFrame::GetStatusBar() const
835 return m_frameStatusBar
;
838 void wxFrame::SetTitle( const wxString
&title
)
840 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
843 if (m_title
.IsNull()) m_title
= _T("");
844 gtk_window_set_title( GTK_WINDOW(m_widget
), title
.mbc_str() );
847 void wxFrame::SetIcon( const wxIcon
&icon
)
849 wxASSERT_MSG( (m_widget
!= NULL
), _T("invalid frame") );
852 if (!icon
.Ok()) return;
854 wxMask
*mask
= icon
.GetMask();
855 GdkBitmap
*bm
= (GdkBitmap
*) NULL
;
856 if (mask
) bm
= mask
->GetBitmap();
858 gdk_window_set_icon( m_widget
->window
, (GdkWindow
*) NULL
, icon
.GetPixmap(), bm
);