merge the formfield patch from ooo-build
[ooovba.git] / svx / source / unodraw / unoshap2.cxx
blob1d3b94ebe9b2623f9db4dc01c12dc7b4e4526656
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unoshap2.cxx,v $
10 * $Revision: 1.70 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #define _SVX_USE_UNOGLOBALS_
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <com/sun/star/awt/FontSlant.hpp>
37 #include <com/sun/star/style/VerticalAlignment.hpp>
38 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
39 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
40 #include <com/sun/star/awt/TextAlign.hpp> //added by BerryJia for fixing Bug102407 2002-11-4
41 #include <com/sun/star/style/ParagraphAdjust.hpp> //added by BerryJia for fixing Bug102407 2002-11-4
42 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
43 #include <com/sun/star/drawing/PointSequence.hpp>
44 #include <com/sun/star/graphic/XGraphic.hpp>
45 #include <tools/urlobj.hxx>
46 #include <unotools/localfilehelper.hxx>
47 #include <vcl/svapp.hxx>
48 #include <vos/mutex.hxx>
49 #include <svtools/fltcall.hxx>
50 #include "impgrf.hxx"
52 #include <boost/scoped_ptr.hpp>
54 #include <rtl/uuid.h>
55 #include <rtl/memory.h>
56 #include <tools/urlobj.hxx>
58 #include <svx/unoprnms.hxx>
59 #include <svx/unoshape.hxx>
60 #include <svx/unopage.hxx>
61 #include <svx/svdobj.hxx>
62 #include <svx/svdpage.hxx>
63 #include <svx/svdmodel.hxx>
64 #include <svx/svdouno.hxx>
65 #include "shapeimpl.hxx"
66 #include "svx/unoshprp.hxx"
67 #include <svx/svdoashp.hxx>
68 #include "unopolyhelper.hxx"
70 // #i29181#
71 #include "svdviter.hxx"
72 #include <svx/svdview.hxx>
73 #include <basegfx/matrix/b2dhommatrix.hxx>
74 #include <basegfx/polygon/b2dpolygon.hxx>
75 #include <basegfx/point/b2dpoint.hxx>
76 #include <basegfx/polygon/b2dpolygontools.hxx>
78 using ::rtl::OUString;
79 using namespace ::osl;
80 using namespace ::vos;
81 using namespace ::cppu;
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::uno;
84 using namespace ::com::sun::star::lang;
85 using namespace ::com::sun::star::container;
87 #define INTERFACE_TYPE( xint ) \
88 ::getCppuType((const Reference< xint >*)0)
90 #define QUERYINT( xint ) \
91 if( rType == ::getCppuType((const Reference< xint >*)0) ) \
92 aAny <<= Reference< xint >(this)
94 class GDIMetaFile;
95 class SvStream;
96 sal_Bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
97 FilterConfigItem* pFilterConfigItem = NULL, sal_Bool bPlaceable = sal_True );
99 /***********************************************************************
100 * class SvxShapeGroup *
101 ***********************************************************************/
103 SvxShapeGroup::SvxShapeGroup( SdrObject* pObj, SvxDrawPage* pDrawPage ) throw() :
104 SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_GROUP), aSvxMapProvider.GetPropertySet(SVXMAP_GROUP) ),
105 mxPage( pDrawPage )
109 //----------------------------------------------------------------------
110 SvxShapeGroup::~SvxShapeGroup() throw()
114 //----------------------------------------------------------------------
115 void SvxShapeGroup::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
117 SvxShape::Create( pNewObj, pNewPage );
118 mxPage = pNewPage;
121 //----------------------------------------------------------------------
122 uno::Any SAL_CALL SvxShapeGroup::queryInterface( const uno::Type & rType )
123 throw(uno::RuntimeException)
125 return SvxShape::queryInterface( rType );
128 uno::Any SAL_CALL SvxShapeGroup::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
130 uno::Any aAny;
132 QUERYINT( drawing::XShapeGroup );
133 else QUERYINT( drawing::XShapes );
134 else QUERYINT( container::XIndexAccess );
135 else QUERYINT( container::XElementAccess );
136 else
137 return SvxShape::queryAggregation( rType );
139 return aAny;
142 void SAL_CALL SvxShapeGroup::acquire() throw ( )
144 SvxShape::acquire();
147 void SAL_CALL SvxShapeGroup::release() throw ( )
149 SvxShape::release();
152 uno::Sequence< uno::Type > SAL_CALL SvxShapeGroup::getTypes()
153 throw (uno::RuntimeException)
155 return SvxShape::getTypes();
158 uno::Sequence< sal_Int8 > SAL_CALL SvxShapeGroup::getImplementationId()
159 throw (uno::RuntimeException)
161 static uno::Sequence< sal_Int8 > aId;
162 if( aId.getLength() == 0 )
164 aId.realloc( 16 );
165 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
167 return aId;
170 // ::com::sun::star::drawing::XShape
172 //----------------------------------------------------------------------
173 OUString SAL_CALL SvxShapeGroup::getShapeType()
174 throw( uno::RuntimeException )
176 return SvxShape::getShapeType();
179 //------------------------------------------------------------------1----
180 awt::Point SAL_CALL SvxShapeGroup::getPosition() throw(uno::RuntimeException)
182 return SvxShape::getPosition();
185 //----------------------------------------------------------------------
186 void SAL_CALL SvxShapeGroup::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
188 SvxShape::setPosition(Position);
191 //----------------------------------------------------------------------
193 awt::Size SAL_CALL SvxShapeGroup::getSize() throw(uno::RuntimeException)
195 return SvxShape::getSize();
198 //----------------------------------------------------------------------
199 void SAL_CALL SvxShapeGroup::setSize( const awt::Size& rSize )
200 throw(beans::PropertyVetoException, uno::RuntimeException)
202 SvxShape::setSize( rSize );
205 // drawing::XShapeGroup
207 //----------------------------------------------------------------------
208 void SAL_CALL SvxShapeGroup::enterGroup( ) throw(uno::RuntimeException)
210 // Todo
211 // pDrView->EnterMarkedGroup();
214 //----------------------------------------------------------------------
215 void SAL_CALL SvxShapeGroup::leaveGroup( ) throw(uno::RuntimeException)
217 // Todo
218 // pDrView->LeaveOneGroup();
221 //----------------------------------------------------------------------
223 // XShapes
224 void SAL_CALL SvxShapeGroup::add( const uno::Reference< drawing::XShape >& xShape )
225 throw( uno::RuntimeException )
227 OGuard aGuard( Application::GetSolarMutex() );
229 SvxShape* pShape = SvxShape::getImplementation( xShape );
231 if( mpObj.is()&& mxPage.is() && pShape )
233 SdrObject* pSdrShape = pShape->GetSdrObject();
234 if( pSdrShape == NULL )
235 pSdrShape = mxPage->_CreateSdrObject( xShape );
237 if( pSdrShape->IsInserted() )
238 pSdrShape->GetObjList()->RemoveObject( pSdrShape->GetOrdNum() );
240 mpObj->GetSubList()->InsertObject( pSdrShape );
241 pSdrShape->SetModel(mpObj->GetModel());
243 // #85922# It makes no sense to set the layer asked
244 // from the group object since these is an iteration
245 // over the contained objects. In consequence, this
246 // statement erases all layer information from the draw
247 // objects. Layers need to be set at draw objects directly
248 // and have nothing to do with grouping at all.
249 // pSdrShape->SetLayer(pObject->GetLayer());
251 // Establish connection between new SdrObject and its wrapper before
252 // inserting the new shape into the group. There a new wrapper
253 // would be created when this connection would not already exist.
254 if(pShape)
255 pShape->Create( pSdrShape, mxPage.get() );
257 if( mpModel )
258 mpModel->SetChanged();
260 else
262 DBG_ERROR("could not add XShape to group shape!");
266 //----------------------------------------------------------------------
267 void SAL_CALL SvxShapeGroup::remove( const uno::Reference< drawing::XShape >& xShape )
268 throw( uno::RuntimeException )
270 OGuard aGuard( Application::GetSolarMutex() );
272 SdrObject* pSdrShape = NULL;
273 SvxShape* pShape = SvxShape::getImplementation( xShape );
275 if( pShape )
276 pSdrShape = pShape->GetSdrObject();
278 if( !mpObj.is() || pSdrShape == NULL || pSdrShape->GetObjList()->GetOwnerObj() != mpObj.get() )
279 throw uno::RuntimeException();
281 SdrObjList& rList = *pSdrShape->GetObjList();
283 const sal_uInt32 nObjCount = rList.GetObjCount();
284 sal_uInt32 nObjNum = 0;
285 while( nObjNum < nObjCount )
287 if(rList.GetObj( nObjNum ) == pSdrShape )
288 break;
289 nObjNum++;
292 if( nObjNum < nObjCount )
294 // #i29181#
295 // If the SdrObject which is about to be deleted is in any selection,
296 // deselect it first.
297 SdrViewIter aIter( pSdrShape );
299 for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
301 if(CONTAINER_ENTRY_NOTFOUND != pView->TryToFindMarkedObject(pSdrShape))
303 pView->MarkObj(pSdrShape, pView->GetSdrPageView(), sal_True, sal_False);
307 SdrObject* pObject = rList.NbcRemoveObject( nObjNum );
308 SdrObject::Free( pObject );
310 else
312 DBG_ASSERT( 0, "Fatality! SdrObject is not belonging to its SdrObjList! [CL]" );
315 if( mpModel )
316 mpModel->SetChanged();
319 // XIndexAccess
321 //----------------------------------------------------------------------
322 sal_Int32 SAL_CALL SvxShapeGroup::getCount() throw( uno::RuntimeException )
324 OGuard aGuard( Application::GetSolarMutex() );
326 sal_Int32 nRetval = 0;
328 if(mpObj.is() && mpObj->GetSubList())
329 nRetval = mpObj->GetSubList()->GetObjCount();
330 else
331 throw uno::RuntimeException();
333 return nRetval;
336 //----------------------------------------------------------------------
337 uno::Any SAL_CALL SvxShapeGroup::getByIndex( sal_Int32 Index )
338 throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
340 OGuard aGuard( Application::GetSolarMutex() );
342 if( !mpObj.is() || mpObj->GetSubList() == NULL )
343 throw uno::RuntimeException();
345 if( mpObj->GetSubList()->GetObjCount() <= (sal_uInt32)Index )
346 throw lang::IndexOutOfBoundsException();
348 SdrObject* pDestObj = mpObj->GetSubList()->GetObj( Index );
350 if(pDestObj == NULL)
351 throw lang::IndexOutOfBoundsException();
353 Reference< drawing::XShape > xShape( pDestObj->getUnoShape(), uno::UNO_QUERY );
354 return uno::makeAny( xShape );
357 // ::com::sun::star::container::XElementAccess
359 //----------------------------------------------------------------------
360 uno::Type SAL_CALL SvxShapeGroup::getElementType() throw( uno::RuntimeException )
362 return ::getCppuType(( const Reference< drawing::XShape >*)0);
365 //----------------------------------------------------------------------
366 sal_Bool SAL_CALL SvxShapeGroup::hasElements() throw( uno::RuntimeException )
368 OGuard aGuard( Application::GetSolarMutex() );
370 return mpObj.is() && mpObj->GetSubList() && (mpObj->GetSubList()->GetObjCount() > 0);
373 //----------------------------------------------------------------------
374 // ::com::sun::star::lang::XServiceInfo
376 uno::Sequence< OUString > SAL_CALL SvxShapeGroup::getSupportedServiceNames()
377 throw(uno::RuntimeException)
379 return SvxShape::getSupportedServiceNames();
382 /***********************************************************************
384 ***********************************************************************/
386 SvxShapeConnector::SvxShapeConnector( SdrObject* pObj ) throw() :
387 SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CONNECTOR), aSvxMapProvider.GetPropertySet(SVXMAP_CONNECTOR) )
391 //----------------------------------------------------------------------
392 SvxShapeConnector::~SvxShapeConnector() throw()
396 //----------------------------------------------------------------------
398 uno::Any SAL_CALL SvxShapeConnector::queryInterface( const uno::Type & rType )
399 throw(uno::RuntimeException)
401 return SvxShapeText::queryInterface( rType );
404 uno::Any SAL_CALL SvxShapeConnector::queryAggregation( const uno::Type & rType )
405 throw(uno::RuntimeException)
407 uno::Any aAny;
409 QUERYINT( drawing::XConnectorShape );
410 else
411 return SvxShapeText::queryAggregation( rType );
413 return aAny;
416 void SAL_CALL SvxShapeConnector::acquire() throw ( )
418 SvxShapeText::acquire();
421 void SAL_CALL SvxShapeConnector::release() throw ( )
423 SvxShapeText::release();
425 // XTypeProvider
427 uno::Sequence< uno::Type > SAL_CALL SvxShapeConnector::getTypes()
428 throw (uno::RuntimeException)
430 return SvxShape::getTypes();
433 uno::Sequence< sal_Int8 > SAL_CALL SvxShapeConnector::getImplementationId()
434 throw (uno::RuntimeException)
436 static uno::Sequence< sal_Int8 > aId;
437 if( aId.getLength() == 0 )
439 aId.realloc( 16 );
440 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
442 return aId;
445 // ::com::sun::star::drawing::XShape
447 //----------------------------------------------------------------------
448 OUString SAL_CALL SvxShapeConnector::getShapeType()
449 throw( uno::RuntimeException )
451 return SvxShapeText::getShapeType();
454 //------------------------------------------------------------------1----
455 awt::Point SAL_CALL SvxShapeConnector::getPosition() throw(uno::RuntimeException)
457 return SvxShapeText::getPosition();
460 //----------------------------------------------------------------------
461 void SAL_CALL SvxShapeConnector::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
463 SvxShapeText::setPosition(Position);
466 //----------------------------------------------------------------------
468 awt::Size SAL_CALL SvxShapeConnector::getSize() throw(uno::RuntimeException)
470 return SvxShapeText::getSize();
473 //----------------------------------------------------------------------
474 void SAL_CALL SvxShapeConnector::setSize( const awt::Size& rSize )
475 throw(beans::PropertyVetoException, uno::RuntimeException)
477 SvxShapeText::setSize( rSize );
480 //----------------------------------------------------------------------
482 // XConnectorShape
484 void SAL_CALL SvxShapeConnector::connectStart( const uno::Reference< drawing::XConnectableShape >& xShape, drawing::ConnectionType ) throw( uno::RuntimeException )
486 OGuard aGuard( Application::GetSolarMutex() );
488 Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
489 SvxShape* pShape = SvxShape::getImplementation( xRef );
491 if( pShape )
492 mpObj->ConnectToNode( sal_True, pShape->mpObj.get() );
494 if( mpModel )
495 mpModel->SetChanged();
498 //----------------------------------------------------------------------
499 void SAL_CALL SvxShapeConnector::connectEnd( const uno::Reference< drawing::XConnectableShape >& xShape, drawing::ConnectionType )
500 throw( uno::RuntimeException )
502 OGuard aGuard( Application::GetSolarMutex() );
504 Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
505 SvxShape* pShape = SvxShape::getImplementation( xRef );
507 if( mpObj.is() && pShape )
508 mpObj->ConnectToNode( sal_False, pShape->mpObj.get() );
510 if( mpModel )
511 mpModel->SetChanged();
514 //----------------------------------------------------------------------
515 void SAL_CALL SvxShapeConnector::disconnectBegin( const uno::Reference< drawing::XConnectableShape >& )
516 throw( uno::RuntimeException )
518 OGuard aGuard( Application::GetSolarMutex() );
520 if(mpObj.is())
521 mpObj->DisconnectFromNode( sal_True );
523 if( mpModel )
524 mpModel->SetChanged();
527 //----------------------------------------------------------------------
528 void SAL_CALL SvxShapeConnector::disconnectEnd( const uno::Reference< drawing::XConnectableShape >& )
529 throw( uno::RuntimeException )
531 OGuard aGuard( Application::GetSolarMutex() );
533 if(mpObj.is())
534 mpObj->DisconnectFromNode( sal_False );
536 if( mpModel )
537 mpModel->SetChanged();
540 //----------------------------------------------------------------------
541 // ::com::sun::star::lang::XServiceInfo
542 //----------------------------------------------------------------------
543 uno::Sequence< OUString > SAL_CALL SvxShapeConnector::getSupportedServiceNames() throw( uno::RuntimeException )
545 return SvxShapeText::getSupportedServiceNames();
548 /***********************************************************************
549 * class SvxShapeControl *
550 ***********************************************************************/
551 DBG_NAME(SvxShapeControl)
553 SvxShapeControl::SvxShapeControl( SdrObject* pObj ) throw() :
554 SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CONTROL), aSvxMapProvider.GetPropertySet(SVXMAP_CONTROL) )
556 DBG_CTOR(SvxShapeControl,NULL);
557 setShapeKind( OBJ_UNO );
560 //----------------------------------------------------------------------
561 SvxShapeControl::~SvxShapeControl() throw()
563 DBG_DTOR(SvxShapeControl,NULL);
566 //----------------------------------------------------------------------
567 uno::Any SAL_CALL SvxShapeControl::queryInterface( const uno::Type & rType )
568 throw(uno::RuntimeException)
570 return SvxShapeText::queryInterface( rType );
573 uno::Any SAL_CALL SvxShapeControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
575 uno::Any aAny;
577 QUERYINT( drawing::XControlShape );
578 else
579 return SvxShapeText::queryAggregation( rType );
581 return aAny;
584 void SAL_CALL SvxShapeControl::acquire() throw ( )
586 SvxShapeText::acquire();
589 void SAL_CALL SvxShapeControl::release() throw ( )
591 SvxShapeText::release();
593 // XTypeProvider
595 uno::Sequence< uno::Type > SAL_CALL SvxShapeControl::getTypes()
596 throw (uno::RuntimeException)
598 return SvxShape::getTypes();
601 uno::Sequence< sal_Int8 > SAL_CALL SvxShapeControl::getImplementationId()
602 throw (uno::RuntimeException)
604 static uno::Sequence< sal_Int8 > aId;
605 if( aId.getLength() == 0 )
607 aId.realloc( 16 );
608 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
610 return aId;
613 // ::com::sun::star::drawing::XShape
615 //----------------------------------------------------------------------
616 OUString SAL_CALL SvxShapeControl::getShapeType()
617 throw( uno::RuntimeException )
619 return SvxShapeText::getShapeType();
622 //------------------------------------------------------------------1----
623 awt::Point SAL_CALL SvxShapeControl::getPosition() throw(uno::RuntimeException)
625 return SvxShapeText::getPosition();
628 //----------------------------------------------------------------------
629 void SAL_CALL SvxShapeControl::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
631 SvxShapeText::setPosition(Position);
634 //----------------------------------------------------------------------
636 awt::Size SAL_CALL SvxShapeControl::getSize() throw(uno::RuntimeException)
638 return SvxShapeText::getSize();
641 //----------------------------------------------------------------------
642 void SAL_CALL SvxShapeControl::setSize( const awt::Size& rSize )
643 throw(beans::PropertyVetoException, uno::RuntimeException)
645 SvxShapeText::setSize( rSize );
648 //----------------------------------------------------------------------
649 // XControlShape
651 Reference< awt::XControlModel > SAL_CALL SvxShapeControl::getControl()
652 throw( uno::RuntimeException )
654 OGuard aGuard( Application::GetSolarMutex() );
656 Reference< awt::XControlModel > xModel;
658 SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(mpObj.get());
659 if( pUnoObj )
660 xModel = pUnoObj->GetUnoControlModel();
662 return xModel;
665 //----------------------------------------------------------------------
666 void SAL_CALL SvxShapeControl::setControl( const Reference< awt::XControlModel >& xControl )
667 throw( uno::RuntimeException )
669 OGuard aGuard( Application::GetSolarMutex() );
671 SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(mpObj.get());
672 if( pUnoObj )
673 pUnoObj->SetUnoControlModel( xControl );
675 if( mpModel )
676 mpModel->SetChanged();
679 // XServiceInfo
680 uno::Sequence< OUString > SAL_CALL SvxShapeControl::getSupportedServiceNames() throw( uno::RuntimeException )
682 return SvxShapeText::getSupportedServiceNames();
685 static struct
687 const sal_Char* mpAPIName;
688 sal_uInt16 mnAPINameLen;
690 const sal_Char* mpFormName;
691 sal_uInt16 mnFormNameLen;
693 SvxShapeControlPropertyMapping[] =
695 // Warning: The first entry must be FontSlant because the any needs to be converted
696 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_POSTURE), MAP_CHAR_LEN("FontSlant") }, // const sal_Int16 => ::com::sun::star::awt::FontSlant
697 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTNAME), MAP_CHAR_LEN("FontName") },
698 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTSTYLENAME), MAP_CHAR_LEN("FontStyleName") },
699 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTFAMILY), MAP_CHAR_LEN("FontFamily") },
700 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTCHARSET), MAP_CHAR_LEN("FontCharset") },
701 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_HEIGHT), MAP_CHAR_LEN("FontHeight") },
702 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTPITCH), MAP_CHAR_LEN("FontPitch" ) },
703 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_WEIGHT), MAP_CHAR_LEN("FontWeight" ) },
704 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_UNDERLINE), MAP_CHAR_LEN("FontUnderline") },
705 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_STRIKEOUT), MAP_CHAR_LEN("FontStrikeout") },
706 { MAP_CHAR_LEN("CharKerning"), MAP_CHAR_LEN("FontKerning") },
707 { MAP_CHAR_LEN("CharWordMode"), MAP_CHAR_LEN("FontWordLineMode" ) },
708 { MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_COLOR), MAP_CHAR_LEN("TextColor") },
709 { MAP_CHAR_LEN("CharRelief"), MAP_CHAR_LEN("FontRelief") },
710 { MAP_CHAR_LEN("CharUnderlineColor"), MAP_CHAR_LEN("TextLineColor") },
711 { MAP_CHAR_LEN(UNO_NAME_EDIT_PARA_ADJUST), MAP_CHAR_LEN("Align") },
712 { MAP_CHAR_LEN("TextVerticalAdjust"), MAP_CHAR_LEN("VerticalAlign") },
713 { MAP_CHAR_LEN("ControlBackground"), MAP_CHAR_LEN("BackgroundColor") },
714 { MAP_CHAR_LEN("ControlSymbolColor"), MAP_CHAR_LEN("SymbolColor") },
715 { MAP_CHAR_LEN("ControlBorder"), MAP_CHAR_LEN("Border") },
716 { MAP_CHAR_LEN("ControlBorderColor"), MAP_CHAR_LEN("BorderColor") },
717 { MAP_CHAR_LEN("ControlTextEmphasis"), MAP_CHAR_LEN("FontEmphasisMark") },
718 { MAP_CHAR_LEN("ImageScaleMode"), MAP_CHAR_LEN("ScaleMode") },
719 { MAP_CHAR_LEN("ControlWritingMode"), MAP_CHAR_LEN("WritingMode") },
720 { NULL,0, NULL, 0 }
723 namespace
725 static bool lcl_convertPropertyName( const OUString& rApiName, OUString& rInternalName )
727 sal_uInt16 i = 0;
728 while( SvxShapeControlPropertyMapping[i].mpAPIName )
730 if( rApiName.reverseCompareToAsciiL( SvxShapeControlPropertyMapping[i].mpAPIName, SvxShapeControlPropertyMapping[i].mnAPINameLen ) == 0 )
732 rInternalName = OUString( SvxShapeControlPropertyMapping[i].mpFormName, SvxShapeControlPropertyMapping[i].mnFormNameLen, RTL_TEXTENCODING_ASCII_US );
734 ++i;
736 return rInternalName.getLength() > 0;
739 struct EnumConversionMap
741 sal_Int16 nAPIValue;
742 sal_Int16 nFormValue;
745 EnumConversionMap aMapAdjustToAlign[] =
747 // note that order matters:
748 // lcl_convertTextAlignmentToParaAdjustment and lcl_convertParaAdjustmentToTextAlignment search this map from the _beginning_
749 // and use the first matching entry
750 {style::ParagraphAdjust_LEFT, (sal_Int16)awt::TextAlign::LEFT},
751 {style::ParagraphAdjust_CENTER, (sal_Int16)awt::TextAlign::CENTER},
752 {style::ParagraphAdjust_RIGHT, (sal_Int16)awt::TextAlign::RIGHT},
753 {style::ParagraphAdjust_BLOCK, (sal_Int16)awt::TextAlign::RIGHT},
754 {style::ParagraphAdjust_STRETCH, (sal_Int16)awt::TextAlign::LEFT},
755 {-1,-1}
758 static void lcl_mapFormToAPIValue( Any& _rValue, const EnumConversionMap* _pMap )
760 sal_Int16 nValue = sal_Int16();
761 OSL_VERIFY( _rValue >>= nValue );
763 const EnumConversionMap* pEntry = _pMap;
764 while ( pEntry && ( pEntry->nFormValue != -1 ) )
766 if ( nValue == pEntry->nFormValue )
768 _rValue <<= pEntry->nAPIValue;
769 return;
771 ++pEntry;
775 static void lcl_mapAPIToFormValue( Any& _rValue, const EnumConversionMap* _pMap )
777 sal_Int32 nValue = 0;
778 OSL_VERIFY( _rValue >>= nValue );
780 const EnumConversionMap* pEntry = _pMap;
781 while ( pEntry && ( pEntry->nAPIValue != -1 ) )
783 if ( nValue == pEntry->nAPIValue )
785 _rValue <<= pEntry->nFormValue;
786 return;
788 ++pEntry;
792 static void lcl_convertTextAlignmentToParaAdjustment( Any& rValue )
794 lcl_mapFormToAPIValue( rValue, aMapAdjustToAlign );
797 static void lcl_convertParaAdjustmentToTextAlignment( Any& rValue )
799 lcl_mapAPIToFormValue( rValue, aMapAdjustToAlign );
802 void convertVerticalAdjustToVerticalAlign( Any& _rValue ) SAL_THROW( ( lang::IllegalArgumentException ) )
804 if ( !_rValue.hasValue() )
805 return;
807 drawing::TextVerticalAdjust eAdjust = drawing::TextVerticalAdjust_TOP;
808 style::VerticalAlignment eAlign = style::VerticalAlignment_TOP;
809 if ( !( _rValue >>= eAdjust ) )
810 throw lang::IllegalArgumentException();
811 switch ( eAdjust )
813 case drawing::TextVerticalAdjust_TOP: eAlign = style::VerticalAlignment_TOP; break;
814 case drawing::TextVerticalAdjust_BOTTOM: eAlign = style::VerticalAlignment_BOTTOM; break;
815 default: eAlign = style::VerticalAlignment_MIDDLE; break;
817 _rValue <<= eAlign;
820 void convertVerticalAlignToVerticalAdjust( Any& _rValue )
822 if ( !_rValue.hasValue() )
823 return;
824 style::VerticalAlignment eAlign = style::VerticalAlignment_TOP;
825 drawing::TextVerticalAdjust eAdjust = drawing::TextVerticalAdjust_TOP;
826 OSL_VERIFY( _rValue >>= eAlign );
827 switch ( eAlign )
829 case style::VerticalAlignment_TOP: eAdjust = drawing::TextVerticalAdjust_TOP; break;
830 case style::VerticalAlignment_BOTTOM: eAdjust = drawing::TextVerticalAdjust_BOTTOM; break;
831 default: eAdjust = drawing::TextVerticalAdjust_CENTER; break;
833 _rValue <<= eAdjust;
837 void SAL_CALL SvxShapeControl::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
838 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException)
840 OUString aFormsName;
841 if ( lcl_convertPropertyName( aPropertyName, aFormsName ) )
843 uno::Reference< beans::XPropertySet > xControl( getControl(), uno::UNO_QUERY );
844 if( xControl.is() )
846 uno::Reference< beans::XPropertySetInfo > xInfo( xControl->getPropertySetInfo() );
847 if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
849 uno::Any aConvertedValue( aValue );
850 if ( aFormsName.equalsAscii( "FontSlant" ) )
852 awt::FontSlant nSlant;
853 if( !(aValue >>= nSlant ) )
854 throw lang::IllegalArgumentException();
855 aConvertedValue <<= (sal_Int16)nSlant;
857 else if ( aFormsName.equalsAscii( "Align" ) )
859 lcl_convertParaAdjustmentToTextAlignment( aConvertedValue );
861 else if ( aFormsName.equalsAscii( "VerticalAlign" ) )
863 convertVerticalAdjustToVerticalAlign( aConvertedValue );
866 xControl->setPropertyValue( aFormsName, aConvertedValue );
870 else
872 SvxShape::setPropertyValue( aPropertyName, aValue );
876 uno::Any SAL_CALL SvxShapeControl::getPropertyValue( const OUString& aPropertyName )
877 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
879 OUString aFormsName;
880 if ( lcl_convertPropertyName( aPropertyName, aFormsName ) )
882 uno::Reference< beans::XPropertySet > xControl( getControl(), uno::UNO_QUERY );
884 uno::Any aValue;
885 if( xControl.is() )
887 uno::Reference< beans::XPropertySetInfo > xInfo( xControl->getPropertySetInfo() );
888 if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
890 aValue = xControl->getPropertyValue( aFormsName );
891 if ( aFormsName.equalsAscii( "FontSlant" ) )
893 awt::FontSlant eSlant = awt::FontSlant_NONE;
894 sal_Int16 nSlant = sal_Int16();
895 if ( aValue >>= nSlant )
897 eSlant = (awt::FontSlant)nSlant;
899 else
901 OSL_VERIFY( aValue >>= eSlant );
903 aValue <<= eSlant;
905 else if ( aFormsName.equalsAscii( "Align" ) )
907 lcl_convertTextAlignmentToParaAdjustment( aValue );
909 else if ( aFormsName.equalsAscii( "VerticalAlign" ) )
911 convertVerticalAlignToVerticalAdjust( aValue );
916 return aValue;
918 else
920 return SvxShape::getPropertyValue( aPropertyName );
925 // XPropertyState
926 beans::PropertyState SAL_CALL SvxShapeControl::getPropertyState( const ::rtl::OUString& PropertyName ) throw( beans::UnknownPropertyException, uno::RuntimeException )
928 OUString aFormsName;
929 if ( lcl_convertPropertyName( PropertyName, aFormsName ) )
931 uno::Reference< beans::XPropertyState > xControl( getControl(), uno::UNO_QUERY );
932 uno::Reference< beans::XPropertySet > xPropSet( getControl(), uno::UNO_QUERY );
934 if( xControl.is() && xPropSet.is() )
936 uno::Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
937 if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
939 return xControl->getPropertyState( aFormsName );
943 return beans::PropertyState_DEFAULT_VALUE;
945 else
947 return SvxShape::getPropertyState( PropertyName );
951 void SAL_CALL SvxShapeControl::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw( beans::UnknownPropertyException, uno::RuntimeException )
953 OUString aFormsName;
954 if ( lcl_convertPropertyName( PropertyName, aFormsName ) )
956 uno::Reference< beans::XPropertyState > xControl( getControl(), uno::UNO_QUERY );
957 uno::Reference< beans::XPropertySet > xPropSet( getControl(), uno::UNO_QUERY );
959 if( xControl.is() && xPropSet.is() )
961 uno::Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
962 if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
964 xControl->setPropertyToDefault( aFormsName );
968 else
970 SvxShape::setPropertyToDefault( PropertyName );
974 uno::Any SAL_CALL SvxShapeControl::getPropertyDefault( const ::rtl::OUString& aPropertyName )
975 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
977 OUString aFormsName;
978 if ( lcl_convertPropertyName( aPropertyName, aFormsName ) )
980 uno::Reference< beans::XPropertyState > xControl( getControl(), uno::UNO_QUERY );
982 if( xControl.is() )
984 Any aDefault( xControl->getPropertyDefault( aFormsName ) );
985 if ( aFormsName.equalsAscii( "FontSlant" ) )
987 sal_Int16 nSlant( 0 );
988 aDefault >>= nSlant;
989 aDefault <<= (awt::FontSlant)nSlant;
991 else if ( aFormsName.equalsAscii( "Align" ) )
993 lcl_convertTextAlignmentToParaAdjustment( aDefault );
995 else if ( aFormsName.equalsAscii( "VerticalAlign" ) )
997 convertVerticalAlignToVerticalAdjust( aDefault );
999 return aDefault;
1002 throw beans::UnknownPropertyException();
1004 else
1006 return SvxShape::getPropertyDefault( aPropertyName );
1011 /***********************************************************************
1012 * class SvxShapeDimensioning *
1013 ***********************************************************************/
1015 //----------------------------------------------------------------------
1016 SvxShapeDimensioning::SvxShapeDimensioning( SdrObject* pObj ) throw()
1017 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_DIMENSIONING), aSvxMapProvider.GetPropertySet(SVXMAP_DIMENSIONING) )
1021 //----------------------------------------------------------------------
1022 SvxShapeDimensioning::~SvxShapeDimensioning() throw()
1026 // ::com::sun::star::lang::XServiceInfo
1027 uno::Sequence< OUString > SAL_CALL SvxShapeDimensioning::getSupportedServiceNames() throw( uno::RuntimeException )
1029 return SvxShapeText::getSupportedServiceNames();
1032 /***********************************************************************
1034 ***********************************************************************/
1036 //----------------------------------------------------------------------
1037 SvxShapeCircle::SvxShapeCircle( SdrObject* pObj ) throw()
1038 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CIRCLE), aSvxMapProvider.GetPropertySet(SVXMAP_CIRCLE) )
1042 //----------------------------------------------------------------------
1043 SvxShapeCircle::~SvxShapeCircle() throw()
1047 // ::com::sun::star::lang::XServiceInfo
1048 // XServiceInfo
1049 uno::Sequence< OUString > SAL_CALL SvxShapeCircle::getSupportedServiceNames() throw( uno::RuntimeException )
1051 return SvxShapeText::getSupportedServiceNames();
1054 /***********************************************************************
1056 ***********************************************************************/
1058 #include <svx/svdopath.hxx>
1060 //----------------------------------------------------------------------
1061 SvxShapePolyPolygon::SvxShapePolyPolygon( SdrObject* pObj , drawing::PolygonKind eNew )
1062 throw( com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException)
1063 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_POLYPOLYGON), aSvxMapProvider.GetPropertySet(SVXMAP_POLYPOLYGON) )
1064 , mePolygonKind( eNew )
1068 //----------------------------------------------------------------------
1069 SvxShapePolyPolygon::~SvxShapePolyPolygon() throw()
1073 basegfx::B2DPolyPolygon SAL_CALL ImplSvxPointSequenceSequenceToB2DPolyPolygon( const drawing::PointSequenceSequence* pOuterSequence) throw()
1075 basegfx::B2DPolyPolygon aRetval;
1077 // Zeiger auf innere sequences holen
1078 const drawing::PointSequence* pInnerSequence = pOuterSequence->getConstArray();
1079 const drawing::PointSequence* pInnerSeqEnd = pInnerSequence + pOuterSequence->getLength();
1081 for(;pInnerSequence != pInnerSeqEnd; ++pInnerSequence)
1083 // Neues Polygon vorbereiten
1084 basegfx::B2DPolygon aNewPolygon;
1086 // Zeiger auf Arrays holen
1087 const awt::Point* pArray = pInnerSequence->getConstArray();
1088 const awt::Point* pArrayEnd = pArray + pInnerSequence->getLength();
1090 for(;pArray != pArrayEnd;++pArray)
1092 aNewPolygon.append(basegfx::B2DPoint(pArray->X, pArray->Y));
1095 // check for closed state flag
1096 basegfx::tools::checkClosed(aNewPolygon);
1098 // Neues Teilpolygon einfuegen
1099 aRetval.append(aNewPolygon);
1102 return aRetval;
1105 //----------------------------------------------------------------------
1107 bool SvxShapePolyPolygon::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1109 switch( pProperty->nWID )
1111 case OWN_ATTR_VALUE_POLYPOLYGON:
1113 if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PointSequenceSequence*)0) ) )
1115 basegfx::B2DPolyPolygon aNewPolyPolygon(ImplSvxPointSequenceSequenceToB2DPolyPolygon( (drawing::PointSequenceSequence*)rValue.getValue()));
1116 SetPolygon(aNewPolyPolygon);
1117 return true;
1119 break;
1121 case OWN_ATTR_BASE_GEOMETRY:
1123 if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PointSequenceSequence*)0)))
1125 if( mpObj.is() )
1127 basegfx::B2DPolyPolygon aNewPolyPolygon;
1128 basegfx::B2DHomMatrix aNewHomogenMatrix;
1130 mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1131 aNewPolyPolygon = ImplSvxPointSequenceSequenceToB2DPolyPolygon((drawing::PointSequenceSequence*)rValue.getValue());
1132 mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1134 return true;
1136 break;
1138 case OWN_ATTR_VALUE_POLYGON:
1140 if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PointSequenceSequence*)0) ))
1142 drawing::PointSequence* pSequence = (drawing::PointSequence*)rValue.getValue();
1144 // Neues Polygon vorbereiten
1145 basegfx::B2DPolygon aNewPolygon;
1147 // Zeiger auf Arrays holen
1148 // Zeiger auf Arrays holen
1149 const awt::Point* pArray = pSequence->getConstArray();
1150 const awt::Point* pArrayEnd = pArray + pSequence->getLength();
1152 for(;pArray != pArrayEnd;++pArray)
1154 aNewPolygon.append(basegfx::B2DPoint(pArray->X, pArray->Y));
1157 // check for closed state flag
1158 basegfx::tools::checkClosed(aNewPolygon);
1160 // Polygon setzen
1161 SetPolygon(basegfx::B2DPolyPolygon(aNewPolygon));
1162 return true;
1164 break;
1166 default:
1167 return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
1170 throw lang::IllegalArgumentException();
1173 void SAL_CALL B2DPolyPolygonToSvxPointSequenceSequence( const basegfx::B2DPolyPolygon& rPolyPoly, drawing::PointSequenceSequence& rRetval )
1175 if( (sal_uInt32)rRetval.getLength() != rPolyPoly.count() )
1176 rRetval.realloc( rPolyPoly.count() );
1178 // Zeiger auf aeussere Arrays holen
1179 drawing::PointSequence* pOuterSequence = rRetval.getArray();
1181 for(sal_uInt32 a(0L); a < rPolyPoly.count(); a++)
1183 // Einzelpolygon holen
1184 const basegfx::B2DPolygon aPoly(rPolyPoly.getB2DPolygon(a));
1186 // #i75974# take closed stae into account, the API polygon still uses the old closed definition
1187 // with last/first point are identical (cannot hold information about open polygons with identical
1188 // first and last point, though)
1189 const sal_uInt32 nPointCount(aPoly.count());
1190 const bool bIsClosed(aPoly.isClosed());
1192 // Platz in Arrays schaffen
1193 pOuterSequence->realloc(bIsClosed ? nPointCount + 1 : nPointCount);
1195 // Pointer auf arrays holen
1196 awt::Point* pInnerSequence = pOuterSequence->getArray();
1198 for(sal_uInt32 b(0L); b < nPointCount; b++)
1200 const basegfx::B2DPoint aPoint(aPoly.getB2DPoint(b));
1201 *pInnerSequence = awt::Point( basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY()) );
1202 pInnerSequence++;
1205 // #i75974# copy first point
1206 if(bIsClosed)
1208 *pInnerSequence = *pOuterSequence->getArray();
1211 pOuterSequence++;
1215 //----------------------------------------------------------------------
1217 bool SvxShapePolyPolygon::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1219 switch( pProperty->nWID )
1221 case OWN_ATTR_VALUE_POLYPOLYGON:
1223 // PolyPolygon in eine struct PolyPolygon packen
1224 const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
1225 drawing::PointSequenceSequence aRetval( rPolyPoly.count() );
1227 B2DPolyPolygonToSvxPointSequenceSequence( rPolyPoly, aRetval );
1229 rValue <<= aRetval;
1230 break;
1232 case OWN_ATTR_BASE_GEOMETRY:
1234 // pack a PolyPolygon in struct PolyPolygon
1235 basegfx::B2DPolyPolygon aNewPolyPolygon;
1236 basegfx::B2DHomMatrix aNewHomogenMatrix;
1238 if(mpObj.is())
1239 mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1241 drawing::PointSequenceSequence aRetval(aNewPolyPolygon.count());
1242 B2DPolyPolygonToSvxPointSequenceSequence(aNewPolyPolygon, aRetval);
1243 rValue <<= aRetval;
1244 break;
1246 case OWN_ATTR_VALUE_POLYGON:
1248 // PolyPolygon in eine struct PolyPolygon packen
1249 const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
1251 sal_Int32 nCount = 0;
1252 if( rPolyPoly.count() > 0 )
1253 nCount = rPolyPoly.getB2DPolygon(0L).count();
1255 drawing::PointSequence aRetval( nCount );
1257 if( nCount > 0 )
1259 // Einzelpolygon holen
1260 const basegfx::B2DPolygon aPoly(rPolyPoly.getB2DPolygon(0L));
1262 // Pointer auf arrays holen
1263 awt::Point* pSequence = aRetval.getArray();
1265 for(sal_Int32 b=0;b<nCount;b++)
1267 const basegfx::B2DPoint aPoint(aPoly.getB2DPoint(b));
1268 *pSequence++ = awt::Point( basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY()) );
1272 rValue <<= aRetval;
1273 break;
1275 case OWN_ATTR_VALUE_POLYGONKIND:
1277 rValue <<= GetPolygonKind();
1278 break;
1280 default:
1281 return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
1284 return true;
1287 //----------------------------------------------------------------------
1288 drawing::PolygonKind SvxShapePolyPolygon::GetPolygonKind() const throw()
1290 return mePolygonKind;
1293 //----------------------------------------------------------------------
1294 void SvxShapePolyPolygon::SetPolygon(const basegfx::B2DPolyPolygon& rNew) throw()
1296 OGuard aGuard( Application::GetSolarMutex() );
1298 if(mpObj.is())
1299 ((SdrPathObj*)mpObj.get())->SetPathPoly(rNew);
1302 //----------------------------------------------------------------------
1303 basegfx::B2DPolyPolygon SvxShapePolyPolygon::GetPolygon() const throw()
1305 OGuard aGuard( Application::GetSolarMutex() );
1307 if(mpObj.is())
1309 return ((SdrPathObj*)mpObj.get())->GetPathPoly();
1311 else
1313 return basegfx::B2DPolyPolygon();
1317 // ::com::sun::star::lang::XServiceInfo
1318 uno::Sequence< OUString > SAL_CALL SvxShapePolyPolygon::getSupportedServiceNames() throw( uno::RuntimeException )
1320 return SvxShapeText::getSupportedServiceNames();
1323 /***********************************************************************
1324 * class SvxShapePolyPolygonBezier *
1325 ***********************************************************************/
1326 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
1327 #include <com/sun/star/drawing/FlagSequence.hpp>
1328 //----------------------------------------------------------------------
1329 SvxShapePolyPolygonBezier::SvxShapePolyPolygonBezier( SdrObject* pObj , drawing::PolygonKind eNew ) throw()
1330 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_POLYPOLYGONBEZIER), aSvxMapProvider.GetPropertySet(SVXMAP_POLYPOLYGONBEZIER) )
1331 , mePolygonKind( eNew )
1335 //----------------------------------------------------------------------
1336 SvxShapePolyPolygonBezier::~SvxShapePolyPolygonBezier() throw()
1340 basegfx::B2DPolyPolygon SvxConvertPolyPolygonBezierToB2DPolyPolygon(const drawing::PolyPolygonBezierCoords* pSourcePolyPolygon)
1341 throw( IllegalArgumentException )
1343 const sal_Int32 nOuterSequenceCount(pSourcePolyPolygon->Coordinates.getLength());
1344 basegfx::B2DPolyPolygon aNewPolyPolygon;
1346 if(pSourcePolyPolygon->Flags.getLength() != nOuterSequenceCount)
1348 throw IllegalArgumentException();
1351 // get pointers to inner sequence
1352 const drawing::PointSequence* pInnerSequence = pSourcePolyPolygon->Coordinates.getConstArray();
1353 const drawing::FlagSequence* pInnerSequenceFlags = pSourcePolyPolygon->Flags.getConstArray();
1355 for(sal_Int32 a(0); a < nOuterSequenceCount; a++)
1357 const sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
1359 if(pInnerSequenceFlags->getLength() != nInnerSequenceCount)
1361 throw IllegalArgumentException();
1364 // prepare new polygon
1365 basegfx::B2DPolygon aNewPolygon;
1366 const awt::Point* pArray = pInnerSequence->getConstArray();
1367 const drawing::PolygonFlags* pArrayFlags = pInnerSequenceFlags->getConstArray();
1369 // get first point and flag
1370 basegfx::B2DPoint aNewCoordinatePair(pArray->X, pArray->Y); pArray++;
1371 XPolyFlags ePolyFlag((XPolyFlags)((sal_uInt16)*pArrayFlags)); pArrayFlags++;
1372 basegfx::B2DPoint aControlA;
1373 basegfx::B2DPoint aControlB;
1375 // first point is not allowed to be a control point
1376 if(XPOLY_CONTROL == ePolyFlag)
1378 throw IllegalArgumentException();
1381 // add first point as start point
1382 aNewPolygon.append(aNewCoordinatePair);
1384 for(sal_Int32 b(1); b < nInnerSequenceCount;)
1386 // prepare loop
1387 bool bControlA(false);
1388 bool bControlB(false);
1390 // get next point and flag
1391 aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
1392 ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
1393 pArray++; pArrayFlags++; b++;
1395 if(b < nInnerSequenceCount && XPOLY_CONTROL == ePolyFlag)
1397 aControlA = aNewCoordinatePair;
1398 bControlA = true;
1400 // get next point and flag
1401 aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
1402 ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
1403 pArray++; pArrayFlags++; b++;
1406 if(b < nInnerSequenceCount && XPOLY_CONTROL == ePolyFlag)
1408 aControlB = aNewCoordinatePair;
1409 bControlB = true;
1411 // get next point and flag
1412 aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
1413 ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
1414 pArray++; pArrayFlags++; b++;
1417 // two or no control points are consumed, another one would be an error.
1418 // It's also an error if only one control point was read
1419 if(XPOLY_CONTROL == ePolyFlag || bControlA != bControlB)
1421 throw IllegalArgumentException();
1424 // the previous writes used the B2DPolyPoygon -> PolyPolygon converter
1425 // which did not create minimal PolyPolygons, but created all control points
1426 // as null vectors (identical points). Because of the former P(CA)(CB)-norm of
1427 // B2DPolygon and it's unused sign of being the zero-vector and CA and CB being
1428 // relative to P, an empty edge was exported as P == CA == CB. Luckily, the new
1429 // export format can be read without errors by the old OOo-versions, so we need only
1430 // to correct here at read and do not need to export a wrong but compatible version
1431 // for the future.
1432 if(bControlA
1433 && aControlA.equal(aControlB)
1434 && aControlA.equal(aNewPolygon.getB2DPoint(aNewPolygon.count() - 1)))
1436 bControlA = bControlB = false;
1439 if(bControlA)
1441 // add bezier edge
1442 aNewPolygon.appendBezierSegment(aControlA, aControlB, aNewCoordinatePair);
1444 else
1446 // add edge
1447 aNewPolygon.append(aNewCoordinatePair);
1451 // next sequence
1452 pInnerSequence++;
1453 pInnerSequenceFlags++;
1455 // #i72807# API import uses old line start/end-equal definition for closed,
1456 // so we need to correct this to closed state here
1457 basegfx::tools::checkClosed(aNewPolygon);
1459 // add new subpolygon
1460 aNewPolyPolygon.append(aNewPolygon);
1463 return aNewPolyPolygon;
1466 //----------------------------------------------------------------------
1468 bool SvxShapePolyPolygonBezier::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1470 switch( pProperty->nWID )
1472 case OWN_ATTR_VALUE_POLYPOLYGONBEZIER:
1474 if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PolyPolygonBezierCoords*)0) ) )
1476 basegfx::B2DPolyPolygon aNewPolyPolygon(SvxConvertPolyPolygonBezierToB2DPolyPolygon( (drawing::PolyPolygonBezierCoords*)rValue.getValue()));
1477 SetPolygon(aNewPolyPolygon);
1478 return true;
1480 break;
1482 case OWN_ATTR_BASE_GEOMETRY:
1484 if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PolyPolygonBezierCoords*)0)) )
1486 if( mpObj.is() )
1488 basegfx::B2DPolyPolygon aNewPolyPolygon;
1489 basegfx::B2DHomMatrix aNewHomogenMatrix;
1491 mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1492 aNewPolyPolygon = SvxConvertPolyPolygonBezierToB2DPolyPolygon((drawing::PolyPolygonBezierCoords*)rValue.getValue());
1493 mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1495 return true;
1497 break;
1499 default:
1500 return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
1503 throw IllegalArgumentException();
1506 void SvxConvertB2DPolyPolygonToPolyPolygonBezier( const basegfx::B2DPolyPolygon& rPolyPoly, drawing::PolyPolygonBezierCoords& rRetval )
1508 // use PolyPolygon converter as base. Since PolyPolygonBezierCoords uses
1509 // integer coordinates, this is no precision loss at all.
1510 const PolyPolygon aPolyPoly(rPolyPoly);
1512 // Polygone innerhalb vrobereiten
1513 rRetval.Coordinates.realloc((sal_Int32)aPolyPoly.Count());
1514 rRetval.Flags.realloc((sal_Int32)aPolyPoly.Count());
1516 // Zeiger auf aeussere Arrays holen
1517 drawing::PointSequence* pOuterSequence = rRetval.Coordinates.getArray();
1518 drawing::FlagSequence* pOuterFlags = rRetval.Flags.getArray();
1520 for(sal_uInt16 a=0;a<aPolyPoly.Count();a++)
1522 // Einzelpolygon holen
1523 const Polygon& rPoly = aPolyPoly[a];
1525 // Platz in Arrays schaffen
1526 pOuterSequence->realloc((sal_Int32)rPoly.GetSize());
1527 pOuterFlags->realloc((sal_Int32)rPoly.GetSize());
1529 // Pointer auf arrays holen
1530 awt::Point* pInnerSequence = pOuterSequence->getArray();
1531 drawing::PolygonFlags* pInnerFlags = pOuterFlags->getArray();
1533 for(sal_uInt16 b=0;b<rPoly.GetSize();b++)
1535 *pInnerSequence++ = awt::Point( rPoly[b].X(), rPoly[b].Y() );
1536 *pInnerFlags++ = (drawing::PolygonFlags)((sal_uInt16)rPoly.GetFlags(b));
1539 pOuterSequence++;
1540 pOuterFlags++;
1544 //----------------------------------------------------------------------
1546 bool SvxShapePolyPolygonBezier::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1548 switch( pProperty->nWID )
1550 case OWN_ATTR_VALUE_POLYPOLYGONBEZIER:
1552 // PolyPolygon in eine struct PolyPolygon packen
1553 const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
1554 drawing::PolyPolygonBezierCoords aRetval;
1555 SvxConvertB2DPolyPolygonToPolyPolygonBezier(rPolyPoly, aRetval );
1557 rValue <<= aRetval;
1558 break;
1560 case OWN_ATTR_BASE_GEOMETRY:
1562 // PolyPolygon in eine struct PolyPolygon packen
1563 basegfx::B2DPolyPolygon aNewPolyPolygon;
1564 basegfx::B2DHomMatrix aNewHomogenMatrix;
1565 mpObj.get()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1566 drawing::PolyPolygonBezierCoords aRetval;
1567 SvxConvertB2DPolyPolygonToPolyPolygonBezier(aNewPolyPolygon, aRetval);
1569 rValue <<= aRetval;
1570 break;
1572 case OWN_ATTR_VALUE_POLYGONKIND:
1574 rValue <<= mePolygonKind;
1575 break;
1577 default:
1578 return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
1580 return true;
1583 //----------------------------------------------------------------------
1584 drawing::PolygonKind SvxShapePolyPolygonBezier::GetPolygonKind() const throw()
1586 return mePolygonKind;
1589 //----------------------------------------------------------------------
1590 void SvxShapePolyPolygonBezier::SetPolygon(const basegfx::B2DPolyPolygon& rNew) throw()
1592 OGuard aGuard( Application::GetSolarMutex() );
1594 if(mpObj.is())
1595 static_cast<SdrPathObj*>(mpObj.get())->SetPathPoly(rNew);
1598 //----------------------------------------------------------------------
1599 basegfx::B2DPolyPolygon SvxShapePolyPolygonBezier::GetPolygon() const throw()
1601 OGuard aGuard( Application::GetSolarMutex() );
1603 if(mpObj.is())
1605 return static_cast<SdrPathObj*>(mpObj.get())->GetPathPoly();
1607 else
1609 return basegfx::B2DPolyPolygon();
1614 // ::com::sun::star::lang::XServiceInfo
1615 uno::Sequence< OUString > SAL_CALL SvxShapePolyPolygonBezier::getSupportedServiceNames() throw( uno::RuntimeException )
1617 return SvxShapeText::getSupportedServiceNames();
1620 /***********************************************************************
1621 * class SvxGraphicObject *
1622 ***********************************************************************/
1623 #include <com/sun/star/awt/XBitmap.hpp>
1624 #include <vcl/cvtgrf.hxx>
1625 #include <svx/svdograf.hxx>
1626 #ifndef SVX_LIGHT
1627 #ifndef _SFXDOCFILE_HXX
1628 #include <sfx2/docfile.hxx>
1629 #endif
1630 #include <sfx2/app.hxx>
1631 #include <sfx2/fcontnr.hxx>
1632 #endif
1634 #include "toolkit/unohlp.hxx"
1636 //----------------------------------------------------------------------
1637 SvxGraphicObject::SvxGraphicObject( SdrObject* pObj ) throw()
1638 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_GRAPHICOBJECT), aSvxMapProvider.GetPropertySet(SVXMAP_GRAPHICOBJECT) )
1642 //----------------------------------------------------------------------
1643 SvxGraphicObject::~SvxGraphicObject() throw()
1647 //----------------------------------------------------------------------
1649 bool SvxGraphicObject::setPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1651 bool bOk = false;
1652 switch( pProperty->nWID )
1654 case OWN_ATTR_VALUE_FILLBITMAP:
1656 if( rValue.getValue() )
1658 if( rValue.getValueType() == ::getCppuType(( const uno::Sequence< sal_Int8 >*)0) )
1660 uno::Sequence<sal_Int8>* pSeq( (uno::Sequence<sal_Int8>*)rValue.getValue() );
1661 SvMemoryStream aMemStm;
1662 Graphic aGraphic;
1664 aMemStm.SetBuffer( (char*)pSeq->getConstArray(), pSeq->getLength(), sal_False, pSeq->getLength() );
1666 if( GraphicConverter::Import( aMemStm, aGraphic ) == ERRCODE_NONE )
1668 static_cast<SdrGrafObj*>(mpObj.get())->SetGraphic(aGraphic);
1669 bOk = true;
1673 else if( (rValue.getValueType() == awt::XBitmap::static_type()) || (rValue.getValueType() == graphic::XGraphic::static_type()))
1675 Reference< graphic::XGraphic> xGraphic( rValue, UNO_QUERY );
1676 if( xGraphic.is() )
1678 ((SdrGrafObj*)mpObj.get())->SetGraphic(Graphic(xGraphic));
1679 bOk = true;
1681 else
1683 // Bitmap in das Objekt packen
1684 Reference< awt::XBitmap > xBmp( rValue, UNO_QUERY );
1685 if( xBmp.is() )
1687 // Bitmap einsetzen
1688 Graphic aGraphic(VCLUnoHelper::GetBitmap( xBmp ));
1689 ((SdrGrafObj*)mpObj.get())->SetGraphic(aGraphic);
1690 bOk = true;
1694 break;
1696 case OWN_ATTR_GRAFURL:
1698 OUString aURL;
1699 if( rValue >>= aURL )
1701 if( aURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 )
1703 // graphic manager url
1704 aURL = aURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 );
1705 String aTmpStr(aURL);
1706 ByteString aUniqueID( aTmpStr, RTL_TEXTENCODING_UTF8 );
1707 GraphicObject aGrafObj( aUniqueID );
1709 // #101808# since loading a graphic can cause a reschedule of the office
1710 // it is possible that our shape is removed while where in this
1711 // method.
1712 if( mpObj.is() )
1714 static_cast<SdrGrafObj*>(mpObj.get())->ReleaseGraphicLink();
1715 static_cast<SdrGrafObj*>(mpObj.get())->SetGraphicObject( aGrafObj );
1718 else if( aURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPKGPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPKGPREFIX ) ) != 0 )
1720 // normal link
1721 String aFilterName;
1722 const SfxFilter* pSfxFilter = NULL;
1723 SfxMedium aSfxMedium( aURL, STREAM_READ | STREAM_SHARE_DENYNONE, FALSE );
1725 SFX_APP()->GetFilterMatcher().GuessFilter( aSfxMedium, &pSfxFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
1727 if( !pSfxFilter )
1729 INetURLObject aURLObj( aURL );
1731 if( aURLObj.GetProtocol() == INET_PROT_NOT_VALID )
1733 String aValidURL;
1735 if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aURL, aValidURL ) )
1736 aURLObj = INetURLObject( aValidURL );
1739 if( aURLObj.GetProtocol() != INET_PROT_NOT_VALID )
1741 GraphicFilter* pGrfFilter = GetGrfFilter();
1742 aFilterName = pGrfFilter->GetImportFormatName( pGrfFilter->GetImportFormatNumberForShortName( aURLObj.getExtension() ) );
1745 else
1746 aFilterName = pSfxFilter->GetFilterName();
1748 // #101808# since loading a graphic can cause a reschedule of the office
1749 // it is possible that our shape is removed while where in this
1750 // method.
1751 if( mpObj.is() )
1752 static_cast<SdrGrafObj*>(mpObj.get())->SetGraphicLink( aURL, aFilterName );
1755 bOk = true;
1757 break;
1760 case OWN_ATTR_GRAFSTREAMURL:
1762 OUString aStreamURL;
1764 if( rValue >>= aStreamURL )
1766 if( aStreamURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPKGPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPKGPREFIX ) ) != 0 )
1767 aStreamURL = OUString();
1769 if( mpObj.is() )
1771 static_cast<SdrGrafObj*>(mpObj.get())->SetGrafStreamURL( aStreamURL );
1772 static_cast<SdrGrafObj*>(mpObj.get())->ForceSwapOut();
1774 bOk = true;
1776 break;
1779 case OWN_ATTR_VALUE_GRAPHIC:
1781 Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
1782 if( xGraphic.is() )
1784 static_cast< SdrGrafObj*>( mpObj.get() )->SetGraphic( xGraphic );
1785 bOk = true;
1787 break;
1789 default:
1790 return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
1793 if( !bOk )
1794 throw lang::IllegalArgumentException();
1796 if( mpModel )
1797 mpModel->SetChanged();
1799 return true;
1802 //----------------------------------------------------------------------
1804 bool SvxGraphicObject::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1806 switch( pProperty->nWID )
1808 case OWN_ATTR_VALUE_FILLBITMAP:
1810 const Graphic& rGraphic = static_cast< SdrGrafObj*>( mpObj.get() )->GetGraphic();
1812 if(rGraphic.GetType() != GRAPHIC_GDIMETAFILE)
1814 // Objekt in eine Bitmap packen
1815 Reference< ::com::sun::star::awt::XBitmap > xBitmap( VCLUnoHelper::CreateBitmap(static_cast< SdrGrafObj*>( mpObj.get() )->GetGraphic().GetBitmapEx()) );
1816 rValue <<= xBitmap;
1818 else
1820 SvMemoryStream aDestStrm( 65535, 65535 );
1822 ConvertGDIMetaFileToWMF( rGraphic.GetGDIMetaFile(), aDestStrm, NULL, sal_False );
1823 uno::Sequence<sal_Int8> aSeq((sal_Int8*)aDestStrm.GetData(), aDestStrm.GetSize());
1824 rValue <<= aSeq;
1826 break;
1829 case OWN_ATTR_GRAFURL:
1831 if( static_cast< SdrGrafObj*>( mpObj.get() )->IsLinkedGraphic() )
1833 rValue <<= OUString( static_cast< SdrGrafObj*>( mpObj.get() )->GetFileName() );
1835 else
1837 const GraphicObject& rGrafObj = static_cast< SdrGrafObj*>( mpObj.get() )->GetGraphicObject(true);
1838 OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
1839 aURL += OUString::createFromAscii( rGrafObj.GetUniqueID().GetBuffer() );
1840 rValue <<= aURL;
1842 break;
1845 case OWN_ATTR_GRAFSTREAMURL:
1847 const OUString aStreamURL( ( (SdrGrafObj*) mpObj.get() )->GetGrafStreamURL() );
1848 if( aStreamURL.getLength() )
1849 rValue <<= aStreamURL;
1850 break;
1853 case OWN_ATTR_VALUE_GRAPHIC:
1855 Reference< graphic::XGraphic > xGraphic( static_cast< SdrGrafObj* >( mpObj.get() )->GetGraphic().GetXGraphic() );
1856 rValue <<= xGraphic;
1857 break;
1860 case OWN_ATTR_GRAPHIC_STREAM:
1862 rValue <<= static_cast< SdrGrafObj* >( mpObj.get() )->getInputStream();
1863 break;
1865 default:
1866 return SvxShapeText::getPropertyValueImpl(rName, pProperty,rValue);
1869 return true;
1872 ///////////////////////////////////////////////////////////////////////
1874 SvxShapeCaption::SvxShapeCaption( SdrObject* pObj ) throw()
1875 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CAPTION), aSvxMapProvider.GetPropertySet(SVXMAP_CAPTION) )
1879 SvxShapeCaption::~SvxShapeCaption() throw()
1883 /***********************************************************************
1884 * class SvxCustomShape *
1885 ***********************************************************************/
1887 SvxCustomShape::SvxCustomShape( SdrObject* pObj ) throw() :
1888 SvxShapeText( pObj, aSvxMapProvider.GetMap( SVXMAP_CUSTOMSHAPE ), aSvxMapProvider.GetPropertySet(SVXMAP_CUSTOMSHAPE) )
1892 //----------------------------------------------------------------------
1893 SvxCustomShape::~SvxCustomShape() throw()
1897 //----------------------------------------------------------------------
1899 void SvxCustomShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
1901 SvxShapeText::Create( pNewObj, pNewPage );
1904 //----------------------------------------------------------------------
1906 uno::Any SAL_CALL SvxCustomShape::queryInterface( const uno::Type & rType )
1907 throw(uno::RuntimeException)
1909 return SvxShapeText::queryInterface( rType );
1912 uno::Any SAL_CALL SvxCustomShape::queryAggregation( const uno::Type & rType )
1913 throw(uno::RuntimeException)
1915 ::com::sun::star::uno::Any aReturn = SvxShapeText::queryAggregation( rType );
1916 if ( !aReturn.hasValue() )
1917 aReturn = ::cppu::queryInterface(rType, static_cast<drawing::XEnhancedCustomShapeDefaulter*>(this) );
1918 return aReturn;
1921 void SAL_CALL SvxCustomShape::acquire() throw ( )
1923 SvxShapeText::acquire();
1926 void SAL_CALL SvxCustomShape::release() throw ( )
1928 SvxShapeText::release();
1931 //----------------------------------------------------------------------
1933 uno::Sequence< uno::Type > SAL_CALL SvxCustomShape::getTypes()
1934 throw (uno::RuntimeException)
1936 return SvxShapeText::getTypes();
1939 uno::Sequence< sal_Int8 > SAL_CALL SvxCustomShape::getImplementationId()
1940 throw (uno::RuntimeException)
1942 static uno::Sequence< sal_Int8 > aId;
1943 if( aId.getLength() == 0 )
1945 aId.realloc( 16 );
1946 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1948 return aId;
1951 // ::com::sun::star::drawing::XShape
1953 //----------------------------------------------------------------------
1954 OUString SAL_CALL SvxCustomShape::getShapeType()
1955 throw( uno::RuntimeException )
1957 return SvxShape::getShapeType();
1960 //------------------------------------------------------------------1----
1961 awt::Point SAL_CALL SvxCustomShape::getPosition() throw(uno::RuntimeException)
1963 OGuard aGuard( Application::GetSolarMutex() );
1964 if ( mpModel && mpObj.is() )
1966 SdrAShapeObjGeoData aCustomShapeGeoData;
1967 ((SdrObjCustomShape*)mpObj.get())->SaveGeoData( aCustomShapeGeoData );
1969 sal_Bool bMirroredX = sal_False;
1970 sal_Bool bMirroredY = sal_False;
1972 if ( mpObj.is() )
1974 bMirroredX = ( ((SdrObjCustomShape*)mpObj.get())->IsMirroredX() );
1975 bMirroredY = ( ((SdrObjCustomShape*)mpObj.get())->IsMirroredY() );
1977 // get aRect, this is the unrotated snaprect
1978 Rectangle aRect(((SdrObjCustomShape*)mpObj.get())->GetLogicRect());
1979 Rectangle aRectangle( aRect );
1981 if ( bMirroredX || bMirroredY )
1982 { // we have to retrieve the unmirrored rect
1984 GeoStat aNewGeo( aCustomShapeGeoData.aGeo );
1985 if ( bMirroredX )
1987 Polygon aPol( Rect2Poly( aRect, aNewGeo ) );
1988 Rectangle aBoundRect( aPol.GetBoundRect() );
1990 Point aRef1( ( aBoundRect.Left() + aBoundRect.Right() ) >> 1, aBoundRect.Top() );
1991 Point aRef2( aRef1.X(), aRef1.Y() + 1000 );
1992 USHORT i;
1993 USHORT nPntAnz=aPol.GetSize();
1994 for (i=0; i<nPntAnz; i++)
1996 MirrorPoint(aPol[i],aRef1,aRef2);
1998 // Polygon wenden und etwas schieben
1999 Polygon aPol0(aPol);
2000 aPol[0]=aPol0[1];
2001 aPol[1]=aPol0[0];
2002 aPol[2]=aPol0[3];
2003 aPol[3]=aPol0[2];
2004 aPol[4]=aPol0[1];
2005 Poly2Rect(aPol,aRectangle,aNewGeo);
2007 if ( bMirroredY )
2009 Polygon aPol( Rect2Poly( aRectangle, aNewGeo ) );
2010 Rectangle aBoundRect( aPol.GetBoundRect() );
2012 Point aRef1( aBoundRect.Left(), ( aBoundRect.Top() + aBoundRect.Bottom() ) >> 1 );
2013 Point aRef2( aRef1.X() + 1000, aRef1.Y() );
2014 USHORT i;
2015 USHORT nPntAnz=aPol.GetSize();
2016 for (i=0; i<nPntAnz; i++)
2018 MirrorPoint(aPol[i],aRef1,aRef2);
2020 // Polygon wenden und etwas schieben
2021 Polygon aPol0(aPol);
2022 aPol[0]=aPol0[1];
2023 aPol[1]=aPol0[0];
2024 aPol[2]=aPol0[3];
2025 aPol[3]=aPol0[2];
2026 aPol[4]=aPol0[1];
2027 Poly2Rect( aPol, aRectangle, aNewGeo );
2030 Point aPt( aRectangle.TopLeft() );
2032 if( mpModel->IsWriter() )
2033 aPt -= mpObj->GetAnchorPos();
2035 ForceMetricTo100th_mm(aPt);
2036 return ::com::sun::star::awt::Point( aPt.X(), aPt.Y() );
2038 else
2039 return SvxShape::getPosition();
2042 //----------------------------------------------------------------------
2043 void SAL_CALL SvxCustomShape::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
2045 SvxShapeText::setPosition(Position);
2048 //----------------------------------------------------------------------
2050 awt::Size SAL_CALL SvxCustomShape::getSize() throw(uno::RuntimeException)
2052 return SvxShapeText::getSize();
2055 //----------------------------------------------------------------------
2056 void SAL_CALL SvxCustomShape::setSize( const awt::Size& rSize )
2057 throw(beans::PropertyVetoException, uno::RuntimeException)
2059 SvxShapeText::setSize( rSize );
2062 //----------------------------------------------------------------------
2064 //----------------------------------------------------------------------
2065 void SAL_CALL SvxCustomShape::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
2066 throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException)
2068 OGuard aGuard( Application::GetSolarMutex() );
2069 SdrObject* pObject = mpObj.get();
2071 sal_Bool bCustomShapeGeometry = pObject && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CustomShapeGeometry" ) );
2073 sal_Bool bMirroredX = sal_False;
2074 sal_Bool bMirroredY = sal_False;
2076 if ( bCustomShapeGeometry )
2078 bMirroredX = ( ((SdrObjCustomShape*)pObject)->IsMirroredX() );
2079 bMirroredY = ( ((SdrObjCustomShape*)pObject)->IsMirroredY() );
2082 SvxShape::setPropertyValue( aPropertyName, aValue );
2084 if ( bCustomShapeGeometry )
2086 ((SdrObjCustomShape*)pObject)->MergeDefaultAttributes(0);
2087 Rectangle aRect( pObject->GetSnapRect() );
2089 // #i38892#
2090 bool bNeedsMirrorX = ((SdrObjCustomShape*)pObject)->IsMirroredX() != bMirroredX;
2091 bool bNeedsMirrorY = ((SdrObjCustomShape*)pObject)->IsMirroredY() != bMirroredY;
2093 boost::scoped_ptr< SdrGluePointList > pListCopy;
2094 if( bNeedsMirrorX || bNeedsMirrorY )
2096 const SdrGluePointList* pList = pObject->GetGluePointList();
2097 if( pList )
2098 pListCopy.reset( new SdrGluePointList(*pList) );
2101 if ( bNeedsMirrorX )
2103 Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
2104 Point aBottom( aTop.X(), aTop.Y() + 1000 );
2105 pObject->NbcMirror( aTop, aBottom );
2106 // NbcMirroring is flipping the current mirror state,
2107 // so we have to set the correct state again
2108 ((SdrObjCustomShape*)pObject)->SetMirroredX( bMirroredX ? sal_False : sal_True );
2110 if ( bNeedsMirrorY )
2112 Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
2113 Point aRight( aLeft.X() + 1000, aLeft.Y() );
2114 pObject->NbcMirror( aLeft, aRight );
2115 // NbcMirroring is flipping the current mirror state,
2116 // so we have to set the correct state again
2117 ((SdrObjCustomShape*)pObject)->SetMirroredY( bMirroredY ? sal_False : sal_True );
2120 if( pListCopy )
2122 SdrGluePointList* pNewList = const_cast< SdrGluePointList* >( pObject->GetGluePointList() );
2123 if(pNewList)
2124 *pNewList = *pListCopy;
2129 bool SvxCustomShape::getPropertyValueImpl( const ::rtl::OUString& rName, const SfxItemPropertySimpleEntry* pProperty, ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
2131 switch( pProperty->nWID )
2133 case SDRATTR_ROTATEANGLE:
2135 double fAngle = static_cast<SdrObjCustomShape*>(mpObj.get())->GetObjectRotation();
2136 fAngle *= 100;
2137 rValue <<= (sal_Int32)fAngle;
2138 return true;
2140 default:
2141 return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
2144 //----------------------------------------------------------------------
2146 void SvxCustomShape::createCustomShapeDefaults( const rtl::OUString& rValueType ) throw (::com::sun::star::uno::RuntimeException)
2148 ((SdrObjCustomShape*)mpObj.get())->MergeDefaultAttributes( &rValueType );