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;
151  sal_Int8 nRet = gallery::GalleryItemType::EMPTY;
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  { OUString(), 0, css::uno::Type(), 0, 0 }
198  };
199 
200  return rtl::Reference<::comphelper::PropertySetInfo>( new ::comphelper::PropertySetInfo( aEntries ) );
201 }
202 
204 {
205  const SolarMutexGuard aGuard;
206 
207  while( *ppEntries )
208  {
209  if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
210  {
211  OUString aNewTitle;
212 
213  if( !(*pValues >>= aNewTitle) )
214  {
215  throw lang::IllegalArgumentException();
216  }
217 
218  ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
219 
220  if( pGalTheme )
221  {
222  std::unique_ptr<SgaObject> pObj(pGalTheme->getGalleryStorageEngine()->implReadSgaObject( implGetObject() ));
223 
224  if( pObj )
225  {
226  if( pObj->GetTitle() != aNewTitle )
227  {
228  pObj->SetTitle( aNewTitle );
229  pGalTheme->InsertObject( *pObj );
230  }
231  }
232  }
233 
234  }
235 
236  ++ppEntries;
237  ++pValues;
238  }
239 }
240 
242 {
243  const SolarMutexGuard aGuard;
244 
245  while( *ppEntries )
246  {
247  switch( (*ppEntries)->mnHandle )
248  {
250  {
251  *pValue <<= getType();
252  }
253  break;
254 
255  case UNOGALLERY_URL:
256  {
257  ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
258 
259  if( pGalTheme )
261  }
262  break;
263 
264  case UNOGALLERY_TITLE:
265  {
266  ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
267 
268  if( pGalTheme )
269  {
270  std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
271 
272  if( pObj )
273  {
274  *pValue <<= pObj->GetTitle();
275  }
276  }
277  }
278  break;
279 
281  {
282  ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
283 
284  if( pGalTheme )
285  {
286  std::unique_ptr<SgaObject> pObj = pGalTheme->AcquireObject( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ) );
287 
288  if( pObj )
289  {
290  Graphic aThumbnail;
291 
292  if( pObj->IsThumbBitmap() )
293  aThumbnail = pObj->GetThumbBmp();
294  else
295  aThumbnail = pObj->GetThumbMtf();
296 
297  *pValue <<= aThumbnail.GetXGraphic();
298  }
299  }
300  }
301  break;
302 
303  case UNOGALLERY_GRAPHIC:
304  {
305  ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
306  Graphic aGraphic;
307 
308  if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), aGraphic ) )
309  *pValue <<= aGraphic.GetXGraphic();
310  }
311  break;
312 
313  case UNOGALLERY_DRAWING:
314  {
315  if( gallery::GalleryItemType::DRAWING == getType() )
316  {
317  ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : nullptr );
318  FmFormModel* pModel = new FmFormModel();
319 
320  pModel->GetItemPool().FreezeIdRanges();
321 
322  if( pGalTheme && pGalTheme->GetModel( pGalTheme->maGalleryObjectCollection.searchPosWithObject( implGetObject() ), *pModel ) )
323  {
324  uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
325 
326  pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
327  *pValue <<= xDrawing;
328  }
329  else
330  delete pModel;
331  }
332  }
333  break;
334  }
335 
336  ++ppEntries;
337  ++pValue;
338  }
339 }
340 
341 
343 {
344  if( mpTheme )
345  {
346  mpTheme = nullptr;
347  mpGalleryObject = nullptr;
348  }
349 }
350 
351 
353  noexcept :
354  SvxUnoDrawingModel( pDoc )
355 {
356 }
357 
358 
360  noexcept
361 {
362  delete GetDoc();
363 }
364 
365 
367 
368 }
369 
370 /* 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()
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
GalleryDrawingModel(SdrModel *pDoc) noexcept
Definition: unogalitem.cxx:352
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:1597
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
#define UNOGALLERY_DRAWING
Definition: unogalitem.cxx:42
virtual ~GalleryDrawingModel() noexcept override
Definition: unogalitem.cxx:359
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:203
#define UNOGALLERY_TITLE
Definition: unogalitem.cxx:39
GalleryItem(::unogallery::GalleryTheme &rTheme, const GalleryObject &rObject)
Definition: unogalitem.cxx:49
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:309
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:241