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>
38 #include <boost/scoped_ptr.hpp>
40 #define UNOGALLERY_GALLERYITEMTYPE 1
41 #define UNOGALLERY_URL 2
42 #define UNOGALLERY_TITLE 3
43 #define UNOGALLERY_THUMBNAIL 4
44 #define UNOGALLERY_GRAPHIC 5
45 #define UNOGALLERY_DRAWING 6
47 using namespace ::com::sun::star
;
49 namespace unogallery
{
55 GalleryItem::GalleryItem( ::unogallery::GalleryTheme
& rTheme
, const GalleryObject
& rObject
) :
56 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
58 mpGalleryObject( &rObject
)
60 mpTheme
->implRegisterGalleryItem( *this );
65 GalleryItem::~GalleryItem()
69 mpTheme
->implDeregisterGalleryItem( *this );
74 bool GalleryItem::isValid() const
76 return( mpTheme
!= NULL
);
81 uno::Any SAL_CALL
GalleryItem::queryAggregation( const uno::Type
& rType
)
82 throw( uno::RuntimeException
, std::exception
)
86 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
87 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
88 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
89 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
90 else if( rType
== cppu::UnoType
<gallery::XGalleryItem
>::get())
91 aAny
<<= uno::Reference
< gallery::XGalleryItem
>(this);
92 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
93 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
94 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
95 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
96 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
97 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
99 aAny
<<= OWeakAggObject::queryAggregation( rType
);
106 uno::Any SAL_CALL
GalleryItem::queryInterface( const uno::Type
& rType
)
107 throw( uno::RuntimeException
, std::exception
)
109 return OWeakAggObject::queryInterface( rType
);
114 void SAL_CALL
GalleryItem::acquire()
117 OWeakAggObject::acquire();
122 void SAL_CALL
GalleryItem::release()
125 OWeakAggObject::release();
130 OUString
GalleryItem::getImplementationName_Static()
133 return OUString( "com.sun.star.comp.gallery.GalleryItem" );
138 uno::Sequence
< OUString
> GalleryItem::getSupportedServiceNames_Static()
141 uno::Sequence
< OUString
> aSeq( 1 );
143 aSeq
.getArray()[ 0 ] = "com.sun.star.gallery.GalleryItem";
148 OUString SAL_CALL
GalleryItem::getImplementationName()
149 throw( uno::RuntimeException
, std::exception
)
151 return getImplementationName_Static();
154 sal_Bool SAL_CALL
GalleryItem::supportsService( const OUString
& ServiceName
)
155 throw( uno::RuntimeException
, std::exception
)
157 return cppu::supportsService(this, ServiceName
);
160 uno::Sequence
< OUString
> SAL_CALL
GalleryItem::getSupportedServiceNames()
161 throw( uno::RuntimeException
, std::exception
)
163 return getSupportedServiceNames_Static();
166 uno::Sequence
< uno::Type
> SAL_CALL
GalleryItem::getTypes()
167 throw(uno::RuntimeException
, std::exception
)
169 uno::Sequence
< uno::Type
> aTypes( 6 );
170 uno::Type
* pTypes
= aTypes
.getArray();
172 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
173 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
174 *pTypes
++ = cppu::UnoType
<gallery::XGalleryItem
>::get();
175 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
176 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
177 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
182 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryItem::getImplementationId()
183 throw(uno::RuntimeException
, std::exception
)
185 return css::uno::Sequence
<sal_Int8
>();
190 sal_Int8 SAL_CALL
GalleryItem::getType()
191 throw (uno::RuntimeException
, std::exception
)
193 const SolarMutexGuard aGuard
;
194 sal_Int8 nRet
= gallery::GalleryItemType::EMPTY
;
198 switch( implGetObject()->eObjKind
)
200 case( SGA_OBJ_SOUND
):
201 case( SGA_OBJ_VIDEO
):
202 nRet
= gallery::GalleryItemType::MEDIA
;
205 case( SGA_OBJ_SVDRAW
):
206 nRet
= gallery::GalleryItemType::DRAWING
;
210 nRet
= gallery::GalleryItemType::GRAPHIC
;
220 ::comphelper::PropertySetInfo
* GalleryItem::createPropertySetInfo()
222 SolarMutexGuard aGuard
;
223 ::comphelper::PropertySetInfo
* pRet
= new ::comphelper::PropertySetInfo();
225 static ::comphelper::PropertyMapEntry
const aEntries
[] =
227 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE
, cppu::UnoType
<sal_Int8
>::get(),
228 beans::PropertyAttribute::READONLY
, 0 },
230 { OUString("URL"), UNOGALLERY_URL
, ::cppu::UnoType
<OUString
>::get(),
231 beans::PropertyAttribute::READONLY
, 0 },
233 { OUString("Title"), UNOGALLERY_TITLE
, ::cppu::UnoType
<OUString
>::get(),
236 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL
, cppu::UnoType
<graphic::XGraphic
>::get(),
237 beans::PropertyAttribute::READONLY
, 0 },
239 { OUString("Graphic"), UNOGALLERY_GRAPHIC
, cppu::UnoType
<graphic::XGraphic
>::get(),
240 beans::PropertyAttribute::READONLY
, 0 },
242 { OUString("Drawing"), UNOGALLERY_DRAWING
, cppu::UnoType
<lang::XComponent
>::get(),
243 beans::PropertyAttribute::READONLY
, 0 },
245 { OUString(), 0, css::uno::Type(), 0, 0 }
249 pRet
->add( aEntries
);
254 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
255 throw (beans::UnknownPropertyException
,
256 beans::PropertyVetoException
,
257 lang::IllegalArgumentException
,
258 lang::WrappedTargetException
,
259 uno::RuntimeException
)
261 const SolarMutexGuard aGuard
;
265 if( UNOGALLERY_TITLE
== (*ppEntries
)->mnHandle
)
269 if( *pValues
>>= aNewTitle
)
271 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
275 boost::scoped_ptr
<SgaObject
> pObj(pGalTheme
->ImplReadSgaObject( const_cast< GalleryObject
* >( implGetObject() ) ));
279 if( OUString( pObj
->GetTitle() ) != aNewTitle
)
281 pObj
->SetTitle( aNewTitle
);
282 pGalTheme
->InsertObject( *pObj
);
289 throw lang::IllegalArgumentException();
298 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
299 throw (beans::UnknownPropertyException
,
300 lang::WrappedTargetException
,
301 css::uno::RuntimeException
,
304 const SolarMutexGuard aGuard
;
308 switch( (*ppEntries
)->mnHandle
)
310 case( UNOGALLERY_GALLERYITEMTYPE
):
312 *pValue
<<= sal_Int8( getType() );
316 case( UNOGALLERY_URL
):
318 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
321 *pValue
<<= OUString( implGetObject()->aURL
.GetMainURL( INetURLObject::NO_DECODE
) );
325 case( UNOGALLERY_TITLE
):
327 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
331 SgaObject
* pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
335 *pValue
<<= OUString( pObj
->GetTitle() );
336 ::GalleryTheme::ReleaseObject( pObj
);
342 case( UNOGALLERY_THUMBNAIL
):
344 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
348 SgaObject
* pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
354 if( pObj
->IsThumbBitmap() )
355 aThumbnail
= pObj
->GetThumbBmp();
357 aThumbnail
= pObj
->GetThumbMtf();
359 *pValue
<<= aThumbnail
.GetXGraphic();
360 ::GalleryTheme::ReleaseObject( pObj
);
366 case( UNOGALLERY_GRAPHIC
):
368 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
371 if( pGalTheme
&& pGalTheme
->GetGraphic( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), aGraphic
) )
372 *pValue
<<= aGraphic
.GetXGraphic();
376 case( UNOGALLERY_DRAWING
):
378 if( gallery::GalleryItemType::DRAWING
== getType() )
380 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : NULL
);
381 FmFormModel
* pModel
= new FmFormModel
;
383 pModel
->GetItemPool().FreezeIdRanges();
385 if( pGalTheme
&& pGalTheme
->GetModel( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), *pModel
) )
387 uno::Reference
< lang::XComponent
> xDrawing( new GalleryDrawingModel( pModel
) );
389 pModel
->setUnoModel( uno::Reference
< uno::XInterface
>::query( xDrawing
) );
390 *pValue
<<= xDrawing
;
409 void GalleryItem::implSetInvalid()
414 mpGalleryObject
= NULL
;
419 // - GalleryDrawingModel -
422 GalleryDrawingModel::GalleryDrawingModel( SdrModel
* pDoc
)
424 SvxUnoDrawingModel( pDoc
)
430 GalleryDrawingModel::~GalleryDrawingModel()
438 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel
);
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */