]>
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
.c_str());
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()
754 // We should free PM's resources only if PM doesn't do it for us
755 // which happens if we're attached to a frame
757 if (m_hMenu
&& !IsAttached())
759 ::WinDestroyWindow((HMENU
)m_hMenu
);
760 m_hMenu
= (WXHMENU
)NULL
;
762 } // end of wxMenuBar::~wxMenuBar
764 // ---------------------------------------------------------------------------
766 // ---------------------------------------------------------------------------
768 void wxMenuBar::Refresh()
770 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
772 WinSendMsg(GetWinHwnd(m_menuBarFrame
), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
773 } // end of wxMenuBar::Refresh
775 WXHMENU
wxMenuBar::Create()
783 wxCHECK_MSG(!m_hMenu
, TRUE
, wxT("menubar already created"));
786 // Menubars should be associated with a frame otherwise they are popups
788 if (m_menuBarFrame
!= NULL
)
789 hFrame
= GetWinHwnd(m_menuBarFrame
);
791 hFrame
= HWND_DESKTOP
;
793 // Create an empty menu and then fill it with insertions
795 if ((m_hMenu
= ::WinCreateWindow( hFrame
798 ,MS_ACTIONBAR
| WS_SYNCPAINT
| WS_VISIBLE
810 wxLogLastError("WinLoadMenu");
814 size_t nCount
= GetMenuCount();
816 for (size_t i
= 0; i
< nCount
; i
++)
824 // Set the parent and owner of the submenues to be the menubar, not the desktop
826 hSubMenu
= m_menus
[i
]->m_vMenuData
.hwndSubMenu
;
827 if (!::WinSetParent(m_menus
[i
]->m_vMenuData
.hwndSubMenu
, m_hMenu
, FALSE
))
829 vError
= ::WinGetLastError(vHabmain
);
830 sError
= wxPMErrorToStr(vError
);
831 wxLogError("Error setting parent for submenu. Error: %s\n", sError
.c_str());
835 if (!::WinSetOwner(m_menus
[i
]->m_vMenuData
.hwndSubMenu
, m_hMenu
))
837 vError
= ::WinGetLastError(vHabmain
);
838 sError
= wxPMErrorToStr(vError
);
839 wxLogError("Error setting parent for submenu. Error: %s\n", sError
.c_str());
843 m_menus
[i
]->m_vMenuData
.iPosition
= i
;
845 rc
= (APIRET
)::WinSendMsg(m_hMenu
, MM_INSERTITEM
, (MPARAM
)&m_menus
[i
]->m_vMenuData
, (MPARAM
)m_titles
[i
].c_str());
846 if (rc
== MIT_MEMERROR
|| rc
== MIT_ERROR
)
848 vError
= ::WinGetLastError(vHabmain
);
849 sError
= wxPMErrorToStr(vError
);
850 wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError
.c_str());
856 } // end of wxMenuBar::Create
858 // ---------------------------------------------------------------------------
859 // wxMenuBar functions to work with the top level submenus
860 // ---------------------------------------------------------------------------
863 // NB: we don't support owner drawn top level items for now, if we do these
864 // functions would have to be changed to use wxMenuItem as well
866 void wxMenuBar::EnableTop(
871 wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars"));
876 uFlag
= MIA_DISABLED
;
878 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
879 if (nId
== MIT_ERROR
)
881 wxLogLastError("LogLastError");
884 ::WinSendMsg((HWND
)m_hMenu
, MM_SETITEMATTR
, MPFROM2SHORT(nId
, TRUE
), MPFROM2SHORT(MIA_DISABLED
, uFlag
));
886 } // end of wxMenuBar::EnableTop
888 void wxMenuBar::SetLabelTop(
890 , const wxString
& rLabel
896 wxCHECK_RET(nPos
< GetMenuCount(), wxT("invalid menu index"));
897 m_titles
[nPos
] = rLabel
;
904 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
905 if (nId
== MIT_ERROR
)
907 wxLogLastError("LogLastError");
910 if(!::WinSendMsg( (HWND
)m_hMenu
912 ,MPFROM2SHORT(nId
, TRUE
)
916 wxLogLastError("QueryItem");
920 if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT
, MPFROMSHORT(nId
), (MPARAM
)rLabel
.c_str()));
922 wxLogLastError("ModifyMenu");
925 } // end of wxMenuBar::SetLabelTop
927 wxString
wxMenuBar::GetLabelTop(
931 wxCHECK_MSG( nPos
< GetMenuCount(), wxEmptyString
,
932 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
933 return m_titles
[nPos
];
934 } // end of wxMenuBar::GetLabelTop
936 // ---------------------------------------------------------------------------
937 // wxMenuBar construction
938 // ---------------------------------------------------------------------------
940 wxMenu
* wxMenuBar::Replace(
943 , const wxString
& rTitle
947 wxString sTitle
= TextToLabel(rTitle
);
948 wxMenu
* pMenuOld
= wxMenuBarBase::Replace( nPos
954 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
955 if (nId
== MIT_ERROR
)
957 wxLogLastError("LogLastError");
962 m_titles
[nPos
] = sTitle
;
965 ::WinSendMsg((HWND
)m_hMenu
, MM_REMOVEITEM
, MPFROM2SHORT(nId
, TRUE
), (MPARAM
)0);
966 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)sTitle
.c_str());
969 if (pMenuOld
->HasAccels() || pMenu
->HasAccels())
972 // Need to rebuild accell table
976 #endif // wxUSE_ACCEL
980 } // end of wxMenuBar::Replace
982 bool wxMenuBar::Insert(
985 , const wxString
& rTitle
988 wxString sTitle
= TextToLabel(rTitle
);
990 if (!wxMenuBarBase::Insert( nPos
996 m_titles
.Insert( sTitle
1002 pMenu
->m_vMenuData
.iPosition
= nPos
;
1003 ::WinSendMsg( (HWND
)m_hMenu
1005 ,(MPARAM
)&pMenu
->m_vMenuData
1006 ,(MPARAM
)sTitle
.c_str()
1009 if (pMenu
->HasAccels())
1011 // need to rebuild accell table
1012 RebuildAccelTable();
1014 #endif // wxUSE_ACCEL
1018 } // end of wxMenuBar::Insert
1020 bool wxMenuBar::Append(
1022 , const wxString
& rsTitle
1025 WXHMENU hSubmenu
= pMenu
? pMenu
->GetHMenu() : 0;
1027 wxCHECK_MSG(hSubmenu
, FALSE
, wxT("can't append invalid menu to menubar"));
1029 wxString sTitle
= TextToLabel(rsTitle
);
1031 if (!wxMenuBarBase::Append(pMenu
, sTitle
))
1034 m_titles
.Add(sTitle
);
1038 pMenu
->m_vMenuData
.iPosition
= MIT_END
;
1039 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)sTitle
.c_str());
1041 if (pMenu
->HasAccels())
1044 // Need to rebuild accell table
1046 RebuildAccelTable();
1048 #endif // wxUSE_ACCEL
1052 } // end of wxMenuBar::Append
1054 wxMenu
* wxMenuBar::Remove(
1058 wxMenu
* pMenu
= wxMenuBarBase::Remove(nPos
);
1064 nId
= SHORT1FROMMR(::WinSendMsg( (HWND
)GetHmenu()
1065 ,MM_ITEMIDFROMPOSITION
1069 if (nId
== MIT_ERROR
)
1071 wxLogLastError("LogLastError");
1076 ::WinSendMsg( (HWND
)GetHmenu()
1078 ,MPFROM2SHORT(nId
, TRUE
)
1083 if (pMenu
->HasAccels())
1086 // Need to rebuild accell table
1088 RebuildAccelTable();
1090 #endif // wxUSE_ACCEL
1093 m_titles
.Remove(nPos
);
1095 } // end of wxMenuBar::Remove
1099 void wxMenuBar::RebuildAccelTable()
1102 // Merge the accelerators of all menus into one accel table
1104 size_t nAccelCount
= 0;
1106 size_t nCount
= GetMenuCount();
1108 for (i
= 0; i
< nCount
; i
++)
1110 nAccelCount
+= m_menus
[i
]->GetAccelCount();
1115 wxAcceleratorEntry
* pAccelEntries
= new wxAcceleratorEntry
[nAccelCount
];
1118 for (i
= 0; i
< nCount
; i
++)
1120 nAccelCount
+= m_menus
[i
]->CopyAccels(&pAccelEntries
[nAccelCount
]);
1122 m_vAccelTable
= wxAcceleratorTable( nAccelCount
1125 delete [] pAccelEntries
;
1127 } // end of wxMenuBar::RebuildAccelTable
1129 #endif // wxUSE_ACCEL
1131 void wxMenuBar::Attach(
1135 wxMenuBarBase::Attach(pFrame
);
1138 RebuildAccelTable();
1140 // Ensure the accelerator table is set to the frame (not the client!)
1142 if (!::WinSetAccelTable( vHabmain
1143 ,m_vAccelTable
.GetHACCEL()
1144 ,(HWND
)pFrame
->GetFrame()
1146 wxLogLastError("WinSetAccelTable");
1147 #endif // wxUSE_ACCEL
1148 } // end of wxMenuBar::Attach
1150 void wxMenuBar::Detach()
1152 ::WinDestroyWindow((HWND
)m_hMenu
);
1153 m_hMenu
= (WXHMENU
)NULL
;
1154 m_menuBarFrame
= NULL
;
1155 } // end of wxMenuBar::Detach
1157 // ---------------------------------------------------------------------------
1158 // wxMenuBar searching for menu items
1159 // ---------------------------------------------------------------------------
1162 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1164 int wxMenuBar::FindMenuItem(
1165 const wxString
& rMenuString
1166 , const wxString
& rItemString
1169 wxString sMenuLabel
= wxStripMenuCodes(rMenuString
);
1170 size_t nCount
= GetMenuCount();
1172 for (size_t i
= 0; i
< nCount
; i
++)
1174 wxString sTitle
= wxStripMenuCodes(m_titles
[i
]);
1176 if (rMenuString
== sTitle
)
1177 return m_menus
[i
]->FindItem(rItemString
);
1180 } // end of wxMenuBar::FindMenuItem
1182 wxMenuItem
* wxMenuBar::FindItem(
1184 , wxMenu
** ppItemMenu
1190 wxMenuItem
* pItem
= NULL
;
1191 size_t nCount
= GetMenuCount();
1193 for (size_t i
= 0; !pItem
&& (i
< nCount
); i
++)
1195 pItem
= m_menus
[i
]->FindItem( nId
1200 } // end of wxMenuBar::FindItem
1202 wxMenuItem
* wxMenuBar::FindItem(
1205 , wxMenu
** ppItemMenu
1211 wxMenuItem
* pItem
= NULL
;
1212 size_t nCount
= GetMenuCount();
1214 for (size_t i
= 0; !pItem
&& (i
< nCount
); i
++)
1216 pItem
= m_menus
[i
]->FindItem( nId
1222 } // end of wxMenuBar::FindItem