]> git.saurik.com Git - wxWidgets.git/blob - src/mac/frame.cpp
Forgot ! in wxTreeCtrl flag test.
[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_frameMenuBar = NULL;
58
59 #if wxUSE_TOOLBAR
60 m_frameToolBar = NULL ;
61 #endif
62 m_frameStatusBar = NULL;
63 m_winLastFocused = NULL ;
64
65 m_iconized = FALSE;
66
67 #if wxUSE_TOOLTIPS
68 m_hwndToolTip = 0;
69 #endif
70 }
71
72 wxPoint wxFrame::GetClientAreaOrigin() const
73 {
74 // on mac we are at position -1,-1 with the control
75 wxPoint pt(0, 0);
76
77 #if wxUSE_TOOLBAR
78 if ( GetToolBar() )
79 {
80 int w, h;
81 GetToolBar()->GetSize(& w, & h);
82
83 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
84 {
85 pt.x += w - 1;
86 }
87 else
88 {
89 pt.y += h - 1 ;
90 }
91 }
92 #endif // wxUSE_TOOLBAR
93
94 return pt;
95 }
96
97 bool wxFrame::Create(wxWindow *parent,
98 wxWindowID id,
99 const wxString& title,
100 const wxPoint& pos,
101 const wxSize& size,
102 long style,
103 const wxString& name)
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 = menuBar;
233 // m_frameMenuBar->MacInstallMenuBar() ;
234 m_frameMenuBar->Attach(this);
235 }
236
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
255
256 // Default activation behaviour - set the focus for the first child
257 // subwindow found.
258 void wxFrame::OnActivate(wxActivateEvent& event)
259 {
260 if ( !event.GetActive() )
261 {
262 // remember the last focused child
263 m_winLastFocused = FindFocus();
264 while ( m_winLastFocused )
265 {
266 if ( GetChildren().Find(m_winLastFocused) )
267 break;
268
269 m_winLastFocused = m_winLastFocused->GetParent();
270 }
271
272 event.Skip();
273 }
274 else
275 {
276 /*
277 for ( wxWindowList::Node *node = GetChildren().GetFirst();
278 node;
279 node = node->GetNext() )
280 {
281 // FIXME all this is totally bogus - we need to do the same as wxPanel,
282 // but how to do it without duplicating the code?
283
284 // restore focus
285 wxWindow *child = node->GetData();
286
287 if ( !child->IsTopLevel() && child->AcceptsFocus()
288 #if wxUSE_TOOLBAR
289 && !wxDynamicCast(child, wxToolBar)
290 #endif // wxUSE_TOOLBAR
291 #if wxUSE_STATUSBAR
292 && !wxDynamicCast(child, wxStatusBar)
293 #endif // wxUSE_STATUSBAR
294 )
295 {
296 child->SetFocus();
297 break;
298 }
299 }
300 */
301 wxSetFocusToChild(this, &m_winLastFocused);
302
303 if ( m_frameMenuBar != NULL )
304 {
305 m_frameMenuBar->MacInstallMenuBar() ;
306 }
307 }
308 }
309
310 void wxFrame::DoGetClientSize(int *x, int *y) const
311 {
312 wxWindow::DoGetClientSize( x , y ) ;
313
314 #if wxUSE_STATUSBAR
315 if ( GetStatusBar() )
316 {
317 int statusX, statusY;
318 GetStatusBar()->GetClientSize(&statusX, &statusY);
319 *y -= statusY;
320 }
321 #endif // wxUSE_STATUSBAR
322
323 wxPoint pt(GetClientAreaOrigin());
324 *y -= pt.y;
325 *x -= pt.x;
326 }
327
328 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
329 {
330 int currentclientwidth , currentclientheight ;
331 int currentwidth , currentheight ;
332
333 GetClientSize( &currentclientwidth , &currentclientheight ) ;
334 GetSize( &currentwidth , &currentheight ) ;
335
336 // find the current client size
337
338 // Find the difference between the entire window (title bar and all)
339 // and the client area; add this to the new client size to move the
340 // window
341
342 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
343 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
344 }
345
346
347 #if wxUSE_TOOLBAR
348 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
349 {
350 if ( wxFrameBase::CreateToolBar(style, id, name) )
351 {
352 PositionToolBar();
353 }
354
355 return m_frameToolBar;
356 }
357
358 void wxFrame::PositionToolBar()
359 {
360 int cw, ch;
361
362 cw = m_width ;
363 ch = m_height ;
364
365 if ( GetStatusBar() )
366 {
367 int statusX, statusY;
368 GetStatusBar()->GetClientSize(&statusX, &statusY);
369 ch -= statusY;
370 }
371
372 if (GetToolBar())
373 {
374 int tw, th;
375 GetToolBar()->GetSize(& tw, & th);
376
377 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
378 {
379 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
380 // means, pretend we don't have toolbar/status bar, so we
381 // have the original client size.
382 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
383 }
384 else
385 {
386 // Use the 'real' position
387 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
388 }
389 }
390 }
391 #endif