]> git.saurik.com Git - wxWidgets.git/blob - src/msw/frame.cpp
compilation fix
[wxWidgets.git] / src / msw / frame.cpp
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 tx, ty;
478 int tw, th;
479 toolbar->GetPosition(&tx, &ty);
480 toolbar->GetSize(&tw, &th);
481
482 // Adjust
483 if (ty < 0 && (-ty == th))
484 ty = 0;
485 if (tx < 0 && (-tx == tw))
486 tx = 0;
487
488 int desiredW = tw;
489 int desiredH = th;
490
491 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
492 {
493 desiredH = height;
494 }
495 else
496 {
497 desiredW = width;
498 // if ( toolbar->GetWindowStyleFlag() & wxTB_FLAT )
499 // desiredW -= 3;
500 }
501
502 // use the 'real' MSW position here, don't offset relativly to the
503 // client area origin
504
505 // Optimise such that we don't have to always resize the toolbar
506 // when the frame changes, otherwise we'll get a lot of flicker.
507 bool heightChanging = TRUE;
508 bool widthChanging = TRUE;
509
510 if ( toolbar->GetWindowStyleFlag() & wxTB_VERTICAL )
511 {
512 // It's OK if the current height is greater than what can be shown.
513 heightChanging = (desiredH > th) ;
514 widthChanging = (desiredW != tw) ;
515
516 // The next time around, we may not have to set the size
517 if (heightChanging)
518 desiredH = desiredH + 200;
519 }
520 else
521 {
522 // It's OK if the current width is greater than what can be shown.
523 widthChanging = (desiredW > tw) ;
524 heightChanging = (desiredH != th) ;
525
526 // The next time around, we may not have to set the size
527 if (widthChanging)
528 desiredW = desiredW + 200;
529 }
530
531 if (tx != 0 || ty != 0 || widthChanging || heightChanging)
532 toolbar->SetSize(0, 0, desiredW, desiredH, wxSIZE_NO_ADJUSTMENTS);
533
534 #endif // __WXWINCE__
535 }
536 }
537
538 #endif // wxUSE_TOOLBAR
539
540 // ----------------------------------------------------------------------------
541 // frame state (iconized/maximized/...)
542 // ----------------------------------------------------------------------------
543
544 // propagate our state change to all child frames: this allows us to emulate X
545 // Windows behaviour where child frames float independently of the parent one
546 // on the desktop, but are iconized/restored with it
547 void wxFrame::IconizeChildFrames(bool bIconize)
548 {
549 for ( wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
550 node;
551 node = node->GetNext() )
552 {
553 wxWindow *win = node->GetData();
554
555 // iconizing the frames with this style under Win95 shell puts them at
556 // the bottom of the screen (as the MDI children) instead of making
557 // them appear in the taskbar because they are, by virtue of this
558 // style, not managed by the taskbar - instead leave Windows take care
559 // of them
560 #ifdef __WIN95__
561 if ( win->GetWindowStyle() & wxFRAME_TOOL_WINDOW )
562 continue;
563 #endif // Win95
564
565 // the child MDI frames are a special case and should not be touched by
566 // the parent frame - instead, they are managed by the user
567 wxFrame *frame = wxDynamicCast(win, wxFrame);
568 if ( frame
569 #if wxUSE_MDI_ARCHITECTURE
570 && !wxDynamicCast(frame, wxMDIChildFrame)
571 #endif // wxUSE_MDI_ARCHITECTURE
572 )
573 {
574 // we don't want to restore the child frames which had been
575 // iconized even before we were iconized, so save the child frame
576 // status when iconizing the parent frame and check it when
577 // restoring it
578 if ( bIconize )
579 {
580 // note that we shouldn't touch the hidden frames neither
581 // because iconizing/restoring them would show them as a side
582 // effect
583 frame->m_wasMinimized = frame->IsIconized() || !frame->IsShown();
584 }
585
586 // this test works for both iconizing and restoring
587 if ( !frame->m_wasMinimized )
588 frame->Iconize(bIconize);
589 }
590 }
591 }
592
593 WXHICON wxFrame::GetDefaultIcon() const
594 {
595 // we don't have any standard icons (any more)
596 return (WXHICON)0;
597 }
598
599 // ===========================================================================
600 // message processing
601 // ===========================================================================
602
603 // ---------------------------------------------------------------------------
604 // preprocessing
605 // ---------------------------------------------------------------------------
606
607 bool wxFrame::MSWTranslateMessage(WXMSG* pMsg)
608 {
609 if ( wxWindow::MSWTranslateMessage(pMsg) )
610 return TRUE;
611
612 #if wxUSE_MENUS && wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
613 // try the menu bar accels
614 wxMenuBar *menuBar = GetMenuBar();
615 if ( !menuBar )
616 return FALSE;
617
618 const wxAcceleratorTable& acceleratorTable = menuBar->GetAccelTable();
619 return acceleratorTable.Translate(this, pMsg);
620 #else
621 return FALSE;
622 #endif // wxUSE_MENUS && wxUSE_ACCEL
623 }
624
625 // ---------------------------------------------------------------------------
626 // our private (non virtual) message handlers
627 // ---------------------------------------------------------------------------
628
629 bool wxFrame::HandlePaint()
630 {
631 RECT rect;
632 if ( GetUpdateRect(GetHwnd(), &rect, FALSE) )
633 {
634 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
635 if ( m_iconized )
636 {
637 const wxIcon& icon = GetIcon();
638 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
639 : (HICON)GetDefaultIcon();
640
641 // Hold a pointer to the dc so long as the OnPaint() message
642 // is being processed
643 PAINTSTRUCT ps;
644 HDC hdc = ::BeginPaint(GetHwnd(), &ps);
645
646 // Erase background before painting or we get white background
647 MSWDefWindowProc(WM_ICONERASEBKGND, (WORD)(LONG)ps.hdc, 0L);
648
649 if ( hIcon )
650 {
651 RECT rect;
652 ::GetClientRect(GetHwnd(), &rect);
653
654 // FIXME: why hardcoded?
655 static const int icon_width = 32;
656 static const int icon_height = 32;
657
658 int icon_x = (int)((rect.right - icon_width)/2);
659 int icon_y = (int)((rect.bottom - icon_height)/2);
660
661 ::DrawIcon(hdc, icon_x, icon_y, hIcon);
662 }
663
664 ::EndPaint(GetHwnd(), &ps);
665
666 return TRUE;
667 }
668 else
669 #endif
670 {
671 return wxWindow::HandlePaint();
672 }
673 }
674 else
675 {
676 // nothing to paint - processed
677 return TRUE;
678 }
679 }
680
681 bool wxFrame::HandleSize(int x, int y, WXUINT id)
682 {
683 bool processed = FALSE;
684 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
685
686 switch ( id )
687 {
688 case SIZENORMAL:
689 // only do it it if we were iconized before, otherwise resizing the
690 // parent frame has a curious side effect of bringing it under it's
691 // children
692 if ( !m_iconized )
693 break;
694
695 // restore all child frames too
696 IconizeChildFrames(FALSE);
697
698 (void)SendIconizeEvent(FALSE);
699
700 // fall through
701
702 case SIZEFULLSCREEN:
703 m_iconized = FALSE;
704 break;
705
706 case SIZEICONIC:
707 // iconize all child frames too
708 IconizeChildFrames(TRUE);
709
710 (void)SendIconizeEvent();
711
712 m_iconized = TRUE;
713 break;
714 }
715 #endif
716
717 if ( !m_iconized )
718 {
719 #if wxUSE_STATUSBAR
720 PositionStatusBar();
721 #endif // wxUSE_STATUSBAR
722
723 #if wxUSE_TOOLBAR
724 PositionToolBar();
725 #endif // wxUSE_TOOLBAR
726
727 processed = wxWindow::HandleSize(x, y, id);
728 }
729
730 return processed;
731 }
732
733 bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
734 {
735 if ( control )
736 {
737 // In case it's e.g. a toolbar.
738 wxWindow *win = wxFindWinFromHandle(control);
739 if ( win )
740 return win->MSWCommand(cmd, id);
741 }
742
743 // handle here commands from menus and accelerators
744 if ( cmd == 0 || cmd == 1 )
745 {
746 #if wxUSE_MENUS_NATIVE
747 if ( wxCurrentPopupMenu )
748 {
749 wxMenu *popupMenu = wxCurrentPopupMenu;
750 wxCurrentPopupMenu = NULL;
751
752 return popupMenu->MSWCommand(cmd, id);
753 }
754 #endif // wxUSE_MENUS_NATIVE
755
756 if ( ProcessCommand(id) )
757 {
758 return TRUE;
759 }
760 }
761
762 return FALSE;
763 }
764
765 bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
766 {
767 int item;
768 if ( flags == 0xFFFF && hMenu == 0 )
769 {
770 // menu was removed from screen
771 item = -1;
772 }
773 #ifndef __WXMICROWIN__
774 else if ( !(flags & MF_POPUP) && !(flags & MF_SEPARATOR) )
775 {
776 item = nItem;
777 }
778 #endif
779 else
780 {
781 // don't give hints for separators (doesn't make sense) nor for the
782 // items opening popup menus (they don't have them anyhow) but do clear
783 // the status line - otherwise, we would be left with the help message
784 // for the previous item which doesn't apply any more
785 DoGiveHelp(wxEmptyString, FALSE);
786
787 return FALSE;
788 }
789
790 wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
791 event.SetEventObject(this);
792
793 return GetEventHandler()->ProcessEvent(event);
794 }
795
796 bool wxFrame::HandleMenuLoop(const wxEventType& evtType, WXWORD isPopup)
797 {
798 // we don't have the menu id here, so we use the id to specify if the event
799 // was from a popup menu or a normal one
800 wxMenuEvent event(evtType, isPopup ? -1 : 0);
801 event.SetEventObject(this);
802
803 return GetEventHandler()->ProcessEvent(event);
804 }
805
806 // ---------------------------------------------------------------------------
807 // the window proc for wxFrame
808 // ---------------------------------------------------------------------------
809
810 long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
811 {
812 long rc = 0;
813 bool processed = FALSE;
814
815 switch ( message )
816 {
817 case WM_CLOSE:
818 // if we can't close, tell the system that we processed the
819 // message - otherwise it would close us
820 processed = !Close();
821 break;
822
823 case WM_SIZE:
824 processed = HandleSize(LOWORD(lParam), HIWORD(lParam), wParam);
825 break;
826
827 case WM_COMMAND:
828 {
829 WORD id, cmd;
830 WXHWND hwnd;
831 UnpackCommand((WXWPARAM)wParam, (WXLPARAM)lParam,
832 &id, &hwnd, &cmd);
833
834 processed = HandleCommand(id, cmd, (WXHWND)hwnd);
835 }
836 break;
837
838 case WM_PAINT:
839 processed = HandlePaint();
840 break;
841
842 case WM_INITMENUPOPUP:
843 processed = HandleInitMenuPopup((WXHMENU) wParam);
844 break;
845
846 #if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
847 case WM_MENUSELECT:
848 {
849 WXWORD item, flags;
850 WXHMENU hmenu;
851 UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
852
853 processed = HandleMenuSelect(item, flags, hmenu);
854 }
855 break;
856
857 case WM_EXITMENULOOP:
858 processed = HandleMenuLoop(wxEVT_MENU_CLOSE, wParam);
859 break;
860
861 case WM_QUERYDRAGICON:
862 {
863 const wxIcon& icon = GetIcon();
864 HICON hIcon = icon.Ok() ? GetHiconOf(icon)
865 : (HICON)GetDefaultIcon();
866 rc = (long)hIcon;
867 processed = rc != 0;
868 }
869 break;
870 #endif // !__WXMICROWIN__
871 }
872
873 if ( !processed )
874 rc = wxFrameBase::MSWWindowProc(message, wParam, lParam);
875
876 return rc;
877 }
878
879 // handle WM_INITMENUPOPUP message
880 bool wxFrame::HandleInitMenuPopup(WXHMENU hMenu)
881 {
882 wxMenu* menu = NULL;
883 if (GetMenuBar())
884 {
885 int nCount = GetMenuBar()->GetMenuCount();
886 for (int n = 0; n < nCount; n++)
887 {
888 if (GetMenuBar()->GetMenu(n)->GetHMenu() == hMenu)
889 {
890 menu = GetMenuBar()->GetMenu(n);
891 break;
892 }
893 }
894 }
895
896 wxMenuEvent event(wxEVT_MENU_OPEN, 0, menu);
897 event.SetEventObject(this);
898
899 return GetEventHandler()->ProcessEvent(event);
900 }