[Libreoffice-commits] core.git: sw/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 5 12:45:34 UTC 2020


 sw/source/ui/table/tabledlg.cxx    |  131 +++++++++++++++++++------------------
 sw/source/uibase/table/tablepg.hxx |    5 -
 2 files changed, 72 insertions(+), 64 deletions(-)

New commits:
commit 3326a3a07d7567852486d7f1a2355f1499a33dda
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Aug 4 21:08:08 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Aug 5 14:44:38 2020 +0200

    tdf#134925 keep a copy of the original SwTableRep to Reset back to
    
    instead of operating on a copy of the original SwTableRep and over
    writing the original at commit
    
    Change-Id: I5c42291302f8b4a3394adcdb3425524623f7a051
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100140
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/ui/table/tabledlg.cxx b/sw/source/ui/table/tabledlg.cxx
index c8f466728e80..082b23ee4214 100644
--- a/sw/source/ui/table/tabledlg.cxx
+++ b/sw/source/ui/table/tabledlg.cxx
@@ -456,6 +456,11 @@ void  SwFormatTablePage::Reset( const SfxItemSet* )
     if(SfxItemState::SET == rSet.GetItemState( FN_TABLE_REP, false, &pItem ))
     {
         pTableData = static_cast<SwTableRep*>(static_cast<const SwPtrItem*>( pItem)->GetValue());
+        if (!m_xOrigTableData)
+            m_xOrigTableData.reset(new SwTableRep(*pTableData));
+        else // tdf#134925 and tdf#134913, reset back to the original data seen on dialog creation
+            *pTableData = *m_xOrigTableData;
+
         nMinTableWidth = pTableData->GetColCount() * MINLAY;
 
         if(pTableData->GetWidthPercent())
@@ -707,7 +712,7 @@ DeactivateRC SwFormatTablePage::DeactivatePage( SfxItemSet* _pSet )
 //Description: Page column configuration
 SwTableColumnPage::SwTableColumnPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
     : SfxTabPage(pPage, pController, "modules/swriter/ui/tablecolumnpage.ui", "TableColumnPage", &rSet)
-    , m_pOrigTableData(nullptr)
+    , m_pTableData(nullptr)
     , m_pSizeHdlEvent(nullptr)
     , m_nTableWidth(0)
     , m_nMinWidth(MINLAY)
@@ -793,18 +798,22 @@ void  SwTableColumnPage::Reset( const SfxItemSet* )
     const SfxPoolItem* pItem;
     if(SfxItemState::SET == rSet.GetItemState( FN_TABLE_REP, false, &pItem ))
     {
-        m_pOrigTableData = static_cast<SwTableRep*>(static_cast<const SwPtrItem*>( pItem)->GetValue());
-        m_xTableData.reset(new SwTableRep(*m_pOrigTableData));
-        m_nNoOfVisibleCols = m_xTableData->GetColCount();
-        m_nNoOfCols = m_xTableData->GetAllColCount();
-        m_nTableWidth = m_xTableData->GetAlign() != text::HoriOrientation::FULL &&
-                            m_xTableData->GetAlign() != text::HoriOrientation::LEFT_AND_WIDTH?
-                        m_xTableData->GetWidth() : m_xTableData->GetSpace();
+        m_pTableData = static_cast<SwTableRep*>(static_cast<const SwPtrItem*>( pItem)->GetValue());
+        if (!m_xOrigTableData)
+            m_xOrigTableData.reset(new SwTableRep(*m_pTableData));
+        else // tdf#134925 and tdf#134913, reset back to the original data seen on dialog creation
+            *m_pTableData = *m_xOrigTableData;
+
+        m_nNoOfVisibleCols = m_pTableData->GetColCount();
+        m_nNoOfCols = m_pTableData->GetAllColCount();
+        m_nTableWidth = m_pTableData->GetAlign() != text::HoriOrientation::FULL &&
+                            m_pTableData->GetAlign() != text::HoriOrientation::LEFT_AND_WIDTH?
+                        m_pTableData->GetWidth() : m_pTableData->GetSpace();
 
         for( sal_uInt16 i = 0; i < m_nNoOfCols; i++ )
         {
-            if( m_xTableData->GetColumns()[i].nWidth  < m_nMinWidth )
-                    m_nMinWidth = m_xTableData->GetColumns()[i].nWidth;
+            if (m_pTableData->GetColumns()[i].nWidth  < m_nMinWidth)
+                m_nMinWidth = m_pTableData->GetColumns()[i].nWidth;
         }
         sal_Int64 nMinTwips = m_aFieldArr[0].NormalizePercent( m_nMinWidth );
         sal_Int64 nMaxTwips = m_aFieldArr[0].NormalizePercent( m_nTableWidth );
@@ -830,7 +839,6 @@ void  SwTableColumnPage::Reset( const SfxItemSet* )
         }
     }
     ActivatePage(rSet);
