xref: /AOO41X/main/framework/inc/xml/menudocumenthandler.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_XML_MENUDOCUMENTHANDLER_HXX_
29 #define __FRAMEWORK_XML_MENUDOCUMENTHANDLER_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	interface includes
33 //_________________________________________________________________________________________________________________
34 
35 #ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
36 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
37 #endif
38 #include <com/sun/star/container/XIndexContainer.hpp>
39 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/uno/Sequence.h>
42 #include <com/sun/star/uno/XComponentContext.hpp>
43 
44 //_________________________________________________________________________________________________________________
45 //	other includes
46 //_________________________________________________________________________________________________________________
47 #include <threadhelp/threadhelpbase.hxx>
48 #include <rtl/ustring.hxx>
49 #include <cppuhelper/implbase1.hxx>
50 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
51 #include <framework/fwedllapi.h>
52 
53 //_________________________________________________________________________________________________________________
54 //	namespace
55 //_________________________________________________________________________________________________________________
56 
57 namespace framework{
58 
59 class FWE_DLLPUBLIC ReadMenuDocumentHandlerBase : public ThreadHelpBase,	// Struct for right initalization of mutex member! Must be first of baseclasses.
60 									public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
61 {
62 	public:
63 		ReadMenuDocumentHandlerBase();
64 		virtual ~ReadMenuDocumentHandlerBase();
65 
66 		// XDocumentHandler
67 		virtual void SAL_CALL startDocument(void)
68 		throw (	::com::sun::star::xml::sax::SAXException,
69 				::com::sun::star::uno::RuntimeException ) = 0;
70 
71 		virtual void SAL_CALL endDocument(void)
72 		throw(	::com::sun::star::xml::sax::SAXException,
73 				::com::sun::star::uno::RuntimeException ) = 0;
74 
75 		virtual void SAL_CALL startElement(
76 			const rtl::OUString& aName,
77 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
78 		throw(	::com::sun::star::xml::sax::SAXException,
79 				::com::sun::star::uno::RuntimeException ) = 0;
80 
81 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
82 		throw(	::com::sun::star::xml::sax::SAXException,
83 				::com::sun::star::uno::RuntimeException ) = 0;
84 
85 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
86 		throw(	::com::sun::star::xml::sax::SAXException,
87 				::com::sun::star::uno::RuntimeException ) = 0;
88 
89 		virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces)
90 		throw(	::com::sun::star::xml::sax::SAXException,
91 				::com::sun::star::uno::RuntimeException );
92 
93 		virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget,
94 													const rtl::OUString& aData)
95 		throw(	::com::sun::star::xml::sax::SAXException,
96 				::com::sun::star::uno::RuntimeException );
97 
98 		virtual void SAL_CALL setDocumentLocator(
99 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator)
100 		throw(	::com::sun::star::xml::sax::SAXException,
101 				::com::sun::star::uno::RuntimeException );
102 
103 	protected:
104 		::rtl::OUString getErrorLineString();
105 
106 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator;
107 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler> m_xReader;
108 		void initPropertyCommon( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &rProps,
109 								 const rtl::OUString &rCommandURL, const rtl::OUString &rHelpId,
110                                  const rtl::OUString &rLabel, sal_Int16 nItemStyleBits );
111 	private:
112 		rtl::OUString m_aType;
113 		rtl::OUString m_aLabel;
114 		rtl::OUString m_aContainer;
115 		rtl::OUString m_aHelpURL;
116 		rtl::OUString m_aCommandURL;
117         rtl::OUString m_aStyle;
118 		::com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > m_aItemProp;
119 };
120 
121 
122 class FWE_DLLPUBLIC OReadMenuDocumentHandler : public ReadMenuDocumentHandlerBase
123 {
124 	public:
125 		// #110897#
126         OReadMenuDocumentHandler(
127 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
128 			const com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer >& rItemContainer );
129 		virtual ~OReadMenuDocumentHandler();
130 
131 		// #110897#
132 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
133 
134 		// XDocumentHandler
135 		virtual void SAL_CALL startDocument(void)
136 		throw (	::com::sun::star::xml::sax::SAXException,
137 				::com::sun::star::uno::RuntimeException );
138 
139 		virtual void SAL_CALL endDocument(void)
140 		throw(	::com::sun::star::xml::sax::SAXException,
141 				::com::sun::star::uno::RuntimeException );
142 
143 		virtual void SAL_CALL startElement(
144 			const rtl::OUString& aName,
145 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
146 		throw(	::com::sun::star::xml::sax::SAXException,
147 				::com::sun::star::uno::RuntimeException );
148 
149 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
150 		throw(	::com::sun::star::xml::sax::SAXException,
151 				::com::sun::star::uno::RuntimeException );
152 
153 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
154 		throw(	::com::sun::star::xml::sax::SAXException,
155 				::com::sun::star::uno::RuntimeException );
156 
157 	private:
158           int		m_nElementDepth;
159           sal_Bool	m_bMenuBarMode;
160           com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuBarContainer;
161           com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
162           const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& mxServiceFactory;
163 };	// OReadMenuDocumentHandler
164 
165 
166 class FWE_DLLPUBLIC OReadMenuBarHandler : public ReadMenuDocumentHandlerBase
167 {
168 	public:
169 		// #110897#
170 		OReadMenuBarHandler(
171 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
172 			const com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rMenuBarContainer,
173             const com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >& rContainerFactory );
174 		virtual ~OReadMenuBarHandler();
175 
176 		// #110897#
177 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
178 
179 		// XDocumentHandler
180 		virtual void SAL_CALL startDocument(void)
181 		throw (	::com::sun::star::xml::sax::SAXException,
182 				::com::sun::star::uno::RuntimeException );
183 
184 		virtual void SAL_CALL endDocument(void)
185 		throw(	::com::sun::star::xml::sax::SAXException,
186 				::com::sun::star::uno::RuntimeException );
187 
188 		virtual void SAL_CALL startElement(
189 			const rtl::OUString& aName,
190 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
191 		throw(	::com::sun::star::xml::sax::SAXException,
192 				::com::sun::star::uno::RuntimeException );
193 
194 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
195 		throw(	::com::sun::star::xml::sax::SAXException,
196 				::com::sun::star::uno::RuntimeException );
197 
198 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
199 		throw(	::com::sun::star::xml::sax::SAXException,
200 				::com::sun::star::uno::RuntimeException );
201 
202 	private:
203 		int			m_nElementDepth;
204 		sal_Bool	m_bMenuMode;
205         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuBarContainer;
206         com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
207 
208 		// #110897#
209 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& mxServiceFactory;
210 };	// OReadMenuBarHandler
211 
212 
213 class FWE_DLLPUBLIC OReadMenuHandler : public ReadMenuDocumentHandlerBase
214 {
215 	public:
216 		OReadMenuHandler( const com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rMenuContainer,
217                           const com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >& rContainerFactory );
218 		virtual ~OReadMenuHandler();
219 
220 		// XDocumentHandler
221 		virtual void SAL_CALL startDocument(void)
222 		throw (	::com::sun::star::xml::sax::SAXException,
223 				::com::sun::star::uno::RuntimeException );
224 
225 		virtual void SAL_CALL endDocument(void)
226 		throw(	::com::sun::star::xml::sax::SAXException,
227 				::com::sun::star::uno::RuntimeException );
228 
229 		virtual void SAL_CALL startElement(
230 			const rtl::OUString& aName,
231 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
232 		throw(	::com::sun::star::xml::sax::SAXException,
233 				::com::sun::star::uno::RuntimeException );
234 
235 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
236 		throw(	::com::sun::star::xml::sax::SAXException,
237 				::com::sun::star::uno::RuntimeException );
238 
239 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
240 		throw(	::com::sun::star::xml::sax::SAXException,
241 				::com::sun::star::uno::RuntimeException );
242 
243 	private:
244 		int					m_nElementDepth;
245 		sal_Bool			m_bMenuPopupMode;
246         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuContainer;
247         com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
248 }; // OReadMenuHandler
249 
250 
251 class FWE_DLLPUBLIC OReadMenuPopupHandler : public ReadMenuDocumentHandlerBase
252 {
253 	public:
254 		OReadMenuPopupHandler( const com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rMenuContainer,
255                                const com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >& rContainerFactory );
256 		virtual ~OReadMenuPopupHandler();
257 
258 		// XDocumentHandler
259 		virtual void SAL_CALL startDocument(void)
260 			throw (	::com::sun::star::xml::sax::SAXException,
261 					::com::sun::star::uno::RuntimeException );
262 
263 		virtual void SAL_CALL endDocument(void)
264 			throw (	::com::sun::star::xml::sax::SAXException,
265 					::com::sun::star::uno::RuntimeException );
266 
267 		virtual void SAL_CALL startElement(
268 			const rtl::OUString& aName,
269 			const ::com::sun::star::uno::Reference<
270 				::com::sun::star::xml::sax::XAttributeList > &xAttribs)
271 			throw (	::com::sun::star::xml::sax::SAXException,
272 					::com::sun::star::uno::RuntimeException );
273 
274 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
275 			throw (	::com::sun::star::xml::sax::SAXException,
276 					::com::sun::star::uno::RuntimeException );
277 
278 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
279 			throw (	::com::sun::star::xml::sax::SAXException,
280 					::com::sun::star::uno::RuntimeException );
281 
282 	private:
283 		enum NextElementClose { ELEM_CLOSE_NONE, ELEM_CLOSE_MENUITEM, ELEM_CLOSE_MENUSEPARATOR };
284 
285 		int					m_nElementDepth;
286 		sal_Bool			m_bMenuMode;
287         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuContainer;
288         com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
289         com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >     m_xComponentContext;
290 		NextElementClose	m_nNextElementExpected;
291 }; // OReadMenuPopupHandler
292 
293 
294 class FWE_DLLPUBLIC OWriteMenuDocumentHandler
295 {
296 	public:
297 		OWriteMenuDocumentHandler(
298             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rMenuBarContainer,
299 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& rDocumentHandler );
300 		virtual ~OWriteMenuDocumentHandler();
301 
302 		void WriteMenuDocument() throw
303 			( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
304 	protected:
305 		virtual void WriteMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rSubMenuContainer ) throw
306 			( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
307 
308         virtual void WriteMenuItem( const rtl::OUString& aCommandURL, const rtl::OUString& aLabel, const rtl::OUString& aHelpURL, sal_Int16 nStyle = 0 );
309 		virtual void WriteMenuSeparator();
310 
311         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xMenuBarContainer;
312 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xWriteDocumentHandler;
313 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xEmptyList;
314 		::rtl::OUString m_aAttributeType;
315 };
316 
317 } // namespace framework
318 
319 #endif	// #ifndef __FRAMEWORK_XML_MENUDOCUMENTHANDLER_HXX_
320