xref: /aoo41x/main/vcl/source/window/keycod.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <salinst.hxx>
28cdf0e10cSrcweir #include <salframe.hxx>
29cdf0e10cSrcweir #include <svdata.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <vcl/window.hxx>
32cdf0e10cSrcweir #include <vcl/keycod.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <tools/rc.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // =======================================================================
38cdf0e10cSrcweir static sal_uInt16 aImplKeyFuncTab[(KEYFUNC_FRONT+1)*4] =
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	0, 0, 0, 0,                                                    // KEYFUNC_DONTKNOW
41cdf0e10cSrcweir 	KEY_N | KEY_MOD1, 0, 0, 0,                                     // KEYFUNC_NEW
42cdf0e10cSrcweir 	KEY_O | KEY_MOD1, KEY_OPEN, 0, 0,                              // KEYFUNC_OPEN
43cdf0e10cSrcweir 	KEY_S | KEY_MOD1, 0, 0, 0,                                     // KEYFUNC_SAVE
44cdf0e10cSrcweir 	0, 0, 0, 0,                                                    // KEYFUNC_SAVEAS
45cdf0e10cSrcweir 	KEY_P | KEY_MOD1, 0, 0, 0,                                     // KEYFUNC_PRINT
46cdf0e10cSrcweir 	KEY_W | KEY_MOD1, KEY_F4 | KEY_MOD1, 0, 0,                     // KEYFUNC_CLOSE
47cdf0e10cSrcweir 	KEY_Q | KEY_MOD1, KEY_F4 | KEY_MOD2, 0, 0,                     // KEYFUNC_QUIT
48cdf0e10cSrcweir 	KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0,          // KEYFUNC_CUT
49cdf0e10cSrcweir 	KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0,          // KEYFUNC_COPY
50cdf0e10cSrcweir 	KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0,        // KEYFUNC_PASTE
51cdf0e10cSrcweir 	KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0,       // KEYFUNC_UNDO
52cdf0e10cSrcweir 	0, 0, 0, 0,                                                    // KEYFUNC_REDO
53cdf0e10cSrcweir 	KEY_DELETE, 0, 0, 0,                                           // KEYFUNC_DELETE
54cdf0e10cSrcweir 	KEY_REPEAT, 0, 0, 0,                                           // KEYFUNC_REPEAT
55cdf0e10cSrcweir 	KEY_F | KEY_MOD1, KEY_FIND, 0, 0,                              // KEYFUNC_FIND
56cdf0e10cSrcweir 	KEY_F | KEY_SHIFT | KEY_MOD1, KEY_SHIFT | KEY_FIND, 0, 0,      // KEYFUNC_FINDBACKWARD
57cdf0e10cSrcweir 	KEY_RETURN | KEY_MOD2, 0, 0, 0,                                // KEYFUNC_PROPERTIES
58cdf0e10cSrcweir 	0, 0, 0, 0                                                     // KEYFUNC_FRONT
59cdf0e10cSrcweir };
60cdf0e10cSrcweir 
61cdf0e10cSrcweir // -----------------------------------------------------------------------
62cdf0e10cSrcweir 
ImplGetKeyCode(KeyFuncType eFunc,sal_uInt16 & rCode1,sal_uInt16 & rCode2,sal_uInt16 & rCode3,sal_uInt16 & rCode4)63cdf0e10cSrcweir void ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	sal_uInt16 nIndex = (sal_uInt16)eFunc;
66cdf0e10cSrcweir 	nIndex *= 4;
67cdf0e10cSrcweir 	rCode1 = aImplKeyFuncTab[nIndex];
68cdf0e10cSrcweir 	rCode2 = aImplKeyFuncTab[nIndex+1];
69cdf0e10cSrcweir 	rCode3 = aImplKeyFuncTab[nIndex+2];
70cdf0e10cSrcweir         rCode4 = aImplKeyFuncTab[nIndex+3];
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // =======================================================================
74cdf0e10cSrcweir 
KeyCode(KeyFuncType eFunction)75cdf0e10cSrcweir KeyCode::KeyCode( KeyFuncType eFunction )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	sal_uInt16 nDummy;
78cdf0e10cSrcweir 	ImplGetKeyCode( eFunction, nCode, nDummy, nDummy, nDummy );
79cdf0e10cSrcweir 	eFunc = eFunction;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // -----------------------------------------------------------------------
83cdf0e10cSrcweir 
KeyCode(const ResId & rResId)84cdf0e10cSrcweir KeyCode::KeyCode( const ResId& rResId )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	rResId.SetRT( RSC_KEYCODE );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	ResMgr* pResMgr = rResId.GetResMgr();
89cdf0e10cSrcweir 	if ( pResMgr && pResMgr->GetResource( rResId ) )
90cdf0e10cSrcweir 	{
91cdf0e10cSrcweir 		pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 		sal_uLong nKeyCode 	= pResMgr->ReadLong();
94cdf0e10cSrcweir 		sal_uLong nModifier	= pResMgr->ReadLong();
95cdf0e10cSrcweir 		sal_uLong nKeyFunc 	= pResMgr->ReadLong();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 		eFunc = (KeyFuncType)nKeyFunc;
98cdf0e10cSrcweir 		if ( eFunc != KEYFUNC_DONTKNOW )
99cdf0e10cSrcweir 		{
100cdf0e10cSrcweir 			sal_uInt16 nDummy;
101cdf0e10cSrcweir 			ImplGetKeyCode( eFunc, nCode, nDummy, nDummy, nDummy );
102cdf0e10cSrcweir 		}
103cdf0e10cSrcweir 		else
104cdf0e10cSrcweir 			nCode = sal::static_int_cast<sal_uInt16>(nKeyCode | nModifier);
105cdf0e10cSrcweir 	}
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir // -----------------------------------------------------------------------
109cdf0e10cSrcweir 
GetName(Window * pWindow) const110cdf0e10cSrcweir XubString KeyCode::GetName( Window* pWindow ) const
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	if ( !pWindow )
113cdf0e10cSrcweir 		pWindow = ImplGetDefaultWindow();
114cdf0e10cSrcweir 	return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : XubString();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir // -----------------------------------------------------------------------
118cdf0e10cSrcweir 
GetSymbolName(const XubString & rFontName,Window * pWindow) const119cdf0e10cSrcweir XubString KeyCode::GetSymbolName( const XubString& rFontName, Window* pWindow ) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	if ( !pWindow )
122cdf0e10cSrcweir 		pWindow = ImplGetDefaultWindow();
123cdf0e10cSrcweir 	return pWindow ? pWindow->ImplGetFrame()->GetSymbolKeyName( rFontName, GetFullCode() ) : XubString();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir // -----------------------------------------------------------------------
127cdf0e10cSrcweir 
GetFunction() const128cdf0e10cSrcweir KeyFuncType KeyCode::GetFunction() const
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	if ( eFunc != KEYFUNC_DONTKNOW )
131cdf0e10cSrcweir 		return eFunc;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	sal_uInt16 nCompCode = GetModifier() | GetCode();
134cdf0e10cSrcweir 	if ( nCompCode )
135cdf0e10cSrcweir 	{
136cdf0e10cSrcweir 		for ( sal_uInt16 i = (sal_uInt16)KEYFUNC_NEW; i < (sal_uInt16)KEYFUNC_FRONT; i++ )
137cdf0e10cSrcweir 		{
138cdf0e10cSrcweir 			sal_uInt16 nKeyCode1;
139cdf0e10cSrcweir 			sal_uInt16 nKeyCode2;
140cdf0e10cSrcweir 			sal_uInt16 nKeyCode3;
141cdf0e10cSrcweir                         sal_uInt16 nKeyCode4;
142cdf0e10cSrcweir 			ImplGetKeyCode( (KeyFuncType)i, nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
143cdf0e10cSrcweir 			if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
144cdf0e10cSrcweir 				return (KeyFuncType)i;
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 	}
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	return KEYFUNC_DONTKNOW;
149cdf0e10cSrcweir }
150