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 KeyCode(const KeyCode&) = default;
105 sal_Bool operator ==( const KeyCode& rKeyCode ) const;
106 sal_Bool operator !=( const KeyCode& rKeyCode ) const;
107 };
108
KeyCode(sal_uInt16 nKey,sal_Bool bShift,sal_Bool bMod1,sal_Bool bMod2,sal_Bool bMod3)109 inline KeyCode::KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 )
110 {
111 nCode = nKey;
112 if( bShift )
113 nCode |= KEY_SHIFT;
114 if( bMod1 )
115 nCode |= KEY_MOD1;
116 if( bMod2 )
117 nCode |= KEY_MOD2;
118 if( bMod3 )
119 nCode |= KEY_MOD3;
120 eFunc = KEYFUNC_DONTKNOW;
121 }
122
operator ==(const KeyCode & rKeyCode) const123 inline sal_Bool KeyCode::operator ==( const KeyCode& rKeyCode ) const
124 {
125 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
126 return (nCode == rKeyCode.nCode);
127 else
128 return (GetFunction() == rKeyCode.GetFunction());
129 }
130
operator !=(const KeyCode & rKeyCode) const131 inline sal_Bool KeyCode::operator !=( const KeyCode& rKeyCode ) const
132 {
133 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
134 return (nCode != rKeyCode.nCode);
135 else
136 return (GetFunction() != rKeyCode.GetFunction());
137 }
138
IsDefinedKeyCodeEqual(const KeyCode & rKeyCode) const139 inline sal_Bool KeyCode::IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const
140 {
141 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
142 return (GetFullKeyCode() == rKeyCode.GetFullKeyCode());
143 return (GetFunction() == rKeyCode.GetFunction());
144 }
145
operator =(const KeyCode & rKeyCode)146 inline KeyCode& KeyCode::operator = ( const KeyCode& rKeyCode )
147 {
148 nCode = rKeyCode.nCode;
149 eFunc = rKeyCode.eFunc;
150
151 return *this;
152 }
153
154 #endif // _SV_KEYCODE_HXX
155