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