]> git.saurik.com Git - wxWidgets.git/blame - src/mac/frame.cpp
Got rid of some wierd VisualAge debug nonsense that had appeared in this after the...
[wxWidgets.git] / src / mac / frame.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
3// Purpose: wxFrame
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "frame.h"
14#endif
15
16#include "wx/frame.h"
03e11df5 17#include "wx/statusbr.h"
e9576ca5
SC
18#include "wx/toolbar.h"
19#include "wx/menuitem.h"
20#include "wx/menu.h"
21#include "wx/dcclient.h"
22#include "wx/dialog.h"
23#include "wx/settings.h"
24#include "wx/app.h"
25
519cb848
SC
26#include <wx/mac/uma.h>
27
e9576ca5
SC
28extern wxList wxModelessWindows;
29extern wxList wxPendingDelete;
30
2f1ae414
SC
31#if !USE_SHARED_LIBRARY
32BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
33// EVT_SIZE(wxFrame::OnSize)
e9576ca5 34 EVT_ACTIVATE(wxFrame::OnActivate)
2f1ae414 35 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
e9576ca5 36 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
2f1ae414
SC
37// EVT_IDLE(wxFrame::OnIdle)
38// EVT_CLOSE(wxFrame::OnCloseWindow)
e9576ca5
SC
39END_EVENT_TABLE()
40
41IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
2f1ae414 42#endif
e9576ca5
SC
43
44#if wxUSE_NATIVE_STATUSBAR
45bool wxFrame::m_useNativeStatusBar = TRUE;
46#else
47bool wxFrame::m_useNativeStatusBar = FALSE;
48#endif
49
2f1ae414
SC
50#define WX_MAC_STATUSBAR_HEIGHT 15
51// ----------------------------------------------------------------------------
52// creation/destruction
53// ----------------------------------------------------------------------------
54
55void wxFrame::Init()
e9576ca5 56{
2f1ae414
SC
57 m_iconized = FALSE;
58
59#if wxUSE_TOOLTIPS
60 m_hwndToolTip = 0;
519cb848 61#endif
2f1ae414 62}
e7549107 63
2f1ae414
SC
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;
e9576ca5
SC
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{
e9576ca5 97 m_frameMenuBar = NULL;
519cb848
SC
98
99#if wxUSE_TOOLBAR
e9576ca5 100 m_frameToolBar = NULL ;
519cb848 101#endif
e9576ca5 102 m_frameStatusBar = NULL;
7810c95b 103 m_winLastFocused = NULL ;
e9576ca5
SC
104
105 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
106
107 if ( id > -1 )
108 m_windowId = id;
109 else
110 m_windowId = (int)NewControlId();
111
112 if (parent) parent->AddChild(this);
113
2f1ae414
SC
114 if (!parent)
115 wxTopLevelWindows.Append(this);
519cb848 116
2f1ae414
SC
117 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
118
119 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
519cb848 120
2f1ae414 121 wxModelessWindows.Append(this);
519cb848 122
519cb848 123 return TRUE;
e9576ca5
SC
124}
125
126wxFrame::~wxFrame()
127{
2f1ae414 128 m_isBeingDeleted = TRUE;
e9576ca5
SC
129 wxTopLevelWindows.DeleteObject(this);
130
2f1ae414 131 DeleteAllBars();
e9576ca5
SC
132
133/* Check if it's the last top-level window */
134
135 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
136 {
137 wxTheApp->SetTopWindow(NULL);
138
139 if (wxTheApp->GetExitOnFrameDelete())
140 {
519cb848 141 wxTheApp->ExitMainLoop() ;
e9576ca5
SC
142 }
143 }
144
145 wxModelessWindows.DeleteObject(this);
146}
147
e9576ca5 148
2f1ae414 149bool wxFrame::Enable(bool enable)
e9576ca5 150{
2f1ae414
SC
151 if ( !wxWindow::Enable(enable) )
152 return FALSE;
e9576ca5 153
2f1ae414
SC
154 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
155 {
156 for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i )
157 {
158 m_frameMenuBar->EnableTop( i , enable ) ;
159 }
160 }
161
162 return TRUE;
163}
e9576ca5
SC
164// Equivalent to maximize/restore in Windows
165void wxFrame::Maximize(bool maximize)
166{
167 // TODO
168}
169
170bool wxFrame::IsIconized() const
171{
172 // TODO
173 return FALSE;
174}
175
2f1ae414
SC
176void wxFrame::Iconize(bool iconize)
177{
178 // TODO
179}
180
e9576ca5
SC
181// Is the frame maximized?
182bool wxFrame::IsMaximized(void) const
183{
184 // TODO
185 return FALSE;
186}
187
2f1ae414
SC
188void wxFrame::Restore()
189{
190 // TODO
191}
192
e9576ca5
SC
193void wxFrame::SetIcon(const wxIcon& icon)
194{
2f1ae414 195 wxFrameBase::SetIcon(icon);
e9576ca5
SC
196}
197
198wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
199 const wxString& name)
200{
201 wxStatusBar *statusBar = NULL;
202
5b781a67
SC
203 statusBar = new wxStatusBar(this, id,
204 style, name);
205 statusBar->SetSize( 100 , 15 ) ;
e9576ca5
SC
206 statusBar->SetFieldsCount(number);
207 return statusBar;
208}
209
e9576ca5
SC
210void wxFrame::PositionStatusBar()
211{
519cb848
SC
212 if (m_frameStatusBar )
213 {
e9576ca5
SC
214 int w, h;
215 GetClientSize(&w, &h);
216 int sw, sh;
217 m_frameStatusBar->GetSize(&sw, &sh);
218
219 // Since we wish the status bar to be directly under the client area,
220 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
5b781a67 221 m_frameStatusBar->SetSize(0, h, w, sh);
519cb848 222 }
e9576ca5
SC
223}
224
225void wxFrame::SetMenuBar(wxMenuBar *menuBar)
226{
227 if (!menuBar)
228 {
e9576ca5
SC
229 return;
230 }
231
2f1ae414 232 m_frameMenuBar = NULL;
e9576ca5 233 m_frameMenuBar = menuBar;
41f38f4d 234// m_frameMenuBar->MacInstallMenuBar() ;
2f1ae414 235 m_frameMenuBar->Attach(this);
e9576ca5
SC
236}
237
e9576ca5
SC
238
239// Responds to colour changes, and passes event on to children.
240void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
241{
242 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
243 Refresh();
244
245 if ( m_frameStatusBar )
246 {
247 wxSysColourChangedEvent event2;
248 event2.SetEventObject( m_frameStatusBar );
249 m_frameStatusBar->ProcessEvent(event2);
250 }
251
252 // Propagate the event to the non-top-level children
253 wxWindow::OnSysColourChanged(event);
254}
255
e9576ca5
SC
256
257// Default activation behaviour - set the focus for the first child
258// subwindow found.
259void wxFrame::OnActivate(wxActivateEvent& event)
260{
2f1ae414 261 if ( !event.GetActive() )
e9576ca5 262 {
7810c95b
SC
263 // remember the last focused child
264 m_winLastFocused = FindFocus();
265 while ( m_winLastFocused )
266 {
267 if ( GetChildren().Find(m_winLastFocused) )
268 break;
269
270 m_winLastFocused = m_winLastFocused->GetParent();
271 }
272
2f1ae414 273 event.Skip();
e9576ca5 274 }
7810c95b
SC
275 else
276 {
277/*
2f1ae414
SC
278 for ( wxWindowList::Node *node = GetChildren().GetFirst();
279 node;
280 node = node->GetNext() )
e9576ca5 281 {
2f1ae414
SC
282 // FIXME all this is totally bogus - we need to do the same as wxPanel,
283 // but how to do it without duplicating the code?
e9576ca5 284
2f1ae414
SC
285 // restore focus
286 wxWindow *child = node->GetData();
e9576ca5 287
7810c95b 288 if ( !child->IsTopLevel() && child->AcceptsFocus()
519cb848 289#if wxUSE_TOOLBAR
2f1ae414
SC
290 && !wxDynamicCast(child, wxToolBar)
291#endif // wxUSE_TOOLBAR
292#if wxUSE_STATUSBAR
293 && !wxDynamicCast(child, wxStatusBar)
294#endif // wxUSE_STATUSBAR
295 )
e9576ca5 296 {
2f1ae414 297 child->SetFocus();
41f38f4d 298 break;
e9576ca5
SC
299 }
300 }
7810c95b
SC
301 */
302 wxSetFocusToChild(this, &m_winLastFocused);
303
304 if ( m_frameMenuBar != NULL )
305 {
306 m_frameMenuBar->MacInstallMenuBar() ;
307 }
308 }
e9576ca5
SC
309}
310
7c74e7fe 311void wxFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 312{
7c74e7fe 313 wxWindow::DoGetClientSize( x , y ) ;
519cb848 314
2f1ae414 315#if wxUSE_STATUSBAR
519cb848
SC
316 if ( GetStatusBar() )
317 {
318 int statusX, statusY;
319 GetStatusBar()->GetClientSize(&statusX, &statusY);
5b781a67 320 *y -= statusY;
519cb848 321 }
2f1ae414 322#endif // wxUSE_STATUSBAR
519cb848
SC
323
324 wxPoint pt(GetClientAreaOrigin());
325 *y -= pt.y;
326 *x -= pt.x;
e9576ca5
SC
327}
328
519cb848 329void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 330{
519cb848
SC
331 int currentclientwidth , currentclientheight ;
332 int currentwidth , currentheight ;
333
334 GetClientSize( &currentclientwidth , &currentclientheight ) ;
335 GetSize( &currentwidth , &currentheight ) ;
336
337 // find the current client size
338
339 // Find the difference between the entire window (title bar and all)
340 // and the client area; add this to the new client size to move the
341 // window
342
343 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
344 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
e9576ca5
SC
345}
346
519cb848
SC
347
348#if wxUSE_TOOLBAR
e9576ca5
SC
349wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
350{
2f1ae414 351 if ( wxFrameBase::CreateToolBar(style, id, name) )
e9576ca5 352 {
e9576ca5 353 PositionToolBar();
e9576ca5 354 }
e9576ca5 355
2f1ae414 356 return m_frameToolBar;
e9576ca5
SC
357}
358
359void wxFrame::PositionToolBar()
360{
361 int cw, ch;
362
2f1ae414
SC
363 cw = m_width ;
364 ch = m_height ;
e9576ca5
SC
365
366 if ( GetStatusBar() )
367 {
368 int statusX, statusY;
369 GetStatusBar()->GetClientSize(&statusX, &statusY);
370 ch -= statusY;
371 }
372
373 if (GetToolBar())
374 {
375 int tw, th;
376 GetToolBar()->GetSize(& tw, & th);
377
378 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
379 {
380 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
381 // means, pretend we don't have toolbar/status bar, so we
382 // have the original client size.
2f1ae414 383 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
384 }
385 else
386 {
387 // Use the 'real' position
2f1ae414 388 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
389 }
390 }
391}
519cb848 392#endif