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"
20 #include "wx/toolbar.h"
23 #include "wx/statusbr.h"
25 #include "wx/dcclient.h"
30 #include "wx/gtk/win_gtk.h"
31 #include "gdk/gdkkeysyms.h"
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 const int wxMENU_HEIGHT
= 27;
39 const int wxSTATUS_HEIGHT
= 25;
40 const int wxPLACE_HOLDER
= 0;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
46 extern void wxapp_install_idle_handler();
49 //-----------------------------------------------------------------------------
51 //-----------------------------------------------------------------------------
53 extern wxList wxPendingDelete
;
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
61 extern void debug_focus_in( GtkWidget
* widget
, const wxChar
* name
, const wxChar
*window
);
65 //-----------------------------------------------------------------------------
67 //-----------------------------------------------------------------------------
69 static void gtk_frame_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxFrame
*win
)
72 wxapp_install_idle_handler();
77 if ((win
->m_width
!= alloc
->width
) || (win
->m_height
!= alloc
->height
))
80 wxPrintf( "OnSize from " );
81 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
82 wxPrintf( win->GetClassInfo()->GetClassName() );
83 wxPrintf( " %d %d %d %d\n", (int)alloc->x,
89 win
->m_width
= alloc
->width
;
90 win
->m_height
= alloc
->height
;
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 static gint
gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxFrame
*win
)
102 wxapp_install_idle_handler();
109 //-----------------------------------------------------------------------------
110 // "child_attached" of menu bar
111 //-----------------------------------------------------------------------------
113 static void gtk_menu_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
115 if (!win
->m_hasVMT
) return;
117 win
->m_menuBarDetached
= FALSE
;
121 //-----------------------------------------------------------------------------
122 // "child_detached" of menu bar
123 //-----------------------------------------------------------------------------
125 static void gtk_menu_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
127 if (!win
->m_hasVMT
) return;
129 win
->m_menuBarDetached
= TRUE
;
134 //-----------------------------------------------------------------------------
135 // "child_attached" of tool bar
136 //-----------------------------------------------------------------------------
138 static void gtk_toolbar_attached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
140 if (!win
->m_hasVMT
) return;
142 win
->m_toolBarDetached
= FALSE
;
147 //-----------------------------------------------------------------------------
148 // "child_detached" of tool bar
149 //-----------------------------------------------------------------------------
151 static void gtk_toolbar_detached_callback( GtkWidget
*WXUNUSED(widget
), GtkWidget
*WXUNUSED(child
), wxFrame
*win
)
154 wxapp_install_idle_handler();
156 if (!win
->m_hasVMT
) return;
158 win
->m_toolBarDetached
= TRUE
;
161 #endif // wxUSE_TOOLBAR
163 //-----------------------------------------------------------------------------
165 //-----------------------------------------------------------------------------
168 #if (GTK_MINOR_VERSON > 0)
169 gtk_frame_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*WXUNUSED(event
), wxFrame
*win
)
171 gtk_frame_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*event
, wxFrame
*win
)
175 wxapp_install_idle_handler();
177 if (!win
->m_hasVMT
) return FALSE
;
179 #if (GTK_MINOR_VERSON > 0)
182 gdk_window_get_root_origin( win
->m_widget
->window
, &x
, &y
);
190 wxMoveEvent
mevent( wxPoint(win
->m_x
,win
->m_y
), win
->GetId() );
191 mevent
.SetEventObject( win
);
192 win
->GetEventHandler()->ProcessEvent( mevent
);
197 //-----------------------------------------------------------------------------
198 // "realize" from m_widget
199 //-----------------------------------------------------------------------------
201 /* we cannot MWM hints and icons before the widget has been realized,
202 so we do this directly after realization */
205 gtk_frame_realized_callback( GtkWidget
*WXUNUSED(widget
), wxFrame
*win
)
208 wxapp_install_idle_handler();
210 /* all this is for Motif Window Manager "hints" and is supposed to be
211 recognized by other WM as well. not tested. */
212 long decor
= (long) GDK_DECOR_BORDER
;
213 long func
= (long) GDK_FUNC_MOVE
;
215 if ((win
->GetWindowStyle() & wxCAPTION
) != 0)
216 decor
|= GDK_DECOR_TITLE
;
217 if ((win
->GetWindowStyle() & wxSYSTEM_MENU
) != 0)
219 decor
|= GDK_DECOR_MENU
;
220 func
|= GDK_FUNC_CLOSE
;
222 if ((win
->GetWindowStyle() & wxMINIMIZE_BOX
) != 0)
224 func
|= GDK_FUNC_MINIMIZE
;
225 decor
|= GDK_DECOR_MINIMIZE
;
227 if ((win
->GetWindowStyle() & wxMAXIMIZE_BOX
) != 0)
229 func
|= GDK_FUNC_MAXIMIZE
;
230 decor
|= GDK_DECOR_MAXIMIZE
;
232 if ((win
->GetWindowStyle() & wxRESIZE_BORDER
) != 0)
234 func
|= GDK_FUNC_RESIZE
;
235 decor
|= GDK_DECOR_RESIZEH
;
238 gdk_window_set_decorations( win
->m_widget
->window
, (GdkWMDecoration
)decor
);
239 gdk_window_set_functions( win
->m_widget
->window
, (GdkWMFunction
)func
);
241 /* GTK's shrinking/growing policy */
242 if ((win
->GetWindowStyle() & wxRESIZE_BORDER
) == 0)
243 gtk_window_set_policy(GTK_WINDOW(win
->m_widget
), 0, 0, 1);
245 gtk_window_set_policy(GTK_WINDOW(win
->m_widget
), 1, 1, 1);
248 gint flag
= GDK_HINT_POS
;
249 if ((win
->GetMinWidth() != -1) || (win
->GetMinHeight() != -1)) flag
|= GDK_HINT_MIN_SIZE
;
250 if ((win
->GetMaxWidth() != -1) || (win
->GetMaxHeight() != -1)) flag
|= GDK_HINT_MAX_SIZE
;
253 gdk_window_set_hints( win
->m_widget
->window
,
255 win
->GetMinWidth(), win
->GetMinHeight(),
256 win
->GetMaxWidth(), win
->GetMaxHeight(),
261 if (win
->m_icon
!= wxNullIcon
)
263 wxIcon
icon( win
->m_icon
);
264 win
->m_icon
= wxNullIcon
;
265 win
->SetIcon( icon
);
268 /* we set the focus to the child that accepts the focus. this
269 doesn't really have to be done in "realize" but why not? */
270 wxWindowList::Node
*node
= win
->GetChildren().GetFirst();
273 wxWindow
*child
= node
->GetData();
274 if (child
->AcceptsFocus())
280 node
= node
->GetNext();
286 //-----------------------------------------------------------------------------
287 // InsertChild for wxFrame
288 //-----------------------------------------------------------------------------
290 /* Callback for wxFrame. This very strange beast has to be used because
291 * C++ has no virtual methods in a constructor. We have to emulate a
292 * virtual function here as wxWindows requires different ways to insert
293 * a child in container classes. */
295 static void wxInsertChildInFrame( wxFrame
* parent
, wxWindow
* child
)
297 wxASSERT( GTK_IS_WIDGET(child
->m_widget
) );
299 if (!parent
->m_insertInClientArea
)
301 /* these are outside the client area */
302 wxFrame
* frame
= (wxFrame
*) parent
;
303 gtk_myfixed_put( GTK_MYFIXED(frame
->m_mainWidget
),
304 GTK_WIDGET(child
->m_widget
),
311 /* we connect to these events for recalculating the client area
312 space when the toolbar is floating */
313 if (wxIS_KIND_OF(child
,wxToolBar
))
315 wxToolBar
*toolBar
= (wxToolBar
*) child
;
316 if (toolBar
->GetWindowStyle() & wxTB_DOCKABLE
)
318 gtk_signal_connect( GTK_OBJECT(toolBar
->m_widget
), "child_attached",
319 GTK_SIGNAL_FUNC(gtk_toolbar_attached_callback
), (gpointer
)parent
);
321 gtk_signal_connect( GTK_OBJECT(toolBar
->m_widget
), "child_detached",
322 GTK_SIGNAL_FUNC(gtk_toolbar_detached_callback
), (gpointer
)parent
);
325 #endif // wxUSE_TOOLBAR
329 /* these are inside the client area */
330 gtk_myfixed_put( GTK_MYFIXED(parent
->m_wxwindow
),
331 GTK_WIDGET(child
->m_widget
),
338 /* resize on OnInternalIdle */
339 parent
->UpdateSize();
342 //-----------------------------------------------------------------------------
344 //-----------------------------------------------------------------------------
346 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
347 EVT_SIZE(wxFrame::OnSize
)
348 EVT_IDLE(wxFrame::OnIdle
)
349 EVT_CLOSE(wxFrame::OnCloseWindow
)
350 EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight
)
353 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
357 m_frameMenuBar
= (wxMenuBar
*) NULL
;
359 m_frameStatusBar
= (wxStatusBar
*) NULL
;
360 #endif // wxUSE_STATUSBAR
362 m_frameToolBar
= (wxToolBar
*) NULL
;
363 #endif // wxUSE_TOOLBAR
367 m_mainWidget
= (GtkWidget
*) NULL
;
368 m_menuBarDetached
= FALSE
;
369 m_toolBarDetached
= FALSE
;
370 m_insertInClientArea
= TRUE
;
374 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
375 const wxPoint
&pos
, const wxSize
&size
,
376 long style
, const wxString
&name
)
380 Create( parent
, id
, title
, pos
, size
, style
, name
);
383 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
384 const wxPoint
&pos
, const wxSize
&size
,
385 long style
, const wxString
&name
)
387 wxTopLevelWindows
.Append( this );
389 m_needParent
= FALSE
;
391 if (!PreCreation( parent
, pos
, size
) ||
392 !CreateBase( parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
))
394 wxFAIL_MSG( wxT("wxFrame creation failed") );
400 m_insertCallback
= (wxInsertChildFunction
) wxInsertChildInFrame
;
402 GtkWindowType win_type
= GTK_WINDOW_TOPLEVEL
;
403 if (style
& wxSIMPLE_BORDER
) win_type
= GTK_WINDOW_POPUP
;
405 m_widget
= gtk_window_new( win_type
);
408 gtk_window_set_wmclass( GTK_WINDOW(m_widget
), name
.mb_str(), name
.mb_str() );
411 debug_focus_in( m_widget
, wxT("wxFrame::m_widget"), name
);
414 gtk_window_set_title( GTK_WINDOW(m_widget
), title
.mbc_str() );
415 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
417 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
418 GTK_SIGNAL_FUNC(gtk_frame_delete_callback
), (gpointer
)this );
420 /* m_mainWidget holds the toolbar, the menubar and the client area */
421 m_mainWidget
= gtk_myfixed_new();
422 gtk_widget_show( m_mainWidget
);
423 GTK_WIDGET_UNSET_FLAGS( m_mainWidget
, GTK_CAN_FOCUS
);
424 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWidget
);
427 debug_focus_in( m_mainWidget
, wxT("wxFrame::m_mainWidget"), name
);
430 /* m_wxwindow only represents the client area without toolbar and menubar */
431 m_wxwindow
= gtk_myfixed_new();
432 gtk_widget_show( m_wxwindow
);
433 gtk_container_add( GTK_CONTAINER(m_mainWidget
), m_wxwindow
);
436 debug_focus_in( m_wxwindow
, wxT("wxFrame::m_wxwindow"), name
);
439 /* we donm't allow the frame to get the focus as otherwise
440 the frame will grabit at arbitrary fcous changes. */
441 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
443 if (m_parent
) m_parent
->AddChild( this );
445 /* the user resized the frame by dragging etc. */
446 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
447 GTK_SIGNAL_FUNC(gtk_frame_size_callback
), (gpointer
)this );
451 /* we cannot set MWM hints and icons before the widget has
452 been realized, so we do this directly after realization */
453 gtk_signal_connect( GTK_OBJECT(m_widget
), "realize",
454 GTK_SIGNAL_FUNC(gtk_frame_realized_callback
), (gpointer
) this );
456 /* the only way to get the window size is to connect to this event */
457 gtk_signal_connect( GTK_OBJECT(m_widget
), "configure_event",
458 GTK_SIGNAL_FUNC(gtk_frame_configure_callback
), (gpointer
)this );
465 m_isBeingDeleted
= TRUE
;
467 if (m_frameMenuBar
) delete m_frameMenuBar
;
468 m_frameMenuBar
= (wxMenuBar
*) NULL
;
471 if (m_frameStatusBar
) delete m_frameStatusBar
;
472 m_frameStatusBar
= (wxStatusBar
*) NULL
;
473 #endif // wxUSE_STATUSBAR
476 if (m_frameToolBar
) delete m_frameToolBar
;
477 m_frameToolBar
= (wxToolBar
*) NULL
;
478 #endif // wxUSE_TOOLBAR
480 wxTopLevelWindows
.DeleteObject( this );
482 if (wxTheApp
->GetTopWindow() == this)
483 wxTheApp
->SetTopWindow( (wxWindow
*) NULL
);
485 if (wxTopLevelWindows
.Number() == 0)
486 wxTheApp
->ExitMainLoop();
489 bool wxFrame::Show( bool show
)
491 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
493 if (show
&& !m_sizeSet
)
495 /* by calling GtkOnSize here, we don't have to call
496 either after showing the frame, which would entail
497 much ugly flicker or from within the size_allocate
498 handler, because GTK 1.1.X forbids that. */
500 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
503 return wxWindow::Show( show
);
506 bool wxFrame::Destroy()
508 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
510 if (!wxPendingDelete
.Member(this)) wxPendingDelete
.Append(this);
515 void wxFrame::DoSetSize( int x
, int y
, int width
, int height
, int sizeFlags
)
517 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
519 /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */
520 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
522 /* avoid recursions */
523 if (m_resizing
) return;
528 int old_width
= m_width
;
529 int old_height
= m_height
;
531 if ((sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) == 0)
533 if (x
!= -1) m_x
= x
;
534 if (y
!= -1) m_y
= y
;
535 if (width
!= -1) m_width
= width
;
536 if (height
!= -1) m_height
= height
;
546 if ((sizeFlags
& wxSIZE_AUTO_WIDTH
) == wxSIZE_AUTO_WIDTH
)
548 if (width
== -1) m_width
= 80;
551 if ((sizeFlags
& wxSIZE_AUTO_HEIGHT
) == wxSIZE_AUTO_HEIGHT
)
553 if (height
== -1) m_height
= 26;
556 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
557 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
558 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_maxWidth
;
559 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_maxHeight
;
561 if ((m_x
!= -1) || (m_y
!= -1))
563 if ((m_x
!= old_x
) || (m_y
!= old_y
))
565 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
569 if ((m_width
!= old_width
) || (m_height
!= old_height
))
571 /* we set the size in GtkOnSize, i.e. mostly the actual resizing is
572 done either directly before the frame is shown or in idle time
573 so that different calls to SetSize() don't lead to flicker. */
580 void wxFrame::Centre( int direction
)
582 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
587 if ((direction
& wxHORIZONTAL
) == wxHORIZONTAL
) x
= (gdk_screen_width () - m_width
) / 2;
588 if ((direction
& wxVERTICAL
) == wxVERTICAL
) y
= (gdk_screen_height () - m_height
) / 2;
593 void wxFrame::DoGetClientSize( int *width
, int *height
) const
595 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
597 wxWindow::DoGetClientSize( width
, height
);
603 if (!m_menuBarDetached
)
604 (*height
) -= wxMENU_HEIGHT
;
606 (*height
) -= wxPLACE_HOLDER
;
611 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
618 if (!m_toolBarDetached
)
621 m_frameToolBar
->GetSize( (int *) NULL
, &y
);
625 (*height
) -= wxPLACE_HOLDER
;
630 (*height
) -= m_miniEdge
*2 + m_miniTitle
;
634 (*width
) -= m_miniEdge
*2;
638 void wxFrame::DoSetClientSize( int width
, int height
)
640 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
645 if (!m_menuBarDetached
)
646 height
+= wxMENU_HEIGHT
;
648 height
+= wxPLACE_HOLDER
;
653 if (m_frameStatusBar
) height
+= wxSTATUS_HEIGHT
;
660 if (!m_toolBarDetached
)
663 m_frameToolBar
->GetSize( (int *) NULL
, &y
);
667 height
+= wxPLACE_HOLDER
;
671 DoSetSize( -1, -1, width
+ m_miniEdge
*2, height
+ m_miniEdge
*2 + m_miniTitle
, 0 );
674 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
), int width
, int height
)
676 // due to a bug in gtk, x,y are always 0
680 /* avoid recursions */
681 if (m_resizing
) return;
684 /* this shouldn't happen: wxFrame, wxMDIParentFrame and wxMDIChildFrame have m_wxwindow */
685 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
690 /* space occupied by m_frameToolBar and m_frameMenuBar */
691 int client_area_y_offset
= 0;
693 /* wxMDIChildFrame derives from wxFrame but it _is_ a wxWindow as it uses
694 wxWindow::Create to create it's GTK equivalent. m_mainWidget is only
695 set in wxFrame::Create so it is used to check what kind of frame we
696 have here. if m_mainWidget is NULL it is a wxMDIChildFrame and so we
697 skip the part which handles m_frameMenuBar, m_frameToolBar and (most
698 importantly) m_mainWidget */
702 /* check if size is in legal range */
703 if ((m_minWidth
!= -1) && (m_width
< m_minWidth
)) m_width
= m_minWidth
;
704 if ((m_minHeight
!= -1) && (m_height
< m_minHeight
)) m_height
= m_minHeight
;
705 if ((m_maxWidth
!= -1) && (m_width
> m_maxWidth
)) m_width
= m_maxWidth
;
706 if ((m_maxHeight
!= -1) && (m_height
> m_maxHeight
)) m_height
= m_maxHeight
;
708 /* I revert back to wxGTK's original behaviour. m_mainWidget holds the
709 * menubar, the toolbar and the client area, which is represented by
711 * this hurts in the eye, but I don't want to call SetSize()
712 * because I don't want to call any non-native functions here. */
717 int yy
= m_miniEdge
+ m_miniTitle
;
718 int ww
= m_width
- 2*m_miniEdge
;
719 int hh
= wxMENU_HEIGHT
;
720 if (m_menuBarDetached
) hh
= wxPLACE_HOLDER
;
721 m_frameMenuBar
->m_x
= xx
;
722 m_frameMenuBar
->m_y
= yy
;
723 m_frameMenuBar
->m_width
= ww
;
724 m_frameMenuBar
->m_height
= hh
;
725 gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget
),
726 m_frameMenuBar
->m_widget
,
728 client_area_y_offset
+= hh
;
735 int yy
= m_miniEdge
+ m_miniTitle
;
738 if (!m_menuBarDetached
)
741 yy
+= wxPLACE_HOLDER
;
743 int ww
= m_width
- 2*m_miniEdge
;
744 int hh
= m_frameToolBar
->m_height
;
745 if (m_toolBarDetached
) hh
= wxPLACE_HOLDER
;
746 m_frameToolBar
->m_x
= xx
;
747 m_frameToolBar
->m_y
= yy
;
748 /* m_frameToolBar->m_height = hh; don't change the toolbar's height */
749 m_frameToolBar
->m_width
= ww
;
750 gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget
),
751 m_frameToolBar
->m_widget
,
753 client_area_y_offset
+= hh
;
757 int client_x
= m_miniEdge
;
758 int client_y
= client_area_y_offset
+ m_miniEdge
+ m_miniTitle
;
759 int client_w
= m_width
- 2*m_miniEdge
;
760 int client_h
= m_height
- client_area_y_offset
- 2*m_miniEdge
- m_miniTitle
;
761 gtk_myfixed_set_size( GTK_MYFIXED(m_mainWidget
),
763 client_x
, client_y
, client_w
, client_h
);
767 /* if there is no m_mainWidget between m_widget and m_wxwindow there
768 is no need to set the size or position of m_wxwindow. */
772 if (m_frameStatusBar
)
774 int xx
= 0 + m_miniEdge
;
775 int yy
= m_height
- wxSTATUS_HEIGHT
- m_miniEdge
- client_area_y_offset
;
776 int ww
= m_width
- 2*m_miniEdge
;
777 int hh
= wxSTATUS_HEIGHT
;
778 m_frameStatusBar
->m_x
= xx
;
779 m_frameStatusBar
->m_y
= yy
;
780 m_frameStatusBar
->m_width
= ww
;
781 m_frameStatusBar
->m_height
= hh
;
782 gtk_myfixed_set_size( GTK_MYFIXED(m_wxwindow
),
783 m_frameStatusBar
->m_widget
,
788 /* we actually set the size of a frame here and no-where else */
789 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
794 // send size event to frame
795 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
796 event
.SetEventObject( this );
797 GetEventHandler()->ProcessEvent( event
);
799 // send size event to status bar
800 if (m_frameStatusBar
)
802 wxSizeEvent
event2( wxSize(m_frameStatusBar
->m_width
,m_frameStatusBar
->m_height
), m_frameStatusBar
->GetId() );
803 event2
.SetEventObject( m_frameStatusBar
);
804 m_frameStatusBar
->GetEventHandler()->ProcessEvent( event2
);
810 void wxFrame::MakeModal( bool modal
)
813 gtk_grab_add( m_widget
);
815 gtk_grab_remove( m_widget
);
818 void wxFrame::OnInternalIdle()
820 if (!m_sizeSet
&& GTK_WIDGET_REALIZED(m_wxwindow
))
822 GtkOnSize( m_x
, m_y
, m_width
, m_height
);
824 // we'll come back later
826 wxapp_install_idle_handler();
830 if (m_frameMenuBar
) m_frameMenuBar
->OnInternalIdle();
832 if (m_frameToolBar
) m_frameToolBar
->OnInternalIdle();
835 if (m_frameStatusBar
) m_frameStatusBar
->OnInternalIdle();
838 wxWindow::OnInternalIdle();
841 void wxFrame::OnCloseWindow( wxCloseEvent
& WXUNUSED(event
) )
846 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
848 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
850 #if wxUSE_CONSTRAINTS
856 #endif // wxUSE_CONSTRAINTS
858 /* do we have exactly one child? */
859 wxWindow
*child
= (wxWindow
*)NULL
;
860 for ( wxNode
*node
= GetChildren().First(); node
; node
= node
->Next() )
862 wxWindow
*win
= (wxWindow
*)node
->Data();
863 if ( !wxIS_KIND_OF(win
,wxFrame
) && !wxIS_KIND_OF(win
,wxDialog
) )
867 /* it's the second one: do nothing */
875 /* no children at all? */
878 /* yes: set it's size to fill all the frame */
879 int client_x
, client_y
;
880 DoGetClientSize( &client_x
, &client_y
);
881 child
->SetSize( 1, 1, client_x
-2, client_y
-2 );
886 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
888 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
889 wxASSERT_MSG( (m_wxwindow
!= NULL
), wxT("invalid frame") );
891 m_frameMenuBar
= menuBar
;
895 m_frameMenuBar
->SetInvokingWindow( this );
897 if (m_frameMenuBar
->GetParent() != this)
899 m_frameMenuBar
->SetParent(this);
900 gtk_myfixed_put( GTK_MYFIXED(m_mainWidget
),
901 m_frameMenuBar
->m_widget
,
904 m_frameMenuBar
->m_width
,
905 m_frameMenuBar
->m_height
);
907 if (menuBar
->GetWindowStyle() & wxMB_DOCKABLE
)
909 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_attached",
910 GTK_SIGNAL_FUNC(gtk_menu_attached_callback
), (gpointer
)this );
912 gtk_signal_connect( GTK_OBJECT(menuBar
->m_widget
), "child_detached",
913 GTK_SIGNAL_FUNC(gtk_menu_detached_callback
), (gpointer
)this );
916 m_frameMenuBar
->Show( TRUE
);
920 /* resize window in OnInternalIdle */
924 wxMenuBar
*wxFrame::GetMenuBar() const
926 return m_frameMenuBar
;
929 void wxFrame::OnMenuHighlight(wxMenuEvent
& event
)
934 // if no help string found, we will clear the status bar text
937 int menuId
= event
.GetMenuId();
940 wxMenuBar
*menuBar
= GetMenuBar();
943 helpString
= menuBar
->GetHelpString(menuId
);
947 SetStatusText(helpString
);
949 #endif // wxUSE_STATUSBAR
953 wxToolBar
* wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
955 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
957 wxCHECK_MSG( m_frameToolBar
== NULL
, FALSE
, wxT("recreating toolbar in wxFrame") );
959 m_insertInClientArea
= FALSE
;
961 m_frameToolBar
= OnCreateToolBar( style
, id
, name
);
963 if (m_frameToolBar
) GetChildren().DeleteObject( m_frameToolBar
);
965 m_insertInClientArea
= TRUE
;
969 return m_frameToolBar
;
972 wxToolBar
* wxFrame::OnCreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
974 return new wxToolBar( this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
977 void wxFrame::SetToolBar(wxToolBar
*toolbar
)
979 m_frameToolBar
= toolbar
;
982 /* insert into toolbar area if not already there */
983 if ((m_frameToolBar
->m_widget
->parent
) &&
984 (m_frameToolBar
->m_widget
->parent
!= m_mainWidget
))
986 GetChildren().DeleteObject( m_frameToolBar
);
988 gtk_widget_reparent( m_frameToolBar
->m_widget
, m_mainWidget
);
994 wxToolBar
*wxFrame::GetToolBar() const
996 return m_frameToolBar
;
998 #endif // wxUSE_TOOLBAR
1001 wxStatusBar
* wxFrame::CreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
1003 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1005 wxCHECK_MSG( m_frameStatusBar
== NULL
, FALSE
, wxT("recreating status bar in wxFrame") );
1007 m_frameStatusBar
= OnCreateStatusBar( number
, style
, id
, name
);
1011 return m_frameStatusBar
;
1014 wxStatusBar
*wxFrame::OnCreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
1016 wxStatusBar
*statusBar
= (wxStatusBar
*) NULL
;
1018 statusBar
= new wxStatusBar(this, id
, wxPoint(0, 0), wxSize(100, 20), style
, name
);
1020 // Set the height according to the font and the border size
1021 wxClientDC
dc(statusBar
);
1022 dc
.SetFont( statusBar
->GetFont() );
1025 dc
.GetTextExtent( "X", &x
, &y
);
1027 int height
= (int)( (y
* 1.1) + 2* statusBar
->GetBorderY());
1029 statusBar
->SetSize( -1, -1, 100, height
);
1031 statusBar
->SetFieldsCount( number
);
1035 wxStatusBar
*wxFrame::GetStatusBar() const
1037 return m_frameStatusBar
;
1040 void wxFrame::SetStatusText(const wxString
& text
, int number
)
1042 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1044 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set text for") );
1046 m_frameStatusBar
->SetStatusText(text
, number
);
1049 void wxFrame::SetStatusWidths(int n
, const int widths_field
[] )
1051 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1053 wxCHECK_RET( m_frameStatusBar
!= NULL
, wxT("no statusbar to set widths for") );
1055 m_frameStatusBar
->SetStatusWidths(n
, widths_field
);
1057 #endif // wxUSE_STATUSBAR
1059 void wxFrame::Command( int id
)
1061 wxCommandEvent
commandEvent(wxEVT_COMMAND_MENU_SELECTED
, id
);
1062 commandEvent
.SetInt( id
);
1063 commandEvent
.SetEventObject( this );
1065 wxMenuBar
*bar
= GetMenuBar();
1068 wxMenuItem
*item
= bar
->FindItemForId(id
) ;
1069 if (item
&& item
->IsCheckable())
1071 bar
->Check(id
,!bar
->Checked(id
)) ;
1074 wxEvtHandler
* evtHandler
= GetEventHandler();
1076 evtHandler
->ProcessEvent(commandEvent
);
1079 void wxFrame::SetTitle( const wxString
&title
)
1081 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1084 if (m_title
.IsNull()) m_title
= wxT("");
1085 gtk_window_set_title( GTK_WINDOW(m_widget
), title
.mbc_str() );
1088 void wxFrame::SetIcon( const wxIcon
&icon
)
1090 wxASSERT_MSG( (m_widget
!= NULL
), wxT("invalid frame") );
1093 if (!icon
.Ok()) return;
1095 if (!m_widget
->window
) return;
1097 wxMask
*mask
= icon
.GetMask();
1098 GdkBitmap
*bm
= (GdkBitmap
*) NULL
;
1099 if (mask
) bm
= mask
->GetBitmap();
1101 gdk_window_set_icon( m_widget
->window
, (GdkWindow
*) NULL
, icon
.GetPixmap(), bm
);
1104 void wxFrame::Maximize(bool WXUNUSED(maximize
))
1108 void wxFrame::Restore()
1112 void wxFrame::Iconize( bool iconize
)
1116 XIconifyWindow( GDK_WINDOW_XDISPLAY( m_widget
->window
),
1117 GDK_WINDOW_XWINDOW( m_widget
->window
),
1118 DefaultScreen( GDK_DISPLAY() ) );
1122 bool wxFrame::IsIconized() const