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 const sal_uInt16 aImplKeyFuncTab[(static_cast<int>(KeyFuncType::DELETE)+1)*4] =
30 {
31  0, 0, 0, 0, // KeyFuncType::DONTKNOW
32  KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0, // KeyFuncType::CUT
33  KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0, // KeyFuncType::COPY
34  KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0, // KeyFuncType::PASTE
35  KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0, // KeyFuncType::UNDO
36  KEY_Y | KEY_MOD1, KEY_UNDO | KEY_SHIFT, 0, 0, // KeyFuncType::REDO
37  KEY_DELETE, 0, 0, 0 // KeyFuncType::DELETE
38 };
39 
40 bool ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
41 {
42  size_t nIndex = static_cast<size_t>(eFunc);
43  nIndex *= 4;
44 
45  assert(nIndex + 3 < SAL_N_ELEMENTS(aImplKeyFuncTab) && "bad key code index");
46  if (nIndex + 3 >= SAL_N_ELEMENTS(aImplKeyFuncTab))
47  {
48  rCode1 = rCode2 = rCode3 = rCode4 = 0;
49  return false;
50  }
51 
52  rCode1 = aImplKeyFuncTab[nIndex];
53  rCode2 = aImplKeyFuncTab[nIndex+1];
54  rCode3 = aImplKeyFuncTab[nIndex+2];
55  rCode4 = aImplKeyFuncTab[nIndex+3];
56  return true;
57 }
58 
60 {
61  sal_uInt16 nDummy;
62  ImplGetKeyCode( eFunction, nKeyCodeAndModifiers, nDummy, nDummy, nDummy );
63  eFunc = eFunction;
64 }
65 
66 OUString vcl::KeyCode::GetName( vcl::Window* pWindow ) const
67 {
68  if ( !pWindow )
69  pWindow = ImplGetDefaultWindow();
70  return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : "";
71 }
72 
74 {
75  if ( eFunc != KeyFuncType::DONTKNOW )
76  return eFunc;
77 
78  sal_uInt16 nCompCode = GetModifier() | GetCode();
79  if ( nCompCode )
80  {
81  for ( sal_uInt16 i = sal_uInt16(KeyFuncType::CUT); i <= sal_uInt16(KeyFuncType::DELETE); i++ )
82  {
83  sal_uInt16 nKeyCode1;
84  sal_uInt16 nKeyCode2;
85  sal_uInt16 nKeyCode3;
86  sal_uInt16 nKeyCode4;
87  ImplGetKeyCode( static_cast<KeyFuncType>(i), nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
88  if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
89  return static_cast<KeyFuncType>(i);
90  }
91  }
92 
93  return KeyFuncType::DONTKNOW;
94 }
95 
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nIndex
constexpr sal_uInt16 KEY_MOD1
Definition: keycodes.hxx:31
constexpr sal_uInt16 KEY_C
Definition: keycodes.hxx:58
constexpr sal_uInt16 KEY_V
Definition: keycodes.hxx:77
constexpr sal_uInt16 KEY_X
Definition: keycodes.hxx:79
KeyFuncType eFunc
Definition: keycod.hxx:40
KeyFuncType
Definition: keycod.hxx:29
constexpr sal_uInt16 KEY_Y
Definition: keycodes.hxx:80
sal_uInt16 nKeyCodeAndModifiers
Definition: keycod.hxx:39
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
constexpr sal_uInt16 KEY_UNDO
Definition: keycodes.hxx:141
constexpr sal_uInt16 KEY_CUT
Definition: keycodes.hxx:138
#define SAL_N_ELEMENTS(arr)
int i
OUString GetName(vcl::Window *pWindow=nullptr) const
Definition: keycod.cxx:66
constexpr sal_uInt16 KEY_COPY
Definition: keycodes.hxx:139
constexpr sal_uInt16 KEY_MOD2
Definition: keycodes.hxx:32
KeyFuncType GetFunction() const
Definition: keycod.cxx:73
bool ImplGetKeyCode(KeyFuncType eFunc, sal_uInt16 &rCode1, sal_uInt16 &rCode2, sal_uInt16 &rCode3, sal_uInt16 &rCode4)
Definition: keycod.cxx:40
SalFrame * ImplGetFrame() const
Definition: window2.cxx:848
constexpr sal_uInt16 KEY_BACKSPACE
Definition: keycodes.hxx:122
constexpr sal_uInt16 KEY_Z
Definition: keycodes.hxx:81
constexpr sal_uInt16 KEY_PASTE
Definition: keycodes.hxx:140
constexpr sal_uInt16 KEY_DELETE
Definition: keycodes.hxx:125
virtual OUString GetKeyName(sal_uInt16 nKeyCode)=0
constexpr sal_uInt16 KEY_INSERT
Definition: keycodes.hxx:124
constexpr sal_uInt16 KEY_SHIFT
Definition: keycodes.hxx:30
vcl::Window * ImplGetDefaultWindow()
Returns either the application window, or the default GL context window.
Definition: svdata.cxx:208
const sal_uInt16 aImplKeyFuncTab[(static_cast< int >(KeyFuncType::DELETE)+1)*4]
Definition: keycod.cxx:29