framework/source/uielement/newmenucontroller.cxx      |    7 +++----
 framework/source/uielement/popuptoolbarcontroller.cxx |    8 ++++----
 include/toolkit/awt/vclxmenu.hxx                      |    5 +++--
 toolkit/source/awt/vclxmenu.cxx                       |   16 ++++++++++++++++
 4 files changed, 26 insertions(+), 10 deletions(-)

New commits:
commit 326351e2b342eae5ca0154b2ba303b937a696577
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Dec 14 10:22:00 2021 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sat Jan 8 15:32:56 2022 +0100

    move UserData bodge into VCLXMenu
    
    Change-Id: I20c303788e576a29574a696cb20c9e8a235233b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126804
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/framework/source/uielement/newmenucontroller.cxx 
b/framework/source/uielement/newmenucontroller.cxx
index 9b70d5821682..d282509d93f5 100644
--- a/framework/source/uielement/newmenucontroller.cxx
+++ b/framework/source/uielement/newmenucontroller.cxx
@@ -346,7 +346,7 @@ void NewMenuController::fillPopupMenu( Reference< 
css::awt::XPopupMenu > const &
             rPopupMenu->setCommand(nItemId, aDynamicMenuEntry.sURL);
 
             void* nAttributePtr = MenuAttributes::CreateAttribute( 
aDynamicMenuEntry.sTargetName, aDynamicMenuEntry.sImageIdentifier );
-            pVCLPopupMenu->SetUserValue( nItemId, nAttributePtr, 
MenuAttributes::ReleaseAttribute );
+            pPopupMenu->setUserValue(nItemId, nAttributePtr, 
MenuAttributes::ReleaseAttribute);
 
             nItemId++;
         }
@@ -400,9 +400,8 @@ void SAL_CALL NewMenuController::itemSelected( const 
css::awt::MenuEvent& rEvent
 
     {
         SolarMutexGuard aSolarMutexGuard;
-        PopupMenu* pVCLPopupMenu = static_cast<PopupMenu 
*>(pPopupMenu->GetMenu());
-        aURL = pVCLPopupMenu->GetItemCommand(rEvent.MenuId);
-        void* nAttributePtr = pVCLPopupMenu->GetUserValue(rEvent.MenuId);
+        aURL = pPopupMenu->getCommand(rEvent.MenuId);
+        void* nAttributePtr = pPopupMenu->getUserValue(rEvent.MenuId);
         MenuAttributes* pAttributes = static_cast<MenuAttributes 
*>(nAttributePtr);
         if (pAttributes)
             aTargetFrame = pAttributes->aTargetFrame;
diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx 
b/framework/source/uielement/popuptoolbarcontroller.cxx
index 0e1811f8bcd7..62ac260f6c77 100644
--- a/framework/source/uielement/popuptoolbarcontroller.cxx
+++ b/framework/source/uielement/popuptoolbarcontroller.cxx
@@ -696,8 +696,8 @@ void SAL_CALL NewToolbarController::execute( sal_Int16 
/*KeyModifier*/ )
         aURL = m_xPopupMenu->getCommand(m_nMenuId);
 
         // TODO investigate how to wrap Get/SetUserValue in css::awt::XMenu
-        Menu* pVclMenu = comphelper::getFromUnoTunnel<VCLXMenu>( m_xPopupMenu 
)->GetMenu();
-        MenuAttributes* pMenuAttributes( static_cast<MenuAttributes*>( 
pVclMenu->GetUserValue( m_nMenuId ) ) );
+        VCLXMenu* pMenu = comphelper::getFromUnoTunnel<VCLXMenu>(m_xPopupMenu);
+        MenuAttributes* 
pMenuAttributes(static_cast<MenuAttributes*>(pMenu->getUserValue(m_nMenuId)));
         if ( pMenuAttributes )
             aTarget = pMenuAttributes->aTargetFrame;
         else
@@ -749,8 +749,8 @@ void SAL_CALL NewToolbarController::updateImage()
     if ( m_xPopupMenu.is() && m_nMenuId )
     {
         aURL = m_xPopupMenu->getCommand(m_nMenuId);
-        Menu* pVclMenu = comphelper::getFromUnoTunnel<VCLXMenu>( m_xPopupMenu 
)->GetMenu();
-        MenuAttributes* pMenuAttributes( static_cast<MenuAttributes*>( 
pVclMenu->GetUserValue( m_nMenuId ) ) );
+        VCLXMenu* pMenu = comphelper::getFromUnoTunnel<VCLXMenu>(m_xPopupMenu);
+        MenuAttributes* 
pMenuAttributes(static_cast<MenuAttributes*>(pMenu->getUserValue(m_nMenuId)));
         if ( pMenuAttributes )
             aImageId = pMenuAttributes->aImageId;
     }
diff --git a/include/toolkit/awt/vclxmenu.hxx b/include/toolkit/awt/vclxmenu.hxx
index 5c848975d837..096c370bce82 100644
--- a/include/toolkit/awt/vclxmenu.hxx
+++ b/include/toolkit/awt/vclxmenu.hxx
@@ -48,8 +48,7 @@ typedef ::std::vector<
     css::uno::Reference< css::awt::XPopupMenu >
 > PopupMenuRefList;
 
-
-
+typedef void (*MenuUserDataReleaseFunction)(void*);
 
 class TOOLKIT_DLLPUBLIC VCLXMenu :  public css::awt::XMenuBar,
                                     public css::awt::XPopupMenu,
@@ -80,6 +79,8 @@ public:
 
     Menu*    GetMenu() const { return mpMenu; }
     bool IsPopupMenu() const;
+    void setUserValue(sal_uInt16 nItemId, void* nUserValue, 
MenuUserDataReleaseFunction aFunc);
+    void* getUserValue(sal_uInt16 nItemId);
 
     // css::uno::XInterface
     css::uno::Any  SAL_CALL queryInterface( const css::uno::Type & rType ) 
override;
diff --git a/toolkit/source/awt/vclxmenu.cxx b/toolkit/source/awt/vclxmenu.cxx
index eca9de23fa12..2e7e80636bf6 100644
--- a/toolkit/source/awt/vclxmenu.cxx
+++ b/toolkit/source/awt/vclxmenu.cxx
@@ -819,6 +819,22 @@ VCLXMenu::getItemImage(
     return rxGraphic;
 }
 
+void VCLXMenu::setUserValue(sal_uInt16 nItemId, void* nUserValue, 
MenuUserDataReleaseFunction aFunc)
+{
+    SolarMutexGuard aSolarGuard;
+    ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
+
+    mpMenu->SetUserValue(nItemId, nUserValue, aFunc);
+}
+
+void* VCLXMenu::getUserValue(sal_uInt16 nItemId)
+{
+    SolarMutexGuard aSolarGuard;
+    ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
+
+    return mpMenu->GetUserValue(nItemId);
+}
+
 VCLXMenuBar::VCLXMenuBar()
 {
     ImplCreateMenu( false );

Reply via email to