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