Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / window / keycod.cxx
blobdf81d987cc7340ae297100fdf7b1b59727154890
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <salinst.hxx>
22 #include <salframe.hxx>
23 #include <svdata.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/keycod.hxx>
28 #include <tools/rc.h>
31 // =======================================================================
32 static const sal_uInt16 aImplKeyFuncTab[(KEYFUNC_FRONT+1)*4] =
34 0, 0, 0, 0, // KEYFUNC_DONTKNOW
35 KEY_N | KEY_MOD1, 0, 0, 0, // KEYFUNC_NEW
36 KEY_O | KEY_MOD1, KEY_OPEN, 0, 0, // KEYFUNC_OPEN
37 KEY_S | KEY_MOD1, 0, 0, 0, // KEYFUNC_SAVE
38 KEY_S | KEY_SHIFT | KEY_MOD1, 0, 0, 0, // KEYFUNC_SAVEAS
39 KEY_P | KEY_MOD1, 0, 0, 0, // KEYFUNC_PRINT
40 KEY_W | KEY_MOD1, KEY_F4 | KEY_MOD1, 0, 0, // KEYFUNC_CLOSE
41 KEY_Q | KEY_MOD1, KEY_F4 | KEY_MOD2, 0, 0, // KEYFUNC_QUIT
42 KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0, // KEYFUNC_CUT
43 KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0, // KEYFUNC_COPY
44 KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0, // KEYFUNC_PASTE
45 KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0, // KEYFUNC_UNDO
46 KEY_Y | KEY_MOD1, KEY_UNDO | KEY_SHIFT, 0, 0, // KEYFUNC_REDO
47 KEY_DELETE, 0, 0, 0, // KEYFUNC_DELETE
48 KEY_REPEAT, 0, 0, 0, // KEYFUNC_REPEAT
49 KEY_F | KEY_MOD1, KEY_FIND, 0, 0, // KEYFUNC_FIND
50 KEY_F | KEY_SHIFT | KEY_MOD1, KEY_SHIFT | KEY_FIND, 0, 0, // KEYFUNC_FINDBACKWARD
51 KEY_RETURN | KEY_MOD2, 0, 0, 0, // KEYFUNC_PROPERTIES
52 0, 0, 0, 0 // KEYFUNC_FRONT
55 // -----------------------------------------------------------------------
57 void ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
59 sal_uInt16 nIndex = (sal_uInt16)eFunc;
60 nIndex *= 4;
61 rCode1 = aImplKeyFuncTab[nIndex];
62 rCode2 = aImplKeyFuncTab[nIndex+1];
63 rCode3 = aImplKeyFuncTab[nIndex+2];
64 rCode4 = aImplKeyFuncTab[nIndex+3];
67 // =======================================================================
69 KeyCode::KeyCode( KeyFuncType eFunction )
71 sal_uInt16 nDummy;
72 ImplGetKeyCode( eFunction, nCode, nDummy, nDummy, nDummy );
73 eFunc = eFunction;
76 // -----------------------------------------------------------------------
78 KeyCode::KeyCode( const ResId& rResId )
80 rResId.SetRT( RSC_KEYCODE );
82 ResMgr* pResMgr = rResId.GetResMgr();
83 if ( pResMgr && pResMgr->GetResource( rResId ) )
85 pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
87 sal_uLong nKeyCode = pResMgr->ReadLong();
88 sal_uLong nModifier = pResMgr->ReadLong();
89 sal_uLong nKeyFunc = pResMgr->ReadLong();
91 eFunc = (KeyFuncType)nKeyFunc;
92 if ( eFunc != KEYFUNC_DONTKNOW )
94 sal_uInt16 nDummy;
95 ImplGetKeyCode( eFunc, nCode, nDummy, nDummy, nDummy );
97 else
98 nCode = sal::static_int_cast<sal_uInt16>(nKeyCode | nModifier);
102 // -----------------------------------------------------------------------
104 OUString KeyCode::GetName( Window* pWindow ) const
106 if ( !pWindow )
107 pWindow = ImplGetDefaultWindow();
108 return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : "";
111 // -----------------------------------------------------------------------
113 KeyFuncType KeyCode::GetFunction() const
115 if ( eFunc != KEYFUNC_DONTKNOW )
116 return eFunc;
118 sal_uInt16 nCompCode = GetModifier() | GetCode();
119 if ( nCompCode )
121 for ( sal_uInt16 i = (sal_uInt16)KEYFUNC_NEW; i < (sal_uInt16)KEYFUNC_FRONT; i++ )
123 sal_uInt16 nKeyCode1;
124 sal_uInt16 nKeyCode2;
125 sal_uInt16 nKeyCode3;
126 sal_uInt16 nKeyCode4;
127 ImplGetKeyCode( (KeyFuncType)i, nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
128 if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
129 return (KeyFuncType)i;
133 return KEYFUNC_DONTKNOW;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */