Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / keycod.hxx
blob89e57b988265367a4e2f7989d5c2b92834b28810
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_KEYCOD_HXX
21 #define INCLUDED_VCL_KEYCOD_HXX
23 #include <rtl/ustring.hxx>
24 #include <tools/resid.hxx>
25 #include <vcl/dllapi.h>
26 #include <vcl/keycodes.hxx>
27 #include <vcl/vclenum.hxx>
29 namespace vcl { class Window; }
31 namespace vcl
34 class VCL_DLLPUBLIC KeyCode
36 private:
37 sal_uInt16 nKeyCodeAndModifiers;
38 KeyFuncType eFunc;
40 public:
41 KeyCode() { nKeyCodeAndModifiers = 0; eFunc = KeyFuncType::DONTKNOW; }
42 KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 );
43 KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 );
44 KeyCode( KeyFuncType eFunction );
46 sal_uInt16 GetFullCode() const { return nKeyCodeAndModifiers; }
47 KeyFuncType GetFullFunction() const { return eFunc; }
49 sal_uInt16 GetCode() const
50 { return (nKeyCodeAndModifiers & KEY_CODE_MASK); }
52 sal_uInt16 GetModifier() const
53 { return (nKeyCodeAndModifiers & KEY_MODIFIERS_MASK); }
54 bool IsShift() const
55 { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); }
56 bool IsMod1() const
57 { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); }
58 bool IsMod2() const
59 { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); }
60 bool IsMod3() const
61 { return ((nKeyCodeAndModifiers & KEY_MOD3) != 0); }
62 sal_uInt16 GetGroup() const
63 { return (nKeyCodeAndModifiers & KEYGROUP_TYPE); }
65 OUString GetName( vcl::Window* pWindow = nullptr ) const;
67 bool IsFunction() const
68 { return (eFunc != KeyFuncType::DONTKNOW); }
70 KeyFuncType GetFunction() const;
72 KeyCode& operator = ( const KeyCode& rKeyCode );
73 bool operator ==( const KeyCode& rKeyCode ) const;
74 bool operator !=( const KeyCode& rKeyCode ) const;
77 } // namespace vcl
79 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier )
81 nKeyCodeAndModifiers = nKey | nModifier;
82 eFunc = KeyFuncType::DONTKNOW;
85 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 )
87 nKeyCodeAndModifiers = nKey;
88 if( bShift )
89 nKeyCodeAndModifiers |= KEY_SHIFT;
90 if( bMod1 )
91 nKeyCodeAndModifiers |= KEY_MOD1;
92 if( bMod2 )
93 nKeyCodeAndModifiers |= KEY_MOD2;
94 if( bMod3 )
95 nKeyCodeAndModifiers |= KEY_MOD3;
96 eFunc = KeyFuncType::DONTKNOW;
99 inline bool vcl::KeyCode::operator ==( const vcl::KeyCode& rKeyCode ) const
101 if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
102 return (nKeyCodeAndModifiers == rKeyCode.nKeyCodeAndModifiers);
103 else
104 return (GetFunction() == rKeyCode.GetFunction());
107 inline bool vcl::KeyCode::operator !=( const vcl::KeyCode& rKeyCode ) const
109 if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
110 return (nKeyCodeAndModifiers != rKeyCode.nKeyCodeAndModifiers);
111 else
112 return (GetFunction() != rKeyCode.GetFunction());
115 inline vcl::KeyCode& vcl::KeyCode::operator = ( const vcl::KeyCode& rKeyCode )
117 nKeyCodeAndModifiers = rKeyCode.nKeyCodeAndModifiers;
118 eFunc = rKeyCode.eFunc;
120 return *this;
123 #endif // INCLUDED_VCL_KEYCOD_HXX
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */