bump product version to 7.6.3.2-android
[LibreOffice.git] / svx / source / unogallery / unogalitem.cxx
blobc08e182a46aa6b1ca31f17bc82565f088b34efa2
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 <galleryfilestorage.hxx>
24 #include <svx/galtheme.hxx>
25 #include <svx/galmisc.hxx>
26 #include <svx/fmmodel.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/graph.hxx>
29 #include <svl/itempool.hxx>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/supportsservice.hxx>
32 #include <galobj.hxx>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/gallery/GalleryItemType.hpp>
36 #include <memory>
38 #define UNOGALLERY_GALLERYITEMTYPE 1
39 #define UNOGALLERY_URL 2
40 #define UNOGALLERY_TITLE 3
41 #define UNOGALLERY_THUMBNAIL 4
42 #define UNOGALLERY_GRAPHIC 5
43 #define UNOGALLERY_DRAWING 6
45 using namespace ::com::sun::star;
47 namespace unogallery {
50 GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) :
51 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
52 mpTheme( &rTheme ),
53 mpGalleryObject( &rObject )
55 mpTheme->implRegisterGalleryItem( *this );
59 GalleryItem::~GalleryItem()
60 noexcept
62 if( mpTheme )
63 mpTheme->implDeregisterGalleryItem( *this );
67 bool GalleryItem::isValid() const
69 return( mpTheme != nullptr );
73 uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType )
75 uno::Any aAny;
77 if( rType == cppu::UnoType<lang::XServiceInfo>::get())
78 aAny <<= uno::Reference< lang::XServiceInfo >(this);
79 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
80 aAny <<= uno::Reference< lang::XTypeProvider >(this);
81 else if( rType == cppu::UnoType<gallery::XGalleryItem>::get())
82 aAny <<= uno::Reference< gallery::XGalleryItem >(this);
83 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
84 aAny <<= uno::Reference< beans::XPropertySet >(this);
85 else if( rType == cppu::UnoType<beans::XPropertyState>::get())
86 aAny <<= uno::Reference< beans::XPropertyState >(this);
87 else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
88 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
89 else
90 aAny = OWeakAggObject::queryAggregation( rType );
92 return aAny;
96 uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType )
98 return OWeakAggObject::queryInterface( rType );
102 void SAL_CALL GalleryItem::acquire()
103 noexcept
105 OWeakAggObject::acquire();
109 void SAL_CALL GalleryItem::release()
110 noexcept
112 OWeakAggObject::release();
116 OUString SAL_CALL GalleryItem::getImplementationName()
118 return "com.sun.star.comp.gallery.GalleryItem";
121 sal_Bool SAL_CALL GalleryItem::supportsService( const OUString& ServiceName )
123 return cppu::supportsService(this, ServiceName);
126 uno::Sequence< OUString > SAL_CALL GalleryItem::getSupportedServiceNames()
128 return { "com.sun.star.gallery.GalleryItem" };
131 uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes()
133 static const uno::Sequence aTypes {
134 cppu::UnoType<lang::XServiceInfo>::get(),
135 cppu::UnoType<lang::XTypeProvider>::get(),
136 cppu::UnoType<gallery::XGalleryItem>::get(),
137 cppu::UnoType<beans::XPropertySet>::get(),
138 cppu::UnoType<beans::XPropertyState>::get(),
139 cppu::UnoType<beans::XMultiPropertySet>::get() };
140 return aTypes;
143 uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId()
145 return css::uno::Sequence<sal_Int8>();
149 sal_Int8 SAL_CALL GalleryItem::getType()
151 const SolarMutexGuard aGuard;
152 sal_Int8 nRet = gallery::GalleryItemType::EMPTY;
154 if( isValid() )
156 switch( implGetObject()->eObjKind )
158 case SgaObjKind::Sound:
159 nRet = gallery::GalleryItemType::MEDIA;
160 break;
162 case SgaObjKind::SvDraw:
163 nRet = gallery::GalleryItemType::DRAWING;
164 break;
166 default:
167 nRet = gallery::GalleryItemType::GRAPHIC;
168 break;
172 return nRet;
176 rtl::Reference<::comphelper::PropertySetInfo> GalleryItem::createPropertySetInfo()
178 static ::comphelper::PropertyMapEntry const aEntries[] =
180 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE, cppu::UnoType<sal_Int8>::get(),
181 beans::PropertyAttribute::READONLY, 0 },
183 { OUString("URL"), UNOGALLERY_URL, ::cppu::UnoType<OUString>::get(),
184 beans::PropertyAttribute::READONLY, 0 },
186 { OUString("Title"), UNOGALLERY_TITLE, ::cppu::UnoType<OUString>::get(),
187 0, 0 },
189 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL, cppu::UnoType<graphic::XGraphic>::get(),
190 beans::PropertyAttribute::READONLY, 0 },
192 { OUString("Graphic"), UNOGALLERY_GRAPHIC, cppu::UnoType<graphic::XGraphic>::get(),
193 beans::PropertyAttribute::READONLY, 0 },
195 { OUString("Drawing"), UNOGALLERY_DRAWING, cppu::UnoType<lang::XComponent>::get(),
196 beans::PropertyAttribute::READONLY, 0 },
199 return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo( aEntries ) );
202 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
204 const SolarMutexGuard aGuard;
206 while( *ppEntries )
208 if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
210 OUString aNewTitle;
212 if( !(*pValues >>= aNewTitle) )
214 throw lang::IllegalArgumentException();
217 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
219 if( pGalTheme )
221 std::unique_ptr<SgaObject> pObj(pGalTheme->getGalleryStorageEngine()->implReadSgaObject( implGetObject() ));
223 if( pObj )
225 if( pObj->GetTitle() != aNewTitle )
227 pObj->SetTitle( aNewTitle );
228 pGalTheme->InsertObject( *pObj );
235 ++ppEntries;
236 ++pValues;
240 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
242 const SolarMutexGuard aGuard;
244 while( *ppEntries )
246 switch( (*ppEntries)->mnHandle )
248 case UNOGALLERY_GALLERYITEMTYPE:
250 *pValue <<= getType();
252 break;
254 case UNOGALLERY_URL:
256 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
258 if( pGalTheme )
259 *pValue <<= implGetObject()->m_oStorageUrl->GetMainURL( INetURLObject::DecodeMechanism::NONE );
261 break;
263 case UNOGALLERY_TITLE:
265 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
267 if( pGalTheme )
269 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
271 if( pObj )
273 *pValue <<= pObj->GetTitle();
277 break;
279 case UNOGALLERY_THUMBNAIL:
281 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
283 if( pGalTheme )
285 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
287 if( pObj )
289 Graphic aThumbnail;
291 if( pObj->IsThumbBitmap() )
292 aThumbnail = pObj->GetThumbBmp();
293 else
294 aThumbnail = pObj->GetThumbMtf();
296 *pValue <<= aThumbnail.GetXGraphic();
300 break;
302 case UNOGALLERY_GRAPHIC:
304 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
305 Graphic aGraphic;
307 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), aGraphic ) )
308 *pValue <<= aGraphic.GetXGraphic();
310 break;
312 case UNOGALLERY_DRAWING:
314 if( gallery::GalleryItemType::DRAWING == getType() )
316 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
317 FmFormModel* pModel = new FmFormModel();
319 pModel->GetItemPool().FreezeIdRanges();
321 if( pGalTheme && pGalTheme->GetModel( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), *pModel ) )
323 uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
325 pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
326 *pValue <<= xDrawing;
328 else
329 delete pModel;
332 break;
335 ++ppEntries;
336 ++pValue;
341 void GalleryItem::implSetInvalid()
343 if( mpTheme )
345 mpTheme = nullptr;
346 mpGalleryObject = nullptr;
351 GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc )
352 noexcept :
353 SvxUnoDrawingModel( pDoc )
358 GalleryDrawingModel::~GalleryDrawingModel()
359 noexcept
361 delete GetDoc();
365 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel );
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */