]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/frame.cpp
added virtual DoSetSize method in order to allow for MacOSX Listbox bug workaround
[wxWidgets.git] / src / mac / carbon / frame.cpp
... / ...
CommitLineData
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"
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 wxWindowList wxModelessWindows;
29extern wxList wxPendingDelete;
30
31#if !USE_SHARED_LIBRARY
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)
38END_EVENT_TABLE()
39
40IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
41#endif
42
43#if wxUSE_NATIVE_STATUSBAR
44bool wxFrame::m_useNativeStatusBar = TRUE;
45#else
46bool wxFrame::m_useNativeStatusBar = FALSE;
47#endif
48
49#define WX_MAC_STATUSBAR_HEIGHT 15
50// ----------------------------------------------------------------------------
51// creation/destruction
52// ----------------------------------------------------------------------------
53
54void wxFrame::Init()
55{
56 m_frameMenuBar = NULL;
57
58#if wxUSE_TOOLBAR
59 m_frameToolBar = NULL ;
60#endif
61 m_frameStatusBar = NULL;
62 m_winLastFocused = NULL ;
63
64 m_iconized = FALSE;
65
66#if wxUSE_TOOLTIPS
67 m_hwndToolTip = 0;
68#endif
69}
70
71wxPoint wxFrame::GetClientAreaOrigin() const
72{
73 // on mac we are at position -1,-1 with the control
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;
94}
95
96bool wxFrame::Create(wxWindow *parent,
97 wxWindowID id,
98 const wxString& title,
99 const wxPoint& pos,
100 const wxSize& size,
101 long style,
102 const wxString& name)
103{
104 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
105
106 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
107 return FALSE;
108
109 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
110
111 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
112
113 wxModelessWindows.Append(this);
114
115 return TRUE;
116}
117
118wxFrame::~wxFrame()
119{
120 m_isBeingDeleted = TRUE;
121
122 DeleteAllBars();
123
124}
125
126
127bool wxFrame::Enable(bool enable)
128{
129 if ( !wxWindow::Enable(enable) )
130 return FALSE;
131
132 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
133 {
134 for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i )
135 {
136 m_frameMenuBar->EnableTop( i , enable ) ;
137 }
138 }
139
140 return TRUE;
141}
142
143wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
144 const wxString& name)
145{
146 wxStatusBar *statusBar = NULL;
147
148 statusBar = new wxStatusBar(this, id,
149 style, name);
150 statusBar->SetSize( 100 , 15 ) ;
151 statusBar->SetFieldsCount(number);
152 return statusBar;
153}
154
155void wxFrame::PositionStatusBar()
156{
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 }
168}
169
170// Responds to colour changes, and passes event on to children.
171void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
172{
173 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
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
187
188// Default activation behaviour - set the focus for the first child
189// subwindow found.
190void wxFrame::OnActivate(wxActivateEvent& event)
191{
192 if ( !event.GetActive() )
193 {
194 // remember the last focused child if it is our child
195 m_winLastFocused = FindFocus();
196
197 // so we NULL it out if it's a child from some other frame
198 wxWindow *win = m_winLastFocused;
199 while ( win )
200 {
201 if ( win->IsTopLevel() )
202 {
203 if ( win != this )
204 {
205 m_winLastFocused = NULL;
206 }
207
208 break;
209 }
210
211 win = win->GetParent();
212 }
213
214 event.Skip();
215 }
216 else
217 {
218 // restore focus to the child which was last focused
219 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
220 : NULL;
221 if ( !parent )
222 {
223 parent = this;
224 }
225
226 wxSetFocusToChild(parent, &m_winLastFocused);
227
228 if ( m_frameMenuBar != NULL )
229 {
230 m_frameMenuBar->MacInstallMenuBar() ;
231 }
232 }
233}
234
235void wxFrame::DoGetClientSize(int *x, int *y) const
236{
237 wxWindow::DoGetClientSize( x , y ) ;
238
239#if wxUSE_STATUSBAR
240 if ( GetStatusBar() && y )
241 {
242 int statusX, statusY;
243 GetStatusBar()->GetClientSize(&statusX, &statusY);
244 *y -= statusY;
245 }
246#endif // wxUSE_STATUSBAR
247
248 wxPoint pt(GetClientAreaOrigin());
249 if ( y )
250 *y -= pt.y;
251 if ( x )
252 *x -= pt.x;
253}
254
255void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
256{
257 int currentclientwidth , currentclientheight ;
258 int currentwidth , currentheight ;
259
260 GetClientSize( &currentclientwidth , &currentclientheight ) ;
261 GetSize( &currentwidth , &currentheight ) ;
262
263 // find the current client size
264
265 // Find the difference between the entire window (title bar and all)
266 // and the client area; add this to the new client size to move the
267 // window
268
269 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
270 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
271}
272
273
274#if wxUSE_TOOLBAR
275wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
276{
277 if ( wxFrameBase::CreateToolBar(style, id, name) )
278 {
279 PositionToolBar();
280 }
281
282 return m_frameToolBar;
283}
284
285void wxFrame::PositionToolBar()
286{
287 int cw, ch;
288
289 cw = m_width ;
290 ch = m_height ;
291
292 if ( GetStatusBar() )
293 {
294 int statusX, statusY;
295 GetStatusBar()->GetClientSize(&statusX, &statusY);
296 ch -= statusY;
297 }
298
299 if (GetToolBar())
300 {
301 int tw, th;
302 GetToolBar()->GetSize(& tw, & th);
303
304 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
305 {
306 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
307 // means, pretend we don't have toolbar/status bar, so we
308 // have the original client size.
309 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
310 }
311 else
312 {
313 // Use the 'real' position
314 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
315 }
316 }
317}
318#endif