[Libreoffice-commits] .: writerfilter/source

Noel Power noelp at kemper.freedesktop.org
Thu Feb 24 01:50:37 PST 2011


 writerfilter/source/dmapper/DomainMapper_Impl.cxx |   66 ++++++++++++----------
 writerfilter/source/dmapper/FormControlHelper.cxx |   27 ++++++++-
 2 files changed, 61 insertions(+), 32 deletions(-)

New commits:
commit a4cbd257e4c72078df2cf8d8adfd997299511f2b
Author: Noel Power <noel.power at novell.com>
Date:   Thu Feb 24 09:43:39 2011 +0000

    more form field fixes
    
    writerfilter/source/dmapper/DomainMapper_Impl.cxx: really use enhanced Text
    Form field, also cleaned using enhanced fields or not logic a little more and
    finally got rid of the "com.sun.star.text.FormFieldmark.xxx" type services as I
     realised these weren't necessary
    writerfilter/source/dmapper/FormControlHelper.cxx: added support for Text Form
    in the processField method

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4343690..3e57a56 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -136,6 +136,22 @@ void lcl_handleDropdownField( const uno::Reference< beans::XPropertySet >& rxFie
     }
 }
 
+void lcl_handleTextField( const uno::Reference< beans::XPropertySet >& rxFieldProps, FFDataHandler::Pointer_t pFFDataHandler, PropertyNameSupplier& rPropNameSupplier )
+{
+    if ( rxFieldProps.is() )
+    {
+        rxFieldProps->setPropertyValue
+            (rPropNameSupplier.GetName(PROP_HINT),
+            uno::makeAny(pFFDataHandler->getStatusText()));
+        rxFieldProps->setPropertyValue
+            (rPropNameSupplier.GetName(PROP_HELP),
+            uno::makeAny(pFFDataHandler->getHelpText()));
+        rxFieldProps->setPropertyValue
+            (rPropNameSupplier.GetName(PROP_CONTENT),
+            uno::makeAny(pFFDataHandler->getTextDefault()));
+    }
+}
+
 struct FieldConversion
 {
     ::rtl::OUString     sWordCommand;
@@ -1904,8 +1920,9 @@ const FieldConversionMap_t & lcl_GetEnhancedFieldConversion()
     {
         static const FieldConversion aEnhancedFields[] =
         {
-            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMCHECKBOX")),     "ODFFormCheckbox",                           "", FIELD_FORMCHECKBOX},
-            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMDROPDOWN")),     "ODFFormListbox",                           "", FIELD_FORMDROPDOWN},
+            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMCHECKBOX")),     "FormFieldmark",                           "", FIELD_FORMCHECKBOX},
+            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMDROPDOWN")),     "FormFieldmark",                           "", FIELD_FORMDROPDOWN},
+            {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMTEXT")),     "Fieldmark", "", FIELD_FORMTEXT},
         };
 
         size_t nConversions = SAL_N_ELEMENTS(aEnhancedFields);
@@ -2350,20 +2367,22 @@ void DomainMapper_Impl::CloseFieldCommand()
                 case FIELD_DOCPROPERTY:
                 case FIELD_TOC:
                 case FIELD_TC:
+                        bCreateField = false;
+                        break;
                 case FIELD_FORMCHECKBOX :
+                case FIELD_FORMTEXT :
                 case FIELD_FORMDROPDOWN :
                 {
-                    // If we use 'enhanced' fields then FIELD_FORMCHECKBOX
-                    // & FIELD_FORMDROPDOWN are treated specially
-                    if ( m_bUsingEnhancedFields  && ( aIt->second.eFieldId == FIELD_FORMCHECKBOX || aIt->second.eFieldId == FIELD_FORMDROPDOWN ) )
+                    // If we use 'enhanced' fields then FIELD_FORMCHECKBOX,
+                    // FIELD_FORMTEXT & FIELD_FORMDROPDOWN are treated specially
+                    if ( m_bUsingEnhancedFields  )
                     {
                         bCreateField = false;
                         bCreateEnhancedField = true;
                     }
-                    // if we aren't using enhanced fields and this is a
-                    // drown down then *don't* set bCreateField to false..
-                    // we want to create the field
-                    else if ( aIt->second.eFieldId != FIELD_FORMDROPDOWN )
+                    // for non enhanced fields checkboxes are displayed
+                    // as an awt control not a field
+                    else if ( aIt->second.eFieldId == FIELD_FORMCHECKBOX )
                         bCreateField = false;
                     break;
                 }
@@ -2377,7 +2396,6 @@ void DomainMapper_Impl::CloseFieldCommand()
                     OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text."));
                     if ( bCreateEnhancedField )
                     {
-                        sServiceName += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FormFieldmark."));
                         FieldConversionMap_t aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion();
                         FieldConversionMap_t::iterator aEnhancedIt = aEnhancedFieldConversionMap.find(sCommand);
                         if ( aEnhancedIt != aEnhancedFieldConversionMap.end())
@@ -2478,6 +2496,7 @@ void DomainMapper_Impl::CloseFieldCommand()
                     case FIELD_FORMULA : break;
                     case FIELD_FORMCHECKBOX :
                     case FIELD_FORMDROPDOWN :
+                    case FIELD_FORMTEXT :
                         {
                             uno::Reference< text::XTextField > xTextField( xFieldInterface, uno::UNO_QUERY );
                             if ( !xTextField.is() )
@@ -2500,25 +2519,14 @@ void DomainMapper_Impl::CloseFieldCommand()
                                 }
                             }
                             else
-                                lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() );
+                            {
+                                if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN )
+                                    lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() );
+                                else
+                                    lcl_handleTextField( xFieldProperties, pContext->getFFDataHandler(), rPropNameSupplier );
+                            }
                         }
                         break;
