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_svx.hxx"
26
27 // include ---------------------------------------------------------------
28
29 #include <sot/formats.hxx>
30 #include <tools/vcompat.hxx>
31 #include <svx/xflasit.hxx>
32 #include <svx/xfillit0.hxx>
33 #ifndef _SFXIPOOL_HXX
34 #include <svl/itempool.hxx>
35 #endif
36 #include <svl/whiter.hxx>
37 #ifndef _SFXIPOOL_HXX
38 #include <svl/itempool.hxx>
39 #endif
40 #include <svl/itemset.hxx>
41 #include <svx/xdef.hxx>
42 #include "svx/xexch.hxx"
43
44
45 TYPEINIT1_AUTOFACTORY( XFillExchangeData, SvDataCopyStream );
46
47
48 /*************************************************************************
49 |*
50 |* Default-Ctor (Fuer Assign())
51 |*
52 *************************************************************************/
XFillExchangeData()53 XFillExchangeData::XFillExchangeData() :
54 pXFillAttrSetItem( NULL ),
55 pPool( NULL )
56 {
57 }
58
59
60 /*************************************************************************
61 |*
62 |* Ctor
63 |*
64 *************************************************************************/
XFillExchangeData(const XFillAttrSetItem rXFillAttrSetItem)65 XFillExchangeData::XFillExchangeData( const XFillAttrSetItem rXFillAttrSetItem ) :
66 pXFillAttrSetItem( (XFillAttrSetItem*) rXFillAttrSetItem.Clone( rXFillAttrSetItem.GetItemSet().GetPool() ) ),
67 pPool( rXFillAttrSetItem.GetItemSet().GetPool() )
68 {
69 }
70
71
72 /*************************************************************************
73 |*
74 |* Dtor
75 |*
76 *************************************************************************/
~XFillExchangeData()77 XFillExchangeData::~XFillExchangeData()
78 {
79 delete pXFillAttrSetItem;
80 }
81
82 /*************************************************************************
83 |*
84 |*
85 |*
86 *************************************************************************/
RegisterClipboardFormatName()87 sal_uIntPtr XFillExchangeData::RegisterClipboardFormatName()
88 {
89 return( SOT_FORMATSTR_ID_XFA );
90 }
91
92 /******************************************************************************
93 |*
94 |* Binaer-Export (z.Z. ohne Versionsverwaltung, da nicht persistent!)
95 |*
96 \******************************************************************************/
97
operator <<(SvStream & rOStm,const XFillExchangeData & rData)98 SvStream& operator<<( SvStream& rOStm, const XFillExchangeData& rData )
99 {
100 if( rData.pXFillAttrSetItem )
101 {
102 SfxWhichIter aIter( rData.pXFillAttrSetItem->GetItemSet() );
103 sal_uInt16 nWhich = aIter.FirstWhich();
104 const SfxPoolItem* pItem;
105 sal_uInt32 nItemCount = 0;
106 sal_Size nFirstPos = rOStm.Tell();
107
108 rOStm << nItemCount;
109
110 while( nWhich )
111 {
112 if( SFX_ITEM_SET == rData.pXFillAttrSetItem->GetItemSet().GetItemState( nWhich, sal_False, &pItem ) )
113 {
114 VersionCompat aCompat( rOStm, STREAM_WRITE );
115 const sal_uInt16 nItemVersion2 = pItem->GetVersion( (sal_uInt16) rOStm.GetVersion() );
116
117 rOStm << nWhich << nItemVersion2;
118 pItem->Store( rOStm, nItemVersion2 );
119
120 nItemCount++;
121 }
122
123 nWhich = aIter.NextWhich();
124 }
125
126 const sal_uIntPtr nLastPos = rOStm.Tell();
127 rOStm.Seek( nFirstPos );
128 rOStm << nItemCount;
129 rOStm.Seek( nLastPos );
130 }
131
132 return rOStm;
133 }
134
135
136 /******************************************************************************
137 |*
138 |* Binaer-Import (z.Z. ohne Versionsverwaltung, da nicht persistent!)
139 |*
140 \******************************************************************************/
141
operator >>(SvStream & rIStm,XFillExchangeData & rData)142 SvStream& operator>>( SvStream& rIStm, XFillExchangeData& rData )
143 {
144 DBG_ASSERT( rData.pPool, "XFillExchangeData has no pool" );
145
146 SfxItemSet* pSet = new SfxItemSet ( *rData.pPool, XATTR_FILL_FIRST, XATTR_FILL_LAST );
147 SfxPoolItem* pNewItem;
148 sal_uInt32 nItemCount = 0;
149 sal_uInt16 nWhich, nItemVersion;
150
151 rIStm >> nItemCount;
152
153 if( nItemCount > ( XATTR_FILL_LAST - XATTR_FILL_FIRST + 1 ) )
154 nItemCount = ( XATTR_FILL_LAST - XATTR_FILL_FIRST + 1 );
155
156 for( sal_uInt32 i = 0; i < nItemCount; i++ )
157 {
158 VersionCompat aCompat( rIStm, STREAM_READ );
159
160 rIStm >> nWhich >> nItemVersion;
161
162 if( nWhich )
163 {
164 pNewItem = rData.pPool->GetDefaultItem( nWhich ).Create( rIStm, nItemVersion );
165
166 if( pNewItem )
167 {
168 pSet->Put( *pNewItem );
169 delete pNewItem;
170 }
171 }
172 }
173
174 delete rData.pXFillAttrSetItem;
175 rData.pXFillAttrSetItem = new XFillAttrSetItem( pSet );
176 rData.pPool = rData.pXFillAttrSetItem->GetItemSet().GetPool();
177
178 return rIStm;
179 }
180
181 /*************************************************************************
182 |*
183 |* XBitmap& XBitmap::operator=( const XBitmap& rXBmp )
184 |*
185 *************************************************************************/
186
operator =(const XFillExchangeData & rData)187 XFillExchangeData& XFillExchangeData::operator=( const XFillExchangeData& rData )
188 {
189 delete pXFillAttrSetItem;
190
191 if( rData.pXFillAttrSetItem )
192 pXFillAttrSetItem = (XFillAttrSetItem*) rData.pXFillAttrSetItem->Clone( pPool = rData.pXFillAttrSetItem->GetItemSet().GetPool() );
193 else
194 {
195 pPool = NULL;
196 pXFillAttrSetItem = NULL;
197 }
198
199 return( *this );
200 }
201