]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/frame.cpp
Added extra MicroWindows functions
[wxWidgets.git] / src / mac / carbon / 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{
0a67a93b
SC
57 m_frameMenuBar = NULL;
58
59#if wxUSE_TOOLBAR
60 m_frameToolBar = NULL ;
61#endif
62 m_frameStatusBar = NULL;
63 m_winLastFocused = NULL ;
64
2f1ae414
SC
65 m_iconized = FALSE;
66
67#if wxUSE_TOOLTIPS
68 m_hwndToolTip = 0;
519cb848 69#endif
2f1ae414 70}
e7549107 71
2f1ae414
SC
72wxPoint wxFrame::GetClientAreaOrigin() const
73{
74 // on mac we are at position -1,-1 with the control
75 wxPoint pt(0, 0);
76
77#if wxUSE_TOOLBAR
78 if ( GetToolBar() )
79 {
80 int w, h;
81 GetToolBar()->GetSize(& w, & h);
82
83 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
84 {
85 pt.x += w - 1;
86 }
87 else
88 {
89 pt.y += h - 1 ;
90 }
91 }
92#endif // wxUSE_TOOLBAR
93
94 return pt;
e9576ca5
SC
95}
96
97bool wxFrame::Create(wxWindow *parent,
98 wxWindowID id,
99 const wxString& title,
100 const wxPoint& pos,
101 const wxSize& size,
102 long style,
103 const wxString& name)
104{
e9576ca5
SC
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
232 m_frameMenuBar = menuBar;
41f38f4d 233// m_frameMenuBar->MacInstallMenuBar() ;
2f1ae414 234 m_frameMenuBar->Attach(this);
e9576ca5
SC
235}
236
e9576ca5
SC
237
238// Responds to colour changes, and passes event on to children.
239void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
240{
241 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
242 Refresh();
243
244 if ( m_frameStatusBar )
245 {
246 wxSysColourChangedEvent event2;
247 event2.SetEventObject( m_frameStatusBar );
248 m_frameStatusBar->ProcessEvent(event2);
249 }
250
251 // Propagate the event to the non-top-level children
252 wxWindow::OnSysColourChanged(event);
253}
254
e9576ca5
SC
255
256// Default activation behaviour - set the focus for the first child
257// subwindow found.
258void wxFrame::OnActivate(wxActivateEvent& event)
259{
2f1ae414 260 if ( !event.GetActive() )
e9576ca5 261 {
7810c95b
SC
262 // remember the last focused child
263 m_winLastFocused = FindFocus();
264 while ( m_winLastFocused )
265 {
266 if ( GetChildren().Find(m_winLastFocused) )
267 break;
268
269 m_winLastFocused = m_winLastFocused->GetParent();
270 }
271
2f1ae414 272 event.Skip();
e9576ca5 273 }
7810c95b
SC
274 else
275 {
276/*
2f1ae414
SC
277 for ( wxWindowList::Node *node = GetChildren().GetFirst();
278 node;
279 node = node->GetNext() )
e9576ca5 280 {
2f1ae414
SC
281 // FIXME all this is totally bogus - we need to do the same as wxPanel,
282 // but how to do it without duplicating the code?
e9576ca5 283
2f1ae414
SC
284 // restore focus
285 wxWindow *child = node->GetData();
e9576ca5 286
7810c95b 287 if ( !child->IsTopLevel() && child->AcceptsFocus()
519cb848 288#if wxUSE_TOOLBAR
2f1ae414
SC
289 && !wxDynamicCast(child, wxToolBar)
290#endif // wxUSE_TOOLBAR
291#if wxUSE_STATUSBAR
292 && !wxDynamicCast(child, wxStatusBar)
293#endif // wxUSE_STATUSBAR
294 )
e9576ca5 295 {
2f1ae414 296 child->SetFocus();
41f38f4d 297 break;
e9576ca5
SC
298 }
299 }
7810c95b
SC
300 */
301 wxSetFocusToChild(this, &m_winLastFocused);
302
303 if ( m_frameMenuBar != NULL )
304 {
305 m_frameMenuBar->MacInstallMenuBar() ;
306 }
307 }
e9576ca5
SC
308}
309
7c74e7fe 310void wxFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 311{
7c74e7fe 312 wxWindow::DoGetClientSize( x , y ) ;
519cb848 313
2f1ae414 314#if wxUSE_STATUSBAR
519cb848
SC
315 if ( GetStatusBar() )
316 {
317 int statusX, statusY;
318 GetStatusBar()->GetClientSize(&statusX, &statusY);
5b781a67 319 *y -= statusY;
519cb848 320 }
2f1ae414 321#endif // wxUSE_STATUSBAR
519cb848
SC
322
323 wxPoint pt(GetClientAreaOrigin());
324 *y -= pt.y;
325 *x -= pt.x;
e9576ca5
SC
326}
327
519cb848 328void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 329{
519cb848
SC
330 int currentclientwidth , currentclientheight ;
331 int currentwidth , currentheight ;
332
333 GetClientSize( &currentclientwidth , &currentclientheight ) ;
334 GetSize( &currentwidth , &currentheight ) ;
335
336 // find the current client size
337
338 // Find the difference between the entire window (title bar and all)
339 // and the client area; add this to the new client size to move the
340 // window
341
342 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
343 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
e9576ca5
SC
344}
345
519cb848
SC
346
347#if wxUSE_TOOLBAR
e9576ca5
SC
348wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
349{
2f1ae414 350 if ( wxFrameBase::CreateToolBar(style, id, name) )
e9576ca5 351 {
e9576ca5 352 PositionToolBar();
e9576ca5 353 }
e9576ca5 354
2f1ae414 355 return m_frameToolBar;
e9576ca5
SC
356}
357
358void wxFrame::PositionToolBar()
359{
360 int cw, ch;
361
2f1ae414
SC
362 cw = m_width ;
363 ch = m_height ;
e9576ca5
SC
364
365 if ( GetStatusBar() )
366 {
367 int statusX, statusY;
368 GetStatusBar()->GetClientSize(&statusX, &statusY);
369 ch -= statusY;
370 }
371
372 if (GetToolBar())
373 {
374 int tw, th;
375 GetToolBar()->GetSize(& tw, & th);
376
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.
2f1ae414 382 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
383 }
384 else
385 {
386 // Use the 'real' position
2f1ae414 387 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
388 }
389 }
390}
519cb848 391#endif