Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <xml/acceleratorconfigurationwriter.hxx>
30 : :
31 : : #include <acceleratorconst.h>
32 : : #include <threadhelp/readguard.hxx>
33 : :
34 : : #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
35 : : #include <com/sun/star/xml/sax/XAttributeList.hpp>
36 : : #include <com/sun/star/awt/KeyModifier.hpp>
37 : :
38 : : #include <vcl/svapp.hxx>
39 : : #include <rtl/ustrbuf.hxx>
40 : :
41 : : #include <comphelper/attributelist.hxx>
42 : :
43 : :
44 : : namespace framework{
45 : :
46 : :
47 : : //-----------------------------------------------
48 : 0 : AcceleratorConfigurationWriter::AcceleratorConfigurationWriter(const AcceleratorCache& rContainer,
49 : : const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
50 : 0 : : ThreadHelpBase(&Application::GetSolarMutex())
51 : : , m_xConfig (xConfig )
52 [ # # ]: 0 : , m_rContainer (rContainer )
53 : : {
54 : 0 : }
55 : :
56 : : //-----------------------------------------------
57 [ # # ]: 0 : AcceleratorConfigurationWriter::~AcceleratorConfigurationWriter()
58 : : {
59 [ # # ]: 0 : }
60 : :
61 : : //-----------------------------------------------
62 : 0 : void AcceleratorConfigurationWriter::flush()
63 : : {
64 : : // SAFE -> ----------------------------------
65 [ # # ]: 0 : ReadGuard aReadLock(m_aLock);
66 : :
67 : 0 : css::uno::Reference< css::xml::sax::XDocumentHandler > xCFG = m_xConfig;
68 [ # # ]: 0 : css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > xExtendedCFG(m_xConfig, css::uno::UNO_QUERY_THROW);
69 : :
70 [ # # ]: 0 : aReadLock.unlock();
71 : : // <- SAFE ----------------------------------
72 : :
73 : : // prepare attribute list
74 [ # # ]: 0 : ::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
75 [ # # ][ # # ]: 0 : css::uno::Reference< css::xml::sax::XAttributeList > xAttribs(static_cast< css::xml::sax::XAttributeList* >(pAttribs), css::uno::UNO_QUERY);
76 : :
77 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_XMLNS_ACCEL, ATTRIBUTE_TYPE_CDATA, NS_XMLNS_ACCEL);
[ # # ][ # # ]
78 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_XMLNS_XLINK, ATTRIBUTE_TYPE_CDATA, NS_XMLNS_XLINK);
[ # # ][ # # ]
79 : :
80 : : // generate xml
81 [ # # ][ # # ]: 0 : xCFG->startDocument();
82 : :
83 [ # # ][ # # ]: 0 : xExtendedCFG->unknown(DOCTYPE_ACCELERATORS);
[ # # ]
84 [ # # ][ # # ]: 0 : xCFG->ignorableWhitespace(::rtl::OUString());
85 : :
86 [ # # ][ # # ]: 0 : xCFG->startElement(AL_ELEMENT_ACCELERATORLIST, xAttribs);
[ # # ]
87 [ # # ][ # # ]: 0 : xCFG->ignorableWhitespace(::rtl::OUString());
88 : :
89 : : // TODO think about threadsafe using of cache
90 [ # # ]: 0 : AcceleratorCache::TKeyList lKeys = m_rContainer.getAllKeys();
91 : 0 : AcceleratorCache::TKeyList::const_iterator pKey ;
92 [ # # ][ # # ]: 0 : for ( pKey = lKeys.begin();
[ # # ]
93 : 0 : pKey != lKeys.end() ;
94 : : ++pKey )
95 : : {
96 : 0 : const css::awt::KeyEvent& rKey = *pKey;
97 [ # # ]: 0 : const ::rtl::OUString& rCommand = m_rContainer.getCommandByKey(rKey);
98 [ # # ]: 0 : impl_ts_writeKeyCommandPair(rKey, rCommand, xCFG);
99 : 0 : }
100 : :
101 : : /* TODO write key-command list
102 : : std::vector< SfxAcceleratorConfigItem>::const_iterator p;
103 : : for ( p = m_aWriteAcceleratorList.begin(); p != m_aWriteAcceleratorList.end(); p++ )
104 : : WriteAcceleratorItem( *p );
105 : : */
106 : :
107 [ # # ][ # # ]: 0 : xCFG->ignorableWhitespace(::rtl::OUString());
108 [ # # ][ # # ]: 0 : xCFG->endElement(AL_ELEMENT_ACCELERATORLIST);
[ # # ]
109 [ # # ][ # # ]: 0 : xCFG->ignorableWhitespace(::rtl::OUString());
110 [ # # ][ # # ]: 0 : xCFG->endDocument();
[ # # ]
111 : 0 : }
112 : :
113 : : //-----------------------------------------------
114 : 0 : void AcceleratorConfigurationWriter::impl_ts_writeKeyCommandPair(const css::awt::KeyEvent& aKey ,
115 : : const ::rtl::OUString& sCommand,
116 : : const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
117 : : {
118 [ # # ]: 0 : ::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
119 [ # # ][ # # ]: 0 : css::uno::Reference< css::xml::sax::XAttributeList > xAttribs (static_cast< css::xml::sax::XAttributeList* >(pAttribs) , css::uno::UNO_QUERY_THROW);
120 : :
121 [ # # ][ # # ]: 0 : ::rtl::OUString sKey = m_rKeyMapping->mapCodeToIdentifier(aKey.KeyCode);
122 : : // TODO check if key is empty!
123 : :
124 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_ATTRIBUTE_KEYCODE, ATTRIBUTE_TYPE_CDATA, sKey );
[ # # ]
125 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_ATTRIBUTE_URL , ATTRIBUTE_TYPE_CDATA, sCommand);
[ # # ]
126 : :
127 [ # # ]: 0 : if ((aKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT)
128 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_SHIFT, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
[ # # ]
129 : :
130 [ # # ]: 0 : if ((aKey.Modifiers & css::awt::KeyModifier::MOD1) == css::awt::KeyModifier::MOD1)
131 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD1, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
[ # # ]
132 : :
133 [ # # ]: 0 : if ((aKey.Modifiers & css::awt::KeyModifier::MOD2) == css::awt::KeyModifier::MOD2)
134 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD2, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
[ # # ]
135 : :
136 [ # # ]: 0 : if ((aKey.Modifiers & css::awt::KeyModifier::MOD3) == css::awt::KeyModifier::MOD3)
137 [ # # ][ # # ]: 0 : pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD3, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString("true"));
[ # # ]
138 : :
139 [ # # ][ # # ]: 0 : xConfig->ignorableWhitespace(::rtl::OUString());
140 [ # # ][ # # ]: 0 : xConfig->startElement(AL_ELEMENT_ITEM, xAttribs);
[ # # ]
141 [ # # ][ # # ]: 0 : xConfig->ignorableWhitespace(::rtl::OUString());
142 [ # # ][ # # ]: 0 : xConfig->endElement(AL_ELEMENT_ITEM);
[ # # ]
143 [ # # ][ # # ]: 0 : xConfig->ignorableWhitespace(::rtl::OUString());
144 : 0 : }
145 : :
146 : : } // namespace framework
147 : :
148 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|