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