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 .
20 #include <svx/galleryitem.hxx>
21 #include <com/sun/star/gallery/GalleryItemType.hpp>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/uno/Sequence.hxx>
26 TYPEINIT1_AUTOFACTORY( SvxGalleryItem
, SfxPoolItem
);
28 SvxGalleryItem::SvxGalleryItem()
29 : m_nType( css::gallery::GalleryItemType::EMPTY
)
33 SvxGalleryItem::SvxGalleryItem( const SvxGalleryItem
&rItem
)
34 : SfxPoolItem( rItem
)
35 , m_nType( rItem
.m_nType
)
36 , m_aURL( rItem
.m_aURL
)
37 , m_xDrawing( rItem
.m_xDrawing
)
38 , m_xGraphic( rItem
.m_xGraphic
)
42 SvxGalleryItem::~SvxGalleryItem()
46 bool SvxGalleryItem::QueryValue( css::uno::Any
& rVal
, sal_uInt8
/* nMemberId */ ) const
48 css::uno::Sequence
< css::beans::PropertyValue
> aSeq( SVXGALLERYITEM_PARAMS
);
50 aSeq
[0].Name
= SVXGALLERYITEM_TYPE
;
51 aSeq
[0].Value
<<= m_nType
;
52 aSeq
[1].Name
= SVXGALLERYITEM_URL
;
53 aSeq
[1].Value
<<= m_aURL
;
54 aSeq
[2].Name
= SVXGALLERYITEM_FILTER
;
55 aSeq
[2].Value
<<= m_aURL
;
56 aSeq
[3].Name
= SVXGALLERYITEM_DRAWING
;
57 aSeq
[3].Value
<<= m_xDrawing
;
58 aSeq
[4].Name
= SVXGALLERYITEM_GRAPHIC
;
59 aSeq
[4].Value
<<= m_xGraphic
;
66 bool SvxGalleryItem::PutValue( const css::uno::Any
& rVal
, sal_uInt8
/* nMemberId */)
68 css::uno::Sequence
< css::beans::PropertyValue
> aSeq
;
70 if ( !( rVal
>>= aSeq
) || ( aSeq
.getLength() < SVXGALLERYITEM_PARAMS
) )
74 bool bAllConverted( true );
77 rtl::OUString aURL
, aFilterName
;
78 css::uno::Reference
< css::lang::XComponent
> xDrawing
;
79 css::uno::Reference
< css::graphic::XGraphic
> xGraphic
;
81 const css::beans::PropertyValue
*pProp
= aSeq
.getConstArray();
82 const css::beans::PropertyValue
*pEnd
= pProp
+ aSeq
.getLength();
83 for ( ; pProp
!= pEnd
; pProp
++ )
85 if ( pProp
->Name
== SVXGALLERYITEM_TYPE
)
87 bAllConverted
&= ( pProp
->Value
>>= nType
);
90 else if ( pProp
->Name
== SVXGALLERYITEM_URL
)
92 bAllConverted
&= ( pProp
->Value
>>= aURL
);
95 else if ( pProp
->Name
== SVXGALLERYITEM_FILTER
)
97 bAllConverted
&= ( pProp
->Value
>>= aFilterName
);
100 else if ( pProp
->Name
== SVXGALLERYITEM_DRAWING
)
102 bAllConverted
&= ( pProp
->Value
>>= xDrawing
);
105 else if ( pProp
->Name
== SVXGALLERYITEM_GRAPHIC
)
107 bAllConverted
&= ( pProp
->Value
>>= xGraphic
);
112 if ( !bAllConverted
|| nConverted
!= SVXGALLERYITEM_PARAMS
)
117 m_aFilterName
= aFilterName
;
118 m_xDrawing
= xDrawing
;
119 m_xGraphic
= xGraphic
;
124 bool SvxGalleryItem::operator==( const SfxPoolItem
& rAttr
) const
126 DBG_ASSERT( SfxPoolItem::operator==(rAttr
), "unequal types" );
128 const SvxGalleryItem
& rItem
= static_cast<const SvxGalleryItem
&>(rAttr
);
130 return m_nType
== rItem
.m_nType
&&
131 m_aURL
== rItem
.m_aURL
&&
132 m_xDrawing
== rItem
.m_xDrawing
&&
133 m_xGraphic
== rItem
.m_xGraphic
;
136 SfxPoolItem
* SvxGalleryItem::Clone( SfxItemPool
* ) const
138 return new SvxGalleryItem( *this );
141 SvStream
& SvxGalleryItem::Store( SvStream
& rStream
, sal_uInt16
/*nItemVersion*/ ) const
146 SfxPoolItem
* SvxGalleryItem::Create(SvStream
& , sal_uInt16
) const
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */