]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/frame.cpp
typo fix
[wxWidgets.git] / src / mac / carbon / frame.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
e766c8a9 3// Purpose: wxFrameMac
e9576ca5
SC
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"
03e11df5 17#include "wx/statusbr.h"
e9576ca5
SC
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
d497dca4 26#include "wx/mac/uma.h"
519cb848 27
fe08e597 28extern wxWindowList wxModelessWindows;
e9576ca5
SC
29extern wxList wxPendingDelete;
30
2f1ae414 31#if !USE_SHARED_LIBRARY
e766c8a9 32BEGIN_EVENT_TABLE(wxFrameMac, wxFrameBase)
e766c8a9
SC
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)
e9576ca5
SC
38END_EVENT_TABLE()
39
e766c8a9
SC
40IMPLEMENT_DYNAMIC_CLASS(wxFrameMac, wxWindow)
41#endif
42#ifndef __WXUNIVERSAL__
43IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxFrameMac)
2f1ae414 44#endif
e9576ca5
SC
45
46#if wxUSE_NATIVE_STATUSBAR
e766c8a9 47bool wxFrameMac::m_useNativeStatusBar = TRUE;
e9576ca5 48#else
e766c8a9 49bool wxFrameMac::m_useNativeStatusBar = FALSE;
e9576ca5
SC
50#endif
51
2f1ae414
SC
52#define WX_MAC_STATUSBAR_HEIGHT 15
53// ----------------------------------------------------------------------------
54// creation/destruction
55// ----------------------------------------------------------------------------
56
e766c8a9 57void wxFrameMac::Init()
e9576ca5 58{
0a67a93b
SC
59 m_frameMenuBar = NULL;
60
61#if wxUSE_TOOLBAR
62 m_frameToolBar = NULL ;
63#endif
64 m_frameStatusBar = NULL;
65 m_winLastFocused = NULL ;
66
2f1ae414
SC
67 m_iconized = FALSE;
68
69#if wxUSE_TOOLTIPS
70 m_hwndToolTip = 0;
519cb848 71#endif
2f1ae414 72}
e7549107 73
e766c8a9 74wxPoint wxFrameMac::GetClientAreaOrigin() const
2f1ae414
SC
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;
e9576ca5
SC
97}
98
e766c8a9 99bool wxFrameMac::Create(wxWindow *parent,
e9576ca5
SC
100 wxWindowID id,
101 const wxString& title,
102 const wxPoint& pos,
103 const wxSize& size,
104 long style,
105 const wxString& name)
106{
e9576ca5
SC
107 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
108
a15eb0a5
SC
109 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
110 return FALSE;
519cb848 111
2f1ae414
SC
112 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
113
114 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
519cb848 115
2f1ae414 116 wxModelessWindows.Append(this);
519cb848 117
519cb848 118 return TRUE;
e9576ca5
SC
119}
120
e766c8a9 121wxFrameMac::~wxFrameMac()
e9576ca5 122{
2f1ae414 123 m_isBeingDeleted = TRUE;
e9576ca5 124
2f1ae414 125 DeleteAllBars();
e9576ca5 126
e9576ca5
SC
127}
128
e9576ca5 129
e766c8a9 130bool wxFrameMac::Enable(bool enable)
e9576ca5 131{
2f1ae414
SC
132 if ( !wxWindow::Enable(enable) )
133 return FALSE;
e9576ca5 134
2f1ae414
SC
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}
e9576ca5 145
e766c8a9 146wxStatusBar *wxFrameMac::OnCreateStatusBar(int number, long style, wxWindowID id,
e9576ca5
SC
147 const wxString& name)
148{
149 wxStatusBar *statusBar = NULL;
150
5b781a67
SC
151 statusBar = new wxStatusBar(this, id,
152 style, name);
153 statusBar->SetSize( 100 , 15 ) ;
e9576ca5
SC
154 statusBar->SetFieldsCount(number);
155 return statusBar;
156}
157
e766c8a9 158void wxFrameMac::PositionStatusBar()
e9576ca5 159{
519cb848
SC
160 if (m_frameStatusBar )
161 {
e9576ca5
SC
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.
5b781a67 169 m_frameStatusBar->SetSize(0, h, w, sh);
519cb848 170 }
e9576ca5
SC
171}
172
e9576ca5 173// Responds to colour changes, and passes event on to children.
e766c8a9 174void wxFrameMac::OnSysColourChanged(wxSysColourChangedEvent& event)
e9576ca5
SC
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
e9576ca5
SC
190
191// Default activation behaviour - set the focus for the first child
192// subwindow found.
e766c8a9 193void wxFrameMac::OnActivate(wxActivateEvent& event)
e9576ca5 194{
2f1ae414 195 if ( !event.GetActive() )
e9576ca5 196 {
a15eb0a5 197 // remember the last focused child if it is our child
7810c95b 198 m_winLastFocused = FindFocus();
a15eb0a5
SC
199
200 // so we NULL it out if it's a child from some other frame
201 wxWindow *win = m_winLastFocused;
202 while ( win )
7810c95b 203 {
a15eb0a5
SC
204 if ( win->IsTopLevel() )
205 {
206 if ( win != this )
207 {
208 m_winLastFocused = NULL;
209 }
210
7810c95b 211 break;
a15eb0a5 212 }
7810c95b 213
a15eb0a5 214 win = win->GetParent();
7810c95b
SC
215 }
216
2f1ae414 217 event.Skip();
e9576ca5 218 }
7810c95b
SC
219 else
220 {
a15eb0a5
SC
221 // restore focus to the child which was last focused
222 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
223 : NULL;
224 if ( !parent )
e9576ca5 225 {
a15eb0a5 226 parent = this;
e9576ca5 227 }
a15eb0a5
SC
228
229 wxSetFocusToChild(parent, &m_winLastFocused);
7810c95b
SC
230
231 if ( m_frameMenuBar != NULL )
232 {
233 m_frameMenuBar->MacInstallMenuBar() ;
234 }
235 }
e9576ca5
SC
236}
237
e766c8a9 238void wxFrameMac::DoGetClientSize(int *x, int *y) const
e9576ca5 239{
7c74e7fe 240 wxWindow::DoGetClientSize( x , y ) ;
519cb848 241
2f1ae414 242#if wxUSE_STATUSBAR
9453cf2b 243 if ( GetStatusBar() && y )
519cb848
SC
244 {
245 int statusX, statusY;
246 GetStatusBar()->GetClientSize(&statusX, &statusY);
5b781a67 247 *y -= statusY;
519cb848 248 }
2f1ae414 249#endif // wxUSE_STATUSBAR
519cb848
SC
250
251 wxPoint pt(GetClientAreaOrigin());
9453cf2b
SC
252 if ( y )
253 *y -= pt.y;
254 if ( x )
255 *x -= pt.x;
e9576ca5
SC
256}
257
e766c8a9 258void wxFrameMac::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 259{
519cb848
SC
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 ) ;
e9576ca5
SC
274}
275
519cb848
SC
276
277#if wxUSE_TOOLBAR
e766c8a9 278wxToolBar* wxFrameMac::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
e766c8a9 288void wxFrameMac::PositionToolBar()
e9576ca5
SC
289{
290 int cw, ch;
291
2f1ae414
SC
292 cw = m_width ;
293 ch = m_height ;
e9576ca5
SC
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.
2f1ae414 312 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
313 }
314 else
315 {
316 // Use the 'real' position
2f1ae414 317 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
318 }
319 }
320}
519cb848 321#endif