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
)
73 , m_pOwnedFoundry(NULL
)
75 , m_nPersistentFlags(0)
80 LwpDocument::~LwpDocument()
88 delete m_pOwnedFoundry
;
92 * @descr Read VO_Document from object stream
94 void LwpDocument::Read()
96 LwpDLNFPVList::Read();
100 m_nPersistentFlags
= m_pObjStrm
->QuickReaduInt32();
102 //Skip the SortOption and UIDocument
104 LwpSortOption
m_DocSort( m_pObjStrm
);
105 LwpUIDocument
m_UIDoc( m_pObjStrm
);
108 m_pLnOpts
= new LwpLineNumberOptions(m_pObjStrm
);
110 //Skip LwpUserDictFiles
112 LwpUserDictFiles
m_UsrDicts( m_pObjStrm
);
117 //Skip LwpPrinterInfo
118 LwpPrinterInfo
m_PrtInfo( m_pObjStrm
);
121 m_pFoundry
= m_pOwnedFoundry
= new LwpFoundry(m_pObjStrm
, this);
123 m_DivOpts
.ReadIndexed(m_pObjStrm
);
127 m_FootnoteOpts
.ReadIndexed(m_pObjStrm
);
128 m_DocData
.ReadIndexed(m_pObjStrm
);
132 //Skip the docdata used in old version
133 LwpObjectID dummyDocData
;
134 dummyDocData
.ReadIndexed(m_pObjStrm
);
136 m_DivInfo
.ReadIndexed(m_pObjStrm
);
137 m_Epoch
.Read(m_pObjStrm
);
138 m_WYSIWYGPageHints
.ReadIndexed(m_pObjStrm
);
139 m_VerDoc
.ReadIndexed(m_pObjStrm
);
140 m_STXInfo
.ReadIndexed(m_pObjStrm
);
144 * @descr Read plug related data from m_pObjStram
146 void LwpDocument::ReadPlug()
148 m_DocSockID
.ReadIndexed(m_pObjStrm
);
149 m_nFlags
= m_pObjStrm
->QuickReaduInt16();
150 m_pObjStrm
->SkipExtra();
154 * @descr Parse obj to IXFStream
156 void LwpDocument::Parse(IXFStream
* pOutputStream
)
158 //check the name and skip script division
159 if (!IsSkippedDivision())
161 //the frames which anchor are to page must output before other contents
162 ParseFrameInPage(pOutputStream
);
163 ParseDocContent(pOutputStream
);
166 rtl::Reference
<LwpObject
> pDocSock
= GetSocket().obj( VO_DOCSOCK
);
169 pDocSock
->Parse(pOutputStream
);
173 bool LwpDocument::IsSkippedDivision()
177 LwpDivInfo
* pDiv
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID().obj(VO_DIVISIONINFO
).get());
180 sDivName
= pDiv
->GetDivName();
181 if (!sDivName
.isEmpty() && !pDiv
->IsGotoable()) //including toa,scripts division
183 //skip endnote division
184 OUString strClassName
= pDiv
->GetClassName();
185 if ((strClassName
== STR_DivisionEndnote
)
186 || (strClassName
== STR_DivisionGroupEndnote
)
187 || (strClassName
== STR_DocumentEndnote
))
189 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pDiv
->GetInitialLayoutID().obj(VO_PAGELAYOUT
).get());
192 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pPageLayout
->GetContent().obj(VO_STORY
).get());
195 //This judgement maybe have problem. If there is only one para in the story,
196 //this endnote division has no other contents except endnote table.
197 LwpObjectID
& rFirst
= pStory
->GetFirstPara();
198 LwpObjectID
& rLast
= pStory
->GetLastPara();
208 * @descr Register all styles in this division
210 void LwpDocument::RegisterStyle()
212 RegisterDefaultParaStyles();
213 RegisterGraphicsStyles();
214 RegisterBulletStyles();
216 RegisterTextStyles();
217 RegisterLayoutStyles();
218 RegisterStylesInPara();
220 RegisterLinenumberStyles();
221 RegisterFootnoteStyles();
223 //Register styles in other document connected with this document: next doc, children doc
224 rtl::Reference
<LwpObject
> pDocSock
= GetSocket().obj();
227 pDocSock
->RegisterStyle();
231 * @descr Register all named para styles
233 void LwpDocument::RegisterTextStyles()
235 //Register all text styles: para styles, character styles
236 LwpDLVListHeadHolder
* pParaStyleHolder
= dynamic_cast<LwpDLVListHeadHolder
*>(m_pFoundry
->GetTextStyleHead().obj().get());
239 LwpTextStyle
* pParaStyle
= dynamic_cast<LwpTextStyle
*> (pParaStyleHolder
->GetHeadID().obj().get());
242 pParaStyle
->SetFoundry(m_pFoundry
);
243 pParaStyle
->RegisterStyle();
244 pParaStyle
= dynamic_cast<LwpParaStyle
*>(pParaStyle
->GetNext().obj().get());
247 ChangeStyleName();//add by ,for click here block,05/5/26
250 * @descr Register all layouts styles (page master and master page)
251 * All para styles used in master page (header and footer) are registered and then showed
253 void LwpDocument::RegisterLayoutStyles()
255 //Register all layout styles, before register all styles in para
256 m_pFoundry
->RegisterAllLayouts();
258 //set initial pagelayout in story for parsing pagelayout
259 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*> (m_DivInfo
.obj( VO_DIVISIONINFO
).get());
262 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pDivInfo
->GetInitialLayoutID().obj(VO_PAGELAYOUT
).get());
265 //In Ole division, the content of pagelayout is VO_OLEOBJECT
266 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pPageLayout
->GetContent().obj(VO_STORY
).get());
269 //add all the pagelayout in order into the pagelayout list;
270 pStory
->SortPageLayout();
271 pStory
->SetCurrentLayout(pPageLayout
);
277 * @descr Register all styles used in para
279 void LwpDocument::RegisterStylesInPara()
281 //Register all automatic styles in para
282 LwpHeadContent
* pContent
= dynamic_cast<LwpHeadContent
*> (m_pFoundry
->GetContentManager().GetContentList().obj().get());
285 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pContent
->GetChildHead().obj(VO_STORY
).get());
288 //Register the child para
289 pStory
->SetFoundry(m_pFoundry
);
290 pStory
->RegisterStyle();
291 pStory
= dynamic_cast<LwpStory
*>(pStory
->GetNext().obj(VO_STORY
).get());
296 * @descr Register all bullet styles used in this division
298 void LwpDocument::RegisterBulletStyles()
300 //Register bullet styles
301 LwpDLVListHeadHolder
* mBulletHead
= dynamic_cast<LwpDLVListHeadHolder
*>
302 (m_pFoundry
->GetBulletManagerID().obj(VO_HEADHOLDER
).get());
305 LwpSilverBullet
* pBullet
= dynamic_cast<LwpSilverBullet
*>
306 (mBulletHead
->GetHeadID().obj().get());
309 pBullet
->SetFoundry(m_pFoundry
);
310 pBullet
->RegisterStyle();
311 pBullet
= dynamic_cast<LwpSilverBullet
*> (pBullet
->GetNext().obj().get());
316 * @descr Register all styles used in VO_Graphic
318 void LwpDocument::RegisterGraphicsStyles()
320 //Register all graphics styles, the first object should register the next;
321 rtl::Reference
<LwpObject
> pGraphic
= m_pFoundry
->GetGraphicListHead().obj(VO_GRAPHIC
);
324 pGraphic
->SetFoundry(m_pFoundry
);
325 pGraphic
->RegisterStyle();
329 * @descr Register line number styles
331 void LwpDocument::RegisterLinenumberStyles()
335 m_pLnOpts
->RegisterStyle();
339 * @descr Register footnote/endnote configuration for the entire document
341 void LwpDocument::RegisterFootnoteStyles()
343 //Register footnote and endnote configuration for the entire document
344 if(!m_FootnoteOpts
.IsNull())
346 LwpFootnoteOptions
* pFootnoteOpts
= dynamic_cast<LwpFootnoteOptions
*>(m_FootnoteOpts
.obj().get());
349 pFootnoteOpts
->SetMasterPage("Endnote");
350 pFootnoteOpts
->RegisterStyle();
353 //Register endnote page style for endnote configuration, use the last division that has endnote for the endnote page style
354 //This page style must register after its division default styles have registered
355 LwpDocument
* pEndnoteDiv
= GetLastDivisionThatHasEndnote();
356 if(this == pEndnoteDiv
)
358 LwpDLVListHeadTailHolder
* pHeadTail
= dynamic_cast<LwpDLVListHeadTailHolder
*>(GetPageHintsID().obj().get());
361 LwpPageHint
* pPageHint
= dynamic_cast<LwpPageHint
*>(pHeadTail
->GetTail().obj().get());
362 if(pPageHint
&& !pPageHint
->GetPageLayoutID().IsNull())
364 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pPageHint
->GetPageLayoutID().obj().get());
367 pPageLayout
->SetFoundry(GetFoundry());
368 pPageLayout
->RegisterEndnoteStyle();
376 * @descr Register default para styles
378 #include "lwpverdocument.hxx"
379 void LwpDocument::RegisterDefaultParaStyles()
384 //LwpDocument* pFirstDoc = GetFirstDivision();
385 LwpDocument
* pFirstDoc
= GetFirstDivisionWithContentsThatIsNotOLE();
388 LwpVerDocument
* pVerDoc
= dynamic_cast<LwpVerDocument
*>(pFirstDoc
->GetVerDoc().obj().get());
391 pVerDoc
->RegisterStyle();
399 * @descr Parse content in this division to IXFStream
400 * LwpDocument->LwpDivInfo->LwpPageLayout.Parse()
402 void LwpDocument::ParseDocContent(IXFStream
* pOutputStream
)
404 //Parse content in PageLayout
405 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*> (m_DivInfo
.obj().get());
406 if(pDivInfo
==NULL
) return;
408 rtl::Reference
<LwpObject
> pLayoutObj
= pDivInfo
->GetInitialLayoutID().obj();
411 //master document not supported now.
414 pLayoutObj
->SetFoundry(m_pFoundry
);
415 pLayoutObj
->Parse(pOutputStream
);
419 * @descr Get the footnoteoptions from the root document
421 LwpObjectID
* LwpDocument::GetValidFootnoteOpts()
423 LwpDocument
* pRoot
= GetRootDocument();
426 return &pRoot
->GetFootnoteOpts();
432 * @descr Get the endnote type
434 sal_uInt16
LwpDocument::GetEndnoteType()
436 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID().obj().get());
439 OUString strClassName
= pDivInfo
->GetClassName();
440 if (strClassName
== STR_DivisionEndnote
)
441 return FN_DIVISION_SEPARATE
;
442 if (strClassName
== STR_DivisionGroupEndnote
)
443 return FN_DIVISIONGROUP_SEPARATE
;
444 if (strClassName
== STR_DocumentEndnote
)
445 return FN_DOCUMENT_SEPARATE
;
449 * @descr Get previous division
451 LwpDocument
* LwpDocument::GetPreviousDivision()
453 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket().obj().get());
456 return dynamic_cast<LwpDocument
*>(pDocSock
->GetPrevious().obj().get());
461 * @descr Get next division
463 LwpDocument
* LwpDocument::GetNextDivision()
465 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket().obj().get());
468 return dynamic_cast<LwpDocument
*>(pDocSock
->GetNext().obj().get());
473 * @descr Get parent division
475 LwpDocument
* LwpDocument::GetParentDivision()
477 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket().obj().get());
480 return dynamic_cast<LwpDocument
*>(pDocSock
->GetParent().obj().get());
485 * @descr Get previous division in group, copy from lwp source code
487 LwpDocument
* LwpDocument::GetPreviousInGroup()
489 LwpDocument
* pPrev
= NULL
;
491 for (pPrev
= GetPreviousDivision(); pPrev
; pPrev
= pPrev
->GetPreviousDivision())
493 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(pPrev
->GetDivInfoID().obj().get());
494 if(pDivInfo
&& pDivInfo
->HasContents())
500 * @descr Get previous division in group, copy from lwp source code
502 LwpDocument
* LwpDocument::GetNextInGroup()
504 LwpDocument
* pNext
= NULL
;
506 for (pNext
= GetNextDivision(); pNext
; pNext
= pNext
->GetNextDivision())
508 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(pNext
->GetDivInfoID().obj().get());
509 if(pDivInfo
&& pDivInfo
->HasContents())
516 * @descr Get previous division which has contents, copy from lwp source code
518 LwpDocument
* LwpDocument::GetPreviousDivisionWithContents()
520 if(GetPreviousDivision())
522 LwpDocument
* pDoc
= GetPreviousDivision()->GetLastDivisionWithContents();
526 if(GetParentDivision())
527 return GetParentDivision()->GetPreviousDivisionWithContents();
531 * @descr Get last division which has contents, copy from lwp source code
533 LwpDocument
* LwpDocument::GetLastDivisionWithContents()
535 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID().obj().get());
536 if(pDivInfo
&& pDivInfo
->HasContents())
541 LwpDocument
* pDivision
= GetLastDivision();
545 LwpDocument
* pContentDivision
= pDivision
->GetLastDivisionWithContents();
548 return pContentDivision
;
550 pDivision
= pDivision
->GetPreviousDivision();
556 * @descr Get last division in group which has contents, copy from lwp source code
558 LwpDocument
* LwpDocument::GetLastInGroupWithContents()
560 LwpDocument
* pLast
= NULL
;
561 LwpDocument
* pNext
= this;
565 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(pNext
->GetDivInfoID().obj().get());
566 if (pDivInfo
&& pDivInfo
->HasContents())
568 pNext
= pNext
->GetNextInGroup();
575 * @descr Get last division
577 LwpDocument
* LwpDocument::GetLastDivision()
579 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket().obj().get());
581 return dynamic_cast<LwpDocument
*>(pDocSock
->GetChildTail().obj().get());
586 * @descr Get first division
588 LwpDocument
* LwpDocument::GetFirstDivision()
590 LwpDocSock
* pDocSock
= dynamic_cast<LwpDocSock
*>(GetSocket().obj().get());
592 return dynamic_cast<LwpDocument
*>(pDocSock
->GetChildHead().obj().get());
597 * @descr Get root document
599 LwpDocument
* LwpDocument::GetRootDocument()
601 LwpDocument
* pRoot
= this;
604 if(!pRoot
->IsChildDoc())
606 pRoot
= pRoot
->GetParentDivision();
611 * @descr Get first division with contents that is not ole, copy from lwp-source code
613 LwpDocument
* LwpDocument::GetFirstDivisionWithContentsThatIsNotOLE()
615 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(GetDivInfoID().obj().get());
616 if(pDivInfo
&& pDivInfo
->HasContents()
617 && !pDivInfo
->IsOleDivision())
620 LwpDocument
* pDivision
= GetFirstDivision();
624 LwpDocument
* pContentDivision
= pDivision
->GetFirstDivisionWithContentsThatIsNotOLE();
626 return pContentDivision
;
627 pDivision
= pDivision
->GetNextDivision();
632 * @descr Get last division that has endnote
634 LwpDocument
* LwpDocument::GetLastDivisionThatHasEndnote()
636 LwpDocument
* pRoot
= GetRootDocument();
637 LwpDocument
*pLastDoc
= pRoot
->GetLastDivisionWithContents();
640 if(pLastDoc
->GetEnSuperTableLayout())
642 pLastDoc
= pLastDoc
->GetPreviousDivisionWithContents();
648 * @descr Get endnote supertable layout, every division has only one endnote supertable layout.
650 LwpVirtualLayout
* LwpDocument::GetEnSuperTableLayout()
652 LwpHeadLayout
* pHeadLayout
= dynamic_cast<LwpHeadLayout
*>(GetFoundry()->GetLayout().obj().get());
655 return pHeadLayout
->FindEnSuperTableLayout();
661 * @descr Get the numbers of page before pEndDivision, copy from lwp source code
663 bool LwpDocument::GetNumberOfPages(LwpDocument
* pEndDivision
, sal_uInt16
& nCount
)
665 if(this == pEndDivision
)
668 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(m_DivInfo
.obj().get());
671 pDivInfo
->GetNumberOfPages(nCount
);
674 LwpDocument
* pDivision
= GetFirstDivision();
677 if(pDivision
->GetNumberOfPages(pEndDivision
,nCount
))
679 pDivision
= pDivision
->GetNextDivision();
685 * @descr Get the numbers of page before curruent division
687 sal_uInt16
LwpDocument::GetNumberOfPagesBefore()
689 sal_uInt16 nPageNumber
= 0;
690 LwpDocument
* pRoot
= GetRootDocument();
692 pRoot
->GetNumberOfPages(this,nPageNumber
);
697 * @descr Get Max number of pages
699 void LwpDocument::MaxNumberOfPages(sal_uInt16
& nNumPages
)
701 LwpDocument
* pDivision
= GetFirstDivision();
703 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*>(m_DivInfo
.obj().get());
705 nNumPages
+= pDivInfo
->GetMaxNumberOfPages();
708 pDivision
->MaxNumberOfPages(nNumPages
);
709 pDivision
= pDivision
->GetNextDivision();
713 * @descr Parse the frame which anchor is to page before parse other contents,
714 * This method is called when the document is root document.
716 void LwpDocument::ParseFrameInPage(IXFStream
* pOutputStream
)
721 XFContentContainer
* pXFContainer
= new XFContentContainer
;
723 XFConvertFrameInPage(pXFContainer
);
725 pXFContainer
->ToXml(pOutputStream
);
730 * @descr Parse the frame which anchor is to page in the entire document
732 void LwpDocument::XFConvertFrameInPage(XFContentContainer
* pCont
)
734 LwpDocument
* pDivision
= GetFirstDivision();
736 LwpDivInfo
* pDivInfo
= dynamic_cast<LwpDivInfo
*> (GetDivInfoID().obj().get());
739 LwpPageLayout
* pPageLayout
= dynamic_cast<LwpPageLayout
*>(pDivInfo
->GetInitialLayoutID().obj().get());
742 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(pPageLayout
->GetContent().obj().get());
744 pStory
->XFConvertFrameInPage(pCont
);
749 pDivision
->XFConvertFrameInPage(pCont
);
750 pDivision
= pDivision
->GetNextDivision();
754 * @descr change click here to placeholder
756 void LwpDocument::ChangeStyleName()
758 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
759 XFTextStyle
* pStyle
= dynamic_cast<XFTextStyle
*>(pXFStyleManager
->FindStyle("ClickHere"));
762 pStyle
->SetStyleName("Placeholder");
765 LwpDocSock::LwpDocSock(LwpObjectHeader
& objHdr
, LwpSvStream
* pStrm
)
766 :LwpDLNFVList(objHdr
, pStrm
)
770 * @descr read VO_DOCSOCK from file
772 void LwpDocSock::Read()
774 LwpDLNFVList::Read();
775 m_Doc
.ReadIndexed(m_pObjStrm
);
776 m_pObjStrm
->SkipExtra();
779 * @descr register styles in documents plugged
781 void LwpDocSock::RegisterStyle()
783 rtl::Reference
<LwpObject
> pDoc
= GetNext().obj();
785 pDoc
->RegisterStyle();
787 pDoc
= GetChildHead().obj();
789 pDoc
->RegisterStyle();
792 * @descr parse contents of documents plugged
794 void LwpDocSock::Parse(IXFStream
* pOutputStream
)
796 rtl::Reference
<LwpObject
> pDoc
= GetChildHead().obj();
798 pDoc
->Parse(pOutputStream
);
800 pDoc
= GetNext().obj();
802 pDoc
->Parse(pOutputStream
);
805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */