merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpdocdata.cxx
blobcbbb3fde2201628eddb8fedb943090f492c3775d
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 "lwpdocdata.hxx"
56 #include "xfilter/xfofficemeta.hxx"
57 #include "localtime.hxx"
58 #include <rtl/ustrbuf.hxx>
59 #include "lwpfilehdr.hxx"
60 #include "lwpglobalmgr.hxx"
62 //std::map<sal_uInt16,LwpEditorAttr*> LwpDocData::m_EditorAttrMap;
64 LwpDocData::LwpDocData(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
65 :LwpObject(objHdr, pStrm)//m_pEditorAttrList(0)
68 LwpDocData::~LwpDocData()
71 void LwpDocData::SkipExtra(LwpSvStream* pStream)
73 sal_uInt16 extra;
74 pStream->Read(&extra,2);
75 while(extra != 0)
77 pStream->SeekRel(extra);
78 pStream->Read(&extra,2);
81 void LwpDocData::SkipAtomHandler(LwpSvStream* pStream)
83 sal_uInt16 disksize;
84 sal_uInt16 len;
85 pStream->Read(&disksize,2);
86 pStream->Read(&len,2);
87 if(len)pStream->SeekRel(disksize-2);
89 void LwpDocData::Read()
91 //XFDateTime
92 //////////////////////////////////////////////////////////////////////////
93 //doc options
94 //cOptionFlag
95 m_DocOptions.nOptionFlag = m_pObjStrm->QuickReaduInt16();
96 //cEncrypt1Password
97 m_DocOptions.encrypt1password.Read(m_pObjStrm);
98 //cEncrypt2Password
99 m_DocOptions.encrypt2password.Read(m_pObjStrm);
100 //cCharecterSet
101 m_DocOptions.characterSet.Read(m_pObjStrm);
102 //cGrammerSet
103 m_DocOptions.grammerSet.Read(m_pObjStrm);
104 //cShowMarginMarks
105 m_DocOptions.nMarginMarks = m_pObjStrm->QuickReaduInt16();
106 //cMarginMarksLocation
107 m_DocOptions.nMarginMarksLocation = m_pObjStrm->QuickReaduInt16();
108 //cMarginMarksChar
109 m_DocOptions.nMarginMarksChar = m_pObjStrm->QuickReaduInt16();
110 m_pObjStrm->SkipExtra();
111 //////////////////////////////////////////////////////////////////////////
112 //doc info
113 //cDescription
114 m_DocInfo.description.Read(m_pObjStrm);
115 //cKeyWord
116 m_DocInfo.keywords.Read(m_pObjStrm);
117 //cCreatedBy
118 m_DocInfo.createdBy.Read(m_pObjStrm);
119 //cCreationTime
120 m_DocInfo.nCreationTime = m_pObjStrm->QuickReadInt32();
121 LtgLocalTime(m_DocInfo.nCreationTime,m_nCreationTime);
122 //cLastRevisionTime
123 m_DocInfo.nLastRevisionTime = m_pObjStrm->QuickReadInt32();
124 LtgLocalTime(m_DocInfo.nLastRevisionTime,m_nLastRevisionTime);
125 //cTotalEditTime
126 m_DocInfo.nTotalEditTime = m_pObjStrm->QuickReadInt32();
128 m_nTotalEditTime.tm_hour = m_DocInfo.nTotalEditTime / 60;
129 m_nTotalEditTime.tm_min = m_DocInfo.nTotalEditTime % 60;
130 m_nTotalEditTime.tm_sec = 0;
131 //cpVerDocInfo
132 m_DocInfo.cpVerDocInfo.ReadIndexed(m_pObjStrm);
134 //EditorList
135 m_DocInfo.nNumEditedBy = m_pObjStrm->QuickReaduInt16();
136 LwpAtomHolder* pCDLNList = new LwpAtomHolder[m_DocInfo.nNumEditedBy];
137 LwpAtomHolder* pEditorList = new LwpAtomHolder[m_DocInfo.nNumEditedBy];
138 sal_uInt16 i = 0;
139 for ( i = 0; i < m_DocInfo.nNumEditedBy; i++)
141 //CDLNList
142 pCDLNList[i].Read(m_pObjStrm); //cName
143 m_pObjStrm->SkipExtra();
144 //CEditedBy
145 pEditorList[i].Read(m_pObjStrm); //cName
146 m_pObjStrm->SkipExtra();
149 m_pObjStrm->SkipExtra();
151 delete [] pCDLNList;
152 delete [] pEditorList;
153 //////////////////////////////////////////////////////////////////////////
154 //doc control
155 //cGreeting
156 m_DocControl.cGreeting.Read(m_pObjStrm);
157 //cFlags
158 m_DocControl.nFlags = m_pObjStrm->QuickReaduInt16();
160 //cDocControlProtection
161 m_DocControl.nDocControlProtection = m_pObjStrm->QuickReaduInt16();
162 //Len
163 m_DocControl.nLen1 = m_pObjStrm->QuickReaduInt16();
164 //skip doc control password string
165 m_pObjStrm->SeekRel(m_DocControl.nLen1);
167 //cFileProtection
168 m_DocControl.nFileProtection = m_pObjStrm->QuickReaduInt16();
169 //Len
170 m_DocControl.nLen2 = m_pObjStrm->QuickReaduInt16();
171 //skip file password string
172 m_pObjStrm->SeekRel(m_DocControl.nLen2);
174 //cAutoVersioning
175 m_DocControl.nAutoVersioning = m_pObjStrm->QuickReaduInt16();
176 //cDocControlOnlyEditor
177 m_DocControl.cDocControlOnlyEditor.Read(m_pObjStrm);
178 //cEditorVerification
179 m_DocControl.nEditorVerification = m_pObjStrm->QuickReaduInt16();
181 m_pObjStrm->SkipExtra();
182 //////////////////////////////////////////////////////////////////////////
183 //editor list
184 //numeditors
185 sal_uInt16 numeditors = m_pObjStrm->QuickReaduInt16();
186 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
188 for (i = 0;i<numeditors;i++)
190 LwpEditorAttr* pEditorAttr = new LwpEditorAttr;
191 //cName
192 pEditorAttr->cName.Read(m_pObjStrm);
193 //cInitials
194 pEditorAttr->cInitials.Read(m_pObjStrm);
195 //cHiLite
196 pEditorAttr->cHiLiteColor.Read(m_pObjStrm);
198 //cID
199 pEditorAttr->nID = m_pObjStrm->QuickReaduInt16();
201 //cInsFontOver
202 //CFontAttributeOverride --cAttrBits
203 pEditorAttr->cInsFontOver.cFontAttributeOverride.cAttrBits = m_pObjStrm->QuickReaduInt16();
204 //CFontAttributeOverride --cAttrOverrideBits
205 pEditorAttr->cInsFontOver.cFontAttributeOverride.cAttrOverrideBits = m_pObjStrm->QuickReaduInt16();
206 //CFontAttributeOverride --cAttrApplyBits
207 pEditorAttr->cInsFontOver.cFontAttributeOverride.cAttrApplyBits = m_pObjStrm->QuickReaduInt16();
208 //CFontAttributeOverride --cAttrOverrideBits2
209 pEditorAttr->cInsFontOver.cFontAttributeOverride.cAttrOverrideBits2 = m_pObjStrm->QuickReaduInt8();
210 //CFontAttributeOverride --cAttrApplyBits2
211 pEditorAttr->cInsFontOver.cFontAttributeOverride.cAttrApplyBits2 = m_pObjStrm->QuickReaduInt8();
212 //CFontAttributeOverride --cCase
213 pEditorAttr->cInsFontOver.cFontAttributeOverride.cCase = m_pObjStrm->QuickReaduInt8();
214 //CFontAttributeOverride --cUnder
215 pEditorAttr->cInsFontOver.cFontAttributeOverride.cUnder = m_pObjStrm->QuickReaduInt8();
216 m_pObjStrm->SkipExtra();
217 //CFontDescriptionOverrideBase--cOverrideBits
218 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cOverrideBits = m_pObjStrm->QuickReaduInt8();
219 //CFontDescriptionOverrideBase--cApplyBits
220 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cApplyBits = m_pObjStrm->QuickReaduInt8();
221 //CFontDescriptionOverrideBase--cPointSize
222 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cPointSize = m_pObjStrm->QuickReadInt32();
223 //CFontDescriptionOverrideBase--cOverstrike
224 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cOverstrike = m_pObjStrm->QuickReaduInt8();
225 //CFontDescriptionOverrideBase--cTightness
226 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cTightness = m_pObjStrm->QuickReaduInt16();
227 //CFontDescriptionOverrideBase--cColor
228 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cColor.Read(m_pObjStrm);
230 //CFontDescriptionOverrideBase--cBackgroundColor
231 pEditorAttr->cInsFontOver.cFontDescriptionOverrideBase.cBackgroundColor.Read(m_pObjStrm);
233 m_pObjStrm->SkipExtra();
234 //cFaceName
235 pEditorAttr->cInsFontOver.cFaceName.Read(m_pObjStrm);
236 //cAltFaceName
237 pEditorAttr->cInsFontOver.cAltFaceName.Read(m_pObjStrm);
238 m_pObjStrm->SkipExtra();
240 //cDelFontOver
241 //CFontAttributeOverride --cAttrBits
242 pEditorAttr->cDelFontOver.cFontAttributeOverride.cAttrBits = m_pObjStrm->QuickReaduInt16();
243 //CFontAttributeOverride --cAttrOverrideBits
244 pEditorAttr->cDelFontOver.cFontAttributeOverride.cAttrOverrideBits = m_pObjStrm->QuickReaduInt16();
245 //CFontAttributeOverride --cAttrApplyBits
246 pEditorAttr->cDelFontOver.cFontAttributeOverride.cAttrApplyBits = m_pObjStrm->QuickReaduInt16();
247 //CFontAttributeOverride --cAttrOverrideBits2
248 pEditorAttr->cDelFontOver.cFontAttributeOverride.cAttrOverrideBits2 = m_pObjStrm->QuickReaduInt8();
249 //CFontAttributeOverride --cAttrApplyBits2
250 pEditorAttr->cDelFontOver.cFontAttributeOverride.cAttrApplyBits2 = m_pObjStrm->QuickReaduInt8();
251 //CFontAttributeOverride --cCase
252 pEditorAttr->cDelFontOver.cFontAttributeOverride.cCase = m_pObjStrm->QuickReaduInt8();
253 //CFontAttributeOverride --cUnder
254 pEditorAttr->cDelFontOver.cFontAttributeOverride.cUnder = m_pObjStrm->QuickReaduInt8();
255 m_pObjStrm->SkipExtra();
256 //CFontDescriptionOverrideBase--cOverrideBits
257 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cOverrideBits = m_pObjStrm->QuickReaduInt8();
258 //CFontDescriptionOverrideBase--cApplyBits
259 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cApplyBits = m_pObjStrm->QuickReaduInt8();
260 //CFontDescriptionOverrideBase--cPointSize
261 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cPointSize = m_pObjStrm->QuickReadInt32();
262 //CFontDescriptionOverrideBase--cOverstrike
263 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cOverstrike = m_pObjStrm->QuickReaduInt8();
264 //CFontDescriptionOverrideBase--cTightness
265 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cTightness = m_pObjStrm->QuickReaduInt16();
266 //CFontDescriptionOverrideBase--cColor
267 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cColor.Read(m_pObjStrm);
269 //CFontDescriptionOverrideBase--cBackgroundColor
270 pEditorAttr->cDelFontOver.cFontDescriptionOverrideBase.cBackgroundColor.Read(m_pObjStrm);
272 m_pObjStrm->SkipExtra();
273 //cFaceName
274 pEditorAttr->cDelFontOver.cFaceName.Read(m_pObjStrm);
275 //cAltFaceName
276 pEditorAttr->cDelFontOver.cAltFaceName.Read(m_pObjStrm);
277 m_pObjStrm->SkipExtra();
279 //cAbilities
280 pEditorAttr->nAbilities = m_pObjStrm->QuickReaduInt16();
281 //cLocks
282 pEditorAttr->nLocks = m_pObjStrm->QuickReaduInt16();
283 //cSuggestions
284 pEditorAttr->nSuggestions = m_pObjStrm->QuickReaduInt16();
286 //cDelTextAttr
287 //m_pEditorAttrList[i].cDelTextAttr.Read(m_pObjStrm);
288 if (m_pObjStrm->QuickReadBool())
290 pEditorAttr->cDelTextAttr.cOverride.cValues = m_pObjStrm->QuickReaduInt16();
291 pEditorAttr->cDelTextAttr.cOverride.cOverride = m_pObjStrm->QuickReaduInt16();
292 pEditorAttr->cDelTextAttr.cOverride.cApply = m_pObjStrm->QuickReaduInt16();
293 m_pObjStrm->SkipExtra();
294 pEditorAttr->cDelTextAttr.cHideLevels = m_pObjStrm->QuickReaduInt16();
296 if (LwpFileHeader::m_nFileRevision>= 0x000b)
298 pEditorAttr->cDelTextAttr.cBaselineOffset = m_pObjStrm->QuickReadInt32();
300 else
302 pEditorAttr->cDelTextAttr.cBaselineOffset = 0;
305 m_pObjStrm->SkipExtra();
307 m_pObjStrm->SkipExtra();
309 pGlobal->SetEditorAttrMap(pEditorAttr->nID, pEditorAttr);
312 rtl::OUString LwpDocData::DateTimeToOUString(LtTm& dt)
314 rtl::OUStringBuffer buf;
315 buf.append((sal_Int32)dt.tm_year);
316 buf.append( A2OUSTR("-") );
317 buf.append((sal_Int32)dt.tm_mon);
318 buf.append( A2OUSTR("-") );
319 buf.append((sal_Int32)dt.tm_mday);
320 buf.append( A2OUSTR("T") );
321 buf.append((sal_Int32)dt.tm_hour);
322 buf.append( A2OUSTR(":") );
323 buf.append((sal_Int32)dt.tm_min);
324 buf.append( A2OUSTR(":") );
325 buf.append((sal_Int32)dt.tm_sec);
326 buf.append( A2OUSTR(".") );
327 buf.append((sal_Int32)0);
329 return buf.makeStringAndClear();
331 rtl::OUString LwpDocData::TimeToOUString(LtTm& dt)
333 //PT3H43M44S
334 rtl::OUStringBuffer buf;
335 buf.append( A2OUSTR("PT") );
336 buf.append((sal_Int32)dt.tm_hour);
337 buf.append( A2OUSTR("H") );
338 buf.append((sal_Int32)dt.tm_min);
339 buf.append( A2OUSTR("M") );
340 buf.append((sal_Int32)dt.tm_sec);
341 buf.append( A2OUSTR("S") );
343 return buf.makeStringAndClear();
345 void LwpDocData::Parse(IXFStream *pOutputStream)
347 //<!DOCTYPE office:document-meta PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "office.dtd">
348 //<office:document-meta xmlns:office="http://openoffice.org/2000/office" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="http://openoffice.org/2000/meta" office:version="1.0">
349 //</office:document-meta>
350 XFOfficeMeta xfMeta;
351 xfMeta.SetCreator(m_DocInfo.createdBy.str());
352 xfMeta.SetDescription(m_DocInfo.description.str());
353 xfMeta.SetKeywords(m_DocInfo.keywords.str());
354 xfMeta.SetCreationTime(DateTimeToOUString(m_nCreationTime));
355 xfMeta.SetLastTime(DateTimeToOUString(m_nLastRevisionTime));
356 xfMeta.SetEditTime(TimeToOUString(m_nTotalEditTime));
357 xfMeta.ToXml(pOutputStream);
360 OUString LwpDocData::GetEditorName(sal_uInt8 nID)
362 std::map<sal_uInt16,LwpEditorAttr*>::iterator iter;
363 iter = m_EditorAttrMap.find(nID);
364 if (iter != m_EditorAttrMap.end())
365 return iter->second->cName.str();
366 return A2OUSTR("");
369 XFColor LwpDocData::GetHighLightColor(sal_uInt8 nID)
371 std::map<sal_uInt16,LwpEditorAttr*>::iterator iter;
373 iter = m_EditorAttrMap.find(nID);
374 if (iter != m_EditorAttrMap.end())
376 LwpColor aLwpColor = iter->second->cHiLiteColor;
377 XFColor aColor(aLwpColor.GetRed(),aLwpColor.GetGreen(),aLwpColor.GetBlue());
378 return aColor;
380 else
382 XFColor aColor(255,255,0);//yellow
383 return aColor;
386 void LwpDocData::Reset()
388 std::map<sal_uInt16,LwpEditorAttr*>::iterator iter;
389 for (iter =m_EditorAttrMap.begin();iter != m_EditorAttrMap.end(); iter++)
391 delete iter->second;
392 iter->second = NULL;
394 m_EditorAttrMap.clear();