]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/frame.cpp
thread support for mac finished
[wxWidgets.git] / src / mac / carbon / 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/mac/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
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
113 if (!parent)
114 wxTopLevelWindows.Append(this);
115
116 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
117
118 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
119
120 wxModelessWindows.Append(this);
121
122 return TRUE;
123 }
124
125 wxFrame::~wxFrame()
126 {
127 m_isBeingDeleted = TRUE;
128 wxTopLevelWindows.DeleteObject(this);
129
130 DeleteAllBars();
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 {
140 wxTheApp->ExitMainLoop() ;
141 }
142 }
143
144 wxModelessWindows.DeleteObject(this);
145 }
146
147
148 bool wxFrame::Enable(bool enable)
149 {
150 if ( !wxWindow::Enable(enable) )
151 return FALSE;
152
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 }
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
175 void wxFrame::Iconize(bool iconize)
176 {
177 // TODO
178 }
179
180 // Is the frame maximized?
181 bool wxFrame::IsMaximized(void) const
182 {
183 // TODO
184 return FALSE;
185 }
186
187 void wxFrame::Restore()
188 {
189 // TODO
190 }
191
192 void wxFrame::SetIcon(const wxIcon& icon)
193 {
194 wxFrameBase::SetIcon(icon);
195 }
196
197 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
198 const wxString& name)
199 {
200 wxStatusBar *statusBar = NULL;
201
202 statusBar = new wxStatusBar(this, id, style, name);
203
204 statusBar->SetFieldsCount(number);
205 return statusBar;
206 }
207
208 void wxFrame::PositionStatusBar()
209 {
210 if (m_frameStatusBar )
211 {
212 int w, h;
213 GetClientSize(&w, &h);
214 int sw, sh;
215 m_frameStatusBar->GetSize(&sw, &sh);
216
217 // Since we wish the status bar to be directly under the client area,
218 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
219 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT );
220 }
221 }
222
223 void wxFrame::SetMenuBar(wxMenuBar *menuBar)
224 {
225 if (!menuBar)
226 {
227 return;
228 }
229
230 m_frameMenuBar = NULL;
231 m_frameMenuBar = menuBar;
232 m_frameMenuBar->MacInstallMenuBar() ;
233 m_frameMenuBar->Attach(this);
234 }
235
236
237 // Responds to colour changes, and passes event on to children.
238 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
239 {
240 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
241 Refresh();
242
243 if ( m_frameStatusBar )
244 {
245 wxSysColourChangedEvent event2;
246 event2.SetEventObject( m_frameStatusBar );
247 m_frameStatusBar->ProcessEvent(event2);
248 }
249
250 // Propagate the event to the non-top-level children
251 wxWindow::OnSysColourChanged(event);
252 }
253
254
255 // Default activation behaviour - set the focus for the first child
256 // subwindow found.
257 void wxFrame::OnActivate(wxActivateEvent& event)
258 {
259 if ( !event.GetActive() )
260 {
261 event.Skip();
262 return;
263 }
264
265 for ( wxWindowList::Node *node = GetChildren().GetFirst();
266 node;
267 node = node->GetNext() )
268 {
269 // FIXME all this is totally bogus - we need to do the same as wxPanel,
270 // but how to do it without duplicating the code?
271
272 // restore focus
273 wxWindow *child = node->GetData();
274
275 if ( !child->IsTopLevel()
276 #if wxUSE_TOOLBAR
277 && !wxDynamicCast(child, wxToolBar)
278 #endif // wxUSE_TOOLBAR
279 #if wxUSE_STATUSBAR
280 && !wxDynamicCast(child, wxStatusBar)
281 #endif // wxUSE_STATUSBAR
282 )
283 {
284 child->SetFocus();
285 return;
286 }
287 }
288 }
289
290 void wxFrame::DoGetClientSize(int *x, int *y) const
291 {
292 wxWindow::DoGetClientSize( x , y ) ;
293
294 #if wxUSE_STATUSBAR
295 if ( GetStatusBar() )
296 {
297 int statusX, statusY;
298 GetStatusBar()->GetClientSize(&statusX, &statusY);
299 // right now this is a constant, this might change someday
300 *y -= WX_MAC_STATUSBAR_HEIGHT ;
301 }
302 #endif // wxUSE_STATUSBAR
303
304 wxPoint pt(GetClientAreaOrigin());
305 *y -= pt.y;
306 *x -= pt.x;
307 }
308
309 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
310 {
311 int currentclientwidth , currentclientheight ;
312 int currentwidth , currentheight ;
313
314 GetClientSize( &currentclientwidth , &currentclientheight ) ;
315 GetSize( &currentwidth , &currentheight ) ;
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 ) ;
325 }
326
327
328 #if wxUSE_TOOLBAR
329 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
330 {
331 if ( wxFrameBase::CreateToolBar(style, id, name) )
332 {
333 PositionToolBar();
334 }
335
336 return m_frameToolBar;
337 }
338
339 void wxFrame::PositionToolBar()
340 {
341 int cw, ch;
342
343 cw = m_width ;
344 ch = m_height ;
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.
363 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
364 }
365 else
366 {
367 // Use the 'real' position
368 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
369 }
370 }
371 }
372 #endif