1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_svx.hxx" 24 25 #include <svx/galleryitem.hxx> 26 #include <com/sun/star/gallery/GalleryItemType.hpp> 27 #include <com/sun/star/beans/PropertyValue.hpp> 28 #include <com/sun/star/uno/Sequence.hxx> 29 30 namespace css = ::com::sun::star; 31 32 DBG_NAMEEX( SvxGalleryItem ) 33 DBG_NAME( SvxGalleryItem ) 34 35 TYPEINIT1_AUTOFACTORY( SvxGalleryItem, SfxPoolItem ); 36 37 SvxGalleryItem::SvxGalleryItem() 38 : m_nType( css::gallery::GalleryItemType::EMPTY ) 39 , m_bIsLink( sal_False ) 40 { 41 DBG_CTOR(SvxGalleryItem, 0); 42 } 43 44 SvxGalleryItem::SvxGalleryItem( const SvxGalleryItem &rItem ) 45 : SfxPoolItem( rItem ) 46 , m_nType( rItem.m_nType ) 47 , m_bIsLink( rItem.m_bIsLink ) 48 , m_aURL( rItem.m_aURL ) 49 , m_xDrawing( rItem.m_xDrawing ) 50 , m_xGraphic( rItem.m_xGraphic ) 51 { 52 DBG_CTOR(SvxGalleryItem, 0); 53 } 54 55 SvxGalleryItem::SvxGalleryItem( 56 const ::sal_uInt16 nId ) 57 : SfxPoolItem( nId ) 58 , m_nType( css::gallery::GalleryItemType::EMPTY ) 59 , m_bIsLink( sal_False ) 60 { 61 DBG_CTOR(SvxGalleryItem, 0); 62 } 63 64 SvxGalleryItem::~SvxGalleryItem() 65 { 66 DBG_DTOR(SvxGalleryItem, 0); 67 } 68 69 sal_Bool SvxGalleryItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const 70 { 71 css::uno::Sequence< css::beans::PropertyValue > aSeq( SVXGALLERYITEM_PARAMS ); 72 73 aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVXGALLERYITEM_TYPE )); 74 aSeq[0].Value <<= m_nType; 75 aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVXGALLERYITEM_LINK )); 76 aSeq[1].Value <<= m_bIsLink; 77 aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVXGALLERYITEM_URL )); 78 aSeq[2].Value <<= m_aURL; 79 aSeq[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVXGALLERYITEM_FILTER )); 80 aSeq[3].Value <<= m_aURL; 81 aSeq[4].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVXGALLERYITEM_DRAWING )); 82 aSeq[4].Value <<= m_xDrawing; 83 aSeq[5].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SVXGALLERYITEM_GRAPHIC )); 84 aSeq[5].Value <<= m_xGraphic; 85 86 rVal <<= aSeq; 87 88 return sal_True; 89 } 90 91 sal_Bool SvxGalleryItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /* nMemberId */) 92 { 93 css::uno::Sequence< css::beans::PropertyValue > aSeq; 94 95 if ( !( rVal >>= aSeq ) || ( aSeq.getLength() < SVXGALLERYITEM_PARAMS ) ) 96 return sal_False; 97 98 int nConverted(0); 99 sal_Bool bAllConverted( sal_True ); 100 sal_Bool bIsSetType( sal_False ); 101 102 sal_Int8 nType(0); 103 sal_Bool bIsLink( sal_False ); 104 rtl::OUString aURL, aFilterName; 105 css::uno::Reference< css::lang::XComponent > xDrawing; 106 css::uno::Reference< css::graphic::XGraphic > xGraphic; 107 108 const css::beans::PropertyValue *pProp = aSeq.getConstArray(); 109 const css::beans::PropertyValue *pEnd = pProp + aSeq.getLength(); 110 for ( ; pProp != pEnd; pProp++ ) 111 { 112 if ( pProp->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SVXGALLERYITEM_TYPE ) ) ) 113 { 114 bAllConverted &= bIsSetType = ( pProp->Value >>= nType ); 115 ++nConverted; 116 } 117 else if ( pProp->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SVXGALLERYITEM_LINK ) ) ) 118 { 119 bAllConverted &= ( pProp->Value >>= bIsLink ); 120 ++nConverted; 121 } 122 else if ( pProp->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SVXGALLERYITEM_URL ) ) ) 123 { 124 bAllConverted &= ( pProp->Value >>= aURL ); 125 ++nConverted; 126 } 127 else if ( pProp->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SVXGALLERYITEM_FILTER ) ) ) 128 { 129 bAllConverted &= ( pProp->Value >>= aFilterName ); 130 ++nConverted; 131 } 132 else if ( pProp->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SVXGALLERYITEM_DRAWING ) ) ) 133 { 134 bAllConverted &= ( pProp->Value >>= xDrawing ); 135 ++nConverted; 136 } 137 else if ( pProp->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SVXGALLERYITEM_GRAPHIC ) ) ) 138 { 139 bAllConverted &= ( pProp->Value >>= xGraphic ); 140 ++nConverted; 141 } 142 } 143 144 if ( !bAllConverted || nConverted != SVXGALLERYITEM_PARAMS ) 145 return sal_False; 146 147 m_nType = nType; 148 m_bIsLink = bIsLink; 149 m_aURL = aURL; 150 m_aFilterName = aFilterName; 151 m_xDrawing = xDrawing; 152 m_xGraphic = xGraphic; 153 154 return sal_True; 155 } 156 157 int SvxGalleryItem::operator==( const SfxPoolItem& rAttr ) const 158 { 159 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); 160 161 const SvxGalleryItem& rItem = static_cast<const SvxGalleryItem&>(rAttr); 162 163 int bRet = m_nType == rItem.m_nType && 164 m_bIsLink == rItem.m_bIsLink && 165 m_aURL == rItem.m_aURL && 166 m_xDrawing == rItem.m_xDrawing && 167 m_xGraphic == rItem.m_xGraphic; 168 169 return bRet; 170 } 171 172 SfxPoolItem* SvxGalleryItem::Clone( SfxItemPool * ) const 173 { 174 return new SvxGalleryItem( *this ); 175 } 176 177 SvStream& SvxGalleryItem::Store( SvStream& rStream, sal_uInt16 /*nItemVersion*/ ) const 178 { 179 return rStream; 180 } 181 182 SfxPoolItem* SvxGalleryItem::Create(SvStream& , sal_uInt16) const 183 { 184 return 0; 185 } 186