kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0014-resolved-fdo-67536-export-internal-equivalents-as-ad.patch

f0633d
From db0d51e647e01d852ef95e46e12f1dba2d09be2b Mon Sep 17 00:00:00 2001
f0633d
From: Eike Rathke <erack@redhat.com>
f0633d
Date: Sat, 2 Nov 2013 16:25:42 +0100
f0633d
Subject: [PATCH 014/109] resolved fdo#67536 export internal equivalents as
f0633d
 add-in to .xls
f0633d
f0633d
For BIFF .xls export the internal functions that are equivalents of
f0633d
known add-in functions as those add-in functions.
f0633d
f0633d
(cherry picked from commit 06a5b1ecc39bb50dadc0bcb7378455500943ece3)
f0633d
f0633d
Conflicts:
f0633d
	sc/source/filter/inc/xlformula.hxx
f0633d
f0633d
Change-Id: If37f616a34fdabb3fa971fddad01da3dc1f28ee9
f0633d
Reviewed-on: https://gerrit.libreoffice.org/6525
f0633d
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
f0633d
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
f0633d
---
f0633d
 sc/source/filter/excel/xeformula.cxx | 16 +++++++++++++---
f0633d
 sc/source/filter/excel/xlformula.cxx | 24 +++++++++++++++++++++++-
f0633d
 sc/source/filter/inc/xlformula.hxx   | 13 +++++++++++--
f0633d
 3 files changed, 47 insertions(+), 6 deletions(-)
f0633d
f0633d
diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx
f0633d
index 5265bd1..d58e0ba 100644
f0633d
--- a/sc/source/filter/excel/xeformula.cxx
f0633d
+++ b/sc/source/filter/excel/xeformula.cxx
f0633d
@@ -139,6 +139,7 @@ public:
f0633d
     inline sal_uInt16   GetXclFuncIdx() const { return mrFuncInfo.mnXclFunc; }
f0633d
     inline bool         IsVolatile() const { return mrFuncInfo.IsVolatile(); }
f0633d
     inline bool         IsFixedParamCount() const { return mrFuncInfo.IsFixedParamCount(); }
f0633d
+    inline bool         IsAddInEquivalent() const { return mrFuncInfo.IsAddInEquivalent(); }
f0633d
     inline bool         IsMacroFunc() const { return mrFuncInfo.IsMacroFunc(); }
f0633d
     inline sal_uInt8    GetSpaces() const { return mrTokData.mnSpaces; }
f0633d
     inline const XclExpExtFuncData& GetExtFuncData() const { return maExtFuncData; }
f0633d
@@ -1360,8 +1361,11 @@ void XclExpFmlaCompImpl::ProcessFunction( const XclExpScToken& rTokData )
f0633d
     mxData->mbOk = pFuncInfo != 0;
f0633d
     if( !mxData->mbOk ) return;
f0633d
 
f0633d
+    // internal functions equivalent to an existing add-in
f0633d
+    if( pFuncInfo->IsAddInEquivalent() )
f0633d
+        aExtFuncData.Set( pFuncInfo->GetAddInEquivalentFuncName(), true, false );
f0633d
     // functions simulated by a macro call in file format
f0633d
-    if( pFuncInfo->IsMacroFunc() )
f0633d
+    else if( pFuncInfo->IsMacroFunc() )
f0633d
         aExtFuncData.Set( pFuncInfo->GetMacroFuncName(), false, true );
f0633d
 
f0633d
     XclExpFuncData aFuncData( rTokData, *pFuncInfo, aExtFuncData );
f0633d
@@ -1643,8 +1647,11 @@ void XclExpFmlaCompImpl::AppendDefaultParam( XclExpFuncData& rFuncData )
f0633d
         break;
f0633d
         default:
f0633d
         {
f0633d
-            OSL_ENSURE( rFuncData.IsMacroFunc(), "XclExpFmlaCompImpl::AppendDefaultParam - unknown opcode" );
f0633d
-            if( rFuncData.IsMacroFunc() )
f0633d
+            if( rFuncData.IsAddInEquivalent() )
f0633d
+            {
f0633d
+                AppendAddInCallToken( rFuncData.GetExtFuncData() );
f0633d
+            }
f0633d
+            else if( rFuncData.IsMacroFunc() )
f0633d
             {
f0633d
                 // Do not write the OOXML <definedName> element for new _xlfn.
f0633d
                 // prefixed functions.
f0633d
@@ -1654,7 +1661,10 @@ void XclExpFmlaCompImpl::AppendDefaultParam( XclExpFuncData& rFuncData )
f0633d
                     AppendMacroCallToken( rFuncData.GetExtFuncData() );
f0633d
             }
f0633d
             else
f0633d
+            {
f0633d
+                SAL_WARN( "sc.filter", "XclExpFmlaCompImpl::AppendDefaultParam - unknown opcode" );
f0633d
                 AppendMissingToken();   // to keep parameter count valid
f0633d
+            }
f0633d
         }
f0633d
     }
f0633d
 
f0633d
diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx
f0633d
index d4bdc86..a04a101 100644
f0633d
--- a/sc/source/filter/excel/xlformula.cxx
f0633d
+++ b/sc/source/filter/excel/xlformula.cxx
f0633d
@@ -40,6 +40,13 @@ String XclFunctionInfo::GetMacroFuncName() const
f0633d
     return EMPTY_STRING;
f0633d
 }
f0633d
 
f0633d
+String XclFunctionInfo::GetAddInEquivalentFuncName() const
f0633d
+{
f0633d
+    if( IsAddInEquivalent() )
f0633d
+        return String( mpcMacroName, strlen(mpcMacroName), RTL_TEXTENCODING_UTF8 );
f0633d
+    return EMPTY_STRING;
f0633d
+}
f0633d
+
f0633d
 // abbreviations for function return token class
f0633d
 const sal_uInt8 R = EXC_TOKCLASS_REF;
f0633d
 const sal_uInt8 V = EXC_TOKCLASS_VAL;
f0633d
@@ -64,6 +71,7 @@ const sal_uInt8 MX    = 30;                 /// Maximum parameter count.
f0633d
 
f0633d
 #define EXC_FUNCNAME( ascii )       "_xlfn." ascii
f0633d
 #define EXC_FUNCNAME_ODF( ascii )   "_xlfnodf." ascii
f0633d
+#define EXC_FUNCNAME_ADDIN( ascii )   "com.sun.star.sheet.addin." ascii
f0633d
 
f0633d
 /** Functions new in BIFF2. */
f0633d
 static const XclFunctionInfo saFuncTable_2[] =
f0633d
@@ -309,7 +317,21 @@ static const XclFunctionInfo saFuncTable_4[] =
f0633d
     { ocPercentrank,        329,    2,  3,  V, { RX, VR, VR_E }, 0, 0 },
f0633d
     { ocModalValue,         330,    1,  MX, V, { VA }, 0, 0 },
f0633d
     { ocTrimMean,           331,    2,  2,  V, { RX, VR }, 0, 0 },
f0633d
-    { ocTInv,               332,    2,  2,  V, { VR }, 0, 0 }
f0633d
+    { ocTInv,               332,    2,  2,  V, { VR }, 0, 0 },
f0633d
+    // Functions equivalent to add-in functions, use same parameters as
f0633d
+    // ocExternal but add programmatical function name (here without
f0633d
+    // "com.sun.star.sheet.addin.") so it can be looked up and stored as
f0633d
+    // add-in, as older Excel versions only know them as add-in.
f0633d
+    // These are the functions flagged as AddInMap::bMapDupToInternal=true in
f0633d
+    // sc/source/core/tool/odffmap.cxx
f0633d
+    { ocIsEven,             255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getIseven" ) },
f0633d
+    { ocIsOdd,              255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getIsodd" ) },
f0633d
+    { ocGCD,                255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getGcd" ) },
f0633d
+    { ocLCM,                255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getLcm" ) },
f0633d
+    { ocEffektiv,           255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getEffect" ) },
f0633d
+    { ocKumKapZ,            255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getCumprinc" ) },
f0633d
+    { ocKumZinsZ,           255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getCumipmt" ) },
f0633d
+    { ocNominal,            255,    1,  MX, R, { RO_E, RO }, EXC_FUNCFLAG_EXPORTONLY | EXC_FUNCFLAG_ADDINEQUIV, EXC_FUNCNAME_ADDIN( "Analysis.getNominal" ) }
f0633d
 };
f0633d
 
f0633d
 /** Functions new in BIFF5/BIFF7. Unsupported functions: DATESTRING, NUMBERSTRING. */
f0633d
diff --git a/sc/source/filter/inc/xlformula.hxx b/sc/source/filter/inc/xlformula.hxx
f0633d
index 7768769..78b5405 100644
f0633d
--- a/sc/source/filter/inc/xlformula.hxx
f0633d
+++ b/sc/source/filter/inc/xlformula.hxx
f0633d
@@ -285,6 +285,7 @@ const sal_uInt8 EXC_FUNCFLAG_VOLATILE       = 0x01;     /// Result is volatile (
f0633d
 const sal_uInt8 EXC_FUNCFLAG_IMPORTONLY     = 0x02;     /// Only used in import filter.
f0633d
 const sal_uInt8 EXC_FUNCFLAG_EXPORTONLY     = 0x04;     /// Only used in export filter.
f0633d
 const sal_uInt8 EXC_FUNCFLAG_PARAMPAIRS     = 0x08;     /// Optional parameters are expected to appear in pairs.
f0633d
+const sal_uInt8 EXC_FUNCFLAG_ADDINEQUIV     = 0x10;     /// Function is an add-in equivalent
f0633d
 
f0633d
 // selected function IDs
f0633d
 const sal_uInt16 EXC_FUNCID_IF              = 1;
f0633d
@@ -311,7 +312,11 @@ struct XclFunctionInfo
f0633d
     sal_uInt8           mnRetClass;         /// Token class of the return value.
f0633d
     XclFuncParamInfo    mpParamInfos[ EXC_FUNCINFO_PARAMINFO_COUNT ]; /// Information for all parameters.
f0633d
     sal_uInt8           mnFlags;            /// Additional flags (EXC_FUNCFLAG_* constants).
f0633d
-    const sal_Char*     mpcMacroName;       /// Function name, if simulated by a macro call (UTF-8).
f0633d
+    const sal_Char*     mpcMacroName;       /** Function name, if simulated by
f0633d
+                                                a macro call (UTF-8) EXC_FUNCFLAG_ADDINEQUIV is 0;
f0633d
+                                                or programmatical add-in name
f0633d
+                                                if stored as such and
f0633d
+                                                EXC_FUNCFLAG_ADDINEQUIV is set. */
f0633d
 
f0633d
     /** Returns true, if the function is volatile. */
f0633d
     inline bool         IsVolatile() const { return ::get_flag( mnFlags, EXC_FUNCFLAG_VOLATILE ); }
f0633d
@@ -320,9 +325,13 @@ struct XclFunctionInfo
f0633d
     /** Returns true, if the function parameter count is fixed. */
f0633d
     inline bool         IsFixedParamCount() const { return (mnXclFunc != EXC_FUNCID_EXTERNCALL) && (mnMinParamCount == mnMaxParamCount); }
f0633d
     /** Returns true, if the function is simulated by a macro call. */
f0633d
-    inline bool         IsMacroFunc() const { return mpcMacroName != 0; }
f0633d
+    inline bool         IsMacroFunc() const { return mpcMacroName != 0 && !(mnFlags & EXC_FUNCFLAG_ADDINEQUIV); }
f0633d
+    /** Returns true, if the function is stored as an add-in call. */
f0633d
+    inline bool         IsAddInEquivalent() const { return mpcMacroName != 0 && (mnFlags & EXC_FUNCFLAG_ADDINEQUIV); }
f0633d
     /** Returns the name of the external function as string. */
f0633d
     String              GetMacroFuncName() const;
f0633d
+    /** Returns the programmatical name of the Add-In function as string. */
f0633d
+    String              GetAddInEquivalentFuncName() const;
f0633d
 };
f0633d
 
f0633d
 // ----------------------------------------------------------------------------
f0633d
-- 
f0633d
1.8.4.2
f0633d