summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Power <noel.power@novell.com>2011-02-10 16:18:40 +0000
committerNoel Power <noel.power@novell.com>2011-02-10 16:22:29 +0000
commitb547c0c2aa901667fef85233282ec84f34b7e5f4 (patch)
tree526c58394f4a0aa5dc3a13da4ffd341b445fd878
parenta6a5da3e61b0ff4a7e8cfdd50e4680253071aae3 (diff)
some form field import/export improvements
-rw-r--r--sw/source/core/doc/dbgoutsw.cxx3
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx175
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx5
-rw-r--r--sw/source/filter/ww8/docxexport.cxx4
-rw-r--r--sw/source/filter/ww8/ww8par3.cxx10
5 files changed, 177 insertions, 20 deletions
diff --git a/sw/source/core/doc/dbgoutsw.cxx b/sw/source/core/doc/dbgoutsw.cxx
index 5cc6dd03a1e8..ec4560da5492 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 bd7d98a4da48..c9a4d3f37676 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 f3cb8af9200d..65058b6a7190 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 3c13b262c9f4..f6c4238a69a7 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 5fffcc91b744..96da76b63fe7 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;