fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpfoundry.cxx
blobd343520ae96e4c402571aca971b7b1dbf3c89351
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 #include <osl/diagnose.h>
80 LwpFoundry::LwpFoundry(LwpObjectStream *pStrm, LwpDocument* pDoc)
81 : m_pDoc(pDoc)
82 , m_bRegisteredAll(false)
83 , m_pPieceMgr(NULL)
84 , m_pStyleMgr(NULL)
86 Read(pStrm);
87 m_pDropcapMgr = new LwpDropcapMgr;
88 m_pBulletStyleMgr = new LwpBulletStyleMgr();
89 m_pBulletStyleMgr->SetFoundry(this);
92 LwpFoundry::~LwpFoundry()
94 if(m_pPieceMgr)
96 delete m_pPieceMgr;
98 if(m_pStyleMgr)
100 delete m_pStyleMgr;
102 if (m_pDropcapMgr)
103 delete m_pDropcapMgr;
104 if (m_pBulletStyleMgr)
106 delete m_pBulletStyleMgr;
110 void LwpFoundry::Read(LwpObjectStream *pStrm)
112 if (!m_pDoc->IsChildDoc())
114 LwpVersionManager::Read(pStrm);
116 m_ObjMgr.Read(pStrm);
118 m_MarkerHead.ReadIndexed(pStrm);
119 m_FootnoteMgr.ReadIndexed(pStrm);
121 m_NumMgr.Read(pStrm);
122 m_BulMgr.Read(pStrm);
124 m_SectionList.Read(pStrm);
125 m_Layout.ReadIndexed(pStrm);
127 ReadStyles(pStrm);
129 m_BookMarkHead.ReadIndexed(pStrm);
130 m_DdeLinkHead.ReadIndexed(pStrm);
131 m_DirtBagHead.ReadIndexed(pStrm);
132 m_NamedOutlineSeqHead.ReadIndexed(pStrm);
134 m_EnumLayoutHead.ReadIndexed(pStrm);
135 m_EnumLayoutTail.ReadIndexed(pStrm);
136 m_NamedObjects.ReadIndexed(pStrm);
138 m_nLastClickHere = pStrm->QuickReaduInt32();
139 m_SmartTextMgr.ReadIndexed(pStrm);
141 m_ContentMgr.Read(pStrm);
142 m_FontMgr.Read(pStrm);
144 if (!m_pDoc->IsChildDoc() && LwpFileHeader::m_nFileRevision >= 0x000B)
146 m_pPieceMgr = new LwpPieceManager();
148 m_pPieceMgr->Read(pStrm);
151 if( LwpFileHeader::m_nFileRevision >= 0x000B)
153 m_DftDropCapStyle.ReadIndexed(pStrm);
155 if( LwpFileHeader::m_nFileRevision >= 0x000F)
157 m_DftHeaderStyle.ReadIndexed(pStrm);
158 m_DftFooterStyle.ReadIndexed(pStrm);
160 pStrm->SkipExtra();
162 m_pStyleMgr = new LwpStyleManager();
163 m_pStyleMgr->SetFoundry(this);
166 void LwpFoundry::ReadStyles(LwpObjectStream *pStrm)
168 m_TextStyle.ReadIndexed(pStrm);
169 m_DefaultTextStyle.ReadIndexed(pStrm);
170 m_DefaultClickStyle.ReadIndexed(pStrm);
171 m_PageStyle.ReadIndexed(pStrm);
172 m_FrameStyle.ReadIndexed(pStrm);
174 m_TableStyle.ReadIndexed(pStrm);
175 m_CellStyle.ReadIndexed(pStrm);
176 m_DftFrameStyle.ReadIndexed(pStrm);
177 m_DftPageStyle.ReadIndexed(pStrm);
178 m_DftTableStyle.ReadIndexed(pStrm);
180 m_DftCellStyle.ReadIndexed(pStrm);
181 m_DftColumnStyle.ReadIndexed(pStrm);
182 m_DftLeftColumnStyle.ReadIndexed(pStrm);
183 m_DftRighColumnStyle.ReadIndexed(pStrm);
187 #include "xfilter/xfstylemanager.hxx"
188 #include "lwplayout.hxx"
190 void LwpFoundry::RegisterAllLayouts()
192 if (m_bRegisteredAll)
194 OSL_FAIL("recursive LwpFoundry::RegisterAllLayouts!\n");
195 return;
198 m_bRegisteredAll = true;
200 //Register CellStyle
201 rtl::Reference<LwpObject> pStyle = m_CellStyle.obj();
202 if( pStyle.is() )
204 pStyle->SetFoundry(this);
205 pStyle->RegisterStyle();
208 //register content page layout list: Layout
209 pStyle = m_Layout.obj();
210 if( pStyle.is() )
212 pStyle->SetFoundry(this);
213 pStyle->RegisterStyle();
216 //Register page style layout list: PageStyle, such as "Default Page"
217 pStyle = m_PageStyle.obj();
218 if( pStyle.is() )
220 pStyle->SetFoundry(this);
221 pStyle->RegisterStyle();
224 //Register FrameStyle
225 pStyle = m_FrameStyle.obj();
226 if( pStyle.is() )
228 pStyle->SetFoundry(this);
229 pStyle->RegisterStyle();
234 LwpBookMark* LwpFoundry::GetBookMark(LwpObjectID objMarker)
236 LwpDLVListHeadHolder* pHeadHolder= static_cast
237 <LwpDLVListHeadHolder*>(m_BookMarkHead.obj().get());
238 LwpObjectID& rObjID = pHeadHolder->GetHeadID();
239 LwpBookMark* pBookMark;
240 pBookMark = static_cast<LwpBookMark*>(rObjID.obj().get());
242 while (pBookMark)
244 if (pBookMark->IsRightMarker(objMarker))
245 return pBookMark;
246 rObjID = pBookMark->GetNext();
247 pBookMark = static_cast<LwpBookMark*>(rObjID.obj().get());
249 return NULL;
253 * @descr: Get next content
256 LwpContent* LwpFoundry::EnumContents(LwpContent * pContent)
258 return GetContentManager().EnumContents(pContent);
262 * @descr: Get next section
265 LwpSection* LwpFoundry::EnumSections(LwpSection * pSection)
267 return static_cast<LwpSection*>(m_SectionList.Enumerate(pSection));
271 * @descr: Get default text style id
274 LwpObjectID * LwpFoundry::GetDefaultTextStyle()
276 LwpVersionedPointer * pPointer = static_cast<LwpVersionedPointer *>(m_DefaultTextStyle.obj().get());
277 if (!pPointer)
278 return NULL;
280 return &pPointer->GetPointer();
284 * @descr: Get paragraph style object id according to its style name
287 LwpObjectID * LwpFoundry::FindParaStyleByName(const OUString& name)
289 //Register all text styles: para styles, character styles
290 LwpDLVListHeadHolder* pParaStyleHolder = static_cast<LwpDLVListHeadHolder*>(GetTextStyleHead().obj().get());
291 if(pParaStyleHolder)
293 LwpTextStyle* pParaStyle = static_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID().obj().get());
294 while(pParaStyle)
296 OUString strName = pParaStyle->GetName().str();
297 if(strName == name)
298 return &pParaStyle->GetObjectID();
299 pParaStyle = static_cast<LwpTextStyle*>(pParaStyle->GetNext().obj().get());
303 return NULL;
307 * @descr: Get style name registered according the original style name
310 OUString LwpFoundry::FindActuralStyleName(const OUString& name)
312 LwpObjectID* pID = FindParaStyleByName(name);
313 if(pID)
315 IXFStyle* pStyle = GetStyleManager()->GetStyle(*pID);
316 if(pStyle)
318 return pStyle->GetStyleName();
322 return name;
325 void LwpVersionManager::Read(LwpObjectStream *pStrm)
327 // TODO: skip the data for prototype
328 Skip(pStrm);
331 void LwpVersionManager::Skip(LwpObjectStream *pStrm)
333 pStrm->QuickReaduInt32();
334 sal_uInt16 Count = pStrm->QuickReaduInt16();
336 while(Count--)
338 sal_uInt32 tag = pStrm->QuickReaduInt32();
339 switch(tag)
341 case TAG_USER_VERSION:
342 // TODO: skip the CUserVersionControl
343 pStrm->SeekRel(pStrm->QuickReaduInt16());
344 break;
346 default:
347 pStrm->SeekRel(pStrm->QuickReaduInt16());
348 pStrm->SkipExtra();
349 break;
352 pStrm->SkipExtra();
355 void LwpObjectManager::Read(LwpObjectStream *pStrm)
358 LwpObjectID dummy;
359 dummy.Read(pStrm);
360 // TODO: judge if we need to set the cDelta by the dummy id
362 m_Division.ReadIndexed(pStrm);
363 pStrm->SkipExtra();
366 void LwpNumberManager::Read(LwpObjectStream *pStrm)
368 m_TableRange.ReadIndexed(pStrm);
369 pStrm->SkipExtra();
372 void LwpBulletManager::Read(LwpObjectStream *pStrm)
374 m_Head.ReadIndexed(pStrm);
375 pStrm->SkipExtra();
378 void LwpContentManager::Read(LwpObjectStream *pStrm)
380 m_ContentList.ReadIndexed(pStrm);
382 // TODO: to judge the file revision
384 m_EnumHead.ReadIndexed(pStrm);
385 m_EnumTail.ReadIndexed(pStrm);
387 m_OleObjCount.ReadIndexed(pStrm);
389 if( LwpFileHeader::m_nFileRevision >= 0x000B)
391 m_GrapHead.ReadIndexed(pStrm);
392 m_GrapTail.ReadIndexed(pStrm);
393 m_OleHead.ReadIndexed(pStrm);
394 m_OleTail.ReadIndexed(pStrm);
397 pStrm->SkipExtra();
401 * @descr: Get next content
404 LwpContent* LwpContentManager::EnumContents(LwpContent* pContent)
406 if(pContent)
407 return pContent->GetNextEnumerated();
408 LwpVersionedPointer* pPointer = static_cast<LwpVersionedPointer*>(m_EnumHead.obj().get());
409 return pPointer ? static_cast<LwpContent*>(pPointer->GetPointer().obj().get()) : NULL;
412 void LwpPieceManager::Read(LwpObjectStream *pStrm)
414 m_GeometryPieceList.ReadIndexed(pStrm);
415 m_ScalePieceList.ReadIndexed(pStrm);
416 m_MarginsPieceList.ReadIndexed(pStrm);
417 m_ColumnsPieceList.ReadIndexed(pStrm);
418 m_BorderStuffPieceList.ReadIndexed(pStrm);
420 m_GutterStuffPieceList.ReadIndexed(pStrm);
421 m_BackgroundStuffPieceList.ReadIndexed(pStrm);
422 m_JoinStuffPieceList.ReadIndexed(pStrm);
423 m_ShadowPieceList.ReadIndexed(pStrm);
424 m_NumericsPieceList.ReadIndexed(pStrm);
426 m_RelativityPieceList.ReadIndexed(pStrm);
427 m_AlignmentPieceList.ReadIndexed(pStrm);
428 m_IndentPieceList.ReadIndexed(pStrm);
429 m_ParaBorderPieceList.ReadIndexed(pStrm);
430 m_SpacingPieceList.ReadIndexed(pStrm);
432 m_BreaksPieceList.ReadIndexed(pStrm);
433 m_NumberingPieceList.ReadIndexed(pStrm);
434 m_TabPieceList.ReadIndexed(pStrm);
435 m_CharacterBorderPieceList.ReadIndexed(pStrm);
436 m_AmikakePieceList.ReadIndexed(pStrm);
438 if(pStrm->CheckExtra())
440 m_ParaBackgroundPieceList.ReadIndexed(pStrm);
441 m_ExternalBorderStuffPieceList.ReadIndexed(pStrm);
442 m_ExternalJoinStuffPieceList.ReadIndexed(pStrm);
443 pStrm->SkipExtra();
447 void LwpOrderedObjectManager::Read(LwpObjectStream *pStrm)
449 m_Head.ReadIndexed(pStrm);
453 * @descr: Get next orderedobject, copy from lwp source code
456 LwpOrderedObject* LwpOrderedObjectManager::Enumerate(LwpOrderedObject * pLast)
458 // If Last has a next, return it.
459 if(pLast && !pLast->GetNext().IsNull())
460 return static_cast<LwpOrderedObject*>(pLast->GetNext().obj().get());
462 LwpListList* pList = NULL;
463 if(pLast)
465 // We're at the end of Last's list (not Liszt's list).
466 // Start with the next active list
467 pList = static_cast<LwpListList*>(pLast->GetListList().obj().get());
468 pList= GetNextActiveListList(pList);
470 else
472 // Start with the first active ListList
473 pList = GetNextActiveListList(NULL);
476 if(pList)
478 return static_cast<LwpOrderedObject*>(pList->GetHead().obj().get());
481 return NULL;
485 * @descr: Get next listlist object, copy from lwp source code
488 LwpListList* LwpOrderedObjectManager::GetNextActiveListList(LwpListList * pLast)
490 LwpListList* pList = NULL;
491 if(pLast)
492 pList = static_cast<LwpListList*>(pLast->GetNext().obj().get());
493 else
495 LwpDLVListHeadHolder* pHeadHolder= static_cast<LwpDLVListHeadHolder*>(m_Head.obj().get());
496 if(pHeadHolder)
498 pList = static_cast<LwpListList*>(pHeadHolder->GetHeadID().obj().get());
502 while(pList)
504 LwpContent* pContent = static_cast<LwpContent*>(pList->GetObject().obj().get());
505 if(pContent && pContent->HasNonEmbeddedLayouts() &&
506 !pContent->IsStyleContent())
507 return pList;
508 pList = static_cast<LwpListList*>(pList->GetNext().obj().get());
510 return NULL;
513 LwpStyleManager::LwpStyleManager()
514 : m_pFoundry(0)
518 LwpStyleManager::~LwpStyleManager()
520 m_StyleList.clear();
524 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its created style to XFStyleManager
525 1. Add the style to XFStyleManager, and return the <office:styles> style name
526 2. Add it to LwpParaStyleMap.
527 Prerequisite: pStyle has been created and all properties has been set to it.
528 Return the XFStyle* added by XFStyleManager
530 IXFStyle* LwpStyleManager::AddStyle(LwpObjectID styleObjID, IXFStyle* pStyle)
532 assert(pStyle);
533 //pStyle may change if same style is found in XFStyleManager
534 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
535 pStyle = pXFStyleManager->AddStyle(pStyle).m_pStyle;
536 m_StyleList.insert(LwpStyleMap::value_type(styleObjID, pStyle));
537 return pStyle;
541 Called by VO_PARA or other objects to get style name based on the Style object ID
542 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
543 Prerequisite: VO_PARASTYLE/VO_CHARACTERSTYLE should call AddStyle first.
544 Return empty string if no style found.
546 IXFStyle* LwpStyleManager::GetStyle(const LwpObjectID &styleObjID)
548 LwpStyleMap::const_iterator it = m_StyleList.find(styleObjID);
549 if (it != m_StyleList.end()) {
550 return((*it).second);
552 return NULL;
555 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */