1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/itempool.hxx>
29 #include <comphelper/servicehelper.hxx>
30 #include <cppuhelper/supportsservice.hxx>
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/gallery/GalleryItemType.hpp>
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
44 using namespace ::com::sun::star
;
46 namespace unogallery
{
49 GalleryItem::GalleryItem( ::unogallery::GalleryTheme
& rTheme
, const GalleryObject
& rObject
) :
50 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
52 mpGalleryObject( &rObject
)
54 mpTheme
->implRegisterGalleryItem( *this );
58 GalleryItem::~GalleryItem()
62 mpTheme
->implDeregisterGalleryItem( *this );
66 bool GalleryItem::isValid() const
68 return( mpTheme
!= nullptr );
72 uno::Any SAL_CALL
GalleryItem::queryAggregation( const uno::Type
& rType
)
76 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
77 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
78 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
79 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
80 else if( rType
== cppu::UnoType
<gallery::XGalleryItem
>::get())
81 aAny
<<= uno::Reference
< gallery::XGalleryItem
>(this);
82 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
83 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
84 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
85 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
86 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
87 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
89 aAny
= OWeakAggObject::queryAggregation( rType
);
95 uno::Any SAL_CALL
GalleryItem::queryInterface( const uno::Type
& rType
)
97 return OWeakAggObject::queryInterface( rType
);
101 void SAL_CALL
GalleryItem::acquire()
104 OWeakAggObject::acquire();
108 void SAL_CALL
GalleryItem::release()
111 OWeakAggObject::release();
115 OUString SAL_CALL
GalleryItem::getImplementationName()
117 return "com.sun.star.comp.gallery.GalleryItem";
120 sal_Bool SAL_CALL
GalleryItem::supportsService( const OUString
& ServiceName
)
122 return cppu::supportsService(this, ServiceName
);
125 uno::Sequence
< OUString
> SAL_CALL
GalleryItem::getSupportedServiceNames()
127 return { "com.sun.star.gallery.GalleryItem" };
130 uno::Sequence
< uno::Type
> SAL_CALL
GalleryItem::getTypes()
132 static const uno::Sequence aTypes
{
133 cppu::UnoType
<lang::XServiceInfo
>::get(),
134 cppu::UnoType
<lang::XTypeProvider
>::get(),
135 cppu::UnoType
<gallery::XGalleryItem
>::get(),
136 cppu::UnoType
<beans::XPropertySet
>::get(),
137 cppu::UnoType
<beans::XPropertyState
>::get(),
138 cppu::UnoType
<beans::XMultiPropertySet
>::get() };
142 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryItem::getImplementationId()
144 return css::uno::Sequence
<sal_Int8
>();
148 sal_Int8 SAL_CALL
GalleryItem::getType()
150 const SolarMutexGuard aGuard
;
151 sal_Int8 nRet
= gallery::GalleryItemType::EMPTY
;
155 switch( implGetObject()->eObjKind
)
157 case SgaObjKind::Sound
:
158 nRet
= gallery::GalleryItemType::MEDIA
;
161 case SgaObjKind::SvDraw
:
162 nRet
= gallery::GalleryItemType::DRAWING
;
166 nRet
= gallery::GalleryItemType::GRAPHIC
;
175 rtl::Reference
<::comphelper::PropertySetInfo
> GalleryItem::createPropertySetInfo()
177 static ::comphelper::PropertyMapEntry
const aEntries
[] =
179 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE
, cppu::UnoType
<sal_Int8
>::get(),
180 beans::PropertyAttribute::READONLY
, 0 },
182 { OUString("URL"), UNOGALLERY_URL
, ::cppu::UnoType
<OUString
>::get(),
183 beans::PropertyAttribute::READONLY
, 0 },
185 { OUString("Title"), UNOGALLERY_TITLE
, ::cppu::UnoType
<OUString
>::get(),
188 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL
, cppu::UnoType
<graphic::XGraphic
>::get(),
189 beans::PropertyAttribute::READONLY
, 0 },
191 { OUString("Graphic"), UNOGALLERY_GRAPHIC
, cppu::UnoType
<graphic::XGraphic
>::get(),
192 beans::PropertyAttribute::READONLY
, 0 },
194 { OUString("Drawing"), UNOGALLERY_DRAWING
, cppu::UnoType
<lang::XComponent
>::get(),
195 beans::PropertyAttribute::READONLY
, 0 },
197 { OUString(), 0, css::uno::Type(), 0, 0 }
200 return rtl::Reference
<::comphelper::PropertySetInfo
>( new ::comphelper::PropertySetInfo( aEntries
) );
203 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
205 const SolarMutexGuard aGuard
;
209 if( UNOGALLERY_TITLE
== (*ppEntries
)->mnHandle
)
213 if( !(*pValues
>>= aNewTitle
) )
215 throw lang::IllegalArgumentException();
218 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
222 std::unique_ptr
<SgaObject
> pObj(pGalTheme
->getGalleryStorageEngine()->implReadSgaObject( implGetObject() ));
226 if( pObj
->GetTitle() != aNewTitle
)
228 pObj
->SetTitle( aNewTitle
);
229 pGalTheme
->InsertObject( *pObj
);
241 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
243 const SolarMutexGuard aGuard
;
247 switch( (*ppEntries
)->mnHandle
)
249 case UNOGALLERY_GALLERYITEMTYPE
:
251 *pValue
<<= getType();
257 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
260 *pValue
<<= implGetObject()->getURL().GetMainURL( INetURLObject::DecodeMechanism::NONE
);
264 case UNOGALLERY_TITLE
:
266 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
270 std::unique_ptr
<SgaObject
> pObj
= pGalTheme
->AcquireObject( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ) );
274 *pValue
<<= pObj
->GetTitle();
280 case UNOGALLERY_THUMBNAIL
:
282 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
286 std::unique_ptr
<SgaObject
> pObj
= pGalTheme
->AcquireObject( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ) );
292 if( pObj
->IsThumbBitmap() )
293 aThumbnail
= pObj
->GetThumbBmp();
295 aThumbnail
= pObj
->GetThumbMtf();
297 *pValue
<<= aThumbnail
.GetXGraphic();
303 case UNOGALLERY_GRAPHIC
:
305 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
308 if( pGalTheme
&& pGalTheme
->GetGraphic( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ), aGraphic
) )
309 *pValue
<<= aGraphic
.GetXGraphic();
313 case UNOGALLERY_DRAWING
:
315 if( gallery::GalleryItemType::DRAWING
== getType() )
317 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
318 FmFormModel
* pModel
= new FmFormModel();
320 pModel
->GetItemPool().FreezeIdRanges();
322 if( pGalTheme
&& pGalTheme
->GetModel( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ), *pModel
) )
324 uno::Reference
< lang::XComponent
> xDrawing( new GalleryDrawingModel( pModel
) );
326 pModel
->setUnoModel( uno::Reference
< uno::XInterface
>::query( xDrawing
) );
327 *pValue
<<= xDrawing
;
342 void GalleryItem::implSetInvalid()
347 mpGalleryObject
= nullptr;
352 GalleryDrawingModel::GalleryDrawingModel( SdrModel
* pDoc
)
354 SvxUnoDrawingModel( pDoc
)
359 GalleryDrawingModel::~GalleryDrawingModel()
366 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel
);
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */