[Libreoffice-commits] core.git: sc/inc sc/source
Jochen Nitschke
j.nitschke+logerrit at ok.de
Mon Apr 11 07:17:22 UTC 2016
sc/inc/textuno.hxx | 12 +++----
sc/source/ui/unoobj/fielduno.cxx | 20 ++++++++----
sc/source/ui/unoobj/textuno.cxx | 62 +++++++++++++++++++--------------------
3 files changed, 49 insertions(+), 45 deletions(-)
New commits:
commit 2553c5b95d4596fc1ef679a42073d5bc62737914
Author: Jochen Nitschke <j.nitschke+logerrit at ok.de>
Date: Fri Mar 25 19:56:14 2016 +0100
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 at libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin at gmail.com>
diff --git a/sc/inc/textuno.hxx b/sc/inc/textuno.hxx
index bb32420..6447ee0 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 8ec23e9..5f64bfd 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 053e41b..53b23fe 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;
}
More information about the Libreoffice-commits
mailing list