bump product version to 5.0.4.1
[LibreOffice.git] / svx / source / unogallery / unogalitem.cxx
blobe6cf941a84872271dbfd92b5276f2a92763640e2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
33 #include "galobj.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 {
52 // - GalleryItem -
55 GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) :
56 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
57 mpTheme( &rTheme ),
58 mpGalleryObject( &rObject )
60 mpTheme->implRegisterGalleryItem( *this );
65 GalleryItem::~GalleryItem()
66 throw()
68 if( mpTheme )
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 )
84 uno::Any aAny;
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);
98 else
99 aAny <<= OWeakAggObject::queryAggregation( rType );
101 return aAny;
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()
115 throw()
117 OWeakAggObject::acquire();
122 void SAL_CALL GalleryItem::release()
123 throw()
125 OWeakAggObject::release();
130 OUString GalleryItem::getImplementationName_Static()
131 throw()
133 return OUString( "com.sun.star.comp.gallery.GalleryItem" );
138 uno::Sequence< OUString > GalleryItem::getSupportedServiceNames_Static()
139 throw()
141 uno::Sequence< OUString > aSeq( 1 );
143 aSeq.getArray()[ 0 ] = "com.sun.star.gallery.GalleryItem";
145 return aSeq;
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();
179 return aTypes;
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;
196 if( isValid() )
198 switch( implGetObject()->eObjKind )
200 case( SGA_OBJ_SOUND ):
201 case( SGA_OBJ_VIDEO ):
202 nRet = gallery::GalleryItemType::MEDIA;
203 break;
205 case( SGA_OBJ_SVDRAW ):
206 nRet = gallery::GalleryItemType::DRAWING;
207 break;
209 default:
210 nRet = gallery::GalleryItemType::GRAPHIC;
211 break;
215 return nRet;
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(),
234 0, 0 },
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 }
248 pRet->acquire();
249 pRet->add( aEntries );
251 return pRet;
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;
263 while( *ppEntries )
265 if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
267 OUString aNewTitle;
269 if( *pValues >>= aNewTitle )
271 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
273 if( pGalTheme )
275 boost::scoped_ptr<SgaObject> pObj(pGalTheme->ImplReadSgaObject( const_cast< GalleryObject* >( implGetObject() ) ));
277 if( pObj )
279 if( OUString( pObj->GetTitle() ) != aNewTitle )
281 pObj->SetTitle( aNewTitle );
282 pGalTheme->InsertObject( *pObj );
287 else
289 throw lang::IllegalArgumentException();
293 ++ppEntries;
294 ++pValues;
298 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
299 throw (beans::UnknownPropertyException,
300 lang::WrappedTargetException,
301 css::uno::RuntimeException,
302 std::exception)
304 const SolarMutexGuard aGuard;
306 while( *ppEntries )
308 switch( (*ppEntries)->mnHandle )
310 case( UNOGALLERY_GALLERYITEMTYPE ):
312 *pValue <<= sal_Int8( getType() );
314 break;
316 case( UNOGALLERY_URL ):
318 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
320 if( pGalTheme )
321 *pValue <<= OUString( implGetObject()->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
323 break;
325 case( UNOGALLERY_TITLE ):
327 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
329 if( pGalTheme )
331 SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
333 if( pObj )
335 *pValue <<= OUString( pObj->GetTitle() );
336 ::GalleryTheme::ReleaseObject( pObj );
340 break;
342 case( UNOGALLERY_THUMBNAIL ):
344 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
346 if( pGalTheme )
348 SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
350 if( pObj )
352 Graphic aThumbnail;
354 if( pObj->IsThumbBitmap() )
355 aThumbnail = pObj->GetThumbBmp();
356 else
357 aThumbnail = pObj->GetThumbMtf();
359 *pValue <<= aThumbnail.GetXGraphic();
360 ::GalleryTheme::ReleaseObject( pObj );
364 break;
366 case( UNOGALLERY_GRAPHIC ):
368 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
369 Graphic aGraphic;
371 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), aGraphic ) )
372 *pValue <<= aGraphic.GetXGraphic();
374 break;
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;
392 else
393 delete pModel;
396 break;
399 ++ppEntries;
400 ++pValue;
409 void GalleryItem::implSetInvalid()
411 if( mpTheme )
413 mpTheme = NULL;
414 mpGalleryObject = NULL;
419 // - GalleryDrawingModel -
422 GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc )
423 throw() :
424 SvxUnoDrawingModel( pDoc )
430 GalleryDrawingModel::~GalleryDrawingModel()
431 throw()
433 delete GetDoc();
438 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel );
442 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */