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