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 <galleryfilestorage.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>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/supportsservice.hxx>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/gallery/GalleryItemType.hpp>
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
45 using namespace ::com::sun::star
;
47 namespace unogallery
{
50 GalleryItem::GalleryItem( ::unogallery::GalleryTheme
& rTheme
, const GalleryObject
& rObject
) :
51 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
53 mpGalleryObject( &rObject
)
55 mpTheme
->implRegisterGalleryItem( *this );
59 GalleryItem::~GalleryItem()
63 mpTheme
->implDeregisterGalleryItem( *this );
67 bool GalleryItem::isValid() const
69 return( mpTheme
!= nullptr );
73 uno::Any SAL_CALL
GalleryItem::queryAggregation( const uno::Type
& rType
)
77 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
78 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
79 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
80 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
81 else if( rType
== cppu::UnoType
<gallery::XGalleryItem
>::get())
82 aAny
<<= uno::Reference
< gallery::XGalleryItem
>(this);
83 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
84 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
85 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
86 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
87 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
88 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
90 aAny
= OWeakAggObject::queryAggregation( rType
);
96 uno::Any SAL_CALL
GalleryItem::queryInterface( const uno::Type
& rType
)
98 return OWeakAggObject::queryInterface( rType
);
102 void SAL_CALL
GalleryItem::acquire()
105 OWeakAggObject::acquire();
109 void SAL_CALL
GalleryItem::release()
112 OWeakAggObject::release();
116 OUString SAL_CALL
GalleryItem::getImplementationName()
118 return "com.sun.star.comp.gallery.GalleryItem";
121 sal_Bool SAL_CALL
GalleryItem::supportsService( const OUString
& ServiceName
)
123 return cppu::supportsService(this, ServiceName
);
126 uno::Sequence
< OUString
> SAL_CALL
GalleryItem::getSupportedServiceNames()
128 return { "com.sun.star.gallery.GalleryItem" };
131 uno::Sequence
< uno::Type
> SAL_CALL
GalleryItem::getTypes()
133 static const uno::Sequence aTypes
{
134 cppu::UnoType
<lang::XServiceInfo
>::get(),
135 cppu::UnoType
<lang::XTypeProvider
>::get(),
136 cppu::UnoType
<gallery::XGalleryItem
>::get(),
137 cppu::UnoType
<beans::XPropertySet
>::get(),
138 cppu::UnoType
<beans::XPropertyState
>::get(),
139 cppu::UnoType
<beans::XMultiPropertySet
>::get() };
143 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryItem::getImplementationId()
145 return css::uno::Sequence
<sal_Int8
>();
149 sal_Int8 SAL_CALL
GalleryItem::getType()
151 const SolarMutexGuard aGuard
;
152 sal_Int8 nRet
= gallery::GalleryItemType::EMPTY
;
156 switch( implGetObject()->eObjKind
)
158 case SgaObjKind::Sound
:
159 nRet
= gallery::GalleryItemType::MEDIA
;
162 case SgaObjKind::SvDraw
:
163 nRet
= gallery::GalleryItemType::DRAWING
;
167 nRet
= gallery::GalleryItemType::GRAPHIC
;
176 rtl::Reference
<::comphelper::PropertySetInfo
> GalleryItem::createPropertySetInfo()
178 static ::comphelper::PropertyMapEntry
const aEntries
[] =
180 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE
, cppu::UnoType
<sal_Int8
>::get(),
181 beans::PropertyAttribute::READONLY
, 0 },
183 { OUString("URL"), UNOGALLERY_URL
, ::cppu::UnoType
<OUString
>::get(),
184 beans::PropertyAttribute::READONLY
, 0 },
186 { OUString("Title"), UNOGALLERY_TITLE
, ::cppu::UnoType
<OUString
>::get(),
189 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL
, cppu::UnoType
<graphic::XGraphic
>::get(),
190 beans::PropertyAttribute::READONLY
, 0 },
192 { OUString("Graphic"), UNOGALLERY_GRAPHIC
, cppu::UnoType
<graphic::XGraphic
>::get(),
193 beans::PropertyAttribute::READONLY
, 0 },
195 { OUString("Drawing"), UNOGALLERY_DRAWING
, cppu::UnoType
<lang::XComponent
>::get(),
196 beans::PropertyAttribute::READONLY
, 0 },
199 return rtl::Reference
<::comphelper::PropertySetInfo
>( new ::comphelper::PropertySetInfo( aEntries
) );
202 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
204 const SolarMutexGuard aGuard
;
208 if( UNOGALLERY_TITLE
== (*ppEntries
)->mnHandle
)
212 if( !(*pValues
>>= aNewTitle
) )
214 throw lang::IllegalArgumentException();
217 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
221 std::unique_ptr
<SgaObject
> pObj(pGalTheme
->getGalleryStorageEngine()->implReadSgaObject( implGetObject() ));
225 if( pObj
->GetTitle() != aNewTitle
)
227 pObj
->SetTitle( aNewTitle
);
228 pGalTheme
->InsertObject( *pObj
);
240 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
242 const SolarMutexGuard aGuard
;
246 switch( (*ppEntries
)->mnHandle
)
248 case UNOGALLERY_GALLERYITEMTYPE
:
250 *pValue
<<= getType();
256 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
259 *pValue
<<= implGetObject()->m_oStorageUrl
->GetMainURL( INetURLObject::DecodeMechanism::NONE
);
263 case UNOGALLERY_TITLE
:
265 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
269 std::unique_ptr
<SgaObject
> pObj
= pGalTheme
->AcquireObject( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ) );
273 *pValue
<<= pObj
->GetTitle();
279 case UNOGALLERY_THUMBNAIL
:
281 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
285 std::unique_ptr
<SgaObject
> pObj
= pGalTheme
->AcquireObject( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ) );
291 if( pObj
->IsThumbBitmap() )
292 aThumbnail
= pObj
->GetThumbBmp();
294 aThumbnail
= pObj
->GetThumbMtf();
296 *pValue
<<= aThumbnail
.GetXGraphic();
302 case UNOGALLERY_GRAPHIC
:
304 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
307 if( pGalTheme
&& pGalTheme
->GetGraphic( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ), aGraphic
) )
308 *pValue
<<= aGraphic
.GetXGraphic();
312 case UNOGALLERY_DRAWING
:
314 if( gallery::GalleryItemType::DRAWING
== getType() )
316 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
317 FmFormModel
* pModel
= new FmFormModel();
319 pModel
->GetItemPool().FreezeIdRanges();
321 if( pGalTheme
&& pGalTheme
->GetModel( pGalTheme
->maGalleryObjectCollection
.searchPosWithObject( implGetObject() ), *pModel
) )
323 uno::Reference
< lang::XComponent
> xDrawing( new GalleryDrawingModel( pModel
) );
325 pModel
->setUnoModel( uno::Reference
< uno::XInterface
>::query( xDrawing
) );
326 *pValue
<<= xDrawing
;
341 void GalleryItem::implSetInvalid()
346 mpGalleryObject
= nullptr;
351 GalleryDrawingModel::GalleryDrawingModel( SdrModel
* pDoc
)
353 SvxUnoDrawingModel( pDoc
)
358 GalleryDrawingModel::~GalleryDrawingModel()
365 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel
);
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */