Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SV_KEYCODE_HXX
30 : : #define _SV_KEYCODE_HXX
31 : :
32 : : #include <tools/string.hxx>
33 : : #include <tools/solar.h>
34 : : #include <vcl/dllapi.h>
35 : : #include <tools/resid.hxx>
36 : : #include <vcl/keycodes.hxx>
37 : :
38 : : #include <vcl/vclenum.hxx>
39 : :
40 : : class Window;
41 : :
42 : : // -----------
43 : : // - KeyCode -
44 : : // -----------
45 : :
46 : : class VCL_DLLPUBLIC KeyCode
47 : : {
48 : : private:
49 : : sal_uInt16 nCode;
50 : : KeyFuncType eFunc;
51 : :
52 : : public:
53 : 761670 : KeyCode() { nCode = 0; eFunc = KEYFUNC_DONTKNOW; }
54 : : KeyCode( const ResId& rResId );
55 : 3170 : KeyCode( sal_uInt16 nKey, sal_uInt16 nModifier = 0 )
56 : 3170 : { nCode = nKey | nModifier; eFunc = KEYFUNC_DONTKNOW; }
57 : : KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 );
58 : : KeyCode( KeyFuncType eFunction );
59 : :
60 : 46025 : sal_uInt16 GetFullCode() const { return nCode; }
61 : 2932 : sal_uInt16 GetFullKeyCode() const { return (nCode) ; }
62 : 0 : KeyFuncType GetFullFunction() const { return eFunc; }
63 : : sal_Bool IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const;
64 : :
65 : 1132 : sal_uInt16 GetCode() const
66 : 1132 : { return (nCode & KEY_CODE); }
67 : :
68 : 4 : sal_uInt16 GetModifier() const
69 : 4 : { return (nCode & KEY_MODTYPE); }
70 : 0 : sal_uInt16 GetAllModifier() const
71 : 0 : { return (nCode & KEY_ALLMODTYPE); }
72 : 0 : sal_Bool IsShift() const
73 : 0 : { return ((nCode & KEY_SHIFT) != 0); }
74 : 0 : sal_Bool IsMod1() const
75 : 0 : { return ((nCode & KEY_MOD1) != 0); }
76 : 0 : sal_Bool IsMod2() const
77 : 0 : { return ((nCode & KEY_MOD2) != 0); }
78 : 0 : sal_Bool IsMod3() const
79 : 0 : { return ((nCode & KEY_MOD3) != 0); }
80 : 0 : sal_uInt16 GetGroup() const
81 : 0 : { return (nCode & KEYGROUP_TYPE); }
82 : :
83 : : XubString GetName( Window* pWindow = NULL ) const;
84 : :
85 : 2932 : sal_Bool IsFunction() const
86 [ - + ]: 2932 : { return ((eFunc != KEYFUNC_DONTKNOW) ? sal_True : sal_False); }
87 : :
88 : : KeyFuncType GetFunction() const;
89 : :
90 : : KeyCode& operator = ( const KeyCode& rKeyCode );
91 : : sal_Bool operator ==( const KeyCode& rKeyCode ) const;
92 : : sal_Bool operator !=( const KeyCode& rKeyCode ) const;
93 : : };
94 : :
95 : 45873 : inline KeyCode::KeyCode( sal_uInt16 nKey, sal_Bool bShift, sal_Bool bMod1, sal_Bool bMod2, sal_Bool bMod3 )
96 : : {
97 : 45873 : nCode = nKey;
98 [ + + ]: 45873 : if( bShift )
99 : 9653 : nCode |= KEY_SHIFT;
100 [ + + ]: 45873 : if( bMod1 )
101 : 38425 : nCode |= KEY_MOD1;
102 [ - + ]: 45873 : if( bMod2 )
103 : 0 : nCode |= KEY_MOD2;
104 [ - + ]: 45873 : if( bMod3 )
105 : 0 : nCode |= KEY_MOD3;
106 : 45873 : eFunc = KEYFUNC_DONTKNOW;
107 : 45873 : }
108 : :
109 : 310 : inline sal_Bool KeyCode::operator ==( const KeyCode& rKeyCode ) const
110 : : {
111 [ + - ][ + - ]: 310 : if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
112 : 310 : return (nCode == rKeyCode.nCode);
113 : : else
114 : 310 : return (GetFunction() == rKeyCode.GetFunction());
115 : : }
116 : :
117 : 0 : inline sal_Bool KeyCode::operator !=( const KeyCode& rKeyCode ) const
118 : : {
119 [ # # ][ # # ]: 0 : if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
120 : 0 : return (nCode != rKeyCode.nCode);
121 : : else
122 : 0 : return (GetFunction() != rKeyCode.GetFunction());
123 : : }
124 : :
125 : 0 : inline sal_Bool KeyCode::IsDefinedKeyCodeEqual( const KeyCode& rKeyCode ) const
126 : : {
127 [ # # ][ # # ]: 0 : if ( (eFunc == KEYFUNC_DONTKNOW) && (rKeyCode.eFunc == KEYFUNC_DONTKNOW) )
128 : 0 : return (GetFullKeyCode() == rKeyCode.GetFullKeyCode());
129 : 0 : return (GetFunction() == rKeyCode.GetFunction());
130 : : }
131 : :
132 : 5998 : inline KeyCode& KeyCode::operator = ( const KeyCode& rKeyCode )
133 : : {
134 : 5998 : nCode = rKeyCode.nCode;
135 : 5998 : eFunc = rKeyCode.eFunc;
136 : :
137 : 5998 : return *this;
138 : : }
139 : :
140 : : #endif // _SV_KEYCODE_HXX
141 : :
142 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|