Update git submodules
[LibreOffice.git] / framework / inc / xml / menudocumenthandler.hxx
blob35db637184597b9e4b5bb9fa902c6e96662d3d01
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 <com/sun/star/xml/sax/XDocumentHandler.hpp>
23 #include <com/sun/star/container/XIndexContainer.hpp>
24 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
25 #include <com/sun/star/beans/PropertyValue.hpp>
26 #include <com/sun/star/uno/Sequence.h>
27 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <rtl/ustring.hxx>
30 #include <comphelper/attributelist.hxx>
31 #include <cppuhelper/implbase.hxx>
33 namespace framework{
35 class ReadMenuDocumentHandlerBase : public ::cppu::WeakImplHelper< css::xml::sax::XDocumentHandler >
37 public:
38 ReadMenuDocumentHandlerBase();
39 virtual ~ReadMenuDocumentHandlerBase() override;
41 // XDocumentHandler
42 virtual void SAL_CALL startDocument() override = 0;
44 virtual void SAL_CALL endDocument() override = 0;
46 virtual void SAL_CALL startElement(
47 const OUString& aName,
48 const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override = 0;
50 virtual void SAL_CALL endElement(const OUString& aName) override = 0;
52 virtual void SAL_CALL characters(const OUString& aChars) override = 0;
54 virtual void SAL_CALL ignorableWhitespace(const OUString& aWhitespaces) override;
56 virtual void SAL_CALL processingInstruction(const OUString& aTarget,
57 const OUString& aData) override;
59 virtual void SAL_CALL setDocumentLocator(
60 const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override;
62 protected:
63 OUString getErrorLineString();
65 css::uno::Reference< css::xml::sax::XLocator > m_xLocator;
66 css::uno::Reference< css::xml::sax::XDocumentHandler> m_xReader;
67 void initPropertyCommon( css::uno::Sequence< css::beans::PropertyValue > &rProps,
68 const OUString &rCommandURL, const OUString &rHelpId,
69 const OUString &rLabel, sal_Int16 nItemStyleBits );
70 private:
71 OUString m_aType;
72 OUString m_aLabel;
73 OUString m_aContainer;
74 OUString m_aHelpURL;
75 OUString m_aCommandURL;
76 OUString m_aStyle;
79 class OReadMenuDocumentHandler final : public ReadMenuDocumentHandlerBase
81 public:
82 OReadMenuDocumentHandler(
83 const css::uno::Reference< css::container::XIndexContainer >& rItemContainer );
84 virtual ~OReadMenuDocumentHandler() override;
86 // XDocumentHandler
87 virtual void SAL_CALL startDocument() override;
89 virtual void SAL_CALL endDocument() override;
91 virtual void SAL_CALL startElement(
92 const OUString& aName,
93 const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override;
95 virtual void SAL_CALL endElement(const OUString& aName) override;
97 virtual void SAL_CALL characters(const OUString& aChars) override;
99 private:
100 int m_nElementDepth;
101 enum class ReaderMode { None, MenuBar, MenuPopup };
102 ReaderMode m_eReaderMode;
103 css::uno::Reference< css::container::XIndexContainer > m_xMenuBarContainer;
104 css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory;
105 }; // OReadMenuDocumentHandler
107 class OReadMenuBarHandler final : public ReadMenuDocumentHandlerBase
109 public:
110 OReadMenuBarHandler(
111 const css::uno::Reference< css::container::XIndexContainer >& rMenuBarContainer,
112 const css::uno::Reference< css::lang::XSingleComponentFactory >& rContainerFactory );
113 virtual ~OReadMenuBarHandler() override;
115 // XDocumentHandler
116 virtual void SAL_CALL startDocument() override;
118 virtual void SAL_CALL endDocument() override;
120 virtual void SAL_CALL startElement(
121 const OUString& aName,
122 const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override;
124 virtual void SAL_CALL endElement(const OUString& aName) override;
126 virtual void SAL_CALL characters(const OUString& aChars) override;
128 private:
129 int m_nElementDepth;
130 bool m_bMenuMode;
131 css::uno::Reference< css::container::XIndexContainer > m_xMenuBarContainer;
132 css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory;
133 }; // OReadMenuBarHandler
135 class OReadMenuHandler final : public ReadMenuDocumentHandlerBase
137 public:
138 OReadMenuHandler( const css::uno::Reference< css::container::XIndexContainer >& rMenuContainer,
139 const css::uno::Reference< css::lang::XSingleComponentFactory >& rContainerFactory );
140 virtual ~OReadMenuHandler() override;
142 // XDocumentHandler
143 virtual void SAL_CALL startDocument() override;
145 virtual void SAL_CALL endDocument() override;
147 virtual void SAL_CALL startElement(
148 const OUString& aName,
149 const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override;
151 virtual void SAL_CALL endElement(const OUString& aName) override;
153 virtual void SAL_CALL characters(const OUString& aChars) override;
155 private:
156 int m_nElementDepth;
157 bool m_bMenuPopupMode;
158 css::uno::Reference< css::container::XIndexContainer > m_xMenuContainer;
159 css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory;
160 }; // OReadMenuHandler
162 class OReadMenuPopupHandler final : public ReadMenuDocumentHandlerBase
164 public:
165 OReadMenuPopupHandler( const css::uno::Reference< css::container::XIndexContainer >& rMenuContainer,
166 const css::uno::Reference< css::lang::XSingleComponentFactory >& rContainerFactory );
167 virtual ~OReadMenuPopupHandler() override;
169 // XDocumentHandler
170 virtual void SAL_CALL startDocument() override;
172 virtual void SAL_CALL endDocument() override;
174 virtual void SAL_CALL startElement(
175 const OUString& aName,
176 const css::uno::Reference<
177 css::xml::sax::XAttributeList > &xAttribs) override;
179 virtual void SAL_CALL endElement(const OUString& aName) override;
181 virtual void SAL_CALL characters(const OUString& aChars) override;
183 private:
184 enum NextElementClose { ELEM_CLOSE_NONE, ELEM_CLOSE_MENUITEM, ELEM_CLOSE_MENUSEPARATOR };
186 int m_nElementDepth;
187 bool m_bMenuMode;
188 css::uno::Reference< css::container::XIndexContainer > m_xMenuContainer;
189 css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory;
190 css::uno::Reference< css::uno::XComponentContext > m_xComponentContext;
191 NextElementClose m_nNextElementExpected;
192 }; // OReadMenuPopupHandler
194 class OWriteMenuDocumentHandler final
196 public:
197 OWriteMenuDocumentHandler(
198 const css::uno::Reference< css::container::XIndexAccess >& rMenuBarContainer,
199 const css::uno::Reference< css::xml::sax::XDocumentHandler >& rDocumentHandler,
200 bool bIsMenuBar );
201 ~OWriteMenuDocumentHandler();
203 /// @throws css::xml::sax::SAXException
204 /// @throws css::uno::RuntimeException
205 void WriteMenuDocument();
206 private:
207 /// @throws css::xml::sax::SAXException
208 /// @throws css::uno::RuntimeException
209 void WriteMenu( const css::uno::Reference< css::container::XIndexAccess >& rSubMenuContainer );
211 void WriteMenuItem( const OUString& aCommandURL, const OUString& aLabel, const OUString& aHelpURL, sal_Int16 nStyle );
212 void WriteMenuSeparator();
214 css::uno::Reference< css::container::XIndexAccess > m_xMenuBarContainer;
215 css::uno::Reference< css::xml::sax::XDocumentHandler > m_xWriteDocumentHandler;
216 rtl::Reference< ::comphelper::AttributeList > m_xEmptyList;
217 bool m_bIsMenuBar;
220 } // namespace framework
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */