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 /*************************************************************************
58 * For LWP filter architecture prototype
59 ************************************************************************/
60 /*************************************************************************
63 ************************************************************************/
65 #include "lwpfoundry.hxx"
66 #include "lwpfilehdr.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
)
79 , m_bRegisteredAll(false)
84 m_pDropcapMgr
= new LwpDropcapMgr
;
85 m_pBulletStyleMgr
= new LwpBulletStyleMgr();
86 m_pBulletStyleMgr
->SetFoundry(this);
89 LwpFoundry::~LwpFoundry()
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
);
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
);
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");
196 m_bRegisteredAll
= true;
199 LwpObject
* pStyle
= m_CellStyle
.obj();
202 pStyle
->SetFoundry(this);
203 pStyle
->RegisterStyle();
206 //register content page layout list: Layout
207 pStyle
= m_Layout
.obj();
210 pStyle
->SetFoundry(this);
211 pStyle
->RegisterStyle();
214 //Register page style layout list: PageStyle, such as "Default Page"
215 pStyle
= m_PageStyle
.obj();
218 pStyle
->SetFoundry(this);
219 pStyle
->RegisterStyle();
222 //Register FrameStyle
223 pStyle
= m_FrameStyle
.obj();
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
;
239 pBookMark
= static_cast<LwpBookMark
*>(pObjID
->obj());
245 if (pBookMark
->IsRightMarker(objMarker
))
247 pObjID
= pBookMark
->GetNext();
249 pBookMark
= static_cast<LwpBookMark
*>(pObjID
->obj());
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());
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());
297 LwpTextStyle
* pParaStyle
= static_cast<LwpTextStyle
*> (pParaStyleHolder
->GetHeadID()->obj());
300 OUString strName
= pParaStyle
->GetName()->str();
302 return pParaStyle
->GetObjectID();
303 pParaStyle
= static_cast<LwpTextStyle
*>(pParaStyle
->GetNext()->obj());
311 * @descr: Get style name registered according the original style name
314 OUString
LwpFoundry::FindActuralStyleName(OUString name
)
316 LwpObjectID
* pID
= FindParaStyleByName(name
);
319 IXFStyle
* pStyle
= GetStyleManager()->GetStyle(*pID
);
322 return pStyle
->GetStyleName();
329 void LwpVersionManager::Read(LwpObjectStream
*pStrm
)
331 // TODO: skip the data for prototype
335 void LwpVersionManager::Skip(LwpObjectStream
*pStrm
)
337 pStrm
->QuickReaduInt32();
338 sal_uInt16 Count
= pStrm
->QuickReaduInt16();
342 sal_uInt32 tag
= pStrm
->QuickReaduInt32();
345 case TAG_USER_VERSION
:
346 // TODO: skip the CUserVersionControl
347 pStrm
->SeekRel(pStrm
->QuickReaduInt16());
351 pStrm
->SeekRel(pStrm
->QuickReaduInt16());
359 void LwpObjectManager::Read(LwpObjectStream
*pStrm
)
364 // TODO: judge if we need to set the cDelta by the dummy id
366 m_Division
.ReadIndexed(pStrm
);
370 void LwpNumberManager::Read(LwpObjectStream
*pStrm
)
372 m_TableRange
.ReadIndexed(pStrm
);
376 void LwpBulletManager::Read(LwpObjectStream
*pStrm
)
378 m_Head
.ReadIndexed(pStrm
);
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
);
405 * @descr: Get next content
408 LwpContent
* LwpContentManager::EnumContents(LwpContent
* 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
);
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
;
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
);
476 // Start with the first active ListList
477 pList
= GetNextActiveListList(NULL
);
482 return static_cast<LwpOrderedObject
*>(pList
->GetHead()->obj());
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
;
497 pList
= static_cast<LwpListList
*>(pLast
->GetNext()->obj());
500 LwpDLVListHeadHolder
* pHeadHolder
= static_cast<LwpDLVListHeadHolder
*>(m_Head
.obj());
503 pList
= static_cast<LwpListList
*>(pHeadHolder
->GetHeadID()->obj());
509 pContent
= static_cast<LwpContent
*>(pList
->GetObject()->obj());
510 if(pContent
&& pContent
->HasNonEmbeddedLayouts() &&
511 !pContent
->IsStyleContent())
513 pList
= static_cast<LwpListList
*>(pList
->GetNext()->obj());
518 LwpStyleManager::LwpStyleManager()
523 LwpStyleManager::~LwpStyleManager()
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
)
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
));
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
);
562 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */