]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/frame.cpp
Added missing wx_aui.dsp file
[wxWidgets.git] / src / mac / classic / frame.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
670f9935 2// Name: src/mac/classic/frame.cpp
2646f485
SC
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
670f9935
WS
12#include "wx/wxprec.h"
13
2646f485 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"
670f9935
WS
23#endif // WX_PRECOMP
24
2646f485 25#include "wx/statusbr.h"
2646f485 26#include "wx/menuitem.h"
2646f485
SC
27
28#include "wx/mac/uma.h"
29
30extern wxWindowList wxModelessWindows;
2646f485 31
2646f485
SC
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)
2646f485 41
670f9935 42#define WX_MAC_STATUSBAR_HEIGHT 15
2646f485
SC
43// ----------------------------------------------------------------------------
44// creation/destruction
45// ----------------------------------------------------------------------------
46
47void wxFrame::Init()
48{
49 m_frameMenuBar = NULL;
670f9935 50
2646f485
SC
51#if wxUSE_TOOLBAR
52 m_frameToolBar = NULL ;
53#endif
54 m_frameStatusBar = NULL;
55 m_winLastFocused = NULL ;
670f9935
WS
56
57 m_iconized = false;
58
2646f485
SC
59#if wxUSE_TOOLTIPS
60 m_hwndToolTip = 0;
61#endif
62}
63
64wxPoint wxFrame::GetClientAreaOrigin() const
65{
66 // on mac we are at position -1,-1 with the control
67 wxPoint pt(0, 0);
68
69#if wxUSE_TOOLBAR
70 if ( GetToolBar() )
71 {
72 int w, h;
73 GetToolBar()->GetSize(& w, & h);
74
75 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
76 {
77 pt.x += w - 1;
78 }
79 else
80 {
81 pt.y += h - 1 ;
82 }
83 }
84#endif // wxUSE_TOOLBAR
85
86 return pt;
87}
88
89bool wxFrame::Create(wxWindow *parent,
90 wxWindowID id,
91 const wxString& title,
92 const wxPoint& pos,
93 const wxSize& size,
94 long style,
95 const wxString& name)
96{
97 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
670f9935 98
2646f485 99 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
670f9935
WS
100 return false;
101
2646f485
SC
102 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
103
104 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
105 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
106
107 wxModelessWindows.Append(this);
670f9935
WS
108
109 return true;
2646f485
SC
110}
111
112wxFrame::~wxFrame()
113{
670f9935 114 m_isBeingDeleted = true;
2646f485
SC
115 DeleteAllBars();
116}
117
118
119bool wxFrame::Enable(bool enable)
120{
121 if ( !wxWindow::Enable(enable) )
670f9935 122 return false;
2646f485
SC
123
124 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
125 {
670f9935 126 int iMaxMenu = m_frameMenuBar->GetMenuCount();
2646f485
SC
127 for ( int i = 0 ; i < iMaxMenu ; ++ i )
128 {
129 m_frameMenuBar->EnableTop( i , enable ) ;
130 }
131 }
132
670f9935 133 return true;
2646f485
SC
134}
135
136wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
137 const wxString& name)
138{
139 wxStatusBar *statusBar = NULL;
140
141 statusBar = new wxStatusBar(this, id,
142 style, name);
143 statusBar->SetSize( 100 , 15 ) ;
144 statusBar->SetFieldsCount(number);
145 return statusBar;
146}
147
148void wxFrame::PositionStatusBar()
149{
150 if (m_frameStatusBar )
151 {
152 int w, h;
153 GetClientSize(&w, &h);
154 int sw, sh;
155 m_frameStatusBar->GetSize(&sw, &sh);
670f9935 156
2646f485
SC
157 // Since we wish the status bar to be directly under the client area,
158 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
159 m_frameStatusBar->SetSize(0, h, w, sh);
160 }
161}
162
163// Responds to colour changes, and passes event on to children.
164void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
165{
166 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
167 Refresh();
168
169 if ( m_frameStatusBar )
170 {
171 wxSysColourChangedEvent event2;
172 event2.SetEventObject( m_frameStatusBar );
173 m_frameStatusBar->ProcessEvent(event2);
174 }
175
176 // Propagate the event to the non-top-level children
177 wxWindow::OnSysColourChanged(event);
178}
179
180
181// Default activation behaviour - set the focus for the first child
182// subwindow found.
183void wxFrame::OnActivate(wxActivateEvent& event)
184{
185 if ( !event.GetActive() )
186 {
187 // remember the last focused child if it is our child
188 m_winLastFocused = FindFocus();
189
190 // so we NULL it out if it's a child from some other frame
191 wxWindow *win = m_winLastFocused;
192 while ( win )
193 {
194 if ( win->IsTopLevel() )
195 {
196 if ( win != this )
197 {
198 m_winLastFocused = NULL;
199 }
200
201 break;
202 }
203
204 win = win->GetParent();
205 }
206
207 event.Skip();
208 }
209 else
210 {
211 // restore focus to the child which was last focused
212 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
213 : NULL;
214 if ( !parent )
215 {
216 parent = this;
217 }
218
219 wxSetFocusToChild(parent, &m_winLastFocused);
220
221 if ( m_frameMenuBar != NULL )
222 {
223 m_frameMenuBar->MacInstallMenuBar() ;
224 }
225 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
226 {
227 // Trying toplevel frame menbar
228 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
229 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
230 }
231 }
232}
233
234void wxFrame::DetachMenuBar()
235{
236 if ( m_frameMenuBar )
237 {
238 m_frameMenuBar->UnsetInvokingWindow();
239 }
240
241 wxFrameBase::DetachMenuBar();
242}
243
244void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
245{
246 wxFrameBase::AttachMenuBar(menuBar);
247
248 if (m_frameMenuBar)
249 {
250 m_frameMenuBar->SetInvokingWindow( this );
251 }
252}
253
254void wxFrame::DoGetClientSize(int *x, int *y) const
255{
256 wxWindow::DoGetClientSize( x , y ) ;
670f9935 257
2646f485
SC
258#if wxUSE_STATUSBAR
259 if ( GetStatusBar() && y )
260 {
261 int statusX, statusY;
262 GetStatusBar()->GetClientSize(&statusX, &statusY);
263 *y -= statusY;
264 }
265#endif // wxUSE_STATUSBAR
670f9935 266
2646f485
SC
267 wxPoint pt(GetClientAreaOrigin());
268 if ( y )
269 *y -= pt.y;
670f9935 270 if ( x )
2646f485
SC
271 *x -= pt.x;
272}
273
274void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
275{
276 int currentclientwidth , currentclientheight ;
277 int currentwidth , currentheight ;
670f9935 278
2646f485
SC
279 GetClientSize( &currentclientwidth , &currentclientheight ) ;
280 GetSize( &currentwidth , &currentheight ) ;
670f9935 281
2646f485
SC
282 // find the current client size
283
284 // Find the difference between the entire window (title bar and all)
285 // and the client area; add this to the new client size to move the
286 // window
287
288 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
289 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
290}
291
292
293#if wxUSE_TOOLBAR
294wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
295{
296 if ( wxFrameBase::CreateToolBar(style, id, name) )
297 {
298 PositionToolBar();
299 }
300
301 return m_frameToolBar;
302}
303
304void wxFrame::PositionToolBar()
305{
306 int cw, ch;
307
308 cw = m_width ;
309 ch = m_height ;
310
311 if ( GetStatusBar() )
312 {
313 int statusX, statusY;
314 GetStatusBar()->GetClientSize(&statusX, &statusY);
315 ch -= statusY;
316 }
317
318 if (GetToolBar())
319 {
320 int tw, th;
321 GetToolBar()->GetSize(& tw, & th);
322
323 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
324 {
325 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
326 // means, pretend we don't have toolbar/status bar, so we
327 // have the original client size.
328 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
329 }
330 else
331 {
332 // Use the 'real' position
333 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
334 }
335 }
336}
337#endif