1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
7 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "frame.h"
16 #include "wx/dialog.h"
17 #include "wx/control.h"
20 #include "wx/toolbar.h"
21 #include "wx/statusbr.h"
22 #include "wx/gtk/win_gtk.h"
24 const wxMENU_HEIGHT
= 28;
25 const wxSTATUS_HEIGHT
= 25;
27 extern wxList wxTopLevelWindows
;
28 extern wxList wxPendingDelete
;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
37 void gtk_frame_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxFrame
*win
)
39 if (!win
->HasVMT()) return;
42 printf( "OnFrameResize from " );
43 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
44 printf( win->GetClassInfo()->GetClassName() );
48 win
->GtkOnSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
51 //-----------------------------------------------------------------------------
54 bool gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxFrame
*win
)
57 printf( "OnDelete from " );
58 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
59 printf( win->GetClassInfo()->GetClassName() );
68 //-----------------------------------------------------------------------------
70 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
71 EVT_SIZE(wxFrame::OnSize
)
72 EVT_CLOSE(wxFrame::OnCloseWindow
)
73 EVT_IDLE(wxFrame::OnIdle
)
76 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
80 m_frameMenuBar
= NULL
;
81 m_frameStatusBar
= NULL
;
82 m_frameToolBar
= NULL
;
84 m_addPrivateChild
= FALSE
;
87 wxTopLevelWindows
.Insert( this );
90 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
91 const wxPoint
&pos
, const wxSize
&size
,
92 long style
, const wxString
&name
)
94 m_frameMenuBar
= NULL
;
95 m_frameStatusBar
= NULL
;
96 m_frameToolBar
= NULL
;
98 m_addPrivateChild
= FALSE
;
101 Create( parent
, id
, title
, pos
, size
, style
, name
);
102 wxTopLevelWindows
.Insert( this );
105 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
106 const wxPoint
&pos
, const wxSize
&size
,
107 long style
, const wxString
&name
)
109 m_needParent
= FALSE
;
111 PreCreation( parent
, id
, pos
, size
, style
, name
);
115 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
116 if ((size
.x
!= -1) && (size
.y
!= -1))
117 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
118 if ((pos
.x
!= -1) && (pos
.y
!= -1))
119 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
121 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
122 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
124 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
126 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
127 GTK_SIGNAL_FUNC(gtk_frame_delete_callback
), (gpointer
)this );
129 m_mainWindow
= gtk_myfixed_new();
130 gtk_widget_show( m_mainWindow
);
131 GTK_WIDGET_UNSET_FLAGS( m_mainWindow
, GTK_CAN_FOCUS
);
133 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWindow
);
134 gtk_widget_set_uposition( m_mainWindow
, 0, 0 );
136 m_wxwindow
= gtk_myfixed_new();
137 gtk_widget_show( m_wxwindow
);
138 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
140 gtk_container_add( GTK_CONTAINER(m_mainWindow
), m_wxwindow
);
142 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
143 GTK_SIGNAL_FUNC(gtk_frame_size_callback
), (gpointer
)this );
147 gtk_widget_realize( m_mainWindow
);
154 if (m_frameMenuBar
) delete m_frameMenuBar
;
155 if (m_frameStatusBar
) delete m_frameStatusBar
;
157 // if (m_mainWindow) gtk_widget_destroy( m_mainWindow );
159 wxTopLevelWindows
.DeleteObject( this );
160 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
163 bool wxFrame::Show( bool show
)
167 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
169 ProcessEvent( event
);
171 return wxWindow::Show( show
);
174 void wxFrame::Enable( bool enable
)
176 wxWindow::Enable( enable
);
177 gtk_widget_set_sensitive( m_mainWindow
, enable
);
180 void wxFrame::OnCloseWindow( wxCloseEvent
&event
)
182 if ( GetEventHandler()->OnClose() || event
.GetForce())
188 bool wxFrame::Destroy()
190 if (!wxPendingDelete
.Member(this))
191 wxPendingDelete
.Append(this);
196 void wxFrame::GetClientSize( int *width
, int *height
) const
198 wxWindow::GetClientSize( width
, height
);
201 if (m_frameMenuBar
) (*height
) -= wxMENU_HEIGHT
;
202 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
206 m_frameToolBar
->GetSize( NULL
, &y
);
212 void wxFrame::GtkOnSize( int x
, int y
, int width
, int height
)
217 if ((m_height
== height
) && (m_width
== width
) &&
219 if (!m_mainWindow
) return;
220 if (!m_wxwindow
) return;
225 gtk_widget_set_usize( m_widget
, width
, height
);
229 int main_height
= height
;
230 int main_width
= width
;
232 // This emulates Windows behaviour:
233 // The menu bar is part of the main window, but the status bar
234 // is on the implementation side in the client area. The
235 // function GetClientSize returns the size of the client area
236 // minus the status bar height. Under wxGTK, the main window
237 // is represented by m_mainWindow. The menubar is inserted
238 // into m_mainWindow whereas the statusbar is insertes into
239 // m_wxwindow just like any other window.
242 gtk_widget_set_usize( m_mainWindow
, width
, height
);
246 main_y
= wxMENU_HEIGHT
;
247 main_height
-= wxMENU_HEIGHT
;
250 int toolbar_height
= 0;
251 if (m_frameToolBar
) m_frameToolBar
->GetSize( NULL
, &toolbar_height
);
253 main_y
+= toolbar_height
;
254 main_height
-= toolbar_height
;
256 gtk_widget_set_uposition( GTK_WIDGET(m_wxwindow
), main_x
, main_y
);
257 gtk_widget_set_usize( GTK_WIDGET(m_wxwindow
), main_width
, main_height
);
261 gtk_widget_set_uposition( m_frameMenuBar
->m_widget
, 1, 1 );
262 gtk_widget_set_usize( m_frameMenuBar
->m_widget
, width
-2, wxMENU_HEIGHT
-2 );
267 gtk_widget_set_uposition( m_frameToolBar
->m_widget
, 1, wxMENU_HEIGHT
);
268 gtk_widget_set_usize( m_frameToolBar
->m_widget
, width
-2, toolbar_height
);
271 if (m_frameStatusBar
)
273 m_frameStatusBar
->SetSize( 0, main_height
-wxSTATUS_HEIGHT
, width
, wxSTATUS_HEIGHT
);
278 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
279 event
.SetEventObject( this );
280 ProcessEvent( event
);
283 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
285 if ( GetAutoLayout() )
288 // no child: go out !
289 if (!GetChildren()->First())
292 // do we have exactly one child?
293 wxWindow
*child
= NULL
;
294 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
296 wxWindow
*win
= (wxWindow
*)node
->Data();
297 if (!IS_KIND_OF(win
,wxFrame
) && !IS_KIND_OF(win
,wxDialog
)
298 #if 0 // not in m_children anyway
299 && (win
!= m_frameMenuBar
) &&
300 (win
!= m_frameToolBar
) &&
301 (win
!= m_frameStatusBar
)
305 if ( child
) // it's the second one: do nothing
312 // yes: set it's size to fill all the frame
313 int client_x
, client_y
;
314 GetClientSize(&client_x
, &client_y
);
315 child
->SetSize( 1, 1, client_x
-2, client_y
);
319 void wxFrame::AddChild( wxWindow
*child
)
321 // wxFrame and wxDialog as children aren't placed into the parents
323 if (child
->IsKindOf(CLASSINFO(wxFrame
)) || child
->IsKindOf(CLASSINFO(wxDialog
)))
325 m_children
.Append( child
);
327 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
328 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
333 if (m_addPrivateChild
)
335 gtk_myfixed_put( GTK_MYFIXED(m_mainWindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
337 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
341 m_children
.Append( child
);
344 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
346 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
350 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
352 menu
->SetInvokingWindow( win
);
353 wxNode
*node
= menu
->m_items
.First();
356 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
357 if (menuitem
->IsSubMenu())
358 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
363 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
365 m_frameMenuBar
= menuBar
;
369 if (m_frameMenuBar
->m_parent
!= this)
371 wxNode
*node
= m_frameMenuBar
->m_menus
.First();
374 wxMenu
*menu
= (wxMenu
*)node
->Data();
375 SetInvokingWindow( menu
, this );
379 m_frameMenuBar
->m_parent
= this;
380 gtk_myfixed_put( GTK_MYFIXED(m_mainWindow
),
381 m_frameMenuBar
->m_widget
, m_frameMenuBar
->m_x
, m_frameMenuBar
->m_y
);
386 wxMenuBar
*wxFrame::GetMenuBar(void)
388 return m_frameMenuBar
;
391 wxToolBar
*wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
393 m_addPrivateChild
= TRUE
;
395 m_frameToolBar
= new wxToolBar( this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
397 m_addPrivateChild
= FALSE
;
399 return m_frameToolBar
;
402 wxToolBar
*wxFrame::GetToolBar(void)
404 return m_frameToolBar
;
407 wxStatusBar
* wxFrame::CreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
409 if (m_frameStatusBar
)
410 delete m_frameStatusBar
;
412 m_frameStatusBar
= new wxStatusBar( this, id
, wxPoint(0,0), wxSize(100,20), style
, name
);
414 m_frameStatusBar
->SetFieldsCount( number
);
416 return m_frameStatusBar
;
419 void wxFrame::SetStatusText( const wxString
&text
, int number
)
421 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusText( text
, number
);
424 void wxFrame::SetStatusWidths( int n
, int *width
)
426 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusWidths( n
, width
);
429 wxStatusBar
*wxFrame::GetStatusBar(void)
431 return m_frameStatusBar
;
434 void wxFrame::SetTitle( const wxString
&title
)
437 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
440 void wxFrame::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
) )
443 gdk_window_set_hints( m_wxwindow
->window
, -1, -1,
444 minW
, minH
, maxW
, maxH
, GDK_HINT_MIN_SIZE
| GDK_HINT_MIN_SIZE
);
447 void wxFrame::SetIcon( const wxIcon
&icon
)
450 if (!icon
.Ok()) return;
452 wxMask
*mask
= icon
.GetMask();
453 GdkBitmap
*bm
= NULL
;
454 if (mask
) bm
= mask
->GetBitmap();
456 gdk_window_set_icon( m_widget
->window
, NULL
, icon
.GetPixmap(), bm
);