]>
Commit | Line | Data |
---|---|---|
2646f485 | 1 | ///////////////////////////////////////////////////////////////////////////// |
670f9935 | 2 | // Name: src/mac/classic/frame.cpp |
2646f485 SC |
3 | // Purpose: wxFrame |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
65571936 | 9 | // Licence: wxWindows licence |
2646f485 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
670f9935 WS |
12 | #include "wx/wxprec.h" |
13 | ||
2646f485 | 14 | #include "wx/frame.h" |
670f9935 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/app.h" | |
ed4b0fdc | 18 | #include "wx/dcclient.h" |
3b3dc801 | 19 | #include "wx/menu.h" |
670f9935 WS |
20 | #endif // WX_PRECOMP |
21 | ||
2646f485 SC |
22 | #include "wx/statusbr.h" |
23 | #include "wx/toolbar.h" | |
24 | #include "wx/menuitem.h" | |
2646f485 SC |
25 | #include "wx/dialog.h" |
26 | #include "wx/settings.h" | |
2646f485 SC |
27 | |
28 | #include "wx/mac/uma.h" | |
29 | ||
30 | extern wxWindowList wxModelessWindows; | |
31 | extern wxList wxPendingDelete; | |
32 | ||
2646f485 SC |
33 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
34 | EVT_ACTIVATE(wxFrame::OnActivate) | |
35 | // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight) | |
36 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
37 | // EVT_IDLE(wxFrame::OnIdle) | |
38 | // EVT_CLOSE(wxFrame::OnCloseWindow) | |
39 | END_EVENT_TABLE() | |
40 | ||
41 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) | |
2646f485 | 42 | |
670f9935 | 43 | #define WX_MAC_STATUSBAR_HEIGHT 15 |
2646f485 SC |
44 | // ---------------------------------------------------------------------------- |
45 | // creation/destruction | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | void wxFrame::Init() | |
49 | { | |
50 | m_frameMenuBar = NULL; | |
670f9935 | 51 | |
2646f485 SC |
52 | #if wxUSE_TOOLBAR |
53 | m_frameToolBar = NULL ; | |
54 | #endif | |
55 | m_frameStatusBar = NULL; | |
56 | m_winLastFocused = NULL ; | |
670f9935 WS |
57 | |
58 | m_iconized = false; | |
59 | ||
2646f485 SC |
60 | #if wxUSE_TOOLTIPS |
61 | m_hwndToolTip = 0; | |
62 | #endif | |
63 | } | |
64 | ||
65 | wxPoint wxFrame::GetClientAreaOrigin() const | |
66 | { | |
67 | // on mac we are at position -1,-1 with the control | |
68 | wxPoint pt(0, 0); | |
69 | ||
70 | #if wxUSE_TOOLBAR | |
71 | if ( GetToolBar() ) | |
72 | { | |
73 | int w, h; | |
74 | GetToolBar()->GetSize(& w, & h); | |
75 | ||
76 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
77 | { | |
78 | pt.x += w - 1; | |
79 | } | |
80 | else | |
81 | { | |
82 | pt.y += h - 1 ; | |
83 | } | |
84 | } | |
85 | #endif // wxUSE_TOOLBAR | |
86 | ||
87 | return pt; | |
88 | } | |
89 | ||
90 | bool wxFrame::Create(wxWindow *parent, | |
91 | wxWindowID id, | |
92 | const wxString& title, | |
93 | const wxPoint& pos, | |
94 | const wxSize& size, | |
95 | long style, | |
96 | const wxString& name) | |
97 | { | |
98 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
670f9935 | 99 | |
2646f485 | 100 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
670f9935 WS |
101 | return false; |
102 | ||
2646f485 SC |
103 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
104 | ||
105 | m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; | |
106 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ; | |
107 | ||
108 | wxModelessWindows.Append(this); | |
670f9935 WS |
109 | |
110 | return true; | |
2646f485 SC |
111 | } |
112 | ||
113 | wxFrame::~wxFrame() | |
114 | { | |
670f9935 | 115 | m_isBeingDeleted = true; |
2646f485 SC |
116 | DeleteAllBars(); |
117 | } | |
118 | ||
119 | ||
120 | bool wxFrame::Enable(bool enable) | |
121 | { | |
122 | if ( !wxWindow::Enable(enable) ) | |
670f9935 | 123 | return false; |
2646f485 SC |
124 | |
125 | if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) | |
126 | { | |
670f9935 | 127 | int iMaxMenu = m_frameMenuBar->GetMenuCount(); |
2646f485 SC |
128 | for ( int i = 0 ; i < iMaxMenu ; ++ i ) |
129 | { | |
130 | m_frameMenuBar->EnableTop( i , enable ) ; | |
131 | } | |
132 | } | |
133 | ||
670f9935 | 134 | return true; |
2646f485 SC |
135 | } |
136 | ||
137 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, | |
138 | const wxString& name) | |
139 | { | |
140 | wxStatusBar *statusBar = NULL; | |
141 | ||
142 | statusBar = new wxStatusBar(this, id, | |
143 | style, name); | |
144 | statusBar->SetSize( 100 , 15 ) ; | |
145 | statusBar->SetFieldsCount(number); | |
146 | return statusBar; | |
147 | } | |
148 | ||
149 | void wxFrame::PositionStatusBar() | |
150 | { | |
151 | if (m_frameStatusBar ) | |
152 | { | |
153 | int w, h; | |
154 | GetClientSize(&w, &h); | |
155 | int sw, sh; | |
156 | m_frameStatusBar->GetSize(&sw, &sh); | |
670f9935 | 157 | |
2646f485 SC |
158 | // Since we wish the status bar to be directly under the client area, |
159 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
160 | m_frameStatusBar->SetSize(0, h, w, sh); | |
161 | } | |
162 | } | |
163 | ||
164 | // Responds to colour changes, and passes event on to children. | |
165 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) | |
166 | { | |
167 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); | |
168 | Refresh(); | |
169 | ||
170 | if ( m_frameStatusBar ) | |
171 | { | |
172 | wxSysColourChangedEvent event2; | |
173 | event2.SetEventObject( m_frameStatusBar ); | |
174 | m_frameStatusBar->ProcessEvent(event2); | |
175 | } | |
176 | ||
177 | // Propagate the event to the non-top-level children | |
178 | wxWindow::OnSysColourChanged(event); | |
179 | } | |
180 | ||
181 | ||
182 | // Default activation behaviour - set the focus for the first child | |
183 | // subwindow found. | |
184 | void wxFrame::OnActivate(wxActivateEvent& event) | |
185 | { | |
186 | if ( !event.GetActive() ) | |
187 | { | |
188 | // remember the last focused child if it is our child | |
189 | m_winLastFocused = FindFocus(); | |
190 | ||
191 | // so we NULL it out if it's a child from some other frame | |
192 | wxWindow *win = m_winLastFocused; | |
193 | while ( win ) | |
194 | { | |
195 | if ( win->IsTopLevel() ) | |
196 | { | |
197 | if ( win != this ) | |
198 | { | |
199 | m_winLastFocused = NULL; | |
200 | } | |
201 | ||
202 | break; | |
203 | } | |
204 | ||
205 | win = win->GetParent(); | |
206 | } | |
207 | ||
208 | event.Skip(); | |
209 | } | |
210 | else | |
211 | { | |
212 | // restore focus to the child which was last focused | |
213 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
214 | : NULL; | |
215 | if ( !parent ) | |
216 | { | |
217 | parent = this; | |
218 | } | |
219 | ||
220 | wxSetFocusToChild(parent, &m_winLastFocused); | |
221 | ||
222 | if ( m_frameMenuBar != NULL ) | |
223 | { | |
224 | m_frameMenuBar->MacInstallMenuBar() ; | |
225 | } | |
226 | else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame))) | |
227 | { | |
228 | // Trying toplevel frame menbar | |
229 | if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() ) | |
230 | ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar(); | |
231 | } | |
232 | } | |
233 | } | |
234 | ||
235 | void wxFrame::DetachMenuBar() | |
236 | { | |
237 | if ( m_frameMenuBar ) | |
238 | { | |
239 | m_frameMenuBar->UnsetInvokingWindow(); | |
240 | } | |
241 | ||
242 | wxFrameBase::DetachMenuBar(); | |
243 | } | |
244 | ||
245 | void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) | |
246 | { | |
247 | wxFrameBase::AttachMenuBar(menuBar); | |
248 | ||
249 | if (m_frameMenuBar) | |
250 | { | |
251 | m_frameMenuBar->SetInvokingWindow( this ); | |
252 | } | |
253 | } | |
254 | ||
255 | void wxFrame::DoGetClientSize(int *x, int *y) const | |
256 | { | |
257 | wxWindow::DoGetClientSize( x , y ) ; | |
670f9935 | 258 | |
2646f485 SC |
259 | #if wxUSE_STATUSBAR |
260 | if ( GetStatusBar() && y ) | |
261 | { | |
262 | int statusX, statusY; | |
263 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
264 | *y -= statusY; | |
265 | } | |
266 | #endif // wxUSE_STATUSBAR | |
670f9935 | 267 | |
2646f485 SC |
268 | wxPoint pt(GetClientAreaOrigin()); |
269 | if ( y ) | |
270 | *y -= pt.y; | |
670f9935 | 271 | if ( x ) |
2646f485 SC |
272 | *x -= pt.x; |
273 | } | |
274 | ||
275 | void wxFrame::DoSetClientSize(int clientwidth, int clientheight) | |
276 | { | |
277 | int currentclientwidth , currentclientheight ; | |
278 | int currentwidth , currentheight ; | |
670f9935 | 279 | |
2646f485 SC |
280 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; |
281 | GetSize( ¤twidth , ¤theight ) ; | |
670f9935 | 282 | |
2646f485 SC |
283 | // find the current client size |
284 | ||
285 | // Find the difference between the entire window (title bar and all) | |
286 | // and the client area; add this to the new client size to move the | |
287 | // window | |
288 | ||
289 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
290 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
291 | } | |
292 | ||
293 | ||
294 | #if wxUSE_TOOLBAR | |
295 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) | |
296 | { | |
297 | if ( wxFrameBase::CreateToolBar(style, id, name) ) | |
298 | { | |
299 | PositionToolBar(); | |
300 | } | |
301 | ||
302 | return m_frameToolBar; | |
303 | } | |
304 | ||
305 | void wxFrame::PositionToolBar() | |
306 | { | |
307 | int cw, ch; | |
308 | ||
309 | cw = m_width ; | |
310 | ch = m_height ; | |
311 | ||
312 | if ( GetStatusBar() ) | |
313 | { | |
314 | int statusX, statusY; | |
315 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
316 | ch -= statusY; | |
317 | } | |
318 | ||
319 | if (GetToolBar()) | |
320 | { | |
321 | int tw, th; | |
322 | GetToolBar()->GetSize(& tw, & th); | |
323 | ||
324 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
325 | { | |
326 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
327 | // means, pretend we don't have toolbar/status bar, so we | |
328 | // have the original client size. | |
329 | GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); | |
330 | } | |
331 | else | |
332 | { | |
333 | // Use the 'real' position | |
334 | GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); | |
335 | } | |
336 | } | |
337 | } | |
338 | #endif |