-
 }
 
 void  SwTableColumnPage::Init(bool bWeb)
@@ -916,7 +924,7 @@ bool SwTableColumnPage::FillItemSet( SfxItemSet* )
 
     if (m_bModified)
     {
-        m_xTableData->SetColsChanged();
+        m_pTableData->SetColsChanged();
     }
     return m_bModified;
 }
@@ -952,7 +960,7 @@ void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos )
 
     for( sal_uInt16 i = 0; i < m_nNoOfCols; i++ )
     {
-        nSum += (m_xTableData->GetColumns())[i].nWidth;
+        nSum += (m_pTableData->GetColumns())[i].nWidth;
     }
     SwTwips nDiff = nSum - m_nTableWidth;
 
@@ -1003,11 +1011,11 @@ void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos )
     {
         //Difference is balanced by the width of the table,
         //other columns remain unchanged.
-        OSL_ENSURE(nDiff <= m_xTableData->GetSpace() - m_nTableWidth, "wrong maximum" );
-        SwTwips nActSpace = m_xTableData->GetSpace() - m_nTableWidth;
+        OSL_ENSURE(nDiff <= m_pTableData->GetSpace() - m_nTableWidth, "wrong maximum" );
+        SwTwips nActSpace = m_pTableData->GetSpace() - m_nTableWidth;
         if(nDiff > nActSpace)
         {
-            m_nTableWidth = m_xTableData->GetSpace();
+            m_nTableWidth = m_pTableData->GetSpace();
             SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) - nDiff + nActSpace );
         }
         else
@@ -1019,11 +1027,11 @@ void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos )
     {
         //All columns will be changed proportionally with,
         //the table width is adjusted accordingly.
-        OSL_ENSURE(nDiff * m_nNoOfVisibleCols <= m_xTableData->GetSpace() - m_nTableWidth, "wrong maximum" );
+        OSL_ENSURE(nDiff * m_nNoOfVisibleCols <= m_pTableData->GetSpace() - m_nTableWidth, "wrong maximum" );
         long nAdd = nDiff;
-        if(nDiff * m_nNoOfVisibleCols > m_xTableData->GetSpace() - m_nTableWidth)
+        if(nDiff * m_nNoOfVisibleCols > m_pTableData->GetSpace() - m_nTableWidth)
         {
-            nAdd = (m_xTableData->GetSpace() - m_nTableWidth) / m_nNoOfVisibleCols;
+            nAdd = (m_pTableData->GetSpace() - m_nTableWidth) / m_nNoOfVisibleCols;
             SetVisibleWidth(nCurrentPos, GetVisibleWidth(nCurrentPos) - nDiff + nAdd );
             nDiff = nAdd;
         }
@@ -1050,7 +1058,7 @@ void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos )
 
     if (!m_bPercentMode)
     {
-        m_xSpaceED->set_value(m_xSpaceED->normalize(m_xTableData->GetSpace() - m_nTableWidth), FieldUnit::TWIP);
+        m_xSpaceED->set_value(m_xSpaceED->normalize(m_pTableData->GetSpace() - m_nTableWidth), FieldUnit::TWIP);
         m_xSpaceSFT->set_label(m_xSpaceED->get_text());
     }
     else
@@ -1065,26 +1073,26 @@ void SwTableColumnPage::UpdateCols( sal_uInt16 nCurrentPos )
 
 void SwTableColumnPage::ActivatePage( const SfxItemSet& )
 {
-    m_bPercentMode = m_xTableData->GetWidthPercent() != 0;
+    m_bPercentMode = m_pTableData->GetWidthPercent() != 0;
     for( sal_uInt16 i = 0; (i < m_nMetFields) && (i < m_nNoOfVisibleCols); i++ )
     {
-        m_aFieldArr[i].SetRefValue(m_xTableData->GetWidth());
+        m_aFieldArr[i].SetRefValue(m_pTableData->GetWidth());
         m_aFieldArr[i].ShowPercent( m_bPercentMode );
     }
 
-    const sal_uInt16 nTableAlign = m_xTableData->GetAlign();
-    if((text::HoriOrientation::FULL != nTableAlign && m_nTableWidth != m_xTableData->GetWidth()) ||
-    (text::HoriOrientation::FULL == nTableAlign && m_nTableWidth != m_xTableData->GetSpace()))
+    const sal_uInt16 nTableAlign = m_pTableData->GetAlign();
+    if((text::HoriOrientation::FULL != nTableAlign && m_nTableWidth != m_pTableData->GetWidth()) ||
+    (text::HoriOrientation::FULL == nTableAlign && m_nTableWidth != m_pTableData->GetSpace()))
     {
         m_nTableWidth = text::HoriOrientation::FULL == nTableAlign ?
-                                    m_xTableData->GetSpace() :
-                                        m_xTableData->GetWidth();
+                                    m_pTableData->GetSpace() :
+                                        m_pTableData->GetWidth();
         UpdateCols(0);
     }
     m_bModifyTable = true;
-    if (m_xTableData->GetWidthPercent() ||
+    if (m_pTableData->GetWidthPercent() ||
                 text::HoriOrientation::FULL == nTableAlign ||
-                        m_xTableData->IsLineSelected()  )
+                        m_pTableData->IsLineSelected()  )
         m_bModifyTable = false;
     if (m_bPercentMode)
     {
@@ -1102,7 +1110,7 @@ void SwTableColumnPage::ActivatePage( const SfxItemSet& )
     m_xProportionalCB->set_sensitive(!m_bPercentMode && m_bModifyTable );
 
     m_xSpaceED->set_value(m_xSpaceED->normalize(
-                m_xTableData->GetSpace() - m_nTableWidth), FieldUnit::TWIP);
+                m_pTableData->GetSpace() - m_nTableWidth), FieldUnit::TWIP);
     m_xSpaceSFT->set_label(m_xSpaceED->get_text());
 
 }
