]> git.saurik.com Git - wxWidgets.git/blame - src/mac/frame.cpp
corrected indentation
[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"
2f1ae414 17#include "wx/mac/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
SC
102 m_frameStatusBar = NULL;
103
104 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
105
106 if ( id > -1 )
107 m_windowId = id;
108 else
109 m_windowId = (int)NewControlId();
110
111 if (parent) parent->AddChild(this);
112
2f1ae414
SC
113 if (!parent)
114 wxTopLevelWindows.Append(this);
519cb848 115
2f1ae414
SC
116 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
117
118 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
519cb848 119
2f1ae414 120 wxModelessWindows.Append(this);
519cb848 121
519cb848 122 return TRUE;
e9576ca5
SC
123}
124
125wxFrame::~wxFrame()
126{
2f1ae414 127 m_isBeingDeleted = TRUE;
e9576ca5
SC
128 wxTopLevelWindows.DeleteObject(this);
129
2f1ae414 130 DeleteAllBars();
e9576ca5
SC
131
132/* Check if it's the last top-level window */
133
134 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
135 {
136 wxTheApp->SetTopWindow(NULL);
137
138 if (wxTheApp->GetExitOnFrameDelete())
139 {
519cb848 140 wxTheApp->ExitMainLoop() ;
e9576ca5
SC
141 }
142 }
143
144 wxModelessWindows.DeleteObject(this);
145}
146
e9576ca5 147
2f1ae414 148bool wxFrame::Enable(bool enable)
e9576ca5 149{
2f1ae414
SC
150 if ( !wxWindow::Enable(enable) )
151 return FALSE;
e9576ca5 152
2f1ae414
SC
153 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
154 {
155 for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i )
156 {
157 m_frameMenuBar->EnableTop( i , enable ) ;
158 }
159 }
160
161 return TRUE;
162}
e9576ca5
SC
163// Equivalent to maximize/restore in Windows
164void wxFrame::Maximize(bool maximize)
165{
166 // TODO
167}
168
169bool wxFrame::IsIconized() const
170{
171 // TODO
172 return FALSE;
173}
174
2f1ae414
SC
175void wxFrame::Iconize(bool iconize)
176{
177 // TODO
178}
179
e9576ca5
SC
180// Is the frame maximized?
181bool wxFrame::IsMaximized(void) const
182{
183 // TODO
184 return FALSE;
185}
186
2f1ae414
SC
187void wxFrame::Restore()
188{
189 // TODO
190}
191
e9576ca5
SC
192void wxFrame::SetIcon(const wxIcon& icon)
193{
2f1ae414 194 wxFrameBase::SetIcon(icon);
e9576ca5
SC
195}
196
197wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
198 const wxString& name)
199{
200 wxStatusBar *statusBar = NULL;
201
2f1ae414 202 statusBar = new wxStatusBar(this, id, style, name);
519cb848 203
e9576ca5
SC
204 statusBar->SetFieldsCount(number);
205 return statusBar;
206}
207
e9576ca5
SC
208void wxFrame::PositionStatusBar()
209{
519cb848
SC
210 if (m_frameStatusBar )
211 {
e9576ca5
SC
212 int w, h;
213 GetClientSize(&w, &h);
214 int sw, sh;
215 m_frameStatusBar->GetSize(&sw, &sh);
216
217 // Since we wish the status bar to be directly under the client area,
218 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
2f1ae414 219 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT );
519cb848 220 }
e9576ca5
SC
221}
222
223void wxFrame::SetMenuBar(wxMenuBar *menuBar)
224{
225 if (!menuBar)
226 {
e9576ca5
SC
227 return;
228 }
229
2f1ae414 230 m_frameMenuBar = NULL;
e9576ca5 231 m_frameMenuBar = menuBar;
519cb848 232 m_frameMenuBar->MacInstallMenuBar() ;
2f1ae414 233 m_frameMenuBar->Attach(this);
e9576ca5
SC
234}
235
e9576ca5
SC
236
237// Responds to colour changes, and passes event on to children.
238void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
239{
240 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
241 Refresh();
242
243 if ( m_frameStatusBar )
244 {
245 wxSysColourChangedEvent event2;
246 event2.SetEventObject( m_frameStatusBar );
247 m_frameStatusBar->ProcessEvent(event2);
248 }
249
250 // Propagate the event to the non-top-level children
251 wxWindow::OnSysColourChanged(event);
252}
253
e9576ca5
SC
254
255// Default activation behaviour - set the focus for the first child
256// subwindow found.
257void wxFrame::OnActivate(wxActivateEvent& event)
258{
2f1ae414 259 if ( !event.GetActive() )
e9576ca5 260 {
2f1ae414
SC
261 event.Skip();
262 return;
e9576ca5 263 }
e9576ca5 264
2f1ae414
SC
265 for ( wxWindowList::Node *node = GetChildren().GetFirst();
266 node;
267 node = node->GetNext() )
e9576ca5 268 {
2f1ae414
SC
269 // FIXME all this is totally bogus - we need to do the same as wxPanel,
270 // but how to do it without duplicating the code?
e9576ca5 271
2f1ae414
SC
272 // restore focus
273 wxWindow *child = node->GetData();
e9576ca5 274
2f1ae414 275 if ( !child->IsTopLevel()
519cb848 276#if wxUSE_TOOLBAR
2f1ae414
SC
277 && !wxDynamicCast(child, wxToolBar)
278#endif // wxUSE_TOOLBAR
279#if wxUSE_STATUSBAR
280 && !wxDynamicCast(child, wxStatusBar)
281#endif // wxUSE_STATUSBAR
282 )
e9576ca5 283 {
2f1ae414
SC
284 child->SetFocus();
285 return;
e9576ca5
SC
286 }
287 }
e9576ca5
SC
288}
289
7c74e7fe 290void wxFrame::DoGetClientSize(int *x, int *y) const
e9576ca5 291{
7c74e7fe 292 wxWindow::DoGetClientSize( x , y ) ;
519cb848 293
2f1ae414 294#if wxUSE_STATUSBAR
519cb848
SC
295 if ( GetStatusBar() )
296 {
297 int statusX, statusY;
298 GetStatusBar()->GetClientSize(&statusX, &statusY);
2f1ae414
SC
299 // right now this is a constant, this might change someday
300 *y -= WX_MAC_STATUSBAR_HEIGHT ;
519cb848 301 }
2f1ae414 302#endif // wxUSE_STATUSBAR
519cb848
SC
303
304 wxPoint pt(GetClientAreaOrigin());
305 *y -= pt.y;
306 *x -= pt.x;
e9576ca5
SC
307}
308
519cb848 309void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
e9576ca5 310{
519cb848
SC
311 int currentclientwidth , currentclientheight ;
312 int currentwidth , currentheight ;
313
314 GetClientSize( &currentclientwidth , &currentclientheight ) ;
315 GetSize( &currentwidth , &currentheight ) ;
316
317 // find the current client size
318
319 // Find the difference between the entire window (title bar and all)
320 // and the client area; add this to the new client size to move the
321 // window
322
323 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
324 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
e9576ca5
SC
325}
326
519cb848
SC
327
328#if wxUSE_TOOLBAR
e9576ca5
SC
329wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
330{
2f1ae414 331 if ( wxFrameBase::CreateToolBar(style, id, name) )
e9576ca5 332 {
e9576ca5 333 PositionToolBar();
e9576ca5 334 }
e9576ca5 335
2f1ae414 336 return m_frameToolBar;
e9576ca5
SC
337}
338
339void wxFrame::PositionToolBar()
340{
341 int cw, ch;
342
2f1ae414
SC
343 cw = m_width ;
344 ch = m_height ;
e9576ca5
SC
345
346 if ( GetStatusBar() )
347 {
348 int statusX, statusY;
349 GetStatusBar()->GetClientSize(&statusX, &statusY);
350 ch -= statusY;
351 }
352
353 if (GetToolBar())
354 {
355 int tw, th;
356 GetToolBar()->GetSize(& tw, & th);
357
358 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
359 {
360 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
361 // means, pretend we don't have toolbar/status bar, so we
362 // have the original client size.
2f1ae414 363 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
364 }
365 else
366 {
367 // Use the 'real' position
2f1ae414 368 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
e9576ca5
SC
369 }
370 }
371}
519cb848 372#endif