1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 #ifndef INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
57 #define INCLUDED_LOTUSWORDPRO_SOURCE_FILTER_BENTO_HXX
61 #include "lwpsvstream.hxx"
63 #define BEN_CC __stdcall
65 #define BEN_EXPORT __declspec(dllexport)
72 #include <tools/stream.hxx>
73 #include <sot/storage.hxx>
75 namespace OpenStormBento
78 #define BEN_CURR_MAJOR_VERSION 2
79 #define BEN_CURR_MINOR_VERSION 0
80 #define BEN_MAGIC_BYTES_SIZE 8
81 #define BEN_LABEL_SIZE 24
83 #define BEN_MAGIC_BYTES "\xA4""CM""\xA5""Hdr""\xD7"
88 BenErr_NameConflict
= 1,
89 BenErr_DuplicateObjectID
= 2,
90 BenErr_UnknownBentoFormatVersion
= 3,
91 BenErr_NamedObjectError
= 4,
92 BenErr_NamedObjectIllegalValue
= 5,
93 BenErr_InvalidTOC
= 6,
94 BenErr_64BitOffsetNotSupported
= 7,
95 BenErr_ReadPastEndOfTOC
= 8,
96 BenErr_ContainerWithNoObjects
= 9,
97 BenErr_ObjectWithNoProperties
= 10,
98 BenErr_PropertyWithNoValues
= 11,
99 BenErr_IllegalInMemoryTOC
= 12,
100 BenErr_PropertyAlreadyExists
= 13,
101 BenErr_UnexpectedEndOfFile
= 14,
102 BenErr_InvalidWriteOffset
= 15,
103 BenErr_InvalidImmediateWrite
= 16,
104 BenErr_TOCSeedError
= 17,
105 BenErr_ReadPastEndOfContainer
= 18,
106 BenErr_DuplicateName
= 19,
107 BenErr_BadReferencedList
= 20,
108 BenErr_IllegalContinuedImmediate
= 21,
109 BenErr_NotBentoContainer
= 22,
110 BenErr_PropertyWithMoreThanOneValue
= 23
112 // IMPORTANT - UtStream errors (UtErr_....) are also valid Bento
113 // errors. They have codes of 100 and higher. When, say, a Bento
114 // container open fails due to an access violation (somebody else, say,
115 // has it open exclusive), will get a UtErr code. If define own
116 // subclass of UtStream (custom handler), can define own error codes--
117 // those should start at 200
120 UtDefClassP(LtcBenContainer
);
121 UtDefClassP(CBenIDListElmt
);
122 UtDefClassP(CBenObject
);
123 UtDefClassP(CBenProperty
);
124 UtDefClassP(CBenReference
);
125 UtDefClassP(CBenValue
);
126 UtDefClassP(CBenValueSegment
);
127 UtDefClassP(CBenNamedObjectListElmt
);
128 UtDefClassP(CBenNamedObject
);
129 UtDefClassP(CBenPropertyName
);
130 UtDefClassP(CBenTypeName
);
132 typedef unsigned char BenByte
;
133 typedef unsigned short BenWord
;
134 typedef unsigned long BenDWord
;
135 typedef void * BenDataPtr
;
136 typedef const void * BenConstDataPtr
;
138 typedef unsigned long BenContainerPos
;
139 typedef unsigned long BenObjectID
;
140 typedef unsigned long BenGeneration
;
142 sal_uLong
BenOpenContainer(LwpSvStream
* pStream
, pLtcBenContainer
* ppContainer
);
144 class CBenIDListElmt
: public CUtListElmt
146 public: // Internal methods
147 CBenIDListElmt(BenObjectID ID
, pCUtListElmt pPrev
) : CUtListElmt(pPrev
)
149 CBenIDListElmt(BenObjectID ID
) { cID
= ID
; }
150 BenObjectID
GetID() { return cID
; }
156 class CBenNamedObjectListElmt
: public CUtListElmt
159 // added to remove warning
160 CBenNamedObjectListElmt(pCUtListElmt pPrev
) : CUtListElmt(pPrev
)
161 { cpNamedObject
= NULL
; }
162 void SetNamedObject(pCBenNamedObject pObj
)
164 cpNamedObject
= pObj
;
167 CBenNamedObjectListElmt(pCBenNamedObject pNamedObject
,
168 pCBenNamedObjectListElmt pPrev
) : CUtListElmt(pPrev
)
169 { cpNamedObject
= pNamedObject
; }
170 pCBenNamedObject
GetNamedObject() { return cpNamedObject
; }
173 pCBenNamedObject cpNamedObject
;
176 class LtcUtBenValueStream
: public SvStream
179 LtcUtBenValueStream(pCBenValue pValue
);
180 virtual ~LtcUtBenValueStream();
182 public: // Overridden methods
185 CBenValue
* GetValue(){ return cpValue
; };
186 sal_uLong
GetSize() { return m_ulValueLength
; };
187 protected: // Overridden methods
189 virtual sal_uLong
GetData( void* pData
, sal_uLong nSize
) SAL_OVERRIDE
;
190 virtual sal_uLong
PutData( const void* pData
, sal_uLong nSize
) SAL_OVERRIDE
;
191 virtual sal_uInt64
SeekPos( sal_uInt64 nPos
) SAL_OVERRIDE
;
192 virtual void SetSize( sal_uInt64 nSize
) SAL_OVERRIDE
;
193 virtual void FlushData() SAL_OVERRIDE
;
197 unsigned long cCurrentPosition
;
199 sal_uLong m_ulValueLength
; // Added by , sum of length of all sub-valuesegments
200 // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
203 class LtcBenContainer
207 BenError
RegisterPropertyName(const char * sPropertyName
,
208 pCBenPropertyName
* ppPropertyName
);
209 // Pass NULL to begin iteration. Done when returns NULL.
210 // Objects are returned in order of increasing ID
211 pCBenObject
GetNextObject(pCBenObject pCurrObject
);
212 pCBenObject
FindNextObjectWithProperty(pCBenObject pCurrObject
,
213 BenObjectID PropertyID
);
215 public: // Internal methods
216 LtcBenContainer(LwpSvStream
* pStream
);
219 BenError
Read(BenDataPtr pBuffer
, unsigned long MaxSize
,
220 unsigned long * pAmtRead
);
221 BenError
ReadKnownSize(BenDataPtr pBuffer
, unsigned long Amt
);
222 BenError
SeekToPosition(BenContainerPos Pos
);
223 BenError
SeekFromEnd(long Offset
);
225 BenObjectID
GetNextAvailObjectID() { return cNextAvailObjectID
; }
226 void SetNextAvailObjectID(BenObjectID ID
) { cNextAvailObjectID
= ID
; }
227 CUtList
& GetObjects() { return cObjects
; }
228 CUtList
& GetNamedObjects() { return cNamedObjects
; }
230 LtcUtBenValueStream
* FindNextValueStreamWithPropertyName(const char * sPropertyName
, LtcUtBenValueStream
* pCurrentValueStream
);
231 LtcUtBenValueStream
* FindValueStreamWithPropertyName(const char * sPropertyName
);
232 BenError
CreateGraphicStream(SvStream
* &pStream
, const char *pObjectName
);
234 BenError
GetSize(sal_uLong
* pLength
);
235 LwpSvStream
* GetStream()
240 CUtOwningList cObjects
;
241 CUtList cNamedObjects
;
242 LwpSvStream
* cpStream
;
243 sal_uLong m_ulLength
; // Added for TOCRead.cpp
244 BenObjectID cNextAvailObjectID
; // for new object
247 class CBenObject
: public CBenIDListElmt
250 pCBenProperty
UseProperty(BenObjectID PropertyID
);
251 pCBenValue
UseValue(BenObjectID PropertyID
);
252 virtual bool IsNamedObject();
253 pLtcBenContainer
GetContainer() { return cpContainer
; }
254 BenObjectID
GetObjectID() { return GetID(); }
255 public: // Internal methods
256 CBenObject(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
257 pCUtListElmt pPrev
) : CBenIDListElmt(ObjectID
, pPrev
)
258 { cpContainer
= pContainer
; }
259 CUtList
& GetProperties() { return cProperties
; }
262 pLtcBenContainer cpContainer
;
263 CUtOwningList cProperties
;
266 class CBenValue
: public CBenIDListElmt
269 unsigned long GetValueSize();
270 BenError
ReadValueData(BenDataPtr pBuffer
,
271 unsigned long Offset
, unsigned long MaxSize
, unsigned long * pAmtRead
);
273 pCBenProperty BEN_EXPORT
GetProperty() { return cpProperty
; }
275 public: // Internal methods
276 // added to remove WARNING
277 CBenValue(BenObjectID TypeID
):CBenIDListElmt(TypeID
)
280 cpReferencedList
= NULL
;
283 void SetProperty(pCBenProperty pProperty
)
285 cpProperty
= pProperty
;
288 CBenValue(pCBenProperty pProperty
, BenObjectID TypeID
) :
289 CBenIDListElmt(TypeID
)
291 cpProperty
= pProperty
;
292 cpReferencedList
= NULL
;
294 BenObjectID
GetTypeNameID() { return GetID(); }
295 inline pCBenValueSegment
GetNextValueSegment(pCBenValueSegment
297 inline pLtcBenContainer
GetContainer();
298 CUtList
& GetValueSegments() { return cValueSegments
; }
301 pCBenProperty cpProperty
;
302 CUtOwningList cValueSegments
;
303 pCBenValue cpReferencedList
;
306 class CBenProperty
: public CBenIDListElmt
309 // In the Apple Bento, a property can have multiple values, each of a
310 // different type. But we never use it that way, so in this code a
311 // property has exactly one value
313 CBenValue
& UseValue() { return cValue
; }
314 pCBenObject
GetBenObject() { return cpObject
; }
315 pLtcBenContainer
GetContainer() { return GetBenObject()->GetContainer(); }
317 public: // Internal methods
318 // changed to remove WARNING here
319 CBenProperty(pCBenObject pObject
, BenObjectID PropertyID
,
320 BenObjectID TypeID
, pCUtListElmt pPrevProperty
) :
321 CBenIDListElmt(PropertyID
, pPrevProperty
), cValue(TypeID
)
324 cValue
.SetProperty(this);
327 BenObjectID
GetPropertyNameID() { return GetID(); }
330 pCBenObject cpObject
;
334 // In our implementation, reference is always just the object ID for the
335 // object referenced (but you shouldn't assume that)
336 #define BEN_REFERENCE_SIZE 4
341 BenByte
* GetData() { return cData
; }
344 BenByte cData
[BEN_REFERENCE_SIZE
];
347 class CBenValueSegment
: public CUtListElmt
349 public: // Internal methods
350 CBenValueSegment(pCBenValue pValue
, BenContainerPos Pos
,
351 unsigned long Size
) : CUtListElmt(&pValue
->GetValueSegments())
352 { cpValue
= pValue
; cImmediate
= false; cPos
= Pos
;
354 CBenValueSegment(pCBenValue pValue
, BenConstDataPtr pImmData
,
355 unsigned short Size
) : CUtListElmt(&pValue
->GetValueSegments())
356 { cpValue
= pValue
; cImmediate
= true;
357 UtHugeMemcpy(cImmData
, pImmData
, Size
); cSize
= Size
; }
358 CBenValueSegment(BenContainerPos Pos
, unsigned long Size
)
359 { cpValue
= NULL
; cImmediate
= false; cPos
= Pos
;
361 CBenValueSegment(BenConstDataPtr pImmData
, unsigned short Size
)
362 { cpValue
= NULL
; cImmediate
= true;
363 UtHugeMemcpy(cImmData
, pImmData
, Size
); cSize
= Size
; }
366 return cpValue
== NULL
|| cpValue
->GetValueSegments().GetLast() ==
369 bool IsImmediate() { return cImmediate
; }
370 BenContainerPos
GetPosition() { return cPos
; }
371 unsigned long GetSize() { return cSize
; }
372 void SetSize(unsigned long Size
) { cSize
= Size
; }
373 BenByte
* GetImmediateData() { return cImmData
; }
380 BenContainerPos cPos
;
386 inline pCBenValueSegment
CBenValue::GetNextValueSegment(pCBenValueSegment
388 { return static_cast<pCBenValueSegment
>( cValueSegments
.GetNextOrNULL(pCurrValueSegment
) ); }
390 inline pLtcBenContainer
CBenValue::GetContainer()
391 { return GetProperty()->GetContainer(); }
393 class CBenNamedObject
: public CBenObject
396 virtual bool IsNamedObject() SAL_OVERRIDE
;
397 virtual bool IsPropertyName();
398 virtual bool IsTypeName();
400 public: // Internal methods
401 CBenNamedObject(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
402 pCBenObject pPrevObject
, const char * sName
,
403 pCUtListElmt pPrevNamedObjectListElmt
);
404 const char * GetName() { return csName
.data(); }
406 const char * GetNameCStr() { return csName
.c_str(); }
408 void SetPosition(BenContainerPos Pos
) { cPos
= Pos
; }
409 BenContainerPos
GetPosition() { return cPos
; }
410 size_t GetLength() { return csName
.length()+ 1; }
411 CBenNamedObjectListElmt
& GetNameListElmt() { return cNameListElmt
; }
415 CBenNamedObjectListElmt cNameListElmt
;
416 BenContainerPos cPos
;
419 class CBenPropertyName
: public CBenNamedObject
421 public: // Internal methods
422 CBenPropertyName(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
423 pCBenObject pPrevObject
, const char * sName
,
424 pCUtListElmt pPrevNamedObjectListElmt
) :
425 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, sName
,
426 pPrevNamedObjectListElmt
) { ; }
427 virtual bool IsPropertyName() SAL_OVERRIDE
;
430 class CBenTypeName
: public CBenNamedObject
432 public: // Internal methods
433 CBenTypeName(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
434 pCBenObject pPrevObject
, const char * sName
,
435 pCUtListElmt pPrevNamedObjectListElmt
) :
436 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, sName
,
437 pPrevNamedObjectListElmt
) { ; }
438 virtual bool IsTypeName() SAL_OVERRIDE
;
441 } // end namespace OpenStormBento
444 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */