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