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