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