]> git.saurik.com Git - wxWidgets.git/blob - src/mac/frame.cpp
Changed WXUNUSED to WXUNUSED_UNLESS_DEBUG
[wxWidgets.git] / src / mac / frame.cpp
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"
17 #include "wx/statusbr.h"
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
26 #include <wx/mac/uma.h>
27
28 extern wxList wxModelessWindows;
29 extern wxList wxPendingDelete;
30
31 #if !USE_SHARED_LIBRARY
32 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
33 // EVT_SIZE(wxFrame::OnSize)
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, wxWindow)
42 #endif
43
44 #if wxUSE_NATIVE_STATUSBAR
45 bool wxFrame::m_useNativeStatusBar = TRUE;
46 #else
47 bool wxFrame::m_useNativeStatusBar = FALSE;
48 #endif
49
50 #define WX_MAC_STATUSBAR_HEIGHT 15
51 // ----------------------------------------------------------------------------
52 // creation/destruction
53 // ----------------------------------------------------------------------------
54
55 void wxFrame::Init()
56 {
57 m_iconized = FALSE;
58
59 #if wxUSE_TOOLTIPS
60 m_hwndToolTip = 0;
61 #endif
62 }
63
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;
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 {
97 m_frameMenuBar = NULL;
98
99 #if wxUSE_TOOLBAR
100 m_frameToolBar = NULL ;
101 #endif
102 m_frameStatusBar = NULL;
103 m_winLastFocused = NULL ;
104
105 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
106
107 if ( id > -1 )
108 m_windowId = id;
109 else
110 m_windowId = (int)NewControlId();
111
112 if (parent) parent->AddChild(this);
113
114 if (!parent)
115 wxTopLevelWindows.Append(this);
116
117 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
118
119 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
120
121 wxModelessWindows.Append(this);
122
123 return TRUE;
124 }
125
126 wxFrame::~wxFrame()
127 {
128 m_isBeingDeleted = TRUE;
129 wxTopLevelWindows.DeleteObject(this);
130
131 DeleteAllBars();
132
133 /* Check if it's the last top-level window */
134
135 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
136 {
137 wxTheApp->SetTopWindow(NULL);
138
139 if (wxTheApp->GetExitOnFrameDelete())
140 {
141 wxTheApp->ExitMainLoop() ;
142 }
143 }
144
145 wxModelessWindows.DeleteObject(this);
146 }
147
148
149 bool wxFrame::Enable(bool enable)
150 {
151 if ( !wxWindow::Enable(enable) )
152 return FALSE;
153
154 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
155 {
156 for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i )
157 {
158 m_frameMenuBar->EnableTop( i , enable ) ;
159 }
160 }
161
162 return TRUE;
163 }
164 // Equivalent to maximize/restore in Windows
165 void wxFrame::Maximize(bool maximize)
166 {
167 // TODO
168 }
169
170 bool wxFrame::IsIconized() const
171 {
172 // TODO
173 return FALSE;
174 }
175
176 void wxFrame::Iconize(bool iconize)
177 {
178 // TODO
179 }
180
181 // Is the frame maximized?
182 bool wxFrame::IsMaximized(void) const
183 {
184 // TODO
185 return FALSE;
186 }
187
188 void wxFrame::Restore()
189 {
190 // TODO
191 }
192
193 void wxFrame::SetIcon(const wxIcon& icon)
194 {
195 wxFrameBase::SetIcon(icon);
196 }
197
198 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
199 const wxString& name)
200 {
201 wxStatusBar *statusBar = NULL;
202
203 statusBar = new wxStatusBar(this, id,
204 style, name);
205 statusBar->SetSize( 100 , 15 ) ;
206 statusBar->SetFieldsCount(number);
207 return statusBar;
208 }
209
210 void wxFrame::PositionStatusBar()
211 {
212 if (m_frameStatusBar )
213 {
214 int w, h;
215 GetClientSize(&w, &h);
216 int sw, sh;
217 m_frameStatusBar->GetSize(&sw, &sh);
218
219 // Since we wish the status bar to be directly under the client area,
220 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
221 m_frameStatusBar->SetSize(0, h, w, sh);
222 }
223 }
224
225 void wxFrame::SetMenuBar(wxMenuBar *menuBar)
226 {
227 if (!menuBar)
228 {
229 return;
230 }
231
232 m_frameMenuBar = NULL;
233 m_frameMenuBar = menuBar;
234 // m_frameMenuBar->MacInstallMenuBar() ;
235 m_frameMenuBar->Attach(this);
236 }
237
238
239 // Responds to colour changes, and passes event on to children.
240 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
241 {
242 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
243 Refresh();
244
245 if ( m_frameStatusBar )
246 {
247 wxSysColourChangedEvent event2;
248 event2.SetEventObject( m_frameStatusBar );
249 m_frameStatusBar->ProcessEvent(event2);
250 }
251
252 // Propagate the event to the non-top-level children
253 wxWindow::OnSysColourChanged(event);
254 }
255
256
257 // Default activation behaviour - set the focus for the first child
258 // subwindow found.
259 void wxFrame::OnActivate(wxActivateEvent& event)
260 {
261 if ( !event.GetActive() )
262 {
263 // remember the last focused child
264 m_winLastFocused = FindFocus();
265 while ( m_winLastFocused )
266 {
267 if ( GetChildren().Find(m_winLastFocused) )
268 break;
269
270 m_winLastFocused = m_winLastFocused->GetParent();
271 }
272
273 event.Skip();
274 }
275 else
276 {
277 /*
278 for ( wxWindowList::Node *node = GetChildren().GetFirst();
279 node;
280 node = node->GetNext() )
281 {
282 // FIXME all this is totally bogus - we need to do the same as wxPanel,
283 // but how to do it without duplicating the code?
284
285 // restore focus
286 wxWindow *child = node->GetData();
287
288 if ( !child->IsTopLevel() && child->AcceptsFocus()
289 #if wxUSE_TOOLBAR
290 && !wxDynamicCast(child, wxToolBar)
291 #endif // wxUSE_TOOLBAR
292 #if wxUSE_STATUSBAR
293 && !wxDynamicCast(child, wxStatusBar)
294 #endif // wxUSE_STATUSBAR
295 )
296 {
297 child->SetFocus();
298 break;
299 }
300 }
301 */
302 wxSetFocusToChild(this, &m_winLastFocused);
303
304 if ( m_frameMenuBar != NULL )
305 {
306 m_frameMenuBar->MacInstallMenuBar() ;
307 }
308 }
309 }
310
311 void wxFrame::DoGetClientSize(int *x, int *y) const
312 {
313 wxWindow::DoGetClientSize( x , y ) ;
314
315 #if wxUSE_STATUSBAR
316 if ( GetStatusBar() )
317 {
318 int statusX, statusY;
319 GetStatusBar()->GetClientSize(&statusX, &statusY);
320 *y -= statusY;
321 }
322 #endif // wxUSE_STATUSBAR
323
324 wxPoint pt(GetClientAreaOrigin());
325 *y -= pt.y;
326 *x -= pt.x;
327 }
328
329 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
330 {
331 int currentclientwidth , currentclientheight ;
332 int currentwidth , currentheight ;
333
334 GetClientSize( &currentclientwidth , &currentclientheight ) ;
335 GetSize( &currentwidth , &currentheight ) ;
336
337 // find the current client size
338
339 // Find the difference between the entire window (title bar and all)
340 // and the client area; add this to the new client size to move the
341 // window
342
343 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
344 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
345 }
346
347
348 #if wxUSE_TOOLBAR
349 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
350 {
351 if ( wxFrameBase::CreateToolBar(style, id, name) )
352 {
353 PositionToolBar();
354 }
355
356 return m_frameToolBar;
357 }
358
359 void wxFrame::PositionToolBar()
360 {
361 int cw, ch;
362
363 cw = m_width ;
364 ch = m_height ;
365
366 if ( GetStatusBar() )
367 {
368 int statusX, statusY;
369 GetStatusBar()->GetClientSize(&statusX, &statusY);
370 ch -= statusY;
371 }
372
373 if (GetToolBar())
374 {
375 int tw, th;
376 GetToolBar()->GetSize(& tw, & th);
377
378 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
379 {
380 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
381 // means, pretend we don't have toolbar/status bar, so we
382 // have the original client size.
383 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
384 }
385 else
386 {
387 // Use the 'real' position
388 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
389 }
390 }
391 }
392 #endif