Kaydet (Commit) 40af04ce authored tarafından Kohei Yoshida's avatar Kohei Yoshida

fdo#62116: Handle field objects with formats correctly.

Field objects can have formats applied to them, and when they do, they
appear inside a <text:span> element.

Change-Id: I7b4346389f393a4ddf708670b2c524a6594128b5
üst 665cd87e
......@@ -75,24 +75,25 @@ void ScXMLCellTextParaContext::PushSpan(const OUString& rSpan, const OUString& r
mrParentCxt.PushParagraphSpan(rSpan, rStyleName);
}
void ScXMLCellTextParaContext::PushFieldSheetName()
void ScXMLCellTextParaContext::PushFieldSheetName(const OUString& rStyleName)
{
mrParentCxt.PushParagraphFieldSheetName();
mrParentCxt.PushParagraphFieldSheetName(rStyleName);
}
void ScXMLCellTextParaContext::PushFieldDate()
void ScXMLCellTextParaContext::PushFieldDate(const OUString& rStyleName)
{
mrParentCxt.PushParagraphFieldDate();
mrParentCxt.PushParagraphFieldDate(rStyleName);
}
void ScXMLCellTextParaContext::PushFieldTitle()
void ScXMLCellTextParaContext::PushFieldTitle(const OUString& rStyleName)
{
mrParentCxt.PushParagraphFieldDocTitle();
mrParentCxt.PushParagraphFieldDocTitle(rStyleName);
}
void ScXMLCellTextParaContext::PushFieldURL(const OUString& rURL, const OUString& rRep)
void ScXMLCellTextParaContext::PushFieldURL(
const OUString& rURL, const OUString& rRep, const OUString& rStyleName)
{
mrParentCxt.PushParagraphFieldURL(rURL, rRep);
mrParentCxt.PushParagraphFieldURL(rURL, rRep, rStyleName);
}
ScXMLCellTextSpanContext::ScXMLCellTextSpanContext(
......@@ -145,6 +146,43 @@ void ScXMLCellTextSpanContext::Characters(const OUString& rChars)
SvXMLImportContext* ScXMLCellTextSpanContext::CreateChildContext(
sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
{
if (!maContent.isEmpty())
{
mrParentCxt.PushSpan(maContent, maStyleName);
maContent = OUString();
}
const SvXMLTokenMap& rTokenMap = GetScImport().GetCellTextSpanElemTokenMap();
switch (rTokenMap.Get(nPrefix, rLocalName))
{
case XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME:
{
ScXMLCellFieldSheetNameContext* p = new ScXMLCellFieldSheetNameContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
p->SetStyleName(maStyleName);
return p;
}
case XML_TOK_CELL_TEXT_SPAN_ELEM_DATE:
{
ScXMLCellFieldDateContext* p = new ScXMLCellFieldDateContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
p->SetStyleName(maStyleName);
return p;
}
case XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE:
{
ScXMLCellFieldTitleContext* p = new ScXMLCellFieldTitleContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
p->SetStyleName(maStyleName);
return p;
}
case XML_TOK_CELL_TEXT_SPAN_ELEM_URL:
{
ScXMLCellFieldURLContext* p = new ScXMLCellFieldURLContext(GetScImport(), nPrefix, rLocalName, mrParentCxt);
p->SetStyleName(maStyleName);
return p;
}
default:
;
}
return new SvXMLImportContext(GetImport(), nPrefix, rLocalName);
}
......@@ -155,6 +193,11 @@ ScXMLCellFieldSheetNameContext::ScXMLCellFieldSheetNameContext(
{
}
void ScXMLCellFieldSheetNameContext::SetStyleName(const OUString& rStyleName)
{
maStyleName = rStyleName;
}
void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
{
// <text:sheet-name> has no attributes (that I'm aware of).
......@@ -162,7 +205,7 @@ void ScXMLCellFieldSheetNameContext::StartElement(const uno::Reference<xml::sax:
void ScXMLCellFieldSheetNameContext::EndElement()
{
mrParentCxt.PushFieldSheetName();
mrParentCxt.PushFieldSheetName(maStyleName);
}
void ScXMLCellFieldSheetNameContext::Characters(const OUString& /*rChars*/)
......@@ -182,13 +225,18 @@ ScXMLCellFieldDateContext::ScXMLCellFieldDateContext(
{
}
void ScXMLCellFieldDateContext::SetStyleName(const OUString& rStyleName)
{
maStyleName = rStyleName;
}
void ScXMLCellFieldDateContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
{
}
void ScXMLCellFieldDateContext::EndElement()
{
mrParentCxt.PushFieldDate();
mrParentCxt.PushFieldDate(maStyleName);
}
void ScXMLCellFieldDateContext::Characters(const OUString& /*rChars*/)
......@@ -208,13 +256,18 @@ ScXMLCellFieldTitleContext::ScXMLCellFieldTitleContext(
{
}
void ScXMLCellFieldTitleContext::SetStyleName(const OUString& rStyleName)
{
maStyleName = rStyleName;
}
void ScXMLCellFieldTitleContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& /*xAttrList*/)
{
}
void ScXMLCellFieldTitleContext::EndElement()
{
mrParentCxt.PushFieldTitle();
mrParentCxt.PushFieldTitle(maStyleName);
}
void ScXMLCellFieldTitleContext::Characters(const OUString& /*rChars*/)
......@@ -234,6 +287,11 @@ ScXMLCellFieldURLContext::ScXMLCellFieldURLContext(
{
}
void ScXMLCellFieldURLContext::SetStyleName(const OUString& rStyleName)
{
maStyleName = rStyleName;
}
void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttributeList>& xAttrList)
{
if (!xAttrList.is())
......@@ -266,7 +324,7 @@ void ScXMLCellFieldURLContext::StartElement(const uno::Reference<xml::sax::XAttr
void ScXMLCellFieldURLContext::EndElement()
{
mrParentCxt.PushFieldURL(maURL, maRep);
mrParentCxt.PushFieldURL(maURL, maRep, maStyleName);
}
void ScXMLCellFieldURLContext::Characters(const OUString& rChars)
......
......@@ -32,10 +32,10 @@ public:
sal_uInt16 nPrefix, const OUString& rLocalName, const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
void PushSpan(const OUString& rSpan, const OUString& rStyleName);
void PushFieldSheetName();
void PushFieldDate();
void PushFieldTitle();
void PushFieldURL(const OUString& rURL, const OUString& rRep);
void PushFieldSheetName(const OUString& rStyleName);
void PushFieldDate(const OUString& rStyleName);
void PushFieldTitle(const OUString& rStyleName);
void PushFieldURL(const OUString& rURL, const OUString& rRep, const OUString& rStyleName);
};
/**
......@@ -62,9 +62,12 @@ public:
class ScXMLCellFieldSheetNameContext : public ScXMLImportContext
{
ScXMLCellTextParaContext& mrParentCxt;
OUString maStyleName;
public:
ScXMLCellFieldSheetNameContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
void SetStyleName(const OUString& rStyleName);
virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
virtual void EndElement();
virtual void Characters(const OUString& rChars);
......@@ -78,9 +81,12 @@ public:
class ScXMLCellFieldDateContext : public ScXMLImportContext
{
ScXMLCellTextParaContext& mrParentCxt;
OUString maStyleName;
public:
ScXMLCellFieldDateContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
void SetStyleName(const OUString& rStyleName);
virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
virtual void EndElement();
virtual void Characters(const OUString& rChars);
......@@ -94,9 +100,12 @@ public:
class ScXMLCellFieldTitleContext : public ScXMLImportContext
{
ScXMLCellTextParaContext& mrParentCxt;
OUString maStyleName;
public:
ScXMLCellFieldTitleContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
void SetStyleName(const OUString& rStyleName);
virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
virtual void EndElement();
virtual void Characters(const OUString& rChars);
......@@ -105,16 +114,19 @@ public:
};
/**
* This context handles <text:a> element inside <text:p>.
* This context handles <text:a> element inside <text:p> or <text:span>.
*/
class ScXMLCellFieldURLContext : public ScXMLImportContext
{
ScXMLCellTextParaContext& mrParentCxt;
OUString maStyleName;
OUString maURL;
OUString maRep;
public:
ScXMLCellFieldURLContext(ScXMLImport& rImport, sal_uInt16 nPrefix, const OUString& rLName, ScXMLCellTextParaContext& rParent);
void SetStyleName(const OUString& rStyleName);
virtual void StartElement(const com::sun::star::uno::Reference<com::sun::star::xml::sax::XAttributeList>& xAttrList);
virtual void EndElement();
virtual void Characters(const OUString& rChars);
......
......@@ -337,6 +337,26 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU
sal_Int32 nEnd = nBegin + rSpan.getLength();
maParagraph.append(rSpan);
PushFormat(nBegin, nEnd, rStyleName);
}
void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData, const OUString& rStyleName)
{
maFields.push_back(new Field(pData));
Field& rField = maFields.back();
sal_Int32 nPos = maParagraph.getLength();
maParagraph.append(sal_Unicode('\1')); // Placeholder text for inserted field item.
rField.maSelection.nStartPara = mnCurParagraph;
rField.maSelection.nEndPara = mnCurParagraph;
rField.maSelection.nStartPos = nPos;
rField.maSelection.nEndPos = nPos+1;
PushFormat(nPos, nPos+1, rStyleName);
}
void ScXMLTableRowCellContext::PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName)
{
if (rStyleName.isEmpty())
return;
......@@ -559,38 +579,26 @@ void ScXMLTableRowCellContext::PushParagraphSpan(const OUString& rSpan, const OU
rFmt.maItemSet.Put(*pPoolItem);
}
void ScXMLTableRowCellContext::PushParagraphField(SvxFieldData* pData)
{
maFields.push_back(new Field(pData));
Field& rField = maFields.back();
sal_Int32 nPos = maParagraph.getLength();
maParagraph.append(sal_Unicode('\1')); // Placeholder text for inserted field item.
rField.maSelection.nStartPara = mnCurParagraph;
rField.maSelection.nEndPara = mnCurParagraph;
rField.maSelection.nStartPos = nPos;
rField.maSelection.nEndPos = nPos+1;
}
void ScXMLTableRowCellContext::PushParagraphFieldDate()
void ScXMLTableRowCellContext::PushParagraphFieldDate(const OUString& rStyleName)
{
PushParagraphField(new SvxDateField);
PushParagraphField(new SvxDateField, rStyleName);
}
void ScXMLTableRowCellContext::PushParagraphFieldSheetName()
void ScXMLTableRowCellContext::PushParagraphFieldSheetName(const OUString& rStyleName)
{
SCTAB nTab = GetScImport().GetTables().GetCurrentCellPos().Tab();
PushParagraphField(new SvxTableField(nTab));
PushParagraphField(new SvxTableField(nTab), rStyleName);
}
void ScXMLTableRowCellContext::PushParagraphFieldDocTitle()
void ScXMLTableRowCellContext::PushParagraphFieldDocTitle(const OUString& rStyleName)
{
PushParagraphField(new SvxFileField);
PushParagraphField(new SvxFileField, rStyleName);
}
void ScXMLTableRowCellContext::PushParagraphFieldURL(const OUString& rURL, const OUString& rRep)
void ScXMLTableRowCellContext::PushParagraphFieldURL(
const OUString& rURL, const OUString& rRep, const OUString& rStyleName)
{
PushParagraphField(new SvxURLField(rURL, rRep, SVXURLFORMAT_REPR));
PushParagraphField(new SvxURLField(rURL, rRep, SVXURLFORMAT_REPR), rStyleName);
}
void ScXMLTableRowCellContext::PushParagraphEnd()
......
......@@ -118,7 +118,9 @@ class ScXMLTableRowCellContext : public ScXMLImportContext
bool IsPossibleErrorString() const;
void PushParagraphField(SvxFieldData* pData);
void PushParagraphField(SvxFieldData* pData, const OUString& rStyleName);
void PushFormat(sal_Int32 nBegin, sal_Int32 nEnd, const OUString& rStyleName);
public:
......@@ -136,10 +138,10 @@ public:
::com::sun::star::xml::sax::XAttributeList>& xAttrList );
void PushParagraphSpan(const OUString& rSpan, const OUString& rStyleName);
void PushParagraphFieldDate();
void PushParagraphFieldSheetName();
void PushParagraphFieldDocTitle();
void PushParagraphFieldURL(const OUString& rURL, const OUString& rRep);
void PushParagraphFieldDate(const OUString& rStyleName);
void PushParagraphFieldSheetName(const OUString& rStyleName);
void PushParagraphFieldDocTitle(const OUString& rStyleName);
void PushParagraphFieldURL(const OUString& rURL, const OUString& rRep, const OUString& rStyleName);
void PushParagraphEnd();
void SetAnnotation( const ScAddress& rPosition );
......
......@@ -1860,6 +1860,24 @@ const SvXMLTokenMap& ScXMLImport::GetCellTextParaElemTokenMap()
return *pCellTextParaElemTokenMap;
}
const SvXMLTokenMap& ScXMLImport::GetCellTextSpanElemTokenMap()
{
if (!pCellTextSpanElemTokenMap)
{
static SvXMLTokenMapEntry aMap[] =
{
{ XML_NAMESPACE_TEXT, XML_SHEET_NAME, XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME },
{ XML_NAMESPACE_TEXT, XML_DATE, XML_TOK_CELL_TEXT_SPAN_ELEM_DATE },
{ XML_NAMESPACE_TEXT, XML_TITLE, XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE },
{ XML_NAMESPACE_TEXT, XML_A, XML_TOK_CELL_TEXT_SPAN_ELEM_URL },
XML_TOKEN_MAP_END
};
pCellTextSpanElemTokenMap = new SvXMLTokenMap(aMap);
}
return *pCellTextSpanElemTokenMap;
}
const SvXMLTokenMap& ScXMLImport::GetCellTextSpanAttrTokenMap()
{
if (!pCellTextSpanAttrTokenMap)
......@@ -2013,6 +2031,7 @@ ScXMLImport::ScXMLImport(
pDataPilotMemberAttrTokenMap( 0 ),
pConsolidationAttrTokenMap( 0 ),
pCellTextParaElemTokenMap(NULL),
pCellTextSpanElemTokenMap(NULL),
pCellTextSpanAttrTokenMap(NULL),
pCellTextURLAttrTokenMap(NULL),
aTables(*this),
......@@ -2153,6 +2172,7 @@ ScXMLImport::~ScXMLImport() throw()
delete pDataPilotMemberAttrTokenMap;
delete pConsolidationAttrTokenMap;
delete pCellTextParaElemTokenMap;
delete pCellTextSpanElemTokenMap;
delete pCellTextSpanAttrTokenMap;
delete pCellTextURLAttrTokenMap;
......
......@@ -694,6 +694,17 @@ enum ScXMLCellTextParaElemTokens
XML_TOK_CELL_TEXT_URL
};
/**
* Tokens for elements that come under <text:span>
*/
enum ScXMLCellTextSpanElemTokens
{
XML_TOK_CELL_TEXT_SPAN_ELEM_SHEET_NAME,
XML_TOK_CELL_TEXT_SPAN_ELEM_DATE,
XML_TOK_CELL_TEXT_SPAN_ELEM_TITLE,
XML_TOK_CELL_TEXT_SPAN_ELEM_URL
};
/**
* Tokens for attributes for <text:span>
*/
......@@ -877,6 +888,7 @@ class ScXMLImport: public SvXMLImport, boost::noncopyable
SvXMLTokenMap *pDataPilotMemberAttrTokenMap;
SvXMLTokenMap *pConsolidationAttrTokenMap;
SvXMLTokenMap *pCellTextParaElemTokenMap;
SvXMLTokenMap *pCellTextSpanElemTokenMap;
SvXMLTokenMap *pCellTextSpanAttrTokenMap;
SvXMLTokenMap *pCellTextURLAttrTokenMap;
......@@ -1045,6 +1057,7 @@ public:
const SvXMLTokenMap& GetDataPilotMemberAttrTokenMap();
const SvXMLTokenMap& GetConsolidationAttrTokenMap();
const SvXMLTokenMap& GetCellTextParaElemTokenMap();
const SvXMLTokenMap& GetCellTextSpanElemTokenMap();
const SvXMLTokenMap& GetCellTextSpanAttrTokenMap();
const SvXMLTokenMap& GetCellTextURLAttrTokenMap();
......
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