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