LibreOffice Module vcl (master)  1
keycod.hxx
Go to the documentation of this file.
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 INCLUDED_VCL_KEYCOD_HXX
21 #define INCLUDED_VCL_KEYCOD_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <vcl/dllapi.h>
25 #include <vcl/keycodes.hxx>
26 
27 namespace vcl { class Window; }
28 
29 enum class KeyFuncType : sal_Int32 { DONTKNOW,
30  CUT, COPY, PASTE, UNDO,
31  REDO, DELETE };
32 
33 namespace vcl
34 {
35 
37 {
38 private:
41 
42 public:
43  KeyCode() { nKeyCodeAndModifiers = 0; eFunc = KeyFuncType::DONTKNOW; }
44  KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 );
45  KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 );
46  KeyCode( KeyFuncType eFunction );
47 
48  sal_uInt16 GetFullCode() const { return nKeyCodeAndModifiers; }
49  KeyFuncType GetFullFunction() const { return eFunc; }
50 
51  sal_uInt16 GetCode() const
52  { return (nKeyCodeAndModifiers & KEY_CODE_MASK); }
53 
54  sal_uInt16 GetModifier() const
55  { return (nKeyCodeAndModifiers & KEY_MODIFIERS_MASK); }
56  bool IsShift() const
57  { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); }
58  bool IsMod1() const
59  { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); }
60  bool IsMod2() const
61  { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); }
62  bool IsMod3() const
63  { return ((nKeyCodeAndModifiers & KEY_MOD3) != 0); }
64  sal_uInt16 GetGroup() const
65  { return (nKeyCodeAndModifiers & KEYGROUP_TYPE); }
66 
67  OUString GetName( vcl::Window* pWindow = nullptr ) const;
68 
69  bool IsFunction() const
70  { return (eFunc != KeyFuncType::DONTKNOW); }
71 
72  KeyFuncType GetFunction() const;
73 
74  bool operator ==( const KeyCode& rKeyCode ) const;
75  bool operator !=( const KeyCode& rKeyCode ) const;
76 };
77 
78 } // namespace vcl
79 
80 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier )
81 {
82  nKeyCodeAndModifiers = nKey | nModifier;
84 }
85 
86 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 )
87 {
88  nKeyCodeAndModifiers = nKey;
89  if( bShift )
90  nKeyCodeAndModifiers |= KEY_SHIFT;
91  if( bMod1 )
92  nKeyCodeAndModifiers |= KEY_MOD1;
93  if( bMod2 )
94  nKeyCodeAndModifiers |= KEY_MOD2;
95  if( bMod3 )
96  nKeyCodeAndModifiers |= KEY_MOD3;
97  eFunc = KeyFuncType::DONTKNOW;
98 }
99 
100 inline bool vcl::KeyCode::operator ==( const vcl::KeyCode& rKeyCode ) const
101 {
102  if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
103  return (nKeyCodeAndModifiers == rKeyCode.nKeyCodeAndModifiers);
104  else
105  return (GetFunction() == rKeyCode.GetFunction());
106 }
107 
108 inline bool vcl::KeyCode::operator !=( const vcl::KeyCode& rKeyCode ) const
109 {
110  if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
111  return (nKeyCodeAndModifiers != rKeyCode.nKeyCodeAndModifiers);
112  else
113  return (GetFunction() != rKeyCode.GetFunction());
114 }
115 
116 #endif // INCLUDED_VCL_KEYCOD_HXX
117 
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 KEY_CODE_MASK
Definition: keycodes.hxx:27
bool operator!=(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:211
constexpr sal_uInt16 KEY_MOD1
Definition: keycodes.hxx:31
KeyFuncType GetFullFunction() const
Definition: keycod.hxx:49
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
bool operator==(const KeyCode &rKeyCode) const
Definition: keycod.hxx:100
KeyFuncType eFunc
Definition: keycod.hxx:40
sal_uInt16 GetGroup() const
Definition: keycod.hxx:64
sal_uInt16 GetCode() const
Definition: keycod.hxx:51
KeyFuncType
Definition: keycod.hxx:29
sal_uInt16 nKeyCodeAndModifiers
Definition: keycod.hxx:39
sal_uInt16 GetModifier() const
Definition: keycod.hxx:54
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:206
constexpr sal_uInt16 KEY_MODIFIERS_MASK
Definition: keycodes.hxx:34
bool operator!=(const KeyCode &rKeyCode) const
Definition: keycod.hxx:108
constexpr sal_uInt16 KEYGROUP_TYPE
Definition: keycodes.hxx:42
constexpr sal_uInt16 KEY_MOD2
Definition: keycodes.hxx:32
KeyFuncType GetFunction() const
Definition: keycod.cxx:73
bool IsShift() const
Definition: keycod.hxx:56
bool IsMod1() const
Definition: keycod.hxx:58
sal_uInt16 GetFullCode() const
Definition: keycod.hxx:48
constexpr sal_uInt16 KEY_MOD3
Definition: keycodes.hxx:33
constexpr sal_uInt16 KEY_SHIFT
Definition: keycodes.hxx:30
bool IsFunction() const
Definition: keycod.hxx:69
bool IsMod3() const
Definition: keycod.hxx:62
bool IsMod2() const
Definition: keycod.hxx:60