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: statusbardocumenthandler.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/statusbardocumenthandler.hxx>
42 #include <macros/debug.hxx>
44 //_________________________________________________________________________________________________________________
46 //_________________________________________________________________________________________________________________
48 #ifndef __COM_SUN_STAR_XML_SAX_XEXTENDEDDOCUMENTHANDLER_HPP_
49 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
51 #include <com/sun/star/ui/ItemStyle.hpp>
52 #include <com/sun/star/ui/ItemType.hpp>
53 #include <com/sun/star/beans/PropertyValue.hpp>
55 //_________________________________________________________________________________________________________________
57 //_________________________________________________________________________________________________________________
58 #include <vcl/svapp.hxx>
59 #include <vcl/status.hxx>
61 #include <comphelper/attributelist.hxx>
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
67 using namespace ::com::sun::star::uno
;
68 using namespace ::com::sun::star::beans
;
69 using namespace ::com::sun::star::xml::sax
;
70 using namespace ::com::sun::star::ui
;
71 using namespace ::com::sun::star::container
;
73 #define XMLNS_STATUSBAR "http://openoffice.org/2001/statusbar"
74 #define XMLNS_XLINK "http://www.w3.org/1999/xlink"
75 #define XMLNS_STATUSBAR_PREFIX "statusbar:"
76 #define XMLNS_XLINK_PREFIX "xlink:"
78 #define XMLNS_FILTER_SEPARATOR "^"
80 #define ELEMENT_STATUSBAR "statusbar"
81 #define ELEMENT_STATUSBARITEM "statusbaritem"
83 #define ATTRIBUTE_ALIGN "align"
84 #define ATTRIBUTE_STYLE "style"
85 #define ATTRIBUTE_URL "href"
86 #define ATTRIBUTE_WIDTH "width"
87 #define ATTRIBUTE_OFFSET "offset"
88 #define ATTRIBUTE_AUTOSIZE "autosize"
89 #define ATTRIBUTE_OWNERDRAW "ownerdraw"
90 #define ATTRIBUTE_HELPURL "helpid"
92 #define ELEMENT_NS_STATUSBAR "statusbar:statusbar"
93 #define ELEMENT_NS_STATUSBARITEM "statusbar:statusbaritem"
95 #define ATTRIBUTE_XMLNS_STATUSBAR "xmlns:statusbar"
96 #define ATTRIBUTE_XMLNS_XLINK "xmlns:xlink"
98 #define ATTRIBUTE_TYPE_CDATA "CDATA"
100 #define ATTRIBUTE_BOOLEAN_TRUE "true"
101 #define ATTRIBUTE_BOOLEAN_FALSE "false"
103 #define ATTRIBUTE_ALIGN_LEFT "left"
104 #define ATTRIBUTE_ALIGN_RIGHT "right"
105 #define ATTRIBUTE_ALIGN_CENTER "center"
107 #define ATTRIBUTE_STYLE_IN "in"
108 #define ATTRIBUTE_STYLE_OUT "out"
109 #define ATTRIBUTE_STYLE_FLAT "flat"
111 #define STATUSBAR_DOCTYPE "<!DOCTYPE statusbar:statusbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"statusbar.dtd\">"
116 // Property names of a menu/menu item ItemDescriptor
117 static const char ITEM_DESCRIPTOR_COMMANDURL
[] = "CommandURL";
118 static const char ITEM_DESCRIPTOR_HELPURL
[] = "HelpURL";
119 static const char ITEM_DESCRIPTOR_OFFSET
[] = "Offset";
120 static const char ITEM_DESCRIPTOR_STYLE
[] = "Style";
121 static const char ITEM_DESCRIPTOR_WIDTH
[] = "Width";
122 static const char ITEM_DESCRIPTOR_TYPE
[] = "Type";
124 static void ExtractStatusbarItemParameters(
125 const Sequence
< PropertyValue
> rProp
,
126 ::rtl::OUString
& rCommandURL
,
127 ::rtl::OUString
& rHelpURL
,
132 for ( sal_Int32 i
= 0; i
< rProp
.getLength(); i
++ )
134 if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL
))
136 rProp
[i
].Value
>>= rCommandURL
;
137 rCommandURL
= rCommandURL
.intern();
139 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_HELPURL
))
141 rProp
[i
].Value
>>= rHelpURL
;
143 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_OFFSET
))
145 rProp
[i
].Value
>>= rOffset
;
147 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_STYLE
))
149 rProp
[i
].Value
>>= rStyle
;
151 else if ( rProp
[i
].Name
.equalsAscii( ITEM_DESCRIPTOR_WIDTH
))
153 rProp
[i
].Value
>>= rWidth
;
158 struct StatusBarEntryProperty
160 OReadStatusBarDocumentHandler::StatusBar_XML_Namespace nNamespace
;
164 StatusBarEntryProperty StatusBarEntries
[OReadStatusBarDocumentHandler::SB_XML_ENTRY_COUNT
] =
166 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ELEMENT_STATUSBAR
},
167 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ELEMENT_STATUSBARITEM
},
168 { OReadStatusBarDocumentHandler::SB_NS_XLINK
, ATTRIBUTE_URL
},
169 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_ALIGN
},
170 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_STYLE
},
171 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_AUTOSIZE
},
172 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_OWNERDRAW
},
173 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_WIDTH
},
174 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_OFFSET
},
175 { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR
, ATTRIBUTE_HELPURL
}
179 OReadStatusBarDocumentHandler::OReadStatusBarDocumentHandler(
180 const Reference
< XIndexContainer
>& rStatusBarItems
) :
181 ThreadHelpBase( &Application::GetSolarMutex() ),
182 m_aStatusBarItems( rStatusBarItems
)
184 ::rtl::OUString
aNamespaceStatusBar( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR
));
185 ::rtl::OUString
aNamespaceXLink( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK
));
186 ::rtl::OUString
aSeparator( RTL_CONSTASCII_USTRINGPARAM( XMLNS_FILTER_SEPARATOR
));
189 for ( int i
= 0; i
< (int)SB_XML_ENTRY_COUNT
; i
++ )
191 if ( StatusBarEntries
[i
].nNamespace
== SB_NS_STATUSBAR
)
193 ::rtl::OUString
temp( aNamespaceStatusBar
);
195 temp
+= ::rtl::OUString::createFromAscii( StatusBarEntries
[i
].aEntryName
);
196 m_aStatusBarMap
.insert( StatusBarHashMap::value_type( temp
, (StatusBar_XML_Entry
)i
) );
200 ::rtl::OUString
temp( aNamespaceXLink
);
202 temp
+= ::rtl::OUString::createFromAscii( StatusBarEntries
[i
].aEntryName
);
203 m_aStatusBarMap
.insert( StatusBarHashMap::value_type( temp
, (StatusBar_XML_Entry
)i
) );
207 m_bStatusBarStartFound
= sal_False
;
208 m_bStatusBarEndFound
= sal_False
;
209 m_bStatusBarItemStartFound
= sal_False
;
212 OReadStatusBarDocumentHandler::~OReadStatusBarDocumentHandler()
217 void SAL_CALL
OReadStatusBarDocumentHandler::startDocument(void)
218 throw ( SAXException
, RuntimeException
)
222 void SAL_CALL
OReadStatusBarDocumentHandler::endDocument(void)
223 throw( SAXException
, RuntimeException
)
225 ResetableGuard
aGuard( m_aLock
);
227 if (( m_bStatusBarStartFound
&& !m_bStatusBarEndFound
) ||
228 ( !m_bStatusBarStartFound
&& m_bStatusBarEndFound
) )
230 ::rtl::OUString aErrorMessage
= getErrorLineString();
231 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'statusbar' found!" ));
232 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
236 void SAL_CALL
OReadStatusBarDocumentHandler::startElement(
237 const ::rtl::OUString
& aName
, const Reference
< XAttributeList
> &xAttribs
)
238 throw( SAXException
, RuntimeException
)
240 ResetableGuard
aGuard( m_aLock
);
242 StatusBarHashMap::const_iterator pStatusBarEntry
= m_aStatusBarMap
.find( aName
) ;
243 if ( pStatusBarEntry
!= m_aStatusBarMap
.end() )
245 switch ( pStatusBarEntry
->second
)
247 case SB_ELEMENT_STATUSBAR
:
249 if ( m_bStatusBarStartFound
)
251 ::rtl::OUString aErrorMessage
= getErrorLineString();
252 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'statusbar:statusbar' cannot be embeded into 'statusbar:statusbar'!" ));
253 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
256 m_bStatusBarStartFound
= sal_True
;
260 case SB_ELEMENT_STATUSBARITEM
:
262 if ( !m_bStatusBarStartFound
)
264 ::rtl::OUString aErrorMessage
= getErrorLineString();
265 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'statusbar:statusbaritem' must be embeded into element 'statusbar:statusbar'!" ));
266 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
269 if ( m_bStatusBarItemStartFound
)
271 ::rtl::OUString aErrorMessage
= getErrorLineString();
272 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element statusbar:statusbaritem is not a container!" ));
273 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
276 ::rtl::OUString aCommandURL
;
277 ::rtl::OUString aHelpURL
;
278 sal_Int16
nItemBits( ItemStyle::ALIGN_CENTER
|ItemStyle::DRAW_IN3D
);
279 sal_Int16
nWidth( 0 );
280 sal_Int16
nOffset( STATUSBAR_OFFSET
);
281 sal_Bool
bCommandURL( sal_False
);
283 m_bStatusBarItemStartFound
= sal_True
;
284 for ( sal_Int16 n
= 0; n
< xAttribs
->getLength(); n
++ )
286 pStatusBarEntry
= m_aStatusBarMap
.find( xAttribs
->getNameByIndex( n
) );
287 if ( pStatusBarEntry
!= m_aStatusBarMap
.end() )
289 switch ( pStatusBarEntry
->second
)
291 case SB_ATTRIBUTE_URL
:
293 bCommandURL
= sal_True
;
294 aCommandURL
= xAttribs
->getValueByIndex( n
);
298 case SB_ATTRIBUTE_ALIGN
:
300 if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ALIGN_LEFT
)) )
302 nItemBits
|= ItemStyle::ALIGN_LEFT
;
303 nItemBits
&= ~ItemStyle::ALIGN_CENTER
;
305 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ALIGN_CENTER
)) )
307 nItemBits
|= ItemStyle::ALIGN_CENTER
;
308 nItemBits
&= ~ItemStyle::ALIGN_LEFT
;
310 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ALIGN_RIGHT
)) )
312 nItemBits
|= ItemStyle::ALIGN_RIGHT
;
316 ::rtl::OUString aErrorMessage
= getErrorLineString();
317 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:align must have one value of 'left','right' or 'center'!" ));
318 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
323 case SB_ATTRIBUTE_STYLE
:
325 if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE_IN
)) )
327 nItemBits
|= ItemStyle::DRAW_IN3D
;
328 nItemBits
&= ~ItemStyle::DRAW_OUT3D
;
330 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE_OUT
)) )
332 nItemBits
|= ItemStyle::DRAW_OUT3D
;
333 nItemBits
&= ~ItemStyle::DRAW_IN3D
;
335 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE_FLAT
)) )
337 nItemBits
|= ItemStyle::DRAW_FLAT
;
341 ::rtl::OUString aErrorMessage
= getErrorLineString();
342 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:autosize must have value 'true' or 'false'!" ));
343 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
348 case SB_ATTRIBUTE_AUTOSIZE
:
350 if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE
)) )
351 nItemBits
|= ItemStyle::AUTO_SIZE
;
352 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE
)) )
353 nItemBits
&= ~ItemStyle::AUTO_SIZE
;
356 ::rtl::OUString aErrorMessage
= getErrorLineString();
357 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:autosize must have value 'true' or 'false'!" ));
358 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
363 case SB_ATTRIBUTE_OWNERDRAW
:
365 if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE
)) )
366 nItemBits
|= ItemStyle::OWNER_DRAW
;
367 else if ( xAttribs
->getValueByIndex( n
).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE
)) )
368 nItemBits
&= ~ItemStyle::OWNER_DRAW
;
371 ::rtl::OUString aErrorMessage
= getErrorLineString();
372 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:ownerdraw must have value 'true' or 'false'!" ));
373 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
378 case SB_ATTRIBUTE_WIDTH
:
380 nWidth
= (sal_Int16
)(xAttribs
->getValueByIndex( n
).toInt32());
384 case SB_ATTRIBUTE_OFFSET
:
386 nOffset
= (sal_Int16
)(xAttribs
->getValueByIndex( n
).toInt32());
390 case SB_ATTRIBUTE_HELPURL
:
392 aHelpURL
= xAttribs
->getValueByIndex( n
);
404 ::rtl::OUString aErrorMessage
= getErrorLineString();
405 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute statusbar:url must have a value!" ));
406 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
410 Sequence
< PropertyValue
> aStatusbarItemProp( 6 );
411 aStatusbarItemProp
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL
));
412 aStatusbarItemProp
[1].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL
));
413 aStatusbarItemProp
[2].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_OFFSET
));
414 aStatusbarItemProp
[3].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_STYLE
));
415 aStatusbarItemProp
[4].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_WIDTH
));
416 aStatusbarItemProp
[5].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE
));
418 aStatusbarItemProp
[0].Value
<<= aCommandURL
;
419 aStatusbarItemProp
[1].Value
<<= aHelpURL
;
420 aStatusbarItemProp
[2].Value
<<= nOffset
;
421 aStatusbarItemProp
[3].Value
<<= nItemBits
;
422 aStatusbarItemProp
[4].Value
<<= nWidth
;
423 aStatusbarItemProp
[5].Value
= makeAny( ::com::sun::star::ui::ItemType::DEFAULT
);
425 m_aStatusBarItems
->insertByIndex( m_aStatusBarItems
->getCount(), makeAny( aStatusbarItemProp
) );
436 void SAL_CALL
OReadStatusBarDocumentHandler::endElement(const ::rtl::OUString
& aName
)
437 throw( SAXException
, RuntimeException
)
439 ResetableGuard
aGuard( m_aLock
);
441 StatusBarHashMap::const_iterator pStatusBarEntry
= m_aStatusBarMap
.find( aName
) ;
442 if ( pStatusBarEntry
!= m_aStatusBarMap
.end() )
444 switch ( pStatusBarEntry
->second
)
446 case SB_ELEMENT_STATUSBAR
:
448 if ( !m_bStatusBarStartFound
)
450 ::rtl::OUString aErrorMessage
= getErrorLineString();
451 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'statusbar' found, but no start element 'statusbar'" ));
452 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
455 m_bStatusBarStartFound
= sal_False
;
459 case SB_ELEMENT_STATUSBARITEM
:
461 if ( !m_bStatusBarItemStartFound
)
463 ::rtl::OUString aErrorMessage
= getErrorLineString();
464 aErrorMessage
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'statusbar:statusbaritem' found, but no start element 'statusbar:statusbaritem'" ));
465 throw SAXException( aErrorMessage
, Reference
< XInterface
>(), Any() );
468 m_bStatusBarItemStartFound
= sal_False
;
478 void SAL_CALL
OReadStatusBarDocumentHandler::characters(const ::rtl::OUString
&)
479 throw( SAXException
, RuntimeException
)
483 void SAL_CALL
OReadStatusBarDocumentHandler::ignorableWhitespace(const ::rtl::OUString
&)
484 throw( SAXException
, RuntimeException
)
488 void SAL_CALL
OReadStatusBarDocumentHandler::processingInstruction(
489 const ::rtl::OUString
& /*aTarget*/, const ::rtl::OUString
& /*aData*/ )
490 throw( SAXException
, RuntimeException
)
494 void SAL_CALL
OReadStatusBarDocumentHandler::setDocumentLocator(
495 const Reference
< XLocator
> &xLocator
)
496 throw( SAXException
, RuntimeException
)
498 ResetableGuard
aGuard( m_aLock
);
500 m_xLocator
= xLocator
;
503 ::rtl::OUString
OReadStatusBarDocumentHandler::getErrorLineString()
505 ResetableGuard
aGuard( m_aLock
);
509 if ( m_xLocator
.is() )
511 snprintf( buffer
, sizeof(buffer
), "Line: %ld - ", static_cast<long>( m_xLocator
->getLineNumber() ));
512 return ::rtl::OUString::createFromAscii( buffer
);
515 return ::rtl::OUString();
519 //_________________________________________________________________________________________________________________
520 // OWriteStatusBarDocumentHandler
521 //_________________________________________________________________________________________________________________
523 OWriteStatusBarDocumentHandler::OWriteStatusBarDocumentHandler(
524 const Reference
< XIndexAccess
>& aStatusBarItems
,
525 const Reference
< XDocumentHandler
>& rWriteDocumentHandler
) :
526 ThreadHelpBase( &Application::GetSolarMutex() ),
527 m_aStatusBarItems( aStatusBarItems
),
528 m_xWriteDocumentHandler( rWriteDocumentHandler
)
530 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
531 m_xEmptyList
= Reference
< XAttributeList
>( (XAttributeList
*) pList
, UNO_QUERY
);
532 m_aAttributeType
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA
));
533 m_aXMLXlinkNS
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX
));
534 m_aXMLStatusBarNS
= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR_PREFIX
));
537 OWriteStatusBarDocumentHandler::~OWriteStatusBarDocumentHandler()
541 void OWriteStatusBarDocumentHandler::WriteStatusBarDocument() throw
542 ( SAXException
, RuntimeException
)
544 ResetableGuard
aGuard( m_aLock
);
546 m_xWriteDocumentHandler
->startDocument();
548 // write DOCTYPE line!
549 Reference
< XExtendedDocumentHandler
> xExtendedDocHandler( m_xWriteDocumentHandler
, UNO_QUERY
);
550 if ( xExtendedDocHandler
.is() )
552 xExtendedDocHandler
->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATUSBAR_DOCTYPE
)) );
553 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
556 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
557 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
559 pList
->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_STATUSBAR
)),
561 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR
)) );
563 pList
->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK
)),
565 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK
)) );
567 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBAR
)), pList
);
568 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
570 sal_Int32 nItemCount
= m_aStatusBarItems
->getCount();
573 for ( sal_Int32 nItemPos
= 0; nItemPos
< nItemCount
; nItemPos
++ )
575 Sequence
< PropertyValue
> aProps
;
576 aAny
= m_aStatusBarItems
->getByIndex( nItemPos
);
577 if ( aAny
>>= aProps
)
579 ::rtl::OUString aCommandURL
;
580 ::rtl::OUString aHelpURL
;
581 sal_Int16
nStyle( ItemStyle::ALIGN_CENTER
|ItemStyle::DRAW_IN3D
);
582 sal_Int16
nWidth( 0 );
583 sal_Int16
nOffset( STATUSBAR_OFFSET
);
585 ExtractStatusbarItemParameters(
593 if ( aCommandURL
.getLength() > 0 )
594 WriteStatusBarItem( aCommandURL
, aHelpURL
, nOffset
, nStyle
, nWidth
);
598 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
599 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBAR
)) );
600 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
601 m_xWriteDocumentHandler
->endDocument();
604 //_________________________________________________________________________________________________________________
605 // protected member functions
606 //_________________________________________________________________________________________________________________
608 void OWriteStatusBarDocumentHandler::WriteStatusBarItem(
609 const rtl::OUString
& rCommandURL
,
610 const rtl::OUString
& /*rHelpURL*/,
614 throw ( SAXException
, RuntimeException
)
616 ::comphelper::AttributeList
* pList
= new ::comphelper::AttributeList
;
617 Reference
< XAttributeList
> xList( (XAttributeList
*) pList
, UNO_QUERY
);
619 if ( m_aAttributeURL
.getLength() == 0 )
621 m_aAttributeURL
= m_aXMLXlinkNS
;
622 m_aAttributeURL
+= ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_URL
));
625 // save required attribute (URL)
626 pList
->AddAttribute( m_aAttributeURL
, m_aAttributeType
, rCommandURL
);
629 if ( nStyle
& ItemStyle::ALIGN_RIGHT
)
631 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN
)),
633 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_RIGHT
)) );
635 else if ( nStyle
& ItemStyle::ALIGN_CENTER
)
637 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN
)),
639 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_CENTER
)) );
643 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN
)),
645 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_LEFT
)) );
648 // style ( SIB_IN is default )
649 if ( nStyle
& ItemStyle::DRAW_FLAT
)
651 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE
)),
653 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE_FLAT
)) );
655 else if ( nStyle
& ItemStyle::DRAW_OUT3D
)
657 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE
)),
659 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE_OUT
)) );
662 // autosize (default FALSE)
663 if ( nStyle
& ItemStyle::AUTO_SIZE
)
665 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_AUTOSIZE
)),
667 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE
)) );
670 // ownerdraw (default FALSE)
671 if ( nStyle
& ItemStyle::OWNER_DRAW
)
673 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_OWNERDRAW
)),
675 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE
)) );
681 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_WIDTH
)),
683 ::rtl::OUString::valueOf( (sal_Int32
)nWidth
) );
686 // offset (default STATUSBAR_OFFSET)
687 if ( nOffset
!= STATUSBAR_OFFSET
)
689 pList
->AddAttribute( m_aXMLStatusBarNS
+ ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_OFFSET
)),
691 ::rtl::OUString::valueOf( (sal_Int32
)nOffset
) );
694 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
695 m_xWriteDocumentHandler
->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBARITEM
)), xList
);
696 m_xWriteDocumentHandler
->ignorableWhitespace( ::rtl::OUString() );
697 m_xWriteDocumentHandler
->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBARITEM
)) );
700 } // namespace framework