xref: /AOO41X/main/sc/source/core/inc/cellkeytranslator.hxx (revision 38d50f7b14e1cf975d8c6468d9633894cd59b523)
1*38d50f7bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*38d50f7bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*38d50f7bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*38d50f7bSAndrew Rist  * distributed with this work for additional information
6*38d50f7bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*38d50f7bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*38d50f7bSAndrew Rist  * "License"); you may not use this file except in compliance
9*38d50f7bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*38d50f7bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*38d50f7bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*38d50f7bSAndrew Rist  * software distributed under the License is distributed on an
15*38d50f7bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*38d50f7bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*38d50f7bSAndrew Rist  * specific language governing permissions and limitations
18*38d50f7bSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*38d50f7bSAndrew Rist  *************************************************************/
21*38d50f7bSAndrew Rist 
22*38d50f7bSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SC_CELLKEY_TRANSLATOR_HXX
25cdf0e10cSrcweir #define SC_CELLKEY_TRANSLATOR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "global.hxx"
28cdf0e10cSrcweir #include "formula/opcode.hxx"
29cdf0e10cSrcweir #include "unotools/transliterationwrapper.hxx"
30cdf0e10cSrcweir #include <hash_map>
31cdf0e10cSrcweir #include <list>
32cdf0e10cSrcweir #include <memory>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir struct TransItem;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir struct ScCellKeyword
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     const sal_Char* mpName;
41cdf0e10cSrcweir     OpCode meOpCode;
42cdf0e10cSrcweir     const ::com::sun::star::lang::Locale& mrLocale;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     ScCellKeyword(const sal_Char* pName, OpCode eOpCode, const ::com::sun::star::lang::Locale& rLocale);
45cdf0e10cSrcweir };
46cdf0e10cSrcweir 
47cdf0e10cSrcweir typedef ::std::hash_map< String, ::std::list<ScCellKeyword>, ScStringHashCode, ::std::equal_to<String> > ScCellKeywordHashMap;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /** Translate cell function keywords.
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     This class provides a convenient way to translate a string keyword used as
52cdf0e10cSrcweir     a cell function argument.  Since Calc's built-in cell functions don't
53cdf0e10cSrcweir     localize string keywords, this class is used mainly to deal with an Excel
54cdf0e10cSrcweir     document where string names may be localized.
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     To use, simply call the
57cdf0e10cSrcweir 
58cdf0e10cSrcweir        ScCellKeywordTranslator::transKeyword(...)
59cdf0e10cSrcweir 
60cdf0e10cSrcweir     function.
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     Note that when the locale and/or the opcode is specified, the function
63cdf0e10cSrcweir     tries to find a string with matching locale and/or opcode. But when it
64cdf0e10cSrcweir     fails to find one that satisfies the specified locale and/or opcode, it
65cdf0e10cSrcweir     returns a translated string with non-matching locale and/or opcode if
66cdf0e10cSrcweir     available. */
67cdf0e10cSrcweir class ScCellKeywordTranslator
68cdf0e10cSrcweir {
69cdf0e10cSrcweir public:
70cdf0e10cSrcweir     static void transKeyword(String& rName, const ::com::sun::star::lang::Locale* pLocale = NULL, OpCode eOpCode = ocNone);
71cdf0e10cSrcweir     ~ScCellKeywordTranslator();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir private:
74cdf0e10cSrcweir     ScCellKeywordTranslator();
75cdf0e10cSrcweir 
76cdf0e10cSrcweir     void init();
77cdf0e10cSrcweir     void addToMap(const String& rKey, const sal_Char* pName,
78cdf0e10cSrcweir                   const ::com::sun::star::lang::Locale& rLocale,
79cdf0e10cSrcweir                   OpCode eOpCode = ocNone);
80cdf0e10cSrcweir     void addToMap(const TransItem* pItems, const ::com::sun::star::lang::Locale& rLocale);
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     static ::std::auto_ptr<ScCellKeywordTranslator> spInstance;
83cdf0e10cSrcweir     ScCellKeywordHashMap maStringNameMap;
84cdf0e10cSrcweir     ::utl::TransliterationWrapper maTransWrapper;
85cdf0e10cSrcweir };
86cdf0e10cSrcweir 
87cdf0e10cSrcweir #endif
88