xref: /aoo41x/main/svx/source/unodraw/unoshap2.cxx (revision ddde725d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #define _SVX_USE_UNOGLOBALS_
28 #include <com/sun/star/lang/DisposedException.hpp>
29 #include <com/sun/star/awt/FontSlant.hpp>
30 #include <com/sun/star/style/VerticalAlignment.hpp>
31 #include <com/sun/star/drawing/TextVerticalAdjust.hpp>
32 #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp>
33 #include <com/sun/star/awt/TextAlign.hpp>  //added by BerryJia for fixing Bug102407 2002-11-4
34 #include <com/sun/star/style/ParagraphAdjust.hpp>   //added by BerryJia for fixing Bug102407 2002-11-4
35 #include <com/sun/star/drawing/PointSequenceSequence.hpp>
36 #include <com/sun/star/drawing/PointSequence.hpp>
37 #include <com/sun/star/graphic/XGraphic.hpp>
38 #include <tools/urlobj.hxx>
39 #include <unotools/localfilehelper.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vos/mutex.hxx>
42 #include <svtools/fltcall.hxx>
43 #include <svtools/filter.hxx>
44 
45 #include <boost/scoped_ptr.hpp>
46 #include <svx/svdpool.hxx>
47 #include <rtl/uuid.h>
48 #include <rtl/memory.h>
49 #include <tools/urlobj.hxx>
50 
51 #include <editeng/unoprnms.hxx>
52 #include <svx/unoshape.hxx>
53 #include <svx/unopage.hxx>
54 #include <svx/svdobj.hxx>
55 #include <svx/svdpage.hxx>
56 #include <svx/svdmodel.hxx>
57 #include <svx/svdouno.hxx>
58 #include "shapeimpl.hxx"
59 #include "svx/unoshprp.hxx"
60 #include <svx/svdoashp.hxx>
61 #include "unopolyhelper.hxx"
62 
63 // #i29181#
64 #include "svx/svdviter.hxx"
65 #include <svx/svdview.hxx>
66 #include <basegfx/matrix/b2dhommatrix.hxx>
67 #include <basegfx/polygon/b2dpolygon.hxx>
68 #include <basegfx/point/b2dpoint.hxx>
69 #include <basegfx/polygon/b2dpolygontools.hxx>
70 
71 using ::rtl::OUString;
72 using namespace ::osl;
73 using namespace ::vos;
74 using namespace ::cppu;
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::container;
79 
80 #define INTERFACE_TYPE( xint ) \
81 	::getCppuType((const Reference< xint >*)0)
82 
83 #define QUERYINT( xint ) \
84 	if( rType == ::getCppuType((const Reference< xint >*)0) ) \
85 		aAny <<= Reference< xint >(this)
86 
87 class GDIMetaFile;
88 class SvStream;
89 sal_Bool ConvertGDIMetaFileToWMF( const GDIMetaFile & rMTF, SvStream & rTargetStream,
90 							  FilterConfigItem* pFilterConfigItem = NULL, sal_Bool bPlaceable = sal_True );
91 
92 /***********************************************************************
93 * class SvxShapeGroup                                                  *
94 ***********************************************************************/
95 
96 SvxShapeGroup::SvxShapeGroup( SdrObject* pObj, SvxDrawPage* pDrawPage  )  throw() :
97 	SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_GROUP), aSvxMapProvider.GetPropertySet(SVXMAP_GROUP, SdrObject::GetGlobalDrawObjectItemPool()) ),
98 	mxPage( pDrawPage )
99 {
100 }
101 
102 //----------------------------------------------------------------------
103 SvxShapeGroup::~SvxShapeGroup() throw()
104 {
105 }
106 
107 //----------------------------------------------------------------------
108 void SvxShapeGroup::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
109 {
110 	SvxShape::Create( pNewObj, pNewPage );
111 	mxPage = pNewPage;
112 }
113 
114 //----------------------------------------------------------------------
115 uno::Any SAL_CALL SvxShapeGroup::queryInterface( const uno::Type & rType )
116 	throw(uno::RuntimeException)
117 {
118 	return SvxShape::queryInterface( rType );
119 }
120 
121 uno::Any SAL_CALL SvxShapeGroup::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
122 {
123 	uno::Any aAny;
124 
125 	QUERYINT( drawing::XShapeGroup );
126 	else QUERYINT( drawing::XShapes );
127 	else QUERYINT( container::XIndexAccess );
128 	else QUERYINT( container::XElementAccess );
129 	else
130 		return SvxShape::queryAggregation( rType );
131 
132 	return aAny;
133 }
134 
135 void SAL_CALL SvxShapeGroup::acquire() throw ( )
136 {
137 	SvxShape::acquire();
138 }
139 
140 void SAL_CALL SvxShapeGroup::release() throw ( )
141 {
142 	SvxShape::release();
143 }
144 
145 uno::Sequence< uno::Type > SAL_CALL SvxShapeGroup::getTypes()
146 	throw (uno::RuntimeException)
147 {
148 	return SvxShape::getTypes();
149 }
150 
151 uno::Sequence< sal_Int8 > SAL_CALL SvxShapeGroup::getImplementationId()
152 	throw (uno::RuntimeException)
153 {
154 	static uno::Sequence< sal_Int8 > aId;
155 	if( aId.getLength() == 0 )
156 	{
157 		aId.realloc( 16 );
158 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
159 	}
160 	return aId;
161 }
162 
163 // ::com::sun::star::drawing::XShape
164 
165 //----------------------------------------------------------------------
166 OUString SAL_CALL SvxShapeGroup::getShapeType()
167 	throw( uno::RuntimeException )
168 {
169 	return SvxShape::getShapeType();
170 }
171 
172 //------------------------------------------------------------------1----
173 awt::Point SAL_CALL SvxShapeGroup::getPosition() throw(uno::RuntimeException)
174 {
175 	return SvxShape::getPosition();
176 }
177 
178 //----------------------------------------------------------------------
179 void SAL_CALL SvxShapeGroup::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
180 {
181 	SvxShape::setPosition(Position);
182 }
183 
184 //----------------------------------------------------------------------
185 
186 awt::Size SAL_CALL SvxShapeGroup::getSize() throw(uno::RuntimeException)
187 {
188 	return SvxShape::getSize();
189 }
190 
191 //----------------------------------------------------------------------
192 void SAL_CALL SvxShapeGroup::setSize( const awt::Size& rSize )
193 	throw(beans::PropertyVetoException, uno::RuntimeException)
194 {
195 	SvxShape::setSize( rSize );
196 }
197 
198 // drawing::XShapeGroup
199 
200 //----------------------------------------------------------------------
201 void SAL_CALL SvxShapeGroup::enterGroup(  ) throw(uno::RuntimeException)
202 {
203 	// Todo
204 //	pDrView->EnterMarkedGroup();
205 }
206 
207 //----------------------------------------------------------------------
208 void SAL_CALL SvxShapeGroup::leaveGroup(  ) throw(uno::RuntimeException)
209 {
210 	// Todo
211 //	pDrView->LeaveOneGroup();
212 }
213 
214 //----------------------------------------------------------------------
215 
216 // XShapes
217 void SAL_CALL SvxShapeGroup::add( const uno::Reference< drawing::XShape >& xShape )
218 	throw( uno::RuntimeException )
219 {
220 	OGuard aGuard( Application::GetSolarMutex() );
221 
222 	SvxShape* pShape = SvxShape::getImplementation( xShape );
223 
224 	if( mpObj.is()&& mxPage.is() && pShape )
225 	{
226 		SdrObject* pSdrShape = pShape->GetSdrObject();
227 		if( pSdrShape == NULL )
228 			pSdrShape = mxPage->_CreateSdrObject( xShape );
229 
230 		if( pSdrShape->IsInserted() )
231 			pSdrShape->GetObjList()->RemoveObject( pSdrShape->GetOrdNum() );
232 
233 		mpObj->GetSubList()->InsertObject( pSdrShape );
234 		pSdrShape->SetModel(mpObj->GetModel());
235 
236 		// #85922# It makes no sense to set the layer asked
237 		// from the group object since these is an iteration
238 		// over the contained objects. In consequence, this
239 		// statement erases all layer information from the draw
240 		// objects. Layers need to be set at draw objects directly
241 		// and have nothing to do with grouping at all.
242 		// pSdrShape->SetLayer(pObject->GetLayer());
243 
244         // Establish connection between new SdrObject and its wrapper before
245         // inserting the new shape into the group.  There a new wrapper
246         // would be created when this connection would not already exist.
247 		if(pShape)
248 			pShape->Create( pSdrShape, mxPage.get() );
249 
250 		if( mpModel )
251 			mpModel->SetChanged();
252 	}
253 	else
254 	{
255 		DBG_ERROR("could not add XShape to group shape!");
256 	}
257 }
258 
259 //----------------------------------------------------------------------
260 void SAL_CALL SvxShapeGroup::remove( const uno::Reference< drawing::XShape >& xShape )
261 	throw( uno::RuntimeException )
262 {
263 	OGuard aGuard( Application::GetSolarMutex() );
264 
265 	SdrObject* pSdrShape = NULL;
266 	SvxShape* pShape = SvxShape::getImplementation( xShape );
267 
268 	if( pShape )
269 		pSdrShape = pShape->GetSdrObject();
270 
271 	if( !mpObj.is() || pSdrShape == NULL || pSdrShape->GetObjList()->GetOwnerObj() != mpObj.get() )
272 		throw uno::RuntimeException();
273 
274 	SdrObjList& rList = *pSdrShape->GetObjList();
275 
276 	const sal_uInt32 nObjCount = rList.GetObjCount();
277 	sal_uInt32 nObjNum = 0;
278 	while( nObjNum < nObjCount )
279 	{
280 		if(rList.GetObj( nObjNum ) == pSdrShape )
281 			break;
282 		nObjNum++;
283 	}
284 
285 	if( nObjNum < nObjCount )
286 	{
287 		// #i29181#
288 		// If the SdrObject which is about to be deleted is in any selection,
289 		// deselect it first.
290         SdrViewIter aIter( pSdrShape );
291 
292 		for ( SdrView* pView = aIter.FirstView(); pView; pView = aIter.NextView() )
293 		{
294 			if(CONTAINER_ENTRY_NOTFOUND != pView->TryToFindMarkedObject(pSdrShape))
295 			{
296 				pView->MarkObj(pSdrShape, pView->GetSdrPageView(), sal_True, sal_False);
297 			}
298 		}
299 
300 		SdrObject* pObject = rList.NbcRemoveObject( nObjNum );
301         SdrObject::Free( pObject );
302 	}
303 	else
304 	{
305 		DBG_ASSERT( 0, "Fatality! SdrObject is not belonging to its SdrObjList! [CL]" );
306 	}
307 
308 	if( mpModel )
309 		mpModel->SetChanged();
310 }
311 
312 // XIndexAccess
313 
314 //----------------------------------------------------------------------
315 sal_Int32 SAL_CALL SvxShapeGroup::getCount() throw( uno::RuntimeException )
316 {
317 	OGuard aGuard( Application::GetSolarMutex() );
318 
319 	sal_Int32 nRetval = 0;
320 
321 	if(mpObj.is() && mpObj->GetSubList())
322 		nRetval = mpObj->GetSubList()->GetObjCount();
323 	else
324 		throw uno::RuntimeException();
325 
326 	return nRetval;
327 }
328 
329 //----------------------------------------------------------------------
330 uno::Any SAL_CALL SvxShapeGroup::getByIndex( sal_Int32 Index )
331 	throw( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
332 {
333 	OGuard aGuard( Application::GetSolarMutex() );
334 
335 	if( !mpObj.is() || mpObj->GetSubList() == NULL )
336 		throw uno::RuntimeException();
337 
338 	if( mpObj->GetSubList()->GetObjCount() <= (sal_uInt32)Index )
339 		throw lang::IndexOutOfBoundsException();
340 
341 	SdrObject* pDestObj = mpObj->GetSubList()->GetObj( Index );
342 
343 	if(pDestObj == NULL)
344 		throw lang::IndexOutOfBoundsException();
345 
346 	Reference< drawing::XShape > xShape( pDestObj->getUnoShape(), uno::UNO_QUERY );
347 	return uno::makeAny( xShape );
348 }
349 
350 // ::com::sun::star::container::XElementAccess
351 
352 //----------------------------------------------------------------------
353 uno::Type SAL_CALL SvxShapeGroup::getElementType() throw( uno::RuntimeException )
354 {
355 	return ::getCppuType(( const Reference< drawing::XShape >*)0);
356 }
357 
358 //----------------------------------------------------------------------
359 sal_Bool SAL_CALL SvxShapeGroup::hasElements() throw( uno::RuntimeException )
360 {
361 	OGuard aGuard( Application::GetSolarMutex() );
362 
363 	return mpObj.is() && mpObj->GetSubList() && (mpObj->GetSubList()->GetObjCount() > 0);
364 }
365 
366 //----------------------------------------------------------------------
367 // ::com::sun::star::lang::XServiceInfo
368 
369 uno::Sequence< OUString > SAL_CALL SvxShapeGroup::getSupportedServiceNames()
370 	throw(uno::RuntimeException)
371 {
372 	return SvxShape::getSupportedServiceNames();
373 }
374 
375 /***********************************************************************
376 *                                                                      *
377 ***********************************************************************/
378 
379 SvxShapeConnector::SvxShapeConnector( SdrObject* pObj )  throw() :
380 	SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CONNECTOR), aSvxMapProvider.GetPropertySet(SVXMAP_CONNECTOR, SdrObject::GetGlobalDrawObjectItemPool()) )
381 {
382 }
383 
384 //----------------------------------------------------------------------
385 SvxShapeConnector::~SvxShapeConnector() throw()
386 {
387 }
388 
389 //----------------------------------------------------------------------
390 
391 uno::Any SAL_CALL SvxShapeConnector::queryInterface( const uno::Type & rType )
392 	throw(uno::RuntimeException)
393 {
394 	return SvxShapeText::queryInterface( rType );
395 }
396 
397 uno::Any SAL_CALL SvxShapeConnector::queryAggregation( const uno::Type & rType )
398 	throw(uno::RuntimeException)
399 {
400 	uno::Any aAny;
401 
402 	QUERYINT( drawing::XConnectorShape );
403 	else
404 		return SvxShapeText::queryAggregation( rType );
405 
406 	return aAny;
407 }
408 
409 void SAL_CALL SvxShapeConnector::acquire() throw ( )
410 {
411 	SvxShapeText::acquire();
412 }
413 
414 void SAL_CALL SvxShapeConnector::release() throw ( )
415 {
416 	SvxShapeText::release();
417 }
418 // XTypeProvider
419 
420 uno::Sequence< uno::Type > SAL_CALL SvxShapeConnector::getTypes()
421 	throw (uno::RuntimeException)
422 {
423 	return SvxShape::getTypes();
424 }
425 
426 uno::Sequence< sal_Int8 > SAL_CALL SvxShapeConnector::getImplementationId()
427 	throw (uno::RuntimeException)
428 {
429 	static uno::Sequence< sal_Int8 > aId;
430 	if( aId.getLength() == 0 )
431 	{
432 		aId.realloc( 16 );
433 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
434 	}
435 	return aId;
436 }
437 
438 // ::com::sun::star::drawing::XShape
439 
440 //----------------------------------------------------------------------
441 OUString SAL_CALL SvxShapeConnector::getShapeType()
442 	throw( uno::RuntimeException )
443 {
444 	return SvxShapeText::getShapeType();
445 }
446 
447 //------------------------------------------------------------------1----
448 awt::Point SAL_CALL SvxShapeConnector::getPosition() throw(uno::RuntimeException)
449 {
450 	return SvxShapeText::getPosition();
451 }
452 
453 //----------------------------------------------------------------------
454 void SAL_CALL SvxShapeConnector::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
455 {
456 	SvxShapeText::setPosition(Position);
457 }
458 
459 //----------------------------------------------------------------------
460 
461 awt::Size SAL_CALL SvxShapeConnector::getSize() throw(uno::RuntimeException)
462 {
463 	return SvxShapeText::getSize();
464 }
465 
466 //----------------------------------------------------------------------
467 void SAL_CALL SvxShapeConnector::setSize( const awt::Size& rSize )
468 	throw(beans::PropertyVetoException, uno::RuntimeException)
469 {
470 	SvxShapeText::setSize( rSize );
471 }
472 
473 //----------------------------------------------------------------------
474 
475 // XConnectorShape
476 
477 void SAL_CALL SvxShapeConnector::connectStart( const uno::Reference< drawing::XConnectableShape >& xShape, drawing::ConnectionType ) throw( uno::RuntimeException )
478 {
479 	OGuard aGuard( Application::GetSolarMutex() );
480 
481 	Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
482 	SvxShape* pShape = SvxShape::getImplementation( xRef );
483 
484 	if( pShape )
485 		mpObj->ConnectToNode( sal_True, pShape->mpObj.get() );
486 
487 	if( mpModel )
488 		mpModel->SetChanged();
489 }
490 
491 //----------------------------------------------------------------------
492 void SAL_CALL SvxShapeConnector::connectEnd( const uno::Reference< drawing::XConnectableShape >& xShape, drawing::ConnectionType  )
493 	throw( uno::RuntimeException )
494 {
495 	OGuard aGuard( Application::GetSolarMutex() );
496 
497 	Reference< drawing::XShape > xRef( xShape, UNO_QUERY );
498 	SvxShape* pShape = SvxShape::getImplementation( xRef );
499 
500 	if( mpObj.is() && pShape )
501 		mpObj->ConnectToNode( sal_False, pShape->mpObj.get() );
502 
503 	if( mpModel )
504 		mpModel->SetChanged();
505 }
506 
507 //----------------------------------------------------------------------
508 void SAL_CALL SvxShapeConnector::disconnectBegin( const uno::Reference< drawing::XConnectableShape >&  )
509 	throw( uno::RuntimeException )
510 {
511 	OGuard aGuard( Application::GetSolarMutex() );
512 
513 	if(mpObj.is())
514 		mpObj->DisconnectFromNode( sal_True );
515 
516 	if( mpModel )
517 		mpModel->SetChanged();
518 }
519 
520 //----------------------------------------------------------------------
521 void SAL_CALL SvxShapeConnector::disconnectEnd( const uno::Reference< drawing::XConnectableShape >& )
522 	throw( uno::RuntimeException )
523 {
524 	OGuard aGuard( Application::GetSolarMutex() );
525 
526 	if(mpObj.is())
527 		mpObj->DisconnectFromNode( sal_False );
528 
529 	if( mpModel )
530 		mpModel->SetChanged();
531 }
532 
533 //----------------------------------------------------------------------
534 // ::com::sun::star::lang::XServiceInfo
535 //----------------------------------------------------------------------
536 uno::Sequence< OUString > SAL_CALL SvxShapeConnector::getSupportedServiceNames() throw( uno::RuntimeException )
537 {
538 	return SvxShapeText::getSupportedServiceNames();
539 }
540 
541 /***********************************************************************
542 * class SvxShapeControl                                                *
543 ***********************************************************************/
544 DBG_NAME(SvxShapeControl)
545 
546 SvxShapeControl::SvxShapeControl( SdrObject* pObj )  throw() :
547 	SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CONTROL), aSvxMapProvider.GetPropertySet(SVXMAP_CONTROL, SdrObject::GetGlobalDrawObjectItemPool()) )
548 {
549     DBG_CTOR(SvxShapeControl,NULL);
550 	setShapeKind( OBJ_UNO );
551 }
552 
553 //----------------------------------------------------------------------
554 SvxShapeControl::~SvxShapeControl() throw()
555 {
556     DBG_DTOR(SvxShapeControl,NULL);
557 }
558 
559 //----------------------------------------------------------------------
560 uno::Any SAL_CALL SvxShapeControl::queryInterface( const uno::Type & rType )
561 	throw(uno::RuntimeException)
562 {
563 	return SvxShapeText::queryInterface( rType );
564 }
565 
566 uno::Any SAL_CALL SvxShapeControl::queryAggregation( const uno::Type & rType ) throw(uno::RuntimeException)
567 {
568 	uno::Any aAny;
569 
570 	QUERYINT( drawing::XControlShape );
571 	else
572 		return SvxShapeText::queryAggregation( rType );
573 
574 	return aAny;
575 }
576 
577 void SAL_CALL SvxShapeControl::acquire() throw ( )
578 {
579 	SvxShapeText::acquire();
580 }
581 
582 void SAL_CALL SvxShapeControl::release() throw ( )
583 {
584 	SvxShapeText::release();
585 }
586 // XTypeProvider
587 
588 uno::Sequence< uno::Type > SAL_CALL SvxShapeControl::getTypes()
589 	throw (uno::RuntimeException)
590 {
591 	return SvxShape::getTypes();
592 }
593 
594 uno::Sequence< sal_Int8 > SAL_CALL SvxShapeControl::getImplementationId()
595 	throw (uno::RuntimeException)
596 {
597 	static uno::Sequence< sal_Int8 > aId;
598 	if( aId.getLength() == 0 )
599 	{
600 		aId.realloc( 16 );
601 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
602 	}
603 	return aId;
604 }
605 
606 // ::com::sun::star::drawing::XShape
607 
608 //----------------------------------------------------------------------
609 OUString SAL_CALL SvxShapeControl::getShapeType()
610 	throw( uno::RuntimeException )
611 {
612 	return SvxShapeText::getShapeType();
613 }
614 
615 //------------------------------------------------------------------1----
616 awt::Point SAL_CALL SvxShapeControl::getPosition() throw(uno::RuntimeException)
617 {
618 	return SvxShapeText::getPosition();
619 }
620 
621 //----------------------------------------------------------------------
622 void SAL_CALL SvxShapeControl::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
623 {
624 	SvxShapeText::setPosition(Position);
625 }
626 
627 //----------------------------------------------------------------------
628 
629 awt::Size SAL_CALL SvxShapeControl::getSize() throw(uno::RuntimeException)
630 {
631 	return SvxShapeText::getSize();
632 }
633 
634 //----------------------------------------------------------------------
635 void SAL_CALL SvxShapeControl::setSize( const awt::Size& rSize )
636 	throw(beans::PropertyVetoException, uno::RuntimeException)
637 {
638 	SvxShapeText::setSize( rSize );
639 }
640 
641 //----------------------------------------------------------------------
642 // XControlShape
643 
644 Reference< awt::XControlModel > SAL_CALL SvxShapeControl::getControl()
645 	throw( uno::RuntimeException )
646 {
647 	OGuard aGuard( Application::GetSolarMutex() );
648 
649 	Reference< awt::XControlModel > xModel;
650 
651 	SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(mpObj.get());
652 	if( pUnoObj )
653 		xModel = pUnoObj->GetUnoControlModel();
654 
655 	return xModel;
656 }
657 
658 //----------------------------------------------------------------------
659 void SAL_CALL SvxShapeControl::setControl( const Reference< awt::XControlModel >& xControl )
660 	throw( uno::RuntimeException )
661 {
662 	OGuard aGuard( Application::GetSolarMutex() );
663 
664 	SdrUnoObj* pUnoObj = dynamic_cast< SdrUnoObj * >(mpObj.get());
665 	if( pUnoObj )
666 		pUnoObj->SetUnoControlModel( xControl );
667 
668 	if( mpModel )
669 		mpModel->SetChanged();
670 }
671 
672 // XServiceInfo
673 uno::Sequence< OUString > SAL_CALL SvxShapeControl::getSupportedServiceNames() throw( uno::RuntimeException )
674 {
675 	return SvxShapeText::getSupportedServiceNames();
676 }
677 
678 static struct
679 {
680 	const sal_Char* mpAPIName;
681 	sal_uInt16 mnAPINameLen;
682 
683 	const sal_Char* mpFormName;
684 	sal_uInt16 mnFormNameLen;
685 }
686 SvxShapeControlPropertyMapping[] =
687 {
688 	// Warning: The first entry must be FontSlant because the any needs to be converted
689 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_POSTURE), MAP_CHAR_LEN("FontSlant")  }, //  const sal_Int16 => ::com::sun::star::awt::FontSlant
690 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTNAME), MAP_CHAR_LEN("FontName") },
691 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTSTYLENAME), MAP_CHAR_LEN("FontStyleName") },
692 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTFAMILY), MAP_CHAR_LEN("FontFamily") },
693 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTCHARSET), MAP_CHAR_LEN("FontCharset") },
694 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_HEIGHT), MAP_CHAR_LEN("FontHeight") },
695 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_FONTPITCH), MAP_CHAR_LEN("FontPitch" ) },
696 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_WEIGHT), MAP_CHAR_LEN("FontWeight" ) },
697 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_UNDERLINE), MAP_CHAR_LEN("FontUnderline") },
698 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_STRIKEOUT), MAP_CHAR_LEN("FontStrikeout") },
699 	{ MAP_CHAR_LEN("CharKerning"), MAP_CHAR_LEN("FontKerning") },
700 	{ MAP_CHAR_LEN("CharWordMode"), MAP_CHAR_LEN("FontWordLineMode" ) },
701 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_CHAR_COLOR),	MAP_CHAR_LEN("TextColor") },
702 	{ MAP_CHAR_LEN("CharRelief"),	MAP_CHAR_LEN("FontRelief") },
703 	{ MAP_CHAR_LEN("CharUnderlineColor"),	MAP_CHAR_LEN("TextLineColor") },
704 	{ MAP_CHAR_LEN(UNO_NAME_EDIT_PARA_ADJUST), MAP_CHAR_LEN("Align") },
705     { MAP_CHAR_LEN("TextVerticalAdjust"), MAP_CHAR_LEN("VerticalAlign") },
706 	{ MAP_CHAR_LEN("ControlBackground"), MAP_CHAR_LEN("BackgroundColor") },
707 	{ MAP_CHAR_LEN("ControlSymbolColor"), MAP_CHAR_LEN("SymbolColor") },
708 	{ MAP_CHAR_LEN("ControlBorder"), MAP_CHAR_LEN("Border") },
709 	{ MAP_CHAR_LEN("ControlBorderColor"), MAP_CHAR_LEN("BorderColor") },
710 	{ MAP_CHAR_LEN("ControlTextEmphasis"),	MAP_CHAR_LEN("FontEmphasisMark") },
711     { MAP_CHAR_LEN("ImageScaleMode"),  MAP_CHAR_LEN("ScaleMode") },
712 	{ MAP_CHAR_LEN("ControlWritingMode"), MAP_CHAR_LEN("WritingMode") },
713 	{ NULL,0, NULL, 0 }
714 };
715 
716 namespace
717 {
718     static bool lcl_convertPropertyName( const OUString& rApiName, OUString& rInternalName )
719     {
720 	    sal_uInt16 i = 0;
721 	    while( SvxShapeControlPropertyMapping[i].mpAPIName )
722 	    {
723 		    if( rApiName.reverseCompareToAsciiL( SvxShapeControlPropertyMapping[i].mpAPIName, SvxShapeControlPropertyMapping[i].mnAPINameLen ) == 0 )
724 		    {
725 			    rInternalName = OUString( SvxShapeControlPropertyMapping[i].mpFormName, SvxShapeControlPropertyMapping[i].mnFormNameLen, RTL_TEXTENCODING_ASCII_US );
726 		    }
727 		    ++i;
728 	    }
729         return rInternalName.getLength() > 0;
730     }
731 
732     struct EnumConversionMap
733     {
734         sal_Int16   nAPIValue;
735         sal_Int16   nFormValue;
736     };
737 
738     EnumConversionMap aMapAdjustToAlign[] =
739     {
740 	    // note that order matters:
741 	    // lcl_convertTextAlignmentToParaAdjustment and lcl_convertParaAdjustmentToTextAlignment search this map from the _beginning_
742 	    // and use the first matching entry
743 	    {style::ParagraphAdjust_LEFT,			(sal_Int16)awt::TextAlign::LEFT},
744 	    {style::ParagraphAdjust_CENTER,			(sal_Int16)awt::TextAlign::CENTER},
745 	    {style::ParagraphAdjust_RIGHT,			(sal_Int16)awt::TextAlign::RIGHT},
746 	    {style::ParagraphAdjust_BLOCK,			(sal_Int16)awt::TextAlign::RIGHT},
747 	    {style::ParagraphAdjust_STRETCH,		(sal_Int16)awt::TextAlign::LEFT},
748 	    {-1,-1}
749     };
750 
751     static void lcl_mapFormToAPIValue( Any& _rValue, const EnumConversionMap* _pMap )
752     {
753 	    sal_Int16 nValue = sal_Int16();
754 	    OSL_VERIFY( _rValue >>= nValue );
755 
756         const EnumConversionMap* pEntry = _pMap;
757         while ( pEntry && ( pEntry->nFormValue != -1 ) )
758 	    {
759 		    if ( nValue == pEntry->nFormValue )
760 		    {
761 			    _rValue <<= pEntry->nAPIValue;
762 			    return;
763 		    }
764             ++pEntry;
765 	    }
766     }
767 
768     static void lcl_mapAPIToFormValue( Any& _rValue, const EnumConversionMap* _pMap )
769     {
770 	    sal_Int32 nValue = 0;
771 	    OSL_VERIFY( _rValue >>= nValue );
772 
773         const EnumConversionMap* pEntry = _pMap;
774         while ( pEntry && ( pEntry->nAPIValue != -1 ) )
775 	    {
776 		    if ( nValue == pEntry->nAPIValue )
777 		    {
778 			    _rValue <<= pEntry->nFormValue;
779 			    return;
780 		    }
781             ++pEntry;
782 	    }
783     }
784 
785     static void lcl_convertTextAlignmentToParaAdjustment( Any& rValue )
786     {
787         lcl_mapFormToAPIValue( rValue, aMapAdjustToAlign );
788     }
789 
790     static void lcl_convertParaAdjustmentToTextAlignment( Any& rValue )
791     {
792         lcl_mapAPIToFormValue( rValue, aMapAdjustToAlign );
793     }
794 
795     void convertVerticalAdjustToVerticalAlign( Any& _rValue ) SAL_THROW( ( lang::IllegalArgumentException ) )
796     {
797         if ( !_rValue.hasValue() )
798             return;
799 
800         drawing::TextVerticalAdjust eAdjust = drawing::TextVerticalAdjust_TOP;
801         style::VerticalAlignment    eAlign  = style::VerticalAlignment_TOP;
802         if ( !( _rValue >>= eAdjust ) )
803             throw lang::IllegalArgumentException();
804         switch ( eAdjust )
805         {
806         case drawing::TextVerticalAdjust_TOP:    eAlign = style::VerticalAlignment_TOP; break;
807         case drawing::TextVerticalAdjust_BOTTOM: eAlign = style::VerticalAlignment_BOTTOM; break;
808         default:                                 eAlign = style::VerticalAlignment_MIDDLE; break;
809         }
810         _rValue <<= eAlign;
811     }
812 
813     void convertVerticalAlignToVerticalAdjust( Any& _rValue )
814     {
815         if ( !_rValue.hasValue() )
816             return;
817         style::VerticalAlignment    eAlign  = style::VerticalAlignment_TOP;
818         drawing::TextVerticalAdjust eAdjust = drawing::TextVerticalAdjust_TOP;
819         OSL_VERIFY( _rValue >>= eAlign );
820         switch ( eAlign )
821         {
822         case style::VerticalAlignment_TOP:    eAdjust = drawing::TextVerticalAdjust_TOP; break;
823         case style::VerticalAlignment_BOTTOM: eAdjust = drawing::TextVerticalAdjust_BOTTOM; break;
824         default:                              eAdjust = drawing::TextVerticalAdjust_CENTER; break;
825         }
826         _rValue <<= eAdjust;
827     }
828 }
829 
830 void SAL_CALL SvxShapeControl::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
831 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException)
832 {
833 	OUString aFormsName;
834 	if ( lcl_convertPropertyName( aPropertyName, aFormsName ) )
835 	{
836 		uno::Reference< beans::XPropertySet > xControl( getControl(), uno::UNO_QUERY );
837 		if( xControl.is() )
838 		{
839 			uno::Reference< beans::XPropertySetInfo > xInfo( xControl->getPropertySetInfo() );
840 			if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
841 			{
842                 uno::Any aConvertedValue( aValue );
843                 if ( aFormsName.equalsAscii( "FontSlant" ) )
844                 {
845                     awt::FontSlant nSlant;
846                     if( !(aValue >>= nSlant ) )
847                         throw lang::IllegalArgumentException();
848                     aConvertedValue <<= (sal_Int16)nSlant;
849                 }
850                 else if ( aFormsName.equalsAscii( "Align" ) )
851                 {
852                     lcl_convertParaAdjustmentToTextAlignment( aConvertedValue );
853                 }
854                 else if ( aFormsName.equalsAscii( "VerticalAlign" ) )
855                 {
856                     convertVerticalAdjustToVerticalAlign( aConvertedValue );
857                 }
858 
859                 xControl->setPropertyValue( aFormsName, aConvertedValue );
860 			}
861 		}
862 	}
863 	else
864 	{
865 		SvxShape::setPropertyValue( aPropertyName, aValue );
866 	}
867 }
868 
869 uno::Any SAL_CALL SvxShapeControl::getPropertyValue( const OUString& aPropertyName )
870 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
871 {
872 	OUString aFormsName;
873 	if ( lcl_convertPropertyName( aPropertyName, aFormsName ) )
874 	{
875 		uno::Reference< beans::XPropertySet > xControl( getControl(), uno::UNO_QUERY );
876 
877         uno::Any aValue;
878 		if( xControl.is() )
879 		{
880 			uno::Reference< beans::XPropertySetInfo > xInfo( xControl->getPropertySetInfo() );
881 			if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
882 			{
883                 aValue = xControl->getPropertyValue( aFormsName );
884                 if ( aFormsName.equalsAscii( "FontSlant" ) )
885 				{
886                     awt::FontSlant eSlant = awt::FontSlant_NONE;
887 					sal_Int16 nSlant = sal_Int16();
888                     if ( aValue >>= nSlant )
889                     {
890                         eSlant = (awt::FontSlant)nSlant;
891                     }
892                     else
893                     {
894                         OSL_VERIFY( aValue >>= eSlant );
895                     }
896                     aValue <<= eSlant;
897 				}
898 				else if ( aFormsName.equalsAscii( "Align" ) )
899 				{
900                     lcl_convertTextAlignmentToParaAdjustment( aValue );
901 				}
902                 else if ( aFormsName.equalsAscii( "VerticalAlign" ) )
903                 {
904                     convertVerticalAlignToVerticalAdjust( aValue );
905                 }
906 			}
907 		}
908 
909 		return aValue;
910 	}
911 	else
912 	{
913 		return SvxShape::getPropertyValue( aPropertyName );
914 	}
915 
916 }
917 
918 // XPropertyState
919 beans::PropertyState SAL_CALL SvxShapeControl::getPropertyState( const ::rtl::OUString& PropertyName ) throw( beans::UnknownPropertyException, uno::RuntimeException )
920 {
921 	OUString aFormsName;
922 	if ( lcl_convertPropertyName( PropertyName, aFormsName ) )
923 	{
924 		uno::Reference< beans::XPropertyState > xControl( getControl(), uno::UNO_QUERY );
925 		uno::Reference< beans::XPropertySet > xPropSet( getControl(), uno::UNO_QUERY );
926 
927 		if( xControl.is() && xPropSet.is() )
928 		{
929 			uno::Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
930 			if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
931 			{
932 				return xControl->getPropertyState( aFormsName );
933 			}
934 		}
935 
936 		return beans::PropertyState_DEFAULT_VALUE;
937 	}
938 	else
939 	{
940 		return SvxShape::getPropertyState( PropertyName );
941 	}
942 }
943 
944 void SAL_CALL SvxShapeControl::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw( beans::UnknownPropertyException, uno::RuntimeException )
945 {
946 	OUString aFormsName;
947 	if ( lcl_convertPropertyName( PropertyName, aFormsName ) )
948 	{
949 		uno::Reference< beans::XPropertyState > xControl( getControl(), uno::UNO_QUERY );
950 		uno::Reference< beans::XPropertySet > xPropSet( getControl(), uno::UNO_QUERY );
951 
952 		if( xControl.is() && xPropSet.is() )
953 		{
954 			uno::Reference< beans::XPropertySetInfo > xInfo( xPropSet->getPropertySetInfo() );
955 			if( xInfo.is() && xInfo->hasPropertyByName( aFormsName ) )
956 			{
957 				xControl->setPropertyToDefault( aFormsName );
958 			}
959 		}
960 	}
961 	else
962 	{
963 		SvxShape::setPropertyToDefault( PropertyName );
964 	}
965 }
966 
967 uno::Any SAL_CALL SvxShapeControl::getPropertyDefault( const ::rtl::OUString& aPropertyName )
968 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
969 {
970 	OUString aFormsName;
971 	if ( lcl_convertPropertyName( aPropertyName, aFormsName ) )
972 	{
973 		uno::Reference< beans::XPropertyState > xControl( getControl(), uno::UNO_QUERY );
974 
975 		if( xControl.is() )
976 		{
977             Any aDefault( xControl->getPropertyDefault( aFormsName ) );
978             if ( aFormsName.equalsAscii( "FontSlant" ) )
979 			{
980 				sal_Int16 nSlant( 0 );
981 				aDefault >>= nSlant;
982                 aDefault <<= (awt::FontSlant)nSlant;
983 			}
984             else if ( aFormsName.equalsAscii( "Align" ) )
985             {
986                 lcl_convertTextAlignmentToParaAdjustment( aDefault );
987             }
988             else if ( aFormsName.equalsAscii( "VerticalAlign" ) )
989             {
990                 convertVerticalAlignToVerticalAdjust( aDefault );
991             }
992             return aDefault;
993 		}
994 
995 		throw beans::UnknownPropertyException();
996 	}
997 	else
998 	{
999 		return SvxShape::getPropertyDefault( aPropertyName );
1000 	}
1001 }
1002 
1003 
1004 /***********************************************************************
1005 * class SvxShapeDimensioning                                           *
1006 ***********************************************************************/
1007 
1008 //----------------------------------------------------------------------
1009 SvxShapeDimensioning::SvxShapeDimensioning( SdrObject* pObj ) throw()
1010 :	SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_DIMENSIONING), aSvxMapProvider.GetPropertySet(SVXMAP_DIMENSIONING, SdrObject::GetGlobalDrawObjectItemPool()) )
1011 {
1012 }
1013 
1014 //----------------------------------------------------------------------
1015 SvxShapeDimensioning::~SvxShapeDimensioning() throw()
1016 {
1017 }
1018 
1019 // ::com::sun::star::lang::XServiceInfo
1020 uno::Sequence< OUString > SAL_CALL SvxShapeDimensioning::getSupportedServiceNames() throw( uno::RuntimeException )
1021 {
1022 	return SvxShapeText::getSupportedServiceNames();
1023 }
1024 
1025 /***********************************************************************
1026 *                                                                      *
1027 ***********************************************************************/
1028 
1029 //----------------------------------------------------------------------
1030 SvxShapeCircle::SvxShapeCircle( SdrObject* pObj ) throw()
1031 :	SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CIRCLE), aSvxMapProvider.GetPropertySet(SVXMAP_CIRCLE, SdrObject::GetGlobalDrawObjectItemPool()) )
1032 {
1033 }
1034 
1035 //----------------------------------------------------------------------
1036 SvxShapeCircle::~SvxShapeCircle() throw()
1037 {
1038 }
1039 
1040 // ::com::sun::star::lang::XServiceInfo
1041 // XServiceInfo
1042 uno::Sequence< OUString > SAL_CALL SvxShapeCircle::getSupportedServiceNames() throw( uno::RuntimeException )
1043 {
1044 	return SvxShapeText::getSupportedServiceNames();
1045 }
1046 
1047 /***********************************************************************
1048 *                                                                      *
1049 ***********************************************************************/
1050 
1051 #include <svx/svdopath.hxx>
1052 
1053 //----------------------------------------------------------------------
1054 SvxShapePolyPolygon::SvxShapePolyPolygon( SdrObject* pObj , drawing::PolygonKind eNew )
1055  throw( com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException)
1056 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_POLYPOLYGON), aSvxMapProvider.GetPropertySet(SVXMAP_POLYPOLYGON, SdrObject::GetGlobalDrawObjectItemPool()) )
1057 , mePolygonKind( eNew )
1058 {
1059 }
1060 
1061 //----------------------------------------------------------------------
1062 SvxShapePolyPolygon::~SvxShapePolyPolygon() throw()
1063 {
1064 }
1065 
1066 basegfx::B2DPolyPolygon SAL_CALL ImplSvxPointSequenceSequenceToB2DPolyPolygon( const drawing::PointSequenceSequence* pOuterSequence) throw()
1067 {
1068 	basegfx::B2DPolyPolygon aRetval;
1069 
1070 	// Zeiger auf innere sequences holen
1071 	const drawing::PointSequence* pInnerSequence = pOuterSequence->getConstArray();
1072 	const drawing::PointSequence* pInnerSeqEnd   = pInnerSequence + pOuterSequence->getLength();
1073 
1074 	for(;pInnerSequence != pInnerSeqEnd; ++pInnerSequence)
1075 	{
1076 		// Neues Polygon vorbereiten
1077 		basegfx::B2DPolygon aNewPolygon;
1078 
1079 		// Zeiger auf Arrays holen
1080 		const awt::Point* pArray	= pInnerSequence->getConstArray();
1081 		const awt::Point* pArrayEnd = pArray + pInnerSequence->getLength();
1082 
1083 		for(;pArray != pArrayEnd;++pArray)
1084 		{
1085 			aNewPolygon.append(basegfx::B2DPoint(pArray->X, pArray->Y));
1086 		}
1087 
1088 		// check for closed state flag
1089 		basegfx::tools::checkClosed(aNewPolygon);
1090 
1091 		// Neues Teilpolygon einfuegen
1092 		aRetval.append(aNewPolygon);
1093 	}
1094 
1095 	return aRetval;
1096 }
1097 
1098 //----------------------------------------------------------------------
1099 
1100 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)
1101 {
1102 	switch( pProperty->nWID )
1103 	{
1104 	case OWN_ATTR_VALUE_POLYPOLYGON:
1105 	{
1106 		if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PointSequenceSequence*)0) ) )
1107 		{
1108 			basegfx::B2DPolyPolygon aNewPolyPolygon(ImplSvxPointSequenceSequenceToB2DPolyPolygon( (drawing::PointSequenceSequence*)rValue.getValue()));
1109 			SetPolygon(aNewPolyPolygon);
1110 			return true;
1111 		}
1112 		break;
1113 	}
1114 	case OWN_ATTR_BASE_GEOMETRY:
1115 	{
1116 		if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PointSequenceSequence*)0)))
1117 		{
1118 			if( mpObj.is() )
1119 			{
1120 				basegfx::B2DPolyPolygon aNewPolyPolygon;
1121 				basegfx::B2DHomMatrix aNewHomogenMatrix;
1122 
1123 				mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1124 				aNewPolyPolygon = ImplSvxPointSequenceSequenceToB2DPolyPolygon((drawing::PointSequenceSequence*)rValue.getValue());
1125 				mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1126 			}
1127 			return true;
1128 		}
1129 		break;
1130 	}
1131 	case OWN_ATTR_VALUE_POLYGON:
1132 	{
1133 		if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PointSequenceSequence*)0) ))
1134 		{
1135 			drawing::PointSequence* pSequence = (drawing::PointSequence*)rValue.getValue();
1136 
1137 			// Neues Polygon vorbereiten
1138 			basegfx::B2DPolygon aNewPolygon;
1139 
1140 			// Zeiger auf Arrays holen
1141 			// Zeiger auf Arrays holen
1142 			const awt::Point* pArray	= pSequence->getConstArray();
1143 			const awt::Point* pArrayEnd = pArray + pSequence->getLength();
1144 
1145 			for(;pArray != pArrayEnd;++pArray)
1146 			{
1147 				aNewPolygon.append(basegfx::B2DPoint(pArray->X, pArray->Y));
1148 			}
1149 
1150 			// check for closed state flag
1151 			basegfx::tools::checkClosed(aNewPolygon);
1152 
1153 			// Polygon setzen
1154 			SetPolygon(basegfx::B2DPolyPolygon(aNewPolygon));
1155 			return true;
1156 		}
1157 		break;
1158 	}
1159 	default:
1160         return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
1161 	}
1162 
1163 	throw lang::IllegalArgumentException();
1164 }
1165 
1166 void SAL_CALL B2DPolyPolygonToSvxPointSequenceSequence( const basegfx::B2DPolyPolygon& rPolyPoly, drawing::PointSequenceSequence& rRetval )
1167 {
1168 	if( (sal_uInt32)rRetval.getLength() != rPolyPoly.count() )
1169 		rRetval.realloc( rPolyPoly.count() );
1170 
1171 	// Zeiger auf aeussere Arrays holen
1172 	drawing::PointSequence* pOuterSequence = rRetval.getArray();
1173 
1174 	for(sal_uInt32 a(0L); a < rPolyPoly.count(); a++)
1175 	{
1176 		// Einzelpolygon holen
1177 		const basegfx::B2DPolygon aPoly(rPolyPoly.getB2DPolygon(a));
1178 
1179 		// #i75974# take closed stae into account, the API polygon still uses the old closed definition
1180 		// with last/first point are identical (cannot hold information about open polygons with identical
1181 		// first and last point, though)
1182 		const sal_uInt32 nPointCount(aPoly.count());
1183 		const bool bIsClosed(aPoly.isClosed());
1184 
1185 		// Platz in Arrays schaffen
1186 		pOuterSequence->realloc(bIsClosed ? nPointCount + 1 : nPointCount);
1187 
1188 		// Pointer auf arrays holen
1189 		awt::Point* pInnerSequence = pOuterSequence->getArray();
1190 
1191 		for(sal_uInt32 b(0L); b < nPointCount; b++)
1192 		{
1193 			const basegfx::B2DPoint aPoint(aPoly.getB2DPoint(b));
1194 			*pInnerSequence = awt::Point( basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY()) );
1195 			pInnerSequence++;
1196 		}
1197 
1198 		// #i75974# copy first point
1199 		if(bIsClosed)
1200 		{
1201 			*pInnerSequence = *pOuterSequence->getArray();
1202 		}
1203 
1204 		pOuterSequence++;
1205 	}
1206 }
1207 
1208 //----------------------------------------------------------------------
1209 
1210 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)
1211 {
1212 	switch( pProperty->nWID )
1213 	{
1214 	case OWN_ATTR_VALUE_POLYPOLYGON:
1215 	{
1216 		// PolyPolygon in eine struct PolyPolygon packen
1217 		const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
1218 		drawing::PointSequenceSequence aRetval( rPolyPoly.count() );
1219 
1220 		B2DPolyPolygonToSvxPointSequenceSequence( rPolyPoly, aRetval );
1221 
1222 		rValue <<= aRetval;
1223 		break;
1224 	}
1225 	case OWN_ATTR_BASE_GEOMETRY:
1226 	{
1227 		// pack a PolyPolygon in struct PolyPolygon
1228 		basegfx::B2DPolyPolygon aNewPolyPolygon;
1229 		basegfx::B2DHomMatrix aNewHomogenMatrix;
1230 
1231 		if(mpObj.is())
1232 			mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1233 
1234 		drawing::PointSequenceSequence aRetval(aNewPolyPolygon.count());
1235 		B2DPolyPolygonToSvxPointSequenceSequence(aNewPolyPolygon, aRetval);
1236 		rValue <<= aRetval;
1237 		break;
1238 	}
1239 	case OWN_ATTR_VALUE_POLYGON:
1240 	{
1241 		// PolyPolygon in eine struct PolyPolygon packen
1242 		const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
1243 
1244 		sal_Int32 nCount = 0;
1245 		if( rPolyPoly.count() > 0 )
1246 			nCount = rPolyPoly.getB2DPolygon(0L).count();
1247 
1248 		drawing::PointSequence aRetval( nCount );
1249 
1250 		if( nCount > 0 )
1251 		{
1252 			// Einzelpolygon holen
1253 			const basegfx::B2DPolygon aPoly(rPolyPoly.getB2DPolygon(0L));
1254 
1255 			// Pointer auf arrays holen
1256 			awt::Point* pSequence = aRetval.getArray();
1257 
1258 			for(sal_Int32 b=0;b<nCount;b++)
1259 			{
1260 				const basegfx::B2DPoint aPoint(aPoly.getB2DPoint(b));
1261 				*pSequence++ = awt::Point( basegfx::fround(aPoint.getX()), basegfx::fround(aPoint.getY()) );
1262 			}
1263 		}
1264 
1265 		rValue <<= aRetval;
1266 		break;
1267 	}
1268 	case OWN_ATTR_VALUE_POLYGONKIND:
1269 	{
1270 		rValue <<= GetPolygonKind();
1271 		break;
1272 	}
1273 	default:
1274         return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
1275 	}
1276 
1277 	return true;
1278 }
1279 
1280 //----------------------------------------------------------------------
1281 drawing::PolygonKind SvxShapePolyPolygon::GetPolygonKind() const throw()
1282 {
1283 	return mePolygonKind;
1284 }
1285 
1286 //----------------------------------------------------------------------
1287 void SvxShapePolyPolygon::SetPolygon(const basegfx::B2DPolyPolygon& rNew) throw()
1288 {
1289 	OGuard aGuard( Application::GetSolarMutex() );
1290 
1291 	if(mpObj.is())
1292 		((SdrPathObj*)mpObj.get())->SetPathPoly(rNew);
1293 }
1294 
1295 //----------------------------------------------------------------------
1296 basegfx::B2DPolyPolygon SvxShapePolyPolygon::GetPolygon() const throw()
1297 {
1298 	OGuard aGuard( Application::GetSolarMutex() );
1299 
1300 	if(mpObj.is())
1301 	{
1302 		return ((SdrPathObj*)mpObj.get())->GetPathPoly();
1303 	}
1304 	else
1305 	{
1306 		return basegfx::B2DPolyPolygon();
1307 	}
1308 }
1309 
1310 // ::com::sun::star::lang::XServiceInfo
1311 uno::Sequence< OUString > SAL_CALL SvxShapePolyPolygon::getSupportedServiceNames() throw( uno::RuntimeException )
1312 {
1313 	return SvxShapeText::getSupportedServiceNames();
1314 }
1315 
1316 /***********************************************************************
1317 * class SvxShapePolyPolygonBezier                                      *
1318 ***********************************************************************/
1319 #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
1320 #include <com/sun/star/drawing/FlagSequence.hpp>
1321 //----------------------------------------------------------------------
1322 SvxShapePolyPolygonBezier::SvxShapePolyPolygonBezier( SdrObject* pObj , drawing::PolygonKind eNew ) throw()
1323 :	SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_POLYPOLYGONBEZIER), aSvxMapProvider.GetPropertySet(SVXMAP_POLYPOLYGONBEZIER, SdrObject::GetGlobalDrawObjectItemPool()) )
1324 ,	mePolygonKind( eNew )
1325 {
1326 }
1327 
1328 //----------------------------------------------------------------------
1329 SvxShapePolyPolygonBezier::~SvxShapePolyPolygonBezier() throw()
1330 {
1331 }
1332 
1333 basegfx::B2DPolyPolygon SvxConvertPolyPolygonBezierToB2DPolyPolygon(const drawing::PolyPolygonBezierCoords* pSourcePolyPolygon)
1334 	throw( IllegalArgumentException )
1335 {
1336 	const sal_Int32 nOuterSequenceCount(pSourcePolyPolygon->Coordinates.getLength());
1337 	basegfx::B2DPolyPolygon aNewPolyPolygon;
1338 
1339 	if(pSourcePolyPolygon->Flags.getLength() != nOuterSequenceCount)
1340 	{
1341 		throw IllegalArgumentException();
1342 	}
1343 
1344 	// get pointers to inner sequence
1345 	const drawing::PointSequence* pInnerSequence = pSourcePolyPolygon->Coordinates.getConstArray();
1346 	const drawing::FlagSequence* pInnerSequenceFlags = pSourcePolyPolygon->Flags.getConstArray();
1347 
1348 	for(sal_Int32 a(0); a < nOuterSequenceCount; a++)
1349 	{
1350 		const sal_Int32 nInnerSequenceCount(pInnerSequence->getLength());
1351 
1352 		if(pInnerSequenceFlags->getLength() != nInnerSequenceCount)
1353 		{
1354 			throw IllegalArgumentException();
1355 		}
1356 
1357 		// prepare new polygon
1358 		basegfx::B2DPolygon aNewPolygon;
1359 		const awt::Point* pArray = pInnerSequence->getConstArray();
1360 		const drawing::PolygonFlags* pArrayFlags = pInnerSequenceFlags->getConstArray();
1361 
1362 		// get first point and flag
1363 		basegfx::B2DPoint aNewCoordinatePair(pArray->X, pArray->Y); pArray++;
1364 		XPolyFlags ePolyFlag((XPolyFlags)((sal_uInt16)*pArrayFlags)); pArrayFlags++;
1365 		basegfx::B2DPoint aControlA;
1366 		basegfx::B2DPoint aControlB;
1367 
1368 		// first point is not allowed to be a control point
1369 		if(XPOLY_CONTROL == ePolyFlag)
1370 		{
1371 			throw IllegalArgumentException();
1372 		}
1373 
1374 		// add first point as start point
1375 		aNewPolygon.append(aNewCoordinatePair);
1376 
1377 		for(sal_Int32 b(1); b < nInnerSequenceCount;)
1378 		{
1379 			// prepare loop
1380 			bool bControlA(false);
1381 			bool bControlB(false);
1382 
1383 			// get next point and flag
1384 			aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
1385 			ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
1386 			pArray++; pArrayFlags++; b++;
1387 
1388 			if(b < nInnerSequenceCount && XPOLY_CONTROL == ePolyFlag)
1389 			{
1390 				aControlA = aNewCoordinatePair;
1391 				bControlA = true;
1392 
1393 				// get next point and flag
1394 				aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
1395 				ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
1396 				pArray++; pArrayFlags++; b++;
1397 			}
1398 
1399 			if(b < nInnerSequenceCount && XPOLY_CONTROL == ePolyFlag)
1400 			{
1401 				aControlB = aNewCoordinatePair;
1402 				bControlB = true;
1403 
1404 				// get next point and flag
1405 				aNewCoordinatePair = basegfx::B2DPoint(pArray->X, pArray->Y);
1406 				ePolyFlag = XPolyFlags((XPolyFlags)((sal_uInt16)*pArrayFlags));
1407 				pArray++; pArrayFlags++; b++;
1408 			}
1409 
1410 			// two or no control points are consumed, another one would be an error.
1411 			// It's also an error if only one control point was read
1412 			if(XPOLY_CONTROL == ePolyFlag || bControlA != bControlB)
1413 			{
1414 				throw IllegalArgumentException();
1415 			}
1416 
1417 			// the previous writes used the B2DPolyPoygon -> PolyPolygon converter
1418 			// which did not create minimal PolyPolygons, but created all control points
1419 			// as null vectors (identical points). Because of the former P(CA)(CB)-norm of
1420 			// B2DPolygon and it's unused sign of being the zero-vector and CA and CB being
1421 			// relative to P, an empty edge was exported as P == CA == CB. Luckily, the new
1422 			// export format can be read without errors by the old OOo-versions, so we need only
1423 			// to correct here at read and do not need to export a wrong but compatible version
1424 			// for the future.
1425 			if(bControlA
1426 				&& aControlA.equal(aControlB)
1427 				&& aControlA.equal(aNewPolygon.getB2DPoint(aNewPolygon.count() - 1)))
1428 			{
1429 				bControlA = bControlB = false;
1430 			}
1431 
1432 			if(bControlA)
1433 			{
1434 				// add bezier edge
1435 				aNewPolygon.appendBezierSegment(aControlA, aControlB, aNewCoordinatePair);
1436 			}
1437 			else
1438 			{
1439 				// add edge
1440 				aNewPolygon.append(aNewCoordinatePair);
1441 			}
1442 		}
1443 
1444 		// next sequence
1445 		pInnerSequence++;
1446 		pInnerSequenceFlags++;
1447 
1448 		// #i72807# API import uses old line start/end-equal definition for closed,
1449 		// so we need to correct this to closed state here
1450 		basegfx::tools::checkClosed(aNewPolygon);
1451 
1452 		// add new subpolygon
1453 		aNewPolyPolygon.append(aNewPolygon);
1454 	}
1455 
1456 	return aNewPolyPolygon;
1457 }
1458 
1459 //----------------------------------------------------------------------
1460 
1461 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)
1462 {
1463 	switch( pProperty->nWID )
1464 	{
1465 	case OWN_ATTR_VALUE_POLYPOLYGONBEZIER:
1466 	{
1467 		if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PolyPolygonBezierCoords*)0) ) )
1468 		{
1469 			basegfx::B2DPolyPolygon aNewPolyPolygon(SvxConvertPolyPolygonBezierToB2DPolyPolygon( (drawing::PolyPolygonBezierCoords*)rValue.getValue()));
1470 			SetPolygon(aNewPolyPolygon);
1471 			return true;
1472 		}
1473 		break;
1474 	}
1475 	case OWN_ATTR_BASE_GEOMETRY:
1476 	{
1477 		if( rValue.getValue() && (rValue.getValueType() == ::getCppuType(( const drawing::PolyPolygonBezierCoords*)0)) )
1478 		{
1479 			if( mpObj.is() )
1480 			{
1481 				basegfx::B2DPolyPolygon aNewPolyPolygon;
1482 				basegfx::B2DHomMatrix aNewHomogenMatrix;
1483 
1484 				mpObj->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1485 				aNewPolyPolygon = SvxConvertPolyPolygonBezierToB2DPolyPolygon((drawing::PolyPolygonBezierCoords*)rValue.getValue());
1486 				mpObj->TRSetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1487 			}
1488 			return true;
1489 		}
1490 		break;
1491 	}
1492 	default:
1493         return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
1494 	}
1495 
1496 	throw IllegalArgumentException();
1497 }
1498 
1499 void SvxConvertB2DPolyPolygonToPolyPolygonBezier( const basegfx::B2DPolyPolygon& rPolyPoly, drawing::PolyPolygonBezierCoords& rRetval )
1500 {
1501 	// use PolyPolygon converter as base. Since PolyPolygonBezierCoords uses
1502 	// integer coordinates, this is no precision loss at all.
1503 	const PolyPolygon aPolyPoly(rPolyPoly);
1504 
1505 	// Polygone innerhalb vrobereiten
1506 	rRetval.Coordinates.realloc((sal_Int32)aPolyPoly.Count());
1507 	rRetval.Flags.realloc((sal_Int32)aPolyPoly.Count());
1508 
1509 	// Zeiger auf aeussere Arrays holen
1510 	drawing::PointSequence* pOuterSequence = rRetval.Coordinates.getArray();
1511 	drawing::FlagSequence*  pOuterFlags = rRetval.Flags.getArray();
1512 
1513 	for(sal_uInt16 a=0;a<aPolyPoly.Count();a++)
1514 	{
1515 		// Einzelpolygon holen
1516 		const Polygon& rPoly = aPolyPoly[a];
1517 
1518 		// Platz in Arrays schaffen
1519 		pOuterSequence->realloc((sal_Int32)rPoly.GetSize());
1520 		pOuterFlags->realloc((sal_Int32)rPoly.GetSize());
1521 
1522 		// Pointer auf arrays holen
1523 		awt::Point* pInnerSequence = pOuterSequence->getArray();
1524 		drawing::PolygonFlags* pInnerFlags = pOuterFlags->getArray();
1525 
1526 		for(sal_uInt16 b=0;b<rPoly.GetSize();b++)
1527 		{
1528 			*pInnerSequence++ = awt::Point( rPoly[b].X(), rPoly[b].Y() );
1529 			*pInnerFlags++ = (drawing::PolygonFlags)((sal_uInt16)rPoly.GetFlags(b));
1530 		}
1531 
1532 		pOuterSequence++;
1533 		pOuterFlags++;
1534 	}
1535 }
1536 
1537 //----------------------------------------------------------------------
1538 
1539 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)
1540 {
1541 	switch( pProperty->nWID )
1542 	{
1543 	case OWN_ATTR_VALUE_POLYPOLYGONBEZIER:
1544 	{
1545 		// PolyPolygon in eine struct PolyPolygon packen
1546 		const basegfx::B2DPolyPolygon& rPolyPoly = GetPolygon();
1547 		drawing::PolyPolygonBezierCoords aRetval;
1548 		SvxConvertB2DPolyPolygonToPolyPolygonBezier(rPolyPoly, aRetval );
1549 
1550 		rValue <<= aRetval;
1551 		break;
1552 	}
1553 	case OWN_ATTR_BASE_GEOMETRY:
1554 	{
1555 		// PolyPolygon in eine struct PolyPolygon packen
1556 		basegfx::B2DPolyPolygon aNewPolyPolygon;
1557 		basegfx::B2DHomMatrix aNewHomogenMatrix;
1558 		mpObj.get()->TRGetBaseGeometry(aNewHomogenMatrix, aNewPolyPolygon);
1559 		drawing::PolyPolygonBezierCoords aRetval;
1560 		SvxConvertB2DPolyPolygonToPolyPolygonBezier(aNewPolyPolygon, aRetval);
1561 
1562 		rValue <<= aRetval;
1563 		break;
1564 	}
1565 	case OWN_ATTR_VALUE_POLYGONKIND:
1566 	{
1567 		rValue <<= mePolygonKind;
1568 		break;
1569 	}
1570 	default:
1571         return SvxShapeText::getPropertyValueImpl( rName, pProperty, rValue );
1572 	}
1573 	return true;
1574 }
1575 
1576 //----------------------------------------------------------------------
1577 drawing::PolygonKind SvxShapePolyPolygonBezier::GetPolygonKind() const throw()
1578 {
1579 	return mePolygonKind;
1580 }
1581 
1582 //----------------------------------------------------------------------
1583 void SvxShapePolyPolygonBezier::SetPolygon(const basegfx::B2DPolyPolygon& rNew) throw()
1584 {
1585 	OGuard aGuard( Application::GetSolarMutex() );
1586 
1587 	if(mpObj.is())
1588 		static_cast<SdrPathObj*>(mpObj.get())->SetPathPoly(rNew);
1589 }
1590 
1591 //----------------------------------------------------------------------
1592 basegfx::B2DPolyPolygon SvxShapePolyPolygonBezier::GetPolygon() const throw()
1593 {
1594 	OGuard aGuard( Application::GetSolarMutex() );
1595 
1596 	if(mpObj.is())
1597 	{
1598 		return static_cast<SdrPathObj*>(mpObj.get())->GetPathPoly();
1599 	}
1600 	else
1601 	{
1602 		return basegfx::B2DPolyPolygon();
1603 	}
1604 }
1605 
1606 
1607 // ::com::sun::star::lang::XServiceInfo
1608 uno::Sequence< OUString > SAL_CALL SvxShapePolyPolygonBezier::getSupportedServiceNames() throw( uno::RuntimeException )
1609 {
1610 	return SvxShapeText::getSupportedServiceNames();
1611 }
1612 
1613 /***********************************************************************
1614 * class SvxGraphicObject                                               *
1615 ***********************************************************************/
1616 #include <com/sun/star/awt/XBitmap.hpp>
1617 #include <vcl/cvtgrf.hxx>
1618 #include <svx/svdograf.hxx>
1619 #ifndef SVX_LIGHT
1620 #ifndef _SFXDOCFILE_HXX
1621 #include <sfx2/docfile.hxx>
1622 #endif
1623 #include <sfx2/app.hxx>
1624 #include <sfx2/fcontnr.hxx>
1625 #endif
1626 
1627 #include "toolkit/unohlp.hxx"
1628 
1629 //----------------------------------------------------------------------
1630 SvxGraphicObject::SvxGraphicObject( SdrObject* pObj ) throw()
1631 :	SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_GRAPHICOBJECT), aSvxMapProvider.GetPropertySet(SVXMAP_GRAPHICOBJECT, SdrObject::GetGlobalDrawObjectItemPool()) )
1632 {
1633 }
1634 
1635 //----------------------------------------------------------------------
1636 SvxGraphicObject::~SvxGraphicObject() throw()
1637 {
1638 }
1639 
1640 //----------------------------------------------------------------------
1641 
1642 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)
1643 {
1644 	bool bOk = false;
1645 	switch( pProperty->nWID )
1646 	{
1647 	case OWN_ATTR_VALUE_FILLBITMAP:
1648 	{
1649 		if( rValue.getValue() )
1650 		{
1651 			if( rValue.getValueType() == ::getCppuType(( const uno::Sequence< sal_Int8 >*)0) )
1652 			{
1653 				uno::Sequence<sal_Int8>* pSeq( (uno::Sequence<sal_Int8>*)rValue.getValue() );
1654 				SvMemoryStream	aMemStm;
1655 				Graphic			aGraphic;
1656 
1657 				aMemStm.SetBuffer( (char*)pSeq->getConstArray(), pSeq->getLength(), sal_False, pSeq->getLength() );
1658 
1659 				if( GraphicConverter::Import( aMemStm, aGraphic ) == ERRCODE_NONE )
1660 				{
1661 					static_cast<SdrGrafObj*>(mpObj.get())->SetGraphic(aGraphic);
1662 					bOk = true;
1663 				}
1664 			}
1665 		}
1666 		else if( (rValue.getValueType() == awt::XBitmap::static_type()) || (rValue.getValueType() == graphic::XGraphic::static_type()))
1667 		{
1668 			Reference< graphic::XGraphic> xGraphic( rValue, UNO_QUERY );
1669 			if( xGraphic.is() )
1670 			{
1671 				((SdrGrafObj*)mpObj.get())->SetGraphic(Graphic(xGraphic));
1672 				bOk = true;
1673 			}
1674 			else
1675 			{
1676 				// Bitmap in das Objekt packen
1677 				Reference< awt::XBitmap > xBmp( rValue, UNO_QUERY );
1678 				if( xBmp.is() )
1679 				{
1680 					// Bitmap einsetzen
1681 					Graphic aGraphic(VCLUnoHelper::GetBitmap( xBmp ));
1682 					((SdrGrafObj*)mpObj.get())->SetGraphic(aGraphic);
1683 					bOk = true;
1684 				}
1685 			}
1686 		}
1687 		break;
1688 	}
1689 	case OWN_ATTR_GRAFURL:
1690 	{
1691 		OUString aURL;
1692 		if( rValue >>= aURL )
1693 		{
1694 			if( aURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPREFIX ) ) == 0 )
1695 			{
1696 				// graphic manager url
1697 				aURL = aURL.copy( sizeof( UNO_NAME_GRAPHOBJ_URLPREFIX ) - 1 );
1698 				String aTmpStr(aURL);
1699 				ByteString aUniqueID( aTmpStr, RTL_TEXTENCODING_UTF8 );
1700 				GraphicObject aGrafObj( aUniqueID );
1701 
1702 				// #101808# since loading a graphic can cause a reschedule of the office
1703 				//			it is possible that our shape is removed while where in this
1704 				//			method.
1705 				if( mpObj.is() )
1706 				{
1707 					static_cast<SdrGrafObj*>(mpObj.get())->ReleaseGraphicLink();
1708 					static_cast<SdrGrafObj*>(mpObj.get())->SetGraphicObject( aGrafObj );
1709 				}
1710 			}
1711 			else if( aURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPKGPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPKGPREFIX ) ) != 0 )
1712 			{
1713 				// normal link
1714 				String				aFilterName;
1715 				const SfxFilter*	pSfxFilter = NULL;
1716 				SfxMedium			aSfxMedium( aURL, STREAM_READ | STREAM_SHARE_DENYNONE, sal_False );
1717 
1718 				SFX_APP()->GetFilterMatcher().GuessFilter( aSfxMedium, &pSfxFilter, SFX_FILTER_IMPORT, SFX_FILTER_NOTINSTALLED | SFX_FILTER_EXECUTABLE );
1719 
1720 				if( !pSfxFilter )
1721 				{
1722 					INetURLObject aURLObj( aURL );
1723 
1724 					if( aURLObj.GetProtocol() == INET_PROT_NOT_VALID )
1725 					{
1726 						String aValidURL;
1727 
1728 						if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aURL, aValidURL ) )
1729 							aURLObj = INetURLObject( aValidURL );
1730 					}
1731 
1732 					if( aURLObj.GetProtocol() != INET_PROT_NOT_VALID )
1733 					{
1734 						GraphicFilter* pGrfFilter = GraphicFilter::GetGraphicFilter();
1735 						aFilterName = pGrfFilter->GetImportFormatName( pGrfFilter->GetImportFormatNumberForShortName( aURLObj.getExtension() ) );
1736 					}
1737 				}
1738 				else
1739 					aFilterName = pSfxFilter->GetFilterName();
1740 
1741 				// #101808# since loading a graphic can cause a reschedule of the office
1742 				//			it is possible that our shape is removed while where in this
1743 				//			method.
1744 				if( mpObj.is() )
1745 					static_cast<SdrGrafObj*>(mpObj.get())->SetGraphicLink( aURL, aFilterName );
1746 
1747 			}
1748 			bOk = true;
1749 		}
1750 		break;
1751 	}
1752 
1753 	case OWN_ATTR_GRAFSTREAMURL:
1754 	{
1755 		OUString aStreamURL;
1756 
1757 		if( rValue >>= aStreamURL )
1758 		{
1759 			if( aStreamURL.compareToAscii( UNO_NAME_GRAPHOBJ_URLPKGPREFIX, RTL_CONSTASCII_LENGTH( UNO_NAME_GRAPHOBJ_URLPKGPREFIX ) ) != 0 )
1760 				aStreamURL = OUString();
1761 
1762 			if( mpObj.is() )
1763 			{
1764 				static_cast<SdrGrafObj*>(mpObj.get())->SetGrafStreamURL( aStreamURL );
1765 				static_cast<SdrGrafObj*>(mpObj.get())->ForceSwapOut();
1766 			}
1767 			bOk = true;
1768 		}
1769 		break;
1770 	}
1771 
1772 	case OWN_ATTR_VALUE_GRAPHIC:
1773     {
1774 		Reference< graphic::XGraphic > xGraphic( rValue, uno::UNO_QUERY );
1775 		if( xGraphic.is() )
1776 		{
1777 	    	static_cast< SdrGrafObj*>( mpObj.get() )->SetGraphic( xGraphic );
1778 			bOk = true;
1779 		}
1780 		break;
1781     }
1782 	default:
1783         return SvxShapeText::setPropertyValueImpl( rName, pProperty, rValue );
1784 	}
1785 
1786 	if( !bOk )
1787 		throw lang::IllegalArgumentException();
1788 
1789 	if( mpModel )
1790 		mpModel->SetChanged();
1791 
1792 	return true;
1793 }
1794 
1795 //----------------------------------------------------------------------
1796 
1797 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)
1798 {
1799 	switch( pProperty->nWID )
1800 	{
1801 	case OWN_ATTR_VALUE_FILLBITMAP:
1802 	{
1803 		sal_Bool bSwapped = static_cast< SdrGrafObj* >( mpObj.get() )->IsSwappedOut();
1804 		const Graphic& rGraphic = static_cast< SdrGrafObj*>( mpObj.get() )->GetGraphic();
1805 
1806 		if(rGraphic.GetType() != GRAPHIC_GDIMETAFILE)
1807 		{
1808 			// Objekt in eine Bitmap packen
1809 			Reference< ::com::sun::star::awt::XBitmap >  xBitmap( VCLUnoHelper::CreateBitmap(static_cast< SdrGrafObj*>( mpObj.get() )->GetGraphic().GetBitmapEx()) );
1810 			rValue <<= xBitmap;
1811 		}
1812 		else
1813 		{
1814 			SvMemoryStream aDestStrm( 65535, 65535 );
1815 
1816 			ConvertGDIMetaFileToWMF( rGraphic.GetGDIMetaFile(), aDestStrm, NULL, sal_False );
1817             const uno::Sequence<sal_Int8> aSeq(
1818                 static_cast< const sal_Int8* >(aDestStrm.GetData()),
1819                 aDestStrm.GetEndOfData());
1820 			rValue <<= aSeq;
1821 		}
1822 		if ( bSwapped )
1823 			static_cast< SdrGrafObj* >( mpObj.get() )->ForceSwapOut();
1824 		break;
1825 	}
1826 
1827 	case OWN_ATTR_GRAFURL:
1828 	{
1829 		if( static_cast< SdrGrafObj*>( mpObj.get() )->IsLinkedGraphic() )
1830 		{
1831 			rValue <<= OUString( static_cast< SdrGrafObj*>( mpObj.get() )->GetFileName() );
1832 		}
1833 		else
1834 		{
1835 			sal_Bool bSwapped = static_cast< SdrGrafObj* >( mpObj.get() )->IsSwappedOut();
1836 			const GraphicObject& rGrafObj = static_cast< SdrGrafObj*>( mpObj.get() )->GetGraphicObject(true);
1837 			OUString aURL( RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
1838 			aURL += OUString::createFromAscii( rGrafObj.GetUniqueID().GetBuffer() );
1839 			rValue <<= aURL;
1840 			if ( bSwapped )
1841 				static_cast< SdrGrafObj* >( mpObj.get() )->ForceSwapOut();
1842 		}
1843 		break;
1844 	}
1845 
1846 	case OWN_ATTR_REPLACEMENTGRAFURL:
1847 	{
1848 		const GraphicObject* pGrafObj = static_cast< SdrGrafObj* >(mpObj.get())->GetReplacementGraphicObject();
1849 
1850         if(pGrafObj)
1851         {
1852 			OUString aURL(RTL_CONSTASCII_USTRINGPARAM(UNO_NAME_GRAPHOBJ_URLPREFIX));
1853 			aURL += OUString::createFromAscii(pGrafObj->GetUniqueID().GetBuffer());
1854 			rValue <<= aURL;
1855         }
1856 
1857 		break;
1858 	}
1859 
1860     case OWN_ATTR_GRAFSTREAMURL:
1861 	{
1862 		const OUString	aStreamURL( ( (SdrGrafObj*) mpObj.get() )->GetGrafStreamURL() );
1863 		if( aStreamURL.getLength() )
1864 			rValue <<= aStreamURL;
1865 		break;
1866 	}
1867 
1868 	case OWN_ATTR_VALUE_GRAPHIC:
1869     {
1870 		sal_Bool bSwapped = static_cast< SdrGrafObj* >( mpObj.get() )->IsSwappedOut();
1871         Reference< graphic::XGraphic > xGraphic( static_cast< SdrGrafObj* >( mpObj.get() )->GetGraphic().GetXGraphic() );
1872 		rValue <<= xGraphic;
1873 		if ( bSwapped )
1874 			static_cast< SdrGrafObj* >( mpObj.get() )->ForceSwapOut();
1875 		break;
1876     }
1877 
1878 	case OWN_ATTR_GRAPHIC_STREAM:
1879 	{
1880 		rValue <<= static_cast< SdrGrafObj* >( mpObj.get() )->getInputStream();
1881 		break;
1882 	}
1883 	default:
1884         return SvxShapeText::getPropertyValueImpl(rName, pProperty,rValue);
1885 	}
1886 
1887 	return true;
1888 }
1889 
1890 ///////////////////////////////////////////////////////////////////////
1891 
1892 SvxShapeCaption::SvxShapeCaption( SdrObject* pObj ) throw()
1893 : SvxShapeText( pObj, aSvxMapProvider.GetMap(SVXMAP_CAPTION), aSvxMapProvider.GetPropertySet(SVXMAP_CAPTION, SdrObject::GetGlobalDrawObjectItemPool()) )
1894 {
1895 }
1896 
1897 SvxShapeCaption::~SvxShapeCaption() throw()
1898 {
1899 }
1900 
1901 /***********************************************************************
1902 * class SvxCustomShape                                                   *
1903 ***********************************************************************/
1904 
1905 SvxCustomShape::SvxCustomShape( SdrObject* pObj )  throw() :
1906 	SvxShapeText( pObj, aSvxMapProvider.GetMap( SVXMAP_CUSTOMSHAPE ), aSvxMapProvider.GetPropertySet(SVXMAP_CUSTOMSHAPE, SdrObject::GetGlobalDrawObjectItemPool()) )
1907 {
1908 }
1909 
1910 //----------------------------------------------------------------------
1911 SvxCustomShape::~SvxCustomShape() throw()
1912 {
1913 }
1914 
1915 //----------------------------------------------------------------------
1916 
1917 void SvxCustomShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
1918 {
1919 	SvxShapeText::Create( pNewObj, pNewPage );
1920 }
1921 
1922 //----------------------------------------------------------------------
1923 
1924 uno::Any SAL_CALL SvxCustomShape::queryInterface( const uno::Type & rType )
1925 	throw(uno::RuntimeException)
1926 {
1927     return SvxShapeText::queryInterface( rType );
1928 }
1929 
1930 uno::Any SAL_CALL SvxCustomShape::queryAggregation( const uno::Type & rType )
1931 	throw(uno::RuntimeException)
1932 {
1933 	::com::sun::star::uno::Any aReturn = SvxShapeText::queryAggregation( rType );
1934     if ( !aReturn.hasValue() )
1935 		aReturn = ::cppu::queryInterface(rType, static_cast<drawing::XEnhancedCustomShapeDefaulter*>(this) );
1936 	return aReturn;
1937 }
1938 
1939 void SAL_CALL SvxCustomShape::acquire() throw ( )
1940 {
1941 	SvxShapeText::acquire();
1942 }
1943 
1944 void SAL_CALL SvxCustomShape::release() throw ( )
1945 {
1946 	SvxShapeText::release();
1947 }
1948 
1949 //----------------------------------------------------------------------
1950 
1951 uno::Sequence< uno::Type > SAL_CALL SvxCustomShape::getTypes()
1952 	throw (uno::RuntimeException)
1953 {
1954 	return SvxShapeText::getTypes();
1955 }
1956 
1957 uno::Sequence< sal_Int8 > SAL_CALL SvxCustomShape::getImplementationId()
1958 	throw (uno::RuntimeException)
1959 {
1960 	static uno::Sequence< sal_Int8 > aId;
1961 	if( aId.getLength() == 0 )
1962 	{
1963 		aId.realloc( 16 );
1964 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1965 	}
1966 	return aId;
1967 }
1968 
1969 // ::com::sun::star::drawing::XShape
1970 
1971 //----------------------------------------------------------------------
1972 OUString SAL_CALL SvxCustomShape::getShapeType()
1973 	throw( uno::RuntimeException )
1974 {
1975 	return SvxShape::getShapeType();
1976 }
1977 
1978 //------------------------------------------------------------------1----
1979 awt::Point SAL_CALL SvxCustomShape::getPosition() throw(uno::RuntimeException)
1980 {
1981 	OGuard aGuard( Application::GetSolarMutex() );
1982 	if ( mpModel && mpObj.is() )
1983 	{
1984 		SdrAShapeObjGeoData aCustomShapeGeoData;
1985 		((SdrObjCustomShape*)mpObj.get())->SaveGeoData( aCustomShapeGeoData );
1986 
1987 		sal_Bool bMirroredX = sal_False;
1988 		sal_Bool bMirroredY = sal_False;
1989 
1990 		if ( mpObj.is() )
1991 		{
1992 			bMirroredX = ( ((SdrObjCustomShape*)mpObj.get())->IsMirroredX() );
1993 			bMirroredY = ( ((SdrObjCustomShape*)mpObj.get())->IsMirroredY() );
1994 		}
1995 		// get aRect, this is the unrotated snaprect
1996 		Rectangle aRect(((SdrObjCustomShape*)mpObj.get())->GetLogicRect());
1997 		Rectangle aRectangle( aRect );
1998 
1999 		if ( bMirroredX || bMirroredY )
2000 		{	// we have to retrieve the unmirrored rect
2001 
2002 			GeoStat aNewGeo( aCustomShapeGeoData.aGeo );
2003 			if ( bMirroredX )
2004 			{
2005 				Polygon aPol( Rect2Poly( aRect, aNewGeo ) );
2006 				Rectangle aBoundRect( aPol.GetBoundRect() );
2007 
2008 				Point aRef1( ( aBoundRect.Left() + aBoundRect.Right() ) >> 1, aBoundRect.Top() );
2009 				Point aRef2( aRef1.X(), aRef1.Y() + 1000 );
2010 				sal_uInt16 i;
2011 				sal_uInt16 nPntAnz=aPol.GetSize();
2012 				for (i=0; i<nPntAnz; i++)
2013 				{
2014 					MirrorPoint(aPol[i],aRef1,aRef2);
2015 				}
2016 				// Polygon wenden und etwas schieben
2017 				Polygon aPol0(aPol);
2018 				aPol[0]=aPol0[1];
2019 				aPol[1]=aPol0[0];
2020 				aPol[2]=aPol0[3];
2021 				aPol[3]=aPol0[2];
2022 				aPol[4]=aPol0[1];
2023 				Poly2Rect(aPol,aRectangle,aNewGeo);
2024 			}
2025 			if ( bMirroredY )
2026 			{
2027 				Polygon aPol( Rect2Poly( aRectangle, aNewGeo ) );
2028 				Rectangle aBoundRect( aPol.GetBoundRect() );
2029 
2030 				Point aRef1( aBoundRect.Left(), ( aBoundRect.Top() + aBoundRect.Bottom() ) >> 1 );
2031 				Point aRef2( aRef1.X() + 1000, aRef1.Y() );
2032 				sal_uInt16 i;
2033 				sal_uInt16 nPntAnz=aPol.GetSize();
2034 				for (i=0; i<nPntAnz; i++)
2035 				{
2036 					MirrorPoint(aPol[i],aRef1,aRef2);
2037 				}
2038 				// Polygon wenden und etwas schieben
2039 				Polygon aPol0(aPol);
2040 				aPol[0]=aPol0[1];
2041 				aPol[1]=aPol0[0];
2042 				aPol[2]=aPol0[3];
2043 				aPol[3]=aPol0[2];
2044 				aPol[4]=aPol0[1];
2045 				Poly2Rect( aPol, aRectangle, aNewGeo );
2046 			}
2047 		}
2048 		Point aPt( aRectangle.TopLeft() );
2049 
2050 		if( mpModel->IsWriter() )
2051 			aPt -= mpObj->GetAnchorPos();
2052 
2053 		ForceMetricTo100th_mm(aPt);
2054 		return ::com::sun::star::awt::Point( aPt.X(), aPt.Y() );
2055 	}
2056 	else
2057 		return SvxShape::getPosition();
2058 }
2059 
2060 //----------------------------------------------------------------------
2061 void SAL_CALL SvxCustomShape::setPosition( const awt::Point& Position ) throw(uno::RuntimeException)
2062 {
2063 	SvxShapeText::setPosition(Position);
2064 }
2065 
2066 //----------------------------------------------------------------------
2067 
2068 awt::Size SAL_CALL SvxCustomShape::getSize() throw(uno::RuntimeException)
2069 {
2070 	return SvxShapeText::getSize();
2071 }
2072 
2073 //----------------------------------------------------------------------
2074 void SAL_CALL SvxCustomShape::setSize( const awt::Size& rSize )
2075 	throw(beans::PropertyVetoException, uno::RuntimeException)
2076 {
2077 	SvxShapeText::setSize( rSize );
2078 }
2079 
2080 //----------------------------------------------------------------------
2081 
2082 //----------------------------------------------------------------------
2083 void SAL_CALL SvxCustomShape::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
2084 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, com::sun::star::beans::PropertyVetoException, com::sun::star::lang::IllegalArgumentException)
2085 {
2086 	OGuard aGuard( Application::GetSolarMutex() );
2087     SdrObject* pObject = mpObj.get();
2088 
2089     sal_Bool bCustomShapeGeometry = pObject && aPropertyName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "CustomShapeGeometry" ) );
2090 
2091 	sal_Bool bMirroredX = sal_False;
2092 	sal_Bool bMirroredY = sal_False;
2093 
2094 	if ( bCustomShapeGeometry )
2095 	{
2096 		bMirroredX = ( ((SdrObjCustomShape*)pObject)->IsMirroredX() );
2097 		bMirroredY = ( ((SdrObjCustomShape*)pObject)->IsMirroredY() );
2098 	}
2099 
2100 	SvxShape::setPropertyValue( aPropertyName, aValue );
2101 
2102 	if ( bCustomShapeGeometry )
2103 	{
2104 		((SdrObjCustomShape*)pObject)->MergeDefaultAttributes(0);
2105 		Rectangle aRect( pObject->GetSnapRect() );
2106 
2107 		// #i38892#
2108 		bool bNeedsMirrorX = ((SdrObjCustomShape*)pObject)->IsMirroredX() != bMirroredX;
2109 		bool bNeedsMirrorY = ((SdrObjCustomShape*)pObject)->IsMirroredY() != bMirroredY;
2110 
2111 		boost::scoped_ptr< SdrGluePointList > pListCopy;
2112 		if( bNeedsMirrorX || bNeedsMirrorY )
2113 		{
2114 			const SdrGluePointList* pList = pObject->GetGluePointList();
2115 			if( pList )
2116 				pListCopy.reset( new SdrGluePointList(*pList) );
2117 		}
2118 
2119         if ( bNeedsMirrorX )
2120 		{
2121 			Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
2122 			Point aBottom( aTop.X(), aTop.Y() + 1000 );
2123 			pObject->NbcMirror( aTop, aBottom );
2124 			// NbcMirroring is flipping the current mirror state,
2125 			// so we have to set the correct state again
2126 			((SdrObjCustomShape*)pObject)->SetMirroredX( bMirroredX ? sal_False : sal_True );
2127 		}
2128 		if ( bNeedsMirrorY )
2129 		{
2130 			Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
2131 			Point aRight( aLeft.X() + 1000, aLeft.Y() );
2132 			pObject->NbcMirror( aLeft, aRight );
2133 			// NbcMirroring is flipping the current mirror state,
2134 			// so we have to set the correct state again
2135 			((SdrObjCustomShape*)pObject)->SetMirroredY( bMirroredY ? sal_False : sal_True );
2136 		}
2137 
2138 		if( pListCopy )
2139 		{
2140 			SdrGluePointList* pNewList = const_cast< SdrGluePointList* >( pObject->GetGluePointList() );
2141 			if(pNewList)
2142 				*pNewList = *pListCopy;
2143 		}
2144 	}
2145 }
2146 
2147 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)
2148 {
2149 	switch( pProperty->nWID )
2150 	{
2151 	case SDRATTR_ROTATEANGLE:
2152 	{
2153 		double fAngle = static_cast<SdrObjCustomShape*>(mpObj.get())->GetObjectRotation();
2154 		fAngle *= 100;
2155 		rValue <<= (sal_Int32)fAngle;
2156 		return true;
2157 	}
2158 	default:
2159         return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
2160 	}
2161 }
2162 //----------------------------------------------------------------------
2163 
2164 void SvxCustomShape::createCustomShapeDefaults( const rtl::OUString& rValueType ) throw (::com::sun::star::uno::RuntimeException)
2165 {
2166 	((SdrObjCustomShape*)mpObj.get())->MergeDefaultAttributes( &rValueType );
2167 }
2168