Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef _SV_KEYCODE_HXX
21 : #define _SV_KEYCODE_HXX
22 :
23 : #include <tools/string.hxx>
24 : #include <tools/solar.h>
25 : #include <vcl/dllapi.h>
26 : #include <tools/resid.hxx>
27 : #include <vcl/keycodes.hxx>
28 :
29 : #include <vcl/vclenum.hxx>
30 :
31 : class Window;
32 :
33 : // -----------
34 : // - KeyCode -
35 : // -----------
36 :
37 : class VCL_DLLPUBLIC KeyCode
38 : {
39 : private:
40 : sal_uInt16 nCode;
41 : KeyFuncType eFunc;
42 :
43 : public:
44 432043 : KeyCode() { nCode = 0; eFunc = KEYFUNC_DONTKNOW; }
45 : KeyCode( const ResId& rResId );
46 2173 : KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 )
47 2173 : { nCode = nKey | nModifier; eFunc = KEYFUNC_DONTKNOW; }
48 : KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 );
49 : KeyCode( KeyFuncType eFunction );
50 :
51 32473 : sal_uInt16 GetFullCode() const { return nCode; }
52 0 : KeyFuncType GetFullFunction() const { return eFunc; }
53 : sal_Bool IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const;
54 :
55 566 : sal_uInt16 GetCode() const
56 566 : { return (nCode & KEY_CODE); }
57 :
58 3 : sal_uInt16 GetModifier() const
59 3 : { return (nCode & KEY_MODTYPE); }
60 0 : sal_uInt16 GetAllModifier() const
61 0 : { return (nCode & KEY_ALLMODTYPE); }
62 0 : sal_Bool IsShift() const
63 0 : { return ((nCode & KEY_SHIFT) != 0); }
64 0 : sal_Bool IsMod1() const
65 0 : { return ((nCode & KEY_MOD1) != 0); }
66 0 : sal_Bool IsMod2() const
67 0 : { return ((nCode & KEY_MOD2) != 0); }
68 0 : sal_Bool IsMod3() const
69 0 : { return ((nCode & KEY_MOD3) != 0); }
70 0 : sal_uInt16 GetGroup() const
71 0 : { return (nCode & KEYGROUP_TYPE); }
72 :
73 : XubString GetName( Window* pWindow = NULL ) const;
74 :
75 2060 : sal_Bool IsFunction() const
76 2060 : { return ((eFunc != KEYFUNC_DONTKNOW) ? sal_True : sal_False); }
77 :
78 : KeyFuncType GetFunction() const;
79 :
80 : KeyCode& operator = ( const KeyCode& rKeyCode );
81 : sal_Bool operator ==( const KeyCode& rKeyCode ) const;
82 : sal_Bool operator !=( const KeyCode& rKeyCode ) const;
83 : };
84 :
85 30345 : inline KeyCode::KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 )
86 : {
87 30345 : nCode = nKey;
88 30345 : if( bShift )
89 8290 : nCode |= KEY_SHIFT;
90 30345 : if( bMod1 )
91 26323 : nCode |= KEY_MOD1;
92 30345 : if( bMod2 )
93 0 : nCode |= KEY_MOD2;
94 30345 : if( bMod3 )
95 0 : nCode |= KEY_MOD3;
96 30345 : eFunc = KEYFUNC_DONTKNOW;
97 30345 : }
98 :
99 7835 : inline sal_Bool KeyCode::operator ==( const KeyCode& rKeyCode ) const
100 : {
101 7835 : if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
102 7835 : return (nCode == rKeyCode.nCode);
103 : else
104 0 : return (GetFunction() == rKeyCode.GetFunction());
105 : }
106 :
107 0 : inline sal_Bool KeyCode::operator !=( const KeyCode& rKeyCode ) const
108 : {
109 0 : if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
110 0 : return (nCode != rKeyCode.nCode);
111 : else
112 0 : return (GetFunction() != rKeyCode.GetFunction());
113 : }
114 :
115 0 : inline sal_Bool KeyCode::IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const
116 : {
117 0 : if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
118 0 : return (GetFullCode() == rKeyCode.GetFullCode());
119 0 : return (GetFunction() == rKeyCode.GetFunction());
120 : }
121 :
122 3597 : inline KeyCode& KeyCode::operator = ( const KeyCode& rKeyCode )
123 : {
124 3597 : nCode = rKeyCode.nCode;
125 3597 : eFunc = rKeyCode.eFunc;
126 :
127 3597 : return *this;
128 : }
129 :
130 : #endif // _SV_KEYCODE_HXX
131 :
132 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|