Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
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
16 : *
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.
20 : *
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.
25 : *
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
30 : *
31 : *
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.
38 : *
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.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
55 : ************************************************************************/
56 : #include "lwpglobalmgr.hxx"
57 : #include "lwpdoc.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>
70 :
71 20 : LwpDocument::LwpDocument(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
72 : : LwpDLNFPVList(objHdr, pStrm)
73 : , m_pOwnedFoundry(NULL)
74 : , m_nFlags(0)
75 : , m_nPersistentFlags(0)
76 20 : , m_pLnOpts(NULL)
77 : {
78 18 : }
79 :
80 54 : LwpDocument::~LwpDocument()
81 : {
82 18 : if(m_pLnOpts)
83 : {
84 18 : delete m_pLnOpts;
85 : }
86 18 : if(m_pOwnedFoundry)
87 : {
88 18 : delete m_pOwnedFoundry;
89 : }
90 36 : }
91 : /**
92 : * @descr Read VO_Document from object stream
93 : **/
94 18 : void LwpDocument::Read()
95 : {
96 18 : LwpDLNFPVList::Read();
97 :
98 18 : ReadPlug();
99 :
100 18 : m_nPersistentFlags = m_pObjStrm->QuickReaduInt32();
101 :
102 : //Skip the SortOption and UIDocument
103 : {
104 18 : LwpSortOption m_DocSort( m_pObjStrm );
105 18 : LwpUIDocument m_UIDoc( m_pObjStrm );
106 : }
107 :
108 18 : m_pLnOpts = new LwpLineNumberOptions(m_pObjStrm);
109 :
110 : //Skip LwpUserDictFiles
111 : {
112 18 : LwpUserDictFiles m_UsrDicts( m_pObjStrm );
113 : }
114 :
115 18 : if( !IsChildDoc())
116 : {
117 : //Skip LwpPrinterInfo
118 10 : LwpPrinterInfo m_PrtInfo( m_pObjStrm );
119 : }
120 :
121 18 : m_pFoundry = m_pOwnedFoundry = new LwpFoundry(m_pObjStrm, this);
122 :
123 18 : m_DivOpts.ReadIndexed(m_pObjStrm);
124 :
125 18 : if(!IsChildDoc())
126 : {
127 10 : m_FootnoteOpts.ReadIndexed(m_pObjStrm);
128 10 : m_DocData.ReadIndexed(m_pObjStrm);
129 : }
130 : else
131 : {
132 : //Skip the docdata used in old version
133 8 : LwpObjectID dummyDocData;
134 8 : dummyDocData.ReadIndexed(m_pObjStrm);
135 : }
136 18 : m_DivInfo.ReadIndexed(m_pObjStrm);
137 18 : m_Epoch.Read(m_pObjStrm);
138 18 : m_WYSIWYGPageHints.ReadIndexed(m_pObjStrm);
139 16 : m_VerDoc.ReadIndexed(m_pObjStrm);
140 16 : m_STXInfo.ReadIndexed(m_pObjStrm);
141 16 : }
142 :
143 : /**
144 : * @descr Read plug related data from m_pObjStram
145 : **/
146 18 : void LwpDocument::ReadPlug()
147 : {
148 18 : m_DocSockID.ReadIndexed(m_pObjStrm);
149 18 : m_nFlags = m_pObjStrm->QuickReaduInt16();
150 18 : m_pObjStrm->SkipExtra();
151 18 : }
152 :
153 : /**
154 : * @descr Parse obj to IXFStream
155 : **/
156 12 : void LwpDocument::Parse(IXFStream* pOutputStream)
157 : {
158 : //check the name and skip script division
159 12 : if (!IsSkippedDivision())
160 : {
161 : //the frames which anchor are to page must output before other contents
162 12 : ParseFrameInPage(pOutputStream);
163 12 : ParseDocContent(pOutputStream);
164 : }
165 :
166 12 : rtl::Reference<LwpObject> pDocSock = GetSocket().obj( VO_DOCSOCK );
167 12 : if(pDocSock.is())
168 : {
169 12 : pDocSock->Parse(pOutputStream);
170 12 : }
171 12 : }
172 :
173 12 : bool LwpDocument::IsSkippedDivision()
174 : {
175 12 : OUString sDivName;
176 12 : bool ret = false;
177 12 : LwpDivInfo* pDiv = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj(VO_DIVISIONINFO).get());
178 12 : if (pDiv == NULL)
179 0 : return true;
180 12 : sDivName = pDiv->GetDivName();
181 12 : if (!sDivName.isEmpty() && !pDiv->IsGotoable()) //including toa,scripts division
182 0 : return true;
183 : //skip endnote division
184 24 : OUString strClassName = pDiv->GetClassName();
185 24 : if ((strClassName == STR_DivisionEndnote)
186 12 : || (strClassName == STR_DivisionGroupEndnote)
187 24 : || (strClassName == STR_DocumentEndnote))
188 : {
189 0 : LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pDiv->GetInitialLayoutID().obj(VO_PAGELAYOUT).get());
190 0 : if(pPageLayout)
191 : {
192 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent().obj(VO_STORY).get());
193 0 : if(pStory)
194 : {
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 0 : LwpObjectID& rFirst = pStory->GetFirstPara();
198 0 : LwpObjectID& rLast = pStory->GetLastPara();
199 0 : if(rFirst == rLast)
200 0 : ret = true;
201 : }
202 : }
203 : }
204 24 : return ret;
205 : }
206 :
207 : /**
208 : * @descr Register all styles in this division
209 : */
210 16 : void LwpDocument::RegisterStyle()
211 : {
212 16 : RegisterDefaultParaStyles();
213 16 : RegisterGraphicsStyles();
214 16 : RegisterBulletStyles();
215 :
216 16 : RegisterTextStyles();
217 16 : RegisterLayoutStyles();
218 16 : RegisterStylesInPara();
219 :
220 14 : RegisterLinenumberStyles();
221 14 : RegisterFootnoteStyles();
222 :
223 : //Register styles in other document connected with this document: next doc, children doc
224 14 : rtl::Reference<LwpObject> pDocSock = GetSocket().obj();
225 14 : if(pDocSock.is())
226 : {
227 14 : pDocSock->RegisterStyle();
228 14 : }
229 12 : }
230 : /**
231 : * @descr Register all named para styles
232 : */
233 16 : void LwpDocument::RegisterTextStyles()
234 : {
235 : //Register all text styles: para styles, character styles
236 16 : LwpDLVListHeadHolder* pParaStyleHolder = dynamic_cast<LwpDLVListHeadHolder*>(m_pFoundry->GetTextStyleHead().obj().get());
237 16 : if(pParaStyleHolder)
238 : {
239 16 : LwpTextStyle* pParaStyle = dynamic_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID().obj().get());
240 168 : while(pParaStyle)
241 : {
242 136 : pParaStyle->SetFoundry(m_pFoundry);
243 136 : pParaStyle->RegisterStyle();
244 136 : pParaStyle = dynamic_cast<LwpParaStyle*>(pParaStyle->GetNext().obj().get());
245 : }
246 : }
247 16 : ChangeStyleName();//add by ,for click here block,05/5/26
248 16 : }
249 : /**
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
252 : */
253 16 : void LwpDocument::RegisterLayoutStyles()
254 : {
255 : //Register all layout styles, before register all styles in para
256 16 : m_pFoundry->RegisterAllLayouts();
257 :
258 : //set initial pagelayout in story for parsing pagelayout
259 16 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (m_DivInfo.obj( VO_DIVISIONINFO).get());
260 16 : LwpPageLayout* pPageLayout = NULL;
261 16 : if(pDivInfo)
262 : {
263 16 : pPageLayout = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID().obj(VO_PAGELAYOUT).get());
264 16 : if(pPageLayout)
265 : {
266 : //In Ole division, the content of pagelayout is VO_OLEOBJECT
267 8 : LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent().obj(VO_STORY).get());
268 8 : if(pStory)
269 : {
270 : //add all the pagelayout in order into the pagelayout list;
271 8 : pStory->SortPageLayout();
272 8 : pStory->SetCurrentLayout(pPageLayout);
273 : }
274 : }
275 : }
276 16 : }
277 : /**
278 : * @descr Register all styles used in para
279 : */
280 16 : void LwpDocument::RegisterStylesInPara()
281 : {
282 : //Register all automatic styles in para
283 16 : LwpHeadContent* pContent = dynamic_cast<LwpHeadContent*> (m_pFoundry->GetContentManager().GetContentList().obj().get());
284 16 : if(pContent)
285 : {
286 16 : LwpStory* pStory = dynamic_cast<LwpStory*>(pContent->GetChildHead().obj(VO_STORY).get());
287 110 : while(pStory)
288 : {
289 : //Register the child para
290 80 : pStory->SetFoundry(m_pFoundry);
291 80 : pStory->RegisterStyle();
292 78 : pStory = dynamic_cast<LwpStory*>(pStory->GetNext().obj(VO_STORY).get());
293 : }
294 : }
295 14 : }
296 : /**
297 : * @descr Register all bullet styles used in this division
298 : */
299 16 : void LwpDocument::RegisterBulletStyles()
300 : {
301 : //Register bullet styles
302 : LwpDLVListHeadHolder* mBulletHead = dynamic_cast<LwpDLVListHeadHolder*>
303 16 : (m_pFoundry->GetBulletManagerID().obj(VO_HEADHOLDER).get());
304 16 : if( mBulletHead )
305 : {
306 : LwpSilverBullet* pBullet = dynamic_cast<LwpSilverBullet*>
307 16 : (mBulletHead->GetHeadID().obj().get());
308 58 : while(pBullet)
309 : {
310 26 : pBullet->SetFoundry(m_pFoundry);
311 26 : pBullet->RegisterStyle();
312 26 : pBullet = dynamic_cast<LwpSilverBullet*> (pBullet->GetNext().obj().get());
313 : }
314 : }
315 16 : }
316 : /**
317 : * @descr Register all styles used in VO_Graphic
318 : */
319 16 : void LwpDocument::RegisterGraphicsStyles()
320 : {
321 : //Register all graphics styles, the first object should register the next;
322 16 : rtl::Reference<LwpObject> pGraphic = m_pFoundry->GetGraphicListHead().obj(VO_GRAPHIC);
323 16 : if(pGraphic.is())
324 : {
325 0 : pGraphic->SetFoundry(m_pFoundry);
326 0 : pGraphic->RegisterStyle();
327 16 : }
328 16 : }
329 : /**
330 : * @descr Register line number styles
331 : */
332 14 : void LwpDocument::RegisterLinenumberStyles()
333 : {
334 14 : if (!m_pLnOpts)
335 14 : return;
336 14 : m_pLnOpts->RegisterStyle();
337 : }
338 :
339 : /**
340 : * @descr Register footnote/endnote configuration for the entire document
341 : */
342 14 : void LwpDocument::RegisterFootnoteStyles()
343 : {
344 : //Register footnote and endnote configuration for the entire document
345 14 : if(!m_FootnoteOpts.IsNull())
346 : {
347 8 : LwpFootnoteOptions* pFootnoteOpts = dynamic_cast<LwpFootnoteOptions*>(m_FootnoteOpts.obj().get());
348 8 : if (pFootnoteOpts)
349 : {
350 8 : pFootnoteOpts->SetMasterPage("Endnote");
351 8 : pFootnoteOpts->RegisterStyle();
352 : }
353 : }
354 : //Register endnote page style for endnote configuration, use the last division that has endnote for the endnote page style
355 : //This page style must register after its division default styles have registered
356 14 : LwpDocument* pEndnoteDiv = GetLastDivisionThatHasEndnote();
357 14 : if(this == pEndnoteDiv)
358 : {
359 0 : LwpDLVListHeadTailHolder* pHeadTail = dynamic_cast<LwpDLVListHeadTailHolder*>(GetPageHintsID().obj().get());
360 0 : if(pHeadTail)
361 : {
362 0 : LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetTail().obj().get());
363 0 : if(pPageHint && !pPageHint->GetPageLayoutID().IsNull())
364 : {
365 0 : LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pPageHint->GetPageLayoutID().obj().get());
366 0 : if(pPageLayout)
367 : {
368 0 : pPageLayout->SetFoundry(GetFoundry());
369 0 : pPageLayout->RegisterEndnoteStyle();
370 : }
371 : }
372 : }
373 : }
374 14 : }
375 :
376 : /**
377 : * @descr Register default para styles
378 : */
379 : #include "lwpverdocument.hxx"
380 16 : void LwpDocument::RegisterDefaultParaStyles()
381 : {
382 16 : if(!IsChildDoc())
383 : {
384 : //Get First Division
385 : //LwpDocument* pFirstDoc = GetFirstDivision();
386 8 : LwpDocument* pFirstDoc = GetFirstDivisionWithContentsThatIsNotOLE();
387 8 : if(pFirstDoc)
388 : {
389 8 : LwpVerDocument* pVerDoc = dynamic_cast<LwpVerDocument*>(pFirstDoc->GetVerDoc().obj().get());
390 8 : if(pVerDoc)
391 : {
392 8 : pVerDoc->RegisterStyle();
393 : }
394 : }
395 :
396 : }
397 16 : }
398 :
399 : /**
400 : * @descr Parse content in this division to IXFStream
401 : * LwpDocument->LwpDivInfo->LwpPageLayout.Parse()
402 : */
403 12 : void LwpDocument::ParseDocContent(IXFStream* pOutputStream)
404 : {
405 : //Parse content in PageLayout
406 12 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (m_DivInfo.obj().get());
407 18 : if(pDivInfo==NULL) return;
408 :
409 12 : rtl::Reference<LwpObject> pLayoutObj = pDivInfo->GetInitialLayoutID().obj();
410 12 : if(!pLayoutObj.is())
411 : {
412 : //master document not supported now.
413 6 : return;
414 : }
415 6 : pLayoutObj->SetFoundry(m_pFoundry);
416 6 : pLayoutObj->Parse(pOutputStream);
417 : }
418 :
419 : /**
420 : * @descr Get the footnoteoptions from the root document
421 : */
422 16 : LwpObjectID* LwpDocument::GetValidFootnoteOpts()
423 : {
424 16 : LwpDocument* pRoot = GetRootDocument();
425 16 : if(pRoot)
426 : {
427 16 : return &pRoot->GetFootnoteOpts();
428 : }
429 0 : return NULL;
430 : }
431 :
432 : /**
433 : * @descr Get the endnote type
434 : */
435 0 : sal_uInt16 LwpDocument::GetEndnoteType()
436 : {
437 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
438 0 : if (!pDivInfo)
439 0 : return FN_DONTCARE;
440 0 : OUString strClassName = pDivInfo->GetClassName();
441 0 : if (strClassName == STR_DivisionEndnote)
442 0 : return FN_DIVISION_SEPARATE;
443 0 : if (strClassName == STR_DivisionGroupEndnote)
444 0 : return FN_DIVISIONGROUP_SEPARATE;
445 0 : if (strClassName == STR_DocumentEndnote)
446 0 : return FN_DOCUMENT_SEPARATE;
447 0 : return FN_DONTCARE;
448 : }
449 : /**
450 : * @descr Get previous division
451 : */
452 28 : LwpDocument* LwpDocument::GetPreviousDivision()
453 : {
454 28 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
455 28 : if(pDocSock)
456 : {
457 28 : return dynamic_cast<LwpDocument*>(pDocSock->GetPrevious().obj().get());
458 : }
459 0 : return NULL;
460 : }
461 : /**
462 : * @descr Get next division
463 : */
464 6 : LwpDocument* LwpDocument::GetNextDivision()
465 : {
466 6 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
467 6 : if(pDocSock)
468 : {
469 6 : return dynamic_cast<LwpDocument*>(pDocSock->GetNext().obj().get());
470 : }
471 0 : return NULL;
472 : }
473 : /**
474 : * @descr Get parent division
475 : */
476 500 : LwpDocument* LwpDocument::GetParentDivision()
477 : {
478 500 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
479 500 : if(pDocSock)
480 : {
481 500 : return dynamic_cast<LwpDocument*>(pDocSock->GetParent().obj().get());
482 : }
483 0 : return NULL;
484 : }
485 : /**
486 : * @descr Get previous division in group, copy from lwp source code
487 : */
488 0 : LwpDocument* LwpDocument::GetPreviousInGroup()
489 : {
490 0 : LwpDocument* pPrev = NULL;
491 :
492 0 : for (pPrev = GetPreviousDivision(); pPrev; pPrev = pPrev->GetPreviousDivision())
493 : {
494 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pPrev->GetDivInfoID().obj().get());
495 0 : if(pDivInfo && pDivInfo->HasContents())
496 0 : return pPrev;
497 : }
498 0 : return NULL;
499 : }
500 : /**
501 : * @descr Get previous division in group, copy from lwp source code
502 : */
503 0 : LwpDocument* LwpDocument::GetNextInGroup()
504 : {
505 0 : LwpDocument* pNext = NULL;
506 :
507 0 : for (pNext = GetNextDivision(); pNext; pNext = pNext->GetNextDivision())
508 : {
509 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pNext->GetDivInfoID().obj().get());
510 0 : if(pDivInfo && pDivInfo->HasContents())
511 0 : return pNext;
512 : }
513 :
514 0 : return NULL;
515 : }
516 : /**
517 : * @descr Get previous division which has contents, copy from lwp source code
518 : */
519 28 : LwpDocument* LwpDocument::GetPreviousDivisionWithContents()
520 : {
521 28 : if(GetPreviousDivision())
522 : {
523 0 : LwpDocument* pDoc = GetPreviousDivision()->GetLastDivisionWithContents();
524 0 : if (pDoc)
525 0 : return pDoc;
526 : }
527 28 : if(GetParentDivision())
528 14 : return GetParentDivision()->GetPreviousDivisionWithContents();
529 14 : return NULL;
530 : }
531 : /**
532 : * @descr Get last division which has contents, copy from lwp source code
533 : */
534 28 : LwpDocument* LwpDocument::GetLastDivisionWithContents()
535 : {
536 28 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
537 28 : if(pDivInfo && pDivInfo->HasContents())
538 : {
539 14 : return this;
540 : }
541 :
542 14 : LwpDocument* pDivision = GetLastDivision();
543 14 : LwpDocument* pContentDivision = NULL;
544 :
545 28 : while(pDivision)
546 : {
547 14 : pContentDivision = pDivision->GetLastDivisionWithContents();
548 14 : if(pContentDivision)
549 : {
550 14 : return pContentDivision;
551 : }
552 0 : pDivision = pDivision->GetPreviousDivision();
553 : }
554 :
555 0 : return NULL;
556 : }
557 : /**
558 : * @descr Get last division in group which has contents, copy from lwp source code
559 : */
560 0 : LwpDocument* LwpDocument::GetLastInGroupWithContents()
561 : {
562 0 : LwpDocument* pLast = NULL;
563 0 : LwpDocument* pNext = this;
564 :
565 0 : while (pNext)
566 : {
567 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pNext->GetDivInfoID().obj().get());
568 0 : if (pDivInfo && pDivInfo->HasContents())
569 0 : pLast = pNext;
570 0 : pNext = pNext->GetNextInGroup();
571 : }
572 0 : if (pLast)
573 0 : return pLast;
574 0 : return NULL;
575 : }
576 : /**
577 : * @descr Get last division
578 : */
579 14 : LwpDocument* LwpDocument::GetLastDivision()
580 : {
581 14 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
582 14 : if(pDocSock)
583 14 : return dynamic_cast<LwpDocument*>(pDocSock->GetChildTail().obj().get());
584 0 : return NULL;
585 : }
586 :
587 : /**
588 : * @descr Get first division
589 : */
590 20 : LwpDocument* LwpDocument::GetFirstDivision()
591 : {
592 20 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket().obj().get());
593 20 : if(pDocSock)
594 20 : return dynamic_cast<LwpDocument*>(pDocSock->GetChildHead().obj().get());
595 0 : return NULL;
596 : }
597 :
598 : /**
599 : * @descr Get root document
600 : */
601 466 : LwpDocument* LwpDocument::GetRootDocument()
602 : {
603 466 : LwpDocument* pRoot = this;
604 1390 : while(pRoot)
605 : {
606 924 : if(!pRoot->IsChildDoc())
607 466 : return pRoot;
608 458 : pRoot = pRoot->GetParentDivision();
609 : }
610 0 : return NULL;
611 : }
612 : /**
613 : * @descr Get first division with contents that is not ole, copy from lwp-source code
614 : */
615 16 : LwpDocument* LwpDocument::GetFirstDivisionWithContentsThatIsNotOLE()
616 : {
617 16 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID().obj().get());
618 32 : if(pDivInfo && pDivInfo->HasContents()
619 24 : && !pDivInfo->IsOleDivision())
620 8 : return this;
621 :
622 8 : LwpDocument* pDivision = GetFirstDivision();
623 :
624 8 : LwpDocument* pContentDivision = NULL;
625 :
626 16 : while (pDivision)
627 : {
628 8 : pContentDivision = pDivision->GetFirstDivisionWithContentsThatIsNotOLE();
629 8 : if(pContentDivision)
630 8 : return pContentDivision;
631 0 : pDivision = pDivision->GetNextDivision();
632 : }
633 0 : return NULL;
634 : }
635 : /**
636 : * @descr Get last division that has endnote
637 : */
638 14 : LwpDocument* LwpDocument::GetLastDivisionThatHasEndnote()
639 : {
640 14 : LwpDocument* pRoot = GetRootDocument();
641 14 : LwpDocument *pLastDoc = pRoot->GetLastDivisionWithContents();
642 42 : while(pLastDoc)
643 : {
644 14 : if(pLastDoc->GetEnSuperTableLayout())
645 0 : return pLastDoc;
646 14 : pLastDoc = pLastDoc->GetPreviousDivisionWithContents();
647 : }
648 14 : return NULL;
649 :
650 : }
651 : /**
652 : * @descr Get endnote supertable layout, every division has only one endnote supertable layout.
653 : */
654 14 : LwpVirtualLayout* LwpDocument::GetEnSuperTableLayout()
655 : {
656 14 : LwpHeadLayout* pHeadLayout = dynamic_cast<LwpHeadLayout*>(GetFoundry()->GetLayout().obj().get());
657 14 : if(pHeadLayout)
658 : {
659 14 : return pHeadLayout->FindEnSuperTableLayout();
660 : }
661 0 : return NULL;
662 : }
663 :
664 : /**
665 : * @descr Get the numbers of page before pEndDivision, copy from lwp source code
666 : */
667 0 : bool LwpDocument::GetNumberOfPages(LwpDocument* pEndDivision, sal_uInt16& nCount)
668 : {
669 0 : if(this == pEndDivision)
670 0 : return true;
671 :
672 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj().get());
673 0 : if(pDivInfo)
674 : {
675 0 : pDivInfo->GetNumberOfPages(nCount);
676 : }
677 :
678 0 : LwpDocument* pDivision = GetFirstDivision();
679 0 : while(pDivision)
680 : {
681 0 : if(pDivision->GetNumberOfPages(pEndDivision,nCount))
682 0 : return true;
683 0 : pDivision = pDivision->GetNextDivision();
684 :
685 : }
686 0 : return false;
687 : }
688 : /**
689 : * @descr Get the numbers of page before curruent division
690 : */
691 0 : sal_uInt16 LwpDocument::GetNumberOfPagesBefore()
692 : {
693 0 : sal_uInt16 nPageNumber = 0;
694 0 : LwpDocument* pRoot = GetRootDocument();
695 0 : if(pRoot)
696 0 : pRoot->GetNumberOfPages(this,nPageNumber);
697 0 : return nPageNumber;
698 : }
699 :
700 : /**
701 : * @descr Get Max number of pages
702 : */
703 0 : void LwpDocument::MaxNumberOfPages(sal_uInt16& nNumPages)
704 : {
705 0 : LwpDocument* pDivision = GetFirstDivision();
706 :
707 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj().get());
708 0 : if(pDivInfo)
709 0 : nNumPages += pDivInfo->GetMaxNumberOfPages();
710 0 : while(pDivision)
711 : {
712 0 : pDivision->MaxNumberOfPages(nNumPages);
713 0 : pDivision = pDivision->GetNextDivision();
714 : }
715 0 : }
716 : /**
717 : * @descr Parse the frame which anchor is to page before parse other contents,
718 : * This method is called when the document is root document.
719 : */
720 12 : void LwpDocument::ParseFrameInPage(IXFStream * pOutputStream)
721 : {
722 12 : if(IsChildDoc())
723 18 : return;
724 :
725 6 : XFContentContainer* pXFContainer = new XFContentContainer;
726 :
727 6 : XFConvertFrameInPage(pXFContainer);
728 :
729 6 : pXFContainer->ToXml(pOutputStream);
730 6 : delete pXFContainer;
731 6 : pXFContainer = NULL;
732 : }
733 : /**
734 : * @descr Parse the frame which anchor is to page in the entire document
735 : */
736 12 : void LwpDocument::XFConvertFrameInPage(XFContentContainer * pCont)
737 : {
738 12 : LwpDocument* pDivision = GetFirstDivision();
739 :
740 12 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (GetDivInfoID().obj().get());
741 12 : if(pDivInfo)
742 : {
743 12 : LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID().obj().get());
744 12 : if(pPageLayout)
745 : {
746 6 : LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent().obj().get());
747 6 : if(pStory)
748 6 : pStory->XFConvertFrameInPage(pCont);
749 : }
750 : }
751 30 : while(pDivision)
752 : {
753 6 : pDivision->XFConvertFrameInPage(pCont);
754 6 : pDivision = pDivision->GetNextDivision();
755 : }
756 12 : }
757 : /**
758 : * @descr change click here to placeholder
759 : */
760 16 : void LwpDocument::ChangeStyleName()
761 : {
762 16 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
763 16 : XFTextStyle* pStyle = dynamic_cast<XFTextStyle*>(pXFStyleManager->FindStyle("ClickHere"));
764 16 : if (pStyle)
765 : {
766 0 : pStyle->SetStyleName("Placeholder");
767 : }
768 16 : }
769 16 : LwpDocSock::LwpDocSock(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
770 16 : :LwpDLNFVList(objHdr, pStrm)
771 16 : {}
772 :
773 : /**
774 : * @descr read VO_DOCSOCK from file
775 : */
776 16 : void LwpDocSock::Read()
777 : {
778 16 : LwpDLNFVList::Read();
779 16 : m_Doc.ReadIndexed(m_pObjStrm);
780 16 : m_pObjStrm->SkipExtra();
781 16 : }
782 : /**
783 : * @descr register styles in documents plugged
784 : */
785 14 : void LwpDocSock::RegisterStyle()
786 : {
787 14 : rtl::Reference<LwpObject> pDoc = GetNext().obj();
788 14 : if(pDoc.is())
789 0 : pDoc->RegisterStyle();
790 :
791 14 : pDoc = GetChildHead().obj();
792 14 : if(pDoc.is())
793 10 : pDoc->RegisterStyle();
794 12 : }
795 : /**
796 : * @descr parse contents of documents plugged
797 : */
798 12 : void LwpDocSock::Parse(IXFStream* pOutputStream)
799 : {
800 12 : rtl::Reference<LwpObject> pDoc = GetChildHead().obj();
801 12 : if(pDoc.is())
802 6 : pDoc->Parse(pOutputStream);
803 :
804 12 : pDoc = GetNext().obj();
805 12 : if(pDoc.is())
806 0 : pDoc->Parse(pOutputStream);
807 12 : }
808 :
809 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|