23#include <com/sun/star/xml/sax/SAXException.hpp>
24#include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
25#include <com/sun/star/ui/ItemType.hpp>
26#include <com/sun/star/ui/ItemStyle.hpp>
27#include <com/sun/star/beans/XPropertySet.hpp>
28#include <com/sun/star/container/XIndexAccess.hpp>
29#include <com/sun/star/container/XIndexContainer.hpp>
35#include <rtl/ustrbuf.hxx>
46constexpr OUStringLiteral
TOOLBAR_DOCTYPE =
u"<!DOCTYPE toolbar:toolbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"toolbar.dtd\">";
59 OUString& rCommandURL,
65 for (
const PropertyValue& rEntry : rProp )
68 rEntry.Value >>= rCommandURL;
70 rEntry.Value >>= rLabel;
72 rEntry.Value >>= rType;
74 rEntry.Value >>= rVisible;
76 rEntry.Value >>= rStyle;
82struct ToolboxStyleItem
90constexpr ToolboxStyleItem
Styles[ ] = {
105struct ToolBarEntryProperty
128 m_rItemContainer( rItemContainer ),
172 OUString aErrorMessage =
getErrorLineString() +
"No matching start or end element 'toolbar' found!";
173 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
178 const OUString& aName,
const Reference< XAttributeList > &xAttribs )
184 switch ( pToolBoxEntry->second )
190 OUString aErrorMessage =
getErrorLineString() +
"Element 'toolbar:toolbar' cannot be embedded into 'toolbar:toolbar'!";
191 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
197 for ( sal_Int16
n = 0;
n < xAttribs->getLength();
n++ )
199 pToolBoxEntry =
m_aToolBoxMap.find( xAttribs->getNameByIndex(
n ) );
202 switch ( pToolBoxEntry->second )
205 aUIName = xAttribs->getValueByIndex(
n );
220 xPropSet->setPropertyValue(
"UIName",
Any(
aUIName ) );
222 catch (
const UnknownPropertyException& )
237 OUString aErrorMessage =
getErrorLineString() +
"Element 'toolbar:toolbaritem' must be embedded into element 'toolbar:toolbar'!";
238 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
246 OUString aErrorMessage =
getErrorLineString() +
"Element toolbar:toolbaritem is not a container!";
247 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
250 bool bAttributeURL =
false;
254 OUString aCommandURL;
255 sal_uInt16 nItemBits( 0 );
258 for ( sal_Int16
n = 0;
n < xAttribs->getLength();
n++ )
260 pToolBoxEntry =
m_aToolBoxMap.find( xAttribs->getNameByIndex(
n ) );
263 switch ( pToolBoxEntry->second )
267 aLabel = xAttribs->getValueByIndex(
n );
273 bAttributeURL =
true;
274 aCommandURL = xAttribs->getValueByIndex(
n );
286 OUString aErrorMessage =
getErrorLineString() +
"Attribute toolbar:visible must have value 'true' or 'false'!";
287 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
295 OUString aTemp = xAttribs->getValueByIndex(
n );
300 OUString aToken = aTemp.getToken( 0,
' ',
nIndex );
301 if ( !aToken.isEmpty() )
304 nItemBits |= css::ui::ItemStyle::RADIO_CHECK;
306 nItemBits |= css::ui::ItemStyle::ALIGN_LEFT;
308 nItemBits |= css::ui::ItemStyle::AUTO_SIZE;
310 nItemBits |= css::ui::ItemStyle::REPEAT;
312 nItemBits |= css::ui::ItemStyle::DROPDOWN_ONLY;
314 nItemBits |= css::ui::ItemStyle::DROP_DOWN;
316 nItemBits |= css::ui::ItemStyle::TEXT;
318 nItemBits |= css::ui::ItemStyle::ICON;
331 if ( !bAttributeURL )
333 OUString aErrorMessage =
getErrorLineString() +
"Required attribute toolbar:url must have a value!";
334 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
337 if ( !aCommandURL.isEmpty() )
342 if (aCommandURL ==
".uno:ParaLeftToRight")
343 aCommandURL =
".uno:ParaRightToLeft";
344 else if (aCommandURL ==
".uno:ParaRightToLeft")
345 aCommandURL =
".uno:ParaLeftToRight";
346 else if (aCommandURL ==
".uno:LeftPara")
347 aCommandURL =
".uno:RightPara";
348 else if (aCommandURL ==
".uno:RightPara")
349 aCommandURL =
".uno:LeftPara";
350 else if (aCommandURL ==
".uno:AlignLeft")
351 aCommandURL =
".uno:AlignRight";
352 else if (aCommandURL ==
".uno:AlignRight")
353 aCommandURL =
".uno:AlignLeft";
354 else if (aCommandURL ==
".uno:WrapLeft")
355 aCommandURL =
".uno:WrapRight";
356 else if (aCommandURL ==
".uno:WrapRight")
357 aCommandURL =
".uno:WrapLeft";
363 {
m_aType, css::uno::Any( css::ui::ItemType::DEFAULT ) },
364 {
m_aStyle, css::uno::Any( nItemBits ) },
380 OUString aErrorMessage =
getErrorLineString() +
"Element toolbar:toolbarspace is not a container!";
381 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
386 Sequence< PropertyValue > aToolbarItemProp{
402 OUString aErrorMessage =
getErrorLineString() +
"Element toolbar:toolbarbreak is not a container!";
403 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
408 Sequence< PropertyValue > aToolbarItemProp{
424 OUString aErrorMessage =
getErrorLineString() +
"Element toolbar:toolbarseparator is not a container!";
425 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
430 Sequence< PropertyValue > aToolbarItemProp{
450 switch ( pToolBoxEntry->second )
456 OUString aErrorMessage =
getErrorLineString() +
"End element 'toolbar' found, but no start element 'toolbar'";
457 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
468 OUString aErrorMessage =
getErrorLineString() +
"End element 'toolbar:toolbaritem' found, but no start element 'toolbar:toolbaritem'";
469 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
480 OUString aErrorMessage =
getErrorLineString() +
"End element 'toolbar:toolbarbreak' found, but no start element 'toolbar:toolbarbreak'";
481 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
492 OUString aErrorMessage =
getErrorLineString() +
"End element 'toolbar:toolbarspace' found, but no start element 'toolbar:toolbarspace'";
493 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
504 OUString aErrorMessage =
getErrorLineString() +
"End element 'toolbar:toolbarseparator' found, but no start element 'toolbar:toolbarseparator'";
505 throw SAXException( aErrorMessage, Reference< XInterface >(),
Any() );
525 const OUString& ,
const OUString& )
530 const Reference< XLocator > &xLocator)
538 return "Line: " + OUString::number(
m_xLocator->getLineNumber() ) +
" - ";
546 const Reference< XIndexAccess >& rItemAccess,
547 Reference< XDocumentHandler >
const & rWriteDocumentHandler ) :
548 m_xWriteDocumentHandler( rWriteDocumentHandler ),
549 m_rItemAccess( rItemAccess )
566 if ( xExtendedDocHandler.is() )
573 Reference< XPropertySet > xPropSet(
m_rItemAccess, UNO_QUERY );
578 xPropSet->getPropertyValue(
"UIName") >>=
aUIName;
580 catch (
const UnknownPropertyException& )
603 for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ )
605 Sequence< PropertyValue > aProps;
607 if ( aAny >>= aProps )
609 OUString aCommandURL;
612 sal_Int16
nType( css::ui::ItemType::DEFAULT );
613 sal_Int16 nStyle( 0 );
616 if (
nType == css::ui::ItemType::DEFAULT )
618 else if (
nType == css::ui::ItemType::SEPARATOR_SPACE )
620 else if (
nType == css::ui::ItemType::SEPARATOR_LINE )
622 else if (
nType == css::ui::ItemType::SEPARATOR_LINEBREAK )
636 const OUString& rCommandURL,
637 const OUString& rLabel,
651 if ( !rLabel.isEmpty() )
665 OUStringBuffer aValue;
666 const ToolboxStyleItem* pStyle =
Styles;
670 if ( nStyle & pStyle->nBit )
672 if ( !aValue.isEmpty() )
674 aValue.append( OUString(pStyle->attrName) );
678 aValue.makeStringAndClear() );
static bool GetLayoutRTL()
#define SAL_N_ELEMENTS(arr)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral ITEM_DESCRIPTOR_STYLE
constexpr OUStringLiteral ITEM_DESCRIPTOR_COMMANDURL
sal_Int32 const nStyleItemEntries
static void ExtractToolbarParameters(const Sequence< PropertyValue > &rProp, OUString &rCommandURL, OUString &rLabel, sal_Int16 &rStyle, bool &rVisible, sal_Int16 &rType)
constexpr ToolboxStyleItem Styles[]
constexpr OUStringLiteral ITEM_DESCRIPTOR_LABEL
constexpr OUStringLiteral ITEM_DESCRIPTOR_TYPE
ToolBarEntryProperty const ToolBoxEntries[OReadToolBoxDocumentHandler::TB_XML_ENTRY_COUNT]
constexpr OUStringLiteral ITEM_DESCRIPTOR_VISIBLE
constexpr OUStringLiteral ATTRIBUTE_BOOLEAN_TRUE
constexpr OUStringLiteral ATTRIBUTE_BOOLEAN_FALSE
constexpr OUStringLiteral ATTRIBUTE_XMLNS_XLINK
constexpr OUStringLiteral XMLNS_XLINK_PREFIX