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
;
136 typedef unsigned long BenContainerPos
;
137 typedef unsigned long BenObjectID
;
138 typedef unsigned long BenGeneration
;
140 sal_uLong
BenOpenContainer(LwpSvStream
* pStream
, pLtcBenContainer
* ppContainer
);
142 class CBenIDListElmt
: public CUtListElmt
144 public: // Internal methods
145 CBenIDListElmt(BenObjectID ID
, pCUtListElmt pPrev
) : CUtListElmt(pPrev
)
147 explicit CBenIDListElmt(BenObjectID ID
) { cID
= ID
; }
148 BenObjectID
GetID() { return cID
; }
154 class CBenNamedObjectListElmt
: public CUtListElmt
157 // added to remove warning
158 explicit CBenNamedObjectListElmt(pCUtListElmt pPrev
) : CUtListElmt(pPrev
)
159 { cpNamedObject
= nullptr; }
160 void SetNamedObject(pCBenNamedObject pObj
)
162 cpNamedObject
= pObj
;
165 pCBenNamedObject
GetNamedObject() { return cpNamedObject
; }
168 pCBenNamedObject cpNamedObject
;
171 class LtcUtBenValueStream
: public SvStream
174 explicit LtcUtBenValueStream(pCBenValue pValue
);
175 virtual ~LtcUtBenValueStream() override
;
177 public: // Overridden methods
180 sal_uLong
GetSize() { return m_ulValueLength
; };
181 protected: // Overridden methods
183 virtual std::size_t GetData(void* pData
, std::size_t nSize
) override
;
184 virtual std::size_t PutData(const void* pData
, std::size_t nSize
) override
;
185 virtual sal_uInt64
SeekPos( sal_uInt64 nPos
) override
;
186 virtual void SetSize( sal_uInt64 nSize
) override
;
187 virtual void FlushData() override
;
191 unsigned long cCurrentPosition
;
193 sal_uLong m_ulValueLength
; // Added by , sum of length of all sub-valuesegments
194 // void GetAmountLeft(sal_uLong * pAmtLeft); useless in SODC
197 class LtcBenContainer
201 void RegisterPropertyName(const char * sPropertyName
,
202 pCBenPropertyName
* ppPropertyName
);
203 // Pass NULL to begin iteration. Done when returns NULL.
204 // Objects are returned in order of increasing ID
205 pCBenObject
GetNextObject(pCBenObject pCurrObject
);
206 pCBenObject
FindNextObjectWithProperty(pCBenObject pCurrObject
,
207 BenObjectID PropertyID
);
209 public: // Internal methods
210 explicit LtcBenContainer(LwpSvStream
* pStream
);
213 BenError
Read(void * pBuffer
, unsigned long MaxSize
,
214 unsigned long * pAmtRead
);
215 BenError
ReadKnownSize(void * pBuffer
, unsigned long Amt
);
216 BenError
SeekToPosition(BenContainerPos Pos
);
217 BenError
SeekFromEnd(long Offset
);
219 void SetNextAvailObjectID(BenObjectID ID
) { cNextAvailObjectID
= ID
; }
220 CUtList
& GetObjects() { return cObjects
; }
221 CUtList
& GetNamedObjects() { return cNamedObjects
; }
223 LtcUtBenValueStream
* FindNextValueStreamWithPropertyName(const char * sPropertyName
);
224 LtcUtBenValueStream
* FindValueStreamWithPropertyName(const char * sPropertyName
);
225 void CreateGraphicStream(SvStream
* &pStream
, const char *pObjectName
);
227 BenError
GetSize(sal_uLong
* pLength
);
229 CUtOwningList cObjects
;
230 CUtList cNamedObjects
;
231 LwpSvStream
* cpStream
;
232 sal_uLong m_ulLength
; // Added for TOCRead.cpp
233 BenObjectID cNextAvailObjectID
; // for new object
236 class CBenObject
: public CBenIDListElmt
239 pCBenProperty
UseProperty(BenObjectID PropertyID
);
240 pCBenValue
UseValue(BenObjectID PropertyID
);
241 pLtcBenContainer
GetContainer() { return cpContainer
; }
242 public: // Internal methods
243 CBenObject(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
244 pCUtListElmt pPrev
) : CBenIDListElmt(ObjectID
, pPrev
)
245 { cpContainer
= pContainer
; }
246 CUtList
& GetProperties() { return cProperties
; }
249 pLtcBenContainer cpContainer
;
250 CUtOwningList cProperties
;
253 class CBenValue
: public CBenIDListElmt
256 unsigned long GetValueSize();
257 void ReadValueData(void * pBuffer
,
258 unsigned long Offset
, unsigned long MaxSize
, unsigned long * pAmtRead
);
260 pCBenProperty BEN_EXPORT
GetProperty() { return cpProperty
; }
262 public: // Internal methods
263 // added to remove WARNING
264 explicit CBenValue(BenObjectID TypeID
):CBenIDListElmt(TypeID
)
266 cpProperty
= nullptr;
269 void SetProperty(pCBenProperty pProperty
)
271 cpProperty
= pProperty
;
274 inline pCBenValueSegment
GetNextValueSegment(pCBenValueSegment
276 CUtList
& GetValueSegments() { return cValueSegments
; }
279 pCBenProperty cpProperty
;
280 CUtOwningList cValueSegments
;
283 class CBenProperty
: public CBenIDListElmt
286 // In the Apple Bento, a property can have multiple values, each of a
287 // different type. But we never use it that way, so in this code a
288 // property has exactly one value
290 CBenValue
& UseValue() { return cValue
; }
291 pCBenObject
GetBenObject() { return cpObject
; }
292 pLtcBenContainer
GetContainer() { return GetBenObject()->GetContainer(); }
294 public: // Internal methods
295 // changed to remove WARNING here
296 CBenProperty(pCBenObject pObject
, BenObjectID PropertyID
,
297 BenObjectID TypeID
, pCUtListElmt pPrevProperty
) :
298 CBenIDListElmt(PropertyID
, pPrevProperty
), cValue(TypeID
)
301 cValue
.SetProperty(this);
304 pCBenObject cpObject
;
308 class CBenValueSegment
: public CUtListElmt
310 public: // Internal methods
311 CBenValueSegment(pCBenValue pValue
, BenContainerPos Pos
,
312 unsigned long Size
) : CUtListElmt(&pValue
->GetValueSegments())
313 { cpValue
= pValue
; cImmediate
= false; cPos
= Pos
;
315 CBenValueSegment(pCBenValue pValue
, const void * pImmData
,
316 unsigned short Size
) : CUtListElmt(&pValue
->GetValueSegments())
317 { cpValue
= pValue
; cImmediate
= true;
318 UtHugeMemcpy(cImmData
, pImmData
, Size
); cSize
= Size
; }
319 bool IsImmediate() { return cImmediate
; }
320 BenContainerPos
GetPosition() { return cPos
; }
321 unsigned long GetSize() { return cSize
; }
322 BenByte
* GetImmediateData() { return cImmData
; }
329 BenContainerPos cPos
;
335 inline pCBenValueSegment
CBenValue::GetNextValueSegment(pCBenValueSegment
337 { return static_cast<pCBenValueSegment
>( cValueSegments
.GetNextOrNULL(pCurrValueSegment
) ); }
340 class CBenNamedObject
: public CBenObject
343 virtual bool IsPropertyName();
345 public: // Internal methods
346 CBenNamedObject(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
347 pCBenObject pPrevObject
, const OString
& rName
,
348 pCUtListElmt pPrevNamedObjectListElmt
);
350 const OString
& GetName() { return csName
; }
354 CBenNamedObjectListElmt cNameListElmt
;
357 class CBenPropertyName
: public CBenNamedObject
359 public: // Internal methods
360 CBenPropertyName(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
361 pCBenObject pPrevObject
, const OString
& rName
,
362 pCUtListElmt pPrevNamedObjectListElmt
) :
363 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, rName
,
364 pPrevNamedObjectListElmt
) { ; }
365 virtual bool IsPropertyName() override
;
368 class CBenTypeName
: public CBenNamedObject
370 public: // Internal methods
371 CBenTypeName(pLtcBenContainer pContainer
, BenObjectID ObjectID
,
372 pCBenObject pPrevObject
, const OString
& rName
,
373 pCUtListElmt pPrevNamedObjectListElmt
) :
374 CBenNamedObject(pContainer
, ObjectID
, pPrevObject
, rName
,
375 pPrevNamedObjectListElmt
) { ; }
378 } // end namespace OpenStormBento
381 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */