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