LCOV - code coverage report
Current view: top level - oox/source/vml - vmldrawing.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 74 95 77.9 %
Date: 2014-11-03 Functions: 20 27 74.1 %
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/vml/vmldrawing.hxx"
      21             : 
      22             : #include <algorithm>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/drawing/XControlShape.hpp>
      25             : #include <com/sun/star/drawing/XShapes.hpp>
      26             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      27             : #include <com/sun/star/text/HoriOrientation.hpp>
      28             : #include <com/sun/star/text/RelOrientation.hpp>
      29             : #include <com/sun/star/text/VertOrientation.hpp>
      30             : #include <rtl/ustring.hxx>
      31             : #include "oox/core/xmlfilterbase.hxx"
      32             : #include "oox/helper/containerhelper.hxx"
      33             : #include "oox/ole/axcontrol.hxx"
      34             : #include "oox/vml/vmlshape.hxx"
      35             : #include "oox/vml/vmlshapecontainer.hxx"
      36             : 
      37             : namespace oox {
      38             : namespace vml {
      39             : 
      40             : using namespace ::com::sun::star;
      41             : using namespace ::com::sun::star::awt;
      42             : using namespace ::com::sun::star::beans;
      43             : using namespace ::com::sun::star::drawing;
      44             : using namespace ::com::sun::star::lang;
      45             : using namespace ::com::sun::star::text;
      46             : using namespace ::com::sun::star::uno;
      47             : 
      48             : using ::oox::core::XmlFilterBase;
      49             : 
      50             : namespace {
      51             : 
      52             : /** Returns the textual representation of a numeric VML shape identifier. */
      53           0 : OUString lclGetShapeId( sal_Int32 nShapeId )
      54             : {
      55             :     // identifier consists of a literal NUL character, a lowercase 's', and the id
      56           0 :     sal_Unicode aStr[2] = { '\0', 's' };
      57           0 :     return OUString( aStr, 2 ) + OUString::number( nShapeId );
      58             : }
      59             : 
      60             : /** Returns the numeric VML shape identifier from its textual representation. */
      61           2 : sal_Int32 lclGetShapeId( const OUString& rShapeId )
      62             : {
      63             :     // identifier consists of a literal NUL character, a lowercase 's', and the id
      64           2 :     return ((rShapeId.getLength() >= 3) && (rShapeId[ 0 ] == '\0') && (rShapeId[ 1 ] == 's')) ? rShapeId.copy( 2 ).toInt32() : -1;
      65             : }
      66             : 
      67             : } // namespace
      68             : 
      69           4 : OleObjectInfo::OleObjectInfo( bool bDmlShape ) :
      70             :     mbAutoLoad( false ),
      71           4 :     mbDmlShape( bDmlShape )
      72             : {
      73           4 : }
      74             : 
      75           0 : void OleObjectInfo::setShapeId( sal_Int32 nShapeId )
      76             : {
      77           0 :     maShapeId = lclGetShapeId( nShapeId );
      78           0 : }
      79             : 
      80           0 : ControlInfo::ControlInfo()
      81             : {
      82           0 : }
      83             : 
      84           0 : void ControlInfo::setShapeId( sal_Int32 nShapeId )
      85             : {
      86           0 :     maShapeId = lclGetShapeId( nShapeId );
      87           0 : }
      88             : 
      89        2020 : Drawing::Drawing( XmlFilterBase& rFilter, const Reference< XDrawPage >& rxDrawPage, DrawingType eType ) :
      90             :     mrFilter( rFilter ),
      91             :     mxDrawPage( rxDrawPage ),
      92        2020 :     mxShapes( new ShapeContainer( *this ) ),
      93        4040 :     meType( eType )
      94             : {
      95             :     OSL_ENSURE( mxDrawPage.is(), "Drawing::Drawing - missing UNO draw page" );
      96        2020 : }
      97             : 
      98        3780 : Drawing::~Drawing()
      99             : {
     100        3780 : }
     101             : 
     102           2 : ::oox::ole::EmbeddedForm& Drawing::getControlForm() const
     103             : {
     104           2 :     if( !mxCtrlForm.get() )
     105             :         mxCtrlForm.reset( new ::oox::ole::EmbeddedForm(
     106           2 :             mrFilter.getModel(), mxDrawPage, mrFilter.getGraphicHelper() ) );
     107           2 :     return *mxCtrlForm;
     108             : }
     109             : 
     110           6 : void Drawing::registerBlockId( sal_Int32 nBlockId )
     111             : {
     112             :     OSL_ENSURE( nBlockId > 0, "Drawing::registerBlockId - invalid block index" );
     113           6 :     if( nBlockId > 0 )
     114             :     {
     115             :         // lower_bound() returns iterator pointing to element equal to nBlockId, if existing
     116           6 :         BlockIdVector::iterator aIt = ::std::lower_bound( maBlockIds.begin(), maBlockIds.end(), nBlockId );
     117           6 :         if( (aIt == maBlockIds.end()) || (nBlockId != *aIt) )
     118           6 :             maBlockIds.insert( aIt, nBlockId );
     119             :     }
     120           6 : }
     121             : 
     122           4 : void Drawing::registerOleObject( const OleObjectInfo& rOleObject )
     123             : {
     124             :     OSL_ENSURE( !rOleObject.maShapeId.isEmpty(), "Drawing::registerOleObject - missing OLE object shape id" );
     125             :     OSL_ENSURE( maOleObjects.count( rOleObject.maShapeId ) == 0, "Drawing::registerOleObject - OLE object already registered" );
     126           4 :     maOleObjects.insert( OleObjectInfoMap::value_type( rOleObject.maShapeId, rOleObject ) );
     127           4 : }
     128             : 
     129           0 : void Drawing::registerControl( const ControlInfo& rControl )
     130             : {
     131             :     OSL_ENSURE( !rControl.maShapeId.isEmpty(), "Drawing::registerControl - missing form control shape id" );
     132             :     OSL_ENSURE( !rControl.maName.isEmpty(), "Drawing::registerControl - missing form control name" );
     133             :     OSL_ENSURE( maControls.count( rControl.maShapeId ) == 0, "Drawing::registerControl - form control already registered" );
     134           0 :     maControls.insert( ControlInfoMap::value_type( rControl.maShapeId, rControl ) );
     135           0 : }
     136             : 
     137         732 : void Drawing::finalizeFragmentImport()
     138             : {
     139         732 :     mxShapes->finalizeFragmentImport();
     140         732 : }
     141             : 
     142         362 : void Drawing::convertAndInsert() const
     143             : {
     144         362 :     Reference< XShapes > xShapes( mxDrawPage, UNO_QUERY );
     145         362 :     mxShapes->convertAndInsert( xShapes );
     146         362 : }
     147             : 
     148           2 : sal_Int32 Drawing::getLocalShapeIndex( const OUString& rShapeId ) const
     149             : {
     150           2 :     sal_Int32 nShapeId = lclGetShapeId( rShapeId );
     151           2 :     if( nShapeId <= 0 ) return -1;
     152             : 
     153             :     /*  Shapes in a drawing are counted per registered shape identifier blocks
     154             :         as stored in the o:idmap element. The contents of this element have
     155             :         been stored in our member maBlockIds. Each block represents 1024 shape
     156             :         identifiers, starting with identifier 1 for the block #0. This means,
     157             :         block #0 represents the identifiers 1-1024, block #1 represents the
     158             :         identifiers 1025-2048, and so on. The local shape index has to be
     159             :         calculated according to all blocks registered for this drawing.
     160             : 
     161             :         Example:
     162             :             Registered for this drawing are blocks #1 and #3 (shape identifiers
     163             :             1025-2048 and 3073-4096).
     164             :             Shape identifier 1025 -> local shape index 1.
     165             :             Shape identifier 1026 -> local shape index 2.
     166             :             ...
     167             :             Shape identifier 2048 -> local shape index 1024.
     168             :             Shape identifier 3073 -> local shape index 1025.
     169             :             ...
     170             :             Shape identifier 4096 -> local shape index 2048.
     171             :      */
     172             : 
     173             :     // get block id from shape id and find its index in the list of used blocks
     174           2 :     sal_Int32 nBlockId = (nShapeId - 1) / 1024;
     175           2 :     BlockIdVector::iterator aIt = ::std::lower_bound( maBlockIds.begin(), maBlockIds.end(), nBlockId );
     176           2 :     sal_Int32 nIndex = static_cast< sal_Int32 >( aIt - maBlockIds.begin() );
     177             : 
     178             :     // block id not found in set -> register it now (value of nIndex remains valid)
     179           2 :     if( (aIt == maBlockIds.end()) || (*aIt != nBlockId) )
     180           0 :         maBlockIds.insert( aIt, nBlockId );
     181             : 
     182             :     // get one-based offset of shape id in its block
     183           2 :     sal_Int32 nBlockOffset = (nShapeId - 1) % 1024 + 1;
     184             : 
     185             :     // calculate the local shape index
     186           2 :     return 1024 * nIndex + nBlockOffset;
     187             : }
     188             : 
     189         686 : const OleObjectInfo* Drawing::getOleObjectInfo( const OUString& rShapeId ) const
     190             : {
     191         686 :     return ContainerHelper::getMapElement( maOleObjects, rShapeId );
     192             : }
     193             : 
     194         682 : const ControlInfo* Drawing::getControlInfo( const OUString& rShapeId ) const
     195             : {
     196         682 :     return ContainerHelper::getMapElement( maControls, rShapeId );
     197             : }
     198             : 
     199        1922 : Reference< XShape > Drawing::createAndInsertXShape( const OUString& rService,
     200             :         const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect ) const
     201             : {
     202             :     OSL_ENSURE( !rService.isEmpty(), "Drawing::createAndInsertXShape - missing UNO shape service name" );
     203             :     OSL_ENSURE( rxShapes.is(), "Drawing::createAndInsertXShape - missing XShapes container" );
     204        1922 :     Reference< XShape > xShape;
     205        1922 :     if( !rService.isEmpty() && rxShapes.is() ) try
     206             :     {
     207        1922 :         Reference< XMultiServiceFactory > xModelFactory( mrFilter.getModelFactory(), UNO_SET_THROW );
     208        1922 :         xShape.set( xModelFactory->createInstance( rService ), UNO_QUERY_THROW );
     209        1922 :         if ( !rService.equalsAscii( "com.sun.star.text.TextFrame" ) )
     210             :         {
     211             :             // insert shape into passed shape collection (maybe drawpage or group shape)
     212        1776 :             rxShapes->add( xShape );
     213        1776 :             xShape->setPosition( awt::Point( rShapeRect.X, rShapeRect.Y ) );
     214             :         }
     215             :         else
     216             :         {
     217         146 :             Reference< XPropertySet > xPropSet( xShape, UNO_QUERY_THROW );
     218         146 :             xPropSet->setPropertyValue( "HoriOrient", makeAny( HoriOrientation::NONE ) );
     219         146 :             xPropSet->setPropertyValue( "VertOrient", makeAny( VertOrientation::NONE ) );
     220         146 :             xPropSet->setPropertyValue( "HoriOrientPosition", makeAny( rShapeRect.X ) );
     221         146 :             xPropSet->setPropertyValue( "VertOrientPosition", makeAny( rShapeRect.Y ) );
     222         146 :             xPropSet->setPropertyValue( "HoriOrientRelation", makeAny( RelOrientation::FRAME ) );
     223         146 :             xPropSet->setPropertyValue( "VertOrientRelation", makeAny( RelOrientation::FRAME ) );
     224             :         }
     225        1922 :         xShape->setSize( awt::Size( rShapeRect.Width, rShapeRect.Height ) );
     226             :     }
     227           0 :     catch( Exception& e )
     228             :     {
     229             :         SAL_WARN( "oox", "Drawing::createAndInsertXShape - error during shape object creation: " << e.Message );
     230             :     }
     231             :     OSL_ENSURE( xShape.is(), "Drawing::createAndInsertXShape - cannot instanciate shape object" );
     232        1922 :     return xShape;
     233             : }
     234             : 
     235           2 : Reference< XShape > Drawing::createAndInsertXControlShape( const ::oox::ole::EmbeddedControl& rControl,
     236             :         const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect, sal_Int32& rnCtrlIndex ) const
     237             : {
     238           2 :     Reference< XShape > xShape;
     239             :     try
     240             :     {
     241             :         // create control model and insert it into the form of the draw page
     242           2 :         Reference< XControlModel > xCtrlModel( getControlForm().convertAndInsert( rControl, rnCtrlIndex ), UNO_SET_THROW );
     243             : 
     244             :         // create the control shape
     245           2 :         xShape = createAndInsertXShape( "com.sun.star.drawing.ControlShape", rxShapes, rShapeRect );
     246             : 
     247             :         // set the control model at the shape
     248           2 :         Reference< XControlShape >( xShape, UNO_QUERY_THROW )->setControl( xCtrlModel );
     249             :     }
     250           0 :     catch (Exception const& e)
     251             :     {
     252             :         SAL_WARN("oox", "exception inserting Shape: " << e.Message);
     253             :     }
     254           2 :     return xShape;
     255             : }
     256             : 
     257        1922 : bool Drawing::isShapeSupported( const ShapeBase& /*rShape*/ ) const
     258             : {
     259        1922 :     return true;
     260             : }
     261             : 
     262        1084 : OUString Drawing::getShapeBaseName( const ShapeBase& /*rShape*/ ) const
     263             : {
     264        1084 :     return OUString();
     265             : }
     266             : 
     267           0 : bool Drawing::convertClientAnchor( awt::Rectangle& /*orShapeRect*/, const OUString& /*rShapeAnchor*/ ) const
     268             : {
     269           0 :     return false;
     270             : }
     271             : 
     272           0 : Reference< XShape > Drawing::createAndInsertClientXShape( const ShapeBase& /*rShape*/,
     273             :         const Reference< XShapes >& /*rxShapes*/, const awt::Rectangle& /*rShapeRect*/ ) const
     274             : {
     275           0 :     return Reference< XShape >();
     276             : }
     277             : 
     278        1918 : void Drawing::notifyXShapeInserted( const Reference< XShape >& /*rxShape*/,
     279             :         const awt::Rectangle& /*rShapeRect*/, const ShapeBase& /*rShape*/, bool /*bGroupChild*/ )
     280             : {
     281        1918 : }
     282             : 
     283             : } // namespace vml
     284         408 : } // namespave oox
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10