]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: frame.cpp | |
0d53fc34 | 3 | // Purpose: wxFrame |
e9576ca5 SC |
4 | // Author: AUTHOR |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "frame.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/frame.h" | |
03e11df5 | 17 | #include "wx/statusbr.h" |
e9576ca5 SC |
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 | ||
d497dca4 | 26 | #include "wx/mac/uma.h" |
519cb848 | 27 | |
fe08e597 | 28 | extern wxWindowList wxModelessWindows; |
e9576ca5 SC |
29 | extern wxList wxPendingDelete; |
30 | ||
2f1ae414 | 31 | #if !USE_SHARED_LIBRARY |
0d53fc34 VS |
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) | |
e9576ca5 SC |
38 | END_EVENT_TABLE() |
39 | ||
ac0fa9ef | 40 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow) |
2f1ae414 | 41 | #endif |
e9576ca5 SC |
42 | |
43 | #if wxUSE_NATIVE_STATUSBAR | |
0d53fc34 | 44 | bool wxFrame::m_useNativeStatusBar = TRUE; |
e9576ca5 | 45 | #else |
0d53fc34 | 46 | bool wxFrame::m_useNativeStatusBar = FALSE; |
e9576ca5 SC |
47 | #endif |
48 | ||
2f1ae414 SC |
49 | #define WX_MAC_STATUSBAR_HEIGHT 15 |
50 | // ---------------------------------------------------------------------------- | |
51 | // creation/destruction | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
0d53fc34 | 54 | void wxFrame::Init() |
e9576ca5 | 55 | { |
0a67a93b SC |
56 | m_frameMenuBar = NULL; |
57 | ||
58 | #if wxUSE_TOOLBAR | |
59 | m_frameToolBar = NULL ; | |
60 | #endif | |
61 | m_frameStatusBar = NULL; | |
62 | m_winLastFocused = NULL ; | |
63 | ||
2f1ae414 SC |
64 | m_iconized = FALSE; |
65 | ||
66 | #if wxUSE_TOOLTIPS | |
67 | m_hwndToolTip = 0; | |
519cb848 | 68 | #endif |
2f1ae414 | 69 | } |
e7549107 | 70 | |
0d53fc34 | 71 | wxPoint wxFrame::GetClientAreaOrigin() const |
2f1ae414 SC |
72 | { |
73 | // on mac we are at position -1,-1 with the control | |
74 | wxPoint pt(0, 0); | |
75 | ||
76 | #if wxUSE_TOOLBAR | |
77 | if ( GetToolBar() ) | |
78 | { | |
79 | int w, h; | |
80 | GetToolBar()->GetSize(& w, & h); | |
81 | ||
82 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) | |
83 | { | |
84 | pt.x += w - 1; | |
85 | } | |
86 | else | |
87 | { | |
88 | pt.y += h - 1 ; | |
89 | } | |
90 | } | |
91 | #endif // wxUSE_TOOLBAR | |
92 | ||
93 | return pt; | |
e9576ca5 SC |
94 | } |
95 | ||
0d53fc34 | 96 | bool wxFrame::Create(wxWindow *parent, |
e9576ca5 SC |
97 | wxWindowID id, |
98 | const wxString& title, | |
99 | const wxPoint& pos, | |
100 | const wxSize& size, | |
101 | long style, | |
102 | const wxString& name) | |
103 | { | |
a756f210 | 104 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
e9576ca5 | 105 | |
a15eb0a5 SC |
106 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
107 | return FALSE; | |
519cb848 | 108 | |
2f1ae414 SC |
109 | MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ; |
110 | ||
4159f685 | 111 | m_macWindowBackgroundTheme = kThemeBrushDocumentWindowBackground ; |
e4086560 | 112 | SetThemeWindowBackground( (WindowRef) m_macWindow , m_macWindowBackgroundTheme , false ) ; |
519cb848 | 113 | |
2f1ae414 | 114 | wxModelessWindows.Append(this); |
519cb848 | 115 | |
519cb848 | 116 | return TRUE; |
e9576ca5 SC |
117 | } |
118 | ||
0d53fc34 | 119 | wxFrame::~wxFrame() |
e9576ca5 | 120 | { |
2f1ae414 | 121 | m_isBeingDeleted = TRUE; |
e9576ca5 | 122 | |
2f1ae414 | 123 | DeleteAllBars(); |
e9576ca5 | 124 | |
e9576ca5 SC |
125 | } |
126 | ||
e9576ca5 | 127 | |
0d53fc34 | 128 | bool wxFrame::Enable(bool enable) |
e9576ca5 | 129 | { |
2f1ae414 SC |
130 | if ( !wxWindow::Enable(enable) ) |
131 | return FALSE; | |
e9576ca5 | 132 | |
2f1ae414 SC |
133 | if ( m_frameMenuBar && m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar() ) |
134 | { | |
3340066a SC |
135 | int iMaxMenu = m_frameMenuBar->GetMenuCount(); |
136 | for ( int i = 0 ; i < iMaxMenu ; ++ i ) | |
2f1ae414 SC |
137 | { |
138 | m_frameMenuBar->EnableTop( i , enable ) ; | |
139 | } | |
140 | } | |
141 | ||
142 | return TRUE; | |
143 | } | |
e9576ca5 | 144 | |
0d53fc34 | 145 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id, |
e9576ca5 SC |
146 | const wxString& name) |
147 | { | |
148 | wxStatusBar *statusBar = NULL; | |
149 | ||
5b781a67 SC |
150 | statusBar = new wxStatusBar(this, id, |
151 | style, name); | |
152 | statusBar->SetSize( 100 , 15 ) ; | |
e9576ca5 SC |
153 | statusBar->SetFieldsCount(number); |
154 | return statusBar; | |
155 | } | |
156 | ||
0d53fc34 | 157 | void wxFrame::PositionStatusBar() |
e9576ca5 | 158 | { |
519cb848 SC |
159 | if (m_frameStatusBar ) |
160 | { | |
e9576ca5 SC |
161 | int w, h; |
162 | GetClientSize(&w, &h); | |
163 | int sw, sh; | |
164 | m_frameStatusBar->GetSize(&sw, &sh); | |
165 | ||
166 | // Since we wish the status bar to be directly under the client area, | |
167 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
5b781a67 | 168 | m_frameStatusBar->SetSize(0, h, w, sh); |
519cb848 | 169 | } |
e9576ca5 SC |
170 | } |
171 | ||
e9576ca5 | 172 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 173 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
e9576ca5 | 174 | { |
a756f210 | 175 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE)); |
e9576ca5 SC |
176 | Refresh(); |
177 | ||
178 | if ( m_frameStatusBar ) | |
179 | { | |
180 | wxSysColourChangedEvent event2; | |
181 | event2.SetEventObject( m_frameStatusBar ); | |
182 | m_frameStatusBar->ProcessEvent(event2); | |
183 | } | |
184 | ||
185 | // Propagate the event to the non-top-level children | |
186 | wxWindow::OnSysColourChanged(event); | |
187 | } | |
188 | ||
e9576ca5 SC |
189 | |
190 | // Default activation behaviour - set the focus for the first child | |
191 | // subwindow found. | |
0d53fc34 | 192 | void wxFrame::OnActivate(wxActivateEvent& event) |
e9576ca5 | 193 | { |
2f1ae414 | 194 | if ( !event.GetActive() ) |
e9576ca5 | 195 | { |
a15eb0a5 | 196 | // remember the last focused child if it is our child |
7810c95b | 197 | m_winLastFocused = FindFocus(); |
a15eb0a5 SC |
198 | |
199 | // so we NULL it out if it's a child from some other frame | |
200 | wxWindow *win = m_winLastFocused; | |
201 | while ( win ) | |
7810c95b | 202 | { |
a15eb0a5 SC |
203 | if ( win->IsTopLevel() ) |
204 | { | |
205 | if ( win != this ) | |
206 | { | |
207 | m_winLastFocused = NULL; | |
208 | } | |
209 | ||
7810c95b | 210 | break; |
a15eb0a5 | 211 | } |
7810c95b | 212 | |
a15eb0a5 | 213 | win = win->GetParent(); |
7810c95b SC |
214 | } |
215 | ||
2f1ae414 | 216 | event.Skip(); |
e9576ca5 | 217 | } |
7810c95b SC |
218 | else |
219 | { | |
a15eb0a5 SC |
220 | // restore focus to the child which was last focused |
221 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() | |
222 | : NULL; | |
223 | if ( !parent ) | |
e9576ca5 | 224 | { |
a15eb0a5 | 225 | parent = this; |
e9576ca5 | 226 | } |
a15eb0a5 SC |
227 | |
228 | wxSetFocusToChild(parent, &m_winLastFocused); | |
7810c95b SC |
229 | |
230 | if ( m_frameMenuBar != NULL ) | |
231 | { | |
232 | m_frameMenuBar->MacInstallMenuBar() ; | |
233 | } | |
234 | } | |
e9576ca5 SC |
235 | } |
236 | ||
0d53fc34 | 237 | void wxFrame::DoGetClientSize(int *x, int *y) const |
e9576ca5 | 238 | { |
7c74e7fe | 239 | wxWindow::DoGetClientSize( x , y ) ; |
519cb848 | 240 | |
2f1ae414 | 241 | #if wxUSE_STATUSBAR |
9453cf2b | 242 | if ( GetStatusBar() && y ) |
519cb848 SC |
243 | { |
244 | int statusX, statusY; | |
245 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
5b781a67 | 246 | *y -= statusY; |
519cb848 | 247 | } |
2f1ae414 | 248 | #endif // wxUSE_STATUSBAR |
519cb848 SC |
249 | |
250 | wxPoint pt(GetClientAreaOrigin()); | |
9453cf2b SC |
251 | if ( y ) |
252 | *y -= pt.y; | |
253 | if ( x ) | |
254 | *x -= pt.x; | |
e9576ca5 SC |
255 | } |
256 | ||
0d53fc34 | 257 | void wxFrame::DoSetClientSize(int clientwidth, int clientheight) |
e9576ca5 | 258 | { |
519cb848 SC |
259 | int currentclientwidth , currentclientheight ; |
260 | int currentwidth , currentheight ; | |
261 | ||
262 | GetClientSize( ¤tclientwidth , ¤tclientheight ) ; | |
263 | GetSize( ¤twidth , ¤theight ) ; | |
264 | ||
265 | // find the current client size | |
266 | ||
267 | // Find the difference between the entire window (title bar and all) | |
268 | // and the client area; add this to the new client size to move the | |
269 | // window | |
270 | ||
271 | DoSetSize( -1 , -1 , currentwidth + clientwidth - currentclientwidth , | |
272 | currentheight + clientheight - currentclientheight , wxSIZE_USE_EXISTING ) ; | |
e9576ca5 SC |
273 | } |
274 | ||
519cb848 SC |
275 | |
276 | #if wxUSE_TOOLBAR | |
0d53fc34 | 277 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
e9576ca5 | 278 | { |
2f1ae414 | 279 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
e9576ca5 | 280 | { |
e9576ca5 | 281 | PositionToolBar(); |
e9576ca5 | 282 | } |
e9576ca5 | 283 | |
2f1ae414 | 284 | return m_frameToolBar; |
e9576ca5 SC |
285 | } |
286 | ||
0d53fc34 | 287 | void wxFrame::PositionToolBar() |
e9576ca5 SC |
288 | { |
289 | int cw, ch; | |
290 | ||
2f1ae414 SC |
291 | cw = m_width ; |
292 | ch = m_height ; | |
e9576ca5 SC |
293 | |
294 | if ( GetStatusBar() ) | |
295 | { | |
296 | int statusX, statusY; | |
297 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
298 | ch -= statusY; | |
299 | } | |
300 | ||
301 | if (GetToolBar()) | |
302 | { | |
303 | int tw, th; | |
304 | GetToolBar()->GetSize(& tw, & th); | |
305 | ||
306 | if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL) | |
307 | { | |
308 | // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS | |
309 | // means, pretend we don't have toolbar/status bar, so we | |
310 | // have the original client size. | |
2f1ae414 | 311 | GetToolBar()->SetSize(-1, -1, tw, ch + 2 , wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); |
e9576ca5 SC |
312 | } |
313 | else | |
314 | { | |
315 | // Use the 'real' position | |
2f1ae414 | 316 | GetToolBar()->SetSize(-1, -1, cw + 2, th, wxSIZE_NO_ADJUSTMENTS | wxSIZE_ALLOW_MINUS_ONE ); |
e9576ca5 SC |
317 | } |
318 | } | |
319 | } | |
519cb848 | 320 | #endif |