writerfilter/source/dmapper/DomainMapper_Impl.cxx |   26 +++++++++++++++++++---
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    5 +++-
 2 files changed, 27 insertions(+), 4 deletions(-)

New commits:
commit 9b04093e9ab67428276f27a5819d45675a8b3f9a
Author: Charu Tyagi <charu.ty...@ericsson.com>
Date:   Wed Jun 25 15:51:10 2014 +0530

    fdo#74745: (DOCX) Number formatting for custom document properties.
    
    Change-Id: Ifb9ef14180cac84fd111d81b9535266476d5f04f
    Reviewed-on: https://gerrit.libreoffice.org/9896
    Reviewed-by: Muthu Subramanian K <muthus...@gmail.com>
    Tested-by: Muthu Subramanian K <muthus...@gmail.com>

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx 
b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 89edfc4..1cf35e2 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 97b2e1e..a09e8b9 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 )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to