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