cbosdo02: field patch to upstream applied

This commit is contained in:
Cédric Bosdonnat 2009-11-17 12:33:55 +01:00
parent cc423d4be4
commit b54c9639c5
5 changed files with 118 additions and 38 deletions

View file

@ -0,0 +1,68 @@
/*************************************************************************
*
* 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.
*
************************************************************************/
/* and also:
* Author: Florian Reuter <freuter@novell.com>
* Copyright 2008 by Novell, Inc.
*/
#ifndef _ECMAFLDS_HXX
#define _ECMAFLDS_HXX
#define ECMA_FORMTEXT "ecma.office-open-xml.field.FORMTEXT"
#define ECMA_FORMTEXT_NAME "name"
#define ECMA_FORMTEXT_HELPTEXT "helpText"
#define ECMA_FORMTEXT_STATUSTEXT "statusText"
#define ECMA_FORMTEXT_DEFAULT "default"
#define ECMA_FORMTEXT_FORMAT "format"
#define ECMA_FORMTEXT_MAXLENGTH "maxLength"
#define ECMA_FORMTEXT_TYPE "type"
#define ECMA_FORMCHECKBOX "ecma.office-open-xml.field.FORMCHECKBOX"
#define ECMA_FORMCHECKBOX_NAME "name"
#define ECMA_FORMCHECKBOX_HELPTEXT "helpText"
#define ECMA_FORMCHECKBOX_STATUSTEXT "statusText"
#define ECMA_FORMCHECKBOX_CHECKED "checked"
#define ECMA_FORMCHECKBOX_DEFAULT "default"
#define ECMA_FORMCHECKBOX_SIZE "size"
#define ECMA_FORMCHECKBOX_SIZEAUTO "sizeAuto"
#define ECMA_FORMDROPDOWN "ecma.office-open-xml.field.FORMDROPDOWN"
#define ECMA_FORMDROPDOWN_DEFAULT "default"
#define ECMA_FORMDROPDOWN_LISTENTRY "listEntry"
#define ECMA_FORMDROPDOWN_RESULT "result"
#define ECMA_TOC "ecma.office-open-xml.field.TOC"
#define ECMA_HYPERLINK "ecma.office-open-xml.field.HYPERLINK"
#define ECMA_PAGEREF "ecma.office-open-xml.field.PAGEREF"
#endif /* _ECMAFLDS_HXX */

View file

@ -10,6 +10,7 @@ mkdir: %_DEST%\inc%_EXT%\xmloff
..\dtd\* %_DEST%\bin%_EXT%
..\inc\xmloff\ecmaflds.hxx %_DEST%\inc%_EXT%\xmloff\ecmaflds.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

View file

@ -41,6 +41,7 @@
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlimp.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/ecmaflds.hxx>
#include "xmlnmspe.hxx"
#include <com/sun/star/xml/sax/XAttributeList.hpp>
#include <com/sun/star/text/XTextContent.hpp>
@ -138,6 +139,33 @@ static SvXMLEnumMapEntry __READONLY_DATA lcl_aMarkTypeMap[] =
{ XML_TOKEN_INVALID, 0 },
};
static const char *lcl_getFormFieldmarkName(rtl::OUString &name)
{
static const char sCheckbox[]=ECMA_FORMCHECKBOX;
static const char sFormDropDown[]=ECMA_FORMDROPDOWN;
if (name.compareToAscii("msoffice.field.FORMCHECKBOX")==0)
return sCheckbox;
else if (name.compareToAscii(ECMA_FORMCHECKBOX)==0)
return sCheckbox;
if (name.compareToAscii(ECMA_FORMDROPDOWN)==0)
return sFormDropDown;
else
return NULL;
}
static rtl::OUString lcl_getFieldmarkName(rtl::OUString &name)
{
static const char sFormtext[]=ECMA_FORMTEXT;
if (name.compareToAscii("msoffice.field.FORMTEXT")==0)
return rtl::OUString::createFromAscii(sFormtext);
else if (name.compareToAscii(ECMA_FORMTEXT)==0)
return rtl::OUString::createFromAscii(sFormtext);
else
return name;
}
void XMLTextMarkImportContext::StartElement(
const Reference<XAttributeList> & xAttrList)
{
@ -194,7 +222,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(),
@ -213,10 +242,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);
}
}
@ -263,11 +290,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(
@ -288,10 +310,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();

View file

@ -2291,14 +2291,10 @@ void XMLTextImportHelper::setCurrentFieldParamsTo(::com::sun::star::uno::Referen
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());
}
rtl::OString aOString1 = ::rtl::OUStringToOString (i->first, RTL_TEXTENCODING_UTF8);
rtl::OString aOString2 = ::rtl::OUStringToOString (i->second, RTL_TEXTENCODING_UTF8);
/* printf("param[\"%s\"]=\"%s\"\n", aOString1.getStr(), aOString2.getStr()); */
xFormField->addParam(i->first, i->second, false);
}
}
}

View file

@ -2236,14 +2236,16 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
}
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"));
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());
for(sal_Int16 i=0;i<xFormField->getParamCount();i++) {
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, xFormField->getParamName(i));
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, xFormField->getParamValue(i));
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
}
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK_START, sal_False);
}
@ -2260,27 +2262,16 @@ void XMLTextParagraphExport::exportTextRangeEnumeration(
}
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;
}
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()));
for(sal_Int16 i=0;i<xFormField->getParamCount();i++) {
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_NAME, xFormField->getParamName(i));
GetExport().AddAttribute(XML_NAMESPACE_FIELD, XML_VALUE, xFormField->getParamValue(i));
GetExport().StartElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_PARAM, sal_False);
}
}
GetExport().EndElement(XML_NAMESPACE_FIELD, XML_FIELDMARK, sal_False);
}