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