22#include <rtl/ustrbuf.hxx>
26#include <com/sun/star/xml/sax/SAXException.hpp>
27#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
28#include <com/sun/star/lang/XSingleComponentFactory.hpp>
29#include <com/sun/star/ui/ItemType.hpp>
30#include <com/sun/star/ui/ItemStyle.hpp>
31#include <com/sun/star/beans/PropertyValue.hpp>
37#ifdef ATTRIBUTE_HELPID
38#undef ATTRIBUTE_HELPID
41constexpr OUStringLiteral
XMLNS_MENU =
u"http://openoffice.org/2001/menu";
44constexpr OUStringLiteral
ELEMENT_MENU =
u"http://openoffice.org/2001/menu^menu";
55constexpr OUStringLiteral
ATTRIBUTE_ID =
u"http://openoffice.org/2001/menu^id";
67constexpr OUStringLiteral
MENUBAR_DOCTYPE =
u"<!DOCTYPE menu:menubar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"menubar.dtd\">";
69#define ATTRIBUTE_ITEMSTYLE_TEXT "text"
70#define ATTRIBUTE_ITEMSTYLE_IMAGE "image"
71#define ATTRIBUTE_ITEMSTYLE_RADIO "radio"
112 OUString& rCommandURL,
115 Reference< XIndexAccess >& rSubMenu,
119 for (
const PropertyValue&
p : rProp )
123 p.Value >>= rCommandURL;
127 p.Value >>= rHelpURL;
131 p.Value >>= rSubMenu;
170 const OUString& ,
const OUString& )
175 const Reference< XLocator > &xLocator)
183 return "Line: " + OUString::number(
m_xLocator->getLineNumber() ) +
" - ";
189 Sequence< PropertyValue > &rProps,
const OUString &rCommandURL,
190 const OUString &rHelpId,
const OUString &rLabel, sal_Int16 nItemStyleBits )
192 auto pProps = rProps.getArray();
202 pProps[0].Value <<= rCommandURL;
203 pProps[1].Value <<= rHelpId;
204 pProps[2].Value <<= Reference< XIndexContainer >();
205 pProps[3].Value <<= rLabel;
206 pProps[4].Value <<= nItemStyleBits;
207 pProps[5].Value <<= css::ui::ItemType::DEFAULT;
211 const Reference< XIndexContainer >& rMenuBarContainer )
212: m_nElementDepth( 0 ),
214 m_xMenuBarContainer( rMenuBarContainer ),
215 m_xContainerFactory( rMenuBarContainer, UNO_QUERY )
232 "A closing element is missing!";
233 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
238 const OUString& aName,
const Reference< XAttributeList > &xAttrList )
281 "closing element menubar expected!";
282 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
287 "closing element menupopup expected!";
288 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
294 const Reference< XIndexContainer >& rMenuBarContainer,
295 const Reference< XSingleComponentFactory >& rFactory )
296: m_nElementDepth( 0 ),
297 m_bMenuMode( false ),
298 m_xMenuBarContainer( rMenuBarContainer ),
299 m_xContainerFactory( rFactory )
316 const OUString& rName,
const Reference< XAttributeList > &xAttrList )
321 m_xReader->startElement( rName, xAttrList );
330 sal_Int16 nItemBits(0);
335 Reference< XComponentContext > xComponentContext(
338 Reference< XIndexContainer > xSubItemContainer;
340 xSubItemContainer.set(
m_xContainerFactory->createInstanceWithContext( xComponentContext ), UNO_QUERY );
342 if ( xSubItemContainer.is() )
345 for ( sal_Int16
i=0;
i< xAttrList->getLength();
i++ )
347 OUString
aName = xAttrList->getNameByIndex(
i );
348 const OUString aValue = xAttrList->getValueByIndex(
i );
360 OUString aToken = aValue.getToken( 0,
'+',
nIndex );
361 if ( !aToken.isEmpty() )
364 nItemBits |= css::ui::ItemStyle::TEXT;
366 nItemBits |= css::ui::ItemStyle::ICON;
368 nItemBits |= css::ui::ItemStyle::RADIO_CHECK;
375 if ( !aCommandId.isEmpty() )
377 Sequence< PropertyValue > aSubMenuProp( 6 );
379 aSubMenuProp.getArray()[2].Value <<= xSubItemContainer;
386 "attribute id for element menu required!";
387 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
397 "element menu expected!";
398 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
420 "closing element menu expected!";
421 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
429 const Reference< XIndexContainer >& rMenuContainer,
430 const Reference< XSingleComponentFactory >& rFactory ) :
431 m_nElementDepth( 0 ),
432 m_bMenuPopupMode( false ),
433 m_xMenuContainer( rMenuContainer ),
434 m_xContainerFactory( rFactory )
451 const OUString& aName,
const Reference< XAttributeList > &xAttrList )
468 "unknown element found!";
469 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
491 "closing element menupopup expected!";
492 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
500 const Reference< XIndexContainer >& rMenuContainer,
501 const Reference< XSingleComponentFactory >& rFactory ) :
502 m_nElementDepth( 0 ),
503 m_bMenuMode( false ),
504 m_xMenuContainer( rMenuContainer ),
505 m_xContainerFactory( rFactory ),
507 m_nNextElementExpected( ELEM_CLOSE_NONE )
524 const OUString& rName,
const Reference< XAttributeList > &xAttrList )
529 m_xReader->startElement( rName, xAttrList );
535 sal_Int16 nItemBits(0);
540 Reference< XIndexContainer > xSubItemContainer;
545 for ( sal_Int16
i=0;
i< xAttrList->getLength();
i++ )
547 OUString
aName = xAttrList->getNameByIndex(
i );
548 const OUString aValue = xAttrList->getValueByIndex(
i );
560 OUString aToken = aValue.getToken( 0,
'+',
nIndex );
561 if ( !aToken.isEmpty() )
564 nItemBits |= css::ui::ItemStyle::TEXT;
566 nItemBits |= css::ui::ItemStyle::ICON;
568 nItemBits |= css::ui::ItemStyle::RADIO_CHECK;
576 if ( !aCommandId.isEmpty() )
578 Sequence< PropertyValue > aSubMenuProp( 6 );
580 aSubMenuProp.getArray()[2].Value <<= xSubItemContainer;
587 "attribute id for element menu required!";
588 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
599 sal_Int16 nItemBits(0);
601 for ( sal_Int16
i=0;
i< xAttrList->getLength();
i++ )
603 OUString
aName = xAttrList->getNameByIndex(
i );
604 const OUString aValue = xAttrList->getValueByIndex(
i );
616 OUString aToken = aValue.getToken( 0,
'+',
nIndex );
617 if ( !aToken.isEmpty() )
620 nItemBits |= css::ui::ItemStyle::TEXT;
622 nItemBits |= css::ui::ItemStyle::ICON;
624 nItemBits |= css::ui::ItemStyle::RADIO_CHECK;
632 if ( !aCommandId.isEmpty() )
634 Sequence< PropertyValue > aMenuItem( 6 );
636 aMenuItem.getArray()[2].Value <<= Reference< XIndexContainer >();
655 "unknown element found!";
656 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
677 "closing element menu expected!";
678 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
691 "closing element menuitem expected!";
692 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
700 "closing element menuseparator expected!";
701 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
712 const Reference< XIndexAccess >& rMenuBarContainer,
713 const Reference< XDocumentHandler >& rDocumentHandler,
715 m_xMenuBarContainer( rMenuBarContainer ),
716 m_xWriteDocumentHandler( rDocumentHandler ),
717 m_bIsMenuBar( bIsMenuBar )
747 OUString aRootElement;
765 sal_Int32 nItemCount = rMenuContainer->getCount();
766 bool bSeparator =
false;
769 for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ )
771 Sequence< PropertyValue > aProps;
772 aAny = rMenuContainer->getByIndex( nItemPos );
773 if ( aAny >>= aProps )
775 OUString aCommandURL;
778 sal_Int16
nType( css::ui::ItemType::DEFAULT );
779 sal_Int16 nItemBits( 0 );
780 Reference< XIndexAccess > xSubMenu;
785 if ( !aCommandURL.isEmpty() )
814 if (
nType == css::ui::ItemType::DEFAULT )
816 if ( !aCommandURL.isEmpty() )
822 else if ( !bSeparator )
840 if ( !aHelpURL.isEmpty() )
853 OUStringBuffer aValue;
858 if ( nStyle & pStyle->nBit )
860 if ( !aValue.isEmpty() )
862 aValue.appendAscii( pStyle->attrName );
866 aValue.makeStringAndClear() );
css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory
virtual void SAL_CALL characters(const OUString &aChars) override
virtual ~OReadMenuBarHandler() override
virtual void SAL_CALL startDocument() override
virtual void SAL_CALL endElement(const OUString &aName) override
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
virtual void SAL_CALL endDocument() override
css::uno::Reference< css::container::XIndexContainer > m_xMenuBarContainer
OReadMenuBarHandler(const css::uno::Reference< css::container::XIndexContainer > &rMenuBarContainer, const css::uno::Reference< css::lang::XSingleComponentFactory > &rContainerFactory)
virtual void SAL_CALL startDocument() override
css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
virtual void SAL_CALL characters(const OUString &aChars) override
virtual ~OReadMenuDocumentHandler() override
virtual void SAL_CALL endDocument() override
OReadMenuDocumentHandler(const css::uno::Reference< css::container::XIndexContainer > &rItemContainer)
virtual void SAL_CALL endElement(const OUString &aName) override
css::uno::Reference< css::container::XIndexContainer > m_xMenuBarContainer
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
virtual void SAL_CALL characters(const OUString &aChars) override
virtual ~OReadMenuHandler() override
virtual void SAL_CALL startDocument() override
css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory
OReadMenuHandler(const css::uno::Reference< css::container::XIndexContainer > &rMenuContainer, const css::uno::Reference< css::lang::XSingleComponentFactory > &rContainerFactory)
virtual void SAL_CALL endDocument() override
virtual void SAL_CALL endElement(const OUString &aName) override
css::uno::Reference< css::container::XIndexContainer > m_xMenuContainer
virtual void SAL_CALL characters(const OUString &aChars) override
virtual ~OReadMenuPopupHandler() override
css::uno::Reference< css::uno::XComponentContext > m_xComponentContext
NextElementClose m_nNextElementExpected
virtual void SAL_CALL startElement(const OUString &aName, const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs) override
@ ELEM_CLOSE_MENUSEPARATOR
virtual void SAL_CALL endDocument() override
virtual void SAL_CALL startDocument() override
virtual void SAL_CALL endElement(const OUString &aName) override
OReadMenuPopupHandler(const css::uno::Reference< css::container::XIndexContainer > &rMenuContainer, const css::uno::Reference< css::lang::XSingleComponentFactory > &rContainerFactory)
css::uno::Reference< css::container::XIndexContainer > m_xMenuContainer
css::uno::Reference< css::lang::XSingleComponentFactory > m_xContainerFactory
void WriteMenuSeparator()
void WriteMenu(const css::uno::Reference< css::container::XIndexAccess > &rSubMenuContainer)
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xWriteDocumentHandler
~OWriteMenuDocumentHandler()
void WriteMenuItem(const OUString &aCommandURL, const OUString &aLabel, const OUString &aHelpURL, sal_Int16 nStyle)
css::uno::Reference< css::xml::sax::XAttributeList > m_xEmptyList
OWriteMenuDocumentHandler(const css::uno::Reference< css::container::XIndexAccess > &rMenuBarContainer, const css::uno::Reference< css::xml::sax::XDocumentHandler > &rDocumentHandler, bool bIsMenuBar)
css::uno::Reference< css::container::XIndexAccess > m_xMenuBarContainer
virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator > &xLocator) override
OUString getErrorLineString()
ReadMenuDocumentHandlerBase()
virtual void SAL_CALL ignorableWhitespace(const OUString &aWhitespaces) override
virtual ~ReadMenuDocumentHandlerBase() override
void initPropertyCommon(css::uno::Sequence< css::beans::PropertyValue > &rProps, const OUString &rCommandURL, const OUString &rHelpId, const OUString &rLabel, sal_Int16 nItemStyleBits)
css::uno::Reference< css::xml::sax::XDocumentHandler > m_xReader
virtual void SAL_CALL processingInstruction(const OUString &aTarget, const OUString &aData) override
css::uno::Reference< css::xml::sax::XLocator > m_xLocator
Reference< XComponentContext > const m_xComponentContext
#define SAL_N_ELEMENTS(arr)
constexpr OUStringLiteral ELEMENT_MENU
#define ATTRIBUTE_ITEMSTYLE_RADIO
#define ATTRIBUTE_ITEMSTYLE_TEXT
constexpr OUStringLiteral ITEM_DESCRIPTOR_STYLE
constexpr OUStringLiteral ELEMENT_NS_MENUPOPUP
constexpr OUStringLiteral ELEMENT_MENUSEPARATOR
constexpr OUStringLiteral ITEM_DESCRIPTOR_COMMANDURL
constexpr OUStringLiteral ITEM_DESCRIPTOR_TYPE
constexpr OUStringLiteral ATTRIBUTE_STYLE
constexpr OUStringLiteral ATTRIBUTE_LABEL
constexpr OUStringLiteral ATTRIBUTE_NS_HELPID
constexpr OUStringLiteral ELEMENT_NS_MENUSEPARATOR
constexpr OUStringLiteral ATTRIBUTE_ID
constexpr OUStringLiteral ATTRIBUTE_HELPID
constexpr OUStringLiteral ELEMENT_MENUPOPUP
#define ATTRIBUTE_ITEMSTYLE_IMAGE
constexpr OUStringLiteral MENUBAR_DOCTYPE
constexpr OUStringLiteral ITEM_DESCRIPTOR_HELPURL
constexpr OUStringLiteral ATTRIBUTE_NS_STYLE
constexpr OUStringLiteral ELEMENT_NS_MENUITEM
constexpr OUStringLiteral ATTRIBUTE_NS_ID
constexpr OUStringLiteral ATTRIBUTE_XMLNS_MENU
constexpr OUStringLiteral ITEM_DESCRIPTOR_LABEL
constexpr OUStringLiteral ELEMENT_MENUITEM
constexpr OUStringLiteral ELEMENT_NS_MENUBAR
constexpr OUStringLiteral ATTRIBUTE_NS_LABEL
constexpr OUStringLiteral ELEMENT_MENUBAR
constexpr OUStringLiteral XMLNS_MENU
constexpr OUStringLiteral ITEM_DESCRIPTOR_CONTAINER
constexpr OUStringLiteral ELEMENT_NS_MENU
Reference< XComponentContext > getProcessComponentContext()
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral ITEM_DESCRIPTOR_STYLE
constexpr OUStringLiteral ITEM_DESCRIPTOR_COMMANDURL
sal_Int32 const nMenuStyleItemEntries
constexpr OUStringLiteral ITEM_DESCRIPTOR_LABEL
constexpr OUStringLiteral ITEM_DESCRIPTOR_TYPE
constexpr OUStringLiteral ITEM_DESCRIPTOR_HELPURL
const MenuStyleItem MenuItemStyles[]
static void ExtractMenuParameters(const Sequence< PropertyValue > &rProp, OUString &rCommandURL, OUString &rLabel, OUString &rHelpURL, Reference< XIndexAccess > &rSubMenu, sal_Int16 &rType, sal_Int16 &rStyle)