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"
19 #include "wx/gtk/win_gtk.h"
21 const wxMENU_HEIGHT
= 28;
22 const wxSTATUS_HEIGHT
= 25;
24 extern wxList wxTopLevelWindows
;
25 extern wxList wxPendingDelete
;
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 //-----------------------------------------------------------------------------
34 void gtk_frame_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* alloc
, wxFrame
*win
)
36 if (!win
->HasVMT()) return;
39 printf( "OnFrameResize from " );
40 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
41 printf( win->GetClassInfo()->GetClassName() );
45 win
->GtkOnSize( alloc
->x
, alloc
->y
, alloc
->width
, alloc
->height
);
48 //-----------------------------------------------------------------------------
51 bool gtk_frame_delete_callback( GtkWidget
*WXUNUSED(widget
), GdkEvent
*WXUNUSED(event
), wxFrame
*win
)
54 printf( "OnDelete from " );
55 if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
56 printf( win->GetClassInfo()->GetClassName() );
65 //-----------------------------------------------------------------------------
67 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
68 EVT_CLOSE(wxFrame::OnCloseWindow
)
69 EVT_SIZE(wxFrame::OnSize
)
72 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
74 wxFrame::wxFrame(void)
76 m_doingOnSize
= FALSE
;
77 m_frameMenuBar
= NULL
;
78 m_frameStatusBar
= NULL
;
80 wxTopLevelWindows
.Insert( this );
83 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
84 const wxPoint
&pos
, const wxSize
&size
,
85 long style
, const wxString
&name
)
88 Create( parent
, id
, title
, pos
, size
, style
, name
);
89 wxTopLevelWindows
.Insert( this );
92 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
93 const wxPoint
&pos
, const wxSize
&size
,
94 long style
, const wxString
&name
)
100 PreCreation( parent
, id
, pos
, size
, style
, name
);
102 m_doingOnSize
= FALSE
;
106 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
107 if ((size
.x
!= -1) && (size
.y
!= -1))
108 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
109 if ((pos
.x
!= -1) && (pos
.y
!= -1))
110 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
112 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
113 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
115 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
117 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
118 GTK_SIGNAL_FUNC(gtk_frame_delete_callback
), (gpointer
)this );
120 m_mainWindow
= gtk_myfixed_new();
121 gtk_widget_show( m_mainWindow
);
122 GTK_WIDGET_UNSET_FLAGS( m_mainWindow
, GTK_CAN_FOCUS
);
124 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWindow
);
125 gtk_widget_set_uposition( m_mainWindow
, 0, 0 );
127 m_wxwindow
= gtk_myfixed_new();
128 gtk_widget_show( m_wxwindow
);
129 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
131 gtk_container_add( GTK_CONTAINER(m_mainWindow
), m_wxwindow
);
133 m_frameMenuBar
= NULL
;
134 m_frameStatusBar
= NULL
;
136 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
137 GTK_SIGNAL_FUNC(gtk_frame_size_callback
), (gpointer
)this );
141 gtk_widget_realize( m_mainWindow
);
146 wxFrame::~wxFrame(void)
148 if (m_frameMenuBar
) delete m_frameMenuBar
;
149 if (m_frameStatusBar
) delete m_frameStatusBar
;
151 // if (m_mainWindow) gtk_widget_destroy( m_mainWindow );
153 wxTopLevelWindows
.DeleteObject( this );
154 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
157 bool wxFrame::Show( bool show
)
161 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
163 ProcessEvent( event
);
165 return wxWindow::Show( show
);
168 void wxFrame::Enable( bool enable
)
170 wxWindow::Enable( enable
);
171 gtk_widget_set_sensitive( m_mainWindow
, enable
);
174 void wxFrame::OnCloseWindow( wxCloseEvent
& WXUNUSED(event
) )
179 bool wxFrame::Destroy(void)
181 if (!wxPendingDelete
.Member(this))
182 wxPendingDelete
.Append(this);
187 void wxFrame::GetClientSize( int *width
, int *height
) const
189 wxWindow::GetClientSize( width
, height
);
192 if (m_frameMenuBar
) (*height
) -= wxMENU_HEIGHT
;
193 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
197 void wxFrame::GtkOnSize( int x
, int y
, int width
, int height
)
202 if ((m_height
== height
) && (m_width
== width
) &&
204 if (!m_mainWindow
) return;
205 if (!m_wxwindow
) return;
210 gtk_widget_set_usize( m_widget
, width
, height
);
214 int main_height
= height
;
215 int main_width
= width
;
217 // This emulates Windows behaviour:
218 // The menu bar is part of the main window, but the status bar
219 // is on the implementation side in the client area. The
220 // function GetClientSize returns the size of the client area
221 // minus the status bar height. Under wxGTK, the main window
222 // is represented by m_mainWindow. The menubar is inserted
223 // into m_mainWindow whereas the statusbar is insertes into
224 // m_wxwindow just like any other window.
227 gtk_widget_set_usize( m_mainWindow
, width
, height
);
231 main_y
= wxMENU_HEIGHT
;
232 main_height
-= wxMENU_HEIGHT
;
235 gtk_widget_set_uposition( GTK_WIDGET(m_wxwindow
), main_x
, main_y
);
236 gtk_widget_set_usize( GTK_WIDGET(m_wxwindow
), main_width
, main_height
);
240 gtk_widget_set_uposition( m_frameMenuBar
->m_widget
, 1, 1 );
241 gtk_widget_set_usize( m_frameMenuBar
->m_widget
, width
-2, wxMENU_HEIGHT
-2 );
244 if (m_frameStatusBar
)
246 m_frameStatusBar
->SetSize( 0, main_height
-wxSTATUS_HEIGHT
, width
, wxSTATUS_HEIGHT
);
251 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
252 event
.SetEventObject( this );
253 ProcessEvent( event
);
256 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
258 if ( GetAutoLayout() )
261 // no child: go out !
262 if (!GetChildren()->First())
265 // do we have exactly one child?
266 wxWindow
*child
= NULL
;
267 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
269 wxWindow
*win
= (wxWindow
*)node
->Data();
270 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
271 !win
->IsKindOf(CLASSINFO(wxDialog
))
272 #if 0 // not in m_children anyway
273 && (win
!= m_frameMenuBar
) &&
274 (win
!= m_frameStatusBar
)
278 if ( child
) // it's the second one: do nothing
285 // yes: set it's size to fill all the frame
286 int client_x
, client_y
;
287 GetClientSize(&client_x
, &client_y
);
288 child
->SetSize( 1, 1, client_x
-2, client_y
);
292 void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
294 menu
->SetInvokingWindow( win
);
295 wxNode
*node
= menu
->m_items
.First();
298 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
299 if (menuitem
->m_isSubMenu
) SetInvokingWindow( menuitem
->m_subMenu
, win
);
304 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
306 m_frameMenuBar
= menuBar
;
308 wxNode
*node
= m_frameMenuBar
->m_menus
.First();
311 wxMenu
*menu
= (wxMenu
*)node
->Data();
312 SetInvokingWindow( menu
, this );
316 m_frameMenuBar
->m_parent
= this;
317 gtk_myfixed_put( GTK_MYFIXED(m_mainWindow
),
318 m_frameMenuBar
->m_widget
, m_frameMenuBar
->m_x
, m_frameMenuBar
->m_y
);
321 bool wxFrame::CreateStatusBar( int number
)
323 if (m_frameStatusBar
)
324 delete m_frameStatusBar
;
326 m_frameStatusBar
= new wxStatusBar( this, -1, wxPoint(0,0), wxSize(100,20) );
328 m_frameStatusBar
->SetFieldsCount( number
);
332 void wxFrame::SetStatusText( const wxString
&text
, int number
)
334 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusText( text
, number
);
337 void wxFrame::SetStatusWidths( int n
, int *width
)
339 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusWidths( n
, width
);
342 wxStatusBar
*wxFrame::GetStatusBar(void)
344 return m_frameStatusBar
;
347 wxMenuBar
*wxFrame::GetMenuBar(void)
349 return m_frameMenuBar
;
352 void wxFrame::SetTitle( const wxString
&title
)
355 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
358 wxString
wxFrame::GetTitle(void) const
360 return (wxString
&)m_title
;