Bump version to 6.4-15
[LibreOffice.git] / svx / source / unogallery / unogalitem.cxx
blob74023011d380773b9b618e1bcff69a12d8cf92c9
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/itemprop.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/PropertyState.hpp>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/gallery/GalleryItemType.hpp>
37 #include <memory>
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 {
51 GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) :
52 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
53 mpTheme( &rTheme ),
54 mpGalleryObject( &rObject )
56 mpTheme->implRegisterGalleryItem( *this );
60 GalleryItem::~GalleryItem()
61 throw()
63 if( mpTheme )
64 mpTheme->implDeregisterGalleryItem( *this );
68 bool GalleryItem::isValid() const
70 return( mpTheme != nullptr );
74 uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType )
76 uno::Any aAny;
78 if( rType == cppu::UnoType<lang::XServiceInfo>::get())
79 aAny <<= uno::Reference< lang::XServiceInfo >(this);
80 else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
81 aAny <<= uno::Reference< lang::XTypeProvider >(this);
82 else if( rType == cppu::UnoType<gallery::XGalleryItem>::get())
83 aAny <<= uno::Reference< gallery::XGalleryItem >(this);
84 else if( rType == cppu::UnoType<beans::XPropertySet>::get())
85 aAny <<= uno::Reference< beans::XPropertySet >(this);
86 else if( rType == cppu::UnoType<beans::XPropertyState>::get())
87 aAny <<= uno::Reference< beans::XPropertyState >(this);
88 else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
89 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
90 else
91 aAny = OWeakAggObject::queryAggregation( rType );
93 return aAny;
97 uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType )
99 return OWeakAggObject::queryInterface( rType );
103 void SAL_CALL GalleryItem::acquire()
104 throw()
106 OWeakAggObject::acquire();
110 void SAL_CALL GalleryItem::release()
111 throw()
113 OWeakAggObject::release();
117 OUString SAL_CALL GalleryItem::getImplementationName()
119 return "com.sun.star.comp.gallery.GalleryItem";
122 sal_Bool SAL_CALL GalleryItem::supportsService( const OUString& ServiceName )
124 return cppu::supportsService(this, ServiceName);
127 uno::Sequence< OUString > SAL_CALL GalleryItem::getSupportedServiceNames()
129 return { "com.sun.star.gallery.GalleryItem" };
132 uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes()
134 static const uno::Sequence aTypes {
135 cppu::UnoType<lang::XServiceInfo>::get(),
136 cppu::UnoType<lang::XTypeProvider>::get(),
137 cppu::UnoType<gallery::XGalleryItem>::get(),
138 cppu::UnoType<beans::XPropertySet>::get(),
139 cppu::UnoType<beans::XPropertyState>::get(),
140 cppu::UnoType<beans::XMultiPropertySet>::get() };
141 return aTypes;
144 uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId()
146 return css::uno::Sequence<sal_Int8>();
150 sal_Int8 SAL_CALL GalleryItem::getType()
152 const SolarMutexGuard aGuard;
153 sal_Int8 nRet = gallery::GalleryItemType::EMPTY;
155 if( isValid() )
157 switch( implGetObject()->eObjKind )
159 case SgaObjKind::Sound:
160 nRet = gallery::GalleryItemType::MEDIA;
161 break;
163 case SgaObjKind::SvDraw:
164 nRet = gallery::GalleryItemType::DRAWING;
165 break;
167 default:
168 nRet = gallery::GalleryItemType::GRAPHIC;
169 break;
173 return nRet;
177 rtl::Reference<::comphelper::PropertySetInfo> GalleryItem::createPropertySetInfo()
179 static ::comphelper::PropertyMapEntry const aEntries[] =
181 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE, cppu::UnoType<sal_Int8>::get(),
182 beans::PropertyAttribute::READONLY, 0 },
184 { OUString("URL"), UNOGALLERY_URL, ::cppu::UnoType<OUString>::get(),
185 beans::PropertyAttribute::READONLY, 0 },
187 { OUString("Title"), UNOGALLERY_TITLE, ::cppu::UnoType<OUString>::get(),
188 0, 0 },
190 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL, cppu::UnoType<graphic::XGraphic>::get(),
191 beans::PropertyAttribute::READONLY, 0 },
193 { OUString("Graphic"), UNOGALLERY_GRAPHIC, cppu::UnoType<graphic::XGraphic>::get(),
194 beans::PropertyAttribute::READONLY, 0 },
196 { OUString("Drawing"), UNOGALLERY_DRAWING, cppu::UnoType<lang::XComponent>::get(),
197 beans::PropertyAttribute::READONLY, 0 },
199 { OUString(), 0, css::uno::Type(), 0, 0 }
202 return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo( aEntries ) );
205 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
207 const SolarMutexGuard aGuard;
209 while( *ppEntries )
211 if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
213 OUString aNewTitle;
215 if( !(*pValues >>= aNewTitle) )
217 throw lang::IllegalArgumentException();
220 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
222 if( pGalTheme )
224 std::unique_ptr<SgaObject> pObj(pGalTheme->ImplReadSgaObject( implGetObject() ));
226 if( pObj )
228 if( pObj->GetTitle() != aNewTitle )
230 pObj->SetTitle( aNewTitle );
231 pGalTheme->InsertObject( *pObj );
238 ++ppEntries;
239 ++pValues;
243 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
245 const SolarMutexGuard aGuard;
247 while( *ppEntries )
249 switch( (*ppEntries)->mnHandle )
251 case UNOGALLERY_GALLERYITEMTYPE:
253 *pValue <<= getType();
255 break;
257 case UNOGALLERY_URL:
259 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
261 if( pGalTheme )
262 *pValue <<= implGetObject()->aURL.GetMainURL( INetURLObject::DecodeMechanism::NONE );
264 break;
266 case UNOGALLERY_TITLE:
268 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
270 if( pGalTheme )
272 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
274 if( pObj )
276 *pValue <<= pObj->GetTitle();
280 break;
282 case UNOGALLERY_THUMBNAIL:
284 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
286 if( pGalTheme )
288 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
290 if( pObj )
292 Graphic aThumbnail;
294 if( pObj->IsThumbBitmap() )
295 aThumbnail = pObj->GetThumbBmp();
296 else
297 aThumbnail = pObj->GetThumbMtf();
299 *pValue <<= aThumbnail.GetXGraphic();
303 break;
305 case UNOGALLERY_GRAPHIC:
307 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
308 Graphic aGraphic;
310 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), aGraphic ) )
311 *pValue <<= aGraphic.GetXGraphic();
313 break;
315 case UNOGALLERY_DRAWING:
317 if( gallery::GalleryItemType::DRAWING == getType() )
319 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
320 FmFormModel* pModel = new FmFormModel();
322 pModel->GetItemPool().FreezeIdRanges();
324 if( pGalTheme && pGalTheme->GetModel( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), *pModel ) )
326 uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
328 pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
329 *pValue <<= xDrawing;
331 else
332 delete pModel;
335 break;
338 ++ppEntries;
339 ++pValue;
344 void GalleryItem::implSetInvalid()
346 if( mpTheme )
348 mpTheme = nullptr;
349 mpGalleryObject = nullptr;
354 GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc )
355 throw() :
356 SvxUnoDrawingModel( pDoc )
361 GalleryDrawingModel::~GalleryDrawingModel()
362 throw()
364 delete GetDoc();
368 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel );
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */