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 #pragma once
21
22 #include <rtl/ustring.hxx>
23 #include <vcl/dllapi.h>
24 #include <vcl/keycodes.hxx>
25
26 enum class KeyFuncType : sal_Int32 { DONTKNOW,
27 CUT, COPY, PASTE, UNDO,
28 REDO, DELETE };
29
30 namespace vcl
31 {
32
33 class VCL_DLLPUBLIC KeyCode
34 {
35 private:
36 sal_uInt16 nKeyCodeAndModifiers;
37 KeyFuncType eFunc;
38
39 public:
KeyCode()40 KeyCode() { nKeyCodeAndModifiers = 0; eFunc = KeyFuncType::DONTKNOW; }
41 KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 );
42 KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 );
43 KeyCode( KeyFuncType eFunction );
44
GetFullCode() const45 sal_uInt16 GetFullCode() const { return nKeyCodeAndModifiers; }
GetFullFunction() const46 KeyFuncType GetFullFunction() const { return eFunc; }
47
GetCode() const48 sal_uInt16 GetCode() const
49 { return (nKeyCodeAndModifiers & KEY_CODE_MASK); }
50
GetModifier() const51 sal_uInt16 GetModifier() const
52 { return (nKeyCodeAndModifiers & KEY_MODIFIERS_MASK); }
IsShift() const53 bool IsShift() const
54 { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); }
IsMod1() const55 bool IsMod1() const
56 { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); }
IsMod2() const57 bool IsMod2() const
58 { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); }
IsMod3() const59 bool IsMod3() const
60 { return ((nKeyCodeAndModifiers & KEY_MOD3) != 0); }
GetGroup() const61 sal_uInt16 GetGroup() const
62 { return (nKeyCodeAndModifiers & KEYGROUP_TYPE); }
63
64 OUString GetName() const;
65
IsFunction() const66 bool IsFunction() const
67 { return (eFunc != KeyFuncType::DONTKNOW); }
68
69 KeyFuncType GetFunction() const;
70
71 bool operator ==( const KeyCode& rKeyCode ) const;
72 bool operator !=( const KeyCode& rKeyCode ) const;
73 };
74
75 } // namespace vcl
76
KeyCode(sal_uInt16 nKey,sal_uInt16 nModifier)77 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier )
78 {
79 nKeyCodeAndModifiers = nKey | nModifier;
80 eFunc = KeyFuncType::DONTKNOW;
81 }
82
KeyCode(sal_uInt16 nKey,bool bShift,bool bMod1,bool bMod2,bool bMod3)83 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 )
84 {
85 nKeyCodeAndModifiers = nKey;
86 if( bShift )
87 nKeyCodeAndModifiers |= KEY_SHIFT;
88 if( bMod1 )
89 nKeyCodeAndModifiers |= KEY_MOD1;
90 if( bMod2 )
91 nKeyCodeAndModifiers |= KEY_MOD2;
92 if( bMod3 )
93 nKeyCodeAndModifiers |= KEY_MOD3;
94 eFunc = KeyFuncType::DONTKNOW;
95 }
96
operator ==(const vcl::KeyCode & rKeyCode) const97 inline bool vcl::KeyCode::operator ==( const vcl::KeyCode& rKeyCode ) const
98 {
99 if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
100 return (nKeyCodeAndModifiers == rKeyCode.nKeyCodeAndModifiers);
101 else
102 return (GetFunction() == rKeyCode.GetFunction());
103 }
104
operator !=(const vcl::KeyCode & rKeyCode) const105 inline bool vcl::KeyCode::operator !=( const vcl::KeyCode& rKeyCode ) const
106 {
107 if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
108 return (nKeyCodeAndModifiers != rKeyCode.nKeyCodeAndModifiers);
109 else
110 return (GetFunction() != rKeyCode.GetFunction());
111 }
112
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
114