LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/xml - xmlannoi.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 67 83 80.7 %
Date: 2012-12-27 Functions: 10 11 90.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 "xmlannoi.hxx"
      21             : #include "xmlimprt.hxx"
      22             : #include "xmlconti.hxx"
      23             : #include "XMLTableShapeImportHelper.hxx"
      24             : 
      25             : #include <xmloff/xmltkmap.hxx>
      26             : #include <xmloff/nmspmap.hxx>
      27             : #include <xmloff/xmlnmspe.hxx>
      28             : #include <xmloff/xmltoken.hxx>
      29             : 
      30             : using namespace com::sun::star;
      31             : using namespace xmloff::token;
      32             : 
      33             : //------------------------------------------------------------------
      34             : 
      35           1 : ScXMLAnnotationData::ScXMLAnnotationData() :
      36             :     mbUseShapePos( false ),
      37           1 :     mbShown( false )
      38             : {
      39           1 : }
      40             : 
      41           1 : ScXMLAnnotationData::~ScXMLAnnotationData()
      42             : {
      43           1 : }
      44             : 
      45             : //------------------------------------------------------------------
      46             : 
      47           1 : ScXMLAnnotationContext::ScXMLAnnotationContext( ScXMLImport& rImport,
      48             :                                       sal_uInt16 nPrfx,
      49             :                                       const ::rtl::OUString& rLName,
      50             :                                       const uno::Reference<xml::sax::XAttributeList>& xAttrList,
      51             :                                       ScXMLAnnotationData& rAnnotationData,
      52             :                                       ScXMLTableRowCellContext* pTempCellContext) :
      53             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      54             :     mrAnnotationData( rAnnotationData ),
      55             :     pCellContext(pTempCellContext),
      56           1 :     pShapeContext(NULL)
      57             : {
      58           1 :     uno::Reference<drawing::XShapes> xLocalShapes (GetScImport().GetTables().GetCurrentXShapes());
      59           1 :     if (xLocalShapes.is())
      60             :     {
      61           1 :         XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
      62           1 :         pTableShapeImport->SetAnnotation(this);
      63           1 :         pShapeContext = GetScImport().GetShapeImport()->CreateGroupChildContext(
      64           2 :             GetScImport(), nPrfx, rLName, xAttrList, xLocalShapes, true);
      65             :     }
      66             : 
      67           1 :     pCellContext = pTempCellContext;
      68           1 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      69           1 :     const SvXMLTokenMap& rAttrTokenMap = GetScImport().GetTableAnnotationAttrTokenMap();
      70           9 :     for( sal_Int16 i=0; i < nAttrCount; ++i )
      71             :     {
      72           8 :         const rtl::OUString& sAttrName(xAttrList->getNameByIndex( i ));
      73           8 :         rtl::OUString aLocalName;
      74           8 :         sal_uInt16 nPrefix = GetScImport().GetNamespaceMap().GetKeyByAttrName(
      75           8 :                                             sAttrName, &aLocalName );
      76           8 :         const rtl::OUString& sValue(xAttrList->getValueByIndex( i ));
      77             : 
      78           8 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ) )
      79             :         {
      80             :             case XML_TOK_TABLE_ANNOTATION_ATTR_AUTHOR:
      81             :             {
      82           0 :                 maAuthorBuffer = sValue;
      83             :             }
      84           0 :             break;
      85             :             case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE:
      86             :             {
      87           0 :                 maCreateDateBuffer = sValue;
      88             :             }
      89           0 :             break;
      90             :             case XML_TOK_TABLE_ANNOTATION_ATTR_CREATE_DATE_STRING:
      91             :             {
      92           0 :                 maCreateDateStringBuffer = sValue;
      93             :             }
      94           0 :             break;
      95             :             case XML_TOK_TABLE_ANNOTATION_ATTR_DISPLAY:
      96             :             {
      97           0 :                 mrAnnotationData.mbShown = IsXMLToken(sValue, XML_TRUE);
      98             :             }
      99           0 :             break;
     100             :             case XML_TOK_TABLE_ANNOTATION_ATTR_X:
     101             :             {
     102           1 :                 mrAnnotationData.mbUseShapePos = true;
     103             :             }
     104           1 :             break;
     105             :             case XML_TOK_TABLE_ANNOTATION_ATTR_Y:
     106             :             {
     107           1 :                 mrAnnotationData.mbUseShapePos = true;
     108             :             }
     109           1 :             break;
     110             :         }
     111           9 :     }
     112           1 : }
     113             : 
     114           2 : ScXMLAnnotationContext::~ScXMLAnnotationContext()
     115             : {
     116           2 : }
     117             : 
     118           1 : void ScXMLAnnotationContext::StartElement(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList>& xAttrList)
     119             : {
     120           1 :     if (pShapeContext)
     121           1 :         pShapeContext->StartElement(xAttrList);
     122           1 : }
     123             : 
     124           2 : SvXMLImportContext *ScXMLAnnotationContext::CreateChildContext( sal_uInt16 nPrefix,
     125             :                                             const ::rtl::OUString& rLName,
     126             :                                             const ::com::sun::star::uno::Reference<
     127             :                                           ::com::sun::star::xml::sax::XAttributeList>& xAttrList )
     128             : {
     129           2 :     SvXMLImportContext *pContext = 0;
     130             : 
     131           2 :     if( XML_NAMESPACE_DC == nPrefix )
     132             :     {
     133           1 :         if( IsXMLToken( rLName, XML_CREATOR ) )
     134             :             pContext = new ScXMLContentContext(GetScImport(), nPrefix,
     135           0 :                                             rLName, xAttrList, maAuthorBuffer);
     136           1 :         else if( IsXMLToken( rLName, XML_DATE ) )
     137             :             pContext = new ScXMLContentContext(GetScImport(), nPrefix,
     138           1 :                                             rLName, xAttrList, maCreateDateBuffer);
     139             :     }
     140           1 :     else if( XML_NAMESPACE_META == nPrefix )
     141             :     {
     142           0 :         if( IsXMLToken( rLName, XML_DATE_STRING ) )
     143             :             pContext = new ScXMLContentContext(GetScImport(), nPrefix,
     144           0 :                                             rLName, xAttrList, maCreateDateStringBuffer);
     145             :     }
     146             : 
     147           2 :     if( !pContext && pShapeContext )
     148           1 :         pContext = pShapeContext->CreateChildContext(nPrefix, rLName, xAttrList);
     149             : 
     150           2 :     if( !pContext )
     151           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLName );
     152             : 
     153           2 :     return pContext;
     154             : }
     155             : 
     156           0 : void ScXMLAnnotationContext::Characters( const ::rtl::OUString& rChars )
     157             : {
     158           0 :     maTextBuffer.append(rChars);
     159           0 : }
     160             : 
     161           1 : void ScXMLAnnotationContext::EndElement()
     162             : {
     163           1 :     if (pShapeContext)
     164             :     {
     165           1 :         pShapeContext->EndElement();
     166           1 :         delete pShapeContext;
     167           1 :         pShapeContext = NULL;
     168             :     }
     169             : 
     170           1 :     mrAnnotationData.maAuthor = maAuthorBuffer.makeStringAndClear();
     171           1 :     mrAnnotationData.maCreateDate = maCreateDateBuffer.makeStringAndClear();
     172           1 :     if (mrAnnotationData.maCreateDate.isEmpty())
     173           0 :         mrAnnotationData.maCreateDate = maCreateDateStringBuffer.makeStringAndClear();
     174           1 :     mrAnnotationData.maSimpleText = maTextBuffer.makeStringAndClear();
     175             : 
     176           1 :     XMLTableShapeImportHelper* pTableShapeImport = (XMLTableShapeImportHelper*)GetScImport().GetShapeImport().get();
     177           1 :     pTableShapeImport->SetAnnotation(NULL);
     178           1 : }
     179             : 
     180           1 : void ScXMLAnnotationContext::SetShape( const uno::Reference< drawing::XShape >& rxShape, const uno::Reference< drawing::XShapes >& rxShapes,
     181             :                                        const rtl::OUString& rStyleName, const rtl::OUString& rTextStyle )
     182             : {
     183           1 :     mrAnnotationData.mxShape = rxShape;
     184           1 :     mrAnnotationData.mxShapes = rxShapes;
     185           1 :     mrAnnotationData.maStyleName = rStyleName;
     186           1 :     mrAnnotationData.maTextStyle = rTextStyle;
     187           1 : }
     188             : 
     189           1 : void ScXMLAnnotationContext::AddContentStyle( sal_uInt16 nFamily, const rtl::OUString& rName, const ESelection& rSelection )
     190             : {
     191           1 :     mrAnnotationData.maContentStyles.push_back( ScXMLAnnotationStyleEntry( nFamily, rName, rSelection ) );
     192           1 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10