1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unogalitem.cxx,v $
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 #include "unogalitem.hxx"
35 #include "unogaltheme.hxx"
36 #include "galtheme.hxx"
37 #include "galmisc.hxx"
38 #include <svx/fmmodel.hxx>
40 #include <vos/mutex.hxx>
41 #ifndef _SV_SVAPP_HXX_
42 #include <vcl/svapp.hxx>
44 #ifndef _SV_GRAPH_HXX_
45 #include <vcl/graph.hxx>
47 #include <svtools/itemprop.hxx>
48 #include <svtools/itempool.hxx>
51 #ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HDL_
52 #include <com/sun/star/beans/PropertyState.hpp>
54 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HDL_
55 #include <com/sun/star/beans/PropertyAttribute.hpp>
57 #include <com/sun/star/gallery/GalleryItemType.hpp>
59 #define UNOGALLERY_GALLERYITEMTYPE 1
60 #define UNOGALLERY_URL 2
61 #define UNOGALLERY_TITLE 3
62 #define UNOGALLERY_THUMBNAIL 4
63 #define UNOGALLERY_GRAPHIC 5
64 #define UNOGALLERY_DRAWING 6
66 using namespace ::com::sun::star
;
68 namespace unogallery
{
74 GalleryItem::GalleryItem( ::unogallery::GalleryTheme
& rTheme
, const GalleryObject
& rObject
) :
75 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
77 mpGalleryObject( &rObject
)
79 mpTheme
->implRegisterGalleryItem( *this );
82 // ------------------------------------------------------------------------------
84 GalleryItem::~GalleryItem()
88 mpTheme
->implDeregisterGalleryItem( *this );
91 // ------------------------------------------------------------------------------
93 bool GalleryItem::isValid() const
95 return( mpTheme
!= NULL
);
98 // ------------------------------------------------------------------------------
100 uno::Any SAL_CALL
GalleryItem::queryAggregation( const uno::Type
& rType
)
101 throw( uno::RuntimeException
)
105 if( rType
== ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0) )
106 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
107 else if( rType
== ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0) )
108 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
109 else if( rType
== ::getCppuType((const uno::Reference
< gallery::XGalleryItem
>*)0) )
110 aAny
<<= uno::Reference
< gallery::XGalleryItem
>(this);
111 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0) )
112 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
113 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0) )
114 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
115 else if( rType
== ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0) )
116 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
118 aAny
<<= OWeakAggObject::queryAggregation( rType
);
123 // ------------------------------------------------------------------------------
125 uno::Any SAL_CALL
GalleryItem::queryInterface( const uno::Type
& rType
)
126 throw( uno::RuntimeException
)
128 return OWeakAggObject::queryInterface( rType
);
131 // ------------------------------------------------------------------------------
133 void SAL_CALL
GalleryItem::acquire()
136 OWeakAggObject::acquire();
139 // ------------------------------------------------------------------------------
141 void SAL_CALL
GalleryItem::release()
144 OWeakAggObject::release();
147 // ------------------------------------------------------------------------------
149 ::rtl::OUString
GalleryItem::getImplementationName_Static()
152 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.gallery.GalleryItem" ) );
155 // ------------------------------------------------------------------------------
157 uno::Sequence
< ::rtl::OUString
> GalleryItem::getSupportedServiceNames_Static()
160 uno::Sequence
< ::rtl::OUString
> aSeq( 1 );
162 aSeq
.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.gallery.GalleryItem" ) );
167 // ------------------------------------------------------------------------------
169 ::rtl::OUString SAL_CALL
GalleryItem::getImplementationName()
170 throw( uno::RuntimeException
)
172 return getImplementationName_Static();
175 // ------------------------------------------------------------------------------
177 sal_Bool SAL_CALL
GalleryItem::supportsService( const ::rtl::OUString
& ServiceName
)
178 throw( uno::RuntimeException
)
180 uno::Sequence
< ::rtl::OUString
> aSNL( getSupportedServiceNames() );
181 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
183 for( int i
= 0; i
< aSNL
.getLength(); i
++ )
184 if( pArray
[i
] == ServiceName
)
190 // ------------------------------------------------------------------------------
192 uno::Sequence
< ::rtl::OUString
> SAL_CALL
GalleryItem::getSupportedServiceNames()
193 throw( uno::RuntimeException
)
195 return getSupportedServiceNames_Static();
198 // ------------------------------------------------------------------------------
200 uno::Sequence
< uno::Type
> SAL_CALL
GalleryItem::getTypes()
201 throw(uno::RuntimeException
)
203 uno::Sequence
< uno::Type
> aTypes( 6 );
204 uno::Type
* pTypes
= aTypes
.getArray();
206 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0);
207 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0);
208 *pTypes
++ = ::getCppuType((const uno::Reference
< gallery::XGalleryItem
>*)0);
209 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
210 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0);
211 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0);
216 // ------------------------------------------------------------------------------
218 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryItem::getImplementationId()
219 throw(uno::RuntimeException
)
221 const vos::OGuard
aGuard( Application::GetSolarMutex() );
222 static uno::Sequence
< sal_Int8
> aId
;
224 if( aId
.getLength() == 0 )
227 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( aId
.getArray() ), 0, sal_True
);
233 // ------------------------------------------------------------------------------
235 sal_Int8 SAL_CALL
GalleryItem::getType()
236 throw (uno::RuntimeException
)
238 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
239 sal_Int8 nRet
= gallery::GalleryItemType::EMPTY
;
243 switch( implGetObject()->eObjKind
)
245 case( SGA_OBJ_SOUND
):
246 case( SGA_OBJ_VIDEO
):
247 nRet
= gallery::GalleryItemType::MEDIA
;
250 case( SGA_OBJ_SVDRAW
):
251 nRet
= gallery::GalleryItemType::DRAWING
;
255 nRet
= gallery::GalleryItemType::GRAPHIC
;
263 // ------------------------------------------------------------------------------
265 ::comphelper::PropertySetInfo
* GalleryItem::createPropertySetInfo()
267 vos::OGuard
aGuard( Application::GetSolarMutex() );
268 ::comphelper::PropertySetInfo
* pRet
= new ::comphelper::PropertySetInfo();
270 static ::comphelper::PropertyMapEntry aEntries
[] =
272 { MAP_CHAR_LEN( "GalleryItemType" ), UNOGALLERY_GALLERYITEMTYPE
, &::getCppuType( (const sal_Int8
*)(0)),
273 beans::PropertyAttribute::READONLY
, 0 },
275 { MAP_CHAR_LEN( "URL" ), UNOGALLERY_URL
, &::getCppuType( (const ::rtl::OUString
*)(0)),
276 beans::PropertyAttribute::READONLY
, 0 },
278 { MAP_CHAR_LEN( "Title" ), UNOGALLERY_TITLE
, &::getCppuType( (const ::rtl::OUString
*)(0)),
281 { MAP_CHAR_LEN( "Thumbnail" ), UNOGALLERY_THUMBNAIL
, &::getCppuType( (const uno::Reference
< graphic::XGraphic
>*)(0)),
282 beans::PropertyAttribute::READONLY
, 0 },
284 { MAP_CHAR_LEN( "Graphic" ), UNOGALLERY_GRAPHIC
, &::getCppuType( (const uno::Reference
< graphic::XGraphic
>*)(0)),
285 beans::PropertyAttribute::READONLY
, 0 },
287 { MAP_CHAR_LEN( "Drawing" ), UNOGALLERY_DRAWING
, &::getCppuType( (const uno::Reference
< lang::XComponent
>*)(0) ),
288 beans::PropertyAttribute::READONLY
, 0 },
294 pRet
->add( aEntries
);
299 // ------------------------------------------------------------------------------
301 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
302 throw( beans::UnknownPropertyException
,
303 beans::PropertyVetoException
,
304 lang::IllegalArgumentException
,
305 lang::WrappedTargetException
)
307 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
311 if( UNOGALLERY_TITLE
== (*ppEntries
)->mnHandle
)
313 ::rtl::OUString aNewTitle
;
315 if( *pValues
>>= aNewTitle
)
317 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
321 SgaObject
* pObj
= pGalTheme
->ImplReadSgaObject( const_cast< GalleryObject
* >( implGetObject() ) );
325 if( ::rtl::OUString( pObj
->GetTitle() ) != aNewTitle
)
327 pObj
->SetTitle( aNewTitle
);
328 pGalTheme
->InsertObject( *pObj
);
337 throw lang::IllegalArgumentException();
346 // ------------------------------------------------------------------------------
348 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
349 throw( beans::UnknownPropertyException
,
350 lang::WrappedTargetException
)
352 const ::vos::OGuard
aGuard( Application::GetSolarMutex() );
356 switch( (*ppEntries
)->mnHandle
)
358 case( UNOGALLERY_GALLERYITEMTYPE
):
360 *pValue
<<= sal_Int8( getType() );
364 case( UNOGALLERY_URL
):
366 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
369 *pValue
<<= ::rtl::OUString( implGetObject()->aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
373 case( UNOGALLERY_TITLE
):
375 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
379 SgaObject
* pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
383 *pValue
<<= ::rtl::OUString( pObj
->GetTitle() );
384 pGalTheme
->ReleaseObject( pObj
);
390 case( UNOGALLERY_THUMBNAIL
):
392 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
396 SgaObject
* pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
402 if( pObj
->IsThumbBitmap() )
403 aThumbnail
= pObj
->GetThumbBmp();
405 aThumbnail
= pObj
->GetThumbMtf();
407 *pValue
<<= aThumbnail
.GetXGraphic();
408 pGalTheme
->ReleaseObject( pObj
);
414 case( UNOGALLERY_GRAPHIC
):
416 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
419 if( pGalTheme
&& pGalTheme
->GetGraphic( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), aGraphic
) )
420 *pValue
<<= aGraphic
.GetXGraphic();
424 case( UNOGALLERY_DRAWING
):
426 if( gallery::GalleryItemType::DRAWING
== getType() )
428 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
429 FmFormModel
* pModel
= new FmFormModel
;
431 pModel
->GetItemPool().FreezeIdRanges();
433 if( pGalTheme
&& pGalTheme
->GetModel( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), *pModel
) )
435 uno::Reference
< lang::XComponent
> xDrawing( new GalleryDrawingModel( pModel
) );
437 pModel
->setUnoModel( uno::Reference
< uno::XInterface
>::query( xDrawing
) );
438 *pValue
<<= xDrawing
;
452 // ------------------------------------------------------------------------------
454 const ::GalleryObject
* GalleryItem::implGetObject() const
456 return mpGalleryObject
;
459 // ------------------------------------------------------------------------------
461 void GalleryItem::implSetInvalid()
466 mpGalleryObject
= NULL
;
470 // -----------------------
471 // - GalleryDrawingModel -
472 // -----------------------
474 GalleryDrawingModel::GalleryDrawingModel( SdrModel
* pDoc
)
476 SvxUnoDrawingModel( pDoc
)
480 // -----------------------------------------------------------------------------
482 GalleryDrawingModel::~GalleryDrawingModel()
488 // -----------------------------------------------------------------------------
490 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel
);