]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/frame.cpp
great copy ctor/assignment operators cleanup by Paul Cornett (patch 1307665)
[wxWidgets.git] / src / mac / classic / frame.cpp
CommitLineData
2646f485
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: 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
65571936 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
2646f485
SC
12#include "wx/frame.h"
13#include "wx/statusbr.h"
14#include "wx/toolbar.h"
15#include "wx/menuitem.h"
16#include "wx/menu.h"
17#include "wx/dcclient.h"
18#include "wx/dialog.h"
19#include "wx/settings.h"
20#include "wx/app.h"
21
22#include "wx/mac/uma.h"
23
24extern wxWindowList wxModelessWindows;
25extern wxList wxPendingDelete;
26
2646f485
SC
27BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
28 EVT_ACTIVATE(wxFrame::OnActivate)
29 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
30 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
31// EVT_IDLE(wxFrame::OnIdle)
32// EVT_CLOSE(wxFrame::OnCloseWindow)
33END_EVENT_TABLE()
34
35IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
2646f485
SC
36
37#define WX_MAC_STATUSBAR_HEIGHT 15
38// ----------------------------------------------------------------------------
39// creation/destruction
40// ----------------------------------------------------------------------------
41
42void wxFrame::Init()
43{
44 m_frameMenuBar = NULL;
45
46#if wxUSE_TOOLBAR
47 m_frameToolBar = NULL ;
48#endif
49 m_frameStatusBar = NULL;
50 m_winLastFocused = NULL ;
51
52 m_iconized = FALSE;
53
54#if wxUSE_TOOLTIPS
55 m_hwndToolTip = 0;
56#endif
57}
58
59wxPoint wxFrame::GetClientAreaOrigin() const
60{
61 // on mac we are at position -1,-1 with the control
62 wxPoint pt(0, 0);
63
64#if wxUSE_TOOLBAR
65 if ( GetToolBar() )
66 {
67 int w, h;
68 GetToolBar()->GetSize(& w, & h);
69
70 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
71 {
72 pt.x += w - 1;
73 }
74 else
75 {
76 pt.y += h - 1 ;
77 }
78 }
79#endif // wxUSE_TOOLBAR
80
81 return pt;
82}
83
84bool wxFrame::Create(wxWindow *parent,
85 wxWindowID id,
86 const wxString& title,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
91{
92 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
93
94 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
95 return FALSE;
96
97 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
98
99 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
100 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
101
102 wxModelessWindows.Append(this);
103
104 return TRUE;
105}
106
107wxFrame::~wxFrame()
108{
109 m_isBeingDeleted = TRUE;
110 DeleteAllBars();
111}
112
113
114bool wxFrame::Enable(bool enable)
115{
116 if ( !wxWindow::Enable(enable) )
117 return FALSE;
118
119 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
120 {
121 int iMaxMenu = m_frameMenuBar->GetMenuCount();
122 for ( int i = 0 ; i < iMaxMenu ; ++ i )
123 {
124 m_frameMenuBar->EnableTop( i , enable ) ;
125 }
126 }
127
128 return TRUE;
129}
130
131wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
132 const wxString& name)
133{
134 wxStatusBar *statusBar = NULL;
135
136 statusBar = new wxStatusBar(this, id,
137 style, name);
138 statusBar->SetSize( 100 , 15 ) ;
139 statusBar->SetFieldsCount(number);
140 return statusBar;
141}
142
143void wxFrame::PositionStatusBar()
144{
145 if (m_frameStatusBar )
146 {
147 int w, h;
148 GetClientSize(&w, &h);
149 int sw, sh;
150 m_frameStatusBar->GetSize(&sw, &sh);
151
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.
154 m_frameStatusBar->SetSize(0, h, w, sh);
155 }
156}
157
158// Responds to colour changes, and passes event on to children.
159void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
160{
161 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
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
175
176// Default activation behaviour - set the focus for the first child
177// subwindow found.
178void wxFrame::OnActivate(wxActivateEvent& event)
179{
180 if ( !event.GetActive() )
181 {
182 // remember the last focused child if it is our child
183 m_winLastFocused = FindFocus();
184
185 // so we NULL it out if it's a child from some other frame
186 wxWindow *win = m_winLastFocused;
187 while ( win )
188 {
189 if ( win->IsTopLevel() )
190 {
191 if ( win != this )
192 {
193 m_winLastFocused = NULL;
194 }
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 ? m_winLastFocused->GetParent()
208 : NULL;
209 if ( !parent )
210 {
211 parent = this;
212 }
213
214 wxSetFocusToChild(parent, &m_winLastFocused);
215
216 if ( m_frameMenuBar != NULL )
217 {
218 m_frameMenuBar->MacInstallMenuBar() ;
219 }
220 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
221 {
222 // Trying toplevel frame menbar
223 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
224 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
225 }
226 }
227}
228
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
249void wxFrame::DoGetClientSize(int *x, int *y) const
250{
251 wxWindow::DoGetClientSize( x , y ) ;
252
253#if wxUSE_STATUSBAR
254 if ( GetStatusBar() && y )
255 {
256 int statusX, statusY;
257 GetStatusBar()->GetClientSize(&statusX, &statusY);
258 *y -= statusY;
259 }
260#endif // wxUSE_STATUSBAR
261
262 wxPoint pt(GetClientAreaOrigin());
263 if ( y )
264 *y -= pt.y;
265 if ( x )
266 *x -= pt.x;
267}
268
269void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
270{
271 int currentclientwidth , currentclientheight ;
272 int currentwidth , currentheight ;
273
274 GetClientSize( &currentclientwidth , &currentclientheight ) ;
275 GetSize( &currentwidth , &currentheight ) ;
276
277 // find the current client size
278
279 // Find the difference between the entire window (title bar and all)
280 // and the client area; add this to the new client size to move the
281 // window
282
283 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
284 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
285}
286
287
288#if wxUSE_TOOLBAR
289wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
290{
291 if ( wxFrameBase::CreateToolBar(style, id, name) )
292 {
293 PositionToolBar();
294 }
295
296 return m_frameToolBar;
297}
298
299void wxFrame::PositionToolBar()
300{
301 int cw, ch;
302
303 cw = m_width ;
304 ch = m_height ;
305
306 if ( GetStatusBar() )
307 {
308 int statusX, statusY;
309 GetStatusBar()->GetClientSize(&statusX, &statusY);
310 ch -= statusY;
311 }
312
313 if (GetToolBar())
314 {
315 int tw, th;
316 GetToolBar()->GetSize(& tw, & th);
317
318 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
319 {
320 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
321 // means, pretend we don't have toolbar/status bar, so we
322 // have the original client size.
323 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
324 }
325 else
326 {
327 // Use the 'real' position
328 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
329 }
330 }
331}
332#endif