Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svl/lckbitem.hxx>
21 : #include <svl/poolitem.hxx>
22 : #include <com/sun/star/uno/Any.hxx>
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <tools/cachestr.hxx>
25 :
26 : // -----------------------------------------------------------------------
27 :
28 3 : TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem);
29 :
30 : // -----------------------------------------------------------------------
31 :
32 0 : SfxLockBytesItem::SfxLockBytesItem()
33 : {
34 0 : }
35 :
36 : // -----------------------------------------------------------------------
37 :
38 0 : SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvStream &rStream )
39 0 : : SfxPoolItem( nW )
40 : {
41 0 : rStream.Seek( 0L );
42 0 : _xVal = new SvLockBytes( new SvCacheStream(), sal_True );
43 :
44 0 : SvStream aLockBytesStream( _xVal );
45 0 : rStream >> aLockBytesStream;
46 0 : }
47 :
48 : // -----------------------------------------------------------------------
49 :
50 0 : SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem )
51 : : SfxPoolItem( rItem ),
52 0 : _xVal( rItem._xVal )
53 : {
54 0 : }
55 :
56 : // -----------------------------------------------------------------------
57 :
58 0 : SfxLockBytesItem::~SfxLockBytesItem()
59 : {
60 0 : }
61 :
62 : // -----------------------------------------------------------------------
63 :
64 0 : int SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
65 : {
66 0 : return ((SfxLockBytesItem&)rItem)._xVal == _xVal;
67 : }
68 :
69 : // -----------------------------------------------------------------------
70 :
71 0 : SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const
72 : {
73 0 : return new SfxLockBytesItem( *this );
74 : }
75 :
76 : // -----------------------------------------------------------------------
77 :
78 : #define MAX_BUF 32000
79 :
80 0 : SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, sal_uInt16 ) const
81 : {
82 0 : sal_uInt32 nSize = 0;
83 0 : sal_uLong nActRead = 0;
84 : sal_Char cTmpBuf[MAX_BUF];
85 0 : SvMemoryStream aNewStream;
86 0 : rStream >> nSize;
87 :
88 0 : do {
89 : sal_uLong nToRead;
90 0 : if( (nSize - nActRead) > MAX_BUF )
91 0 : nToRead = MAX_BUF;
92 : else
93 0 : nToRead = nSize - nActRead;
94 0 : nActRead += rStream.Read( cTmpBuf, nToRead );
95 0 : aNewStream.Write( cTmpBuf, nToRead );
96 : } while( nSize > nActRead );
97 :
98 0 : return new SfxLockBytesItem( Which(), aNewStream );
99 : }
100 :
101 : // -----------------------------------------------------------------------
102 :
103 0 : SvStream& SfxLockBytesItem::Store(SvStream &rStream, sal_uInt16 ) const
104 : {
105 0 : SvStream aLockBytesStream( _xVal );
106 0 : sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END );
107 0 : aLockBytesStream.Seek( 0L );
108 :
109 0 : rStream << nSize;
110 0 : rStream << aLockBytesStream;
111 :
112 0 : return rStream;
113 : }
114 :
115 : //----------------------------------------------------------------------------
116 : // virtual
117 0 : bool SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
118 : {
119 0 : com::sun::star::uno::Sequence< sal_Int8 > aSeq;
120 0 : if ( rVal >>= aSeq )
121 : {
122 0 : if ( aSeq.getLength() )
123 : {
124 0 : SvCacheStream* pStream = new SvCacheStream;
125 0 : pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() );
126 0 : pStream->Seek(0);
127 :
128 0 : _xVal = new SvLockBytes( pStream, sal_True );
129 : }
130 : else
131 0 : _xVal = NULL;
132 :
133 0 : return true;
134 : }
135 :
136 : OSL_FAIL( "SfxLockBytesItem::PutValue - Wrong type!" );
137 0 : return true;
138 : }
139 :
140 : //----------------------------------------------------------------------------
141 : // virtual
142 0 : bool SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
143 : {
144 0 : if ( _xVal.Is() )
145 : {
146 : sal_uInt32 nLen;
147 0 : SvLockBytesStat aStat;
148 :
149 0 : if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
150 0 : nLen = aStat.nSize;
151 : else
152 0 : return false;
153 :
154 0 : sal_uLong nRead = 0;
155 0 : com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
156 :
157 0 : _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
158 0 : rVal <<= aSeq;
159 : }
160 : else
161 : {
162 0 : com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 );
163 0 : rVal <<= aSeq;
164 : }
165 :
166 0 : return true;
167 : }
168 :
169 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|