1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: toolboxdocumenthandler.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
36 //_________________________________________________________________________________________________________________
38 //_________________________________________________________________________________________________________________
40 #include <threadhelp/resetableguard.hxx>
41 #include <xml/toolboxdocumenthandler.hxx>
42 #include <macros/debug.hxx>
43 #include <xml/toolboxconfigurationdefines.hxx>
45 //_________________________________________________________________________________________________________________
47 //_________________________________________________________________________________________________________________
48 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
49 #include <com/sun/star/ui/ItemType.hpp>
50 #include <com/sun/star/ui/ItemStyle.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
53 //_________________________________________________________________________________________________________________
55 //_________________________________________________________________________________________________________________
57 #include <sal/config.h>
58 #include <vcl/svapp.hxx>
59 #include <vcl/toolbox.hxx>
60 #include <rtl/ustrbuf.hxx>
62 #include <comphelper/attributelist.hxx>
64 //_________________________________________________________________________________________________________________
66 //_________________________________________________________________________________________________________________
68 using namespace ::com::sun::star::uno
;
69 using namespace ::com::sun::star::beans
;
70 using namespace ::com::sun::star::container
;
71 using namespace ::com::sun::star::xml::sax
;
74 #define TOOLBAR_DOCTYPE "<!DOCTYPE toolbar:toolbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"toolbar.dtd\">"
79 // Property names of a menu/menu item ItemDescriptor
80 static const char ITEM_DESCRIPTOR_COMMANDURL
[] = "CommandURL";
81 static const char ITEM_DESCRIPTOR_HELPURL
[] = "HelpURL";
82 static const char ITEM_DESCRIPTOR_LABEL
[] = "Label";
83 static const char ITEM_DESCRIPTOR_TYPE
[] = "Type";
84 static const char ITEM_DESCRIPTOR_STYLE
[] = "Style";
85 static const char ITEM_DESCRIPTOR_VISIBLE
[] = "IsVisible";
86 static const char ITEM_DESCRIPTOR_WIDTH
[] = "Width";
88 static void ExtractToolbarParameters( const Sequence
< PropertyValue
> rProp
,
89 ::rtl::OUString
& rCommandURL
,
90 ::rtl::OUString
& rLabel
,
91 ::rtl::OUString
& rHelpURL
,
96 for ( sal_Int32 i
= 0; i
< rProp
.getLength(); i
++ )
98 if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL
))
100 rProp
[i
].Value
>>= rCommandURL
;
101 rCommandURL
= rCommandURL
.intern();
103 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_HELPURL
))
104 rProp
[i
].Value
>>= rHelpURL
;
105 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_LABEL
))
106 rProp
[i
].Value
>>= rLabel
;
107 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_TYPE
))
108 rProp
[i
].Value
>>= rType
;
109 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_VISIBLE
))
110 rProp
[i
].Value
>>= rVisible
;
111 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_WIDTH
))
112 rProp
[i
].Value
>>= rWidth
;
116 struct ToolBarEntryProperty
118 OReadToolBoxDocumentHandler::ToolBox_XML_Namespace nNamespace
;
122 ToolBarEntryProperty ToolBoxEntries
[OReadToolBoxDocumentHandler::TB_XML_ENTRY_COUNT
] =
124 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ELEMENT_TOOLBAR
},
125 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ELEMENT_TOOLBARITEM
},
126 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ELEMENT_TOOLBARSPACE
},
127 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ELEMENT_TOOLBARBREAK
},
128 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ELEMENT_TOOLBARSEPARATOR
},
129 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_TEXT
},
130 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_BITMAP
},
131 { OReadToolBoxDocumentHandler::TB_NS_XLINK
, ATTRIBUTE_URL
},
132 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_ITEMBITS
},
133 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_VISIBLE
},
134 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_WIDTH
},
135 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_USER
},
136 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_HELPID
},
137 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_ITEMSTYLE
},
138 { OReadToolBoxDocumentHandler::TB_NS_TOOLBAR
, ATTRIBUTE_UINAME
}
141 OReadToolBoxDocumentHandler::OReadToolBoxDocumentHandler( const Reference
< XIndexContainer
>& rItemContainer
) :
142 ThreadHelpBase( &Application::GetSolarMutex() ),
143 m_rItemContainer( rItemContainer
),
144 m_aType( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
)),
145 m_aLabel( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_LABEL
)),
146 m_aStyle( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_STYLE
)),
147 m_aHelpURL( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL
)),
148 m_aIsVisible( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_VISIBLE
)),
149 m_aCommandURL( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL
))
151 ::rtl::OUString
aNamespaceToolBar( RTL_CONSTASCII_USTRINGPARAM( XMLNS_TOOLBAR
));
152 ::rtl::OUString
aNamespaceXLink( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK
));
153 ::rtl::OUString
aSeparator( RTL_CONSTASCII_USTRINGPARAM( XMLNS_FILTER_SEPARATOR
));
156 for ( int i
= 0; i
< (int)TB_XML_ENTRY_COUNT
; i
++ )
158 if ( ToolBoxEntries
[i
].nNamespace
== TB_NS_TOOLBAR
)
160 ::rtl::OUString
temp( aNamespaceToolBar
);
162 temp
+= ::rtl::OUString::createFromAscii( ToolBoxEntries
[i
].aEntryName
);
163 m_aToolBoxMap
.insert( ToolBoxHashMap::value_type( temp
, (ToolBox_XML_Entry
)i
) );
167 ::rtl::OUString
temp( aNamespaceXLink
);
169 temp
+= ::rtl::OUString::createFromAscii( ToolBoxEntries
[i
].aEntryName
);
170 m_aToolBoxMap
.insert( ToolBoxHashMap::value_type( temp
, (ToolBox_XML_Entry
)i
) );
174 // pre-calculate a hash code for all style strings to speed up xml read process
175 m_nHashCode_Style_Radio
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_RADIO
).hashCode();
176 m_nHashCode_Style_Auto
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_AUTO
).hashCode();
177 m_nHashCode_Style_Left
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_LEFT
).hashCode();
178 m_nHashCode_Style_AutoSize
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_AUTOSIZE
).hashCode();
179 m_nHashCode_Style_DropDown
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_DROPDOWN
).hashCode();
180 m_nHashCode_Style_Repeat
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_REPEAT
).hashCode();
181 m_nHashCode_Style_DropDownOnly
= ::rtl::OUString::createFromAscii( ATTRIBUTE_ITEMSTYLE_DROPDOWNONLY
).hashCode();
183 m_bToolBarStartFound
= sal_False
;
184 m_bToolBarEndFound
= sal_False
;
185 m_bToolBarItemStartFound
= sal_False
;
186 m_bToolBarSpaceStartFound
= sal_False
;
187 m_bToolBarBreakStartFound
= sal_False
;
188 m_bToolBarSeparatorStartFound
= sal_False
;
191 OReadToolBoxDocumentHandler::~OReadToolBoxDocumentHandler()
196 void SAL_CALL
OReadToolBoxDocumentHandler::startDocument(void)
197 throw ( SAXException
, RuntimeException
)
201 void SAL_CALL
OReadToolBoxDocumentHandler::endDocument(void)
202 throw( SAXException
, RuntimeException
)
204 ResetableGuard
aGuard( m_aLock
);
206 if (( m_bToolBarStartFound
&& !m_bToolBarEndFound
) ||
207 ( !m_bToolBarStartFound
&& m_bToolBarEndFound
) )
209 ::rtl::OUString aErrorMessage
= getErrorLineString();
210 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'toolbar' found!" ));
211 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
215 void SAL_CALL
OReadToolBoxDocumentHandler::startElement(
216 const ::rtl::OUString
& aName
, const Reference
< XAttributeList
> &xAttribs
)
217 throw( SAXException
, RuntimeException
)
219 ResetableGuard
aGuard( m_aLock
);
221 ToolBoxHashMap::const_iterator pToolBoxEntry
= m_aToolBoxMap
.find( aName
) ;
222 if ( pToolBoxEntry
!= m_aToolBoxMap
.end() )
224 switch ( pToolBoxEntry
->second
)
226 case TB_ELEMENT_TOOLBAR
:
228 if ( m_bToolBarStartFound
)
230 ::rtl::OUString aErrorMessage
= getErrorLineString();
231 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'toolbar:toolbar' cannot be embeded into 'toolbar:toolbar'!" ));
232 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
236 // Check if we have a UI name set in our XML file
237 ::rtl::OUString aUIName
;
238 for ( sal_Int16 n
= 0; n
< xAttribs
->getLength(); n
++ )
240 pToolBoxEntry
= m_aToolBoxMap
.find( xAttribs
->getNameByIndex( n
) );
241 if ( pToolBoxEntry
!= m_aToolBoxMap
.end() )
243 switch ( pToolBoxEntry
->second
)
245 case TB_ATTRIBUTE_UINAME
:
246 aUIName
= xAttribs
->getValueByIndex( n
);
254 if ( aUIName
.getLength() > 0 )
256 // Try to set UI name as a container property
257 Reference
< XPropertySet
> xPropSet( m_rItemContainer
, UNO_QUERY
);
262 xPropSet
->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" )), makeAny( aUIName
) );
264 catch ( UnknownPropertyException
& )
271 m_bToolBarStartFound
= sal_True
;
275 case TB_ELEMENT_TOOLBARITEM
:
277 if ( !m_bToolBarStartFound
)
279 ::rtl::OUString aErrorMessage
= getErrorLineString();
280 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'toolbar:toolbaritem' must be embeded into element 'toolbar:toolbar'!" ));
281 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
284 if ( m_bToolBarSeparatorStartFound
||
285 m_bToolBarBreakStartFound
||
286 m_bToolBarSpaceStartFound
||
287 m_bToolBarItemStartFound
)
289 ::rtl::OUString aErrorMessage
= getErrorLineString();
290 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbaritem is not a container!" ));
291 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
294 ::rtl::OUString aAttribute
;
295 sal_Bool bAttributeURL
= sal_False
;
297 m_bToolBarItemStartFound
= sal_True
;
298 ::rtl::OUString aLabel
;
299 ::rtl::OUString aCommandURL
;
300 ::rtl::OUString aHelpURL
;
301 ::rtl::OUString aBitmapName
;
302 sal_uInt16
nItemBits( 0 );
303 sal_uInt16
nWidth( 0 );
304 sal_uInt16
nUserDef( 0 );
305 sal_Bool
bVisible( sal_True
);
307 for ( sal_Int16 n
= 0; n
< xAttribs
->getLength(); n
++ )
309 pToolBoxEntry
= m_aToolBoxMap
.find( xAttribs
->getNameByIndex( n
) );
310 if ( pToolBoxEntry
!= m_aToolBoxMap
.end() )
312 switch ( pToolBoxEntry
->second
)
314 case TB_ATTRIBUTE_TEXT
:
316 aLabel
= xAttribs
->getValueByIndex( n
);
320 case TB_ATTRIBUTE_BITMAP
:
322 aBitmapName
= xAttribs
->getValueByIndex( n
);
326 case TB_ATTRIBUTE_URL
:
328 bAttributeURL
= sal_True
;
329 aCommandURL
= xAttribs
->getValueByIndex( n
).intern();
333 case TB_ATTRIBUTE_ITEMBITS
:
335 nItemBits
= (USHORT
)(xAttribs
->getValueByIndex( n
).toInt32());
339 case TB_ATTRIBUTE_VISIBLE
:
341 if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE
)) )
343 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE
)) )
344 bVisible
= sal_False
;
347 ::rtl::OUString aErrorMessage
= getErrorLineString();
348 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute toolbar:visible must have value 'true' or 'false'!" ));
349 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
354 case TB_ATTRIBUTE_WIDTH
:
356 nWidth
= (USHORT
)(xAttribs
->getValueByIndex( n
).toInt32());
360 case TB_ATTRIBUTE_USER
:
362 nUserDef
= (USHORT
)(xAttribs
->getValueByIndex( n
).toInt32());
366 case TB_ATTRIBUTE_HELPID
:
368 aHelpURL
= xAttribs
->getValueByIndex( n
);
372 case TB_ATTRIBUTE_STYLE
:
374 // read space seperated item style list
375 ::rtl::OUString aTemp
= xAttribs
->getValueByIndex( n
);
376 sal_Int32 nIndex
= 0;
380 ::rtl::OUString aToken
= aTemp
.getToken( 0, ' ', nIndex
);
381 if ( aToken
.getLength() > 0 )
383 sal_Int32 nHashCode
= aToken
.hashCode();
384 if ( nHashCode
== m_nHashCode_Style_Radio
)
385 nItemBits
|= ::com::sun::star::ui::ItemStyle::RADIO_CHECK
;
386 else if ( nHashCode
== m_nHashCode_Style_Left
)
387 nItemBits
|= ::com::sun::star::ui::ItemStyle::ALIGN_LEFT
;
388 else if ( nHashCode
== m_nHashCode_Style_AutoSize
)
389 nItemBits
|= ::com::sun::star::ui::ItemStyle::AUTO_SIZE
;
390 else if ( nHashCode
== m_nHashCode_Style_DropDown
)
391 nItemBits
|= ::com::sun::star::ui::ItemStyle::DROP_DOWN
;
392 else if ( nHashCode
== m_nHashCode_Style_Repeat
)
393 nItemBits
|= ::com::sun::star::ui::ItemStyle::REPEAT
;
394 else if ( nHashCode
== m_nHashCode_Style_DropDownOnly
)
395 nItemBits
|= ::com::sun::star::ui::ItemStyle::DROPDOWN_ONLY
;
398 while ( nIndex
>= 0 );
408 if ( !bAttributeURL
)
410 ::rtl::OUString aErrorMessage
= getErrorLineString();
411 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute toolbar:url must have a value!" ));
412 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
415 if ( aCommandURL
.getLength() > 0 )
417 Sequence
< PropertyValue
> aToolbarItemProp( 6 );
418 aToolbarItemProp
[0].Name
= m_aCommandURL
;
419 aToolbarItemProp
[1].Name
= m_aHelpURL
;
420 aToolbarItemProp
[2].Name
= m_aLabel
;
421 aToolbarItemProp
[3].Name
= m_aType
;
422 aToolbarItemProp
[4].Name
= m_aStyle
;
423 aToolbarItemProp
[5].Name
= m_aIsVisible
;
425 aToolbarItemProp
[0].Value
<<= aCommandURL
;
426 aToolbarItemProp
[1].Value
<<= aHelpURL
;
427 aToolbarItemProp
[2].Value
<<= aLabel
;
428 aToolbarItemProp
[3].Value
= makeAny( ::com::sun::star::ui::ItemType::DEFAULT
);
429 aToolbarItemProp
[4].Value
<<= nItemBits
;
430 aToolbarItemProp
[5].Value
<<= bVisible
;
432 m_rItemContainer
->insertByIndex( m_rItemContainer
->getCount(), makeAny( aToolbarItemProp
) );
437 case TB_ELEMENT_TOOLBARSPACE
:
439 if ( m_bToolBarSeparatorStartFound
||
440 m_bToolBarBreakStartFound
||
441 m_bToolBarSpaceStartFound
||
442 m_bToolBarItemStartFound
)
444 ::rtl::OUString aErrorMessage
= getErrorLineString();
445 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbarspace is not a container!" ));
446 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
449 m_bToolBarSpaceStartFound
= sal_True
;
451 Sequence
< PropertyValue
> aToolbarItemProp( 2 );
452 aToolbarItemProp
[0].Name
= m_aCommandURL
;
453 aToolbarItemProp
[1].Name
= m_aType
;
455 aToolbarItemProp
[0].Value
<<= rtl::OUString();
456 aToolbarItemProp
[1].Value
<<= ::com::sun::star::ui::ItemType::SEPARATOR_SPACE
;
458 m_rItemContainer
->insertByIndex( m_rItemContainer
->getCount(), makeAny( aToolbarItemProp
) );
462 case TB_ELEMENT_TOOLBARBREAK
:
464 if ( m_bToolBarSeparatorStartFound
||
465 m_bToolBarBreakStartFound
||
466 m_bToolBarSpaceStartFound
||
467 m_bToolBarItemStartFound
)
469 ::rtl::OUString aErrorMessage
= getErrorLineString();
470 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbarbreak is not a container!" ));
471 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
474 m_bToolBarBreakStartFound
= sal_True
;
476 Sequence
< PropertyValue
> aToolbarItemProp( 2 );
477 aToolbarItemProp
[0].Name
= m_aCommandURL
;
478 aToolbarItemProp
[1].Name
= m_aType
;
480 aToolbarItemProp
[0].Value
<<= rtl::OUString();
481 aToolbarItemProp
[1].Value
<<= ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK
;
483 m_rItemContainer
->insertByIndex( m_rItemContainer
->getCount(), makeAny( aToolbarItemProp
) );
487 case TB_ELEMENT_TOOLBARSEPARATOR
:
489 if ( m_bToolBarSeparatorStartFound
||
490 m_bToolBarBreakStartFound
||
491 m_bToolBarSpaceStartFound
||
492 m_bToolBarItemStartFound
)
494 ::rtl::OUString aErrorMessage
= getErrorLineString();
495 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element toolbar:toolbarseparator is not a container!" ));
496 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
499 m_bToolBarSeparatorStartFound
= sal_True
;
501 Sequence
< PropertyValue
> aToolbarItemProp( 2 );
502 aToolbarItemProp
[0].Name
= m_aCommandURL
;
503 aToolbarItemProp
[1].Name
= m_aType
;
505 aToolbarItemProp
[0].Value
<<= rtl::OUString();
506 aToolbarItemProp
[1].Value
<<= ::com::sun::star::ui::ItemType::SEPARATOR_LINE
;
508 m_rItemContainer
->insertByIndex( m_rItemContainer
->getCount(), makeAny( aToolbarItemProp
) );
518 void SAL_CALL
OReadToolBoxDocumentHandler::endElement(const ::rtl::OUString
& aName
)
519 throw( SAXException
, RuntimeException
)
521 ResetableGuard
aGuard( m_aLock
);
523 ToolBoxHashMap::const_iterator pToolBoxEntry
= m_aToolBoxMap
.find( aName
) ;
524 if ( pToolBoxEntry
!= m_aToolBoxMap
.end() )
526 switch ( pToolBoxEntry
->second
)
528 case TB_ELEMENT_TOOLBAR
:
530 if ( !m_bToolBarStartFound
)
532 ::rtl::OUString aErrorMessage
= getErrorLineString();
533 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar' found, but no start element 'toolbar'" ));
534 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
537 m_bToolBarStartFound
= sal_False
;
541 case TB_ELEMENT_TOOLBARITEM
:
543 if ( !m_bToolBarItemStartFound
)
545 ::rtl::OUString aErrorMessage
= getErrorLineString();
546 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbaritem' found, but no start element 'toolbar:toolbaritem'" ));
547 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
550 m_bToolBarItemStartFound
= sal_False
;
554 case TB_ELEMENT_TOOLBARBREAK
:
556 if ( !m_bToolBarBreakStartFound
)
558 ::rtl::OUString aErrorMessage
= getErrorLineString();
559 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbarbreak' found, but no start element 'toolbar:toolbarbreak'" ));
560 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
563 m_bToolBarBreakStartFound
= sal_False
;
567 case TB_ELEMENT_TOOLBARSPACE
:
569 if ( !m_bToolBarSpaceStartFound
)
571 ::rtl::OUString aErrorMessage
= getErrorLineString();
572 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbarspace' found, but no start element 'toolbar:toolbarspace'" ));
573 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
576 m_bToolBarSpaceStartFound
= sal_False
;
580 case TB_ELEMENT_TOOLBARSEPARATOR
:
582 if ( !m_bToolBarSeparatorStartFound
)
584 ::rtl::OUString aErrorMessage
= getErrorLineString();
585 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'toolbar:toolbarseparator' found, but no start element 'toolbar:toolbarseparator'" ));
586 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
589 m_bToolBarSeparatorStartFound
= sal_False
;
599 void SAL_CALL
OReadToolBoxDocumentHandler::characters(const ::rtl::OUString
&)
600 throw( SAXException
, RuntimeException
)
604 void SAL_CALL
OReadToolBoxDocumentHandler::ignorableWhitespace(const ::rtl::OUString
&)
605 throw( SAXException
, RuntimeException
)
609 void SAL_CALL
OReadToolBoxDocumentHandler::processingInstruction(
610 const ::rtl::OUString
& /*aTarget*/, const ::rtl::OUString
& /*aData*/ )
611 throw( SAXException
, RuntimeException
)
615 void SAL_CALL
OReadToolBoxDocumentHandler::setDocumentLocator(
616 const Reference
< XLocator
> &xLocator
)
617 throw( SAXException
, RuntimeException
)
619 ResetableGuard
aGuard( m_aLock
);
621 m_xLocator
= xLocator
;
624 ::rtl::OUString
OReadToolBoxDocumentHandler::getErrorLineString()
626 ResetableGuard
aGuard( m_aLock
);
630 if ( m_xLocator
.is() )
632 snprintf( buffer
, sizeof(buffer
), "Line: %ld - ", static_cast<long>( m_xLocator
->getLineNumber() ));
633 return ::rtl::OUString::createFromAscii( buffer
);
636 return ::rtl::OUString();
640 //_________________________________________________________________________________________________________________
641 // OWriteToolBoxDocumentHandler
642 //_________________________________________________________________________________________________________________
644 OWriteToolBoxDocumentHandler::OWriteToolBoxDocumentHandler(
645 const Reference
< XIndexAccess
>& rItemAccess
,
646 Reference
< XDocumentHandler
>& rWriteDocumentHandler
) :
647 ThreadHelpBase( &Application::GetSolarMutex() ),
648 m_xWriteDocumentHandler( rWriteDocumentHandler
),
649 m_rItemAccess( rItemAccess
)
651 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
652 m_xEmptyList
= Reference
< XAttributeList
>( (XAttributeList
*) pList
, UNO_QUERY
);
653 m_aAttributeType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA
));
654 m_aXMLXlinkNS
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX
));
655 m_aXMLToolbarNS
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_TOOLBAR_PREFIX
));
658 OWriteToolBoxDocumentHandler::~OWriteToolBoxDocumentHandler()
662 void OWriteToolBoxDocumentHandler::WriteToolBoxDocument() throw
663 ( SAXException
, RuntimeException
)
665 ResetableGuard
aGuard( m_aLock
);
667 m_xWriteDocumentHandler
->startDocument();
669 // write DOCTYPE line!
670 Reference
< XExtendedDocumentHandler
> xExtendedDocHandler( m_xWriteDocumentHandler
, UNO_QUERY
);
671 if ( xExtendedDocHandler
.is() )
673 xExtendedDocHandler
->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( TOOLBAR_DOCTYPE
)) );
674 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
677 ::rtl::OUString aUIName
;
678 Reference
< XPropertySet
> xPropSet( m_rItemAccess
, UNO_QUERY
);
683 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= aUIName
;
685 catch ( UnknownPropertyException
& )
690 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
691 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
693 pList
->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_TOOLBAR
)),
695 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_TOOLBAR
)) );
697 pList
->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK
)),
699 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK
)) );
701 if ( aUIName
.getLength() > 0 )
702 pList
->AddAttribute( m_aXMLToolbarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_UINAME
)),
706 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBAR
)), pList
);
707 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
709 sal_Int32 nItemCount
= m_rItemAccess
->getCount();
712 for ( sal_Int32 nItemPos
= 0; nItemPos
< nItemCount
; nItemPos
++ )
714 Sequence
< PropertyValue
> aProps
;
715 aAny
= m_rItemAccess
->getByIndex( nItemPos
);
716 if ( aAny
>>= aProps
)
718 ::rtl::OUString aCommandURL
;
719 ::rtl::OUString aLabel
;
720 ::rtl::OUString aHelpURL
;
721 sal_Bool
bVisible( sal_True
);
722 sal_Int16
nType( ::com::sun::star::ui::ItemType::DEFAULT
);
723 sal_Int16
nWidth( 0 );
725 ExtractToolbarParameters( aProps
, aCommandURL
, aLabel
, aHelpURL
, nWidth
, bVisible
, nType
);
726 if ( nType
== ::com::sun::star::ui::ItemType::DEFAULT
)
727 WriteToolBoxItem( aCommandURL
, aLabel
, aHelpURL
, nWidth
, bVisible
);
728 else if ( nType
== ::com::sun::star::ui::ItemType::SEPARATOR_SPACE
)
730 else if ( nType
== ::com::sun::star::ui::ItemType::SEPARATOR_LINE
)
731 WriteToolBoxSeparator();
732 else if ( nType
== ::com::sun::star::ui::ItemType::SEPARATOR_LINEBREAK
)
737 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
738 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBAR
)) );
739 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
740 m_xWriteDocumentHandler
->endDocument();
743 //_________________________________________________________________________________________________________________
744 // protected member functions
745 //_________________________________________________________________________________________________________________
747 void OWriteToolBoxDocumentHandler::WriteToolBoxItem(
748 const ::rtl::OUString
& rCommandURL
,
749 const ::rtl::OUString
& rLabel
,
750 const ::rtl::OUString
& rHelpURL
,
753 throw ( SAXException
, RuntimeException
)
755 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
756 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
758 if ( m_aAttributeURL
.getLength() == 0 )
760 m_aAttributeURL
= m_aXMLXlinkNS
;
761 m_aAttributeURL
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_URL
));
764 // save required attribute (URL)
765 pList
->AddAttribute( m_aAttributeURL
, m_aAttributeType
, rCommandURL
);
767 if ( rLabel
.getLength() > 0 )
769 pList
->AddAttribute( m_aXMLToolbarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TEXT
)),
774 if ( bVisible
== sal_False
)
776 pList
->AddAttribute( m_aXMLToolbarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_VISIBLE
)),
778 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE
)) );
781 if ( rHelpURL
.getLength() > 0 )
783 pList
->AddAttribute( m_aXMLToolbarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_HELPID
)),
790 pList
->AddAttribute( m_aXMLToolbarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_WIDTH
)),
792 ::rtl::OUString::valueOf( sal_Int32( nWidth
)) );
795 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
796 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARITEM
)), xList
);
797 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
798 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARITEM
)) );
801 void OWriteToolBoxDocumentHandler::WriteToolBoxSpace() throw
802 ( SAXException
, RuntimeException
)
804 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
805 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSPACE
)), m_xEmptyList
);
806 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
807 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSPACE
)) );
810 void OWriteToolBoxDocumentHandler::WriteToolBoxBreak() throw
811 ( SAXException
, RuntimeException
)
813 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
814 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARBREAK
)), m_xEmptyList
);
815 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
816 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARBREAK
)) );
819 void OWriteToolBoxDocumentHandler::WriteToolBoxSeparator() throw
820 ( SAXException
, RuntimeException
)
822 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
823 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSEPARATOR
)), m_xEmptyList
);
824 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
825 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_TOOLBARSEPARATOR
)) );
828 } // namespace framework