]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/frame.cpp
RTTI and exceptions settings for WinCE are restored.
[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 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "frame.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
e9576ca5 18#include "wx/frame.h"
03e11df5 19#include "wx/statusbr.h"
e9576ca5
SC
20#include "wx/toolbar.h"
21#include "wx/menuitem.h"
22#include "wx/menu.h"
23#include "wx/dcclient.h"
24#include "wx/dialog.h"
25#include "wx/settings.h"
26#include "wx/app.h"
27
d497dca4 28#include "wx/mac/uma.h"
519cb848 29
fe08e597 30extern wxWindowList wxModelessWindows;
e9576ca5
SC
31extern wxList wxPendingDelete;
32
0d53fc34
VS
33BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
34 EVT_ACTIVATE(wxFrame::OnActivate)
35 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
36 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
37// EVT_IDLE(wxFrame::OnIdle)
38// EVT_CLOSE(wxFrame::OnCloseWindow)
e9576ca5
SC
39END_EVENT_TABLE()
40
ac0fa9ef 41IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
e9576ca5 42
902725ee 43#define WX_MAC_STATUSBAR_HEIGHT 18
2f1ae414
SC
44// ----------------------------------------------------------------------------
45// creation/destruction
46// ----------------------------------------------------------------------------
47
0d53fc34 48void wxFrame::Init()
e9576ca5 49{
e40298d5 50 m_frameMenuBar = NULL;
902725ee 51
0a67a93b 52#if wxUSE_TOOLBAR
e40298d5 53 m_frameToolBar = NULL ;
0a67a93b 54#endif
e40298d5
JS
55 m_frameStatusBar = NULL;
56 m_winLastFocused = NULL ;
902725ee
WS
57
58 m_iconized = false;
59
2f1ae414
SC
60#if wxUSE_TOOLTIPS
61 m_hwndToolTip = 0;
519cb848 62#endif
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();
92
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);
99
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 }
111#endif // wxUSE_TOOLBAR
112
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 {
902725ee 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{
136 wxStatusBar *statusBar = NULL;
137
5b781a67
SC
138 statusBar = new wxStatusBar(this, id,
139 style, name);
f80ffb32 140 statusBar->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT ) ;
e9576ca5
SC
141 statusBar->SetFieldsCount(number);
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;
167 event2.SetEventObject( m_frameStatusBar );
168 m_frameStatusBar->ProcessEvent(event2);
169 }
170
171 // Propagate the event to the non-top-level children
172 wxWindow::OnSysColourChanged(event);
173}
174
e9576ca5
SC
175
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 )
192 {
193 m_winLastFocused = NULL;
194 }
195
7810c95b 196 break;
a15eb0a5 197 }
7810c95b 198
a15eb0a5 199 win = win->GetParent();
7810c95b
SC
200 }
201
2f1ae414 202 event.Skip();
e9576ca5 203 }
e40298d5
JS
204 else
205 {
a15eb0a5
SC
206 // restore focus to the child which was last focused
207 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
208 : NULL;
209 if ( !parent )
e9576ca5 210 {
a15eb0a5 211 parent = this;
e9576ca5 212 }
a15eb0a5 213
e40298d5 214 wxSetFocusToChild(parent, &m_winLastFocused);
7810c95b 215
e40298d5
JS
216 if ( m_frameMenuBar != NULL )
217 {
218 m_frameMenuBar->MacInstallMenuBar() ;
219 }
220 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
2b5f62a0
VZ
221 {
222 // Trying toplevel frame menbar
223 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
e40298d5
JS
224 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
225 }
226 }
e9576ca5
SC
227}
228
2b5f62a0
VZ
229void wxFrame::DetachMenuBar()
230{
231 if ( m_frameMenuBar )
232 {
233 m_frameMenuBar->UnsetInvokingWindow();
234 }
235
236 wxFrameBase::DetachMenuBar();
237}
238
239void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
240{
241 wxFrameBase::AttachMenuBar(menuBar);
242
243 if (m_frameMenuBar)
244 {
245 m_frameMenuBar->SetInvokingWindow( this );
246 }
247}
248
0d53fc34 249void wxFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 250{
facd6764 251 wxTopLevelWindow::DoGetClientSize( x , y ) ;
902725ee 252
2f1ae414 253#if wxUSE_STATUSBAR
f5d63a57 254 if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
e40298d5 255 {
902725ee 256 *y -= WX_MAC_STATUSBAR_HEIGHT;
e40298d5 257 }
2f1ae414 258#endif // wxUSE_STATUSBAR
902725ee 259
facd6764
SC
260#if wxUSE_TOOLBAR
261 wxToolBar *toolbar = GetToolBar();
262 if ( toolbar && toolbar->IsShown() )
263 {
264 int w, h;
265 toolbar->GetSize(&w, &h);
266
267 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
268 {
269 if ( x ) *x -= w;
270 }
271 else
272 {
a85245b1 273#if !wxMAC_USE_NATIVE_TOOLBAR
facd6764 274 if ( y ) *y -= h;
a85245b1 275#endif
facd6764
SC
276 }
277 }
278#endif // wxUSE_TOOLBAR
e9576ca5
SC
279}
280
902725ee 281bool wxFrame::MacIsChildOfClientArea( const wxWindow* child ) const
e905b636
SC
282{
283#if wxUSE_STATUSBAR
284 if ( child == GetStatusBar() )
285 return false ;
286#endif // wxUSE_STATUSBAR
287
288#if wxUSE_TOOLBAR
289 if ( child == GetToolBar() )
290 return false ;
291#endif // wxUSE_TOOLBAR
292
293 return wxFrameBase::MacIsChildOfClientArea( child ) ;
294}
295
0d53fc34 296void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 297{
e40298d5
JS
298 int currentclientwidth , currentclientheight ;
299 int currentwidth , currentheight ;
902725ee 300
e40298d5 301 GetClientSize( &currentclientwidth , &currentclientheight ) ;
facd6764
SC
302 if ( clientwidth == -1 )
303 clientwidth = currentclientwidth ;
304 if ( clientheight == -1 )
305 clientheight = currentclientheight ;
e40298d5 306 GetSize( &currentwidth , &currentheight ) ;
902725ee 307
e40298d5 308 // find the current client size
519cb848
SC
309
310 // Find the difference between the entire window (title bar and all)
311 // and the client area; add this to the new client size to move the
312 // window
313
e40298d5
JS
314 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
315 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
e9576ca5
SC
316}
317
519cb848
SC
318
319#if wxUSE_TOOLBAR
e56d2520
SC
320void wxFrame::SetToolBar(wxToolBar *toolbar)
321{
322 if ( m_frameToolBar == toolbar )
323 return ;
324
325#if wxMAC_USE_NATIVE_TOOLBAR
326 if ( m_frameToolBar )
327 m_frameToolBar->MacInstallNativeToolbar(false) ;
328#endif
329
330 m_frameToolBar = toolbar ;
331#if wxMAC_USE_NATIVE_TOOLBAR
332 if ( toolbar )
333 toolbar->MacInstallNativeToolbar( true ) ;
334#endif
335}
336
0d53fc34 337wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
e9576ca5 338{
2f1ae414 339 if ( wxFrameBase::CreateToolBar(style, id, name) )
e9576ca5 340 {
e9576ca5 341 PositionToolBar();
e9576ca5 342 }
e9576ca5 343
2f1ae414 344 return m_frameToolBar;
e9576ca5
SC
345}
346
0d53fc34 347void wxFrame::PositionToolBar()
e9576ca5
SC
348{
349 int cw, ch;
350
facd6764 351 GetSize( &cw , &ch ) ;
e9576ca5 352
f5d63a57 353 if ( GetStatusBar() && GetStatusBar()->IsShown())
e9576ca5
SC
354 {
355 int statusX, statusY;
356 GetStatusBar()->GetClientSize(&statusX, &statusY);
357 ch -= statusY;
358 }
359
360 if (GetToolBar())
361 {
facd6764
SC
362 int tx, ty, tw, th;
363 tx = ty = 0 ;
902725ee 364
e9576ca5 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
SC
372 }
373 else
374 {
e56d2520 375#if !wxMAC_USE_NATIVE_TOOLBAR
e9576ca5 376 // Use the 'real' position
facd6764 377 GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS );
e56d2520 378#endif
e9576ca5
SC
379 }
380 }
381}
519cb848 382#endif