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