xref: /aoo41x/main/vcl/inc/vcl/mnemonic.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _SV_MNEMONIC_HXX
29 #define _SV_MNEMONIC_HXX
30 
31 #include <vcl/dllapi.h>
32 #include <tools/string.hxx>
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/i18n/XCharacterClassification.hpp>
35 
36 // ---------------------
37 // - ImplMnemonicTypes -
38 // ---------------------
39 
40 // Mnemonic Chars, which we want support
41 // Latin 0-9
42 #define MNEMONIC_RANGE_1_START		0x30
43 #define MNEMONIC_RANGE_1_END		0x39
44 // Latin A-Z
45 #define MNEMONIC_RANGE_2_START		0x41
46 #define MNEMONIC_RANGE_2_END		0x5A
47 // Cyrillic
48 #define MNEMONIC_RANGE_3_START		0x0410
49 #define MNEMONIC_RANGE_3_END		0x042F
50 // Greek
51 #define MNEMONIC_RANGE_4_START		0x0391
52 #define MNEMONIC_RANGE_4_END		0x03AB
53 #define MNEMONIC_RANGES 			4
54 #define MAX_MNEMONICS				((MNEMONIC_RANGE_1_END-MNEMONIC_RANGE_1_START+1)+\
55 									 (MNEMONIC_RANGE_2_END-MNEMONIC_RANGE_2_START+1)+\
56 									 (MNEMONIC_RANGE_3_END-MNEMONIC_RANGE_3_START+1)+\
57 									 (MNEMONIC_RANGE_4_END-MNEMONIC_RANGE_4_START+1))
58 
59 #define MNEMONIC_CHAR				((sal_Unicode)'~')
60 #define MNEMONIC_INDEX_NOTFOUND 	((sal_uInt16)0xFFFF)
61 
62 // -------------------------
63 // - MnemonicGenerator -
64 // -------------------------
65 
66 class VCL_DLLPUBLIC MnemonicGenerator
67 {
68 private:
69 	// 0 == Mnemonic; >0 == count of characters
70 	sal_uInt8				maMnemonics[MAX_MNEMONICS];
71 	::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > mxCharClass;
72 
73 protected:
74 	SAL_DLLPRIVATE sal_uInt16		ImplGetMnemonicIndex( sal_Unicode c );
75 	SAL_DLLPRIVATE sal_Unicode 	ImplFindMnemonic( const XubString& rKey );
76 
77 public:
78 						MnemonicGenerator();
79 
80 	void				RegisterMnemonic( const XubString& rKey );
81 	sal_Bool				CreateMnemonic( XubString& rKey );
82 	::com::sun::star::uno::Reference< ::com::sun::star::i18n::XCharacterClassification > GetCharClass();
83 
84     // returns a string where all '~'-characters and CJK mnemonics of the form (~A) are completely removed
85     static String EraseAllMnemonicChars( const String& rStr );
86 };
87 
88 #endif // _SV_MNEMONIC_HXX
89