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"
23 #include "wx/gtk/win_gtk.h"
25 const wxMENU_HEIGHT
= 28;
26 const wxSTATUS_HEIGHT
= 25;
28 extern wxList wxTopLevelWindows
;
29 extern wxList wxPendingDelete
;
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
38 void gtk_frame_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxFrame
*win
)
40 if (!win
->HasVMT()) return;
43 printf( "OnFrameResize from " );
44 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
45 printf( win->GetClassInfo()->GetClassName() );
49 win
->GtkOnSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
52 //-----------------------------------------------------------------------------
55 bool gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxFrame
*win
)
58 printf( "OnDelete from " );
59 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
60 printf( win->GetClassInfo()->GetClassName() );
69 //-----------------------------------------------------------------------------
72 gint
gtk_frame_configure_callback( GtkWidget
*WXUNUSED(widget
), GdkEventConfigure
*event
, wxFrame
*win
)
74 if (!win
->HasVMT()) return FALSE
;
82 //-----------------------------------------------------------------------------
84 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
85 EVT_SIZE(wxFrame::OnSize
)
86 EVT_CLOSE(wxFrame::OnCloseWindow
)
87 EVT_IDLE(wxFrame::OnIdle
)
90 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
94 m_frameMenuBar
= NULL
;
95 m_frameStatusBar
= NULL
;
96 m_frameToolBar
= NULL
;
98 m_addPrivateChild
= FALSE
;
101 wxTopLevelWindows
.Insert( this );
104 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
105 const wxPoint
&pos
, const wxSize
&size
,
106 long style
, const wxString
&name
)
108 m_frameMenuBar
= NULL
;
109 m_frameStatusBar
= NULL
;
110 m_frameToolBar
= NULL
;
112 m_addPrivateChild
= FALSE
;
115 Create( parent
, id
, title
, pos
, size
, style
, name
);
116 wxTopLevelWindows
.Insert( this );
119 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
120 const wxPoint
&pos
, const wxSize
&size
,
121 long style
, const wxString
&name
)
123 m_needParent
= FALSE
;
125 PreCreation( parent
, id
, pos
, size
, style
, name
);
129 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
130 if ((size
.x
!= -1) && (size
.y
!= -1))
131 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
132 if ((pos
.x
!= -1) && (pos
.y
!= -1))
133 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
135 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
136 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
138 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
140 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
141 GTK_SIGNAL_FUNC(gtk_frame_delete_callback
), (gpointer
)this );
143 m_mainWindow
= gtk_myfixed_new();
144 gtk_widget_show( m_mainWindow
);
145 GTK_WIDGET_UNSET_FLAGS( m_mainWindow
, GTK_CAN_FOCUS
);
147 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWindow
);
148 gtk_widget_set_uposition( m_mainWindow
, 0, 0 );
150 m_wxwindow
= gtk_myfixed_new();
151 gtk_widget_show( m_wxwindow
);
152 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
154 gtk_container_add( GTK_CONTAINER(m_mainWindow
), m_wxwindow
);
156 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
157 GTK_SIGNAL_FUNC(gtk_frame_size_callback
), (gpointer
)this );
159 gtk_signal_connect( GTK_OBJECT(m_widget
), "configure_event",
160 GTK_SIGNAL_FUNC(gtk_frame_configure_callback
), (gpointer
)this );
164 gtk_widget_realize( m_mainWindow
);
171 if (m_frameMenuBar
) delete m_frameMenuBar
;
172 if (m_frameStatusBar
) delete m_frameStatusBar
;
174 // if (m_mainWindow) gtk_widget_destroy( m_mainWindow );
176 wxTopLevelWindows
.DeleteObject( this );
177 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
180 bool wxFrame::Show( bool show
)
184 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
186 ProcessEvent( event
);
188 return wxWindow::Show( show
);
191 void wxFrame::Enable( bool enable
)
193 wxWindow::Enable( enable
);
194 gtk_widget_set_sensitive( m_mainWindow
, enable
);
197 void wxFrame::OnCloseWindow( wxCloseEvent
&event
)
199 if ( GetEventHandler()->OnClose() || event
.GetForce())
205 bool wxFrame::Destroy()
207 if (!wxPendingDelete
.Member(this))
208 wxPendingDelete
.Append(this);
213 void wxFrame::GetClientSize( int *width
, int *height
) const
215 wxWindow::GetClientSize( width
, height
);
218 if (m_frameMenuBar
) (*height
) -= wxMENU_HEIGHT
;
219 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
223 m_frameToolBar
->GetSize( NULL
, &y
);
229 void wxFrame::GtkOnSize( int WXUNUSED(x
), int WXUNUSED(y
), int width
, int height
)
231 // due to a bug in gtk, x,y are always 0
235 if ((m_height
== height
) && (m_width
== width
) &&
237 if (!m_mainWindow
) return;
238 if (!m_wxwindow
) return;
243 gtk_widget_set_usize( m_widget
, width
, height
);
247 int main_height
= height
;
248 int main_width
= width
;
250 // This emulates Windows behaviour:
251 // The menu bar is part of the main window, but the status bar
252 // is on the implementation side in the client area. The
253 // function GetClientSize returns the size of the client area
254 // minus the status bar height. Under wxGTK, the main window
255 // is represented by m_mainWindow. The menubar is inserted
256 // into m_mainWindow whereas the statusbar is insertes into
257 // m_wxwindow just like any other window.
260 // gtk_widget_set_usize( m_mainWindow, width, height );
264 main_y
= wxMENU_HEIGHT
;
265 main_height
-= wxMENU_HEIGHT
;
268 int toolbar_height
= 0;
269 if (m_frameToolBar
) m_frameToolBar
->GetSize( NULL
, &toolbar_height
);
271 main_y
+= toolbar_height
;
272 main_height
-= toolbar_height
;
274 gtk_myfixed_move( GTK_MYFIXED(m_mainWindow
), m_wxwindow
, main_x
, main_y
);
275 gtk_widget_set_usize( m_wxwindow
, main_width
, main_height
);
279 gtk_myfixed_move( GTK_MYFIXED(m_mainWindow
), m_frameMenuBar
->m_widget
, 1, 1 );
280 gtk_widget_set_usize( m_frameMenuBar
->m_widget
, width
-2, wxMENU_HEIGHT
-2 );
285 gtk_myfixed_move( GTK_MYFIXED(m_mainWindow
), m_frameToolBar
->m_widget
, 1, wxMENU_HEIGHT
);
286 gtk_widget_set_usize( m_frameToolBar
->m_widget
, width
-2, toolbar_height
);
289 if (m_frameStatusBar
)
291 m_frameStatusBar
->SetSize( 0, main_height
-wxSTATUS_HEIGHT
, width
, wxSTATUS_HEIGHT
);
296 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
297 event
.SetEventObject( this );
298 ProcessEvent( event
);
301 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
303 if ( GetAutoLayout() )
306 // no child: go out !
307 if (!GetChildren()->First())
310 // do we have exactly one child?
311 wxWindow
*child
= NULL
;
312 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
314 wxWindow
*win
= (wxWindow
*)node
->Data();
315 if (!IS_KIND_OF(win
,wxFrame
) && !IS_KIND_OF(win
,wxDialog
)
316 #if 0 // not in m_children anyway
317 && (win
!= m_frameMenuBar
) &&
318 (win
!= m_frameToolBar
) &&
319 (win
!= m_frameStatusBar
)
323 if ( child
) // it's the second one: do nothing
330 // yes: set it's size to fill all the frame
331 int client_x
, client_y
;
332 GetClientSize(&client_x
, &client_y
);
333 child
->SetSize( 1, 1, client_x
-2, client_y
);
337 void wxFrame::AddChild( wxWindow
*child
)
339 // wxFrame and wxDialog as children aren't placed into the parents
341 if (IS_KIND_OF(child
,wxMDIChildFrame
)) printf( "wxFrame::AddChild error.\n" );
343 if ( IS_KIND_OF(child
,wxFrame
) || IS_KIND_OF(child
,wxDialog
))
345 m_children
.Append( child
);
347 if ((child
->m_x
!= -1) && (child
->m_y
!= -1))
348 gtk_widget_set_uposition( child
->m_widget
, child
->m_x
, child
->m_y
);
353 if (m_addPrivateChild
)
355 gtk_myfixed_put( GTK_MYFIXED(m_mainWindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
357 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
361 m_children
.Append( child
);
364 gtk_myfixed_put( GTK_MYFIXED(m_wxwindow
), child
->m_widget
, child
->m_x
, child
->m_y
);
366 gtk_widget_set_usize( child
->m_widget
, child
->m_width
, child
->m_height
);
370 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
372 menu
->SetInvokingWindow( win
);
373 wxNode
*node
= menu
->m_items
.First();
376 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
377 if (menuitem
->IsSubMenu())
378 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
383 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
385 m_frameMenuBar
= menuBar
;
389 if (m_frameMenuBar
->m_parent
!= this)
391 wxNode
*node
= m_frameMenuBar
->m_menus
.First();
394 wxMenu
*menu
= (wxMenu
*)node
->Data();
395 SetInvokingWindow( menu
, this );
399 m_frameMenuBar
->m_parent
= this;
400 gtk_myfixed_put( GTK_MYFIXED(m_mainWindow
),
401 m_frameMenuBar
->m_widget
, m_frameMenuBar
->m_x
, m_frameMenuBar
->m_y
);
406 wxMenuBar
*wxFrame::GetMenuBar(void)
408 return m_frameMenuBar
;
411 wxToolBar
*wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
413 m_addPrivateChild
= TRUE
;
415 m_frameToolBar
= new wxToolBar( this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
417 m_addPrivateChild
= FALSE
;
419 return m_frameToolBar
;
422 wxToolBar
*wxFrame::GetToolBar(void)
424 return m_frameToolBar
;
427 wxStatusBar
* wxFrame::CreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
429 if (m_frameStatusBar
)
430 delete m_frameStatusBar
;
432 m_frameStatusBar
= new wxStatusBar( this, id
, wxPoint(0,0), wxSize(100,20), style
, name
);
434 m_frameStatusBar
->SetFieldsCount( number
);
436 return m_frameStatusBar
;
439 void wxFrame::SetStatusText( const wxString
&text
, int number
)
441 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusText( text
, number
);
444 void wxFrame::SetStatusWidths( int n
, int *width
)
446 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusWidths( n
, width
);
449 wxStatusBar
*wxFrame::GetStatusBar(void)
451 return m_frameStatusBar
;
454 void wxFrame::SetTitle( const wxString
&title
)
457 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
460 void wxFrame::SetSizeHints(int minW
, int minH
, int maxW
, int maxH
, int WXUNUSED(incW
) )
463 gdk_window_set_hints( m_wxwindow
->window
, -1, -1,
464 minW
, minH
, maxW
, maxH
, GDK_HINT_MIN_SIZE
| GDK_HINT_MIN_SIZE
);
467 void wxFrame::SetIcon( const wxIcon
&icon
)
470 if (!icon
.Ok()) return;
472 wxMask
*mask
= icon
.GetMask();
473 GdkBitmap
*bm
= NULL
;
474 if (mask
) bm
= mask
->GetBitmap();
476 gdk_window_set_icon( m_widget
->window
, NULL
, icon
.GetPixmap(), bm
);