]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/frame.cpp
save correctly oriented GraphicState and clear Context before destruction (is invalid...
[wxWidgets.git] / src / mac / carbon / frame.cpp
... / ...
CommitLineData
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#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13#pragma implementation "frame.h"
14#endif
15
16#include "wx/wxprec.h"
17
18#include "wx/frame.h"
19#include "wx/statusbr.h"
20#include "wx/toolbar.h"
21#include "wx/menuitem.h"
22#include "wx/menu.h"
23#include "wx/dcclient.h"
24#include "wx/dialog.h"
25#include "wx/settings.h"
26#include "wx/app.h"
27
28#include "wx/mac/uma.h"
29
30extern wxWindowList wxModelessWindows;
31extern wxList wxPendingDelete;
32
33BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
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)
39END_EVENT_TABLE()
40
41IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
42
43#define WX_MAC_STATUSBAR_HEIGHT 18
44// ----------------------------------------------------------------------------
45// creation/destruction
46// ----------------------------------------------------------------------------
47
48void wxFrame::Init()
49{
50 m_frameMenuBar = NULL;
51
52#if wxUSE_TOOLBAR
53 m_frameToolBar = NULL ;
54#endif
55 m_frameStatusBar = NULL;
56 m_winLastFocused = NULL ;
57
58 m_iconized = false;
59
60#if wxUSE_TOOLTIPS
61 m_hwndToolTip = 0;
62#endif
63}
64
65bool wxFrame::Create(wxWindow *parent,
66 wxWindowID id,
67 const wxString& title,
68 const wxPoint& pos,
69 const wxSize& size,
70 long style,
71 const wxString& name)
72{
73
74 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
75 return false;
76
77 wxModelessWindows.Append(this);
78
79 return true;
80}
81
82wxFrame::~wxFrame()
83{
84 m_isBeingDeleted = true;
85 DeleteAllBars();
86}
87
88// get the origin of the client area in the client coordinates
89wxPoint wxFrame::GetClientAreaOrigin() const
90{
91 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
92
93#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
94 wxToolBar *toolbar = GetToolBar();
95 if ( toolbar && toolbar->IsShown() )
96 {
97 int w, h;
98 toolbar->GetSize(&w, &h);
99
100 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
101 {
102 pt.x += w;
103 }
104 else
105 {
106#if !wxMAC_USE_NATIVE_TOOLBAR
107 pt.y += h;
108#endif
109 }
110 }
111#endif // wxUSE_TOOLBAR
112
113 return pt;
114}
115
116bool wxFrame::Enable(bool enable)
117{
118 if ( !wxWindow::Enable(enable) )
119 return false;
120
121 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
122 {
123 int iMaxMenu = m_frameMenuBar->GetMenuCount();
124 for ( int i = 0 ; i < iMaxMenu ; ++ i )
125 {
126 m_frameMenuBar->EnableTop( i , enable ) ;
127 }
128 }
129
130 return true;
131}
132
133wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
134 const wxString& name)
135{
136 wxStatusBar *statusBar = NULL;
137
138 statusBar = new wxStatusBar(this, id,
139 style, name);
140 statusBar->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT ) ;
141 statusBar->SetFieldsCount(number);
142 return statusBar;
143}
144
145void wxFrame::PositionStatusBar()
146{
147 if (m_frameStatusBar && m_frameStatusBar->IsShown() )
148 {
149 int w, h;
150 GetClientSize(&w, &h);
151
152 // Since we wish the status bar to be directly under the client area,
153 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
154 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
155 }
156}
157
158// Responds to colour changes, and passes event on to children.
159void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
160{
161 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
162 Refresh();
163
164 if ( m_frameStatusBar )
165 {
166 wxSysColourChangedEvent event2;
167 event2.SetEventObject( m_frameStatusBar );
168 m_frameStatusBar->ProcessEvent(event2);
169 }
170
171 // Propagate the event to the non-top-level children
172 wxWindow::OnSysColourChanged(event);
173}
174
175
176// Default activation behaviour - set the focus for the first child
177// subwindow found.
178void wxFrame::OnActivate(wxActivateEvent& event)
179{
180 if ( !event.GetActive() )
181 {
182 // remember the last focused child if it is our child
183 m_winLastFocused = FindFocus();
184
185 // so we NULL it out if it's a child from some other frame
186 wxWindow *win = m_winLastFocused;
187 while ( win )
188 {
189 if ( win->IsTopLevel() )
190 {
191 if ( win != this )
192 {
193 m_winLastFocused = NULL;
194 }
195
196 break;
197 }
198
199 win = win->GetParent();
200 }
201
202 event.Skip();
203 }
204 else
205 {
206 // restore focus to the child which was last focused
207 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
208 : NULL;
209 if ( !parent )
210 {
211 parent = this;
212 }
213
214 wxSetFocusToChild(parent, &m_winLastFocused);
215
216 if ( m_frameMenuBar != NULL )
217 {
218 m_frameMenuBar->MacInstallMenuBar() ;
219 }
220 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
221 {
222 // Trying toplevel frame menbar
223 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
224 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
225 }
226 }
227}
228
229void wxFrame::DetachMenuBar()
230{
231 if ( m_frameMenuBar )
232 {
233 m_frameMenuBar->UnsetInvokingWindow();
234 }
235
236 wxFrameBase::DetachMenuBar();
237}
238
239void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
240{
241 wxFrameBase::AttachMenuBar(menuBar);
242
243 if (m_frameMenuBar)
244 {
245 m_frameMenuBar->SetInvokingWindow( this );
246 }
247}
248
249void wxFrame::DoGetClientSize(int *x, int *y) const
250{
251 wxTopLevelWindow::DoGetClientSize( x , y ) ;
252
253#if wxUSE_STATUSBAR
254 if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
255 {
256 *y -= WX_MAC_STATUSBAR_HEIGHT;
257 }
258#endif // wxUSE_STATUSBAR
259
260#if wxUSE_TOOLBAR
261 wxToolBar *toolbar = GetToolBar();
262 if ( toolbar && toolbar->IsShown() )
263 {
264 int w, h;
265 toolbar->GetSize(&w, &h);
266
267 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
268 {
269 if ( x ) *x -= w;
270 }
271 else
272 {
273#if !wxMAC_USE_NATIVE_TOOLBAR
274 if ( y ) *y -= h;
275#endif
276 }
277 }
278#endif // wxUSE_TOOLBAR
279}
280
281bool wxFrame::MacIsChildOfClientArea( const wxWindow* child ) const
282{
283#if wxUSE_STATUSBAR
284 if ( child == GetStatusBar() )
285 return false ;
286#endif // wxUSE_STATUSBAR
287
288#if wxUSE_TOOLBAR
289 if ( child == GetToolBar() )
290 return false ;
291#endif // wxUSE_TOOLBAR
292
293 return wxFrameBase::MacIsChildOfClientArea( child ) ;
294}
295
296void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
297{
298 int currentclientwidth , currentclientheight ;
299 int currentwidth , currentheight ;
300
301 GetClientSize( &currentclientwidth , &currentclientheight ) ;
302 if ( clientwidth == -1 )
303 clientwidth = currentclientwidth ;
304 if ( clientheight == -1 )
305 clientheight = currentclientheight ;
306 GetSize( &currentwidth , &currentheight ) ;
307
308 // find the current client size
309
310 // Find the difference between the entire window (title bar and all)
311 // and the client area; add this to the new client size to move the
312 // window
313
314 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
315 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
316}
317
318
319#if wxUSE_TOOLBAR
320void wxFrame::SetToolBar(wxToolBar *toolbar)
321{
322 if ( m_frameToolBar == toolbar )
323 return ;
324
325#if wxMAC_USE_NATIVE_TOOLBAR
326 if ( m_frameToolBar )
327 m_frameToolBar->MacInstallNativeToolbar(false) ;
328#endif
329
330 m_frameToolBar = toolbar ;
331#if wxMAC_USE_NATIVE_TOOLBAR
332 if ( toolbar )
333 toolbar->MacInstallNativeToolbar( true ) ;
334#endif
335}
336
337wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
338{
339 if ( wxFrameBase::CreateToolBar(style, id, name) )
340 {
341 PositionToolBar();
342 }
343
344 return m_frameToolBar;
345}
346
347void wxFrame::PositionToolBar()
348{
349 int cw, ch;
350
351 GetSize( &cw , &ch ) ;
352
353 if ( GetStatusBar() && GetStatusBar()->IsShown())
354 {
355 int statusX, statusY;
356 GetStatusBar()->GetClientSize(&statusX, &statusY);
357 ch -= statusY;
358 }
359
360 if (GetToolBar())
361 {
362 int tx, ty, tw, th;
363 tx = ty = 0 ;
364
365 GetToolBar()->GetSize(& tw, & th);
366 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
367 {
368 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
369 // means, pretend we don't have toolbar/status bar, so we
370 // have the original client size.
371 GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
372 }
373 else
374 {
375#if !wxMAC_USE_NATIVE_TOOLBAR
376 // Use the 'real' position
377 GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS );
378#endif
379 }
380 }
381}
382#endif