bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwpfoundry.cxx
blob30380c6530b778360803cfb1c5393943f41e5f3a
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,
29 * MA 02111-1307 USA
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 /*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
60 /*************************************************************************
61 * Change History
62 Jan 2005 Created
63 ************************************************************************/
65 #include "lwpfoundry.hxx"
66 #include "lwpfilehdr.hxx"
67 #include "lwpdoc.hxx"
68 #include "lwpmarker.hxx"
69 #include "lwpholder.hxx"
70 #include "lwpbulletstylemgr.hxx"
71 #include "lwpcontent.hxx"
72 #include "lwpvpointer.hxx"
73 #include "lwpsection.hxx"
74 #include "lwpcharacterstyle.hxx"
75 #include "lwpglobalmgr.hxx"
77 LwpFoundry::LwpFoundry(LwpObjectStream *pStrm, LwpDocument* pDoc)
78 : m_pDoc(pDoc)
79 , m_bRegisteredAll(false)
80 , m_pPieceMgr(NULL)
81 , m_pStyleMgr(NULL)
83 Read(pStrm);
84 m_pDropcapMgr = new LwpDropcapMgr;
85 m_pBulletStyleMgr = new LwpBulletStyleMgr();
86 m_pBulletStyleMgr->SetFoundry(this);
89 LwpFoundry::~LwpFoundry()
91 if(m_pPieceMgr)
93 delete m_pPieceMgr;
95 if(m_pStyleMgr)
97 delete m_pStyleMgr;
99 if (m_pDropcapMgr)
100 delete m_pDropcapMgr;
101 if (m_pBulletStyleMgr)
103 delete m_pBulletStyleMgr;
107 void LwpFoundry::Read(LwpObjectStream *pStrm)
109 if (!m_pDoc->IsChildDoc())
111 m_VerMgr.Read(pStrm);
113 m_ObjMgr.Read(pStrm);
115 m_MarkerHead.ReadIndexed(pStrm);
116 m_FootnoteMgr.ReadIndexed(pStrm);
118 m_NumMgr.Read(pStrm);
119 m_BulMgr.Read(pStrm);
121 m_SectionList.Read(pStrm);
122 m_Layout.ReadIndexed(pStrm);
124 ReadStyles(pStrm);
126 m_BookMarkHead.ReadIndexed(pStrm);
127 m_DdeLinkHead.ReadIndexed(pStrm);
128 m_DirtBagHead.ReadIndexed(pStrm);
129 m_NamedOutlineSeqHead.ReadIndexed(pStrm);
131 m_EnumLayoutHead.ReadIndexed(pStrm);
132 m_EnumLayoutTail.ReadIndexed(pStrm);
133 m_NamedObjects.ReadIndexed(pStrm);
135 m_nLastClickHere = pStrm->QuickReaduInt32();
136 m_SmartTextMgr.ReadIndexed(pStrm);
138 m_ContentMgr.Read(pStrm);
139 m_FontMgr.Read(pStrm);
141 if (!m_pDoc->IsChildDoc() && LwpFileHeader::m_nFileRevision >= 0x000B)
143 m_pPieceMgr = new LwpPieceManager();
145 m_pPieceMgr->Read(pStrm);
148 if( LwpFileHeader::m_nFileRevision >= 0x000B)
150 m_DftDropCapStyle.ReadIndexed(pStrm);
152 if( LwpFileHeader::m_nFileRevision >= 0x000F)
154 m_DftHeaderStyle.ReadIndexed(pStrm);
155 m_DftFooterStyle.ReadIndexed(pStrm);
157 pStrm->SkipExtra();
159 m_pStyleMgr = new LwpStyleManager();
160 m_pStyleMgr->SetFoundry(this);
164 void LwpFoundry::ReadStyles(LwpObjectStream *pStrm)
166 m_TextStyle.ReadIndexed(pStrm);
167 m_DefaultTextStyle.ReadIndexed(pStrm);
168 m_DefaultClickStyle.ReadIndexed(pStrm);
169 m_PageStyle.ReadIndexed(pStrm);
170 m_FrameStyle.ReadIndexed(pStrm);
172 m_TableStyle.ReadIndexed(pStrm);
173 m_CellStyle.ReadIndexed(pStrm);
174 m_DftFrameStyle.ReadIndexed(pStrm);
175 m_DftPageStyle.ReadIndexed(pStrm);
176 m_DftTableStyle.ReadIndexed(pStrm);
178 m_DftCellStyle.ReadIndexed(pStrm);
179 m_DftColumnStyle.ReadIndexed(pStrm);
180 m_DftLeftColumnStyle.ReadIndexed(pStrm);
181 m_DftRighColumnStyle.ReadIndexed(pStrm);
185 #include "xfilter/xfstylemanager.hxx"
186 #include "lwplayout.hxx"
188 void LwpFoundry::RegisterAllLayouts()
190 if (m_bRegisteredAll)
192 OSL_FAIL("recursive LwpFoundry::RegisterAllLayouts!\n");
193 return;
196 m_bRegisteredAll = true;
198 //Register CellStyle
199 LwpObject* pStyle = m_CellStyle.obj();
200 if( pStyle )
202 pStyle->SetFoundry(this);
203 pStyle->RegisterStyle();
206 //register content page layout list: Layout
207 pStyle = m_Layout.obj();
208 if( pStyle )
210 pStyle->SetFoundry(this);
211 pStyle->RegisterStyle();
214 //Register page style layout list: PageStyle, such as "Default Page"
215 pStyle = m_PageStyle.obj();
216 if( pStyle )
218 pStyle->SetFoundry(this);
219 pStyle->RegisterStyle();
222 //Register FrameStyle
223 pStyle = m_FrameStyle.obj();
224 if( pStyle )
226 pStyle->SetFoundry(this);
227 pStyle->RegisterStyle();
232 LwpBookMark* LwpFoundry::GetBookMark(LwpObjectID objMarker)
234 LwpDLVListHeadHolder* pHeadHolder= static_cast
235 <LwpDLVListHeadHolder*>(m_BookMarkHead.obj());
236 LwpObjectID* pObjID = pHeadHolder->GetHeadID();
237 LwpBookMark* pBookMark;
238 if (pObjID)
239 pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
240 else
241 return NULL;
243 while (pBookMark)
245 if (pBookMark->IsRightMarker(objMarker))
246 return pBookMark;
247 pObjID = pBookMark->GetNext();
248 if (pObjID)
249 pBookMark = static_cast<LwpBookMark*>(pObjID->obj());
250 else
251 return NULL;
253 return NULL;
257 * @descr: Get next content
260 LwpContent* LwpFoundry::EnumContents(LwpContent * pContent)
262 return GetContentManager()->EnumContents(pContent);
266 * @descr: Get next section
269 LwpSection* LwpFoundry::EnumSections(LwpSection * pSection)
271 return static_cast<LwpSection*>(m_SectionList.Enumerate(pSection));
275 * @descr: Get default text style id
278 LwpObjectID * LwpFoundry::GetDefaultTextStyle()
280 LwpVersionedPointer * pPointer = static_cast<LwpVersionedPointer *>(m_DefaultTextStyle.obj());
281 if (!pPointer)
282 return NULL;
284 return pPointer->GetPointer();
288 * @descr: Get paragraph style object id according to its style name
291 LwpObjectID * LwpFoundry::FindParaStyleByName(OUString name)
293 //Register all text styles: para styles, character styles
294 LwpDLVListHeadHolder* pParaStyleHolder = static_cast<LwpDLVListHeadHolder*>(GetTextStyleHead()->obj());
295 if(pParaStyleHolder)
297 LwpTextStyle* pParaStyle = static_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID()->obj());
298 while(pParaStyle)
300 OUString strName = pParaStyle->GetName()->str();
301 if(strName == name)
302 return pParaStyle->GetObjectID();
303 pParaStyle = static_cast<LwpTextStyle*>(pParaStyle->GetNext()->obj());
307 return NULL;
311 * @descr: Get style name registered according the original style name
314 OUString LwpFoundry::FindActuralStyleName(OUString name)
316 LwpObjectID* pID = FindParaStyleByName(name);
317 if(pID)
319 IXFStyle* pStyle = GetStyleManager()->GetStyle(*pID);
320 if(pStyle)
322 return pStyle->GetStyleName();
326 return name;
329 void LwpVersionManager::Read(LwpObjectStream *pStrm)
331 // TODO: skip the data for prototype
332 Skip(pStrm);
335 void LwpVersionManager::Skip(LwpObjectStream *pStrm)
337 pStrm->QuickReaduInt32();
338 sal_uInt16 Count = pStrm->QuickReaduInt16();
340 while(Count--)
342 sal_uInt32 tag = pStrm->QuickReaduInt32();
343 switch(tag)
345 case TAG_USER_VERSION:
346 // TODO: skip the CUserVersionControl
347 pStrm->SeekRel(pStrm->QuickReaduInt16());
348 break;
350 default:
351 pStrm->SeekRel(pStrm->QuickReaduInt16());
352 pStrm->SkipExtra();
353 break;
356 pStrm->SkipExtra();
359 void LwpObjectManager::Read(LwpObjectStream *pStrm)
362 LwpObjectID dummy;
363 dummy.Read(pStrm);
364 // TODO: judge if we need to set the cDelta by the dummy id
366 m_Division.ReadIndexed(pStrm);
367 pStrm->SkipExtra();
370 void LwpNumberManager::Read(LwpObjectStream *pStrm)
372 m_TableRange.ReadIndexed(pStrm);
373 pStrm->SkipExtra();
376 void LwpBulletManager::Read(LwpObjectStream *pStrm)
378 m_Head.ReadIndexed(pStrm);
379 pStrm->SkipExtra();
382 void LwpContentManager::Read(LwpObjectStream *pStrm)
384 m_ContentList.ReadIndexed(pStrm);
386 // TODO: to judge the file revision
388 m_EnumHead.ReadIndexed(pStrm);
389 m_EnumTail.ReadIndexed(pStrm);
391 m_OleObjCount.ReadIndexed(pStrm);
393 if( LwpFileHeader::m_nFileRevision >= 0x000B)
395 m_GrapHead.ReadIndexed(pStrm);
396 m_GrapTail.ReadIndexed(pStrm);
397 m_OleHead.ReadIndexed(pStrm);
398 m_OleTail.ReadIndexed(pStrm);
401 pStrm->SkipExtra();
405 * @descr: Get next content
408 LwpContent* LwpContentManager::EnumContents(LwpContent* pContent)
410 if(pContent)
411 return pContent->GetNextEnumerated();
412 LwpVersionedPointer* pPointer = static_cast<LwpVersionedPointer*>(m_EnumHead.obj());
413 return pPointer ? static_cast<LwpContent*>(pPointer->GetPointer()->obj()) : NULL;
416 void LwpPieceManager::Read(LwpObjectStream *pStrm)
418 m_GeometryPieceList.ReadIndexed(pStrm);
419 m_ScalePieceList.ReadIndexed(pStrm);
420 m_MarginsPieceList.ReadIndexed(pStrm);
421 m_ColumnsPieceList.ReadIndexed(pStrm);
422 m_BorderStuffPieceList.ReadIndexed(pStrm);
424 m_GutterStuffPieceList.ReadIndexed(pStrm);
425 m_BackgroundStuffPieceList.ReadIndexed(pStrm);
426 m_JoinStuffPieceList.ReadIndexed(pStrm);
427 m_ShadowPieceList.ReadIndexed(pStrm);
428 m_NumericsPieceList.ReadIndexed(pStrm);
430 m_RelativityPieceList.ReadIndexed(pStrm);
431 m_AlignmentPieceList.ReadIndexed(pStrm);
432 m_IndentPieceList.ReadIndexed(pStrm);
433 m_ParaBorderPieceList.ReadIndexed(pStrm);
434 m_SpacingPieceList.ReadIndexed(pStrm);
436 m_BreaksPieceList.ReadIndexed(pStrm);
437 m_NumberingPieceList.ReadIndexed(pStrm);
438 m_TabPieceList.ReadIndexed(pStrm);
439 m_CharacterBorderPieceList.ReadIndexed(pStrm);
440 m_AmikakePieceList.ReadIndexed(pStrm);
442 if(pStrm->CheckExtra())
444 m_ParaBackgroundPieceList.ReadIndexed(pStrm);
445 m_ExternalBorderStuffPieceList.ReadIndexed(pStrm);
446 m_ExternalJoinStuffPieceList.ReadIndexed(pStrm);
447 pStrm->SkipExtra();
451 void LwpOrderedObjectManager::Read(LwpObjectStream *pStrm)
453 m_Head.ReadIndexed(pStrm);
457 * @descr: Get next orderedobject, copy from lwp source code
460 LwpOrderedObject* LwpOrderedObjectManager::Enumerate(LwpOrderedObject * pLast)
462 // If Last has a next, return it.
463 if(pLast && !pLast->GetNext()->IsNull())
464 return static_cast<LwpOrderedObject*>(pLast->GetNext()->obj());
466 LwpListList* pList = NULL;
467 if(pLast)
469 // We're at the end of Last's list (not Liszt's list).
470 // Start with the next active list
471 pList = static_cast<LwpListList*>(pLast->GetListList()->obj());
472 pList= GetNextActiveListList(pList);
474 else
476 // Start with the first active ListList
477 pList = GetNextActiveListList(NULL);
480 if(pList)
482 return static_cast<LwpOrderedObject*>(pList->GetHead()->obj());
485 return NULL;
489 * @descr: Get next listlist object, copy from lwp source code
492 LwpListList* LwpOrderedObjectManager::GetNextActiveListList(LwpListList * pLast)
494 LwpListList* pList = NULL;
495 LwpContent* pContent = NULL;
496 if(pLast)
497 pList = static_cast<LwpListList*>(pLast->GetNext()->obj());
498 else
500 LwpDLVListHeadHolder* pHeadHolder= static_cast<LwpDLVListHeadHolder*>(m_Head.obj());
501 if(pHeadHolder)
503 pList = static_cast<LwpListList*>(pHeadHolder->GetHeadID()->obj());
507 while(pList)
509 pContent = static_cast<LwpContent*>(pList->GetObject()->obj());
510 if(pContent && pContent->HasNonEmbeddedLayouts() &&
511 !pContent->IsStyleContent())
512 return pList;
513 pList = static_cast<LwpListList*>(pList->GetNext()->obj());
515 return NULL;
518 LwpStyleManager::LwpStyleManager()
519 : m_pFoundry(0)
523 LwpStyleManager::~LwpStyleManager()
525 m_StyleList.clear();
529 #include "xfilter/xfstylemanager.hxx"
531 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its created style to XFStyleManager
532 1. Add the style to XFStyleManager, and return the <office:styles> style name
533 2. Add it to LwpParaStyleMap.
534 Prerequisite: pStyle has been created and all properties has been set to it.
535 Return the XFStyle* added by XFStyleManager
537 IXFStyle* LwpStyleManager::AddStyle(LwpObjectID styleObjID, IXFStyle* pStyle)
539 assert(pStyle);
540 //pStyle may change if same style is found in XFStyleManager
541 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
542 pStyle = pXFStyleManager->AddStyle(pStyle);
543 m_StyleList.insert(LwpStyleMap::value_type(styleObjID, pStyle));
544 return pStyle;
548 Called by VO_PARA or other objects to get style name based on the Style object ID
549 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
550 Prerequisite: VO_PARASTYLE/VO_CHARACTERSTYLE should call AddStyle first.
551 Return empty string if no style found.
553 IXFStyle* LwpStyleManager::GetStyle(const LwpObjectID &styleObjID)
555 LwpStyleMap::const_iterator it = m_StyleList.find(styleObjID);
556 if (it != m_StyleList.end()) {
557 return((*it).second);
559 return NULL;
562 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */