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