]>
git.saurik.com Git - wxWidgets.git/blob - src/qt/frame.cpp
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"
24 const wxMENU_HEIGHT
= 28;
25 const wxSTATUS_HEIGHT
= 25;
27 extern wxList wxTopLevelWindows
;
28 extern wxList wxPendingDelete
;
30 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 BEGIN_EVENT_TABLE(wxFrame
, wxWindow
)
37 EVT_SIZE(wxFrame::OnSize
)
38 EVT_CLOSE(wxFrame::OnCloseWindow
)
39 EVT_IDLE(wxFrame::OnIdle
)
42 IMPLEMENT_DYNAMIC_CLASS(wxFrame
,wxWindow
)
46 wxTopLevelWindows
.Insert( this );
49 wxFrame::wxFrame( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
50 const wxPoint
&pos
, const wxSize
&size
,
51 long style
, const wxString
&name
)
53 Create( parent
, id
, title
, pos
, size
, style
, name
);
54 wxTopLevelWindows
.Insert( this );
57 bool wxFrame::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&title
,
58 const wxPoint
&pos
, const wxSize
&size
,
59 long style
, const wxString
&name
)
68 if (m_frameMenuBar
) delete m_frameMenuBar
;
69 if (m_frameStatusBar
) delete m_frameStatusBar
;
71 wxTopLevelWindows
.DeleteObject( this );
72 if (wxTopLevelWindows
.Number() == 0) wxTheApp
->ExitMainLoop();
75 bool wxFrame::Show( bool show
)
79 wxSizeEvent
event( wxSize(m_width
,m_height
), GetId() );
80 ProcessEvent( event
);
82 return wxWindow::Show( show
);
85 void wxFrame::Enable( bool enable
)
87 wxWindow::Enable( enable
);
90 void wxFrame::OnCloseWindow( wxCloseEvent
&event
)
92 if ( GetEventHandler()->OnClose() || event
.GetForce())
98 bool wxFrame::Destroy()
100 if (!wxPendingDelete
.Member(this))
101 wxPendingDelete
.Append(this);
106 void wxFrame::GetClientSize( int *width
, int *height
) const
108 wxWindow::GetClientSize( width
, height
);
111 if (m_frameMenuBar
) (*height
) -= wxMENU_HEIGHT
;
112 if (m_frameStatusBar
) (*height
) -= wxSTATUS_HEIGHT
;
116 m_frameToolBar
->GetSize( NULL
, &y
);
123 void wxFrame::OnSize( wxSizeEvent
&WXUNUSED(event
) )
125 if ( GetAutoLayout() )
128 // no child: go out !
129 if (!GetChildren()->First())
132 // do we have exactly one child?
133 wxWindow
*child
= NULL
;
134 for(wxNode
*node
= GetChildren()->First(); node
; node
= node
->Next())
136 wxWindow
*win
= (wxWindow
*)node
->Data();
137 if (!IS_KIND_OF(win
,wxFrame
) && !IS_KIND_OF(win
,wxDialog
)
138 #if 0 // not in m_children anyway
139 && (win
!= m_frameMenuBar
) &&
140 (win
!= m_frameToolBar
) &&
141 (win
!= m_frameStatusBar
)
145 if ( child
) // it's the second one: do nothing
152 // yes: set it's size to fill all the frame
153 int client_x
, client_y
;
154 GetClientSize(&client_x
, &client_y
);
155 child
->SetSize( 1, 1, client_x
-2, client_y
);
159 static void SetInvokingWindow( wxMenu
*menu
, wxWindow
*win
)
161 menu
->SetInvokingWindow( win
);
162 wxNode
*node
= menu
->m_items
.First();
165 wxMenuItem
*menuitem
= (wxMenuItem
*)node
->Data();
166 if (menuitem
->IsSubMenu())
167 SetInvokingWindow( menuitem
->GetSubMenu(), win
);
172 void wxFrame::SetMenuBar( wxMenuBar
*menuBar
)
174 m_frameMenuBar
= menuBar
;
178 if (m_frameMenuBar
->m_parent
!= this)
180 wxNode
*node
= m_frameMenuBar
->m_menus
.First();
183 wxMenu
*menu
= (wxMenu
*)node
->Data();
184 SetInvokingWindow( menu
, this );
192 wxMenuBar
*wxFrame::GetMenuBar(void)
194 return m_frameMenuBar
;
197 wxToolBar
*wxFrame::CreateToolBar( long style
, wxWindowID id
, const wxString
& name
)
199 m_frameToolBar
= new wxToolBar( this, id
, wxDefaultPosition
, wxDefaultSize
, style
, name
);
201 return m_frameToolBar
;
204 wxToolBar
*wxFrame::GetToolBar(void)
206 return m_frameToolBar
;
209 wxStatusBar
* wxFrame::CreateStatusBar( int number
, long style
, wxWindowID id
, const wxString
& name
)
211 if (m_frameStatusBar
)
212 delete m_frameStatusBar
;
214 m_frameStatusBar
= new wxStatusBar( this, id
, wxPoint(0,0), wxSize(100,20), style
, name
);
216 m_frameStatusBar
->SetFieldsCount( number
);
218 return m_frameStatusBar
;
221 void wxFrame::SetStatusText( const wxString
&text
, int number
)
223 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusText( text
, number
);
226 void wxFrame::SetStatusWidths( int n
, int *width
)
228 if (m_frameStatusBar
) m_frameStatusBar
->SetStatusWidths( n
, width
);
231 wxStatusBar
*wxFrame::GetStatusBar(void)
233 return m_frameStatusBar
;
236 void wxFrame::SetTitle( const wxString
&title
)
241 void wxFrame::SetSizeHints( int WXUNUSED(minW
), int WXUNUSED(minH
),
242 int WXUNUSED(maxW
), int WXUNUSED(maxH
), int WXUNUSED(incW
) )
246 void wxFrame::SetIcon( const wxIcon
&icon
)
249 if (!icon
.Ok()) return;