1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "unogalitem.hxx"
22 #include "unogaltheme.hxx"
23 #include "svx/galtheme.hxx"
24 #include "svx/galmisc.hxx"
25 #include <svx/fmmodel.hxx>
26 #include <osl/mutex.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/graph.hxx>
29 #include <svl/itemprop.hxx>
30 #include <svl/itempool.hxx>
31 #include <comphelper/servicehelper.hxx>
32 #include <cppuhelper/supportsservice.hxx>
35 #include <com/sun/star/beans/PropertyState.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/gallery/GalleryItemType.hpp>
39 #define UNOGALLERY_GALLERYITEMTYPE 1
40 #define UNOGALLERY_URL 2
41 #define UNOGALLERY_TITLE 3
42 #define UNOGALLERY_THUMBNAIL 4
43 #define UNOGALLERY_GRAPHIC 5
44 #define UNOGALLERY_DRAWING 6
46 using namespace ::com::sun::star
;
48 namespace unogallery
{
54 GalleryItem::GalleryItem( ::unogallery::GalleryTheme
& rTheme
, const GalleryObject
& rObject
) :
55 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
57 mpGalleryObject( &rObject
)
59 mpTheme
->implRegisterGalleryItem( *this );
64 GalleryItem::~GalleryItem()
68 mpTheme
->implDeregisterGalleryItem( *this );
73 bool GalleryItem::isValid() const
75 return( mpTheme
!= NULL
);
80 uno::Any SAL_CALL
GalleryItem::queryAggregation( const uno::Type
& rType
)
81 throw( uno::RuntimeException
, std::exception
)
85 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
86 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
87 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
88 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
89 else if( rType
== cppu::UnoType
<gallery::XGalleryItem
>::get())
90 aAny
<<= uno::Reference
< gallery::XGalleryItem
>(this);
91 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
92 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
93 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
94 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
95 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
96 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
98 aAny
<<= OWeakAggObject::queryAggregation( rType
);
105 uno::Any SAL_CALL
GalleryItem::queryInterface( const uno::Type
& rType
)
106 throw( uno::RuntimeException
, std::exception
)
108 return OWeakAggObject::queryInterface( rType
);
113 void SAL_CALL
GalleryItem::acquire()
116 OWeakAggObject::acquire();
121 void SAL_CALL
GalleryItem::release()
124 OWeakAggObject::release();
129 OUString
GalleryItem::getImplementationName_Static()
132 return OUString( "com.sun.star.comp.gallery.GalleryItem" );
137 uno::Sequence
< OUString
> GalleryItem::getSupportedServiceNames_Static()
140 uno::Sequence
< OUString
> aSeq( 1 );
142 aSeq
.getArray()[ 0 ] = "com.sun.star.gallery.GalleryItem";
147 OUString SAL_CALL
GalleryItem::getImplementationName()
148 throw( uno::RuntimeException
, std::exception
)
150 return getImplementationName_Static();
153 sal_Bool SAL_CALL
GalleryItem::supportsService( const OUString
& ServiceName
)
154 throw( uno::RuntimeException
, std::exception
)
156 return cppu::supportsService(this, ServiceName
);
159 uno::Sequence
< OUString
> SAL_CALL
GalleryItem::getSupportedServiceNames()
160 throw( uno::RuntimeException
, std::exception
)
162 return getSupportedServiceNames_Static();
165 uno::Sequence
< uno::Type
> SAL_CALL
GalleryItem::getTypes()
166 throw(uno::RuntimeException
, std::exception
)
168 uno::Sequence
< uno::Type
> aTypes( 6 );
169 uno::Type
* pTypes
= aTypes
.getArray();
171 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
172 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
173 *pTypes
++ = cppu::UnoType
<gallery::XGalleryItem
>::get();
174 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
175 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
176 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
181 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryItem::getImplementationId()
182 throw(uno::RuntimeException
, std::exception
)
184 return css::uno::Sequence
<sal_Int8
>();
189 sal_Int8 SAL_CALL
GalleryItem::getType()
190 throw (uno::RuntimeException
, std::exception
)
192 const SolarMutexGuard aGuard
;
193 sal_Int8 nRet
= gallery::GalleryItemType::EMPTY
;
197 switch( implGetObject()->eObjKind
)
199 case( SGA_OBJ_SOUND
):
200 case( SGA_OBJ_VIDEO
):
201 nRet
= gallery::GalleryItemType::MEDIA
;
204 case( SGA_OBJ_SVDRAW
):
205 nRet
= gallery::GalleryItemType::DRAWING
;
209 nRet
= gallery::GalleryItemType::GRAPHIC
;
219 ::comphelper::PropertySetInfo
* GalleryItem::createPropertySetInfo()
221 SolarMutexGuard aGuard
;
222 ::comphelper::PropertySetInfo
* pRet
= new ::comphelper::PropertySetInfo();
224 static ::comphelper::PropertyMapEntry
const aEntries
[] =
226 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE
, cppu::UnoType
<sal_Int8
>::get(),
227 beans::PropertyAttribute::READONLY
, 0 },
229 { OUString("URL"), UNOGALLERY_URL
, ::cppu::UnoType
<OUString
>::get(),
230 beans::PropertyAttribute::READONLY
, 0 },
232 { OUString("Title"), UNOGALLERY_TITLE
, ::cppu::UnoType
<OUString
>::get(),
235 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL
, cppu::UnoType
<graphic::XGraphic
>::get(),
236 beans::PropertyAttribute::READONLY
, 0 },
238 { OUString("Graphic"), UNOGALLERY_GRAPHIC
, cppu::UnoType
<graphic::XGraphic
>::get(),
239 beans::PropertyAttribute::READONLY
, 0 },
241 { OUString("Drawing"), UNOGALLERY_DRAWING
, cppu::UnoType
<lang::XComponent
>::get(),
242 beans::PropertyAttribute::READONLY
, 0 },
244 { OUString(), 0, css::uno::Type(), 0, 0 }
248 pRet
->add( aEntries
);
255 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
256 throw( beans::UnknownPropertyException
,
257 beans::PropertyVetoException
,
258 lang::IllegalArgumentException
,
259 lang::WrappedTargetException
)
261 const SolarMutexGuard aGuard
;
265 if( UNOGALLERY_TITLE
== (*ppEntries
)->mnHandle
)
269 if( *pValues
>>= aNewTitle
)
271 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
275 SgaObject
* pObj
= pGalTheme
->ImplReadSgaObject( const_cast< GalleryObject
* >( implGetObject() ) );
279 if( OUString( pObj
->GetTitle() ) != aNewTitle
)
281 pObj
->SetTitle( aNewTitle
);
282 pGalTheme
->InsertObject( *pObj
);
291 throw lang::IllegalArgumentException();
302 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
303 throw( beans::UnknownPropertyException
,
304 lang::WrappedTargetException
)
306 const SolarMutexGuard aGuard
;
310 switch( (*ppEntries
)->mnHandle
)
312 case( UNOGALLERY_GALLERYITEMTYPE
):
314 *pValue
<<= sal_Int8( getType() );
318 case( UNOGALLERY_URL
):
320 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
323 *pValue
<<= OUString( implGetObject()->aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
327 case( UNOGALLERY_TITLE
):
329 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
333 SgaObject
* pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
337 *pValue
<<= OUString( pObj
->GetTitle() );
338 pGalTheme
->ReleaseObject( pObj
);
344 case( UNOGALLERY_THUMBNAIL
):
346 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
350 SgaObject
* pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
356 if( pObj
->IsThumbBitmap() )
357 aThumbnail
= pObj
->GetThumbBmp();
359 aThumbnail
= pObj
->GetThumbMtf();
361 *pValue
<<= aThumbnail
.GetXGraphic();
362 pGalTheme
->ReleaseObject( pObj
);
368 case( UNOGALLERY_GRAPHIC
):
370 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
373 if( pGalTheme
&& pGalTheme
->GetGraphic( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), aGraphic
) )
374 *pValue
<<= aGraphic
.GetXGraphic();
378 case( UNOGALLERY_DRAWING
):
380 if( gallery::GalleryItemType::DRAWING
== getType() )
382 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
383 FmFormModel
* pModel
= new FmFormModel
;
385 pModel
->GetItemPool().FreezeIdRanges();
387 if( pGalTheme
&& pGalTheme
->GetModel( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), *pModel
) )
389 uno::Reference
< lang::XComponent
> xDrawing( new GalleryDrawingModel( pModel
) );
391 pModel
->setUnoModel( uno::Reference
< uno::XInterface
>::query( xDrawing
) );
392 *pValue
<<= xDrawing
;
408 const ::GalleryObject
* GalleryItem::implGetObject() const
410 return mpGalleryObject
;
415 void GalleryItem::implSetInvalid()
420 mpGalleryObject
= NULL
;
425 // - GalleryDrawingModel -
428 GalleryDrawingModel::GalleryDrawingModel( SdrModel
* pDoc
)
430 SvxUnoDrawingModel( pDoc
)
436 GalleryDrawingModel::~GalleryDrawingModel()
444 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel
);
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */