update dev300-m58
[ooovba.git] / svtools / source / items1 / lckbitem.cxx
blob2a6b3bf9efa4c517dada67fee43bd0897742418a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lckbitem.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #define _LCKBITEM_CXX
35 #include <svtools/lckbitem.hxx>
36 #include <svtools/poolitem.hxx>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <tools/cachestr.hxx>
41 // STATIC DATA -----------------------------------------------------------
44 // -----------------------------------------------------------------------
46 TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem);
48 // -----------------------------------------------------------------------
50 SfxLockBytesItem::SfxLockBytesItem()
54 // -----------------------------------------------------------------------
56 SfxLockBytesItem::SfxLockBytesItem( USHORT nW, SvLockBytes *pLockBytes )
57 : SfxPoolItem( nW ),
58 _xVal( pLockBytes )
62 // -----------------------------------------------------------------------
64 SfxLockBytesItem::SfxLockBytesItem( USHORT nW, SvStream &rStream )
65 : SfxPoolItem( nW )
67 rStream.Seek( 0L );
68 _xVal = new SvLockBytes( new SvCacheStream(), TRUE );
70 SvStream aLockBytesStream( _xVal );
71 rStream >> aLockBytesStream;
74 // -----------------------------------------------------------------------
76 SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem )
77 : SfxPoolItem( rItem ),
78 _xVal( rItem._xVal )
82 // -----------------------------------------------------------------------
84 SfxLockBytesItem::~SfxLockBytesItem()
88 // -----------------------------------------------------------------------
90 int SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
92 return ((SfxLockBytesItem&)rItem)._xVal == _xVal;
95 // -----------------------------------------------------------------------
97 SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const
99 return new SfxLockBytesItem( *this );
102 // -----------------------------------------------------------------------
104 #define MAX_BUF 32000
106 SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, USHORT ) const
108 sal_uInt32 nSize = 0;
109 ULONG nActRead = 0;
110 sal_Char cTmpBuf[MAX_BUF];
111 SvMemoryStream aNewStream;
112 rStream >> nSize;
114 do {
115 ULONG nToRead;
116 if( (nSize - nActRead) > MAX_BUF )
117 nToRead = MAX_BUF;
118 else
119 nToRead = nSize - nActRead;
120 nActRead += rStream.Read( cTmpBuf, nToRead );
121 aNewStream.Write( cTmpBuf, nToRead );
122 } while( nSize > nActRead );
124 return new SfxLockBytesItem( Which(), aNewStream );
127 // -----------------------------------------------------------------------
129 SvStream& SfxLockBytesItem::Store(SvStream &rStream, USHORT ) const
131 SvStream aLockBytesStream( _xVal );
132 sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END );
133 aLockBytesStream.Seek( 0L );
135 rStream << nSize;
136 rStream << aLockBytesStream;
138 return rStream;
141 //----------------------------------------------------------------------------
142 // virtual
143 BOOL SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE )
145 com::sun::star::uno::Sequence< sal_Int8 > aSeq;
146 if ( rVal >>= aSeq )
148 if ( aSeq.getLength() )
150 SvCacheStream* pStream = new SvCacheStream;
151 pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() );
152 pStream->Seek(0);
154 _xVal = new SvLockBytes( pStream, TRUE );
156 else
157 _xVal = NULL;
159 return TRUE;
162 DBG_ERROR( "SfxLockBytesItem::PutValue - Wrong type!" );
163 return FALSE;
166 //----------------------------------------------------------------------------
167 // virtual
168 BOOL SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal,BYTE ) const
170 if ( _xVal.Is() )
172 sal_uInt32 nLen;
173 SvLockBytesStat aStat;
175 if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
176 nLen = aStat.nSize;
177 else
178 return FALSE;
180 ULONG nRead = 0;
181 com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
183 _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
184 rVal <<= aSeq;
186 else
188 com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 );
189 rVal <<= aSeq;
192 return TRUE;