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