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