xref: /trunk/main/framework/source/fwe/xml/statusbardocumenthandler.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_framework.hxx"
26 
27 #include <stdio.h>
28 
29 //_________________________________________________________________________________________________________________
30 //  my own includes
31 //_________________________________________________________________________________________________________________
32 
33 #include <threadhelp/resetableguard.hxx>
34 #include <xml/statusbardocumenthandler.hxx>
35 #include <macros/debug.hxx>
36 
37 //_________________________________________________________________________________________________________________
38 //  interface includes
39 //_________________________________________________________________________________________________________________
40 
41 #ifndef __COM_SUN_STAR_XML_SAX_XEXTENDEDDOCUMENTHANDLER_HPP_
42 #include <com/sun/star/xml/sax/XExtendedDocumentHandler.hpp>
43 #endif
44 #include <com/sun/star/ui/ItemStyle.hpp>
45 #include <com/sun/star/ui/ItemType.hpp>
46 #include <com/sun/star/beans/PropertyValue.hpp>
47 
48 //_________________________________________________________________________________________________________________
49 //  other includes
50 //_________________________________________________________________________________________________________________
51 #include <vcl/svapp.hxx>
52 #include <vcl/status.hxx>
53 
54 #include <comphelper/attributelist.hxx>
55 
56 //_________________________________________________________________________________________________________________
57 //  namespace
58 //_________________________________________________________________________________________________________________
59 
60 using namespace ::com::sun::star::uno;
61 using namespace ::com::sun::star::beans;
62 using namespace ::com::sun::star::xml::sax;
63 using namespace ::com::sun::star::ui;
64 using namespace ::com::sun::star::container;
65 
66 #define XMLNS_STATUSBAR             "http://openoffice.org/2001/statusbar"
67 #define XMLNS_XLINK                 "http://www.w3.org/1999/xlink"
68 #define XMLNS_STATUSBAR_PREFIX      "statusbar:"
69 #define XMLNS_XLINK_PREFIX          "xlink:"
70 
71 #define XMLNS_FILTER_SEPARATOR      "^"
72 
73 #define ELEMENT_STATUSBAR           "statusbar"
74 #define ELEMENT_STATUSBARITEM       "statusbaritem"
75 
76 #define ATTRIBUTE_ALIGN             "align"
77 #define ATTRIBUTE_STYLE             "style"
78 #define ATTRIBUTE_URL               "href"
79 #define ATTRIBUTE_WIDTH             "width"
80 #define ATTRIBUTE_OFFSET            "offset"
81 #define ATTRIBUTE_AUTOSIZE          "autosize"
82 #define ATTRIBUTE_OWNERDRAW         "ownerdraw"
83 #define ATTRIBUTE_HELPURL           "helpid"
84 
85 #define ELEMENT_NS_STATUSBAR        "statusbar:statusbar"
86 #define ELEMENT_NS_STATUSBARITEM    "statusbar:statusbaritem"
87 
88 #define ATTRIBUTE_XMLNS_STATUSBAR   "xmlns:statusbar"
89 #define ATTRIBUTE_XMLNS_XLINK       "xmlns:xlink"
90 
91 #define ATTRIBUTE_TYPE_CDATA        "CDATA"
92 
93 #define ATTRIBUTE_BOOLEAN_TRUE      "true"
94 #define ATTRIBUTE_BOOLEAN_FALSE     "false"
95 
96 #define ATTRIBUTE_ALIGN_LEFT        "left"
97 #define ATTRIBUTE_ALIGN_RIGHT       "right"
98 #define ATTRIBUTE_ALIGN_CENTER      "center"
99 
100 #define ATTRIBUTE_STYLE_IN          "in"
101 #define ATTRIBUTE_STYLE_OUT         "out"
102 #define ATTRIBUTE_STYLE_FLAT        "flat"
103 
104 #define STATUSBAR_DOCTYPE           "<!DOCTYPE statusbar:statusbar PUBLIC \"-//OpenOffice.org//DTD OfficeDocument 1.0//EN\" \"statusbar.dtd\">"
105 
106 namespace framework
107 {
108 
109 // Property names of a menu/menu item ItemDescriptor
110 static const char ITEM_DESCRIPTOR_COMMANDURL[]  = "CommandURL";
111 static const char ITEM_DESCRIPTOR_HELPURL[]     = "HelpURL";
112 static const char ITEM_DESCRIPTOR_OFFSET[]      = "Offset";
113 static const char ITEM_DESCRIPTOR_STYLE[]       = "Style";
114 static const char ITEM_DESCRIPTOR_WIDTH[]       = "Width";
115 static const char ITEM_DESCRIPTOR_TYPE[]        = "Type";
116 
ExtractStatusbarItemParameters(const Sequence<PropertyValue> rProp,::rtl::OUString & rCommandURL,::rtl::OUString & rHelpURL,sal_Int16 & rOffset,sal_Int16 & rStyle,sal_Int16 & rWidth)117 static void ExtractStatusbarItemParameters(
118     const Sequence< PropertyValue > rProp,
119     ::rtl::OUString&                rCommandURL,
120     ::rtl::OUString&                rHelpURL,
121     sal_Int16&                      rOffset,
122     sal_Int16&                      rStyle,
123     sal_Int16&                      rWidth )
124 {
125     for ( sal_Int32 i = 0; i < rProp.getLength(); i++ )
126     {
127         if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_COMMANDURL ))
128         {
129             rProp[i].Value >>= rCommandURL;
130             rCommandURL = rCommandURL.intern();
131         }
132         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_HELPURL ))
133         {
134             rProp[i].Value >>= rHelpURL;
135         }
136         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_OFFSET ))
137         {
138             rProp[i].Value >>= rOffset;
139         }
140         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_STYLE ))
141         {
142             rProp[i].Value >>= rStyle;
143         }
144         else if ( rProp[i].Name.equalsAscii( ITEM_DESCRIPTOR_WIDTH ))
145         {
146             rProp[i].Value >>= rWidth;
147         }
148     }
149 }
150 
151 struct StatusBarEntryProperty
152 {
153     OReadStatusBarDocumentHandler::StatusBar_XML_Namespace  nNamespace;
154     char                                                    aEntryName[20];
155 };
156 
157 StatusBarEntryProperty StatusBarEntries[OReadStatusBarDocumentHandler::SB_XML_ENTRY_COUNT] =
158 {
159     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ELEMENT_STATUSBAR       },
160     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ELEMENT_STATUSBARITEM   },
161     { OReadStatusBarDocumentHandler::SB_NS_XLINK,       ATTRIBUTE_URL           },
162     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_ALIGN         },
163     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_STYLE         },
164     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_AUTOSIZE      },
165     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_OWNERDRAW     },
166     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_WIDTH         },
167     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_OFFSET        },
168     { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR,   ATTRIBUTE_HELPURL       }
169 };
170 
171 
OReadStatusBarDocumentHandler(const Reference<XIndexContainer> & rStatusBarItems)172 OReadStatusBarDocumentHandler::OReadStatusBarDocumentHandler(
173     const Reference< XIndexContainer >& rStatusBarItems ) :
174     ThreadHelpBase( &Application::GetSolarMutex() ),
175     m_aStatusBarItems( rStatusBarItems )
176 {
177     ::rtl::OUString aNamespaceStatusBar( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR ));
178     ::rtl::OUString aNamespaceXLink( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK ));
179     ::rtl::OUString aSeparator( RTL_CONSTASCII_USTRINGPARAM( XMLNS_FILTER_SEPARATOR ));
180 
181     // create hash map
182     for ( int i = 0; i < (int)SB_XML_ENTRY_COUNT; i++ )
183     {
184         if ( StatusBarEntries[i].nNamespace == SB_NS_STATUSBAR )
185         {
186             ::rtl::OUString temp( aNamespaceStatusBar );
187             temp += aSeparator;
188             temp += ::rtl::OUString::createFromAscii( StatusBarEntries[i].aEntryName );
189             m_aStatusBarMap.insert( StatusBarHashMap::value_type( temp, (StatusBar_XML_Entry)i ) );
190         }
191         else
192         {
193             ::rtl::OUString temp( aNamespaceXLink );
194             temp += aSeparator;
195             temp += ::rtl::OUString::createFromAscii( StatusBarEntries[i].aEntryName );
196             m_aStatusBarMap.insert( StatusBarHashMap::value_type( temp, (StatusBar_XML_Entry)i ) );
197         }
198     }
199 
200     m_bStatusBarStartFound          = sal_False;
201     m_bStatusBarEndFound            = sal_False;
202     m_bStatusBarItemStartFound      = sal_False;
203 }
204 
~OReadStatusBarDocumentHandler()205 OReadStatusBarDocumentHandler::~OReadStatusBarDocumentHandler()
206 {
207 }
208 
209 // XDocumentHandler
startDocument(void)210 void SAL_CALL OReadStatusBarDocumentHandler::startDocument(void)
211 {
212 }
213 
endDocument(void)214 void SAL_CALL OReadStatusBarDocumentHandler::endDocument(void)
215 {
216     ResetableGuard aGuard( m_aLock );
217 
218     if (( m_bStatusBarStartFound && !m_bStatusBarEndFound ) ||
219         ( !m_bStatusBarStartFound && m_bStatusBarEndFound )     )
220     {
221         ::rtl::OUString aErrorMessage = getErrorLineString();
222         aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No matching start or end element 'statusbar' found!" ));
223         throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
224     }
225 }
226 
startElement(const::rtl::OUString & aName,const Reference<XAttributeList> & xAttribs)227 void SAL_CALL OReadStatusBarDocumentHandler::startElement(
228     const ::rtl::OUString& aName, const Reference< XAttributeList > &xAttribs )
229 {
230     ResetableGuard aGuard( m_aLock );
231 
232     StatusBarHashMap::const_iterator pStatusBarEntry = m_aStatusBarMap.find( aName ) ;
233     if ( pStatusBarEntry != m_aStatusBarMap.end() )
234     {
235         switch ( pStatusBarEntry->second )
236         {
237             case SB_ELEMENT_STATUSBAR:
238             {
239                 if ( m_bStatusBarStartFound )
240                 {
241                     ::rtl::OUString aErrorMessage = getErrorLineString();
242                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'statusbar:statusbar' cannot be embedded into 'statusbar:statusbar'!" ));
243                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
244                 }
245 
246                 m_bStatusBarStartFound = sal_True;
247             }
248             break;
249 
250             case SB_ELEMENT_STATUSBARITEM:
251             {
252                 if ( !m_bStatusBarStartFound )
253                 {
254                     ::rtl::OUString aErrorMessage = getErrorLineString();
255                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element 'statusbar:statusbaritem' must be embedded into element 'statusbar:statusbar'!" ));
256                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
257                 }
258 
259                 if ( m_bStatusBarItemStartFound )
260                 {
261                     ::rtl::OUString aErrorMessage = getErrorLineString();
262                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Element statusbar:statusbaritem is not a container!" ));
263                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
264                 }
265 
266                 ::rtl::OUString     aCommandURL;
267                 ::rtl::OUString     aHelpURL;
268                 sal_Int16   nItemBits( ItemStyle::ALIGN_CENTER|ItemStyle::DRAW_IN3D );
269                 sal_Int16   nWidth( 0 );
270                 sal_Int16   nOffset( STATUSBAR_OFFSET );
271                 sal_Bool    bCommandURL( sal_False );
272 
273                 m_bStatusBarItemStartFound = sal_True;
274                 for ( sal_Int16 n = 0; n < xAttribs->getLength(); n++ )
275                 {
276                     pStatusBarEntry = m_aStatusBarMap.find( xAttribs->getNameByIndex( n ) );
277                     if ( pStatusBarEntry != m_aStatusBarMap.end() )
278                     {
279                         switch ( pStatusBarEntry->second )
280                         {
281                             case SB_ATTRIBUTE_URL:
282                             {
283                                 bCommandURL = sal_True;
284                                 aCommandURL = xAttribs->getValueByIndex( n );
285                             }
286                             break;
287 
288                             case SB_ATTRIBUTE_ALIGN:
289                             {
290                                 if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ALIGN_LEFT )) )
291                                 {
292                                     nItemBits |= ItemStyle::ALIGN_LEFT;
293                                     nItemBits &= ~ItemStyle::ALIGN_CENTER;
294                                 }
295                                 else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ALIGN_CENTER )) )
296                                 {
297                                     nItemBits |= ItemStyle::ALIGN_CENTER;
298                                     nItemBits &= ~ItemStyle::ALIGN_LEFT;
299                                 }
300                                 else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_ALIGN_RIGHT )) )
301                                 {
302                                     nItemBits |= ItemStyle::ALIGN_RIGHT;
303                                 }
304                                 else
305                                 {
306                                     ::rtl::OUString aErrorMessage = getErrorLineString();
307                                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:align must have one value of 'left','right' or 'center'!" ));
308                                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
309                                 }
310                             }
311                             break;
312 
313                             case SB_ATTRIBUTE_STYLE:
314                             {
315                                 if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE_IN )) )
316                                 {
317                                     nItemBits |= ItemStyle::DRAW_IN3D;
318                                     nItemBits &= ~ItemStyle::DRAW_OUT3D;
319                                 }
320                                 else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE_OUT )) )
321                                 {
322                                     nItemBits |= ItemStyle::DRAW_OUT3D;
323                                     nItemBits &= ~ItemStyle::DRAW_IN3D;
324                                 }
325                                 else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_STYLE_FLAT )) )
326                                 {
327                                     nItemBits |= ItemStyle::DRAW_FLAT;
328                                 }
329                                 else
330                                 {
331                                     ::rtl::OUString aErrorMessage = getErrorLineString();
332                                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:autosize must have value 'true' or 'false'!" ));
333                                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
334                                 }
335                             }
336                             break;
337 
338                             case SB_ATTRIBUTE_AUTOSIZE:
339                             {
340                                 if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) )
341                                     nItemBits |= ItemStyle::AUTO_SIZE;
342                                 else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE )) )
343                                     nItemBits &= ~ItemStyle::AUTO_SIZE;
344                                 else
345                                 {
346                                     ::rtl::OUString aErrorMessage = getErrorLineString();
347                                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:autosize must have value 'true' or 'false'!" ));
348                                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
349                                 }
350                             }
351                             break;
352 
353                             case SB_ATTRIBUTE_OWNERDRAW:
354                             {
355                                 if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) )
356                                     nItemBits |= ItemStyle::OWNER_DRAW;
357                                 else if ( xAttribs->getValueByIndex( n ).equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( ATTRIBUTE_BOOLEAN_FALSE )) )
358                                     nItemBits &= ~ItemStyle::OWNER_DRAW;
359                                 else
360                                 {
361                                     ::rtl::OUString aErrorMessage = getErrorLineString();
362                                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Attribute statusbar:ownerdraw must have value 'true' or 'false'!" ));
363                                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
364                                 }
365                             }
366                             break;
367 
368                             case SB_ATTRIBUTE_WIDTH:
369                             {
370                                 nWidth = (sal_Int16)(xAttribs->getValueByIndex( n ).toInt32());
371                             }
372                             break;
373 
374                             case SB_ATTRIBUTE_OFFSET:
375                             {
376                                 nOffset = (sal_Int16)(xAttribs->getValueByIndex( n ).toInt32());
377                             }
378                             break;
379 
380                             case SB_ATTRIBUTE_HELPURL:
381                             {
382                                 aHelpURL = xAttribs->getValueByIndex( n );
383                             }
384                             break;
385 
386                                 default:
387                                     break;
388                         }
389                     }
390                 } // for
391 
392                 if ( !bCommandURL )
393                 {
394                     ::rtl::OUString aErrorMessage = getErrorLineString();
395                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Required attribute statusbar:url must have a value!" ));
396                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
397                 }
398                     else
399                     {
400                         Sequence< PropertyValue > aStatusbarItemProp( 6 );
401                         aStatusbarItemProp[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_COMMANDURL ));
402                         aStatusbarItemProp[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_HELPURL ));
403                         aStatusbarItemProp[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_OFFSET ));
404                         aStatusbarItemProp[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_STYLE ));
405                         aStatusbarItemProp[4].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_WIDTH ));
406                         aStatusbarItemProp[5].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ITEM_DESCRIPTOR_TYPE ));
407 
408                         aStatusbarItemProp[0].Value <<= aCommandURL;
409                         aStatusbarItemProp[1].Value <<= aHelpURL;
410                         aStatusbarItemProp[2].Value <<= nOffset;
411                         aStatusbarItemProp[3].Value <<= nItemBits;
412                         aStatusbarItemProp[4].Value <<= nWidth;
413                         aStatusbarItemProp[5].Value = makeAny( ::com::sun::star::ui::ItemType::DEFAULT );
414 
415                         m_aStatusBarItems->insertByIndex( m_aStatusBarItems->getCount(), makeAny( aStatusbarItemProp ) );
416                     }
417             }
418             break;
419 
420                 default:
421                     break;
422         }
423     }
424 }
425 
endElement(const::rtl::OUString & aName)426 void SAL_CALL OReadStatusBarDocumentHandler::endElement(const ::rtl::OUString& aName)
427 {
428     ResetableGuard aGuard( m_aLock );
429 
430     StatusBarHashMap::const_iterator pStatusBarEntry = m_aStatusBarMap.find( aName ) ;
431     if ( pStatusBarEntry != m_aStatusBarMap.end() )
432     {
433         switch ( pStatusBarEntry->second )
434         {
435             case SB_ELEMENT_STATUSBAR:
436             {
437                 if ( !m_bStatusBarStartFound )
438                 {
439                     ::rtl::OUString aErrorMessage = getErrorLineString();
440                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'statusbar' found, but no start element 'statusbar'" ));
441                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
442                 }
443 
444                 m_bStatusBarStartFound = sal_False;
445             }
446             break;
447 
448             case SB_ELEMENT_STATUSBARITEM:
449             {
450                 if ( !m_bStatusBarItemStartFound )
451                 {
452                     ::rtl::OUString aErrorMessage = getErrorLineString();
453                     aErrorMessage += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "End element 'statusbar:statusbaritem' found, but no start element 'statusbar:statusbaritem'" ));
454                     throw SAXException( aErrorMessage, Reference< XInterface >(), Any() );
455                 }
456 
457                 m_bStatusBarItemStartFound = sal_False;
458             }
459             break;
460 
461                 default:
462                     break;
463         }
464     }
465 }
466 
characters(const::rtl::OUString &)467 void SAL_CALL OReadStatusBarDocumentHandler::characters(const ::rtl::OUString&)
468 {
469 }
470 
ignorableWhitespace(const::rtl::OUString &)471 void SAL_CALL OReadStatusBarDocumentHandler::ignorableWhitespace(const ::rtl::OUString&)
472 {
473 }
474 
processingInstruction(const::rtl::OUString &,const::rtl::OUString &)475 void SAL_CALL OReadStatusBarDocumentHandler::processingInstruction(
476     const ::rtl::OUString& /*aTarget*/, const ::rtl::OUString& /*aData*/ )
477 {
478 }
479 
setDocumentLocator(const Reference<XLocator> & xLocator)480 void SAL_CALL OReadStatusBarDocumentHandler::setDocumentLocator(
481     const Reference< XLocator > &xLocator)
482 {
483     ResetableGuard aGuard( m_aLock );
484 
485     m_xLocator = xLocator;
486 }
487 
getErrorLineString()488 ::rtl::OUString OReadStatusBarDocumentHandler::getErrorLineString()
489 {
490     ResetableGuard aGuard( m_aLock );
491 
492     char buffer[32];
493 
494     if ( m_xLocator.is() )
495     {
496         snprintf( buffer, sizeof(buffer), "Line: %ld - ", static_cast<long>( m_xLocator->getLineNumber() ));
497         return ::rtl::OUString::createFromAscii( buffer );
498     }
499     else
500         return ::rtl::OUString();
501 }
502 
503 
504 //_________________________________________________________________________________________________________________
505 //  OWriteStatusBarDocumentHandler
506 //_________________________________________________________________________________________________________________
507 
OWriteStatusBarDocumentHandler(const Reference<XIndexAccess> & aStatusBarItems,const Reference<XDocumentHandler> & rWriteDocumentHandler)508 OWriteStatusBarDocumentHandler::OWriteStatusBarDocumentHandler(
509     const Reference< XIndexAccess >& aStatusBarItems,
510     const Reference< XDocumentHandler >& rWriteDocumentHandler ) :
511     ThreadHelpBase( &Application::GetSolarMutex() ),
512     m_aStatusBarItems( aStatusBarItems ),
513     m_xWriteDocumentHandler( rWriteDocumentHandler )
514 {
515     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
516     m_xEmptyList        = Reference< XAttributeList >( (XAttributeList *) pList, UNO_QUERY );
517     m_aAttributeType    = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_TYPE_CDATA ));
518     m_aXMLXlinkNS       = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK_PREFIX ));
519     m_aXMLStatusBarNS   = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR_PREFIX ));
520 }
521 
~OWriteStatusBarDocumentHandler()522 OWriteStatusBarDocumentHandler::~OWriteStatusBarDocumentHandler()
523 {
524 }
525 
WriteStatusBarDocument()526 void OWriteStatusBarDocumentHandler::WriteStatusBarDocument()
527 {
528     ResetableGuard aGuard( m_aLock );
529 
530     m_xWriteDocumentHandler->startDocument();
531 
532     // write DOCTYPE line!
533     Reference< XExtendedDocumentHandler > xExtendedDocHandler( m_xWriteDocumentHandler, UNO_QUERY );
534     if ( xExtendedDocHandler.is() )
535     {
536         xExtendedDocHandler->unknown( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( STATUSBAR_DOCTYPE )) );
537         m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
538     }
539 
540     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
541     Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
542 
543     pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_STATUSBAR )),
544                          m_aAttributeType,
545                          ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_STATUSBAR )) );
546 
547     pList->AddAttribute( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_XMLNS_XLINK )),
548                          m_aAttributeType,
549                          ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( XMLNS_XLINK )) );
550 
551     m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBAR )), pList );
552     m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
553 
554     sal_Int32   nItemCount = m_aStatusBarItems->getCount();
555     Any         aAny;
556 
557     for ( sal_Int32 nItemPos = 0; nItemPos < nItemCount; nItemPos++ )
558     {
559         Sequence< PropertyValue > aProps;
560         aAny = m_aStatusBarItems->getByIndex( nItemPos );
561         if ( aAny >>= aProps )
562         {
563             ::rtl::OUString     aCommandURL;
564             ::rtl::OUString     aHelpURL;
565             sal_Int16   nStyle( ItemStyle::ALIGN_CENTER|ItemStyle::DRAW_IN3D );
566             sal_Int16   nWidth( 0 );
567             sal_Int16   nOffset( STATUSBAR_OFFSET );
568 
569             ExtractStatusbarItemParameters(
570                 aProps,
571                 aCommandURL,
572                 aHelpURL,
573                 nOffset,
574                 nStyle,
575                 nWidth );
576 
577             if ( aCommandURL.getLength() > 0 )
578                 WriteStatusBarItem( aCommandURL, aHelpURL, nOffset, nStyle, nWidth );
579         }
580     }
581 
582     m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
583     m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBAR )) );
584     m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
585     m_xWriteDocumentHandler->endDocument();
586 }
587 
588 //_________________________________________________________________________________________________________________
589 //  protected member functions
590 //_________________________________________________________________________________________________________________
591 
WriteStatusBarItem(const rtl::OUString & rCommandURL,const rtl::OUString &,sal_Int16 nOffset,sal_Int16 nStyle,sal_Int16 nWidth)592 void OWriteStatusBarDocumentHandler::WriteStatusBarItem(
593     const rtl::OUString&    rCommandURL,
594     const rtl::OUString&    /*rHelpURL*/,
595     sal_Int16               nOffset,
596     sal_Int16               nStyle,
597     sal_Int16               nWidth )
598 {
599     ::comphelper::AttributeList* pList = new ::comphelper::AttributeList;
600     Reference< XAttributeList > xList( (XAttributeList *) pList , UNO_QUERY );
601 
602     if ( m_aAttributeURL.getLength() == 0 )
603     {
604         m_aAttributeURL = m_aXMLXlinkNS;
605         m_aAttributeURL += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_URL ));
606     }
607 
608     // save required attribute (URL)
609     pList->AddAttribute( m_aAttributeURL, m_aAttributeType, rCommandURL );
610 
611     // alignment
612     if ( nStyle & ItemStyle::ALIGN_RIGHT )
613     {
614         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN )),
615                              m_aAttributeType,
616                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_RIGHT )) );
617     }
618     else if ( nStyle & ItemStyle::ALIGN_CENTER )
619     {
620         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN )),
621                              m_aAttributeType,
622                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_CENTER )) );
623     }
624     else
625     {
626         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN )),
627                              m_aAttributeType,
628                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_ALIGN_LEFT )) );
629     }
630 
631     // style ( SIB_IN is default )
632     if ( nStyle & ItemStyle::DRAW_FLAT )
633     {
634         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE )),
635                              m_aAttributeType,
636                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE_FLAT )) );
637     }
638     else if ( nStyle & ItemStyle::DRAW_OUT3D )
639     {
640         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE )),
641                              m_aAttributeType,
642                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_STYLE_OUT )) );
643     }
644 
645     // autosize (default sal_False)
646     if ( nStyle & ItemStyle::AUTO_SIZE )
647     {
648         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_AUTOSIZE )),
649                              m_aAttributeType,
650                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) );
651     }
652 
653     // ownerdraw (default sal_False)
654     if ( nStyle & ItemStyle::OWNER_DRAW )
655     {
656         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_OWNERDRAW )),
657                              m_aAttributeType,
658                              ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_BOOLEAN_TRUE )) );
659     }
660 
661     // width (default 0)
662     if ( nWidth > 0 )
663     {
664         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_WIDTH )),
665                              m_aAttributeType,
666                              ::rtl::OUString::valueOf( (sal_Int32)nWidth ) );
667     }
668 
669     // offset (default STATUSBAR_OFFSET)
670     if ( nOffset != STATUSBAR_OFFSET )
671     {
672         pList->AddAttribute( m_aXMLStatusBarNS + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ATTRIBUTE_OFFSET )),
673                              m_aAttributeType,
674                              ::rtl::OUString::valueOf( (sal_Int32)nOffset ) );
675     }
676 
677     m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
678     m_xWriteDocumentHandler->startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBARITEM )), xList );
679     m_xWriteDocumentHandler->ignorableWhitespace( ::rtl::OUString() );
680     m_xWriteDocumentHandler->endElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ELEMENT_NS_STATUSBARITEM )) );
681 }
682 
683 } // namespace framework
684