/src/libreoffice/include/vcl/keycod.hxx
Line | Count | Source |
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: |
40 | 280k | 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 | | |
45 | 0 | sal_uInt16 GetFullCode() const { return nKeyCodeAndModifiers; } |
46 | 0 | KeyFuncType GetFullFunction() const { return eFunc; } |
47 | | |
48 | | sal_uInt16 GetCode() const |
49 | 0 | { return (nKeyCodeAndModifiers & KEY_CODE_MASK); } |
50 | | |
51 | | sal_uInt16 GetModifier() const |
52 | 0 | { return (nKeyCodeAndModifiers & KEY_MODIFIERS_MASK); } |
53 | | bool IsShift() const |
54 | 0 | { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); } |
55 | | bool IsMod1() const |
56 | 0 | { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); } |
57 | | bool IsMod2() const |
58 | 0 | { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); } |
59 | | bool IsMod3() const |
60 | 0 | { return ((nKeyCodeAndModifiers & KEY_MOD3) != 0); } |
61 | | sal_uInt16 GetGroup() const |
62 | 0 | { return (nKeyCodeAndModifiers & KEYGROUP_TYPE); } |
63 | | |
64 | | OUString GetName() const; |
65 | | |
66 | | bool IsFunction() const |
67 | 0 | { 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 | | |
77 | | inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier ) |
78 | 972 | { |
79 | 972 | nKeyCodeAndModifiers = nKey | nModifier; |
80 | 972 | eFunc = KeyFuncType::DONTKNOW; |
81 | 972 | } |
82 | | |
83 | | inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 ) |
84 | 0 | { |
85 | 0 | nKeyCodeAndModifiers = nKey; |
86 | 0 | if( bShift ) |
87 | 0 | nKeyCodeAndModifiers |= KEY_SHIFT; |
88 | 0 | if( bMod1 ) |
89 | 0 | nKeyCodeAndModifiers |= KEY_MOD1; |
90 | 0 | if( bMod2 ) |
91 | 0 | nKeyCodeAndModifiers |= KEY_MOD2; |
92 | 0 | if( bMod3 ) |
93 | 0 | nKeyCodeAndModifiers |= KEY_MOD3; |
94 | 0 | eFunc = KeyFuncType::DONTKNOW; |
95 | 0 | } |
96 | | |
97 | | inline bool vcl::KeyCode::operator ==( const vcl::KeyCode& rKeyCode ) const |
98 | 0 | { |
99 | 0 | if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) ) |
100 | 0 | return (nKeyCodeAndModifiers == rKeyCode.nKeyCodeAndModifiers); |
101 | 0 | else |
102 | 0 | return (GetFunction() == rKeyCode.GetFunction()); |
103 | 0 | } |
104 | | |
105 | | inline bool vcl::KeyCode::operator !=( const vcl::KeyCode& rKeyCode ) const |
106 | 0 | { |
107 | 0 | if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) ) |
108 | 0 | return (nKeyCodeAndModifiers != rKeyCode.nKeyCodeAndModifiers); |
109 | 0 | else |
110 | 0 | return (GetFunction() != rKeyCode.GetFunction()); |
111 | 0 | } |
112 | | |
113 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |