]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
7c0ea335 | 2 | // Name: msw/frame.cpp |
0d53fc34 | 3 | // Purpose: wxFrame |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
7c0ea335 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
7c0ea335 | 21 | #pragma implementation "frame.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
9f3362c4 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
9f3362c4 | 32 | #include "wx/frame.h" |
9f3362c4 | 33 | #include "wx/app.h" |
1e6feb95 | 34 | #include "wx/menu.h" |
9f3362c4 VZ |
35 | #include "wx/utils.h" |
36 | #include "wx/dialog.h" | |
37 | #include "wx/settings.h" | |
38 | #include "wx/dcclient.h" | |
d3cc7c65 | 39 | #include "wx/mdi.h" |
f6bcfd97 | 40 | #include "wx/panel.h" |
9f3362c4 | 41 | #endif // WX_PRECOMP |
2bda0e17 KB |
42 | |
43 | #include "wx/msw/private.h" | |
7c0ea335 VZ |
44 | |
45 | #if wxUSE_STATUSBAR | |
46 | #include "wx/statusbr.h" | |
ed791986 | 47 | #include "wx/generic/statusbr.h" |
7c0ea335 VZ |
48 | #endif // wxUSE_STATUSBAR |
49 | ||
50 | #if wxUSE_TOOLBAR | |
51 | #include "wx/toolbar.h" | |
52 | #endif // wxUSE_TOOLBAR | |
53 | ||
2bda0e17 | 54 | #include "wx/menuitem.h" |
6776a0b2 | 55 | #include "wx/log.h" |
2bda0e17 | 56 | |
1e6feb95 VZ |
57 | #ifdef __WXUNIVERSAL__ |
58 | #include "wx/univ/theme.h" | |
59 | #include "wx/univ/colschem.h" | |
60 | #endif // __WXUNIVERSAL__ | |
61 | ||
7c0ea335 VZ |
62 | // ---------------------------------------------------------------------------- |
63 | // globals | |
64 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 65 | |
2ffa221c | 66 | extern const wxChar *wxFrameClassName; |
1e6feb95 VZ |
67 | |
68 | #if wxUSE_MENUS_NATIVE | |
e1a6fc11 | 69 | extern wxMenu *wxCurrentPopupMenu; |
1e6feb95 | 70 | #endif // wxUSE_MENUS_NATIVE |
2bda0e17 | 71 | |
7c0ea335 VZ |
72 | // ---------------------------------------------------------------------------- |
73 | // event tables | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
0d53fc34 VS |
76 | BEGIN_EVENT_TABLE(wxFrame, wxFrameBase) |
77 | EVT_ACTIVATE(wxFrame::OnActivate) | |
78 | EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged) | |
2bda0e17 KB |
79 | END_EVENT_TABLE() |
80 | ||
0d53fc34 | 81 | IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow) |
2bda0e17 | 82 | |
7c0ea335 VZ |
83 | // ============================================================================ |
84 | // implementation | |
85 | // ============================================================================ | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // static class members | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
1e6feb95 VZ |
91 | #if wxUSE_STATUSBAR |
92 | #if wxUSE_NATIVE_STATUSBAR | |
0d53fc34 | 93 | bool wxFrame::m_useNativeStatusBar = TRUE; |
1e6feb95 | 94 | #else |
0d53fc34 | 95 | bool wxFrame::m_useNativeStatusBar = FALSE; |
1e6feb95 VZ |
96 | #endif |
97 | #endif // wxUSE_NATIVE_STATUSBAR | |
2bda0e17 | 98 | |
7c0ea335 VZ |
99 | // ---------------------------------------------------------------------------- |
100 | // creation/destruction | |
101 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 102 | |
0d53fc34 | 103 | void wxFrame::Init() |
2bda0e17 | 104 | { |
9f3362c4 VZ |
105 | #if wxUSE_TOOLTIPS |
106 | m_hwndToolTip = 0; | |
107 | #endif | |
a2327a9f JS |
108 | |
109 | // Data to save/restore when calling ShowFullScreen | |
a2327a9f JS |
110 | m_fsStatusBarFields = 0; |
111 | m_fsStatusBarHeight = 0; | |
112 | m_fsToolBarHeight = 0; | |
f6bcfd97 | 113 | // m_fsMenu = 0; |
f6bcfd97 | 114 | |
9327c3aa VZ |
115 | m_wasMinimized = FALSE; |
116 | ||
f6bcfd97 | 117 | m_winLastFocused = (wxWindow *)NULL; |
7c0ea335 | 118 | } |
9f3362c4 | 119 | |
0d53fc34 | 120 | bool wxFrame::Create(wxWindow *parent, |
7c0ea335 VZ |
121 | wxWindowID id, |
122 | const wxString& title, | |
123 | const wxPoint& pos, | |
124 | const wxSize& size, | |
125 | long style, | |
126 | const wxString& name) | |
127 | { | |
82c9f85c VZ |
128 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
129 | return FALSE; | |
d2aef312 | 130 | |
82c9f85c | 131 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); |
2bda0e17 | 132 | |
82c9f85c | 133 | wxModelessWindows.Append(this); |
f6bcfd97 | 134 | |
82c9f85c | 135 | return TRUE; |
2bda0e17 KB |
136 | } |
137 | ||
0d53fc34 | 138 | wxFrame::~wxFrame() |
2bda0e17 | 139 | { |
82c9f85c | 140 | m_isBeingDeleted = TRUE; |
2bda0e17 | 141 | |
82c9f85c | 142 | DeleteAllBars(); |
2bda0e17 KB |
143 | } |
144 | ||
81d66cf3 | 145 | // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc. |
0d53fc34 | 146 | void wxFrame::DoGetClientSize(int *x, int *y) const |
2bda0e17 KB |
147 | { |
148 | RECT rect; | |
42e69d6b | 149 | ::GetClientRect(GetHwnd(), &rect); |
2bda0e17 | 150 | |
7c0ea335 | 151 | #if wxUSE_STATUSBAR |
a2327a9f | 152 | if ( GetStatusBar() && GetStatusBar()->IsShown() ) |
2bda0e17 | 153 | { |
81d66cf3 JS |
154 | int statusX, statusY; |
155 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
156 | rect.bottom -= statusY; | |
2bda0e17 | 157 | } |
7c0ea335 | 158 | #endif // wxUSE_STATUSBAR |
81d66cf3 JS |
159 | |
160 | wxPoint pt(GetClientAreaOrigin()); | |
161 | rect.bottom -= pt.y; | |
162 | rect.right -= pt.x; | |
163 | ||
0655ad29 VZ |
164 | if ( x ) |
165 | *x = rect.right; | |
166 | if ( y ) | |
167 | *y = rect.bottom; | |
2bda0e17 KB |
168 | } |
169 | ||
0d53fc34 | 170 | void wxFrame::DoSetClientSize(int width, int height) |
2bda0e17 | 171 | { |
82c9f85c | 172 | // leave enough space for the status bar if we have (and show) it |
7c0ea335 | 173 | #if wxUSE_STATUSBAR |
8d8bd249 VZ |
174 | wxStatusBar *statbar = GetStatusBar(); |
175 | if ( statbar && statbar->IsShown() ) | |
176 | { | |
8d8bd249 VZ |
177 | height += statbar->GetSize().y; |
178 | } | |
7c0ea335 | 179 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 180 | |
82c9f85c | 181 | wxTopLevelWindow::DoSetClientSize(width, height); |
2bda0e17 KB |
182 | } |
183 | ||
7c0ea335 | 184 | // ---------------------------------------------------------------------------- |
0d53fc34 | 185 | // wxFrame: various geometry-related functions |
7c0ea335 VZ |
186 | // ---------------------------------------------------------------------------- |
187 | ||
0d53fc34 | 188 | void wxFrame::Raise() |
c48926e1 VZ |
189 | { |
190 | #ifdef __WIN16__ | |
191 | // no SetForegroundWindow() in Win16 | |
192 | wxFrameBase::Raise(); | |
193 | #else // Win32 | |
194 | ::SetForegroundWindow(GetHwnd()); | |
195 | #endif // Win16/32 | |
196 | } | |
197 | ||
67bd5bad | 198 | // generate an artificial resize event |
0d53fc34 | 199 | void wxFrame::SendSizeEvent() |
67bd5bad | 200 | { |
67bd5bad GT |
201 | if ( !m_iconized ) |
202 | { | |
82c9f85c VZ |
203 | RECT r = wxGetWindowRect(GetHwnd()); |
204 | ||
67bd5bad GT |
205 | (void)::PostMessage(GetHwnd(), WM_SIZE, |
206 | IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED, | |
207 | MAKELPARAM(r.right - r.left, r.bottom - r.top)); | |
208 | } | |
209 | } | |
210 | ||
d427503c | 211 | #if wxUSE_STATUSBAR |
0d53fc34 | 212 | wxStatusBar *wxFrame::OnCreateStatusBar(int number, |
7c0ea335 VZ |
213 | long style, |
214 | wxWindowID id, | |
215 | const wxString& name) | |
2bda0e17 KB |
216 | { |
217 | wxStatusBar *statusBar = NULL; | |
218 | ||
47d67540 | 219 | #if wxUSE_NATIVE_STATUSBAR |
1f0500b3 | 220 | if ( !UsesNativeStatusBar() ) |
2bda0e17 | 221 | { |
1f0500b3 | 222 | statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style); |
2bda0e17 KB |
223 | } |
224 | else | |
225 | #endif | |
226 | { | |
1f0500b3 VZ |
227 | statusBar = new wxStatusBar(this, id, style, name); |
228 | } | |
ed791986 | 229 | |
1f0500b3 | 230 | statusBar->SetFieldsCount(number); |
2bda0e17 | 231 | |
7c0ea335 | 232 | return statusBar; |
2bda0e17 KB |
233 | } |
234 | ||
0d53fc34 | 235 | void wxFrame::PositionStatusBar() |
2bda0e17 | 236 | { |
ed791986 VZ |
237 | if ( !m_frameStatusBar ) |
238 | return; | |
239 | ||
cbc66a27 VZ |
240 | int w, h; |
241 | GetClientSize(&w, &h); | |
242 | int sw, sh; | |
243 | m_frameStatusBar->GetSize(&sw, &sh); | |
244 | ||
245 | // Since we wish the status bar to be directly under the client area, | |
246 | // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS. | |
247 | m_frameStatusBar->SetSize(0, h, w, sh); | |
2bda0e17 | 248 | } |
d427503c | 249 | #endif // wxUSE_STATUSBAR |
2bda0e17 | 250 | |
6522713c | 251 | #if wxUSE_MENUS_NATIVE |
ea9a4296 | 252 | |
0d53fc34 | 253 | void wxFrame::AttachMenuBar(wxMenuBar *menubar) |
2bda0e17 | 254 | { |
f008af16 | 255 | wxFrameBase::AttachMenuBar(menubar); |
6beb85c0 | 256 | |
f6bcfd97 | 257 | if ( !menubar ) |
c2dcfdef | 258 | { |
f6bcfd97 BP |
259 | // actually remove the menu from the frame |
260 | m_hMenu = (WXHMENU)0; | |
261 | InternalSetMenuBar(); | |
065de612 | 262 | } |
f6bcfd97 | 263 | else // set new non NULL menu bar |
065de612 | 264 | { |
f6bcfd97 | 265 | // Can set a menubar several times. |
f6bcfd97 BP |
266 | if ( menubar->GetHMenu() ) |
267 | { | |
268 | m_hMenu = menubar->GetHMenu(); | |
269 | } | |
f008af16 | 270 | else // no HMENU yet |
f6bcfd97 | 271 | { |
f6bcfd97 | 272 | m_hMenu = menubar->Create(); |
065de612 | 273 | |
f6bcfd97 | 274 | if ( !m_hMenu ) |
f008af16 VZ |
275 | { |
276 | wxFAIL_MSG( _T("failed to create menu bar") ); | |
f6bcfd97 | 277 | return; |
f008af16 | 278 | } |
f6bcfd97 | 279 | } |
065de612 | 280 | |
f6bcfd97 | 281 | InternalSetMenuBar(); |
1e6feb95 | 282 | } |
2bda0e17 KB |
283 | } |
284 | ||
0d53fc34 | 285 | void wxFrame::InternalSetMenuBar() |
2bda0e17 | 286 | { |
04ef50df | 287 | #ifndef __WXMICROWIN__ |
42e69d6b | 288 | if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) ) |
2bda0e17 | 289 | { |
f6bcfd97 | 290 | wxLogLastError(wxT("SetMenu")); |
2bda0e17 | 291 | } |
04ef50df | 292 | #endif |
2bda0e17 KB |
293 | } |
294 | ||
1e6feb95 VZ |
295 | #endif // wxUSE_MENUS_NATIVE |
296 | ||
2bda0e17 | 297 | // Responds to colour changes, and passes event on to children. |
0d53fc34 | 298 | void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) |
2bda0e17 KB |
299 | { |
300 | SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE)); | |
301 | Refresh(); | |
302 | ||
1e6feb95 | 303 | #if wxUSE_STATUSBAR |
2bda0e17 KB |
304 | if ( m_frameStatusBar ) |
305 | { | |
306 | wxSysColourChangedEvent event2; | |
307 | event2.SetEventObject( m_frameStatusBar ); | |
02800301 | 308 | m_frameStatusBar->GetEventHandler()->ProcessEvent(event2); |
2bda0e17 | 309 | } |
1e6feb95 | 310 | #endif // wxUSE_STATUSBAR |
2bda0e17 KB |
311 | |
312 | // Propagate the event to the non-top-level children | |
313 | wxWindow::OnSysColourChanged(event); | |
314 | } | |
315 | ||
a2327a9f | 316 | // Pass TRUE to show full screen, FALSE to restore. |
0d53fc34 | 317 | bool wxFrame::ShowFullScreen(bool show, long style) |
a2327a9f | 318 | { |
c641b1d2 VS |
319 | if ( IsFullScreen() == show ) |
320 | return FALSE; | |
321 | ||
a2327a9f JS |
322 | if (show) |
323 | { | |
1e6feb95 | 324 | #if wxUSE_TOOLBAR |
f6bcfd97 | 325 | wxToolBar *theToolBar = GetToolBar(); |
a2327a9f | 326 | if (theToolBar) |
1e6feb95 | 327 | theToolBar->GetSize(NULL, &m_fsToolBarHeight); |
a2327a9f JS |
328 | |
329 | // zap the toolbar, menubar, and statusbar | |
330 | ||
331 | if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar) | |
332 | { | |
333 | theToolBar->SetSize(-1,0); | |
334 | theToolBar->Show(FALSE); | |
335 | } | |
1e6feb95 | 336 | #endif // wxUSE_TOOLBAR |
a2327a9f | 337 | |
04ef50df | 338 | #ifndef __WXMICROWIN__ |
a2327a9f JS |
339 | if (style & wxFULLSCREEN_NOMENUBAR) |
340 | SetMenu((HWND)GetHWND(), (HMENU) NULL); | |
04ef50df | 341 | #endif |
a2327a9f | 342 | |
1e6feb95 VZ |
343 | #if wxUSE_STATUSBAR |
344 | wxStatusBar *theStatusBar = GetStatusBar(); | |
345 | if (theStatusBar) | |
346 | theStatusBar->GetSize(NULL, &m_fsStatusBarHeight); | |
347 | ||
a2327a9f JS |
348 | // Save the number of fields in the statusbar |
349 | if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar) | |
350 | { | |
579b10c2 JS |
351 | //m_fsStatusBarFields = theStatusBar->GetFieldsCount(); |
352 | //SetStatusBar((wxStatusBar*) NULL); | |
353 | //delete theStatusBar; | |
354 | theStatusBar->Show(FALSE); | |
a2327a9f JS |
355 | } |
356 | else | |
357 | m_fsStatusBarFields = 0; | |
1e6feb95 | 358 | #endif // wxUSE_STATUSBAR |
a2327a9f JS |
359 | } |
360 | else | |
361 | { | |
1e6feb95 | 362 | #if wxUSE_TOOLBAR |
a2327a9f JS |
363 | wxToolBar *theToolBar = GetToolBar(); |
364 | ||
365 | // restore the toolbar, menubar, and statusbar | |
366 | if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR)) | |
367 | { | |
368 | theToolBar->SetSize(-1, m_fsToolBarHeight); | |
369 | theToolBar->Show(TRUE); | |
370 | } | |
1e6feb95 | 371 | #endif // wxUSE_TOOLBAR |
a2327a9f | 372 | |
1e6feb95 VZ |
373 | #if wxUSE_STATUSBAR |
374 | if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR ) | |
a2327a9f | 375 | { |
579b10c2 JS |
376 | //CreateStatusBar(m_fsStatusBarFields); |
377 | if (GetStatusBar()) | |
378 | { | |
379 | GetStatusBar()->Show(TRUE); | |
380 | PositionStatusBar(); | |
381 | } | |
a2327a9f | 382 | } |
1e6feb95 | 383 | #endif // wxUSE_STATUSBAR |
a2327a9f | 384 | |
04ef50df | 385 | #ifndef __WXMICROWIN__ |
a2327a9f JS |
386 | if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0)) |
387 | SetMenu((HWND)GetHWND(), (HMENU)m_hMenu); | |
04ef50df | 388 | #endif |
a2327a9f | 389 | } |
c641b1d2 VS |
390 | |
391 | return wxFrameBase::ShowFullScreen(show, style); | |
a2327a9f JS |
392 | } |
393 | ||
2bda0e17 KB |
394 | // Default activation behaviour - set the focus for the first child |
395 | // subwindow found. | |
0d53fc34 | 396 | void wxFrame::OnActivate(wxActivateEvent& event) |
2bda0e17 | 397 | { |
f6bcfd97 | 398 | if ( event.GetActive() ) |
00c4e897 | 399 | { |
f6bcfd97 | 400 | // restore focus to the child which was last focused |
0d53fc34 | 401 | wxLogTrace(_T("focus"), _T("wxFrame %08x activated."), m_hWnd); |
00c4e897 | 402 | |
e9456d8d VZ |
403 | wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent() |
404 | : NULL; | |
405 | if ( !parent ) | |
406 | { | |
407 | parent = this; | |
408 | } | |
409 | ||
410 | wxSetFocusToChild(parent, &m_winLastFocused); | |
00c4e897 | 411 | } |
e9456d8d | 412 | else // deactivating |
2bda0e17 | 413 | { |
e9456d8d | 414 | // remember the last focused child if it is our child |
f6bcfd97 | 415 | m_winLastFocused = FindFocus(); |
e9456d8d VZ |
416 | |
417 | // so we NULL it out if it's a child from some other frame | |
418 | wxWindow *win = m_winLastFocused; | |
419 | while ( win ) | |
319fefa9 | 420 | { |
e9456d8d VZ |
421 | if ( win->IsTopLevel() ) |
422 | { | |
423 | if ( win != this ) | |
424 | { | |
425 | m_winLastFocused = NULL; | |
426 | } | |
427 | ||
f6bcfd97 | 428 | break; |
e9456d8d | 429 | } |
f6bcfd97 | 430 | |
e9456d8d | 431 | win = win->GetParent(); |
319fefa9 | 432 | } |
f6bcfd97 BP |
433 | |
434 | wxLogTrace(_T("focus"), | |
0d53fc34 | 435 | _T("wxFrame %08x deactivated, last focused: %08x."), |
f6bcfd97 BP |
436 | m_hWnd, |
437 | m_winLastFocused ? GetHwndOf(m_winLastFocused) | |
438 | : NULL); | |
439 | ||
440 | event.Skip(); | |
2bda0e17 | 441 | } |
2bda0e17 KB |
442 | } |
443 | ||
7c0ea335 VZ |
444 | // ---------------------------------------------------------------------------- |
445 | // tool/status bar stuff | |
446 | // ---------------------------------------------------------------------------- | |
447 | ||
d427503c | 448 | #if wxUSE_TOOLBAR |
7c0ea335 | 449 | |
0d53fc34 | 450 | wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name) |
81d66cf3 | 451 | { |
7c0ea335 | 452 | if ( wxFrameBase::CreateToolBar(style, id, name) ) |
81d66cf3 | 453 | { |
81d66cf3 | 454 | PositionToolBar(); |
81d66cf3 | 455 | } |
81d66cf3 | 456 | |
7c0ea335 | 457 | return m_frameToolBar; |
81d66cf3 JS |
458 | } |
459 | ||
0d53fc34 | 460 | void wxFrame::PositionToolBar() |
81d66cf3 | 461 | { |
81d66cf3 | 462 | RECT rect; |
42e69d6b | 463 | ::GetClientRect(GetHwnd(), &rect); |
81d66cf3 | 464 | |
7c0ea335 | 465 | #if wxUSE_STATUSBAR |
81d66cf3 JS |
466 | if ( GetStatusBar() ) |
467 | { | |
7c0ea335 VZ |
468 | int statusX, statusY; |
469 | GetStatusBar()->GetClientSize(&statusX, &statusY); | |
470 | rect.bottom -= statusY; | |
81d66cf3 | 471 | } |
7c0ea335 | 472 | #endif // wxUSE_STATUSBAR |
81d66cf3 | 473 | |
a2327a9f | 474 | if ( GetToolBar() && GetToolBar()->IsShown() ) |
81d66cf3 JS |
475 | { |
476 | int tw, th; | |
7c0ea335 | 477 | GetToolBar()->GetSize(&tw, &th); |
81d66cf3 | 478 | |
7c0ea335 | 479 | if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL ) |
81d66cf3 | 480 | { |
7c0ea335 | 481 | th = rect.bottom; |
81d66cf3 JS |
482 | } |
483 | else | |
484 | { | |
7c0ea335 | 485 | tw = rect.right; |
81d66cf3 | 486 | } |
7c0ea335 VZ |
487 | |
488 | // Use the 'real' MSW position here | |
489 | GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS); | |
81d66cf3 JS |
490 | } |
491 | } | |
d427503c | 492 | #endif // wxUSE_TOOLBAR |
d2aef312 | 493 | |
7c0ea335 VZ |
494 | // ---------------------------------------------------------------------------- |
495 | // frame state (iconized/maximized/...) | |
496 | // ---------------------------------------------------------------------------- | |
497 | ||
a23fd0e1 VZ |
498 | // propagate our state change to all child frames: this allows us to emulate X |
499 | // Windows behaviour where child frames float independently of the parent one | |
500 | // on the desktop, but are iconized/restored with it | |
0d53fc34 | 501 | void wxFrame::IconizeChildFrames(bool bIconize) |
d2aef312 | 502 | { |
a23fd0e1 VZ |
503 | for ( wxWindowList::Node *node = GetChildren().GetFirst(); |
504 | node; | |
505 | node = node->GetNext() ) | |
506 | { | |
507 | wxWindow *win = node->GetData(); | |
508 | ||
3ca6a5f0 BP |
509 | // iconizing the frames with this style under Win95 shell puts them at |
510 | // the bottom of the screen (as the MDI children) instead of making | |
511 | // them appear in the taskbar because they are, by virtue of this | |
512 | // style, not managed by the taskbar - instead leave Windows take care | |
513 | // of them | |
514 | #ifdef __WIN95__ | |
515 | if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW ) | |
516 | continue; | |
517 | #endif // Win95 | |
518 | ||
3f7bc32b VZ |
519 | // the child MDI frames are a special case and should not be touched by |
520 | // the parent frame - instead, they are managed by the user | |
2e9f62da | 521 | wxFrame *frame = wxDynamicCast(win, wxFrame); |
1e6feb95 VZ |
522 | if ( frame |
523 | #if wxUSE_MDI_ARCHITECTURE | |
524 | && !wxDynamicCast(frame, wxMDIChildFrame) | |
525 | #endif // wxUSE_MDI_ARCHITECTURE | |
526 | ) | |
a23fd0e1 | 527 | { |
9327c3aa VZ |
528 | // we don't want to restore the child frames which had been |
529 | // iconized even before we were iconized, so save the child frame | |
530 | // status when iconizing the parent frame and check it when | |
531 | // restoring it | |
532 | if ( bIconize ) | |
533 | { | |
534 | frame->m_wasMinimized = frame->IsIconized(); | |
535 | } | |
536 | ||
537 | // this test works for both iconizing and restoring | |
538 | if ( !frame->m_wasMinimized ) | |
539 | frame->Iconize(bIconize); | |
a23fd0e1 | 540 | } |
d2aef312 | 541 | } |
d2aef312 VZ |
542 | } |
543 | ||
0d53fc34 | 544 | WXHICON wxFrame::GetDefaultIcon() const |
82c9f85c VZ |
545 | { |
546 | return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON | |
547 | : wxDEFAULT_FRAME_ICON); | |
548 | } | |
549 | ||
a23fd0e1 | 550 | // =========================================================================== |
42e69d6b | 551 | // message processing |
a23fd0e1 VZ |
552 | // =========================================================================== |
553 | ||
42e69d6b VZ |
554 | // --------------------------------------------------------------------------- |
555 | // preprocessing | |
556 | // --------------------------------------------------------------------------- | |
557 | ||
0d53fc34 | 558 | bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) |
42e69d6b VZ |
559 | { |
560 | if ( wxWindow::MSWTranslateMessage(pMsg) ) | |
561 | return TRUE; | |
562 | ||
1e6feb95 | 563 | #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__) |
42e69d6b VZ |
564 | // try the menu bar accels |
565 | wxMenuBar *menuBar = GetMenuBar(); | |
566 | if ( !menuBar ) | |
567 | return FALSE; | |
568 | ||
569 | const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable(); | |
c50f1fb9 | 570 | return acceleratorTable.Translate(this, pMsg); |
1e6feb95 VZ |
571 | #else |
572 | return FALSE; | |
573 | #endif // wxUSE_MENUS && wxUSE_ACCEL | |
42e69d6b VZ |
574 | } |
575 | ||
576 | // --------------------------------------------------------------------------- | |
577 | // our private (non virtual) message handlers | |
578 | // --------------------------------------------------------------------------- | |
579 | ||
0d53fc34 | 580 | bool wxFrame::HandlePaint() |
42e69d6b VZ |
581 | { |
582 | RECT rect; | |
583 | if ( GetUpdateRect(GetHwnd(), &rect, FALSE) ) | |
584 | { | |
04ef50df | 585 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
586 | if ( m_iconized ) |
587 | { | |
c50f1fb9 | 588 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
82c9f85c | 589 | : (HICON)GetDefaultIcon(); |
42e69d6b VZ |
590 | |
591 | // Hold a pointer to the dc so long as the OnPaint() message | |
592 | // is being processed | |
593 | PAINTSTRUCT ps; | |
594 | HDC hdc = ::BeginPaint(GetHwnd(), &ps); | |
595 | ||
596 | // Erase background before painting or we get white background | |
597 | MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L); | |
598 | ||
599 | if ( hIcon ) | |
600 | { | |
601 | RECT rect; | |
602 | ::GetClientRect(GetHwnd(), &rect); | |
603 | ||
604 | // FIXME: why hardcoded? | |
605 | static const int icon_width = 32; | |
606 | static const int icon_height = 32; | |
607 | ||
608 | int icon_x = (int)((rect.right - icon_width)/2); | |
609 | int icon_y = (int)((rect.bottom - icon_height)/2); | |
610 | ||
611 | ::DrawIcon(hdc, icon_x, icon_y, hIcon); | |
612 | } | |
613 | ||
614 | ::EndPaint(GetHwnd(), &ps); | |
615 | ||
616 | return TRUE; | |
617 | } | |
618 | else | |
04ef50df | 619 | #endif |
42e69d6b | 620 | { |
5d1d2d46 | 621 | return wxWindow::HandlePaint(); |
42e69d6b VZ |
622 | } |
623 | } | |
624 | else | |
625 | { | |
626 | // nothing to paint - processed | |
627 | return TRUE; | |
628 | } | |
629 | } | |
630 | ||
0d53fc34 | 631 | bool wxFrame::HandleSize(int x, int y, WXUINT id) |
42e69d6b VZ |
632 | { |
633 | bool processed = FALSE; | |
04ef50df | 634 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
635 | |
636 | switch ( id ) | |
637 | { | |
638 | case SIZENORMAL: | |
639 | // only do it it if we were iconized before, otherwise resizing the | |
640 | // parent frame has a curious side effect of bringing it under it's | |
641 | // children | |
642 | if ( !m_iconized ) | |
643 | break; | |
644 | ||
645 | // restore all child frames too | |
646 | IconizeChildFrames(FALSE); | |
647 | ||
3dd9b88a VZ |
648 | (void)SendIconizeEvent(FALSE); |
649 | ||
42e69d6b VZ |
650 | // fall through |
651 | ||
652 | case SIZEFULLSCREEN: | |
653 | m_iconized = FALSE; | |
654 | break; | |
655 | ||
656 | case SIZEICONIC: | |
657 | // iconize all child frames too | |
658 | IconizeChildFrames(TRUE); | |
659 | ||
3dd9b88a VZ |
660 | (void)SendIconizeEvent(); |
661 | ||
42e69d6b VZ |
662 | m_iconized = TRUE; |
663 | break; | |
664 | } | |
04ef50df | 665 | #endif |
42e69d6b VZ |
666 | |
667 | if ( !m_iconized ) | |
668 | { | |
1e6feb95 | 669 | #if wxUSE_STATUSBAR |
42e69d6b | 670 | PositionStatusBar(); |
1e6feb95 VZ |
671 | #endif // wxUSE_STATUSBAR |
672 | ||
673 | #if wxUSE_TOOLBAR | |
42e69d6b | 674 | PositionToolBar(); |
1e6feb95 | 675 | #endif // wxUSE_TOOLBAR |
42e69d6b VZ |
676 | |
677 | wxSizeEvent event(wxSize(x, y), m_windowId); | |
678 | event.SetEventObject( this ); | |
679 | processed = GetEventHandler()->ProcessEvent(event); | |
680 | } | |
681 | ||
682 | return processed; | |
683 | } | |
684 | ||
0d53fc34 | 685 | bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control) |
42e69d6b VZ |
686 | { |
687 | if ( control ) | |
688 | { | |
689 | // In case it's e.g. a toolbar. | |
690 | wxWindow *win = wxFindWinFromHandle(control); | |
691 | if ( win ) | |
692 | return win->MSWCommand(cmd, id); | |
693 | } | |
694 | ||
695 | // handle here commands from menus and accelerators | |
696 | if ( cmd == 0 || cmd == 1 ) | |
697 | { | |
1e6feb95 | 698 | #if wxUSE_MENUS_NATIVE |
42e69d6b VZ |
699 | if ( wxCurrentPopupMenu ) |
700 | { | |
701 | wxMenu *popupMenu = wxCurrentPopupMenu; | |
702 | wxCurrentPopupMenu = NULL; | |
703 | ||
704 | return popupMenu->MSWCommand(cmd, id); | |
705 | } | |
1e6feb95 | 706 | #endif // wxUSE_MENUS_NATIVE |
42e69d6b VZ |
707 | |
708 | if ( ProcessCommand(id) ) | |
709 | { | |
710 | return TRUE; | |
711 | } | |
712 | } | |
713 | ||
714 | return FALSE; | |
715 | } | |
716 | ||
0d53fc34 | 717 | bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu) |
a23fd0e1 VZ |
718 | { |
719 | int item; | |
c219cecc | 720 | if ( flags == 0xFFFF && hMenu == 0 ) |
a23fd0e1 | 721 | { |
c219cecc | 722 | // menu was removed from screen |
a23fd0e1 VZ |
723 | item = -1; |
724 | } | |
04ef50df | 725 | #ifndef __WXMICROWIN__ |
c219cecc | 726 | else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) ) |
a23fd0e1 VZ |
727 | { |
728 | item = nItem; | |
729 | } | |
04ef50df | 730 | #endif |
a23fd0e1 VZ |
731 | else |
732 | { | |
1e6feb95 | 733 | #if wxUSE_STATUSBAR |
c219cecc | 734 | // don't give hints for separators (doesn't make sense) nor for the |
f6bcfd97 BP |
735 | // items opening popup menus (they don't have them anyhow) but do clear |
736 | // the status line - otherwise, we would be left with the help message | |
737 | // for the previous item which doesn't apply any more | |
738 | wxStatusBar *statbar = GetStatusBar(); | |
739 | if ( statbar ) | |
740 | { | |
741 | statbar->SetStatusText(wxEmptyString); | |
742 | } | |
1e6feb95 | 743 | #endif // wxUSE_STATUSBAR |
f6bcfd97 | 744 | |
a23fd0e1 VZ |
745 | return FALSE; |
746 | } | |
747 | ||
748 | wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); | |
749 | event.SetEventObject( this ); | |
750 | ||
751 | return GetEventHandler()->ProcessEvent(event); | |
752 | } | |
753 | ||
754 | // --------------------------------------------------------------------------- | |
0d53fc34 | 755 | // the window proc for wxFrame |
a23fd0e1 VZ |
756 | // --------------------------------------------------------------------------- |
757 | ||
0d53fc34 | 758 | long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
a23fd0e1 VZ |
759 | { |
760 | long rc = 0; | |
761 | bool processed = FALSE; | |
762 | ||
763 | switch ( message ) | |
764 | { | |
42e69d6b VZ |
765 | case WM_CLOSE: |
766 | // if we can't close, tell the system that we processed the | |
767 | // message - otherwise it would close us | |
768 | processed = !Close(); | |
769 | break; | |
770 | ||
771 | case WM_COMMAND: | |
772 | { | |
773 | WORD id, cmd; | |
774 | WXHWND hwnd; | |
775 | UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam, | |
776 | &id, &hwnd, &cmd); | |
777 | ||
778 | processed = HandleCommand(id, cmd, (WXHWND)hwnd); | |
779 | } | |
780 | break; | |
781 | ||
04ef50df | 782 | #ifndef __WXMICROWIN__ |
a23fd0e1 VZ |
783 | case WM_MENUSELECT: |
784 | { | |
42e69d6b VZ |
785 | WXWORD item, flags; |
786 | WXHMENU hmenu; | |
787 | UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); | |
788 | ||
789 | processed = HandleMenuSelect(item, flags, hmenu); | |
a23fd0e1 VZ |
790 | } |
791 | break; | |
04ef50df | 792 | #endif |
42e69d6b VZ |
793 | |
794 | case WM_PAINT: | |
795 | processed = HandlePaint(); | |
796 | break; | |
797 | ||
04ef50df | 798 | #ifndef __WXMICROWIN__ |
42e69d6b VZ |
799 | case WM_QUERYDRAGICON: |
800 | { | |
c50f1fb9 | 801 | HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon) |
82c9f85c | 802 | : (HICON)GetDefaultIcon(); |
42e69d6b VZ |
803 | rc = (long)hIcon; |
804 | processed = rc != 0; | |
805 | } | |
806 | break; | |
04ef50df | 807 | #endif |
42e69d6b VZ |
808 | |
809 | case WM_SIZE: | |
810 | processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam); | |
811 | break; | |
a23fd0e1 VZ |
812 | } |
813 | ||
814 | if ( !processed ) | |
815 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
816 | ||
817 | return rc; | |
818 | } | |
21802234 | 819 |