diff options
author | Noel Power <noel.power@novell.com> | 2011-02-10 16:18:38 +0000 |
---|---|---|
committer | Noel Power <noel.power@novell.com> | 2011-02-10 16:18:38 +0000 |
commit | 0a078aa069667094bbfc77beda6d15064665be68 (patch) | |
tree | ca3a5a86e3fe760f514e2bcae3c01bd420707f60 /writerfilter | |
parent | c879cedd660ecc7736e5fb9086026060cea4522b (diff) |
some form field import/export improvements
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/dmapper/FormControlHelper.cxx | 88 | ||||
-rw-r--r-- | writerfilter/source/dmapper/FormControlHelper.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/ooxml/model.xml | 2 |
4 files changed, 98 insertions, 4 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index d9c3b143b381..fa3625f7a2dd 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1833,7 +1833,7 @@ if(!bFilled) // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILESIZE")), "", "", FIELD_FILESIZE }, // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMULA")), "", "", FIELD_FORMULA }, {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMCHECKBOX")), "", "", FIELD_FORMCHECKBOX}, -// {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMDROPDOWN")), "", "", FIELD_FORMDROWDOWN}, + {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMDROPDOWN")), "", "", FIELD_FORMDROPDOWN}, {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMTEXT")), "Input", "", FIELD_FORMTEXT}, // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GOTOBUTTON")), "", "", FIELD_GOTOBUTTON }, {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HYPERLINK")), "", "", FIELD_HYPERLINK }, @@ -2320,6 +2320,7 @@ void DomainMapper_Impl::CloseFieldCommand() case FIELD_TOC: case FIELD_TC: case FIELD_FORMCHECKBOX: + case FIELD_FORMDROPDOWN: bCreateField = false; break; default: @@ -2419,17 +2420,20 @@ void DomainMapper_Impl::CloseFieldCommand() case FIELD_FILESIZE : break; case FIELD_FORMULA : break; case FIELD_FORMCHECKBOX : + case FIELD_FORMDROPDOWN : { FFDataHandler::Pointer_t pFFDataHandler(pContext->getFFDataHandler()); + FieldId eFieldId = FIELD_FORMCHECKBOX; + if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN ) + eFieldId = FIELD_FORMDROPDOWN; FormControlHelper::Pointer_t pFormControlHelper(new FormControlHelper - (FIELD_FORMCHECKBOX, + (eFieldId, m_xTextDocument, pFFDataHandler)); pContext->setFormControlHelper(pFormControlHelper); } break; - case FIELD_FORMDROPDOWN : break; case FIELD_FORMTEXT : { FFDataHandler::Pointer_t pFFDataHandler diff --git a/writerfilter/source/dmapper/FormControlHelper.cxx b/writerfilter/source/dmapper/FormControlHelper.cxx index 350a47a7c585..1df2fbb9c863 100644 --- a/writerfilter/source/dmapper/FormControlHelper.cxx +++ b/writerfilter/source/dmapper/FormControlHelper.cxx @@ -153,6 +153,91 @@ FormControlHelper::~FormControlHelper() { } +bool FormControlHelper::createDropdown(uno::Reference<text::XTextRange> xTextRange, + const ::rtl::OUString & rControlName) +{ + uno::Reference<lang::XMultiServiceFactory> + xServiceFactory(m_pImpl->getServiceFactory()); + + if (! xServiceFactory.is()) + return false; + + uno::Reference<uno::XInterface> xInterface = + xServiceFactory->createInstance + (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.ComboBox"))); + + if (!xInterface.is()) + return false; + + m_pImpl->rFormComponent = uno::Reference<form::XFormComponent>(xInterface, uno::UNO_QUERY); + if (!m_pImpl->rFormComponent.is()) + return false; + + uno::Reference<beans::XPropertySet> xPropSet(xInterface, uno::UNO_QUERY); + + uno::Any aAny; + + aAny <<= rControlName; + xPropSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name")), aAny); + xPropSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Dropdown")), uno::makeAny( sal_True )); + + uno::Sequence< rtl::OUString > sItems; + + sal_Int32 nMaxChars = 0; + if ( m_pFFData->getDropDownEntries().size() ) + { + sItems.realloc( m_pFFData->getDropDownEntries().size() ); + FFDataHandler::DropDownEntries_t::const_iterator it_end = m_pFFData->getDropDownEntries().end(); + FFDataHandler::DropDownEntries_t::const_iterator it = m_pFFData->getDropDownEntries().begin(); + + rtl::OUString* pItem = sItems.getArray(); + + for( ;it != it_end; ++it, ++pItem ) + { + *pItem = *it; + if ( (*pItem).getLength() > nMaxChars ) + nMaxChars = (*pItem).getLength(); + } + } + + if ( sItems.getLength() ) + { + aAny <<= sItems; + xPropSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StringItemList")), aAny); + if ( m_pFFData->getDropDownResult().getLength() ) + { + sal_Int32 nResult = m_pFFData->getDropDownResult().toInt32(); + if ( nResult ) + { + aAny <<= sItems[ nResult ]; + xPropSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text")), aAny); + } + } + } + + // #FIXME improve the auto height width calculation + // some fallback values ( to display something ) + + m_pImpl->aSize.Width = 2381; + m_pImpl->aSize.Height = 713; + + try + { + uno::Reference<beans::XPropertySet> xTextRangeProps(xTextRange, uno::UNO_QUERY_THROW); + static ::rtl::OUString sCharHeight(RTL_CONSTASCII_USTRINGPARAM("CharHeight")); + float fComboBoxHeight = 0.0; + xTextRangeProps->getPropertyValue(sCharHeight) >>= fComboBoxHeight; + m_pImpl->aSize.Height = floor(fComboBoxHeight * 35.3); + if ( nMaxChars ) + m_pImpl->aSize.Width = floor( m_pImpl->aSize.Height * nMaxChars ); + } + catch( uno::Exception& e ) + { + } + return true; +} + + bool FormControlHelper::createCheckbox(uno::Reference<text::XTextRange> xTextRange, const ::rtl::OUString & rControlName) { @@ -250,6 +335,9 @@ bool FormControlHelper::insertControl(uno::Reference<text::XTextRange> xTextRang switch (m_pImpl->m_eFieldId) { + case FIELD_FORMDROPDOWN: + bCreated = createDropdown(xTextRange, sControlName); + break; case FIELD_FORMCHECKBOX: bCreated = createCheckbox(xTextRange, sControlName); break; diff --git a/writerfilter/source/dmapper/FormControlHelper.hxx b/writerfilter/source/dmapper/FormControlHelper.hxx index 2dd6fb4574fa..274dd4ffe8e6 100644 --- a/writerfilter/source/dmapper/FormControlHelper.hxx +++ b/writerfilter/source/dmapper/FormControlHelper.hxx @@ -57,6 +57,8 @@ private: bool createCheckbox(uno::Reference<text::XTextRange> xTextRange, const ::rtl::OUString & rControlName); + bool createDropdown(uno::Reference<text::XTextRange> xTextRange, + const ::rtl::OUString & rControlName); }; } diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 65f5fa181a2f..ba836fe1acfe 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -15282,7 +15282,7 @@ <define name="CT_FFDDList"> <optional> <element name="result"> - <ref name="CT_DecimalNumber"/> + <ref name="CT_String"/> </element> </optional> <optional> |