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

Caolán McNamara caolanm at redhat.com
Wed Dec 13 08:11:33 UTC 2017


 starmath/source/parse.cxx                                |  103 ++++++++-------
 sw/source/filter/html/htmlgrin.cxx                       |    6 
 sw/source/filter/html/htmltab.cxx                        |  103 ++++++---------
 sw/source/ui/index/cnttab.cxx                            |    8 -
 xmloff/source/text/XMLIndexIllustrationSourceContext.cxx |    2 
 xmloff/source/text/XMLIndexTemplateContext.cxx           |   14 --
 xmloff/source/text/XMLIndexTemplateContext.hxx           |    1 
 7 files changed, 120 insertions(+), 117 deletions(-)

New commits:
commit 6ca6d6ac912588a8f62d7e6b668ebec333752ebc
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Dec 7 09:35:08 2017 +0000

    Related: tdf#71737: allows links in more indexes
    
    tables, objects and user-defined
    
    Change-Id: I081446832ee86453227f4838552c88fd9e5cf75f
    Reviewed-on: https://gerrit.libreoffice.org/46326
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index ac3b7fc411d0..0fbc5b42f22d 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -2103,7 +2103,11 @@ void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& /*rSet*/)
         bool bToxIsAuthorities = TOX_AUTHORITIES == aCurType.eType;
         bool bToxIsIndex =       TOX_INDEX == aCurType.eType;
         bool bToxIsContent =     TOX_CONTENT == aCurType.eType;
-        bool bToxIsSequence =    TOX_ILLUSTRATIONS == aCurType.eType;
+        bool bToxSupportsLinks = TOX_CONTENT == aCurType.eType ||
+                                 TOX_ILLUSTRATIONS == aCurType.eType ||
+                                 TOX_TABLES == aCurType.eType ||
+                                 TOX_OBJECTS == aCurType.eType ||
+                                 TOX_USER == aCurType.eType;
 
         m_pLevelLB->Clear();
         for(sal_uInt16 i = 1; i < m_pCurrentForm->GetFormMax(); i++)
@@ -2173,7 +2177,7 @@ void SwTOXEntryTabPage::ActivatePage( const SfxItemSet& /*rSet*/)
 
         //show or hide controls
         m_pEntryNoPB->Show(bToxIsContent);
-        m_pHyperLinkPB->Show(bToxIsContent || bToxIsSequence);
+        m_pHyperLinkPB->Show(bToxSupportsLinks);
         m_pRelToStyleCB->Show(!bToxIsAuthorities);
         m_pChapterInfoPB->Show(!bToxIsContent && !bToxIsAuthorities);
         m_pEntryPB->Show(!bToxIsAuthorities);
diff --git a/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx b/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx
index 4e79914d4856..87fa6219b570 100644
--- a/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx
+++ b/xmloff/source/text/XMLIndexIllustrationSourceContext.cxx
@@ -63,7 +63,7 @@ SvXMLImportContextRef XMLIndexIllustrationSourceContext::CreateChildContext(
                                            aLevelNameTableMap,
                                            XML_TOKEN_INVALID, // no outline-level attr
                                            aLevelStylePropNameTableMap,
-                                           aIllustrationAllowedTokenTypesTable);
+                                           aAllowedTokenTypesTable);
     }
     else
     {
diff --git a/xmloff/source/text/XMLIndexTemplateContext.cxx b/xmloff/source/text/XMLIndexTemplateContext.cxx
index b538860afeeb..17d718fc6cdf 100644
--- a/xmloff/source/text/XMLIndexTemplateContext.cxx
+++ b/xmloff/source/text/XMLIndexTemplateContext.cxx
@@ -432,7 +432,7 @@ const SvXMLEnumMapEntry<sal_uInt16>* aLevelNameTableMap = nullptr;
 const sal_Char* aLevelStylePropNameTableMap[] =
     { nullptr, "ParaStyleLevel1", nullptr };
 
-const bool aIllustrationAllowedTokenTypesTable[] =
+const bool aAllowedTokenTypesTable[] =
 {
     true,       // XML_TOK_INDEX_TYPE_ENTRY_TEXT =
     true,       // XML_TOK_INDEX_TYPE_TAB_STOP,
@@ -444,16 +444,4 @@ const bool aIllustrationAllowedTokenTypesTable[] =
     false       // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY
 };
 
-const bool aAllowedTokenTypesTable[] =
-{
-    true,       // XML_TOK_INDEX_TYPE_ENTRY_TEXT =
-    true,       // XML_TOK_INDEX_TYPE_TAB_STOP,
-    true,       // XML_TOK_INDEX_TYPE_TEXT,
-    true,       // XML_TOK_INDEX_TYPE_PAGE_NUMBER,
-    true,       // XML_TOK_INDEX_TYPE_CHAPTER,
-    false,      // XML_TOK_INDEX_TYPE_LINK_START,
-    false,      // XML_TOK_INDEX_TYPE_LINK_END,
-    false       // XML_TOK_INDEX_TYPE_BIBLIOGRAPHY
-};
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/text/XMLIndexTemplateContext.hxx b/xmloff/source/text/XMLIndexTemplateContext.hxx
index b2907ef1efb3..03562ee91541 100644
--- a/xmloff/source/text/XMLIndexTemplateContext.hxx
+++ b/xmloff/source/text/XMLIndexTemplateContext.hxx
@@ -56,7 +56,6 @@ extern const bool aAllowedTokenTypesBibliography[];
 // table, illustration and object tables:
 extern const SvXMLEnumMapEntry<sal_uInt16>* aLevelNameTableMap; // NULL: no outline-level
 extern const sal_Char* aLevelStylePropNameTableMap[];
-extern const bool aIllustrationAllowedTokenTypesTable[];
 extern const bool aAllowedTokenTypesTable[];
 
 
commit 5c3317897b2ddd9f7144917685a4da2242fd1696
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Dec 12 15:24:46 2017 +0000

    ofz: fix leaks by exceptions
    
    Change-Id: Iad0987e9935ff02c80fea9dd7ebd4fdbe9fe2a9c
    Reviewed-on: https://gerrit.libreoffice.org/46317
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/starmath/source/parse.cxx b/starmath/source/parse.cxx
index 4a9dd64a0bc8..c9a6cfdf9c5d 100644
--- a/starmath/source/parse.cxx
+++ b/starmath/source/parse.cxx
@@ -1021,28 +1021,39 @@ SmLineNode *SmParser::DoLine()
     return pSNode.release();
 }
 
+namespace
+{
+    SmNodeArray buildNodeArray(std::vector<std::unique_ptr<SmNode>>& rSubNodes)
+    {
+        SmNodeArray aSubArray(rSubNodes.size());
+        for (size_t i = 0; i < rSubNodes.size(); ++i)
+            aSubArray[i] = rSubNodes[i].release();
+        return aSubArray;
+    }
+}
+
 SmNode *SmParser::DoExpression(bool bUseExtraSpaces)
 {
     DepthProtect aDepthGuard(m_nParseDepth);
     if (aDepthGuard.TooDeep())
         throw std::range_error("parser depth limit");
 
-    SmNodeArray  RelationArray;
-    RelationArray.push_back(DoRelation());
+    std::vector<std::unique_ptr<SmNode>> RelationArray;
+    RelationArray.emplace_back(std::unique_ptr<SmNode>(DoRelation()));
     while (m_aCurToken.nLevel >= 4)
-        RelationArray.push_back(DoRelation());
+        RelationArray.emplace_back(std::unique_ptr<SmNode>(DoRelation()));
 
     if (RelationArray.size() > 1)
     {
         std::unique_ptr<SmExpressionNode> pSNode(new SmExpressionNode(m_aCurToken));
-        pSNode->SetSubNodes(RelationArray);
+        pSNode->SetSubNodes(buildNodeArray(RelationArray));
         pSNode->SetUseExtraSpaces(bUseExtraSpaces);
         return pSNode.release();
     }
     else
     {
         // This expression has only one node so just push this node.
-        return RelationArray[0];
+        return RelationArray[0].release();
     }
 }
 
@@ -1070,16 +1081,16 @@ SmNode *SmParser::DoSum()
     if (aDepthGuard.TooDeep())
         throw std::range_error("parser depth limit");
 
-    SmNode *pFirst = DoProduct();
+    std::unique_ptr<SmNode> xFirst(DoProduct());
     while (TokenInGroup(TG::Sum))
     {
-        std::unique_ptr<SmStructureNode> pSNode(new SmBinHorNode(m_aCurToken));
-        SmNode *pSecond = DoOpSubSup();
-        SmNode *pThird = DoProduct();
-        pSNode->SetSubNodes(pFirst, pSecond, pThird);
-        pFirst = pSNode.release();
+        std::unique_ptr<SmStructureNode> xSNode(new SmBinHorNode(m_aCurToken));
+        std::unique_ptr<SmNode> xSecond(DoOpSubSup());
+        std::unique_ptr<SmNode> xThird(DoProduct());
+        xSNode->SetSubNodes(xFirst.release(), xSecond.release(), xThird.release());
+        xFirst = std::move(xSNode);
     }
-    return pFirst;
+    return xFirst.release();
 }
 
 SmNode *SmParser::DoProduct()
@@ -1088,37 +1099,38 @@ SmNode *SmParser::DoProduct()
     if (aDepthGuard.TooDeep())
         throw std::range_error("parser depth limit");
 
-    SmNode *pFirst = DoPower();
+    std::unique_ptr<SmNode> xFirst(DoPower());
 
     while (TokenInGroup(TG::Product))
-    {   SmStructureNode *pSNode;
-        SmNode *pOper;
+    {
+        std::unique_ptr<SmStructureNode> xSNode;
+        std::unique_ptr<SmNode> xOper;
         bool bSwitchArgs = false;
 
         SmTokenType eType = m_aCurToken.eType;
         switch (eType)
         {
             case TOVER:
-                pSNode = new SmBinVerNode(m_aCurToken);
-                pOper = new SmRectangleNode(m_aCurToken);
+                xSNode.reset(new SmBinVerNode(m_aCurToken));
+                xOper.reset(new SmRectangleNode(m_aCurToken));
                 NextToken();
                 break;
 
             case TBOPER:
-                pSNode = new SmBinHorNode(m_aCurToken);
+                xSNode.reset(new SmBinHorNode(m_aCurToken));
 
                 NextToken();
 
                 //Let the glyph node know it's a binary operation
                 m_aCurToken.eType = TBOPER;
                 m_aCurToken.nGroup = TG::Product;
-                pOper = DoGlyphSpecial();
+                xOper.reset(DoGlyphSpecial());
                 break;
 
             case TOVERBRACE :
             case TUNDERBRACE :
-                pSNode = new SmVerticalBraceNode(m_aCurToken);
-                pOper = new SmMathSymbolNode(m_aCurToken);
+                xSNode.reset(new SmVerticalBraceNode(m_aCurToken));
+                xOper.reset(new SmMathSymbolNode(m_aCurToken));
 
                 NextToken();
                 break;
@@ -1128,9 +1140,9 @@ SmNode *SmParser::DoProduct()
             {
                 SmBinDiagonalNode *pSTmp = new SmBinDiagonalNode(m_aCurToken);
                 pSTmp->SetAscending(eType == TWIDESLASH);
-                pSNode = pSTmp;
+                xSNode.reset(pSTmp);
 
-                pOper = new SmPolyLineNode(m_aCurToken);
+                xOper.reset(new SmPolyLineNode(m_aCurToken));
                 NextToken();
 
                 bSwitchArgs = true;
@@ -1138,29 +1150,30 @@ SmNode *SmParser::DoProduct()
             }
 
             default:
-                pSNode = new SmBinHorNode(m_aCurToken);
+                xSNode.reset(new SmBinHorNode(m_aCurToken));
 
-                pOper = DoOpSubSup();
+                xOper.reset(DoOpSubSup());
         }
 
-        SmNode *pArg = DoPower();
+        std::unique_ptr<SmNode> xArg(DoPower());
 
         if (bSwitchArgs)
         {
             //! vgl siehe SmBinDiagonalNode::Arrange
-            pSNode->SetSubNodes(pFirst, pArg, pOper);
+            xSNode->SetSubNodes(xFirst.release(), xArg.release(), xOper.release());
         }
         else
         {
-            pSNode->SetSubNodes(pFirst, pOper, pArg);
+            xSNode->SetSubNodes(xFirst.release(), xOper.release(), xArg.release());
         }
-        pFirst = pSNode;
+        xFirst = std::move(xSNode);
     }
-    return pFirst;
+    return xFirst.release();
 }
 
 SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
 {
+    std::unique_ptr<SmNode> xGivenNode(pGivenNode);
     DepthProtect aDepthGuard(m_nParseDepth);
     if (aDepthGuard.TooDeep())
         throw std::range_error("parser depth limit");
@@ -1177,13 +1190,14 @@ SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
     pNode->SetUseLimits(nActiveGroup == TG::Limit);
 
     // initialize subnodes array
-    SmNodeArray aSubNodes(1 + SUBSUP_NUM_ENTRIES, nullptr);
-    aSubNodes[0] = pGivenNode;
+    std::vector<std::unique_ptr<SmNode>> aSubNodes(1 + SUBSUP_NUM_ENTRIES);
+    aSubNodes[0] = std::move(xGivenNode);
 
     // process all sub-/supscripts
     int  nIndex = 0;
     while (TokenInGroup(nActiveGroup))
-    {   SmTokenType  eType (m_aCurToken.eType);
+    {
+        SmTokenType  eType (m_aCurToken.eType);
 
         switch (eType)
         {
@@ -1205,7 +1219,7 @@ SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
         if (aSubNodes[nIndex]) // if already occupied at earlier iteration
         {
             // forget the earlier one, remember an error instead
-            delete aSubNodes[nIndex];
+            aSubNodes[nIndex].reset();
             pENode.reset(DoError(SmParseError::DoubleSubsupscript)); // this also skips current token.
         }
         else
@@ -1226,10 +1240,10 @@ SmNode *SmParser::DoSubSup(TG nActiveGroup, SmNode *pGivenNode)
         else
             pSNode.reset(DoTerm(true));
 
-        aSubNodes[nIndex] = pENode ? pENode.release() : pSNode.release();
+        aSubNodes[nIndex] = std::move(pENode ? pENode : pSNode);
     }
 
-    pNode->SetSubNodes(aSubNodes);
+    pNode->SetSubNodes(buildNodeArray(aSubNodes));
     return pNode.release();
 }
 
@@ -2019,7 +2033,8 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight)
         throw std::range_error("parser depth limit");
 
     auto pBody = o3tl::make_unique<SmBracebodyNode>(m_aCurToken);
-    SmNodeArray aNodes;
+
+    std::vector<std::unique_ptr<SmNode>> aNodes;
     // get body if any
     if (bIsLeftRight)
     {
@@ -2027,14 +2042,14 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight)
         {
             if (m_aCurToken.eType == TMLINE)
             {
-                aNodes.push_back(new SmMathSymbolNode(m_aCurToken));
+                aNodes.emplace_back(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
                 NextToken();
             }
             else if (m_aCurToken.eType != TRIGHT)
             {
-                aNodes.push_back(DoAlign());
+                aNodes.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
                 if (m_aCurToken.eType != TMLINE  &&  m_aCurToken.eType != TRIGHT)
-                    aNodes.push_back(DoError(SmParseError::RightExpected));
+                    aNodes.emplace_back(std::unique_ptr<SmNode>(DoError(SmParseError::RightExpected)));
             }
         } while (m_aCurToken.eType != TEND  &&  m_aCurToken.eType != TRIGHT);
     }
@@ -2044,19 +2059,19 @@ SmBracebodyNode *SmParser::DoBracebody(bool bIsLeftRight)
         {
             if (m_aCurToken.eType == TMLINE)
             {
-                aNodes.push_back(new SmMathSymbolNode(m_aCurToken));
+                aNodes.emplace_back(o3tl::make_unique<SmMathSymbolNode>(m_aCurToken));
                 NextToken();
             }
             else if (!TokenInGroup(TG::RBrace))
             {
-                aNodes.push_back(DoAlign());
+                aNodes.emplace_back(std::unique_ptr<SmNode>(DoAlign()));
                 if (m_aCurToken.eType != TMLINE  &&  !TokenInGroup(TG::RBrace))
-                    aNodes.push_back(DoError(SmParseError::RbraceExpected));
+                    aNodes.emplace_back(std::unique_ptr<SmNode>(DoError(SmParseError::RbraceExpected)));
             }
         } while (m_aCurToken.eType != TEND  &&  !TokenInGroup(TG::RBrace));
     }
 
-    pBody->SetSubNodes(aNodes);
+    pBody->SetSubNodes(buildNodeArray(aNodes));
     pBody->SetScaleMode(bIsLeftRight ? SmScaleMode::Height : SmScaleMode::None);
     return pBody.release();
 }
