[Libreoffice-commits] core.git: include/svtools svtools/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 12 14:41:26 UTC 2021


 include/svtools/valueset.hxx        |    8 -
 svtools/source/control/valueacc.cxx |   26 ++--
 svtools/source/control/valueimp.hxx |    6 -
 svtools/source/control/valueset.cxx |  188 ++++++++++++++++++------------------
 4 files changed, 115 insertions(+), 113 deletions(-)

New commits:
commit f09d23f80f8f492a5cf27d3fef5b007357a585fa
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Jul 12 13:43:56 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Jul 12 16:40:49 2021 +0200

    Revert "flatten ValueSet item array"
    
    I'm seeing a11y crashes in the impress slide transition ValueSet. The
    mxAcc member contains a ValueItemAcc which has a pointer back to the
    ValueSetItem so if its std::moved into another ValueSetItem then it
    continues to point to the older ValueSetItem and not the new one
    
    This reverts commit 30aa33e6a6b9fb230af96f619db27fcaf31ef914.
    
    Change-Id: I1fd81aa81e47f2e984dd47fdc8a905e25c9f6266
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118775
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index 55399b24f711..084008c79e2e 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -175,6 +175,8 @@ to be set (before Show) with SetStyle().
 
 *************************************************************************/
 
+typedef std::vector<std::unique_ptr<ValueSetItem>> ValueItemList;
+
 #define WB_ITEMBORDER           (WinBits(0x00010000))
 #define WB_DOUBLEBORDER         (WinBits(0x00020000))
 #define WB_NAMEFIELD            (WinBits(0x00040000))
@@ -191,7 +193,7 @@ class SVT_DLLPUBLIC ValueSet : public weld::CustomWidgetController
 private:
     ScopedVclPtr<VirtualDevice> maVirDev;
     css::uno::Reference<css::accessibility::XAccessible> mxAccessible;
-    std::vector<ValueSetItem>  mItemList;
+    ValueItemList   mItemList;
     std::unique_ptr<ValueSetItem> mpNoneItem;
     std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
     tools::Rectangle  maNoneItemRect;
@@ -234,7 +236,7 @@ private:
     friend class ValueSetAcc;
 
     SVT_DLLPRIVATE void         ImplDeleteItems();
-    SVT_DLLPRIVATE void         ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem& rItem, tools::Rectangle aRect);
+    SVT_DLLPRIVATE void         ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem* pItem, tools::Rectangle aRect);
     SVT_DLLPRIVATE void         ImplDrawItemText(vcl::RenderContext& rRenderContext, const OUString& rStr);
     SVT_DLLPRIVATE void         ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel);
     SVT_DLLPRIVATE void         ImplDrawSelect(vcl::RenderContext& rRenderContext);
@@ -244,7 +246,7 @@ private:
     SVT_DLLPRIVATE ValueSetItem*    ImplGetItem( size_t nPos );
     SVT_DLLPRIVATE ValueSetItem*    ImplGetFirstItem();
     SVT_DLLPRIVATE sal_uInt16          ImplGetVisibleItemCount() const;
-    SVT_DLLPRIVATE void         ImplInsertItem( const ValueSetItem& rItem, const size_t nPos );
+    SVT_DLLPRIVATE void         ImplInsertItem( std::unique_ptr<ValueSetItem> pItem, const size_t nPos );
     SVT_DLLPRIVATE tools::Rectangle    ImplGetItemRect( size_t nPos ) const;
     SVT_DLLPRIVATE void         ImplFireAccessibleEvent( short nEventId, const css::uno::Any& rOldValue, const css::uno::Any& rNewValue );
     SVT_DLLPRIVATE bool         ImplHasAccessibleListeners();
diff --git a/svtools/source/control/valueacc.cxx b/svtools/source/control/valueacc.cxx
index 1fe72be58cc8..a6364d784064 100644
--- a/svtools/source/control/valueacc.cxx
+++ b/svtools/source/control/valueacc.cxx
@@ -35,7 +35,7 @@ using namespace ::com::sun::star;
 
 
 ValueSetItem::ValueSetItem( ValueSet& rParent )
