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

Mike Kaganski mike.kaganski at collabora.com
Fri Feb 23 06:15:51 UTC 2018


 cui/source/tabpages/borderconn.cxx |    7 +++++
 include/sfx2/controlwrapper.hxx    |    7 +++++
 include/sfx2/itemconnect.hxx       |   17 ++++++++------
 sfx2/source/dialog/tabdlg.cxx      |   44 +++++++++++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 8 deletions(-)

New commits:
commit b37a46fdf91dbc66f6ddc1c070aec70716d94a01
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Wed Feb 21 11:25:16 2018 +0300

    tdf#115938: Properly detect shadow size control's changed state
    
    This change makes sure that only if the shadow size edit box' text
    is changed, it is converted to the size in twips. It sets wrapper's
    default value on each SetControlValue, to return proper initial
    size when the size text wasn't modified.
    
    Also both ExampleSet and OutSet in SfxTabDialog's Reset handler are
    processed to set relevant items back to initial value; otherwise,
    as the restored item (marked as unchanged) will be absent in tab's
    result set, it would not modify the old items in the two, and they
    would keep previous modified values.
    
    Change-Id: Ie4362811968c6e6cbe0f9229bd3c9b29462f5704
    Reviewed-on: https://gerrit.libreoffice.org/50196
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/cui/source/tabpages/borderconn.cxx b/cui/source/tabpages/borderconn.cxx
index 90b6b2f1b41e..7b49f35022f1 100644
--- a/cui/source/tabpages/borderconn.cxx
+++ b/cui/source/tabpages/borderconn.cxx
@@ -230,7 +230,10 @@ SvxShadowItem ShadowControlsWrapper::GetControlValue() const
     SvxShadowItem aItem( GetDefaultValue() );
     if( !maPosWrp.IsControlDontKnow() )
         aItem.SetLocation( maPosWrp.GetControlValue() );
-    if( !maSizeWrp.IsControlDontKnow() )
+    // Default value was saved; so don't change the aItem's width if the control
+    // has not changed its value, to avoid round-trip errors (like twip->cm->twip)
+    // E.g., initial 100 twip will become 0.18 cm, which will return as 102 twip
+    if( !maSizeWrp.IsControlDontKnow() && maSizeWrp.IsControlValueChanged() )
         aItem.SetWidth( maSizeWrp.GetControlValue() );
     if( !maColorWrp.IsControlDontKnow() )
         aItem.SetColor( maColorWrp.GetControlValue() );
@@ -239,8 +242,10 @@ SvxShadowItem ShadowControlsWrapper::GetControlValue() const
 
 void ShadowControlsWrapper::SetControlValue( SvxShadowItem aItem )
 {
+    SetDefaultValue(aItem);
     maPosWrp.SetControlValue( aItem.GetLocation() );
     maSizeWrp.SetControlValue( aItem.GetWidth() );
+    maSizeWrp.GetControl().SaveValue();
     maColorWrp.SetControlValue( aItem.GetColor() );
 }
 
diff --git a/include/sfx2/controlwrapper.hxx b/include/sfx2/controlwrapper.hxx
index c130ae1c7328..746a0821a9a8 100644
--- a/include/sfx2/controlwrapper.hxx
+++ b/include/sfx2/controlwrapper.hxx
@@ -259,6 +259,7 @@ public:
 
     virtual ValueT      GetControlValue() const SAL_OVERRIDE;
     virtual void        SetControlValue( ValueT nValue ) SAL_OVERRIDE;
+    bool                IsControlValueChanged() const;
 
 private:
     FieldUnit           meUnit;
@@ -480,6 +481,12 @@ void MetricFieldWrapper< ValueT >::SetControlValue( ValueT nValue )
     this->GetControl().SetValue( this->GetControl().Normalize( static_cast< sal_Int64 >( nValue ) ), meUnit );
 }
 
+template< typename ValueT >
+bool MetricFieldWrapper< ValueT >::IsControlValueChanged() const
+{
+    return this->GetControl().IsValueChangedFromSaved();
+}
+
 
 template< typename ValueT >
 ValueT ListBoxWrapper< ValueT >::GetControlValue() const
diff --git a/include/sfx2/itemconnect.hxx b/include/sfx2/itemconnect.hxx
index a14361103bce..a4a122cddaac 100644
--- a/include/sfx2/itemconnect.hxx
+++ b/include/sfx2/itemconnect.hxx
@@ -243,6 +243,7 @@ protected:
 
     ItemWrapperType     maItemWrp;
     std::unique_ptr<ControlWrpT>   mxCtrlWrp;
+    bool                mbModified;
 };
 
 
@@ -393,7 +394,8 @@ ItemControlConnection< ItemWrpT, ControlWrpT >::ItemControlConnection(
         sal_uInt16 nSlot, ControlWrpT* pNewCtrlWrp, ItemConnFlags nFlags ) :
     ItemConnectionBase( nFlags ),
     maItemWrp( nSlot ),
-    mxCtrlWrp( pNewCtrlWrp )
+    mxCtrlWrp( pNewCtrlWrp ),
+    mbModified( false )
 {
 }
 
