diff options
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/editutil.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/tool/editutil.cxx | 168 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.cxx | 122 |
3 files changed, 194 insertions, 99 deletions
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx index 34ffd34f514a..bf296c067821 100644 --- a/sc/inc/editutil.hxx +++ b/sc/inc/editutil.hxx @@ -77,6 +77,9 @@ public: static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc ); + static OUString GetCellFieldValue( + const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor ); + public: ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ, const Point& rScrPosPixel, diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx index 0a0a0571c6d2..c9632438d3b0 100644 --- a/sc/source/core/tool/editutil.cxx +++ b/sc/source/core/tool/editutil.cxx @@ -195,6 +195,93 @@ EditTextObject* ScEditUtil::Clone( const EditTextObject& rObj, ScDocument& rDest return pNew; } +OUString ScEditUtil::GetCellFieldValue( + const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor ) +{ + OUString aRet; + switch (rFieldData.GetClassId()) + { + case text::textfield::Type::URL: + { + const SvxURLField& rField = static_cast<const SvxURLField&>(rFieldData); + OUString aURL = rField.GetURL(); + + switch (rField.GetFormat()) + { + case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App??? + case SVXURLFORMAT_REPR: + aRet = rField.GetRepresentation(); + break; + case SVXURLFORMAT_URL: + aRet = aURL; + break; + default: + ; + } + + svtools::ColorConfigEntry eEntry = + INetURLHistory::GetOrCreate()->QueryUrl(aURL) ? svtools::LINKSVISITED : svtools::LINKS; + + if (ppTextColor) + *ppTextColor = new Color( SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor ); + } + break; + case text::textfield::Type::EXTENDED_TIME: + { + const SvxExtTimeField& rField = static_cast<const SvxExtTimeField&>(rFieldData); + if (pDoc) + aRet = rField.GetFormatted(*pDoc->GetFormatTable(), ScGlobal::eLnge); + else + { + /* TODO: quite expensive, we could have a global formatter? */ + SvNumberFormatter aFormatter( comphelper::getProcessComponentContext(), ScGlobal::eLnge ); + aRet = rField.GetFormatted(aFormatter, ScGlobal::eLnge); + } + } + break; + case text::textfield::Type::DATE: + { + Date aDate(Date::SYSTEM); + aRet = ScGlobal::pLocaleData->getDate(aDate); + } + break; + case text::textfield::Type::DOCINFO_TITLE: + { + if (pDoc) + { + SfxObjectShell* pDocShell = pDoc->GetDocumentShell(); + if (pDocShell) + { + aRet = pDocShell->getDocProperties()->getTitle(); + if (aRet.isEmpty()) + aRet = pDocShell->GetTitle(); + } + } + if (aRet.isEmpty()) + aRet = "?"; + } + break; + case text::textfield::Type::TABLE: + { + const SvxTableField& rField = static_cast<const SvxTableField&>(rFieldData); + SCTAB nTab = rField.GetTab(); + OUString aName; + if (pDoc && pDoc->GetName(nTab, aName)) + aRet = aName; + else + aRet = "?"; + } + break; + default: + aRet = "?"; + } + + if (aRet.isEmpty()) // leer ist baeh + aRet = " "; // Space ist Default der Editengine + + return aRet; +} + //------------------------------------------------------------------------ Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop ) @@ -818,86 +905,7 @@ OUString ScFieldEditEngine::CalcFieldValue( const SvxFieldItem& rField, if (!pFieldData) return OUString(" "); - sal_uInt16 nClsId = pFieldData->GetClassId(); - switch (nClsId) - { - case text::textfield::Type::URL: - { - const SvxURLField* pField = static_cast<const SvxURLField*>(pFieldData); - OUString aURL = pField->GetURL(); - - switch (pField->GetFormat()) - { - case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App??? - case SVXURLFORMAT_REPR: - aRet = pField->GetRepresentation(); - break; - case SVXURLFORMAT_URL: - aRet = aURL; - break; - default: - ; - } - - svtools::ColorConfigEntry eEntry = - INetURLHistory::GetOrCreate()->QueryUrl(String(aURL)) ? svtools::LINKSVISITED : svtools::LINKS; - rTxtColor = new Color( SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor ); - } - break; - case text::textfield::Type::EXTENDED_TIME: - { - const SvxExtTimeField* pField = static_cast<const SvxExtTimeField*>(pFieldData); - if (mpDoc) - aRet = pField->GetFormatted(*mpDoc->GetFormatTable(), ScGlobal::eLnge); - else - { - /* TODO: quite expensive, we could have a global formatter? */ - SvNumberFormatter aFormatter( comphelper::getProcessComponentContext(), ScGlobal::eLnge ); - aRet = pField->GetFormatted( aFormatter, ScGlobal::eLnge); - } - } - break; - case text::textfield::Type::DATE: - { - Date aDate(Date::SYSTEM); - aRet = ScGlobal::pLocaleData->getDate(aDate); - } - break; - case text::textfield::Type::DOCINFO_TITLE: - { - if (mpDoc) - { - SfxObjectShell* pDocShell = mpDoc->GetDocumentShell(); - if (pDocShell) - { - aRet = pDocShell->getDocProperties()->getTitle(); - if (aRet.isEmpty()) - aRet = pDocShell->GetTitle(); - } - } - if (aRet.isEmpty()) - aRet = "?"; - } - break; - case text::textfield::Type::TABLE: - { - const SvxTableField* pField = static_cast<const SvxTableField*>(pFieldData); - SCTAB nTab = pField->GetTab(); - OUString aName; - if (mpDoc && mpDoc->GetName(nTab, aName)) - aRet = aName; - else - aRet = "?"; - } - break; - default: - aRet = "?"; - } - - if (aRet.isEmpty()) // leer ist baeh - aRet = " "; // Space ist Default der Editengine - - return aRet; + return ScEditUtil::GetCellFieldValue(*pFieldData, mpDoc, &rTxtColor); } void ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_uInt16 ) diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index 8e07ed72c116..10da5ff58889 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -17,8 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <editeng/eeitem.hxx> - #include "xmlexprt.hxx" #include "XMLConverter.hxx" #include "xmlstyle.hxx" @@ -89,6 +87,8 @@ #include "editeng/wghtitem.hxx" #include "editeng/wrlmitem.hxx" #include "editeng/xmlcnitm.hxx" +#include "editeng/flditem.hxx" +#include "editeng/eeitem.hxx" #include <xmloff/xmlerror.hxx> #include <xmloff/XMLEventExport.hxx> @@ -151,6 +151,7 @@ #include <vector> #include <vbahelper/vbaaccesshelper.hxx> +#include <boost/scoped_ptr.hpp> //! not found in unonames.hxx #define SC_LAYERID "LayerID" @@ -1113,16 +1114,23 @@ void ScXMLExport::ExportExternalRefCacheStyles() namespace { -void toXMLPropertyStates( +const SvxFieldData* toXMLPropertyStates( std::vector<XMLPropertyState>& rPropStates, const std::vector<const SfxPoolItem*>& rSecAttrs, const UniReference<XMLPropertySetMapper>& xMapper, const ScXMLEditAttributeMap& rAttrMap ) { + const SvxFieldData* pField = NULL; sal_Int32 nEntryCount = xMapper->GetEntryCount(); rPropStates.reserve(rSecAttrs.size()); std::vector<const SfxPoolItem*>::const_iterator it = rSecAttrs.begin(), itEnd = rSecAttrs.end(); for (; it != itEnd; ++it) { const SfxPoolItem* p = *it; + if (p->Which() == EE_FEATURE_FIELD) + { + pField = static_cast<const SvxFieldItem*>(p)->GetField(); + continue; + } + const ScXMLEditAttributeMap::Entry* pEntry = rAttrMap.getEntryByItemID(p->Which()); if (!pEntry) continue; @@ -1317,6 +1325,8 @@ void toXMLPropertyStates( continue; } } + + return pField; } } @@ -3061,6 +3071,94 @@ void ScXMLExport::WriteTable(sal_Int32 nTable, const Reference<sheet::XSpreadshe namespace { +void writeContent( + ScXMLExport& rExport, const OUString& rStyleName, const OUString& rContent, const SvxFieldData* pField ) +{ + boost::scoped_ptr<SvXMLElementExport> pElem; + if (!rStyleName.isEmpty()) + { + // Formatted section with automatic style. + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, rStyleName); + OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, GetXMLToken(XML_SPAN)); + pElem.reset(new SvXMLElementExport(rExport, aElemName, false, false)); + } + + if (pField) + { + // Write an field item. + OUString aFieldVal = ScEditUtil::GetCellFieldValue(*pField, rExport.GetDocument(), NULL); + switch (pField->GetClassId()) + { + case text::textfield::Type::URL: + { + // <text:a xlink:href="url" xlink:type="simple">value</text:a> + + OUString aURL = static_cast<const SvxURLField*>(pField)->GetURL(); + rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aURL); + rExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, "simple"); + + OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, GetXMLToken(XML_A)); + SvXMLElementExport aElem(rExport, aElemName, false, false); + rExport.Characters(aFieldVal); + } + break; + case text::textfield::Type::DATE: + { + // <text:date style:data-style-name="N2" text:date-value="YYYY-MM-DD">value</text:date> + + Date aDate(Date::SYSTEM); + OUStringBuffer aBuf; + sal_Int32 nVal = aDate.GetYear(); + aBuf.append(nVal); + aBuf.append(sal_Unicode('-')); + nVal = aDate.GetMonth(); + if (nVal < 10) + aBuf.append(sal_Unicode('0')); + aBuf.append(nVal); + aBuf.append(sal_Unicode('-')); + nVal = aDate.GetDay(); + if (nVal < 10) + aBuf.append(sal_Unicode('0')); + aBuf.append(nVal); + rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_DATA_STYLE_NAME, "N2"); + rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_DATE_VALUE, aBuf.makeStringAndClear()); + + OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, GetXMLToken(XML_DATE)); + SvXMLElementExport aElem(rExport, aElemName, false, false); + rExport.Characters(aFieldVal); + } + break; + case text::textfield::Type::DOCINFO_TITLE: + { + // <text:title>value</text:title> + + OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, GetXMLToken(XML_TITLE)); + SvXMLElementExport aElem(rExport, aElemName, false, false); + rExport.Characters(aFieldVal); + } + break; + case text::textfield::Type::TABLE: + { + // <text:sheet-name>value</text:sheet-name> + + OUString aElemName = rExport.GetNamespaceMap().GetQNameByKey( + XML_NAMESPACE_TEXT, GetXMLToken(XML_SHEET_NAME)); + SvXMLElementExport aElem(rExport, aElemName, false, false); + rExport.Characters(aFieldVal); + } + break; + default: + rExport.Characters(aFieldVal); + } + } + else + rExport.Characters(rContent); +} + void flushParagraph( ScXMLExport& rExport, const OUString& rParaText, UniReference<XMLPropertySetMapper> xMapper, UniReference<SvXMLAutoStylePoolP> xStylePool, @@ -3083,23 +3181,9 @@ void flushParagraph( OUString aContent(pBeg, pEnd-pBeg); std::vector<XMLPropertyState> aPropStates; - toXMLPropertyStates(aPropStates, rSec.maAttributes, xMapper, rAttrMap); + const SvxFieldData* pField = toXMLPropertyStates(aPropStates, rSec.maAttributes, xMapper, rAttrMap); OUString aStyleName = xStylePool->Find(XML_STYLE_FAMILY_TEXT_TEXT, OUString(), aPropStates); - - if (aStyleName.isEmpty()) - { - // Unformatted section. - rExport.Characters(aContent); - } - else - { - // Formatted section with automatic style. - rExport.AddAttribute(XML_NAMESPACE_TEXT, XML_STYLE_NAME, aStyleName); - aElemName = rExport.GetNamespaceMap().GetQNameByKey( - XML_NAMESPACE_TEXT, GetXMLToken(XML_SPAN)); - SvXMLElementExport aElem(rExport, aElemName, false, false); - rExport.Characters(aContent); - } + writeContent(rExport, aStyleName, aContent, pField); } } |