bool wxMenuBar::Insert( size_t nPos, wxMenu* pMenu, const wxString& rTitle ) { wxString sTitle = wxPMTextToLabel(rTitle); if (!wxMenuBarBase::Insert( nPos, pMenu, sTitle )) return false; m_titles.Insert( sTitle, nPos ); if (IsAttached()) { pMenu->m_vMenuData.iPosition = (SHORT)nPos; ::WinSendMsg( (HWND)m_hMenu ,MM_INSERTITEM ,(MPARAM)&pMenu->m_vMenuData ,(MPARAM)sTitle.wx_str() ); #if wxUSE_ACCEL if (pMenu->HasAccels()) { // need to rebuild accell table RebuildAccelTable(); } #endif // wxUSE_ACCEL Refresh(); } return true; } // end of wxMenuBar::Insert
bool wxMenuBar::Append( wxMenu* pMenu, const wxString& rsTitle ) { WXHMENU hSubmenu = pMenu ? pMenu->GetHMenu() : 0; wxCHECK_MSG(hSubmenu, false, wxT("can't append invalid menu to menubar")); wxString sTitle = wxPMTextToLabel(rsTitle); if (!wxMenuBarBase::Append(pMenu, sTitle)) return false; m_titles.Add(sTitle); if ( IsAttached() ) { pMenu->m_vMenuData.iPosition = MIT_END; ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)sTitle.wx_str()); #if wxUSE_ACCEL if (pMenu->HasAccels()) { // // Need to rebuild accell table // RebuildAccelTable(); } #endif // wxUSE_ACCEL Refresh(); } return true; } // end of wxMenuBar::Append
wxMenu* wxMenuBar::Replace( size_t nPos , wxMenu* pMenu , const wxString& rTitle ) { SHORT nId; wxString sTitle = wxPMTextToLabel(rTitle); wxMenu* pMenuOld = wxMenuBarBase::Replace( nPos ,pMenu ,sTitle ); nId = SHORT1FROMMR(::WinSendMsg((HWND)m_hMenu, MM_ITEMIDFROMPOSITION, MPFROMSHORT(nPos), (MPARAM)0)); if (nId == MIT_ERROR) { wxLogLastError(wxT("LogLastError")); return NULL; } if (!pMenuOld) return NULL; m_titles[nPos] = sTitle; if (IsAttached()) { ::WinSendMsg((HWND)m_hMenu, MM_REMOVEITEM, MPFROM2SHORT(nId, TRUE), (MPARAM)0); ::WinSendMsg((HWND)m_hMenu, MM_INSERTITEM, (MPARAM)&pMenu->m_vMenuData, (MPARAM)sTitle.wx_str()); #if wxUSE_ACCEL if (pMenuOld->HasAccels() || pMenu->HasAccels()) { // // Need to rebuild accell table // RebuildAccelTable(); } #endif // wxUSE_ACCEL Refresh(); } return pMenuOld; } // end of wxMenuBar::Replace
wxMenuItem::wxMenuItem( wxMenu* pParentMenu , int nId , const wxString& rsText , const wxString& rsHelp , bool bIsCheckable , wxMenu* pSubMenu ) : wxMenuItemBase( pParentMenu ,nId ,wxPMTextToLabel(rsText) ,rsHelp ,bIsCheckable ? wxITEM_CHECK : wxITEM_NORMAL ,pSubMenu ) { wxASSERT_MSG(pParentMenu != NULL, wxT("a menu item should have a parent")); memset(&m_vMenuData, '\0', sizeof(m_vMenuData)); m_vMenuData.id = (USHORT)nId; Init(); } // end of wxMenuItem::wxMenuItem
void wxMenuItem::SetItemLabel( const wxString& rText ) { // // Don't do anything if label didn't change // wxString sText = wxPMTextToLabel(rText); if (m_text == sText) return; // wxMenuItemBase will do stock ID checks wxMenuItemBase::SetItemLabel(sText); HWND hMenu = GetHmenuOf(m_parentMenu); wxCHECK_RET(hMenu, wxT("menuitem without menu")); #if wxUSE_ACCEL m_parentMenu->UpdateAccel(this); #endif // wxUSE_ACCEL USHORT uId = (USHORT)GetRealId(); MENUITEM vItem; USHORT uFlagsOld; if (!::WinSendMsg( hMenu ,MM_QUERYITEM ,MPFROM2SHORT(uId, TRUE) ,(MPARAM)&vItem )) { wxLogLastError(wxT("GetMenuState")); } else { uFlagsOld = vItem.afStyle; if (IsSubMenu()) { uFlagsOld |= MIS_SUBMENU; } char* pData; #if wxUSE_OWNER_DRAWN if (IsOwnerDrawn()) { uFlagsOld |= MIS_OWNERDRAW; pData = (char*)this; } else #endif //owner drawn { uFlagsOld |= MIS_TEXT; pData = (char*) m_text.wx_str(); } // // Set the style // if (!::WinSendMsg( hMenu ,MM_SETITEM ,MPFROM2SHORT(uId, TRUE) ,(MPARAM)&vItem )) { wxLogLastError(wxT("ModifyMenu")); } // // Set the text // if (::WinSendMsg( hMenu ,MM_SETITEMTEXT ,MPFROMSHORT(uId) ,(MPARAM)pData )) { wxLogLastError(wxT("ModifyMenu")); } } } // end of wxMenuItem::SetText