]> git.saurik.com Git - wxWidgets.git/blob - src/mac/frame.cpp
corrected hiding/showing of native mac controls
[wxWidgets.git] / src / mac / frame.cpp
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
28 extern wxList wxModelessWindows;
29 extern wxList wxPendingDelete;
30
31 #if !USE_SHARED_LIBRARY
32 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
33 // EVT_SIZE(wxFrame::OnSize)
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, wxWindow)
42 #endif
43
44 #if wxUSE_NATIVE_STATUSBAR
45 bool wxFrame::m_useNativeStatusBar = TRUE;
46 #else
47 bool wxFrame::m_useNativeStatusBar = FALSE;
48 #endif
49
50 #define WX_MAC_STATUSBAR_HEIGHT 15
51 // ----------------------------------------------------------------------------
52 // creation/destruction
53 // ----------------------------------------------------------------------------
54
55 void wxFrame::Init()
56 {
57 m_iconized = FALSE;
58
59 #if wxUSE_TOOLTIPS
60 m_hwndToolTip = 0;
61 #endif
62 }
63
64 wxPoint wxFrame::GetClientAreaOrigin() const
65 {
66 // on mac we are at position -1,-1 with the control
67 wxPoint pt(0, 0);
68
69 #if wxUSE_TOOLBAR
70 if ( GetToolBar() )
71 {
72 int w, h;
73 GetToolBar()->GetSize(& w, & h);
74
75 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
76 {
77 pt.x += w - 1;
78 }
79 else
80 {
81 pt.y += h - 1 ;
82 }
83 }
84 #endif // wxUSE_TOOLBAR
85
86 return pt;
87 }
88
89 bool wxFrame::Create(wxWindow *parent,
90 wxWindowID id,
91 const wxString& title,
92 const wxPoint& pos,
93 const wxSize& size,
94 long style,
95 const wxString& name)
96 {
97 m_frameMenuBar = NULL;
98
99 #if wxUSE_TOOLBAR
100 m_frameToolBar = NULL ;
101 #endif
102 m_frameStatusBar = NULL;
103
104 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
105
106 if ( id > -1 )
107 m_windowId = id;
108 else
109 m_windowId = (int)NewControlId();
110
111 if (parent) parent->AddChild(this);
112
113 if (!parent)
114 wxTopLevelWindows.Append(this);
115
116 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
117
118 m_macWindowData->m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
119
120 wxModelessWindows.Append(this);
121
122 return TRUE;
123 }
124
125 wxFrame::~wxFrame()
126 {
127 m_isBeingDeleted = TRUE;
128 wxTopLevelWindows.DeleteObject(this);
129
130 DeleteAllBars();
131
132 /* Check if it's the last top-level window */
133
134 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
135 {
136 wxTheApp->SetTopWindow(NULL);
137
138 if (wxTheApp->GetExitOnFrameDelete())
139 {
140 wxTheApp->ExitMainLoop() ;
141 }
142 }
143
144 wxModelessWindows.DeleteObject(this);
145 }
146
147
148 bool wxFrame::Enable(bool enable)
149 {
150 if ( !wxWindow::Enable(enable) )
151 return FALSE;
152
153 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
154 {
155 for ( int i = 0 ; i < m_frameMenuBar->GetMenuCount() ; ++ i )
156 {
157 m_frameMenuBar->EnableTop( i , enable ) ;
158 }
159 }
160
161 return TRUE;
162 }
163 // Equivalent to maximize/restore in Windows
164 void wxFrame::Maximize(bool maximize)
165 {
166 // TODO
167 }
168
169 bool wxFrame::IsIconized() const
170 {
171 // TODO
172 return FALSE;
173 }
174
175 void wxFrame::Iconize(bool iconize)
176 {
177 // TODO
178 }
179
180 // Is the frame maximized?
181 bool wxFrame::IsMaximized(void) const
182 {
183 // TODO
184 return FALSE;
185 }
186
187 void wxFrame::Restore()
188 {
189 // TODO
190 }
191
192 void wxFrame::SetIcon(const wxIcon& icon)
193 {
194 wxFrameBase::SetIcon(icon);
195 }
196
197 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
198 const wxString& name)
199 {
200 wxStatusBar *statusBar = NULL;
201
202 statusBar = new wxStatusBar(this, id,
203 style, name);
204 statusBar->SetSize( 100 , 15 ) ;
205 statusBar->SetFieldsCount(number);
206 return statusBar;
207 }
208
209 void wxFrame::PositionStatusBar()
210 {
211 if (m_frameStatusBar )
212 {
213 int w, h;
214 GetClientSize(&w, &h);
215 int sw, sh;
216 m_frameStatusBar->GetSize(&sw, &sh);
217
218 // Since we wish the status bar to be directly under the client area,
219 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
220 m_frameStatusBar->SetSize(0, h, w, sh);
221 }
222 }
223
224 void wxFrame::SetMenuBar(wxMenuBar *menuBar)
225 {
226 if (!menuBar)
227 {
228 return;
229 }
230
231 m_frameMenuBar = NULL;
232 m_frameMenuBar = menuBar;
233 m_frameMenuBar->MacInstallMenuBar() ;
234 m_frameMenuBar->Attach(this);
235 }
236
237
238 // Responds to colour changes, and passes event on to children.
239 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
240 {
241 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
242 Refresh();
243
244 if ( m_frameStatusBar )
245 {
246 wxSysColourChangedEvent event2;
247 event2.SetEventObject( m_frameStatusBar );
248 m_frameStatusBar->ProcessEvent(event2);
249 }
250
251 // Propagate the event to the non-top-level children
252 wxWindow::OnSysColourChanged(event);
253 }
254
255
256 // Default activation behaviour - set the focus for the first child
257 // subwindow found.
258 void wxFrame::OnActivate(wxActivateEvent& event)
259 {
260 if ( !event.GetActive() )
261 {
262 event.Skip();
263 return;
264 }
265
266 for ( wxWindowList::Node *node = GetChildren().GetFirst();
267 node;
268 node = node->GetNext() )
269 {
270 // FIXME all this is totally bogus - we need to do the same as wxPanel,
271 // but how to do it without duplicating the code?
272
273 // restore focus
274 wxWindow *child = node->GetData();
275
276 if ( !child->IsTopLevel()
277 #if wxUSE_TOOLBAR
278 && !wxDynamicCast(child, wxToolBar)
279 #endif // wxUSE_TOOLBAR
280 #if wxUSE_STATUSBAR
281 && !wxDynamicCast(child, wxStatusBar)
282 #endif // wxUSE_STATUSBAR
283 )
284 {
285 child->SetFocus();
286 return;
287 }
288 }
289 }
290
291 void wxFrame::DoGetClientSize(int *x, int *y) const
292 {
293 wxWindow::DoGetClientSize( x , y ) ;
294
295 #if wxUSE_STATUSBAR
296 if ( GetStatusBar() )
297 {
298 int statusX, statusY;
299 GetStatusBar()->GetClientSize(&statusX, &statusY);
300 *y -= statusY;
301 }
302 #endif // wxUSE_STATUSBAR
303
304 wxPoint pt(GetClientAreaOrigin());
305 *y -= pt.y;
306 *x -= pt.x;
307 }
308
309 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
310 {
311 int currentclientwidth , currentclientheight ;
312 int currentwidth , currentheight ;
313
314 GetClientSize( &currentclientwidth , &currentclientheight ) ;
315 GetSize( &currentwidth , &currentheight ) ;
316
317 // find the current client size
318
319 // Find the difference between the entire window (title bar and all)
320 // and the client area; add this to the new client size to move the
321 // window
322
323 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
324 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
325 }
326
327
328 #if wxUSE_TOOLBAR
329 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
330 {
331 if ( wxFrameBase::CreateToolBar(style, id, name) )
332 {
333 PositionToolBar();
334 }
335
336 return m_frameToolBar;
337 }
338
339 void wxFrame::PositionToolBar()
340 {
341 int cw, ch;
342
343 cw = m_width ;
344 ch = m_height ;
345
346 if ( GetStatusBar() )
347 {
348 int statusX, statusY;
349 GetStatusBar()->GetClientSize(&statusX, &statusY);
350 ch -= statusY;
351 }
352
353 if (GetToolBar())
354 {
355 int tw, th;
356 GetToolBar()->GetSize(& tw, & th);
357
358 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
359 {
360 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
361 // means, pretend we don't have toolbar/status bar, so we
362 // have the original client size.
363 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
364 }
365 else
366 {
367 // Use the 'real' position
368 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
369 }
370 }
371 }
372 #endif