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