xref: /aoo41x/main/sc/source/core/tool/addinhelpid.cxx (revision b3f79822)
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     { "getImdiv"                    , HID_AAI_FUNC_IMDIV            },
92     { "getImexp"                    , HID_AAI_FUNC_IMEXP            },
93     { "getImln"                     , HID_AAI_FUNC_IMLN             },
94     { "getImlog10"                  , HID_AAI_FUNC_IMLOG10          },
95     { "getImlog2"                   , HID_AAI_FUNC_IMLOG2           },
96     { "getImpower"                  , HID_AAI_FUNC_IMPOWER          },
97     { "getImproduct"                , HID_AAI_FUNC_IMPRODUCT        },
98     { "getImreal"                   , HID_AAI_FUNC_IMREAL           },
99     { "getImsin"                    , HID_AAI_FUNC_IMSIN            },
100     { "getImsqrt"                   , HID_AAI_FUNC_IMSQRT           },
101     { "getImsub"                    , HID_AAI_FUNC_IMSUB            },
102     { "getImsum"                    , HID_AAI_FUNC_IMSUM            },
103     { "getIntrate"                  , HID_AAI_FUNC_INTRATE          },
104     { "getIseven"                   , HID_AAI_FUNC_ISEVEN           },
105     { "getIsodd"                    , HID_AAI_FUNC_ISODD            },
106     { "getLcm"                      , HID_AAI_FUNC_LCM              },
107     { "getMduration"                , HID_AAI_FUNC_MDURATION        },
108     { "getMround"                   , HID_AAI_FUNC_MROUND           },
109     { "getMultinomial"              , HID_AAI_FUNC_MULTINOMIAL      },
110     { "getNetworkdays"              , HID_AAI_FUNC_NETWORKDAYS      },
111     { "getNominal"                  , HID_AAI_FUNC_NOMINAL          },
112     { "getOct2Bin"                  , HID_AAI_FUNC_OCT2BIN          },
113     { "getOct2Dec"                  , HID_AAI_FUNC_OCT2DEZ          },
114     { "getOct2Hex"                  , HID_AAI_FUNC_OCT2HEX          },
115     { "getOddfprice"                , HID_AAI_FUNC_ODDFPRICE        },
116     { "getOddfyield"                , HID_AAI_FUNC_ODDFYIELD        },
117     { "getOddlprice"                , HID_AAI_FUNC_ODDLPRICE        },
118     { "getOddlyield"                , HID_AAI_FUNC_ODDLYIELD        },
119     { "getPrice"                    , HID_AAI_FUNC_PRICE            },
120     { "getPricedisc"                , HID_AAI_FUNC_PRICEDISC        },
121     { "getPricemat"                 , HID_AAI_FUNC_PRICEMAT         },
122     { "getQuotient"                 , HID_AAI_FUNC_QUOTIENT         },
123     { "getRandbetween"              , HID_AAI_FUNC_RANDBETWEEN      },
124     { "getReceived"                 , HID_AAI_FUNC_RECEIVED         },
125     { "getSeriessum"                , HID_AAI_FUNC_SERIESSUM        },
126     { "getSqrtpi"                   , HID_AAI_FUNC_SQRTPI           },
127     { "getTbilleq"                  , HID_AAI_FUNC_TBILLEQ          },
128     { "getTbillprice"               , HID_AAI_FUNC_TBILLPRICE       },
129     { "getTbillyield"               , HID_AAI_FUNC_TBILLYIELD       },
130     { "getWeeknum"                  , HID_AAI_FUNC_WEEKNUM          },
131     { "getWorkday"                  , HID_AAI_FUNC_WORKDAY          },
132     { "getXirr"                     , HID_AAI_FUNC_XIRR             },
133     { "getXnpv"                     , HID_AAI_FUNC_XNPV             },
134     { "getYearfrac"                 , HID_AAI_FUNC_YEARFRAC         },
135     { "getYield"                    , HID_AAI_FUNC_YIELD            },
136     { "getYielddisc"                , HID_AAI_FUNC_YIELDDISC        },
137     { "getYieldmat"                 , HID_AAI_FUNC_YIELDMAT         }
138 };
139 
140 
141 // ----------------------------------------------------------------------------
142 
143 // Help IDs for DateFunc AddIn. MUST BE SORTED for binary search.
144 const ScUnoAddInHelpId pDateFuncHelpIds[] =
145 {
146     { "getDaysInMonth"              , HID_DAI_FUNC_DAYSINMONTH      },
147     { "getDaysInYear"               , HID_DAI_FUNC_DAYSINYEAR       },
148     { "getDiffMonths"               , HID_DAI_FUNC_DIFFMONTHS       },
149     { "getDiffWeeks"                , HID_DAI_FUNC_DIFFWEEKS        },
150     { "getDiffYears"                , HID_DAI_FUNC_DIFFYEARS        },
151     { "getRot13"                    , HID_DAI_FUNC_ROT13            },
152     { "getWeeksInYear"              , HID_DAI_FUNC_WEEKSINYEAR      }
153 };
154 
155 
156 // ============================================================================
157 
158 //UNUSED2008-05  ScUnoAddInHelpIdGenerator::ScUnoAddInHelpIdGenerator() :
159 //UNUSED2008-05  pCurrHelpIds( NULL ),
160 //UNUSED2008-05  nArrayCount( 0 )
161 //UNUSED2008-05  {
162 //UNUSED2008-05  }
163 
164 ScUnoAddInHelpIdGenerator::ScUnoAddInHelpIdGenerator( const ::rtl::OUString& rServiceName )
165 {
166     SetServiceName( rServiceName );
167 }
168 
169 void ScUnoAddInHelpIdGenerator::SetServiceName( const ::rtl::OUString& rServiceName )
170 {
171     pCurrHelpIds = NULL;
172     sal_uInt32 nSize = 0;
173 
174     if( rServiceName.equalsAscii( "com.sun.star.sheet.addin.Analysis" ) )
175     {
176         pCurrHelpIds = pAnalysisHelpIds;
177         nSize = sizeof( pAnalysisHelpIds );
178     }
179     else if( rServiceName.equalsAscii( "com.sun.star.sheet.addin.DateFunctions" ) )
180     {
181         pCurrHelpIds = pDateFuncHelpIds;
182         nSize = sizeof( pDateFuncHelpIds );
183     }
184 
185     nArrayCount = nSize / sizeof( ScUnoAddInHelpId );
186 }
187 
188 rtl::OString ScUnoAddInHelpIdGenerator::GetHelpId( const ::rtl::OUString& rFuncName ) const
189 {
190     if( !pCurrHelpIds || !nArrayCount )
191         return rtl::OString();
192 
193     const ScUnoAddInHelpId* pFirst = pCurrHelpIds;
194     const ScUnoAddInHelpId* pLast = pCurrHelpIds + nArrayCount - 1;
195 
196     while( pFirst <= pLast )
197     {
198         const ScUnoAddInHelpId* pMiddle = pFirst + (pLast - pFirst) / 2;
199         sal_Int32 nResult = rFuncName.compareToAscii( pMiddle->pFuncName );
200         if( !nResult )
201             return pMiddle->sHelpId;
202         else if( nResult < 0 )
203             pLast = pMiddle - 1;
204         else
205             pFirst = pMiddle + 1;
206     }
207 
208     return rtl::OString();
209 }
210 
211 
212 // ============================================================================
213 
214