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 : :
30 : : #include <salinst.hxx>
31 : : #include <salframe.hxx>
32 : : #include <svdata.hxx>
33 : :
34 : : #include <vcl/window.hxx>
35 : : #include <vcl/keycod.hxx>
36 : :
37 : : #include <tools/rc.h>
38 : :
39 : :
40 : : // =======================================================================
41 : : static sal_uInt16 aImplKeyFuncTab[(KEYFUNC_FRONT+1)*4] =
42 : : {
43 : : 0, 0, 0, 0, // KEYFUNC_DONTKNOW
44 : : KEY_N | KEY_MOD1, 0, 0, 0, // KEYFUNC_NEW
45 : : KEY_O | KEY_MOD1, KEY_OPEN, 0, 0, // KEYFUNC_OPEN
46 : : KEY_S | KEY_MOD1, 0, 0, 0, // KEYFUNC_SAVE
47 : : 0, 0, 0, 0, // KEYFUNC_SAVEAS
48 : : KEY_P | KEY_MOD1, 0, 0, 0, // KEYFUNC_PRINT
49 : : KEY_W | KEY_MOD1, KEY_F4 | KEY_MOD1, 0, 0, // KEYFUNC_CLOSE
50 : : KEY_Q | KEY_MOD1, KEY_F4 | KEY_MOD2, 0, 0, // KEYFUNC_QUIT
51 : : KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0, // KEYFUNC_CUT
52 : : KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0, // KEYFUNC_COPY
53 : : KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0, // KEYFUNC_PASTE
54 : : KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0, // KEYFUNC_UNDO
55 : : 0, 0, 0, 0, // KEYFUNC_REDO
56 : : KEY_DELETE, 0, 0, 0, // KEYFUNC_DELETE
57 : : KEY_REPEAT, 0, 0, 0, // KEYFUNC_REPEAT
58 : : KEY_F | KEY_MOD1, KEY_FIND, 0, 0, // KEYFUNC_FIND
59 : : KEY_F | KEY_SHIFT | KEY_MOD1, KEY_SHIFT | KEY_FIND, 0, 0, // KEYFUNC_FINDBACKWARD
60 : : KEY_RETURN | KEY_MOD2, 0, 0, 0, // KEYFUNC_PROPERTIES
61 : : 0, 0, 0, 0 // KEYFUNC_FRONT
62 : : };
63 : :
64 : : // -----------------------------------------------------------------------
65 : :
66 : 34 : void ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
67 : : {
68 : 34 : sal_uInt16 nIndex = (sal_uInt16)eFunc;
69 : 34 : nIndex *= 4;
70 : 34 : rCode1 = aImplKeyFuncTab[nIndex];
71 : 34 : rCode2 = aImplKeyFuncTab[nIndex+1];
72 : 34 : rCode3 = aImplKeyFuncTab[nIndex+2];
73 : 34 : rCode4 = aImplKeyFuncTab[nIndex+3];
74 : 34 : }
75 : :
76 : : // =======================================================================
77 : :
78 : 0 : KeyCode::KeyCode( KeyFuncType eFunction )
79 : : {
80 : : sal_uInt16 nDummy;
81 : 0 : ImplGetKeyCode( eFunction, nCode, nDummy, nDummy, nDummy );
82 : 0 : eFunc = eFunction;
83 : 0 : }
84 : :
85 : : // -----------------------------------------------------------------------
86 : :
87 : 0 : KeyCode::KeyCode( const ResId& rResId )
88 : : {
89 : 0 : rResId.SetRT( RSC_KEYCODE );
90 : :
91 : 0 : ResMgr* pResMgr = rResId.GetResMgr();
92 [ # # ][ # # ]: 0 : if ( pResMgr && pResMgr->GetResource( rResId ) )
[ # # ]
93 : : {
94 : 0 : pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
95 : :
96 : 0 : sal_uLong nKeyCode = pResMgr->ReadLong();
97 : 0 : sal_uLong nModifier = pResMgr->ReadLong();
98 : 0 : sal_uLong nKeyFunc = pResMgr->ReadLong();
99 : :
100 : 0 : eFunc = (KeyFuncType)nKeyFunc;
101 [ # # ]: 0 : if ( eFunc != KEYFUNC_DONTKNOW )
102 : : {
103 : : sal_uInt16 nDummy;
104 : 0 : ImplGetKeyCode( eFunc, nCode, nDummy, nDummy, nDummy );
105 : : }
106 : : else
107 : 0 : nCode = sal::static_int_cast<sal_uInt16>(nKeyCode | nModifier);
108 : : }
109 : 0 : }
110 : :
111 : : // -----------------------------------------------------------------------
112 : :
113 : 46025 : XubString KeyCode::GetName( Window* pWindow ) const
114 : : {
115 [ + - ]: 46025 : if ( !pWindow )
116 : 46025 : pWindow = ImplGetDefaultWindow();
117 [ + - ][ + - ]: 46025 : return pWindow ? XubString( pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) ) : XubString();
[ + - ][ + - ]
[ # # ][ + - ]
[ # # ]
118 : : }
119 : :
120 : : // -----------------------------------------------------------------------
121 : :
122 : 2 : KeyFuncType KeyCode::GetFunction() const
123 : : {
124 [ - + ]: 2 : if ( eFunc != KEYFUNC_DONTKNOW )
125 : 0 : return eFunc;
126 : :
127 : 2 : sal_uInt16 nCompCode = GetModifier() | GetCode();
128 [ + - ]: 2 : if ( nCompCode )
129 : : {
130 [ + + ]: 36 : for ( sal_uInt16 i = (sal_uInt16)KEYFUNC_NEW; i < (sal_uInt16)KEYFUNC_FRONT; i++ )
131 : : {
132 : : sal_uInt16 nKeyCode1;
133 : : sal_uInt16 nKeyCode2;
134 : : sal_uInt16 nKeyCode3;
135 : : sal_uInt16 nKeyCode4;
136 : 34 : ImplGetKeyCode( (KeyFuncType)i, nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
137 [ + - ][ + - ]: 34 : if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
[ - + ][ + - ]
138 : 0 : return (KeyFuncType)i;
139 : : }
140 : : }
141 : :
142 : 2 : return KEYFUNC_DONTKNOW;
143 : : }
144 : :
145 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|