]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
changed/centralized window creation code to allow wxTLW work in wxUniv
[wxWidgets.git] / src / msw / frame.cpp
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_fsStyle = 0;
113 m_fsOldWindowStyle = 0;
114 m_fsStatusBarFields = 0;
115 m_fsStatusBarHeight = 0;
116 m_fsToolBarHeight = 0;
117 // m_fsMenu = 0;
118 m_fsIsMaximized = FALSE;
119 m_fsIsShowing = FALSE;
120
121 m_winLastFocused = (wxWindow *)NULL;
122 }
123
124 bool wxFrameMSW::Create(wxWindow *parent,
125 wxWindowID id,
126 const wxString& title,
127 const wxPoint& pos,
128 const wxSize& size,
129 long style,
130 const wxString& name)
131 {
132 if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) )
133 return FALSE;
134
135 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
136
137 wxModelessWindows.Append(this);
138
139 return TRUE;
140 }
141
142 wxFrameMSW::~wxFrameMSW()
143 {
144 m_isBeingDeleted = TRUE;
145
146 DeleteAllBars();
147 }
148
149 // Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
150 void wxFrameMSW::DoGetClientSize(int *x, int *y) const
151 {
152 RECT rect;
153 ::GetClientRect(GetHwnd(), &rect);
154
155 #if wxUSE_STATUSBAR
156 if ( GetStatusBar() && GetStatusBar()->IsShown() )
157 {
158 int statusX, statusY;
159 GetStatusBar()->GetClientSize(&statusX, &statusY);
160 rect.bottom -= statusY;
161 }
162 #endif // wxUSE_STATUSBAR
163
164 wxPoint pt(GetClientAreaOrigin());
165 rect.bottom -= pt.y;
166 rect.right -= pt.x;
167
168 if ( x )
169 *x = rect.right;
170 if ( y )
171 *y = rect.bottom;
172 }
173
174 void wxFrameMSW::DoSetClientSize(int width, int height)
175 {
176 // leave enough space for the status bar if we have (and show) it
177 #if wxUSE_STATUSBAR
178 wxStatusBar *statbar = GetStatusBar();
179 if ( statbar && statbar->IsShown() )
180 {
181 height += statbar->GetSize().y;
182 }
183 #endif // wxUSE_STATUSBAR
184
185 wxTopLevelWindow::DoSetClientSize(width, height);
186 }
187
188 // ----------------------------------------------------------------------------
189 // wxFrameMSW: various geometry-related functions
190 // ----------------------------------------------------------------------------
191
192 void wxFrameMSW::Raise()
193 {
194 #ifdef __WIN16__
195 // no SetForegroundWindow() in Win16
196 wxFrameBase::Raise();
197 #else // Win32
198 ::SetForegroundWindow(GetHwnd());
199 #endif // Win16/32
200 }
201
202 // generate an artificial resize event
203 void wxFrameMSW::SendSizeEvent()
204 {
205 if ( !m_iconized )
206 {
207 RECT r = wxGetWindowRect(GetHwnd());
208
209 (void)::PostMessage(GetHwnd(), WM_SIZE,
210 IsMaximized() ? SIZE_MAXIMIZED : SIZE_RESTORED,
211 MAKELPARAM(r.right - r.left, r.bottom - r.top));
212 }
213 }
214
215 #if wxUSE_STATUSBAR
216 wxStatusBar *wxFrameMSW::OnCreateStatusBar(int number,
217 long style,
218 wxWindowID id,
219 const wxString& name)
220 {
221 wxStatusBar *statusBar = NULL;
222
223 #if wxUSE_NATIVE_STATUSBAR
224 if ( !UsesNativeStatusBar() )
225 {
226 statusBar = (wxStatusBar *)new wxStatusBarGeneric(this, id, style);
227 }
228 else
229 #endif
230 {
231 statusBar = new wxStatusBar(this, id, style, name);
232 }
233
234 // Set the height according to the font and the border size
235 wxClientDC dc(statusBar);
236 dc.SetFont(statusBar->GetFont());
237
238 wxCoord y;
239 dc.GetTextExtent(_T("X"), NULL, &y );
240
241 int height = (int)( (11*y)/10 + 2*statusBar->GetBorderY());
242
243 statusBar->SetSize(-1, -1, -1, height);
244
245 statusBar->SetFieldsCount(number);
246
247 return statusBar;
248 }
249
250 void wxFrameMSW::PositionStatusBar()
251 {
252 if ( !m_frameStatusBar )
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 wxFrameMSW::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 // Can set a menubar several times.
281 if ( menubar->GetHMenu() )
282 {
283 m_hMenu = menubar->GetHMenu();
284 }
285 else // no HMENU yet
286 {
287 m_hMenu = menubar->Create();
288
289 if ( !m_hMenu )
290 {
291 wxFAIL_MSG( _T("failed to create menu bar") );
292 return;
293 }
294 }
295
296 InternalSetMenuBar();
297 }
298 }
299
300 void wxFrameMSW::InternalSetMenuBar()
301 {
302 #ifndef __WXMICROWIN__
303 if ( !::SetMenu(GetHwnd(), (HMENU)m_hMenu) )
304 {
305 wxLogLastError(wxT("SetMenu"));
306 }
307 #endif
308 }
309
310 #endif // wxUSE_MENUS_NATIVE
311
312 // Responds to colour changes, and passes event on to children.
313 void wxFrameMSW::OnSysColourChanged(wxSysColourChangedEvent& event)
314 {
315 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
316 Refresh();
317
318 #if wxUSE_STATUSBAR
319 if ( m_frameStatusBar )
320 {
321 wxSysColourChangedEvent event2;
322 event2.SetEventObject( m_frameStatusBar );
323 m_frameStatusBar->GetEventHandler()->ProcessEvent(event2);
324 }
325 #endif // wxUSE_STATUSBAR
326
327 // Propagate the event to the non-top-level children
328 wxWindow::OnSysColourChanged(event);
329 }
330
331 // Pass TRUE to show full screen, FALSE to restore.
332 bool wxFrameMSW::ShowFullScreen(bool show, long style)
333 {
334 if (show)
335 {
336 if (IsFullScreen())
337 return FALSE;
338
339 m_fsIsShowing = TRUE;
340 m_fsStyle = style;
341
342 #if wxUSE_TOOLBAR
343 wxToolBar *theToolBar = GetToolBar();
344 if (theToolBar)
345 theToolBar->GetSize(NULL, &m_fsToolBarHeight);
346
347 // zap the toolbar, menubar, and statusbar
348
349 if ((style & wxFULLSCREEN_NOTOOLBAR) && theToolBar)
350 {
351 theToolBar->SetSize(-1,0);
352 theToolBar->Show(FALSE);
353 }
354 #endif // wxUSE_TOOLBAR
355
356 #ifndef __WXMICROWIN__
357 if (style & wxFULLSCREEN_NOMENUBAR)
358 SetMenu((HWND)GetHWND(), (HMENU) NULL);
359 #endif
360
361 #if wxUSE_STATUSBAR
362 wxStatusBar *theStatusBar = GetStatusBar();
363 if (theStatusBar)
364 theStatusBar->GetSize(NULL, &m_fsStatusBarHeight);
365
366 // Save the number of fields in the statusbar
367 if ((style & wxFULLSCREEN_NOSTATUSBAR) && theStatusBar)
368 {
369 //m_fsStatusBarFields = theStatusBar->GetFieldsCount();
370 //SetStatusBar((wxStatusBar*) NULL);
371 //delete theStatusBar;
372 theStatusBar->Show(FALSE);
373 }
374 else
375 m_fsStatusBarFields = 0;
376 #endif // wxUSE_STATUSBAR
377
378 // zap the frame borders
379
380 // save the 'normal' window style
381 m_fsOldWindowStyle = GetWindowLong((HWND)GetHWND(), GWL_STYLE);
382
383 // save the old position, width & height, maximize state
384 m_fsOldSize = GetRect();
385 m_fsIsMaximized = IsMaximized();
386
387 // decide which window style flags to turn off
388 LONG newStyle = m_fsOldWindowStyle;
389 LONG offFlags = 0;
390
391 if (style & wxFULLSCREEN_NOBORDER)
392 offFlags |= WS_BORDER | WS_THICKFRAME;
393 if (style & wxFULLSCREEN_NOCAPTION)
394 offFlags |= (WS_CAPTION | WS_SYSMENU);
395
396 newStyle &= (~offFlags);
397
398 // change our window style to be compatible with full-screen mode
399 ::SetWindowLong((HWND)GetHWND(), GWL_STYLE, newStyle);
400
401 // resize to the size of the desktop
402 int width, height;
403
404 RECT rect = wxGetWindowRect(::GetDesktopWindow());
405 width = rect.right - rect.left;
406 height = rect.bottom - rect.top;
407
408 SetSize(width, height);
409
410 // now flush the window style cache and actually go full-screen
411 SetWindowPos((HWND)GetHWND(), HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED);
412
413 wxSizeEvent event(wxSize(width, height), GetId());
414 GetEventHandler()->ProcessEvent(event);
415
416 return TRUE;
417 }
418 else
419 {
420 if (!IsFullScreen())
421 return FALSE;
422
423 m_fsIsShowing = FALSE;
424
425 #if wxUSE_TOOLBAR
426 wxToolBar *theToolBar = GetToolBar();
427
428 // restore the toolbar, menubar, and statusbar
429 if (theToolBar && (m_fsStyle & wxFULLSCREEN_NOTOOLBAR))
430 {
431 theToolBar->SetSize(-1, m_fsToolBarHeight);
432 theToolBar->Show(TRUE);
433 }
434 #endif // wxUSE_TOOLBAR
435
436 #if wxUSE_STATUSBAR
437 if ( m_fsStyle & wxFULLSCREEN_NOSTATUSBAR )
438 {
439 //CreateStatusBar(m_fsStatusBarFields);
440 if (GetStatusBar())
441 {
442 GetStatusBar()->Show(TRUE);
443 PositionStatusBar();
444 }
445 }
446 #endif // wxUSE_STATUSBAR
447
448 #ifndef __WXMICROWIN__
449 if ((m_fsStyle & wxFULLSCREEN_NOMENUBAR) && (m_hMenu != 0))
450 SetMenu((HWND)GetHWND(), (HMENU)m_hMenu);
451 #endif
452
453 Maximize(m_fsIsMaximized);
454 SetWindowLong((HWND)GetHWND(),GWL_STYLE, m_fsOldWindowStyle);
455 SetWindowPos((HWND)GetHWND(),HWND_TOP,m_fsOldSize.x, m_fsOldSize.y,
456 m_fsOldSize.width, m_fsOldSize.height, SWP_FRAMECHANGED);
457
458 return TRUE;
459 }
460 }
461
462 // Default activation behaviour - set the focus for the first child
463 // subwindow found.
464 void wxFrameMSW::OnActivate(wxActivateEvent& event)
465 {
466 if ( event.GetActive() )
467 {
468 // restore focus to the child which was last focused
469 wxLogTrace(_T("focus"), _T("wxFrameMSW %08x activated."), m_hWnd);
470
471 wxWindow *parent = m_winLastFocused ? m_winLastFocused->GetParent()
472 : NULL;
473 if ( !parent )
474 {
475 parent = this;
476 }
477
478 wxSetFocusToChild(parent, &m_winLastFocused);
479 }
480 else // deactivating
481 {
482 // remember the last focused child if it is our child
483 m_winLastFocused = FindFocus();
484
485 // so we NULL it out if it's a child from some other frame
486 wxWindow *win = m_winLastFocused;
487 while ( win )
488 {
489 if ( win->IsTopLevel() )
490 {
491 if ( win != this )
492 {
493 m_winLastFocused = NULL;
494 }
495
496 break;
497 }
498
499 win = win->GetParent();
500 }
501
502 wxLogTrace(_T("focus"),
503 _T("wxFrameMSW %08x deactivated, last focused: %08x."),
504 m_hWnd,
505 m_winLastFocused ? GetHwndOf(m_winLastFocused)
506 : NULL);
507
508 event.Skip();
509 }
510 }
511
512 // ----------------------------------------------------------------------------
513 // tool/status bar stuff
514 // ----------------------------------------------------------------------------
515
516 #if wxUSE_TOOLBAR
517
518 wxToolBar* wxFrameMSW::CreateToolBar(long style, wxWindowID id, const wxString& name)
519 {
520 if ( wxFrameBase::CreateToolBar(style, id, name) )
521 {
522 PositionToolBar();
523 }
524
525 return m_frameToolBar;
526 }
527
528 void wxFrameMSW::PositionToolBar()
529 {
530 RECT rect;
531 ::GetClientRect(GetHwnd(), &rect);
532
533 #if wxUSE_STATUSBAR
534 if ( GetStatusBar() )
535 {
536 int statusX, statusY;
537 GetStatusBar()->GetClientSize(&statusX, &statusY);
538 rect.bottom -= statusY;
539 }
540 #endif // wxUSE_STATUSBAR
541
542 if ( GetToolBar() && GetToolBar()->IsShown() )
543 {
544 int tw, th;
545 GetToolBar()->GetSize(&tw, &th);
546
547 if ( GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL )
548 {
549 th = rect.bottom;
550 }
551 else
552 {
553 tw = rect.right;
554 }
555
556 // Use the 'real' MSW position here
557 GetToolBar()->SetSize(0, 0, tw, th, wxSIZE_NO_ADJUSTMENTS);
558 }
559 }
560 #endif // wxUSE_TOOLBAR
561
562 // ----------------------------------------------------------------------------
563 // frame state (iconized/maximized/...)
564 // ----------------------------------------------------------------------------
565
566 // propagate our state change to all child frames: this allows us to emulate X
567 // Windows behaviour where child frames float independently of the parent one
568 // on the desktop, but are iconized/restored with it
569 void wxFrameMSW::IconizeChildFrames(bool bIconize)
570 {
571 for ( wxWindowList::Node *node = GetChildren().GetFirst();
572 node;
573 node = node->GetNext() )
574 {
575 wxWindow *win = node->GetData();
576
577 // iconizing the frames with this style under Win95 shell puts them at
578 // the bottom of the screen (as the MDI children) instead of making
579 // them appear in the taskbar because they are, by virtue of this
580 // style, not managed by the taskbar - instead leave Windows take care
581 // of them
582 #ifdef __WIN95__
583 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
584 continue;
585 #endif // Win95
586
587 // the child MDI frames are a special case and should not be touched by
588 // the parent frame - instead, they are managed by the user
589 wxFrame *frame = wxDynamicCast(win, wxFrame);
590 if ( frame
591 #if wxUSE_MDI_ARCHITECTURE
592 && !wxDynamicCast(frame, wxMDIChildFrame)
593 #endif // wxUSE_MDI_ARCHITECTURE
594 )
595 {
596 frame->Iconize(bIconize);
597 }
598 }
599 }
600
601 WXHICON wxFrameMSW::GetDefaultIcon() const
602 {
603 return (WXHICON)(wxSTD_FRAME_ICON ? wxSTD_FRAME_ICON
604 : wxDEFAULT_FRAME_ICON);
605 }
606
607 // ===========================================================================
608 // message processing
609 // ===========================================================================
610
611 // ---------------------------------------------------------------------------
612 // preprocessing
613 // ---------------------------------------------------------------------------
614
615 bool wxFrameMSW::MSWTranslateMessage(WXMSG* pMsg)
616 {
617 if ( wxWindow::MSWTranslateMessage(pMsg) )
618 return TRUE;
619
620 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
621 // try the menu bar accels
622 wxMenuBar *menuBar = GetMenuBar();
623 if ( !menuBar )
624 return FALSE;
625
626 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
627 return acceleratorTable.Translate(this, pMsg);
628 #else
629 return FALSE;
630 #endif // wxUSE_MENUS && wxUSE_ACCEL
631 }
632
633 // ---------------------------------------------------------------------------
634 // our private (non virtual) message handlers
635 // ---------------------------------------------------------------------------
636
637 bool wxFrameMSW::HandlePaint()
638 {
639 RECT rect;
640 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
641 {
642 #ifndef __WXMICROWIN__
643 if ( m_iconized )
644 {
645 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
646 : (HICON)GetDefaultIcon();
647
648 // Hold a pointer to the dc so long as the OnPaint() message
649 // is being processed
650 PAINTSTRUCT ps;
651 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
652
653 // Erase background before painting or we get white background
654 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
655
656 if ( hIcon )
657 {
658 RECT rect;
659 ::GetClientRect(GetHwnd(), &rect);
660
661 // FIXME: why hardcoded?
662 static const int icon_width = 32;
663 static const int icon_height = 32;
664
665 int icon_x = (int)((rect.right - icon_width)/2);
666 int icon_y = (int)((rect.bottom - icon_height)/2);
667
668 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
669 }
670
671 ::EndPaint(GetHwnd(), &ps);
672
673 return TRUE;
674 }
675 else
676 #endif
677 {
678 return wxWindow::HandlePaint();
679 }
680 }
681 else
682 {
683 // nothing to paint - processed
684 return TRUE;
685 }
686 }
687
688 bool wxFrameMSW::HandleSize(int x, int y, WXUINT id)
689 {
690 bool processed = FALSE;
691 #ifndef __WXMICROWIN__
692
693 switch ( id )
694 {
695 case SIZENORMAL:
696 // only do it it if we were iconized before, otherwise resizing the
697 // parent frame has a curious side effect of bringing it under it's
698 // children
699 if ( !m_iconized )
700 break;
701
702 // restore all child frames too
703 IconizeChildFrames(FALSE);
704
705 (void)SendIconizeEvent(FALSE);
706
707 // fall through
708
709 case SIZEFULLSCREEN:
710 m_iconized = FALSE;
711 break;
712
713 case SIZEICONIC:
714 // iconize all child frames too
715 IconizeChildFrames(TRUE);
716
717 (void)SendIconizeEvent();
718
719 m_iconized = TRUE;
720 break;
721 }
722 #endif
723
724 if ( !m_iconized )
725 {
726 #if wxUSE_STATUSBAR
727 PositionStatusBar();
728 #endif // wxUSE_STATUSBAR
729
730 #if wxUSE_TOOLBAR
731 PositionToolBar();
732 #endif // wxUSE_TOOLBAR
733
734 wxSizeEvent event(wxSize(x, y), m_windowId);
735 event.SetEventObject( this );
736 processed = GetEventHandler()->ProcessEvent(event);
737 }
738
739 return processed;
740 }
741
742 bool wxFrameMSW::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
743 {
744 if ( control )
745 {
746 // In case it's e.g. a toolbar.
747 wxWindow *win = wxFindWinFromHandle(control);
748 if ( win )
749 return win->MSWCommand(cmd, id);
750 }
751
752 // handle here commands from menus and accelerators
753 if ( cmd == 0 || cmd == 1 )
754 {
755 #if wxUSE_MENUS_NATIVE
756 if ( wxCurrentPopupMenu )
757 {
758 wxMenu *popupMenu = wxCurrentPopupMenu;
759 wxCurrentPopupMenu = NULL;
760
761 return popupMenu->MSWCommand(cmd, id);
762 }
763 #endif // wxUSE_MENUS_NATIVE
764
765 if ( ProcessCommand(id) )
766 {
767 return TRUE;
768 }
769 }
770
771 return FALSE;
772 }
773
774 bool wxFrameMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
775 {
776 int item;
777 if ( flags == 0xFFFF && hMenu == 0 )
778 {
779 // menu was removed from screen
780 item = -1;
781 }
782 #ifndef __WXMICROWIN__
783 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
784 {
785 item = nItem;
786 }
787 #endif
788 else
789 {
790 #if wxUSE_STATUSBAR
791 // don't give hints for separators (doesn't make sense) nor for the
792 // items opening popup menus (they don't have them anyhow) but do clear
793 // the status line - otherwise, we would be left with the help message
794 // for the previous item which doesn't apply any more
795 wxStatusBar *statbar = GetStatusBar();
796 if ( statbar )
797 {
798 statbar->SetStatusText(wxEmptyString);
799 }
800 #endif // wxUSE_STATUSBAR
801
802 return FALSE;
803 }
804
805 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
806 event.SetEventObject( this );
807
808 return GetEventHandler()->ProcessEvent(event);
809 }
810
811 // ---------------------------------------------------------------------------
812 // the window proc for wxFrameMSW
813 // ---------------------------------------------------------------------------
814
815 long wxFrameMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
816 {
817 long rc = 0;
818 bool processed = FALSE;
819
820 switch ( message )
821 {
822 case WM_CLOSE:
823 // if we can't close, tell the system that we processed the
824 // message - otherwise it would close us
825 processed = !Close();
826 break;
827
828 case WM_COMMAND:
829 {
830 WORD id, cmd;
831 WXHWND hwnd;
832 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
833 &id, &hwnd, &cmd);
834
835 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
836 }
837 break;
838
839 #ifndef __WXMICROWIN__
840 case WM_MENUSELECT:
841 {
842 WXWORD item, flags;
843 WXHMENU hmenu;
844 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
845
846 processed = HandleMenuSelect(item, flags, hmenu);
847 }
848 break;
849 #endif
850
851 case WM_PAINT:
852 processed = HandlePaint();
853 break;
854
855 #ifndef __WXMICROWIN__
856 case WM_QUERYDRAGICON:
857 {
858 HICON hIcon = m_icon.Ok() ? GetHiconOf(m_icon)
859 : (HICON)GetDefaultIcon();
860 rc = (long)hIcon;
861 processed = rc != 0;
862 }
863 break;
864 #endif
865
866 case WM_SIZE:
867 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
868 break;
869 }
870
871 if ( !processed )
872 rc = wxWindow::MSWWindowProc(message, wParam, lParam);
873
874 return rc;
875 }
876