@@ -1112,60 +1120,59 @@ DeactivateRC SwTableColumnPage::DeactivatePage( SfxItemSet* _pSet )
     if(_pSet)
     {
         FillItemSet(_pSet);
-        if(text::HoriOrientation::FULL != m_xTableData->GetAlign() && m_xTableData->GetWidth() != m_nTableWidth)
+        if(text::HoriOrientation::FULL != m_pTableData->GetAlign() && m_pTableData->GetWidth() != m_nTableWidth)
         {
-            m_xTableData->SetWidth(m_nTableWidth);
-            SwTwips nDiff = m_xTableData->GetSpace() - m_xTableData->GetWidth() -
-                            m_xTableData->GetLeftSpace() - m_xTableData->GetRightSpace();
-            switch( m_xTableData->GetAlign()  )
+            m_pTableData->SetWidth(m_nTableWidth);
+            SwTwips nDiff = m_pTableData->GetSpace() - m_pTableData->GetWidth() -
+                            m_pTableData->GetLeftSpace() - m_pTableData->GetRightSpace();
+            switch( m_pTableData->GetAlign()  )
             {
                 case text::HoriOrientation::RIGHT:
-                    m_xTableData->SetLeftSpace(m_xTableData->GetLeftSpace() + nDiff);
+                    m_pTableData->SetLeftSpace(m_pTableData->GetLeftSpace() + nDiff);
                 break;
                 case text::HoriOrientation::LEFT:
-                    m_xTableData->SetRightSpace(m_xTableData->GetRightSpace() + nDiff);
+                    m_pTableData->SetRightSpace(m_pTableData->GetRightSpace() + nDiff);
                 break;
                 case text::HoriOrientation::NONE:
                 {
                     SwTwips nDiff2 = nDiff/2;
                     if( nDiff > 0 ||
-                        (-nDiff2 < m_xTableData->GetRightSpace() && - nDiff2 < m_xTableData->GetLeftSpace()))
+                        (-nDiff2 < m_pTableData->GetRightSpace() && - nDiff2 < m_pTableData->GetLeftSpace()))
                     {
-                        m_xTableData->SetRightSpace(m_xTableData->GetRightSpace() + nDiff2);
-                        m_xTableData->SetLeftSpace(m_xTableData->GetLeftSpace() + nDiff2);
+                        m_pTableData->SetRightSpace(m_pTableData->GetRightSpace() + nDiff2);
+                        m_pTableData->SetLeftSpace(m_pTableData->GetLeftSpace() + nDiff2);
                     }
                     else
                     {
-                        if(m_xTableData->GetRightSpace() > m_xTableData->GetLeftSpace())
+                        if(m_pTableData->GetRightSpace() > m_pTableData->GetLeftSpace())
                         {
-                            m_xTableData->SetLeftSpace(0);
-                            m_xTableData->SetRightSpace(m_xTableData->GetSpace() - m_xTableData->GetWidth());
+                            m_pTableData->SetLeftSpace(0);
+                            m_pTableData->SetRightSpace(m_pTableData->GetSpace() - m_pTableData->GetWidth());
                         }
                         else
                         {
-                            m_xTableData->SetRightSpace(0);
-                            m_xTableData->SetLeftSpace(m_xTableData->GetSpace() - m_xTableData->GetWidth());
+                            m_pTableData->SetRightSpace(0);
+                            m_pTableData->SetLeftSpace(m_pTableData->GetSpace() - m_pTableData->GetWidth());
                         }
                     }
                 }
                 break;
                 case text::HoriOrientation::CENTER:
-                    m_xTableData->SetRightSpace(m_xTableData->GetRightSpace() + nDiff/2);
-                    m_xTableData->SetLeftSpace(m_xTableData->GetLeftSpace() + nDiff/2);
+                    m_pTableData->SetRightSpace(m_pTableData->GetRightSpace() + nDiff/2);
+                    m_pTableData->SetLeftSpace(m_pTableData->GetLeftSpace() + nDiff/2);
                 break;
                 case text::HoriOrientation::LEFT_AND_WIDTH :
-                    if(nDiff > m_xTableData->GetRightSpace())
+                    if(nDiff > m_pTableData->GetRightSpace())
                     {
-                        m_xTableData->SetLeftSpace(m_xTableData->GetSpace() - m_xTableData->GetWidth());
+                        m_pTableData->SetLeftSpace(m_pTableData->GetSpace() - m_pTableData->GetWidth());
                     }
-                    m_xTableData->SetRightSpace(
-                        m_xTableData->GetSpace() - m_xTableData->GetWidth() - m_xTableData->GetLeftSpace());
+                    m_pTableData->SetRightSpace(
+                        m_pTableData->GetSpace() - m_pTableData->GetWidth() - m_pTableData->GetLeftSpace());
                 break;
             }
-            m_xTableData->SetWidthChanged();
+            m_pTableData->SetWidthChanged();
         }
