LibreOffice Module svx (master)  1
galleryitem.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
26 
28 
29 #include <cassert>
30 
31 
33 
35  : m_nType( css::gallery::GalleryItemType::EMPTY )
36 {
37 }
38 
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 )
45 {
46 }
47 
49 {
50 }
51 
52 bool SvxGalleryItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const
53 {
54  css::uno::Sequence< css::beans::PropertyValue > aSeq{
60  };
61  assert(aSeq.getLength() == SVXGALLERYITEM_PARAMS);
62 
63  rVal <<= aSeq;
64 
65  return true;
66 }
67 
68 bool SvxGalleryItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /* nMemberId */)
69 {
70  css::uno::Sequence< css::beans::PropertyValue > aSeq;
71 
72  if ( !( rVal >>= aSeq ) || ( aSeq.getLength() < SVXGALLERYITEM_PARAMS ) )
73  return false;
74 
75  int nConverted(0);
76  bool bAllConverted( true );
77 
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;
82 
83  for ( const css::beans::PropertyValue& rProp : std::as_const(aSeq) )
84  {
85  if ( rProp.Name == SVXGALLERYITEM_TYPE )
86  {
87  bAllConverted &= ( rProp.Value >>= nType );
88  ++nConverted;
89  }
90  else if ( rProp.Name == SVXGALLERYITEM_URL )
91  {
92  bAllConverted &= ( rProp.Value >>= aURL );
93  ++nConverted;
94  }
95  else if ( rProp.Name == SVXGALLERYITEM_FILTER )
96  {
97  bAllConverted &= ( rProp.Value >>= aFilterName );
98  ++nConverted;
99  }
100  else if ( rProp.Name == SVXGALLERYITEM_DRAWING )
101  {
102  bAllConverted &= ( rProp.Value >>= xDrawing );
103  ++nConverted;
104  }
105  else if ( rProp.Name == SVXGALLERYITEM_GRAPHIC )
106  {
107  bAllConverted &= ( rProp.Value >>= xGraphic );
108  ++nConverted;
109  }
110  }
111 
112  if ( !bAllConverted || nConverted != SVXGALLERYITEM_PARAMS )
113  return false;
114 
115  m_nType = nType;
116  m_aURL = aURL;
117  m_xDrawing = xDrawing;
118  m_xGraphic = xGraphic;
119 
120  return true;
121 }
122 
123 bool SvxGalleryItem::operator==( const SfxPoolItem& rAttr ) const
124 {
125  assert(SfxPoolItem::operator==(rAttr));
126 
127  const SvxGalleryItem& rItem = static_cast<const SvxGalleryItem&>(rAttr);
128 
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;
133 }
134 
136 {
137  return new SvxGalleryItem( *this );
138 }
139 
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
URL aURL
signed char sal_Int8
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr OUStringLiteral SVXGALLERYITEM_URL
Definition: galleryitem.hxx:33
virtual bool operator==(const SfxPoolItem &) const override
#define SVXGALLERYITEM_PARAMS
Definition: galleryitem.hxx:37
constexpr OUStringLiteral SVXGALLERYITEM_TYPE
Definition: galleryitem.hxx:32
constexpr OUStringLiteral SVXGALLERYITEM_FILTER
Definition: galleryitem.hxx:34
constexpr OUStringLiteral EMPTY
constexpr OUStringLiteral SVXGALLERYITEM_DRAWING
Definition: galleryitem.hxx:35
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: galleryitem.cxx:52
css::util::URL m_aURL
exports com.sun.star. gallery
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: galleryitem.cxx:68
OUString m_aURL
Definition: galleryitem.hxx:43
virtual SvxGalleryItem * Clone(SfxItemPool *pPool=nullptr) const override
unsigned char sal_uInt8
static SfxPoolItem * CreateDefault()
Definition: galleryitem.cxx:32
QPRO_FUNC_TYPE nType
css::uno::Reference< css::graphic::XGraphic > m_xGraphic
Definition: galleryitem.hxx:45
Sequence< sal_Int8 > aSeq
virtual ~SvxGalleryItem() override
Definition: galleryitem.cxx:48
sal_Int8 m_nType
Definition: galleryitem.hxx:42
constexpr OUStringLiteral SVXGALLERYITEM_GRAPHIC
Definition: galleryitem.hxx:36
css::uno::Reference< css::lang::XComponent > m_xDrawing
Definition: galleryitem.hxx:44