commit a1d685988d99fa24e9625b751f50c327c4803005
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Dec 12 15:47:25 2017 +0000

    ofz: throw early
    
    Change-Id: I6d3ce03d5cb43df30f6f693c73ccf22c45a8b839
    Reviewed-on: https://gerrit.libreoffice.org/46323
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 5a5924b0cfd4..620bcf6d101d 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -259,6 +259,12 @@ void SwHTMLParser::SetAnchorAndAdjustment( sal_Int16 eVertOri,
     if( bMoveBackward )
         m_pPam->Move( fnMoveBackward );
 
+    if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR && !m_pPam->GetNode().GetTextNode())
+    {
+        eState = SvParserState::Error;
+        throw std::runtime_error("missing paragraph");
+    }
+
     aAnchor.SetAnchor( m_pPam->GetPoint() );
 
     if( bMoveBackward )
diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 0551c886c022..80d0d883d8e8 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -2729,7 +2729,10 @@ const SwStartNode *SwHTMLParser::InsertTableSection( sal_uInt16 nPoolId )
     }
 
     if (!pStNd)
+    {
+        eState = SvParserState::Error;
         throw std::runtime_error("missing table start node");
+    }
 
     return pStNd;
 }
commit b4eac2d4d9fcfd1e08e5e51ba540d154faa6d083
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Dec 12 11:40:13 2017 +0000

    ofz: fix brush leak
    
    Change-Id: Iaab1d09be69fd3a47975ca360b78ca23954056af
    Reviewed-on: https://gerrit.libreoffice.org/46290
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 5680ca23b932..0551c886c022 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -267,7 +267,7 @@ typedef std::vector<std::unique_ptr<HTMLTableCell>> HTMLTableCells;
 
 class HTMLTableRow
 {
-    HTMLTableCells *m_pCells;   ///< cells of the row
+    std::unique_ptr<HTMLTableCells> m_xCells;   ///< cells of the row
 
     bool bIsEndOfGroup : 1;
 
@@ -276,7 +276,7 @@ class HTMLTableRow
 
     SvxAdjust eAdjust;
     sal_Int16 eVertOri;
-    SvxBrushItem *pBGBrush;             // background of cell from STYLE
+    std::unique_ptr<SvxBrushItem> xBGBrush;             // background of cell from STYLE
 
 public:
 
@@ -284,8 +284,6 @@ public:
 
     explicit HTMLTableRow( sal_uInt16 nCells );    // cells of the row are empty
 
-    ~HTMLTableRow();
-
     inline void SetHeight( sal_uInt16 nHeight );
     sal_uInt16 GetHeight() const { return nHeight; }
 
@@ -297,8 +295,8 @@ public:
     void SetVertOri( sal_Int16 eV) { eVertOri = eV; }
     sal_Int16 GetVertOri() const { return eVertOri; }
 
-    void SetBGBrush( SvxBrushItem *pBrush ) { pBGBrush = pBrush; }
-    const SvxBrushItem *GetBGBrush() const { return pBGBrush; }
+    void SetBGBrush(std::unique_ptr<SvxBrushItem>& rBrush ) { xBGBrush = std::move(rBrush); }
+    const std::unique_ptr<SvxBrushItem>& GetBGBrush() const { return xBGBrush; }
 
     void SetEndOfGroup() { bIsEndOfGroup = true; }
     bool IsEndOfGroup() const { return bIsEndOfGroup; }
@@ -397,8 +395,8 @@ class HTMLTable
     SwTableBoxFormat *m_pBoxFormat;         // frame::Frame-Format from SwTableBox
     SwTableLineFormat *m_pLineFormat;       // frame::Frame-Format from SwTableLine
     SwTableLineFormat *m_pLineFrameFormatNoHeight;
-    SvxBrushItem *m_pBackgroundBrush;         // background of the table
-    SvxBrushItem *m_pInheritedBackgroundBrush;      // "inherited" background of the table
+    std::unique_ptr<SvxBrushItem> m_xBackgroundBrush;          // background of the table
+    std::unique_ptr<SvxBrushItem> m_xInheritedBackgroundBrush; // "inherited" background of the table
     const SwStartNode *m_pCaptionStartNode;   // Start-Node of the table-caption
     //lines for the border
     SvxBorderLine m_aTopBorderLine;
@@ -503,8 +501,8 @@ class HTMLTable
     // is the border already set?
     bool BordersSet() const { return m_bBordersSet; }
 
-    const SvxBrushItem *GetBGBrush() const { return m_pBackgroundBrush; }
-    const SvxBrushItem *GetInhBGBrush() const { return m_pInheritedBackgroundBrush; }
+    const std::unique_ptr<SvxBrushItem>& GetBGBrush() const { return m_xBackgroundBrush; }
+    const std::unique_ptr<SvxBrushItem>& GetInhBGBrush() const { return m_xInheritedBackgroundBrush; }
 
     sal_uInt16 GetBorderWidth( const SvxBorderLine& rBLine,
                            bool bWithDistance=false ) const;
@@ -549,8 +547,7 @@ public:
                      bool bHasValue, double nValue, bool bNoWrap );
 
     // announce the start/end of a new row
-    void OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOri,
-                  SvxBrushItem *pBGBrush );
+    void OpenRow(SvxAdjust eAdjust, sal_Int16 eVertOri, std::unique_ptr<SvxBrushItem>& rBGBrush);
     void CloseRow( bool bEmpty );
 
     // announce the end of a new section
@@ -602,7 +599,7 @@ public:
 
     const SwTable *GetSwTable() const { return m_pSwTable; }
 
-    void SetBGBrush( const SvxBrushItem& rBrush ) { delete m_pBackgroundBrush; m_pBackgroundBrush = new SvxBrushItem( rBrush ); }
+    void SetBGBrush(const SvxBrushItem& rBrush) { m_xBackgroundBrush.reset(new SvxBrushItem(rBrush)); }
 
     const OUString& GetId() const { return m_aId; }
     const OUString& GetClass() const { return m_aClass; }
@@ -753,30 +750,23 @@ std::unique_ptr<SwHTMLTableLayoutCell> HTMLTableCell::CreateLayoutInfo()
 }
 
 HTMLTableRow::HTMLTableRow(sal_uInt16 const nCells)
-    : m_pCells(new HTMLTableCells),
+    : m_xCells(new HTMLTableCells),
     bIsEndOfGroup(false),
     nHeight(0),
     nEmptyRows(0),
     eAdjust(SvxAdjust::End),
     eVertOri(text::VertOrientation::TOP),