-        *m_pOrigTableData = *m_xTableData;
-        _pSet->Put(SwPtrItem( FN_TABLE_REP, m_pOrigTableData ));
+        _pSet->Put(SwPtrItem( FN_TABLE_REP, m_pTableData ));
     }
     return DeactivateRC::LeavePage;
 }
@@ -1176,14 +1183,14 @@ SwTwips  SwTableColumnPage::GetVisibleWidth(sal_uInt16 nPos)
 
     while( nPos )
     {
-        if(m_xTableData->GetColumns()[i].bVisible)
+        if(m_pTableData->GetColumns()[i].bVisible)
             nPos--;
         i++;
     }
-    SwTwips nReturn = m_xTableData->GetColumns()[i].nWidth;
+    SwTwips nReturn = m_pTableData->GetColumns()[i].nWidth;
     OSL_ENSURE(i < m_nNoOfCols, "Array index out of range");
-    while(!m_xTableData->GetColumns()[i].bVisible && (i + 1) < m_nNoOfCols)
-        nReturn += m_xTableData->GetColumns()[++i].nWidth;
+    while(!m_pTableData->GetColumns()[i].bVisible && (i + 1) < m_nNoOfCols)
+        nReturn += m_pTableData->GetColumns()[++i].nWidth;
 
     return nReturn;
 }
@@ -1193,14 +1200,14 @@ void SwTableColumnPage::SetVisibleWidth(sal_uInt16 nPos, SwTwips nNewWidth)
     sal_uInt16 i=0;
     while( nPos )
     {
-        if(m_xTableData->GetColumns()[i].bVisible)
+        if(m_pTableData->GetColumns()[i].bVisible)
             nPos--;
         i++;
     }
     OSL_ENSURE(i < m_nNoOfCols, "Array index out of range");
-    m_xTableData->GetColumns()[i].nWidth = nNewWidth;
-    while(!m_xTableData->GetColumns()[i].bVisible && (i + 1) < m_nNoOfCols)
-        m_xTableData->GetColumns()[++i].nWidth = 0;
+    m_pTableData->GetColumns()[i].nWidth = nNewWidth;
+    while(!m_pTableData->GetColumns()[i].bVisible && (i + 1) < m_nNoOfCols)
+        m_pTableData->GetColumns()[++i].nWidth = 0;
 
 }
 
diff --git a/sw/source/uibase/table/tablepg.hxx b/sw/source/uibase/table/tablepg.hxx
index c00f7dafb547..438926aa1152 100644
--- a/sw/source/uibase/table/tablepg.hxx
+++ b/sw/source/uibase/table/tablepg.hxx
@@ -30,6 +30,7 @@ struct ImplSVEvent;
 class SwFormatTablePage : public SfxTabPage
 {
     SwTableRep*     pTableData;
+    std::unique_ptr<SwTableRep> m_xOrigTableData;
     SwTwips         nSaveWidth;
     SwTwips         nMinTableWidth;
     bool            bModified;
@@ -84,8 +85,8 @@ public:
 
 class SwTableColumnPage : public SfxTabPage
 {
-    SwTableRep*     m_pOrigTableData;
-    std::unique_ptr<SwTableRep> m_xTableData;
+    SwTableRep*     m_pTableData;
+    std::unique_ptr<SwTableRep> m_xOrigTableData;
     ImplSVEvent*    m_pSizeHdlEvent;
     SwTwips         m_nTableWidth;
     SwTwips         m_nMinWidth;


More information about the Libreoffice-commits mailing list