update credits
[LibreOffice.git] / include / vcl / keycod.hxx
blob70df7583bcca830a056f3b96685ab3c1dd2dbe47
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 _SV_KEYCODE_HXX
21 #define _SV_KEYCODE_HXX
23 #include <tools/string.hxx>
24 #include <tools/solar.h>
25 #include <vcl/dllapi.h>
26 #include <tools/resid.hxx>
27 #include <vcl/keycodes.hxx>
29 #include <vcl/vclenum.hxx>
31 class Window;
33 // -----------
34 // - KeyCode -
35 // -----------
37 class VCL_DLLPUBLIC KeyCode
39 private:
40 sal_uInt16 nCode;
41 KeyFuncType eFunc;
43 public:
44 KeyCode() { nCode = 0; eFunc = KEYFUNC_DONTKNOW; }
45 KeyCode( const ResId& rResId );
46 KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 )
47 { nCode = nKey | nModifier; eFunc = KEYFUNC_DONTKNOW; }
48 KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 );
49 KeyCode( KeyFuncType eFunction );
51 sal_uInt16 GetFullCode() const { return nCode; }
52 KeyFuncType GetFullFunction() const { return eFunc; }
53 sal_Bool IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const;
55 sal_uInt16 GetCode() const
56 { return (nCode & KEY_CODE); }
58 sal_uInt16 GetModifier() const
59 { return (nCode & KEY_MODTYPE); }
60 sal_uInt16 GetAllModifier() const
61 { return (nCode & KEY_ALLMODTYPE); }
62 sal_Bool IsShift() const
63 { return ((nCode & KEY_SHIFT) != 0); }
64 sal_Bool IsMod1() const
65 { return ((nCode & KEY_MOD1) != 0); }
66 sal_Bool IsMod2() const
67 { return ((nCode & KEY_MOD2) != 0); }
68 sal_Bool IsMod3() const
69 { return ((nCode & KEY_MOD3) != 0); }
70 sal_uInt16 GetGroup() const
71 { return (nCode & KEYGROUP_TYPE); }
73 XubString GetName( Window* pWindow = NULL ) const;
75 sal_Bool IsFunction() const
76 { return ((eFunc != KEYFUNC_DONTKNOW) ? sal_True : sal_False); }
78 KeyFuncType GetFunction() const;
80 KeyCode& operator = ( const KeyCode& rKeyCode );
81 sal_Bool operator ==( const KeyCode& rKeyCode ) const;
82 sal_Bool operator !=( const KeyCode& rKeyCode ) const;
85 inline KeyCode::KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 )
87 nCode = nKey;
88 if( bShift )
89 nCode |= KEY_SHIFT;
90 if( bMod1 )
91 nCode |= KEY_MOD1;
92 if( bMod2 )
93 nCode |= KEY_MOD2;
94 if( bMod3 )
95 nCode |= KEY_MOD3;
96 eFunc = KEYFUNC_DONTKNOW;
99 inline sal_Bool KeyCode::operator ==( const KeyCode& rKeyCode ) const
101 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
102 return (nCode == rKeyCode.nCode);
103 else
104 return (GetFunction() == rKeyCode.GetFunction());
107 inline sal_Bool KeyCode::operator !=( const KeyCode& rKeyCode ) const
109 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
110 return (nCode != rKeyCode.nCode);
111 else
112 return (GetFunction() != rKeyCode.GetFunction());
115 inline sal_Bool KeyCode::IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const
117 if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
118 return (GetFullCode() == rKeyCode.GetFullCode());
119 return (GetFunction() == rKeyCode.GetFunction());
122 inline KeyCode& KeyCode::operator = ( const KeyCode& rKeyCode )
124 nCode = rKeyCode.nCode;
125 eFunc = rKeyCode.eFunc;
127 return *this;
130 #endif // _SV_KEYCODE_HXX
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */