]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/frame.cpp
24 bit depth
[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 #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 wxWindowList wxModelessWindows;
29 extern wxList wxPendingDelete;
30
31 #if !USE_SHARED_LIBRARY
32 BEGIN_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)
38 END_EVENT_TABLE()
39
40 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
41 #endif
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
89 bool wxFrame::Enable(bool enable)
90 {
91 if ( !wxWindow::Enable(enable) )
92 return FALSE;
93
94 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
95 {
96 int iMaxMenu = m_frameMenuBar->GetMenuCount();
97 for ( int i = 0 ; i < iMaxMenu ; ++ i )
98 {
99 m_frameMenuBar->EnableTop( i , enable ) ;
100 }
101 }
102
103 return TRUE;
104 }
105
106 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
107 const wxString& name)
108 {
109 wxStatusBar *statusBar = NULL;
110
111 statusBar = new wxStatusBar(this, id,
112 style, name);
113 statusBar->SetSize( 100 , WX_MAC_STATUSBAR_HEIGHT ) ;
114 statusBar->SetFieldsCount(number);
115 return statusBar;
116 }
117
118 void wxFrame::PositionStatusBar()
119 {
120 if (m_frameStatusBar && m_frameStatusBar->IsShown() )
121 {
122 int w, h;
123 GetClientSize(&w, &h);
124
125 // Since we wish the status bar to be directly under the client area,
126 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
127 m_frameStatusBar->SetSize(0, h, w, WX_MAC_STATUSBAR_HEIGHT);
128 }
129 }
130
131 // Responds to colour changes, and passes event on to children.
132 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
133 {
134 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
135 Refresh();
136
137 if ( m_frameStatusBar )
138 {
139 wxSysColourChangedEvent event2;
140 event2.SetEventObject( m_frameStatusBar );
141 m_frameStatusBar->ProcessEvent(event2);
142 }
143
144 // Propagate the event to the non-top-level children
145 wxWindow::OnSysColourChanged(event);
146 }
147
148
149 // Default activation behaviour - set the focus for the first child
150 // subwindow found.
151 void wxFrame::OnActivate(wxActivateEvent& event)
152 {
153 if ( !event.GetActive() )
154 {
155 // remember the last focused child if it is our child
156 m_winLastFocused = FindFocus();
157
158 // so we NULL it out if it's a child from some other frame
159 wxWindow *win = m_winLastFocused;
160 while ( win )
161 {
162 if ( win->IsTopLevel() )
163 {
164 if ( win != this )
165 {
166 m_winLastFocused = NULL;
167 }
168
169 break;
170 }
171
172 win = win->GetParent();
173 }
174
175 event.Skip();
176 }
177 else
178 {
179 // restore focus to the child which was last focused
180 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
181 : NULL;
182 if ( !parent )
183 {
184 parent = this;
185 }
186
187 wxSetFocusToChild(parent, &m_winLastFocused);
188
189 if ( m_frameMenuBar != NULL )
190 {
191 m_frameMenuBar->MacInstallMenuBar() ;
192 }
193 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
194 {
195 // Trying toplevel frame menbar
196 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
197 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
198 }
199 }
200 }
201
202 void wxFrame::DetachMenuBar()
203 {
204 if ( m_frameMenuBar )
205 {
206 m_frameMenuBar->UnsetInvokingWindow();
207 }
208
209 wxFrameBase::DetachMenuBar();
210 }
211
212 void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
213 {
214 wxFrameBase::AttachMenuBar(menuBar);
215
216 if (m_frameMenuBar)
217 {
218 m_frameMenuBar->SetInvokingWindow( this );
219 }
220 }
221
222 void wxFrame::DoGetClientSize(int *x, int *y) const
223 {
224 wxTopLevelWindow::DoGetClientSize( x , y ) ;
225
226 #if wxUSE_STATUSBAR
227 if ( GetStatusBar() && GetStatusBar()->IsShown() && y )
228 {
229 if ( y) *y -= WX_MAC_STATUSBAR_HEIGHT;
230 }
231 #endif // wxUSE_STATUSBAR
232
233 #if wxUSE_TOOLBAR
234 wxToolBar *toolbar = GetToolBar();
235 if ( toolbar && toolbar->IsShown() )
236 {
237 int w, h;
238 toolbar->GetSize(&w, &h);
239
240 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
241 {
242 if ( x ) *x -= w;
243 }
244 else
245 {
246 if ( y ) *y -= h;
247 }
248 }
249 #endif // wxUSE_TOOLBAR
250 }
251
252 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
253 {
254 int currentclientwidth , currentclientheight ;
255 int currentwidth , currentheight ;
256
257 GetClientSize( &currentclientwidth , &currentclientheight ) ;
258 if ( clientwidth == -1 )
259 clientwidth = currentclientwidth ;
260 if ( clientheight == -1 )
261 clientheight = currentclientheight ;
262 GetSize( &currentwidth , &currentheight ) ;
263
264 // find the current client size
265
266 // Find the difference between the entire window (title bar and all)
267 // and the client area; add this to the new client size to move the
268 // window
269
270 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
271 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
272 }
273
274
275 #if wxUSE_TOOLBAR
276 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
277 {
278 if ( wxFrameBase::CreateToolBar(style, id, name) )
279 {
280 PositionToolBar();
281 }
282
283 return m_frameToolBar;
284 }
285
286 void wxFrame::PositionToolBar()
287 {
288 int cw, ch;
289
290 GetSize( &cw , &ch ) ;
291
292 if ( GetStatusBar() && GetStatusBar()->IsShown())
293 {
294 int statusX, statusY;
295 GetStatusBar()->GetClientSize(&statusX, &statusY);
296 ch -= statusY;
297 }
298
299 if (GetToolBar())
300 {
301 int tx, ty, tw, th;
302 tx = ty = 0 ;
303
304 GetToolBar()->GetSize(& tw, & th);
305 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
306 {
307 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
308 // means, pretend we don't have toolbar/status bar, so we
309 // have the original client size.
310 GetToolBar()->SetSize(tx , ty , tw, ch , wxSIZE_NO_ADJUSTMENTS );
311 }
312 else
313 {
314 // Use the 'real' position
315 GetToolBar()->SetSize(tx , ty , cw , th, wxSIZE_NO_ADJUSTMENTS );
316 }
317 }
318 }
319 #endif