LCOV - code coverage report
Current view: top level - sc/source/filter/oox - drawingfragment.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 176 367 48.0 %
Date: 2014-04-11 Functions: 24 30 80.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             : #include "drawingfragment.hxx"
      21             : 
      22             : #include <com/sun/star/beans/PropertyValue.hpp>
      23             : #include <com/sun/star/container/XNameReplace.hpp>
      24             : #include <com/sun/star/document/XEventsSupplier.hpp>
      25             : #include <com/sun/star/drawing/XControlShape.hpp>
      26             : #include <com/sun/star/script/ScriptEventDescriptor.hpp>
      27             : #include <com/sun/star/script/XEventAttacherManager.hpp>
      28             : #include <rtl/strbuf.hxx>
      29             : #include <svx/svdobj.hxx>
      30             : #include "drwlayer.hxx"
      31             : #include "userdat.hxx"
      32             : #include "oox/drawingml/connectorshapecontext.hxx"
      33             : #include "oox/drawingml/graphicshapecontext.hxx"
      34             : #include "oox/helper/attributelist.hxx"
      35             : #include "oox/helper/propertyset.hxx"
      36             : #include "oox/vml/vmlshape.hxx"
      37             : #include "oox/vml/vmlshapecontainer.hxx"
      38             : #include "formulaparser.hxx"
      39             : #include "stylesbuffer.hxx"
      40             : #include "themebuffer.hxx"
      41             : #include "unitconverter.hxx"
      42             : #include "worksheetbuffer.hxx"
      43             : namespace oox {
      44             : namespace xls {
      45             : 
      46             : using namespace ::com::sun::star::beans;
      47             : using namespace ::com::sun::star::container;
      48             : using namespace ::com::sun::star::document;
      49             : using namespace ::com::sun::star::drawing;
      50             : using namespace ::com::sun::star::script;
      51             : using namespace ::com::sun::star::table;
      52             : using namespace ::com::sun::star::uno;
      53             : using namespace ::com::sun::star::xml::sax;
      54             : using namespace ::oox::core;
      55             : using namespace ::oox::drawingml;
      56             : using namespace ::oox::ole;
      57             : 
      58             : using ::com::sun::star::awt::Size;
      59             : using ::com::sun::star::awt::Point;
      60             : using ::com::sun::star::awt::Rectangle;
      61             : using ::com::sun::star::awt::XControlModel;
      62             : // no using's for ::oox::vml, that may clash with ::oox::drawingml types
      63             : 
      64           0 : ShapeMacroAttacher::ShapeMacroAttacher( const OUString& rMacroName, const Reference< XShape >& rxShape ) :
      65             :     VbaMacroAttacherBase( rMacroName ),
      66           0 :     mxShape( rxShape )
      67             : {
      68           0 : }
      69             : 
      70           0 : void ShapeMacroAttacher::attachMacro( const OUString& rMacroUrl )
      71             : {
      72             :     try
      73             :     {
      74           0 :         Reference< XEventsSupplier > xSupplier( mxShape, UNO_QUERY_THROW );
      75           0 :         Reference< XNameReplace > xEvents( xSupplier->getEvents(), UNO_SET_THROW );
      76           0 :         Sequence< PropertyValue > aEventProps( 2 );
      77           0 :         aEventProps[ 0 ].Name = "EventType";
      78           0 :         aEventProps[ 0 ].Value <<= OUString( "Script" );
      79           0 :         aEventProps[ 1 ].Name = "Script";
      80           0 :         aEventProps[ 1 ].Value <<= rMacroUrl;
      81           0 :         xEvents->replaceByName( "OnClick", Any( aEventProps ) );
      82             :     }
      83           0 :     catch( Exception& )
      84             :     {
      85             :     }
      86           0 : }
      87             : 
      88          14 : Shape::Shape( const WorksheetHelper& rHelper, const AttributeList& rAttribs, const sal_Char* pcServiceName ) :
      89             :     ::oox::drawingml::Shape( pcServiceName ),
      90          14 :     WorksheetHelper( rHelper )
      91             : {
      92          14 :     OUString aMacro = rAttribs.getXString( XML_macro, OUString() );
      93          14 :     if( !aMacro.isEmpty() )
      94           0 :         maMacroName = getFormulaParser().importMacroName( aMacro );
      95          14 : }
      96             : 
      97          14 : void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& rxShapes )
      98             : {
      99          14 :     OUString sURL;
     100          14 :     getShapeProperties().getProperty( PROP_URL ) >>= sURL;
     101          14 :     getWorksheets().convertSheetNameRef( sURL );
     102          14 :     if( !maMacroName.isEmpty() && mxShape.is() )
     103             :     {
     104           0 :         VbaMacroAttacherRef xAttacher( new ShapeMacroAttacher( maMacroName, mxShape ) );
     105           0 :         getBaseFilter().getVbaProject().registerMacroAttacher( xAttacher );
     106             :     }
     107          14 :     ::oox::drawingml::Shape::finalizeXShape( rFilter, rxShapes );
     108          14 :     if ( !sURL.isEmpty() )
     109             :     {
     110           0 :         SdrObject* pObj = SdrObject::getSdrObjectFromXShape( mxShape );
     111           0 :         if ( pObj )
     112             :         {
     113           0 :             if ( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true ) )
     114           0 :                 pInfo->SetHlink( sURL );
     115             :         }
     116          14 :     }
     117          14 : }
     118             : 
     119           0 : GroupShapeContext::GroupShapeContext( ContextHandler2Helper& rParent,
     120             :         const WorksheetHelper& rHelper, const ShapePtr& rxParentShape, const ShapePtr& rxShape ) :
     121             :     ShapeGroupContext( rParent, rxParentShape, rxShape ),
     122           0 :     WorksheetHelper( rHelper )
     123             : {
     124           0 : }
     125             : 
     126          14 : /*static*/ ContextHandlerRef GroupShapeContext::createShapeContext( ContextHandler2Helper& rParent,
     127             :         const WorksheetHelper& rHelper, sal_Int32 nElement, const AttributeList& rAttribs,
     128             :         const ShapePtr& rxParentShape, ShapePtr* pxShape )
     129             : {
     130          14 :     switch( nElement )
     131             :     {
     132             :         case XDR_TOKEN( sp ):
     133             :         {
     134           0 :             ShapePtr xShape( new Shape( rHelper, rAttribs, "com.sun.star.drawing.CustomShape" ) );
     135           0 :             if( pxShape ) *pxShape = xShape;
     136           0 :             return new ShapeContext( rParent, rxParentShape, xShape );
     137             :         }
     138             :         case XDR_TOKEN( cxnSp ):
     139             :         {
     140           0 :             ShapePtr xShape( new Shape( rHelper, rAttribs, "com.sun.star.drawing.ConnectorShape" ) );
     141           0 :             if( pxShape ) *pxShape = xShape;
     142           0 :             return new ConnectorShapeContext( rParent, rxParentShape, xShape );
     143             :         }
     144             :         case XDR_TOKEN( pic ):
     145             :         {
     146           4 :             ShapePtr xShape( new Shape( rHelper, rAttribs, "com.sun.star.drawing.GraphicObjectShape" ) );
     147           4 :             if( pxShape ) *pxShape = xShape;
     148           4 :             return new GraphicShapeContext( rParent, rxParentShape, xShape );
     149             :         }
     150             :         case XDR_TOKEN( graphicFrame ):
     151             :         {
     152          10 :             ShapePtr xShape( new Shape( rHelper, rAttribs, "com.sun.star.drawing.GraphicObjectShape" ) );
     153          10 :             if( pxShape ) *pxShape = xShape;
     154          10 :             return new GraphicalObjectFrameContext( rParent, rxParentShape, xShape, rHelper.getSheetType() != SHEETTYPE_CHARTSHEET );
     155             :         }
     156             :         case XDR_TOKEN( grpSp ):
     157             :         {
     158           0 :             ShapePtr xShape( new Shape( rHelper, rAttribs, "com.sun.star.drawing.GroupShape" ) );
     159           0 :             if( pxShape ) *pxShape = xShape;
     160           0 :             return new GroupShapeContext( rParent, rHelper, rxParentShape, xShape );
     161             :         }
     162             :     }
     163           0 :     return 0;
     164             : }
     165             : 
     166           0 : ContextHandlerRef GroupShapeContext::onCreateContext(
     167             :         sal_Int32 nElement, const AttributeList& rAttribs )
     168             : {
     169           0 :     ContextHandlerRef xContext = createShapeContext( *this, *this, nElement, rAttribs, mpGroupShapePtr );
     170           0 :     return xContext.get() ? xContext.get() : ShapeGroupContext::onCreateContext( nElement, rAttribs );
     171             : }
     172             : 
     173          16 : DrawingFragment::DrawingFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
     174             :     WorksheetFragmentBase( rHelper, rFragmentPath ),
     175          16 :     mxDrawPage( rHelper.getDrawPage(), UNO_QUERY )
     176             : {
     177             :     OSL_ENSURE( mxDrawPage.is(), "DrawingFragment::DrawingFragment - missing drawing page" );
     178          16 : }
     179             : 
     180         198 : ContextHandlerRef DrawingFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     181             : {
     182         198 :     switch( getCurrentElement() )
     183             :     {
     184             :         case XML_ROOT_CONTEXT:
     185          16 :             if( nElement == XDR_TOKEN( wsDr ) ) return this;
     186           0 :         break;
     187             : 
     188             :         case XDR_TOKEN( wsDr ):
     189          14 :             switch( nElement )
     190             :             {
     191             :                 case XDR_TOKEN( absoluteAnchor ):
     192             :                 case XDR_TOKEN( oneCellAnchor ):
     193             :                 case XDR_TOKEN( twoCellAnchor ):
     194          14 :                     mxAnchor.reset( new ShapeAnchor( *this ) );
     195          14 :                     mxAnchor->importAnchor( nElement, rAttribs );
     196          14 :                     return this;
     197             :             }
     198           0 :         break;
     199             : 
     200             :         case XDR_TOKEN( absoluteAnchor ):
     201             :         case XDR_TOKEN( oneCellAnchor ):
     202             :         case XDR_TOKEN( twoCellAnchor ):
     203             :         {
     204          56 :             switch( nElement )
     205             :             {
     206             :                 case XDR_TOKEN( from ):
     207          28 :                 case XDR_TOKEN( to ):           return this;
     208             : 
     209           0 :                 case XDR_TOKEN( pos ):          if( mxAnchor.get() ) mxAnchor->importPos( rAttribs );           break;
     210           0 :                 case XDR_TOKEN( ext ):          if( mxAnchor.get() ) mxAnchor->importExt( rAttribs );           break;
     211          14 :                 case XDR_TOKEN( clientData ):   if( mxAnchor.get() ) mxAnchor->importClientData( rAttribs );    break;
     212             : 
     213          14 :                 default:                        return GroupShapeContext::createShapeContext( *this, *this, nElement, rAttribs, ShapePtr(), &mxShape );
     214             :             }
     215             :         }
     216          14 :         break;
     217             : 
     218             :         case XDR_TOKEN( from ):
     219             :         case XDR_TOKEN( to ):
     220         112 :             switch( nElement )
     221             :             {
     222             :                 case XDR_TOKEN( col ):
     223             :                 case XDR_TOKEN( row ):
     224             :                 case XDR_TOKEN( colOff ):
     225         112 :                 case XDR_TOKEN( rowOff ):       return this;    // collect index in onCharacters()
     226             :             }
     227           0 :         break;
     228             :     }
     229          14 :     return 0;
     230             : }
     231             : 
     232         112 : void DrawingFragment::onCharacters( const OUString& rChars )
     233             : {
     234         112 :     switch( getCurrentElement() )
     235             :     {
     236             :         case XDR_TOKEN( col ):
     237             :         case XDR_TOKEN( row ):
     238             :         case XDR_TOKEN( colOff ):
     239             :         case XDR_TOKEN( rowOff ):
     240         112 :             if( mxAnchor.get() ) mxAnchor->setCellPos( getCurrentElement(), getParentElement(), rChars );
     241         112 :         break;
     242             :     }
     243         112 : }
     244             : 
     245         172 : void DrawingFragment::onEndElement()
     246             : {
     247         172 :     switch( getCurrentElement() )
     248             :     {
     249             :         case XDR_TOKEN( absoluteAnchor ):
     250             :         case XDR_TOKEN( oneCellAnchor ):
     251             :         case XDR_TOKEN( twoCellAnchor ):
     252          14 :             if( mxDrawPage.is() && mxShape.get() && mxAnchor.get() )
     253             :             {
     254             :                 // Rotation is decided by orientation of shape determined
     255             :                 // by the anchor position given by 'twoCellAnchor'
     256          14 :                 if ( getCurrentElement() == XDR_TOKEN( twoCellAnchor ) )
     257          14 :                     mxShape->setRotation(0);
     258          14 :                 EmuRectangle aShapeRectEmu = mxAnchor->calcAnchorRectEmu( getDrawPageSize() );
     259          14 :                 if( (aShapeRectEmu.X >= 0) && (aShapeRectEmu.Y >= 0) && (aShapeRectEmu.Width >= 0) && (aShapeRectEmu.Height >= 0) )
     260             :                 {
     261             :                     // TODO: DrawingML implementation expects 32-bit coordinates for EMU rectangles (change that to EmuRectangle)
     262             :                     Rectangle aShapeRectEmu32(
     263          14 :                         getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.X, 0, SAL_MAX_INT32 ),
     264          14 :                         getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Y, 0, SAL_MAX_INT32 ),
     265          14 :                         getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Width, 0, SAL_MAX_INT32 ),
     266          56 :                         getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Height, 0, SAL_MAX_INT32 ) );
     267             : 
     268             :                     // Make sure to set the position and size *before* calling addShape().
     269          14 :                     mxShape->setPosition(Point(aShapeRectEmu.X, aShapeRectEmu.Y));
     270          14 :                     mxShape->setSize(Size(aShapeRectEmu.Width, aShapeRectEmu.Height));
     271             : 
     272          14 :                     basegfx::B2DHomMatrix aTransformation;
     273          14 :                     mxShape->addShape( getOoxFilter(), &getTheme(), mxDrawPage, aTransformation, mxShape->getFillProperties(), &aShapeRectEmu32 );
     274             : 
     275             :                     /*  Collect all shape positions in the WorksheetHelper base
     276             :                         class. But first, scale EMUs to 1/100 mm. */
     277             :                     Rectangle aShapeRectHmm(
     278          28 :                         convertEmuToHmm( aShapeRectEmu.X ), convertEmuToHmm( aShapeRectEmu.Y ),
     279          42 :                         convertEmuToHmm( aShapeRectEmu.Width ), convertEmuToHmm( aShapeRectEmu.Height ) );
     280          14 :                     extendShapeBoundingBox( aShapeRectHmm );
     281             :                     // set cell Anchoring
     282          14 :                     if ( mxAnchor->getEditAs() != ShapeAnchor::ANCHOR_ABSOLUTE )
     283             :                     {
     284          14 :                         SdrObject* pObj = SdrObject::getSdrObjectFromXShape( mxShape->getXShape() );
     285          14 :                         if ( pObj )
     286             :                         {
     287          14 :                              ScDrawLayer::SetCellAnchoredFromPosition( *pObj, getScDocument(), static_cast<SCTAB>( getSheetIndex() ) );
     288             :                         }
     289          14 :                     }
     290             :                 }
     291             :             }
     292          14 :             mxShape.reset();
     293          14 :             mxAnchor.reset();
     294          14 :         break;
     295             :     }
     296         172 : }
     297             : 
     298             : 
     299             : // VML
     300             : 
     301             : 
     302             : namespace {
     303             : 
     304             : class VmlFindNoteFunc
     305             : {
     306             : public:
     307             :     explicit            VmlFindNoteFunc( const CellAddress& rPos );
     308             :     bool                operator()( const ::oox::vml::ShapeBase& rShape ) const;
     309             : 
     310             : private:
     311             :     sal_Int32           mnCol;
     312             :     sal_Int32           mnRow;
     313             : };
     314             : 
     315           1 : VmlFindNoteFunc::VmlFindNoteFunc( const CellAddress& rPos ) :
     316             :     mnCol( rPos.Column ),
     317           1 :     mnRow( rPos.Row )
     318             : {
     319           1 : }
     320             : 
     321           1 : bool VmlFindNoteFunc::operator()( const ::oox::vml::ShapeBase& rShape ) const
     322             : {
     323           1 :     const ::oox::vml::ClientData* pClientData = rShape.getClientData();
     324           1 :     return pClientData && (pClientData->mnCol == mnCol) && (pClientData->mnRow == mnRow);
     325             : }
     326             : 
     327             : } // namespace
     328             : 
     329           0 : VmlControlMacroAttacher::VmlControlMacroAttacher( const OUString& rMacroName,
     330             :         const Reference< XIndexContainer >& rxCtrlFormIC, sal_Int32 nCtrlIndex, sal_Int32 nCtrlType, sal_Int32 nDropStyle ) :
     331             :     VbaMacroAttacherBase( rMacroName ),
     332             :     mxCtrlFormIC( rxCtrlFormIC ),
     333             :     mnCtrlIndex( nCtrlIndex ),
     334             :     mnCtrlType( nCtrlType ),
     335           0 :     mnDropStyle( nDropStyle )
     336             : {
     337           0 : }
     338             : 
     339           0 : void VmlControlMacroAttacher::attachMacro( const OUString& rMacroUrl )
     340             : {
     341           0 :     ScriptEventDescriptor aEventDesc;
     342           0 :     aEventDesc.ScriptType = "Script";
     343           0 :     aEventDesc.ScriptCode = rMacroUrl;
     344             : 
     345             :     // editable drop downs are treated like edit boxes
     346           0 :     bool bEditDropDown = (mnCtrlType == XML_Drop) && (mnDropStyle == XML_ComboEdit);
     347           0 :     sal_Int32 nCtrlType = bEditDropDown ? XML_Edit : mnCtrlType;
     348             : 
     349           0 :     switch( nCtrlType )
     350             :     {
     351             :         case XML_Button:
     352             :         case XML_Checkbox:
     353             :         case XML_Radio:
     354           0 :             aEventDesc.ListenerType = "XActionListener";
     355           0 :             aEventDesc.EventMethod = "actionPerformed";
     356           0 :         break;
     357             :         case XML_Label:
     358             :         case XML_GBox:
     359             :         case XML_Dialog:
     360           0 :             aEventDesc.ListenerType = "XMouseListener";
     361           0 :             aEventDesc.EventMethod = "mouseReleased";
     362           0 :         break;
     363             :         case XML_Edit:
     364           0 :             aEventDesc.ListenerType = "XTextListener";
     365           0 :             aEventDesc.EventMethod = "textChanged";
     366           0 :         break;
     367             :         case XML_Spin:
     368             :         case XML_Scroll:
     369           0 :             aEventDesc.ListenerType = "XAdjustmentListener";
     370           0 :             aEventDesc.EventMethod = "adjustmentValueChanged";
     371           0 :         break;
     372             :         case XML_List:
     373             :         case XML_Drop:
     374           0 :             aEventDesc.ListenerType = "XChangeListener";
     375           0 :             aEventDesc.EventMethod = "changed";
     376           0 :         break;
     377             :         default:
     378             :             OSL_ENSURE( false, "VmlControlMacroAttacher::attachMacro - unexpected object type" );
     379           0 :             return;
     380             :     }
     381             : 
     382             :     try
     383             :     {
     384           0 :         Reference< XEventAttacherManager > xEventMgr( mxCtrlFormIC, UNO_QUERY_THROW );
     385           0 :         xEventMgr->registerScriptEvent( mnCtrlIndex, aEventDesc );
     386             :     }
     387           0 :     catch( Exception& )
     388             :     {
     389           0 :     }
     390             : }
     391             : 
     392          85 : VmlDrawing::VmlDrawing( const WorksheetHelper& rHelper ) :
     393          85 :     ::oox::vml::Drawing( rHelper.getOoxFilter(), rHelper.getDrawPage(), ::oox::vml::VMLDRAWING_EXCEL ),
     394             :     WorksheetHelper( rHelper ),
     395         170 :     maControlConv( rHelper.getBaseFilter().getModel(), rHelper.getBaseFilter().getGraphicHelper() )
     396             : {
     397             :     // default font for legacy listboxes and dropdowns: Tahoma, 8pt
     398          85 :     maListBoxFont.moName = "Tahoma";
     399          85 :     maListBoxFont.moColor = "auto";
     400          85 :     maListBoxFont.monSize = 160;
     401          85 : }
     402             : 
     403           1 : const ::oox::vml::ShapeBase* VmlDrawing::getNoteShape( const CellAddress& rPos ) const
     404             : {
     405           1 :     return getShapes().findShape( VmlFindNoteFunc( rPos ) );
     406             : }
     407             : 
     408           3 : bool VmlDrawing::isShapeSupported( const ::oox::vml::ShapeBase& rShape ) const
     409             : {
     410           3 :     const ::oox::vml::ClientData* pClientData = rShape.getClientData();
     411           3 :     return !pClientData || (pClientData->mnObjType != XML_Note);
     412             : }
     413             : 
     414           1 : OUString VmlDrawing::getShapeBaseName( const ::oox::vml::ShapeBase& rShape ) const
     415             : {
     416           1 :     if( const ::oox::vml::ClientData* pClientData = rShape.getClientData() )
     417             :     {
     418           1 :         switch( pClientData->mnObjType )
     419             :         {
     420           0 :             case XML_Button:    return OUString( "Button" );
     421           1 :             case XML_Checkbox:  return OUString( "Check Box" );
     422           0 :             case XML_Dialog:    return OUString( "Dialog Frame" );
     423           0 :             case XML_Drop:      return OUString( "Drop Down" );
     424           0 :             case XML_Edit:      return OUString( "Edit Box" );
     425           0 :             case XML_GBox:      return OUString( "Group Box" );
     426           0 :             case XML_Label:     return OUString( "Label" );
     427           0 :             case XML_List:      return OUString( "List Box" );
     428           0 :             case XML_Note:      return OUString( "Comment" );
     429           0 :             case XML_Pict:      return (pClientData->mbDde || getOleObjectInfo( rShape.getShapeId() )) ? OUString( "Object" ) : OUString( "Picture" );
     430           0 :             case XML_Radio:     return OUString( "Option Button" );
     431           0 :             case XML_Scroll:    return OUString( "Scroll Bar" );
     432           0 :             case XML_Spin:      return OUString( "Spinner" );
     433             :         }
     434             :     }
     435           0 :     return ::oox::vml::Drawing::getShapeBaseName( rShape );
     436             : }
     437             : 
     438           2 : bool VmlDrawing::convertClientAnchor( Rectangle& orShapeRect, const OUString& rShapeAnchor ) const
     439             : {
     440           2 :     if( rShapeAnchor.isEmpty() )
     441           0 :         return false;
     442           2 :     ShapeAnchor aAnchor( *this );
     443           2 :     aAnchor.importVmlAnchor( rShapeAnchor );
     444           2 :     orShapeRect = aAnchor.calcAnchorRectHmm( getDrawPageSize() );
     445           2 :     return (orShapeRect.Width >= 0) && (orShapeRect.Height >= 0);
     446             : }
     447             : 
     448           1 : Reference< XShape > VmlDrawing::createAndInsertClientXShape( const ::oox::vml::ShapeBase& rShape,
     449             :         const Reference< XShapes >& rxShapes, const Rectangle& rShapeRect ) const
     450             : {
     451             :     // simulate the legacy drawing controls with OLE form controls
     452           1 :     OUString aShapeName = rShape.getShapeName();
     453           1 :     const ::oox::vml::ClientData* pClientData = rShape.getClientData();
     454           1 :     if( !aShapeName.isEmpty() && pClientData )
     455             :     {
     456           1 :         Rectangle aShapeRect = rShapeRect;
     457           1 :         const ::oox::vml::TextBox* pTextBox = rShape.getTextBox();
     458           1 :         EmbeddedControl aControl( aShapeName );
     459           1 :         switch( pClientData->mnObjType )
     460             :         {
     461             :             case XML_Button:
     462             :             {
     463           0 :                 AxCommandButtonModel& rAxModel = aControl.createModel< AxCommandButtonModel >();
     464           0 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign );
     465           0 :                 rAxModel.mnFlags = AX_FLAGS_ENABLED | AX_FLAGS_OPAQUE | AX_FLAGS_WORDWRAP;
     466           0 :                 rAxModel.mnVerticalAlign = pClientData->mnTextVAlign;
     467             :             }
     468           0 :             break;
     469             : 
     470             :             case XML_Label:
     471             :             {
     472           0 :                 AxLabelModel& rAxModel = aControl.createModel< AxLabelModel >();
     473           0 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign );
     474           0 :                 rAxModel.mnFlags = AX_FLAGS_ENABLED | AX_FLAGS_WORDWRAP;
     475           0 :                 rAxModel.mnBorderStyle = AX_BORDERSTYLE_NONE;
     476           0 :                 rAxModel.mnSpecialEffect = AX_SPECIALEFFECT_FLAT;
     477           0 :                 rAxModel.mnVerticalAlign = pClientData->mnTextVAlign;
     478             :             }
     479           0 :             break;
     480             : 
     481             :             case XML_Edit:
     482             :             {
     483           0 :                 bool bNumeric = (pClientData->mnVTEdit == ::oox::vml::VML_CLIENTDATA_INTEGER) || (pClientData->mnVTEdit == ::oox::vml::VML_CLIENTDATA_NUMBER);
     484             :                 AxMorphDataModelBase& rAxModel = bNumeric ?
     485           0 :                     static_cast< AxMorphDataModelBase& >( aControl.createModel< AxNumericFieldModel >() ) :
     486           0 :                     static_cast< AxMorphDataModelBase& >( aControl.createModel< AxTextBoxModel >() );
     487           0 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maValue, pTextBox, pClientData->mnTextHAlign );
     488           0 :                 setFlag( rAxModel.mnFlags, AX_FLAGS_MULTILINE, pClientData->mbMultiLine );
     489           0 :                 setFlag( rAxModel.mnScrollBars, AX_SCROLLBAR_VERTICAL, pClientData->mbVScroll );
     490           0 :                 if( pClientData->mbSecretEdit )
     491           0 :                     rAxModel.mnPasswordChar = '*';
     492             :             }
     493           0 :             break;
     494             : 
     495             :             case XML_GBox:
     496             :             {
     497           0 :                 AxFrameModel& rAxModel = aControl.createModel< AxFrameModel >();
     498           0 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign );
     499           0 :                 rAxModel.mnBorderStyle = pClientData->mbNo3D ? AX_BORDERSTYLE_SINGLE : AX_BORDERSTYLE_NONE;
     500           0 :                 rAxModel.mnSpecialEffect = pClientData->mbNo3D ? AX_SPECIALEFFECT_FLAT : AX_SPECIALEFFECT_BUMPED;
     501             : 
     502             :                 /*  Move top border of groupbox up by half font height, because
     503             :                     Excel specifies Y position of the groupbox border line
     504             :                     instead the top border of the caption text. */
     505           0 :                 if( const ::oox::vml::TextFontModel* pFontModel = pTextBox ? pTextBox->getFirstFont() : 0 )
     506             :                 {
     507           0 :                     sal_Int32 nFontHeightHmm = getUnitConverter().scaleToMm100( pFontModel->monSize.get( 160 ), UNIT_TWIP );
     508           0 :                     sal_Int32 nYDiff = ::std::min< sal_Int32 >( nFontHeightHmm / 2, aShapeRect.Y );
     509           0 :                     aShapeRect.Y -= nYDiff;
     510           0 :                     aShapeRect.Height += nYDiff;
     511             :                 }
     512             :             }
     513           0 :             break;
     514             : 
     515             :             case XML_Checkbox:
     516             :             {
     517           1 :                 AxCheckBoxModel& rAxModel = aControl.createModel< AxCheckBoxModel >();
     518           1 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign );
     519           1 :                 convertControlBackground( rAxModel, rShape );
     520           1 :                 rAxModel.maValue = OUString::number( pClientData->mnChecked );
     521           1 :                 rAxModel.mnSpecialEffect = pClientData->mbNo3D ? AX_SPECIALEFFECT_FLAT : AX_SPECIALEFFECT_SUNKEN;
     522           1 :                 rAxModel.mnVerticalAlign = pClientData->mnTextVAlign;
     523           1 :                 bool bTriState = (pClientData->mnChecked != ::oox::vml::VML_CLIENTDATA_UNCHECKED) && (pClientData->mnChecked != ::oox::vml::VML_CLIENTDATA_CHECKED);
     524           1 :                 rAxModel.mnMultiSelect = bTriState ? AX_SELECTION_MULTI : AX_SELECTION_SINGLE;
     525             :             }
     526           1 :             break;
     527             : 
     528             :             case XML_Radio:
     529             :             {
     530           0 :                 AxOptionButtonModel& rAxModel = aControl.createModel< AxOptionButtonModel >();
     531           0 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, pClientData->mnTextHAlign );
     532           0 :                 convertControlBackground( rAxModel, rShape );
     533           0 :                 rAxModel.maValue = OUString::number( pClientData->mnChecked );
     534           0 :                 rAxModel.mnSpecialEffect = pClientData->mbNo3D ? AX_SPECIALEFFECT_FLAT : AX_SPECIALEFFECT_SUNKEN;
     535           0 :                 rAxModel.mnVerticalAlign = pClientData->mnTextVAlign;
     536             :             }
     537           0 :             break;
     538             : 
     539             :             case XML_List:
     540             :             {
     541           0 :                 AxListBoxModel& rAxModel = aControl.createModel< AxListBoxModel >();
     542           0 :                 convertControlFontData( rAxModel.maFontData, rAxModel.mnTextColor, maListBoxFont );
     543           0 :                 rAxModel.mnBorderStyle = pClientData->mbNo3D2 ? AX_BORDERSTYLE_SINGLE : AX_BORDERSTYLE_NONE;
     544           0 :                 rAxModel.mnSpecialEffect = pClientData->mbNo3D2 ? AX_SPECIALEFFECT_FLAT : AX_SPECIALEFFECT_SUNKEN;
     545           0 :                 switch( pClientData->mnSelType )
     546             :                 {
     547           0 :                     case XML_Single:    rAxModel.mnMultiSelect = AX_SELECTION_SINGLE;    break;
     548           0 :                     case XML_Multi:     rAxModel.mnMultiSelect = AX_SELECTION_MULTI;     break;
     549           0 :                     case XML_Extend:    rAxModel.mnMultiSelect = AX_SELECTION_EXTENDED;  break;
     550             :                 }
     551             :             }
     552           0 :             break;
     553             : 
     554             :             case XML_Drop:
     555             :             {
     556           0 :                 AxComboBoxModel& rAxModel = aControl.createModel< AxComboBoxModel >();
     557           0 :                 convertControlFontData( rAxModel.maFontData, rAxModel.mnTextColor, maListBoxFont );
     558           0 :                 rAxModel.mnDisplayStyle = AX_DISPLAYSTYLE_DROPDOWN;
     559           0 :                 rAxModel.mnShowDropButton = AX_SHOWDROPBUTTON_ALWAYS;
     560           0 :                 rAxModel.mnBorderStyle = pClientData->mbNo3D2 ? AX_BORDERSTYLE_SINGLE : AX_BORDERSTYLE_NONE;
     561           0 :                 rAxModel.mnSpecialEffect = pClientData->mbNo3D2 ? AX_SPECIALEFFECT_FLAT : AX_SPECIALEFFECT_SUNKEN;
     562           0 :                 rAxModel.mnListRows = pClientData->mnDropLines;
     563             :             }
     564           0 :             break;
     565             : 
     566             :             case XML_Spin:
     567             :             {
     568           0 :                 AxSpinButtonModel& rAxModel = aControl.createModel< AxSpinButtonModel >();
     569           0 :                 rAxModel.mnMin = pClientData->mnMin;
     570           0 :                 rAxModel.mnMax = pClientData->mnMax;
     571           0 :                 rAxModel.mnPosition = pClientData->mnVal;
     572           0 :                 rAxModel.mnSmallChange = pClientData->mnInc;
     573             :             }
     574           0 :             break;
     575             : 
     576             :             case XML_Scroll:
     577             :             {
     578           0 :                 AxScrollBarModel& rAxModel = aControl.createModel< AxScrollBarModel >();
     579           0 :                 rAxModel.mnMin = pClientData->mnMin;
     580           0 :                 rAxModel.mnMax = pClientData->mnMax;
     581           0 :                 rAxModel.mnPosition = pClientData->mnVal;
     582           0 :                 rAxModel.mnSmallChange = pClientData->mnInc;
     583           0 :                 rAxModel.mnLargeChange = pClientData->mnPage;
     584             :             }
     585           0 :             break;
     586             : 
     587             :             case XML_Dialog:
     588             :             {
     589             :                 // fake with a group box
     590           0 :                 AxFrameModel& rAxModel = aControl.createModel< AxFrameModel >();
     591           0 :                 convertControlText( rAxModel.maFontData, rAxModel.mnTextColor, rAxModel.maCaption, pTextBox, XML_Left );
     592           0 :                 rAxModel.mnBorderStyle = AX_BORDERSTYLE_SINGLE;
     593           0 :                 rAxModel.mnSpecialEffect = AX_SPECIALEFFECT_FLAT;
     594             :             }
     595           0 :             break;
     596             :         }
     597             : 
     598           1 :         if( ControlModelBase* pAxModel = aControl.getModel() )
     599             :         {
     600             :             // create the control shape
     601           1 :             pAxModel->maSize.first = aShapeRect.Width;
     602           1 :             pAxModel->maSize.second = aShapeRect.Height;
     603           1 :             sal_Int32 nCtrlIndex = -1;
     604           1 :             Reference< XShape > xShape = createAndInsertXControlShape( aControl, rxShapes, aShapeRect, nCtrlIndex );
     605             : 
     606             :             // control shape macro
     607           1 :             if( xShape.is() && (nCtrlIndex >= 0) && !pClientData->maFmlaMacro.isEmpty() )
     608             :             {
     609           0 :                 OUString aMacroName = getFormulaParser().importMacroName( pClientData->maFmlaMacro );
     610           0 :                 if( !aMacroName.isEmpty() )
     611             :                 {
     612           0 :                     Reference< XIndexContainer > xFormIC = getControlForm().getXForm();
     613           0 :                     VbaMacroAttacherRef xAttacher( new VmlControlMacroAttacher( aMacroName, xFormIC, nCtrlIndex, pClientData->mnObjType, pClientData->mnDropStyle ) );
     614           0 :                     getBaseFilter().getVbaProject().registerMacroAttacher( xAttacher );
     615           0 :                 }
     616             :             }
     617             : 
     618           1 :             return xShape;
     619           0 :         }
     620             :     }
     621             : 
     622           0 :     return Reference< XShape >();
     623             : }
     624             : 
     625           2 : void VmlDrawing::notifyXShapeInserted( const Reference< XShape >& rxShape,
     626             :         const Rectangle& rShapeRect, const ::oox::vml::ShapeBase& rShape, bool bGroupChild )
     627             : {
     628             :     // collect all shape positions in the WorksheetHelper base class (but not children of group shapes)
     629           2 :     if( !bGroupChild )
     630           2 :         extendShapeBoundingBox( rShapeRect );
     631             : 
     632             :     // convert settings from VML client data
     633           2 :     if( const ::oox::vml::ClientData* pClientData = rShape.getClientData() )
     634             :     {
     635             :         // specific settings for embedded form controls
     636             :         try
     637             :         {
     638           1 :             Reference< XControlShape > xCtrlShape( rxShape, UNO_QUERY_THROW );
     639           2 :             Reference< XControlModel > xCtrlModel( xCtrlShape->getControl(), UNO_SET_THROW );
     640           2 :             PropertySet aPropSet( xCtrlModel );
     641             : 
     642             :             // printable
     643           1 :             aPropSet.setProperty( PROP_Printable, pClientData->mbPrintObject );
     644             : 
     645             :             // control source links
     646           1 :             if( !pClientData->maFmlaLink.isEmpty() || !pClientData->maFmlaRange.isEmpty() )
     647           1 :                 maControlConv.bindToSources( xCtrlModel, pClientData->maFmlaLink, pClientData->maFmlaRange, getSheetIndex() );
     648             :         }
     649           0 :         catch( Exception& )
     650             :         {
     651             :         }
     652             :     }
     653           2 : }
     654             : 
     655             : // private --------------------------------------------------------------------
     656             : 
     657           1 : sal_uInt32 VmlDrawing::convertControlTextColor( const OUString& rTextColor ) const
     658             : {
     659             :     // color attribute not present or 'auto' - use passed default color
     660           1 :     if( rTextColor.isEmpty() || rTextColor.equalsIgnoreAsciiCase( "auto" ) )
     661           0 :         return AX_SYSCOLOR_WINDOWTEXT;
     662             : 
     663           1 :     if( rTextColor[ 0 ] == '#' )
     664             :     {
     665             :         // RGB colors in the format '#RRGGBB'
     666           1 :         if( rTextColor.getLength() == 7 )
     667           1 :             return OleHelper::encodeOleColor( rTextColor.copy( 1 ).toUInt32( 16 ) );
     668             : 
     669             :         // RGB colors in the format '#RGB'
     670           0 :         if( rTextColor.getLength() == 4 )
     671             :         {
     672           0 :             sal_Int32 nR = rTextColor.copy( 1, 1 ).toUInt32( 16 ) * 0x11;
     673           0 :             sal_Int32 nG = rTextColor.copy( 2, 1 ).toUInt32( 16 ) * 0x11;
     674           0 :             sal_Int32 nB = rTextColor.copy( 3, 1 ).toUInt32( 16 ) * 0x11;
     675           0 :             return OleHelper::encodeOleColor( (nR << 16) | (nG << 8) | nB );
     676             :         }
     677             : 
     678             :         OSL_ENSURE( false, OStringBuffer( "VmlDrawing::convertControlTextColor - invalid color name '" ).
     679             :             append( OUStringToOString( rTextColor, RTL_TEXTENCODING_ASCII_US ) ).append( '\'' ).getStr() );
     680           0 :         return AX_SYSCOLOR_WINDOWTEXT;
     681             :     }
     682             : 
     683           0 :     const GraphicHelper& rGraphicHelper = getBaseFilter().getGraphicHelper();
     684             : 
     685             :     /*  Predefined color names or system color names (resolve to RGB to detect
     686             :         valid color name). */
     687           0 :     sal_Int32 nColorToken = AttributeConversion::decodeToken( rTextColor );
     688           0 :     sal_Int32 nRgbValue = Color::getVmlPresetColor( nColorToken, API_RGB_TRANSPARENT );
     689           0 :     if( nRgbValue == API_RGB_TRANSPARENT )
     690           0 :         nRgbValue = rGraphicHelper.getSystemColor( nColorToken, API_RGB_TRANSPARENT );
     691           0 :     if( nRgbValue != API_RGB_TRANSPARENT )
     692           0 :         return OleHelper::encodeOleColor( nRgbValue );
     693             : 
     694             :     // try palette color
     695           0 :     return OleHelper::encodeOleColor( rGraphicHelper.getPaletteColor( rTextColor.toInt32() ) );
     696             : }
     697             : 
     698           1 : void VmlDrawing::convertControlFontData( AxFontData& rAxFontData, sal_uInt32& rnOleTextColor, const ::oox::vml::TextFontModel& rFontModel ) const
     699             : {
     700           1 :     if( rFontModel.moName.has() )
     701           1 :         rAxFontData.maFontName = rFontModel.moName.get();
     702             : 
     703             :     // font height: convert from twips to points, then to internal representation of AX controls
     704           1 :     rAxFontData.setHeightPoints( static_cast< sal_Int16 >( (rFontModel.monSize.get( 200 ) + 10) / 20 ) );
     705             : 
     706             :     // font effects
     707           1 :     rAxFontData.mnFontEffects = 0;
     708           1 :     setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_BOLD, rFontModel.mobBold.get( false ) );
     709           1 :     setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_ITALIC, rFontModel.mobItalic.get( false ) );
     710           1 :     setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_STRIKEOUT, rFontModel.mobStrikeout.get( false ) );
     711           1 :     sal_Int32 nUnderline = rFontModel.monUnderline.get( XML_none );
     712           1 :     setFlag( rAxFontData.mnFontEffects, AX_FONTDATA_UNDERLINE, nUnderline != XML_none );
     713           1 :     rAxFontData.mbDblUnderline = nUnderline == XML_double;
     714             : 
     715             :     // font color
     716           1 :     rnOleTextColor = convertControlTextColor( rFontModel.moColor.get( OUString() ) );
     717           1 : }
     718             : 
     719           1 : void VmlDrawing::convertControlText( AxFontData& rAxFontData, sal_uInt32& rnOleTextColor,
     720             :         OUString& rCaption, const ::oox::vml::TextBox* pTextBox, sal_Int32 nTextHAlign ) const
     721             : {
     722           1 :     if( pTextBox )
     723             :     {
     724           1 :         rCaption = pTextBox->getText();
     725           1 :         if( const ::oox::vml::TextFontModel* pFontModel = pTextBox->getFirstFont() )
     726           1 :             convertControlFontData( rAxFontData, rnOleTextColor, *pFontModel );
     727             :     }
     728             : 
     729           1 :     switch( nTextHAlign )
     730             :     {
     731           1 :         case XML_Left:      rAxFontData.mnHorAlign = AX_FONTDATA_LEFT;      break;
     732           0 :         case XML_Center:    rAxFontData.mnHorAlign = AX_FONTDATA_CENTER;    break;
     733           0 :         case XML_Right:     rAxFontData.mnHorAlign = AX_FONTDATA_RIGHT;     break;
     734           0 :         default:            rAxFontData.mnHorAlign = AX_FONTDATA_LEFT;
     735             :     }
     736           1 : }
     737             : 
     738           1 : void VmlDrawing::convertControlBackground( AxMorphDataModelBase& rAxModel, const ::oox::vml::ShapeBase& rShape ) const
     739             : {
     740           1 :     const ::oox::vml::FillModel& rFillModel = rShape.getTypeModel().maFillModel;
     741           1 :     bool bHasFill = rFillModel.moFilled.get( true );
     742           1 :     setFlag( rAxModel.mnFlags, AX_FLAGS_OPAQUE, bHasFill );
     743           1 :     if( bHasFill )
     744             :     {
     745           0 :         const GraphicHelper& rGraphicHelper = getBaseFilter().getGraphicHelper();
     746           0 :         sal_Int32 nSysWindowColor = rGraphicHelper.getSystemColor( XML_window, API_RGB_WHITE );
     747           0 :         ::oox::drawingml::Color aColor = ::oox::vml::ConversionHelper::decodeColor( rGraphicHelper, rFillModel.moColor, rFillModel.moOpacity, nSysWindowColor );
     748           0 :         sal_Int32 nRgbValue = aColor.getColor( rGraphicHelper );
     749           0 :         rAxModel.mnBackColor = OleHelper::encodeOleColor( nRgbValue );
     750             :     }
     751           1 : }
     752             : 
     753           3 : VmlDrawingFragment::VmlDrawingFragment( const WorksheetHelper& rHelper, const OUString& rFragmentPath ) :
     754           6 :     ::oox::vml::DrawingFragment( rHelper.getOoxFilter(), rFragmentPath, rHelper.getVmlDrawing() ),
     755           6 :     WorksheetHelper( rHelper )
     756             : {
     757           3 : }
     758             : 
     759           3 : void VmlDrawingFragment::finalizeImport()
     760             : {
     761           3 :     ::oox::vml::DrawingFragment::finalizeImport();
     762           3 :     getVmlDrawing().convertAndInsert();
     763           3 : }
     764             : 
     765             : } // namespace xls
     766          18 : } // namespace oox
     767             : 
     768             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10