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 <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>
35 class ReadMenuDocumentHandlerBase
: public ::cppu::WeakImplHelper
< css::xml::sax::XDocumentHandler
>
38 ReadMenuDocumentHandlerBase();
39 virtual ~ReadMenuDocumentHandlerBase() override
;
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
;
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
);
73 OUString m_aContainer
;
75 OUString m_aCommandURL
;
79 class OReadMenuDocumentHandler final
: public ReadMenuDocumentHandlerBase
82 OReadMenuDocumentHandler(
83 const css::uno::Reference
< css::container::XIndexContainer
>& rItemContainer
);
84 virtual ~OReadMenuDocumentHandler() override
;
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
;
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
111 const css::uno::Reference
< css::container::XIndexContainer
>& rMenuBarContainer
,
112 const css::uno::Reference
< css::lang::XSingleComponentFactory
>& rContainerFactory
);
113 virtual ~OReadMenuBarHandler() override
;
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
;
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
138 OReadMenuHandler( const css::uno::Reference
< css::container::XIndexContainer
>& rMenuContainer
,
139 const css::uno::Reference
< css::lang::XSingleComponentFactory
>& rContainerFactory
);
140 virtual ~OReadMenuHandler() override
;
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
;
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
165 OReadMenuPopupHandler( const css::uno::Reference
< css::container::XIndexContainer
>& rMenuContainer
,
166 const css::uno::Reference
< css::lang::XSingleComponentFactory
>& rContainerFactory
);
167 virtual ~OReadMenuPopupHandler() override
;
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
;
184 enum NextElementClose
{ ELEM_CLOSE_NONE
, ELEM_CLOSE_MENUITEM
, ELEM_CLOSE_MENUSEPARATOR
};
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
197 OWriteMenuDocumentHandler(
198 const css::uno::Reference
< css::container::XIndexAccess
>& rMenuBarContainer
,
199 const css::uno::Reference
< css::xml::sax::XDocumentHandler
>& rDocumentHandler
,
201 ~OWriteMenuDocumentHandler();
203 /// @throws css::xml::sax::SAXException
204 /// @throws css::uno::RuntimeException
205 void WriteMenuDocument();
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
;
220 } // namespace framework
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */