Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/framework/source/xml/acceleratorconfigurationwriter.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 <accelerators/keymapping.hxx>
23
#include <utility>
24
#include <xml/acceleratorconfigurationwriter.hxx>
25
26
#include <acceleratorconst.h>
27
28
#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
29
#include <com/sun/star/awt/KeyModifier.hpp>
30
31
#include <comphelper/attributelist.hxx>
32
#include <rtl/ref.hxx>
33
34
namespace framework{
35
36
AcceleratorConfigurationWriter::AcceleratorConfigurationWriter(const AcceleratorCache&                                       rContainer,
37
                                                               css::uno::Reference< css::xml::sax::XDocumentHandler >  xConfig   )
38
0
    : m_xConfig     (std::move(xConfig                      ))
39
0
    , m_rContainer  (rContainer                   )
40
0
{
41
0
}
42
43
AcceleratorConfigurationWriter::~AcceleratorConfigurationWriter()
44
0
{
45
0
}
46
47
void AcceleratorConfigurationWriter::flush()
48
0
{
49
0
    css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > xExtendedCFG(m_xConfig, css::uno::UNO_QUERY_THROW);
50
51
    // prepare attribute list
52
0
    rtl::Reference<::comphelper::AttributeList> pAttribs = new ::comphelper::AttributeList;
53
54
0
    pAttribs->AddAttribute(
55
0
        u"xmlns:accel"_ustr,
56
0
        u"http://openoffice.org/2001/accel"_ustr);
57
0
    pAttribs->AddAttribute(
58
0
        u"xmlns:xlink"_ustr, u"http://www.w3.org/1999/xlink"_ustr);
59
60
    // generate xml
61
0
    xExtendedCFG->startDocument();
62
63
0
    xExtendedCFG->unknown(
64
0
        u"<!DOCTYPE accel:acceleratorlist PUBLIC \"-//OpenOffice.org//DTD"
65
0
        " OfficeDocument 1.0//EN\" \"accelerator.dtd\">"_ustr);
66
0
    xExtendedCFG->ignorableWhitespace(OUString());
67
68
0
    xExtendedCFG->startElement(AL_ELEMENT_ACCELERATORLIST, pAttribs);
69
0
    xExtendedCFG->ignorableWhitespace(OUString());
70
71
    // TODO think about threadsafe using of cache
72
0
    AcceleratorCache::TKeyList                 lKeys = m_rContainer.getAllKeys();
73
0
    for (auto const& lKey : lKeys)
74
0
    {
75
0
        const OUString aCommand = m_rContainer.getCommandByKey(lKey);
76
0
        impl_ts_writeKeyCommandPair(lKey, aCommand, xExtendedCFG);
77
0
    }
78
79
    /* TODO write key-command list
80
    for (auto const& writeAccelerator : m_aWriteAcceleratorList)
81
        WriteAcceleratorItem(writeAccelerator);
82
    */
83
84
0
    xExtendedCFG->ignorableWhitespace(OUString());
85
0
    xExtendedCFG->endElement(AL_ELEMENT_ACCELERATORLIST);
86
0
    xExtendedCFG->ignorableWhitespace(OUString());
87
0
    xExtendedCFG->endDocument();
88
0
}
89
90
// static
91
void AcceleratorConfigurationWriter::impl_ts_writeKeyCommandPair(const css::awt::KeyEvent&                                     aKey    ,
92
                                                                 const OUString&                                        sCommand,
93
                                                                 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
94
0
{
95
0
    rtl::Reference<::comphelper::AttributeList> pAttribs = new ::comphelper::AttributeList;
96
97
0
    OUString sKey = KeyMapping::get().mapCodeToIdentifier(aKey.KeyCode);
98
    // TODO check if key is empty!
99
100
0
    pAttribs->AddAttribute(u"accel:code"_ustr, sKey    );
101
0
    pAttribs->AddAttribute(u"xlink:href"_ustr, sCommand);
102
103
0
    if ((aKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT)
104
0
        pAttribs->AddAttribute(u"accel:shift"_ustr, u"true"_ustr);
105
106
0
    if ((aKey.Modifiers & css::awt::KeyModifier::MOD1) == css::awt::KeyModifier::MOD1)
107
0
        pAttribs->AddAttribute(u"accel:mod1"_ustr, u"true"_ustr);
108
109
0
    if ((aKey.Modifiers & css::awt::KeyModifier::MOD2) == css::awt::KeyModifier::MOD2)
110
0
        pAttribs->AddAttribute(u"accel:mod2"_ustr, u"true"_ustr);
111
112
0
    if ((aKey.Modifiers & css::awt::KeyModifier::MOD3) == css::awt::KeyModifier::MOD3)
113
0
        pAttribs->AddAttribute(u"accel:mod3"_ustr, u"true"_ustr);
114
115
0
    xConfig->ignorableWhitespace(OUString());
116
0
    xConfig->startElement(AL_ELEMENT_ITEM, pAttribs);
117
0
    xConfig->ignorableWhitespace(OUString());
118
0
    xConfig->endElement(AL_ELEMENT_ITEM);
119
0
    xConfig->ignorableWhitespace(OUString());
120
0
}
121
122
} // namespace framework
123
124
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */