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

Caolán McNamara caolanm at redhat.com
Fri May 8 05:18:36 PDT 2015


 sw/inc/modeltoviewhelper.hxx                 |   25 ++++++++++++++-------
 sw/qa/core/uwriter.cxx                       |   32 +++++++++++++--------------
 sw/source/core/txtnode/modeltoviewhelper.cxx |   22 +++++++++---------
 sw/source/core/txtnode/ndtxt.cxx             |    4 +--
 sw/source/core/txtnode/txtedt.cxx            |    2 -
 5 files changed, 47 insertions(+), 38 deletions(-)

New commits:
commit 520400e8faf8e7346d16f34babb6258033673e12
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri May 8 12:59:51 2015 +0100

    convert EXPAND constants to scoped enum
    
    Change-Id: I98a0fecf15337db729b39b80aa9c664abcdd3daa

diff --git a/sw/inc/modeltoviewhelper.hxx b/sw/inc/modeltoviewhelper.hxx
index d99c9db..386b536 100644
--- a/sw/inc/modeltoviewhelper.hxx
+++ b/sw/inc/modeltoviewhelper.hxx
@@ -22,6 +22,7 @@
 
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
+#include <o3tl/typed_flags_set.hxx>
 #include <vector>
 
 class SwTxtNode;
@@ -61,13 +62,21 @@ class SwTxtNode;
     0111: expanding fields + hiding hiddens + hiding redlines gives: AAAABB foo CCCCC foo DDDDD
 */
 
-#define PASSTHROUGH    0x0000
-#define EXPANDFIELDS   0x0001
-#define EXPANDFOOTNOTE 0x0002
-#define HIDEINVISIBLE  0x0004
-#define HIDEDELETIONS  0x0008
-/// do not expand to content, but replace with ZWSP
-#define REPLACEMODE    0x0010
+enum class ExpandMode
+{
+    PassThrough    = 0x0000,
+    ExpandFields   = 0x0001,
+    ExpandFootnote = 0x0002,
+    HideInvisible  = 0x0004,
+    HideDeletions  = 0x0008,
+    /// do not expand to content, but replace with zwsp
+    ReplaceMode    = 0x0010,
+};
+
+namespace o3tl
+{
+    template<> struct typed_flags<ExpandMode> : is_typed_flags<ExpandMode, 0x001f> {};
+}
 
 class ModelToViewHelper
 {
@@ -118,7 +127,7 @@ public:
 
     ModelToViewHelper(const SwTxtNode &rNode,
             // defaults are appropriate for spell/grammar checking
-            sal_uInt16 eMode = EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
+            ExpandMode eMode = ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
     ModelToViewHelper() //pass through filter, view == model
     {
     }
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index b56d308..1d5986c 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -341,7 +341,7 @@ void SwDocTest::testModelToViewHelperPassthrough()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, PASSTHROUGH);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::PassThrough);
     OUString sViewText = aModelToViewHelper.getViewText();
     OUString sModelText = pTxtNode->GetTxt();
     CPPUNIT_ASSERT_EQUAL(sModelText, sViewText);
@@ -351,7 +351,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsExpandFootnote()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | EXPANDFOOTNOTE);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::ExpandFields | ExpandMode::ExpandFootnote);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAAA BBBBB foo CCCCC foo DDDDD"), sViewText);
@@ -362,7 +362,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsExpandFootnoteReplaceMode()
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
     ModelToViewHelper aModelToViewHelper(*pTxtNode,
-            EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
+            ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAAA BBBBB " + OUString(CHAR_ZWSP) + " CCCCC " + OUString(CHAR_ZWSP) + " DDDDD"),
@@ -381,7 +381,7 @@ void SwDocTest::testModelToViewHelperExpandFields()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::ExpandFields);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAAA BBBBB  CCCCC  DDDDD"), sViewText);
@@ -392,7 +392,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsReplaceMode()
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
     ModelToViewHelper aModelToViewHelper(*pTxtNode,
-        EXPANDFIELDS | REPLACEMODE);
+        ExpandMode::ExpandFields | ExpandMode::ReplaceMode);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(OUString("AAAAA BBBBB  CCCCC  DDDDD"),
         sViewText);
@@ -406,7 +406,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideInvisible()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEINVISIBLE);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::HideInvisible);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAAA CCCCC " + OUStringLiteral1<CH_TXTATR_BREAKWORD>() + " DDDDD"),
@@ -417,7 +417,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideRedlined()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEDELETIONS);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::HideDeletions);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAABB " + OUStringLiteral1<CH_TXTATR_BREAKWORD>() + " CCCCC " + OUStringLiteral1<CH_TXTATR_BREAKWORD>() + " DDDDD"),
@@ -428,7 +428,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideInvisibleExpandFootnote()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEINVISIBLE | EXPANDFOOTNOTE);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::ExpandFields | ExpandMode::HideInvisible | ExpandMode::ExpandFootnote);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(OUString("AAAAA CCCCC foo DDDDD"), sViewText);
 }
@@ -438,7 +438,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideInvisibleExpandFootnoteRepl
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
     ModelToViewHelper aModelToViewHelper(*pTxtNode,
-        EXPANDFIELDS | HIDEINVISIBLE | EXPANDFOOTNOTE | REPLACEMODE);
+        ExpandMode::ExpandFields | ExpandMode::HideInvisible | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAAA CCCCC " + OUString(CHAR_ZWSP) + " DDDDD"),
@@ -455,7 +455,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideHideRedlinedExpandFootnote(
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEDELETIONS | EXPANDFOOTNOTE);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::ExpandFields | ExpandMode::HideDeletions | ExpandMode::ExpandFootnote);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAABB foo CCCCC foo DDDDD"), sViewText);
@@ -466,7 +466,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideHideRedlinedExpandFootnoteR
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
     ModelToViewHelper aModelToViewHelper(*pTxtNode,
-        EXPANDFIELDS | HIDEDELETIONS | EXPANDFOOTNOTE | REPLACEMODE);
+        ExpandMode::ExpandFields | ExpandMode::HideDeletions | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
        OUString("AAAABB " + OUString(CHAR_ZWSP) + " CCCCC " + OUString(CHAR_ZWSP) + " DDDDD"),
@@ -485,7 +485,7 @@ void SwDocTest::testModelToViewHelperHideInvisibleHideRedlined()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, HIDEINVISIBLE | HIDEDELETIONS);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::HideInvisible | ExpandMode::HideDeletions);
     OUString sViewText = aModelToViewHelper.getViewText();
     OUStringBuffer aBuffer;
     aBuffer.append("AAAACCCCC ");
@@ -498,7 +498,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideInvisibleHideRedlinedExpand
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | HIDEINVISIBLE | HIDEDELETIONS | EXPANDFOOTNOTE);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::ExpandFields | ExpandMode::HideInvisible | ExpandMode::HideDeletions | ExpandMode::ExpandFootnote);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(OUString("AAAACCCCC foo DDDDD"), sViewText);
 }
@@ -508,7 +508,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsHideInvisibleHideRedlinedExpand
     SwTxtNode* pTxtNode = getModelToViewTestDocument(m_pDoc);
 
     ModelToViewHelper aModelToViewHelper(*pTxtNode,
-        EXPANDFIELDS | HIDEINVISIBLE | HIDEDELETIONS | EXPANDFOOTNOTE | REPLACEMODE);
+        ExpandMode::ExpandFields | ExpandMode::HideInvisible | ExpandMode::HideDeletions | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(sViewText,
         OUString("AAAACCCCC " + OUString(CHAR_ZWSP) + " DDDDD"));
@@ -524,7 +524,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsExpandFootnote2()
 {
     SwTxtNode* pTxtNode = getModelToViewTestDocument2(m_pDoc);
 
-    ModelToViewHelper aModelToViewHelper(*pTxtNode, EXPANDFIELDS | EXPANDFOOTNOTE);
+    ModelToViewHelper aModelToViewHelper(*pTxtNode, ExpandMode::ExpandFields | ExpandMode::ExpandFootnote);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(OUString("AAAAABBBBBCCCCC"), sViewText);
 }
@@ -534,7 +534,7 @@ void SwDocTest::testModelToViewHelperExpandFieldsExpandFootnoteReplaceMode2()
     SwTxtNode* pTxtNode = getModelToViewTestDocument2(m_pDoc);
 
     ModelToViewHelper aModelToViewHelper(*pTxtNode,
-        EXPANDFIELDS | EXPANDFOOTNOTE | REPLACEMODE);
+        ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::ReplaceMode);
     OUString sViewText = aModelToViewHelper.getViewText();
     CPPUNIT_ASSERT_EQUAL(
         OUString("AAAAA" + OUString(CHAR_ZWSP) + "CCCCC"),
diff --git a/sw/source/core/txtnode/modeltoviewhelper.cxx b/sw/source/core/txtnode/modeltoviewhelper.cxx
index 43bab21..dddf82f 100644
--- a/sw/source/core/txtnode/modeltoviewhelper.cxx
+++ b/sw/source/core/txtnode/modeltoviewhelper.cxx
@@ -80,21 +80,21 @@ struct containsPos
     }
 };
 
-ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
+ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, ExpandMode eMode)
 {
     const OUString& rNodeText = rNode.GetTxt();
     m_aRetText = rNodeText;
 
-    if (eMode == PASSTHROUGH)
+    if (eMode == ExpandMode::PassThrough)
         return;
 
     Range aRange( 0, rNodeText.isEmpty() ? 0 : rNodeText.getLength() - 1);
     MultiSelection aHiddenMulti(aRange);
 
-    if (eMode & HIDEINVISIBLE)
+    if (eMode & ExpandMode::HideInvisible)
         SwScriptInfo::selectHiddenTextProperty(rNode, aHiddenMulti);
 
-    if (eMode & HIDEDELETIONS)
+    if (eMode & ExpandMode::HideDeletions)
         SwScriptInfo::selectRedLineDeleted(rNode, aHiddenMulti);
 
     std::vector<block> aBlocks;
@@ -123,7 +123,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
     if (nTrailingShownLen)
         aBlocks.push_back(block(nShownStart, nTrailingShownLen, true));
 
-    if (eMode & EXPANDFIELDS || eMode & EXPANDFOOTNOTE)
+    if (eMode & ExpandMode::ExpandFields || eMode & ExpandMode::ExpandFootnote)
     {
         //first the normal fields, get their position in the node and what the text they expand
         //to is
@@ -145,9 +145,9 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
                     {
                         case RES_TXTATR_FIELD:
                         case RES_TXTATR_ANNOTATION:
-                            if (eMode & EXPANDFIELDS)
+                            if (eMode & ExpandMode::ExpandFields)
                             {
-                                aFieldResult.m_sExpand = (eMode & REPLACEMODE)
+                                aFieldResult.m_sExpand = (eMode & ExpandMode::ReplaceMode)
                                     ? OUString(CHAR_ZWSP)
                                     : static_txtattr_cast<SwTxtFld const*>(pAttr)->
                                       GetFmtFld().GetField()->ExpandField(true);
@@ -155,11 +155,11 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
                             }
                             break;
                         case RES_TXTATR_FTN:
-                            if (eMode & EXPANDFOOTNOTE)
+                            if (eMode & ExpandMode::ExpandFootnote)
                             {
                                 const SwFmtFtn& rFtn = static_cast<SwTxtFtn const*>(pAttr)->GetFtn();
                                 const SwDoc *pDoc = rNode.GetDoc();
-                                aFieldResult.m_sExpand = (eMode & REPLACEMODE)
+                                aFieldResult.m_sExpand = (eMode & ExpandMode::ReplaceMode)
                                     ? OUString(CHAR_ZWSP)
                                     : rFtn.GetViewNumStr(*pDoc);
                                 aFieldResult.m_eType = FieldResult::FOOTNOTE;
@@ -173,7 +173,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
             }
         }
 
-        if (eMode & EXPANDFIELDS)
+        if (eMode & ExpandMode::ExpandFields)
         {
             //now get the dropdown formfields, get their position in the node and what the text they expand
             //to is
@@ -193,7 +193,7 @@ ModelToViewHelper::ModelToViewHelper(const SwTxtNode &rNode, sal_uInt16 eMode)
                 if (aFind != aBlocks.end())
                 {
                     FieldResult aFieldResult(nDummyCharPos);
-                    aFieldResult.m_sExpand = (eMode & REPLACEMODE)
+                    aFieldResult.m_sExpand = (eMode & ExpandMode::ReplaceMode)
                         ? OUString(CHAR_ZWSP)
                         : sw::mark::ExpandFieldmark(pMark);
                     aFieldResult.m_eType = FieldResult::FIELD;
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 2d70627..c291f14 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -3138,9 +3138,9 @@ OUString SwTxtNode::GetExpandTxt(  const sal_Int32 nIdx,
                                    const bool bWithFtn ) const
 
 {
-    sal_uInt16 eMode = EXPANDFIELDS;
+    ExpandMode eMode = ExpandMode::ExpandFields;
     if (bWithFtn)
-        eMode |= EXPANDFOOTNOTE;
+        eMode |= ExpandMode::ExpandFootnote;
 
     ModelToViewHelper aConversionMap(*this, eMode);
     OUString aExpandText = aConversionMap.getViewText();
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 90c8fcd..ba0e2ad 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -1985,7 +1985,7 @@ bool SwTxtNode::CountWords( SwDocStat& rStat,
     }
 
     // ConversionMap to expand fields, remove invisible and redline deleted text for scanner
-    const ModelToViewHelper aConversionMap(*this, EXPANDFIELDS | EXPANDFOOTNOTE | HIDEINVISIBLE | HIDEDELETIONS);
+    const ModelToViewHelper aConversionMap(*this, ExpandMode::ExpandFields | ExpandMode::ExpandFootnote | ExpandMode::HideInvisible | ExpandMode::HideDeletions);
     OUString aExpandText = aConversionMap.getViewText();
 
     if (aExpandText.isEmpty() && !bCountNumbering)


More information about the Libreoffice-commits mailing list