[Libreoffice-commits] .: 2 commits - sw/source

Noel Power noelp at kemper.freedesktop.org
Thu Feb 10 08:23:27 PST 2011


 sw/source/core/doc/dbgoutsw.cxx              |    3 
 sw/source/filter/ww8/docxattributeoutput.cxx |  175 ++++++++++++++++++++++++---
 sw/source/filter/ww8/docxattributeoutput.hxx |    5 
 sw/source/filter/ww8/docxexport.cxx          |    4 
 sw/source/filter/ww8/ww8par3.cxx             |   10 +
 5 files changed, 177 insertions(+), 20 deletions(-)

New commits:
commit 02513d2ca4ea525eeb33c2eecd60cf38ebe53585
Author: Noel Power <noel.power at novell.com>
Date:   Thu Feb 10 16:19:38 2011 +0000

    fix trailing ws

diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 432905f..c48ed65 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -307,7 +307,7 @@ eF_ResT SwWW8ImplReader::Read_F_FormListBox( WW8FieldDesc* pF, String& rStr)
                 uno::Sequence< ::rtl::OUString > vListEntries(aFormula.maListEntries.size());
                 ::std::copy(aFormula.maListEntries.begin(), aFormula.maListEntries.end(), ::comphelper::stl_begin(vListEntries));
                 (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_LISTENTRY))] = uno::makeAny(vListEntries);
-                (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_NAME))] = uno::makeAny(rtl::OUString( aFormula.sTitle )); 
+                (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_NAME))] = uno::makeAny(rtl::OUString( aFormula.sTitle ));
                 sal_Int32 nIndex = aFormula.fDropdownIndex  < aFormula.maListEntries.size() ? aFormula.fDropdownIndex : 0;
                 (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_RESULT))] = uno::makeAny(nIndex);
                 // set field data here...
commit 803409125f4ed896b391acb99266d50691c6fd4a
Author: Noel Power <noel.power at novell.com>
Date:   Thu Feb 10 16:18:40 2011 +0000

    some form field import/export improvements

diff --git a/sw/source/core/doc/dbgoutsw.cxx b/sw/source/core/doc/dbgoutsw.cxx
index a29ede3..3b99a31 100644
--- a/sw/source/core/doc/dbgoutsw.cxx
+++ b/sw/source/core/doc/dbgoutsw.cxx
@@ -112,7 +112,8 @@ SW_DLLPUBLIC const char * dbg_out(const String & aStr)
 
 SW_DLLPUBLIC const char * dbg_out(const ::rtl::OUString & aStr)
 {
-    return OUStringToOString(aStr, RTL_TEXTENCODING_ASCII_US).getStr();
+    aDbgOutResult = ByteString( rtl::OUStringToOString( aStr, RTL_TEXTENCODING_ASCII_US ) );
+    return aDbgOutResult.GetBuffer();
 }
 
 
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index bd7d98a..c9a4d3f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -133,6 +133,7 @@
 #include <com/sun/star/chart2/XChartDocument.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XNamed.hpp>
+#include <IMark.hxx>
 
 #if OSL_DEBUG_LEVEL > 1
 #include <stdio.h>
@@ -151,6 +152,79 @@ using namespace nsFieldFlags;
 using namespace sw::util;
 using namespace ::com::sun::star;
 
+class FFDataWriterHelper
+{
+    ::sax_fastparser::FSHelperPtr m_pSerializer;
+    void writeCommonStart( const rtl::OUString& rName )
+    {
+        m_pSerializer->startElementNS( XML_w, XML_ffData, FSEND );
+        m_pSerializer->singleElementNS( XML_w, XML_name,
+            FSNS( XML_w, XML_val ), OUStringToOString( rName, RTL_TEXTENCODING_UTF8 ).getStr(),
+            FSEND );
+        m_pSerializer->singleElementNS( XML_w, XML_enabled, FSEND );
+        m_pSerializer->singleElementNS( XML_w, XML_calcOnExit,
+            FSNS( XML_w, XML_val ),
+            "0", FSEND );
+    }
+    void writeFinish()
+    {
+        m_pSerializer->endElementNS( XML_w, XML_ffData );
+    }
+public:
+    FFDataWriterHelper( const ::sax_fastparser::FSHelperPtr pSerializer ) : m_pSerializer( pSerializer ){}
+    void WriteFormCheckbox( const rtl::OUString& rName, const rtl::OUString& rDefault, bool bChecked )
+    {
+       writeCommonStart( rName );
+       // Checkbox specific bits
+       m_pSerializer->startElementNS( XML_w, XML_checkBox, FSEND );
+       // currently hardcoding autosize
+       // #TODO check if this defaulted
+       m_pSerializer->startElementNS( XML_w, XML_sizeAuto, FSEND );
+       m_pSerializer->endElementNS( XML_w, XML_sizeAuto );
+       if ( rDefault.getLength() )
+       {
+           m_pSerializer->singleElementNS( XML_w, XML_default,
+               FSNS( XML_w, XML_val ),
+                   rtl::OUStringToOString( rDefault, RTL_TEXTENCODING_UTF8 ).getStr(), FSEND );
+       }
+       if ( bChecked )
+            m_pSerializer->singleElementNS( XML_w, XML_checked, FSEND );
+        m_pSerializer->endElementNS( XML_w, XML_checkBox );
+       writeFinish();
+    }
+    void WriteFormText(  const rtl::OUString& rName, const rtl::OUString& rDefault )
+    {
+       writeCommonStart( rName );
+       if ( rDefault.getLength() )
+       {
+           m_pSerializer->startElementNS( XML_w, XML_textInput, FSEND );
+           m_pSerializer->singleElementNS( XML_w, XML_default,
+               FSNS( XML_w, XML_val ),
+               rtl::OUStringToOString( rDefault, RTL_TEXTENCODING_UTF8 ).getStr(), FSEND );
+           m_pSerializer->endElementNS( XML_w, XML_textInput );
+       }
+       writeFinish();
+    }
+};
+
+class FieldMarkParamsHelper
+{
+    const sw::mark::IFieldmark& mrFieldmark;
+    public:
+    FieldMarkParamsHelper( const sw::mark::IFieldmark& rFieldmark ) : mrFieldmark( rFieldmark ) {}
+    template < typename T >
+    bool extractParam( const rtl::OUString& rKey, T& rResult )
+    {
+        bool bResult = false;
+        if ( mrFieldmark.GetParameters() )
+        {
+            sw::mark::IFieldmark::parameter_map_t::const_iterator it = mrFieldmark.GetParameters()->find( rKey );
+            if ( it != mrFieldmark.GetParameters()->end() )
+                bResult = ( it->second >>= rResult );
+        }
+        return bResult;
+    }
+};
 void DocxAttributeOutput::RTLAndCJKState( bool bIsRTL, sal_uInt16 /*nScript*/ )
 {
     if (bIsRTL)
@@ -549,6 +623,56 @@ void DocxAttributeOutput::DoWriteBookmarks()
     m_rMarksEnd.clear();
 }
 
+void DocxAttributeOutput::WriteFFData(  const FieldInfos& rInfos )
+{
+    const ::sw::mark::IFieldmark& rFieldmark = *rInfos.pFieldmark;
+    if ( rInfos.eType == ww::eFORMDROPDOWN )
+    {
+        uno::Sequence< ::rtl::OUString> vListEntries;
+        rtl::OUString sName, sHelp, sToolTip, sSelected;
+
+        FieldMarkParamsHelper params( rFieldmark );
+        params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_NAME) ), sName );
+        params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_LISTENTRY) ), vListEntries );
+
+        sal_Int32 nSelectedIndex = 0;
+
+        if ( params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_RESULT) ), nSelectedIndex ) )
+        {
+            if (nSelectedIndex < vListEntries.getLength() )
+                sSelected = vListEntries[ nSelectedIndex ];
+        }
+
+        GetExport().DoComboBox( sName, sHelp, sToolTip, sSelected, vListEntries );
+    }
+    else if ( rInfos.eType == ww::eFORMCHECKBOX )
+    {
+        rtl::OUString sName, sDefault;
+        bool bChecked = false;
+
+        FieldMarkParamsHelper params( rFieldmark );
+        params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ODF_FORMCHECKBOX_NAME ) ), sName );
+        params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ODF_FORMCHECKBOX_DEFAULT ) ), sDefault );
+
+        const sw::mark::ICheckboxFieldmark* pCheckboxFm = dynamic_cast<const sw::mark::ICheckboxFieldmark*>(&rFieldmark);
+        if ( pCheckboxFm && pCheckboxFm->IsChecked() )
+            bChecked = true;
+
+        FFDataWriterHelper ffdataOut( m_pSerializer );
+        ffdataOut.WriteFormCheckbox( sName, sDefault, bChecked );
+    }
+    else if ( rInfos.eType == ww::eFORMTEXT )
+    {
+        rtl::OUString sName, sDefault;
+        FieldMarkParamsHelper params( rFieldmark );
+        params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ODF_FORMTEXT_NAME ) ), sName );
+        params.extractParam( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( ODF_FORMTEXT_DEFAULT ) ), sDefault );
+
+        FFDataWriterHelper ffdataOut( m_pSerializer );
+        ffdataOut.WriteFormText( sName, sDefault );
+    }
+}
+
 void DocxAttributeOutput::StartField_Impl( FieldInfos& rInfos, sal_Bool bWriteRun )
 {
     if ( rInfos.pField && rInfos.eType == ww::eUNKNOWN )
@@ -566,28 +690,38 @@ void DocxAttributeOutput::StartField_Impl( FieldInfos& rInfos, sal_Bool bWriteRu
                 m_pSerializer->startElementNS( XML_w, XML_fldChar,
                     FSNS( XML_w, XML_fldCharType ), "begin",
                     FSEND );
-
-                const SwDropDownField& rFld2 = *(SwDropDownField*)rInfos.pField;
-                uno::Sequence<rtl::OUString> aItems =
-                    rFld2.GetItemSequence();
-                GetExport().DoComboBox(rFld2.GetName(),
-                           rFld2.GetHelp(),
-                           rFld2.GetToolTip(),
-                           rFld2.GetSelectedItem(), aItems);
-
+                if ( rInfos.pFieldmark && !rInfos.pField )
+                    WriteFFData(  rInfos );
+                if ( rInfos.pField )
+                {
+                    const SwDropDownField& rFld2 = *(SwDropDownField*)rInfos.pField;
+                    uno::Sequence<rtl::OUString> aItems =
+                        rFld2.GetItemSequence();
+                    GetExport().DoComboBox(rFld2.GetName(),
+                               rFld2.GetHelp(),
+                               rFld2.GetToolTip(),
+                               rFld2.GetSelectedItem(), aItems);
+                }
                 m_pSerializer->endElementNS( XML_w, XML_fldChar );
 
                 if ( bWriteRun )
                     m_pSerializer->endElementNS( XML_w, XML_r );
+                if ( !rInfos.pField )
+                    CmdField_Impl( rInfos );
 
         }
         else
         {
             // Write the field start
-            m_pSerializer->singleElementNS( XML_w, XML_fldChar,
+            m_pSerializer->startElementNS( XML_w, XML_fldChar,
                 FSNS( XML_w, XML_fldCharType ), "begin",
                 FSEND );
 
+            if ( rInfos.pFieldmark )
+                WriteFFData(  rInfos );
+
+            m_pSerializer->endElementNS( XML_w, XML_fldChar );
+
             if ( bWriteRun )
                 m_pSerializer->endElementNS( XML_w, XML_r );
 
@@ -673,12 +807,14 @@ void DocxAttributeOutput::EndField_Impl( FieldInfos& rInfos )
     }
 
     // Write the Field end
-    m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
-    m_pSerializer->singleElementNS( XML_w, XML_fldChar,
-          FSNS( XML_w, XML_fldCharType ), "end",
-          FSEND );
-    m_pSerializer->endElementNS( XML_w, XML_r );
-
+    if ( rInfos.bClose  )
+    {
+        m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
+        m_pSerializer->singleElementNS( XML_w, XML_fldChar,
+              FSNS( XML_w, XML_fldCharType ), "end",
+              FSEND );
+        m_pSerializer->endElementNS( XML_w, XML_r );
+    }
     // Write the ref field if a bookmark had to be set and the field
     // should be visible
     if ( rInfos.pField )
@@ -3059,7 +3195,6 @@ void DocxAttributeOutput::WriteField_Impl( const SwField* pFld, ww::eField eType
     infos.eType = eType;
     infos.bClose = WRITEFIELD_CLOSE & nMode;
     infos.bOpen = WRITEFIELD_START & nMode;
-
     m_Fields.push_back( infos );
 
     if ( pFld )
@@ -3081,6 +3216,12 @@ void DocxAttributeOutput::WriteField_Impl( const SwField* pFld, ww::eField eType
     }
 }
 
+void DocxAttributeOutput::WriteFormData_Impl( const ::sw::mark::IFieldmark& rFieldmark )
+{
+    if ( !m_Fields.empty() )
+        m_Fields.begin()->pFieldmark = &rFieldmark;
+}
+
 void DocxAttributeOutput::WriteBookmarks_Impl( std::vector< OUString >& rStarts,
         std::vector< OUString >& rEnds )
 {
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index afec908..dbffadc 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -31,6 +31,7 @@
 
 #include "attributeoutputbase.hxx"
 #include "fields.hxx"
+#include "IMark.hxx"
 
 #include <sax/fshelper.hxx>
 #include <sax/fastattribs.hxx>
@@ -51,10 +52,12 @@ namespace oox { namespace drawingml { class DrawingML; } }
 struct FieldInfos
 {
     const SwField*    pField;
+    const ::sw::mark::IFieldmark* pFieldmark;
     ww::eField  eType;
     bool        bOpen;
     bool        bClose;
     String     sCmd;
+    FieldInfos() : pField(NULL), pFieldmark(NULL), eType(ww::eUNKNOWN), bOpen(false), bClose(false){}
 };
 
 enum DocxColBreakStatus
@@ -259,6 +262,7 @@ public:
         const String &rNumberingString );
 
     void WriteField_Impl( const SwField* pFld, ww::eField eType, const String& rFldCmd, BYTE nMode );
+    void WriteFormData_Impl( const ::sw::mark::IFieldmark& rFieldmark );
 
     void WriteBookmarks_Impl( std::vector< rtl::OUString >& rStarts, std::vector< rtl::OUString >& rEnds );
 
@@ -305,6 +309,7 @@ private:
     /// End cell, row, and even the entire table if necessary.
     void FinishTableRowCell( ww8::WW8TableNodeInfoInner::Pointer_t pInner, bool bForceEmptyParagraph = false );
 
+    void WriteFFData( const FieldInfos& rInfos );
 protected:
 
     /// Output frames - the implementation.
diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index 48ffe71..64c88d9 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -223,9 +223,9 @@ void DocxExport::OutputField( const SwField* pFld, ww::eField eFldType, const St
     m_pAttrOutput->WriteField_Impl( pFld, eFldType, rFldCmd, nMode );
 }
 
-void DocxExport::WriteFormData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
+void DocxExport::WriteFormData( const ::sw::mark::IFieldmark& rFieldmark )
 {
-    OSL_TRACE( "TODO DocxExport::WriteFormData()\n" );
+    m_pAttrOutput->WriteFormData_Impl( rFieldmark );
 }
 
 void DocxExport::WriteHyperlinkData( const ::sw::mark::IFieldmark& /*rFieldmark*/ )
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index d36916e..432905f 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -175,6 +175,8 @@ eF_ResT SwWW8ImplReader::Read_F_FormTextBox( WW8FieldDesc* pF, String& rStr )
         maFieldStack.back().SetBookmarkType(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT)));
         maFieldStack.back().getParameters()[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Description"))] = uno::makeAny(::rtl::OUString(aFormula.sToolTip));
         maFieldStack.back().getParameters()[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"))] = uno::makeAny(::rtl::OUString(aFormula.sTitle));
+        if ( aFormula.sDefault.Len() )
+            maFieldStack.back().getParameters()[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMTEXT_DEFAULT))] = uno::makeAny(::rtl::OUString(aFormula.sDefault));
     }
     return FLD_TEXT;
     }
