diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-11-01 03:05:09 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-11-02 14:58:09 +0100 |
commit | 3247394f9244212aadff733692e2c9ba76fc30e5 (patch) | |
tree | 281834292d75f68d1b536496c3bb5df2c6a8aa05 | |
parent | f73571b5897a53be28ee61d1d1693a5d64065f85 (diff) |
implement icon set import/export from odf
Change-Id: I7fb265194811ef8ba0b7aed04d4bd28181612ebc
-rw-r--r-- | sc/source/filter/xml/xmlcondformat.cxx | 116 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcondformat.hxx | 30 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.cxx | 41 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.cxx | 21 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlimprt.hxx | 17 | ||||
-rw-r--r-- | xmloff/inc/xmloff/xmltoken.hxx | 3 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 3 |
7 files changed, 197 insertions, 34 deletions
diff --git a/sc/source/filter/xml/xmlcondformat.cxx b/sc/source/filter/xml/xmlcondformat.cxx index 9733bd28e9a1..ef2b5909f268 100644 --- a/sc/source/filter/xml/xmlcondformat.cxx +++ b/sc/source/filter/xml/xmlcondformat.cxx @@ -121,6 +121,9 @@ SvXMLImportContext* ScXMLConditionalFormatContext::CreateChildContext( sal_uInt1 case XML_TOK_CONDFORMAT_DATABAR: pContext = new ScXMLDataBarFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat ); break; + case XML_TOK_CONDFORMAT_ICONSET: + pContext = new ScXMLIconSetFormatContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormat ); + break; default: break; } @@ -271,14 +274,26 @@ SvXMLImportContext* ScXMLDataBarFormatContext::CreateChildContext( sal_uInt16 nP const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) { - const SvXMLTokenMap& rTokenMap = GetScImport().GetDataBarTokenMap(); + const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap(); sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName); SvXMLImportContext* pContext = NULL; switch (nToken) { + case XML_TOK_FORMATTING_ENTRY: case XML_TOK_DATABAR_DATABARENTRY: - pContext = new ScXMLDataBarFormatEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, mpFormatData ); - break; + { + ScColorScaleEntry* pEntry; + pContext = new ScXMLDataBarFormatEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry ); + if(mpFormatData->mpLowerLimit) + { + mpFormatData->mpUpperLimit.reset(pEntry); + } + else + { + mpFormatData->mpLowerLimit.reset(pEntry); + } + } + break; default: break; } @@ -290,6 +305,79 @@ void ScXMLDataBarFormatContext::EndElement() { } +ScXMLIconSetFormatContext::ScXMLIconSetFormatContext(ScXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList, + ScConditionalFormat* pFormat): + SvXMLImportContext( rImport, nPrfx, rLName ) +{ + rtl::OUString aIconSetType; + sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0); + const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetIconSetAttrMap(); + for( sal_Int16 i=0; i < nAttrCount; ++i ) + { + const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i )); + rtl::OUString aLocalName; + sal_uInt16 nPrefix(GetScImport().GetNamespaceMap().GetKeyByAttrName( + sAttrName, &aLocalName )); + const rtl::OUString& sValue(xAttrList->getValueByIndex( i )); + + switch( rAttrTokenMap.Get( nPrefix, aLocalName ) ) + { + case XML_TOK_ICONSET_TYPE: + aIconSetType = sValue; + break; + default: + break; + } + } + + ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap(); + ScIconSetType eType = IconSet_3Arrows; + for(; pMap->pName; ++pMap) + { + rtl::OUString aName = rtl::OUString::createFromAscii(pMap->pName); + if(aName ==aIconSetType) + { + eType = pMap->eType; + break; + } + } + + ScIconSetFormat* pIconSetFormat = new ScIconSetFormat(GetScImport().GetDocument()); + ScIconSetFormatData* pIconSetFormatData = new ScIconSetFormatData; + pIconSetFormatData->eIconSetType = eType; + pIconSetFormat->SetIconSetData(pIconSetFormatData); + pFormat->AddEntry(pIconSetFormat); + + mpFormatData = pIconSetFormatData; +} + +SvXMLImportContext* ScXMLIconSetFormatContext::CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ) +{ + const SvXMLTokenMap& rTokenMap = GetScImport().GetFormattingTokenMap(); + sal_uInt16 nToken = rTokenMap.Get(nPrefix, rLocalName); + SvXMLImportContext* pContext = NULL; + switch (nToken) + { + case XML_TOK_FORMATTING_ENTRY: + { + ScColorScaleEntry* pEntry; + pContext = new ScXMLDataBarFormatEntryContext( GetScImport(), nPrefix, rLocalName, xAttrList, pEntry ); + mpFormatData->maEntries.push_back(pEntry); + } + break; + default: + break; + } + + return pContext; +} + namespace { void GetConditionData(const rtl::OUString& rValue, ScConditionMode& eMode, rtl::OUString& rExpr1, rtl::OUString& rExpr2) @@ -411,11 +499,6 @@ ScXMLCondContext::ScXMLCondContext( ScXMLImport& rImport, sal_uInt16 nPrfx, pFormat->AddEntry(pFormatEntry); } -void ScXMLCondContext::EndElement() -{ - -} - namespace { void setColorEntryType(const rtl::OUString& rType, ScColorScaleEntry* pEntry, const rtl::OUString rFormula, @@ -500,7 +583,7 @@ void ScXMLColorScaleFormatEntryContext::EndElement() ScXMLDataBarFormatEntryContext::ScXMLDataBarFormatEntryContext( ScXMLImport& rImport, sal_uInt16 nPrfx, const ::rtl::OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList, - ScDataBarFormatData* pData): + ScColorScaleEntry*& pColorScaleEntry): SvXMLImportContext( rImport, nPrfx, rLName ) { rtl::OUString sVal; @@ -533,19 +616,8 @@ ScXMLDataBarFormatEntryContext::ScXMLDataBarFormatEntryContext( ScXMLImport& rIm if(!sVal.isEmpty()) sax::Converter::convertDouble(nVal, sVal); - ScColorScaleEntry* pEntry = new ScColorScaleEntry(nVal, Color()); - setColorEntryType(sType, pEntry, sVal, GetScImport()); - if(pData->mpLowerLimit) - { - pData->mpUpperLimit.reset(pEntry); - } - else - { - pData->mpLowerLimit.reset(pEntry); - } + pColorScaleEntry = new ScColorScaleEntry(nVal, Color()); + setColorEntryType(sType, pColorScaleEntry, sVal, GetScImport()); } -void ScXMLDataBarFormatEntryContext::EndElement() -{ -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlcondformat.hxx b/sc/source/filter/xml/xmlcondformat.hxx index a31bdff6d2d7..9e7eba62c0c4 100644 --- a/sc/source/filter/xml/xmlcondformat.hxx +++ b/sc/source/filter/xml/xmlcondformat.hxx @@ -35,6 +35,7 @@ class ScColorScaleEntry; class ScDataBarFormat; struct ScDataBarFormatData; class ScConditionalFormat; +struct ScIconSetFormatData; class ScXMLConditionalFormatsContext : public SvXMLImportContext { @@ -132,6 +133,29 @@ private: }; +class ScXMLIconSetFormatContext : public SvXMLImportContext +{ + const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); } + ScXMLImport& GetScImport() { return (ScXMLImport&)GetImport(); } + + ScIconSetFormatData* mpFormatData; +public: + + ScXMLIconSetFormatContext( ScXMLImport& rImport, sal_uInt16 nPrfx, + const ::rtl::OUString& rLName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList, + ScConditionalFormat* pFormat); + + virtual ~ScXMLIconSetFormatContext() {} + + + virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, + const ::rtl::OUString& rLocalName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XAttributeList>& xAttrList ); +}; + class ScXMLColorScaleFormatEntryContext : public SvXMLImportContext { const ScXMLImport& GetScImport() const { return (const ScXMLImport&)GetImport(); } @@ -161,11 +185,9 @@ public: const ::rtl::OUString& rLName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList>& xAttrList, - ScDataBarFormatData* pData); + ScColorScaleEntry*& pData); virtual ~ScXMLDataBarFormatEntryContext() {} - - virtual void EndElement(); }; class ScXMLCondContext : public SvXMLImportContext @@ -180,8 +202,6 @@ public: ScConditionalFormat* pFormat); virtual ~ScXMLCondContext() {} - - virtual void EndElement(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index 46d35bf8c35c..fda1912f1073 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -3810,6 +3810,22 @@ rtl::OUString getCondFormatEntryType(const ScColorScaleEntry& rEntry, bool bFirs return rtl::OUString(); } +rtl::OUString getIconSetName(ScIconSetType eType) +{ + const char* pName = NULL; + ScIconSetMap* pMap = ScIconSetFormat::getIconSetMap(); + for(;pMap->pName;++pMap) + { + if(pMap->eType == eType) + { + pName = pMap->pName; + break; + } + } + assert(pName); + return rtl::OUString::createFromAscii(pName); +} + } void ScXMLExport::ExportConditionalFormat(SCTAB nTab) @@ -3980,7 +3996,7 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab) else AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, rtl::OUString::valueOf(pFormatData->mpLowerLimit->GetValue())); AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*pFormatData->mpLowerLimit, true)); - SvXMLElementExport aElementDataBarEntryLower(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_BAR_ENTRY, true, true); + SvXMLElementExport aElementDataBarEntryLower(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true); } { @@ -3992,7 +4008,28 @@ void ScXMLExport::ExportConditionalFormat(SCTAB nTab) else AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, rtl::OUString::valueOf(pFormatData->mpUpperLimit->GetValue())); AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*pFormatData->mpUpperLimit, false)); - SvXMLElementExport aElementDataBarEntryUpper(*this, XML_NAMESPACE_CALC_EXT, XML_DATA_BAR_ENTRY, true, true); + SvXMLElementExport aElementDataBarEntryUpper(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true); + } + } + else if(pFormatEntry->GetType() == condformat::ICONSET) + { + const ScIconSetFormat& mrIconSet = static_cast<const ScIconSetFormat&>(*pFormatEntry); + rtl::OUString aIconSetName = getIconSetName(mrIconSet.GetIconSetData()->eIconSetType); + AddAttribute( XML_NAMESPACE_CALC_EXT, XML_ICON_SET_TYPE, aIconSetName ); + SvXMLElementExport aElementColorScale(*this, XML_NAMESPACE_CALC_EXT, XML_ICON_SET, true, true); + for(ScIconSetFormat::const_iterator it = mrIconSet.begin(); + it != mrIconSet.end(); ++it) + { + if(it->GetType() == COLORSCALE_FORMULA) + { + rtl::OUString sFormula = it->GetFormula(formula::FormulaGrammar::GRAM_ODFF); + AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, sFormula); + } + else + AddAttribute(XML_NAMESPACE_CALC_EXT, XML_VALUE, rtl::OUString::valueOf(it->GetValue())); + + AddAttribute(XML_NAMESPACE_CALC_EXT, XML_TYPE, getCondFormatEntryType(*it)); + SvXMLElementExport aElementColorScaleEntry(*this, XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, true, true); } } } diff --git a/sc/source/filter/xml/xmlimprt.cxx b/sc/source/filter/xml/xmlimprt.cxx index 872c967f9a88..02bed6b62d7a 100644 --- a/sc/source/filter/xml/xmlimprt.cxx +++ b/sc/source/filter/xml/xmlimprt.cxx @@ -618,6 +618,7 @@ const SvXMLTokenMap& ScXMLImport::GetCondFormatTokenMap() { XML_NAMESPACE_CALC_EXT, XML_COLOR_SCALE, XML_TOK_CONDFORMAT_COLORSCALE }, { XML_NAMESPACE_CALC_EXT, XML_DATA_BAR, XML_TOK_CONDFORMAT_DATABAR }, { XML_NAMESPACE_CALC_EXT, XML_CONDITION, XML_TOK_CONDFORMAT_CONDITION }, + { XML_NAMESPACE_CALC_EXT, XML_ICON_SET, XML_TOK_CONDFORMAT_ICONSET }, XML_TOKEN_MAP_END }; @@ -695,13 +696,14 @@ const SvXMLTokenMap& ScXMLImport::GetColorScaleEntryAttrMap() return *pColorScaleEntryAttrTokenMap; } -const SvXMLTokenMap& ScXMLImport::GetDataBarTokenMap() +const SvXMLTokenMap& ScXMLImport::GetFormattingTokenMap() { if( !pDataBarTokenMap ) { static SvXMLTokenMapEntry aDataBarElemTokenMap[] = { { XML_NAMESPACE_CALC_EXT, XML_DATA_BAR_ENTRY, XML_TOK_DATABAR_DATABARENTRY }, + { XML_NAMESPACE_CALC_EXT, XML_FORMATTING_ENTRY, XML_TOK_FORMATTING_ENTRY }, XML_TOKEN_MAP_END }; @@ -732,6 +734,22 @@ const SvXMLTokenMap& ScXMLImport::GetDataBarAttrMap() return *pDataBarAttrMap; } +const SvXMLTokenMap& ScXMLImport::GetIconSetAttrMap() +{ + if( !pIconSetAttrMap ) + { + static SvXMLTokenMapEntry aIconSetAttrTokenMap[] = + { + { XML_NAMESPACE_CALC_EXT, XML_ICON_SET_TYPE, XML_TOK_ICONSET_TYPE }, + XML_TOKEN_MAP_END + }; + + pIconSetAttrMap = new SvXMLTokenMap( aIconSetAttrTokenMap ); + } + + return *pIconSetAttrMap; +} + const SvXMLTokenMap& ScXMLImport::GetDataBarEntryAttrMap() { if( !pDataBarEntryAttrMap ) @@ -1874,6 +1892,7 @@ ScXMLImport::ScXMLImport( pDataBarTokenMap( 0 ), pDataBarAttrMap( 0 ), pDataBarEntryAttrMap( 0 ), + pIconSetAttrMap( 0 ), pLabelRangesElemTokenMap( 0 ), pLabelRangeAttrTokenMap( 0 ), pTableElemTokenMap( 0 ), diff --git a/sc/source/filter/xml/xmlimprt.hxx b/sc/source/filter/xml/xmlimprt.hxx index f3706d9854cf..9102430164a7 100644 --- a/sc/source/filter/xml/xmlimprt.hxx +++ b/sc/source/filter/xml/xmlimprt.hxx @@ -159,7 +159,8 @@ enum ScXMLCondFormatTokens { XML_TOK_CONDFORMAT_COLORSCALE, XML_TOK_CONDFORMAT_DATABAR, - XML_TOK_CONDFORMAT_CONDITION + XML_TOK_CONDFORMAT_CONDITION, + XML_TOK_CONDFORMAT_ICONSET }; enum ScXMLCondFormatAttrTokens @@ -186,9 +187,10 @@ enum ScXMLColorScaleEntryAttrTokens XML_TOK_COLORSCALEENTRY_COLOR }; -enum ScXMLDataBarFormatTokens +enum ScXMLFormattingFormatTokens { - XML_TOK_DATABAR_DATABARENTRY + XML_TOK_DATABAR_DATABARENTRY, + XML_TOK_FORMATTING_ENTRY }; enum ScXMLDataBarAttrTokens @@ -207,6 +209,11 @@ enum ScXMLDataBarEntryAttrTokens XML_TOK_DATABARENTRY_VALUE }; +enum ScXMLIconSetAttrTokens +{ + XML_TOK_ICONSET_TYPE +}; + enum ScXMLLabelRangesElemTokens { XML_TOK_LABEL_RANGE_ELEM @@ -778,6 +785,7 @@ class ScXMLImport: public SvXMLImport SvXMLTokenMap *pDataBarTokenMap; SvXMLTokenMap *pDataBarAttrMap; SvXMLTokenMap *pDataBarEntryAttrMap; + SvXMLTokenMap *pIconSetAttrMap; SvXMLTokenMap *pLabelRangesElemTokenMap; SvXMLTokenMap *pLabelRangeAttrTokenMap; SvXMLTokenMap *pTableElemTokenMap; @@ -938,9 +946,10 @@ public: const SvXMLTokenMap& GetConditionAttrMap(); const SvXMLTokenMap& GetColorScaleTokenMap(); const SvXMLTokenMap& GetColorScaleEntryAttrMap(); - const SvXMLTokenMap& GetDataBarTokenMap(); + const SvXMLTokenMap& GetFormattingTokenMap(); const SvXMLTokenMap& GetDataBarAttrMap(); const SvXMLTokenMap& GetDataBarEntryAttrMap(); + const SvXMLTokenMap& GetIconSetAttrMap(); const SvXMLTokenMap& GetLabelRangesElemTokenMap(); const SvXMLTokenMap& GetLabelRangeAttrTokenMap(); const SvXMLTokenMap& GetTableElemTokenMap(); diff --git a/xmloff/inc/xmloff/xmltoken.hxx b/xmloff/inc/xmloff/xmltoken.hxx index 4ade92824a5f..f97d1e305bdc 100644 --- a/xmloff/inc/xmloff/xmltoken.hxx +++ b/xmloff/inc/xmloff/xmltoken.hxx @@ -852,6 +852,7 @@ namespace xmloff { namespace token { XML_FOREIGN_OBJECT, XML_FORMAT_CHANGE, XML_FORMAT_SOURCE, + XML_FORMATTING_ENTRY, XML_FORMS, XML_FORMULA, XML_FORMULA_HIDDEN, @@ -971,6 +972,8 @@ namespace xmloff { namespace token { XML_HYPHENATION_REMAIN_CHAR_COUNT, XML_I, XML_ICON, + XML_ICON_SET, + XML_ICON_SET_TYPE, XML_ID, XML_IDENT, XML_IDENTIFIER, diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index cbbd48b21b0c..be8d9ce742a2 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -856,6 +856,7 @@ namespace xmloff { namespace token { TOKEN( "foreign-object", XML_FOREIGN_OBJECT ), TOKEN( "format-change", XML_FORMAT_CHANGE ), TOKEN( "format-source", XML_FORMAT_SOURCE ), + TOKEN( "formatting-entry", XML_FORMATTING_ENTRY ), TOKEN( "forms", XML_FORMS ), TOKEN( "formula", XML_FORMULA ), TOKEN( "formula-hidden", XML_FORMULA_HIDDEN ), @@ -976,6 +977,8 @@ namespace xmloff { namespace token { TOKEN( "hyphenation-remain-char-count", XML_HYPHENATION_REMAIN_CHAR_COUNT ), TOKEN( "i", XML_I ), TOKEN( "icon", XML_ICON ), + TOKEN( "icon-set", XML_ICON_SET ), + TOKEN( "icon-set-type", XML_ICON_SET_TYPE ), TOKEN( "id", XML_ID ), TOKEN( "ident", XML_IDENT ), TOKEN( "identifier", XML_IDENTIFIER ), |