]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/frame.cpp
reintroducing direct access, clipping to client area in dc
[wxWidgets.git] / src / mac / carbon / frame.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
0d53fc34 3// Purpose: wxFrame
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "frame.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
e9576ca5 18#include "wx/frame.h"
03e11df5 19#include "wx/statusbr.h"
e9576ca5
SC
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
d497dca4 28#include "wx/mac/uma.h"
519cb848 29
fe08e597 30extern wxWindowList wxModelessWindows;
e9576ca5
SC
31extern wxList wxPendingDelete;
32
2f1ae414 33#if !USE_SHARED_LIBRARY
0d53fc34
VS
34BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
35 EVT_ACTIVATE(wxFrame::OnActivate)
36 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
37 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
38// EVT_IDLE(wxFrame::OnIdle)
39// EVT_CLOSE(wxFrame::OnCloseWindow)
e9576ca5
SC
40END_EVENT_TABLE()
41
ac0fa9ef 42IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2f1ae414 43#endif
e9576ca5 44
326d5a74 45#define WX_MAC_STATUSBAR_HEIGHT 18
2f1ae414
SC
46// ----------------------------------------------------------------------------
47// creation/destruction
48// ----------------------------------------------------------------------------
49
0d53fc34 50void wxFrame::Init()
e9576ca5 51{
e40298d5
JS
52 m_frameMenuBar = NULL;
53
0a67a93b 54#if wxUSE_TOOLBAR
e40298d5 55 m_frameToolBar = NULL ;
0a67a93b 56#endif
e40298d5
JS
57 m_frameStatusBar = NULL;
58 m_winLastFocused = NULL ;
59
2f1ae414 60 m_iconized = FALSE;
e40298d5 61
2f1ae414
SC
62#if wxUSE_TOOLTIPS
63 m_hwndToolTip = 0;
519cb848 64#endif
2f1ae414 65}
e7549107 66
0d53fc34 67bool wxFrame::Create(wxWindow *parent,
e9576ca5
SC
68 wxWindowID id,
69 const wxString& title,
70 const wxPoint& pos,
71 const wxSize& size,
72 long style,
73 const wxString& name)
74{
e40298d5 75
a15eb0a5
SC
76 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
77 return FALSE;
e40298d5 78
e40298d5
JS
79 wxModelessWindows.Append(this);
80
81 return TRUE;
e9576ca5
SC
82}
83
0d53fc34 84wxFrame::~wxFrame()
e9576ca5 85{
e40298d5 86 m_isBeingDeleted = TRUE;
e40298d5 87 DeleteAllBars();
e9576ca5
SC
88}
89
e9576ca5 90
0d53fc34 91bool wxFrame::Enable(bool enable)
e9576ca5 92{
2f1ae414
SC
93 if ( !wxWindow::Enable(enable) )
94 return FALSE;
e9576ca5 95
e40298d5
JS
96 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
97 {
98 int iMaxMenu = m_frameMenuBar->GetMenuCount();
99 for ( int i = 0 ; i < iMaxMenu ; ++ i )
100 {
101 m_frameMenuBar->EnableTop( i , enable ) ;
102 }
103 }
2f1ae414
SC
104
105 return TRUE;
106}
e9576ca5 107
0d53fc34 108wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
e9576ca5
SC
109 const wxString& name)
110{
111 wxStatusBar *statusBar = NULL;
112
5b781a67
SC
113 statusBar = new wxStatusBar(this, id,
114 style, name);
f80ffb32 115 statusBar->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT ) ;
e9576ca5
SC
116 statusBar->SetFieldsCount(number);
117 return statusBar;
118}
119
0d53fc34 120void wxFrame::PositionStatusBar()
e9576ca5 121{
f5d63a57 122 if (m_frameStatusBar && m_frameStatusBar->IsShown() )
e40298d5
JS
123 {
124 int w, h;
125 GetClientSize(&w, &h);
e40298d5
JS
126
127 // Since we wish the status bar to be directly under the client area,
128 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
f80ffb32 129 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
e40298d5 130 }
e9576ca5
SC
131}
132
e9576ca5 133// Responds to colour changes, and passes event on to children.
0d53fc34 134void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
e9576ca5 135{
a756f210 136 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
e9576ca5
SC
137 Refresh();
138
139 if ( m_frameStatusBar )
140 {
141 wxSysColourChangedEvent event2;
142 event2.SetEventObject( m_frameStatusBar );
143 m_frameStatusBar->ProcessEvent(event2);
144 }
145
146 // Propagate the event to the non-top-level children
147 wxWindow::OnSysColourChanged(event);
148}
149
e9576ca5
SC
150
151// Default activation behaviour - set the focus for the first child
152// subwindow found.
0d53fc34 153void wxFrame::OnActivate(wxActivateEvent& event)
e9576ca5 154{
2f1ae414 155 if ( !event.GetActive() )
e9576ca5 156 {
a15eb0a5 157 // remember the last focused child if it is our child
7810c95b 158 m_winLastFocused = FindFocus();
a15eb0a5
SC
159
160 // so we NULL it out if it's a child from some other frame
161 wxWindow *win = m_winLastFocused;
162 while ( win )
7810c95b 163 {
a15eb0a5
SC
164 if ( win->IsTopLevel() )
165 {
166 if ( win != this )
167 {
168 m_winLastFocused = NULL;
169 }
170
7810c95b 171 break;
a15eb0a5 172 }
7810c95b 173
a15eb0a5 174 win = win->GetParent();
7810c95b
SC
175 }
176
2f1ae414 177 event.Skip();
e9576ca5 178 }
e40298d5
JS
179 else
180 {
a15eb0a5
SC
181 // restore focus to the child which was last focused
182 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
183 : NULL;
184 if ( !parent )
e9576ca5 185 {
a15eb0a5 186 parent = this;
e9576ca5 187 }
a15eb0a5 188
e40298d5 189 wxSetFocusToChild(parent, &m_winLastFocused);
7810c95b 190
e40298d5
JS
191 if ( m_frameMenuBar != NULL )
192 {
193 m_frameMenuBar->MacInstallMenuBar() ;
194 }
195 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
2b5f62a0
VZ
196 {
197 // Trying toplevel frame menbar
198 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
e40298d5
JS
199 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
200 }
201 }
e9576ca5
SC
202}
203
2b5f62a0
VZ
204void wxFrame::DetachMenuBar()
205{
206 if ( m_frameMenuBar )
207 {
208 m_frameMenuBar->UnsetInvokingWindow();
209 }
210
211 wxFrameBase::DetachMenuBar();
212}
213
214void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
215{
216 wxFrameBase::AttachMenuBar(menuBar);
217
218 if (m_frameMenuBar)
219 {
220 m_frameMenuBar->SetInvokingWindow( this );
221 }
222}
223
0d53fc34 224void wxFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 225{
facd6764 226 wxTopLevelWindow::DoGetClientSize( x , y ) ;
e40298d5 227
2f1ae414 228#if wxUSE_STATUSBAR
f5d63a57 229 if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
e40298d5 230 {
f80ffb32 231 if ( y) *y -= WX_MAC_STATUSBAR_HEIGHT;
e40298d5 232 }
2f1ae414 233#endif // wxUSE_STATUSBAR
e40298d5 234
facd6764
SC
235#if wxUSE_TOOLBAR
236 wxToolBar *toolbar = GetToolBar();
237 if ( toolbar && toolbar->IsShown() )
238 {
239 int w, h;
240 toolbar->GetSize(&w, &h);
241
242 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
243 {
244 if ( x ) *x -= w;
245 }
246 else
247 {
248 if ( y ) *y -= h;
249 }
250 }
251#endif // wxUSE_TOOLBAR
e9576ca5
SC
252}
253
0d53fc34 254void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 255{
e40298d5
JS
256 int currentclientwidth , currentclientheight ;
257 int currentwidth , currentheight ;
258
259 GetClientSize( &currentclientwidth , &currentclientheight ) ;
facd6764
SC
260 if ( clientwidth == -1 )
261 clientwidth = currentclientwidth ;
262 if ( clientheight == -1 )
263 clientheight = currentclientheight ;
e40298d5
JS
264 GetSize( &currentwidth , &currentheight ) ;
265
266 // find the current client size
519cb848
SC
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
e40298d5
JS
272 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
273 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
e9576ca5
SC
274}
275
519cb848
SC
276
277#if wxUSE_TOOLBAR
0d53fc34 278wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
e9576ca5 279{
2f1ae414 280 if ( wxFrameBase::CreateToolBar(style, id, name) )
e9576ca5 281 {
e9576ca5 282 PositionToolBar();
e9576ca5 283 }
e9576ca5 284
2f1ae414 285 return m_frameToolBar;
e9576ca5
SC
286}
287
0d53fc34 288void wxFrame::PositionToolBar()
e9576ca5
SC
289{
290 int cw, ch;
291
facd6764 292 GetSize( &cw , &ch ) ;
e9576ca5 293
f5d63a57 294 if ( GetStatusBar() && GetStatusBar()->IsShown())
e9576ca5
SC
295 {
296 int statusX, statusY;
297 GetStatusBar()->GetClientSize(&statusX, &statusY);
298 ch -= statusY;
299 }
300
301 if (GetToolBar())
302 {
facd6764
SC
303 int tx, ty, tw, th;
304 tx = ty = 0 ;
305
e9576ca5 306 GetToolBar()->GetSize(& tw, & th);
e9576ca5
SC
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.
facd6764 312 GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
e9576ca5
SC
313 }
314 else
315 {
316 // Use the 'real' position
facd6764 317 GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS );
e9576ca5
SC
318 }
319 }
320}
519cb848 321#endif