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