LCOV - code coverage report
Current view: top level - framework/source/fwe/xml - statusbardocumenthandler.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 100 266 37.6 %
Date: 2014-04-11 Functions: 7 18 38.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10