Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / items / galleryitem.cxx
blobe5c1762c377ea4bec1b3f49e7cd97594da4c34ae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/graphic/XGraphic.hpp>
23 #include <com/sun/star/lang/XComponent.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/uno/Sequence.hxx>
28 SfxPoolItem* SvxGalleryItem::CreateDefault() { return new SvxGalleryItem; }
30 SvxGalleryItem::SvxGalleryItem()
31 : m_nType( css::gallery::GalleryItemType::EMPTY )
35 SvxGalleryItem::SvxGalleryItem( const SvxGalleryItem &rItem )
36 : SfxPoolItem( rItem )
37 , m_nType( rItem.m_nType )
38 , m_aURL( rItem.m_aURL )
39 , m_xDrawing( rItem.m_xDrawing )
40 , m_xGraphic( rItem.m_xGraphic )
44 SvxGalleryItem::~SvxGalleryItem()
48 bool SvxGalleryItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const
50 css::uno::Sequence< css::beans::PropertyValue > aSeq( SVXGALLERYITEM_PARAMS );
52 aSeq[0].Name = SVXGALLERYITEM_TYPE;
53 aSeq[0].Value <<= m_nType;
54 aSeq[1].Name = SVXGALLERYITEM_URL;
55 aSeq[1].Value <<= m_aURL;
56 aSeq[2].Name = SVXGALLERYITEM_FILTER;
57 aSeq[2].Value <<= m_aURL;
58 aSeq[3].Name = SVXGALLERYITEM_DRAWING;
59 aSeq[3].Value <<= m_xDrawing;
60 aSeq[4].Name = SVXGALLERYITEM_GRAPHIC;
61 aSeq[4].Value <<= m_xGraphic;
63 rVal <<= aSeq;
65 return true;
68 bool SvxGalleryItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /* nMemberId */)
70 css::uno::Sequence< css::beans::PropertyValue > aSeq;
72 if ( !( rVal >>= aSeq ) || ( aSeq.getLength() < SVXGALLERYITEM_PARAMS ) )
73 return false;
75 int nConverted(0);
76 bool bAllConverted( true );
78 sal_Int8 nType(0);
79 OUString aURL, aFilterName;
80 css::uno::Reference< css::lang::XComponent > xDrawing;
81 css::uno::Reference< css::graphic::XGraphic > xGraphic;
83 for ( const css::beans::PropertyValue& rProp : std::as_const(aSeq) )
85 if ( rProp.Name == SVXGALLERYITEM_TYPE )
87 bAllConverted &= ( rProp.Value >>= nType );
88 ++nConverted;
90 else if ( rProp.Name == SVXGALLERYITEM_URL )
92 bAllConverted &= ( rProp.Value >>= aURL );
93 ++nConverted;
95 else if ( rProp.Name == SVXGALLERYITEM_FILTER )
97 bAllConverted &= ( rProp.Value >>= aFilterName );
98 ++nConverted;
100 else if ( rProp.Name == SVXGALLERYITEM_DRAWING )
102 bAllConverted &= ( rProp.Value >>= xDrawing );
103 ++nConverted;
105 else if ( rProp.Name == SVXGALLERYITEM_GRAPHIC )
107 bAllConverted &= ( rProp.Value >>= xGraphic );
108 ++nConverted;
112 if ( !bAllConverted || nConverted != SVXGALLERYITEM_PARAMS )
113 return false;
115 m_nType = nType;
116 m_aURL = aURL;
117 m_xDrawing = xDrawing;
118 m_xGraphic = xGraphic;
120 return true;
123 bool SvxGalleryItem::operator==( const SfxPoolItem& rAttr ) const
125 assert(SfxPoolItem::operator==(rAttr));
127 const SvxGalleryItem& rItem = static_cast<const SvxGalleryItem&>(rAttr);
129 return m_nType == rItem.m_nType &&
130 m_aURL == rItem.m_aURL &&
131 m_xDrawing == rItem.m_xDrawing &&
132 m_xGraphic == rItem.m_xGraphic;
135 SvxGalleryItem* SvxGalleryItem::Clone( SfxItemPool * ) const
137 return new SvxGalleryItem( *this );
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */