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