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