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 <lwpobjtags.hxx>
73 #include <xfilter/xfstylemanager.hxx>
75 #include <osl/diagnose.h>
77 LwpFoundry::LwpFoundry(LwpObjectStream
*pStrm
, LwpDocument
* pDoc
)
79 , m_bRegisteredAll(false)
82 m_xBulletStyleMgr
.reset(new LwpBulletStyleMgr
);
83 m_xBulletStyleMgr
->SetFoundry(this);
86 LwpFoundry::~LwpFoundry()
90 void LwpFoundry::Read(LwpObjectStream
*pStrm
)
92 if (!m_pDoc
->IsChildDoc())
94 LwpVersionManager::Read(pStrm
);
98 m_MarkerHead
.ReadIndexed(pStrm
);
99 m_FootnoteMgr
.ReadIndexed(pStrm
);
101 m_NumMgr
.Read(pStrm
);
102 m_BulMgr
.Read(pStrm
);
104 m_SectionList
.Read(pStrm
);
105 m_Layout
.ReadIndexed(pStrm
);
109 m_BookMarkHead
.ReadIndexed(pStrm
);
110 m_DdeLinkHead
.ReadIndexed(pStrm
);
111 m_DirtBagHead
.ReadIndexed(pStrm
);
112 m_NamedOutlineSeqHead
.ReadIndexed(pStrm
);
114 m_EnumLayoutHead
.ReadIndexed(pStrm
);
115 m_EnumLayoutTail
.ReadIndexed(pStrm
);
116 m_NamedObjects
.ReadIndexed(pStrm
);
118 m_nLastClickHere
= pStrm
->QuickReaduInt32();
119 m_SmartTextMgr
.ReadIndexed(pStrm
);
121 m_ContentMgr
.Read(pStrm
);
122 m_FontMgr
.Read(pStrm
);
124 if (!m_pDoc
->IsChildDoc() && LwpFileHeader::m_nFileRevision
>= 0x000B)
126 m_xPieceMgr
.reset(new LwpPieceManager
);
127 m_xPieceMgr
->Read(pStrm
);
130 if( LwpFileHeader::m_nFileRevision
>= 0x000B)
132 m_DftDropCapStyle
.ReadIndexed(pStrm
);
134 if( LwpFileHeader::m_nFileRevision
>= 0x000F)
136 m_DftHeaderStyle
.ReadIndexed(pStrm
);
137 m_DftFooterStyle
.ReadIndexed(pStrm
);
141 m_xStyleMgr
.reset(new LwpStyleManager
);
142 m_xStyleMgr
->SetFoundry(this);
145 void LwpFoundry::ReadStyles(LwpObjectStream
*pStrm
)
147 m_TextStyle
.ReadIndexed(pStrm
);
148 m_DefaultTextStyle
.ReadIndexed(pStrm
);
149 m_DefaultClickStyle
.ReadIndexed(pStrm
);
150 m_PageStyle
.ReadIndexed(pStrm
);
151 m_FrameStyle
.ReadIndexed(pStrm
);
153 m_TableStyle
.ReadIndexed(pStrm
);
154 m_CellStyle
.ReadIndexed(pStrm
);
155 m_DftFrameStyle
.ReadIndexed(pStrm
);
156 m_DftPageStyle
.ReadIndexed(pStrm
);
157 m_DftTableStyle
.ReadIndexed(pStrm
);
159 m_DftCellStyle
.ReadIndexed(pStrm
);
160 m_DftColumnStyle
.ReadIndexed(pStrm
);
161 m_DftLeftColumnStyle
.ReadIndexed(pStrm
);
162 m_DftRighColumnStyle
.ReadIndexed(pStrm
);
166 void LwpFoundry::RegisterAllLayouts()
168 if (m_bRegisteredAll
)
170 OSL_FAIL("recursive LwpFoundry::RegisterAllLayouts!");
174 m_bRegisteredAll
= true;
177 rtl::Reference
<LwpObject
> pStyle
= m_CellStyle
.obj();
180 pStyle
->SetFoundry(this);
181 pStyle
->DoRegisterStyle();
184 //register content page layout list: Layout
185 pStyle
= m_Layout
.obj();
188 pStyle
->SetFoundry(this);
189 pStyle
->DoRegisterStyle();
192 //Register page style layout list: PageStyle, such as "Default Page"
193 pStyle
= m_PageStyle
.obj();
196 pStyle
->SetFoundry(this);
197 pStyle
->DoRegisterStyle();
200 //Register FrameStyle
201 pStyle
= m_FrameStyle
.obj();
204 pStyle
->SetFoundry(this);
205 pStyle
->DoRegisterStyle();
210 LwpBookMark
* LwpFoundry::GetBookMark(LwpObjectID objMarker
)
212 LwpDLVListHeadHolder
* pHeadHolder
= dynamic_cast
213 <LwpDLVListHeadHolder
*>(m_BookMarkHead
.obj().get());
218 LwpObjectID
* pObjID
= &pHeadHolder
->GetHeadID();
219 LwpBookMark
* pBookMark
= dynamic_cast<LwpBookMark
*>(pObjID
->obj().get());
223 if (pBookMark
->IsRightMarker(objMarker
))
225 pObjID
= &pBookMark
->GetNext();
226 pBookMark
= dynamic_cast<LwpBookMark
*>(pObjID
->obj().get());
232 * @descr: Get next content
235 LwpContent
* LwpFoundry::EnumContents(LwpContent
* pContent
)
237 return GetContentManager().EnumContents(pContent
);
241 * @descr: Get next section
244 LwpSection
* LwpFoundry::EnumSections(LwpSection
* pSection
)
246 return static_cast<LwpSection
*>(m_SectionList
.Enumerate(pSection
));
250 * @descr: Get default text style id
253 LwpObjectID
* LwpFoundry::GetDefaultTextStyle()
255 LwpVersionedPointer
* pPointer
= dynamic_cast<LwpVersionedPointer
*>(m_DefaultTextStyle
.obj().get());
259 return &pPointer
->GetPointer();
263 * @descr: Get paragraph style object id according to its style name
266 LwpObjectID
* LwpFoundry::FindParaStyleByName(std::u16string_view name
)
268 LwpDLVListHeadHolder
* pParaStyleHolder
= dynamic_cast<LwpDLVListHeadHolder
*>(GetTextStyleHead().obj().get());
271 LwpTextStyle
* pParaStyle
= dynamic_cast<LwpTextStyle
*> (pParaStyleHolder
->GetHeadID().obj().get());
274 OUString strName
= pParaStyle
->GetName().str();
276 return &pParaStyle
->GetObjectID();
277 pParaStyle
= dynamic_cast<LwpTextStyle
*>(pParaStyle
->GetNext().obj().get());
285 * @descr: Get style name registered according the original style name
288 OUString
LwpFoundry::FindActualStyleName(const OUString
& name
)
290 LwpObjectID
* pID
= FindParaStyleByName(name
);
293 IXFStyle
* pStyle
= GetStyleManager()->GetStyle(*pID
);
296 return pStyle
->GetStyleName();
303 void LwpVersionManager::Read(LwpObjectStream
*pStrm
)
305 // TODO: skip the data for prototype
309 void LwpVersionManager::Skip(LwpObjectStream
*pStrm
)
311 pStrm
->QuickReaduInt32();
312 sal_uInt16 Count
= pStrm
->QuickReaduInt16();
316 sal_uInt32 tag
= pStrm
->QuickReaduInt32();
319 case TAG_USER_VERSION
:
320 // TODO: skip the CUserVersionControl
321 pStrm
->SeekRel(pStrm
->QuickReaduInt16());
325 pStrm
->SeekRel(pStrm
->QuickReaduInt16());
333 void LwpObjectManager::Read(LwpObjectStream
*pStrm
)
338 // TODO: judge if we need to set the cDelta by the dummy id
340 m_Division
.ReadIndexed(pStrm
);
344 void LwpNumberManager::Read(LwpObjectStream
*pStrm
)
346 m_TableRange
.ReadIndexed(pStrm
);
350 void LwpBulletManager::Read(LwpObjectStream
*pStrm
)
352 m_Head
.ReadIndexed(pStrm
);
356 void LwpContentManager::Read(LwpObjectStream
*pStrm
)
358 m_ContentList
.ReadIndexed(pStrm
);
360 // TODO: to judge the file revision
362 m_EnumHead
.ReadIndexed(pStrm
);
363 m_EnumTail
.ReadIndexed(pStrm
);
365 m_OleObjCount
.ReadIndexed(pStrm
);
367 if( LwpFileHeader::m_nFileRevision
>= 0x000B)
369 m_GrapHead
.ReadIndexed(pStrm
);
370 m_GrapTail
.ReadIndexed(pStrm
);
371 m_OleHead
.ReadIndexed(pStrm
);
372 m_OleTail
.ReadIndexed(pStrm
);
379 * @descr: Get next content
382 LwpContent
* LwpContentManager::EnumContents(LwpContent
* pContent
)
385 return pContent
->GetNextEnumerated();
386 LwpVersionedPointer
* pPointer
= dynamic_cast<LwpVersionedPointer
*>(m_EnumHead
.obj().get());
387 return pPointer
? dynamic_cast<LwpContent
*>(pPointer
->GetPointer().obj().get()) : nullptr;
390 void LwpPieceManager::Read(LwpObjectStream
*pStrm
)
392 m_GeometryPieceList
.ReadIndexed(pStrm
);
393 m_ScalePieceList
.ReadIndexed(pStrm
);
394 m_MarginsPieceList
.ReadIndexed(pStrm
);
395 m_ColumnsPieceList
.ReadIndexed(pStrm
);
396 m_BorderStuffPieceList
.ReadIndexed(pStrm
);
398 m_GutterStuffPieceList
.ReadIndexed(pStrm
);
399 m_BackgroundStuffPieceList
.ReadIndexed(pStrm
);
400 m_JoinStuffPieceList
.ReadIndexed(pStrm
);
401 m_ShadowPieceList
.ReadIndexed(pStrm
);
402 m_NumericsPieceList
.ReadIndexed(pStrm
);
404 m_RelativityPieceList
.ReadIndexed(pStrm
);
405 m_AlignmentPieceList
.ReadIndexed(pStrm
);
406 m_IndentPieceList
.ReadIndexed(pStrm
);
407 m_ParaBorderPieceList
.ReadIndexed(pStrm
);
408 m_SpacingPieceList
.ReadIndexed(pStrm
);
410 m_BreaksPieceList
.ReadIndexed(pStrm
);
411 m_NumberingPieceList
.ReadIndexed(pStrm
);
412 m_TabPieceList
.ReadIndexed(pStrm
);
413 m_CharacterBorderPieceList
.ReadIndexed(pStrm
);
414 m_AmikakePieceList
.ReadIndexed(pStrm
);
416 if(pStrm
->CheckExtra())
418 m_ParaBackgroundPieceList
.ReadIndexed(pStrm
);
419 m_ExternalBorderStuffPieceList
.ReadIndexed(pStrm
);
420 m_ExternalJoinStuffPieceList
.ReadIndexed(pStrm
);
425 void LwpOrderedObjectManager::Read(LwpObjectStream
*pStrm
)
427 m_Head
.ReadIndexed(pStrm
);
431 * @descr: Get next orderedobject, copy from lwp source code
434 LwpOrderedObject
* LwpOrderedObjectManager::Enumerate(LwpOrderedObject
* pLast
)
436 // If Last has a next, return it.
437 if(pLast
&& !pLast
->GetNext().IsNull())
438 return dynamic_cast<LwpOrderedObject
*>(pLast
->GetNext().obj().get());
440 LwpListList
* pList
= nullptr;
443 // We're at the end of Last's list (not list's list).
444 // Start with the next active list
445 pList
= dynamic_cast<LwpListList
*>(pLast
->GetListList().obj().get());
446 pList
= GetNextActiveListList(pList
);
450 // Start with the first active ListList
451 pList
= GetNextActiveListList(nullptr);
456 return dynamic_cast<LwpOrderedObject
*>(pList
->GetHead().obj().get());
463 * @descr: Get next listlist object, copy from lwp source code
466 LwpListList
* LwpOrderedObjectManager::GetNextActiveListList(LwpListList
* pLast
)
468 LwpListList
* pList
= nullptr;
470 pList
= dynamic_cast<LwpListList
*>(pLast
->GetNext().obj().get());
473 LwpDLVListHeadHolder
* pHeadHolder
= dynamic_cast<LwpDLVListHeadHolder
*>(m_Head
.obj().get());
476 pList
= dynamic_cast<LwpListList
*>(pHeadHolder
->GetHeadID().obj().get());
482 LwpContent
* pContent
= dynamic_cast<LwpContent
*>(pList
->GetObject().obj().get());
483 if (pContent
&& pContent
->HasNonEmbeddedLayouts() && !pContent
->IsStyleContent())
485 pList
= dynamic_cast<LwpListList
*>(pList
->GetNext().obj().get());
490 LwpStyleManager::LwpStyleManager()
491 : m_pFoundry(nullptr)
495 LwpStyleManager::~LwpStyleManager()
501 VO_PARASTYLE/VO_CHARACTERSTYLE call this method to add its created style to XFStyleManager
502 1. Add the style to XFStyleManager, and return the <office:styles> style name
503 2. Add it to LwpParaStyleMap.
504 Prerequisite: pStyle has been created and all properties has been set to it.
505 Return the XFStyle* added by XFStyleManager
507 void LwpStyleManager::AddStyle(LwpObjectID styleObjID
, std::unique_ptr
<IXFStyle
> pNewStyle
)
510 //pStyle may change if same style is found in XFStyleManager
511 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
512 auto pStyle
= pXFStyleManager
->AddStyle(std::move(pNewStyle
)).m_pStyle
;
513 m_StyleList
.emplace(styleObjID
, pStyle
);
517 Called by VO_PARA or other objects to get style name based on the Style object ID
518 1) Get style from LwpParaStyleMap based on the LwpObjectID of VO_PARASTYLE.
519 Prerequisite: VO_PARASTYLE/VO_CHARACTERSTYLE should call AddStyle first.
520 Return empty string if no style found.
522 IXFStyle
* LwpStyleManager::GetStyle(const LwpObjectID
&styleObjID
)
524 LwpStyleMap::const_iterator it
= m_StyleList
.find(styleObjID
);
525 if (it
!= m_StyleList
.end()) {
526 return((*it
).second
);
531 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */