[Libreoffice-commits] .: writerfilter/source
Noel Power
noelp at kemper.freedesktop.org
Thu Feb 10 08:23:19 PST 2011
writerfilter/source/dmapper/DomainMapper_Impl.cxx | 10 +-
writerfilter/source/dmapper/FormControlHelper.cxx | 88 ++++++++++++++++++++++
writerfilter/source/dmapper/FormControlHelper.hxx | 2
writerfilter/source/ooxml/model.xml | 2
4 files changed, 98 insertions(+), 4 deletions(-)
New commits:
commit 70108372a4205a89ff6df7bbcf9b4ad8b39269e9
Author: Noel Power <noel.power at novell.com>
Date: Thu Feb 10 16:18:38 2011 +0000
some form field import/export improvements
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index d9c3b14..fa3625f 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 b47186c..0a568c8 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 88a9c03..9ef58ca 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 65f5fa1..ba836fe 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>
More information about the Libreoffice-commits
mailing list