merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / utbenvs.cxx
blobef78c01cdebdcab25960025e56064caea7bcc98b
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 #include "first.hxx"
56 #include <assert.h>
57 namespace OpenStormBento
60 * useless in SODC
61 void LtcUtBenValueStream::GetAmountLeft(ULONG * pAmtLeft)
63 if (cCurrentPosition >= m_ulValueLength)
65 *pAmtLeft = 0;
67 else
69 *pAmtLeft = m_ulValueLength - cCurrentPosition;
73 /**
74 * Value stream read function
75 * @date 07/05/2004
76 * @param data pointer of bytes read
77 * @param number of bytes to be read
78 * @return number of bytes read
80 ULONG LtcUtBenValueStream::GetData( void* pData, ULONG nSize )
82 //unsigned long AmtLeft;
83 ULONG AmtRead;
84 //GetAmountLeft(&AmtLeft);
86 //unsigned long AmtShouldRead = UtMin(nSize, AmtLeft);
87 BenError Err = cpValue->ReadValueData(pData, cCurrentPosition, nSize,
88 &AmtRead);
89 cCurrentPosition += AmtRead;
91 return AmtRead;
93 /**
94 * Value stream write function, not suppoted now
95 * @date 07/05/2004
96 * @param pointer of saved buffer
97 * @param size of buffer to be written
98 * @return number of bytes written into value stream
100 ULONG LtcUtBenValueStream::PutData( const void* pData, ULONG nSize )
102 /* Because we only support IMPORT filter, PutData implementation is ignored
103 It won't bring negative influence to read-only stream object */
104 assert(false);
105 return nSize;
108 * Seek function of value stream
109 * @date 07/05/2004
110 * @param position in value stream
111 * @return current position in value stream
113 ULONG LtcUtBenValueStream::SeekPos( ULONG nPos )
115 if (nPos <= m_ulValueLength)
116 cCurrentPosition = nPos;
117 else
118 cCurrentPosition = m_ulValueLength;
119 return cCurrentPosition;
122 * Set buffer size function
123 * @date 07/05/2004
124 * @param size of buffer
125 * @return
127 void LtcUtBenValueStream::SetSize( ULONG nSize )
129 pLtcBenContainer pContainer = cpValue->GetContainer();
130 //pContainer->GetStream()->SetStreamSize(nSize);
132 return;
135 * Flush data funciton, not supported now
136 * @date 07/05/2004
137 * @param
138 * @return
140 void LtcUtBenValueStream::FlushData()
142 /* Because we only support IMPORT filter, FlushData implementation is ignored
143 It won't bring negative influence to read-only stream object
144 pLtcBenContainer pContainer = cpValue->GetContainer();
145 pContainer->GetStream()->Flush();*/
146 assert(false);
147 return;
150 * Construction
151 * @date 07/05/2004
152 * @param pointer to CBenValue object
153 * @return
155 LtcUtBenValueStream::LtcUtBenValueStream(pCBenValue pValue)
157 // Calculate the length of the whole value stream
158 cCurrentPosition = 0;
159 m_ulValueLength = pValue->GetValueSize();
160 cpValue = pValue;
163 LtcUtBenValueStream::~LtcUtBenValueStream()
166 #if 0 // Deleted by 2004-06-16
167 UtError
168 CUtBenValueStream::Open(UtBool /* OpenNew */, UtStrmOpenFlags /* Flags */)
170 cCurrentPosition = 0;
171 return UtErr_OK;
174 UtError
175 CUtBenValueStream::Close()
177 return UtErr_OK;
180 UtError
181 CUtBenValueStream::Seek(long Offset, UtSeekMode Mode)
183 unsigned long NewPos;
185 if (Mode == UtSeek_FromStart)
186 NewPos = (unsigned long) Offset;
187 else if (Mode == UtSeek_FromCurr)
189 if (Offset < 0 && cCurrentPosition < (unsigned long) -Offset)
190 return UtErr_SeekError;
191 NewPos = cCurrentPosition + Offset;
193 else if (Mode == UtSeek_FromEnd)
195 unsigned long ValueSize = cpValue->GetValueSize();
196 if (Offset < 0 && ValueSize < (unsigned long) -Offset)
197 return UtErr_SeekError;
198 NewPos = ValueSize + Offset;
200 else
202 UT_ASSERT(! "Illegal seek");
203 return UtErr_SeekError;
206 cCurrentPosition = NewPos;
207 return UtErr_OK;
210 UtError
211 CUtBenValueStream::GetPosition(unsigned long * pPosition)
213 *pPosition = cCurrentPosition;
214 return UtErr_OK;
217 UtError
218 CUtBenValueStream::GetSize(unsigned long * pSize)
220 *pSize = cpValue->GetValueSize();
221 return UtErr_OK;
224 UtError
225 CUtBenValueStream::Read(UtStrmDataPtr pBuffer, unsigned long MaxSize,
226 unsigned long * pAmtRead)
228 unsigned long AmtLeft;
229 GetAmountLeft(&AmtLeft);
231 unsigned long AmtShouldRead = UtMin(MaxSize, AmtLeft);
233 BenError Err = cpValue->ReadValueData(pBuffer, cCurrentPosition, MaxSize,
234 pAmtRead);
235 cCurrentPosition += *pAmtRead;
237 return BenToUtError(Err);
240 UtError
241 CUtBenValueStream::Write(UtConstStrmDataPtr pBuffer, unsigned long Size,
242 unsigned long * pAmtWritten)
244 BenError Err;
246 *pAmtWritten = 0;
248 // IStream::Write semantics are that when write zero bytes, doesn't fill
249 // in gap
250 if (Size == 0)
251 return UtErr_OK;
253 // See if anybody exercies code below
254 //UT_ASSERT(cCurrentPosition <= (long) cpValue->GetValueSize());
256 // Fill out "gap" in data, if there is one, with nulls
257 while (cCurrentPosition > cpValue->GetValueSize())
258 if ((Err = cpValue->WriteValueData("", cpValue->GetValueSize(), 1,
259 NULL)) != BenErr_OK)
260 return BenToUtError(Err);
262 unsigned long AmtWritten;
263 Err = cpValue->WriteValueData(pBuffer, cCurrentPosition, Size,
264 &AmtWritten);
266 //UT_ASSERT(Size == AmtWritten);
268 cCurrentPosition += AmtWritten;
270 *pAmtWritten = AmtWritten;
272 return BenToUtError(Err);
275 UtError
276 CUtBenValueStream::TruncateSize(unsigned long Size)
278 return BenToUtError(cpValue->TruncateValueSize(Size));
281 UtError
282 CUtBenValueStream::Flush()
284 return UtErr_OK;
287 #endif
288 } // end namespace OpenStormBento