]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/frame.cpp
recommit after mac binary lapsus
[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/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
128 bool wxFrame::Enable(bool enable)
129 {
130 if ( !wxWindow::Enable(enable) )
131 return FALSE;
132
133 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
134 {
135 int iMaxMenu = m_frameMenuBar->GetMenuCount();
136 for ( int i = 0 ; i < iMaxMenu ; ++ i )
137 {
138 m_frameMenuBar->EnableTop( i , enable ) ;
139 }
140 }
141
142 return TRUE;
143 }
144
145 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
146 const wxString& name)
147 {
148 wxStatusBar *statusBar = NULL;
149
150 statusBar = new wxStatusBar(this, id,
151 style, name);
152 statusBar->SetSize( 100 , 15 ) ;
153 statusBar->SetFieldsCount(number);
154 return statusBar;
155 }
156
157 void wxFrame::PositionStatusBar()
158 {
159 if (m_frameStatusBar )
160 {
161 int w, h;
162 GetClientSize(&w, &h);
163 int sw, sh;
164 m_frameStatusBar->GetSize(&sw, &sh);
165
166 // Since we wish the status bar to be directly under the client area,
167 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
168 m_frameStatusBar->SetSize(0, h, w, sh);
169 }
170 }
171
172 // Responds to colour changes, and passes event on to children.
173 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
174 {
175 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
176 Refresh();
177
178 if ( m_frameStatusBar )
179 {
180 wxSysColourChangedEvent event2;
181 event2.SetEventObject( m_frameStatusBar );
182 m_frameStatusBar->ProcessEvent(event2);
183 }
184
185 // Propagate the event to the non-top-level children
186 wxWindow::OnSysColourChanged(event);
187 }
188
189
190 // Default activation behaviour - set the focus for the first child
191 // subwindow found.
192 void wxFrame::OnActivate(wxActivateEvent& event)
193 {
194 if ( !event.GetActive() )
195 {
196 // remember the last focused child if it is our child
197 m_winLastFocused = FindFocus();
198
199 // so we NULL it out if it's a child from some other frame
200 wxWindow *win = m_winLastFocused;
201 while ( win )
202 {
203 if ( win->IsTopLevel() )
204 {
205 if ( win != this )
206 {
207 m_winLastFocused = NULL;
208 }
209
210 break;
211 }
212
213 win = win->GetParent();
214 }
215
216 event.Skip();
217 }
218 else
219 {
220 // restore focus to the child which was last focused
221 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
222 : NULL;
223 if ( !parent )
224 {
225 parent = this;
226 }
227
228 wxSetFocusToChild(parent, &m_winLastFocused);
229
230 if ( m_frameMenuBar != NULL )
231 {
232 m_frameMenuBar->MacInstallMenuBar() ;
233 }
234 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
235 {
236 // Trying toplevel frame menbar
237 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
238 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
239 }
240 }
241 }
242
243 void wxFrame::DetachMenuBar()
244 {
245 if ( m_frameMenuBar )
246 {
247 m_frameMenuBar->UnsetInvokingWindow();
248 }
249
250 wxFrameBase::DetachMenuBar();
251 }
252
253 void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
254 {
255 wxFrameBase::AttachMenuBar(menuBar);
256
257 if (m_frameMenuBar)
258 {
259 m_frameMenuBar->SetInvokingWindow( this );
260 }
261 }
262
263 void wxFrame::DoGetClientSize(int *x, int *y) const
264 {
265 wxWindow::DoGetClientSize( x , y ) ;
266
267 #if wxUSE_STATUSBAR
268 if ( GetStatusBar() && y )
269 {
270 int statusX, statusY;
271 GetStatusBar()->GetClientSize(&statusX, &statusY);
272 *y -= statusY;
273 }
274 #endif // wxUSE_STATUSBAR
275
276 wxPoint pt(GetClientAreaOrigin());
277 if ( y )
278 *y -= pt.y;
279 if ( x )
280 *x -= pt.x;
281 }
282
283 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
284 {
285 int currentclientwidth , currentclientheight ;
286 int currentwidth , currentheight ;
287
288 GetClientSize( &currentclientwidth , &currentclientheight ) ;
289 GetSize( &currentwidth , &currentheight ) ;
290
291 // find the current client size
292
293 // Find the difference between the entire window (title bar and all)
294 // and the client area; add this to the new client size to move the
295 // window
296
297 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
298 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
299 }
300
301
302 #if wxUSE_TOOLBAR
303 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
304 {
305 if ( wxFrameBase::CreateToolBar(style, id, name) )
306 {
307 PositionToolBar();
308 }
309
310 return m_frameToolBar;
311 }
312
313 void wxFrame::PositionToolBar()
314 {
315 int cw, ch;
316
317 cw = m_width ;
318 ch = m_height ;
319
320 if ( GetStatusBar() )
321 {
322 int statusX, statusY;
323 GetStatusBar()->GetClientSize(&statusX, &statusY);
324 ch -= statusY;
325 }
326
327 if (GetToolBar())
328 {
329 int tw, th;
330 GetToolBar()->GetSize(& tw, & th);
331
332 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
333 {
334 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
335 // means, pretend we don't have toolbar/status bar, so we
336 // have the original client size.
337 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
338 }
339 else
340 {
341 // Use the 'real' position
342 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
343 }
344 }
345 }
346 #endif