xref: /aoo4110/main/vcl/inc/vcl/mnemonic.hxx (revision b1cdbd2c)
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 #ifndef _SV_MNEMONIC_HXX
25 #define _SV_MNEMONIC_HXX
26 
27 #include <vcl/dllapi.h>
28 #include <tools/string.hxx>
29 #include <com/sun/star/uno/Reference.h>
30 #include <com/sun/star/i18n/XCharacterClassification.hpp>
31 
32 // ---------------------
33 // - ImplMnemonicTypes -
34 // ---------------------
35 
36 // Mnemonic Chars, which we want support
37 // Latin 0-9
38 #define MNEMONIC_RANGE_1_START		0x30
39 #define MNEMONIC_RANGE_1_END		0x39
40 // Latin A-Z
41 #define MNEMONIC_RANGE_2_START		0x41
42 #define MNEMONIC_RANGE_2_END		0x5A
43 // Cyrillic
44 #define MNEMONIC_RANGE_3_START		0x0410
45 #define MNEMONIC_RANGE_3_END		0x042F
46 // Greek
47 #define MNEMONIC_RANGE_4_START		0x0391
48 #define MNEMONIC_RANGE_4_END		0x03AB
49 #define MNEMONIC_RANGES 			4
50 #define MAX_MNEMONICS				((MNEMONIC_RANGE_1_END-MNEMONIC_RANGE_1_START+1)+\
51 									 (MNEMONIC_RANGE_2_END-MNEMONIC_RANGE_2_START+1)+\
52 									 (MNEMONIC_RANGE_3_END-MNEMONIC_RANGE_3_START+1)+\
53 									 (MNEMONIC_RANGE_4_END-MNEMONIC_RANGE_4_START+1))
54 
55 #define MNEMONIC_CHAR				((sal_Unicode)'~')
56 #define MNEMONIC_INDEX_NOTFOUND 	((sal_uInt16)0xFFFF)
57 
58 // -------------------------
59 // - MnemonicGenerator -
60 // -------------------------
61 
62 class VCL_DLLPUBLIC MnemonicGenerator
63 {
64 private:
65 	// 0 == Mnemonic; >0 == count of characters
66 	sal_uInt8				maMnemonics[MAX_MNEMONICS];
67 	::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > mxCharClass;
68 
69 protected:
70 	SAL_DLLPRIVATE sal_uInt16		ImplGetMnemonicIndex( sal_Unicode c );
71 	SAL_DLLPRIVATE sal_Unicode 	ImplFindMnemonic( const XubString& rKey );
72 
73 public:
74 						MnemonicGenerator();
75 
76 	void				RegisterMnemonic( const XubString& rKey );
77 	sal_Bool				CreateMnemonic( XubString& rKey );
78 	::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > GetCharClass();
79 
80     // returns a string where all '~'-characters and CJK mnemonics of the form (~A) are completely removed
81     static String EraseAllMnemonicChars( const String& rStr );
82 };
83 
84 #endif // _SV_MNEMONIC_HXX
85