1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <stdio.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir // my own includes 35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 38*cdf0e10cSrcweir #include <xml/toolboxdocumenthandler.hxx> 39*cdf0e10cSrcweir #include <macros/debug.hxx> 40*cdf0e10cSrcweir #include <xml/toolboxconfigurationdefines.hxx> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43*cdf0e10cSrcweir // interface includes 44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 45*cdf0e10cSrcweir #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/ui/ItemType.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ui/ItemStyle.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51*cdf0e10cSrcweir // other includes 52*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include <sal/config.h> 55*cdf0e10cSrcweir #include <vcl/svapp.hxx> 56*cdf0e10cSrcweir #include <vcl/toolbox.hxx> 57*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir #include <comphelper/attributelist.hxx> 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 62*cdf0e10cSrcweir // namespace 63*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 66*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 67*cdf0e10cSrcweir using namespace ::com::sun::star::container; 68*cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir #define TOOLBAR_DOCTYPE "<!DOCTYPE toolbar:toolbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"toolbar.dtd\">" 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir namespace framework 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // Property names of a menu/menu item ItemDescriptor 77*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL"; 78*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_HELPURL[] = "HelpURL"; 79*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_TOOLTIP[] = "Tooltip"; 80*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_LABEL[] = "Label"; 81*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_TYPE[] = "Type"; 82*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; 83*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_VISIBLE[] = "IsVisible"; 84*cdf0e10cSrcweir static const char ITEM_DESCRIPTOR_WIDTH[] = "Width"; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir static void ExtractToolbarParameters( const Sequence< PropertyValue > rProp, 87*cdf0e10cSrcweir ::rtl::OUString& rCommandURL, 88*cdf0e10cSrcweir ::rtl::OUString& rLabel, 89*cdf0e10cSrcweir ::rtl::OUString& rHelpURL, 90*cdf0e10cSrcweir ::rtl::OUString& rTooltip, 91*cdf0e10cSrcweir sal_Int16& rStyle, 92*cdf0e10cSrcweir sal_Int16& rWidth, 93*cdf0e10cSrcweir sal_Bool& rVisible, 94*cdf0e10cSrcweir sal_Int16& rType ) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < rProp.getLength(); i++ ) 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL )) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir rProp[i].Value >>= rCommandURL; 101*cdf0e10cSrcweir rCommandURL = rCommandURL.intern(); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_HELPURL )) 104*cdf0e10cSrcweir rProp[i].Value >>= rHelpURL; 105*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TOOLTIP )) 106*cdf0e10cSrcweir rProp[i].Value >>= rTooltip; 107*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_LABEL )) 108*cdf0e10cSrcweir rProp[i].Value >>= rLabel; 109*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_TYPE )) 110*cdf0e10cSrcweir rProp[i].Value >>= rType; 111*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_VISIBLE )) 112*cdf0e10cSrcweir rProp[i].Value >>= rVisible; 113*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_WIDTH )) 114*cdf0e10cSrcweir rProp[i].Value >>= rWidth; 115*cdf0e10cSrcweir else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE )) 116*cdf0e10cSrcweir rProp[i].Value >>= rStyle; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir struct ToolboxStyleItem 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir sal_Int16 nBit; 123*cdf0e10cSrcweir const char* attrName; 124*cdf0e10cSrcweir }; 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir ToolboxStyleItem Styles[ ] = { 127*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::RADIO_CHECK, ATTRIBUTE_ITEMSTYLE_RADIO }, 128*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::ALIGN_LEFT, ATTRIBUTE_ITEMSTYLE_LEFT }, 129*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::AUTO_SIZE, ATTRIBUTE_ITEMSTYLE_AUTO }, 130*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::REPEAT, ATTRIBUTE_ITEMSTYLE_REPEAT }, 131*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY, ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY }, 132*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::DROP_DOWN, ATTRIBUTE_ITEMSTYLE_DROPDOWN }, 133*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::ICON, ATTRIBUTE_ITEMSTYLE_IMAGE }, 134*cdf0e10cSrcweir { ::com::sun::star::ui::ItemStyle::TEXT, ATTRIBUTE_ITEMSTYLE_TEXT }, 135*cdf0e10cSrcweir }; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir sal_Int32 nStyleItemEntries = sizeof( Styles ) / sizeof( Styles[ 0 ] ); 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir struct ToolBarEntryProperty 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir OReadToolBoxDocumentHandler::ToolBox_XML_Namespace nNamespace; 142*cdf0e10cSrcweir char aEntryName[20]; 143*cdf0e10cSrcweir }; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir ToolBarEntryProperty ToolBoxEntries[OReadToolBoxDocumentHandler::TB_XML_ENTRY_COUNT] = 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ELEMENT_TOOLBAR }, 148*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ELEMENT_TOOLBARITEM }, 149*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ELEMENT_TOOLBARSPACE }, 150*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ELEMENT_TOOLBARBREAK }, 151*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ELEMENT_TOOLBARSEPARATOR }, 152*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_TEXT }, 153*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_BITMAP }, 154*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_XLINK, ATTRIBUTE_URL }, 155*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_ITEMBITS }, 156*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_VISIBLE }, 157*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_WIDTH }, 158*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_USER }, 159*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_HELPID }, 160*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_ITEMSTYLE }, 161*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_UINAME }, 162*cdf0e10cSrcweir { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR, ATTRIBUTE_TOOLTIP }, 163*cdf0e10cSrcweir }; 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir OReadToolBoxDocumentHandler::OReadToolBoxDocumentHandler( const Reference< XIndexContainer >& rItemContainer ) : 166*cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ), 167*cdf0e10cSrcweir m_rItemContainer( rItemContainer ), 168*cdf0e10cSrcweir m_aType( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE )), 169*cdf0e10cSrcweir m_aLabel( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL )), 170*cdf0e10cSrcweir m_aStyle( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_STYLE )), 171*cdf0e10cSrcweir m_aHelpURL( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL )), 172*cdf0e10cSrcweir m_aTooltip( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TOOLTIP )), 173*cdf0e10cSrcweir m_aIsVisible( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_VISIBLE )), 174*cdf0e10cSrcweir m_aCommandURL( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL )) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir ::rtl::OUString aNamespaceToolBar( RTL_CONSTASCII_USTRINGPARAM( XMLNS_TOOLBAR )); 177*cdf0e10cSrcweir ::rtl::OUString aNamespaceXLink( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK )); 178*cdf0e10cSrcweir ::rtl::OUString aSeparator( RTL_CONSTASCII_USTRINGPARAM( XMLNS_FILTER_SEPARATOR )); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir // create hash map 181*cdf0e10cSrcweir for ( int i = 0; i < (int)TB_XML_ENTRY_COUNT; i++ ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if ( ToolBoxEntries[i].nNamespace == TB_NS_TOOLBAR ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir ::rtl::OUString temp( aNamespaceToolBar ); 186*cdf0e10cSrcweir temp += aSeparator; 187*cdf0e10cSrcweir temp += ::rtl::OUString::createFromAscii( ToolBoxEntries[i].aEntryName ); 188*cdf0e10cSrcweir m_aToolBoxMap.insert( ToolBoxHashMap::value_type( temp, (ToolBox_XML_Entry)i ) ); 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir else 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir ::rtl::OUString temp( aNamespaceXLink ); 193*cdf0e10cSrcweir temp += aSeparator; 194*cdf0e10cSrcweir temp += ::rtl::OUString::createFromAscii( ToolBoxEntries[i].aEntryName ); 195*cdf0e10cSrcweir m_aToolBoxMap.insert( ToolBoxHashMap::value_type( temp, (ToolBox_XML_Entry)i ) ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir // pre-calculate a hash code for all style strings to speed up xml read process 200*cdf0e10cSrcweir m_nHashCode_Style_Radio = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_RADIO ).hashCode(); 201*cdf0e10cSrcweir m_nHashCode_Style_Auto = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_AUTO ).hashCode(); 202*cdf0e10cSrcweir m_nHashCode_Style_Left = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_LEFT ).hashCode(); 203*cdf0e10cSrcweir m_nHashCode_Style_AutoSize = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_AUTOSIZE ).hashCode(); 204*cdf0e10cSrcweir m_nHashCode_Style_DropDown = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_DROPDOWN ).hashCode(); 205*cdf0e10cSrcweir m_nHashCode_Style_Repeat = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_REPEAT ).hashCode(); 206*cdf0e10cSrcweir m_nHashCode_Style_DropDownOnly = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY ).hashCode(); 207*cdf0e10cSrcweir m_nHashCode_Style_Text = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_TEXT ).hashCode(); 208*cdf0e10cSrcweir m_nHashCode_Style_Image = ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_IMAGE ).hashCode(); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir m_bToolBarStartFound = sal_False; 211*cdf0e10cSrcweir m_bToolBarEndFound = sal_False; 212*cdf0e10cSrcweir m_bToolBarItemStartFound = sal_False; 213*cdf0e10cSrcweir m_bToolBarSpaceStartFound = sal_False; 214*cdf0e10cSrcweir m_bToolBarBreakStartFound = sal_False; 215*cdf0e10cSrcweir m_bToolBarSeparatorStartFound = sal_False; 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir OReadToolBoxDocumentHandler::~OReadToolBoxDocumentHandler() 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir // XDocumentHandler 223*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::startDocument(void) 224*cdf0e10cSrcweir throw ( SAXException, RuntimeException ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::endDocument(void) 229*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir if (( m_bToolBarStartFound && !m_bToolBarEndFound ) || 234*cdf0e10cSrcweir ( !m_bToolBarStartFound && m_bToolBarEndFound ) ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 237*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'toolbar' found!" )); 238*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::startElement( 243*cdf0e10cSrcweir const ::rtl::OUString& aName, const Reference< XAttributeList > &xAttribs ) 244*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir ToolBoxHashMap::const_iterator pToolBoxEntry = m_aToolBoxMap.find( aName ) ; 249*cdf0e10cSrcweir if ( pToolBoxEntry != m_aToolBoxMap.end() ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir switch ( pToolBoxEntry->second ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir case TB_ELEMENT_TOOLBAR: 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir if ( m_bToolBarStartFound ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 258*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'toolbar:toolbar' cannot be embeded into 'toolbar:toolbar'!" )); 259*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 260*cdf0e10cSrcweir } 261*cdf0e10cSrcweir else 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir // Check if we have a UI name set in our XML file 264*cdf0e10cSrcweir ::rtl::OUString aUIName; 265*cdf0e10cSrcweir for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir pToolBoxEntry = m_aToolBoxMap.find( xAttribs->getNameByIndex( n ) ); 268*cdf0e10cSrcweir if ( pToolBoxEntry != m_aToolBoxMap.end() ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir switch ( pToolBoxEntry->second ) 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir case TB_ATTRIBUTE_UINAME: 273*cdf0e10cSrcweir aUIName = xAttribs->getValueByIndex( n ); 274*cdf0e10cSrcweir break; 275*cdf0e10cSrcweir default: 276*cdf0e10cSrcweir break; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir if ( aUIName.getLength() > 0 ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir // Try to set UI name as a container property 284*cdf0e10cSrcweir Reference< XPropertySet > xPropSet( m_rItemContainer, UNO_QUERY ); 285*cdf0e10cSrcweir if ( xPropSet.is() ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir try 288*cdf0e10cSrcweir { 289*cdf0e10cSrcweir xPropSet->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" )), makeAny( aUIName ) ); 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir catch ( UnknownPropertyException& ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir m_bToolBarStartFound = sal_True; 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir break; 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARITEM: 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir if ( !m_bToolBarStartFound ) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 307*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'toolbar:toolbaritem' must be embeded into element 'toolbar:toolbar'!" )); 308*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir if ( m_bToolBarSeparatorStartFound || 312*cdf0e10cSrcweir m_bToolBarBreakStartFound || 313*cdf0e10cSrcweir m_bToolBarSpaceStartFound || 314*cdf0e10cSrcweir m_bToolBarItemStartFound ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 317*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbaritem is not a container!" )); 318*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir ::rtl::OUString aAttribute; 322*cdf0e10cSrcweir sal_Bool bAttributeURL = sal_False; 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir m_bToolBarItemStartFound = sal_True; 325*cdf0e10cSrcweir ::rtl::OUString aLabel; 326*cdf0e10cSrcweir ::rtl::OUString aCommandURL; 327*cdf0e10cSrcweir ::rtl::OUString aHelpURL; 328*cdf0e10cSrcweir ::rtl::OUString aTooltip; 329*cdf0e10cSrcweir ::rtl::OUString aBitmapName; 330*cdf0e10cSrcweir sal_uInt16 nItemBits( 0 ); 331*cdf0e10cSrcweir sal_uInt16 nWidth( 0 ); 332*cdf0e10cSrcweir sal_uInt16 nUserDef( 0 ); 333*cdf0e10cSrcweir sal_Bool bVisible( sal_True ); 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir pToolBoxEntry = m_aToolBoxMap.find( xAttribs->getNameByIndex( n ) ); 338*cdf0e10cSrcweir if ( pToolBoxEntry != m_aToolBoxMap.end() ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir switch ( pToolBoxEntry->second ) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir case TB_ATTRIBUTE_TEXT: 343*cdf0e10cSrcweir { 344*cdf0e10cSrcweir aLabel = xAttribs->getValueByIndex( n ); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir break; 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir case TB_ATTRIBUTE_BITMAP: 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir aBitmapName = xAttribs->getValueByIndex( n ); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir break; 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir case TB_ATTRIBUTE_URL: 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir bAttributeURL = sal_True; 357*cdf0e10cSrcweir aCommandURL = xAttribs->getValueByIndex( n ).intern(); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir break; 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir case TB_ATTRIBUTE_ITEMBITS: 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir nItemBits = (sal_uInt16)(xAttribs->getValueByIndex( n ).toInt32()); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir break; 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir case TB_ATTRIBUTE_VISIBLE: 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) ) 370*cdf0e10cSrcweir bVisible = sal_True; 371*cdf0e10cSrcweir else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE )) ) 372*cdf0e10cSrcweir bVisible = sal_False; 373*cdf0e10cSrcweir else 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 376*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute toolbar:visible must have value 'true' or 'false'!" )); 377*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir break; 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir case TB_ATTRIBUTE_WIDTH: 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir nWidth = (sal_uInt16)(xAttribs->getValueByIndex( n ).toInt32()); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir break; 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir case TB_ATTRIBUTE_USER: 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir nUserDef = (sal_uInt16)(xAttribs->getValueByIndex( n ).toInt32()); 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir break; 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir case TB_ATTRIBUTE_HELPID: 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir aHelpURL = xAttribs->getValueByIndex( n ); 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir break; 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir case TB_ATTRIBUTE_TOOLTIP: 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir aTooltip = xAttribs->getValueByIndex( n ); 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir break; 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir case TB_ATTRIBUTE_STYLE: 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir // read space seperated item style list 409*cdf0e10cSrcweir ::rtl::OUString aTemp = xAttribs->getValueByIndex( n ); 410*cdf0e10cSrcweir sal_Int32 nIndex = 0; 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir do 413*cdf0e10cSrcweir { 414*cdf0e10cSrcweir ::rtl::OUString aToken = aTemp.getToken( 0, ' ', nIndex ); 415*cdf0e10cSrcweir if ( aToken.getLength() > 0 ) 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir sal_Int32 nHashCode = aToken.hashCode(); 418*cdf0e10cSrcweir if ( nHashCode == m_nHashCode_Style_Radio ) 419*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::RADIO_CHECK; 420*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_Left ) 421*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::ALIGN_LEFT; 422*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_AutoSize ) 423*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::AUTO_SIZE; 424*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_DropDown ) 425*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::DROP_DOWN; 426*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_Repeat ) 427*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::REPEAT; 428*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_DropDownOnly ) 429*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY; 430*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_DropDown ) 431*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::DROP_DOWN; 432*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_Text ) 433*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::TEXT; 434*cdf0e10cSrcweir else if ( nHashCode == m_nHashCode_Style_Image ) 435*cdf0e10cSrcweir nItemBits |= ::com::sun::star::ui::ItemStyle::ICON; 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir while ( nIndex >= 0 ); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir break; 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir default: 443*cdf0e10cSrcweir break; 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir } // for 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir if ( !bAttributeURL ) 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 451*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute toolbar:url must have a value!" )); 452*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir if ( aCommandURL.getLength() > 0 ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir Sequence< PropertyValue > aToolbarItemProp( 7 ); 458*cdf0e10cSrcweir aToolbarItemProp[0].Name = m_aCommandURL; 459*cdf0e10cSrcweir aToolbarItemProp[1].Name = m_aHelpURL; 460*cdf0e10cSrcweir aToolbarItemProp[2].Name = m_aLabel; 461*cdf0e10cSrcweir aToolbarItemProp[3].Name = m_aType; 462*cdf0e10cSrcweir aToolbarItemProp[4].Name = m_aStyle; 463*cdf0e10cSrcweir aToolbarItemProp[5].Name = m_aIsVisible; 464*cdf0e10cSrcweir aToolbarItemProp[6].Name = m_aTooltip; 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir aToolbarItemProp[0].Value <<= aCommandURL; 467*cdf0e10cSrcweir aToolbarItemProp[1].Value <<= aHelpURL; 468*cdf0e10cSrcweir aToolbarItemProp[2].Value <<= aLabel; 469*cdf0e10cSrcweir aToolbarItemProp[3].Value = makeAny( ::com::sun::star::ui::ItemType::DEFAULT ); 470*cdf0e10cSrcweir aToolbarItemProp[4].Value <<= nItemBits; 471*cdf0e10cSrcweir aToolbarItemProp[5].Value <<= bVisible; 472*cdf0e10cSrcweir aToolbarItemProp[6].Value <<= aTooltip; 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), makeAny( aToolbarItemProp ) ); 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir break; 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARSPACE: 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir if ( m_bToolBarSeparatorStartFound || 482*cdf0e10cSrcweir m_bToolBarBreakStartFound || 483*cdf0e10cSrcweir m_bToolBarSpaceStartFound || 484*cdf0e10cSrcweir m_bToolBarItemStartFound ) 485*cdf0e10cSrcweir { 486*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 487*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbarspace is not a container!" )); 488*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir 491*cdf0e10cSrcweir m_bToolBarSpaceStartFound = sal_True; 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir Sequence< PropertyValue > aToolbarItemProp( 2 ); 494*cdf0e10cSrcweir aToolbarItemProp[0].Name = m_aCommandURL; 495*cdf0e10cSrcweir aToolbarItemProp[1].Name = m_aType; 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir aToolbarItemProp[0].Value <<= rtl::OUString(); 498*cdf0e10cSrcweir aToolbarItemProp[1].Value <<= ::com::sun::star::ui::ItemType::SEPARATOR_SPACE; 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), makeAny( aToolbarItemProp ) ); 501*cdf0e10cSrcweir } 502*cdf0e10cSrcweir break; 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARBREAK: 505*cdf0e10cSrcweir { 506*cdf0e10cSrcweir if ( m_bToolBarSeparatorStartFound || 507*cdf0e10cSrcweir m_bToolBarBreakStartFound || 508*cdf0e10cSrcweir m_bToolBarSpaceStartFound || 509*cdf0e10cSrcweir m_bToolBarItemStartFound ) 510*cdf0e10cSrcweir { 511*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 512*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbarbreak is not a container!" )); 513*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir m_bToolBarBreakStartFound = sal_True; 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir Sequence< PropertyValue > aToolbarItemProp( 2 ); 519*cdf0e10cSrcweir aToolbarItemProp[0].Name = m_aCommandURL; 520*cdf0e10cSrcweir aToolbarItemProp[1].Name = m_aType; 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir aToolbarItemProp[0].Value <<= rtl::OUString(); 523*cdf0e10cSrcweir aToolbarItemProp[1].Value <<= ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK; 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), makeAny( aToolbarItemProp ) ); 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir break; 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARSEPARATOR: 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir if ( m_bToolBarSeparatorStartFound || 532*cdf0e10cSrcweir m_bToolBarBreakStartFound || 533*cdf0e10cSrcweir m_bToolBarSpaceStartFound || 534*cdf0e10cSrcweir m_bToolBarItemStartFound ) 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 537*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbarseparator is not a container!" )); 538*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir m_bToolBarSeparatorStartFound = sal_True; 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir Sequence< PropertyValue > aToolbarItemProp( 2 ); 544*cdf0e10cSrcweir aToolbarItemProp[0].Name = m_aCommandURL; 545*cdf0e10cSrcweir aToolbarItemProp[1].Name = m_aType; 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir aToolbarItemProp[0].Value <<= rtl::OUString(); 548*cdf0e10cSrcweir aToolbarItemProp[1].Value <<= ::com::sun::star::ui::ItemType::SEPARATOR_LINE; 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir m_rItemContainer->insertByIndex( m_rItemContainer->getCount(), makeAny( aToolbarItemProp ) ); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir break; 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir default: 555*cdf0e10cSrcweir break; 556*cdf0e10cSrcweir } 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir } 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::endElement(const ::rtl::OUString& aName) 561*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir ToolBoxHashMap::const_iterator pToolBoxEntry = m_aToolBoxMap.find( aName ) ; 566*cdf0e10cSrcweir if ( pToolBoxEntry != m_aToolBoxMap.end() ) 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir switch ( pToolBoxEntry->second ) 569*cdf0e10cSrcweir { 570*cdf0e10cSrcweir case TB_ELEMENT_TOOLBAR: 571*cdf0e10cSrcweir { 572*cdf0e10cSrcweir if ( !m_bToolBarStartFound ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 575*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar' found, but no start element 'toolbar'" )); 576*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir 579*cdf0e10cSrcweir m_bToolBarStartFound = sal_False; 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir break; 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARITEM: 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir if ( !m_bToolBarItemStartFound ) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 588*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbaritem' found, but no start element 'toolbar:toolbaritem'" )); 589*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir m_bToolBarItemStartFound = sal_False; 593*cdf0e10cSrcweir } 594*cdf0e10cSrcweir break; 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARBREAK: 597*cdf0e10cSrcweir { 598*cdf0e10cSrcweir if ( !m_bToolBarBreakStartFound ) 599*cdf0e10cSrcweir { 600*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 601*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbarbreak' found, but no start element 'toolbar:toolbarbreak'" )); 602*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir m_bToolBarBreakStartFound = sal_False; 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir break; 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARSPACE: 610*cdf0e10cSrcweir { 611*cdf0e10cSrcweir if ( !m_bToolBarSpaceStartFound ) 612*cdf0e10cSrcweir { 613*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 614*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbarspace' found, but no start element 'toolbar:toolbarspace'" )); 615*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir m_bToolBarSpaceStartFound = sal_False; 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir break; 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir case TB_ELEMENT_TOOLBARSEPARATOR: 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir if ( !m_bToolBarSeparatorStartFound ) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir ::rtl::OUString aErrorMessage = getErrorLineString(); 627*cdf0e10cSrcweir aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbarseparator' found, but no start element 'toolbar:toolbarseparator'" )); 628*cdf0e10cSrcweir throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); 629*cdf0e10cSrcweir } 630*cdf0e10cSrcweir 631*cdf0e10cSrcweir m_bToolBarSeparatorStartFound = sal_False; 632*cdf0e10cSrcweir } 633*cdf0e10cSrcweir break; 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir default: 636*cdf0e10cSrcweir break; 637*cdf0e10cSrcweir } 638*cdf0e10cSrcweir } 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::characters(const ::rtl::OUString&) 642*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 643*cdf0e10cSrcweir { 644*cdf0e10cSrcweir } 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::ignorableWhitespace(const ::rtl::OUString&) 647*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 648*cdf0e10cSrcweir { 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::processingInstruction( 652*cdf0e10cSrcweir const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ ) 653*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 654*cdf0e10cSrcweir { 655*cdf0e10cSrcweir } 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir void SAL_CALL OReadToolBoxDocumentHandler::setDocumentLocator( 658*cdf0e10cSrcweir const Reference< XLocator > &xLocator) 659*cdf0e10cSrcweir throw( SAXException, RuntimeException ) 660*cdf0e10cSrcweir { 661*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 662*cdf0e10cSrcweir 663*cdf0e10cSrcweir m_xLocator = xLocator; 664*cdf0e10cSrcweir } 665*cdf0e10cSrcweir 666*cdf0e10cSrcweir ::rtl::OUString OReadToolBoxDocumentHandler::getErrorLineString() 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir char buffer[32]; 671*cdf0e10cSrcweir 672*cdf0e10cSrcweir if ( m_xLocator.is() ) 673*cdf0e10cSrcweir { 674*cdf0e10cSrcweir snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>( m_xLocator->getLineNumber() )); 675*cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( buffer ); 676*cdf0e10cSrcweir } 677*cdf0e10cSrcweir else 678*cdf0e10cSrcweir return ::rtl::OUString(); 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir 681*cdf0e10cSrcweir 682*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 683*cdf0e10cSrcweir // OWriteToolBoxDocumentHandler 684*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 685*cdf0e10cSrcweir 686*cdf0e10cSrcweir OWriteToolBoxDocumentHandler::OWriteToolBoxDocumentHandler( 687*cdf0e10cSrcweir const Reference< XIndexAccess >& rItemAccess, 688*cdf0e10cSrcweir Reference< XDocumentHandler >& rWriteDocumentHandler ) : 689*cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ), 690*cdf0e10cSrcweir m_xWriteDocumentHandler( rWriteDocumentHandler ), 691*cdf0e10cSrcweir m_rItemAccess( rItemAccess ) 692*cdf0e10cSrcweir { 693*cdf0e10cSrcweir ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; 694*cdf0e10cSrcweir m_xEmptyList = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY ); 695*cdf0e10cSrcweir m_aAttributeType = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA )); 696*cdf0e10cSrcweir m_aXMLXlinkNS = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX )); 697*cdf0e10cSrcweir m_aXMLToolbarNS = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_TOOLBAR_PREFIX )); 698*cdf0e10cSrcweir } 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir OWriteToolBoxDocumentHandler::~OWriteToolBoxDocumentHandler() 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir } 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir void OWriteToolBoxDocumentHandler::WriteToolBoxDocument() throw 705*cdf0e10cSrcweir ( SAXException, RuntimeException ) 706*cdf0e10cSrcweir { 707*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir m_xWriteDocumentHandler->startDocument(); 710*cdf0e10cSrcweir 711*cdf0e10cSrcweir // write DOCTYPE line! 712*cdf0e10cSrcweir Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY ); 713*cdf0e10cSrcweir if ( xExtendedDocHandler.is() ) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir xExtendedDocHandler->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( TOOLBAR_DOCTYPE )) ); 716*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 717*cdf0e10cSrcweir } 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir ::rtl::OUString aUIName; 720*cdf0e10cSrcweir Reference< XPropertySet > xPropSet( m_rItemAccess, UNO_QUERY ); 721*cdf0e10cSrcweir if ( xPropSet.is() ) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir try 724*cdf0e10cSrcweir { 725*cdf0e10cSrcweir xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName; 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir catch ( UnknownPropertyException& ) 728*cdf0e10cSrcweir { 729*cdf0e10cSrcweir } 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; 733*cdf0e10cSrcweir Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY ); 734*cdf0e10cSrcweir 735*cdf0e10cSrcweir pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_TOOLBAR )), 736*cdf0e10cSrcweir m_aAttributeType, 737*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_TOOLBAR )) ); 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK )), 740*cdf0e10cSrcweir m_aAttributeType, 741*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK )) ); 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir if ( aUIName.getLength() > 0 ) 744*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_UINAME )), 745*cdf0e10cSrcweir m_aAttributeType, 746*cdf0e10cSrcweir aUIName ); 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBAR )), pList ); 749*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir sal_Int32 nItemCount = m_rItemAccess->getCount(); 752*cdf0e10cSrcweir Any aAny; 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ ) 755*cdf0e10cSrcweir { 756*cdf0e10cSrcweir Sequence< PropertyValue > aProps; 757*cdf0e10cSrcweir aAny = m_rItemAccess->getByIndex( nItemPos ); 758*cdf0e10cSrcweir if ( aAny >>= aProps ) 759*cdf0e10cSrcweir { 760*cdf0e10cSrcweir ::rtl::OUString aCommandURL; 761*cdf0e10cSrcweir ::rtl::OUString aLabel; 762*cdf0e10cSrcweir ::rtl::OUString aHelpURL; 763*cdf0e10cSrcweir ::rtl::OUString aTooltip; 764*cdf0e10cSrcweir sal_Bool bVisible( sal_True ); 765*cdf0e10cSrcweir sal_Int16 nType( ::com::sun::star::ui::ItemType::DEFAULT ); 766*cdf0e10cSrcweir sal_Int16 nWidth( 0 ); 767*cdf0e10cSrcweir sal_Int16 nStyle( 0 ); 768*cdf0e10cSrcweir 769*cdf0e10cSrcweir ExtractToolbarParameters( aProps, aCommandURL, aLabel, aHelpURL, aTooltip, nStyle, nWidth, bVisible, nType ); 770*cdf0e10cSrcweir if ( nType == ::com::sun::star::ui::ItemType::DEFAULT ) 771*cdf0e10cSrcweir WriteToolBoxItem( aCommandURL, aLabel, aHelpURL, aTooltip, nStyle, nWidth, bVisible ); 772*cdf0e10cSrcweir else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_SPACE ) 773*cdf0e10cSrcweir WriteToolBoxSpace(); 774*cdf0e10cSrcweir else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINE ) 775*cdf0e10cSrcweir WriteToolBoxSeparator(); 776*cdf0e10cSrcweir else if ( nType == ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK ) 777*cdf0e10cSrcweir WriteToolBoxBreak(); 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 782*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBAR )) ); 783*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 784*cdf0e10cSrcweir m_xWriteDocumentHandler->endDocument(); 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir 787*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 788*cdf0e10cSrcweir // protected member functions 789*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir void OWriteToolBoxDocumentHandler::WriteToolBoxItem( 792*cdf0e10cSrcweir const ::rtl::OUString& rCommandURL, 793*cdf0e10cSrcweir const ::rtl::OUString& rLabel, 794*cdf0e10cSrcweir const ::rtl::OUString& rHelpURL, 795*cdf0e10cSrcweir const ::rtl::OUString& rTooltip, 796*cdf0e10cSrcweir sal_Int16 nStyle, 797*cdf0e10cSrcweir sal_Int16 nWidth, 798*cdf0e10cSrcweir sal_Bool bVisible ) 799*cdf0e10cSrcweir throw ( SAXException, RuntimeException ) 800*cdf0e10cSrcweir { 801*cdf0e10cSrcweir ::comphelper::AttributeList* pList = new ::comphelper::AttributeList; 802*cdf0e10cSrcweir Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY ); 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir if ( m_aAttributeURL.getLength() == 0 ) 805*cdf0e10cSrcweir { 806*cdf0e10cSrcweir m_aAttributeURL = m_aXMLXlinkNS; 807*cdf0e10cSrcweir m_aAttributeURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_URL )); 808*cdf0e10cSrcweir } 809*cdf0e10cSrcweir 810*cdf0e10cSrcweir // save required attribute (URL) 811*cdf0e10cSrcweir pList->AddAttribute( m_aAttributeURL, m_aAttributeType, rCommandURL ); 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir if ( rLabel.getLength() > 0 ) 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TEXT )), 816*cdf0e10cSrcweir m_aAttributeType, 817*cdf0e10cSrcweir rLabel ); 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir if ( bVisible == sal_False ) 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_VISIBLE )), 823*cdf0e10cSrcweir m_aAttributeType, 824*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE )) ); 825*cdf0e10cSrcweir } 826*cdf0e10cSrcweir 827*cdf0e10cSrcweir if ( rHelpURL.getLength() > 0 ) 828*cdf0e10cSrcweir { 829*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HELPID )), 830*cdf0e10cSrcweir m_aAttributeType, 831*cdf0e10cSrcweir rHelpURL ); 832*cdf0e10cSrcweir } 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir if ( rTooltip.getLength() > 0 ) 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TOOLTIP )), 837*cdf0e10cSrcweir m_aAttributeType, 838*cdf0e10cSrcweir rTooltip ); 839*cdf0e10cSrcweir } 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir if ( nStyle > 0 ) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir rtl::OUString aValue; 844*cdf0e10cSrcweir ToolboxStyleItem* pStyle = Styles; 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir for ( sal_Int32 nIndex = 0; nIndex < nStyleItemEntries; ++nIndex, ++pStyle ) 847*cdf0e10cSrcweir { 848*cdf0e10cSrcweir if ( nStyle & pStyle->nBit ) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir if ( aValue.getLength() ) 851*cdf0e10cSrcweir aValue = aValue.concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(" ") ) ); 852*cdf0e10cSrcweir aValue += rtl::OUString::createFromAscii( pStyle->attrName ); 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir } 855*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ITEMSTYLE )), 856*cdf0e10cSrcweir m_aAttributeType, 857*cdf0e10cSrcweir aValue ); 858*cdf0e10cSrcweir } 859*cdf0e10cSrcweir 860*cdf0e10cSrcweir if ( nWidth > 0 ) 861*cdf0e10cSrcweir { 862*cdf0e10cSrcweir pList->AddAttribute( m_aXMLToolbarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_WIDTH )), 863*cdf0e10cSrcweir m_aAttributeType, 864*cdf0e10cSrcweir ::rtl::OUString::valueOf( sal_Int32( nWidth )) ); 865*cdf0e10cSrcweir } 866*cdf0e10cSrcweir 867*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 868*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARITEM )), xList ); 869*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 870*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARITEM )) ); 871*cdf0e10cSrcweir } 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir void OWriteToolBoxDocumentHandler::WriteToolBoxSpace() throw 874*cdf0e10cSrcweir ( SAXException, RuntimeException ) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 877*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSPACE )), m_xEmptyList ); 878*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 879*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSPACE )) ); 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir void OWriteToolBoxDocumentHandler::WriteToolBoxBreak() throw 883*cdf0e10cSrcweir ( SAXException, RuntimeException ) 884*cdf0e10cSrcweir { 885*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 886*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARBREAK )), m_xEmptyList ); 887*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 888*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARBREAK )) ); 889*cdf0e10cSrcweir } 890*cdf0e10cSrcweir 891*cdf0e10cSrcweir void OWriteToolBoxDocumentHandler::WriteToolBoxSeparator() throw 892*cdf0e10cSrcweir ( SAXException, RuntimeException ) 893*cdf0e10cSrcweir { 894*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 895*cdf0e10cSrcweir m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSEPARATOR )), m_xEmptyList ); 896*cdf0e10cSrcweir m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() ); 897*cdf0e10cSrcweir m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSEPARATOR )) ); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir } // namespace framework 901*cdf0e10cSrcweir 902