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 ************************************************************************/
61 #include "lwpfoundry.hxx"
62 #include "lwpfilehdr.hxx"
64 #include "lwpmarker.hxx"
65 #include "lwpholder.hxx"
66 #include "lwpbulletstylemgr.hxx"
67 #include "lwpcontent.hxx"
68 #include "lwpvpointer.hxx"
69 #include "lwpsection.hxx"
70 #include "lwpcharacterstyle.hxx"
71 #include "lwpglobalmgr.hxx"
72 #include "xfilter/xfstylemanager.hxx"
73 #include "lwplayout.hxx"
76 #include <osl/diagnose.h>
79 LwpFoundry::LwpFoundry(LwpObjectStream
*pStrm
, LwpDocument
* pDoc
)
81 , m_bRegisteredAll(false)
82 , m_pPieceMgr(nullptr)
83 , m_pStyleMgr(nullptr)
86 m_pDropcapMgr
= new LwpDropcapMgr
;
87 m_pBulletStyleMgr
= new LwpBulletStyleMgr();
88 m_pBulletStyleMgr
->SetFoundry(this);
91 LwpFoundry::~LwpFoundry()
96 delete m_pBulletStyleMgr
;
99 void LwpFoundry::Read(LwpObjectStream
*pStrm
)
101 if (!m_pDoc
->IsChildDoc())
103 LwpVersionManager::Read(pStrm
);
105 m_ObjMgr
.Read(pStrm
);
107 m_MarkerHead
.ReadIndexed(pStrm
);
108 m_FootnoteMgr
.ReadIndexed(pStrm
);
110 m_NumMgr
.Read(pStrm
);
111 m_BulMgr
.Read(pStrm
);
113 m_SectionList
.Read(pStrm
);
114 m_Layout
.ReadIndexed(pStrm
);
118 m_BookMarkHead
.ReadIndexed(pStrm
);
119 m_DdeLinkHead
.ReadIndexed(pStrm
);
120 m_DirtBagHead
.ReadIndexed(pStrm
);
121 m_NamedOutlineSeqHead
.ReadIndexed(pStrm
);
123 m_EnumLayoutHead
.ReadIndexed(pStrm
);
124 m_EnumLayoutTail
.ReadIndexed(pStrm
);
125 m_NamedObjects
.ReadIndexed(pStrm
);
127 m_nLastClickHere
= pStrm
->QuickReaduInt32();
128 m_SmartTextMgr
.ReadIndexed(pStrm
);
130 m_ContentMgr
.Read(pStrm
);
131 m_FontMgr
.Read(pStrm
);
133 if (!m_pDoc
->IsChildDoc() && LwpFileHeader::m_nFileRevision
>= 0x000B)
135 m_pPieceMgr
= new LwpPieceManager();
137 m_pPieceMgr
->Read(pStrm
);
140 if( LwpFileHeader::m_nFileRevision
>= 0x000B)
142 m_DftDropCapStyle
.ReadIndexed(pStrm
);
144 if( LwpFileHeader::m_nFileRevision
>= 0x000F)
146 m_DftHeaderStyle
.ReadIndexed(pStrm
);
147 m_DftFooterStyle
.ReadIndexed(pStrm
);
151 m_pStyleMgr
= new LwpStyleManager();
152 m_pStyleMgr
->SetFoundry(this);
155 void LwpFoundry::ReadStyles(LwpObjectStream
*pStrm
)
157 m_TextStyle
.ReadIndexed(pStrm
);
158 m_DefaultTextStyle
.ReadIndexed(pStrm
);
159 m_DefaultClickStyle
.ReadIndexed(pStrm
);
160 m_PageStyle
.ReadIndexed(pStrm
);
161 m_FrameStyle
.ReadIndexed(pStrm
);
163 m_TableStyle
.ReadIndexed(pStrm
);
164 m_CellStyle
.ReadIndexed(pStrm
);
165 m_DftFrameStyle
.ReadIndexed(pStrm
);
166 m_DftPageStyle
.ReadIndexed(pStrm
);
167 m_DftTableStyle
.ReadIndexed(pStrm
);
169 m_DftCellStyle
.ReadIndexed(pStrm
);
170 m_DftColumnStyle
.ReadIndexed(pStrm
);
171 m_DftLeftColumnStyle
.ReadIndexed(pStrm
);
172 m_DftRighColumnStyle
.ReadIndexed(pStrm
);
176 void LwpFoundry::RegisterAllLayouts()
178 if (m_bRegisteredAll
)
180 OSL_FAIL("recursive LwpFoundry::RegisterAllLayouts!\n");
184 m_bRegisteredAll
= true;
187 rtl::Reference
<LwpObject
> pStyle
= m_CellStyle
.obj();
190 pStyle
->SetFoundry(this);
191 pStyle
->DoRegisterStyle();
194 //register content page layout list: Layout
195 pStyle
= m_Layout
.obj();
198 pStyle
->SetFoundry(this);
199 pStyle
->DoRegisterStyle();
202 //Register page style layout list: PageStyle, such as "Default Page"
203 pStyle
= m_PageStyle
.obj();
206 pStyle
->SetFoundry(this);
207 pStyle
->DoRegisterStyle();
210 //Register FrameStyle
211 pStyle
= m_FrameStyle
.obj();
214 pStyle
->SetFoundry(this);
215 pStyle
->DoRegisterStyle();
220 LwpBookMark
* LwpFoundry::GetBookMark(LwpObjectID objMarker
)
222 LwpDLVListHeadHolder
* pHeadHolder
= dynamic_cast
223 <LwpDLVListHeadHolder
*>(m_BookMarkHead
.obj().get());
228 LwpObjectID
& rObjID
= pHeadHolder
->GetHeadID();
229 LwpBookMark
* pBookMark
= dynamic_cast<LwpBookMark
*>(rObjID
.obj().get());
233 if (pBookMark
->IsRightMarker(objMarker
))
235 rObjID
= pBookMark
->GetNext();
236 pBookMark
= dynamic_cast<LwpBookMark
*>(rObjID
.obj().get());
242 * @descr: Get next content
245 LwpContent
* LwpFoundry::EnumContents(LwpContent
* pContent
)
247 return GetContentManager().EnumContents(pContent
);
251 * @descr: Get next section
254 LwpSection
* LwpFoundry::EnumSections(LwpSection
* pSection
)
256 return static_cast<LwpSection
*>(m_SectionList
.Enumerate(pSection
));
260 * @descr: Get default text style id
263 LwpObjectID
* LwpFoundry::GetDefaultTextStyle()
265 LwpVersionedPointer
* pPointer
= dynamic_cast<LwpVersionedPointer
*>(m_DefaultTextStyle
.obj().get());
269 return &pPointer
->GetPointer();
273 * @descr: Get paragraph style object id according to its style name
276 LwpObjectID
* LwpFoundry::FindParaStyleByName(const OUString
& name
)
278 //Register all text styles: para styles, character styles
279 LwpDLVListHeadHolder
* pParaStyleHolder
= dynamic_cast<LwpDLVListHeadHolder
*>(GetTextStyleHead().obj().get());
282 LwpTextStyle
* pParaStyle
= dynamic_cast<LwpTextStyle
*> (pParaStyleHolder
->GetHeadID().obj().get());
285 OUString strName
= pParaStyle
->GetName().str();
287 return &pParaStyle
->GetObjectID();
288 pParaStyle
= dynamic_cast<LwpTextStyle
*>(pParaStyle
->GetNext().obj().get());
296 * @descr: Get style name registered according the original style name
299 OUString
LwpFoundry::FindActuralStyleName(const OUString
& name
)
301 LwpObjectID
* pID
= FindParaStyleByName(name
);
304 IXFStyle
* pStyle
= GetStyleManager()->GetStyle(*pID
);
307 return pStyle
->GetStyleName();
314 void LwpVersionManager::Read(LwpObjectStream
*pStrm
)
316 // TODO: skip the data for prototype
320 void LwpVersionManager::Skip(LwpObjectStream
*pStrm
)
322 pStrm
->QuickReaduInt32();
323 sal_uInt16 Count
= pStrm
->QuickReaduInt16();
327 sal_uInt32 tag
= pStrm
->QuickReaduInt32();
330 case TAG_USER_VERSION
:
331 // TODO: skip the CUserVersionControl
332 pStrm
->SeekRel(pStrm
->QuickReaduInt16());
336 pStrm
->SeekRel(pStrm
->QuickReaduInt16());
344 void LwpObjectManager::Read(LwpObjectStream
*pStrm
)
349 // TODO: judge if we need to set the cDelta by the dummy id
351 m_Division
.ReadIndexed(pStrm
);
355 void LwpNumberManager::Read(LwpObjectStream
*pStrm
)
357 m_TableRange
.ReadIndexed(pStrm
);
361 void LwpBulletManager::Read(LwpObjectStream
*pStrm
)
363 m_Head
.ReadIndexed(pStrm
);
367 void LwpContentManager::Read(LwpObjectStream
*pStrm
)
369 m_ContentList
.ReadIndexed(pStrm
);
371 // TODO: to judge the file revision
373 m_EnumHead
.ReadIndexed(pStrm
);
374 m_EnumTail
.ReadIndexed(pStrm
);
376 m_OleObjCount
.ReadIndexed(pStrm
);
378 if( LwpFileHeader::m_nFileRevision
>= 0x000B)
380 m_GrapHead
.ReadIndexed(pStrm
);
381 m_GrapTail
.ReadIndexed(pStrm
);
382 m_OleHead
.ReadIndexed(pStrm
);
383 m_OleTail
.ReadIndexed(pStrm
);
390 * @descr: Get next content
393 LwpContent
* LwpContentManager::EnumContents(LwpContent
* pContent
)
396 return pContent
->GetNextEnumerated();
397 LwpVersionedPointer
* pPointer
= dynamic_cast<LwpVersionedPointer
*>(m_EnumHead
.obj().get());
398 return pPointer
? dynamic_cast<LwpContent
*>(pPointer
->GetPointer().obj().get()) : nullptr;
401 void LwpPieceManager::Read(LwpObjectStream
*pStrm
)
403 m_GeometryPieceList
.ReadIndexed(pStrm
);
404 m_ScalePieceList
.ReadIndexed(pStrm
);
405 m_MarginsPieceList
.ReadIndexed(pStrm
);
406 m_ColumnsPieceList
.ReadIndexed(pStrm
);
407 m_BorderStuffPieceList
.ReadIndexed(pStrm
);
409 m_GutterStuffPieceList
.ReadIndexed(pStrm
);
410 m_BackgroundStuffPieceList
.ReadIndexed(pStrm
);
411 m_JoinStuffPieceList
.ReadIndexed(pStrm
);
412 m_ShadowPieceList
.ReadIndexed(pStrm
);
413 m_NumericsPieceList
.ReadIndexed(pStrm
);
415 m_RelativityPieceList
.ReadIndexed(pStrm
);
416 m_AlignmentPieceList
.ReadIndexed(pStrm
);
417 m_IndentPieceList
.ReadIndexed(pStrm
);
418 m_ParaBorderPieceList
.ReadIndexed(pStrm
);
419 m_SpacingPieceList
.ReadIndexed(pStrm
);
421 m_BreaksPieceList
.ReadIndexed(pStrm
);
422 m_NumberingPieceList
.ReadIndexed(pStrm
);
423 m_TabPieceList
.ReadIndexed(pStrm
);
424 m_CharacterBorderPieceList
.ReadIndexed(pStrm
);
425 m_AmikakePieceList
.ReadIndexed(pStrm
);
427 if(pStrm
->CheckExtra())
429 m_ParaBackgroundPieceList
.ReadIndexed(pStrm
);
430 m_ExternalBorderStuffPieceList
.ReadIndexed(pStrm
);
431 m_ExternalJoinStuffPieceList
.ReadIndexed(pStrm
);
436 void LwpOrderedObjectManager::Read(LwpObjectStream
*pStrm
)
438 m_Head
.ReadIndexed(pStrm
);
442 * @descr: Get next orderedobject, copy from lwp source code
445 LwpOrderedObject
* LwpOrderedObjectManager::Enumerate(LwpOrderedObject
* pLast
)
447 // If Last has a next, return it.
448 if(pLast
&& !pLast
->GetNext().IsNull())
449 return dynamic_cast<LwpOrderedObject
*>(pLast
->GetNext().obj().get());
451 LwpListList
* pList
= nullptr;
454 // We're at the end of Last's list (not Liszt's list).
455 // Start with the next active list
456 pList
= dynamic_cast<LwpListList
*>(pLast
->GetListList().obj().get());
457 pList
= GetNextActiveListList(pList
);
461 // Start with the first active ListList
462 pList
= GetNextActiveListList(nullptr);
467 return dynamic_cast<LwpOrderedObject
*>(pList
->GetHead().obj().get());
474 * @descr: Get next listlist object, copy from lwp source code
477 LwpListList
* LwpOrderedObjectManager::GetNextActiveListList(LwpListList
* pLast
)
479 LwpListList
* pList
= nullptr;
481 pList
= dynamic_cast<LwpListList
*>(pLast
->GetNext().obj().get());
484 LwpDLVListHeadHolder
* pHeadHolder
= dynamic_cast<LwpDLVListHeadHolder
*>(m_Head
.obj().get());
487 pList
= dynamic_cast<LwpListList
*>(pHeadHolder
->GetHeadID().obj().get());
493 LwpContent
* pContent
= dynamic_cast<LwpContent
*>(pList
->GetObject().obj().get());
494 if (pContent
&& pContent
->HasNonEmbeddedLayouts() && !pContent
->IsStyleContent())
496 pList
= dynamic_cast<LwpListList
*>(pList
->GetNext().obj().get());
501 LwpStyleManager::LwpStyleManager()
502 : m_pFoundry(nullptr)
506 LwpStyleManager::~LwpStyleManager()
512 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its created style to XFStyleManager
513 1. Add the style to XFStyleManager, and return the <office:styles> style name
514 2. Add it to LwpParaStyleMap.
515 Prerequisite: pStyle has been created and all properties has been set to it.
516 Return the XFStyle* added by XFStyleManager
518 void LwpStyleManager::AddStyle(LwpObjectID styleObjID
, IXFStyle
* pStyle
)
521 //pStyle may change if same style is found in XFStyleManager
522 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
523 pStyle
= pXFStyleManager
->AddStyle(pStyle
).m_pStyle
;
524 m_StyleList
.insert(LwpStyleMap::value_type(styleObjID
, pStyle
));
528 Called by VO_PARA or other objects to get style name based on the Style object ID
529 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
530 Prerequisite: VO_PARASTYLE/VO_CHARACTERSTYLE should call AddStyle first.
531 Return empty string if no style found.
533 IXFStyle
* LwpStyleManager::GetStyle(const LwpObjectID
&styleObjID
)
535 LwpStyleMap::const_iterator it
= m_StyleList
.find(styleObjID
);
536 if (it
!= m_StyleList
.end()) {
537 return((*it
).second
);
542 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */