Update git submodules
[LibreOffice.git] / framework / inc / xml / toolboxdocumenthandler.hxx
blob3e13b948a06372a6807c697407dbcefb9a282e9f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #pragma once
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>
33 namespace framework{
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
42 public:
43 enum ToolBox_XML_Entry
45 TB_ELEMENT_TOOLBAR,
46 TB_ELEMENT_TOOLBARITEM,
47 TB_ELEMENT_TOOLBARSPACE,
48 TB_ELEMENT_TOOLBARBREAK,
49 TB_ELEMENT_TOOLBARSEPARATOR,
50 TB_ATTRIBUTE_TEXT,
51 TB_ATTRIBUTE_URL,
52 TB_ATTRIBUTE_VISIBLE,
53 TB_ATTRIBUTE_STYLE,
54 TB_ATTRIBUTE_UINAME,
55 TB_XML_ENTRY_COUNT
58 enum ToolBox_XML_Namespace
60 TB_NS_TOOLBAR,
61 TB_NS_XLINK
64 OReadToolBoxDocumentHandler( const css::uno::Reference< css::container::XIndexContainer >& rItemContainer );
65 virtual ~OReadToolBoxDocumentHandler() override;
67 // XDocumentHandler
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;
88 private:
89 OUString getErrorLineString();
91 class ToolBoxHashMap : public std::unordered_map<OUString,
92 ToolBox_XML_Entry>
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;
105 OUString m_aType;
106 OUString m_aLabel;
107 OUString m_aStyle;
108 OUString m_aIsVisible;
109 OUString m_aCommandURL;
112 class OWriteToolBoxDocumentHandler final
114 public:
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();
124 private:
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: */