1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: menudocumenthandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
35 #include <services/menudocumenthandler.hxx>
36 #include <classes/menuconfiguration.hxx>
37 #include <classes/addonmenu.hxx>
39 #ifndef __FRAMEWORK_SERVICES_ATTRIBUTELIST_HXX_
40 #include <services/attributelist.hxx>
43 #ifndef __COM_SUN_STAR_XML_SAX_XEXTENDEDDOCUMENTHANDLER_HPP_
44 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
48 using namespace ::rtl
;
49 using namespace ::com::sun::star::uno
;
50 using namespace ::com::sun::star::xml::sax
;
52 const int ITEMID_START_VALUE
= 1000;
54 #define XMLNS_MENU "http://openoffice.org/2001/menu"
55 #define XMLNS_PREFIX "menu:"
57 #define ELEMENT_MENUBAR "http://openoffice.org/2001/menu^menubar"
58 #define ELEMENT_MENU "http://openoffice.org/2001/menu^menu"
59 #define ELEMENT_MENUPOPUP "http://openoffice.org/2001/menu^menupopup"
60 #define ELEMENT_MENUITEM "http://openoffice.org/2001/menu^menuitem"
61 #define ELEMENT_MENUSEPARATOR "http://openoffice.org/2001/menu^menuseparator"
63 #define ELEMENT_NS_MENUBAR "menu:menubar"
64 #define ELEMENT_NS_MENU "menu:menu"
65 #define ELEMENT_NS_MENUPOPUP "menu:menupopup"
66 #define ELEMENT_NS_MENUITEM "menu:menuitem"
67 #define ELEMENT_NS_MENUSEPARATOR "menu:menuseparator"
69 #define ATTRIBUTE_ID "http://openoffice.org/2001/menu^id"
70 #define ATTRIBUTE_LABEL "http://openoffice.org/2001/menu^label"
71 #define ATTRIBUTE_HELPID "http://openoffice.org/2001/menu^helpid"
72 #define ATTRIBUTE_LINEBREAK "http://openoffice.org/2001/menu^linebreak"
74 #define ATTRIBUTE_NS_ID "menu:id"
75 #define ATTRIBUTE_NS_LABEL "menu:label"
76 #define ATTRIBUTE_NS_HELPID "menu:helpid"
77 #define ATTRIBUTE_NS_LINEBREAK "menu:linebreak"
79 #define ATTRIBUTE_XMLNS_MENU "xmlns:menu"
81 #define ATTRIBUTE_TYPE_CDATA "CDATA"
83 #define MENUBAR_DOCTYPE "<!DOCTYPE menu:menubar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"menubar.dtd\">"
86 // special popup menus (filled during runtime) must be saved as a menuitem!!!
87 // same as in menumanager.cxx - you have to change both files!!!
88 #define SID_SFX_START 5000
89 #define SID_NEWDOCDIRECT (SID_SFX_START + 537)
90 #define SID_AUTOPILOTMENU (SID_SFX_START + 1381)
91 #define SID_FORMATMENU (SID_SFX_START + 780)
93 const ::rtl::OUString
aSlotProtocol( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
94 const ::rtl::OUString
aSlotNewDocDirect( RTL_CONSTASCII_USTRINGPARAM( "slot:5537" ));
95 const ::rtl::OUString
aSlotAutoPilot( RTL_CONSTASCII_USTRINGPARAM( "slot:6381" ));
97 const ::rtl::OUString
aSpecialFileMenu( RTL_CONSTASCII_USTRINGPARAM( "file" ));
98 const ::rtl::OUString
aSpecialWindowMenu( RTL_CONSTASCII_USTRINGPARAM( "window" ));
100 const ULONG MENU_SAVE_LABEL
= 0x00000001;
105 // -----------------------------------------------------------------------------
106 // Base class implementation
108 ReadMenuDocumentHandlerBase::ReadMenuDocumentHandlerBase() :
114 ReadMenuDocumentHandlerBase::~ReadMenuDocumentHandlerBase()
118 Any SAL_CALL
ReadMenuDocumentHandlerBase::queryInterface(
120 throw( RuntimeException
)
122 Any a
= ::cppu::queryInterface(
124 SAL_STATIC_CAST( XDocumentHandler
*, this ));
128 return OWeakObject::queryInterface( rType
);
131 void SAL_CALL
ReadMenuDocumentHandlerBase::ignorableWhitespace(
132 const OUString
& aWhitespaces
)
133 throw( SAXException
, RuntimeException
)
137 void SAL_CALL
ReadMenuDocumentHandlerBase::processingInstruction(
138 const OUString
& aTarget
, const OUString
& aData
)
139 throw( SAXException
, RuntimeException
)
143 void SAL_CALL
ReadMenuDocumentHandlerBase::setDocumentLocator(
144 const Reference
< XLocator
> &xLocator
)
145 throw( SAXException
, RuntimeException
)
147 m_xLocator
= xLocator
;
150 ::rtl::OUString
ReadMenuDocumentHandlerBase::getErrorLineString()
154 if ( m_xLocator
.is() )
156 snprintf( buffer
, sizeof(buffer
), "Line: %ld - ", static_cast<long>( m_xLocator
->getLineNumber() ));
157 return OUString::createFromAscii( buffer
);
163 // -----------------------------------------------------------------------------
166 OReadMenuDocumentHandler::OReadMenuDocumentHandler(
167 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
,
170 mxServiceFactory(xServiceFactory
),
171 m_pMenuBar( pMenuBar
),
172 m_nElementDepth( 0 ),
173 m_bMenuBarMode( sal_False
),
174 m_nItemId( ITEMID_START_VALUE
)
179 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& OReadMenuDocumentHandler::getServiceFactory()
182 return mxServiceFactory
;
185 OReadMenuDocumentHandler::~OReadMenuDocumentHandler()
190 void SAL_CALL
OReadMenuDocumentHandler::startDocument(void)
191 throw ( SAXException
, RuntimeException
)
196 void SAL_CALL
OReadMenuDocumentHandler::endDocument(void)
197 throw( SAXException
, RuntimeException
)
199 if ( m_nElementDepth
> 0 )
201 OUString aErrorMessage
= getErrorLineString();
202 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "A closing element is missing!" ));
203 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
208 void SAL_CALL
OReadMenuDocumentHandler::startElement(
209 const OUString
& aName
, const Reference
< XAttributeList
> &xAttrList
)
210 throw( SAXException
, RuntimeException
)
212 if ( m_bMenuBarMode
)
215 m_xReader
->startElement( aName
, xAttrList
);
217 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUBAR
)))
220 m_bMenuBarMode
= sal_True
;
222 // #110897# m_xReader = Reference< XDocumentHandler >( new OReadMenuBarHandler( m_pMenuBar, &m_nItemId ));
223 m_xReader
= Reference
< XDocumentHandler
>( new OReadMenuBarHandler( getServiceFactory(), m_pMenuBar
, &m_nItemId
));
225 m_xReader
->startDocument();
230 void SAL_CALL
OReadMenuDocumentHandler::characters(const rtl::OUString
& aChars
)
231 throw( SAXException
, RuntimeException
)
236 void SAL_CALL
OReadMenuDocumentHandler::endElement( const OUString
& aName
)
237 throw( SAXException
, RuntimeException
)
239 if ( m_bMenuBarMode
)
242 m_xReader
->endElement( aName
);
243 if ( 0 == m_nElementDepth
)
245 m_xReader
->endDocument();
246 m_xReader
= Reference
< XDocumentHandler
>();
247 m_bMenuBarMode
= sal_False
;
248 if ( !aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUBAR
)))
250 OUString aErrorMessage
= getErrorLineString();
251 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menubar expected!" ));
252 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
259 // -----------------------------------------------------------------------------
263 OReadMenuBarHandler::OReadMenuBarHandler(
264 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& xServiceFactory
,
265 MenuBar
* pMenuBar
, USHORT
* pItemId
)
267 mxServiceFactory( xServiceFactory
),
268 m_pMenuBar( pMenuBar
),
269 m_nElementDepth( 0 ),
270 m_bMenuMode( sal_False
),
276 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& OReadMenuBarHandler::getServiceFactory()
279 return mxServiceFactory
;
282 OReadMenuBarHandler::~OReadMenuBarHandler()
287 void SAL_CALL
OReadMenuBarHandler::startDocument(void)
288 throw ( SAXException
, RuntimeException
)
293 void SAL_CALL
OReadMenuBarHandler::endDocument(void)
294 throw( SAXException
, RuntimeException
)
299 void SAL_CALL
OReadMenuBarHandler::startElement(
300 const OUString
& aName
, const Reference
< XAttributeList
> &xAttrList
)
301 throw( SAXException
, RuntimeException
)
306 m_xReader
->startElement( aName
, xAttrList
);
308 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU
)))
316 m_bMenuMode
= sal_True
;
317 PopupMenu
* pMenu
= new PopupMenu();
319 // read attributes for menu
320 for ( int i
=0; i
< xAttrList
->getLength(); i
++ )
322 OUString aName
= xAttrList
->getNameByIndex( i
);
323 OUString aValue
= xAttrList
->getValueByIndex( i
);
324 if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ID
)))
326 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_LABEL
)))
328 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_HELPID
)))
329 nHelpId
= aValue
.toInt32();
332 if ( aCommandId
.getLength() > 0 )
335 if ( aCommandId
.compareTo( aSlotProtocol
, aSlotProtocol
.getLength() ) == 0 )
336 nItemId
= (USHORT
) aCommandId
.copy( aSlotProtocol
.getLength() ).toInt32();
338 nItemId
= ++(*m_pItemId
);
340 m_pMenuBar
->InsertItem( nItemId
, String() );
341 m_pMenuBar
->SetPopupMenu( nItemId
, pMenu
);
342 m_pMenuBar
->SetItemCommand( nItemId
, aCommandId
);
344 m_pMenuBar
->SetHelpId( nItemId
, nHelpId
);
345 if ( aLabel
.getLength() > 0 )
347 m_pMenuBar
->SetItemText( nItemId
, aLabel
);
348 m_pMenuBar
->SetUserValue( nItemId
, MENU_SAVE_LABEL
);
352 m_pMenuBar
->SetUserValue( nItemId
, 0 );
358 OUString aErrorMessage
= getErrorLineString();
359 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "attribute id for element menu required!" ));
360 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
363 m_xReader
= Reference
< XDocumentHandler
>( new OReadMenuHandler( pMenu
, m_pItemId
));
364 m_xReader
->startDocument();
368 OUString aErrorMessage
= getErrorLineString();
369 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "element menu expected!" ));
370 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
375 void SAL_CALL
OReadMenuBarHandler::characters(const rtl::OUString
& aChars
)
376 throw( SAXException
, RuntimeException
)
381 void OReadMenuBarHandler::endElement( const OUString
& aName
)
382 throw( SAXException
, RuntimeException
)
387 if ( 0 == m_nElementDepth
)
389 m_xReader
->endDocument();
390 m_xReader
= Reference
< XDocumentHandler
>();
391 m_bMenuMode
= sal_False
;
392 if ( !aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU
)))
394 OUString aErrorMessage
= getErrorLineString();
395 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menu expected!" ));
396 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
400 m_xReader
->endElement( aName
);
405 // -----------------------------------------------------------------------------
408 OReadMenuHandler::OReadMenuHandler( Menu
* pMenu
, USHORT
* pItemId
) :
410 m_nElementDepth( 0 ),
411 m_bMenuPopupMode( sal_False
),
417 OReadMenuHandler::~OReadMenuHandler()
422 void SAL_CALL
OReadMenuHandler::startDocument(void)
423 throw ( SAXException
, RuntimeException
)
428 void SAL_CALL
OReadMenuHandler::endDocument(void)
429 throw( SAXException
, RuntimeException
)
434 void SAL_CALL
OReadMenuHandler::startElement(
435 const OUString
& aName
, const Reference
< XAttributeList
> &xAttrList
)
436 throw( SAXException
, RuntimeException
)
438 if ( m_bMenuPopupMode
)
441 m_xReader
->startElement( aName
, xAttrList
);
443 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUPOPUP
)))
446 m_bMenuPopupMode
= sal_True
;
447 m_xReader
= Reference
< XDocumentHandler
>( new OReadMenuPopupHandler( m_pMenu
, m_pItemId
));
448 m_xReader
->startDocument();
452 OUString aErrorMessage
= getErrorLineString();
453 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "unknown element found!" ));
454 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
459 void SAL_CALL
OReadMenuHandler::characters(const rtl::OUString
& aChars
)
460 throw( SAXException
, RuntimeException
)
465 void SAL_CALL
OReadMenuHandler::endElement( const OUString
& aName
)
466 throw( SAXException
, RuntimeException
)
468 if ( m_bMenuPopupMode
)
471 if ( 0 == m_nElementDepth
)
473 m_xReader
->endDocument();
474 m_xReader
= Reference
< XDocumentHandler
>();
475 m_bMenuPopupMode
= sal_False
;
476 if ( !aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUPOPUP
)))
478 OUString aErrorMessage
= getErrorLineString();
479 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menupopup expected!" ));
480 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
484 m_xReader
->endElement( aName
);
489 // -----------------------------------------------------------------------------
492 OReadMenuPopupHandler::OReadMenuPopupHandler( Menu
* pMenu
, USHORT
* pItemId
) :
494 m_nElementDepth( 0 ),
495 m_bMenuMode( sal_False
),
496 m_pItemId( pItemId
),
497 m_nNextElementExpected( ELEM_CLOSE_NONE
)
502 OReadMenuPopupHandler::~OReadMenuPopupHandler()
507 void SAL_CALL
OReadMenuPopupHandler::startDocument(void)
508 throw ( SAXException
, RuntimeException
)
513 void SAL_CALL
OReadMenuPopupHandler::endDocument(void)
514 throw( SAXException
, RuntimeException
)
519 void SAL_CALL
OReadMenuPopupHandler::startElement(
520 const OUString
& aName
, const Reference
< XAttributeList
> &xAttrList
)
521 throw( SAXException
, RuntimeException
)
526 m_xReader
->startElement( aName
, xAttrList
);
527 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU
)))
533 m_bMenuMode
= sal_True
;
534 PopupMenu
* pMenu
= new PopupMenu();
536 // read attributes for menu
537 for ( int i
=0; i
< xAttrList
->getLength(); i
++ )
539 OUString aName
= xAttrList
->getNameByIndex( i
);
540 OUString aValue
= xAttrList
->getValueByIndex( i
);
541 if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ID
)))
543 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_LABEL
)))
545 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_HELPID
)))
546 nHelpId
= aValue
.toInt32();
549 if ( aCommandId
.getLength() > 0 )
552 if ( aCommandId
.compareTo( aSlotProtocol
, aSlotProtocol
.getLength() ) == 0 )
553 nItemId
= (USHORT
) aCommandId
.copy( aSlotProtocol
.getLength() ).toInt32();
555 nItemId
= ++(*m_pItemId
);
557 m_pMenu
->InsertItem( nItemId
, String() );
558 m_pMenu
->SetPopupMenu( nItemId
, pMenu
);
559 m_pMenu
->SetItemCommand( nItemId
, aCommandId
);
561 m_pMenu
->SetHelpId( nItemId
, nHelpId
);
562 if ( aLabel
.getLength() > 0 )
564 m_pMenu
->SetItemText( nItemId
, aLabel
);
565 m_pMenu
->SetUserValue( nItemId
, MENU_SAVE_LABEL
);
569 m_pMenu
->SetUserValue( nItemId
, 0 );
575 OUString aErrorMessage
= getErrorLineString();
576 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "attribute id for element menu required!" ));
577 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
580 m_xReader
= Reference
< XDocumentHandler
>( new OReadMenuHandler( pMenu
, m_pItemId
));
581 m_xReader
->startDocument();
583 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUITEM
)))
589 // read attributes for menu item
590 for ( int i
=0; i
< xAttrList
->getLength(); i
++ )
592 OUString aName
= xAttrList
->getNameByIndex( i
);
593 OUString aValue
= xAttrList
->getValueByIndex( i
);
594 if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ID
)))
596 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_LABEL
)))
598 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_HELPID
)))
599 nHelpId
= aValue
.toInt32();
602 if ( aCommandId
.getLength() > 0 )
605 if ( aCommandId
.compareTo( aSlotProtocol
, aSlotProtocol
.getLength() ) == 0 )
606 nItemId
= (USHORT
) aCommandId
.copy( aSlotProtocol
.getLength() ).toInt32();
608 nItemId
= ++(*m_pItemId
);
610 m_pMenu
->InsertItem( nItemId
, String() );
611 m_pMenu
->SetItemCommand( nItemId
, aCommandId
);
613 m_pMenu
->SetHelpId( nItemId
, nHelpId
);
614 if ( aLabel
.getLength() > 0 )
616 m_pMenu
->SetItemText( nItemId
, aLabel
);
617 m_pMenu
->SetUserValue( nItemId
, MENU_SAVE_LABEL
);
621 m_pMenu
->SetUserValue( nItemId
, 0 );
625 m_nNextElementExpected
= ELEM_CLOSE_MENUITEM
;
627 else if ( aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUSEPARATOR
)))
629 m_pMenu
->InsertSeparator();
630 m_nNextElementExpected
= ELEM_CLOSE_MENUSEPARATOR
;
634 OUString aErrorMessage
= getErrorLineString();
635 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "unknown element found!" ));
636 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
641 void SAL_CALL
OReadMenuPopupHandler::characters(const rtl::OUString
& aChars
)
642 throw( SAXException
, RuntimeException
)
647 void SAL_CALL
OReadMenuPopupHandler::endElement( const OUString
& aName
)
648 throw( SAXException
, RuntimeException
)
653 if ( 0 == m_nElementDepth
)
655 m_xReader
->endDocument();
656 m_xReader
= Reference
< XDocumentHandler
>();
657 m_bMenuMode
= sal_False
;
658 if ( !aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENU
)))
660 OUString aErrorMessage
= getErrorLineString();
661 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menu expected!" ));
662 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
666 m_xReader
->endElement( aName
);
670 if ( m_nNextElementExpected
== ELEM_CLOSE_MENUITEM
)
672 if ( !aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUITEM
)))
674 OUString aErrorMessage
= getErrorLineString();
675 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menuitem expected!" ));
676 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
679 else if ( m_nNextElementExpected
== ELEM_CLOSE_MENUSEPARATOR
)
681 if ( !aName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ELEMENT_MENUSEPARATOR
)))
683 OUString aErrorMessage
= getErrorLineString();
684 aErrorMessage
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "closing element menuseparator expected!" ));
685 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
689 m_nNextElementExpected
= ELEM_CLOSE_NONE
;
694 // --------------------------------- Write XML ---------------------------------
697 OWriteMenuDocumentHandler::OWriteMenuDocumentHandler( MenuBar
* pMenu
, Reference
< XDocumentHandler
> rxWriteDocumentHandler
) :
699 m_xWriteDocumentHandler( rxWriteDocumentHandler
)
701 m_xEmptyList
= Reference
< XAttributeList
>( (XAttributeList
*)new AttributeListImpl
, UNO_QUERY
);
702 m_aAttributeType
= OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA
));
706 OWriteMenuDocumentHandler::~OWriteMenuDocumentHandler()
711 void OWriteMenuDocumentHandler::WriteMenuDocument()
712 throw ( SAXException
, RuntimeException
)
714 AttributeListImpl
* pList
= new AttributeListImpl
;
715 Reference
< XAttributeList
> rList( (XAttributeList
*) pList
, UNO_QUERY
);
717 m_xWriteDocumentHandler
->startDocument();
719 // write DOCTYPE line!
720 Reference
< XExtendedDocumentHandler
> xExtendedDocHandler( m_xWriteDocumentHandler
, UNO_QUERY
);
721 if ( xExtendedDocHandler
.is() )
723 xExtendedDocHandler
->unknown( OUString( RTL_CONSTASCII_USTRINGPARAM( MENUBAR_DOCTYPE
)) );
724 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
727 pList
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_MENU
)),
729 OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_MENU
)) );
731 pList
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID
)),
733 OUString( RTL_CONSTASCII_USTRINGPARAM( "menubar" )) );
735 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUBAR
)), pList
);
736 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
738 WriteMenu( m_pMenuBar
);
740 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
741 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUBAR
)) );
742 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
743 m_xWriteDocumentHandler
->endDocument();
747 void OWriteMenuDocumentHandler::WriteMenu( Menu
* pMenu
)
748 throw ( SAXException
, RuntimeException
)
750 USHORT nItemCount
= pMenu
->GetItemCount();
751 BOOL bSeparator
= FALSE
;
753 for ( USHORT nItemPos
= 0; nItemPos
< nItemCount
; nItemPos
++ )
755 USHORT nItemId
= pMenu
->GetItemId( nItemPos
);
757 PopupMenu
* pPopupMenu
= pMenu
->GetPopupMenu( nItemId
);
760 OUString aItemCommand
= pMenu
->GetItemCommand( nItemId
);
762 if ( nItemId
== SID_NEWDOCDIRECT
||
763 nItemId
== SID_AUTOPILOTMENU
)
765 // special popup menus (filled during runtime) must be saved as a menuitem!!!
766 WriteMenuItem( pMenu
, nItemId
);
769 else if ( nItemId
== SID_FORMATMENU
)
771 // special popup menu - must be written as empty popup!
772 AttributeListImpl
* pListMenu
= new AttributeListImpl
;
773 Reference
< XAttributeList
> xListMenu( (XAttributeList
*)pListMenu
, UNO_QUERY
);
775 String
aCommand( pMenu
->GetItemCommand( nItemId
) );
776 if ( !aCommand
.Len() )
778 aCommand
= String::CreateFromAscii("slot:");
779 aCommand
+= String::CreateFromInt32( nItemId
);
782 pListMenu
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID
)),
786 // if ( pMenu->GetUserValue( nItemId ) & MENU_SAVE_LABEL )
787 pListMenu
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_LABEL
)),
789 pMenu
->GetItemText( nItemId
) );
791 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENU
)), xListMenu
);
792 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
793 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUPOPUP
)), m_xEmptyList
);
794 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
795 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUPOPUP
)) );
796 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
797 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENU
)) );
798 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
801 else if ( !AddonPopupMenu::IsCommandURLPrefix ( aItemCommand
))
803 AttributeListImpl
* pListMenu
= new AttributeListImpl
;
804 Reference
< XAttributeList
> xListMenu( (XAttributeList
*)pListMenu
, UNO_QUERY
);
806 String
aCommand( pMenu
->GetItemCommand( nItemId
) );
807 if ( !aCommand
.Len() )
809 aCommand
= String::CreateFromAscii("slot:");
810 aCommand
+= String::CreateFromInt32( nItemId
);
813 pListMenu
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID
)),
817 // if ( pMenu->GetUserValue( nItemId ) & MENU_SAVE_LABEL )
818 pListMenu
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_LABEL
)),
820 pMenu
->GetItemText( nItemId
) );
822 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
823 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENU
)), xListMenu
);
824 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
825 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUPOPUP
)), m_xEmptyList
);
826 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
828 WriteMenu( pPopupMenu
);
830 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
831 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUPOPUP
)) );
832 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
833 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENU
)) );
834 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
840 if ( pMenu
->GetItemType( nItemPos
) != MENUITEM_SEPARATOR
)
842 // don't save special menu items for (window list and pickup list, add-ons )
843 if ( !MenuConfiguration::IsPickListItemId( nItemId
) &&
844 !MenuConfiguration::IsWindowListItemId( nItemId
) &&
845 !AddonMenuManager::IsAddonMenuId( nItemId
))
848 WriteMenuItem( pMenu
, nItemId
);
851 else if ( !bSeparator
)
853 // Don't write two separators together
854 WriteMenuSeparator();
862 void OWriteMenuDocumentHandler::WriteMenuItem( Menu
* pMenu
, USHORT nItemId
)
864 AttributeListImpl
* pList
= new AttributeListImpl
;
865 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
867 String
aCommand( pMenu
->GetItemCommand( nItemId
) );
868 if ( !aCommand
.Len() )
870 aCommand
= String::CreateFromAscii("slot:");
871 aCommand
+= String::CreateFromInt32( nItemId
);
874 pList
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_ID
)),
878 ULONG nHelpId
= pMenu
->GetHelpId( nItemId
);
881 pList
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_HELPID
)),
883 OUString::valueOf( sal_Int64( nHelpId
)) );
886 // if ( pMenu->GetUserValue( nItemId ) & MENU_SAVE_LABEL )
887 pList
->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_NS_LABEL
)),
889 pMenu
->GetItemText( nItemId
));
891 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
892 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUITEM
)), xList
);
893 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
894 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUITEM
)) );
898 void OWriteMenuDocumentHandler::WriteMenuSeparator()
900 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
901 m_xWriteDocumentHandler
->startElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUSEPARATOR
)), m_xEmptyList
);
902 m_xWriteDocumentHandler
->ignorableWhitespace( OUString() );
903 m_xWriteDocumentHandler
->endElement( OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_MENUSEPARATOR
)) );
906 } // namespace framework