]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/menu.cpp
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
= -2;
53 // The unique ID for Menus
56 USHORT
wxMenu::m_nextMenuId
= 0;
58 static USHORT
wxMenu::m_nextMenuId
= 0;
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 IMPLEMENT_DYNAMIC_CLASS(wxMenu
, wxEvtHandler
)
66 IMPLEMENT_DYNAMIC_CLASS(wxMenuBar
, wxEvtHandler
)
68 // ----------------------------------------------------------------------------
69 // static function for translating menu labels
70 // ----------------------------------------------------------------------------
72 static wxString
TextToLabel(
73 const wxString
& rsTitle
79 if (rsTitle
.IsEmpty())
81 for (zPc
= rsTitle
.c_str(); *zPc
!= wxT('\0'); zPc
++ )
83 if (*zPc
== wxT('&') )
85 if (*(zPc
+ 1) == wxT('&'))
95 if ( *zPc
== wxT('~') )
98 // Tildes must be doubled to prevent them from being
99 // interpreted as accelerator character prefix by PM ???
107 } // end of TextToLabel
109 // ============================================================================
111 // ============================================================================
113 // ---------------------------------------------------------------------------
114 // wxMenu construction, adding and removing menu items
115 // ---------------------------------------------------------------------------
118 // Construct a menu with optional title (then use append)
123 m_nStartRadioGroup
= -1;
126 // Create the menu (to be used as a submenu or a popup)
128 if ((m_hMenu
= ::WinCreateWindow( HWND_DESKTOP
143 wxLogLastError("WinLoadMenu");
145 m_vMenuData
.iPosition
= 0;
146 m_vMenuData
.afStyle
= MIS_SUBMENU
| MIS_TEXT
;
147 m_vMenuData
.afAttribute
= (USHORT
)0;
148 m_vMenuData
.id
= m_nextMenuId
++;
149 m_vMenuData
.hwndSubMenu
= m_hMenu
;
150 m_vMenuData
.hItem
= NULLHANDLE
;
153 // If we have a title, insert it in the beginning of the menu
155 if (!m_title
.IsEmpty())
164 } // end of wxMenu::Init
167 // The wxWindow destructor will take care of deleting the submenus.
172 // We should free PM resources only if PM doesn't do it for us
173 // which happens if we're attached to a menubar or a submenu of another
175 if (!IsAttached() && !GetParent())
177 if (!::WinDestroyWindow((HWND
)GetHmenu()) )
179 wxLogLastError("WinDestroyWindow");
187 WX_CLEAR_ARRAY(m_vAccels
);
188 #endif // wxUSE_ACCEL
189 } // end of wxMenu::~wxMenu
193 // this will take effect during the next call to Append()
195 } // end of wxMenu::Break
198 wxMenuBarBase
* pMenubar
201 wxMenuBase::Attach(pMenubar
);
203 } // end of wxMenu::Break;
207 int wxMenu::FindAccel(
212 size_t nCount
= m_vAccels
.GetCount();
214 for (n
= 0; n
< nCount
; n
++)
215 if (m_vAccels
[n
]->m_command
== nId
)
218 } // end of wxMenu::FindAccel
220 void wxMenu::UpdateAccel(
224 if (pItem
->IsSubMenu())
226 wxMenu
* pSubmenu
= pItem
->GetSubMenu();
227 wxMenuItemList::Node
* pNode
= pSubmenu
->GetMenuItems().GetFirst();
231 UpdateAccel(pNode
->GetData());
232 pNode
= pNode
->GetNext();
235 else if (!pItem
->IsSeparator())
238 // Find the (new) accel for this item
240 wxAcceleratorEntry
* pAccel
= wxGetAccelFromString(pItem
->GetText());
243 pAccel
->m_command
= pItem
->GetId();
248 size_t n
= FindAccel(pItem
->GetId());
250 if (n
== wxNOT_FOUND
)
253 // No old, add new if any
256 m_vAccels
.Add(pAccel
);
263 // Replace old with new or just remove the old one if no new
267 m_vAccels
[n
] = pAccel
;
269 m_vAccels
.RemoveAt(n
);
274 m_menuBar
->RebuildAccelTable();
277 } // wxMenu::UpdateAccel
279 #endif // wxUSE_ACCEL
282 // Append a new item or submenu to the menu
284 bool wxMenu::DoInsertOrAppend(
289 wxMenu
* pSubmenu
= pItem
->GetSubMenu();
290 MENUITEM
& rItem
= (pSubmenu
!= NULL
)?pSubmenu
->m_vMenuData
:
299 #endif // wxUSE_ACCEL
302 // If "Break" has just been called, insert a menu break before this item
303 // (and don't forget to reset the flag)
307 rItem
.afStyle
|= MIS_BREAK
;
311 if (pItem
->IsSeparator())
313 rItem
.afStyle
|= MIS_SEPARATOR
;
317 // Id is the numeric id for normal menu items and HMENU for submenus as
318 // required by ::MM_INSERTITEM message API
321 if (pSubmenu
!= NULL
)
323 wxASSERT_MSG(pSubmenu
->GetHMenu(), wxT("invalid submenu"));
324 pSubmenu
->SetParent(this);
326 rItem
.iPosition
= 0; // submenus have a 0 position
327 rItem
.id
= (USHORT
)pSubmenu
->GetHMenu();
328 rItem
.afStyle
|= MIS_SUBMENU
| MIS_TEXT
;
332 rItem
.id
= pItem
->GetId();
337 #if wxUSE_OWNER_DRAWN
338 if (pItem
->IsOwnerDrawn())
341 // Want to get {Measure|Draw}Item messages?
342 // item draws itself, passing pointer to data doesn't work in OS/2
343 // Will eventually need to set the image handle somewhere into vItem.hItem
345 rItem
.afStyle
|= MIS_OWNERDRAW
;
347 rItem
.hItem
= (HBITMAP
)pItem
->GetBitmap().GetHBITMAP();
348 pItem
->m_vMenuData
.afStyle
= rItem
.afStyle
;
349 pItem
->m_vMenuData
.hItem
= rItem
.hItem
;
355 // Menu is just a normal string (passed in data parameter)
357 rItem
.afStyle
|= MIS_TEXT
;
358 pData
= (char*)pItem
->GetText().c_str();
361 if (nPos
== (size_t)-1)
363 rItem
.iPosition
= MIT_END
;
367 rItem
.iPosition
= nPos
;
372 rc
= (APIRET
)::WinSendMsg( GetHmenu()
377 #if wxUSE_OWNER_DRAWN
378 if (pItem
->IsOwnerDrawn())
383 ::WinSendMsg( GetHmenu()
385 ,MPFROM2SHORT( (USHORT
)pItem
->GetId()
392 if (rc
== MIT_MEMERROR
|| rc
== MIT_ERROR
)
394 vError
= ::WinGetLastError(vHabmain
);
395 sError
= wxPMErrorToStr(vError
);
396 wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError
);
397 wxLogLastError("Insert or AppendMenu");
403 // If we're already attached to the menubar, we must update it
405 if (IsAttached() && m_menuBar
->IsAttached())
407 m_menuBar
->Refresh();
412 } // end of wxMenu::DoInsertOrAppend
414 void wxMenu::EndRadioGroup()
417 // We're not inside a radio group any longer
419 m_nStartRadioGroup
= -1;
420 } // end of wxMenu::EndRadioGroup
422 bool wxMenu::DoAppend(
426 wxCHECK_MSG( pItem
, FALSE
, _T("NULL item in wxMenu::DoAppend") );
430 if (pItem
->GetKind() == wxITEM_RADIO
)
432 int nCount
= GetMenuItemCount();
434 if (m_nStartRadioGroup
== -1)
437 // Start a new radio group
439 m_nStartRadioGroup
= nCount
;
442 // For now it has just one element
444 pItem
->SetAsRadioGroupStart();
445 pItem
->SetRadioGroupEnd(m_nStartRadioGroup
);
448 // Ensure that we have a checked item in the radio group
452 else // extend the current radio group
455 // We need to update its end item
457 pItem
->SetRadioGroupStart(m_nStartRadioGroup
);
459 wxMenuItemList::Node
* pNode
= GetMenuItems().Item(m_nStartRadioGroup
);
463 pNode
->GetData()->SetRadioGroupEnd(nCount
);
467 wxFAIL_MSG( _T("where is the radio group start item?") );
471 else // not a radio item
476 if (!wxMenuBase::DoAppend(pItem
) || !DoInsertOrAppend(pItem
))
483 // Check the item initially
488 } // end of wxMenu::DoAppend
490 bool wxMenu::DoInsert(
495 return ( wxMenuBase::DoInsert( nPos
497 DoInsertOrAppend( pItem
501 } // end of wxMenu::DoInsert
503 wxMenuItem
* wxMenu::DoRemove(
508 // We need to find the items position in the child list
511 wxMenuItemList::Node
* pNode
= GetMenuItems().GetFirst();
513 for (nPos
= 0; pNode
; nPos
++)
515 if (pNode
->GetData() == pItem
)
517 pNode
= pNode
->GetNext();
521 // DoRemove() (unlike Remove) can only be called for existing item!
523 wxCHECK_MSG(pNode
, NULL
, wxT("bug in wxMenu::Remove logic"));
527 // Remove the corresponding accel from the accel table
529 int n
= FindAccel(pItem
->GetId());
531 if (n
!= wxNOT_FOUND
)
534 m_vAccels
.RemoveAt(n
);
537 #endif // wxUSE_ACCEL
539 // Remove the item from the menu
541 ::WinSendMsg( GetHmenu()
543 ,MPFROM2SHORT(pItem
->GetId(), TRUE
)
546 if (IsAttached() && m_menuBar
->IsAttached())
549 // Otherwise, the chane won't be visible
551 m_menuBar
->Refresh();
555 // And from internal data structures
557 return wxMenuBase::DoRemove(pItem
);
558 } // end of wxMenu::DoRemove
560 // ---------------------------------------------------------------------------
561 // accelerator helpers
562 // ---------------------------------------------------------------------------
567 // Create the wxAcceleratorEntries for our accels and put them into provided
568 // array - return the number of accels we have
570 size_t wxMenu::CopyAccels(
571 wxAcceleratorEntry
* pAccels
574 size_t nCount
= GetAccelCount();
576 for (size_t n
= 0; n
< nCount
; n
++)
578 *pAccels
++ = *m_vAccels
[n
];
581 } // end of wxMenu::CopyAccels
583 #endif // wxUSE_ACCEL
585 // ---------------------------------------------------------------------------
587 // ---------------------------------------------------------------------------
589 void wxMenu::SetTitle(
590 const wxString
& rLabel
593 bool bHasNoTitle
= m_title
.IsEmpty();
594 HWND hMenu
= GetHmenu();
599 if (!rLabel
.IsEmpty())
601 if (!::WinSetWindowText(hMenu
, rLabel
.c_str()))
603 wxLogLastError("SetMenuTitle");
609 if (rLabel
.IsEmpty() )
611 ::WinSendMsg( GetHmenu()
613 ,MPFROM2SHORT(hMenu
, TRUE
)
622 if (!::WinSetWindowText(hMenu
, rLabel
.c_str()))
624 wxLogLastError("SetMenuTitle");
628 } // end of wxMenu::SetTitle
630 // ---------------------------------------------------------------------------
632 // ---------------------------------------------------------------------------
634 bool wxMenu::OS2Command(
635 WXUINT
WXUNUSED(uParam
)
640 // Ignore commands from the menu title
643 if (vId
!= (WXWORD
)idMenuTitle
)
646 ,(int)::WinSendMsg( GetHmenu()
654 } // end of wxMenu::OS2Command
656 // ---------------------------------------------------------------------------
658 // ---------------------------------------------------------------------------
660 wxWindow
* wxMenu::GetWindow() const
662 if (m_invokingWindow
!= NULL
)
663 return m_invokingWindow
;
664 else if ( m_menuBar
!= NULL
)
665 return m_menuBar
->GetFrame();
668 } // end of wxMenu::GetWindow
670 // recursive search for item by id
671 wxMenuItem
* wxMenu::FindItem(
674 , wxMenu
** ppItemMenu
680 wxMenuItem
* pItem
= NULL
;
682 for ( wxMenuItemList::Node
*node
= m_items
.GetFirst();
684 node
= node
->GetNext() )
686 pItem
= node
->GetData();
688 if ( pItem
->GetId() == nItemId
&& pItem
->m_vMenuData
.hItem
== hItem
)
691 *ppItemMenu
= (wxMenu
*)this;
693 else if ( pItem
->IsSubMenu() )
695 pItem
= pItem
->GetSubMenu()->FindItem( nItemId
704 // don't exit the loop
709 } // end of wxMenu::FindItem
711 // ---------------------------------------------------------------------------
713 // ---------------------------------------------------------------------------
715 void wxMenuBar::Init()
717 m_eventHandler
= this;
718 m_menuBarFrame
= NULL
;
720 } // end of wxMenuBar::Init
722 wxMenuBar::wxMenuBar()
725 } // end of wxMenuBar::wxMenuBar
727 wxMenuBar::wxMenuBar(
728 long WXUNUSED(lStyle
)
732 } // end of wxMenuBar::wxMenuBar
734 wxMenuBar::wxMenuBar(
737 , const wxString sTitles
[]
742 m_titles
.Alloc(nCount
);
743 for ( int i
= 0; i
< nCount
; i
++ )
745 m_menus
.Append(vMenus
[i
]);
746 m_titles
.Add(sTitles
[i
]);
747 vMenus
[i
]->Attach(this);
749 } // end of wxMenuBar::wxMenuBar
751 wxMenuBar::~wxMenuBar()
753 } // end of wxMenuBar::~wxMenuBar
755 // ---------------------------------------------------------------------------
757 // ---------------------------------------------------------------------------
759 void wxMenuBar::Refresh()
761 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
763 WinSendMsg(GetWinHwnd(m_menuBarFrame
), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
764 } // end of wxMenuBar::Refresh
766 WXHMENU
wxMenuBar::Create()
774 wxCHECK_MSG(!m_hMenu
, TRUE
, wxT("menubar already created"));
777 // Menubars should be associated with a frame otherwise they are popups
779 if (m_menuBarFrame
!= NULL
)
780 hFrame
= GetWinHwnd(m_menuBarFrame
);
782 hFrame
= HWND_DESKTOP
;
784 // Create an empty menu and then fill it with insertions
786 if ((m_hMenu
= ::WinCreateWindow( hFrame
789 ,MS_ACTIONBAR
| WS_SYNCPAINT
| WS_VISIBLE
801 wxLogLastError("WinLoadMenu");
805 size_t nCount
= GetMenuCount();
807 for (size_t i
= 0; i
< nCount
; i
++)
815 // Set the parent and owner of the submenues to be the menubar, not the desktop
817 hSubMenu
= m_menus
[i
]->m_vMenuData
.hwndSubMenu
;
818 if (!::WinSetParent(m_menus
[i
]->m_vMenuData
.hwndSubMenu
, m_hMenu
, FALSE
))
820 vError
= ::WinGetLastError(vHabmain
);
821 sError
= wxPMErrorToStr(vError
);
822 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
826 if (!::WinSetOwner(m_menus
[i
]->m_vMenuData
.hwndSubMenu
, m_hMenu
))
828 vError
= ::WinGetLastError(vHabmain
);
829 sError
= wxPMErrorToStr(vError
);
830 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
834 m_menus
[i
]->m_vMenuData
.iPosition
= i
;
836 rc
= (APIRET
)::WinSendMsg(m_hMenu
, MM_INSERTITEM
, (MPARAM
)&m_menus
[i
]->m_vMenuData
, (MPARAM
)m_titles
[i
].c_str());
837 if (rc
== MIT_MEMERROR
|| rc
== MIT_ERROR
)
839 vError
= ::WinGetLastError(vHabmain
);
840 sError
= wxPMErrorToStr(vError
);
841 wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError
);
847 } // end of wxMenuBar::Create
849 // ---------------------------------------------------------------------------
850 // wxMenuBar functions to work with the top level submenus
851 // ---------------------------------------------------------------------------
854 // NB: we don't support owner drawn top level items for now, if we do these
855 // functions would have to be changed to use wxMenuItem as well
857 void wxMenuBar::EnableTop(
862 wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars"));
867 uFlag
= MIA_DISABLED
;
869 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
870 if (nId
== MIT_ERROR
)
872 wxLogLastError("LogLastError");
875 ::WinSendMsg((HWND
)m_hMenu
, MM_SETITEMATTR
, MPFROM2SHORT(nId
, TRUE
), MPFROM2SHORT(MIA_DISABLED
, uFlag
));
877 } // end of wxMenuBar::EnableTop
879 void wxMenuBar::SetLabelTop(
881 , const wxString
& rLabel
887 wxCHECK_RET(nPos
< GetMenuCount(), wxT("invalid menu index"));
888 m_titles
[nPos
] = rLabel
;
895 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
896 if (nId
== MIT_ERROR
)
898 wxLogLastError("LogLastError");
901 if(!::WinSendMsg( (HWND
)m_hMenu
903 ,MPFROM2SHORT(nId
, TRUE
)
907 wxLogLastError("QueryItem");
911 if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT
, MPFROMSHORT(nId
), (MPARAM
)rLabel
.c_str()));
913 wxLogLastError("ModifyMenu");
916 } // end of wxMenuBar::SetLabelTop
918 wxString
wxMenuBar::GetLabelTop(
922 wxCHECK_MSG( nPos
< GetMenuCount(), wxEmptyString
,
923 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
924 return m_titles
[nPos
];
925 } // end of wxMenuBar::GetLabelTop
927 // ---------------------------------------------------------------------------
928 // wxMenuBar construction
929 // ---------------------------------------------------------------------------
931 wxMenu
* wxMenuBar::Replace(
934 , const wxString
& rTitle
938 wxString sTitle
= TextToLabel(rTitle
);
939 wxMenu
* pMenuOld
= wxMenuBarBase::Replace( nPos
945 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
946 if (nId
== MIT_ERROR
)
948 wxLogLastError("LogLastError");
953 m_titles
[nPos
] = sTitle
;
956 ::WinSendMsg((HWND
)m_hMenu
, MM_REMOVEITEM
, MPFROM2SHORT(nId
, TRUE
), (MPARAM
)0);
957 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)sTitle
.c_str());
960 if (pMenuOld
->HasAccels() || pMenu
->HasAccels())
963 // Need to rebuild accell table
967 #endif // wxUSE_ACCEL
971 } // end of wxMenuBar::Replace
973 bool wxMenuBar::Insert(
976 , const wxString
& rTitle
979 wxString sTitle
= TextToLabel(rTitle
);
981 if (!wxMenuBarBase::Insert( nPos
987 m_titles
.Insert( sTitle
993 pMenu
->m_vMenuData
.iPosition
= nPos
;
994 ::WinSendMsg( (HWND
)m_hMenu
996 ,(MPARAM
)&pMenu
->m_vMenuData
997 ,(MPARAM
)sTitle
.c_str()
1000 if (pMenu
->HasAccels())
1002 // need to rebuild accell table
1003 RebuildAccelTable();
1005 #endif // wxUSE_ACCEL
1009 } // end of wxMenuBar::Insert
1011 bool wxMenuBar::Append(
1013 , const wxString
& rsTitle
1016 WXHMENU hSubmenu
= pMenu
? pMenu
->GetHMenu() : 0;
1018 wxCHECK_MSG(hSubmenu
, FALSE
, wxT("can't append invalid menu to menubar"));
1020 wxString sTitle
= TextToLabel(rsTitle
);
1022 if (!wxMenuBarBase::Append(pMenu
, sTitle
))
1025 m_titles
.Add(sTitle
);
1029 pMenu
->m_vMenuData
.iPosition
= MIT_END
;
1030 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)sTitle
.c_str());
1032 if (pMenu
->HasAccels())
1035 // Need to rebuild accell table
1037 RebuildAccelTable();
1039 #endif // wxUSE_ACCEL
1043 } // end of wxMenuBar::Append
1045 wxMenu
* wxMenuBar::Remove(
1049 wxMenu
* pMenu
= wxMenuBarBase::Remove(nPos
);
1055 nId
= SHORT1FROMMR(::WinSendMsg( (HWND
)GetHmenu()
1056 ,MM_ITEMIDFROMPOSITION
1060 if (nId
== MIT_ERROR
)
1062 wxLogLastError("LogLastError");
1067 ::WinSendMsg( (HWND
)GetHmenu()
1069 ,MPFROM2SHORT(nId
, TRUE
)
1074 if (pMenu
->HasAccels())
1077 // Need to rebuild accell table
1079 RebuildAccelTable();
1081 #endif // wxUSE_ACCEL
1084 m_titles
.Remove(nPos
);
1086 } // end of wxMenuBar::Remove
1090 void wxMenuBar::RebuildAccelTable()
1093 // Merge the accelerators of all menus into one accel table
1095 size_t nAccelCount
= 0;
1097 size_t nCount
= GetMenuCount();
1099 for (i
= 0; i
< nCount
; i
++)
1101 nAccelCount
+= m_menus
[i
]->GetAccelCount();
1106 wxAcceleratorEntry
* pAccelEntries
= new wxAcceleratorEntry
[nAccelCount
];
1109 for (i
= 0; i
< nCount
; i
++)
1111 nAccelCount
+= m_menus
[i
]->CopyAccels(&pAccelEntries
[nAccelCount
]);
1113 m_vAccelTable
= wxAcceleratorTable( nAccelCount
1116 delete [] pAccelEntries
;
1118 } // end of wxMenuBar::RebuildAccelTable
1120 #endif // wxUSE_ACCEL
1122 void wxMenuBar::Attach(
1126 wxMenuBarBase::Attach(pFrame
);
1129 RebuildAccelTable();
1131 // Ensure the accelerator table is set to the frame (not the client!)
1133 if (!::WinSetAccelTable( vHabmain
1134 ,m_vAccelTable
.GetHACCEL()
1135 ,(HWND
)pFrame
->GetFrame()
1137 wxLogLastError("WinSetAccelTable");
1138 #endif // wxUSE_ACCEL
1139 } // end of wxMenuBar::Attach
1141 void wxMenuBar::Detach()
1143 ::WinDestroyWindow((HWND
)m_hMenu
);
1144 m_hMenu
= (WXHMENU
)NULL
;
1145 m_menuBarFrame
= NULL
;
1146 } // end of wxMenuBar::Detach
1148 // ---------------------------------------------------------------------------
1149 // wxMenuBar searching for menu items
1150 // ---------------------------------------------------------------------------
1153 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1155 int wxMenuBar::FindMenuItem(
1156 const wxString
& rMenuString
1157 , const wxString
& rItemString
1160 wxString sMenuLabel
= wxStripMenuCodes(rMenuString
);
1161 size_t nCount
= GetMenuCount();
1163 for (size_t i
= 0; i
< nCount
; i
++)
1165 wxString sTitle
= wxStripMenuCodes(m_titles
[i
]);
1167 if (rMenuString
== sTitle
)
1168 return m_menus
[i
]->FindItem(rItemString
);
1171 } // end of wxMenuBar::FindMenuItem
1173 wxMenuItem
* wxMenuBar::FindItem(
1175 , wxMenu
** ppItemMenu
1181 wxMenuItem
* pItem
= NULL
;
1182 size_t nCount
= GetMenuCount();
1184 for (size_t i
= 0; !pItem
&& (i
< nCount
); i
++)
1186 pItem
= m_menus
[i
]->FindItem( nId
1191 } // end of wxMenuBar::FindItem
1193 wxMenuItem
* wxMenuBar::FindItem(
1196 , wxMenu
** ppItemMenu
1202 wxMenuItem
* pItem
= NULL
;
1203 size_t nCount
= GetMenuCount();
1205 for (size_t i
= 0; !pItem
&& (i
< nCount
); i
++)
1207 pItem
= m_menus
[i
]->FindItem( nId
1213 } // end of wxMenuBar::FindItem