summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharu Tyagi <charu.tyagi@ericsson.com>2014-06-25 15:51:10 +0530
committerMuthu Subramanian K <muthusuba@gmail.com>2014-06-27 06:21:20 +0000
commit9b04093e9ab67428276f27a5819d45675a8b3f9a (patch)
treea43172f8b1d3c0d1e6de7cb5aa66443a7f04ae53
parent9a741fcad458875a806295ddbd41b68d82ce9095 (diff)
fdo#74745: (DOCX) Number formatting for custom document properties.
Change-Id: Ifb9ef14180cac84fd111d81b9535266476d5f04f Reviewed-on: https://gerrit.libreoffice.org/9896 Reviewed-by: Muthu Subramanian K <muthusuba@gmail.com> Tested-by: Muthu Subramanian K <muthusuba@gmail.com>
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx26
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx5
2 files changed, 27 insertions, 4 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 89edfc4054a8..1cf35e2b9f73 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -52,7 +52,9 @@
#include <com/sun/star/text/XRedline.hpp>
#include <com/sun/star/text/XTextFieldsSupplier.hpp>
#include <com/sun/star/style/DropCapFormat.hpp>
+#include <com/sun/star/util/NumberFormatter.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
+#include <com/sun/star/util/XNumberFormatter.hpp>
#include <com/sun/star/document/XViewDataSupplier.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
@@ -2215,7 +2217,7 @@ void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale)
format to the XPropertySet
-----------------------------------------------------------------------*/
void DomainMapper_Impl::SetNumberFormat( const OUString& rCommand,
- uno::Reference< beans::XPropertySet >& xPropertySet )
+ uno::Reference< beans::XPropertySet >& xPropertySet, bool bDetectFormat )
{
OUString sFormatString = lcl_ParseFormat( rCommand );
// find \h - hijri/luna calendar todo: what about saka/era calendar?
@@ -2231,8 +2233,18 @@ void DomainMapper_Impl::SetNumberFormat( const OUString& rCommand,
//get the number formatter and convert the string to a format value
try
{
+ sal_Int32 nKey = 0;
uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW );
- sal_Int32 nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale );
+ if( bDetectFormat )
+ {
+ uno::Reference< util::XNumberFormatter> xFormatter( ::com::sun::star::util::NumberFormatter::create( m_xComponentContext ), uno::UNO_QUERY_THROW );
+ xFormatter->attachNumberFormatsSupplier( xNumberSupplier );
+ nKey = xFormatter->detectNumberFormat( 0, rCommand );
+ }
+ else
+ {
+ nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale );
+ }
xPropertySet->setPropertyValue(
PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT),
uno::makeAny( nKey ));
@@ -2797,8 +2809,11 @@ void DomainMapper_Impl::handleAuthor
uno::Reference< beans::XPropertySet >( xFieldInterface,
uno::UNO_QUERY_THROW);
if( bIsCustomField )
+ {
xFieldProperties->setPropertyValue(
rPropNameSupplier.GetName(PROP_NAME), uno::makeAny(rFirstParam));
+ pContext->SetCustomField( xFieldProperties );
+ }
else
{
if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
@@ -4036,7 +4051,12 @@ void DomainMapper_Impl::PopFieldContext()
CloseFieldCommand();
if (!pContext->GetResult().isEmpty())
- SetFieldResult(pContext->GetResult());
+ {
+ uno::Reference< beans::XPropertySet > xFieldProperties = pContext->GetCustomField();
+ if(xFieldProperites.is())
+ SetNumberFormat( pContext->GetResult(), xFieldProperties, true );
+ SetFieldResult( pContext->GetResult() );
+ }
//insert the field, TC or TOC
uno::Reference< text::XTextAppend > xTextAppend;
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index 97b2e1efa101..a09e8b99671b 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -128,6 +128,7 @@ class FieldContext
::com::sun::star::uno::Reference< ::com::sun::star::text::XFormField > m_xFormField;
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTOC;//TOX
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xTC;//TOX entry
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > m_xCustomField;
OUString m_sHyperlinkURL;
FFDataHandler::Pointer_t m_pFFDataHandler;
FormControlHelper::Pointer_t m_pFormControlHelper;
@@ -147,6 +148,8 @@ public:
void SetCommandCompleted() { m_bFieldCommandCompleted = true; }
bool IsCommandCompleted() const { return m_bFieldCommandCompleted; }
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > GetCustomField() const { return m_xCustomField; }
+ void SetCustomField( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xCustomField ) { m_xCustomField = xCustomField; }
::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > GetTextField() const { return m_xTextField;}
void SetTextField(::com::sun::star::uno::Reference< ::com::sun::star::text::XTextField > xTextField) { m_xTextField = xTextField;}
::com::sun::star::uno::Reference< ::com::sun::star::text::XFormField > GetFormField() const { return m_xFormField;}
@@ -401,7 +404,7 @@ private:
void GetCurrentLocale(::com::sun::star::lang::Locale& rLocale);
void SetNumberFormat( const OUString& rCommand,
- ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xPropertySet );
+ ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xPropertySet, bool bDetectFormat = false );
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >
FindOrCreateFieldMaster( const sal_Char* pFieldMasterService,
const OUString& rFieldMasterName )