summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-05-16 00:25:51 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2015-05-16 07:26:39 +0200
commit37d6f7a18453658147dd1c32a90915c6a603a857 (patch)
tree5ad225c233b3253685577b1f1fd578deddc9cbab
parent4eb19ec569579137de9d835fe584e47b871c4e8c (diff)
export iconSet to extLst
Change-Id: I7606c5cb6321cfec9b36332dcd76fbad81d269d6
-rw-r--r--sc/source/filter/excel/xecontent.cxx138
-rw-r--r--sc/source/filter/excel/xeextlst.cxx177
-rw-r--r--sc/source/filter/inc/xecontent.hxx4
-rw-r--r--sc/source/filter/inc/xeextlst.hxx44
4 files changed, 300 insertions, 63 deletions
diff --git a/sc/source/filter/excel/xecontent.cxx b/sc/source/filter/excel/xecontent.cxx
index 2913107c539d..ca05734ed370 100644
--- a/sc/source/filter/excel/xecontent.cxx
+++ b/sc/source/filter/excel/xecontent.cxx
@@ -1125,6 +1125,40 @@ void XclExpColScaleCol::SaveXml( XclExpXmlStream& rStrm )
rWorksheet->endElement( XML_color );
}
+namespace {
+
+OString createHexStringFromDigit(sal_uInt8 nDigit)
+{
+ OString aString = OString::number( nDigit, 16 );
+ if(aString.getLength() == 1)
+ aString = aString + OString::number(0);
+ return aString;
+}
+
+OString createGuidStringFromInt(sal_uInt8 nGuid[16])
+{
+ OStringBuffer aBuffer;
+ aBuffer.append('{');
+ for(size_t i = 0; i < 16; ++i)
+ {
+ aBuffer.append(createHexStringFromDigit(nGuid[i]));
+ if(i == 3|| i == 5 || i == 7 || i == 9 )
+ aBuffer.append('-');
+ }
+ aBuffer.append('}');
+ OString aString = aBuffer.makeStringAndClear();
+ return aString.toAsciiUpperCase();
+}
+
+OString generateGUIDString()
+{
+ sal_uInt8 nGuid[16];
+ rtl_createUuid(nGuid, NULL, true);
+ return createGuidStringFromInt(nGuid);
+}
+
+}
+
XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat, XclExtLstRef xExtLst, sal_Int32& rIndex ) :
XclExpRecord( EXC_ID_CONDFMT ),
XclExpRoot( rRoot )
@@ -1133,6 +1167,7 @@ XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat
GetAddressConverter().ConvertRangeList( maXclRanges, aScRanges, true );
if( !maXclRanges.empty() )
{
+ std::vector<XclExpExtCondFormatData> aExtEntries;
for( size_t nIndex = 0, nCount = rCondFormat.size(); nIndex < nCount; ++nIndex )
if( const ScFormatEntry* pFormatEntry = rCondFormat.GetEntry( nIndex ) )
{
@@ -1141,13 +1176,65 @@ XclExpCondfmt::XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat
else if(pFormatEntry->GetType() == condformat::COLORSCALE)
maCFList.AppendNewRecord( new XclExpColorScale( GetRoot(), static_cast<const ScColorScaleFormat&>(*pFormatEntry), ++rIndex ) );
else if(pFormatEntry->GetType() == condformat::DATABAR)
- maCFList.AppendNewRecord( new XclExpDataBar( GetRoot(), static_cast<const ScDataBarFormat&>(*pFormatEntry), ++rIndex, xExtLst ) );
+ {
+ const ScDataBarFormat& rFormat = static_cast<const ScDataBarFormat&>(*pFormatEntry);
+ XclExpExtCondFormatData aExtEntry;
+ aExtEntry.nPriority = -1;
+ aExtEntry.aGUID = generateGUIDString();
+ aExtEntry.pEntry = &rFormat;
+ aExtEntries.push_back(aExtEntry);
+
+ maCFList.AppendNewRecord( new XclExpDataBar( GetRoot(), rFormat, ++rIndex, aExtEntry.aGUID));
+ }
else if(pFormatEntry->GetType() == condformat::ICONSET)
- maCFList.AppendNewRecord( new XclExpIconSet( GetRoot(), static_cast<const ScIconSetFormat&>(*pFormatEntry), ++rIndex ) );
+ {
+ // don't export iconSet entries that are not in OOXML
+ const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(*pFormatEntry);
+ bool bNeedsExt = false;
+ switch (rIconSet.GetIconSetData()->eIconSetType)
+ {
+ case IconSet_3Smilies:
+ case IconSet_3ColorSmilies:
+ case IconSet_3Stars:
+ case IconSet_3Triangles:
+ case IconSet_5Boxes:
+ {
+ bNeedsExt = true;
+ }
+ break;
+ default:
+ break;
+ }
+
+ bNeedsExt |= rIconSet.GetIconSetData()->mbCustom;
+
+ if (bNeedsExt)
+ {
+ XclExpExtCondFormatData aExtEntry;
+ aExtEntry.nPriority = ++rIndex;
+ aExtEntry.aGUID = generateGUIDString();
+ aExtEntry.pEntry = &rIconSet;
+ aExtEntries.push_back(aExtEntry);
+ }
+ else
+ maCFList.AppendNewRecord( new XclExpIconSet( GetRoot(), rIconSet, ++rIndex ) );
+ }
else if(pFormatEntry->GetType() == condformat::DATE)
maCFList.AppendNewRecord( new XclExpDateFormat( GetRoot(), static_cast<const ScCondDateFormatEntry&>(*pFormatEntry), ++rIndex ) );
}
aScRanges.Format( msSeqRef, SCA_VALID, NULL, formula::FormulaGrammar::CONV_XL_A1 );
+
+ if(!aExtEntries.empty() && xExtLst.get())
+ {
+ XclExpExtRef pParent = xExtLst->GetItem( XclExpExtDataBarType );
+ if( !pParent.get() )
+ {
+ xExtLst->AddRecord( XclExpExtRef(new XclExpExtCondFormat( *xExtLst.get() )) );
+ pParent = xExtLst->GetItem( XclExpExtDataBarType );
+ }
+ static_cast<XclExpExtCondFormat*>(xExtLst->GetItem( XclExpExtDataBarType ).get())->AddRecord(
+ XclExpExtConditionalFormattingRef(new XclExpExtConditionalFormatting( *pParent, aExtEntries, aScRanges)));
+ }
}
}
@@ -1234,38 +1321,12 @@ void XclExpColorScale::SaveXml( XclExpXmlStream& rStrm )
rWorksheet->endElement( XML_cfRule );
}
-namespace {
-
-OString createHexStringFromDigit(sal_uInt8 nDigit)
-{
- OString aString = OString::number( nDigit, 16 );
- if(aString.getLength() == 1)
- aString = aString + OString::number(0);
- return aString;
-}
-
-OString createGuidStringFromInt(sal_uInt8 nGuid[16])
-{
- OStringBuffer aBuffer;
- aBuffer.append('{');
- for(size_t i = 0; i < 16; ++i)
- {
- aBuffer.append(createHexStringFromDigit(nGuid[i]));
- if(i == 3|| i == 5 || i == 7 || i == 9 )
- aBuffer.append('-');
- }
- aBuffer.append('}');
- OString aString = aBuffer.makeStringAndClear();
- return aString.toAsciiUpperCase();
-}
-
-}
-
-XclExpDataBar::XclExpDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, sal_Int32 nPriority, XclExtLstRef xExtLst ):
+XclExpDataBar::XclExpDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, sal_Int32 nPriority, const OString& rGUID):
XclExpRecord(),
XclExpRoot( rRoot ),
mrFormat( rFormat ),
- mnPriority( nPriority )
+ mnPriority( nPriority ),
+ maGUID(rGUID)
{
const ScRange* pRange = rFormat.GetRange().front();
ScAddress aAddr = pRange->aStart;
@@ -1274,19 +1335,6 @@ XclExpDataBar::XclExpDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rF
mpCfvoUpperLimit.reset( new XclExpCfvo( GetRoot(), *mrFormat.GetDataBarData()->mpUpperLimit.get(), aAddr, false ) );
mpCol.reset( new XclExpColScaleCol( GetRoot(), mrFormat.GetDataBarData()->maPositiveColor ) );
- if(xExtLst.get())
- {
- XclExpExtRef pParent = xExtLst->GetItem( XclExpExtDataBarType );
- if( !pParent.get() )
- {
- xExtLst->AddRecord( XclExpExtRef(new XclExpExtCondFormat( *xExtLst.get() )) );
- pParent = xExtLst->GetItem( XclExpExtDataBarType );
- }
- sal_uInt8 nGuid[16];
- rtl_createUuid(nGuid, NULL, true);
- maGuid = createGuidStringFromInt(nGuid);
- static_cast<XclExpExtCondFormat*>(xExtLst->GetItem( XclExpExtDataBarType ).get())->AddRecord( XclExpExtConditionalFormattingRef(new XclExpExtConditionalFormatting( *pParent, rFormat, aAddr, maGuid) ));
- }
}
void XclExpDataBar::SaveXml( XclExpXmlStream& rStrm )
@@ -1318,7 +1366,7 @@ void XclExpDataBar::SaveXml( XclExpXmlStream& rStrm )
FSEND );
rWorksheet->startElementNS( XML_x14, XML_id, FSEND );
- rWorksheet->write( maGuid.getStr() );
+ rWorksheet->write( maGUID.getStr() );
rWorksheet->endElementNS( XML_x14, XML_id );
rWorksheet->endElement( XML_ext );
diff --git a/sc/source/filter/excel/xeextlst.cxx b/sc/source/filter/excel/xeextlst.cxx
index 885e1fdecdd9..c90b57f591da 100644
--- a/sc/source/filter/excel/xeextlst.cxx
+++ b/sc/source/filter/excel/xeextlst.cxx
@@ -17,6 +17,22 @@
using namespace ::oox;
+namespace {
+
+const char* getIconSetName( ScIconSetType eType )
+{
+ ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap();
+ for(; pMap->pName; ++pMap)
+ {
+ if(pMap->eType == eType)
+ return pMap->pName;
+ }
+
+ return "";
+}
+
+}
+
XclExpExt::XclExpExt( const XclExpRoot& rRoot ):
XclExpRoot(rRoot)
{
@@ -51,6 +67,29 @@ void XclExpExtAxisColor::SaveXml( XclExpXmlStream& rStrm )
FSEND );
}
+XclExpExtIcon::XclExpExtIcon(const XclExpRoot& rRoot, const std::pair<ScIconSetType, sal_Int32>& rCustomEntry):
+ XclExpRoot(rRoot),
+ nIndex(rCustomEntry.second)
+{
+ pIconSetName = getIconSetName(rCustomEntry.first);
+}
+
+void XclExpExtIcon::SaveXml(XclExpXmlStream& rStrm)
+{
+ sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
+
+ if (nIndex == -1)
+ {
+ nIndex = 0;
+ pIconSetName = "NoIcons";
+ }
+
+ rWorksheet->singleElementNS(XML_x14, XML_cfIcon,
+ XML_iconSet, pIconSetName,
+ XML_iconId, OString::number(nIndex).getStr(),
+ FSEND);
+}
+
XclExpExtCfvo::XclExpExtCfvo( const XclExpRoot& rRoot, const ScColorScaleEntry& rEntry, const ScAddress& rSrcPos, bool bFirst ):
XclExpRoot(rRoot),
meType(rEntry.GetType()),
@@ -103,10 +142,21 @@ const char* getColorScaleType( ScColorScaleEntryType eType, bool bFirst )
void XclExpExtCfvo::SaveXml( XclExpXmlStream& rStrm )
{
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
- rWorksheet->singleElementNS( XML_x14, XML_cfvo,
+ rWorksheet->startElementNS( XML_x14, XML_cfvo,
XML_type, getColorScaleType(meType, mbFirst),
- XML_value, maValue.getStr(),
FSEND );
+
+ if (meType == COLORSCALE_FORMULA ||
+ meType == COLORSCALE_PERCENT ||
+ meType == COLORSCALE_PERCENTILE ||
+ meType == COLORSCALE_VALUE)
+ {
+ rWorksheet->startElementNS(XML_xm, XML_f, FSEND);
+ rWorksheet->writeEscaped(maValue.getStr());
+ rWorksheet->endElementNS(XML_xm, XML_f);
+ }
+
+ rWorksheet->endElementNS(XML_x14, XML_cfvo);
}
XclExpExtDataBar::XclExpExtDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos ):
@@ -163,32 +213,135 @@ void XclExpExtDataBar::SaveXml( XclExpXmlStream& rStrm )
rWorksheet->endElementNS( XML_x14, XML_dataBar );
}
-XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId ):
+XclExpExtIconSet::XclExpExtIconSet(const XclExpRoot& rRoot, const ScIconSetFormat& rFormat, const ScAddress& rPos):
+ XclExpRoot(rRoot)
+{
+ const ScIconSetFormatData& rData = *rFormat.GetIconSetData();
+ for (auto itr = rData.maEntries.begin(); itr != rData.maEntries.end(); ++itr)
+ {
+ maCfvos.AppendNewRecord(new XclExpExtCfvo(*this, *itr, rPos, false));
+ }
+ mbCustom = rData.mbCustom;
+ mbReverse = rData.mbReverse;
+ mbShowValue = rData.mbShowValue;
+ mpIconSetName = getIconSetName(rData.eIconSetType);
+
+ if (mbCustom)
+ {
+ for (auto itr = rData.maCustomVector.begin(); itr != rData.maCustomVector.end(); ++itr)
+ {
+ maCustom.AppendNewRecord(new XclExpExtIcon(*this, *itr));
+ }
+ }
+}
+
+void XclExpExtIconSet::SaveXml(XclExpXmlStream& rStrm)
+{
+ sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
+
+ rWorksheet->startElementNS(XML_x14, XML_iconSet,
+ XML_iconSet, mpIconSetName,
+ XML_custom, mbCustom ? XclXmlUtils::ToPsz10(mbCustom) : NULL,
+ XML_reverse, XclXmlUtils::ToPsz10(mbReverse),
+ XML_showValue, XclXmlUtils::ToPsz10(mbShowValue),
+ FSEND);
+
+ maCfvos.SaveXml(rStrm);
+
+ if (mbCustom)
+ {
+ maCustom.SaveXml(rStrm);
+ }
+
+ rWorksheet->endElementNS(XML_x14, XML_iconSet);
+}
+
+XclExpExtCfRule::XclExpExtCfRule( const XclExpRoot& rRoot, const ScFormatEntry& rFormat, const ScAddress& rPos, const OString& rId, sal_Int32 nPriority ):
XclExpRoot(rRoot),
- maId(rId)
+ maId(rId),
+ mnPriority(nPriority)
{
- maDataBar.reset( new XclExpExtDataBar( *this, rFormat, rPos ) );
+ switch (rFormat.GetType())
+ {
+ case condformat::DATABAR:
+ {
+ const ScDataBarFormat& rDataBar = static_cast<const ScDataBarFormat&>(rFormat);
+ mxEntry.reset( new XclExpExtDataBar( *this, rDataBar, rPos ) );
+ pType = "dataBar";
+ }
+ break;
+ case condformat::ICONSET:
+ {
+ const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(rFormat);
+ mxEntry.reset(new XclExpExtIconSet(*this, rIconSet, rPos));
+ pType = "iconSet";
+ }
+ default:
+ break;
+ }
}
void XclExpExtCfRule::SaveXml( XclExpXmlStream& rStrm )
{
+ if (!mxEntry)
+ return;
+
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
rWorksheet->startElementNS( XML_x14, XML_cfRule,
- XML_type, "dataBar",
+ XML_type, pType,
+ XML_priority, mnPriority == -1 ? NULL : OString::number(mnPriority).getStr(),
XML_id, maId.getStr(),
FSEND );
- maDataBar->SaveXml( rStrm );
+ mxEntry->SaveXml( rStrm );
rWorksheet->endElementNS( XML_x14, XML_cfRule );
}
-XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId ):
- XclExpRoot(rRoot)
+XclExpExtConditionalFormatting::XclExpExtConditionalFormatting( const XclExpRoot& rRoot,
+ std::vector<XclExpExtCondFormatData>& rData, const ScRangeList& rRange):
+ XclExpRoot(rRoot),
+ maRange(rRange)
{
- maCfRule.reset( new XclExpExtCfRule( *this, rFormat, rPos, rId ) );
- maRange = rFormat.GetRange();
+ ScAddress aAddr = maRange.front()->aStart;
+ for (auto itr = rData.begin(), itrEnd = rData.end(); itr != itrEnd; ++itr)
+ {
+ const ScFormatEntry* pEntry = itr->pEntry;
+ switch (pEntry->GetType())
+ {
+ case condformat::ICONSET:
+ {
+ const ScIconSetFormat& rIconSet = static_cast<const ScIconSetFormat&>(*pEntry);
+ bool bNeedsExt = false;
+ switch (rIconSet.GetIconSetData()->eIconSetType)
+ {
+ case IconSet_3Triangles:
+ case IconSet_3Smilies:
+ case IconSet_3ColorSmilies:
+ case IconSet_5Boxes:
+ bNeedsExt = true;
+ break;
+ default:
+ break;
+ }
+
+ if (rIconSet.GetIconSetData()->mbCustom)
+ bNeedsExt = true;
+
+ if (bNeedsExt)
+ {
+ maCfRules.AppendNewRecord(new XclExpExtCfRule(*this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
+ }
+ }
+ break;
+ case condformat::DATABAR:
+ maCfRules.AppendNewRecord(new XclExpExtCfRule( *this, *pEntry, aAddr, itr->aGUID, itr->nPriority));
+ break;
+ default:
+ break;
+ }
+ }
}
void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
@@ -198,7 +351,7 @@ void XclExpExtConditionalFormatting::SaveXml( XclExpXmlStream& rStrm )
FSNS( XML_xmlns, XML_xm ), "http://schemas.microsoft.com/office/excel/2006/main",
FSEND );
- maCfRule->SaveXml( rStrm );
+ maCfRules.SaveXml( rStrm );
rWorksheet->startElementNS( XML_xm, XML_sqref, FSEND );
rWorksheet->write(XclXmlUtils::ToOString(maRange).getStr());
diff --git a/sc/source/filter/inc/xecontent.hxx b/sc/source/filter/inc/xecontent.hxx
index 07334c2122af..d986d75fcfa4 100644
--- a/sc/source/filter/inc/xecontent.hxx
+++ b/sc/source/filter/inc/xecontent.hxx
@@ -269,7 +269,7 @@ private:
class XclExpDataBar : public XclExpRecord, protected XclExpRoot
{
public:
- explicit XclExpDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, sal_Int32 nPriority, XclExtLstRef xExtLst );
+ explicit XclExpDataBar( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, sal_Int32 nPriority, const OString& rGUID);
virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
private:
@@ -279,7 +279,7 @@ private:
const ScDataBarFormat& mrFormat;
sal_Int32 mnPriority;
- OString maGuid;
+ OString maGUID;
};
class XclExpIconSet : public XclExpRecord, protected XclExpRoot
diff --git a/sc/source/filter/inc/xeextlst.hxx b/sc/source/filter/inc/xeextlst.hxx
index e92afd5ffb87..f148f836186e 100644
--- a/sc/source/filter/inc/xeextlst.hxx
+++ b/sc/source/filter/inc/xeextlst.hxx
@@ -22,6 +22,14 @@ enum XclExpExtType
XclExpExtDataBarType
};
+struct XclExpExtCondFormatData
+{
+ // -1 means don't write priority
+ sal_Int32 nPriority;
+ OString aGUID;
+ const ScFormatEntry* pEntry;
+};
+
/**
* Base class for ext entries. Extend this class to provide the needed functionality
*
@@ -69,6 +77,17 @@ private:
Color maAxisColor;
};
+class XclExpExtIcon : public XclExpRecordBase, protected XclExpRoot
+{
+public:
+ explicit XclExpExtIcon( const XclExpRoot& rRoot, const std::pair<ScIconSetType, sal_Int32>& rCustomEntry);
+ virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
+
+private:
+ const char* pIconSetName;
+ sal_Int32 nIndex;
+};
+
class XclExpExtDataBar : public XclExpRecordBase, protected XclExpRoot
{
public:
@@ -88,17 +107,34 @@ private:
};
+class XclExpExtIconSet : public XclExpRecordBase, protected XclExpRoot
+{
+public:
+ explicit XclExpExtIconSet(const XclExpRoot& rRoot, const ScIconSetFormat& rFormat, const ScAddress& rPos);
+ virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
+
+private:
+ XclExpRecordList<XclExpExtCfvo> maCfvos;
+ XclExpRecordList<XclExpExtIcon> maCustom;
+ bool mbCustom;
+ bool mbReverse;
+ bool mbShowValue;
+ const char* mpIconSetName;
+};
+
typedef std::shared_ptr<XclExpExtDataBar> XclExpExtDataBarRef;
class XclExpExtCfRule : public XclExpRecordBase, protected XclExpRoot
{
public:
- XclExpExtCfRule( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId );
+ XclExpExtCfRule( const XclExpRoot& rRoot, const ScFormatEntry& rFormat, const ScAddress& rPos, const OString& rId, sal_Int32 nPriority );
virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
private:
- XclExpExtDataBarRef maDataBar;
+ XclExpRecordRef mxEntry;
OString maId;
+ const char* pType;
+ sal_Int32 mnPriority;
};
typedef std::shared_ptr<XclExpExt> XclExpExtRef;
@@ -107,11 +143,11 @@ typedef std::shared_ptr<XclExpExtCfRule> XclExpExtCfRuleRef;
class XclExpExtConditionalFormatting : public XclExpRecordBase, protected XclExpRoot
{
public:
- explicit XclExpExtConditionalFormatting( const XclExpRoot& rRoot, const ScDataBarFormat& rFormat, const ScAddress& rPos, const OString& rId );
+ explicit XclExpExtConditionalFormatting( const XclExpRoot& rRoot, std::vector<XclExpExtCondFormatData>& rData, const ScRangeList& rRange);
virtual void SaveXml( XclExpXmlStream& rStrm ) SAL_OVERRIDE;
private:
- XclExpExtCfRuleRef maCfRule;
+ XclExpRecordList<XclExpExtCfRule> maCfRules;
ScRangeList maRange;
};