-                    case FIELD_FORMTEXT :
-                    {
-                        FFDataHandler::Pointer_t pFFDataHandler
-                            (pContext->getFFDataHandler());
-
-                        xFieldProperties->setPropertyValue
-                            (rPropNameSupplier.GetName(PROP_HINT),
-                            uno::makeAny(pFFDataHandler->getStatusText()));
-                        xFieldProperties->setPropertyValue
-                            (rPropNameSupplier.GetName(PROP_HELP),
-                            uno::makeAny(pFFDataHandler->getHelpText()));
-                        xFieldProperties->setPropertyValue
-                            (rPropNameSupplier.GetName(PROP_CONTENT),
-                            uno::makeAny(pFFDataHandler->getTextDefault()));
-                    }
-                    break;
                     case FIELD_GOTOBUTTON   : break;
                     case FIELD_HYPERLINK:
                     {
@@ -2895,8 +2903,8 @@ void DomainMapper_Impl::PopFieldContext()
                             xToInsert.set(xFormField, uno::UNO_QUERY);
                             if ( xFormField.is() && xToInsert.is() )
                             {
-                                uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( xTextAppend, uno::UNO_QUERY_THROW );
-                                xTextAppendAndConvert->appendTextContent( xToInsert, uno::Sequence< beans::PropertyValue >() );
+                                xCrsr->gotoEnd( true );
+                                xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
                                 pFormControlHelper->processField( xFormField );
                             }
                             else
diff --git a/writerfilter/source/dmapper/FormControlHelper.cxx b/writerfilter/source/dmapper/FormControlHelper.cxx
index 0bf02b7..6088620 100644
--- a/writerfilter/source/dmapper/FormControlHelper.cxx
+++ b/writerfilter/source/dmapper/FormControlHelper.cxx
@@ -223,9 +223,31 @@ bool FormControlHelper::createCheckbox(uno::Reference<text::XTextRange> xTextRan
 
 bool FormControlHelper::processField(uno::Reference<text::XFormField> xFormField)
 {
-    if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX )
+    uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters();
+    if (m_pImpl->m_eFieldId == FIELD_FORMTEXT )
     {
-        xFormField->setFieldType( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.oasis.opendocument.field.FORMCHECKBOX")));
+        xFormField->setFieldType( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT)));
+        if ( xNameCont.is() )
+        {
+            if (  m_pFFData->getName().getLength() )
+            {
+                if ( xNameCont->hasByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_NAME)) ) )
+                    xNameCont->replaceByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_NAME)), uno::makeAny( m_pFFData->getName() ) );
+                else
+                    xNameCont->insertByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_NAME)), uno::makeAny( m_pFFData->getName() ) );
+            }
+            if (  m_pFFData->getTextDefault().getLength() )
+            {
+                if ( xNameCont->hasByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_DEFAULT)) ) )
+                    xNameCont->replaceByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_DEFAULT)), uno::makeAny( m_pFFData->getTextDefault() ) );
+                else
+                    xNameCont->insertByName( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_DEFAULT)), uno::makeAny( m_pFFData->getTextDefault() ) );
+            }
+        }
+    }
+    else if (m_pImpl->m_eFieldId == FIELD_FORMCHECKBOX )
+    {
+        xFormField->setFieldType( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX)));
         uno::Reference<beans::XPropertySet> xPropSet(xFormField, uno::UNO_QUERY);
         uno::Any aAny;
         aAny <<= m_pFFData->getCheckboxChecked();
@@ -236,7 +258,6 @@ bool FormControlHelper::processField(uno::Reference<text::XFormField> xFormField
     else if (m_pImpl->m_eFieldId == FIELD_FORMDROPDOWN )
     {
         xFormField->setFieldType( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN)));
-        uno::Reference<container::XNameContainer> xNameCont = xFormField->getParameters();
         if ( xNameCont.is() )
         {
             uno::Sequence< rtl::OUString > sItems;


More information about the Libreoffice-commits mailing list