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

Generated by: LCOV version 1.10