]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
3 | // Purpose: wxFrame | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "frame.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/frame.h" | |
03e11df5 | 17 | #include "wx/statusbr.h" |
e9576ca5 SC |
18 | #include "wx/toolbar.h" |
19 | #include "wx/menuitem.h" | |
20 | #include "wx/menu.h" | |
21 | #include "wx/dcclient.h" | |
22 | #include "wx/dialog.h" | |
23 | #include "wx/settings.h" | |
24 | #include "wx/app.h" | |
25 | ||
519cb848 SC |
26 | #include <wx/mac/uma.h> |
27 | ||
e9576ca5 SC |
28 | extern wxList wxModelessWindows; |
29 | extern wxList wxPendingDelete; | |
30 | ||
2f1ae414 SC |
31 | #if !USE_SHARED_LIBRARY |
32 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) | |
33 | // EVT_SIZE(wxFrame::OnSize) | |
e9576ca5 | 34 | EVT_ACTIVATE(wxFrame::OnActivate) |
2f1ae414 | 35 | // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) |
e9576ca5 | 36 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) |
2f1ae414 SC |
37 | // EVT_IDLE(wxFrame::OnIdle) |
38 | // EVT_CLOSE(wxFrame::OnCloseWindow) | |
e9576ca5 SC |
39 | END_EVENT_TABLE() |
40 | ||
41 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) | |
2f1ae414 | 42 | #endif |
e9576ca5 SC |
43 | |
44 | #if wxUSE_NATIVE_STATUSBAR | |
45 | bool wxFrame::m_useNativeStatusBar = TRUE; | |
46 | #else | |
47 | bool wxFrame::m_useNativeStatusBar = FALSE; | |
48 | #endif | |
49 | ||
2f1ae414 SC |
50 | #define WX_MAC_STATUSBAR_HEIGHT 15 |
51 | // ---------------------------------------------------------------------------- | |
52 | // creation/destruction | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | void wxFrame::Init() | |
e9576ca5 | 56 | { |
2f1ae414 SC |
57 | m_iconized = FALSE; |
58 | ||
59 | #if wxUSE_TOOLTIPS | |
60 | m_hwndToolTip = 0; | |
519cb848 | 61 | #endif |
2f1ae414 | 62 | } |
e7549107 | 63 | |
2f1ae414 SC |
64 | wxPoint wxFrame::GetClientAreaOrigin() const |
65 | { | |
66 | // on mac we are at position -1,-1 with the control | |
67 | wxPoint pt(0, 0); | |
68 | ||
69 | #if wxUSE_TOOLBAR | |
70 | if ( GetToolBar() ) | |
71 | { | |
72 | int w, h; | |
73 | GetToolBar()->GetSize(& w, & h); | |
74 | ||
75 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
76 | { | |
77 | pt.x += w - 1; | |
78 | } | |
79 | else | |
80 | { | |
81 | pt.y += h - 1 ; | |
82 | } | |
83 | } | |
84 | #endif // wxUSE_TOOLBAR | |
85 | ||
86 | return pt; | |
e9576ca5 SC |
87 | } |
88 | ||
89 | bool wxFrame::Create(wxWindow *parent, | |
90 | wxWindowID id, | |
91 | const wxString& title, | |
92 | const wxPoint& pos, | |
93 | const wxSize& size, | |
94 | long style, | |
95 | const wxString& name) | |
96 | { | |
e9576ca5 | 97 | m_frameMenuBar = NULL; |
519cb848 SC |
98 | |
99 | #if wxUSE_TOOLBAR | |
e9576ca5 | 100 | m_frameToolBar = NULL ; |
519cb848 | 101 | #endif |
e9576ca5 SC |
102 | m_frameStatusBar = NULL; |
103 | ||
104 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
105 | ||
106 | if ( id > -1 ) | |
107 | m_windowId = id; | |
108 | else | |
109 | m_windowId = (int)NewControlId(); | |
110 | ||
111 | if (parent) parent->AddChild(this); | |
112 | ||
2f1ae414 SC |
113 | if (!parent) |
114 | wxTopLevelWindows.Append(this); | |
519cb848 | 115 | |
2f1ae414 SC |
116 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
117 | ||
118 | m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; | |
519cb848 | 119 | |
2f1ae414 | 120 | wxModelessWindows.Append(this); |
519cb848 | 121 | |
519cb848 | 122 | return TRUE; |
e9576ca5 SC |
123 | } |
124 | ||
125 | wxFrame::~wxFrame() | |
126 | { | |
2f1ae414 | 127 | m_isBeingDeleted = TRUE; |
e9576ca5 SC |
128 | wxTopLevelWindows.DeleteObject(this); |
129 | ||
2f1ae414 | 130 | DeleteAllBars(); |
e9576ca5 SC |
131 | |
132 | /* Check if it's the last top-level window */ | |
133 | ||
134 | if (wxTheApp && (wxTopLevelWindows.Number() == 0)) | |
135 | { | |
136 | wxTheApp->SetTopWindow(NULL); | |
137 | ||
138 | if (wxTheApp->GetExitOnFrameDelete()) | |
139 | { | |
519cb848 | 140 | wxTheApp->ExitMainLoop() ; |
e9576ca5 SC |
141 | } |
142 | } | |
143 | ||
144 | wxModelessWindows.DeleteObject(this); | |
145 | } | |
146 | ||
e9576ca5 | 147 | |
2f1ae414 | 148 | bool wxFrame::Enable(bool enable) |
e9576ca5 | 149 | { |
2f1ae414 SC |
150 | if ( !wxWindow::Enable(enable) ) |
151 | return FALSE; | |
e9576ca5 | 152 | |
2f1ae414 SC |
153 | if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) |
154 | { | |
155 | for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i ) | |
156 | { | |
157 | m_frameMenuBar->EnableTop( i , enable ) ; | |
158 | } | |
159 | } | |
160 | ||
161 | return TRUE; | |
162 | } | |
e9576ca5 SC |
163 | // Equivalent to maximize/restore in Windows |
164 | void wxFrame::Maximize(bool maximize) | |
165 | { | |
166 | // TODO | |
167 | } | |
168 | ||
169 | bool wxFrame::IsIconized() const | |
170 | { | |
171 | // TODO | |
172 | return FALSE; | |
173 | } | |
174 | ||
2f1ae414 SC |
175 | void wxFrame::Iconize(bool iconize) |
176 | { | |
177 | // TODO | |
178 | } | |
179 | ||
e9576ca5 SC |
180 | // Is the frame maximized? |
181 | bool wxFrame::IsMaximized(void) const | |
182 | { | |
183 | // TODO | |
184 | return FALSE; | |
185 | } | |
186 | ||
2f1ae414 SC |
187 | void wxFrame::Restore() |
188 | { | |
189 | // TODO | |
190 | } | |
191 | ||
e9576ca5 SC |
192 | void wxFrame::SetIcon(const wxIcon& icon) |
193 | { | |
2f1ae414 | 194 | wxFrameBase::SetIcon(icon); |
e9576ca5 SC |
195 | } |
196 | ||
197 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, | |
198 | const wxString& name) | |
199 | { | |
200 | wxStatusBar *statusBar = NULL; | |
201 | ||
5b781a67 SC |
202 | statusBar = new wxStatusBar(this, id, |
203 | style, name); | |
204 | statusBar->SetSize( 100 , 15 ) ; | |
e9576ca5 SC |
205 | statusBar->SetFieldsCount(number); |
206 | return statusBar; | |
207 | } | |
208 | ||
e9576ca5 SC |
209 | void wxFrame::PositionStatusBar() |
210 | { | |
519cb848 SC |
211 | if (m_frameStatusBar ) |
212 | { | |
e9576ca5 SC |
213 | int w, h; |
214 | GetClientSize(&w, &h); | |
215 | int sw, sh; | |
216 | m_frameStatusBar->GetSize(&sw, &sh); | |
217 | ||
218 | // Since we wish the status bar to be directly under the client area, | |
219 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
5b781a67 | 220 | m_frameStatusBar->SetSize(0, h, w, sh); |
519cb848 | 221 | } |
e9576ca5 SC |
222 | } |
223 | ||
224 | void wxFrame::SetMenuBar(wxMenuBar *menuBar) | |
225 | { | |
226 | if (!menuBar) | |
227 | { | |
e9576ca5 SC |
228 | return; |
229 | } | |
230 | ||
2f1ae414 | 231 | m_frameMenuBar = NULL; |
e9576ca5 | 232 | m_frameMenuBar = menuBar; |
519cb848 | 233 | m_frameMenuBar->MacInstallMenuBar() ; |
2f1ae414 | 234 | m_frameMenuBar->Attach(this); |
e9576ca5 SC |
235 | } |
236 | ||
e9576ca5 SC |
237 | |
238 | // Responds to colour changes, and passes event on to children. | |
239 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
240 | { | |
241 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
242 | Refresh(); | |
243 | ||
244 | if ( m_frameStatusBar ) | |
245 | { | |
246 | wxSysColourChangedEvent event2; | |
247 | event2.SetEventObject( m_frameStatusBar ); | |
248 | m_frameStatusBar->ProcessEvent(event2); | |
249 | } | |
250 | ||
251 | // Propagate the event to the non-top-level children | |
252 | wxWindow::OnSysColourChanged(event); | |
253 | } | |
254 | ||
e9576ca5 SC |
255 | |
256 | // Default activation behaviour - set the focus for the first child | |
257 | // subwindow found. | |
258 | void wxFrame::OnActivate(wxActivateEvent& event) | |
259 | { | |
2f1ae414 | 260 | if ( !event.GetActive() ) |
e9576ca5 | 261 | { |
2f1ae414 SC |
262 | event.Skip(); |
263 | return; | |
e9576ca5 | 264 | } |
e9576ca5 | 265 | |
2f1ae414 SC |
266 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
267 | node; | |
268 | node = node->GetNext() ) | |
e9576ca5 | 269 | { |
2f1ae414 SC |
270 | // FIXME all this is totally bogus - we need to do the same as wxPanel, |
271 | // but how to do it without duplicating the code? | |
e9576ca5 | 272 | |
2f1ae414 SC |
273 | // restore focus |
274 | wxWindow *child = node->GetData(); | |
e9576ca5 | 275 | |
2f1ae414 | 276 | if ( !child->IsTopLevel() |
519cb848 | 277 | #if wxUSE_TOOLBAR |
2f1ae414 SC |
278 | && !wxDynamicCast(child, wxToolBar) |
279 | #endif // wxUSE_TOOLBAR | |
280 | #if wxUSE_STATUSBAR | |
281 | && !wxDynamicCast(child, wxStatusBar) | |
282 | #endif // wxUSE_STATUSBAR | |
283 | ) | |
e9576ca5 | 284 | { |
2f1ae414 SC |
285 | child->SetFocus(); |
286 | return; | |
e9576ca5 SC |
287 | } |
288 | } | |
e9576ca5 SC |
289 | } |
290 | ||
7c74e7fe | 291 | void wxFrame::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 292 | { |
7c74e7fe | 293 | wxWindow::DoGetClientSize( x , y ) ; |
519cb848 | 294 | |
2f1ae414 | 295 | #if wxUSE_STATUSBAR |
519cb848 SC |
296 | if ( GetStatusBar() ) |
297 | { | |
298 | int statusX, statusY; | |
299 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
5b781a67 | 300 | *y -= statusY; |
519cb848 | 301 | } |
2f1ae414 | 302 | #endif // wxUSE_STATUSBAR |
519cb848 SC |
303 | |
304 | wxPoint pt(GetClientAreaOrigin()); | |
305 | *y -= pt.y; | |
306 | *x -= pt.x; | |
e9576ca5 SC |
307 | } |
308 | ||
519cb848 | 309 | void wxFrame::DoSetClientSize(int clientwidth, int clientheight) |
e9576ca5 | 310 | { |
519cb848 SC |
311 | int currentclientwidth , currentclientheight ; |
312 | int currentwidth , currentheight ; | |
313 | ||
314 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
315 | GetSize( ¤twidth , ¤theight ) ; | |
316 | ||
317 | // find the current client size | |
318 | ||
319 | // Find the difference between the entire window (title bar and all) | |
320 | // and the client area; add this to the new client size to move the | |
321 | // window | |
322 | ||
323 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
324 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
e9576ca5 SC |
325 | } |
326 | ||
519cb848 SC |
327 | |
328 | #if wxUSE_TOOLBAR | |
e9576ca5 SC |
329 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
330 | { | |
2f1ae414 | 331 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
e9576ca5 | 332 | { |
e9576ca5 | 333 | PositionToolBar(); |
e9576ca5 | 334 | } |
e9576ca5 | 335 | |
2f1ae414 | 336 | return m_frameToolBar; |
e9576ca5 SC |
337 | } |
338 | ||
339 | void wxFrame::PositionToolBar() | |
340 | { | |
341 | int cw, ch; | |
342 | ||
2f1ae414 SC |
343 | cw = m_width ; |
344 | ch = m_height ; | |
e9576ca5 SC |
345 | |
346 | if ( GetStatusBar() ) | |
347 | { | |
348 | int statusX, statusY; | |
349 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
350 | ch -= statusY; | |
351 | } | |
352 | ||
353 | if (GetToolBar()) | |
354 | { | |
355 | int tw, th; | |
356 | GetToolBar()->GetSize(& tw, & th); | |
357 | ||
358 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
359 | { | |
360 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
361 | // means, pretend we don't have toolbar/status bar, so we | |
362 | // have the original client size. | |
2f1ae414 | 363 | GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); |
e9576ca5 SC |
364 | } |
365 | else | |
366 | { | |
367 | // Use the 'real' position | |
2f1ae414 | 368 | GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); |
e9576ca5 SC |
369 | } |
370 | } | |
371 | } | |
519cb848 | 372 | #endif |