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