Kaydet (Commit) 486fa0ba authored tarafından Kohei Yoshida's avatar Kohei Yoshida

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.
üst e04892db
......@@ -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 )
......
......@@ -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
......
......@@ -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;
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment