LibreOffice Module svx (master) 1
unogalitem.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include "unogalitem.hxx"
22#include "unogaltheme.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>
32#include <galobj.hxx>
33
34#include <com/sun/star/beans/PropertyAttribute.hpp>
35#include <com/sun/star/gallery/GalleryItemType.hpp>
36#include <memory>
37
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
44
45using namespace ::com::sun::star;
46
47namespace unogallery {
48
49
51 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
52 mpTheme( &rTheme ),
53 mpGalleryObject( &rObject )
54{
56}
57
58
60 noexcept
61{
62 if( mpTheme )
64}
65
66
68{
69 return( mpTheme != nullptr );
70}
71
72
74{
75 uno::Any aAny;
76
78 aAny <<= uno::Reference< lang::XServiceInfo >(this);
80 aAny <<= uno::Reference< lang::XTypeProvider >(this);
82 aAny <<= uno::Reference< gallery::XGalleryItem >(this);
84 aAny <<= uno::Reference< beans::XPropertySet >(this);
86 aAny <<= uno::Reference< beans::XPropertyState >(this);
88 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
89 else
90 aAny = OWeakAggObject::queryAggregation( rType );
91
92 return aAny;
93}
94
95
97{
98 return OWeakAggObject::queryInterface( rType );
99}
100
101
102void SAL_CALL GalleryItem::acquire()
103 noexcept
104{
105 OWeakAggObject::acquire();
106}
107
108
109void SAL_CALL GalleryItem::release()
110 noexcept
111{
112 OWeakAggObject::release();
113}
114
115
117{
118 return "com.sun.star.comp.gallery.GalleryItem";
119}
120
121sal_Bool SAL_CALL GalleryItem::supportsService( const OUString& ServiceName )
122{
124}
125
126uno::Sequence< OUString > SAL_CALL GalleryItem::getSupportedServiceNames()
127{
128 return { "com.sun.star.gallery.GalleryItem" };
129}
130
131uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes()
132{
133 static const uno::Sequence aTypes {
140 return aTypes;
141}
142
143uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId()
144{
145 return css::uno::Sequence<sal_Int8>();
146}
147
148
150{
151 const SolarMutexGuard aGuard;
153
154 if( isValid() )
155 {
156 switch( implGetObject()->eObjKind )
157 {
159 nRet = gallery::GalleryItemType::MEDIA;
160 break;
161
163 nRet = gallery::GalleryItemType::DRAWING;
164 break;
165
166 default:
167 nRet = gallery::GalleryItemType::GRAPHIC;
168 break;
169 }
170 }
171
172 return nRet;
173}
174
175
177{
179 {
180 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE, cppu::UnoType<sal_Int8>::get(),
181 beans::PropertyAttribute::READONLY, 0 },
182
184 beans::PropertyAttribute::READONLY, 0 },
185
186 { OUString("Title"), UNOGALLERY_TITLE, ::cppu::UnoType<OUString>::get(),
187 0, 0 },
188
190 beans::PropertyAttribute::READONLY, 0 },
191
193 beans::PropertyAttribute::READONLY, 0 },
194
196 beans::PropertyAttribute::READONLY, 0 },
197 };
198
199 return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo( aEntries ) );
200}
201
203{
204 const SolarMutexGuard aGuard;
205
206 while( *ppEntries )
207 {
208 if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
209 {
210 OUString aNewTitle;
211
212 if( !(*pValues >>= aNewTitle) )
213 {
214 throw lang::IllegalArgumentException();
215 }
216
217 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
218
219 if( pGalTheme )
220 {
221 std::unique_ptr<SgaObject> pObj(pGalTheme->getGalleryStorageEngine()->implReadSgaObject( implGetObject() ));
222
223 if( pObj )
224 {
225 if( pObj->GetTitle() != aNewTitle )
226 {
227 pObj->SetTitle( aNewTitle );
228 pGalTheme->InsertObject( *pObj );
229 }
230 }
231 }
232
233 }
234
235 ++ppEntries;
236 ++pValues;
237 }
238}
239
241{
242 const SolarMutexGuard aGuard;
243
244 while( *ppEntries )
245 {
246 switch( (*ppEntries)->mnHandle )
247 {
249 {
250 *pValue <<= getType();
251 }
252 break;
253
254 case UNOGALLERY_URL:
255 {
256 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
257
258 if( pGalTheme )
260 }
261 break;
262
263 case UNOGALLERY_TITLE:
264 {
265 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
266
267 if( pGalTheme )
268 {
269 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
270
271 if( pObj )
272 {
273 *pValue <<= pObj->GetTitle();
274 }
275 }
276 }
277 break;
278
280 {
281 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
282
283 if( pGalTheme )
284 {
285 std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
286
287 if( pObj )
288 {
289 Graphic aThumbnail;
290
291 if( pObj->IsThumbBitmap() )
292 aThumbnail = pObj->GetThumbBmp();
293 else
294 aThumbnail = pObj->GetThumbMtf();
295
296 *pValue <<= aThumbnail.GetXGraphic();
297 }
298 }
299 }
300 break;
301
303 {
304 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
305 Graphic aGraphic;
306
307 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), aGraphic ) )
308 *pValue <<= aGraphic.GetXGraphic();
309 }
310 break;
311
313 {
314 if( gallery::GalleryItemType::DRAWING == getType() )
315 {
316 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
317 FmFormModel* pModel = new FmFormModel();
318
319 pModel->GetItemPool().FreezeIdRanges();
320
321 if( pGalTheme && pGalTheme->GetModel( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), *pModel ) )
322 {
323 uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
324
325 pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
326 *pValue <<= xDrawing;
327 }
328 else
329 delete pModel;
330 }
331 }
332 break;
333 }
334
335 ++ppEntries;
336 ++pValue;
337 }
338}
339
340
342{
343 if( mpTheme )
344 {
345 mpTheme = nullptr;
346 mpGalleryObject = nullptr;
347 }
348}
349
350
352 noexcept :
353 SvxUnoDrawingModel( pDoc )
354{
355}
356
357
359 noexcept
360{
361 delete GetDoc();
362}
363
364
366
367}
368
369/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
sal_uInt32 searchPosWithObject(const GalleryObject *pObj)
GalleryObjectCollection maGalleryObjectCollection
Definition: galtheme.hxx:61
bool GetGraphic(sal_uInt32 nPos, Graphic &rGraphic)
Definition: galtheme.cxx:311
bool InsertObject(const SgaObject &rObj, sal_uInt32 nPos=SAL_MAX_UINT32)
Definition: galtheme.cxx:118
const std::unique_ptr< GalleryFileStorage > & getGalleryStorageEngine() const
Definition: galtheme.hxx:70
std::unique_ptr< SgaObject > AcquireObject(sal_uInt32 nPos)
Definition: galtheme.cxx:142
bool GetModel(sal_uInt32 nPos, SdrModel &rModel)
Definition: galtheme.cxx:437
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
const SfxItemPool & GetItemPool() const
Definition: svdmodel.hxx:318
void setUnoModel(const css::uno::Reference< css::uno::XInterface > &xModel)
Definition: svdmodel.cxx:1583
void FreezeIdRanges()
SdrModel * GetDoc() const
Definition: unomodel.hxx:66
css::uno::Type const & get()
GalleryDrawingModel(SdrModel *pDoc) noexcept
Definition: unogalitem.cxx:351
virtual ~GalleryDrawingModel() noexcept override
Definition: unogalitem.cxx:358
virtual ~GalleryItem() noexcept override
Definition: unogalitem.cxx:59
virtual ::sal_Int8 SAL_CALL getType() override
Definition: unogalitem.cxx:149
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
Definition: unogalitem.cxx:73
virtual void _setPropertyValues(const comphelper::PropertyMapEntry **ppEntries, const css::uno::Any *pValues) override
Definition: unogalitem.cxx:202
virtual OUString SAL_CALL getImplementationName() override
Definition: unogalitem.cxx:116
virtual void SAL_CALL acquire() noexcept override
Definition: unogalitem.cxx:102
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unogalitem.cxx:121
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: unogalitem.cxx:131
const ::GalleryObject * implGetObject() const
Definition: unogalitem.hxx:79
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unogalitem.cxx:126
virtual void _getPropertyValues(const comphelper::PropertyMapEntry **ppEntries, css::uno::Any *pValue) override
Definition: unogalitem.cxx:240
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: unogalitem.cxx:143
virtual void SAL_CALL release() noexcept override
Definition: unogalitem.cxx:109
static rtl::Reference<::comphelper::PropertySetInfo > createPropertySetInfo()
Definition: unogalitem.cxx:176
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: unogalitem.cxx:96
const ::GalleryObject * mpGalleryObject
Definition: unogalitem.hxx:86
::unogallery::GalleryTheme * mpTheme
Definition: unogalitem.hxx:85
GalleryItem(::unogallery::GalleryTheme &rTheme, const GalleryObject &rObject)
Definition: unogalitem.cxx:50
void implRegisterGalleryItem(::unogallery::GalleryItem &rItem)
::GalleryTheme * implGetTheme() const
Definition: unogaltheme.hxx:88
void implDeregisterGalleryItem(::unogallery::GalleryItem &rItem)
ScXMLEditAttributeMap::Entry const aEntries[]
class SvxPropertySetInfoPool
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral EMPTY
std::pair< OUString const, DataAccessDescriptorProperty > PropertyMapEntry
UNO3_GETIMPLEMENTATION_IMPL(GalleryDrawingModel)
std::optional< INetURLObject > m_oStorageUrl
unsigned char sal_Bool
signed char sal_Int8
#define UNOGALLERY_GALLERYITEMTYPE
Definition: unogalitem.cxx:38
#define UNOGALLERY_GRAPHIC
Definition: unogalitem.cxx:42
#define UNOGALLERY_URL
Definition: unogalitem.cxx:39
#define UNOGALLERY_DRAWING
Definition: unogalitem.cxx:43
#define UNOGALLERY_THUMBNAIL
Definition: unogalitem.cxx:41
#define UNOGALLERY_TITLE
Definition: unogalitem.cxx:40
const SvXMLTokenMapEntry aTypes[]