]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/frame.cpp
Implementing column click event handler and SortItems function for native list ctrl.
[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{
7ad25aed 49 m_winLastFocused = NULL;
2f1ae414 50}
e7549107 51
0d53fc34 52bool wxFrame::Create(wxWindow *parent,
e9576ca5
SC
53 wxWindowID id,
54 const wxString& title,
55 const wxPoint& pos,
56 const wxSize& size,
57 long style,
58 const wxString& name)
59{
902725ee 60
a15eb0a5 61 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
902725ee
WS
62 return false;
63
e40298d5 64 wxModelessWindows.Append(this);
902725ee
WS
65
66 return true;
e9576ca5
SC
67}
68
0d53fc34 69wxFrame::~wxFrame()
e9576ca5 70{
902725ee 71 m_isBeingDeleted = true;
e40298d5 72 DeleteAllBars();
e9576ca5
SC
73}
74
e56d2520
SC
75// get the origin of the client area in the client coordinates
76wxPoint wxFrame::GetClientAreaOrigin() const
77{
78 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
7ad25aed 79
e56d2520
SC
80#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
81 wxToolBar *toolbar = GetToolBar();
82 if ( toolbar && toolbar->IsShown() )
83 {
84 int w, h;
85 toolbar->GetSize(&w, &h);
7ad25aed 86
e56d2520
SC
87 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
88 {
89 pt.x += w;
90 }
91 else
92 {
93#if !wxMAC_USE_NATIVE_TOOLBAR
94 pt.y += h;
95#endif
96 }
97 }
7ad25aed 98#endif
be6068f6 99
e56d2520
SC
100 return pt;
101}
e9576ca5 102
0d53fc34 103bool wxFrame::Enable(bool enable)
e9576ca5 104{
2f1ae414 105 if ( !wxWindow::Enable(enable) )
902725ee 106 return false;
e9576ca5 107
e40298d5
JS
108 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
109 {
7ad25aed 110 int iMaxMenu = m_frameMenuBar->GetMenuCount();
e40298d5
JS
111 for ( int i = 0 ; i < iMaxMenu ; ++ i )
112 {
113 m_frameMenuBar->EnableTop( i , enable ) ;
114 }
115 }
2f1ae414 116
902725ee 117 return true;
2f1ae414 118}
e9576ca5 119
0d53fc34 120wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
e9576ca5
SC
121 const wxString& name)
122{
7ad25aed 123 wxStatusBar *statusBar;
e9576ca5 124
7ad25aed 125 statusBar = new wxStatusBar(this, id, style, name);
617bfeec 126 statusBar->SetSize(100, WX_MAC_STATUSBAR_HEIGHT);
e9576ca5 127 statusBar->SetFieldsCount(number);
7ad25aed 128
e9576ca5
SC
129 return statusBar;
130}
131
0d53fc34 132void wxFrame::PositionStatusBar()
e9576ca5 133{
f5d63a57 134 if (m_frameStatusBar && m_frameStatusBar->IsShown() )
e40298d5
JS
135 {
136 int w, h;
137 GetClientSize(&w, &h);
902725ee 138
e40298d5
JS
139 // Since we wish the status bar to be directly under the client area,
140 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
f80ffb32 141 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
e40298d5 142 }
e9576ca5
SC
143}
144
e9576ca5 145// Responds to colour changes, and passes event on to children.
0d53fc34 146void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
e9576ca5 147{
a756f210 148 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
e9576ca5
SC
149 Refresh();
150
151 if ( m_frameStatusBar )
152 {
153 wxSysColourChangedEvent event2;
7ad25aed 154
e9576ca5
SC
155 event2.SetEventObject( m_frameStatusBar );
156 m_frameStatusBar->ProcessEvent(event2);
157 }
158
159 // Propagate the event to the non-top-level children
160 wxWindow::OnSysColourChanged(event);
161}
162
e9576ca5
SC
163// Default activation behaviour - set the focus for the first child
164// subwindow found.
0d53fc34 165void wxFrame::OnActivate(wxActivateEvent& event)
e9576ca5 166{
2f1ae414 167 if ( !event.GetActive() )
e9576ca5 168 {
a15eb0a5 169 // remember the last focused child if it is our child
7810c95b 170 m_winLastFocused = FindFocus();
a15eb0a5
SC
171
172 // so we NULL it out if it's a child from some other frame
173 wxWindow *win = m_winLastFocused;
174 while ( win )
7810c95b 175 {
a15eb0a5
SC
176 if ( win->IsTopLevel() )
177 {
178 if ( win != this )
a15eb0a5 179 m_winLastFocused = NULL;
a15eb0a5 180
7810c95b 181 break;
a15eb0a5 182 }
7810c95b 183
a15eb0a5 184 win = win->GetParent();
7810c95b
SC
185 }
186
2f1ae414 187 event.Skip();
e9576ca5 188 }
e40298d5
JS
189 else
190 {
a15eb0a5 191 // restore focus to the child which was last focused
7ad25aed
DS
192 wxWindow *parent = m_winLastFocused
193 ? m_winLastFocused->GetParent()
194 : NULL;
195
617bfeec 196 if (parent == NULL)
a15eb0a5 197 parent = this;
a15eb0a5 198
e40298d5 199 wxSetFocusToChild(parent, &m_winLastFocused);
7810c95b 200
7ad25aed 201 if (m_frameMenuBar != NULL)
e40298d5 202 {
617bfeec 203 m_frameMenuBar->MacInstallMenuBar();
e40298d5 204 }
617bfeec 205 else
2b5f62a0 206 {
617bfeec
DS
207 wxFrame *tlf = wxDynamicCast( wxTheApp->GetTopWindow(), wxFrame );
208 if (tlf != NULL)
209 {
210 // Trying top-level frame membar
211 if (tlf->GetMenuBar())
212 tlf->GetMenuBar()->MacInstallMenuBar();
213 }
214 }
e40298d5 215 }
e9576ca5
SC
216}
217
2b5f62a0
VZ
218void wxFrame::DetachMenuBar()
219{
220 if ( m_frameMenuBar )
2b5f62a0 221 m_frameMenuBar->UnsetInvokingWindow();
2b5f62a0
VZ
222
223 wxFrameBase::DetachMenuBar();
224}
225
226void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
227{
487eedb8 228 wxFrame* tlf = wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame );
be6068f6 229 bool makeCurrent = false;
d059fe4a 230
d059fe4a 231 // if this is already the current menubar or we are the frontmost window
487eedb8 232 if ( (tlf == this) || (m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar()) )
be6068f6
DS
233 makeCurrent = true;
234 // or there is an app-level menubar like MDI
487eedb8 235 else if ( tlf && (tlf->GetMenuBar() == NULL) && (((wxFrame*)wxTheApp->GetTopWindow()) == this) )
be6068f6
DS
236 makeCurrent = true;
237
238 wxFrameBase::AttachMenuBar( menuBar );
2b5f62a0
VZ
239
240 if (m_frameMenuBar)
d059fe4a 241 {
2b5f62a0 242 m_frameMenuBar->SetInvokingWindow( this );
d059fe4a 243 if (makeCurrent)
be6068f6 244 m_frameMenuBar->MacInstallMenuBar();
d059fe4a 245 }
2b5f62a0
VZ
246}
247
0d53fc34 248void wxFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 249{
7ad25aed 250 wxTopLevelWindow::DoGetClientSize( x , y );
902725ee 251
2f1ae414 252#if wxUSE_STATUSBAR
f5d63a57 253 if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
902725ee 254 *y -= WX_MAC_STATUSBAR_HEIGHT;
7ad25aed 255#endif
902725ee 256
facd6764
SC
257#if wxUSE_TOOLBAR
258 wxToolBar *toolbar = GetToolBar();
259 if ( toolbar && toolbar->IsShown() )
260 {
261 int w, h;
262 toolbar->GetSize(&w, &h);
263
264 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
265 {
7ad25aed
DS
266 if ( x )
267 *x -= w;
facd6764
SC
268 }
269 else
270 {
a85245b1 271#if !wxMAC_USE_NATIVE_TOOLBAR
7ad25aed
DS
272 if ( y )
273 *y -= h;
a85245b1 274#endif
facd6764
SC
275 }
276 }
7ad25aed 277#endif
e9576ca5
SC
278}
279
902725ee 280bool wxFrame::MacIsChildOfClientArea( const wxWindow* child ) const
e905b636
SC
281{
282#if wxUSE_STATUSBAR
283 if ( child == GetStatusBar() )
284 return false ;
7ad25aed 285#endif
e905b636
SC
286
287#if wxUSE_TOOLBAR
288 if ( child == GetToolBar() )
289 return false ;
7ad25aed 290#endif
e905b636
SC
291
292 return wxFrameBase::MacIsChildOfClientArea( child ) ;
293}
294
0d53fc34 295void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 296{
e40298d5
JS
297 int currentclientwidth , currentclientheight ;
298 int currentwidth , currentheight ;
902725ee 299
e40298d5 300 GetClientSize( &currentclientwidth , &currentclientheight ) ;
facd6764
SC
301 if ( clientwidth == -1 )
302 clientwidth = currentclientwidth ;
303 if ( clientheight == -1 )
304 clientheight = currentclientheight ;
e40298d5 305 GetSize( &currentwidth , &currentheight ) ;
902725ee 306
e40298d5 307 // find the current client size
519cb848 308
7ad25aed
DS
309 // Find the difference between the entire window (title bar and all) and
310 // the client area; add this to the new client size to move the window
e40298d5
JS
311 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
312 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
e9576ca5
SC
313}
314
519cb848 315#if wxUSE_TOOLBAR
e56d2520
SC
316void wxFrame::SetToolBar(wxToolBar *toolbar)
317{
318 if ( m_frameToolBar == toolbar )
319 return ;
be6068f6 320
e56d2520
SC
321#if wxMAC_USE_NATIVE_TOOLBAR
322 if ( m_frameToolBar )
7ad25aed 323 m_frameToolBar->MacInstallNativeToolbar( false ) ;
e56d2520 324#endif
7ad25aed 325
e56d2520 326 m_frameToolBar = toolbar ;
7ad25aed 327
e56d2520
SC
328#if wxMAC_USE_NATIVE_TOOLBAR
329 if ( toolbar )
330 toolbar->MacInstallNativeToolbar( true ) ;
331#endif
332}
333
0d53fc34 334wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
e9576ca5 335{
2f1ae414 336 if ( wxFrameBase::CreateToolBar(style, id, name) )
e9576ca5 337 PositionToolBar();
e9576ca5 338
2f1ae414 339 return m_frameToolBar;
e9576ca5
SC
340}
341
0d53fc34 342void wxFrame::PositionToolBar()
e9576ca5
SC
343{
344 int cw, ch;
345
facd6764 346 GetSize( &cw , &ch ) ;
f4183326 347
50d8f022
SC
348 int statusX = 0 ;
349 int statusY = 0 ;
350
351#if wxUSE_STATUSBAR
7ad25aed 352 if (GetStatusBar() && GetStatusBar()->IsShown())
e9576ca5 353 {
50d8f022 354 GetStatusBar()->GetClientSize(&statusX, &statusY);
7ad25aed 355 ch -= statusY;
e9576ca5 356 }
50d8f022 357#endif
e9576ca5 358
50d8f022 359#if wxUSE_TOOLBAR
e9576ca5
SC
360 if (GetToolBar())
361 {
facd6764 362 int tx, ty, tw, th;
902725ee 363
7ad25aed
DS
364 tx = ty = 0 ;
365 GetToolBar()->GetSize(&tw, &th);
e9576ca5
SC
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.
facd6764 371 GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
e9576ca5 372 }
f4183326 373 else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM)
5b2acc3a 374 {
f4183326
KO
375 //FIXME: this positions the tool bar almost correctly, but still it doesn't work right yet,
376 //as 1) the space for the 'old' top toolbar is still taken up, and 2) the toolbar
377 //doesn't extend it's width to the width of the frame.
5b2acc3a 378 tx = 0;
f4183326
KO
379 ty = ch - (th + statusY);
380 GetToolBar()->SetSize(tx, ty, cw, th, wxSIZE_NO_ADJUSTMENTS );
5b2acc3a 381 }
e9576ca5
SC
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 }
50d8f022 390#endif
e9576ca5 391}
6f02a879
VZ
392
393void wxFrame::PositionBars()
394{
395#if wxUSE_STATUSBAR
396 PositionStatusBar();
397#endif
398#if wxUSE_TOOLBAR
399 PositionToolBar();
400#endif
401}
402
519cb848 403#endif