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