]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/frame.cpp
File/dir dialog styles and other changes (patch 1488371):
[wxWidgets.git] / src / mac / classic / frame.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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/wxprec.h"
13
14 #include "wx/frame.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/app.h"
18 #include "wx/dcclient.h"
19 #include "wx/menu.h"
20 #include "wx/dialog.h"
21 #include "wx/settings.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/statusbr.h"
25 #include "wx/toolbar.h"
26 #include "wx/menuitem.h"
27
28 #include "wx/mac/uma.h"
29
30 extern wxWindowList wxModelessWindows;
31
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
42 #define WX_MAC_STATUSBAR_HEIGHT 15
43 // ----------------------------------------------------------------------------
44 // creation/destruction
45 // ----------------------------------------------------------------------------
46
47 void wxFrame::Init()
48 {
49 m_frameMenuBar = NULL;
50
51 #if wxUSE_TOOLBAR
52 m_frameToolBar = NULL ;
53 #endif
54 m_frameStatusBar = NULL;
55 m_winLastFocused = NULL ;
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 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
98
99 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
100 return false;
101
102 MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;
103
104 m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ;
105 SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ;
106
107 wxModelessWindows.Append(this);
108
109 return true;
110 }
111
112 wxFrame::~wxFrame()
113 {
114 m_isBeingDeleted = true;
115 DeleteAllBars();
116 }
117
118
119 bool wxFrame::Enable(bool enable)
120 {
121 if ( !wxWindow::Enable(enable) )
122 return false;
123
124 if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() )
125 {
126 int iMaxMenu = m_frameMenuBar->GetMenuCount();
127 for ( int i = 0 ; i < iMaxMenu ; ++ i )
128 {
129 m_frameMenuBar->EnableTop( i , enable ) ;
130 }
131 }
132
133 return true;
134 }
135
136 wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
137 const wxString& name)
138 {
139 wxStatusBar *statusBar = NULL;
140
141 statusBar = new wxStatusBar(this, id,
142 style, name);
143 statusBar->SetSize( 100 , 15 ) ;
144 statusBar->SetFieldsCount(number);
145 return statusBar;
146 }
147
148 void wxFrame::PositionStatusBar()
149 {
150 if (m_frameStatusBar )
151 {
152 int w, h;
153 GetClientSize(&w, &h);
154 int sw, sh;
155 m_frameStatusBar->GetSize(&sw, &sh);
156
157 // Since we wish the status bar to be directly under the client area,
158 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
159 m_frameStatusBar->SetSize(0, h, w, sh);
160 }
161 }
162
163 // Responds to colour changes, and passes event on to children.
164 void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
165 {
166 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
167 Refresh();
168
169 if ( m_frameStatusBar )
170 {
171 wxSysColourChangedEvent event2;
172 event2.SetEventObject( m_frameStatusBar );
173 m_frameStatusBar->ProcessEvent(event2);
174 }
175
176 // Propagate the event to the non-top-level children
177 wxWindow::OnSysColourChanged(event);
178 }
179
180
181 // Default activation behaviour - set the focus for the first child
182 // subwindow found.
183 void wxFrame::OnActivate(wxActivateEvent& event)
184 {
185 if ( !event.GetActive() )
186 {
187 // remember the last focused child if it is our child
188 m_winLastFocused = FindFocus();
189
190 // so we NULL it out if it's a child from some other frame
191 wxWindow *win = m_winLastFocused;
192 while ( win )
193 {
194 if ( win->IsTopLevel() )
195 {
196 if ( win != this )
197 {
198 m_winLastFocused = NULL;
199 }
200
201 break;
202 }
203
204 win = win->GetParent();
205 }
206
207 event.Skip();
208 }
209 else
210 {
211 // restore focus to the child which was last focused
212 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
213 : NULL;
214 if ( !parent )
215 {
216 parent = this;
217 }
218
219 wxSetFocusToChild(parent, &m_winLastFocused);
220
221 if ( m_frameMenuBar != NULL )
222 {
223 m_frameMenuBar->MacInstallMenuBar() ;
224 }
225 else if (wxTheApp->GetTopWindow() && wxTheApp->GetTopWindow()->IsKindOf(CLASSINFO(wxFrame)))
226 {
227 // Trying toplevel frame menbar
228 if( ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar() )
229 ((wxFrame*)wxTheApp->GetTopWindow())->GetMenuBar()->MacInstallMenuBar();
230 }
231 }
232 }
233
234 void wxFrame::DetachMenuBar()
235 {
236 if ( m_frameMenuBar )
237 {
238 m_frameMenuBar->UnsetInvokingWindow();
239 }
240
241 wxFrameBase::DetachMenuBar();
242 }
243
244 void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
245 {
246 wxFrameBase::AttachMenuBar(menuBar);
247
248 if (m_frameMenuBar)
249 {
250 m_frameMenuBar->SetInvokingWindow( this );
251 }
252 }
253
254 void wxFrame::DoGetClientSize(int *x, int *y) const
255 {
256 wxWindow::DoGetClientSize( x , y ) ;
257
258 #if wxUSE_STATUSBAR
259 if ( GetStatusBar() && y )
260 {
261 int statusX, statusY;
262 GetStatusBar()->GetClientSize(&statusX, &statusY);
263 *y -= statusY;
264 }
265 #endif // wxUSE_STATUSBAR
266
267 wxPoint pt(GetClientAreaOrigin());
268 if ( y )
269 *y -= pt.y;
270 if ( x )
271 *x -= pt.x;
272 }
273
274 void wxFrame::DoSetClientSize(int clientwidth, int clientheight)
275 {
276 int currentclientwidth , currentclientheight ;
277 int currentwidth , currentheight ;
278
279 GetClientSize( &currentclientwidth , &currentclientheight ) ;
280 GetSize( &currentwidth , &currentheight ) ;
281
282 // find the current client size
283
284 // Find the difference between the entire window (title bar and all)
285 // and the client area; add this to the new client size to move the
286 // window
287
288 DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth ,
289 currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ;
290 }
291
292
293 #if wxUSE_TOOLBAR
294 wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
295 {
296 if ( wxFrameBase::CreateToolBar(style, id, name) )
297 {
298 PositionToolBar();
299 }
300
301 return m_frameToolBar;
302 }
303
304 void wxFrame::PositionToolBar()
305 {
306 int cw, ch;
307
308 cw = m_width ;
309 ch = m_height ;
310
311 if ( GetStatusBar() )
312 {
313 int statusX, statusY;
314 GetStatusBar()->GetClientSize(&statusX, &statusY);
315 ch -= statusY;
316 }
317
318 if (GetToolBar())
319 {
320 int tw, th;
321 GetToolBar()->GetSize(& tw, & th);
322
323 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
324 {
325 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
326 // means, pretend we don't have toolbar/status bar, so we
327 // have the original client size.
328 GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
329 }
330 else
331 {
332 // Use the 'real' position
333 GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE );
334 }
335 }
336 }
337 #endif