update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwpfoundry.cxx
blobf1b0a39c4111f40d1df7d902b43ce2abc6b49b54
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 /*************************************************************************
56 * @file
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
60 * Change History
61 Jan 2005 Created
62 ************************************************************************/
64 #include "lwpfoundry.hxx"
65 #include "lwpfilehdr.hxx"
66 #include "lwpdoc.hxx"
67 #include "lwpmarker.hxx"
68 #include "lwpholder.hxx"
69 #include "lwpbulletstylemgr.hxx"
70 #include "lwpcontent.hxx"
71 #include "lwpvpointer.hxx"
72 #include "lwpsection.hxx"
73 #include "lwpcharacterstyle.hxx"
74 #include "lwpglobalmgr.hxx"
76 LwpFoundry::LwpFoundry(LwpObjectStream *pStrm, LwpDocument* pDoc)
77 : m_pDoc(pDoc), m_pPieceMgr(NULL), m_pStyleMgr(NULL)
79 Read(pStrm);
80 m_pDropcapMgr = new LwpDropcapMgr;
81 m_pBulletStyleMgr = new LwpBulletStyleMgr();
82 m_pBulletStyleMgr->SetFoundry(this);
85 LwpFoundry::~LwpFoundry()
87 if(m_pPieceMgr)
89 delete m_pPieceMgr;
91 if(m_pStyleMgr)
93 delete m_pStyleMgr;
95 if (m_pDropcapMgr)
96 delete m_pDropcapMgr;
97 if (m_pBulletStyleMgr)
99 delete m_pBulletStyleMgr;
103 void LwpFoundry::Read(LwpObjectStream *pStrm)
105 if (!m_pDoc->IsChildDoc())
107 m_VerMgr.Read(pStrm);
109 m_ObjMgr.Read(pStrm);
111 m_MarkerHead.ReadIndexed(pStrm);
112 m_FootnoteMgr.ReadIndexed(pStrm);
114 m_NumMgr.Read(pStrm);
115 m_BulMgr.Read(pStrm);
117 m_SectionList.Read(pStrm);
118 m_Layout.ReadIndexed(pStrm);
120 ReadStyles(pStrm);
122 m_BookMarkHead.ReadIndexed(pStrm);
123 m_DdeLinkHead.ReadIndexed(pStrm);
124 m_DirtBagHead.ReadIndexed(pStrm);
125 m_NamedOutlineSeqHead.ReadIndexed(pStrm);
127 m_EnumLayoutHead.ReadIndexed(pStrm);
128 m_EnumLayoutTail.ReadIndexed(pStrm);
129 m_NamedObjects.ReadIndexed(pStrm);
131 pStrm->QuickRead(&m_nLastClickHere, sizeof(m_nLastClickHere));
132 m_SmartTextMgr.ReadIndexed(pStrm);
134 m_ContentMgr.Read(pStrm);
135 m_FontMgr.Read(pStrm);
137 if (!m_pDoc->IsChildDoc() && LwpFileHeader::m_nFileRevision >= 0x000B)
139 m_pPieceMgr = new LwpPieceManager();
141 m_pPieceMgr->Read(pStrm);
144 if( LwpFileHeader::m_nFileRevision >= 0x000B)
146 m_DftDropCapStyle.ReadIndexed(pStrm);
148 if( LwpFileHeader::m_nFileRevision >= 0x000F)
150 m_DftHeaderStyle.ReadIndexed(pStrm);
151 m_DftFooterStyle.ReadIndexed(pStrm);
153 pStrm->SkipExtra();
155 m_pStyleMgr = new LwpStyleManager();
156 m_pStyleMgr->SetFoundry(this);
160 void LwpFoundry::ReadStyles(LwpObjectStream *pStrm)
162 m_TextStyle.ReadIndexed(pStrm);
163 m_DefaultTextStyle.ReadIndexed(pStrm);
164 m_DefaultClickStyle.ReadIndexed(pStrm);
165 m_PageStyle.ReadIndexed(pStrm);
166 m_FrameStyle.ReadIndexed(pStrm);
168 m_TableStyle.ReadIndexed(pStrm);
169 m_CellStyle.ReadIndexed(pStrm);
170 m_DftFrameStyle.ReadIndexed(pStrm);
171 m_DftPageStyle.ReadIndexed(pStrm);
172 m_DftTableStyle.ReadIndexed(pStrm);
174 m_DftCellStyle.ReadIndexed(pStrm);
175 m_DftColumnStyle.ReadIndexed(pStrm);
176 m_DftLeftColumnStyle.ReadIndexed(pStrm);
177 m_DftRighColumnStyle.ReadIndexed(pStrm);
181 #include "xfilter/xfstylemanager.hxx"
182 #include "lwplayout.hxx"
184 void LwpFoundry::RegisterAllLayouts()
186 //Register CellStyle
187 LwpObject* pStyle = m_CellStyle.obj();
188 if( pStyle )
190 pStyle->SetFoundry(this);
191 pStyle->RegisterStyle();
194 //register content page layout list: Layout
195 pStyle = m_Layout.obj();
196 if( pStyle )
198 pStyle->SetFoundry(this);
199 pStyle->RegisterStyle();
202 //Register page style layout list: PageStyle, such as "Default Page"
203 pStyle = m_PageStyle.obj();
204 if( pStyle )
206 pStyle->SetFoundry(this);
207 pStyle->RegisterStyle();
210 //Register FrameStyle
211 pStyle = m_FrameStyle.obj();
212 if( pStyle )
214 pStyle->SetFoundry(this);
215 pStyle->RegisterStyle();
220 LwpBookMark* LwpFoundry::GetBookMark(LwpObjectID objMarker)
222 LwpDLVListHeadHolder* pHeadHolder= static_cast
223 <LwpDLVListHeadHolder*>(m_BookMarkHead.obj());
224 LwpObjectID* pObjID = pHeadHolder->GetHeadID();
225 LwpBookMark* pBookMark;
226 if (pObjID)
227 pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
228 else
229 return NULL;
231 while (pBookMark)
233 if (pBookMark->IsRightMarker(objMarker))
234 return pBookMark;
235 pObjID = pBookMark->GetNext();
236 if (pObjID)
237 pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
238 else
239 return NULL;
241 return NULL;
244 sal_Bool LwpFoundry::FindBookMarkByName(OUString sName)
246 LwpDLVListHeadHolder* pHeadHolder= static_cast
247 <LwpDLVListHeadHolder*>(m_BookMarkHead.obj());
248 LwpObjectID* pObjID = pHeadHolder->GetHeadID();
249 LwpBookMark* pBookMark;
250 if (pObjID)
251 pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
252 else
253 return NULL;
255 while (pBookMark)
257 if (pBookMark->IsRightName(sName))
258 return sal_True;
259 pObjID = pBookMark->GetNext();
260 if (pObjID)
261 pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
262 else
263 return sal_False;
265 return sal_False;
269 * @descr: Get next content
272 LwpContent* LwpFoundry::EnumContents(LwpContent * pContent)
274 return GetContentManager()->EnumContents(pContent);
278 * @descr: Get next section
281 LwpSection* LwpFoundry::EnumSections(LwpSection * pSection)
283 return static_cast<LwpSection*>(m_SectionList.Enumerate(pSection));
287 * @descr: Get default text style id
290 LwpObjectID * LwpFoundry::GetDefaultTextStyle()
292 LwpVersionedPointer * pPointer = static_cast<LwpVersionedPointer *>(m_DefaultTextStyle.obj());
293 if (!pPointer)
294 return NULL;
296 return pPointer->GetPointer();
300 * @descr: Get paragraph style object id according to its style name
303 LwpObjectID * LwpFoundry::FindParaStyleByName(OUString name)
305 //Register all text styles: para styles, character styles
306 LwpDLVListHeadHolder* pParaStyleHolder = static_cast<LwpDLVListHeadHolder*>(GetTextStyleHead()->obj());
307 if(pParaStyleHolder)
309 LwpTextStyle* pParaStyle = static_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID()->obj());
310 while(pParaStyle)
312 OUString strName = pParaStyle->GetName()->str();
313 if(strName == name)
314 return pParaStyle->GetObjectID();
315 pParaStyle = static_cast<LwpTextStyle*>(pParaStyle->GetNext()->obj());
319 return NULL;
323 * @descr: Get style name registed according the original style name
326 OUString LwpFoundry::FindActuralStyleName(OUString name)
328 LwpObjectID* pID = FindParaStyleByName(name);
329 if(pID)
331 IXFStyle* pStyle = GetStyleManager()->GetStyle(*pID);
332 if(pStyle)
334 return pStyle->GetStyleName();
338 return name;
341 void LwpVersionManager::Read(LwpObjectStream *pStrm)
343 // TODO: skip the data for prototype
344 Skip(pStrm);
347 void LwpVersionManager::Skip(LwpObjectStream *pStrm)
350 sal_uInt32 cNextUserVersionID;
351 pStrm->QuickRead(&cNextUserVersionID, sizeof(cNextUserVersionID));
353 sal_uInt16 Count;
354 pStrm->QuickRead(&Count, sizeof(Count));
356 sal_uInt32 tag;
357 while(Count--)
359 pStrm->QuickRead(&tag, sizeof(tag));
360 USHORT len;
361 switch(tag)
363 case TAG_USER_VERSION:
364 // TODO: skip the CUserVersionControl
365 pStrm->QuickRead(&len, sizeof(len));
366 pStrm->SeekRel(len);
367 //pStrm->SkipExtra(); //The length has included the extra
368 break;
370 default:
371 pStrm->QuickRead(&len, sizeof(USHORT));
372 pStrm->SeekRel(len);
373 pStrm->SkipExtra();
374 break;
377 pStrm->SkipExtra();
380 void LwpObjectManager::Read(LwpObjectStream *pStrm)
383 LwpObjectID dummy;
384 dummy.Read(pStrm);
385 // TODO: judge if we need to set the cDelta by the dummy id
387 m_Division.ReadIndexed(pStrm);
388 pStrm->SkipExtra();
391 void LwpNumberManager::Read(LwpObjectStream *pStrm)
393 m_TableRange.ReadIndexed(pStrm);
394 pStrm->SkipExtra();
397 void LwpBulletManager::Read(LwpObjectStream *pStrm)
399 m_Head.ReadIndexed(pStrm);
400 pStrm->SkipExtra();
403 void LwpContentManager::Read(LwpObjectStream *pStrm)
405 m_ContentList.ReadIndexed(pStrm);
407 // TODO: to judge the file revision
409 m_EnumHead.ReadIndexed(pStrm);
410 m_EnumTail.ReadIndexed(pStrm);
412 m_OleObjCount.ReadIndexed(pStrm);
414 if( LwpFileHeader::m_nFileRevision >= 0x000B)
416 m_GrapHead.ReadIndexed(pStrm);
417 m_GrapTail.ReadIndexed(pStrm);
418 m_OleHead.ReadIndexed(pStrm);
419 m_OleTail.ReadIndexed(pStrm);
422 pStrm->SkipExtra();
426 * @descr: Get next content
429 LwpContent* LwpContentManager::EnumContents(LwpContent* pContent)
431 if(pContent)
432 return pContent->GetNextEnumerated();
433 LwpVersionedPointer* pPointer = static_cast<LwpVersionedPointer*>(m_EnumHead.obj());
434 return pPointer ? static_cast<LwpContent*>(pPointer->GetPointer()->obj()) : NULL;
437 void LwpPieceManager::Read(LwpObjectStream *pStrm)
439 m_GeometryPieceList.ReadIndexed(pStrm);
440 m_ScalePieceList.ReadIndexed(pStrm);
441 m_MarginsPieceList.ReadIndexed(pStrm);
442 m_ColumnsPieceList.ReadIndexed(pStrm);
443 m_BorderStuffPieceList.ReadIndexed(pStrm);
445 m_GutterStuffPieceList.ReadIndexed(pStrm);
446 m_BackgroundStuffPieceList.ReadIndexed(pStrm);
447 m_JoinStuffPieceList.ReadIndexed(pStrm);
448 m_ShadowPieceList.ReadIndexed(pStrm);
449 m_NumericsPieceList.ReadIndexed(pStrm);
451 m_RelativityPieceList.ReadIndexed(pStrm);
452 m_AlignmentPieceList.ReadIndexed(pStrm);
453 m_IndentPieceList.ReadIndexed(pStrm);
454 m_ParaBorderPieceList.ReadIndexed(pStrm);
455 m_SpacingPieceList.ReadIndexed(pStrm);
457 m_BreaksPieceList.ReadIndexed(pStrm);
458 m_NumberingPieceList.ReadIndexed(pStrm);
459 m_TabPieceList.ReadIndexed(pStrm);
460 m_CharacterBorderPieceList.ReadIndexed(pStrm);
461 m_AmikakePieceList.ReadIndexed(pStrm);
463 if(pStrm->CheckExtra())
465 m_ParaBackgroundPieceList.ReadIndexed(pStrm);
466 m_ExternalBorderStuffPieceList.ReadIndexed(pStrm);
467 m_ExternalJoinStuffPieceList.ReadIndexed(pStrm);
468 pStrm->SkipExtra();
472 void LwpOrderedObjectManager::Read(LwpObjectStream *pStrm)
474 m_Head.ReadIndexed(pStrm);
478 * @descr: Get next orderedobject, copy from lwp source code
481 LwpOrderedObject* LwpOrderedObjectManager::Enumerate(LwpOrderedObject * pLast)
483 // If Last has a next, return it.
484 if(pLast && !pLast->GetNext()->IsNull())
485 return static_cast<LwpOrderedObject*>(pLast->GetNext()->obj());
487 LwpListList* pList = NULL;
488 if(pLast)
490 // We're at the end of Last's list (not Liszt's list).
491 // Start with the next active list
492 pList = static_cast<LwpListList*>(pLast->GetListList()->obj());
493 pList= GetNextActiveListList(pList);
495 else
497 // Start with the first active ListList
498 pList = GetNextActiveListList(NULL);
501 if(pList)
503 return static_cast<LwpOrderedObject*>(pList->GetHead()->obj());
506 return NULL;
510 * @descr: Get next listlist object, copy from lwp source code
513 LwpListList* LwpOrderedObjectManager::GetNextActiveListList(LwpListList * pLast)
515 LwpListList* pList = NULL;
516 LwpContent* pContent = NULL;
517 if(pLast)
518 pList = static_cast<LwpListList*>(pLast->GetNext()->obj());
519 else
521 LwpDLVListHeadHolder* pHeadHolder= static_cast<LwpDLVListHeadHolder*>(m_Head.obj());
522 if(pHeadHolder)
524 pList = static_cast<LwpListList*>(pHeadHolder->GetHeadID()->obj());
528 while(pList)
530 pContent = static_cast<LwpContent*>(pList->GetObject()->obj());
531 if(pContent && pContent->HasNonEmbeddedLayouts() &&
532 !pContent->IsStyleContent())
533 return pList;
534 pList = static_cast<LwpListList*>(pList->GetNext()->obj());
536 return NULL;
539 LwpStyleManager::LwpStyleManager()
542 LwpStyleManager::~LwpStyleManager()
544 m_StyleList.clear();
548 #include "xfilter/xfstylemanager.hxx"
550 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its created style to XFStyleManager
551 1. Add the style to XFStyleManager, and return the <office:styles> style name
552 2. Add it to LwpParaStyleMap.
553 Prerequisite: pStyle has been created and all properties has been set to it.
554 Return the XFStyle* added by XFStyleManager
556 IXFStyle* LwpStyleManager::AddStyle(LwpObjectID styleObjID, IXFStyle* pStyle)
558 assert(pStyle);
559 //pStyle may change if same style is found in XFStyleManager
560 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
561 pStyle = pXFStyleManager->AddStyle(pStyle);
562 m_StyleList.insert(LwpStyleMap::value_type(styleObjID, pStyle));
563 return pStyle;
567 Called by VO_PARA or other objects to get style name based on the Style object ID
568 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
569 Prerequisite: VO_PARASTYLE/VO_CHARACTERSTYLE should call AddStyle first.
570 Return empty string if no style found.
572 IXFStyle* LwpStyleManager::GetStyle(const LwpObjectID &styleObjID)
574 LwpStyleMap::const_iterator it = m_StyleList.find(styleObjID);
575 if (it != m_StyleList.end()) {
576 return((*it).second);
578 return NULL;