]>
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(const wxString
& rTitle
)
76 for (pc
= rTitle
.c_str(); *pc
!= wxT('\0'); pc
++ )
80 if (*(pc
+1) == wxT('&'))
90 if ( *pc
== wxT('~') )
92 // tildes must be doubled to prevent them from being
93 // interpreted as accelerator character prefix by PM ???
102 // ============================================================================
104 // ============================================================================
106 // ---------------------------------------------------------------------------
107 // wxMenu construction, adding and removing menu items
108 // ---------------------------------------------------------------------------
111 // Construct a menu with optional title (then use append)
118 // Create the menu (to be used as a submenu or a popup)
120 if ((m_hMenu
= ::WinCreateWindow( HWND_DESKTOP
135 wxLogLastError("WinLoadMenu");
137 m_vMenuData
.iPosition
= 0;
138 m_vMenuData
.afStyle
= MIS_SUBMENU
| MIS_TEXT
;
139 m_vMenuData
.afAttribute
= (USHORT
)0;
140 m_vMenuData
.id
= m_nextMenuId
++;
141 m_vMenuData
.hwndSubMenu
= m_hMenu
;
142 m_vMenuData
.hItem
= NULLHANDLE
;
145 // If we have a title, insert it in the beginning of the menu
147 if (!m_title
.IsEmpty())
154 for (int i
= 0; i
< 128; i
++)
157 } // end of wxMenu::Init
160 // The wxWindow destructor will take care of deleting the submenus.
165 // We should free PM resources only if PM doesn't do it for us
166 // which happens if we're attached to a menubar or a submenu of another
168 if (!IsAttached() && !GetParent())
170 if (!::WinDestroyWindow((HWND
)GetHmenu()) )
172 wxLogLastError("WinDestroyWindow");
180 #if (!(defined(__VISAGECPP__) && (__IBMCPP__ < 400 || __IBMC__ < 400 )))
181 for (int i
= 0; i
< 128; i
++)
189 // WX_CLEAR_ARRAY(m_vAccels);
191 #endif // wxUSE_ACCEL
192 } // end of wxMenu::~wxMenu
196 // this will take effect during the next call to Append()
198 } // end of wxMenu::Break
202 void wxMenu::EndRadioGroup()
205 // We're not inside a radio group any longer
207 m_nStartRadioGroup
= -1;
208 } // end of wxMenu::EndRadioGroup
210 int wxMenu::FindAccel(
215 // size_t nCount = m_vAccels.GetCount();
217 for (n
= 0; n
< m_nNextAccel
; n
++)
219 if (m_vAccels
[n
] != NULL
)
221 if (m_vAccels
[n
]->m_command
== nId
)
226 } // end of wxMenu::FindAccel
228 void wxMenu::UpdateAccel(
232 if (pItem
->IsSubMenu())
234 wxMenu
* pSubmenu
= pItem
->GetSubMenu();
235 wxMenuItemList::Node
* pNode
= pSubmenu
->GetMenuItems().GetFirst();
239 UpdateAccel(pNode
->GetData());
240 pNode
= pNode
->GetNext();
243 else if (!pItem
->IsSeparator())
246 // Find the (new) accel for this item
248 wxAcceleratorEntry
* pAccel
= wxGetAccelFromString(pItem
->GetText());
250 pAccel
->m_command
= pItem
->GetId();
255 size_t n
= FindAccel(pItem
->GetId());
257 if (n
== wxNOT_FOUND
)
260 // No old, add new if any
264 if (m_nNextAccel
< 128)
266 m_vAccels
[m_nNextAccel
] = pAccel
;
270 return; // skipping RebuildAccelTable() below
273 return; // skipping RebuildAccelTable() below
278 // Replace old with new or just remove the old one if no new
284 m_vAccels
[n
] = pAccel
;
289 m_menuBar
->RebuildAccelTable();
292 } // wxMenu::UpdateAccel
294 #endif // wxUSE_ACCEL
297 // Append a new item or submenu to the menu
299 bool wxMenu::DoInsertOrAppend(
304 wxMenu
* pSubmenu
= pItem
->GetSubMenu();
305 MENUITEM
& rItem
= (pSubmenu
!= NULL
)?pSubmenu
->m_vMenuData
:
313 #endif // wxUSE_ACCEL
316 // rItem is the member MENUITEM for the menu items and the submenu's
317 // MENUITEM for submenus as required by ::MM_INSERTITEM message API
322 wxASSERT_MSG(pSubmenu
->GetHMenu(), wxT("invalid submenu"));
323 pSubmenu
->SetParent(this);
324 rItem
.afStyle
|= MIS_SUBMENU
| MIS_TEXT
;
328 // If "Break" has just been called, insert a menu break before this item
329 // (and don't forget to reset the flag)
333 rItem
.afStyle
|= MIS_BREAK
;
337 if (pItem
->IsSeparator())
339 rItem
.afStyle
|= MIS_SEPARATOR
;
343 // Id is the numeric id for normal menu items and HMENU for submenus as
344 // required by ::MM_INSERTITEM message API
347 if (pSubmenu
!= NULL
)
349 wxASSERT_MSG(pSubmenu
->GetHMenu(), wxT("invalid submenu"));
350 pSubmenu
->SetParent(this);
352 rItem
.iPosition
= 0; // submenus have a 0 position
353 rItem
.id
= (USHORT
)pSubmenu
->GetHMenu();
354 rItem
.afStyle
|= MIS_SUBMENU
| MIS_TEXT
;
358 rItem
.id
= pItem
->GetId();
363 #if wxUSE_OWNER_DRAWN
364 if (pItem
->IsOwnerDrawn())
367 // Want to get {Measure|Draw}Item messages?
368 // item draws itself, passing pointer to data doesn't work in OS/2
369 // Will eventually need to set the image handle somewhere into vItem.hItem
371 rItem
.afStyle
|= MIS_OWNERDRAW
;
373 rItem
.hItem
= (HBITMAP
)pItem
->GetBitmap().GetHBITMAP();
374 pItem
->m_vMenuData
.afStyle
= rItem
.afStyle
;
375 pItem
->m_vMenuData
.hItem
= rItem
.hItem
;
381 // Menu is just a normal string (passed in data parameter)
383 rItem
.afStyle
|= MIS_TEXT
;
384 pData
= (char*)pItem
->GetText().c_str();
387 if (nPos
== (size_t)-1)
389 rItem
.iPosition
= MIT_END
;
393 rItem
.iPosition
= nPos
;
398 rc
= (APIRET
)::WinSendMsg( GetHmenu()
403 #if wxUSE_OWNER_DRAWN
404 if (pItem
->IsOwnerDrawn())
409 ::WinSendMsg( GetHmenu()
411 ,MPFROM2SHORT( (USHORT
)pItem
->GetId()
418 if (rc
== MIT_MEMERROR
|| rc
== MIT_ERROR
)
420 vError
= ::WinGetLastError(vHabmain
);
421 sError
= wxPMErrorToStr(vError
);
422 wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError
);
423 wxLogLastError("Insert or AppendMenu");
429 // If we're already attached to the menubar, we must update it
431 if (IsAttached() && m_menuBar
->IsAttached())
433 m_menuBar
->Refresh();
438 } // end of wxMenu::DoInsertOrAppend
440 bool wxMenu::DoAppend(
444 wxCHECK_MSG( pItem
, FALSE
, _T("NULL item in wxMenu::DoAppend") );
448 if (pItem
->GetKind() == wxITEM_RADIO
)
450 int nCount
= GetMenuItemCount();
452 if (m_nStartRadioGroup
== -1)
455 // Start a new radio group
457 m_nStartRadioGroup
= nCount
;
460 // For now it has just one element
462 pItem
->SetAsRadioGroupStart();
463 pItem
->SetRadioGroupEnd(m_nStartRadioGroup
);
466 // Ensure that we have a checked item in the radio group
470 else // extend the current radio group
473 // We need to update its end item
475 pItem
->SetRadioGroupStart(m_nStartRadioGroup
);
476 wxMenuItemList::Node
* pNode
= GetMenuItems().Item(m_nStartRadioGroup
);
480 pNode
->GetData()->SetRadioGroupEnd(nCount
);
484 wxFAIL_MSG( _T("where is the radio group start item?") );
488 else // not a radio item
492 if (!wxMenuBase::DoAppend(pItem
) || !DoInsertOrAppend(pItem
))
501 } // end of wxMenu::DoInsert
503 bool wxMenu::DoInsert(
508 return ( wxMenuBase::DoInsert( nPos
510 DoInsertOrAppend( pItem
513 } // end of wxMenu::DoInsert
515 wxMenuItem
* wxMenu::DoRemove(
520 // We need to find the items position in the child list
523 wxMenuItemList::Node
* pNode
= GetMenuItems().GetFirst();
525 for (nPos
= 0; pNode
; nPos
++)
527 if (pNode
->GetData() == pItem
)
529 pNode
= pNode
->GetNext();
533 // DoRemove() (unlike Remove) can only be called for existing item!
535 wxCHECK_MSG(pNode
, NULL
, wxT("bug in wxMenu::Remove logic"));
539 // Remove the corresponding accel from the accel table
541 int n
= FindAccel(pItem
->GetId());
543 if (n
!= wxNOT_FOUND
)
549 #endif // wxUSE_ACCEL
551 // Remove the item from the menu
553 ::WinSendMsg( GetHmenu()
555 ,MPFROM2SHORT(pItem
->GetId(), TRUE
)
558 if (IsAttached() && m_menuBar
->IsAttached())
561 // Otherwise, the chane won't be visible
563 m_menuBar
->Refresh();
567 // And from internal data structures
569 return wxMenuBase::DoRemove(pItem
);
570 } // end of wxMenu::DoRemove
572 // ---------------------------------------------------------------------------
573 // accelerator helpers
574 // ---------------------------------------------------------------------------
579 // Create the wxAcceleratorEntries for our accels and put them into provided
580 // array - return the number of accels we have
582 size_t wxMenu::CopyAccels(
583 wxAcceleratorEntry
* pAccels
586 size_t nCount
= GetAccelCount();
588 for (size_t n
= 0; n
< nCount
; n
++)
590 *pAccels
++ = *m_vAccels
[n
];
593 } // end of wxMenu::CopyAccels
595 #endif // wxUSE_ACCEL
597 // ---------------------------------------------------------------------------
599 // ---------------------------------------------------------------------------
601 void wxMenu::SetTitle(
602 const wxString
& rLabel
605 bool bHasNoTitle
= m_title
.IsEmpty();
606 HWND hMenu
= GetHmenu();
611 if (!rLabel
.IsEmpty())
613 if (!::WinSetWindowText(hMenu
, rLabel
.c_str()))
615 wxLogLastError("SetMenuTitle");
621 if (rLabel
.IsEmpty() )
623 ::WinSendMsg( GetHmenu()
625 ,MPFROM2SHORT(hMenu
, TRUE
)
634 if (!::WinSetWindowText(hMenu
, rLabel
.c_str()))
636 wxLogLastError("SetMenuTitle");
640 } // end of wxMenu::SetTitle
642 // ---------------------------------------------------------------------------
644 // ---------------------------------------------------------------------------
646 bool wxMenu::OS2Command(
647 WXUINT
WXUNUSED(uParam
)
652 // Ignore commands from the menu title
655 if (vId
!= (WXWORD
)idMenuTitle
)
658 ,(int)::WinSendMsg( GetHmenu()
666 } // end of wxMenu::OS2Command
668 // ---------------------------------------------------------------------------
670 // ---------------------------------------------------------------------------
672 wxWindow
* wxMenu::GetWindow() const
674 if (m_invokingWindow
!= NULL
)
675 return m_invokingWindow
;
676 else if ( m_menuBar
!= NULL
)
677 return m_menuBar
->GetFrame();
680 } // end of wxMenu::GetWindow
682 // recursive search for item by id
683 wxMenuItem
* wxMenu::FindItem(
686 , wxMenu
** ppItemMenu
692 wxMenuItem
* pItem
= NULL
;
694 for ( wxMenuItemList::Node
*node
= m_items
.GetFirst();
696 node
= node
->GetNext() )
698 pItem
= node
->GetData();
700 if ( pItem
->GetId() == nItemId
&& pItem
->m_vMenuData
.hItem
== hItem
)
703 *ppItemMenu
= (wxMenu
*)this;
705 else if ( pItem
->IsSubMenu() )
707 pItem
= pItem
->GetSubMenu()->FindItem( nItemId
716 // don't exit the loop
721 } // end of wxMenu::FindItem
723 // ---------------------------------------------------------------------------
725 // ---------------------------------------------------------------------------
727 void wxMenuBar::Init()
729 m_eventHandler
= this;
730 m_menuBarFrame
= NULL
;
732 } // end of wxMenuBar::Init
734 wxMenuBar::wxMenuBar()
737 } // end of wxMenuBar::wxMenuBar
739 wxMenuBar::wxMenuBar(
740 long WXUNUSED(lStyle
)
744 } // end of wxMenuBar::wxMenuBar
746 wxMenuBar::wxMenuBar(
749 , const wxString sTitles
[]
754 m_titles
.Alloc(nCount
);
755 for ( int i
= 0; i
< nCount
; i
++ )
757 m_menus
.Append(vMenus
[i
]);
758 m_titles
.Add(sTitles
[i
]);
759 vMenus
[i
]->Attach(this);
761 } // end of wxMenuBar::wxMenuBar
763 wxMenuBar::~wxMenuBar()
765 } // end of wxMenuBar::~wxMenuBar
767 // ---------------------------------------------------------------------------
769 // ---------------------------------------------------------------------------
771 void wxMenuBar::Refresh()
773 wxCHECK_RET( IsAttached(), wxT("can't refresh unatteched menubar") );
775 WinSendMsg(GetWinHwnd(m_menuBarFrame
), WM_UPDATEFRAME
, (MPARAM
)FCF_MENU
, (MPARAM
)0);
776 } // end of wxMenuBar::Refresh
778 WXHMENU
wxMenuBar::Create()
786 wxCHECK_MSG(!m_hMenu
, TRUE
, wxT("menubar already created"));
789 // Menubars should be associated with a frame otherwise they are popups
791 if (m_menuBarFrame
!= NULL
)
792 hFrame
= GetWinHwnd(m_menuBarFrame
);
794 hFrame
= HWND_DESKTOP
;
796 // Create an empty menu and then fill it with insertions
798 if ((m_hMenu
= ::WinCreateWindow( hFrame
801 ,MS_ACTIONBAR
| WS_SYNCPAINT
| WS_VISIBLE
813 wxLogLastError("WinLoadMenu");
817 size_t nCount
= GetMenuCount();
819 for (size_t i
= 0; i
< nCount
; i
++)
827 // Set the parent and owner of the submenues to be the menubar, not the desktop
829 hSubMenu
= m_menus
[i
]->m_vMenuData
.hwndSubMenu
;
830 if (!::WinSetParent(m_menus
[i
]->m_vMenuData
.hwndSubMenu
, m_hMenu
, FALSE
))
832 vError
= ::WinGetLastError(vHabmain
);
833 sError
= wxPMErrorToStr(vError
);
834 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
838 if (!::WinSetOwner(m_menus
[i
]->m_vMenuData
.hwndSubMenu
, m_hMenu
))
840 vError
= ::WinGetLastError(vHabmain
);
841 sError
= wxPMErrorToStr(vError
);
842 wxLogError("Error setting parent for submenu. Error: %s\n", sError
);
846 m_menus
[i
]->m_vMenuData
.iPosition
= i
;
848 rc
= (APIRET
)::WinSendMsg(m_hMenu
, MM_INSERTITEM
, (MPARAM
)&m_menus
[i
]->m_vMenuData
, (MPARAM
)m_titles
[i
].c_str());
849 if (rc
== MIT_MEMERROR
|| rc
== MIT_ERROR
)
851 vError
= ::WinGetLastError(vHabmain
);
852 sError
= wxPMErrorToStr(vError
);
853 wxLogError("Error inserting or appending a menuitem. Error: %s\n", sError
);
859 } // end of wxMenuBar::Create
861 // ---------------------------------------------------------------------------
862 // wxMenuBar functions to work with the top level submenus
863 // ---------------------------------------------------------------------------
866 // NB: we don't support owner drawn top level items for now, if we do these
867 // functions would have to be changed to use wxMenuItem as well
869 void wxMenuBar::EnableTop(
874 wxCHECK_RET(IsAttached(), wxT("doesn't work with unattached menubars"));
879 uFlag
= MIA_DISABLED
;
881 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
882 if (nId
== MIT_ERROR
)
884 wxLogLastError("LogLastError");
887 ::WinSendMsg((HWND
)m_hMenu
, MM_SETITEMATTR
, MPFROM2SHORT(nId
, TRUE
), MPFROM2SHORT(MIA_DISABLED
, uFlag
));
889 } // end of wxMenuBar::EnableTop
891 void wxMenuBar::SetLabelTop(
893 , const wxString
& rLabel
899 wxCHECK_RET(nPos
< GetMenuCount(), wxT("invalid menu index"));
900 m_titles
[nPos
] = rLabel
;
907 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
908 if (nId
== MIT_ERROR
)
910 wxLogLastError("LogLastError");
913 if(!::WinSendMsg( (HWND
)m_hMenu
915 ,MPFROM2SHORT(nId
, TRUE
)
919 wxLogLastError("QueryItem");
923 if (::WinSendMsg(GetHmenu(), MM_SETITEMTEXT
, MPFROMSHORT(nId
), (MPARAM
)rLabel
.c_str()));
925 wxLogLastError("ModifyMenu");
928 } // end of wxMenuBar::SetLabelTop
930 wxString
wxMenuBar::GetLabelTop(
934 wxCHECK_MSG( nPos
< GetMenuCount(), wxEmptyString
,
935 wxT("invalid menu index in wxMenuBar::GetLabelTop") );
936 return m_titles
[nPos
];
937 } // end of wxMenuBar::GetLabelTop
939 // ---------------------------------------------------------------------------
940 // wxMenuBar construction
941 // ---------------------------------------------------------------------------
943 wxMenu
* wxMenuBar::Replace(
946 , const wxString
& rTitle
950 wxString Title
= TextToLabel(rTitle
);
951 wxMenu
* pMenuOld
= wxMenuBarBase::Replace( nPos
957 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)m_hMenu
, MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
958 if (nId
== MIT_ERROR
)
960 wxLogLastError("LogLastError");
965 m_titles
[nPos
] = Title
;
968 ::WinSendMsg((HWND
)m_hMenu
, MM_REMOVEITEM
, MPFROM2SHORT(nId
, TRUE
), (MPARAM
)0);
969 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)Title
.c_str());
972 if (pMenuOld
->HasAccels() || pMenu
->HasAccels())
975 // Need to rebuild accell table
979 #endif // wxUSE_ACCEL
983 } // end of wxMenuBar::Replace
985 bool wxMenuBar::Insert(
988 , const wxString
& rTitle
991 wxString Title
= TextToLabel(rTitle
);
992 if (!wxMenuBarBase::Insert( nPos
998 m_titles
.Insert( Title
1004 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)Title
.c_str());
1006 if (pMenu
->HasAccels())
1008 // need to rebuild accell table
1009 RebuildAccelTable();
1011 #endif // wxUSE_ACCEL
1015 } // end of wxMenuBar::Insert
1017 bool wxMenuBar::Append(
1019 , const wxString
& rTitle
1022 WXHMENU hSubmenu
= pMenu
? pMenu
->GetHMenu() : 0;
1024 wxCHECK_MSG(hSubmenu
, FALSE
, wxT("can't append invalid menu to menubar"));
1026 wxString Title
= TextToLabel(rTitle
);
1027 if (!wxMenuBarBase::Append(pMenu
, Title
))
1030 m_titles
.Add(Title
);
1034 pMenu
->m_vMenuData
.iPosition
= MIT_END
;
1035 ::WinSendMsg((HWND
)m_hMenu
, MM_INSERTITEM
, (MPARAM
)&pMenu
->m_vMenuData
, (MPARAM
)Title
.c_str());
1037 if (pMenu
->HasAccels())
1040 // Need to rebuild accell table
1042 RebuildAccelTable();
1044 #endif // wxUSE_ACCEL
1048 } // end of wxMenuBar::Append
1050 wxMenu
* wxMenuBar::Remove(
1054 wxMenu
* pMenu
= wxMenuBarBase::Remove(nPos
);
1060 nId
= SHORT1FROMMR(::WinSendMsg((HWND
)GetHmenu(), MM_ITEMIDFROMPOSITION
, MPFROMSHORT(nPos
), (MPARAM
)0));
1061 if (nId
== MIT_ERROR
)
1063 wxLogLastError("LogLastError");
1068 ::WinSendMsg((HWND
)GetHmenu(), MM_REMOVEITEM
, MPFROM2SHORT(nId
, TRUE
), (MPARAM
)0);
1071 if (pMenu
->HasAccels())
1074 // Need to rebuild accell table
1076 RebuildAccelTable();
1078 #endif // wxUSE_ACCEL
1081 m_titles
.Remove(nPos
);
1083 } // end of wxMenuBar::Remove
1087 void wxMenuBar::RebuildAccelTable()
1090 // Merge the accelerators of all menus into one accel table
1092 size_t nAccelCount
= 0;
1094 size_t nCount
= GetMenuCount();
1096 for (i
= 0; i
< nCount
; i
++)
1098 nAccelCount
+= m_menus
[i
]->GetAccelCount();
1103 wxAcceleratorEntry
* pAccelEntries
= new wxAcceleratorEntry
[nAccelCount
];
1106 for (i
= 0; i
< nCount
; i
++)
1108 nAccelCount
+= m_menus
[i
]->CopyAccels(&pAccelEntries
[nAccelCount
]);
1110 m_vAccelTable
= wxAcceleratorTable( nAccelCount
1113 delete [] pAccelEntries
;
1115 } // end of wxMenuBar::RebuildAccelTable
1117 #endif // wxUSE_ACCEL
1119 void wxMenuBar::Attach(
1123 wxASSERT_MSG( !IsAttached(), wxT("menubar already attached!") );
1126 RebuildAccelTable();
1128 // Ensure the accelerator table is set to the frame (not the client!)
1130 if (!::WinSetAccelTable( vHabmain
1131 ,(HWND
)pFrame
->GetHWND()
1132 ,m_vAccelTable
.GetHACCEL()
1134 wxLogLastError("WinSetAccelTable");
1135 #endif // wxUSE_ACCEL
1136 } // end of wxMenuBar::Attach
1138 void wxMenuBar::Detach()
1140 ::WinDestroyWindow((HWND
)m_hMenu
);
1141 m_hMenu
= (WXHMENU
)NULL
;
1142 m_menuBarFrame
= NULL
;
1143 } // end of wxMenuBar::Detach
1145 // ---------------------------------------------------------------------------
1146 // wxMenuBar searching for menu items
1147 // ---------------------------------------------------------------------------
1150 // Find the itemString in menuString, and return the item id or wxNOT_FOUND
1152 int wxMenuBar::FindMenuItem(
1153 const wxString
& rMenuString
1154 , const wxString
& rItemString
1157 wxString sMenuLabel
= wxStripMenuCodes(rMenuString
);
1158 size_t nCount
= GetMenuCount();
1160 for (size_t i
= 0; i
< nCount
; i
++)
1162 wxString sTitle
= wxStripMenuCodes(m_titles
[i
]);
1164 if (rMenuString
== sTitle
)
1165 return m_menus
[i
]->FindItem(rItemString
);
1168 } // end of wxMenuBar::FindMenuItem
1170 wxMenuItem
* wxMenuBar::FindItem(
1172 , wxMenu
** ppItemMenu
1178 wxMenuItem
* pItem
= NULL
;
1179 size_t nCount
= GetMenuCount();
1181 for (size_t i
= 0; !pItem
&& (i
< nCount
); i
++)
1183 pItem
= m_menus
[i
]->FindItem( nId
1188 } // end of wxMenuBar::FindItem
1190 wxMenuItem
* wxMenuBar::FindItem(
1193 , wxMenu
** ppItemMenu
1199 wxMenuItem
* pItem
= NULL
;
1200 size_t nCount
= GetMenuCount();
1202 for (size_t i
= 0; !pItem
&& (i
< nCount
); i
++)
1204 pItem
= m_menus
[i
]->FindItem( nId
1210 } // end of wxMenuBar::FindItem