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
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26
27 #include <tools/debug.hxx>
28 #include <tools/string.hxx>
29 #include <tools/stream.hxx>
30 #include <tools/vcompat.hxx>
31
32 #include <svl/cntwall.hxx>
33
34 #define CNTWALLPAPERITEM_STREAM_MAGIC ( (sal_uInt32)0xfefefefe )
35 #define CNTWALLPAPERITEM_STREAM_SEEKREL (-( (long)( sizeof( sal_uInt32 ) ) ) )
36
37 TYPEINIT1( CntWallpaperItem, SfxPoolItem );
38
39 // -----------------------------------------------------------------------
CntWallpaperItem(sal_uInt16 which)40 CntWallpaperItem::CntWallpaperItem( sal_uInt16 which )
41 : SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 )
42 {
43 }
44
45 // -----------------------------------------------------------------------
CntWallpaperItem(sal_uInt16 which,SvStream & rStream,sal_uInt16 nVersion)46 CntWallpaperItem::CntWallpaperItem( sal_uInt16 which, SvStream& rStream, sal_uInt16 nVersion )
47 : SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 )
48 {
49 sal_uInt32 nMagic = 0;
50 rStream >> nMagic;
51 if ( nMagic == CNTWALLPAPERITEM_STREAM_MAGIC )
52 {
53 // Okay, data were stored by CntWallpaperItem.
54
55 readUnicodeString(rStream, _aURL, nVersion >= 1);
56 // !!! Color stream operators do not work - they discard any
57 // transparency info !!!
58 _nColor.Read( rStream, sal_True );
59 rStream >> _nStyle;
60 }
61 else
62 {
63 rStream.SeekRel( CNTWALLPAPERITEM_STREAM_SEEKREL );
64
65 // Data were stored by SfxWallpaperItem ( SO < 6.0 ). The only
66 // thing we can do here is to get the URL and to position the stream.
67
68 {
69 // "Read" Wallpaper member - The version compat object positions
70 // the stream after the wallpaper data in its dtor. We must use
71 // this trick here as no VCL must be used here ( No Wallpaper
72 // object allowed ).
73 VersionCompat aCompat( rStream, STREAM_READ );
74 }
75
76 // Read SfxWallpaperItem's string member _aURL.
77 readUnicodeString(rStream, _aURL, false);
78
79 // "Read" SfxWallpaperItem's string member _aFilter.
80 ByteString aDummy;
81 rStream.ReadByteString(aDummy);
82 }
83 }
84
85 // -----------------------------------------------------------------------
CntWallpaperItem(const CntWallpaperItem & rItem)86 CntWallpaperItem::CntWallpaperItem( const CntWallpaperItem& rItem ) :
87 SfxPoolItem( rItem ),
88 _aURL( rItem._aURL ),
89 _nColor( rItem._nColor ),
90 _nStyle( rItem._nStyle )
91 {
92 }
93
94 // -----------------------------------------------------------------------
~CntWallpaperItem()95 CntWallpaperItem::~CntWallpaperItem()
96 {
97 }
98
99 // -----------------------------------------------------------------------
operator ==(const SfxPoolItem & rItem) const100 int CntWallpaperItem::operator==( const SfxPoolItem& rItem ) const
101 {
102 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
103
104 const CntWallpaperItem& rWallItem = (const CntWallpaperItem&)rItem;
105
106 if( ( rWallItem._nStyle == _nStyle ) &&
107 ( rWallItem._nColor == _nColor ) &&
108 ( rWallItem._aURL == _aURL ) )
109 return sal_True;
110 else
111 return sal_False;
112 }
113
114 //============================================================================
115 // virtual
GetVersion(sal_uInt16) const116 sal_uInt16 CntWallpaperItem::GetVersion(sal_uInt16) const
117 {
118 return 1; // because it uses SfxPoolItem::read/writeUnicodeString()
119 }
120
121 // -----------------------------------------------------------------------
Create(SvStream & rStream,sal_uInt16 nVersion) const122 SfxPoolItem* CntWallpaperItem::Create( SvStream& rStream, sal_uInt16 nVersion) const
123 {
124 return new CntWallpaperItem( Which(), rStream, nVersion );
125 }
126
127 // -----------------------------------------------------------------------
Store(SvStream & rStream,sal_uInt16) const128 SvStream& CntWallpaperItem::Store( SvStream& rStream, sal_uInt16 ) const
129 {
130 rStream << CNTWALLPAPERITEM_STREAM_MAGIC;
131 writeUnicodeString(rStream, _aURL);
132 // !!! Color stream operators do not work - they discard any
133 // transparency info !!!
134 // ??? Why the hell Color::Write(...) isn't const ???
135 SAL_CONST_CAST( CntWallpaperItem*, this )->_nColor.Write( rStream, sal_True );
136 rStream << _nStyle;
137
138 return rStream;
139 }
140
141 // -----------------------------------------------------------------------
Clone(SfxItemPool *) const142 SfxPoolItem* CntWallpaperItem::Clone( SfxItemPool* ) const
143 {
144 return new CntWallpaperItem( *this );
145 }
146
147 //----------------------------------------------------------------------------
148 // virtual
QueryValue(com::sun::star::uno::Any &,sal_uInt8) const149 sal_Bool CntWallpaperItem::QueryValue( com::sun::star::uno::Any&,sal_uInt8 ) const
150 {
151 DBG_ERROR("Not implemented!");
152 return sal_False;
153 }
154
155 //----------------------------------------------------------------------------
156 // virtual
PutValue(const com::sun::star::uno::Any &,sal_uInt8)157 sal_Bool CntWallpaperItem::PutValue( const com::sun::star::uno::Any&,sal_uInt8 )
158 {
159 DBG_ERROR("Not implemented!");
160 return sal_False;
161 }
162
163
164