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