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