1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <rtl/ustring.hxx>
23 #include <vcl/dllapi.h>
24 #include <vcl/keycodes.hxx>
26 enum class KeyFuncType
: sal_Int32
{ DONTKNOW
,
27 CUT
, COPY
, PASTE
, UNDO
,
33 class VCL_DLLPUBLIC KeyCode
36 sal_uInt16 nKeyCodeAndModifiers
;
40 KeyCode() { nKeyCodeAndModifiers
= 0; eFunc
= KeyFuncType::DONTKNOW
; }
41 KeyCode( sal_uInt16 nKey
, sal_uInt16 nModifier
= 0 );
42 KeyCode( sal_uInt16 nKey
, bool bShift
, bool bMod1
, bool bMod2
, bool bMod3
);
43 KeyCode( KeyFuncType eFunction
);
45 sal_uInt16
GetFullCode() const { return nKeyCodeAndModifiers
; }
46 KeyFuncType
GetFullFunction() const { return eFunc
; }
48 sal_uInt16
GetCode() const
49 { return (nKeyCodeAndModifiers
& KEY_CODE_MASK
); }
51 sal_uInt16
GetModifier() const
52 { return (nKeyCodeAndModifiers
& KEY_MODIFIERS_MASK
); }
54 { return ((nKeyCodeAndModifiers
& KEY_SHIFT
) != 0); }
56 { return ((nKeyCodeAndModifiers
& KEY_MOD1
) != 0); }
58 { return ((nKeyCodeAndModifiers
& KEY_MOD2
) != 0); }
60 { return ((nKeyCodeAndModifiers
& KEY_MOD3
) != 0); }
61 sal_uInt16
GetGroup() const
62 { return (nKeyCodeAndModifiers
& KEYGROUP_TYPE
); }
64 OUString
GetName() const;
66 bool IsFunction() const
67 { return (eFunc
!= KeyFuncType::DONTKNOW
); }
69 KeyFuncType
GetFunction() const;
71 bool operator ==( const KeyCode
& rKeyCode
) const;
72 bool operator !=( const KeyCode
& rKeyCode
) const;
77 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey
, sal_uInt16 nModifier
)
79 nKeyCodeAndModifiers
= nKey
| nModifier
;
80 eFunc
= KeyFuncType::DONTKNOW
;
83 inline vcl::KeyCode::KeyCode( sal_uInt16 nKey
, bool bShift
, bool bMod1
, bool bMod2
, bool bMod3
)
85 nKeyCodeAndModifiers
= nKey
;
87 nKeyCodeAndModifiers
|= KEY_SHIFT
;
89 nKeyCodeAndModifiers
|= KEY_MOD1
;
91 nKeyCodeAndModifiers
|= KEY_MOD2
;
93 nKeyCodeAndModifiers
|= KEY_MOD3
;
94 eFunc
= KeyFuncType::DONTKNOW
;
97 inline bool vcl::KeyCode::operator ==( const vcl::KeyCode
& rKeyCode
) const
99 if ( (eFunc
== KeyFuncType::DONTKNOW
) && (rKeyCode
.eFunc
== KeyFuncType::DONTKNOW
) )
100 return (nKeyCodeAndModifiers
== rKeyCode
.nKeyCodeAndModifiers
);
102 return (GetFunction() == rKeyCode
.GetFunction());
105 inline bool vcl::KeyCode::operator !=( const vcl::KeyCode
& rKeyCode
) const
107 if ( (eFunc
== KeyFuncType::DONTKNOW
) && (rKeyCode
.eFunc
== KeyFuncType::DONTKNOW
) )
108 return (nKeyCodeAndModifiers
!= rKeyCode
.nKeyCodeAndModifiers
);
110 return (GetFunction() != rKeyCode
.GetFunction());
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */