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