Branch libreoffice-5-0-4
[LibreOffice.git] / include / vcl / keycod.hxx
blobf33daf7fe853cf6f9ff4d65aae1ce9b2c60fbcbe
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( const ResId& rResId );
43 KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 );
44 KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 );
45 KeyCode( KeyFuncType eFunction );
47 sal_uInt16 GetFullCode() const { return nKeyCodeAndModifiers; }
48 KeyFuncType GetFullFunction() const { return eFunc; }
50 sal_uInt16 GetCode() const
51 { return (nKeyCodeAndModifiers & KEY_CODE_MASK); }
53 sal_uInt16 GetModifier() const
54 { return (nKeyCodeAndModifiers & KEY_MODIFIERS_MASK); }
55 bool IsShift() const
56 { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); }
57 bool IsMod1() const
58 { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); }
59 bool IsMod2() const
60 { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); }
61 bool IsMod3() const
62 { return ((nKeyCodeAndModifiers & KEY_MOD3) != 0); }
63 sal_uInt16 GetGroup() const
64 { return (nKeyCodeAndModifiers & KEYGROUP_TYPE); }
66 OUString GetName( vcl::Window* pWindow = NULL ) const;
68 bool IsFunction() const
69 { return (eFunc != KeyFuncType::DONTKNOW); }
71 KeyFuncType GetFunction() const;
73 KeyCode& operator = ( const KeyCode& rKeyCode );
74 bool operator ==( const KeyCode& rKeyCode ) const;
75 bool operator !=( const KeyCode& rKeyCode ) const;
78 } // namespace vcl
80 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier )
82 nKeyCodeAndModifiers = nKey | nModifier;
83 eFunc = KeyFuncType::DONTKNOW;
86 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 )
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;
100 inline bool vcl::KeyCode::operator ==( const vcl::KeyCode& rKeyCode ) const
102 if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
103 return (nKeyCodeAndModifiers == rKeyCode.nKeyCodeAndModifiers);
104 else
105 return (GetFunction() == rKeyCode.GetFunction());
108 inline bool vcl::KeyCode::operator !=( const vcl::KeyCode& rKeyCode ) const
110 if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
111 return (nKeyCodeAndModifiers != rKeyCode.nKeyCodeAndModifiers);
112 else
113 return (GetFunction() != rKeyCode.GetFunction());
116 inline vcl::KeyCode& vcl::KeyCode::operator = ( const vcl::KeyCode& rKeyCode )
118 nKeyCodeAndModifiers = rKeyCode.nKeyCodeAndModifiers;
119 eFunc = rKeyCode.eFunc;
121 return *this;
124 #endif // INCLUDED_VCL_KEYCOD_HXX
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */