tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / vcl / keycod.hxx
blob43eb872efc12fb967a2918ef0f755f6ab1b312d9
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 #pragma once
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,
28 REDO, DELETE };
30 namespace vcl
33 class VCL_DLLPUBLIC KeyCode
35 private:
36 sal_uInt16 nKeyCodeAndModifiers;
37 KeyFuncType eFunc;
39 public:
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); }
53 bool IsShift() const
54 { return ((nKeyCodeAndModifiers & KEY_SHIFT) != 0); }
55 bool IsMod1() const
56 { return ((nKeyCodeAndModifiers & KEY_MOD1) != 0); }
57 bool IsMod2() const
58 { return ((nKeyCodeAndModifiers & KEY_MOD2) != 0); }
59 bool IsMod3() const
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;
75 } // namespace vcl
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;
86 if( bShift )
87 nKeyCodeAndModifiers |= KEY_SHIFT;
88 if( bMod1 )
89 nKeyCodeAndModifiers |= KEY_MOD1;
90 if( bMod2 )
91 nKeyCodeAndModifiers |= KEY_MOD2;
92 if( bMod3 )
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);
101 else
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);
109 else
110 return (GetFunction() != rKeyCode.GetFunction());
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */