Line data Source code
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 <tools/resid.hxx>
25 : #include <vcl/dllapi.h>
26 : #include <vcl/keycodes.hxx>
27 : #include <vcl/vclenum.hxx>
28 :
29 : namespace vcl { class Window; }
30 :
31 : namespace vcl
32 : {
33 :
34 : class VCL_DLLPUBLIC KeyCode
35 : {
36 : private:
37 : sal_uInt16 nKeyCodeAndModifiers;
38 : KeyFuncType eFunc;
39 :
40 : public:
41 536691 : 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 );
46 :
47 49337 : sal_uInt16 GetFullCode() const { return nKeyCodeAndModifiers; }
48 0 : KeyFuncType GetFullFunction() const { return eFunc; }
49 :
50 702 : sal_uInt16 GetCode() const
51 702 : { return (nKeyCodeAndModifiers & KEY_CODE_MASK); }
52 :
53 22 : sal_uInt16 GetModifier() const
54 22 : { return (nKeyCodeAndModifiers & KEY_MODIFIERS_MASK); }
55 3 : bool IsShift() const
56 3 : { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); }
57 4 : bool IsMod1() const
58 4 : { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); }
59 5 : bool IsMod2() const
60 5 : { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); }
61 3 : bool IsMod3() const
62 3 : { return ((nKeyCodeAndModifiers & KEY_MOD3) != 0); }
63 0 : sal_uInt16 GetGroup() const
64 0 : { return (nKeyCodeAndModifiers & KEYGROUP_TYPE); }
65 :
66 : OUString GetName( vcl::Window* pWindow = NULL ) const;
67 :
68 6144 : bool IsFunction() const
69 6144 : { return (eFunc != KeyFuncType::DONTKNOW); }
70 :
71 : KeyFuncType GetFunction() const;
72 :
73 : KeyCode& operator = ( const KeyCode& rKeyCode );
74 : bool operator ==( const KeyCode& rKeyCode ) const;
75 : bool operator !=( const KeyCode& rKeyCode ) const;
76 : };
77 :
78 : } // namespace vcl
79 :
80 6271 : inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier )
81 : {
82 6271 : nKeyCodeAndModifiers = nKey | nModifier;
83 6271 : eFunc = KeyFuncType::DONTKNOW;
84 6271 : }
85 :
86 43073 : inline vcl::KeyCode::KeyCode( sal_uInt16 nKey, bool bShift, bool bMod1, bool bMod2, bool bMod3 )
87 : {
88 43073 : nKeyCodeAndModifiers = nKey;
89 43073 : if( bShift )
90 13232 : nKeyCodeAndModifiers |= KEY_SHIFT;
91 43073 : if( bMod1 )
92 37534 : nKeyCodeAndModifiers |= KEY_MOD1;
93 43073 : if( bMod2 )
94 508 : nKeyCodeAndModifiers |= KEY_MOD2;
95 43073 : if( bMod3 )
96 0 : nKeyCodeAndModifiers |= KEY_MOD3;
97 43073 : eFunc = KeyFuncType::DONTKNOW;
98 43073 : }
99 :
100 7421 : inline bool vcl::KeyCode::operator ==( const vcl::KeyCode& rKeyCode ) const
101 : {
102 7421 : if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
103 7421 : return (nKeyCodeAndModifiers == rKeyCode.nKeyCodeAndModifiers);
104 : else
105 0 : return (GetFunction() == rKeyCode.GetFunction());
106 : }
107 :
108 0 : inline bool vcl::KeyCode::operator !=( const vcl::KeyCode& rKeyCode ) const
109 : {
110 0 : if ( (eFunc == KeyFuncType::DONTKNOW) && (rKeyCode.eFunc == KeyFuncType::DONTKNOW) )
111 0 : return (nKeyCodeAndModifiers != rKeyCode.nKeyCodeAndModifiers);
112 : else
113 0 : return (GetFunction() != rKeyCode.GetFunction());
114 : }
115 :
116 7727 : inline vcl::KeyCode& vcl::KeyCode::operator = ( const vcl::KeyCode& rKeyCode )
117 : {
118 7727 : nKeyCodeAndModifiers = rKeyCode.nKeyCodeAndModifiers;
119 7727 : eFunc = rKeyCode.eFunc;
120 :
121 7727 : return *this;
122 : }
123 :
124 : #endif // INCLUDED_VCL_KEYCOD_HXX
125 :
126 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|