xref: /aoo41x/main/svl/source/items/cntwall.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #include <tools/debug.hxx>
32 #include <tools/string.hxx>
33 #include <tools/stream.hxx>
34 #include <tools/vcompat.hxx>
35 
36 #include <svl/cntwall.hxx>
37 
38 #define CNTWALLPAPERITEM_STREAM_MAGIC   ( (sal_uInt32)0xfefefefe )
39 #define CNTWALLPAPERITEM_STREAM_SEEKREL (-( (long)( sizeof( sal_uInt32 ) ) ) )
40 
41 TYPEINIT1( CntWallpaperItem, SfxPoolItem );
42 
43 // -----------------------------------------------------------------------
44 CntWallpaperItem::CntWallpaperItem( sal_uInt16 which )
45 	: SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 )
46 {
47 }
48 
49 // -----------------------------------------------------------------------
50 CntWallpaperItem::CntWallpaperItem( sal_uInt16 which, SvStream& rStream, sal_uInt16 nVersion )
51 	: SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 )
52 {
53 	sal_uInt32 nMagic = 0;
54 	rStream >> nMagic;
55 	if ( nMagic == CNTWALLPAPERITEM_STREAM_MAGIC )
56 	{
57 		// Okay, data were stored by CntWallpaperItem.
58 
59 		readUnicodeString(rStream, _aURL, nVersion >= 1);
60 		// !!! Color stream operators do not work - they discard any
61 		// transparency info !!!
62 		_nColor.Read( rStream, sal_True );
63 		rStream >> _nStyle;
64 	}
65 	else
66 	{
67 		rStream.SeekRel( CNTWALLPAPERITEM_STREAM_SEEKREL );
68 
69 		// Data were stored by SfxWallpaperItem ( SO < 6.0 ). The only
70 		// thing we can do here is to get the URL and to position the stream.
71 
72 		{
73 			// "Read" Wallpaper member - The version compat object positions
74 			// the stream after the wallpaper data in its dtor. We must use
75 			// this trick here as no VCL must be used here ( No Wallpaper
76 			// object allowed ).
77 			VersionCompat aCompat( rStream, STREAM_READ );
78 		}
79 
80 		// Read SfxWallpaperItem's string member _aURL.
81 		readUnicodeString(rStream, _aURL, false);
82 
83 		// "Read" SfxWallpaperItem's string member _aFilter.
84 		ByteString aDummy;
85 		rStream.ReadByteString(aDummy);
86 	}
87 }
88 
89 // -----------------------------------------------------------------------
90 CntWallpaperItem::CntWallpaperItem( const CntWallpaperItem& rItem ) :
91 	SfxPoolItem( rItem ),
92 	_aURL( rItem._aURL ),
93 	_nColor( rItem._nColor ),
94 	_nStyle( rItem._nStyle )
95 {
96 }
97 
98 // -----------------------------------------------------------------------
99 CntWallpaperItem::~CntWallpaperItem()
100 {
101 }
102 
103 // -----------------------------------------------------------------------
104 int CntWallpaperItem::operator==( const SfxPoolItem& rItem ) const
105 {
106 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
107 
108 	const CntWallpaperItem& rWallItem = (const CntWallpaperItem&)rItem;
109 
110 	if( ( rWallItem._nStyle == _nStyle ) &&
111 		( rWallItem._nColor == _nColor ) &&
112 		( rWallItem._aURL == _aURL ) )
113 		return sal_True;
114 	else
115 		return sal_False;
116 }
117 
118 //============================================================================
119 // virtual
120 sal_uInt16 CntWallpaperItem::GetVersion(sal_uInt16) const
121 {
122 	return 1; // because it uses SfxPoolItem::read/writeUnicodeString()
123 }
124 
125 // -----------------------------------------------------------------------
126 SfxPoolItem* CntWallpaperItem::Create( SvStream& rStream, sal_uInt16 nVersion) const
127 {
128 	return new CntWallpaperItem( Which(), rStream, nVersion );
129 }
130 
131 // -----------------------------------------------------------------------
132 SvStream& CntWallpaperItem::Store( SvStream& rStream, sal_uInt16 ) const
133 {
134 	rStream << CNTWALLPAPERITEM_STREAM_MAGIC;
135 	writeUnicodeString(rStream, _aURL);
136 	// !!! Color stream operators do not work - they discard any
137 	// transparency info !!!
138 	// ??? Why the hell Color::Write(...) isn't const ???
139 	SAL_CONST_CAST( CntWallpaperItem*, this )->_nColor.Write( rStream, sal_True );
140 	rStream << _nStyle;
141 
142 	return rStream;
143 }
144 
145 // -----------------------------------------------------------------------
146 SfxPoolItem* CntWallpaperItem::Clone( SfxItemPool* ) const
147 {
148 	return new CntWallpaperItem( *this );
149 }
150 
151 //----------------------------------------------------------------------------
152 // virtual
153 sal_Bool CntWallpaperItem::QueryValue( com::sun::star::uno::Any&,sal_uInt8 ) const
154 {
155     DBG_ERROR("Not implemented!");
156 	return sal_False;
157 }
158 
159 //----------------------------------------------------------------------------
160 // virtual
161 sal_Bool CntWallpaperItem::PutValue( const com::sun::star::uno::Any&,sal_uInt8 )
162 {
163     DBG_ERROR("Not implemented!");
164 	return sal_False;
165 }
166 
167 
168