LibreOffice Module vcl (master)  1
keycod.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <accel.h>
23 #include <salframe.hxx>
24 #include <svdata.hxx>
25 
26 #include <vcl/window.hxx>
27 #include <vcl/keycod.hxx>
28 
29 static const sal_uInt16 aImplKeyFuncTab[(static_cast<int>(KeyFuncType::FRONT)+1)*4] =
30 {
31  0, 0, 0, 0, // KeyFuncType::DONTKNOW
32  KEY_N | KEY_MOD1, 0, 0, 0, // KeyFuncType::NEW
33  KEY_O | KEY_MOD1, KEY_OPEN, 0, 0, // KeyFuncType::OPEN
34  KEY_S | KEY_MOD1, 0, 0, 0, // KeyFuncType::SAVE
35  KEY_S | KEY_SHIFT | KEY_MOD1, 0, 0, 0, // KeyFuncType::SAVEAS
36  KEY_P | KEY_MOD1, 0, 0, 0, // KeyFuncType::PRINT
37  KEY_W | KEY_MOD1, KEY_F4 | KEY_MOD1, 0, 0, // KeyFuncType::CLOSE
38  KEY_Q | KEY_MOD1, KEY_F4 | KEY_MOD2, 0, 0, // KeyFuncType::QUIT
39  KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0, // KeyFuncType::CUT
40  KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0, // KeyFuncType::COPY
41  KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0, // KeyFuncType::PASTE
42  KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0, // KeyFuncType::UNDO
43  KEY_Y | KEY_MOD1, KEY_UNDO | KEY_SHIFT, 0, 0, // KeyFuncType::REDO
44  KEY_DELETE, 0, 0, 0, // KeyFuncType::DELETE
45  KEY_REPEAT, 0, 0, 0, // KeyFuncType::REPEAT
46  KEY_F | KEY_MOD1, KEY_FIND, 0, 0, // KeyFuncType::FIND
47  KEY_F | KEY_SHIFT | KEY_MOD1, KEY_SHIFT | KEY_FIND, 0, 0, // KeyFuncType::FINDBACKWARD
48  KEY_RETURN | KEY_MOD2, 0, 0, 0, // KeyFuncType::PROPERTIES
49  0, 0, 0, 0 // KeyFuncType::FRONT
50 };
51 
52 bool ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
53 {
54  size_t nIndex = static_cast<size_t>(eFunc);
55  nIndex *= 4;
56 
57  assert(nIndex + 3 < SAL_N_ELEMENTS(aImplKeyFuncTab) && "bad key code index");
58  if (nIndex + 3 >= SAL_N_ELEMENTS(aImplKeyFuncTab))
59  {
60  rCode1 = rCode2 = rCode3 = rCode4 = 0;
61  return false;
62  }
63 
64  rCode1 = aImplKeyFuncTab[nIndex];
65  rCode2 = aImplKeyFuncTab[nIndex+1];
66  rCode3 = aImplKeyFuncTab[nIndex+2];
67  rCode4 = aImplKeyFuncTab[nIndex+3];
68  return true;
69 }
70 
72 {
73  sal_uInt16 nDummy;
74  ImplGetKeyCode( eFunction, nKeyCodeAndModifiers, nDummy, nDummy, nDummy );
75  eFunc = eFunction;
76 }
77 
78 OUString vcl::KeyCode::GetName( vcl::Window* pWindow ) const
79 {
80  if ( !pWindow )
81  pWindow = ImplGetDefaultWindow();
82  return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : "";
83 }
84 
86 {
87  if ( eFunc != KeyFuncType::DONTKNOW )
88  return eFunc;
89 
90  sal_uInt16 nCompCode = GetModifier() | GetCode();
91  if ( nCompCode )
92  {
93  for ( sal_uInt16 i = sal_uInt16(KeyFuncType::NEW); i < sal_uInt16(KeyFuncType::FRONT); i++ )
94  {
95  sal_uInt16 nKeyCode1;
96  sal_uInt16 nKeyCode2;
97  sal_uInt16 nKeyCode3;
98  sal_uInt16 nKeyCode4;
99  ImplGetKeyCode( static_cast<KeyFuncType>(i), nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
100  if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
101  return static_cast<KeyFuncType>(i);
102  }
103  }
104 
105  return KeyFuncType::DONTKNOW;
106 }
107 
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define KEY_V
Definition: keycodes.hxx:77
#define KEY_COPY
Definition: keycodes.hxx:139
#define KEY_BACKSPACE
Definition: keycodes.hxx:122
#define KEY_DELETE
Definition: keycodes.hxx:125
#define KEY_CUT
Definition: keycodes.hxx:138
#define KEY_PASTE
Definition: keycodes.hxx:140
#define KEY_F4
Definition: keycodes.hxx:86
#define KEY_C
Definition: keycodes.hxx:58
#define KEY_SHIFT
Definition: keycodes.hxx:30
#define KEY_MOD1
Definition: keycodes.hxx:31
KeyFuncType eFunc
Definition: keycod.hxx:42
#define KEY_W
Definition: keycodes.hxx:78
#define KEY_UNDO
Definition: keycodes.hxx:141
KeyFuncType
Definition: keycod.hxx:29
sal_uInt16 nKeyCodeAndModifiers
Definition: keycod.hxx:41
#define KEY_Y
Definition: keycodes.hxx:80
#define KEY_F
Definition: keycodes.hxx:61
#define KEY_MOD2
Definition: keycodes.hxx:32
#define SAL_N_ELEMENTS(arr)
#define KEY_N
Definition: keycodes.hxx:69
#define KEY_O
Definition: keycodes.hxx:70
int i
OUString GetName(vcl::Window *pWindow=nullptr) const
Definition: keycod.cxx:78
#define KEY_Z
Definition: keycodes.hxx:81
KeyFuncType GetFunction() const
Definition: keycod.cxx:85
bool ImplGetKeyCode(KeyFuncType eFunc, sal_uInt16 &rCode1, sal_uInt16 &rCode2, sal_uInt16 &rCode3, sal_uInt16 &rCode4)
Definition: keycod.cxx:52
#define KEY_RETURN
Definition: keycodes.hxx:119
#define KEY_Q
Definition: keycodes.hxx:72
SalFrame * ImplGetFrame() const
Definition: window2.cxx:848
#define KEY_X
Definition: keycodes.hxx:79
#define KEY_S
Definition: keycodes.hxx:74
#define KEY_OPEN
Definition: keycodes.hxx:137
#define KEY_FIND
Definition: keycodes.hxx:143
#define KEY_INSERT
Definition: keycodes.hxx:124
virtual OUString GetKeyName(sal_uInt16 nKeyCode)=0
static const sal_uInt16 aImplKeyFuncTab[(static_cast< int >(KeyFuncType::FRONT)+1)*4]
Definition: keycod.cxx:29
#define KEY_REPEAT
Definition: keycodes.hxx:142
#define KEY_P
Definition: keycodes.hxx:71
vcl::Window * ImplGetDefaultWindow()
Returns either the application window, or the default GL context window.
Definition: svdata.cxx:202