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