1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: keycod.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
37 #include <vcl/salinst.hxx>
38 #include <vcl/salframe.hxx>
39 #include <vcl/svdata.hxx>
40 #include <vcl/window.hxx>
41 #ifndef _SV_KEYCOD_HXX
42 #include <vcl/keycod.hxx>
51 // =======================================================================
52 static USHORT aImplKeyFuncTab
[(KEYFUNC_FRONT
+1)*4] =
54 0, 0, 0, 0, // KEYFUNC_DONTKNOW
55 KEY_N
| KEY_MOD1
, 0, 0, 0, // KEYFUNC_NEW
56 KEY_O
| KEY_MOD1
, KEY_OPEN
, 0, 0, // KEYFUNC_OPEN
57 KEY_S
| KEY_MOD1
, 0, 0, 0, // KEYFUNC_SAVE
58 0, 0, 0, 0, // KEYFUNC_SAVEAS
59 KEY_P
| KEY_MOD1
, 0, 0, 0, // KEYFUNC_PRINT
60 KEY_W
| KEY_MOD1
, KEY_F4
| KEY_MOD1
, 0, 0, // KEYFUNC_CLOSE
61 KEY_Q
| KEY_MOD1
, KEY_F4
| KEY_MOD2
, 0, 0, // KEYFUNC_QUIT
62 KEY_X
| KEY_MOD1
, KEY_DELETE
| KEY_SHIFT
, KEY_CUT
, 0, // KEYFUNC_CUT
63 KEY_C
| KEY_MOD1
, KEY_INSERT
| KEY_MOD1
, KEY_COPY
, 0, // KEYFUNC_COPY
64 KEY_V
| KEY_MOD1
, KEY_INSERT
| KEY_SHIFT
, KEY_PASTE
, 0, // KEYFUNC_PASTE
65 KEY_Z
| KEY_MOD1
, KEY_BACKSPACE
| KEY_MOD2
, KEY_UNDO
, 0, // KEYFUNC_UNDO
66 0, 0, 0, 0, // KEYFUNC_REDO
67 KEY_DELETE
, 0, 0, 0, // KEYFUNC_DELETE
68 KEY_REPEAT
, 0, 0, 0, // KEYFUNC_REPEAT
69 KEY_F
| KEY_MOD1
, KEY_FIND
, 0, 0, // KEYFUNC_FIND
70 KEY_F
| KEY_SHIFT
| KEY_MOD1
, KEY_SHIFT
| KEY_FIND
, 0, 0, // KEYFUNC_FINDBACKWARD
71 KEY_RETURN
| KEY_MOD2
, 0, 0, 0, // KEYFUNC_PROPERTIES
72 0, 0, 0, 0 // KEYFUNC_FRONT
75 // -----------------------------------------------------------------------
77 void ImplGetKeyCode( KeyFuncType eFunc
, USHORT
& rCode1
, USHORT
& rCode2
, USHORT
& rCode3
, USHORT
& rCode4
)
79 USHORT nIndex
= (USHORT
)eFunc
;
81 rCode1
= aImplKeyFuncTab
[nIndex
];
82 rCode2
= aImplKeyFuncTab
[nIndex
+1];
83 rCode3
= aImplKeyFuncTab
[nIndex
+2];
84 rCode4
= aImplKeyFuncTab
[nIndex
+3];
87 // =======================================================================
89 KeyCode::KeyCode( KeyFuncType eFunction
)
92 ImplGetKeyCode( eFunction
, nCode
, nDummy
, nDummy
, nDummy
);
96 // -----------------------------------------------------------------------
98 KeyCode::KeyCode( const ResId
& rResId
)
100 rResId
.SetRT( RSC_KEYCODE
);
102 ResMgr
* pResMgr
= rResId
.GetResMgr();
103 if ( pResMgr
&& pResMgr
->GetResource( rResId
) )
105 pResMgr
->Increment( sizeof( RSHEADER_TYPE
) );
107 ULONG nKeyCode
= pResMgr
->ReadLong();
108 ULONG nModifier
= pResMgr
->ReadLong();
109 ULONG nKeyFunc
= pResMgr
->ReadLong();
111 eFunc
= (KeyFuncType
)nKeyFunc
;
112 if ( eFunc
!= KEYFUNC_DONTKNOW
)
115 ImplGetKeyCode( eFunc
, nCode
, nDummy
, nDummy
, nDummy
);
118 nCode
= sal::static_int_cast
<USHORT
>(nKeyCode
| nModifier
);
122 // -----------------------------------------------------------------------
124 XubString
KeyCode::GetName( Window
* pWindow
) const
127 pWindow
= ImplGetDefaultWindow();
128 return pWindow
? pWindow
->ImplGetFrame()->GetKeyName( GetFullCode() ) : XubString();
131 // -----------------------------------------------------------------------
133 XubString
KeyCode::GetSymbolName( const XubString
& rFontName
, Window
* pWindow
) const
136 pWindow
= ImplGetDefaultWindow();
137 return pWindow
? pWindow
->ImplGetFrame()->GetSymbolKeyName( rFontName
, GetFullCode() ) : XubString();
140 // -----------------------------------------------------------------------
142 KeyFuncType
KeyCode::GetFunction() const
144 if ( eFunc
!= KEYFUNC_DONTKNOW
)
147 USHORT nCompCode
= GetModifier() | GetCode();
150 for ( USHORT i
= (USHORT
)KEYFUNC_NEW
; i
< (USHORT
)KEYFUNC_FRONT
; i
++ )
156 ImplGetKeyCode( (KeyFuncType
)i
, nKeyCode1
, nKeyCode2
, nKeyCode3
, nKeyCode4
);
157 if ( (nCompCode
== nKeyCode1
) || (nCompCode
== nKeyCode2
) || (nCompCode
== nKeyCode3
) || (nCompCode
== nKeyCode4
) )
158 return (KeyFuncType
)i
;
162 return KEYFUNC_DONTKNOW
;