bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / unogallery / unogalitem.cxx
blob0a40fb05d19bf948a3958e02302af0cdc9a933e6
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 <vcl/svapp.hxx>
27 #include <vcl/graph.hxx>
28 #include <svl/itempool.hxx>
29 #include <comphelper/servicehelper.hxx>
30 #include <cppuhelper/supportsservice.hxx>
31 #include <galobj.hxx>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/gallery/GalleryItemType.hpp>
35 #include <memory>
37 #define UNOGALLERY_GALLERYITEMTYPE 1
38 #define UNOGALLERY_URL 2
39 #define UNOGALLERY_TITLE 3
40 #define UNOGALLERY_THUMBNAIL 4
41 #define UNOGALLERY_GRAPHIC 5
42 #define UNOGALLERY_DRAWING 6
44 using namespace ::com::sun::star;
46 namespace unogallery {
49 GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) :
50 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
51 mpTheme( &rTheme ),
52 mpGalleryObject( &rObject )
54 mpTheme->implRegisterGalleryItem( *this );
58 GalleryItem::~GalleryItem()
59 noexcept
61 if( mpTheme )
62 mpTheme->implDeregisterGalleryItem( *this );
66 bool GalleryItem::isValid() const
68 return( mpTheme != nullptr );
72 uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType )
74 uno::Any aAny;
76 if( rType == cppu::UnoType<lang::XServiceInfo>::get())
77 aAny <<= uno::Reference< lang::XServiceInfo >(this);
78 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
79 aAny <<= uno::Reference< lang::XTypeProvider >(this);
80 else if( rType == cppu::UnoType<gallery::XGalleryItem>::get())
81 aAny <<= uno::Reference< gallery::XGalleryItem >(this);
82 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
83 aAny <<= uno::Reference< beans::XPropertySet >(this);
84 else if( rType == cppu::UnoType<beans::XPropertyState>::get())
85 aAny <<= uno::Reference< beans::XPropertyState >(this);
86 else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
87 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
88 else
89 aAny = OWeakAggObject::queryAggregation( rType );
91 return aAny;
95 uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType )
97 return OWeakAggObject::queryInterface( rType );
101 void SAL_CALL GalleryItem::acquire()
102 noexcept
104 OWeakAggObject::acquire();
108 void SAL_CALL GalleryItem::release()
109 noexcept
111 OWeakAggObject::release();
115 OUString SAL_CALL GalleryItem::getImplementationName()
117 return "com.sun.star.comp.gallery.GalleryItem";
120 sal_Bool SAL_CALL GalleryItem::supportsService( const OUString& ServiceName )
122 return cppu::supportsService(this, ServiceName);
125 uno::Sequence< OUString > SAL_CALL GalleryItem::getSupportedServiceNames()
127 return { "com.sun.star.gallery.GalleryItem" };
130 uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes()
132 static const uno::Sequence aTypes {
133 cppu::UnoType<lang::XServiceInfo>::get(),
134 cppu::UnoType<lang::XTypeProvider>::get(),
135 cppu::UnoType<gallery::XGalleryItem>::get(),
136 cppu::UnoType<beans::XPropertySet>::get(),
137 cppu::UnoType<beans::XPropertyState>::get(),
138 cppu::UnoType<beans::XMultiPropertySet>::get() };
139 return aTypes;
142 uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId()
144 return css::uno::Sequence<sal_Int8>();
148 sal_Int8 SAL_CALL GalleryItem::getType()
150 const SolarMutexGuard aGuard;
151 sal_Int8 nRet = gallery::GalleryItemType::EMPTY;
153 if( isValid() )
155 switch( implGetObject()->eObjKind )
157 case SgaObjKind::Sound:
158 nRet = gallery::GalleryItemType::MEDIA;
159 break;
161 case SgaObjKind::SvDraw:
162 nRet = gallery::GalleryItemType::DRAWING;
163 break;
165 default:
166 nRet = gallery::GalleryItemType::GRAPHIC;
167 break;
171 return nRet;
175 rtl::Reference<::comphelper::PropertySetInfo> GalleryItem::createPropertySetInfo()
177 static ::comphelper::PropertyMapEntry const aEntries[] =
179 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE, cppu::UnoType<sal_Int8>::get(),
180 beans::PropertyAttribute::READONLY, 0 },
182 { OUString("URL"), UNOGALLERY_URL, ::cppu::UnoType<OUString>::get(),
183 beans::PropertyAttribute::READONLY, 0 },
185 { OUString("Title"), UNOGALLERY_TITLE, ::cppu::UnoType<OUString>::get(),
186 0, 0 },
188 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL, cppu::UnoType<graphic::XGraphic>::get(),
189 beans::PropertyAttribute::READONLY, 0 },
191 { OUString("Graphic"), UNOGALLERY_GRAPHIC, cppu::UnoType<graphic::XGraphic>::get(),
192 beans::PropertyAttribute::READONLY, 0 },
194 { OUString("Drawing"), UNOGALLERY_DRAWING, cppu::UnoType<lang::XComponent>::get(),
195 beans::PropertyAttribute::READONLY, 0 },
197 { OUString(), 0, css::uno::Type(), 0, 0 }
200 return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo( aEntries ) );
203 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
205 const SolarMutexGuard aGuard;
207 while( *ppEntries )
209 if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
211 OUString aNewTitle;
213 if( !(*pValues >>= aNewTitle) )
215 throw lang::IllegalArgumentException();
218 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
220 if( pGalTheme )
222 std::unique_ptr<SgaObject> pObj(pGalTheme->getGalleryStorageEngine()->implReadSgaObject( implGetObject() ));
224 if( pObj )
226 if( pObj->GetTitle() != aNewTitle )
228 pObj->SetTitle( aNewTitle );
229 pGalTheme->InsertObject( *pObj );
236 ++ppEntries;
237 ++pValues;
241 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
243 const SolarMutexGuard aGuard;
245 while( *ppEntries )
247 switch( (*ppEntries)->mnHandle )
249 case UNOGALLERY_GALLERYITEMTYPE:
251 *pValue <<= getType();
253 break;
255 case UNOGALLERY_URL:
257 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
259 if( pGalTheme )
260 *pValue <<= implGetObject()->getURL().GetMainURL( INetURLObject::DecodeMechanism::NONE );
262 break;
264 case UNOGALLERY_TITLE:
266 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
268 if( pGalTheme )
270 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
272 if( pObj )
274 *pValue <<= pObj->GetTitle();
278 break;
280 case UNOGALLERY_THUMBNAIL:
282 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
284 if( pGalTheme )
286 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
288 if( pObj )
290 Graphic aThumbnail;
292 if( pObj->IsThumbBitmap() )
293 aThumbnail = pObj->GetThumbBmp();
294 else
295 aThumbnail = pObj->GetThumbMtf();
297 *pValue <<= aThumbnail.GetXGraphic();
301 break;
303 case UNOGALLERY_GRAPHIC:
305 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
306 Graphic aGraphic;
308 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), aGraphic ) )
309 *pValue <<= aGraphic.GetXGraphic();
311 break;
313 case UNOGALLERY_DRAWING:
315 if( gallery::GalleryItemType::DRAWING == getType() )
317 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
318 FmFormModel* pModel = new FmFormModel();
320 pModel->GetItemPool().FreezeIdRanges();
322 if( pGalTheme && pGalTheme->GetModel( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), *pModel ) )
324 uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
326 pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
327 *pValue <<= xDrawing;
329 else
330 delete pModel;
333 break;
336 ++ppEntries;
337 ++pValue;
342 void GalleryItem::implSetInvalid()
344 if( mpTheme )
346 mpTheme = nullptr;
347 mpGalleryObject = nullptr;
352 GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc )
353 noexcept :
354 SvxUnoDrawingModel( pDoc )
359 GalleryDrawingModel::~GalleryDrawingModel()
360 noexcept
362 delete GetDoc();
366 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel );
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */