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

Generated by: LCOV version 1.10