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 <osl/diagnose.h>
23 : #include <com/sun/star/uno/Any.hxx>
24 : #include <com/sun/star/uno/Sequence.hxx>
25 :
26 :
27 :
28 22 : 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 SvMemoryStream(), true );
43 :
44 0 : SvStream aLockBytesStream( _xVal );
45 0 : rStream.ReadStream( 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 : bool SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
65 : {
66 0 : return static_cast<const 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.ReadUInt32( 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 0 : } 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.WriteUInt32( nSize );
110 0 : rStream.WriteStream( aLockBytesStream );
111 :
112 0 : return rStream;
113 : }
114 :
115 : // virtual
116 0 : bool SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
117 : {
118 0 : com::sun::star::uno::Sequence< sal_Int8 > aSeq;
119 0 : if ( rVal >>= aSeq )
120 : {
121 0 : if ( aSeq.getLength() )
122 : {
123 0 : SvMemoryStream* pStream = new SvMemoryStream();
124 0 : pStream->Write( aSeq.getConstArray(), aSeq.getLength() );
125 0 : pStream->Seek(0);
126 :
127 0 : _xVal = new SvLockBytes( pStream, true );
128 : }
129 : else
130 0 : _xVal = NULL;
131 :
132 0 : return true;
133 : }
134 :
135 : OSL_FAIL( "SfxLockBytesItem::PutValue - Wrong type!" );
136 0 : return true;
137 : }
138 :
139 : // virtual
140 0 : bool SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
141 : {
142 0 : if ( _xVal.Is() )
143 : {
144 : sal_uInt32 nLen;
145 0 : SvLockBytesStat aStat;
146 :
147 0 : if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE )
148 0 : nLen = aStat.nSize;
149 : else
150 0 : return false;
151 :
152 0 : sal_uLong nRead = 0;
153 0 : com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen );
154 :
155 0 : _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
156 0 : rVal <<= aSeq;
157 : }
158 : else
159 : {
160 0 : com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 );
161 0 : rVal <<= aSeq;
162 : }
163 :
164 0 : return true;
165 : }
166 :
167 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|