-    pBGBrush(nullptr),
     bBottomBorder(false)
 {
     for( sal_uInt16 i=0; i<nCells; i++ )
     {
-        m_pCells->push_back(o3tl::make_unique<HTMLTableCell>());
+        m_xCells->push_back(o3tl::make_unique<HTMLTableCell>());
     }
 
-    OSL_ENSURE(nCells == m_pCells->size(),
+    OSL_ENSURE(nCells == m_xCells->size(),
             "wrong Cell count in new HTML table row");
 }
 
-HTMLTableRow::~HTMLTableRow()
-{
-    delete m_pCells;
-    delete pBGBrush;
-}
-
 inline void HTMLTableRow::SetHeight( sal_uInt16 nHght )
 {
     if( nHght > nHeight  )
@@ -785,9 +775,9 @@ inline void HTMLTableRow::SetHeight( sal_uInt16 nHght )
 
 inline HTMLTableCell *HTMLTableRow::GetCell( sal_uInt16 nCell ) const
 {
-    OSL_ENSURE( nCell < m_pCells->size(),
+    OSL_ENSURE( nCell < m_xCells->size(),
         "invalid cell index in HTML table row" );
-    return (*m_pCells)[nCell].get();
+    return (*m_xCells)[nCell].get();
 }
 
 void HTMLTableRow::Expand( sal_uInt16 nCells, bool bOneCell )
@@ -795,34 +785,34 @@ void HTMLTableRow::Expand( sal_uInt16 nCells, bool bOneCell )
     // This row will be filled with a single cell if bOneCell is set.
     // This will only work for rows that don't allow adding cells!
 
-    sal_uInt16 nColSpan = nCells - m_pCells->size();
-    for (sal_uInt16 i = m_pCells->size(); i < nCells; ++i)
+    sal_uInt16 nColSpan = nCells - m_xCells->size();
+    for (sal_uInt16 i = m_xCells->size(); i < nCells; ++i)
     {
         std::unique_ptr<HTMLTableCell> pCell(new HTMLTableCell);
         if( bOneCell )
             pCell->SetColSpan( nColSpan );
 
-        m_pCells->push_back(std::move(pCell));
+        m_xCells->push_back(std::move(pCell));
         nColSpan--;
     }
 
-    OSL_ENSURE(nCells == m_pCells->size(),
+    OSL_ENSURE(nCells == m_xCells->size(),
             "wrong Cell count in expanded HTML table row");
 }
 
 void HTMLTableRow::Shrink( sal_uInt16 nCells )
 {
-    OSL_ENSURE(nCells < m_pCells->size(), "number of cells too large");
+    OSL_ENSURE(nCells < m_xCells->size(), "number of cells too large");
 
 #if OSL_DEBUG_LEVEL > 0
-     sal_uInt16 const nEnd = m_pCells->size();
+     sal_uInt16 const nEnd = m_xCells->size();
 #endif
     // The colspan of empty cells at the end has to be fixed to the new
     // number of cells.
     sal_uInt16 i=nCells;
     while( i )
     {
-        HTMLTableCell *pCell = (*m_pCells)[--i].get();
+        HTMLTableCell *pCell = (*m_xCells)[--i].get();
         if( !pCell->GetContents() )
         {
 #if OSL_DEBUG_LEVEL > 0
@@ -837,7 +827,7 @@ void HTMLTableRow::Shrink( sal_uInt16 nCells )
 #if OSL_DEBUG_LEVEL > 0
     for( i=nCells; i<nEnd; i++ )
     {
-        HTMLTableCell *pCell = (*m_pCells)[i].get();
+        HTMLTableCell *pCell = (*m_xCells)[i].get();
         OSL_ENSURE( pCell->GetRowSpan() == 1,
                     "RowSpan of to be deleted cell is wrong" );
         OSL_ENSURE( pCell->GetColSpan() == nEnd - i,
@@ -846,7 +836,7 @@ void HTMLTableRow::Shrink( sal_uInt16 nCells )
     }
 #endif
 
-    m_pCells->erase( m_pCells->begin() + nCells, m_pCells->end() );
+    m_xCells->erase(m_xCells->begin() + nCells, m_xCells->end());
 }
 
 HTMLTableColumn::HTMLTableColumn():
@@ -916,7 +906,7 @@ void HTMLTable::InitCtor( const HTMLTableOptions *pOptions )
     m_xBox1.reset();
     m_pBoxFormat = nullptr; m_pLineFormat = nullptr;
     m_pLineFrameFormatNoHeight = nullptr;
-    m_pInheritedBackgroundBrush = nullptr;
+    m_xInheritedBackgroundBrush.reset();
 
     m_pPrevStartNode = nullptr;
     m_pSwTable = nullptr;
@@ -1007,9 +997,9 @@ void HTMLTable::InitCtor( const HTMLTableOptions *pOptions )
 
     m_bColSpec = false;
 
-    m_pBackgroundBrush = m_pParser->CreateBrushItem(
+    m_xBackgroundBrush.reset(m_pParser->CreateBrushItem(
                     pOptions->bBGColor ? &(pOptions->aBGColor) : nullptr,
-                    pOptions->aBGImage, aEmptyOUStr, aEmptyOUStr, aEmptyOUStr );
+                    pOptions->aBGImage, aEmptyOUStr, aEmptyOUStr, aEmptyOUStr));
 
     m_pContext = nullptr;
     m_xParentContents.reset();
@@ -1061,8 +1051,6 @@ HTMLTable::~HTMLTable()
 
     delete m_pRows;
     delete m_pColumns;
-    delete m_pBackgroundBrush;
-    delete m_pInheritedBackgroundBrush;
 
     delete m_pContext;
 
@@ -1278,12 +1266,12 @@ void HTMLTable::FixFrameFormat( SwTableBox *pBox,
             // since the line is gonna be GC-ed (correctly).
             if( nRowSpan > 1 || (this != m_pTopTable && nRowSpan==m_nRows) )
             {
-                pBGBrushItem = (*m_pRows)[nRow]->GetBGBrush();
+                pBGBrushItem = (*m_pRows)[nRow]->GetBGBrush().get();
                 if( !pBGBrushItem && this != m_pTopTable )
                 {
-                    pBGBrushItem = GetBGBrush();
+                    pBGBrushItem = GetBGBrush().get();
                     if( !pBGBrushItem )
-                        pBGBrushItem = GetInhBGBrush();
+                        pBGBrushItem = GetInhBGBrush().get();
                 }
             }
         }
@@ -1551,15 +1539,15 @@ SwTableLine *HTMLTable::MakeTableLine( SwTableBox *pUpper,
     {
         // It doesn't make sense to set a color on a line,
         // if it's the outermost and simultaneously sole line of a table in a table
-        pBGBrushItem = pTopRow->GetBGBrush();
+        pBGBrushItem = pTopRow->GetBGBrush().get();
 
         if( !pBGBrushItem && this != m_pTopTable )
         {
             // A background that's set on a table in a table is set on the rows.
             // It's the same for the background of the cell where that table is
-            pBGBrushItem = GetBGBrush();
+            pBGBrushItem = GetBGBrush().get();
             if( !pBGBrushItem )
-                pBGBrushItem = GetInhBGBrush();
+                pBGBrushItem = GetInhBGBrush().get();
         }
     }
     if( nTopRow==nBottomRow-1 && (nRowHeight || pBGBrushItem) )
@@ -1799,14 +1787,14 @@ void HTMLTable::InheritBorders( const HTMLTable *pParent,
     {
         // the whole surrounding table is a table in a table and consists only of a single line
         // that's gonna be GC-ed (correctly). That's why the background of that line is copied.
-        pInhBG = (*pParent->m_pRows)[nRow]->GetBGBrush();
+        pInhBG = (*pParent->m_pRows)[nRow]->GetBGBrush().get();
         if( !pInhBG )
-            pInhBG = pParent->GetBGBrush();
+            pInhBG = pParent->GetBGBrush().get();
         if( !pInhBG )
-            pInhBG = pParent->GetInhBGBrush();
+            pInhBG = pParent->GetInhBGBrush().get();
     }
     if( pInhBG )
-        m_pInheritedBackgroundBrush = new SvxBrushItem( *pInhBG );
+        m_xInheritedBackgroundBrush.reset(new SvxBrushItem(*pInhBG));
 }
 
 void HTMLTable::InheritVertBorders( const HTMLTable *pParent,
@@ -2077,8 +2065,8 @@ inline void HTMLTable::CloseSection( bool bHead )
         m_nHeadlineRepeat = m_nCurrentRow;
 }
 
-void HTMLTable::OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOrient,
-                         SvxBrushItem *pBGBrushItem )
+void HTMLTable::OpenRow(SvxAdjust eAdjust, sal_Int16 eVertOrient,
+                        std::unique_ptr<SvxBrushItem>& rBGBrushItem)
 {
     sal_uInt16 nRowsReq = m_nCurrentRow+1;
 
@@ -2095,8 +2083,8 @@ void HTMLTable::OpenRow( SvxAdjust eAdjust, sal_Int16 eVertOrient,
     HTMLTableRow *const pCurRow = (*m_pRows)[m_nCurrentRow].get();
     pCurRow->SetAdjust( eAdjust );
     pCurRow->SetVertOri( eVertOrient );
-    if( pBGBrushItem )
-        (*m_pRows)[m_nCurrentRow]->SetBGBrush( pBGBrushItem );
+    if (rBGBrushItem)
+        (*m_pRows)[m_nCurrentRow]->SetBGBrush(rBGBrushItem);
 
     // reset the column counter
     m_nCurrentColumn=0;
@@ -4053,10 +4041,10 @@ void SwHTMLParser::BuildTableRow( HTMLTable *pCurTable, bool bReadOptions,
         if( !aId.isEmpty() )
             InsertBookmark( aId );
 
-        SvxBrushItem *pBrushItem =
+        std::unique_ptr<SvxBrushItem> xBrushItem(
             CreateBrushItem( bBGColor ? &aBGColor : nullptr, aBGImage, aStyle,
-                             aId, aClass );
-        pCurTable->OpenRow( eAdjust, eVertOri, pBrushItem );
+                             aId, aClass ));
+        pCurTable->OpenRow(eAdjust, eVertOri, xBrushItem);
         // If the first GetNextToken() doesn't succeed (pending input), must re-read from the beginning.
         SaveState( HtmlTokenId::NONE );
     }


More information about the Libreoffice-commits mailing list