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/itemprop.hxx>
29 #include <svl/itempool.hxx>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/supportsservice.hxx>
34 #include <com/sun/star/beans/PropertyState.hpp>
35 #include <com/sun/star/beans/PropertyAttribute.hpp>
36 #include <com/sun/star/gallery/GalleryItemType.hpp>
39 #define UNOGALLERY_GALLERYITEMTYPE 1
40 #define UNOGALLERY_URL 2
41 #define UNOGALLERY_TITLE 3
42 #define UNOGALLERY_THUMBNAIL 4
43 #define UNOGALLERY_GRAPHIC 5
44 #define UNOGALLERY_DRAWING 6
46 using namespace ::com::sun::star
;
48 namespace unogallery
{
51 GalleryItem::GalleryItem( ::unogallery::GalleryTheme
& rTheme
, const GalleryObject
& rObject
) :
52 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
54 mpGalleryObject( &rObject
)
56 mpTheme
->implRegisterGalleryItem( *this );
60 GalleryItem::~GalleryItem()
64 mpTheme
->implDeregisterGalleryItem( *this );
68 bool GalleryItem::isValid() const
70 return( mpTheme
!= nullptr );
74 uno::Any SAL_CALL
GalleryItem::queryAggregation( const uno::Type
& rType
)
78 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
79 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
80 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
81 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
82 else if( rType
== cppu::UnoType
<gallery::XGalleryItem
>::get())
83 aAny
<<= uno::Reference
< gallery::XGalleryItem
>(this);
84 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
85 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
86 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
87 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
88 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
89 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
91 aAny
= OWeakAggObject::queryAggregation( rType
);
97 uno::Any SAL_CALL
GalleryItem::queryInterface( const uno::Type
& rType
)
99 return OWeakAggObject::queryInterface( rType
);
103 void SAL_CALL
GalleryItem::acquire()
106 OWeakAggObject::acquire();
110 void SAL_CALL
GalleryItem::release()
113 OWeakAggObject::release();
117 OUString SAL_CALL
GalleryItem::getImplementationName()
119 return "com.sun.star.comp.gallery.GalleryItem";
122 sal_Bool SAL_CALL
GalleryItem::supportsService( const OUString
& ServiceName
)
124 return cppu::supportsService(this, ServiceName
);
127 uno::Sequence
< OUString
> SAL_CALL
GalleryItem::getSupportedServiceNames()
129 return { "com.sun.star.gallery.GalleryItem" };
132 uno::Sequence
< uno::Type
> SAL_CALL
GalleryItem::getTypes()
134 static const uno::Sequence aTypes
{
135 cppu::UnoType
<lang::XServiceInfo
>::get(),
136 cppu::UnoType
<lang::XTypeProvider
>::get(),
137 cppu::UnoType
<gallery::XGalleryItem
>::get(),
138 cppu::UnoType
<beans::XPropertySet
>::get(),
139 cppu::UnoType
<beans::XPropertyState
>::get(),
140 cppu::UnoType
<beans::XMultiPropertySet
>::get() };
144 uno::Sequence
< sal_Int8
> SAL_CALL
GalleryItem::getImplementationId()
146 return css::uno::Sequence
<sal_Int8
>();
150 sal_Int8 SAL_CALL
GalleryItem::getType()
152 const SolarMutexGuard aGuard
;
153 sal_Int8 nRet
= gallery::GalleryItemType::EMPTY
;
157 switch( implGetObject()->eObjKind
)
159 case SgaObjKind::Sound
:
160 nRet
= gallery::GalleryItemType::MEDIA
;
163 case SgaObjKind::SvDraw
:
164 nRet
= gallery::GalleryItemType::DRAWING
;
168 nRet
= gallery::GalleryItemType::GRAPHIC
;
177 rtl::Reference
<::comphelper::PropertySetInfo
> GalleryItem::createPropertySetInfo()
179 static ::comphelper::PropertyMapEntry
const aEntries
[] =
181 { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE
, cppu::UnoType
<sal_Int8
>::get(),
182 beans::PropertyAttribute::READONLY
, 0 },
184 { OUString("URL"), UNOGALLERY_URL
, ::cppu::UnoType
<OUString
>::get(),
185 beans::PropertyAttribute::READONLY
, 0 },
187 { OUString("Title"), UNOGALLERY_TITLE
, ::cppu::UnoType
<OUString
>::get(),
190 { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL
, cppu::UnoType
<graphic::XGraphic
>::get(),
191 beans::PropertyAttribute::READONLY
, 0 },
193 { OUString("Graphic"), UNOGALLERY_GRAPHIC
, cppu::UnoType
<graphic::XGraphic
>::get(),
194 beans::PropertyAttribute::READONLY
, 0 },
196 { OUString("Drawing"), UNOGALLERY_DRAWING
, cppu::UnoType
<lang::XComponent
>::get(),
197 beans::PropertyAttribute::READONLY
, 0 },
199 { OUString(), 0, css::uno::Type(), 0, 0 }
202 return rtl::Reference
<::comphelper::PropertySetInfo
>( new ::comphelper::PropertySetInfo( aEntries
) );
205 void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
207 const SolarMutexGuard aGuard
;
211 if( UNOGALLERY_TITLE
== (*ppEntries
)->mnHandle
)
215 if( !(*pValues
>>= aNewTitle
) )
217 throw lang::IllegalArgumentException();
220 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
224 std::unique_ptr
<SgaObject
> pObj(pGalTheme
->ImplReadSgaObject( implGetObject() ));
228 if( pObj
->GetTitle() != aNewTitle
)
230 pObj
->SetTitle( aNewTitle
);
231 pGalTheme
->InsertObject( *pObj
);
243 void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValue
)
245 const SolarMutexGuard aGuard
;
249 switch( (*ppEntries
)->mnHandle
)
251 case UNOGALLERY_GALLERYITEMTYPE
:
253 *pValue
<<= getType();
259 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
262 *pValue
<<= implGetObject()->aURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
);
266 case UNOGALLERY_TITLE
:
268 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
272 std::unique_ptr
<SgaObject
> pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
276 *pValue
<<= pObj
->GetTitle();
282 case UNOGALLERY_THUMBNAIL
:
284 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
288 std::unique_ptr
<SgaObject
> pObj
= pGalTheme
->AcquireObject( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ) );
294 if( pObj
->IsThumbBitmap() )
295 aThumbnail
= pObj
->GetThumbBmp();
297 aThumbnail
= pObj
->GetThumbMtf();
299 *pValue
<<= aThumbnail
.GetXGraphic();
305 case UNOGALLERY_GRAPHIC
:
307 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
310 if( pGalTheme
&& pGalTheme
->GetGraphic( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), aGraphic
) )
311 *pValue
<<= aGraphic
.GetXGraphic();
315 case UNOGALLERY_DRAWING
:
317 if( gallery::GalleryItemType::DRAWING
== getType() )
319 ::GalleryTheme
* pGalTheme
= ( isValid() ? mpTheme
->implGetTheme() : nullptr );
320 FmFormModel
* pModel
= new FmFormModel();
322 pModel
->GetItemPool().FreezeIdRanges();
324 if( pGalTheme
&& pGalTheme
->GetModel( pGalTheme
->ImplGetGalleryObjectPos( implGetObject() ), *pModel
) )
326 uno::Reference
< lang::XComponent
> xDrawing( new GalleryDrawingModel( pModel
) );
328 pModel
->setUnoModel( uno::Reference
< uno::XInterface
>::query( xDrawing
) );
329 *pValue
<<= xDrawing
;
344 void GalleryItem::implSetInvalid()
349 mpGalleryObject
= nullptr;
354 GalleryDrawingModel::GalleryDrawingModel( SdrModel
* pDoc
)
356 SvxUnoDrawingModel( pDoc
)
361 GalleryDrawingModel::~GalleryDrawingModel()
368 UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel
);
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */