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