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