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