Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / items / galleryitem.cxx
blob5e50c5efbe3c0090fc903f032b7bb815062a9908
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>
27 #include <comphelper/propertyvalue.hxx>
29 #include <cassert>
32 SfxPoolItem* SvxGalleryItem::CreateDefault() { return new SvxGalleryItem; }
34 SvxGalleryItem::SvxGalleryItem()
35 : m_nType( css::gallery::GalleryItemType::EMPTY )
39 SvxGalleryItem::SvxGalleryItem( const SvxGalleryItem &rItem )
40 : SfxPoolItem( rItem )
41 , m_nType( rItem.m_nType )
42 , m_aURL( rItem.m_aURL )
43 , m_xDrawing( rItem.m_xDrawing )
44 , m_xGraphic( rItem.m_xGraphic )
48 SvxGalleryItem::~SvxGalleryItem()
52 bool SvxGalleryItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const
54 css::uno::Sequence< css::beans::PropertyValue > aSeq{
55 comphelper::makePropertyValue(SVXGALLERYITEM_TYPE, m_nType),
56 comphelper::makePropertyValue(SVXGALLERYITEM_URL, m_aURL),
57 comphelper::makePropertyValue(SVXGALLERYITEM_FILTER, m_aURL),
58 comphelper::makePropertyValue(SVXGALLERYITEM_DRAWING, m_xDrawing),
59 comphelper::makePropertyValue(SVXGALLERYITEM_GRAPHIC, m_xGraphic)
61 assert(aSeq.getLength() == SVXGALLERYITEM_PARAMS);
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: */