1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <toolboxconfiguration.hxx>
24 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
26 #include <rtl/ustring.hxx>
27 #include <rtl/ref.hxx>
28 #include <comphelper/attributelist.hxx>
29 #include <cppuhelper/implbase.hxx>
31 #include <unordered_map>
35 // Hash code function for using in all hash maps of follow implementation.
37 // workaround for incremental linking bugs in MSVC2015
38 class SAL_DLLPUBLIC_TEMPLATE OReadToolBoxDocumentHandler_Base
: public cppu::WeakImplHelper
< css::xml::sax::XDocumentHandler
> {};
40 class OReadToolBoxDocumentHandler final
: public OReadToolBoxDocumentHandler_Base
43 enum ToolBox_XML_Entry
46 TB_ELEMENT_TOOLBARITEM
,
47 TB_ELEMENT_TOOLBARSPACE
,
48 TB_ELEMENT_TOOLBARBREAK
,
49 TB_ELEMENT_TOOLBARSEPARATOR
,
58 enum ToolBox_XML_Namespace
64 OReadToolBoxDocumentHandler( const css::uno::Reference
< css::container::XIndexContainer
>& rItemContainer
);
65 virtual ~OReadToolBoxDocumentHandler() override
;
68 virtual void SAL_CALL
startDocument() override
;
70 virtual void SAL_CALL
endDocument() override
;
72 virtual void SAL_CALL
startElement(
73 const OUString
& aName
,
74 const css::uno::Reference
< css::xml::sax::XAttributeList
> &xAttribs
) override
;
76 virtual void SAL_CALL
endElement(const OUString
& aName
) override
;
78 virtual void SAL_CALL
characters(const OUString
& aChars
) override
;
80 virtual void SAL_CALL
ignorableWhitespace(const OUString
& aWhitespaces
) override
;
82 virtual void SAL_CALL
processingInstruction(const OUString
& aTarget
,
83 const OUString
& aData
) override
;
85 virtual void SAL_CALL
setDocumentLocator(
86 const css::uno::Reference
< css::xml::sax::XLocator
> &xLocator
) override
;
89 OUString
getErrorLineString();
91 class ToolBoxHashMap
: public std::unordered_map
<OUString
,
96 bool m_bToolBarStartFound
: 1;
97 bool m_bToolBarItemStartFound
: 1;
98 bool m_bToolBarSpaceStartFound
: 1;
99 bool m_bToolBarBreakStartFound
: 1;
100 bool m_bToolBarSeparatorStartFound
: 1;
101 ToolBoxHashMap m_aToolBoxMap
;
102 css::uno::Reference
< css::container::XIndexContainer
> m_rItemContainer
;
103 css::uno::Reference
< css::xml::sax::XLocator
> m_xLocator
;
108 OUString m_aIsVisible
;
109 OUString m_aCommandURL
;
112 class OWriteToolBoxDocumentHandler final
115 OWriteToolBoxDocumentHandler(
116 const css::uno::Reference
< css::container::XIndexAccess
>& rItemAccess
,
117 css::uno::Reference
< css::xml::sax::XDocumentHandler
> const & rDocumentHandler
);
118 ~OWriteToolBoxDocumentHandler();
120 /// @throws css::xml::sax::SAXException
121 /// @throws css::uno::RuntimeException
122 void WriteToolBoxDocument();
125 /// @throws css::xml::sax::SAXException
126 /// @throws css::uno::RuntimeException
127 void WriteToolBoxItem( const OUString
& aCommandURL
, const OUString
& aLabel
, sal_Int16 nStyle
, bool bVisible
);
129 /// @throws css::xml::sax::SAXException
130 /// @throws css::uno::RuntimeException
131 void WriteToolBoxSpace();
133 /// @throws css::xml::sax::SAXException
134 /// @throws css::uno::RuntimeException
135 void WriteToolBoxBreak();
137 /// @throws css::xml::sax::SAXException
138 /// @throws css::uno::RuntimeException
139 void WriteToolBoxSeparator();
141 css::uno::Reference
< css::xml::sax::XDocumentHandler
> m_xWriteDocumentHandler
;
142 rtl::Reference
< ::comphelper::AttributeList
> m_xEmptyList
;
143 css::uno::Reference
< css::container::XIndexAccess
> m_rItemAccess
;
144 OUString m_aXMLToolbarNS
;
145 OUString m_aXMLXlinkNS
;
146 OUString m_aAttributeURL
;
149 } // namespace framework
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */