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_KEYCODE_HXX
25 #define _SV_KEYCODE_HXX
26
27 #include <tools/string.hxx>
28 #include <vcl/sv.h>
29 #include <vcl/dllapi.h>
30 #include <tools/resid.hxx>
31 #include <vcl/keycodes.hxx>
32
33 #include <vcl/vclenum.hxx>
34
35 class Window;
36
37 // -------------
38 // - Key-Types -
39 // -------------
40
41 // Logische KeyFunktionen
42 /*
43 #ifndef ENUM_KEYFUNCTYPE_DECLARED
44 #define ENUM_KEYFUNCTYPE_DECLARED
45 enum KeyFuncType { KEYFUNC_DONTKNOW, KEYFUNC_NEW, KEYFUNC_OPEN,
46 KEYFUNC_SAVE, KEYFUNC_SAVEAS, KEYFUNC_PRINT,
47 KEYFUNC_CLOSE, KEYFUNC_QUIT,
48 KEYFUNC_CUT, KEYFUNC_COPY, KEYFUNC_PASTE, KEYFUNC_UNDO,
49 KEYFUNC_REDO, KEYFUNC_DELETE, KEYFUNC_REPEAT,
50 KEYFUNC_FIND, KEYFUNC_FINDBACKWARD, KEYFUNC_PROPERTIES,
51 KEYFUNC_FRONT };
52 #endif
53 */
54 // -----------
55 // - KeyCode -
56 // -----------
57
58 class VCL_DLLPUBLIC KeyCode
59 {
60 private:
61 sal_uInt16 nCode;
62 KeyFuncType eFunc;
63
64 public:
KeyCode()65 KeyCode() { nCode = 0; eFunc = KEYFUNC_DONTKNOW; }
66 KeyCode( const ResId& rResId );
KeyCode(sal_uInt16 nKey,sal_uInt16 nModifier=0)67 KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 )
68 { nCode = nKey | nModifier; eFunc = KEYFUNC_DONTKNOW; }
69 KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 );
70 KeyCode( KeyFuncType eFunction );
71
GetFullCode() const72 sal_uInt16 GetFullCode() const { return nCode; }
GetFullKeyCode() const73 sal_uInt16 GetFullKeyCode() const { return (nCode) ; }
GetFullFunction() const74 KeyFuncType GetFullFunction() const { return eFunc; }
75 sal_Bool IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const;
76
GetCode() const77 sal_uInt16 GetCode() const
78 { return (nCode & KEY_CODE); }
79
GetModifier() const80 sal_uInt16 GetModifier() const
81 { return (nCode & KEY_MODTYPE); }
GetAllModifier() const82 sal_uInt16 GetAllModifier() const
83 { return (nCode & KEY_ALLMODTYPE); }
IsShift() const84 sal_Bool IsShift() const
85 { return ((nCode & KEY_SHIFT) != 0); }
IsMod1() const86 sal_Bool IsMod1() const
87 { return ((nCode & KEY_MOD1) != 0); }
IsMod2() const88 sal_Bool IsMod2() const
89 { return ((nCode & KEY_MOD2) != 0); }
IsMod3() const90 sal_Bool IsMod3() const
91 { return ((nCode & KEY_MOD3) != 0); }
GetGroup() const92 sal_uInt16 GetGroup() const
93 { return (nCode & KEYGROUP_TYPE); }
94
95 XubString GetName( Window* pWindow = NULL ) const;
96 XubString GetSymbolName( const XubString& rFontName, Window* pWindow = NULL ) const;
97
IsFunction() const98 sal_Bool IsFunction() const
99 { return ((eFunc != KEYFUNC_DONTKNOW) ? sal_True : sal_False); }
100
101 KeyFuncType GetFunction() const;
102
103 KeyCode& operator = ( const KeyCode& rKeyCode );
104 sal_Bool operator ==( const KeyCode& rKeyCode ) const;
105 sal_Bool operator !=( const KeyCode& rKeyCode ) const;
106 };
107
KeyCode(sal_uInt16 nKey,sal_Bool bShift,sal_Bool bMod1,sal_Bool bMod2,sal_Bool bMod3)108 inline KeyCode::KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 )
109 {
110 nCode = nKey;
111 if( bShift )
112 nCode |= KEY_SHIFT;
113 if( bMod1 )
114 nCode |= KEY_MOD1;
115 if( bMod2 )
116 nCode |= KEY_MOD2;
117 if( bMod3 )
118 nCode |= KEY_MOD3;
119 eFunc = KEYFUNC_DONTKNOW;
120 }
121
operator ==(const KeyCode & rKeyCode) const122 inline sal_Bool KeyCode::operator ==( const KeyCode& rKeyCode ) const
123 {
124 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
125 return (nCode == rKeyCode.nCode);
126 else
127 return (GetFunction() == rKeyCode.GetFunction());
128 }
129
operator !=(const KeyCode & rKeyCode) const130 inline sal_Bool KeyCode::operator !=( const KeyCode& rKeyCode ) const
131 {
132 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
133 return (nCode != rKeyCode.nCode);
134 else
135 return (GetFunction() != rKeyCode.GetFunction());
136 }
137
IsDefinedKeyCodeEqual(const KeyCode & rKeyCode) const138 inline sal_Bool KeyCode::IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const
139 {
140 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
141 return (GetFullKeyCode() == rKeyCode.GetFullKeyCode());
142 return (GetFunction() == rKeyCode.GetFunction());
143 }
144
operator =(const KeyCode & rKeyCode)145 inline KeyCode& KeyCode::operator = ( const KeyCode& rKeyCode )
146 {
147 nCode = rKeyCode.nCode;
148 eFunc = rKeyCode.eFunc;
149
150 return *this;
151 }
152
153 #endif // _SV_KEYCODE_HXX
154