LCOV - code coverage report
Current view: top level - oox/source/ole - axcontrolfragment.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 55 1.8 %
Date: 2015-06-13 12:38:46 Functions: 2 6 33.3 %
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 "oox/ole/axcontrolfragment.hxx"
      21             : 
      22             : #include "oox/core/xmlfilterbase.hxx"
      23             : #include "oox/helper/binaryinputstream.hxx"
      24             : #include "oox/helper/binaryoutputstream.hxx"
      25             : #include "oox/ole/axcontrol.hxx"
      26             : #include "oox/ole/olehelper.hxx"
      27             : #include "oox/ole/olestorage.hxx"
      28             : 
      29             : #include <osl/diagnose.h>
      30             : 
      31             : namespace oox {
      32             : namespace ole {
      33             : 
      34             : using namespace ::com::sun::star::io;
      35             : using namespace ::com::sun::star::uno;
      36             : 
      37             : using ::oox::core::ContextHandler2;
      38             : using ::oox::core::ContextHandlerRef;
      39             : using ::oox::core::FragmentHandler2;
      40             : using ::oox::core::XmlFilterBase;
      41             : 
      42           0 : AxControlPropertyContext::AxControlPropertyContext( FragmentHandler2& rFragment, ControlModelBase& rModel ) :
      43             :     ContextHandler2( rFragment ),
      44             :     mrModel( rModel ),
      45           0 :     mnPropId( XML_TOKEN_INVALID )
      46             : {
      47           0 : }
      48             : 
      49           0 : ContextHandlerRef AxControlPropertyContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      50             : {
      51           0 :     switch( getCurrentElement() )
      52             :     {
      53             :         case AX_TOKEN( ocx ):
      54           0 :             if( nElement == AX_TOKEN( ocxPr ) )
      55             :             {
      56           0 :                 mnPropId = rAttribs.getToken( AX_TOKEN( name ), XML_TOKEN_INVALID );
      57           0 :                 switch( mnPropId )
      58             :                 {
      59             :                     case XML_TOKEN_INVALID:
      60           0 :                         return 0;
      61             :                     case XML_Picture:
      62             :                     case XML_MouseIcon:
      63           0 :                         return this;        // import picture path from ax:picture child element
      64             :                     default:
      65           0 :                         mrModel.importProperty( mnPropId, rAttribs.getString( AX_TOKEN( value ), OUString() ) );
      66             :                 }
      67             :             }
      68           0 :         break;
      69             : 
      70             :         case AX_TOKEN( ocxPr ):
      71           0 :             if( nElement == AX_TOKEN( picture ) )
      72             :             {
      73           0 :                 OUString aPicturePath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
      74           0 :                 if( !aPicturePath.isEmpty() )
      75             :                 {
      76           0 :                     BinaryXInputStream aInStrm( getFilter().openInputStream( aPicturePath ), true );
      77           0 :                     mrModel.importPictureData( mnPropId, aInStrm );
      78           0 :                 }
      79             :             }
      80           0 :         break;
      81             :     }
      82           0 :     return 0;
      83             : }
      84             : 
      85           0 : AxControlFragment::AxControlFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, EmbeddedControl& rControl ) :
      86             :     FragmentHandler2( rFilter, rFragmentPath, true ),
      87           0 :     mrControl( rControl )
      88             : {
      89           0 : }
      90             : 
      91           0 : ContextHandlerRef AxControlFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      92             : {
      93           0 :     if( isRootElement() && (nElement == AX_TOKEN( ocx )) )
      94             :     {
      95           0 :         OUString aClassId = rAttribs.getString( AX_TOKEN( classid ), OUString() );
      96           0 :         switch( rAttribs.getToken( AX_TOKEN( persistence ), XML_TOKEN_INVALID ) )
      97             :         {
      98             :             case XML_persistPropertyBag:
      99           0 :                 if( ControlModelBase* pModel = mrControl.createModelFromGuid( aClassId ) )
     100           0 :                     return new AxControlPropertyContext( *this, *pModel );
     101           0 :             break;
     102             : 
     103             :             case XML_persistStreamInit:
     104             :             {
     105           0 :                 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     106           0 :                 if( !aFragmentPath.isEmpty() )
     107             :                 {
     108           0 :                     BinaryXInputStream aInStrm( getFilter().openInputStream( aFragmentPath ), true );
     109           0 :                     if( !aInStrm.isEof() )
     110             :                     {
     111             :                         // binary stream contains a copy of the class ID, must be equal to attribute value
     112           0 :                         OUString aStrmClassId = OleHelper::importGuid( aInStrm );
     113             :                         OSL_ENSURE( aClassId.equalsIgnoreAsciiCase( aStrmClassId ),
     114             :                             "AxControlFragment::importBinaryControl - form control class ID mismatch" );
     115           0 :                         if( ControlModelBase* pModel = mrControl.createModelFromGuid( aStrmClassId ) )
     116           0 :                             pModel->importBinaryModel( aInStrm );
     117           0 :                     }
     118           0 :                 }
     119             :             }
     120           0 :             break;
     121             : 
     122             :             case XML_persistStorage:
     123             :             {
     124           0 :                 OUString aFragmentPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) );
     125           0 :                 if( !aFragmentPath.isEmpty() )
     126             :                 {
     127           0 :                     Reference< XInputStream > xStrgStrm = getFilter().openInputStream( aFragmentPath );
     128           0 :                     if( xStrgStrm.is() )
     129             :                     {
     130           0 :                         OleStorage aStorage( getFilter().getComponentContext(), xStrgStrm, false );
     131           0 :                         BinaryXInputStream aInStrm( aStorage.openInputStream( "f" ), true );
     132           0 :                         if( !aInStrm.isEof() )
     133           0 :                             if( AxContainerModelBase* pModel = dynamic_cast< AxContainerModelBase* >( mrControl.createModelFromGuid( aClassId ) ) )
     134           0 :                                 pModel->importBinaryModel( aInStrm );
     135           0 :                     }
     136           0 :                 }
     137             :             }
     138           0 :             break;
     139           0 :         }
     140             :     }
     141           0 :     return 0;
     142             : }
     143             : 
     144             : } // namespace ole
     145         246 : } // namespace oox
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11