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 #define _LCKBITEM_CXX
28 #include <svl/lckbitem.hxx>
29 #include <svl/poolitem.hxx>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <tools/cachestr.hxx>
33
34 // STATIC DATA -----------------------------------------------------------
35
36
37 // -----------------------------------------------------------------------
38
39 TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem);
40
41 // -----------------------------------------------------------------------
42
SfxLockBytesItem()43 SfxLockBytesItem::SfxLockBytesItem()
44 {
45 }
46
47 // -----------------------------------------------------------------------
48
SfxLockBytesItem(sal_uInt16 nW,SvLockBytes * pLockBytes)49 SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvLockBytes *pLockBytes )
50 : SfxPoolItem( nW ),
51 _xVal( pLockBytes )
52 {
53 }
54
55 // -----------------------------------------------------------------------
56
SfxLockBytesItem(sal_uInt16 nW,SvStream & rStream)57 SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvStream &rStream )
58 : SfxPoolItem( nW )
59 {
60 rStream.Seek( 0L );
61 _xVal = new SvLockBytes( new SvCacheStream(), sal_True );
62
63 SvStream aLockBytesStream( _xVal );
64 rStream >> aLockBytesStream;
65 }
66
67 // -----------------------------------------------------------------------
68
SfxLockBytesItem(const SfxLockBytesItem & rItem)69 SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem )
70 : SfxPoolItem( rItem ),
71 _xVal( rItem._xVal )
72 {
73 }
74
75 // -----------------------------------------------------------------------
76
~SfxLockBytesItem()77 SfxLockBytesItem::~SfxLockBytesItem()
78 {
79 }
80
81 // -----------------------------------------------------------------------
82
operator ==(const SfxPoolItem & rItem) const83 int SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
84 {
85 return ((SfxLockBytesItem&)rItem)._xVal == _xVal;
86 }
87
88 // -----------------------------------------------------------------------
89
Clone(SfxItemPool *) const90 SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const
91 {
92 return new SfxLockBytesItem( *this );
93 }
94
95 // -----------------------------------------------------------------------
96
97 #define MAX_BUF 32000
98
Create(SvStream & rStream,sal_uInt16) const99 SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, sal_uInt16 ) const
100 {
101 sal_uInt32 nSize = 0;
102 sal_uLong nActRead = 0;
103 sal_Char cTmpBuf[MAX_BUF];
104 SvMemoryStream aNewStream;
105 rStream >> nSize;
106
107 do {
108 sal_uLong nToRead;
109 if( (nSize - nActRead) > MAX_BUF )
110 nToRead = MAX_BUF;
111 else
112 nToRead = nSize - nActRead;
113 nActRead += rStream.Read( cTmpBuf, nToRead );
114 aNewStream.Write( cTmpBuf, nToRead );
115 } while( nSize > nActRead );
116
117 return new SfxLockBytesItem( Which(), aNewStream );
118 }
119
120 // -----------------------------------------------------------------------
121
Store(SvStream & rStream,sal_uInt16) const122 SvStream& SfxLockBytesItem::Store(SvStream &rStream, sal_uInt16 ) const
123 {
124 SvStream aLockBytesStream( _xVal );
125 sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END );
126 aLockBytesStream.Seek( 0L );
127
128 rStream << nSize;
129 rStream << aLockBytesStream;
130
131 return rStream;
132 }
133
134 //----------------------------------------------------------------------------
135 // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)136 sal_Bool SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
137 {
138 com::sun::star::uno::Sequence< sal_Int8 > aSeq;
139 if ( rVal >>= aSeq )
140 {
141 if ( aSeq.getLength() )
142 {
143 SvCacheStream* pStream = new SvCacheStream;
144 pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() );
145 pStream->Seek(0);
146
147 _xVal = new SvLockBytes( pStream, sal_True );
148 }
149 else
150 _xVal = NULL;
151
152 return sal_True;
153 }
154
155 DBG_ERROR( "SfxLockBytesItem::PutValue - Wrong type!" );
156 return sal_False;
157 }
158
159 //----------------------------------------------------------------------------
160 // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const161 sal_Bool SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal,sal_uInt8 ) const
162 {
163 if ( _xVal.Is() )
164 {
165 sal_uInt32 nLen;
166 SvLockBytesStat aStat;
167
168 if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
169 nLen = aStat.nSize;
170 else
171 return sal_False;
172
173 sal_uLong nRead = 0;
174 com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
175
176 _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
177 rVal <<= aSeq;
178 }
179 else
180 {
181 com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 );
182 rVal <<= aSeq;
183 }
184
185 return sal_True;
186 }
187
188