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