]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/frame.cpp
Query value from the model column given by col->GetModelColumn()
[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
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
7ad25aed 40
2f1ae414
SC
41// ----------------------------------------------------------------------------
42// creation/destruction
43// ----------------------------------------------------------------------------
44
0d53fc34 45void wxFrame::Init()
e9576ca5 46{
7ad25aed 47 m_winLastFocused = NULL;
2f1ae414 48}
e7549107 49
0d53fc34 50bool wxFrame::Create(wxWindow *parent,
e9576ca5
SC
51 wxWindowID id,
52 const wxString& title,
53 const wxPoint& pos,
54 const wxSize& size,
55 long style,
56 const wxString& name)
57{
902725ee 58
a15eb0a5 59 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
902725ee
WS
60 return false;
61
902725ee 62 return true;
e9576ca5
SC
63}
64
0d53fc34 65wxFrame::~wxFrame()
e9576ca5 66{
902725ee 67 m_isBeingDeleted = true;
e40298d5 68 DeleteAllBars();
e9576ca5
SC
69}
70
e56d2520
SC
71// get the origin of the client area in the client coordinates
72wxPoint wxFrame::GetClientAreaOrigin() const
73{
74 wxPoint pt = wxTopLevelWindow::GetClientAreaOrigin();
7ad25aed 75
e56d2520
SC
76#if wxUSE_TOOLBAR && !defined(__WXUNIVERSAL__)
77 wxToolBar *toolbar = GetToolBar();
78 if ( toolbar && toolbar->IsShown() )
79 {
80 int w, h;
81 toolbar->GetSize(&w, &h);
7ad25aed 82
e56d2520
SC
83 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
84 {
85 pt.x += w;
86 }
87 else
88 {
89#if !wxMAC_USE_NATIVE_TOOLBAR
90 pt.y += h;
91#endif
92 }
93 }
7ad25aed 94#endif
be6068f6 95
e56d2520
SC
96 return pt;
97}
e9576ca5 98
0d53fc34 99bool wxFrame::Enable(bool enable)
e9576ca5 100{
2f1ae414 101 if ( !wxWindow::Enable(enable) )
902725ee 102 return false;
e9576ca5 103
e40298d5
JS
104 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
105 {
7ad25aed 106 int iMaxMenu = m_frameMenuBar->GetMenuCount();
e40298d5
JS
107 for ( int i = 0 ; i < iMaxMenu ; ++ i )
108 {
109 m_frameMenuBar->EnableTop( i , enable ) ;
110 }
111 }
2f1ae414 112
902725ee 113 return true;
2f1ae414 114}
e9576ca5 115
72c1ba98 116#if wxUSE_STATUSBAR
0d53fc34 117wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
e9576ca5
SC
118 const wxString& name)
119{
7ad25aed 120 wxStatusBar *statusBar;
e9576ca5 121
7ad25aed 122 statusBar = new wxStatusBar(this, id, style, name);
617bfeec 123 statusBar->SetSize(100, WX_MAC_STATUSBAR_HEIGHT);
e9576ca5 124 statusBar->SetFieldsCount(number);
7ad25aed 125
e9576ca5
SC
126 return statusBar;
127}
128
0d53fc34 129void wxFrame::PositionStatusBar()
e9576ca5 130{
f5d63a57 131 if (m_frameStatusBar && m_frameStatusBar->IsShown() )
e40298d5
JS
132 {
133 int w, h;
134 GetClientSize(&w, &h);
902725ee 135
e40298d5
JS
136 // Since we wish the status bar to be directly under the client area,
137 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
f80ffb32 138 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
e40298d5 139 }
e9576ca5 140}
72c1ba98 141#endif // wxUSE_STATUSBAR
e9576ca5 142
e9576ca5 143// Responds to colour changes, and passes event on to children.
0d53fc34 144void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
e9576ca5 145{
a756f210 146 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
e9576ca5
SC
147 Refresh();
148
72c1ba98 149#if wxUSE_STATUSBAR
e9576ca5
SC
150 if ( m_frameStatusBar )
151 {
152 wxSysColourChangedEvent event2;
7ad25aed 153
e9576ca5
SC
154 event2.SetEventObject( m_frameStatusBar );
155 m_frameStatusBar->ProcessEvent(event2);
156 }
72c1ba98 157#endif // wxUSE_STATUSBAR
e9576ca5
SC
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
SC
358
359 if (GetToolBar())
360 {
facd6764 361 int tx, ty, tw, th;
902725ee 362
7ad25aed
DS
363 tx = ty = 0 ;
364 GetToolBar()->GetSize(&tw, &th);
e9576ca5
SC
365 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
366 {
367 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
368 // means, pretend we don't have toolbar/status bar, so we
369 // have the original client size.
facd6764 370 GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
e9576ca5 371 }
f4183326 372 else if (GetToolBar()->GetWindowStyleFlag() & wxTB_BOTTOM)
5b2acc3a 373 {
f4183326
KO
374 //FIXME: this positions the tool bar almost correctly, but still it doesn't work right yet,
375 //as 1) the space for the 'old' top toolbar is still taken up, and 2) the toolbar
376 //doesn't extend it's width to the width of the frame.
5b2acc3a 377 tx = 0;
f4183326
KO
378 ty = ch - (th + statusY);
379 GetToolBar()->SetSize(tx, ty, cw, th, wxSIZE_NO_ADJUSTMENTS );
5b2acc3a 380 }
e9576ca5
SC
381 else
382 {
e56d2520 383#if !wxMAC_USE_NATIVE_TOOLBAR
e9576ca5 384 // Use the 'real' position
facd6764 385 GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS );
e56d2520 386#endif
e9576ca5
SC
387 }
388 }
389}
72c1ba98 390#endif // wxUSE_TOOLBAR
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
72c1ba98 402