1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lckbitem.cxx,v $
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"
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
)
62 // -----------------------------------------------------------------------
64 SfxLockBytesItem::SfxLockBytesItem( USHORT nW
, SvStream
&rStream
)
68 _xVal
= new SvLockBytes( new SvCacheStream(), TRUE
);
70 SvStream
aLockBytesStream( _xVal
);
71 rStream
>> aLockBytesStream
;
74 // -----------------------------------------------------------------------
76 SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem
& rItem
)
77 : SfxPoolItem( rItem
),
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;
110 sal_Char cTmpBuf
[MAX_BUF
];
111 SvMemoryStream aNewStream
;
116 if( (nSize
- nActRead
) > MAX_BUF
)
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 );
136 rStream
<< aLockBytesStream
;
141 //----------------------------------------------------------------------------
143 BOOL
SfxLockBytesItem::PutValue( const com::sun::star::uno::Any
& rVal
, BYTE
)
145 com::sun::star::uno::Sequence
< sal_Int8
> aSeq
;
148 if ( aSeq
.getLength() )
150 SvCacheStream
* pStream
= new SvCacheStream
;
151 pStream
->Write( (void*)aSeq
.getConstArray(), aSeq
.getLength() );
154 _xVal
= new SvLockBytes( pStream
, TRUE
);
162 DBG_ERROR( "SfxLockBytesItem::PutValue - Wrong type!" );
166 //----------------------------------------------------------------------------
168 BOOL
SfxLockBytesItem::QueryValue( com::sun::star::uno::Any
& rVal
,BYTE
) const
173 SvLockBytesStat aStat
;
175 if ( _xVal
->Stat( &aStat
, SVSTATFLAG_DEFAULT
) == ERRCODE_NONE
)
181 com::sun::star::uno::Sequence
< sal_Int8
> aSeq( nLen
);
183 _xVal
->ReadAt( 0, aSeq
.getArray(), nLen
, &nRead
);
188 com::sun::star::uno::Sequence
< sal_Int8
> aSeq( 0 );