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