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
)
70 EVT_IDLE(wxFrame::OnIdle
)
73 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
75 wxFrame::wxFrame(void)
77 m_doingOnSize
= FALSE
;
78 m_frameMenuBar
= NULL
;
79 m_frameStatusBar
= NULL
;
81 wxTopLevelWindows
.Insert( this );
84 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
85 const wxPoint
&pos
, const wxSize
&size
,
86 long style
, const wxString
&name
)
89 Create( parent
, id
, title
, pos
, size
, style
, name
);
90 wxTopLevelWindows
.Insert( this );
93 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
94 const wxPoint
&pos
, const wxSize
&size
,
95 long style
, const wxString
&name
)
101 PreCreation( parent
, id
, pos
, size
, style
, name
);
103 m_doingOnSize
= FALSE
;
107 m_widget
= gtk_window_new( GTK_WINDOW_TOPLEVEL
);
108 if ((size
.x
!= -1) && (size
.y
!= -1))
109 gtk_widget_set_usize( m_widget
, m_width
, m_height
);
110 if ((pos
.x
!= -1) && (pos
.y
!= -1))
111 gtk_widget_set_uposition( m_widget
, m_x
, m_y
);
113 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
114 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
116 gtk_widget_set( m_widget
, "GtkWindow::allow_shrink", TRUE
, NULL
);
118 gtk_signal_connect( GTK_OBJECT(m_widget
), "delete_event",
119 GTK_SIGNAL_FUNC(gtk_frame_delete_callback
), (gpointer
)this );
121 m_mainWindow
= gtk_myfixed_new();
122 gtk_widget_show( m_mainWindow
);
123 GTK_WIDGET_UNSET_FLAGS( m_mainWindow
, GTK_CAN_FOCUS
);
125 gtk_container_add( GTK_CONTAINER(m_widget
), m_mainWindow
);
126 gtk_widget_set_uposition( m_mainWindow
, 0, 0 );
128 m_wxwindow
= gtk_myfixed_new();
129 gtk_widget_show( m_wxwindow
);
130 GTK_WIDGET_UNSET_FLAGS( m_wxwindow
, GTK_CAN_FOCUS
);
132 gtk_container_add( GTK_CONTAINER(m_mainWindow
), m_wxwindow
);
134 m_frameMenuBar
= NULL
;
135 m_frameStatusBar
= NULL
;
137 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
138 GTK_SIGNAL_FUNC(gtk_frame_size_callback
), (gpointer
)this );
142 gtk_widget_realize( m_mainWindow
);
147 wxFrame::~wxFrame(void)
149 if (m_frameMenuBar
) delete m_frameMenuBar
;
150 if (m_frameStatusBar
) delete m_frameStatusBar
;
152 // if (m_mainWindow) gtk_widget_destroy( m_mainWindow );
154 wxTopLevelWindows
.DeleteObject( this );
155 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
158 bool wxFrame::Show( bool show
)
162 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
164 ProcessEvent( event
);
166 return wxWindow::Show( show
);
169 void wxFrame::Enable( bool enable
)
171 wxWindow::Enable( enable
);
172 gtk_widget_set_sensitive( m_mainWindow
, enable
);
175 void wxFrame::OnCloseWindow( wxCloseEvent
& WXUNUSED(event
) )
180 bool wxFrame::Destroy(void)
182 if (!wxPendingDelete
.Member(this))
183 wxPendingDelete
.Append(this);
188 void wxFrame::GetClientSize( int *width
, int *height
) const
190 wxWindow::GetClientSize( width
, height
);
193 if (m_frameMenuBar
) (*height
) -= wxMENU_HEIGHT
;
194 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
198 void wxFrame::GtkOnSize( int x
, int y
, int width
, int height
)
203 if ((m_height
== height
) && (m_width
== width
) &&
205 if (!m_mainWindow
) return;
206 if (!m_wxwindow
) return;
211 gtk_widget_set_usize( m_widget
, width
, height
);
215 int main_height
= height
;
216 int main_width
= width
;
218 // This emulates Windows behaviour:
219 // The menu bar is part of the main window, but the status bar
220 // is on the implementation side in the client area. The
221 // function GetClientSize returns the size of the client area
222 // minus the status bar height. Under wxGTK, the main window
223 // is represented by m_mainWindow. The menubar is inserted
224 // into m_mainWindow whereas the statusbar is insertes into
225 // m_wxwindow just like any other window.
228 gtk_widget_set_usize( m_mainWindow
, width
, height
);
232 main_y
= wxMENU_HEIGHT
;
233 main_height
-= wxMENU_HEIGHT
;
236 gtk_widget_set_uposition( GTK_WIDGET(m_wxwindow
), main_x
, main_y
);
237 gtk_widget_set_usize( GTK_WIDGET(m_wxwindow
), main_width
, main_height
);
241 gtk_widget_set_uposition( m_frameMenuBar
->m_widget
, 1, 1 );
242 gtk_widget_set_usize( m_frameMenuBar
->m_widget
, width
-2, wxMENU_HEIGHT
-2 );
245 if (m_frameStatusBar
)
247 m_frameStatusBar
->SetSize( 0, main_height
-wxSTATUS_HEIGHT
, width
, wxSTATUS_HEIGHT
);
252 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
253 event
.SetEventObject( this );
254 ProcessEvent( event
);
257 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
259 if ( GetAutoLayout() )
262 // no child: go out !
263 if (!GetChildren()->First())
266 // do we have exactly one child?
267 wxWindow
*child
= NULL
;
268 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
270 wxWindow
*win
= (wxWindow
*)node
->Data();
271 if (!win
->IsKindOf(CLASSINFO(wxFrame
)) &&
272 !win
->IsKindOf(CLASSINFO(wxDialog
))
273 #if 0 // not in m_children anyway
274 && (win
!= m_frameMenuBar
) &&
275 (win
!= m_frameStatusBar
)
279 if ( child
) // it's the second one: do nothing
286 // yes: set it's size to fill all the frame
287 int client_x
, client_y
;
288 GetClientSize(&client_x
, &client_y
);
289 child
->SetSize( 1, 1, client_x
-2, client_y
);
293 void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
295 menu
->SetInvokingWindow( win
);
296 wxNode
*node
= menu
->m_items
.First();
299 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
300 if (menuitem
->m_isSubMenu
) SetInvokingWindow( menuitem
->m_subMenu
, win
);
305 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
307 m_frameMenuBar
= menuBar
;
309 wxNode
*node
= m_frameMenuBar
->m_menus
.First();
312 wxMenu
*menu
= (wxMenu
*)node
->Data();
313 SetInvokingWindow( menu
, this );
317 m_frameMenuBar
->m_parent
= this;
318 gtk_myfixed_put( GTK_MYFIXED(m_mainWindow
),
319 m_frameMenuBar
->m_widget
, m_frameMenuBar
->m_x
, m_frameMenuBar
->m_y
);
322 bool wxFrame::CreateStatusBar( int number
)
324 if (m_frameStatusBar
)
325 delete m_frameStatusBar
;
327 m_frameStatusBar
= new wxStatusBar( this, -1, wxPoint(0,0), wxSize(100,20) );
329 m_frameStatusBar
->SetFieldsCount( number
);
333 void wxFrame::SetStatusText( const wxString
&text
, int number
)
335 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusText( text
, number
);
338 void wxFrame::SetStatusWidths( int n
, int *width
)
340 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusWidths( n
, width
);
343 wxStatusBar
*wxFrame::GetStatusBar(void)
345 return m_frameStatusBar
;
348 wxMenuBar
*wxFrame::GetMenuBar(void)
350 return m_frameMenuBar
;
353 void wxFrame::SetTitle( const wxString
&title
)
356 gtk_window_set_title( GTK_WINDOW(m_widget
), title
);
359 wxString
wxFrame::GetTitle(void) const
361 return (wxString
&)m_title
;
364 void wxFrame::OnIdle(wxIdleEvent
& WXUNUSED(event
))
369 // Query app for menu item updates (called from OnIdle)
370 void wxFrame::DoMenuUpdates(void)
372 wxMenuBar
* bar
= GetMenuBar();
375 wxNode
*node
= bar
->m_menus
.First();
378 wxMenu
* menu
= (wxMenu
*)node
->Data();
385 void wxFrame::DoMenuUpdates(wxMenu
* menu
)
387 wxNode
* node
= menu
->m_items
.First();
390 wxMenuItem
* item
= (wxMenuItem
*) node
->Data();
391 if ( !item
->IsSeparator() )
393 wxWindowID id
= item
->GetId();
394 wxUpdateUIEvent
event(id
);
395 event
.SetEventObject( this );
397 if (GetEventHandler()->ProcessEvent(event
))
399 if (event
.GetSetText())
400 menu
->SetLabel(id
, event
.GetText());
401 if (event
.GetSetChecked())
402 menu
->Check(id
, event
.GetChecked());
403 if (event
.GetSetEnabled())
404 menu
->Enable(id
, event
.GetEnabled());
407 if (item
->GetSubMenu())
408 DoMenuUpdates(item
->GetSubMenu());