]>
Commit | Line | Data |
---|---|---|
7c78e7c7 RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
5 | // Created: 01/02/97 | |
6 | // Id: | |
7 | // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifdef __GNUG__ | |
12 | #pragma implementation "frame.h" | |
13 | #endif | |
14 | ||
15 | #include "wx/frame.h" | |
16 | #include "wx/dialog.h" | |
17 | #include "wx/control.h" | |
18 | #include "wx/app.h" | |
19 | #include "wx/menu.h" | |
20 | #include "wx/toolbar.h" | |
21 | #include "wx/statusbr.h" | |
22 | #include "wx/mdi.h" | |
23 | ||
24 | const wxMENU_HEIGHT = 28; | |
25 | const wxSTATUS_HEIGHT = 25; | |
26 | ||
27 | extern wxList wxTopLevelWindows; | |
28 | extern wxList wxPendingDelete; | |
29 | ||
30 | //----------------------------------------------------------------------------- | |
31 | // wxFrame | |
32 | //----------------------------------------------------------------------------- | |
33 | ||
34 | //----------------------------------------------------------------------------- | |
35 | ||
36 | BEGIN_EVENT_TABLE(wxFrame, wxWindow) | |
37 | EVT_SIZE(wxFrame::OnSize) | |
38 | EVT_CLOSE(wxFrame::OnCloseWindow) | |
39 | EVT_IDLE(wxFrame::OnIdle) | |
40 | END_EVENT_TABLE() | |
41 | ||
42 | IMPLEMENT_DYNAMIC_CLASS(wxFrame,wxWindow) | |
43 | ||
44 | wxFrame::wxFrame() | |
45 | { | |
46 | wxTopLevelWindows.Insert( this ); | |
47 | }; | |
48 | ||
49 | wxFrame::wxFrame( wxWindow *parent, wxWindowID id, const wxString &title, | |
50 | const wxPoint &pos, const wxSize &size, | |
51 | long style, const wxString &name ) | |
52 | { | |
53 | Create( parent, id, title, pos, size, style, name ); | |
54 | wxTopLevelWindows.Insert( this ); | |
55 | }; | |
56 | ||
57 | bool wxFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title, | |
58 | const wxPoint &pos, const wxSize &size, | |
59 | long style, const wxString &name ) | |
60 | { | |
61 | m_title = title; | |
62 | ||
63 | return TRUE; | |
64 | }; | |
65 | ||
66 | wxFrame::~wxFrame() | |
67 | { | |
68 | if (m_frameMenuBar) delete m_frameMenuBar; | |
69 | if (m_frameStatusBar) delete m_frameStatusBar; | |
70 | ||
71 | wxTopLevelWindows.DeleteObject( this ); | |
72 | if (wxTopLevelWindows.Number() == 0) wxTheApp->ExitMainLoop(); | |
73 | }; | |
74 | ||
75 | bool wxFrame::Show( bool show ) | |
76 | { | |
77 | if (show) | |
78 | { | |
79 | wxSizeEvent event( wxSize(m_width,m_height), GetId() ); | |
80 | ProcessEvent( event ); | |
81 | }; | |
82 | return wxWindow::Show( show ); | |
83 | }; | |
84 | ||
85 | void wxFrame::Enable( bool enable ) | |
86 | { | |
87 | wxWindow::Enable( enable ); | |
88 | }; | |
89 | ||
90 | void wxFrame::OnCloseWindow( wxCloseEvent &event ) | |
91 | { | |
92 | if ( GetEventHandler()->OnClose() || event.GetForce()) | |
93 | { | |
94 | this->Destroy(); | |
95 | } | |
96 | }; | |
97 | ||
98 | bool wxFrame::Destroy() | |
99 | { | |
100 | if (!wxPendingDelete.Member(this)) | |
101 | wxPendingDelete.Append(this); | |
102 | ||
103 | return TRUE; | |
104 | } | |
105 | ||
106 | void wxFrame::GetClientSize( int *width, int *height ) const | |
107 | { | |
108 | wxWindow::GetClientSize( width, height ); | |
109 | if (height) | |
110 | { | |
111 | if (m_frameMenuBar) (*height) -= wxMENU_HEIGHT; | |
112 | if (m_frameStatusBar) (*height) -= wxSTATUS_HEIGHT; | |
113 | if (m_frameToolBar) | |
114 | { | |
115 | int y = 0; | |
116 | m_frameToolBar->GetSize( NULL, &y ); | |
117 | (*height) -= y; | |
118 | } | |
119 | }; | |
120 | }; | |
121 | ||
122 | ||
123 | void wxFrame::OnSize( wxSizeEvent &WXUNUSED(event) ) | |
124 | { | |
125 | if ( GetAutoLayout() ) | |
126 | Layout(); | |
127 | else { | |
128 | // no child: go out ! | |
129 | if (!GetChildren()->First()) | |
130 | return; | |
131 | ||
132 | // do we have exactly one child? | |
133 | wxWindow *child = NULL; | |
134 | for(wxNode *node = GetChildren()->First(); node; node = node->Next()) | |
135 | { | |
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) | |
142 | #endif | |
143 | ) | |
144 | { | |
145 | if ( child ) // it's the second one: do nothing | |
146 | return; | |
147 | ||
148 | child = win; | |
149 | }; | |
150 | }; | |
151 | ||
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); | |
156 | } | |
157 | }; | |
158 | ||
159 | static void SetInvokingWindow( wxMenu *menu, wxWindow *win ) | |
160 | { | |
161 | menu->SetInvokingWindow( win ); | |
162 | wxNode *node = menu->m_items.First(); | |
163 | while (node) | |
164 | { | |
165 | wxMenuItem *menuitem = (wxMenuItem*)node->Data(); | |
166 | if (menuitem->IsSubMenu()) | |
167 | SetInvokingWindow( menuitem->GetSubMenu(), win ); | |
168 | node = node->Next(); | |
169 | }; | |
170 | }; | |
171 | ||
172 | void wxFrame::SetMenuBar( wxMenuBar *menuBar ) | |
173 | { | |
174 | m_frameMenuBar = menuBar; | |
175 | ||
176 | if (m_frameMenuBar) | |
177 | { | |
178 | if (m_frameMenuBar->m_parent != this) | |
179 | { | |
180 | wxNode *node = m_frameMenuBar->m_menus.First(); | |
181 | while (node) | |
182 | { | |
183 | wxMenu *menu = (wxMenu*)node->Data(); | |
184 | SetInvokingWindow( menu, this ); | |
185 | node = node->Next(); | |
186 | }; | |
187 | ||
188 | } | |
189 | } | |
190 | }; | |
191 | ||
192 | wxMenuBar *wxFrame::GetMenuBar(void) | |
193 | { | |
194 | return m_frameMenuBar; | |
195 | }; | |
196 | ||
197 | wxToolBar *wxFrame::CreateToolBar( long style , wxWindowID id, const wxString& name ) | |
198 | { | |
199 | m_frameToolBar = new wxToolBar( this, id, wxDefaultPosition, wxDefaultSize, style, name ); | |
200 | ||
201 | return m_frameToolBar; | |
202 | }; | |
203 | ||
204 | wxToolBar *wxFrame::GetToolBar(void) | |
205 | { | |
206 | return m_frameToolBar; | |
207 | }; | |
208 | ||
209 | wxStatusBar* wxFrame::CreateStatusBar( int number, long style, wxWindowID id, const wxString& name ) | |
210 | { | |
211 | if (m_frameStatusBar) | |
212 | delete m_frameStatusBar; | |
213 | ||
214 | m_frameStatusBar = new wxStatusBar( this, id, wxPoint(0,0), wxSize(100,20), style, name ); | |
215 | ||
216 | m_frameStatusBar->SetFieldsCount( number ); | |
217 | ||
218 | return m_frameStatusBar; | |
219 | }; | |
220 | ||
221 | void wxFrame::SetStatusText( const wxString &text, int number ) | |
222 | { | |
223 | if (m_frameStatusBar) m_frameStatusBar->SetStatusText( text, number ); | |
224 | }; | |
225 | ||
226 | void wxFrame::SetStatusWidths( int n, int *width ) | |
227 | { | |
228 | if (m_frameStatusBar) m_frameStatusBar->SetStatusWidths( n, width ); | |
229 | }; | |
230 | ||
231 | wxStatusBar *wxFrame::GetStatusBar(void) | |
232 | { | |
233 | return m_frameStatusBar; | |
234 | }; | |
235 | ||
236 | void wxFrame::SetTitle( const wxString &title ) | |
237 | { | |
238 | m_title = title; | |
239 | }; | |
240 | ||
241 | void wxFrame::SetSizeHints( int WXUNUSED(minW), int WXUNUSED(minH), | |
242 | int WXUNUSED(maxW), int WXUNUSED(maxH), int WXUNUSED(incW) ) | |
243 | { | |
244 | } | |
245 | ||
246 | void wxFrame::SetIcon( const wxIcon &icon ) | |
247 | { | |
248 | m_icon = icon; | |
249 | if (!icon.Ok()) return; | |
250 | ||
251 | } | |
252 |