From 38bef03742c94376a974f84693ff2e48693e6839 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 1 Oct 2018 13:10:10 +0100 Subject: pass menuitem ident around directly, instead of deriving from itemid MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sidestepping the while duplicate itemids in separate submenus problem Change-Id: Icb57ac805f3c8c4fc3a68341e318375c6492cbb1 Reviewed-on: https://gerrit.libreoffice.org/61189 Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/vcl/menu.hxx | 4 ++-- include/vcl/menubtn.hxx | 3 ++- sc/source/ui/navipi/content.cxx | 4 ++-- vcl/source/control/menubtn.cxx | 11 ++++------- vcl/source/window/menu.cxx | 26 +++++++++++++------------- vcl/source/window/menufloatingwindow.cxx | 9 ++++++++- vcl/source/window/menuitemlist.cxx | 11 ----------- vcl/source/window/menuitemlist.hxx | 1 - 8 files changed, 31 insertions(+), 38 deletions(-) diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx index f865166c0b57..3d0e6cb09195 100644 --- a/include/vcl/menu.hxx +++ b/include/vcl/menu.hxx @@ -146,6 +146,7 @@ private: sal_uInt16 mnHighlightedItemPos; // for native menus: keeps track of the highlighted item MenuFlags nMenuFlags; sal_uInt16 nSelectedId; + OString sSelectedIdent; // for output: sal_uInt16 nImgOrChkPos; @@ -262,8 +263,7 @@ public: OString GetItemIdent(sal_uInt16 nItemId) const; MenuItemType GetItemType( sal_uInt16 nPos ) const; sal_uInt16 GetCurItemId() const { return nSelectedId;} - OString GetCurItemIdent() const; - OString GetItemIdentFromSubMenu(sal_uInt16 nItemId) const; + OString GetCurItemIdent() const { return sSelectedIdent; } void SetItemBits( sal_uInt16 nItemId, MenuItemBits nBits ); MenuItemBits GetItemBits( sal_uInt16 nItemId ) const; diff --git a/include/vcl/menubtn.hxx b/include/vcl/menubtn.hxx index b5c1e226a372..a76e3a3aba94 100644 --- a/include/vcl/menubtn.hxx +++ b/include/vcl/menubtn.hxx @@ -38,6 +38,7 @@ private: std::unique_ptr mpMenuTimer; VclPtr mpMenu; VclPtr mpFloatingWindow; + OString msCurItemIdent; sal_uInt16 mnCurItemId; bool mbDelayMenu; Link maActivateHdl; @@ -81,7 +82,7 @@ public: void SetPopover(Window* pWindow); sal_uInt16 GetCurItemId() const { return mnCurItemId; } - OString GetCurItemIdent() const; + OString GetCurItemIdent() const { return msCurItemIdent; } void SetActivateHdl( const Link& rLink ) { maActivateHdl = rLink; } void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; } diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx index 6ab4e597fa15..489a12de9739 100644 --- a/sc/source/ui/navipi/content.cxx +++ b/sc/source/ui/navipi/content.cxx @@ -668,8 +668,8 @@ void ScContentTree::Command( const CommandEvent& rCEvt ) aPop->InsertItem( 2, pParentWindow->GetStrDisplay() ); aPop->SetPopupMenu( 2, aDocMenu.get() ); - sal_uInt16 nSelected = aPop->Execute(this, rCEvt.GetMousePosPixel()); - OString sIdent = aPop->GetItemIdentFromSubMenu(nSelected); + aPop->Execute(this, rCEvt.GetMousePosPixel()); + OString sIdent = aPop->GetCurItemIdent(); if (sIdent.startsWith("document")) { diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx index 8ffa935e9141..6aa89d937b8b 100644 --- a/vcl/source/control/menubtn.cxx +++ b/vcl/source/control/menubtn.cxx @@ -50,7 +50,9 @@ void MenuButton::ExecuteMenu() { Point aPos(0, 1); tools::Rectangle aRect(aPos, aSize ); - mnCurItemId = mpMenu->Execute(this, aRect, PopupMenuFlags::ExecuteDown); + mpMenu->Execute(this, aRect, PopupMenuFlags::ExecuteDown); + mnCurItemId = mpMenu->GetCurItemId(); + msCurItemIdent = mpMenu->GetCurItemIdent(); } else { @@ -70,6 +72,7 @@ void MenuButton::ExecuteMenu() { Select(); mnCurItemId = 0; + msCurItemIdent.clear(); } } @@ -107,12 +110,6 @@ bool MenuButton::MenuShown() const } } -OString MenuButton::GetCurItemIdent() const -{ - return (mnCurItemId && mpMenu) ? - mpMenu->GetItemIdent(mnCurItemId) : OString(); -} - MenuButton::MenuButton( vcl::Window* pParent, WinBits nWinBits ) : PushButton(WindowType::MENUBUTTON) , mnCurItemId(0) diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index b92daf20f10c..d1adaf25211c 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -364,6 +364,7 @@ void Menu::Select() if ( pStartMenu && ( pStartMenu != this ) ) { pStartMenu->nSelectedId = nSelectedId; + pStartMenu->sSelectedIdent = sSelectedIdent; pStartMenu->aSelectHdl.Call( this ); } } @@ -690,24 +691,12 @@ MenuItemType Menu::GetItemType( sal_uInt16 nPos ) const return MenuItemType::DONTKNOW; } -OString Menu::GetCurItemIdent() const -{ - const MenuItemData* pData = pItemList->GetData(nSelectedId); - return pData ? pData->sIdent : OString(); -} - OString Menu::GetItemIdent(sal_uInt16 nId) const { const MenuItemData* pData = pItemList->GetData(nId); return pData ? pData->sIdent : OString(); } -OString Menu::GetItemIdentFromSubMenu(sal_uInt16 nId) const -{ - const MenuItemData* pData = pItemList->GetDataFromSubMenu(nId); - return pData ? pData->sIdent : OString(); -} - void Menu::SetItemBits( sal_uInt16 nItemId, MenuItemBits nBits ) { MenuItemData* pData = pItemList->GetData( nItemId ); @@ -2132,13 +2121,20 @@ void Menu::ImplCallHighlight(sal_uInt16 nItem) ImplMenuDelData aDelData( this ); nSelectedId = 0; + sSelectedIdent.clear(); MenuItemData* pData = pItemList->GetDataFromPos(nItem); - if ( pData ) + if (pData) + { nSelectedId = pData->nId; + sSelectedIdent = pData->sIdent; + } ImplCallEventListeners( VclEventId::MenuHighlight, GetItemPos( GetCurItemId() ) ); if( !aDelData.isDeleted() ) + { nSelectedId = 0; + sSelectedIdent.clear(); + } } IMPL_LINK_NOARG(Menu, ImplCallSelect, void*, void) @@ -2620,6 +2616,7 @@ bool MenuBar::HandleMenuHighlightEvent( Menu *pMenu, sal_uInt16 nHighlightEventI { pMenu->mnHighlightedItemPos = pMenu->GetItemPos( nHighlightEventId ); pMenu->nSelectedId = nHighlightEventId; + pMenu->sSelectedIdent = pMenu->GetItemIdent( nHighlightEventId ); pMenu->pStartedFrom = const_cast(this); pMenu->ImplCallHighlight( pMenu->mnHighlightedItemPos ); } @@ -2636,6 +2633,7 @@ bool Menu::HandleMenuCommandEvent( Menu *pMenu, sal_uInt16 nCommandEventId ) con if( pMenu ) { pMenu->nSelectedId = nCommandEventId; + pMenu->sSelectedIdent = pMenu->GetItemIdent(nCommandEventId); pMenu->pStartedFrom = const_cast(this); pMenu->ImplSelect(); return true; @@ -2762,6 +2760,7 @@ void PopupMenu::SelectItem(sal_uInt16 nId) void PopupMenu::SetSelectedEntry( sal_uInt16 nId ) { nSelectedId = nId; + sSelectedIdent = GetItemIdent(nId); } sal_uInt16 PopupMenu::Execute( vcl::Window* pExecWindow, const Point& rPopupPos ) @@ -2825,6 +2824,7 @@ sal_uInt16 PopupMenu::ImplExecute( const VclPtr& pW, const tools::R pStartedFrom = pSFrom; nSelectedId = 0; + sSelectedIdent.clear(); bCanceled = false; VclPtr xFocusId; diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx index 8e7254299a3d..67d6d0ce3a8e 100644 --- a/vcl/source/window/menufloatingwindow.cxx +++ b/vcl/source/window/menufloatingwindow.cxx @@ -508,8 +508,12 @@ void MenuFloatingWindow::EndExecute() if ( pItemData && !pItemData->bIsTemporary ) { pM->nSelectedId = pItemData->nId; - if ( pStart ) + pM->sSelectedIdent = pItemData->sIdent; + if (pStart) + { pStart->nSelectedId = pItemData->nId; + pStart->sSelectedIdent = pItemData->sIdent; + } pM->ImplSelect(); } @@ -749,7 +753,10 @@ void MenuFloatingWindow::ChangeHighlightItem( sal_uInt16 n, bool bStartPopupTime pMenu->ImplCallHighlight( nHighlightedItem ); } else + { pMenu->nSelectedId = 0; + pMenu->sSelectedIdent.clear(); + } if ( bStartPopupTimer ) { diff --git a/vcl/source/window/menuitemlist.cxx b/vcl/source/window/menuitemlist.cxx index 7be1f22f917e..9c25bf4e17d1 100644 --- a/vcl/source/window/menuitemlist.cxx +++ b/vcl/source/window/menuitemlist.cxx @@ -163,17 +163,6 @@ MenuItemData* MenuItemList::GetData( sal_uInt16 nSVId, size_t& rPos ) const return nullptr; } -MenuItemData* MenuItemList::GetDataFromSubMenu(sal_uInt16 nSVId) const -{ - for ( size_t i = 0, n = maItemList.size(); i < n; ++i ) - { - if ( maItemList[i]->pSubMenu - && maItemList[i]->pSubMenu->GetCurItemId() != 0 ) // if something is selected - return maItemList[i].get()->pSubMenu->GetItemList()->GetDataFromPos(nSVId - 1); - } - return nullptr; -} - MenuItemData* MenuItemList::SearchItem( sal_Unicode cSelectChar, KeyCode aKeyCode, diff --git a/vcl/source/window/menuitemlist.hxx b/vcl/source/window/menuitemlist.hxx index 89d1953de607..276c078e6431 100644 --- a/vcl/source/window/menuitemlist.hxx +++ b/vcl/source/window/menuitemlist.hxx @@ -122,7 +122,6 @@ public: void Clear(); MenuItemData* GetData( sal_uInt16 nSVId, size_t& rPos ) const; - MenuItemData* GetDataFromSubMenu( sal_uInt16 nSVId ) const; MenuItemData* GetData( sal_uInt16 nSVId ) const { size_t nTemp; -- cgit v1.2.3