LibreOffice Module framework (master) 1
acceleratorconfigurationwriter.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
23#include <utility>
25
26#include <acceleratorconst.h>
27
28#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
29#include <com/sun/star/awt/KeyModifier.hpp>
30
32#include <rtl/ref.hxx>
33
34namespace framework{
35
37 css::uno::Reference< css::xml::sax::XDocumentHandler > xConfig )
38 : m_xConfig (std::move(xConfig ))
39 , m_rContainer (rContainer )
40{
41}
42
44{
45}
46
48{
49 css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > xExtendedCFG(m_xConfig, css::uno::UNO_QUERY_THROW);
50
51 // prepare attribute list
52 rtl::Reference<::comphelper::AttributeList> pAttribs = new ::comphelper::AttributeList;
53
54 pAttribs->AddAttribute(
55 "xmlns:accel",
56 "http://openoffice.org/2001/accel");
57 pAttribs->AddAttribute(
58 "xmlns:xlink", "http://www.w3.org/1999/xlink");
59
60 // generate xml
61 xExtendedCFG->startDocument();
62
63 xExtendedCFG->unknown(
64 "<!DOCTYPE accel:acceleratorlist PUBLIC \"-//OpenOffice.org//DTD"
65 " OfficeDocument 1.0//EN\" \"accelerator.dtd\">");
66 xExtendedCFG->ignorableWhitespace(OUString());
67
68 xExtendedCFG->startElement(AL_ELEMENT_ACCELERATORLIST, pAttribs);
69 xExtendedCFG->ignorableWhitespace(OUString());
70
71 // TODO think about threadsafe using of cache
73 for (auto const& lKey : lKeys)
74 {
75 const OUString& rCommand = m_rContainer.getCommandByKey(lKey);
76 impl_ts_writeKeyCommandPair(lKey, rCommand, xExtendedCFG);
77 }
78
79 /* TODO write key-command list
80 for (auto const& writeAccelerator : m_aWriteAcceleratorList)
81 WriteAcceleratorItem(writeAccelerator);
82 */
83
84 xExtendedCFG->ignorableWhitespace(OUString());
85 xExtendedCFG->endElement(AL_ELEMENT_ACCELERATORLIST);
86 xExtendedCFG->ignorableWhitespace(OUString());
87 xExtendedCFG->endDocument();
88}
89
91 const OUString& sCommand,
92 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
93{
94 rtl::Reference<::comphelper::AttributeList> pAttribs = new ::comphelper::AttributeList;
95
96 OUString sKey = KeyMapping::get().mapCodeToIdentifier(aKey.KeyCode);
97 // TODO check if key is empty!
98
99 pAttribs->AddAttribute("accel:code", sKey );
100 pAttribs->AddAttribute("xlink:href", sCommand);
101
102 if ((aKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT)
103 pAttribs->AddAttribute("accel:shift", "true");
104
105 if ((aKey.Modifiers & css::awt::KeyModifier::MOD1) == css::awt::KeyModifier::MOD1)
106 pAttribs->AddAttribute("accel:mod1", "true");
107
108 if ((aKey.Modifiers & css::awt::KeyModifier::MOD2) == css::awt::KeyModifier::MOD2)
109 pAttribs->AddAttribute("accel:mod2", "true");
110
111 if ((aKey.Modifiers & css::awt::KeyModifier::MOD3) == css::awt::KeyModifier::MOD3)
112 pAttribs->AddAttribute("accel:mod3", "true");
113
114 xConfig->ignorableWhitespace(OUString());
115 xConfig->startElement(AL_ELEMENT_ITEM, pAttribs);
116 xConfig->ignorableWhitespace(OUString());
117 xConfig->endElement(AL_ELEMENT_ITEM);
118 xConfig->ignorableWhitespace(OUString());
119}
120
121} // namespace framework
122
123/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
implements a cache for any accelerator configuration.
::std::vector< css::awt::KeyEvent > TKeyList
commands -> keys
OUString getCommandByKey(const css::awt::KeyEvent &aKey) const
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xConfig
needed to write the xml configuration.
AcceleratorConfigurationWriter(const AcceleratorCache &rContainer, css::uno::Reference< css::xml::sax::XDocumentHandler > xConfig)
connect this new writer instance to an outside container, which should be flushed to the underlying X...
void impl_ts_writeKeyCommandPair(const css::awt::KeyEvent &aKey, const OUString &sCommand, const css::uno::Reference< css::xml::sax::XDocumentHandler > &xConfig)
TODO.
const AcceleratorCache & m_rContainer
reference to the outside container, where this writer must work on.
OUString mapCodeToIdentifier(sal_uInt16 nCode)
return a suitable key identifier for the specified key code.
Definition: keymapping.cxx:182
static KeyMapping & get()
Definition: keymapping.cxx:159
constexpr OUStringLiteral AL_ELEMENT_ITEM
constexpr OUStringLiteral AL_ELEMENT_ACCELERATORLIST