merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / bento.hxx
blobf8e408decab081dc7bbb99b9e241550c1deb933f
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 #ifndef BENTO_H
56 #define BENTO_H
58 #include <string>
59 #include <vector>
60 #include "lwpsvstream.hxx"
62 #define BEN_CC __stdcall
63 #ifdef COMP_BENTO
64 #define BEN_EXPORT __declspec(dllexport)
65 #else
66 #define BEN_EXPORT
67 #endif
69 using namespace std;
71 #include "ut.hxx"
72 #include "utlist.hxx"
73 // removed for WordPro filter, 2005-01-27
74 //#include <scerrors.hxx> // error code defined for SC
75 //#include <filter.hxx> // error code defined for SC filters
76 #include <tools/stream.hxx> // SvStream definition
77 #include <sot/storage.hxx> // SotStorageStream definition, add by 10/24/2005
79 namespace OpenStormBento
82 #define BEN_CURR_MAJOR_VERSION 2
83 #define BEN_CURR_MINOR_VERSION 0
84 #define BEN_MAGIC_BYTES_SIZE 8
85 #define BEN_LABEL_SIZE 24
87 #define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
88 //For Ole2DirectoryStruct, Add by 10/24/2005
89 #define BEN_STGTY_STORAGE 1
90 #define BEN_STGTY_STREAM 2
91 #define ASWENTRY_SIZE 204
92 struct ClsId
94 INT32 n1;
95 INT16 n2, n3;
96 UINT8 n4, n5, n6, n7, n8, n9, n10, n11;
98 class AswEntry //total length: 204
100 UINT16 nName[ 68 ]; //Name of IStorage or IStream referenced by this entry, length = 136
101 INT32 nMtime[ 2 ];
102 INT32 nCtime[ 2 ];
103 INT32 nAtime[ 2 ];
104 ClsId aClsId; //CLSID from OLE 2 IStorage::SetClass call
105 UINT32 nStatebits; //State bits from OLE 2 IStorage::SetStateBits call
106 UINT32 nType; // STGTY_STORAGE: 1 or STGTY_STREAM:2,
107 UINT32 nObjectIDRef; //Persistent Bento reference to Bento object for this IStorage or IStream
108 UINT32 nMversion;
109 UINT32 nLversion;
110 UINT32 nReserved[2]; //skip 16 char
111 public:
112 AswEntry();
113 void Init(); // initialize the data
114 void SetName( const String& ); // store a name (ASCII, up to 32 chars)
115 void GetName( String& rName ) const;
116 void Load( const void* );
117 void Store( void* );
118 UINT32 GetType() const { return nType; }
119 void SetType( UINT32 t ) { nType = t;}
120 const ClsId& GetClassId() const { return aClsId;}
121 void SetClassId( const ClsId& );
122 void SetObjectID(UINT32 id) { nObjectIDRef = id;}
123 UINT32 GetObjectID() const { return nObjectIDRef;}
125 //End by
127 enum BenError
129 BenErr_OK = 0,
130 BenErr_NameConflict = 1,
131 BenErr_DuplicateObjectID = 2,
132 BenErr_UnknownBentoFormatVersion = 3,
133 BenErr_NamedObjectError = 4,
134 BenErr_NamedObjectIllegalValue = 5,
135 BenErr_InvalidTOC = 6,
136 BenErr_64BitOffsetNotSupported = 7,
137 BenErr_ReadPastEndOfTOC = 8,
138 BenErr_ContainerWithNoObjects = 9,
139 BenErr_ObjectWithNoProperties = 10,
140 BenErr_PropertyWithNoValues = 11,
141 BenErr_IllegalInMemoryTOC = 12,
142 BenErr_PropertyAlreadyExists = 13,
143 BenErr_UnexpectedEndOfFile = 14,
144 BenErr_InvalidWriteOffset = 15,
145 BenErr_InvalidImmediateWrite = 16,
146 BenErr_TOCSeedError = 17,
147 BenErr_ReadPastEndOfContainer = 18,
148 BenErr_DuplicateName = 19,
149 BenErr_BadReferencedList = 20,
150 BenErr_IllegalContinuedImmediate = 21,
151 BenErr_NotBentoContainer = 22,
152 BenErr_PropertyWithMoreThanOneValue = 23
154 // IMPORTANT - UtStream errors (UtErr_....) are also valid Bento
155 // errors. They have codes of 100 and higher. When, say, a Bento
156 // container open fails due to an access violation (somebody else, say,
157 // has it open exclusive), will get a UtErr code. If define own
158 // subclass of UtStream (custom handler), can define own error codes--
159 // those should start at 200
162 * These two functions are useless in SODC
164 inline UtError BenToUtError(BenError Err)
166 if (Err == 0 || Err >= 100)
167 return (UtError) Err;
168 else return UtErr_Fail;
171 inline BenError UtToBenError(UtError Err)
172 { UT_ASSERT(Err == 0 || Err >= 100); return (BenError) Err; }
173 enum BenSeekMode {
174 BenSeek_FromStart = 1,
175 BenSeek_FromCurr = 2,
176 BenSeek_FromEnd = 3
180 UtDefClassP(LtcBenContainer);
181 UtDefClassP(CBenIDListElmt);
182 UtDefClassP(CBenObject);
183 UtDefClassP(CBenProperty);
184 UtDefClassP(CBenReference);
185 UtDefClassP(CBenValue);
186 UtDefClassP(CBenValueSegment);
187 UtDefClassP(CBenNamedObjectListElmt);
188 UtDefClassP(CBenNamedObject);
189 UtDefClassP(CBenPropertyName);
190 UtDefClassP(CBenTypeName);
192 typedef unsigned char BenByte;
193 typedef unsigned short BenWord;
194 typedef unsigned long BenDWord;
195 typedef void * BenDataPtr;
196 typedef const void * BenConstDataPtr;
198 typedef unsigned long BenContainerPos;
199 typedef unsigned long BenObjectID;
200 typedef unsigned long BenGeneration;
202 ULONG BenOpenContainer(LwpSvStream * pStream, pLtcBenContainer * ppContainer);
204 class CBenIDListElmt : public CUtListElmt
206 public: // Internal methods
207 CBenIDListElmt(BenObjectID ID, pCBenIDListElmt pPrev) : CUtListElmt(pPrev)
208 { cID = ID; }
209 CBenIDListElmt(BenObjectID ID) { cID = ID; }
210 BenObjectID GetID() { return cID; }
212 private: // Data
213 BenObjectID cID;
216 class CBenNamedObjectListElmt : public CUtListElmt
218 public: // Methods
219 // added by to remove warning 2004-06-24
220 CBenNamedObjectListElmt(pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
221 { cpNamedObject = NULL; }
222 void SetNamedObject(pCBenNamedObject pObj)
224 cpNamedObject = pObj;
227 CBenNamedObjectListElmt(pCBenNamedObject pNamedObject,
228 pCBenNamedObjectListElmt pPrev) : CUtListElmt(pPrev)
229 { cpNamedObject = pNamedObject; }
230 pCBenNamedObject GetNamedObject() { return cpNamedObject; }
232 private: // Data
233 pCBenNamedObject cpNamedObject;
236 class LtcUtBenValueStream : public SvStream
238 public:
239 LtcUtBenValueStream(pCBenValue pValue);
240 ~LtcUtBenValueStream();
242 public: // Overridden methods
243 #if 0 // Deleted by 2004-06-16
244 UtError Open(UtBool /* OpenNew */, UtStrmOpenFlags /* Flags */);
245 UtError Close();
246 UtError Seek(long Offset, UtSeekMode Mode);
247 UtError GetPosition(unsigned long * pPosition);
248 UtError GetSize(unsigned long * pSize);
249 UtError Read(UtStrmDataPtr pBuffer, unsigned long MaxSize,
250 unsigned long * pAmtRead);
251 UtError Write(UtConstStrmDataPtr pBuffer, unsigned long Size,
252 unsigned long * pAmtWritten);
253 UtError Flush();
254 #endif
256 /* added by */
257 CBenValue * GetValue(){ return cpValue; };
258 ULONG GetSize() { return m_ulValueLength; };
259 protected: // Overridden methods
261 virtual ULONG GetData( void* pData, ULONG nSize );
262 virtual ULONG PutData( const void* pData, ULONG nSize );
263 virtual ULONG SeekPos( ULONG nPos );
264 virtual void SetSize( ULONG nSize );
265 virtual void FlushData();
267 #if 0// Deleted by 2004-06-16
268 UtError TruncateSize(unsigned long Size);
269 #endif
270 private: // Data
271 pCBenValue cpValue;
272 unsigned long cCurrentPosition;
274 ULONG m_ulValueLength; // Added by , sum of length of all sub-valuesegments
275 // void GetAmountLeft(ULONG * pAmtLeft); useless in SODC
278 class LtcBenContainer
280 public:
281 BenError Open();
282 void Release(); // Deletes container object--last call
283 BenError Close();
284 BenError RegisterTypeName(const char * sTypeName,
285 pCBenTypeName * ppTypeName);
286 BenError RegisterPropertyName(const char * sPropertyName,
287 pCBenPropertyName * ppPropertyName);
288 // Pass NULL to begin iteration. Done when returns NULL.
289 // Objects are returned in order of increasing ID
290 pCBenObject GetNextObject(pCBenObject pCurrObject);
291 pCBenObject FindObject(BenObjectID ObjectID);
292 pCBenObject FindNextObjectWithProperty(pCBenObject pCurrObject,
293 BenObjectID PropertyID);
294 BenError BEN_EXPORT NewObject(pCBenObject * ppBenObject);
296 public: // Internal methods
297 LtcBenContainer(LwpSvStream * pStream);
298 ~LtcBenContainer();
300 BenError Read(BenDataPtr pBuffer, unsigned long MaxSize,
301 unsigned long * pAmtRead);
302 BenError ReadKnownSize(BenDataPtr pBuffer, unsigned long Amt);
303 BenError SeekToPosition(BenContainerPos Pos);
304 BenError SeekFromEnd(long Offset);
306 BenError GetPosition(BenContainerPos * pPosition);
308 BenObjectID GetNextAvailObjectID() { return cNextAvailObjectID; }
309 void SetNextAvailObjectID(BenObjectID ID) { cNextAvailObjectID = ID; }
310 pCUtList GetObjects() { return &cObjects; }
311 pCUtList GetNamedObjects() { return &cNamedObjects; }
313 // Added by 2004-06-10
314 LtcUtBenValueStream * FindNextValueStreamWithPropertyName(const char * sPropertyName, LtcUtBenValueStream * pCurrentValueStream);
315 LtcUtBenValueStream * FindValueStreamWithPropertyName(const char * sPropertyName);
316 LtcUtBenValueStream * FindObjectValueStreamWithObjectIDAndProperty(BenObjectID ObjectID, const char * sPropertyName);
317 BenError CreateGraphicStreams(std::vector<SvStream *> * pStreamVector) ;
318 BenError CreateGraphicStream(SvStream * &pStream, const char *pObjectName);
319 //Add by 10/24/2005
320 SotStorageStreamRef ConvertAswStorageToOLE2Stream(const char * sObjectName);
321 LtcUtBenValueStream * FindOLEStorageStreamWithObjectName(const char * sObjectName, AswEntry& rDirStruct);
322 void ReadAswEntry(SvStream * pStream, AswEntry& rEntry);
324 BenError GetSize(ULONG * pLength);
325 LwpSvStream * GetStream()
327 return cpStream;
329 private: // Data
330 CUtOwningList cObjects;
331 CUtList cNamedObjects;
332 LwpSvStream * cpStream;
333 ULONG m_ulLength; // Added for TOCRead.cpp
334 BenObjectID cNextAvailObjectID; // for new object
337 class CBenObject : public CBenIDListElmt
339 public:
340 pCBenProperty GetNextProperty(pCBenProperty pCurrProperty);
341 pCBenProperty UseProperty(BenObjectID PropertyID);
342 void DeleteProperty(pCBenProperty pProperty);
343 pCBenValue UseValue(BenObjectID PropertyID);
344 pCBenValue UseSingleValue();
345 // Inefficient to use this method if will use property multiple times--
346 // instead register property and call UseProperty with property ID
347 pCBenValue UseValueWithPropertyName(const char * sPropertyName);
348 virtual UtBool IsNamedObject();
349 pLtcBenContainer GetContainer() { return cpContainer; }
350 BenObjectID GetObjectID() { return GetID(); }
351 BenError BEN_EXPORT NewValue(BenObjectID PropertyID, BenObjectID TypeID,
352 pCBenValue * ppValue);
353 public: // Internal methods
354 CBenObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
355 pCBenIDListElmt pPrev) : CBenIDListElmt(ObjectID, pPrev)
356 { cpContainer = pContainer; }
357 pCUtList GetProperties() { return &cProperties; }
359 private: // Data
360 pLtcBenContainer cpContainer;
361 CUtOwningList cProperties;
364 class CBenValue : public CBenIDListElmt
366 public:
367 unsigned long GetValueSize();
368 BenError ReadValueData(BenDataPtr pBuffer,
369 unsigned long Offset, unsigned long MaxSize, unsigned long * pAmtRead);
370 BenError ReadValueDataKnownSize(BenDataPtr pBuffer,
371 unsigned long Offset, unsigned long Amt);
373 BenError BEN_EXPORT WriteValueData(BenConstDataPtr pBuffer,
374 unsigned long Offset, unsigned long Size);
375 BenError BEN_EXPORT WriteValueData(BenConstDataPtr pBuffer,
376 unsigned long Offset, unsigned long Size, unsigned long * pAmtWritten);
377 BenError BEN_EXPORT WriteImmediateValueData(BenConstDataPtr pBuffer,
378 unsigned short Size);
379 BenError BEN_EXPORT TruncateValueSize(unsigned long NewSize);
380 BenError BEN_EXPORT NewReference(BenObjectID ReferencedObjectID,
381 pCBenReference pReference);
382 BenObjectID BEN_EXPORT GetReferencedObject(pCBenReference pReference);
385 pCBenProperty BEN_EXPORT GetProperty() { return cpProperty; }
387 public: // Internal methods
388 // added by to remove WARNING 2004-06-24
389 CBenValue(BenObjectID TypeID):CBenIDListElmt(TypeID)
391 cpProperty = NULL;
392 cpReferencedList = NULL;
395 void SetProperty(pCBenProperty pProperty)
397 cpProperty = pProperty;
400 CBenValue(pCBenProperty pProperty, BenObjectID TypeID) :
401 CBenIDListElmt(TypeID)
403 cpProperty = pProperty;
404 cpReferencedList = NULL;
406 BenObjectID GetTypeNameID() { return GetID(); }
407 inline pCBenValueSegment GetNextValueSegment(pCBenValueSegment
408 pCurrValueSegment);
409 inline pLtcBenContainer GetContainer();
410 pCUtList GetValueSegments() { return &cValueSegments; }
411 BenObjectID GetReferencedListID();
412 // Currently, no generation support
413 BenGeneration GetGeneration() { return 1; }
415 private: // Data
416 pCBenProperty cpProperty;
417 CUtOwningList cValueSegments;
418 pCBenValue cpReferencedList;
419 unsigned long cReferencedObjectsSize;
422 class CBenProperty : public CBenIDListElmt
424 public:
425 // In the Apple Bento, a property can have multiple values, each of a
426 // different type. But we never use it that way, so in this code a
427 // property has exactly one value
429 pCBenValue UseValue() { return &cValue; }
430 pCBenObject GetBenObject() { return cpObject; }
431 pLtcBenContainer GetContainer() { return GetBenObject()->GetContainer(); }
433 public: // Internal methods
434 #if 0
435 CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
436 BenObjectID TypeID, pCBenIDListElmt pPrevProperty) :
437 CBenIDListElmt(PropertyID, pPrevProperty), cValue(this, TypeID)
438 { cpObject = pObject; }
439 #endif
440 // changed by to remove WARNING here 2004-06-24
441 CBenProperty(pCBenObject pObject, BenObjectID PropertyID,
442 BenObjectID TypeID, pCBenIDListElmt pPrevProperty) :
443 CBenIDListElmt(PropertyID, pPrevProperty), cValue(TypeID)
445 cpObject = pObject;
446 cValue.SetProperty(this);
449 BenObjectID GetPropertyNameID() { return GetID(); }
451 private: // Data
452 pCBenObject cpObject;
453 CBenValue cValue;
456 // In our implementation, reference is always just the object ID for the
457 // object referenced (but you shouldn't assume that)
458 #define BEN_REFERENCE_SIZE 4
460 class CBenReference
462 public: // Methods
463 BenByte * GetData() { return cData; }
465 private: // Data
466 BenByte cData[BEN_REFERENCE_SIZE];
469 class CBenValueSegment : public CUtListElmt
471 public: // Internal methods
472 CBenValueSegment(pCBenValue pValue, BenContainerPos Pos,
473 unsigned long Size) : CUtListElmt(pValue->GetValueSegments())
474 { cpValue = pValue; cImmediate = UT_FALSE; cPos = Pos;
475 cSize = Size; }
476 CBenValueSegment(pCBenValue pValue, BenConstDataPtr pImmData,
477 unsigned short Size) : CUtListElmt(pValue->GetValueSegments())
478 { cpValue = pValue; cImmediate = UT_TRUE;
479 UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
480 CBenValueSegment(BenContainerPos Pos, unsigned long Size)
481 { cpValue = NULL; cImmediate = UT_FALSE; cPos = Pos;
482 cSize = Size; }
483 CBenValueSegment(BenConstDataPtr pImmData, unsigned short Size)
484 { cpValue = NULL; cImmediate = UT_TRUE;
485 UtHugeMemcpy(cImmData, pImmData, Size); cSize = Size; }
486 UtBool IsLast()
488 return cpValue == NULL || cpValue->GetValueSegments()->GetLast() ==
489 this;
491 UtBool IsImmediate() { return cImmediate; }
492 BenContainerPos GetPosition() { return cPos; }
493 unsigned long GetSize() { return cSize; }
494 void SetSize(unsigned long Size) { cSize = Size; }
495 BenByte * GetImmediateData() { return cImmData; }
497 private: // Data
498 pCBenValue cpValue;
499 UtBool cImmediate;
500 union
502 BenContainerPos cPos;
503 BenByte cImmData[4];
505 unsigned long cSize;
508 inline pCBenValueSegment CBenValue::GetNextValueSegment(pCBenValueSegment
509 pCurrValueSegment)
510 { return (pCBenValueSegment) cValueSegments.GetNextOrNULL(pCurrValueSegment); }
512 inline pLtcBenContainer CBenValue::GetContainer()
513 { return GetProperty()->GetContainer(); }
515 class CBenNamedObject : public CBenObject
517 public: // Methods
518 virtual UtBool IsNamedObject();
519 virtual UtBool IsPropertyName();
520 virtual UtBool IsTypeName();
522 public: // Internal methods
523 CBenNamedObject(pLtcBenContainer pContainer, BenObjectID ObjectID,
524 pCBenObject pPrevObject, const char * sName,
525 pCBenNamedObjectListElmt pPrevNamedObjectListElmt);
526 const char * GetName() { return csName.data(); }
529 const char * GetNameCStr() { return csName.c_str(); }
532 void SetPosition(BenContainerPos Pos) { cPos = Pos; }
533 BenContainerPos GetPosition(void) { return cPos; }
534 size_t GetLength(void) { return csName.length()+ 1; }
535 pCBenNamedObjectListElmt GetNameListElmt() { return &cNameListElmt; }
537 private: // Data
538 string csName;
539 CBenNamedObjectListElmt cNameListElmt;
540 BenContainerPos cPos;
543 class CBenPropertyName : public CBenNamedObject
545 public: // Internal methods
546 CBenPropertyName(pLtcBenContainer pContainer, BenObjectID ObjectID,
547 pCBenObject pPrevObject, const char * sName,
548 pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
549 CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
550 pPrevNamedObjectListElmt) { ; }
551 virtual UtBool IsPropertyName();
554 class CBenTypeName : public CBenNamedObject
556 public: // Internal methods
557 CBenTypeName(pLtcBenContainer pContainer, BenObjectID ObjectID,
558 pCBenObject pPrevObject, const char * sName,
559 pCBenNamedObjectListElmt pPrevNamedObjectListElmt) :
560 CBenNamedObject(pContainer, ObjectID, pPrevObject, sName,
561 pPrevNamedObjectListElmt) { ; }
562 virtual UtBool IsTypeName();
566 } // end namespace OpenStormBento
567 #endif