Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/window/keycod.cxx
Line
Count
Source
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.hxx>
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
0
{
42
0
    size_t nIndex = static_cast<size_t>(eFunc);
43
0
    nIndex *= 4;
44
45
0
    assert(nIndex + 3 < SAL_N_ELEMENTS(aImplKeyFuncTab) && "bad key code index");
46
0
    if (nIndex + 3  >= SAL_N_ELEMENTS(aImplKeyFuncTab))
47
0
    {
48
0
        rCode1 = rCode2 = rCode3 = rCode4 = 0;
49
0
        return false;
50
0
    }
51
52
0
    rCode1 = aImplKeyFuncTab[nIndex];
53
0
    rCode2 = aImplKeyFuncTab[nIndex+1];
54
0
    rCode3 = aImplKeyFuncTab[nIndex+2];
55
0
    rCode4 = aImplKeyFuncTab[nIndex+3];
56
0
    return true;
57
0
}
58
59
vcl::KeyCode::KeyCode( KeyFuncType eFunction )
60
0
{
61
0
    sal_uInt16 nDummy;
62
0
    ImplGetKeyCode( eFunction, nKeyCodeAndModifiers, nDummy, nDummy, nDummy );
63
0
    eFunc = eFunction;
64
0
}
65
66
OUString vcl::KeyCode::GetName() const
67
0
{
68
0
    vcl::Window* pWindow = ImplGetDefaultWindow();
69
0
    return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : u""_ustr;
70
0
}
71
72
KeyFuncType vcl::KeyCode::GetFunction() const
73
0
{
74
0
    if ( eFunc != KeyFuncType::DONTKNOW )
75
0
        return eFunc;
76
77
0
    sal_uInt16 nCompCode = GetModifier() | GetCode();
78
0
    if ( nCompCode )
79
0
    {
80
0
        for ( sal_uInt16 i = sal_uInt16(KeyFuncType::CUT); i <= sal_uInt16(KeyFuncType::DELETE); i++ )
81
0
        {
82
0
            sal_uInt16 nKeyCode1;
83
0
            sal_uInt16 nKeyCode2;
84
0
            sal_uInt16 nKeyCode3;
85
0
            sal_uInt16 nKeyCode4;
86
0
            ImplGetKeyCode( static_cast<KeyFuncType>(i), nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
87
0
            if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
88
0
                return static_cast<KeyFuncType>(i);
89
0
        }
90
0
    }
91
92
0
    return KeyFuncType::DONTKNOW;
93
0
}
94
95
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */