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 #include "lwpglobalmgr.hxx"
58 #include "lwpfootnote.hxx"
59 #include "lwppagehint.hxx"
60 #include "lwpdivinfo.hxx"
61 #include "lwpholder.hxx"
62 #include "lwpparastyle.hxx"
63 #include "lwpstory.hxx"
64 #include "lwppara.hxx"
65 #include "lwpsilverbullet.hxx"
66 #include "lwplayout.hxx"
67 #include "lwppagelayout.hxx"
68 #include "xfilter/xfstylemanager.hxx"
69 #include <osl/thread.h>
71 LwpDocument::LwpDocument(LwpObjectHeader
& objHdr
, LwpSvStream
* pStrm
)
72 : LwpDLNFPVList(objHdr
, pStrm
), m_pOwnedFoundry(NULL
), m_pLnOpts(NULL
)
75 LwpDocument::~LwpDocument()
83 delete m_pOwnedFoundry
;
87 * @descr Read VO_Document from object stream
89 void LwpDocument::Read()
91 LwpDLNFPVList::Read();
95 m_nPersistentFlags
= m_pObjStrm
->QuickReaduInt32();
97 //Skip the SortOption and UIDocument
99 LwpSortOption
m_DocSort( m_pObjStrm
);
100 LwpUIDocument
m_UIDoc( m_pObjStrm
);
103 m_pLnOpts
= new LwpLineNumberOptions(m_pObjStrm
);
105 //Skip LwpUserDictFiles
107 LwpUserDictFiles
m_UsrDicts( m_pObjStrm
);
112 //Skip LwpPrinterInfo
113 LwpPrinterInfo
m_PrtInfo( m_pObjStrm
);
116 m_pFoundry
= m_pOwnedFoundry
= new LwpFoundry(m_pObjStrm
, this);
118 m_DivOpts
.ReadIndexed(m_pObjStrm
);
122 m_FootnoteOpts
.ReadIndexed(m_pObjStrm
);
123 m_DocData
.ReadIndexed(m_pObjStrm
);
127 //Skip the docdata used in old version
128 LwpObjectID dummyDocData
;
129 dummyDocData
.ReadIndexed(m_pObjStrm
);
131 m_DivInfo
.ReadIndexed(m_pObjStrm
);
132 m_Epoch
.Read(m_pObjStrm
);
133 m_WYSIWYGPageHints
.ReadIndexed(m_pObjStrm
);
134 m_VerDoc
.ReadIndexed(m_pObjStrm
);
135 m_STXInfo
.ReadIndexed(m_pObjStrm
);
139 * @descr Read plug related data from m_pObjStram
141 void LwpDocument::ReadPlug()
143 m_DocSockID
.ReadIndexed(m_pObjStrm
);
144 m_nFlags
= m_pObjStrm
->QuickReaduInt16();
145 m_pObjStrm
->SkipExtra();
149 * @descr Parse obj to IXFStream
151 void LwpDocument::Parse(IXFStream
* pOutputStream
)
153 //check the name and skip script division
154 if (!IsSkippedDivision())
156 //the frames which anchor are to page must output before other contents
157 ParseFrameInPage(pOutputStream
);
158 ParseDocContent(pOutputStream
);
161 LwpObject
* pDocSock
= GetSocket()->obj( VO_DOCSOCK
);
164 pDocSock
->Parse(pOutputStream
);
168 sal_Bool
LwpDocument::IsSkippedDivision()
171 sal_uInt8 ret
= sal_False
;
172 LwpDivInfo
* pDiv
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID()->obj(VO_DIVISIONINFO
));
175 sDivName
= pDiv
->GetDivName();
176 if (!sDivName
.isEmpty() && !pDiv
->IsGotoable()) //including toa,scripts division
178 //skip endnote division
179 OUString strClassName
= pDiv
->GetClassName();
180 if (strClassName
.equals(A2OUSTR(STR_DivisionEndnote
))
181 || strClassName
.equals(A2OUSTR(STR_DivisionGroupEndnote
))
182 || strClassName
.equals(A2OUSTR(STR_DocumentEndnote
)))
184 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pDiv
->GetInitialLayoutID()->obj(VO_PAGELAYOUT
));
187 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pPageLayout
->GetContent()->obj(VO_STORY
));
190 //This judgement maybe have problem. If there is only one para in the story,
191 //this endnote division has no other contents except endnote table.
192 LwpObjectID
* pFirst
= pStory
->GetFirstPara();
193 LwpObjectID
* pLast
= pStory
->GetLastPara();
194 if(*pFirst
== *pLast
)
203 * @descr Register all styles in this division
205 void LwpDocument::RegisterStyle()
207 RegisterDefaultParaStyles();
208 RegisterGraphicsStyles();
209 RegisterBulletStyles();
211 RegisterTextStyles();
212 RegisterLayoutStyles();
213 RegisterStylesInPara();
215 RegisterLinenumberStyles();
216 RegisterFootnoteStyles();
218 //Register styles in other document connected with this document: next doc, children doc
219 LwpObject
* pDocSock
= GetSocket()->obj();
222 pDocSock
->RegisterStyle();
226 * @descr Register all named para styles
228 void LwpDocument::RegisterTextStyles()
230 //Register all text styles: para styles, character styles
231 LwpDLVListHeadHolder
* pParaStyleHolder
= dynamic_cast<LwpDLVListHeadHolder
*>(m_pFoundry
->GetTextStyleHead()->obj());
234 LwpTextStyle
* pParaStyle
= dynamic_cast<LwpTextStyle
*> (pParaStyleHolder
->GetHeadID()->obj());
237 pParaStyle
->SetFoundry(m_pFoundry
);
238 pParaStyle
->RegisterStyle();
239 pParaStyle
= dynamic_cast<LwpParaStyle
*>(pParaStyle
->GetNext()->obj());
242 ChangeStyleName();//add by ,for click here block,05/5/26
245 * @descr Register all layouts styles (page master and master page)
246 * All para styles used in master page (header and footer) are registered and then showed
248 void LwpDocument::RegisterLayoutStyles()
250 //Register all layout styles, before register all styles in para
251 m_pFoundry
->RegisterAllLayouts();
253 //set initial pagelayout in story for parsing pagelayout
254 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*> (m_DivInfo
.obj( VO_DIVISIONINFO
));
255 LwpPageLayout
* pPageLayout
= NULL
;
258 pPageLayout
= dynamic_cast<LwpPageLayout
*>(pDivInfo
->GetInitialLayoutID()->obj(VO_PAGELAYOUT
));
261 //In Ole division, the content of pagelayout is VO_OLEOBJECT
262 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pPageLayout
->GetContent()->obj(VO_STORY
));
265 //add all the pagelayout in order into the pagelayout list;
266 pStory
->SortPageLayout();
267 pStory
->SetCurrentLayout(pPageLayout
);
273 * @descr Register all styles used in para
275 void LwpDocument::RegisterStylesInPara()
277 //Register all automatic styles in para
278 LwpHeadContent
* pContent
= dynamic_cast<LwpHeadContent
*> (m_pFoundry
->GetContentManager()->GetContentList()->obj());
281 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pContent
->GetChildHead()->obj(VO_STORY
));
284 //Register the child para
285 pStory
->SetFoundry(m_pFoundry
);
286 pStory
->RegisterStyle();
287 pStory
= dynamic_cast<LwpStory
*>(pStory
->GetNext()->obj(VO_STORY
));
292 * @descr Register all bullet styles used in this division
294 void LwpDocument::RegisterBulletStyles()
296 //Register bullet styles
297 LwpDLVListHeadHolder
* mBulletHead
= dynamic_cast<LwpDLVListHeadHolder
*>
298 (m_pFoundry
->GetBulletManagerID()->obj(VO_HEADHOLDER
));
301 LwpSilverBullet
* pBullet
= dynamic_cast<LwpSilverBullet
*>
302 (mBulletHead
->GetHeadID()->obj());
305 pBullet
->SetFoundry(m_pFoundry
);
306 pBullet
->RegisterStyle();
307 pBullet
= dynamic_cast<LwpSilverBullet
*> (pBullet
->GetNext()->obj());
312 * @descr Register all styles used in VO_Graphic
314 void LwpDocument::RegisterGraphicsStyles()
316 //Register all graphics styles, the first object should register the next;
317 LwpObject
* pGraphic
= m_pFoundry
->GetGraphicListHead()->obj(VO_GRAPHIC
);
320 pGraphic
->SetFoundry(m_pFoundry
);
321 pGraphic
->RegisterStyle();
325 * @descr Register line number styles
327 void LwpDocument::RegisterLinenumberStyles()
331 m_pLnOpts
->RegisterStyle();
335 * @descr Register footnote/endnote configuration for the entire document
337 void LwpDocument::RegisterFootnoteStyles()
339 //Register footnote and endnote configuration for the entire document
340 if(!m_FootnoteOpts
.IsNull())
342 LwpFootnoteOptions
* pFootnoteOpts
= dynamic_cast<LwpFootnoteOptions
*>(m_FootnoteOpts
.obj());
345 pFootnoteOpts
->SetMasterPage(A2OUSTR("Endnote"));
346 pFootnoteOpts
->RegisterStyle();
349 //Register endnote page style for endnote configuration, use the last division that has endnote for the endnote page style
350 //This page style must register after its division default styles have registered
351 LwpDocument
* pEndnoteDiv
= GetLastDivisionThatHasEndnote();
352 if(this == pEndnoteDiv
)
354 LwpDLVListHeadTailHolder
* pHeadTail
= dynamic_cast<LwpDLVListHeadTailHolder
*>(GetPageHintsID()->obj());
357 LwpPageHint
* pPageHint
= dynamic_cast<LwpPageHint
*>(pHeadTail
->GetTail()->obj());
358 if(pPageHint
&& !pPageHint
->GetPageLayoutID()->IsNull())
360 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pPageHint
->GetPageLayoutID()->obj());
363 pPageLayout
->SetFoundry(GetFoundry());
364 pPageLayout
->RegisterEndnoteStyle();
372 * @descr Register default para styles
374 #include "lwpverdocument.hxx"
375 void LwpDocument::RegisterDefaultParaStyles()
380 //LwpDocument* pFirstDoc = GetFirstDivision();
381 LwpDocument
* pFirstDoc
= GetFirstDivisionWithContentsThatIsNotOLE();
384 LwpVerDocument
* pVerDoc
= dynamic_cast<LwpVerDocument
*>(pFirstDoc
->GetVerDoc()->obj());
387 pVerDoc
->RegisterStyle();
395 * @descr Parse content in this division to IXFStream
396 * LwpDocument->LwpDivInfo->LwpPageLayout.Parse()
398 void LwpDocument::ParseDocContent(IXFStream
* pOutputStream
)
400 //Parse content in PageLayout
401 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*> (m_DivInfo
.obj());
402 if(pDivInfo
==NULL
) return;
404 LwpObject
* pLayoutObj
= pDivInfo
->GetInitialLayoutID()->obj();
407 //master document not supported now.
410 pLayoutObj
->SetFoundry(m_pFoundry
);
411 pLayoutObj
->Parse(pOutputStream
);
415 * @descr Get the footnoteoptions from the root document
417 LwpObjectID
* LwpDocument::GetValidFootnoteOpts()
419 LwpDocument
* pRoot
= GetRootDocument();
422 return pRoot
->GetFootnoteOpts();
428 * @descr Get the endnote type
430 sal_uInt16
LwpDocument::GetEndnoteType()
432 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID()->obj());
435 OUString strClassName
= pDivInfo
->GetClassName();
436 if (strClassName
.equals(A2OUSTR(STR_DivisionEndnote
)))
437 return FN_DIVISION_SEPARATE
;
438 if (strClassName
.equals(A2OUSTR(STR_DivisionGroupEndnote
)))
439 return FN_DIVISIONGROUP_SEPARATE
;
440 if (strClassName
.equals(A2OUSTR(STR_DocumentEndnote
)))
441 return FN_DOCUMENT_SEPARATE
;
445 * @descr Get previous division
447 LwpDocument
* LwpDocument::GetPreviousDivision()
449 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket()->obj());
452 return dynamic_cast<LwpDocument
*>(pDocSock
->GetPrevious()->obj());
457 * @descr Get next division
459 LwpDocument
* LwpDocument::GetNextDivision()
461 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket()->obj());
464 return dynamic_cast<LwpDocument
*>(pDocSock
->GetNext()->obj());
469 * @descr Get parent division
471 LwpDocument
* LwpDocument::GetParentDivision()
473 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket()->obj());
476 return dynamic_cast<LwpDocument
*>(pDocSock
->GetParent()->obj());
481 * @descr Get previous division in group, copy from lwp source code
483 LwpDocument
* LwpDocument::GetPreviousInGroup()
485 LwpDocument
* pPrev
= NULL
;
487 for (pPrev
= GetPreviousDivision(); pPrev
; pPrev
= pPrev
->GetPreviousDivision())
489 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(pPrev
->GetDivInfoID()->obj());
490 if(pDivInfo
&& pDivInfo
->HasContents())
496 * @descr Get previous division in group, copy from lwp source code
498 LwpDocument
* LwpDocument::GetNextInGroup()
500 LwpDocument
* pNext
= NULL
;
502 for (pNext
= GetNextDivision(); pNext
; pNext
= pNext
->GetNextDivision())
504 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(pNext
->GetDivInfoID()->obj());
505 if(pDivInfo
&& pDivInfo
->HasContents())
512 * @descr Get previous division which has contents, copy from lwp source code
514 LwpDocument
* LwpDocument::GetPreviousDivisionWithContents()
516 if(GetPreviousDivision())
518 LwpDocument
* pDoc
= GetPreviousDivision()->GetLastDivisionWithContents();
522 if(GetParentDivision())
523 return GetParentDivision()->GetPreviousDivisionWithContents();
527 * @descr Get last division which has contents, copy from lwp source code
529 LwpDocument
* LwpDocument::GetLastDivisionWithContents()
531 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID()->obj());
532 if(pDivInfo
&& pDivInfo
->HasContents())
537 LwpDocument
* pDivision
= GetLastDivision();
538 LwpDocument
* pContentDivision
= NULL
;
542 pContentDivision
= pDivision
->GetLastDivisionWithContents();
545 return pContentDivision
;
547 pDivision
= pDivision
->GetPreviousDivision();
553 * @descr Get last division in group which has contents, copy from lwp source code
555 LwpDocument
* LwpDocument::GetLastInGroupWithContents()
557 LwpDocument
* pLast
= NULL
;
558 LwpDocument
* pNext
= this;
562 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(pNext
->GetDivInfoID()->obj());
563 if (pDivInfo
&& pDivInfo
->HasContents())
565 pNext
= pNext
->GetNextInGroup();
572 * @descr Get last division
574 LwpDocument
* LwpDocument::GetLastDivision()
576 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket()->obj());
578 return dynamic_cast<LwpDocument
*>(pDocSock
->GetChildTail()->obj());
583 * @descr Get first division
585 LwpDocument
* LwpDocument::GetFirstDivision()
587 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket()->obj());
589 return dynamic_cast<LwpDocument
*>(pDocSock
->GetChildHead()->obj());
594 * @descr Get root document
596 LwpDocument
* LwpDocument::GetRootDocument()
598 LwpDocument
* pRoot
= this;
601 if(!pRoot
->IsChildDoc())
603 pRoot
= pRoot
->GetParentDivision();
608 * @descr Get first division with contents that is not ole, copy from lwp-source code
610 LwpDocument
* LwpDocument::GetFirstDivisionWithContentsThatIsNotOLE()
612 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID()->obj());
613 if(pDivInfo
&& pDivInfo
->HasContents()
614 && !pDivInfo
->IsOleDivision())
617 LwpDocument
* pDivision
= GetFirstDivision();
619 LwpDocument
* pContentDivision
= NULL
;
623 pContentDivision
= pDivision
->GetFirstDivisionWithContentsThatIsNotOLE();
625 return pContentDivision
;
626 pDivision
= pDivision
->GetNextDivision();
631 * @descr Get last division that has endnote
633 LwpDocument
* LwpDocument::GetLastDivisionThatHasEndnote()
635 LwpDocument
* pRoot
= GetRootDocument();
636 LwpDocument
*pLastDoc
= pRoot
->GetLastDivisionWithContents();
639 if(pLastDoc
->GetEnSuperTableLayout())
641 pLastDoc
= pLastDoc
->GetPreviousDivisionWithContents();
647 * @descr Get endnote supertable layout, every division has only one endnote supertable layout.
649 LwpVirtualLayout
* LwpDocument::GetEnSuperTableLayout()
651 LwpHeadLayout
* pHeadLayout
= dynamic_cast<LwpHeadLayout
*>(GetFoundry()->GetLayout()->obj());
654 return pHeadLayout
->FindEnSuperTableLayout();
660 * @descr Get the numbers of page before pEndDivision, copy from lwp source code
662 sal_Bool
LwpDocument::GetNumberOfPages(LwpDocument
* pEndDivision
, sal_uInt16
& nCount
)
664 if(this == pEndDivision
)
667 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(m_DivInfo
.obj());
670 pDivInfo
->GetNumberOfPages(nCount
);
673 LwpDocument
* pDivision
= GetFirstDivision();
676 if(pDivision
->GetNumberOfPages(pEndDivision
,nCount
))
678 pDivision
= pDivision
->GetNextDivision();
684 * @descr Get the numbers of page before curruent division
686 sal_uInt16
LwpDocument::GetNumberOfPagesBefore()
688 sal_uInt16 nPageNumber
= 0;
689 LwpDocument
* pRoot
= GetRootDocument();
691 pRoot
->GetNumberOfPages(this,nPageNumber
);
696 * @descr Get Max number of pages
698 void LwpDocument::MaxNumberOfPages(sal_uInt16
& nNumPages
)
700 LwpDocument
* pDivision
= GetFirstDivision();
702 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(m_DivInfo
.obj());
704 nNumPages
+= pDivInfo
->GetMaxNumberOfPages();
707 pDivision
->MaxNumberOfPages(nNumPages
);
708 pDivision
= pDivision
->GetNextDivision();
712 * @descr Parse the frame which anchor is to page before parse other contents,
713 * This method is called when the document is root document.
715 void LwpDocument::ParseFrameInPage(IXFStream
* pOutputStream
)
720 XFContentContainer
* pXFContainer
= new XFContentContainer
;
722 XFConvertFrameInPage(pXFContainer
);
724 pXFContainer
->ToXml(pOutputStream
);
729 * @descr Parse the frame which anchor is to page in the entire document
731 void LwpDocument::XFConvertFrameInPage(XFContentContainer
* pCont
)
733 LwpDocument
* pDivision
= GetFirstDivision();
735 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*> (GetDivInfoID()->obj());
738 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pDivInfo
->GetInitialLayoutID()->obj());
741 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pPageLayout
->GetContent()->obj());
743 pStory
->XFConvertFrameInPage(pCont
);
748 pDivision
->XFConvertFrameInPage(pCont
);
749 pDivision
= pDivision
->GetNextDivision();
753 * @descr change click here to placeholder
755 void LwpDocument::ChangeStyleName()
757 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
758 XFTextStyle
* pStyle
= dynamic_cast<XFTextStyle
*>(pXFStyleManager
->FindStyle(A2OUSTR("ClickHere")));
761 pStyle
->SetStyleName(A2OUSTR("Placeholder"));
764 LwpDocSock::LwpDocSock(LwpObjectHeader
& objHdr
, LwpSvStream
* pStrm
)
765 :LwpDLNFVList(objHdr
, pStrm
)
769 * @descr read VO_DOCSOCK from file
771 void LwpDocSock::Read()
773 LwpDLNFVList::Read();
774 m_Doc
.ReadIndexed(m_pObjStrm
);
775 m_pObjStrm
->SkipExtra();
778 * @descr register styles in documents plugged
780 void LwpDocSock::RegisterStyle()
782 LwpObject
* pDoc
= GetNext()->obj();
784 pDoc
->RegisterStyle();
786 pDoc
= GetChildHead()->obj();
788 pDoc
->RegisterStyle();
791 * @descr parse contents of documents plugged
793 void LwpDocSock::Parse(IXFStream
* pOutputStream
)
795 LwpObject
* pDoc
= GetChildHead()->obj();
797 pDoc
->Parse(pOutputStream
);
799 pDoc
= GetNext()->obj();
801 pDoc
->Parse(pOutputStream
);
804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */