tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / framework / source / fwe / xml / toolboxdocumenthandler.cxx
blob48e30561531e4a896405c33f289c3fa75ce0bfe7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xml/toolboxdocumenthandler.hxx>
21 #include <xml/toolboxconfigurationdefines.hxx>
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>
31 #include <sal/config.h>
32 #include <sal/macros.h>
33 #include <vcl/settings.hxx>
34 #include <rtl/ref.hxx>
35 #include <rtl/ustrbuf.hxx>
37 #include <comphelper/propertysequence.hxx>
38 #include <comphelper/propertyvalue.hxx>
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::xml::sax;
45 constexpr OUStringLiteral TOOLBAR_DOCTYPE = u"<!DOCTYPE toolbar:toolbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"toolbar.dtd\">";
47 namespace framework
50 // Property names of a menu/menu item ItemDescriptor
51 constexpr OUString ITEM_DESCRIPTOR_COMMANDURL = u"CommandURL"_ustr;
52 constexpr OUString ITEM_DESCRIPTOR_LABEL = u"Label"_ustr;
53 constexpr OUString ITEM_DESCRIPTOR_TYPE = u"Type"_ustr;
54 constexpr OUString ITEM_DESCRIPTOR_STYLE = u"Style"_ustr;
55 constexpr OUString ITEM_DESCRIPTOR_VISIBLE = u"IsVisible"_ustr;
57 static void ExtractToolbarParameters( const Sequence< PropertyValue >& rProp,
58 OUString& rCommandURL,
59 OUString& rLabel,
60 sal_Int16& rStyle,
61 bool& rVisible,
62 sal_Int16& rType )
64 for ( const PropertyValue& rEntry : rProp )
66 if ( rEntry.Name == ITEM_DESCRIPTOR_COMMANDURL )
67 rEntry.Value >>= rCommandURL;
68 else if ( rEntry.Name == ITEM_DESCRIPTOR_LABEL )
69 rEntry.Value >>= rLabel;
70 else if ( rEntry.Name == ITEM_DESCRIPTOR_TYPE )
71 rEntry.Value >>= rType;
72 else if ( rEntry.Name == ITEM_DESCRIPTOR_VISIBLE )
73 rEntry.Value >>= rVisible;
74 else if ( rEntry.Name == ITEM_DESCRIPTOR_STYLE )
75 rEntry.Value >>= rStyle;
79 namespace {
81 struct ToolboxStyleItem
83 sal_Int16 nBit;
84 OUString attrName;
89 constexpr ToolboxStyleItem Styles[ ] = {
90 { css::ui::ItemStyle::RADIO_CHECK, ATTRIBUTE_ITEMSTYLE_RADIO },
91 { css::ui::ItemStyle::ALIGN_LEFT, ATTRIBUTE_ITEMSTYLE_LEFT },
92 { css::ui::ItemStyle::AUTO_SIZE, ATTRIBUTE_ITEMSTYLE_AUTO },
93 { css::ui::ItemStyle::REPEAT, ATTRIBUTE_ITEMSTYLE_REPEAT },
94 { css::ui::ItemStyle::DROPDOWN_ONLY, ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY },
95 { css::ui::ItemStyle::DROP_DOWN, ATTRIBUTE_ITEMSTYLE_DROPDOWN },
96 { css::ui::ItemStyle::ICON, ATTRIBUTE_ITEMSTYLE_IMAGE },
97 { css::ui::ItemStyle::TEXT, ATTRIBUTE_ITEMSTYLE_TEXT },
100 sal_Int32 const nStyleItemEntries = SAL_N_ELEMENTS(Styles);
102 namespace {
104 struct ToolBarEntryProperty
106 OReadToolBoxDocumentHandler::ToolBox_XML_Namespace nNamespace;
107 OUString aEntryName;
112 ToolBarEntryProperty constexpr ToolBoxEntries[OReadToolBoxDocumentHandler::TB_XML_ENTRY_COUNT] =
114 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, u"toolbar"_ustr },
115 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, u"toolbaritem"_ustr },
116 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, u"toolbarspace"_ustr },
117 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, u"toolbarbreak"_ustr },
118 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, u"toolbarseparator"_ustr },
119 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_TEXT },
120 { OReadToolBoxDocumentHandler::TB_NS_XLINK, ATTRIBUTE_URL },
121 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_VISIBLE },
122 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_ITEMSTYLE },
123 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_UINAME },
126 OReadToolBoxDocumentHandler::OReadToolBoxDocumentHandler( const Reference< XIndexContainer >& rItemContainer ) :
127 m_rItemContainer( rItemContainer ),
128 m_aType( ITEM_DESCRIPTOR_TYPE ),
129 m_aLabel( ITEM_DESCRIPTOR_LABEL ),
130 m_aStyle( ITEM_DESCRIPTOR_STYLE ),
131 m_aIsVisible( ITEM_DESCRIPTOR_VISIBLE ),
132 m_aCommandURL( ITEM_DESCRIPTOR_COMMANDURL )
134 // create hash map
135 for ( int i = 0; i < TB_XML_ENTRY_COUNT; i++ )
137 if ( ToolBoxEntries[i].nNamespace == TB_NS_TOOLBAR )
139 OUString temp = XMLNS_TOOLBAR XMLNS_FILTER_SEPARATOR +
140 ToolBoxEntries[i].aEntryName;
141 m_aToolBoxMap.emplace( temp, static_cast<ToolBox_XML_Entry>(i) );
143 else
145 OUString temp = XMLNS_XLINK XMLNS_FILTER_SEPARATOR +
146 ToolBoxEntries[i].aEntryName;
147 m_aToolBoxMap.emplace( temp, static_cast<ToolBox_XML_Entry>(i) );
151 m_bToolBarStartFound = false;
152 m_bToolBarItemStartFound = false;
153 m_bToolBarSpaceStartFound = false;
154 m_bToolBarBreakStartFound = false;
155 m_bToolBarSeparatorStartFound = false;
158 OReadToolBoxDocumentHandler::~OReadToolBoxDocumentHandler()
162 // XDocumentHandler
163 void SAL_CALL OReadToolBoxDocumentHandler::startDocument()
167 void SAL_CALL OReadToolBoxDocumentHandler::endDocument()
169 if ( m_bToolBarStartFound )
171 OUString aErrorMessage = getErrorLineString() + "No matching start or end element 'toolbar' found!";
172 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
176 void SAL_CALL OReadToolBoxDocumentHandler::startElement(
177 const OUString& aName, const Reference< XAttributeList > &xAttribs )
179 ToolBoxHashMap::const_iterator pToolBoxEntry = m_aToolBoxMap.find( aName );
180 if ( pToolBoxEntry == m_aToolBoxMap.end() )
181 return;
183 switch ( pToolBoxEntry->second )
185 case TB_ELEMENT_TOOLBAR:
187 if ( m_bToolBarStartFound )
189 OUString aErrorMessage = getErrorLineString() + "Element 'toolbar:toolbar' cannot be embedded into 'toolbar:toolbar'!";
190 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
192 else
194 // Check if we have a UI name set in our XML file
195 OUString aUIName;
196 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
198 pToolBoxEntry = m_aToolBoxMap.find( xAttribs->getNameByIndex( n ) );
199 if ( pToolBoxEntry != m_aToolBoxMap.end() )
201 switch ( pToolBoxEntry->second )
203 case TB_ATTRIBUTE_UINAME:
204 aUIName = xAttribs->getValueByIndex( n );
205 break;
206 default:
207 break;
211 if ( !aUIName.isEmpty() )
213 // Try to set UI name as a container property
214 Reference< XPropertySet > xPropSet( m_rItemContainer, UNO_QUERY );
215 if ( xPropSet.is() )
219 xPropSet->setPropertyValue(u"UIName"_ustr, Any( aUIName ) );
221 catch ( const UnknownPropertyException& )
228 m_bToolBarStartFound = true;
230 break;
232 case TB_ELEMENT_TOOLBARITEM:
234 if ( !m_bToolBarStartFound )
236 OUString aErrorMessage = getErrorLineString() + "Element 'toolbar:toolbaritem' must be embedded into element 'toolbar:toolbar'!";
237 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
240 if ( m_bToolBarSeparatorStartFound ||
241 m_bToolBarBreakStartFound ||
242 m_bToolBarSpaceStartFound ||
243 m_bToolBarItemStartFound )
245 OUString aErrorMessage = getErrorLineString() + "Element toolbar:toolbaritem is not a container!";
246 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
249 bool bAttributeURL = false;
251 m_bToolBarItemStartFound = true;
252 OUString aLabel;
253 OUString aCommandURL;
254 sal_uInt16 nItemBits( 0 );
255 bool bVisible( true );
257 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
259 pToolBoxEntry = m_aToolBoxMap.find( xAttribs->getNameByIndex( n ) );
260 if ( pToolBoxEntry != m_aToolBoxMap.end() )
262 switch ( pToolBoxEntry->second )
264 case TB_ATTRIBUTE_TEXT:
266 aLabel = xAttribs->getValueByIndex( n );
268 break;
270 case TB_ATTRIBUTE_URL:
272 bAttributeURL = true;
273 aCommandURL = xAttribs->getValueByIndex( n );
275 break;
277 case TB_ATTRIBUTE_VISIBLE:
279 if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_TRUE )
280 bVisible = true;
281 else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_FALSE )
282 bVisible = false;
283 else
285 OUString aErrorMessage = getErrorLineString() + "Attribute toolbar:visible must have value 'true' or 'false'!";
286 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
289 break;
291 case TB_ATTRIBUTE_STYLE:
293 // read space separated item style list
294 OUString aTemp = xAttribs->getValueByIndex( n );
295 sal_Int32 nIndex = 0;
299 OUString aToken = aTemp.getToken( 0, ' ', nIndex );
300 if ( !aToken.isEmpty() )
302 if ( aToken == ATTRIBUTE_ITEMSTYLE_RADIO )
303 nItemBits |= css::ui::ItemStyle::RADIO_CHECK;
304 else if ( aToken == ATTRIBUTE_ITEMSTYLE_LEFT )
305 nItemBits |= css::ui::ItemStyle::ALIGN_LEFT;
306 else if ( aToken == ATTRIBUTE_ITEMSTYLE_AUTOSIZE )
307 nItemBits |= css::ui::ItemStyle::AUTO_SIZE;
308 else if ( aToken == ATTRIBUTE_ITEMSTYLE_REPEAT )
309 nItemBits |= css::ui::ItemStyle::REPEAT;
310 else if ( aToken == ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY )
311 nItemBits |= css::ui::ItemStyle::DROPDOWN_ONLY;
312 else if ( aToken == ATTRIBUTE_ITEMSTYLE_DROPDOWN )
313 nItemBits |= css::ui::ItemStyle::DROP_DOWN;
314 else if ( aToken == ATTRIBUTE_ITEMSTYLE_TEXT )
315 nItemBits |= css::ui::ItemStyle::TEXT;
316 else if ( aToken == ATTRIBUTE_ITEMSTYLE_IMAGE )
317 nItemBits |= css::ui::ItemStyle::ICON;
320 while ( nIndex >= 0 );
322 break;
324 default:
325 break;
328 } // for
330 if ( !bAttributeURL )
332 OUString aErrorMessage = getErrorLineString() + "Required attribute toolbar:url must have a value!";
333 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
336 if ( !aCommandURL.isEmpty() )
338 //fix for fdo#39370
339 /// check whether RTL interface or not
340 if(AllSettings::GetLayoutRTL()){
341 if (aCommandURL == ".uno:ParaLeftToRight")
342 aCommandURL = ".uno:ParaRightToLeft";
343 else if (aCommandURL == ".uno:ParaRightToLeft")
344 aCommandURL = ".uno:ParaLeftToRight";
345 else if (aCommandURL == ".uno:LeftPara")
346 aCommandURL = ".uno:RightPara";
347 else if (aCommandURL == ".uno:RightPara")
348 aCommandURL = ".uno:LeftPara";
349 else if (aCommandURL == ".uno:AlignLeft")
350 aCommandURL = ".uno:AlignRight";
351 else if (aCommandURL == ".uno:AlignRight")
352 aCommandURL = ".uno:AlignLeft";
353 else if (aCommandURL == ".uno:WrapLeft")
354 aCommandURL = ".uno:WrapRight";
355 else if (aCommandURL == ".uno:WrapRight")
356 aCommandURL = ".uno:WrapLeft";
359 auto aToolbarItemProp( comphelper::InitPropertySequence( {
360 { m_aCommandURL, css::uno::Any( aCommandURL ) },
361 { m_aLabel, css::uno::Any( aLabel ) },
362 { m_aType, css::uno::Any( css::ui::ItemType::DEFAULT ) },
363 { m_aStyle, css::uno::Any( nItemBits ) },
364 { m_aIsVisible, css::uno::Any( bVisible ) },
365 } ) );
367 m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), Any( aToolbarItemProp ) );
370 break;
372 case TB_ELEMENT_TOOLBARSPACE:
374 if ( m_bToolBarSeparatorStartFound ||
375 m_bToolBarBreakStartFound ||
376 m_bToolBarSpaceStartFound ||
377 m_bToolBarItemStartFound )
379 OUString aErrorMessage = getErrorLineString() + "Element toolbar:toolbarspace is not a container!";
380 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
383 m_bToolBarSpaceStartFound = true;
385 Sequence< PropertyValue > aToolbarItemProp{
386 comphelper::makePropertyValue(m_aCommandURL, OUString()),
387 comphelper::makePropertyValue(m_aType, css::ui::ItemType::SEPARATOR_SPACE)
390 m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), Any( aToolbarItemProp ) );
392 break;
394 case TB_ELEMENT_TOOLBARBREAK:
396 if ( m_bToolBarSeparatorStartFound ||
397 m_bToolBarBreakStartFound ||
398 m_bToolBarSpaceStartFound ||
399 m_bToolBarItemStartFound )
401 OUString aErrorMessage = getErrorLineString() + "Element toolbar:toolbarbreak is not a container!";
402 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
405 m_bToolBarBreakStartFound = true;
407 Sequence< PropertyValue > aToolbarItemProp{
408 comphelper::makePropertyValue(m_aCommandURL, OUString()),
409 comphelper::makePropertyValue(m_aType, css::ui::ItemType::SEPARATOR_LINEBREAK)
412 m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), Any( aToolbarItemProp ) );
414 break;
416 case TB_ELEMENT_TOOLBARSEPARATOR:
418 if ( m_bToolBarSeparatorStartFound ||
419 m_bToolBarBreakStartFound ||
420 m_bToolBarSpaceStartFound ||
421 m_bToolBarItemStartFound )
423 OUString aErrorMessage = getErrorLineString() + "Element toolbar:toolbarseparator is not a container!";
424 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
427 m_bToolBarSeparatorStartFound = true;
429 Sequence< PropertyValue > aToolbarItemProp{
430 comphelper::makePropertyValue(m_aCommandURL, OUString()),
431 comphelper::makePropertyValue(m_aType, css::ui::ItemType::SEPARATOR_LINE)
434 m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), Any( aToolbarItemProp ) );
436 break;
438 default:
439 break;
443 void SAL_CALL OReadToolBoxDocumentHandler::endElement(const OUString& aName)
445 ToolBoxHashMap::const_iterator pToolBoxEntry = m_aToolBoxMap.find( aName );
446 if ( pToolBoxEntry == m_aToolBoxMap.end() )
447 return;
449 switch ( pToolBoxEntry->second )
451 case TB_ELEMENT_TOOLBAR:
453 if ( !m_bToolBarStartFound )
455 OUString aErrorMessage = getErrorLineString() + "End element 'toolbar' found, but no start element 'toolbar'";
456 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
459 m_bToolBarStartFound = false;
461 break;
463 case TB_ELEMENT_TOOLBARITEM:
465 if ( !m_bToolBarItemStartFound )
467 OUString aErrorMessage = getErrorLineString() + "End element 'toolbar:toolbaritem' found, but no start element 'toolbar:toolbaritem'";
468 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
471 m_bToolBarItemStartFound = false;
473 break;
475 case TB_ELEMENT_TOOLBARBREAK:
477 if ( !m_bToolBarBreakStartFound )
479 OUString aErrorMessage = getErrorLineString() + "End element 'toolbar:toolbarbreak' found, but no start element 'toolbar:toolbarbreak'";
480 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
483 m_bToolBarBreakStartFound = false;
485 break;
487 case TB_ELEMENT_TOOLBARSPACE:
489 if ( !m_bToolBarSpaceStartFound )
491 OUString aErrorMessage = getErrorLineString() + "End element 'toolbar:toolbarspace' found, but no start element 'toolbar:toolbarspace'";
492 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
495 m_bToolBarSpaceStartFound = false;
497 break;
499 case TB_ELEMENT_TOOLBARSEPARATOR:
501 if ( !m_bToolBarSeparatorStartFound )
503 OUString aErrorMessage = getErrorLineString() + "End element 'toolbar:toolbarseparator' found, but no start element 'toolbar:toolbarseparator'";
504 throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
507 m_bToolBarSeparatorStartFound = false;
509 break;
511 default: break;
515 void SAL_CALL OReadToolBoxDocumentHandler::characters(const OUString&)
519 void SAL_CALL OReadToolBoxDocumentHandler::ignorableWhitespace(const OUString&)
523 void SAL_CALL OReadToolBoxDocumentHandler::processingInstruction(
524 const OUString& /*aTarget*/, const OUString& /*aData*/ )
528 void SAL_CALL OReadToolBoxDocumentHandler::setDocumentLocator(
529 const Reference< XLocator > &xLocator)
531 m_xLocator = xLocator;
534 OUString OReadToolBoxDocumentHandler::getErrorLineString()
536 if ( m_xLocator.is() )
537 return "Line: " + OUString::number( m_xLocator->getLineNumber() ) + " - ";
538 else
539 return OUString();
542 // OWriteToolBoxDocumentHandler
544 OWriteToolBoxDocumentHandler::OWriteToolBoxDocumentHandler(
545 const Reference< XIndexAccess >& rItemAccess,
546 Reference< XDocumentHandler > const & rWriteDocumentHandler ) :
547 m_xWriteDocumentHandler( rWriteDocumentHandler ),
548 m_rItemAccess( rItemAccess )
550 m_xEmptyList = new ::comphelper::AttributeList;
551 m_aXMLXlinkNS = XMLNS_XLINK_PREFIX;
552 m_aXMLToolbarNS = XMLNS_TOOLBAR_PREFIX;
555 OWriteToolBoxDocumentHandler::~OWriteToolBoxDocumentHandler()
559 void OWriteToolBoxDocumentHandler::WriteToolBoxDocument()
561 m_xWriteDocumentHandler->startDocument();
563 // write DOCTYPE line!
564 Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
565 if ( xExtendedDocHandler.is() )
567 xExtendedDocHandler->unknown( TOOLBAR_DOCTYPE );
568 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
571 OUString aUIName;
572 Reference< XPropertySet > xPropSet( m_rItemAccess, UNO_QUERY );
573 if ( xPropSet.is() )
577 xPropSet->getPropertyValue(u"UIName"_ustr) >>= aUIName;
579 catch ( const UnknownPropertyException& )
584 rtl::Reference<::comphelper::AttributeList> pList = new ::comphelper::AttributeList;
586 pList->AddAttribute( ATTRIBUTE_XMLNS_TOOLBAR,
587 u"" XMLNS_TOOLBAR ""_ustr );
589 pList->AddAttribute( ATTRIBUTE_XMLNS_XLINK,
590 u"" XMLNS_XLINK ""_ustr );
592 if ( !aUIName.isEmpty() )
593 pList->AddAttribute( m_aXMLToolbarNS + ATTRIBUTE_UINAME,
594 aUIName );
596 m_xWriteDocumentHandler->startElement( ELEMENT_NS_TOOLBAR, pList );
597 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
599 sal_Int32 nItemCount = m_rItemAccess->getCount();
600 Any aAny;
602 for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ )
604 Sequence< PropertyValue > aProps;
605 aAny = m_rItemAccess->getByIndex( nItemPos );
606 if ( aAny >>= aProps )
608 OUString aCommandURL;
609 OUString aLabel;
610 bool bVisible( true );
611 sal_Int16 nType( css::ui::ItemType::DEFAULT );
612 sal_Int16 nStyle( 0 );
614 ExtractToolbarParameters( aProps, aCommandURL, aLabel, nStyle, bVisible, nType );
615 if ( nType == css::ui::ItemType::DEFAULT )
616 WriteToolBoxItem( aCommandURL, aLabel, nStyle, bVisible );
617 else if ( nType == css::ui::ItemType::SEPARATOR_SPACE )
618 WriteToolBoxSpace();
619 else if ( nType == css::ui::ItemType::SEPARATOR_LINE )
620 WriteToolBoxSeparator();
621 else if ( nType == css::ui::ItemType::SEPARATOR_LINEBREAK )
622 WriteToolBoxBreak();
626 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
627 m_xWriteDocumentHandler->endElement( ELEMENT_NS_TOOLBAR );
628 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
629 m_xWriteDocumentHandler->endDocument();
632 // protected member functions
634 void OWriteToolBoxDocumentHandler::WriteToolBoxItem(
635 const OUString& rCommandURL,
636 const OUString& rLabel,
637 sal_Int16 nStyle,
638 bool bVisible )
640 rtl::Reference<::comphelper::AttributeList> pList = new ::comphelper::AttributeList;
642 if ( m_aAttributeURL.isEmpty() )
644 m_aAttributeURL = m_aXMLXlinkNS + ATTRIBUTE_URL;
647 // save required attribute (URL)
648 pList->AddAttribute( m_aAttributeURL, rCommandURL );
650 if ( !rLabel.isEmpty() )
652 pList->AddAttribute( m_aXMLToolbarNS + ATTRIBUTE_TEXT,
653 rLabel );
656 if ( !bVisible )
658 pList->AddAttribute( m_aXMLToolbarNS + ATTRIBUTE_VISIBLE,
659 ATTRIBUTE_BOOLEAN_FALSE );
662 if ( nStyle > 0 )
664 OUStringBuffer aValue;
665 const ToolboxStyleItem* pStyle = Styles;
667 for ( sal_Int32 nIndex = 0; nIndex < nStyleItemEntries; ++nIndex, ++pStyle )
669 if ( nStyle & pStyle->nBit )
671 if ( !aValue.isEmpty() )
672 aValue.append(" ");
673 aValue.append( pStyle->attrName );
676 pList->AddAttribute( m_aXMLToolbarNS + ATTRIBUTE_ITEMSTYLE,
677 aValue.makeStringAndClear() );
680 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
681 m_xWriteDocumentHandler->startElement( ELEMENT_NS_TOOLBARITEM, pList );
682 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
683 m_xWriteDocumentHandler->endElement( ELEMENT_NS_TOOLBARITEM );
686 void OWriteToolBoxDocumentHandler::WriteToolBoxSpace()
688 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
689 m_xWriteDocumentHandler->startElement( ELEMENT_NS_TOOLBARSPACE, m_xEmptyList );
690 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
691 m_xWriteDocumentHandler->endElement( ELEMENT_NS_TOOLBARSPACE );
694 void OWriteToolBoxDocumentHandler::WriteToolBoxBreak()
696 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
697 m_xWriteDocumentHandler->startElement( ELEMENT_NS_TOOLBARBREAK, m_xEmptyList );
698 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
699 m_xWriteDocumentHandler->endElement( ELEMENT_NS_TOOLBARBREAK );
702 void OWriteToolBoxDocumentHandler::WriteToolBoxSeparator()
704 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
705 m_xWriteDocumentHandler->startElement( ELEMENT_NS_TOOLBARSEPARATOR, m_xEmptyList );
706 m_xWriteDocumentHandler->ignorableWhitespace( OUString() );
707 m_xWriteDocumentHandler->endElement( ELEMENT_NS_TOOLBARSEPARATOR );
710 } // namespace framework
712 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */