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