@@ -402,7 +404,8 @@ ItemControlConnection< ItemWrpT, ControlWrpT >::ItemControlConnection(
         sal_uInt16 nSlot, ControlType& rControl, ItemConnFlags nFlags ) :
     ItemConnectionBase( nFlags ),
     maItemWrp( nSlot ),
-    mxCtrlWrp( new ControlWrpT( rControl ) )
+    mxCtrlWrp( new ControlWrpT( rControl ) ),
+    mbModified( false )
 {
 }
 
@@ -425,6 +428,7 @@ void ItemControlConnection< ItemWrpT, ControlWrpT >::Reset( const SfxItemSet* pI
     mxCtrlWrp->SetControlDontKnow( pItem == nullptr );
     if( pItem )
         mxCtrlWrp->SetControlValue( maItemWrp.GetItemValue( *pItem ) );
+    mbModified = false;
 }
 
 template< typename ItemWrpT, typename ControlWrpT >
@@ -432,7 +436,6 @@ bool ItemControlConnection< ItemWrpT, ControlWrpT >::FillItemSet(
         SfxItemSet& rDestSet, const SfxItemSet& rOldSet )
 {
     const ItemType* pOldItem = maItemWrp.GetUniqueItem( rOldSet );
-    bool bChanged = false;
     if( !mxCtrlWrp->IsControlDontKnow() )
     {
         // first store the control value in a local variable
@@ -440,7 +443,7 @@ bool ItemControlConnection< ItemWrpT, ControlWrpT >::FillItemSet(
         // convert to item value type -> possible to convert i.e. from 'T' to 'const T&'
         ItemValueType aNewValue( aCtrlValue );
         // do not rely on existence of ItemValueType::operator!=
-        if( !pOldItem || !(maItemWrp.GetItemValue( *pOldItem ) == aNewValue) )
+        if( mbModified || !pOldItem || !(maItemWrp.GetItemValue( *pOldItem ) == aNewValue) )
         {
             sal_uInt16 nWhich = ItemWrapperHelper::GetWhichId( rDestSet, maItemWrp.GetSlotId() );
             std::unique_ptr< ItemType > xItem(
@@ -448,12 +451,12 @@ bool ItemControlConnection< ItemWrpT, ControlWrpT >::FillItemSet(
             xItem->SetWhich( nWhich );
             maItemWrp.SetItemValue( *xItem, aNewValue );
             rDestSet.Put( *xItem );
-            bChanged = true;
+            mbModified = true;
         }
     }
-    if( !bChanged )
+    if( !mbModified )
         ItemWrapperHelper::RemoveDefaultItem( rDestSet, rOldSet, maItemWrp.GetSlotId() );
-    return bChanged;
+    return mbModified;
 }
 
 
diff --git a/sfx2/source/dialog/tabdlg.cxx b/sfx2/source/dialog/tabdlg.cxx
index c707cccea6a8..4dfc47a248f3 100644
--- a/sfx2/source/dialog/tabdlg.cxx
+++ b/sfx2/source/dialog/tabdlg.cxx
@@ -962,6 +962,50 @@ IMPL_LINK_NOARG(SfxTabDialog, ResetHdl, Button*, void)
     DBG_ASSERT( pDataObject, "Id not known" );
 
     pDataObject->pTabPage->Reset( m_pSet );
+    // Also reset relevant items of ExampleSet and OutSet to initial state
+    if (pDataObject->fnGetRanges)
+    {
+        if (!m_pExampleSet)
+            m_pExampleSet = new SfxItemSet(*m_pSet);
+
+        const SfxItemPool* pPool = m_pSet->GetPool();
+        const sal_uInt16* pTmpRanges = (pDataObject->fnGetRanges)();
+
+        while (*pTmpRanges)
+        {
+            const sal_uInt16* pU = pTmpRanges + 1;
+
+            // Correct Range with multiple values
+            sal_uInt16 nTmp = *pTmpRanges, nTmpEnd = *pU;
+            DBG_ASSERT(nTmp <= nTmpEnd, "Range is sorted the wrong way");
+
+            if (nTmp > nTmpEnd)
+            {
+                // If really sorted wrongly, then set new
+                std::swap(nTmp, nTmpEnd);
+            }
+
+            while (nTmp && nTmp <= nTmpEnd)
+            {
+                // Iterate over the Range and set the Items
+                sal_uInt16 nWh = pPool->GetWhich(nTmp);
+                const SfxPoolItem* pItem;
+                if (SfxItemState::SET == m_pSet->GetItemState(nWh, false, &pItem))
+                {
+                    m_pExampleSet->Put(*pItem);
+                    m_pOutSet->Put(*pItem);
+                }
+                else
+                {
+                    m_pExampleSet->ClearItem(nWh);
+                    m_pOutSet->ClearItem(nWh);
+                }
+                nTmp++;
+            }
+            // Go to the next pair
+            pTmpRanges += 2;
+        }
+    }
 }
 
 


More information about the Libreoffice-commits mailing list