tdf#131098 docx export: write fill property of graphic
[LibreOffice.git] / lotuswordpro / source / filter / lwpdoc.cxx
blob8a2b0de32944587c6259a7ed2b073ec3efccefc8
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,
29 * MA 02111-1307 USA
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>
57 #include "lwpcharacterstyle.hxx"
58 #include "lwpdoc.hxx"
59 #include "lwpfootnote.hxx"
60 #include "lwppagehint.hxx"
61 #include "lwpdivinfo.hxx"
62 #include "lwpholder.hxx"
63 #include "lwpstory.hxx"
64 #include "lwpsilverbullet.hxx"
65 #include "lwpsortopt.hxx"
66 #include "lwplayout.hxx"
67 #include "lwppagelayout.hxx"
68 #include "lwpuidoc.hxx"
69 #include "lwpusrdicts.hxx"
70 #include "lwpprtinfo.hxx"
71 #include "lwpverdocument.hxx"
72 #include <xfilter/xftextstyle.hxx>
73 #include <xfilter/xfstylemanager.hxx>
74 #include <o3tl/sorted_vector.hxx>
76 LwpDocument::LwpDocument(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
77 : LwpDLNFPVList(objHdr, pStrm)
78 , m_bGettingFirstDivisionWithContentsThatIsNotOLE(false)
79 , m_bGettingPreviousDivisionWithContents(false)
80 , m_bGettingGetLastDivisionWithContents(false)
81 , m_nFlags(0)
82 , m_nPersistentFlags(0)
86 LwpDocument::~LwpDocument() {}
87 /**
88 * @descr Read VO_Document from object stream
89 **/
90 void LwpDocument::Read()
92 LwpDLNFPVList::Read();
94 ReadPlug();
96 m_nPersistentFlags = m_pObjStrm->QuickReaduInt32();
98 //Skip the SortOption and UIDocument
100 LwpSortOption aDocSort(m_pObjStrm.get());
101 LwpUIDocument aUIDoc(m_pObjStrm.get());
104 m_oLnOpts.emplace(m_pObjStrm.get());
106 //Skip LwpUserDictFiles
108 LwpUserDictFiles aUsrDicts(m_pObjStrm.get());
111 if (!IsChildDoc())
113 //Skip LwpPrinterInfo
114 LwpPrinterInfo aPrtInfo(m_pObjStrm.get());
117 m_xOwnedFoundry.reset(new LwpFoundry(m_pObjStrm.get(), this));
119 m_DivOpts.ReadIndexed(m_pObjStrm.get());
121 if (!IsChildDoc())
123 m_FootnoteOpts.ReadIndexed(m_pObjStrm.get());
124 m_DocData.ReadIndexed(m_pObjStrm.get());
126 else
128 //Skip the docdata used in old version
129 LwpObjectID dummyDocData;
130 dummyDocData.ReadIndexed(m_pObjStrm.get());
132 m_DivInfo.ReadIndexed(m_pObjStrm.get());
133 m_Epoch.Read(m_pObjStrm.get());
134 m_WYSIWYGPageHints.ReadIndexed(m_pObjStrm.get());
135 m_VerDoc.ReadIndexed(m_pObjStrm.get());
136 m_STXInfo.ReadIndexed(m_pObjStrm.get());
140 * @descr Read plug related data from m_pObjStram
142 void LwpDocument::ReadPlug()
144 m_DocSockID.ReadIndexed(m_pObjStrm.get());
145 m_nFlags = m_pObjStrm->QuickReaduInt16();
146 m_pObjStrm->SkipExtra();
150 * @descr Parse obj to IXFStream
152 void LwpDocument::Parse(IXFStream* pOutputStream)
154 //check the name and skip script division
155 if (!IsSkippedDivision())
157 //the frames which anchor are to page must output before other contents
158 ParseFrameInPage(pOutputStream);
159 ParseDocContent(pOutputStream);
162 rtl::Reference<LwpObject> pDocSock = GetSocket().obj(VO_DOCSOCK);
163 if (pDocSock.is())
165 pDocSock->DoParse(pOutputStream);
169 bool LwpDocument::IsSkippedDivision()
171 OUString sDivName;
172 bool ret = false;
173 LwpDivInfo* pDiv = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj(VO_DIVISIONINFO).get());
174 if (pDiv == nullptr)
175 return true;
176 sDivName = pDiv->GetDivName();
177 if (!sDivName.isEmpty() && !pDiv->IsGotoable()) //including toa,scripts division
178 return true;
179 //skip endnote division
180 OUString strClassName = pDiv->GetClassName();
181 if ((strClassName == STR_DivisionEndnote) || (strClassName == STR_DivisionGroupEndnote)
182 || (strClassName == STR_DocumentEndnote))
184 LwpPageLayout* pPageLayout
185 = dynamic_cast<LwpPageLayout*>(pDiv->GetInitialLayoutID().obj(VO_PAGELAYOUT).get());
186 if (pPageLayout)
188 LwpStory* pStory
189 = dynamic_cast<LwpStory*>(pPageLayout->GetContent().obj(VO_STORY).get());
190 if (pStory)
192 //This judgement maybe have problem. If there is only one para in the story,
193 //this endnote division has no other contents except endnote table.
194 LwpObjectID& rFirst = pStory->GetFirstPara();
195 LwpObjectID& rLast = pStory->GetLastPara();
196 if (rFirst == rLast)
197 ret = true;
201 return ret;
205 * @descr Register all styles in this division
207 void LwpDocument::RegisterStyle()
209 RegisterDefaultParaStyles();
210 RegisterGraphicsStyles();
211 RegisterBulletStyles();
213 RegisterTextStyles();
214 RegisterLayoutStyles();
215 RegisterStylesInPara();
217 RegisterLinenumberStyles();
218 RegisterFootnoteStyles();
220 //Register styles in other document connected with this document: next doc, children doc
221 rtl::Reference<LwpObject> pDocSock = GetSocket().obj();
222 if (pDocSock.is())
224 pDocSock->DoRegisterStyle();
228 * @descr Register all named para styles
230 void LwpDocument::RegisterTextStyles()
232 //Register all text styles: para styles, character styles
233 LwpDLVListHeadHolder* pTextStyleHolder
234 = m_xOwnedFoundry
235 ? dynamic_cast<LwpDLVListHeadHolder*>(m_xOwnedFoundry->GetTextStyleHead().obj().get())
236 : nullptr;
237 if (pTextStyleHolder)
239 LwpTextStyle* pTextStyle
240 = dynamic_cast<LwpTextStyle*>(pTextStyleHolder->GetHeadID().obj().get());
241 while (pTextStyle)
243 if (pTextStyle->GetFoundry())
244 throw std::runtime_error("loop in register text style");
245 pTextStyle->SetFoundry(m_xOwnedFoundry.get());
246 pTextStyle->RegisterStyle();
247 pTextStyle = dynamic_cast<LwpTextStyle*>(pTextStyle->GetNext().obj().get());
250 ChangeStyleName(); //for click here block
253 * @descr Register all layouts styles (page master and master page)
254 * All para styles used in master page (header and footer) are registered and then showed
256 void LwpDocument::RegisterLayoutStyles()
258 if (m_xOwnedFoundry)
260 //Register all layout styles, before register all styles in para
261 m_xOwnedFoundry->RegisterAllLayouts();
264 //set initial pagelayout in story for parsing pagelayout
265 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj(VO_DIVISIONINFO).get());
266 if (!pDivInfo)
267 return;
269 LwpPageLayout* pPageLayout
270 = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID().obj(VO_PAGELAYOUT).get());
271 if (pPageLayout)
273 //In Ole division, the content of pagelayout is VO_OLEOBJECT
274 LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent().obj(VO_STORY).get());
275 if (pStory)
277 //add all the pagelayout in order into the pagelayout list;
278 pStory->SortPageLayout();
279 pStory->SetCurrentLayout(pPageLayout);
284 * @descr Register all styles used in para
286 void LwpDocument::RegisterStylesInPara()
288 //Register all automatic styles in para
289 rtl::Reference<LwpHeadContent> xContent(
290 m_xOwnedFoundry ? dynamic_cast<LwpHeadContent*>(
291 m_xOwnedFoundry->GetContentManager().GetContentList().obj().get())
292 : nullptr);
293 if (!xContent.is())
294 return;
296 rtl::Reference<LwpStory> xStory(
297 dynamic_cast<LwpStory*>(xContent->GetChildHead().obj(VO_STORY).get()));
298 o3tl::sorted_vector<LwpStory*> aSeen;
299 while (xStory.is())
301 bool bAlreadySeen = !aSeen.insert(xStory.get()).second;
302 if (bAlreadySeen)
303 throw std::runtime_error("loop in conversion");
304 //Register the child para
305 xStory->SetFoundry(m_xOwnedFoundry.get());
306 xStory->DoRegisterStyle();
307 xStory.set(dynamic_cast<LwpStory*>(xStory->GetNext().obj(VO_STORY).get()));
311 * @descr Register all bullet styles used in this division
313 void LwpDocument::RegisterBulletStyles()
315 if (!m_xOwnedFoundry)
316 return;
317 //Register bullet styles
318 LwpDLVListHeadHolder* pBulletHead = dynamic_cast<LwpDLVListHeadHolder*>(
319 m_xOwnedFoundry->GetBulletManagerID().obj(VO_HEADHOLDER).get());
320 if (!pBulletHead)
321 return;
322 LwpSilverBullet* pBullet = dynamic_cast<LwpSilverBullet*>(pBulletHead->GetHeadID().obj().get());
323 o3tl::sorted_vector<LwpSilverBullet*> aSeen;
324 while (pBullet)
326 bool bAlreadySeen = !aSeen.insert(pBullet).second;
327 if (bAlreadySeen)
328 throw std::runtime_error("loop in conversion");
329 pBullet->SetFoundry(m_xOwnedFoundry.get());
330 pBullet->RegisterStyle();
331 pBullet = dynamic_cast<LwpSilverBullet*>(pBullet->GetNext().obj().get());
335 * @descr Register all styles used in VO_Graphic
337 void LwpDocument::RegisterGraphicsStyles()
339 if (!m_xOwnedFoundry)
340 return;
341 //Register all graphics styles, the first object should register the next;
342 rtl::Reference<LwpObject> pGraphic = m_xOwnedFoundry->GetGraphicListHead().obj(VO_GRAPHIC);
343 if (!pGraphic.is())
344 return;
345 pGraphic->SetFoundry(m_xOwnedFoundry.get());
346 pGraphic->DoRegisterStyle();
349 * @descr Register line number styles
351 void LwpDocument::RegisterLinenumberStyles()
353 if (!m_oLnOpts)
354 return;
355 m_oLnOpts->RegisterStyle();
359 * @descr Register footnote/endnote configuration for the entire document
361 void LwpDocument::RegisterFootnoteStyles()
363 //Register footnote and endnote configuration for the entire document
364 if (!m_FootnoteOpts.IsNull())
366 LwpFootnoteOptions* pFootnoteOpts
367 = dynamic_cast<LwpFootnoteOptions*>(m_FootnoteOpts.obj().get());
368 if (pFootnoteOpts)
370 pFootnoteOpts->SetMasterPage(u"Endnote"_ustr);
371 pFootnoteOpts->RegisterStyle();
374 //Register endnote page style for endnote configuration, use the last division that has endnote for the endnote page style
375 //This page style must register after its division default styles have registered
376 LwpDocument* pEndnoteDiv = GetLastDivisionThatHasEndnote();
377 if (this != pEndnoteDiv)
378 return;
380 LwpDLVListHeadTailHolder* pHeadTail
381 = dynamic_cast<LwpDLVListHeadTailHolder*>(GetPageHintsID().obj().get());
382 if (!pHeadTail)
383 return;
385 LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetTail().obj().get());
386 if (pPageHint && !pPageHint->GetPageLayoutID().IsNull())
388 LwpPageLayout* pPageLayout
389 = dynamic_cast<LwpPageLayout*>(pPageHint->GetPageLayoutID().obj().get());
390 if (pPageLayout)
392 pPageLayout->SetFoundry(GetFoundry());
393 pPageLayout->RegisterEndnoteStyle();
399 * @descr Register default para styles
401 void LwpDocument::RegisterDefaultParaStyles()
403 if (IsChildDoc())
404 return;
406 //Get First Division
407 //LwpDocument* pFirstDoc = GetFirstDivision();
408 LwpDocument* pFirstDoc = GetFirstDivisionWithContentsThatIsNotOLE();
409 if (pFirstDoc)
411 LwpVerDocument* pVerDoc = dynamic_cast<LwpVerDocument*>(pFirstDoc->GetVerDoc().obj().get());
412 if (pVerDoc)
414 pVerDoc->RegisterStyle();
420 * @descr Parse content in this division to IXFStream
421 * LwpDocument->LwpDivInfo->LwpPageLayout.Parse()
423 void LwpDocument::ParseDocContent(IXFStream* pOutputStream)
425 //Parse content in PageLayout
426 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj().get());
427 if (pDivInfo == nullptr)
428 return;
430 rtl::Reference<LwpObject> pLayoutObj = pDivInfo->GetInitialLayoutID().obj();
431 if (!pLayoutObj.is())
433 //master document not supported now.
434 return;
436 pLayoutObj->SetFoundry(m_xOwnedFoundry.get());
437 pLayoutObj->DoParse(pOutputStream);
441 * @descr Get the footnoteoptions from the root document
443 LwpObjectID* LwpDocument::GetValidFootnoteOpts()
445 LwpDocument* pRoot = GetRootDocument();
446 if (pRoot)
448 return &pRoot->GetFootnoteOpts();
450 return nullptr;
454 * @descr Get the endnote type
456 sal_uInt16 LwpDocument::GetEndnoteType()
458 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
459 if (!pDivInfo)
460 return FN_DONTCARE;
461 OUString strClassName = pDivInfo->GetClassName();
462 if (strClassName == STR_DivisionEndnote)
463 return FN_DIVISION_SEPARATE;
464 if (strClassName == STR_DivisionGroupEndnote)
465 return FN_DIVISIONGROUP_SEPARATE;
466 if (strClassName == STR_DocumentEndnote)
467 return FN_DOCUMENT_SEPARATE;
468 return FN_DONTCARE;
471 * @descr Get previous division
473 LwpDocument* LwpDocument::GetPreviousDivision()
475 LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
476 if (pDocSock)
478 return dynamic_cast<LwpDocument*>(pDocSock->GetPrevious().obj().get());
480 return nullptr;
483 * @descr Get next division
485 LwpDocument* LwpDocument::GetNextDivision()
487 LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
488 if (pDocSock)
490 return dynamic_cast<LwpDocument*>(pDocSock->GetNext().obj().get());
492 return nullptr;
495 * @descr Get parent division
497 LwpDocument* LwpDocument::GetParentDivision()
499 LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
500 if (pDocSock)
502 return dynamic_cast<LwpDocument*>(pDocSock->GetParent().obj().get());
504 return nullptr;
507 * @descr Get previous division in group, copy from lwp source code
509 LwpDocument* LwpDocument::GetPreviousInGroup()
511 LwpDocument* pPrev = nullptr;
513 for (pPrev = GetPreviousDivision(); pPrev; pPrev = pPrev->GetPreviousDivision())
515 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pPrev->GetDivInfoID().obj().get());
516 if (pDivInfo && pDivInfo->HasContents())
517 return pPrev;
519 return nullptr;
522 * @descr Get previous division in group, copy from lwp source code
524 LwpDocument* LwpDocument::GetNextInGroup()
526 LwpDocument* pNext = nullptr;
528 for (pNext = GetNextDivision(); pNext; pNext = pNext->GetNextDivision())
530 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pNext->GetDivInfoID().obj().get());
531 if (pDivInfo && pDivInfo->HasContents())
532 return pNext;
535 return nullptr;
538 * @descr Get previous division which has contents, copy from lwp source code
540 LwpDocument* LwpDocument::GetPreviousDivisionWithContents()
542 if (m_bGettingPreviousDivisionWithContents)
543 throw std::runtime_error("recursion in page divisions");
544 m_bGettingPreviousDivisionWithContents = true;
545 LwpDocument* pRet = nullptr;
547 if (GetPreviousDivision())
548 pRet = GetPreviousDivision()->GetLastDivisionWithContents();
549 if (!pRet && GetParentDivision())
550 pRet = GetParentDivision()->GetPreviousDivisionWithContents();
552 m_bGettingPreviousDivisionWithContents = false;
553 return pRet;
557 * @descr Get last division which has contents, copy from lwp source code
559 LwpDocument* LwpDocument::GetLastDivisionWithContents()
561 if (m_bGettingGetLastDivisionWithContents)
562 throw std::runtime_error("recursion in page divisions");
563 m_bGettingGetLastDivisionWithContents = true;
564 LwpDocument* pRet = nullptr;
566 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
567 if (pDivInfo && pDivInfo->HasContents())
568 pRet = this;
570 if (!pRet)
572 LwpDocument* pDivision = GetLastDivision();
574 o3tl::sorted_vector<LwpDocument*> aSeen;
575 while (pDivision && pDivision != this)
577 bool bAlreadySeen = !aSeen.insert(pDivision).second;
578 if (bAlreadySeen)
579 throw std::runtime_error("loop in conversion");
580 LwpDocument* pContentDivision = pDivision->GetLastDivisionWithContents();
581 if (pContentDivision)
583 pRet = pContentDivision;
584 break;
586 pDivision = pDivision->GetPreviousDivision();
590 m_bGettingGetLastDivisionWithContents = false;
591 return pRet;
594 * @descr Get last division in group which has contents, copy from lwp source code
596 LwpDocument* LwpDocument::GetLastInGroupWithContents()
598 LwpDocument* pLast = nullptr;
599 LwpDocument* pNext = this;
601 while (pNext)
603 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pNext->GetDivInfoID().obj().get());
604 if (pDivInfo && pDivInfo->HasContents())
605 pLast = pNext;
606 pNext = pNext->GetNextInGroup();
608 if (pLast)
609 return pLast;
610 return nullptr;
613 * @descr Get last division
615 LwpDocument* LwpDocument::GetLastDivision()
617 LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
618 if (pDocSock)
619 return dynamic_cast<LwpDocument*>(pDocSock->GetChildTail().obj().get());
620 return nullptr;
624 * @descr Get first division
626 LwpDocument* LwpDocument::GetFirstDivision()
628 LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
629 if (pDocSock)
630 return dynamic_cast<LwpDocument*>(pDocSock->GetChildHead().obj().get());
631 return nullptr;
635 * @descr Get root document
637 LwpDocument* LwpDocument::GetRootDocument()
639 LwpDocument* pRoot = this;
640 o3tl::sorted_vector<LwpDocument*> aSeen;
641 while (pRoot)
643 bool bAlreadySeen = !aSeen.insert(pRoot).second;
644 if (bAlreadySeen)
645 throw std::runtime_error("loop in conversion");
646 if (!pRoot->IsChildDoc())
647 return pRoot;
648 pRoot = pRoot->GetParentDivision();
650 return nullptr;
653 * @descr Get first division with contents that is not ole, copy from lwp-source code
655 LwpDocument* LwpDocument::ImplGetFirstDivisionWithContentsThatIsNotOLE()
657 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
658 if (pDivInfo && pDivInfo->HasContents() && !pDivInfo->IsOleDivision())
659 return this;
661 LwpDocument* pDivision = GetFirstDivision();
662 o3tl::sorted_vector<LwpDocument*> aSeen;
663 while (pDivision)
665 bool bAlreadySeen = !aSeen.insert(pDivision).second;
666 if (bAlreadySeen)
667 throw std::runtime_error("loop in conversion");
668 LwpDocument* pContentDivision = pDivision->GetFirstDivisionWithContentsThatIsNotOLE();
669 if (pContentDivision)
670 return pContentDivision;
671 pDivision = pDivision->GetNextDivision();
673 return nullptr;
676 * @descr Get last division that has endnote
678 LwpDocument* LwpDocument::GetLastDivisionThatHasEndnote()
680 LwpDocument* pRoot = GetRootDocument();
681 LwpDocument* pLastDoc = pRoot ? pRoot->GetLastDivisionWithContents() : nullptr;
682 o3tl::sorted_vector<LwpDocument*> aSeen;
683 while (pLastDoc)
685 bool bAlreadySeen = !aSeen.insert(pLastDoc).second;
686 if (bAlreadySeen)
687 throw std::runtime_error("loop in conversion");
688 if (pLastDoc->GetEnSuperTableLayout().is())
689 return pLastDoc;
690 pLastDoc = pLastDoc->GetPreviousDivisionWithContents();
692 return nullptr;
695 * @descr Get endnote supertable layout, every division has only one endnote supertable layout.
697 rtl::Reference<LwpVirtualLayout> LwpDocument::GetEnSuperTableLayout()
699 LwpHeadLayout* pHeadLayout
700 = dynamic_cast<LwpHeadLayout*>(GetFoundry()->GetLayout().obj().get());
701 if (pHeadLayout)
703 return pHeadLayout->FindEnSuperTableLayout();
705 return rtl::Reference<LwpVirtualLayout>();
709 * @descr Get the numbers of page before pEndDivision, copy from lwp source code
711 bool LwpDocument::GetNumberOfPages(LwpDocument* pEndDivision, sal_uInt16& nCount)
713 if (this == pEndDivision)
714 return true;
716 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj().get());
717 if (pDivInfo)
719 pDivInfo->GetNumberOfPages(nCount);
722 LwpDocument* pDivision = GetFirstDivision();
723 while (pDivision)
725 if (pDivision->GetNumberOfPages(pEndDivision, nCount))
726 return true;
727 pDivision = pDivision->GetNextDivision();
729 return false;
732 * @descr Get the numbers of page before current division
734 sal_uInt16 LwpDocument::GetNumberOfPagesBefore()
736 sal_uInt16 nPageNumber = 0;
737 LwpDocument* pRoot = GetRootDocument();
738 if (pRoot)
739 pRoot->GetNumberOfPages(this, nPageNumber);
740 return nPageNumber;
744 * @descr Parse the frame which anchor is to page before parse other contents,
745 * This method is called when the document is root document.
747 void LwpDocument::ParseFrameInPage(IXFStream* pOutputStream)
749 if (IsChildDoc())
750 return;
752 rtl::Reference<XFContentContainer> xXFContainer(new XFContentContainer);
753 XFConvertFrameInPage(xXFContainer.get());
754 xXFContainer->ToXml(pOutputStream);
758 * @descr Parse the frame which anchor is to page in the entire document
760 void LwpDocument::XFConvertFrameInPage(XFContentContainer* pCont)
762 LwpDocument* pDivision = GetFirstDivision();
764 LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
765 if (pDivInfo)
767 LwpPageLayout* pPageLayout
768 = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID().obj().get());
769 if (pPageLayout)
771 LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent().obj().get());
772 if (pStory)
773 pStory->XFConvertFrameInPage(pCont);
776 while (pDivision)
778 pDivision->XFConvertFrameInPage(pCont);
779 pDivision = pDivision->GetNextDivision();
783 * @descr change click here to placeholder
785 void LwpDocument::ChangeStyleName()
787 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
788 XFTextStyle* pStyle = dynamic_cast<XFTextStyle*>(pXFStyleManager->FindStyle(u"ClickHere"));
789 if (pStyle)
791 pStyle->SetStyleName(u"Placeholder"_ustr);
794 LwpDocSock::LwpDocSock(LwpObjectHeader const& objHdr, LwpSvStream* pStrm)
795 : LwpDLNFVList(objHdr, pStrm)
800 * @descr read VO_DOCSOCK from file
802 void LwpDocSock::Read()
804 LwpDLNFVList::Read();
805 m_Doc.ReadIndexed(m_pObjStrm.get());
806 m_pObjStrm->SkipExtra();
809 * @descr register styles in documents plugged
811 void LwpDocSock::RegisterStyle()
813 rtl::Reference<LwpObject> pDoc = GetNext().obj();
814 if (pDoc.is())
815 pDoc->DoRegisterStyle();
817 pDoc = GetChildHead().obj();
818 if (pDoc.is())
819 pDoc->DoRegisterStyle();
822 * @descr parse contents of documents plugged
824 void LwpDocSock::Parse(IXFStream* pOutputStream)
826 rtl::Reference<LwpObject> pDoc = GetChildHead().obj();
827 if (pDoc.is())
828 pDoc->DoParse(pOutputStream);
830 pDoc = GetNext().obj();
831 if (pDoc.is())
832 pDoc->DoParse(pOutputStream);
835 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */