xref: /AOO41X/main/framework/source/fwe/xml/menudocumenthandler.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir //	my own includes
35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36*cdf0e10cSrcweir #include <xml/menudocumenthandler.hxx>
37*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
38*cdf0e10cSrcweir #include <framework/addonmenu.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
41*cdf0e10cSrcweir //	interface includes
42*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/lang/XSingleComponentFactory.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/ui/ItemType.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/ui/ItemStyle.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52*cdf0e10cSrcweir //	other includes
53*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
54*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
55*cdf0e10cSrcweir #include <rtl/logfile.hxx>
56*cdf0e10cSrcweir #include <comphelper/attributelist.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
59*cdf0e10cSrcweir //	defines
60*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir #define XMLNS_MENU				    "http://openoffice.org/2001/menu"
63*cdf0e10cSrcweir #define XMLNS_PREFIX			    "menu:"
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #define ELEMENT_MENUBAR			    "http://openoffice.org/2001/menu^menubar"
66*cdf0e10cSrcweir #define ELEMENT_MENU			    "http://openoffice.org/2001/menu^menu"
67*cdf0e10cSrcweir #define ELEMENT_MENUPOPUP		    "http://openoffice.org/2001/menu^menupopup"
68*cdf0e10cSrcweir #define ELEMENT_MENUITEM		    "http://openoffice.org/2001/menu^menuitem"
69*cdf0e10cSrcweir #define ELEMENT_MENUSEPARATOR	    "http://openoffice.org/2001/menu^menuseparator"
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir #define ELEMENT_NS_MENUBAR			"menu:menubar"
72*cdf0e10cSrcweir #define ELEMENT_NS_MENU				"menu:menu"
73*cdf0e10cSrcweir #define ELEMENT_NS_MENUPOPUP		"menu:menupopup"
74*cdf0e10cSrcweir #define ELEMENT_NS_MENUITEM			"menu:menuitem"
75*cdf0e10cSrcweir #define ELEMENT_NS_MENUSEPARATOR	"menu:menuseparator"
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir #define ATTRIBUTE_ID			    "http://openoffice.org/2001/menu^id"
78*cdf0e10cSrcweir #define ATTRIBUTE_LABEL			    "http://openoffice.org/2001/menu^label"
79*cdf0e10cSrcweir #define ATTRIBUTE_HELPID		    "http://openoffice.org/2001/menu^helpid"
80*cdf0e10cSrcweir #define ATTRIBUTE_LINEBREAK		    "http://openoffice.org/2001/menu^linebreak"
81*cdf0e10cSrcweir #define ATTRIBUTE_STYLE		    "http://openoffice.org/2001/menu^style"
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir #define ATTRIBUTE_NS_ID			    "menu:id"
84*cdf0e10cSrcweir #define ATTRIBUTE_NS_LABEL		    "menu:label"
85*cdf0e10cSrcweir #define ATTRIBUTE_NS_HELPID		    "menu:helpid"
86*cdf0e10cSrcweir #define ATTRIBUTE_NS_LINEBREAK	    "menu:linebreak"
87*cdf0e10cSrcweir #define ATTRIBUTE_NS_STYLE		    "menu:style"
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir #define ATTRIBUTE_XMLNS_MENU	    "xmlns:menu"
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir #define ATTRIBUTE_TYPE_CDATA	    "CDATA"
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir #define MENUBAR_DOCTYPE			    "<!DOCTYPE menu:menubar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"menubar.dtd\">"
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir #define ATTRIBUTE_ITEMSTYLE_TEXT    "text"
96*cdf0e10cSrcweir #define ATTRIBUTE_ITEMSTYLE_IMAGE    "image"
97*cdf0e10cSrcweir #define ATTRIBUTE_ITEMSTYLE_RADIO    "radio"
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir // Property names of a menu/menu item ItemDescriptor
100*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_COMMANDURL[]  = "CommandURL";
101*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_HELPURL[]     = "HelpURL";
102*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_CONTAINER[]   = "ItemDescriptorContainer";
103*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_LABEL[]       = "Label";
104*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_TYPE[]        = "Type";
105*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_STYLE[]       = "Style";
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir // special popup menus (filled during runtime) must be saved as an empty popup menu or menuitem!!!
108*cdf0e10cSrcweir static const sal_Int32 CMD_PROTOCOL_SIZE        = 5;
109*cdf0e10cSrcweir static const char CMD_PROTOCOL[]                = ".uno:";
110*cdf0e10cSrcweir static const char ADDDIRECT_CMD[]               = ".uno:AddDirect" ;
111*cdf0e10cSrcweir static const char AUTOPILOTMENU_CMD[]           = ".uno:AutoPilotMenu" ;
112*cdf0e10cSrcweir static const char FILEMENU_CMD[]                = ".uno:Picklist" ;
113*cdf0e10cSrcweir static const char WINDOWMENU_CMD[]              = ".uno:WindowList" ;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
116*cdf0e10cSrcweir //	using namespaces
117*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
120*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
121*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
122*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax;
123*cdf0e10cSrcweir using namespace ::com::sun::star::container;
124*cdf0e10cSrcweir using namespace ::com::sun::star::ui;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir namespace framework
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir struct MenuStyleItem
130*cdf0e10cSrcweir {
131*cdf0e10cSrcweir     sal_Int16 nBit;
132*cdf0e10cSrcweir     const char* attrName;
133*cdf0e10cSrcweir };
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir MenuStyleItem MenuItemStyles[ ] = {
136*cdf0e10cSrcweir     { ::com::sun::star::ui::ItemStyle::ICON, ATTRIBUTE_ITEMSTYLE_IMAGE },
137*cdf0e10cSrcweir     { ::com::sun::star::ui::ItemStyle::TEXT, ATTRIBUTE_ITEMSTYLE_TEXT },
138*cdf0e10cSrcweir     { ::com::sun::star::ui::ItemStyle::RADIO_CHECK, ATTRIBUTE_ITEMSTYLE_RADIO }
139*cdf0e10cSrcweir };
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir sal_Int32 nMenuStyleItemEntries = sizeof( MenuItemStyles ) / sizeof( MenuItemStyles[ 0 ] );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir static void ExtractMenuParameters( const Sequence< PropertyValue > rProp,
145*cdf0e10cSrcweir                                    ::rtl::OUString&                       rCommandURL,
146*cdf0e10cSrcweir                                    ::rtl::OUString&                       rLabel,
147*cdf0e10cSrcweir                                    ::rtl::OUString&                       rHelpURL,
148*cdf0e10cSrcweir                                    Reference< XIndexAccess >&      rSubMenu,
149*cdf0e10cSrcweir                                    sal_Int16&                      rType,
150*cdf0e10cSrcweir                                    sal_Int16&                      rStyle )
151*cdf0e10cSrcweir {
152*cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < rProp.getLength(); i++ )
153*cdf0e10cSrcweir     {
154*cdf0e10cSrcweir         if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
155*cdf0e10cSrcweir         {
156*cdf0e10cSrcweir             rProp[i].Value >>= rCommandURL;
157*cdf0e10cSrcweir             rCommandURL = rCommandURL.intern();
158*cdf0e10cSrcweir         }
159*cdf0e10cSrcweir         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_HELPURL ))
160*cdf0e10cSrcweir         {
161*cdf0e10cSrcweir             rProp[i].Value >>= rHelpURL;
162*cdf0e10cSrcweir         }
163*cdf0e10cSrcweir         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_CONTAINER ))
164*cdf0e10cSrcweir         {
165*cdf0e10cSrcweir             rProp[i].Value >>= rSubMenu;
166*cdf0e10cSrcweir         }
167*cdf0e10cSrcweir         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL ))
168*cdf0e10cSrcweir         {
169*cdf0e10cSrcweir             rProp[i].Value >>= rLabel;
170*cdf0e10cSrcweir         }
171*cdf0e10cSrcweir         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE ))
172*cdf0e10cSrcweir         {
173*cdf0e10cSrcweir             rProp[i].Value >>= rType;
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
176*cdf0e10cSrcweir         {
177*cdf0e10cSrcweir             rProp[i].Value >>= rStyle;
178*cdf0e10cSrcweir         }
179*cdf0e10cSrcweir     }
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir // -----------------------------------------------------------------------------
184*cdf0e10cSrcweir // Base class implementation
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir ReadMenuDocumentHandlerBase::ReadMenuDocumentHandlerBase() :
187*cdf0e10cSrcweir 	m_xLocator( 0 ),
188*cdf0e10cSrcweir 	m_xReader( 0 ),
189*cdf0e10cSrcweir 	m_aType( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE )),
190*cdf0e10cSrcweir 	m_aLabel( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL )),
191*cdf0e10cSrcweir 	m_aContainer( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_CONTAINER )),
192*cdf0e10cSrcweir 	m_aHelpURL( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL )),
193*cdf0e10cSrcweir     m_aCommandURL( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL )),
194*cdf0e10cSrcweir     m_aStyle( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_STYLE ))
195*cdf0e10cSrcweir {
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir ReadMenuDocumentHandlerBase::~ReadMenuDocumentHandlerBase()
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir void SAL_CALL ReadMenuDocumentHandlerBase::ignorableWhitespace(
203*cdf0e10cSrcweir 	const ::rtl::OUString& )
204*cdf0e10cSrcweir throw( SAXException, RuntimeException )
205*cdf0e10cSrcweir {
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir void SAL_CALL ReadMenuDocumentHandlerBase::processingInstruction(
209*cdf0e10cSrcweir 	const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ )
210*cdf0e10cSrcweir throw( SAXException, RuntimeException )
211*cdf0e10cSrcweir {
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir void SAL_CALL ReadMenuDocumentHandlerBase::setDocumentLocator(
215*cdf0e10cSrcweir 	const Reference< XLocator > &xLocator)
216*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	m_xLocator = xLocator;
219*cdf0e10cSrcweir }
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir ::rtl::OUString ReadMenuDocumentHandlerBase::getErrorLineString()
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir 	char buffer[32];
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	if ( m_xLocator.is() )
226*cdf0e10cSrcweir 	{
227*cdf0e10cSrcweir 		snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>( m_xLocator->getLineNumber() ));
228*cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii( buffer );
229*cdf0e10cSrcweir 	}
230*cdf0e10cSrcweir 	else
231*cdf0e10cSrcweir 		return ::rtl::OUString();
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir void ReadMenuDocumentHandlerBase::initPropertyCommon(
235*cdf0e10cSrcweir 	Sequence< PropertyValue > &rProps, const rtl::OUString &rCommandURL,
236*cdf0e10cSrcweir     const rtl::OUString &rHelpId, const rtl::OUString &rLabel, sal_Int16 nItemStyleBits )
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir 	rProps[0].Name = m_aCommandURL;
239*cdf0e10cSrcweir 	rProps[1].Name = m_aHelpURL;
240*cdf0e10cSrcweir 	rProps[2].Name = m_aContainer;
241*cdf0e10cSrcweir 	rProps[3].Name = m_aLabel;
242*cdf0e10cSrcweir     rProps[4].Name = m_aStyle;
243*cdf0e10cSrcweir     rProps[5].Name = m_aType;
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir 	// Common values
246*cdf0e10cSrcweir 	rProps[0].Value <<= rCommandURL.intern();
247*cdf0e10cSrcweir 	rProps[1].Value <<= rHelpId;
248*cdf0e10cSrcweir 	rProps[2].Value <<= Reference< XIndexContainer >();
249*cdf0e10cSrcweir 	rProps[3].Value <<= rLabel;
250*cdf0e10cSrcweir     rProps[4].Value <<= nItemStyleBits;
251*cdf0e10cSrcweir     rProps[5].Value <<= ::com::sun::star::ui::ItemType::DEFAULT;
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir // -----------------------------------------------------------------------------
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir OReadMenuDocumentHandler::OReadMenuDocumentHandler(
257*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
258*cdf0e10cSrcweir 	const Reference< XIndexContainer >& rMenuBarContainer )
259*cdf0e10cSrcweir :	m_nElementDepth( 0 ),
260*cdf0e10cSrcweir 	m_bMenuBarMode( sal_False ),
261*cdf0e10cSrcweir 	m_xMenuBarContainer( rMenuBarContainer ),
262*cdf0e10cSrcweir       m_xContainerFactory( rMenuBarContainer, UNO_QUERY ),
263*cdf0e10cSrcweir 	mxServiceFactory(xServiceFactory)
264*cdf0e10cSrcweir {
265*cdf0e10cSrcweir }
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir // #110897#
268*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& OReadMenuDocumentHandler::getServiceFactory()
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir 	// #110897#
271*cdf0e10cSrcweir 	return mxServiceFactory;
272*cdf0e10cSrcweir }
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir OReadMenuDocumentHandler::~OReadMenuDocumentHandler()
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir void SAL_CALL OReadMenuDocumentHandler::startDocument(void)
280*cdf0e10cSrcweir 	throw ( SAXException, RuntimeException )
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir void SAL_CALL OReadMenuDocumentHandler::endDocument(void)
286*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
287*cdf0e10cSrcweir {
288*cdf0e10cSrcweir 	if ( m_nElementDepth > 0 )
289*cdf0e10cSrcweir 	{
290*cdf0e10cSrcweir 		::rtl::OUString aErrorMessage = getErrorLineString();
291*cdf0e10cSrcweir 		aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "A closing element is missing!" ));
292*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
293*cdf0e10cSrcweir 	}
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir void SAL_CALL OReadMenuDocumentHandler::startElement(
298*cdf0e10cSrcweir 	const ::rtl::OUString& aName, const Reference< XAttributeList > &xAttrList )
299*cdf0e10cSrcweir throw( SAXException, RuntimeException )
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir 	if ( m_bMenuBarMode )
302*cdf0e10cSrcweir 	{
303*cdf0e10cSrcweir 		++m_nElementDepth;
304*cdf0e10cSrcweir 		m_xReader->startElement( aName, xAttrList );
305*cdf0e10cSrcweir 	}
306*cdf0e10cSrcweir 	else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUBAR )))
307*cdf0e10cSrcweir 	{
308*cdf0e10cSrcweir 		++m_nElementDepth;
309*cdf0e10cSrcweir 		m_bMenuBarMode = sal_True;
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 		// #110897# m_xReader = Reference< XDocumentHandler >( new OReadMenuBarHandler( m_xMenuBarContainer, m_xContainerFactory ));
312*cdf0e10cSrcweir 		m_xReader = Reference< XDocumentHandler >( new OReadMenuBarHandler( getServiceFactory(), m_xMenuBarContainer, m_xContainerFactory ));
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir 		m_xReader->startDocument();
315*cdf0e10cSrcweir 	}
316*cdf0e10cSrcweir }
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir void SAL_CALL OReadMenuDocumentHandler::characters(const rtl::OUString&)
320*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir }
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir void SAL_CALL OReadMenuDocumentHandler::endElement( const ::rtl::OUString& aName )
326*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
327*cdf0e10cSrcweir {
328*cdf0e10cSrcweir 	if ( m_bMenuBarMode )
329*cdf0e10cSrcweir 	{
330*cdf0e10cSrcweir 		--m_nElementDepth;
331*cdf0e10cSrcweir 		m_xReader->endElement( aName );
332*cdf0e10cSrcweir 		if ( 0 == m_nElementDepth )
333*cdf0e10cSrcweir 		{
334*cdf0e10cSrcweir 			m_xReader->endDocument();
335*cdf0e10cSrcweir 			m_xReader = Reference< XDocumentHandler >();
336*cdf0e10cSrcweir 			m_bMenuBarMode = sal_False;
337*cdf0e10cSrcweir 			if ( !aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUBAR )))
338*cdf0e10cSrcweir 			{
339*cdf0e10cSrcweir 				::rtl::OUString aErrorMessage = getErrorLineString();
340*cdf0e10cSrcweir 				aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menubar expected!" ));
341*cdf0e10cSrcweir 				throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
342*cdf0e10cSrcweir 			}
343*cdf0e10cSrcweir 		}
344*cdf0e10cSrcweir 	}
345*cdf0e10cSrcweir }
346*cdf0e10cSrcweir 
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir // -----------------------------------------------------------------------------
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir // #110897#
352*cdf0e10cSrcweir OReadMenuBarHandler::OReadMenuBarHandler(
353*cdf0e10cSrcweir 	const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
354*cdf0e10cSrcweir     const Reference< XIndexContainer >& rMenuBarContainer,
355*cdf0e10cSrcweir     const Reference< XSingleComponentFactory >& rFactory          )
356*cdf0e10cSrcweir :	m_nElementDepth( 0 ),
357*cdf0e10cSrcweir 	m_bMenuMode( sal_False ),
358*cdf0e10cSrcweir 	m_xMenuBarContainer( rMenuBarContainer ),
359*cdf0e10cSrcweir       m_xContainerFactory( rFactory ),
360*cdf0e10cSrcweir 	mxServiceFactory( xServiceFactory )
361*cdf0e10cSrcweir {
362*cdf0e10cSrcweir }
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir // #110897#
365*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& OReadMenuBarHandler::getServiceFactory()
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir 	// #110897#
368*cdf0e10cSrcweir 	return mxServiceFactory;
369*cdf0e10cSrcweir }
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir OReadMenuBarHandler::~OReadMenuBarHandler()
372*cdf0e10cSrcweir {
373*cdf0e10cSrcweir }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir void SAL_CALL OReadMenuBarHandler::startDocument(void)
377*cdf0e10cSrcweir 	throw ( SAXException, RuntimeException )
378*cdf0e10cSrcweir {
379*cdf0e10cSrcweir }
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir void SAL_CALL OReadMenuBarHandler::endDocument(void)
383*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir void SAL_CALL OReadMenuBarHandler::startElement(
389*cdf0e10cSrcweir 	const ::rtl::OUString& rName, const Reference< XAttributeList > &xAttrList )
390*cdf0e10cSrcweir throw( SAXException, RuntimeException )
391*cdf0e10cSrcweir {
392*cdf0e10cSrcweir 	if ( m_bMenuMode )
393*cdf0e10cSrcweir 	{
394*cdf0e10cSrcweir 		++m_nElementDepth;
395*cdf0e10cSrcweir 		m_xReader->startElement( rName, xAttrList );
396*cdf0e10cSrcweir 	}
397*cdf0e10cSrcweir 	else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU )))
398*cdf0e10cSrcweir 	{
399*cdf0e10cSrcweir 		++m_nElementDepth;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir 		::rtl::OUString aHelpId;
402*cdf0e10cSrcweir 		::rtl::OUString aCommandId;
403*cdf0e10cSrcweir 		::rtl::OUString aLabel;
404*cdf0e10cSrcweir         sal_Int16 nItemBits(0);
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir 		m_bMenuMode = sal_True;
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir         // Container must be factory to create sub container
409*cdf0e10cSrcweir         Reference< XComponentContext > xComponentContext;
410*cdf0e10cSrcweir         Reference< XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY );
411*cdf0e10cSrcweir         xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>=
412*cdf0e10cSrcweir             xComponentContext;
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir         Reference< XIndexContainer > xSubItemContainer;
415*cdf0e10cSrcweir         if ( m_xContainerFactory.is() )
416*cdf0e10cSrcweir             xSubItemContainer = Reference< XIndexContainer >( m_xContainerFactory->createInstanceWithContext( xComponentContext ), UNO_QUERY );
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir 		if ( xSubItemContainer.is() )
419*cdf0e10cSrcweir         {
420*cdf0e10cSrcweir             // read attributes for menu
421*cdf0e10cSrcweir 		    for ( sal_Int16 i=0; i< xAttrList->getLength(); i++ )
422*cdf0e10cSrcweir 		    {
423*cdf0e10cSrcweir 			    ::rtl::OUString aName = xAttrList->getNameByIndex( i );
424*cdf0e10cSrcweir 			    ::rtl::OUString aValue = xAttrList->getValueByIndex( i );
425*cdf0e10cSrcweir 			    if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ID )))
426*cdf0e10cSrcweir 				    aCommandId = aValue;
427*cdf0e10cSrcweir 			    else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_LABEL )))
428*cdf0e10cSrcweir 				    aLabel = aValue;
429*cdf0e10cSrcweir 			    else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_HELPID )))
430*cdf0e10cSrcweir 				    aHelpId = aValue;
431*cdf0e10cSrcweir                 else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE )))
432*cdf0e10cSrcweir                 {
433*cdf0e10cSrcweir                     ::rtl::OUString aTemp( aValue );
434*cdf0e10cSrcweir                     sal_Int32 nIndex = 0;
435*cdf0e10cSrcweir                     do
436*cdf0e10cSrcweir                     {
437*cdf0e10cSrcweir                         ::rtl::OUString aToken = aTemp.getToken( 0, '+', nIndex );
438*cdf0e10cSrcweir                         if ( aToken.getLength() > 0 )
439*cdf0e10cSrcweir                         {
440*cdf0e10cSrcweir                             if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_TEXT ) ) )
441*cdf0e10cSrcweir                                 nItemBits |= ::com::sun::star::ui::ItemStyle::TEXT;
442*cdf0e10cSrcweir                             else if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_IMAGE ) ) )
443*cdf0e10cSrcweir                                 nItemBits |= ::com::sun::star::ui::ItemStyle::ICON;
444*cdf0e10cSrcweir                             else if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_RADIO ) ) )
445*cdf0e10cSrcweir                                 nItemBits |= ::com::sun::star::ui::ItemStyle::RADIO_CHECK;
446*cdf0e10cSrcweir                         }
447*cdf0e10cSrcweir                     }
448*cdf0e10cSrcweir                     while ( nIndex >= 0 );
449*cdf0e10cSrcweir                 }
450*cdf0e10cSrcweir 		    }
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir 		    if ( aCommandId.getLength() > 0 )
453*cdf0e10cSrcweir 		    {
454*cdf0e10cSrcweir                 Sequence< PropertyValue > aSubMenuProp( 6 );
455*cdf0e10cSrcweir                 initPropertyCommon( aSubMenuProp, aCommandId, aHelpId, aLabel, nItemBits );
456*cdf0e10cSrcweir 				aSubMenuProp[2].Value <<= xSubItemContainer;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir                 m_xMenuBarContainer->insertByIndex( m_xMenuBarContainer->getCount(), makeAny( aSubMenuProp ) );
459*cdf0e10cSrcweir 		    }
460*cdf0e10cSrcweir 		    else
461*cdf0e10cSrcweir 		    {
462*cdf0e10cSrcweir 			    ::rtl::OUString aErrorMessage = getErrorLineString();
463*cdf0e10cSrcweir 			    aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "attribute id for element menu required!" ));
464*cdf0e10cSrcweir 			    throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
465*cdf0e10cSrcweir 		    }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 		    m_xReader = Reference< XDocumentHandler >( new OReadMenuHandler( xSubItemContainer, m_xContainerFactory ));
468*cdf0e10cSrcweir 		    m_xReader->startDocument();
469*cdf0e10cSrcweir         }
470*cdf0e10cSrcweir 	}
471*cdf0e10cSrcweir 	else
472*cdf0e10cSrcweir 	{
473*cdf0e10cSrcweir 		::rtl::OUString aErrorMessage = getErrorLineString();
474*cdf0e10cSrcweir 		aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "element menu expected!" ));
475*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
476*cdf0e10cSrcweir 	}
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir void SAL_CALL OReadMenuBarHandler::characters(const rtl::OUString&)
481*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
482*cdf0e10cSrcweir {
483*cdf0e10cSrcweir }
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir void OReadMenuBarHandler::endElement( const ::rtl::OUString& aName )
487*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir 	if ( m_bMenuMode )
490*cdf0e10cSrcweir 	{
491*cdf0e10cSrcweir 		--m_nElementDepth;
492*cdf0e10cSrcweir 		if ( 0 == m_nElementDepth )
493*cdf0e10cSrcweir 		{
494*cdf0e10cSrcweir 			m_xReader->endDocument();
495*cdf0e10cSrcweir 			m_xReader = Reference< XDocumentHandler >();
496*cdf0e10cSrcweir 			m_bMenuMode = sal_False;
497*cdf0e10cSrcweir 			if ( !aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU )))
498*cdf0e10cSrcweir 			{
499*cdf0e10cSrcweir 				::rtl::OUString aErrorMessage = getErrorLineString();
500*cdf0e10cSrcweir 				aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menu expected!" ));
501*cdf0e10cSrcweir 				throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
502*cdf0e10cSrcweir 			}
503*cdf0e10cSrcweir 		}
504*cdf0e10cSrcweir 		else
505*cdf0e10cSrcweir 			m_xReader->endElement( aName );
506*cdf0e10cSrcweir 	}
507*cdf0e10cSrcweir }
508*cdf0e10cSrcweir 
509*cdf0e10cSrcweir 
510*cdf0e10cSrcweir // -----------------------------------------------------------------------------
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir OReadMenuHandler::OReadMenuHandler(
514*cdf0e10cSrcweir     const Reference< XIndexContainer >& rMenuContainer,
515*cdf0e10cSrcweir     const Reference< XSingleComponentFactory >& rFactory          ) :
516*cdf0e10cSrcweir     m_nElementDepth( 0 ),
517*cdf0e10cSrcweir     m_bMenuPopupMode( sal_False ),
518*cdf0e10cSrcweir     m_xMenuContainer( rMenuContainer ),
519*cdf0e10cSrcweir     m_xContainerFactory( rFactory )
520*cdf0e10cSrcweir {
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir OReadMenuHandler::~OReadMenuHandler()
525*cdf0e10cSrcweir {
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir void SAL_CALL OReadMenuHandler::startDocument(void)
530*cdf0e10cSrcweir 	throw ( SAXException, RuntimeException )
531*cdf0e10cSrcweir {
532*cdf0e10cSrcweir }
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir void SAL_CALL OReadMenuHandler::endDocument(void)
536*cdf0e10cSrcweir 	throw( SAXException, RuntimeException)
537*cdf0e10cSrcweir {
538*cdf0e10cSrcweir }
539*cdf0e10cSrcweir 
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir void SAL_CALL OReadMenuHandler::startElement(
542*cdf0e10cSrcweir 	const ::rtl::OUString& aName, const Reference< XAttributeList > &xAttrList )
543*cdf0e10cSrcweir throw( SAXException, RuntimeException )
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir 	if ( m_bMenuPopupMode )
546*cdf0e10cSrcweir 	{
547*cdf0e10cSrcweir 		++m_nElementDepth;
548*cdf0e10cSrcweir 		m_xReader->startElement( aName, xAttrList );
549*cdf0e10cSrcweir 	}
550*cdf0e10cSrcweir 	else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUPOPUP )))
551*cdf0e10cSrcweir 	{
552*cdf0e10cSrcweir 		++m_nElementDepth;
553*cdf0e10cSrcweir 		m_bMenuPopupMode = sal_True;
554*cdf0e10cSrcweir 		m_xReader = Reference< XDocumentHandler >( new OReadMenuPopupHandler( m_xMenuContainer, m_xContainerFactory ));
555*cdf0e10cSrcweir 		m_xReader->startDocument();
556*cdf0e10cSrcweir 	}
557*cdf0e10cSrcweir 	else
558*cdf0e10cSrcweir 	{
559*cdf0e10cSrcweir 		::rtl::OUString aErrorMessage = getErrorLineString();
560*cdf0e10cSrcweir 		aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unknown element found!" ));
561*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
562*cdf0e10cSrcweir 	}
563*cdf0e10cSrcweir }
564*cdf0e10cSrcweir 
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir void SAL_CALL OReadMenuHandler::characters(const rtl::OUString&)
567*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir 
572*cdf0e10cSrcweir void SAL_CALL OReadMenuHandler::endElement( const ::rtl::OUString& aName )
573*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
574*cdf0e10cSrcweir {
575*cdf0e10cSrcweir 	if ( m_bMenuPopupMode )
576*cdf0e10cSrcweir 	{
577*cdf0e10cSrcweir 		--m_nElementDepth;
578*cdf0e10cSrcweir 		if ( 0 == m_nElementDepth )
579*cdf0e10cSrcweir 		{
580*cdf0e10cSrcweir 			m_xReader->endDocument();
581*cdf0e10cSrcweir 			m_xReader = Reference< XDocumentHandler >();
582*cdf0e10cSrcweir 			m_bMenuPopupMode = sal_False;
583*cdf0e10cSrcweir 			if ( !aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUPOPUP )))
584*cdf0e10cSrcweir 			{
585*cdf0e10cSrcweir 				::rtl::OUString aErrorMessage = getErrorLineString();
586*cdf0e10cSrcweir 				aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menupopup expected!" ));
587*cdf0e10cSrcweir 				throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
588*cdf0e10cSrcweir 			}
589*cdf0e10cSrcweir 		}
590*cdf0e10cSrcweir 		else
591*cdf0e10cSrcweir 			m_xReader->endElement( aName );
592*cdf0e10cSrcweir 	}
593*cdf0e10cSrcweir }
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir // -----------------------------------------------------------------------------
597*cdf0e10cSrcweir 
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir OReadMenuPopupHandler::OReadMenuPopupHandler(
600*cdf0e10cSrcweir     const Reference< XIndexContainer >& rMenuContainer,
601*cdf0e10cSrcweir     const Reference< XSingleComponentFactory >& rFactory          ) :
602*cdf0e10cSrcweir     m_nElementDepth( 0 ),
603*cdf0e10cSrcweir     m_bMenuMode( sal_False ),
604*cdf0e10cSrcweir     m_xMenuContainer( rMenuContainer ),
605*cdf0e10cSrcweir     m_xContainerFactory( rFactory ),
606*cdf0e10cSrcweir     m_nNextElementExpected( ELEM_CLOSE_NONE )
607*cdf0e10cSrcweir {
608*cdf0e10cSrcweir }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir OReadMenuPopupHandler::~OReadMenuPopupHandler()
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir }
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir void SAL_CALL OReadMenuPopupHandler::startDocument(void)
617*cdf0e10cSrcweir 	throw ( SAXException, RuntimeException )
618*cdf0e10cSrcweir {
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir void SAL_CALL OReadMenuPopupHandler::endDocument(void)
623*cdf0e10cSrcweir 	throw( SAXException, RuntimeException)
624*cdf0e10cSrcweir {
625*cdf0e10cSrcweir }
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir void SAL_CALL OReadMenuPopupHandler::startElement(
628*cdf0e10cSrcweir 	const ::rtl::OUString& rName, const Reference< XAttributeList > &xAttrList )
629*cdf0e10cSrcweir throw( SAXException, RuntimeException )
630*cdf0e10cSrcweir {
631*cdf0e10cSrcweir 	++m_nElementDepth;
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 	if ( m_bMenuMode )
634*cdf0e10cSrcweir 		m_xReader->startElement( rName, xAttrList );
635*cdf0e10cSrcweir 	else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU )))
636*cdf0e10cSrcweir 	{
637*cdf0e10cSrcweir 		::rtl::OUString aHelpId;
638*cdf0e10cSrcweir 		::rtl::OUString aCommandId;
639*cdf0e10cSrcweir 		::rtl::OUString aLabel;
640*cdf0e10cSrcweir         sal_Int16 nItemBits(0);
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 		m_bMenuMode = sal_True;
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir         // Container must be factory to create sub container
645*cdf0e10cSrcweir         if ( !m_xComponentContext.is() )
646*cdf0e10cSrcweir         {
647*cdf0e10cSrcweir             const Reference< XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
648*cdf0e10cSrcweir             m_xComponentContext.set(xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );
649*cdf0e10cSrcweir         }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir         Reference< XIndexContainer > xSubItemContainer;
652*cdf0e10cSrcweir         if ( m_xContainerFactory.is() )
653*cdf0e10cSrcweir             xSubItemContainer = Reference< XIndexContainer >( m_xContainerFactory->createInstanceWithContext( m_xComponentContext ), UNO_QUERY );
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir         // read attributes for menu
656*cdf0e10cSrcweir 		for ( sal_Int16 i=0; i< xAttrList->getLength(); i++ )
657*cdf0e10cSrcweir 		{
658*cdf0e10cSrcweir 			::rtl::OUString aName = xAttrList->getNameByIndex( i );
659*cdf0e10cSrcweir 			::rtl::OUString aValue = xAttrList->getValueByIndex( i );
660*cdf0e10cSrcweir 			if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ID )))
661*cdf0e10cSrcweir 				aCommandId = aValue;
662*cdf0e10cSrcweir 			else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_LABEL )))
663*cdf0e10cSrcweir 				aLabel = aValue;
664*cdf0e10cSrcweir 			else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_HELPID )))
665*cdf0e10cSrcweir 				aHelpId = aValue;
666*cdf0e10cSrcweir             else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE )))
667*cdf0e10cSrcweir             {
668*cdf0e10cSrcweir                 ::rtl::OUString aTemp( aValue );
669*cdf0e10cSrcweir                 sal_Int32 nIndex = 0;
670*cdf0e10cSrcweir                 do
671*cdf0e10cSrcweir                 {
672*cdf0e10cSrcweir                     ::rtl::OUString aToken = aTemp.getToken( 0, '+', nIndex );
673*cdf0e10cSrcweir                     if ( aToken.getLength() > 0 )
674*cdf0e10cSrcweir                     {
675*cdf0e10cSrcweir                         if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_TEXT ) ) )
676*cdf0e10cSrcweir                             nItemBits |= ::com::sun::star::ui::ItemStyle::TEXT;
677*cdf0e10cSrcweir                         else if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_IMAGE ) ) )
678*cdf0e10cSrcweir                             nItemBits |= ::com::sun::star::ui::ItemStyle::ICON;
679*cdf0e10cSrcweir                         else if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_RADIO ) ) )
680*cdf0e10cSrcweir                             nItemBits |= ::com::sun::star::ui::ItemStyle::RADIO_CHECK;
681*cdf0e10cSrcweir                     }
682*cdf0e10cSrcweir                 }
683*cdf0e10cSrcweir                 while ( nIndex >= 0 );
684*cdf0e10cSrcweir             }
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir 		}
687*cdf0e10cSrcweir 
688*cdf0e10cSrcweir 		if ( aCommandId.getLength() > 0 )
689*cdf0e10cSrcweir 		{
690*cdf0e10cSrcweir             Sequence< PropertyValue > aSubMenuProp( 6 );
691*cdf0e10cSrcweir             initPropertyCommon( aSubMenuProp, aCommandId, aHelpId, aLabel, nItemBits );
692*cdf0e10cSrcweir 			aSubMenuProp[2].Value <<= xSubItemContainer;
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir             m_xMenuContainer->insertByIndex( m_xMenuContainer->getCount(), makeAny( aSubMenuProp ) );
695*cdf0e10cSrcweir 		}
696*cdf0e10cSrcweir 		else
697*cdf0e10cSrcweir 		{
698*cdf0e10cSrcweir 			::rtl::OUString aErrorMessage = getErrorLineString();
699*cdf0e10cSrcweir 			aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "attribute id for element menu required!" ));
700*cdf0e10cSrcweir 			throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
701*cdf0e10cSrcweir 		}
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir 		m_xReader = Reference< XDocumentHandler >( new OReadMenuHandler( xSubItemContainer, m_xContainerFactory ));
704*cdf0e10cSrcweir 		m_xReader->startDocument();
705*cdf0e10cSrcweir 	}
706*cdf0e10cSrcweir 	else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUITEM )))
707*cdf0e10cSrcweir 	{
708*cdf0e10cSrcweir 		::rtl::OUString aHelpId;
709*cdf0e10cSrcweir 		::rtl::OUString aCommandId;
710*cdf0e10cSrcweir 		::rtl::OUString aLabel;
711*cdf0e10cSrcweir         sal_Int16 nItemBits(0);
712*cdf0e10cSrcweir 		// read attributes for menu item
713*cdf0e10cSrcweir 		for ( sal_Int16 i=0; i< xAttrList->getLength(); i++ )
714*cdf0e10cSrcweir 		{
715*cdf0e10cSrcweir 			::rtl::OUString aName = xAttrList->getNameByIndex( i );
716*cdf0e10cSrcweir 			::rtl::OUString aValue = xAttrList->getValueByIndex( i );
717*cdf0e10cSrcweir 			if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ID )))
718*cdf0e10cSrcweir 				aCommandId = aValue;
719*cdf0e10cSrcweir 			else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_LABEL )))
720*cdf0e10cSrcweir 				aLabel = aValue;
721*cdf0e10cSrcweir 			else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_HELPID )))
722*cdf0e10cSrcweir 				aHelpId = aValue;
723*cdf0e10cSrcweir             else if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE )))
724*cdf0e10cSrcweir             {
725*cdf0e10cSrcweir                 ::rtl::OUString aTemp( aValue );
726*cdf0e10cSrcweir                 sal_Int32 nIndex = 0;
727*cdf0e10cSrcweir                 do
728*cdf0e10cSrcweir                 {
729*cdf0e10cSrcweir                     ::rtl::OUString aToken = aTemp.getToken( 0, '+', nIndex );
730*cdf0e10cSrcweir                     if ( aToken.getLength() > 0 )
731*cdf0e10cSrcweir                     {
732*cdf0e10cSrcweir                         if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_TEXT ) ) )
733*cdf0e10cSrcweir                             nItemBits |= ::com::sun::star::ui::ItemStyle::TEXT;
734*cdf0e10cSrcweir                         else if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_IMAGE ) ) )
735*cdf0e10cSrcweir                             nItemBits |= ::com::sun::star::ui::ItemStyle::ICON;
736*cdf0e10cSrcweir                         else if ( aToken.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ITEMSTYLE_RADIO ) ) )
737*cdf0e10cSrcweir                             nItemBits |= ::com::sun::star::ui::ItemStyle::RADIO_CHECK;
738*cdf0e10cSrcweir                     }
739*cdf0e10cSrcweir                 }
740*cdf0e10cSrcweir                 while ( nIndex >= 0 );
741*cdf0e10cSrcweir             }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir 		}
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir 		if ( aCommandId.getLength() > 0 )
746*cdf0e10cSrcweir 		{
747*cdf0e10cSrcweir             Sequence< PropertyValue > aMenuItem( 6 );
748*cdf0e10cSrcweir             initPropertyCommon( aMenuItem, aCommandId, aHelpId, aLabel, nItemBits );
749*cdf0e10cSrcweir 			aMenuItem[2].Value <<= Reference< XIndexContainer >();
750*cdf0e10cSrcweir 
751*cdf0e10cSrcweir             m_xMenuContainer->insertByIndex( m_xMenuContainer->getCount(), makeAny( aMenuItem ) );
752*cdf0e10cSrcweir 		}
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir 		m_nNextElementExpected = ELEM_CLOSE_MENUITEM;
755*cdf0e10cSrcweir 	}
756*cdf0e10cSrcweir 	else if ( rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUSEPARATOR )))
757*cdf0e10cSrcweir 	{
758*cdf0e10cSrcweir         Sequence< PropertyValue > aMenuSeparator( 1 );
759*cdf0e10cSrcweir         aMenuSeparator[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ));
760*cdf0e10cSrcweir         aMenuSeparator[0].Value <<= ::com::sun::star::ui::ItemType::SEPARATOR_LINE;
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir         m_xMenuContainer->insertByIndex( m_xMenuContainer->getCount(), makeAny( aMenuSeparator ) );
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir         m_nNextElementExpected = ELEM_CLOSE_MENUSEPARATOR;
765*cdf0e10cSrcweir 	}
766*cdf0e10cSrcweir 	else
767*cdf0e10cSrcweir 	{
768*cdf0e10cSrcweir 		::rtl::OUString aErrorMessage = getErrorLineString();
769*cdf0e10cSrcweir 		aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unknown element found!" ));
770*cdf0e10cSrcweir 		throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
771*cdf0e10cSrcweir 	}
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir 
775*cdf0e10cSrcweir void SAL_CALL OReadMenuPopupHandler::characters(const rtl::OUString&)
776*cdf0e10cSrcweir throw(	SAXException, RuntimeException )
777*cdf0e10cSrcweir {
778*cdf0e10cSrcweir }
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir void SAL_CALL OReadMenuPopupHandler::endElement( const ::rtl::OUString& aName )
782*cdf0e10cSrcweir 	throw( SAXException, RuntimeException )
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir 	--m_nElementDepth;
785*cdf0e10cSrcweir 	if ( m_bMenuMode )
786*cdf0e10cSrcweir 	{
787*cdf0e10cSrcweir 		if ( 0 == m_nElementDepth )
788*cdf0e10cSrcweir 		{
789*cdf0e10cSrcweir 			m_xReader->endDocument();
790*cdf0e10cSrcweir 			m_xReader = Reference< XDocumentHandler >();
791*cdf0e10cSrcweir 			m_bMenuMode = sal_False;
792*cdf0e10cSrcweir 			if ( !aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU )))
793*cdf0e10cSrcweir 			{
794*cdf0e10cSrcweir 				::rtl::OUString aErrorMessage = getErrorLineString();
795*cdf0e10cSrcweir 				aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menu expected!" ));
796*cdf0e10cSrcweir 				throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
797*cdf0e10cSrcweir 			}
798*cdf0e10cSrcweir 		}
799*cdf0e10cSrcweir 		else
800*cdf0e10cSrcweir 			m_xReader->endElement( aName );
801*cdf0e10cSrcweir 	}
802*cdf0e10cSrcweir 	else
803*cdf0e10cSrcweir 	{
804*cdf0e10cSrcweir 		if ( m_nNextElementExpected == ELEM_CLOSE_MENUITEM )
805*cdf0e10cSrcweir 		{
806*cdf0e10cSrcweir 			if ( !aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUITEM )))
807*cdf0e10cSrcweir 			{
808*cdf0e10cSrcweir 				::rtl::OUString aErrorMessage = getErrorLineString();
809*cdf0e10cSrcweir 				aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menuitem expected!" ));
810*cdf0e10cSrcweir 				throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
811*cdf0e10cSrcweir 			}
812*cdf0e10cSrcweir 		}
813*cdf0e10cSrcweir 		else if ( m_nNextElementExpected == ELEM_CLOSE_MENUSEPARATOR )
814*cdf0e10cSrcweir 		{
815*cdf0e10cSrcweir 			if ( !aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUSEPARATOR )))
816*cdf0e10cSrcweir 			{
817*cdf0e10cSrcweir 				::rtl::OUString aErrorMessage = getErrorLineString();
818*cdf0e10cSrcweir 				aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menuseparator expected!" ));
819*cdf0e10cSrcweir 				throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
820*cdf0e10cSrcweir 			}
821*cdf0e10cSrcweir 		}
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir 		m_nNextElementExpected = ELEM_CLOSE_NONE;
824*cdf0e10cSrcweir 	}
825*cdf0e10cSrcweir }
826*cdf0e10cSrcweir 
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir // --------------------------------- Write XML ---------------------------------
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir 
831*cdf0e10cSrcweir OWriteMenuDocumentHandler::OWriteMenuDocumentHandler(
832*cdf0e10cSrcweir     const Reference< XIndexAccess >& rMenuBarContainer,
833*cdf0e10cSrcweir     const Reference< XDocumentHandler >& rDocumentHandler ) :
834*cdf0e10cSrcweir 	m_xMenuBarContainer( rMenuBarContainer ),
835*cdf0e10cSrcweir 	m_xWriteDocumentHandler( rDocumentHandler )
836*cdf0e10cSrcweir {
837*cdf0e10cSrcweir 	::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
838*cdf0e10cSrcweir 	m_xEmptyList = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY );
839*cdf0e10cSrcweir 	m_aAttributeType = 	::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA ));
840*cdf0e10cSrcweir }
841*cdf0e10cSrcweir 
842*cdf0e10cSrcweir 
843*cdf0e10cSrcweir OWriteMenuDocumentHandler::~OWriteMenuDocumentHandler()
844*cdf0e10cSrcweir {
845*cdf0e10cSrcweir }
846*cdf0e10cSrcweir 
847*cdf0e10cSrcweir 
848*cdf0e10cSrcweir void OWriteMenuDocumentHandler::WriteMenuDocument()
849*cdf0e10cSrcweir throw ( SAXException, RuntimeException )
850*cdf0e10cSrcweir {
851*cdf0e10cSrcweir 	::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
852*cdf0e10cSrcweir 	Reference< XAttributeList > rList( (XAttributeList *) pList , UNO_QUERY );
853*cdf0e10cSrcweir 
854*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startDocument();
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir 	// write DOCTYPE line!
857*cdf0e10cSrcweir 	Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
858*cdf0e10cSrcweir 	if ( xExtendedDocHandler.is() )
859*cdf0e10cSrcweir 	{
860*cdf0e10cSrcweir 		xExtendedDocHandler->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( MENUBAR_DOCTYPE )) );
861*cdf0e10cSrcweir 		m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
862*cdf0e10cSrcweir 	}
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir 	pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_MENU )),
865*cdf0e10cSrcweir 						 m_aAttributeType,
866*cdf0e10cSrcweir 						 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_MENU )) );
867*cdf0e10cSrcweir 
868*cdf0e10cSrcweir 	pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID )),
869*cdf0e10cSrcweir 						 m_aAttributeType,
870*cdf0e10cSrcweir 						 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "menubar" )) );
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUBAR )), pList );
873*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir 	WriteMenu( m_xMenuBarContainer );
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
878*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUBAR )) );
879*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
880*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endDocument();
881*cdf0e10cSrcweir }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 
884*cdf0e10cSrcweir void OWriteMenuDocumentHandler::WriteMenu( const Reference< XIndexAccess >& rMenuContainer )
885*cdf0e10cSrcweir throw ( SAXException, RuntimeException )
886*cdf0e10cSrcweir {
887*cdf0e10cSrcweir 	sal_Int32  nItemCount = rMenuContainer->getCount();
888*cdf0e10cSrcweir 	sal_Bool   bSeparator = sal_False;
889*cdf0e10cSrcweir     Any        aAny;
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir 	for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ )
892*cdf0e10cSrcweir 	{
893*cdf0e10cSrcweir         Sequence< PropertyValue > aProps;
894*cdf0e10cSrcweir         aAny = rMenuContainer->getByIndex( nItemPos );
895*cdf0e10cSrcweir         if ( aAny >>= aProps )
896*cdf0e10cSrcweir         {
897*cdf0e10cSrcweir             ::rtl::OUString    aCommandURL;
898*cdf0e10cSrcweir             ::rtl::OUString    aLabel;
899*cdf0e10cSrcweir             ::rtl::OUString    aHelpURL;
900*cdf0e10cSrcweir             sal_Int16   nType( ::com::sun::star::ui::ItemType::DEFAULT );
901*cdf0e10cSrcweir             sal_Int16   nItemBits( 0 );
902*cdf0e10cSrcweir             Reference< XIndexAccess > xSubMenu;
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir             ExtractMenuParameters( aProps, aCommandURL, aLabel, aHelpURL, xSubMenu, nType, nItemBits );
905*cdf0e10cSrcweir             if ( xSubMenu.is() )
906*cdf0e10cSrcweir 		    {
907*cdf0e10cSrcweir                 if ( aCommandURL.equalsAscii( ADDDIRECT_CMD ) ||
908*cdf0e10cSrcweir                     aCommandURL.equalsAscii( AUTOPILOTMENU_CMD ))
909*cdf0e10cSrcweir                 {
910*cdf0e10cSrcweir                     WriteMenuItem( aCommandURL, aLabel, aHelpURL, nItemBits );
911*cdf0e10cSrcweir                     bSeparator = sal_False;
912*cdf0e10cSrcweir                 }
913*cdf0e10cSrcweir 			    else if (( aCommandURL.getLength() > 0 ) && !AddonPopupMenu::IsCommandURLPrefix ( aCommandURL ))
914*cdf0e10cSrcweir 			    {
915*cdf0e10cSrcweir 				    ::comphelper::AttributeList* pListMenu = new ::comphelper::AttributeList;
916*cdf0e10cSrcweir 				    Reference< XAttributeList > xListMenu( (XAttributeList *)pListMenu , UNO_QUERY );
917*cdf0e10cSrcweir 
918*cdf0e10cSrcweir                     pListMenu->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID )),
919*cdf0e10cSrcweir                                             m_aAttributeType,
920*cdf0e10cSrcweir                                             aCommandURL );
921*cdf0e10cSrcweir 
922*cdf0e10cSrcweir 				    if ( !( aCommandURL.copy( CMD_PROTOCOL_SIZE ).equalsAscii( CMD_PROTOCOL )))
923*cdf0e10cSrcweir                         pListMenu->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_LABEL )),
924*cdf0e10cSrcweir 						    					 m_aAttributeType,
925*cdf0e10cSrcweir 							    				 aLabel );
926*cdf0e10cSrcweir 
927*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
928*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENU )), xListMenu );
929*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
930*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUPOPUP )), m_xEmptyList );
931*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
932*cdf0e10cSrcweir 
933*cdf0e10cSrcweir 				    WriteMenu( xSubMenu );
934*cdf0e10cSrcweir 
935*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
936*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUPOPUP )) );
937*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
938*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENU )) );
939*cdf0e10cSrcweir 				    m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
940*cdf0e10cSrcweir 				    bSeparator = sal_False;
941*cdf0e10cSrcweir 			    }
942*cdf0e10cSrcweir 		    }
943*cdf0e10cSrcweir 		    else
944*cdf0e10cSrcweir 		    {
945*cdf0e10cSrcweir                 if ( nType == ::com::sun::star::ui::ItemType::DEFAULT )
946*cdf0e10cSrcweir                 {
947*cdf0e10cSrcweir                     if ( aCommandURL.getLength() > 0 )
948*cdf0e10cSrcweir                     {
949*cdf0e10cSrcweir                         bSeparator = sal_False;
950*cdf0e10cSrcweir                         WriteMenuItem( aCommandURL, aLabel, aHelpURL, nItemBits );
951*cdf0e10cSrcweir                     }
952*cdf0e10cSrcweir 			    }
953*cdf0e10cSrcweir 			    else if ( !bSeparator )
954*cdf0e10cSrcweir 			    {
955*cdf0e10cSrcweir                     // Don't write two separators together
956*cdf0e10cSrcweir 				    WriteMenuSeparator();
957*cdf0e10cSrcweir 				    bSeparator = sal_True;
958*cdf0e10cSrcweir 			    }
959*cdf0e10cSrcweir 		    }
960*cdf0e10cSrcweir         }
961*cdf0e10cSrcweir 	}
962*cdf0e10cSrcweir }
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir void OWriteMenuDocumentHandler::WriteMenuItem( const ::rtl::OUString& aCommandURL, const ::rtl::OUString& aLabel, const ::rtl::OUString& aHelpURL, sal_Int16 nStyle )
966*cdf0e10cSrcweir {
967*cdf0e10cSrcweir 	::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
968*cdf0e10cSrcweir 	Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
969*cdf0e10cSrcweir 
970*cdf0e10cSrcweir     pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID )),
971*cdf0e10cSrcweir                                 m_aAttributeType,
972*cdf0e10cSrcweir                                 aCommandURL );
973*cdf0e10cSrcweir 
974*cdf0e10cSrcweir 	if ( aHelpURL.getLength() > 0 )
975*cdf0e10cSrcweir 	{
976*cdf0e10cSrcweir 		pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_HELPID )),
977*cdf0e10cSrcweir 							 m_aAttributeType,
978*cdf0e10cSrcweir 							 aHelpURL );
979*cdf0e10cSrcweir 	}
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir     if (( aLabel.getLength() > 0 ) && !( aCommandURL.copy( CMD_PROTOCOL_SIZE ).equalsAscii( CMD_PROTOCOL )))
982*cdf0e10cSrcweir     {
983*cdf0e10cSrcweir         pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_LABEL )),
984*cdf0e10cSrcweir 							    m_aAttributeType,
985*cdf0e10cSrcweir 							    aLabel );
986*cdf0e10cSrcweir     }
987*cdf0e10cSrcweir     if (( nStyle > 0 ) && !( aCommandURL.copy( CMD_PROTOCOL_SIZE ).equalsAscii( CMD_PROTOCOL )))
988*cdf0e10cSrcweir     {
989*cdf0e10cSrcweir         rtl::OUString aValue;
990*cdf0e10cSrcweir         MenuStyleItem* pStyle = MenuItemStyles;
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir         for ( sal_Int32 nIndex = 0; nIndex < nMenuStyleItemEntries; ++nIndex, ++pStyle )
993*cdf0e10cSrcweir         {
994*cdf0e10cSrcweir             if ( nStyle & pStyle->nBit )
995*cdf0e10cSrcweir             {
996*cdf0e10cSrcweir                 if ( aValue.getLength() )
997*cdf0e10cSrcweir                     aValue = aValue.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("+") ) );
998*cdf0e10cSrcweir                 aValue += rtl::OUString::createFromAscii( pStyle->attrName );
999*cdf0e10cSrcweir             }
1000*cdf0e10cSrcweir         }
1001*cdf0e10cSrcweir         pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_STYLE )),
1002*cdf0e10cSrcweir                                 m_aAttributeType,
1003*cdf0e10cSrcweir                                 aValue );
1004*cdf0e10cSrcweir     }
1005*cdf0e10cSrcweir 
1006*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
1007*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUITEM )), xList );
1008*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
1009*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUITEM )) );
1010*cdf0e10cSrcweir }
1011*cdf0e10cSrcweir 
1012*cdf0e10cSrcweir 
1013*cdf0e10cSrcweir void OWriteMenuDocumentHandler::WriteMenuSeparator()
1014*cdf0e10cSrcweir {
1015*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
1016*cdf0e10cSrcweir 	m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUSEPARATOR )), m_xEmptyList );
1017*cdf0e10cSrcweir 	m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
1018*cdf0e10cSrcweir 	m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUSEPARATOR )) );
1019*cdf0e10cSrcweir }
1020*cdf0e10cSrcweir 
1021*cdf0e10cSrcweir } // namespace framework
1022*cdf0e10cSrcweir 
1023