1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMenu, wxMenuBar, wxMenuItem
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "menu.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #include "wx/ownerdrw.h"
32 #include "wx/os2/private.h"
34 // other standard headers
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 extern wxMenu
* wxCurrentPopupMenu
;
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
48 // The (popup) menu title has this special id
50 static const int idMenuTitle
= -3;
53 // The unique ID for Menus
55 USHORT
wxMenu::m_nextMenuId
= 0;
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
62 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
64 // ============================================================================
66 // ============================================================================
68 // ---------------------------------------------------------------------------
69 // wxMenu construction, adding and removing menu items
70 // ---------------------------------------------------------------------------
73 // Construct a menu with optional title (then use append)
78 m_nStartRadioGroup
= -1;
81 // Create the menu (to be used as a submenu or a popup)
83 if ((m_hMenu
= ::WinCreateWindow( HWND_DESKTOP
98 wxLogLastError(wxT("WinLoadMenu"));
100 m_vMenuData
.iPosition
= 0;
101 m_vMenuData
.afStyle
= MIS_SUBMENU
| MIS_TEXT
;
102 m_vMenuData
.afAttribute
= (USHORT
)0;
103 m_vMenuData
.id
= m_nextMenuId
++;
104 m_vMenuData
.hwndSubMenu
= m_hMenu
;
105 m_vMenuData
.hItem
= NULLHANDLE
;
108 // If we have a title, insert it in the beginning of the menu
110 if (!m_title
.empty())
119 } // end of wxMenu::Init
122 // The wxWindow destructor will take care of deleting the submenus.
127 // We should free PM resources only if PM doesn't do it for us
128 // which happens if we're attached to a menubar or a submenu of another
130 if (!IsAttached() && !GetParent())
132 if (!::WinDestroyWindow((HWND
)GetHmenu()) )
134 wxLogLastError(wxT("WinDestroyWindow"));
142 WX_CLEAR_ARRAY(m_vAccels
);
143 #endif // wxUSE_ACCEL
144 } // end of wxMenu::~wxMenu
148 // this will take effect during the next call to Append()
150 } // end of wxMenu::Break
153 wxMenuBarBase
* pMenubar
156 wxMenuBase::Attach(pMenubar
);
158 } // end of wxMenu::Break;
162 int wxMenu::FindAccel(
167 size_t nCount
= m_vAccels
.GetCount();
169 for (n
= 0; n
< nCount
; n
++)
170 if (m_vAccels
[n
]->m_command
== nId
)
173 } // end of wxMenu::FindAccel
175 void wxMenu::UpdateAccel(
179 if (pItem
->IsSubMenu())
181 wxMenu
* pSubmenu
= pItem
->GetSubMenu();
182 wxMenuItemList::compatibility_iterator node
= pSubmenu
->GetMenuItems().GetFirst();
186 UpdateAccel(node
->GetData());
187 node
= node
->GetNext();
190 else if (!pItem
->IsSeparator())
193 // Recurse upwards: we should only modify m_accels of the top level
194 // menus, not of the submenus as wxMenuBar doesn't look at them
195 // (alternative and arguable cleaner solution would be to recurse
196 // downwards in GetAccelCount() and CopyAccels())
200 GetParent()->UpdateAccel(pItem
);
205 // Find the (new) accel for this item
207 wxAcceleratorEntry
* pAccel
= wxGetAccelFromString(pItem
->GetText());
210 pAccel
->m_command
= pItem
->GetId();
215 size_t n
= FindAccel(pItem
->GetId());
217 if (n
== (size_t)wxNOT_FOUND
)
220 // No old, add new if any
223 m_vAccels
.Add(pAccel
);
230 // Replace old with new or just remove the old one if no new
234 m_vAccels
[n
] = pAccel
;
236 m_vAccels
.RemoveAt(n
);
241 GetMenuBar()->RebuildAccelTable();
244 } // wxMenu::UpdateAccel
246 #endif // wxUSE_ACCEL
249 // Append a new item or submenu to the menu
251 bool wxMenu::DoInsertOrAppend( wxMenuItem
* pItem
,
254 wxMenu
* pSubmenu
= pItem
->GetSubMenu();
255 MENUITEM
& rItem
= (pSubmenu
!= NULL
)?pSubmenu
->m_vMenuData
:
263 #endif // wxUSE_ACCEL
266 // If "Break" has just been called, insert a menu break before this item
267 // (and don't forget to reset the flag)
271 rItem
.afStyle
|= MIS_BREAK
;
276 // Id is the numeric id for normal menu items and HMENU for submenus as
277 // required by ::MM_INSERTITEM message API
279 if (pSubmenu
!= NULL
)
281 wxASSERT_MSG(pSubmenu
->GetHMenu(), wxT("invalid submenu"));
282 pSubmenu
->SetParent(this);
284 rItem
.iPosition
= 0; // submenus have a 0 position
285 rItem
.id
= (USHORT
)pSubmenu
->GetHMenu();
286 rItem
.afStyle
|= MIS_SUBMENU
| MIS_TEXT
;
290 rItem
.id
= (USHORT
)pItem
->GetId();
295 #if wxUSE_OWNER_DRAWN
296 if (pItem
->IsOwnerDrawn())
299 // Want to get {Measure|Draw}Item messages?
300 // item draws itself, passing pointer to data doesn't work in OS/2
301 // Will eventually need to set the image handle somewhere into vItem.hItem
303 rItem
.afStyle
|= MIS_OWNERDRAW
;
305 rItem
.hItem
= (HBITMAP
)pItem
->GetBitmap().GetHBITMAP();
306 pItem
->m_vMenuData
.afStyle
= rItem
.afStyle
;
307 pItem
->m_vMenuData
.hItem
= rItem
.hItem
;
311 if (pItem
->IsSeparator())
313 rItem
.afStyle
= MIS_SEPARATOR
;
317 if (pItem
->GetId() == idMenuTitle
)
319 // Item is an unselectable title to be passed via pData
320 rItem
.afStyle
= MIS_STATIC
;
325 // Menu is just a normal string (passed in data parameter)
327 rItem
.afStyle
|= MIS_TEXT
;
329 pData
= (char*)pItem
->GetText().c_str();
332 if (nPos
== (size_t)-1)
334 rItem
.iPosition
= MIT_END
;
338 rItem
.iPosition
= (SHORT
)nPos
;
343 rc
= (APIRET
)::WinSendMsg( GetHmenu()
348 #if wxUSE_OWNER_DRAWN
349 if (pItem
->IsOwnerDrawn())
353 ::WinSendMsg( GetHmenu()
355 ,MPFROM2SHORT( (USHORT
)pItem
->GetId()
363 if (rc
== (APIRET
)MIT_MEMERROR
|| rc
== (APIRET
)MIT_ERROR
)
365 vError
= ::WinGetLastError(vHabmain
);
366 sError
= wxPMErrorToStr(vError
);
367 wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError
.c_str());
368 wxLogLastError(wxT("Insert or AppendMenu"));
373 // If we're already attached to the menubar, we must update it
375 if (IsAttached() && GetMenuBar()->IsAttached())
377 GetMenuBar()->Refresh();
381 } // end of wxMenu::DoInsertOrAppend
383 void wxMenu::EndRadioGroup()
386 // We're not inside a radio group any longer
388 m_nStartRadioGroup
= -1;
389 } // end of wxMenu::EndRadioGroup
391 wxMenuItem
* wxMenu::DoAppend( wxMenuItem
* pItem
)
393 wxCHECK_MSG( pItem
, NULL
, _T("NULL item in wxMenu::DoAppend") );
397 if (pItem
->GetKind() == wxITEM_RADIO
)
399 int nCount
= GetMenuItemCount();
401 if (m_nStartRadioGroup
== -1)
404 // Start a new radio group
406 m_nStartRadioGroup
= nCount
;
409 // For now it has just one element
411 pItem
->SetAsRadioGroupStart();
412 pItem
->SetRadioGroupEnd(m_nStartRadioGroup
);
415 // Ensure that we have a checked item in the radio group
419 else // extend the current radio group
422 // We need to update its end item
424 pItem
->SetRadioGroupStart(m_nStartRadioGroup
);
426 wxMenuItemList::compatibility_iterator node
= GetMenuItems().Item(m_nStartRadioGroup
);
430 node
->GetData()->SetRadioGroupEnd(nCount
);
434 wxFAIL_MSG( _T("where is the radio group start item?") );
438 else // not a radio item
443 if (!wxMenuBase::DoAppend(pItem
) || !DoInsertOrAppend(pItem
))
450 // Check the item initially
455 } // end of wxMenu::DoAppend
457 wxMenuItem
* wxMenu::DoInsert(
462 if ( wxMenuBase::DoInsert( nPos
464 DoInsertOrAppend( pItem
470 } // end of wxMenu::DoInsert
472 wxMenuItem
* wxMenu::DoRemove(
477 // We need to find the items position in the child list
480 wxMenuItemList::compatibility_iterator node
= GetMenuItems().GetFirst();
482 for (nPos
= 0; node
; nPos
++)
484 if (node
->GetData() == pItem
)
486 node
= node
->GetNext();
490 // DoRemove() (unlike Remove) can only be called for existing item!
492 wxCHECK_MSG(node
, NULL
, wxT("bug in wxMenu::Remove logic"));
496 // Remove the corresponding accel from the accel table
498 int n
= FindAccel(pItem
->GetId());
500 if (n
!= wxNOT_FOUND
)
503 m_vAccels
.RemoveAt(n
);
506 #endif // wxUSE_ACCEL
508 // Remove the item from the menu
510 ::WinSendMsg( GetHmenu()
512 ,MPFROM2SHORT(pItem
->GetId(), TRUE
)
515 if (IsAttached() && GetMenuBar()->IsAttached())
518 // Otherwise, the chane won't be visible
520 GetMenuBar()->Refresh();
524 // And from internal data structures
526 return wxMenuBase::DoRemove(pItem
);
527 } // end of wxMenu::DoRemove
529 // ---------------------------------------------------------------------------
530 // accelerator helpers
531 // ---------------------------------------------------------------------------
536 // Create the wxAcceleratorEntries for our accels and put them into provided
537 // array - return the number of accels we have
539 size_t wxMenu::CopyAccels(
540 wxAcceleratorEntry
* pAccels
543 size_t nCount
= GetAccelCount();
545 for (size_t n
= 0; n
< nCount
; n
++)
547 *pAccels
++ = *m_vAccels
[n
];
550 } // end of wxMenu::CopyAccels
552 #endif // wxUSE_ACCEL
554 // ---------------------------------------------------------------------------
556 // ---------------------------------------------------------------------------
558 void wxMenu::SetTitle( const wxString
& rLabel
)
560 bool bHasNoTitle
= m_title
.empty();
561 HWND hMenu
= GetHmenu();
568 if (!::WinSetWindowText(hMenu
, (PSZ
)rLabel
.c_str()))
570 wxLogLastError(wxT("SetMenuTitle"));
578 ::WinSendMsg( GetHmenu()
580 ,MPFROM2SHORT(hMenu
, TRUE
)
589 if (!::WinSetWindowText(hMenu
, (PSZ
)rLabel
.c_str()))
591 wxLogLastError(wxT("SetMenuTitle"));
595 } // end of wxMenu::SetTitle
597 // ---------------------------------------------------------------------------
599 // ---------------------------------------------------------------------------
601 bool wxMenu::OS2Command(
602 WXUINT
WXUNUSED(uParam
)
607 // Ignore commands from the menu title
610 if (vId
!= (WXWORD
)idMenuTitle
)
613 ,(int)::WinSendMsg( GetHmenu()
621 } // end of wxMenu::OS2Command
623 // ---------------------------------------------------------------------------
625 // ---------------------------------------------------------------------------
627 wxWindow
* wxMenu::GetWindow() const
629 if (m_invokingWindow
!= NULL
)
630 return m_invokingWindow
;
631 else if ( GetMenuBar() != NULL
)
632 return GetMenuBar()->GetFrame();
635 } // end of wxMenu::GetWindow
637 // recursive search for item by id
638 wxMenuItem
* wxMenu::FindItem(
641 , wxMenu
** ppItemMenu
647 wxMenuItem
* pItem
= NULL
;
649 for ( wxMenuItemList::compatibility_iterator node
= m_items
.GetFirst();
651 node
= node
->GetNext() )
653 pItem
= node
->GetData();
655 if ( pItem
->GetId() == nItemId
&& pItem
->m_vMenuData
.hItem
== hItem
)
658 *ppItemMenu
= (wxMenu
*)this;
660 else if ( pItem
->IsSubMenu() )
662 pItem
= pItem
->GetSubMenu()->FindItem( nItemId
671 // don't exit the loop
676 } // end of wxMenu::FindItem
678 // ---------------------------------------------------------------------------
680 // ---------------------------------------------------------------------------
682 void wxMenuBar::Init()
684 m_eventHandler
= this;
685 m_menuBarFrame
= NULL
;
687 } // end of wxMenuBar::Init
689 wxMenuBar::wxMenuBar()
692 } // end of wxMenuBar::wxMenuBar
694 wxMenuBar::wxMenuBar(
695 long WXUNUSED(lStyle
)
699 } // end of wxMenuBar::wxMenuBar
701 wxMenuBar::wxMenuBar(
704 , const wxString sTitles
[]
705 , long WXUNUSED(lStyle
)
710 m_titles
.Alloc(nCount
);
711 for ( int i
= 0; i
< nCount
; i
++ )
713 m_menus
.Append(vMenus
[i
]);
714 m_titles
.Add(sTitles
[i
]);
715 vMenus
[i
]->Attach(this);
717 } // end of wxMenuBar::wxMenuBar
719 wxMenuBar::~wxMenuBar()
722 // We should free PM's resources only if PM doesn't do it for us
723 // which happens if we're attached to a frame
725 if (m_hMenu
&& !IsAttached())
727 ::WinDestroyWindow((HMENU
)m_hMenu
);
728 m_hMenu
= (WXHMENU
)NULL
;
730 } // end of wxMenuBar::~wxMenuBar
732 // ---------------------------------------------------------------------------
734 // ---------------------------------------------------------------------------
736 void wxMenuBar::Refresh()
738 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
740 WinSendMsg(GetWinHwnd(m_menuBarFrame
), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
741 } // end of wxMenuBar::Refresh
743 WXHMENU
wxMenuBar::Create()
750 wxCHECK_MSG(!m_hMenu
, TRUE
, wxT("menubar already created"));
753 // Menubars should be associated with a frame otherwise they are popups
755 if (m_menuBarFrame
!= NULL
)
756 hFrame
= GetWinHwnd(m_menuBarFrame
);
758 hFrame
= HWND_DESKTOP
;
760 // Create an empty menu and then fill it with insertions
762 if ((m_hMenu
= ::WinCreateWindow( hFrame
765 ,MS_ACTIONBAR
| WS_SYNCPAINT
| WS_VISIBLE
777 wxLogLastError(wxT("WinLoadMenu"));
781 size_t nCount
= GetMenuCount(), i
;
782 wxMenuList::iterator it
;
783 for (i
= 0, it
= m_menus
.begin(); i
< nCount
; i
++, it
++)
791 // Set the parent and owner of the submenues to be the menubar, not the desktop
793 hSubMenu
= (*it
)->m_vMenuData
.hwndSubMenu
;
794 if (!::WinSetParent((*it
)->m_vMenuData
.hwndSubMenu
, m_hMenu
, FALSE
))
796 vError
= ::WinGetLastError(vHabmain
);
797 sError
= wxPMErrorToStr(vError
);
798 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
802 if (!::WinSetOwner((*it
)->m_vMenuData
.hwndSubMenu
, m_hMenu
))
804 vError
= ::WinGetLastError(vHabmain
);
805 sError
= wxPMErrorToStr(vError
);
806 wxLogError(wxT("Error setting parent for submenu. Error: %s\n"), sError
.c_str());
810 (*it
)->m_vMenuData
.iPosition
= (SHORT
)i
;
812 rc
= (APIRET
)::WinSendMsg(m_hMenu
, MM_INSERTITEM
, (MPARAM
)&(*it
)->m_vMenuData
, (MPARAM
)m_titles
[i
].c_str());
813 if (rc
== (APIRET
)MIT_MEMERROR
|| rc
== (APIRET
)MIT_ERROR
)
815 vError
= ::WinGetLastError(vHabmain
);
816 sError
= wxPMErrorToStr(vError
);
817 wxLogError(wxT("Error inserting or appending a menuitem. Error: %s\n"), sError
.c_str());
823 } // end of wxMenuBar::Create
825 // ---------------------------------------------------------------------------
826 // wxMenuBar functions to work with the top level submenus
827 // ---------------------------------------------------------------------------
830 // NB: we don't support owner drawn top level items for now, if we do these
831 // functions would have to be changed to use wxMenuItem as well
833 void wxMenuBar::EnableTop(
838 wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars"));
843 uFlag
= MIA_DISABLED
;
845 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
846 if (nId
== MIT_ERROR
)
848 wxLogLastError(wxT("LogLastError"));
851 ::WinSendMsg((HWND
)m_hMenu
, MM_SETITEMATTR
, MPFROM2SHORT(nId
, TRUE
), MPFROM2SHORT(MIA_DISABLED
, uFlag
));
853 } // end of wxMenuBar::EnableTop
855 void wxMenuBar::SetLabelTop(
857 , const wxString
& rLabel
863 wxCHECK_RET(nPos
< GetMenuCount(), wxT("invalid menu index"));
864 m_titles
[nPos
] = rLabel
;
871 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
872 if (nId
== MIT_ERROR
)
874 wxLogLastError(wxT("LogLastError"));
877 if(!::WinSendMsg( (HWND
)m_hMenu
879 ,MPFROM2SHORT(nId
, TRUE
)
883 wxLogLastError(wxT("QueryItem"));
887 if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT
, MPFROMSHORT(nId
), (MPARAM
)rLabel
.c_str()));
889 wxLogLastError(wxT("ModifyMenu"));
892 } // end of wxMenuBar::SetLabelTop
894 wxString
wxMenuBar::GetLabelTop(
898 wxCHECK_MSG( nPos
< GetMenuCount(), wxEmptyString
,
899 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
900 return m_titles
[nPos
];
901 } // end of wxMenuBar::GetLabelTop
903 // ---------------------------------------------------------------------------
904 // wxMenuBar construction
905 // ---------------------------------------------------------------------------
907 wxMenu
* wxMenuBar::Replace(
910 , const wxString
& rTitle
914 wxString sTitle
= wxPMTextToLabel(rTitle
);
915 wxMenu
* pMenuOld
= wxMenuBarBase::Replace( nPos
921 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
922 if (nId
== MIT_ERROR
)
924 wxLogLastError(wxT("LogLastError"));
929 m_titles
[nPos
] = sTitle
;
932 ::WinSendMsg((HWND
)m_hMenu
, MM_REMOVEITEM
, MPFROM2SHORT(nId
, TRUE
), (MPARAM
)0);
933 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)sTitle
.c_str());
936 if (pMenuOld
->HasAccels() || pMenu
->HasAccels())
939 // Need to rebuild accell table
943 #endif // wxUSE_ACCEL
947 } // end of wxMenuBar::Replace
949 bool wxMenuBar::Insert( size_t nPos
,
951 const wxString
& rTitle
)
953 wxString sTitle
= wxPMTextToLabel(rTitle
);
955 if (!wxMenuBarBase::Insert( nPos
, pMenu
, sTitle
))
958 m_titles
.Insert( sTitle
, nPos
);
962 pMenu
->m_vMenuData
.iPosition
= (SHORT
)nPos
;
963 ::WinSendMsg( (HWND
)m_hMenu
965 ,(MPARAM
)&pMenu
->m_vMenuData
966 ,(MPARAM
)sTitle
.c_str()
969 if (pMenu
->HasAccels())
971 // need to rebuild accell table
974 #endif // wxUSE_ACCEL
979 } // end of wxMenuBar::Insert
981 bool wxMenuBar::Append(
983 , const wxString
& rsTitle
986 WXHMENU hSubmenu
= pMenu
? pMenu
->GetHMenu() : 0;
988 wxCHECK_MSG(hSubmenu
, FALSE
, wxT("can't append invalid menu to menubar"));
990 wxString sTitle
= wxPMTextToLabel(rsTitle
);
992 if (!wxMenuBarBase::Append(pMenu
, sTitle
))
995 m_titles
.Add(sTitle
);
999 pMenu
->m_vMenuData
.iPosition
= MIT_END
;
1000 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)sTitle
.c_str());
1002 if (pMenu
->HasAccels())
1005 // Need to rebuild accell table
1007 RebuildAccelTable();
1009 #endif // wxUSE_ACCEL
1013 } // end of wxMenuBar::Append
1015 wxMenu
* wxMenuBar::Remove(
1019 wxMenu
* pMenu
= wxMenuBarBase::Remove(nPos
);
1025 nId
= SHORT1FROMMR(::WinSendMsg( (HWND
)GetHmenu()
1026 ,MM_ITEMIDFROMPOSITION
1030 if (nId
== MIT_ERROR
)
1032 wxLogLastError(wxT("LogLastError"));
1037 ::WinSendMsg( (HWND
)GetHmenu()
1039 ,MPFROM2SHORT(nId
, TRUE
)
1044 if (pMenu
->HasAccels())
1047 // Need to rebuild accell table
1049 RebuildAccelTable();
1051 #endif // wxUSE_ACCEL
1054 m_titles
.RemoveAt(nPos
);
1056 } // end of wxMenuBar::Remove
1060 void wxMenuBar::RebuildAccelTable()
1063 // Merge the accelerators of all menus into one accel table
1065 size_t nAccelCount
= 0;
1067 size_t nCount
= GetMenuCount();
1068 wxMenuList::iterator it
;
1069 for (i
= 0, it
= m_menus
.begin(); i
< nCount
; i
++, it
++)
1071 nAccelCount
+= (*it
)->GetAccelCount();
1076 wxAcceleratorEntry
* pAccelEntries
= new wxAcceleratorEntry
[nAccelCount
];
1079 for (i
= 0, it
= m_menus
.begin(); i
< nCount
; i
++, it
++)
1081 nAccelCount
+= (*it
)->CopyAccels(&pAccelEntries
[nAccelCount
]);
1083 m_vAccelTable
= wxAcceleratorTable( nAccelCount
1086 delete [] pAccelEntries
;
1088 } // end of wxMenuBar::RebuildAccelTable
1090 #endif // wxUSE_ACCEL
1092 void wxMenuBar::Attach(
1096 wxMenuBarBase::Attach(pFrame
);
1099 RebuildAccelTable();
1101 // Ensure the accelerator table is set to the frame (not the client!)
1103 if (!::WinSetAccelTable( vHabmain
1104 ,m_vAccelTable
.GetHACCEL()
1105 ,(HWND
)pFrame
->GetFrame()
1107 wxLogLastError(wxT("WinSetAccelTable"));
1108 #endif // wxUSE_ACCEL
1109 } // end of wxMenuBar::Attach
1111 void wxMenuBar::Detach()
1113 ::WinDestroyWindow((HWND
)m_hMenu
);
1114 m_hMenu
= (WXHMENU
)NULL
;
1115 m_menuBarFrame
= NULL
;
1116 } // end of wxMenuBar::Detach
1118 // ---------------------------------------------------------------------------
1119 // wxMenuBar searching for menu items
1120 // ---------------------------------------------------------------------------
1123 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1125 int wxMenuBar::FindMenuItem(
1126 const wxString
& rMenuString
1127 , const wxString
& rItemString
1130 wxString sMenuLabel
= wxStripMenuCodes(rMenuString
);
1131 size_t nCount
= GetMenuCount(), i
;
1132 wxMenuList::const_iterator it
;
1133 for (i
= 0, it
= m_menus
.begin(); i
< nCount
; i
++, it
++)
1135 wxString sTitle
= wxStripMenuCodes(m_titles
[i
]);
1137 if (rMenuString
== sTitle
)
1138 return (*it
)->FindItem(rItemString
);
1141 } // end of wxMenuBar::FindMenuItem
1143 wxMenuItem
* wxMenuBar::FindItem(
1145 , wxMenu
** ppItemMenu
1151 wxMenuItem
* pItem
= NULL
;
1152 size_t nCount
= GetMenuCount(), i
;
1153 wxMenuList::const_iterator it
;
1154 for (i
= 0, it
= m_menus
.begin(); !pItem
&& (i
< nCount
); i
++, it
++)
1156 pItem
= (*it
)->FindItem( nId
1161 } // end of wxMenuBar::FindItem
1163 wxMenuItem
* wxMenuBar::FindItem(
1166 , wxMenu
** ppItemMenu
1172 wxMenuItem
* pItem
= NULL
;
1173 size_t nCount
= GetMenuCount(), i
;
1174 wxMenuList::const_iterator it
;
1175 for (i
= 0, it
= m_menus
.begin(); !pItem
&& (i
< nCount
); i
++, it
++)
1177 pItem
= (*it
)->FindItem( nId
1183 } // end of wxMenuBar::FindItem