xref: /aoo41x/main/svl/source/items/lckbitem.cxx (revision 40df464e)
1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*40df464eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*40df464eSAndrew Rist  * distributed with this work for additional information
6*40df464eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*40df464eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist  * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*40df464eSAndrew Rist  *
11*40df464eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist  *
13*40df464eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist  * software distributed under the License is distributed on an
15*40df464eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*40df464eSAndrew Rist  * specific language governing permissions and limitations
18*40df464eSAndrew Rist  * under the License.
19*40df464eSAndrew Rist  *
20*40df464eSAndrew Rist  *************************************************************/
21*40df464eSAndrew Rist 
22*40df464eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _LCKBITEM_CXX
28cdf0e10cSrcweir #include <svl/lckbitem.hxx>
29cdf0e10cSrcweir #include <svl/poolitem.hxx>
30cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
31cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
32cdf0e10cSrcweir #include <tools/cachestr.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir // -----------------------------------------------------------------------
38cdf0e10cSrcweir 
39cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem);
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // -----------------------------------------------------------------------
42cdf0e10cSrcweir 
SfxLockBytesItem()43cdf0e10cSrcweir SfxLockBytesItem::SfxLockBytesItem()
44cdf0e10cSrcweir {
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir // -----------------------------------------------------------------------
48cdf0e10cSrcweir 
SfxLockBytesItem(sal_uInt16 nW,SvLockBytes * pLockBytes)49cdf0e10cSrcweir SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvLockBytes *pLockBytes )
50cdf0e10cSrcweir :	SfxPoolItem( nW ),
51cdf0e10cSrcweir 	_xVal( pLockBytes )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir // -----------------------------------------------------------------------
56cdf0e10cSrcweir 
SfxLockBytesItem(sal_uInt16 nW,SvStream & rStream)57cdf0e10cSrcweir SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvStream &rStream )
58cdf0e10cSrcweir :	SfxPoolItem( nW )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	rStream.Seek( 0L );
61cdf0e10cSrcweir 	_xVal = new SvLockBytes( new SvCacheStream(), sal_True );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	SvStream aLockBytesStream( _xVal );
64cdf0e10cSrcweir 	rStream >> aLockBytesStream;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------------------------------------------------------------------
68cdf0e10cSrcweir 
SfxLockBytesItem(const SfxLockBytesItem & rItem)69cdf0e10cSrcweir SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem )
70cdf0e10cSrcweir :	SfxPoolItem( rItem ),
71cdf0e10cSrcweir 	_xVal( rItem._xVal )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // -----------------------------------------------------------------------
76cdf0e10cSrcweir 
~SfxLockBytesItem()77cdf0e10cSrcweir SfxLockBytesItem::~SfxLockBytesItem()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // -----------------------------------------------------------------------
82cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rItem) const83cdf0e10cSrcweir int SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	return ((SfxLockBytesItem&)rItem)._xVal == _xVal;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir // -----------------------------------------------------------------------
89cdf0e10cSrcweir 
Clone(SfxItemPool *) const90cdf0e10cSrcweir SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	return new SfxLockBytesItem( *this );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir // -----------------------------------------------------------------------
96cdf0e10cSrcweir 
97cdf0e10cSrcweir #define MAX_BUF	32000
98cdf0e10cSrcweir 
Create(SvStream & rStream,sal_uInt16) const99cdf0e10cSrcweir SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, sal_uInt16 ) const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	sal_uInt32 nSize = 0;
102cdf0e10cSrcweir 	sal_uLong nActRead = 0;
103cdf0e10cSrcweir 	sal_Char cTmpBuf[MAX_BUF];
104cdf0e10cSrcweir 	SvMemoryStream aNewStream;
105cdf0e10cSrcweir 	rStream >> nSize;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	do {
108cdf0e10cSrcweir 		sal_uLong nToRead;
109cdf0e10cSrcweir 		if( (nSize - nActRead) > MAX_BUF )
110cdf0e10cSrcweir 			nToRead = MAX_BUF;
111cdf0e10cSrcweir 		else
112cdf0e10cSrcweir 			nToRead = nSize - nActRead;
113cdf0e10cSrcweir 		nActRead += rStream.Read( cTmpBuf, nToRead );
114cdf0e10cSrcweir 		aNewStream.Write( cTmpBuf, nToRead );
115cdf0e10cSrcweir 	} while( nSize > nActRead );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	return new SfxLockBytesItem( Which(), aNewStream );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -----------------------------------------------------------------------
121cdf0e10cSrcweir 
Store(SvStream & rStream,sal_uInt16) const122cdf0e10cSrcweir SvStream& SfxLockBytesItem::Store(SvStream &rStream, sal_uInt16 ) const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	SvStream aLockBytesStream( _xVal );
125cdf0e10cSrcweir 	sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END );
126cdf0e10cSrcweir 	aLockBytesStream.Seek( 0L );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	rStream << nSize;
129cdf0e10cSrcweir 	rStream << aLockBytesStream;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	return rStream;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir //----------------------------------------------------------------------------
135cdf0e10cSrcweir // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)136cdf0e10cSrcweir sal_Bool SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir 	com::sun::star::uno::Sequence< sal_Int8 > aSeq;
139cdf0e10cSrcweir 	if ( rVal >>= aSeq )
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		if ( aSeq.getLength() )
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			SvCacheStream* pStream = new SvCacheStream;
144cdf0e10cSrcweir 			pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() );
145cdf0e10cSrcweir 			pStream->Seek(0);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 			_xVal = new SvLockBytes( pStream, sal_True );
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 		else
150cdf0e10cSrcweir 			_xVal = NULL;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 		return sal_True;
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	DBG_ERROR( "SfxLockBytesItem::PutValue - Wrong type!" );
156cdf0e10cSrcweir 	return sal_False;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
159cdf0e10cSrcweir //----------------------------------------------------------------------------
160cdf0e10cSrcweir // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const161cdf0e10cSrcweir sal_Bool SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal,sal_uInt8 ) const
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	if ( _xVal.Is() )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		sal_uInt32 nLen;
166cdf0e10cSrcweir 		SvLockBytesStat aStat;
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 		if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
169cdf0e10cSrcweir 			nLen = aStat.nSize;
170cdf0e10cSrcweir 		else
171cdf0e10cSrcweir 			return sal_False;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 		sal_uLong nRead = 0;
174cdf0e10cSrcweir 		com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		_xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
177cdf0e10cSrcweir 		rVal <<= aSeq;
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 	else
180cdf0e10cSrcweir 	{
181cdf0e10cSrcweir 		com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 );
182cdf0e10cSrcweir 		rVal <<= aSeq;
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	return sal_True;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188