]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/frame.cpp
Testing CVSROOT/loginfo changes
[wxWidgets.git] / src / mac / classic / 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 #include "wx/frame.h"
13 #include "wx/statusbr.h"
14 #include "wx/toolbar.h"
15 #include "wx/menuitem.h"
16 #include "wx/menu.h"
17 #include "wx/dcclient.h"
18 #include "wx/dialog.h"
19 #include "wx/settings.h"
20 #include "wx/app.h"
21
22 #include "wx/mac/uma.h"
23
24 extern wxWindowList wxModelessWindows;
25 extern wxList wxPendingDelete;
26
27 BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
28 EVT_ACTIVATE(wxFrame::OnActivate)
29 // EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
30 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
31 // EVT_IDLE(wxFrame::OnIdle)
32 // EVT_CLOSE(wxFrame::OnCloseWindow)
33 END_EVENT_TABLE()
34
35 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
36
37 #define WX_MAC_STATUSBAR_HEIGHT 15
38 // ----------------------------------------------------------------------------
39 // creation/destruction
40 // ----------------------------------------------------------------------------
41
42 void wxFrame::Init()
43 {
44 m_frameMenuBar = NULL;
45
46 #if wxUSE_TOOLBAR
47 m_frameToolBar = NULL ;
48 #endif
49 m_frameStatusBar = NULL;
50 m_winLastFocused = NULL ;
51
52 m_iconized = FALSE;
53
54 #if wxUSE_TOOLTIPS
55 m_hwndToolTip = 0;
56 #endif
57 }
58
59 wxPoint wxFrame::GetClientAreaOrigin() const
60 {
61 // on mac we are at position -1,-1 with the control
62 wxPoint pt(0, 0);
63
64 #if wxUSE_TOOLBAR
65 if ( GetToolBar() )
66 {
67 int w, h;
68 GetToolBar()->GetSize(& w, & h);
69
70 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
71 {
72 pt.x += w - 1;
73 }
74 else
75 {
76 pt.y += h - 1 ;
77 }
78 }
79 #endif // wxUSE_TOOLBAR
80
81 return pt;
82 }
83
84 bool wxFrame::Create(wxWindow *parent,
85 wxWindowID id,
86 const wxString& title,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
91 {
92 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
93
94 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
95 return FALSE;
96
97 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
98
99 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
100 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
101
102 wxModelessWindows.Append(this);
103
104 return TRUE;
105 }
106
107 wxFrame::~wxFrame()
108 {
109 m_isBeingDeleted = TRUE;
110 DeleteAllBars();
111 }
112
113
114 bool wxFrame::Enable(bool enable)
115 {
116 if ( !wxWindow::Enable(enable) )
117 return FALSE;
118
119 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
120 {
121 int iMaxMenu = m_frameMenuBar->GetMenuCount();
122 for ( int i = 0 ; i < iMaxMenu ; ++ i )
123 {
124 m_frameMenuBar->EnableTop( i , enable ) ;
125 }
126 }
127
128 return TRUE;
129 }
130
131 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
132 const wxString& name)
133 {
134 wxStatusBar *statusBar = NULL;
135
136 statusBar = new wxStatusBar(this, id,
137 style, name);
138 statusBar->SetSize( 100 , 15 ) ;
139 statusBar->SetFieldsCount(number);
140 return statusBar;
141 }
142
143 void wxFrame::PositionStatusBar()
144 {
145 if (m_frameStatusBar )
146 {
147 int w, h;
148 GetClientSize(&w, &h);
149 int sw, sh;
150 m_frameStatusBar->GetSize(&sw, &sh);
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, sh);
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 wxWindow::DoGetClientSize( x , y ) ;
252
253 #if wxUSE_STATUSBAR
254 if ( GetStatusBar() && y )
255 {
256 int statusX, statusY;
257 GetStatusBar()->GetClientSize(&statusX, &statusY);
258 *y -= statusY;
259 }
260 #endif // wxUSE_STATUSBAR
261
262 wxPoint pt(GetClientAreaOrigin());
263 if ( y )
264 *y -= pt.y;
265 if ( x )
266 *x -= pt.x;
267 }
268
269 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
270 {
271 int currentclientwidth , currentclientheight ;
272 int currentwidth , currentheight ;
273
274 GetClientSize( &currentclientwidth , &currentclientheight ) ;
275 GetSize( &currentwidth , &currentheight ) ;
276
277 // find the current client size
278
279 // Find the difference between the entire window (title bar and all)
280 // and the client area; add this to the new client size to move the
281 // window
282
283 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
284 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
285 }
286
287
288 #if wxUSE_TOOLBAR
289 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
290 {
291 if ( wxFrameBase::CreateToolBar(style, id, name) )
292 {
293 PositionToolBar();
294 }
295
296 return m_frameToolBar;
297 }
298
299 void wxFrame::PositionToolBar()
300 {
301 int cw, ch;
302
303 cw = m_width ;
304 ch = m_height ;
305
306 if ( GetStatusBar() )
307 {
308 int statusX, statusY;
309 GetStatusBar()->GetClientSize(&statusX, &statusY);
310 ch -= statusY;
311 }
312
313 if (GetToolBar())
314 {
315 int tw, th;
316 GetToolBar()->GetSize(& tw, & th);
317
318 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
319 {
320 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
321 // means, pretend we don't have toolbar/status bar, so we
322 // have the original client size.
323 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
324 }
325 else
326 {
327 // Use the 'real' position
328 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
329 }
330 }
331 }
332 #endif