summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmloff/inc/xmloff/odffields.hxx56
-rw-r--r--xmloff/prj/d.lst1
-rw-r--r--xmloff/source/text/XMLTextMarkImportContext.cxx46
-rw-r--r--xmloff/source/text/txtimp.cxx83
-rw-r--r--xmloff/source/text/txtparae.cxx110
5 files changed, 244 insertions, 52 deletions
diff --git a/xmloff/inc/xmloff/odffields.hxx b/xmloff/inc/xmloff/odffields.hxx
new file mode 100644
index 000000000000..2be06b578acd
--- /dev/null
+++ b/xmloff/inc/xmloff/odffields.hxx
@@ -0,0 +1,56 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+/*
+ * Copyright 2008 by Novell, Inc.
+ */
+
+#ifndef _ODFFIELDS_HXX
+#define _ODFFIELDS_HXX
+
+
+#define ODF_FORMTEXT "vnd.oasis.opendocument.field.FORMTEXT"
+
+#define ODF_FORMCHECKBOX "vnd.oasis.opendocument.field.FORMCHECKBOX"
+#define ODF_FORMCHECKBOX_HELPTEXT "Checkbox_HelpText"
+#define ODF_FORMCHECKBOX_NAME "Checkbox_Name"
+#define ODF_FORMCHECKBOX_RESULT "Checkbox_Checked"
+
+#define ODF_FORMDROPDOWN "vnd.oasis.opendocument.field.FORMDROPDOWN"
+#define ODF_FORMDROPDOWN_LISTENTRY "Dropdown_ListEntry"
+#define ODF_FORMDROPDOWN_RESULT "Dropdown_Selected"
+
+#define ODF_TOC "vnd.oasis.opendocument.field.TOC"
+
+#define ODF_HYPERLINK "vnd.oasis.opendocument.field.HYPERLINK"
+
+#define ODF_PAGEREF "vnd.oasis.opendocument.field.PAGEREF"
+
+#endif /* _ODFFIELDS_HXX */
diff --git a/xmloff/prj/d.lst b/xmloff/prj/d.lst
index 686b4b70a0ae..ae4f8cd13ffb 100644
--- a/xmloff/prj/d.lst
+++ b/xmloff/prj/d.lst
@@ -10,6 +10,7 @@ mkdir: %_DEST%\inc%_EXT%\xmloff
..\dtd\* %_DEST%\bin%_EXT%
+..\inc\xmloff\odffields.hxx %_DEST%\inc%_EXT%\xmloff\odffields.hxx
..\inc\xmloff\dllapi.h %_DEST%\inc%_EXT%\xmloff\dllapi.h
..\inc\xmloff\attrlist.hxx %_DEST%\inc%_EXT%\xmloff\attrlist.hxx
..\inc\i18nmap.hxx %_DEST%\inc%_EXT%\xmloff\i18nmap.hxx
diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx
index dd16ab983a7b..91fe01dfcc3a 100644
--- a/xmloff/source/text/XMLTextMarkImportContext.cxx
+++ b/xmloff/source/text/XMLTextMarkImportContext.cxx
@@ -38,6 +38,7 @@
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlimp.hxx>
#include <xmloff/nmspmap.hxx>
+#include <xmloff/odffields.hxx>
#include "xmlnmspe.hxx"
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <com/sun/star/text/XTextContent.hpp>
@@ -135,6 +136,33 @@ static SvXMLEnumMapEntry __READONLY_DATA lcl_aMarkTypeMap[] =
{ XML_TOKEN_INVALID, 0 },
};
+
+static const char *lcl_getFormFieldmarkName(rtl::OUString &name)
+{
+ static const char sCheckbox[]=ODF_FORMCHECKBOX;
+ static const char sFormDropDown[]=ODF_FORMDROPDOWN;
+ if (name.compareToAscii("msoffice.field.FORMCHECKBOX")==0)
+ return sCheckbox;
+ else if (name.compareToAscii(ODF_FORMCHECKBOX)==0)
+ return sCheckbox;
+ if (name.compareToAscii(ODF_FORMDROPDOWN)==0)
+ return sFormDropDown;
+ else
+ return NULL;
+}
+
+static rtl::OUString lcl_getFieldmarkName(rtl::OUString &name)
+{
+ static const char sFormtext[]=ODF_FORMTEXT;
+ if (name.compareToAscii("msoffice.field.FORMTEXT")==0)
+ return rtl::OUString::createFromAscii(sFormtext);
+ else if (name.compareToAscii(ODF_FORMTEXT)==0)
+ return rtl::OUString::createFromAscii(sFormtext);
+ else
+ return name;
+}
+
+
void XMLTextMarkImportContext::StartElement(
const Reference<XAttributeList> & xAttrList)
{
@@ -191,7 +219,8 @@ void XMLTextMarkImportContext::EndElement()
case TypeFieldmark:
case TypeBookmark:
{
- bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && m_sFieldName.compareToAscii("msoffice.field.FORMCHECKBOX")==0); // for now only import FORMCHECKBOX boxes
+ const char *formFieldmarkName=lcl_getFormFieldmarkName(m_sFieldName);
+ bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmark && formFieldmarkName!=NULL); //@TODO handle abbreviation cases..
// export point bookmark
const Reference<XInterface> xContent(
CreateAndInsertMark(GetImport(),
@@ -210,10 +239,8 @@ void XMLTextMarkImportContext::EndElement()
if (xContent.is() && bImportAsField) {
// setup fieldmark...
Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY);
- xFormField->setType(1); // Checkbox...
+ xFormField->setFieldType(rtl::OUString::createFromAscii(formFieldmarkName));
if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) {
-// xFormField->setDescription(::rtl::OUString::createFromAscii("HELLO CHECKBOX"));
-// xFormField->setRes(1);
m_rHelper.setCurrentFieldParamsTo(xFormField);
}
}
@@ -260,11 +287,6 @@ void XMLTextMarkImportContext::EndElement()
xInsertionCursor, UNO_QUERY);
bool bImportAsField=((lcl_MarkType)nTmp==TypeFieldmarkEnd && m_rHelper.hasCurrentFieldCtx());
- if (bImportAsField) {
- ::rtl::OUString currentFieldType =
- m_rHelper.getCurrentFieldType();
- bImportAsField=currentFieldType.compareToAscii("msoffice.field.FORMTEXT")==0; // for now only import FORMTEXT boxes
- }
// insert reference
const Reference<XInterface> xContent(
@@ -285,10 +307,12 @@ void XMLTextMarkImportContext::EndElement()
if (xContent.is() && bImportAsField) {
// setup fieldmark...
Reference< ::com::sun::star::text::XFormField> xFormField(xContent, UNO_QUERY);
- xFormField->setType(0); // Text
if (xFormField.is() && m_rHelper.hasCurrentFieldCtx()) {
+ rtl::OUString givenTypeName=m_rHelper.getCurrentFieldType();
+ rtl::OUString fieldmarkTypeName=lcl_getFieldmarkName(givenTypeName);
+
+ xFormField->setFieldType(fieldmarkTypeName);
m_rHelper.setCurrentFieldParamsTo(xFormField);
-// xFormField->setDescription(::rtl::OUString::createFromAscii("HELLO"));
}
}
m_rHelper.popFieldCtx();
diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx
index a7b7b4cb6782..cd09ba7f646f 100644
--- a/xmloff/source/text/txtimp.cxx
+++ b/xmloff/source/text/txtimp.cxx
@@ -89,6 +89,8 @@
// --> OD 2008-04-25 #refactorlists#
#include <txtlists.hxx>
// <--
+#include <xmloff/odffields.hxx>
+#include <comphelper/stlunosequence.hxx>
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
@@ -110,6 +112,8 @@ using namespace ::com::sun::star::ucb;
using ::comphelper::UStringLess;
+
+
static __FAR_DATA SvXMLTokenMapEntry aTextElemTokenMap[] =
{
{ XML_NAMESPACE_TEXT, XML_P, XML_TOK_TEXT_P },
@@ -444,6 +448,70 @@ static __FAR_DATA SvXMLTokenMapEntry aTextMasterPageElemTokenMap[] =
#define MAX_COMBINED_CHARACTERS 6
+namespace
+{
+ class FieldParamImporter
+ {
+ public:
+ typedef pair<OUString,OUString> field_param_t;
+ typedef vector<field_param_t> field_params_t;
+ FieldParamImporter(const field_params_t* const pInParams, Reference<XNameContainer> xOutParams)
+ : m_pInParams(pInParams)
+ , m_xOutParams(xOutParams)
+ { };
+ void Import();
+
+ private:
+ const field_params_t* const m_pInParams;
+ Reference<XNameContainer> m_xOutParams;
+ };
+
+ void FieldParamImporter::Import()
+ {
+ ::std::vector<OUString> vListEntries;
+ ::std::map<OUString, Any> vOutParams;
+ for(field_params_t::const_iterator pCurrent = m_pInParams->begin();
+ pCurrent != m_pInParams->end();
+ ++pCurrent)
+ {
+ if(pCurrent->first.equalsAscii(ODF_FORMDROPDOWN_RESULT))
+ {
+ // sal_Int32
+ vOutParams[pCurrent->first] = makeAny(pCurrent->second.toInt32());
+ }
+ else if(pCurrent->first.equalsAscii(ODF_FORMCHECKBOX_RESULT))
+ {
+ // bool
+ vOutParams[pCurrent->first] = makeAny(pCurrent->second.toBoolean());
+ }
+ else if(pCurrent->first.equalsAscii(ODF_FORMDROPDOWN_LISTENTRY))
+ {
+ // sequence
+ vListEntries.push_back(pCurrent->second);
+ }
+ else
+ vOutParams[pCurrent->first] = makeAny(pCurrent->second);
+ }
+ if(!vListEntries.empty())
+ {
+ Sequence<OUString> vListEntriesSeq(vListEntries.size());
+ copy(vListEntries.begin(), vListEntries.end(), ::comphelper::stl_begin(vListEntriesSeq));
+ vOutParams[OUString::createFromAscii(ODF_FORMDROPDOWN_LISTENTRY)] = makeAny(vListEntriesSeq);
+ }
+ for(::std::map<OUString, Any>::const_iterator pCurrent = vOutParams.begin();
+ pCurrent != vOutParams.end();
+ ++pCurrent)
+ {
+ try
+ {
+ m_xOutParams->insertByName(pCurrent->first, pCurrent->second);
+ }
+ catch(ElementExistException)
+ { }
+ }
+ }
+}
+
XMLTextImportHelper::XMLTextImportHelper(
const Reference < XModel >& rModel,
SvXMLImport& rImport,
@@ -2277,18 +2345,9 @@ bool XMLTextImportHelper::hasCurrentFieldCtx()
void XMLTextImportHelper::setCurrentFieldParamsTo(::com::sun::star::uno::Reference< ::com::sun::star::text::XFormField> &xFormField)
{
DBG_ASSERT(!aFieldStack.empty(), "stack is empty: not good! Do a pushFieldCtx before...");
- if (!aFieldStack.empty() && xFormField.is()) {
- field_params_t &params=aFieldStack.top().second;
- for (field_params_t::iterator i=params.begin();i!=params.end();i++) {
- rtl::OUString name=i->first;
- rtl::OUString value=i->second;
- if (name.compareToAscii("Description")==0){
- xFormField->setDescription(value);
- } else if (name.compareToAscii("Result")==0){
- xFormField->setRes((sal_Int16)value.toInt32());
- }
-
- }
+ if (!aFieldStack.empty() && xFormField.is())
+ {
+ FieldParamImporter(&aFieldStack.top().second, xFormField->getParameters()).Import();
}
}
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index cc2e74b425e7..f1cf89cb0640 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -116,6 +116,7 @@
#include "MultiPropertySetHelper.hxx"
#include <xmloff/formlayerexport.hxx>
#include "XMLTextCharStyleNamesElementExport.hxx"
+#include <comphelper/stlunosequence.hxx>
// --> OD 2008-04-25 #refactorlists#
#include <txtlists.hxx>
@@ -231,6 +232,21 @@ namespace
const OUString BoundFrames::our_sAnchorType = OUString::createFromAscii("AnchorType");
const OUString BoundFrames::our_sAnchorFrame = OUString::createFromAscii("AnchorFrame");
+ class FieldParamExporter
+ {
+ public:
+ FieldParamExporter(SvXMLExport* const pExport, Reference<XNameContainer> xFieldParams)
+ : m_pExport(pExport)
+ , m_xFieldParams(xFieldParams)
+ { };
+ void Export();
+
+ private:
+ SvXMLExport* const m_pExport;
+ const Reference<XNameContainer> m_xFieldParams;
+
+ void ExportParameter(const OUString& sKey, const OUString& sValue);
+ };
}
namespace xmloff
@@ -386,6 +402,55 @@ BoundFrameSets::BoundFrameSets(const Reference<XInterface> xModel)
&lcl_ShapeFilter));
};
+void FieldParamExporter::Export()
+{
+ static const Type aStringType = ::getCppuType((OUString*)0);
+ static const Type aBoolType = ::getCppuType((sal_Bool*)0);
+ static const Type aSeqType = ::getCppuType((Sequence<OUString>*)0);
+ static const Type aIntType = ::getCppuType((sal_Int32*)0);
+ Sequence<OUString> vParameters(m_xFieldParams->getElementNames());
+ for(const OUString* pCurrent=::comphelper::stl_begin(vParameters); pCurrent!=::comphelper::stl_end(vParameters); ++pCurrent)
+ {
+ const Any aValue = m_xFieldParams->getByName(*pCurrent);
+ const Type aValueType = aValue.getValueType();
+ if(aValueType == aStringType)
+ {
+ OUString sValue;
+ aValue >>= sValue;
+ ExportParameter(*pCurrent,sValue);
+ }
+ else if(aValueType == aBoolType)
+ {
+ sal_Bool bValue = false;
+ aValue >>= bValue;
+ ExportParameter(*pCurrent,OUString::createFromAscii(bValue ? "true" : "false"));
+ }
+ else if(aValueType == aSeqType)
+ {
+ Sequence<OUString> vValue;
+ aValue >>= vValue;
+ for(OUString* pSeqCurrent = ::comphelper::stl_begin(vValue); pSeqCurrent != ::comphelper::stl_end(vValue); ++pSeqCurrent)
+ {
+ ExportParameter(*pCurrent, *pSeqCurrent);
+ }
+ }
+ else if(aValueType == aIntType)
+ {
+ sal_Int32 nValue = 0;
+ aValue >>= nValue;
+ ExportParameter(*pCurrent, OUStringBuffer().append(nValue).makeStringAndClear());
+ }
+ }
+}
+
+void FieldParamExporter::ExportParameter(const OUString& sKey, const OUString& sValue)
+{
+ m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, sKey);
+ m_pExport->AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, sValue);
+ m_pExport->StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
+ m_pExport->EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
+}
+
void XMLTextParagraphExport::Add( sal_uInt16 nFamily,
const Reference < XPropertySet > & rPropSet,
const XMLPropertyState** ppAddStates, bool bDontSeek )
@@ -2237,19 +2302,19 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
else if (sType.equals(sTextFieldStart))
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
- if (xBookmark.is()) {
+ if (xBookmark.is())
+ {
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
}
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
- if (xFormField.is()) {
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, ::rtl::OUString::createFromAscii("msoffice.field.FORMTEXT"));
+ if (xFormField.is())
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
}
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
- if (xFormField.is()) {
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, ::rtl::OUString::createFromAscii("Description"));
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, xFormField->getDescription());
- GetExport().StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
- GetExport().EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
+ if (xFormField.is())
+ {
+ FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
}
@@ -2261,32 +2326,19 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
else if (sType.equals(sTextFieldStartEnd))
{
Reference<XNamed> xBookmark(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
- if (xBookmark.is()) {
+ if (xBookmark.is())
+ {
GetExport().AddAttribute(XML_NAMESPACE_TEXT, XML_NAME, xBookmark->getName());
}
Reference< ::com::sun::star::text::XFormField > xFormField(xPropSet->getPropertyValue(sBookmark), UNO_QUERY);
- if (xFormField.is()) {
- sal_Int16 fftype=xFormField->getType();
- switch (fftype) {
- case 1:
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, ::rtl::OUString::createFromAscii("msoffice.field.FORMCHECKBOX"));
- break;
- default:
- DBG_ASSERT(false, "hey ---- add your export stuff here!!");
- break;
- }
+ if (xFormField.is())
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_TYPE, xFormField->getFieldType());
}
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
- if (xFormField.is()) {
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, ::rtl::OUString::createFromAscii("Description"));
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, xFormField->getDescription());
- GetExport().StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
- GetExport().EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
-
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, ::rtl::OUString::createFromAscii("Result"));
- GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, ::rtl::OUString::valueOf((sal_Int32 )xFormField->getRes()));
- GetExport().StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
- GetExport().EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
+ if (xFormField.is())
+ {
+ FieldParamExporter(&GetExport(), xFormField->getParameters()).Export();
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
}