1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: acceleratorconfigurationwriter.cxx,v $
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 //_______________________________________________
37 #include <acceleratorconst.h>
38 #include <threadhelp/readguard.hxx>
40 //_______________________________________________
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 //_______________________________________________
48 #include <vcl/svapp.hxx>
49 #include <rtl/ustrbuf.hxx>
51 #include <comphelper/attributelist.hxx>
54 //_______________________________________________
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
);
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
);
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() ;
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());
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