summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@gmail.com>2012-04-24 09:28:31 -0400
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-04-26 09:57:59 -0400
commit486fa0ba33bab0cbcf42139bfbdd35a4698bad01 (patch)
treed923d0e19d0e72580ba244ef9f5922326a1d20ee /sc
parente04892dbb121b3e04e4f432af0bdc0cd7757973c (diff)
Have the caller pass the content instance directly.
This is to reduce dependency on ScHeaderFooterContentObj from ScHeaderFieldObj. Eventually that member should be removed and ScHeaderFieldObj be replaced with ScEditFieldObj.
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/fielduno.hxx13
-rw-r--r--sc/source/ui/unoobj/fielduno.cxx42
-rw-r--r--sc/source/ui/unoobj/servuno.cxx8
-rw-r--r--sc/source/ui/unoobj/textuno.cxx30
4 files changed, 68 insertions, 25 deletions
diff --git a/sc/inc/fielduno.hxx b/sc/inc/fielduno.hxx
index d0ce1abf4838..a00dc67b187b 100644
--- a/sc/inc/fielduno.hxx
+++ b/sc/inc/fielduno.hxx
@@ -340,6 +340,7 @@ class ScHeaderFieldObj : public ScMutexHelper,
{
private:
const SfxItemPropertySet* pPropSet;
+ com::sun::star::uno::Reference<com::sun::star::text::XTextRange> mpContent;
ScHeaderFooterContentObj* pContentObj;
sal_uInt16 nPart;
sal_uInt16 nType;
@@ -349,16 +350,18 @@ private:
ScHeaderFieldObj(); // disabled
public:
- ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
- sal_uInt16 nT, const ESelection& rSel);
- virtual ~ScHeaderFieldObj();
+ ScHeaderFieldObj(
+ const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent,
+ ScHeaderFooterContentObj* pContent, sal_uInt16 nP, sal_uInt16 nT, const ESelection& rSel);
+ virtual ~ScHeaderFieldObj();
// called by getImplementation:
void DeleteField();
sal_Bool IsInserted() const { return pEditSource != NULL; }
SvxFieldItem CreateFieldItem();
- void InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
- const ESelection& rSel );
+ void InitDoc(
+ const com::sun::star::uno::Reference<com::sun::star::text::XTextRange>& rContent,
+ ScHeaderFooterContentObj* pContent, sal_uInt16 nP, const ESelection& rSel);
virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(
const ::com::sun::star::uno::Type & rType )
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index d9cd0041d1a1..3297842c9e2a 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -926,7 +926,21 @@ ScHeaderFieldObj* ScHeaderFieldsObj::GetObjectByIndex_Impl(sal_Int32 Index) cons
}
ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field is 1 character
- return new ScHeaderFieldObj( pContentObj, nPart, nFieldType, aSelection );
+ uno::Reference<text::XTextRange> xTextRange;
+ if (pContentObj)
+ {
+ uno::Reference<text::XText> xText;
+ if ( nPart == SC_HDFT_LEFT )
+ xText = pContentObj->getLeftText();
+ else if (nPart == SC_HDFT_CENTER)
+ xText = pContentObj->getCenterText();
+ else
+ xText = pContentObj->getRightText();
+
+ uno::Reference<text::XTextRange> xTemp(xText, uno::UNO_QUERY);
+ xTextRange = xTemp;
+ }
+ return new ScHeaderFieldObj(xTextRange, pContentObj, nPart, nFieldType, aSelection);
}
return NULL;
}
@@ -1086,10 +1100,13 @@ sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue )
}
}
-ScHeaderFieldObj::ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
- sal_uInt16 nT, const ESelection& rSel) :
+ScHeaderFieldObj::ScHeaderFieldObj(
+ const uno::Reference<text::XTextRange>& rContent,
+ ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
+ sal_uInt16 nT, const ESelection& rSel) :
OComponentHelper( getMutex() ),
pPropSet( (nT == SC_SERVICE_FILEFIELD) ? lcl_GetFileFieldPropertySet() : lcl_GetHeaderFieldPropertySet() ),
+ mpContent(rContent),
pContentObj( pContent ),
nPart( nP ),
nType( nT ),
@@ -1168,8 +1185,9 @@ void SAL_CALL ScHeaderFieldObj::release() throw()
OComponentHelper::release();
}
-void ScHeaderFieldObj::InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 nP,
- const ESelection& rSel )
+void ScHeaderFieldObj::InitDoc(
+ const uno::Reference<text::XTextRange>& rContent,
+ ScHeaderFooterContentObj* pContent, sal_uInt16 nP, const ESelection& rSel)
{
if ( pContent && !pEditSource )
{
@@ -1178,6 +1196,7 @@ void ScHeaderFieldObj::InitDoc( ScHeaderFooterContentObj* pContent, sal_uInt16 n
aSelection = rSel;
nPart = nP;
pContentObj = pContent;
+ mpContent = rContent;
pContentObj->acquire(); // darf nicht wegkommen
pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart );
@@ -1295,18 +1314,7 @@ void SAL_CALL ScHeaderFieldObj::attach( const uno::Reference<text::XTextRange>&
uno::Reference<text::XTextRange> SAL_CALL ScHeaderFieldObj::getAnchor() throw(uno::RuntimeException)
{
SolarMutexGuard aGuard;
- if (pContentObj)
- {
- uno::Reference<text::XText> xText;
- if ( nPart == SC_HDFT_LEFT )
- xText = pContentObj->getLeftText();
- else if (nPart == SC_HDFT_CENTER)
- xText = pContentObj->getCenterText();
- else
- xText = pContentObj->getRightText();
- return uno::Reference<text::XTextRange>( xText, uno::UNO_QUERY );
- }
- return NULL;
+ return mpContent;
}
// XComponent
diff --git a/sc/source/ui/unoobj/servuno.cxx b/sc/source/ui/unoobj/servuno.cxx
index 5d6a53389d8b..9227423954dc 100644
--- a/sc/source/ui/unoobj/servuno.cxx
+++ b/sc/source/ui/unoobj/servuno.cxx
@@ -442,8 +442,12 @@ uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance(
case SC_SERVICE_TITLEFIELD:
case SC_SERVICE_FILEFIELD:
case SC_SERVICE_SHEETFIELD:
- xRet.set((text::XTextField*)new ScHeaderFieldObj( NULL, 0, nType, ESelection() ));
- break;
+ {
+ uno::Reference<text::XTextRange> xNullContent;
+ xRet.set(static_cast<text::XTextField*>(
+ new ScHeaderFieldObj(xNullContent, NULL, 0, nType, ESelection())));
+ }
+ break;
case SC_SERVICE_CELLSTYLE:
xRet.set((style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ));
break;
diff --git a/sc/source/ui/unoobj/textuno.cxx b/sc/source/ui/unoobj/textuno.cxx
index 7c06fb568f66..42e7011876da 100644
--- a/sc/source/ui/unoobj/textuno.cxx
+++ b/sc/source/ui/unoobj/textuno.cxx
@@ -485,7 +485,35 @@ void SAL_CALL ScHeaderFooterTextObj::insertTextContent(
aSelection.Adjust();
aSelection.nEndPara = aSelection.nStartPara;
aSelection.nEndPos = aSelection.nStartPos + 1;
- pHeaderField->InitDoc( &aTextData.GetContentObj(), aTextData.GetPart(), aSelection );
+
+ uno::Reference<text::XTextRange> xTextRange;
+ switch (aTextData.GetPart())
+ {
+ case SC_HDFT_LEFT:
+ {
+ uno::Reference<text::XTextRange> xTemp(
+ aTextData.GetContentObj().getLeftText(), uno::UNO_QUERY);
+ xTextRange = xTemp;
+ }
+ break;
+ case SC_HDFT_CENTER:
+ {
+ uno::Reference<text::XTextRange> xTemp(
+ aTextData.GetContentObj().getCenterText(), uno::UNO_QUERY);
+ xTextRange = xTemp;
+ }
+ break;
+ case SC_HDFT_RIGHT:
+ {
+ uno::Reference<text::XTextRange> xTemp(
+ aTextData.GetContentObj().getRightText(), uno::UNO_QUERY);
+ xTextRange = xTemp;
+ }
+ break;
+ }
+
+ pHeaderField->InitDoc(
+ xTextRange, &aTextData.GetContentObj(), aTextData.GetPart(), aSelection);
// for bAbsorb=FALSE, the new selection must be behind the inserted content
// (the xml filter relies on this)