-    : mpParent(&rParent)
+    : mrParent(rParent)
     , mnId(0)
     , meType(VALUESETITEM_NONE)
     , mbVisible(true)
@@ -122,7 +122,7 @@ uno::Reference< accessibility::XAccessible > SAL_CALL ValueItemAcc::getAccessibl
     uno::Reference< accessibility::XAccessible >    xRet;
 
     if( mpParent )
-        xRet = mpParent->mpParent->mxAccessible;
+        xRet = mpParent->mrParent.mxAccessible;
 
     return xRet;
 }
@@ -139,7 +139,7 @@ sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
     {
         bool bDone = false;
 
-        sal_uInt16 nCount = mpParent->mpParent->ImplGetVisibleItemCount();
+        sal_uInt16 nCount = mpParent->mrParent.ImplGetVisibleItemCount();
         ValueSetItem* pItem;
         for (sal_uInt16 i=0; i<nCount && !bDone; i++)
         {
@@ -147,7 +147,7 @@ sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
             // just in case the number of children changes in the meantime.
             try
             {
-                pItem = mpParent->mpParent->ImplGetItem(i);
+                pItem = mpParent->mrParent.ImplGetItem(i);
             }
             catch (const lang::IndexOutOfBoundsException&)
             {
@@ -165,9 +165,9 @@ sal_Int32 SAL_CALL ValueItemAcc::getAccessibleIndexInParent()
     }
 
     //if this valueset contain a none field(common value is default), then we should increase the real index and set the noitem index value equal 0.
-    if ( mpParent && ( (mpParent->mpParent->GetStyle() & WB_NONEFIELD) != 0 ) )
+    if ( mpParent && ( (mpParent->mrParent.GetStyle() & WB_NONEFIELD) != 0 ) )
     {
-        ValueSetItem* pFirstItem = mpParent->mpParent->ImplGetItem (VALUESET_ITEM_NONEITEM);
+        ValueSetItem* pFirstItem = mpParent->mrParent.ImplGetItem (VALUESET_ITEM_NONEITEM);
         if( pFirstItem && pFirstItem ->GetAccessible(mbIsTransientChildrenDisabled).get() == this )
             nIndexInParent = 0;
         else
@@ -230,7 +230,7 @@ uno::Reference< accessibility::XAccessibleStateSet > SAL_CALL ValueItemAcc::getA
         //      pStateSet->AddState( accessibility::AccessibleStateType::FOCUSABLE );
 
         // SELECTED
-        if( mpParent->mpParent->GetSelectedItemId() == mpParent->mnId )
+        if( mpParent->mrParent.GetSelectedItemId() == mpParent->mnId )
         {
             pStateSet->AddState( accessibility::AccessibleStateType::SELECTED );
             //              pStateSet->AddState( accessibility::AccessibleStateType::FOCUSED );
@@ -319,8 +319,8 @@ awt::Rectangle SAL_CALL ValueItemAcc::getBounds()
 
     if( mpParent )
     {
-        tools::Rectangle   aRect( mpParent->mpParent->GetItemRect(mpParent->mnId) );
-        tools::Rectangle   aParentRect( Point(), mpParent->mpParent->GetOutputSizePixel() );
+        tools::Rectangle   aRect( mpParent->mrParent.GetItemRect(mpParent->mnId) );
+        tools::Rectangle   aParentRect( Point(), mpParent->mrParent.GetOutputSizePixel() );
 
         aRect.Intersection( aParentRect );
 
@@ -351,8 +351,8 @@ awt::Point SAL_CALL ValueItemAcc::getLocationOnScreen()
 
     if( mpParent )
     {
-        const Point aPos = mpParent->mpParent->GetItemRect(mpParent->mnId).TopLeft();
-        const Point aScreenPos(mpParent->mpParent->GetDrawingArea()->get_accessible_location_on_screen());
+        const Point aPos = mpParent->mrParent.GetItemRect(mpParent->mnId).TopLeft();
+        const Point aScreenPos(mpParent->mrParent.GetDrawingArea()->get_accessible_location_on_screen());
 
         aRet.X = aPos.X() + aScreenPos.X();
         aRet.Y = aPos.Y() + aScreenPos.Y();
@@ -729,8 +729,8 @@ uno::Reference< accessibility::XAccessible > SAL_CALL ValueSetAcc::getAccessible
 
         if( VALUESET_ITEM_NONEITEM != nItemPos )
         {
-            ValueSetItem & rItem = mpParent->mItemList[nItemPos];
-            xRet = rItem.GetAccessible( false/*bIsTransientChildrenDisabled*/ );
+            ValueSetItem *const pItem = mpParent->mItemList[nItemPos].get();
+            xRet = pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/ );
         }
     }
 
diff --git a/svtools/source/control/valueimp.hxx b/svtools/source/control/valueimp.hxx
index 367debaf75e9..b980cb1f5c90 100644
--- a/svtools/source/control/valueimp.hxx
+++ b/svtools/source/control/valueimp.hxx
@@ -50,7 +50,7 @@ class ValueSet;
 
 struct ValueSetItem
 {
-    ValueSet*           mpParent;
+    ValueSet&        mrParent;
     sal_uInt16          mnId;
     sal_uInt8           meType;
     bool                mbVisible;
@@ -62,10 +62,6 @@ struct ValueSetItem
 
     explicit ValueSetItem( ValueSet& rParent );
     ~ValueSetItem();
-    ValueSetItem( const ValueSetItem& ) = default;
-    ValueSetItem( ValueSetItem&& ) = default;
-    ValueSetItem& operator=( const ValueSetItem& ) = default;
-    ValueSetItem& operator=( ValueSetItem&& ) = default;
 
     css::uno::Reference< css::accessibility::XAccessible >
                         GetAccessible( bool bIsTransientChildrenDisabled );
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index a2e3159f1e9b..9e14b49dbe46 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -138,15 +138,17 @@ void ValueSet::ImplDeleteItems()
 
     for ( size_t i = 0; i < n; ++i )
     {
-        ValueSetItem& rItem = mItemList[i];
-        if ( rItem.mbVisible && ImplHasAccessibleListeners() )
+        ValueSetItem* pItem = mItemList[i].get();
+        if ( pItem->mbVisible && ImplHasAccessibleListeners() )
         {
             Any aOldAny;
             Any aNewAny;
 
-            aOldAny <<= rItem.GetAccessible( false/*bIsTransientChildrenDisabled*/ );
+            aOldAny <<= pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/ );
             ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny);
         }
+
+        mItemList[i].reset();
     }
 
     mItemList.clear();
@@ -204,12 +206,12 @@ ValueSetItem* ValueSet::ImplGetItem( size_t nPos )
     if (nPos == VALUESET_ITEM_NONEITEM)
         return mpNoneItem.get();
     else
-        return (nPos < mItemList.size()) ? &mItemList[nPos] : nullptr;
+        return (nPos < mItemList.size()) ? mItemList[nPos].get() : nullptr;
 }
 
 ValueSetItem* ValueSet::ImplGetFirstItem()
 {
-    return !mItemList.empty() ? mItemList.data() : nullptr;
+    return !mItemList.empty() ? mItemList[0].get() : nullptr;
 }
 
 sal_uInt16 ValueSet::ImplGetVisibleItemCount() const
@@ -219,7 +221,7 @@ sal_uInt16 ValueSet::ImplGetVisibleItemCount() const
 
     for ( size_t n = 0; n < nItemCount; ++n )
     {
-        if ( mItemList[n].mbVisible )
+        if ( mItemList[n]->mbVisible )
             ++nRet;
     }
 
@@ -612,7 +614,7 @@ size_t ValueSet::GetItemCount() const
 size_t ValueSet::GetItemPos( sal_uInt16 nItemId ) const
 {
     for ( size_t i = 0, n = mItemList.size(); i < n; ++i ) {
-        if ( mItemList[i].mnId == nItemId ) {
+        if ( mItemList[i]->mnId == nItemId ) {
             return i;
         }
     }
@@ -621,7 +623,7 @@ size_t ValueSet::GetItemPos( sal_uInt16 nItemId ) const
 
 sal_uInt16 ValueSet::GetItemId( size_t nPos ) const
 {
-    return ( nPos < mItemList.size() ) ? mItemList[nPos].mnId : 0 ;
+    return ( nPos < mItemList.size() ) ? mItemList[nPos]->mnId : 0 ;
 }
 
 sal_uInt16 ValueSet::GetItemId( const Point& rPos ) const
@@ -637,7 +639,7 @@ tools::Rectangle ValueSet::GetItemRect( sal_uInt16 nItemId ) const
 {
     const size_t nPos = GetItemPos( nItemId );
 
-    if ( nPos!=VALUESET_ITEM_NOTFOUND && mItemList[nPos].mbVisible )
+    if ( nPos!=VALUESET_ITEM_NOTFOUND && mItemList[nPos]->mbVisible )
         return ImplGetItemRect( nPos );
 
     return tools::Rectangle();
@@ -810,7 +812,7 @@ void ValueSet::SelectItem( sal_uInt16 nItemId )
         if( nPos != VALUESET_ITEM_NOTFOUND )
         {
             ValueItemAcc* pItemAcc = ValueItemAcc::getImplementation(
-                mItemList[nPos].GetAccessible( false/*bIsTransientChildrenDisabled*/ ) );
+                mItemList[nPos]->GetAccessible( false/*bIsTransientChildrenDisabled*/ ) );
 
             if( pItemAcc )
             {
@@ -827,7 +829,7 @@ void ValueSet::SelectItem( sal_uInt16 nItemId )
 
     ValueSetItem* pItem;
     if( nPos != VALUESET_ITEM_NOTFOUND )
-        pItem = &mItemList[nPos];
+        pItem = mItemList[nPos].get();
     else
         pItem = mpNoneItem.get();
 
@@ -1025,7 +1027,7 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
 
         for (size_t i = 0; i < nItemCount; i++)
         {
-            mItemList[i].mbVisible = false;
+            mItemList[i]->mbVisible = false;
         }
 
         if (mxScrolledWindow && mxScrolledWindow->get_vpolicy() != VclPolicyType::NEVER)
@@ -1103,7 +1105,7 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
             maNoneItemRect.SetRight( maNoneItemRect.Left() + aWinSize.Width() - x - 1 );
             maNoneItemRect.SetBottom( y + nNoneHeight - 1 );
 
-            ImplFormatItem(rRenderContext, *mpNoneItem, maNoneItemRect);
+            ImplFormatItem(rRenderContext, mpNoneItem.get(), maNoneItemRect);
 
             y += nNoneHeight + nNoneSpace;
         }
@@ -1128,21 +1130,21 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
         }
         for (size_t i = 0; i < nItemCount; i++)
         {
-            ValueSetItem& rItem = mItemList[i];
+            ValueSetItem* pItem = mItemList[i].get();
 
             if (i >= nFirstItem && i < nLastItem)
             {
-                if (!rItem.mbVisible && ImplHasAccessibleListeners())
+                if (!pItem->mbVisible && ImplHasAccessibleListeners())
                 {
                     Any aOldAny;
                     Any aNewAny;
 
-                    aNewAny <<= rItem.GetAccessible(false/*bIsTransientChildrenDisabled*/);
+                    aNewAny <<= pItem->GetAccessible(false/*bIsTransientChildrenDisabled*/);
                     ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny);
                 }
 
-                rItem.mbVisible = true;
-                ImplFormatItem(rRenderContext, rItem, tools::Rectangle(Point(x, y), Size(mnItemWidth, mnItemHeight)));
+                pItem->mbVisible = true;
+                ImplFormatItem(rRenderContext, pItem, tools::Rectangle(Point(x, y), Size(mnItemWidth, mnItemHeight)));
 
                 if (!((i + 1) % mnCols))
                 {
@@ -1154,16 +1156,16 @@ void ValueSet::Format(vcl::RenderContext const & rRenderContext)
             }
             else
             {
-                if (rItem.mbVisible && ImplHasAccessibleListeners())
+                if (pItem->mbVisible && ImplHasAccessibleListeners())
                 {
                     Any aOldAny;
                     Any aNewAny;
 
-                    aOldAny <<= rItem.GetAccessible(false/*bIsTransientChildrenDisabled*/);
+                    aOldAny <<= pItem->GetAccessible(false/*bIsTransientChildrenDisabled*/);
                     ImplFireAccessibleEvent(AccessibleEventId::CHILD, aOldAny, aNewAny);
                 }
 
-                rItem.mbVisible = false;
+                pItem->mbVisible = false;
             }
         }
 
@@ -1217,7 +1219,7 @@ void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nIt
     if (nItemId)
     {
         const size_t nPos = GetItemPos( nItemId );
-        pItem = &mItemList[ nPos ];
+        pItem = mItemList[ nPos ].get();
         aRect = ImplGetItemRect( nPos );
     }
     else if (mpNoneItem)
@@ -1330,7 +1332,7 @@ void ValueSet::ImplDrawSelect(vcl::RenderContext& rRenderContext, sal_uInt16 nIt
     ImplDrawItemText(rRenderContext, pItem->maText);
 }
 
-void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem& rItem, tools::Rectangle aRect)
+void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSetItem* pItem, tools::Rectangle aRect)
 {
     WinBits nStyle = GetStyle();
     if (nStyle & WB_ITEMBORDER)
@@ -1356,15 +1358,15 @@ void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSe
         }
     }
 
-    if (&rItem == mpNoneItem.get())
-        rItem.maText = GetText();
+    if (pItem == mpNoneItem.get())
+        pItem->maText = GetText();
 
     if ((aRect.GetHeight() <= 0) || (aRect.GetWidth() <= 0))
         return;
 
     const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
 
-    if (&rItem == mpNoneItem.get())
+    if (pItem == mpNoneItem.get())
     {
         maVirDev->SetFont(rRenderContext.GetFont());
         maVirDev->SetTextColor((nStyle & WB_MENUSTYLEVALUESET) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor());
@@ -1372,19 +1374,19 @@ void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSe
         maVirDev->SetFillColor((nStyle & WB_MENUSTYLEVALUESET) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor());
         maVirDev->DrawRect(aRect);
         Point aTxtPos(aRect.Left() + 2, aRect.Top());
-        tools::Long nTxtWidth = rRenderContext.GetTextWidth(rItem.maText);
+        tools::Long nTxtWidth = rRenderContext.GetTextWidth(pItem->maText);
         if ((aTxtPos.X() + nTxtWidth) > aRect.Right())
         {
             maVirDev->SetClipRegion(vcl::Region(aRect));
-            maVirDev->DrawText(aTxtPos, rItem.maText);
+            maVirDev->DrawText(aTxtPos, pItem->maText);
             maVirDev->SetClipRegion();
         }
         else
-            maVirDev->DrawText(aTxtPos, rItem.maText);
+            maVirDev->DrawText(aTxtPos, pItem->maText);
     }
-    else if (rItem.meType == VALUESETITEM_COLOR)
+    else if (pItem->meType == VALUESETITEM_COLOR)
     {
-        maVirDev->SetFillColor(rItem.maColor);
+        maVirDev->SetFillColor(pItem->maColor);
         maVirDev->DrawRect(aRect);
     }
     else
@@ -1399,19 +1401,19 @@ void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSe
             maVirDev->SetFillColor(rStyleSettings.GetFaceColor());
         maVirDev->DrawRect(aRect);
 
-        if (rItem.meType == VALUESETITEM_USERDRAW)
+        if (pItem->meType == VALUESETITEM_USERDRAW)
         {
-            UserDrawEvent aUDEvt(maVirDev.get(), aRect, rItem.mnId);
+            UserDrawEvent aUDEvt(maVirDev.get(), aRect, pItem->mnId);
             UserDraw(aUDEvt);
         }
         else
         {
-            Size aImageSize = rItem.maImage.GetSizePixel();
+            Size aImageSize = pItem->maImage.GetSizePixel();
             Size  aRectSize = aRect.GetSize();
             Point aPos(aRect.Left(), aRect.Top());
             aPos.AdjustX((aRectSize.Width() - aImageSize.Width()) / 2 );
 
-            if (rItem.meType != VALUESETITEM_IMAGE_AND_TEXT)
+            if (pItem->meType != VALUESETITEM_IMAGE_AND_TEXT)
                 aPos.AdjustY((aRectSize.Height() - aImageSize.Height()) / 2 );
 
             DrawImageFlags  nImageStyle  = DrawImageFlags::NONE;
@@ -1422,19 +1424,19 @@ void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSe
                 aImageSize.Height() > aRectSize.Height())
             {
                 maVirDev->SetClipRegion(vcl::Region(aRect));
-                maVirDev->DrawImage(aPos, rItem.maImage, nImageStyle);
+                maVirDev->DrawImage(aPos, pItem->maImage, nImageStyle);
                 maVirDev->SetClipRegion();
             }
             else
-                maVirDev->DrawImage(aPos, rItem.maImage, nImageStyle);
+                maVirDev->DrawImage(aPos, pItem->maImage, nImageStyle);
 
-            if (rItem.meType == VALUESETITEM_IMAGE_AND_TEXT)
+            if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT)
             {
                 maVirDev->SetFont(rRenderContext.GetFont());
                 maVirDev->SetTextColor((nStyle & WB_MENUSTYLEVALUESET) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor());
                 maVirDev->SetTextFillColor();
 
-                tools::Long nTxtWidth = maVirDev->GetTextWidth(rItem.maText);
+                tools::Long nTxtWidth = maVirDev->GetTextWidth(pItem->maText);
 
                 if (nTxtWidth > aRect.GetWidth())
                     maVirDev->SetClipRegion(vcl::Region(aRect));
@@ -1442,7 +1444,7 @@ void ValueSet::ImplFormatItem(vcl::RenderContext const & rRenderContext, ValueSe
                 maVirDev->DrawText(Point(aRect.Left() +
                                          (aRect.GetWidth() - nTxtWidth) / 2,
                                          aRect.Bottom() - maVirDev->GetTextHeight()),
-                                   rItem.maText);
+                                   pItem->maText);
 
                 if (nTxtWidth > aRect.GetWidth())
                     maVirDev->SetClipRegion();
@@ -1520,9 +1522,9 @@ void ValueSet::SetItemImage( sal_uInt16 nItemId, const Image& rImage )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem& rItem = mItemList[nPos];
-    rItem.meType  = VALUESETITEM_IMAGE;
-    rItem.maImage = rImage;
+    ValueSetItem* pItem = mItemList[nPos].get();
+    pItem->meType  = VALUESETITEM_IMAGE;
+    pItem->maImage = rImage;
 
     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
     {
@@ -1540,9 +1542,9 @@ void ValueSet::SetItemColor( sal_uInt16 nItemId, const Color& rColor )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem& rItem = mItemList[nPos];
-    rItem.meType  = VALUESETITEM_COLOR;
-    rItem.maColor = rColor;
+    ValueSetItem* pItem = mItemList[nPos].get();
+    pItem->meType  = VALUESETITEM_COLOR;
+    pItem->maColor = rColor;
 
     if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
     {
@@ -1558,7 +1560,7 @@ Color ValueSet::GetItemColor( sal_uInt16 nItemId ) const
     size_t nPos = GetItemPos( nItemId );
 
     if ( nPos != VALUESET_ITEM_NOTFOUND )
-        return mItemList[nPos].maColor;
+        return mItemList[nPos]->maColor;
     else
         return Color();
 }
@@ -1636,54 +1638,54 @@ Size ValueSet::CalcWindowSizePixel( const Size& rItemSize, sal_uInt16 nDesireCol
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage )
 {
-    ValueSetItem aItem(*this);
-    aItem.mnId     = nItemId;
-    aItem.meType   = VALUESETITEM_IMAGE;
-    aItem.maImage  = rImage;
-    ImplInsertItem( aItem, VALUESET_APPEND );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
+    pItem->mnId     = nItemId;
+    pItem->meType   = VALUESETITEM_IMAGE;
+    pItem->maImage  = rImage;
+    ImplInsertItem( std::move(pItem), VALUESET_APPEND );
 }
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage,
                            const OUString& rText, size_t nPos,
                            bool bShowLegend )
 {
-    ValueSetItem aItem( *this );
-    aItem.mnId     = nItemId;
-    aItem.meType   = bShowLegend ? VALUESETITEM_IMAGE_AND_TEXT : VALUESETITEM_IMAGE;
-    aItem.maImage  = rImage;
-    aItem.maText   = rText;
-    ImplInsertItem( aItem, nPos );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
+    pItem->mnId     = nItemId;
+    pItem->meType   = bShowLegend ? VALUESETITEM_IMAGE_AND_TEXT : VALUESETITEM_IMAGE;
+    pItem->maImage  = rImage;
+    pItem->maText   = rText;
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, size_t nPos )
 {
-    ValueSetItem aItem(*this );
-    aItem.mnId     = nItemId;
-    aItem.meType   = VALUESETITEM_USERDRAW;
-    ImplInsertItem( aItem, nPos );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
+    pItem->mnId     = nItemId;
+    pItem->meType   = VALUESETITEM_USERDRAW;
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void ValueSet::InsertItem( sal_uInt16 nItemId, const Color& rColor,
                            const OUString& rText )
 {
-    ValueSetItem aItem( *this );
-    aItem.mnId     = nItemId;
-    aItem.meType   = VALUESETITEM_COLOR;
-    aItem.maColor  = rColor;
-    aItem.maText   = rText;
-    ImplInsertItem( aItem, VALUESET_APPEND );
+    std::unique_ptr<ValueSetItem> pItem(new ValueSetItem( *this ));
+    pItem->mnId     = nItemId;
+    pItem->meType   = VALUESETITEM_COLOR;
+    pItem->maColor  = rColor;
+    pItem->maText   = rText;
+    ImplInsertItem( std::move(pItem), VALUESET_APPEND );
 }
 
-void ValueSet::ImplInsertItem( const ValueSetItem& rItem, const size_t nPos )
+void ValueSet::ImplInsertItem( std::unique_ptr<ValueSetItem> pItem, const size_t nPos )
 {
-    DBG_ASSERT( rItem.mnId, "ValueSet::InsertItem(): ItemId == 0" );
-    DBG_ASSERT( GetItemPos( rItem.mnId ) == VALUESET_ITEM_NOTFOUND,
+    DBG_ASSERT( pItem->mnId, "ValueSet::InsertItem(): ItemId == 0" );
+    DBG_ASSERT( GetItemPos( pItem->mnId ) == VALUESET_ITEM_NOTFOUND,
                 "ValueSet::InsertItem(): ItemId already exists" );
 
     if ( nPos < mItemList.size() ) {
-        mItemList.insert( mItemList.begin() + nPos, rItem );
+        mItemList.insert( mItemList.begin() + nPos, std::move(pItem) );
     } else {
-        mItemList.push_back( rItem );
+        mItemList.push_back( std::move(pItem) );
     }
 
     QueueReformat();
@@ -1759,7 +1761,7 @@ void ValueSet::InsertItem( sal_uInt16 nItemId, const OUString& rText, size_t nPo
     pItem->mnId     = nItemId;
     pItem->meType   = VALUESETITEM_USERDRAW;
     pItem->maText   = rText;
-    ImplInsertItem( *pItem, nPos );
+    ImplInsertItem( std::move(pItem), nPos );
 }
 
 void ValueSet::SetItemHeight( tools::Long nNewItemHeight )
@@ -1789,7 +1791,7 @@ OUString ValueSet::GetItemText(sal_uInt16 nItemId) const
     const size_t nPos = GetItemPos(nItemId);
 
     if ( nPos != VALUESET_ITEM_NOTFOUND )
-        return mItemList[nPos].maText;
+        return mItemList[nPos]->maText;
 
     return OUString();
 }
@@ -1815,10 +1817,10 @@ void ValueSet::SetItemData( sal_uInt16 nItemId, void* pData )
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem& rItem = mItemList[nPos];
-    rItem.mpData = pData;
+    ValueSetItem* pItem = mItemList[nPos].get();
+    pItem->mpData = pData;
 
-    if ( rItem.meType == VALUESETITEM_USERDRAW )
+    if ( pItem->meType == VALUESETITEM_USERDRAW )
     {
         if ( !mbFormat && IsReallyVisible() && IsUpdateMode() )
         {
@@ -1835,7 +1837,7 @@ void* ValueSet::GetItemData( sal_uInt16 nItemId ) const
     size_t nPos = GetItemPos( nItemId );
 
     if ( nPos != VALUESET_ITEM_NOTFOUND )
-        return mItemList[nPos].mpData;
+        return mItemList[nPos]->mpData;
     else
         return nullptr;
 }
@@ -1847,15 +1849,17 @@ void ValueSet::SetItemText(sal_uInt16 nItemId, const OUString& rText)
     if ( nPos == VALUESET_ITEM_NOTFOUND )
         return;
 
-    ValueSetItem& rItem = mItemList[nPos];
+    ValueSetItem* pItem = mItemList[nPos].get();
 
     // Remember old and new name for accessibility event.
     Any aOldName;
     Any aNewName;
-    aOldName <<= rItem.maText;
-    aNewName <<= rText;
+    OUString sString (pItem->maText);
+    aOldName <<= sString;
+    sString = rText;
+    aNewName <<= sString;
 
-    rItem.maText = rText;
+    pItem->maText = rText;
 
     if (!mbFormat && IsReallyVisible() && IsUpdateMode())
     {
@@ -1870,7 +1874,7 @@ void ValueSet::SetItemText(sal_uInt16 nItemId, const OUString& rText)
 
     if (ImplHasAccessibleListeners())
     {
-        Reference<XAccessible> xAccessible(rItem.GetAccessible( false/*bIsTransientChildrenDisabled*/));
+        Reference<XAccessible> xAccessible(pItem->GetAccessible( false/*bIsTransientChildrenDisabled*/));
         ValueItemAcc* pValueItemAcc = static_cast<ValueItemAcc*>(xAccessible.get());
         pValueItemAcc->FireAccessibleEvent(AccessibleEventId::NAME_CHANGED, aOldName, aNewName);
     }
@@ -1880,25 +1884,25 @@ Size ValueSet::GetLargestItemSize()
 {
     Size aLargestItem;
 
-    for (const ValueSetItem& rItem : mItemList)
+    for (const std::unique_ptr<ValueSetItem>& pItem : mItemList)
     {
-        if (!rItem.mbVisible)
+        if (!pItem->mbVisible)
             continue;
 
-        if (rItem.meType != VALUESETITEM_IMAGE &&
-            rItem.meType != VALUESETITEM_IMAGE_AND_TEXT)
+        if (pItem->meType != VALUESETITEM_IMAGE &&
+            pItem->meType != VALUESETITEM_IMAGE_AND_TEXT)
         {
             // handle determining an optimal size for this case
             continue;
         }
 
-        Size aSize = rItem.maImage.GetSizePixel();
-        if (rItem.meType == VALUESETITEM_IMAGE_AND_TEXT)
+        Size aSize = pItem->maImage.GetSizePixel();
+        if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT)
         {
             aSize.AdjustHeight(3 * NAME_LINE_HEIGHT +
                 maVirDev->GetTextHeight() );
             aSize.setWidth( std::max(aSize.Width(),
-                                     maVirDev->GetTextWidth(rItem.maText) + NAME_OFFSET) );
+                                     maVirDev->GetTextWidth(pItem->maText) + NAME_OFFSET) );
         }
 
         aLargestItem.setWidth( std::max(aLargestItem.Width(), aSize.Width()) );
@@ -1922,7 +1926,7 @@ Image ValueSet::GetItemImage(sal_uInt16 nItemId) const
     size_t nPos = GetItemPos( nItemId );
 
     if ( nPos != VALUESET_ITEM_NOTFOUND )
-        return mItemList[nPos].maImage;
+        return mItemList[nPos]->maImage;
     else
         return Image();
 }


More information about the Libreoffice-commits mailing list