@@ -229,6 +231,9 @@ eF_ResT SwWW8ImplReader::Read_F_FormCheckBox( WW8FieldDesc* pF, String& rStr )
             ICheckboxFieldmark* pCheckboxFm = dynamic_cast<ICheckboxFieldmark*>(pFieldmark);
             (*pParameters)[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX_NAME))] = uno::makeAny(::rtl::OUString(aFormula.sTitle));
             (*pParameters)[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX_HELPTEXT))] = uno::makeAny(::rtl::OUString(aFormula.sToolTip));
+            if ( aFormula.sDefault.Len() )
+                (*pParameters)[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMCHECKBOX_DEFAULT))] = uno::makeAny(::rtl::OUString(aFormula.sDefault));
+
             if(pCheckboxFm)
                 pCheckboxFm->SetChecked(aFormula.nChecked);
             // set field data here...
@@ -302,6 +307,7 @@ eF_ResT SwWW8ImplReader::Read_F_FormListBox( WW8FieldDesc* pF, String& rStr)
                 uno::Sequence< ::rtl::OUString > vListEntries(aFormula.maListEntries.size());
                 ::std::copy(aFormula.maListEntries.begin(), aFormula.maListEntries.end(), ::comphelper::stl_begin(vListEntries));
                 (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_LISTENTRY))] = uno::makeAny(vListEntries);
+                (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_NAME))] = uno::makeAny(rtl::OUString( aFormula.sTitle )); 
                 sal_Int32 nIndex = aFormula.fDropdownIndex  < aFormula.maListEntries.size() ? aFormula.fDropdownIndex : 0;
                 (*pFieldmark->GetParameters())[::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(ODF_FORMDROPDOWN_RESULT))] = uno::makeAny(nIndex);
                 // set field data here...
@@ -2197,6 +2203,10 @@ void WW8FormulaControl::FormulaRead(SwWw8ControlType nWhich,
                 OSL_ENSURE(!this, "unknown option, please report to cmc");
                 break;
         }
+        if ( nDefaultChecked )
+            sDefault = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("1") );
+        else
+            sDefault = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("0") );
     }
     else if (nWhich == WW8_CT_DROPDOWN)
         *pDataStream >> nChecked;


More information about the Libreoffice-commits mailing list