update dev300-m58
[ooovba.git] / framework / source / xml / acceleratorconfigurationwriter.cxx
blob6954314a54a185b2fd9f4ad1a486fcddaaa54e41
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acceleratorconfigurationwriter.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
33 #include <xml/acceleratorconfigurationwriter.hxx>
35 //_______________________________________________
36 // own includes
37 #include <acceleratorconst.h>
38 #include <threadhelp/readguard.hxx>
40 //_______________________________________________
41 // interface includes
42 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
43 #include <com/sun/star/xml/sax/XAttributeList.hpp>
44 #include <com/sun/star/awt/KeyModifier.hpp>
46 //_______________________________________________
47 // other includes
48 #include <vcl/svapp.hxx>
49 #include <rtl/ustrbuf.hxx>
51 #include <comphelper/attributelist.hxx>
54 //_______________________________________________
55 // namespace
57 namespace framework{
60 //-----------------------------------------------
61 AcceleratorConfigurationWriter::AcceleratorConfigurationWriter(const AcceleratorCache& rContainer,
62 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
63 : ThreadHelpBase(&Application::GetSolarMutex())
64 , m_xConfig (xConfig )
65 , m_rContainer (rContainer )
69 //-----------------------------------------------
70 AcceleratorConfigurationWriter::~AcceleratorConfigurationWriter()
74 //-----------------------------------------------
75 void AcceleratorConfigurationWriter::flush()
77 // SAFE -> ----------------------------------
78 ReadGuard aReadLock(m_aLock);
80 css::uno::Reference< css::xml::sax::XDocumentHandler > xCFG = m_xConfig;
81 css::uno::Reference< css::xml::sax::XExtendedDocumentHandler > xExtendedCFG(m_xConfig, css::uno::UNO_QUERY_THROW);
83 aReadLock.unlock();
84 // <- SAFE ----------------------------------
86 // prepare attribute list
87 ::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
88 css::uno::Reference< css::xml::sax::XAttributeList > xAttribs(static_cast< css::xml::sax::XAttributeList* >(pAttribs), css::uno::UNO_QUERY);
90 pAttribs->AddAttribute(AL_XMLNS_ACCEL, ATTRIBUTE_TYPE_CDATA, NS_XMLNS_ACCEL);
91 pAttribs->AddAttribute(AL_XMLNS_XLINK, ATTRIBUTE_TYPE_CDATA, NS_XMLNS_XLINK);
93 // generate xml
94 xCFG->startDocument();
96 xExtendedCFG->unknown(DOCTYPE_ACCELERATORS);
97 xCFG->ignorableWhitespace(::rtl::OUString());
99 xCFG->startElement(AL_ELEMENT_ACCELERATORLIST, xAttribs);
100 xCFG->ignorableWhitespace(::rtl::OUString());
102 // TODO think about threadsafe using of cache
103 AcceleratorCache::TKeyList lKeys = m_rContainer.getAllKeys();
104 AcceleratorCache::TKeyList::const_iterator pKey ;
105 for ( pKey = lKeys.begin();
106 pKey != lKeys.end() ;
107 ++pKey )
109 const css::awt::KeyEvent& rKey = *pKey;
110 const ::rtl::OUString& rCommand = m_rContainer.getCommandByKey(rKey);
111 impl_ts_writeKeyCommandPair(rKey, rCommand, xCFG);
114 /* TODO write key-command list
115 std::vector< SfxAcceleratorConfigItem>::const_iterator p;
116 for ( p = m_aWriteAcceleratorList.begin(); p != m_aWriteAcceleratorList.end(); p++ )
117 WriteAcceleratorItem( *p );
120 xCFG->ignorableWhitespace(::rtl::OUString());
121 xCFG->endElement(AL_ELEMENT_ACCELERATORLIST);
122 xCFG->ignorableWhitespace(::rtl::OUString());
123 xCFG->endDocument();
126 //-----------------------------------------------
127 void AcceleratorConfigurationWriter::impl_ts_writeKeyCommandPair(const css::awt::KeyEvent& aKey ,
128 const ::rtl::OUString& sCommand,
129 const css::uno::Reference< css::xml::sax::XDocumentHandler >& xConfig )
131 ::comphelper::AttributeList* pAttribs = new ::comphelper::AttributeList;
132 css::uno::Reference< css::xml::sax::XAttributeList > xAttribs (static_cast< css::xml::sax::XAttributeList* >(pAttribs) , css::uno::UNO_QUERY_THROW);
134 ::rtl::OUString sKey = m_rKeyMapping->mapCodeToIdentifier(aKey.KeyCode);
135 // TODO check if key is empty!
137 pAttribs->AddAttribute(AL_ATTRIBUTE_KEYCODE, ATTRIBUTE_TYPE_CDATA, sKey );
138 pAttribs->AddAttribute(AL_ATTRIBUTE_URL , ATTRIBUTE_TYPE_CDATA, sCommand);
140 if ((aKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT)
141 pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_SHIFT, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString::createFromAscii("true"));
143 if ((aKey.Modifiers & css::awt::KeyModifier::MOD1) == css::awt::KeyModifier::MOD1)
144 pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD1, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString::createFromAscii("true"));
146 if ((aKey.Modifiers & css::awt::KeyModifier::MOD2) == css::awt::KeyModifier::MOD2)
147 pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD2, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString::createFromAscii("true"));
149 if ((aKey.Modifiers & css::awt::KeyModifier::MOD3) == css::awt::KeyModifier::MOD3)
150 pAttribs->AddAttribute(AL_ATTRIBUTE_MOD_MOD3, ATTRIBUTE_TYPE_CDATA, ::rtl::OUString::createFromAscii("true"));
152 xConfig->ignorableWhitespace(::rtl::OUString());
153 xConfig->startElement(AL_ELEMENT_ITEM, xAttribs);
154 xConfig->ignorableWhitespace(::rtl::OUString());
155 xConfig->endElement(AL_ELEMENT_ITEM);
156 xConfig->ignorableWhitespace(::rtl::OUString());
159 } // namespace framework