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