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