summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Nitschke <j.nitschke+logerrit@ok.de>2016-03-25 19:56:14 +0100
committerNoel Grandin <noelgrandin@gmail.com>2016-04-11 07:16:52 +0000
commit2553c5b95d4596fc1ef679a42073d5bc62737914 (patch)
tree3f2676a60fefa96c717881b3da0fc6b529cfa3d7
parentc210bf4510585b554e0e9a371f27fa27e2874762 (diff)
tdf#84938 replace #defined constants with enum class
replace if constructs with switch remove temp variables tried to squeeze the enum in one of the 3 classes but it doesn't feel right anywhere. ScHeaderFooterContentObj doesn't use it, except for initialzing ScHeaderFooterTextObj. ScHeaderFooterTextData holds it but nothing more. ScHeaderFooterTextObj uses it but always has to get it via ScHeaderFooterTextData.GetPart() Change-Id: I838ebff2e116e24a1c9359d6652bf5b1d30da48a Reviewed-on: https://gerrit.libreoffice.org/23352 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--sc/inc/textuno.hxx12
-rw-r--r--sc/source/ui/unoobj/fielduno.cxx20
-rw-r--r--sc/source/ui/unoobj/textuno.cxx62
3 files changed, 49 insertions, 45 deletions
diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx
index bb32420208fb..6447ee0770f5 100644
--- a/sc/inc/textuno.hxx
+++ b/sc/inc/textuno.hxx
@@ -49,9 +49,7 @@ class ScHeaderFooterTextObj;
struct ScHeaderFieldData;
-#define SC_HDFT_LEFT 0
-#define SC_HDFT_CENTER 1
-#define SC_HDFT_RIGHT 2
+enum class ScHeaderFooterPart{ LEFT, CENTER, RIGHT };
// ScHeaderFooterContentObj is a dumb container which must be re-written into
// the page template using setPropertyValue
@@ -113,7 +111,7 @@ class ScHeaderFooterTextData
private:
std::unique_ptr<EditTextObject> mpTextObj;
rtl::Reference<ScHeaderFooterContentObj> rContentObj;
- sal_uInt16 nPart;
+ ScHeaderFooterPart nPart;
ScEditEngineDefaulter* pEditEngine;
SvxEditEngineForwarder* pForwarder;
bool bDataValid;
@@ -122,7 +120,7 @@ public:
ScHeaderFooterTextData(const ScHeaderFooterTextData&) = delete;
const ScHeaderFooterTextData& operator=(const ScHeaderFooterTextData&) = delete;
ScHeaderFooterTextData(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, sal_uInt16 nP, const EditTextObject* pTextObj);
+ rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
~ScHeaderFooterTextData();
// helper functions
@@ -131,7 +129,7 @@ public:
void UpdateData(EditEngine& rEditEngine);
ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine; }
- sal_uInt16 GetPart() const { return nPart; }
+ ScHeaderFooterPart GetPart() const { return nPart; }
rtl::Reference<ScHeaderFooterContentObj> GetContentObj() const { return rContentObj; }
const EditTextObject* GetTextObject() const { return mpTextObj.get(); }
@@ -160,7 +158,7 @@ private:
public:
ScHeaderFooterTextObj(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, sal_uInt16 nP, const EditTextObject* pTextObj);
+ rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
virtual ~ScHeaderFooterTextObj();
const EditTextObject* GetTextObject() const;
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index 8ec23e93a57e..5f64bfd3f584 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -481,13 +481,19 @@ uno::Reference<text::XTextField> ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_In
uno::Reference<text::XTextRange> xTextRange;
rtl::Reference<ScHeaderFooterContentObj> rContentObj = mrData.GetContentObj();
uno::Reference<text::XText> xText;
- sal_uInt16 nPart = mrData.GetPart();
- if (nPart == SC_HDFT_LEFT)
- xText = rContentObj->getLeftText();
- else if (nPart == SC_HDFT_CENTER)
- xText = rContentObj->getCenterText();
- else
- xText = rContentObj->getRightText();
+
+ switch ( mrData.GetPart() )
+ {
+ case ScHeaderFooterPart::LEFT:
+ xText = rContentObj->getLeftText();
+ break;
+ case ScHeaderFooterPart::CENTER:
+ xText = rContentObj->getCenterText();
+ break;
+ case ScHeaderFooterPart::RIGHT:
+ xText = rContentObj->getRightText();
+ break;
+ }
uno::Reference<text::XTextRange> xTemp(xText, uno::UNO_QUERY);
xTextRange = xTemp;
diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx
index 053e41b3f081..53b23feed53f 100644
--- a/sc/source/ui/unoobj/textuno.cxx
+++ b/sc/source/ui/unoobj/textuno.cxx
@@ -93,9 +93,9 @@ SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj, "ScHeaderFooterTextObj", "stardiv
ScHeaderFooterContentObj::ScHeaderFooterContentObj( const EditTextObject* pLeft,
const EditTextObject* pCenter,
const EditTextObject* pRight ) :
- mxLeftText(new ScHeaderFooterTextObj(this, SC_HDFT_LEFT, pLeft)),
- mxCenterText(new ScHeaderFooterTextObj(this, SC_HDFT_CENTER, pCenter)),
- mxRightText(new ScHeaderFooterTextObj(this, SC_HDFT_RIGHT, pRight))
+ mxLeftText(new ScHeaderFooterTextObj(this, ScHeaderFooterPart::LEFT, pLeft)),
+ mxCenterText(new ScHeaderFooterTextObj(this, ScHeaderFooterPart::CENTER, pCenter)),
+ mxRightText(new ScHeaderFooterTextObj(this, ScHeaderFooterPart::RIGHT, pRight))
{
}
@@ -184,7 +184,7 @@ void ScHeaderFooterContentObj::dispose()
}
ScHeaderFooterTextData::ScHeaderFooterTextData(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, sal_uInt16 nP, const EditTextObject* pTextObj) :
+ rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
mpTextObj(pTextObj ? pTextObj->Clone() : nullptr),
rContentObj( rContent ),
nPart( nP ),
@@ -259,7 +259,7 @@ void ScHeaderFooterTextData::UpdateData(EditEngine& rEditEngine)
}
ScHeaderFooterTextObj::ScHeaderFooterTextObj(
- rtl::Reference<ScHeaderFooterContentObj> const & rContent, sal_uInt16 nP, const EditTextObject* pTextObj) :
+ rtl::Reference<ScHeaderFooterContentObj> const & rContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
aTextData(rContent, nP, pTextObj)
{
// ScHeaderFooterTextData acquires rContent
@@ -327,15 +327,24 @@ OUString SAL_CALL ScHeaderFooterTextObj::getString() throw(uno::RuntimeException
OUString aRet;
const EditTextObject* pData;
- sal_uInt16 nPart = aTextData.GetPart();
rtl::Reference<ScHeaderFooterContentObj> rContentObj = aTextData.GetContentObj();
- if (nPart == SC_HDFT_LEFT)
- pData = rContentObj->GetLeftEditObject();
- else if (nPart == SC_HDFT_CENTER)
- pData = rContentObj->GetCenterEditObject();
- else
- pData = rContentObj->GetRightEditObject();
+ switch ( aTextData.GetPart() )
+ {
+ case ScHeaderFooterPart::LEFT:
+ pData = rContentObj->GetLeftEditObject();
+ break;
+ case ScHeaderFooterPart::CENTER:
+ pData = rContentObj->GetCenterEditObject();
+ break;
+ default: //needed for compiler warning: possible uninitialized pointer
+ assert(!"unexpected enum value of ScHeaderFooterPart");
+ // fall through
+ case ScHeaderFooterPart::RIGHT:
+ pData = rContentObj->GetRightEditObject();
+ break;
+ }
+
if (pData)
{
// for pure text, no font info is needed in pool defaults
@@ -422,28 +431,19 @@ void SAL_CALL ScHeaderFooterTextObj::insertTextContent(
aSelection.nEndPos = aSelection.nStartPos + 1;
uno::Reference<text::XTextRange> xTextRange;
- switch (aTextData.GetPart())
+ switch ( aTextData.GetPart() )
{
- case SC_HDFT_LEFT:
- {
- uno::Reference<text::XTextRange> xTemp(
- aTextData.GetContentObj()->getLeftText(), uno::UNO_QUERY);
- xTextRange = xTemp;
- }
+ case ScHeaderFooterPart::LEFT:
+ xTextRange = uno::Reference<text::XTextRange>(
+ aTextData.GetContentObj()->getLeftText(), uno::UNO_QUERY);
break;
- case SC_HDFT_CENTER:
- {
- uno::Reference<text::XTextRange> xTemp(
- aTextData.GetContentObj()->getCenterText(), uno::UNO_QUERY);
- xTextRange = xTemp;
- }
+ case ScHeaderFooterPart::CENTER:
+ xTextRange = uno::Reference<text::XTextRange>(
+ aTextData.GetContentObj()->getCenterText(), uno::UNO_QUERY);
break;
- case SC_HDFT_RIGHT:
- {
- uno::Reference<text::XTextRange> xTemp(
- aTextData.GetContentObj()->getRightText(), uno::UNO_QUERY);
- xTextRange = xTemp;
- }
+ case ScHeaderFooterPart::RIGHT:
+ xTextRange = uno::Reference<text::XTextRange>(
+ aTextData.GetContentObj()->getRightText(), uno::UNO_QUERY);
break;
}