xref: /aoo42x/main/sc/source/core/tool/addinhelpid.cxx (revision feb8f109)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 #include "addinhelpid.hxx"
28 #include "sc.hrc"
29 
30 // ============================================================================
31 
32 // A struct containing the built-in function name and the built-in help ID.
33 struct ScUnoAddInHelpId
34 {
35     const sal_Char*             pFuncName;
36     const sal_Char*             sHelpId;
37 };
38 
39 
40 // ----------------------------------------------------------------------------
41 
42 // Help IDs for Analysis AddIn. MUST BE SORTED for binary search.
43 const ScUnoAddInHelpId pAnalysisHelpIds[] =
44 {
45     { "getAccrint"                  , HID_AAI_FUNC_ACCRINT          },
46     { "getAccrintm"                 , HID_AAI_FUNC_ACCRINTM         },
47     { "getAmordegrc"                , HID_AAI_FUNC_AMORDEGRC        },
48     { "getAmorlinc"                 , HID_AAI_FUNC_AMORLINC         },
49     { "getBesseli"                  , HID_AAI_FUNC_BESSELI          },
50     { "getBesselj"                  , HID_AAI_FUNC_BESSELJ          },
51     { "getBesselk"                  , HID_AAI_FUNC_BESSELK          },
52     { "getBessely"                  , HID_AAI_FUNC_BESSELY          },
53     { "getBin2Dec"                  , HID_AAI_FUNC_BIN2DEC          },
54     { "getBin2Hex"                  , HID_AAI_FUNC_BIN2HEX          },
55     { "getBin2Oct"                  , HID_AAI_FUNC_BIN2OCT          },
56     { "getComplex"                  , HID_AAI_FUNC_COMPLEX          },
57     { "getConvert"                  , HID_AAI_FUNC_CONVERT          },
58     { "getCoupdaybs"                , HID_AAI_FUNC_COUPDAYBS        },
59     { "getCoupdays"                 , HID_AAI_FUNC_COUPDAYS         },
60     { "getCoupdaysnc"               , HID_AAI_FUNC_COUPDAYSNC       },
61     { "getCoupncd"                  , HID_AAI_FUNC_COUPNCD          },
62     { "getCoupnum"                  , HID_AAI_FUNC_COUPNUM          },
63     { "getCouppcd"                  , HID_AAI_FUNC_COUPPCD          },
64     { "getCumipmt"                  , HID_AAI_FUNC_CUMIPMT          },
65     { "getCumprinc"                 , HID_AAI_FUNC_CUMPRINC         },
66     { "getDec2Bin"                  , HID_AAI_FUNC_DEC2BIN          },
67     { "getDec2Hex"                  , HID_AAI_FUNC_DEC2HEX          },
68     { "getDec2Oct"                  , HID_AAI_FUNC_DEC2OCT          },
69     { "getDelta"                    , HID_AAI_FUNC_DELTA            },
70     { "getDisc"                     , HID_AAI_FUNC_DISC             },
71     { "getDollarde"                 , HID_AAI_FUNC_DOLLARDE         },
72     { "getDollarfr"                 , HID_AAI_FUNC_DOLLARFR         },
73     { "getDuration"                 , HID_AAI_FUNC_DURATION         },
74     { "getEdate"                    , HID_AAI_FUNC_EDATE            },
75     { "getEffect"                   , HID_AAI_FUNC_EFFECT           },
76     { "getEomonth"                  , HID_AAI_FUNC_EOMONTH          },
77     { "getErf"                      , HID_AAI_FUNC_ERF              },
78     { "getErfc"                     , HID_AAI_FUNC_ERFC             },
79     { "getFactdouble"               , HID_AAI_FUNC_FACTDOUBLE       },
80     { "getFvschedule"               , HID_AAI_FUNC_FVSCHEDULE       },
81     { "getGcd"                      , HID_AAI_FUNC_GCD              },
82     { "getGestep"                   , HID_AAI_FUNC_GESTEP           },
83     { "getHex2Bin"                  , HID_AAI_FUNC_HEX2BIN          },
84     { "getHex2Dec"                  , HID_AAI_FUNC_HEX2DEC          },
85     { "getHex2Oct"                  , HID_AAI_FUNC_HEX2OCT          },
86     { "getImabs"                    , HID_AAI_FUNC_IMABS            },
87     { "getImaginary"                , HID_AAI_FUNC_IMAGINARY        },
88     { "getImargument"               , HID_AAI_FUNC_IMARGUMENT       },
89     { "getImconjugate"              , HID_AAI_FUNC_IMCONJUGATE      },
90     { "getImcos"                    , HID_AAI_FUNC_IMCOS            },
91     { "getImcosh"                   , HID_AAI_FUNC_IMCOSH           },
92     { "getImcot"                    , HID_AAI_FUNC_IMCOT            },
93     { "getImcsc"                    , HID_AAI_FUNC_IMCSC            },
94     { "getImcsch"                   , HID_AAI_FUNC_IMCSCH           },
95     { "getImdiv"                    , HID_AAI_FUNC_IMDIV            },
96     { "getImexp"                    , HID_AAI_FUNC_IMEXP            },
97     { "getImln"                     , HID_AAI_FUNC_IMLN             },
98     { "getImlog10"                  , HID_AAI_FUNC_IMLOG10          },
99     { "getImlog2"                   , HID_AAI_FUNC_IMLOG2           },
100     { "getImpower"                  , HID_AAI_FUNC_IMPOWER          },
101     { "getImproduct"                , HID_AAI_FUNC_IMPRODUCT        },
102     { "getImreal"                   , HID_AAI_FUNC_IMREAL           },
103     { "getImsec"                    , HID_AAI_FUNC_IMSEC            },
104     { "getImsech"                   , HID_AAI_FUNC_IMSECH           },
105     { "getImsin"                    , HID_AAI_FUNC_IMSIN            },
106     { "getImsinh"                   , HID_AAI_FUNC_IMSINH           },
107     { "getImsqrt"                   , HID_AAI_FUNC_IMSQRT           },
108     { "getImsub"                    , HID_AAI_FUNC_IMSUB            },
109     { "getImsum"                    , HID_AAI_FUNC_IMSUM            },
110     { "getImtan"                    , HID_AAI_FUNC_IMTAN            },
111     { "getIntrate"                  , HID_AAI_FUNC_INTRATE          },
112     { "getIseven"                   , HID_AAI_FUNC_ISEVEN           },
113     { "getIsodd"                    , HID_AAI_FUNC_ISODD            },
114     { "getLcm"                      , HID_AAI_FUNC_LCM              },
115     { "getMduration"                , HID_AAI_FUNC_MDURATION        },
116     { "getMround"                   , HID_AAI_FUNC_MROUND           },
117     { "getMultinomial"              , HID_AAI_FUNC_MULTINOMIAL      },
118     { "getNetworkdays"              , HID_AAI_FUNC_NETWORKDAYS      },
119     { "getNominal"                  , HID_AAI_FUNC_NOMINAL          },
120     { "getOct2Bin"                  , HID_AAI_FUNC_OCT2BIN          },
121     { "getOct2Dec"                  , HID_AAI_FUNC_OCT2DEZ          },
122     { "getOct2Hex"                  , HID_AAI_FUNC_OCT2HEX          },
123     { "getOddfprice"                , HID_AAI_FUNC_ODDFPRICE        },
124     { "getOddfyield"                , HID_AAI_FUNC_ODDFYIELD        },
125     { "getOddlprice"                , HID_AAI_FUNC_ODDLPRICE        },
126     { "getOddlyield"                , HID_AAI_FUNC_ODDLYIELD        },
127     { "getPrice"                    , HID_AAI_FUNC_PRICE            },
128     { "getPricedisc"                , HID_AAI_FUNC_PRICEDISC        },
129     { "getPricemat"                 , HID_AAI_FUNC_PRICEMAT         },
130     { "getQuotient"                 , HID_AAI_FUNC_QUOTIENT         },
131     { "getRandbetween"              , HID_AAI_FUNC_RANDBETWEEN      },
132     { "getReceived"                 , HID_AAI_FUNC_RECEIVED         },
133     { "getSeriessum"                , HID_AAI_FUNC_SERIESSUM        },
134     { "getSqrtpi"                   , HID_AAI_FUNC_SQRTPI           },
135     { "getTbilleq"                  , HID_AAI_FUNC_TBILLEQ          },
136     { "getTbillprice"               , HID_AAI_FUNC_TBILLPRICE       },
137     { "getTbillyield"               , HID_AAI_FUNC_TBILLYIELD       },
138     { "getWeeknum"                  , HID_AAI_FUNC_WEEKNUM          },
139     { "getWorkday"                  , HID_AAI_FUNC_WORKDAY          },
140     { "getXirr"                     , HID_AAI_FUNC_XIRR             },
141     { "getXnpv"                     , HID_AAI_FUNC_XNPV             },
142     { "getYearfrac"                 , HID_AAI_FUNC_YEARFRAC         },
143     { "getYield"                    , HID_AAI_FUNC_YIELD            },
144     { "getYielddisc"                , HID_AAI_FUNC_YIELDDISC        },
145     { "getYieldmat"                 , HID_AAI_FUNC_YIELDMAT         }
146 };
147 
148 
149 // ----------------------------------------------------------------------------
150 
151 // Help IDs for DateFunc AddIn. MUST BE SORTED for binary search.
152 const ScUnoAddInHelpId pDateFuncHelpIds[] =
153 {
154     { "getDaysInMonth"              , HID_DAI_FUNC_DAYSINMONTH      },
155     { "getDaysInYear"               , HID_DAI_FUNC_DAYSINYEAR       },
156     { "getDiffMonths"               , HID_DAI_FUNC_DIFFMONTHS       },
157     { "getDiffWeeks"                , HID_DAI_FUNC_DIFFWEEKS        },
158     { "getDiffYears"                , HID_DAI_FUNC_DIFFYEARS        },
159     { "getRot13"                    , HID_DAI_FUNC_ROT13            },
160     { "getWeeksInYear"              , HID_DAI_FUNC_WEEKSINYEAR      }
161 };
162 
163 
164 // ============================================================================
165 
166 //UNUSED2008-05  ScUnoAddInHelpIdGenerator::ScUnoAddInHelpIdGenerator() :
167 //UNUSED2008-05  pCurrHelpIds( NULL ),
168 //UNUSED2008-05  nArrayCount( 0 )
169 //UNUSED2008-05  {
170 //UNUSED2008-05  }
171 
ScUnoAddInHelpIdGenerator(const::rtl::OUString & rServiceName)172 ScUnoAddInHelpIdGenerator::ScUnoAddInHelpIdGenerator( const ::rtl::OUString& rServiceName )
173 {
174     SetServiceName( rServiceName );
175 }
176 
SetServiceName(const::rtl::OUString & rServiceName)177 void ScUnoAddInHelpIdGenerator::SetServiceName( const ::rtl::OUString& rServiceName )
178 {
179     pCurrHelpIds = NULL;
180     sal_uInt32 nSize = 0;
181 
182     if( rServiceName.equalsAscii( "com.sun.star.sheet.addin.Analysis" ) )
183     {
184         pCurrHelpIds = pAnalysisHelpIds;
185         nSize = sizeof( pAnalysisHelpIds );
186     }
187     else if( rServiceName.equalsAscii( "com.sun.star.sheet.addin.DateFunctions" ) )
188     {
189         pCurrHelpIds = pDateFuncHelpIds;
190         nSize = sizeof( pDateFuncHelpIds );
191     }
192 
193     nArrayCount = nSize / sizeof( ScUnoAddInHelpId );
194 }
195 
GetHelpId(const::rtl::OUString & rFuncName) const196 rtl::OString ScUnoAddInHelpIdGenerator::GetHelpId( const ::rtl::OUString& rFuncName ) const
197 {
198     if( !pCurrHelpIds || !nArrayCount )
199         return rtl::OString();
200 
201     const ScUnoAddInHelpId* pFirst = pCurrHelpIds;
202     const ScUnoAddInHelpId* pLast = pCurrHelpIds + nArrayCount - 1;
203 
204     while( pFirst <= pLast )
205     {
206         const ScUnoAddInHelpId* pMiddle = pFirst + (pLast - pFirst) / 2;
207         sal_Int32 nResult = rFuncName.compareToAscii( pMiddle->pFuncName );
208         if( !nResult )
209             return pMiddle->sHelpId;
210         else if( nResult < 0 )
211             pLast = pMiddle - 1;
212         else
213             pFirst = pMiddle + 1;
214     }
215 
216     return rtl::OString();
217 }
218 
219 
220 // ============================================================================
221 
222