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 0 : LwpDocument::LwpDocument(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
72 : : LwpDLNFPVList(objHdr, pStrm)
73 : , m_pOwnedFoundry(NULL)
74 : , m_nFlags(0)
75 : , m_nPersistentFlags(0)
76 0 : , m_pLnOpts(NULL)
77 : {
78 0 : }
79 :
80 0 : LwpDocument::~LwpDocument()
81 : {
82 0 : if(m_pLnOpts)
83 : {
84 0 : delete m_pLnOpts;
85 : }
86 0 : if(m_pOwnedFoundry)
87 : {
88 0 : delete m_pOwnedFoundry;
89 : }
90 0 : }
91 : /**
92 : * @descr Read VO_Document from object stream
93 : **/
94 0 : void LwpDocument::Read()
95 : {
96 0 : LwpDLNFPVList::Read();
97 :
98 0 : ReadPlug();
99 :
100 0 : m_nPersistentFlags = m_pObjStrm->QuickReaduInt32();
101 :
102 : //Skip the SortOption and UIDocument
103 : {
104 0 : LwpSortOption m_DocSort( m_pObjStrm );
105 0 : LwpUIDocument m_UIDoc( m_pObjStrm );
106 : }
107 :
108 0 : m_pLnOpts = new LwpLineNumberOptions(m_pObjStrm);
109 :
110 : //Skip LwpUserDictFiles
111 : {
112 0 : LwpUserDictFiles m_UsrDicts( m_pObjStrm );
113 : }
114 :
115 0 : if( !IsChildDoc())
116 : {
117 : //Skip LwpPrinterInfo
118 0 : LwpPrinterInfo m_PrtInfo( m_pObjStrm );
119 : }
120 :
121 0 : m_pFoundry = m_pOwnedFoundry = new LwpFoundry(m_pObjStrm, this);
122 :
123 0 : m_DivOpts.ReadIndexed(m_pObjStrm);
124 :
125 0 : if(!IsChildDoc())
126 : {
127 0 : m_FootnoteOpts.ReadIndexed(m_pObjStrm);
128 0 : m_DocData.ReadIndexed(m_pObjStrm);
129 : }
130 : else
131 : {
132 : //Skip the docdata used in old version
133 0 : LwpObjectID dummyDocData;
134 0 : dummyDocData.ReadIndexed(m_pObjStrm);
135 : }
136 0 : m_DivInfo.ReadIndexed(m_pObjStrm);
137 0 : m_Epoch.Read(m_pObjStrm);
138 0 : m_WYSIWYGPageHints.ReadIndexed(m_pObjStrm);
139 0 : m_VerDoc.ReadIndexed(m_pObjStrm);
140 0 : m_STXInfo.ReadIndexed(m_pObjStrm);
141 0 : }
142 :
143 : /**
144 : * @descr Read plug related data from m_pObjStram
145 : **/
146 0 : void LwpDocument::ReadPlug()
147 : {
148 0 : m_DocSockID.ReadIndexed(m_pObjStrm);
149 0 : m_nFlags = m_pObjStrm->QuickReaduInt16();
150 0 : m_pObjStrm->SkipExtra();
151 0 : }
152 :
153 : /**
154 : * @descr Parse obj to IXFStream
155 : **/
156 0 : void LwpDocument::Parse(IXFStream* pOutputStream)
157 : {
158 : //check the name and skip script division
159 0 : if (!IsSkippedDivision())
160 : {
161 : //the frames which anchor are to page must output before other contents
162 0 : ParseFrameInPage(pOutputStream);
163 0 : ParseDocContent(pOutputStream);
164 : }
165 :
166 0 : LwpObject* pDocSock = GetSocket()->obj( VO_DOCSOCK );
167 0 : if(pDocSock!=NULL)
168 : {
169 0 : pDocSock->Parse(pOutputStream);
170 : }
171 0 : }
172 :
173 0 : sal_Bool LwpDocument::IsSkippedDivision()
174 : {
175 0 : OUString sDivName;
176 0 : sal_uInt8 ret = sal_False;
177 0 : LwpDivInfo* pDiv = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj(VO_DIVISIONINFO));
178 0 : if (pDiv == NULL)
179 0 : return sal_True;
180 0 : sDivName = pDiv->GetDivName();
181 0 : if (!sDivName.isEmpty() && !pDiv->IsGotoable()) //including toa,scripts division
182 0 : return sal_True;
183 : //skip endnote division
184 0 : OUString strClassName = pDiv->GetClassName();
185 0 : if ((strClassName == STR_DivisionEndnote)
186 0 : || (strClassName == STR_DivisionGroupEndnote)
187 0 : || (strClassName == STR_DocumentEndnote))
188 : {
189 0 : LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pDiv->GetInitialLayoutID()->obj(VO_PAGELAYOUT));
190 0 : if(pPageLayout)
191 : {
192 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent()->obj(VO_STORY));
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* pFirst = pStory->GetFirstPara();
198 0 : LwpObjectID* pLast = pStory->GetLastPara();
199 0 : if(*pFirst == *pLast)
200 0 : ret = sal_True;
201 : }
202 : }
203 : }
204 0 : return ret;
205 : }
206 :
207 : /**
208 : * @descr Register all styles in this division
209 : */
210 0 : void LwpDocument::RegisterStyle()
211 : {
212 0 : RegisterDefaultParaStyles();
213 0 : RegisterGraphicsStyles();
214 0 : RegisterBulletStyles();
215 :
216 0 : RegisterTextStyles();
217 0 : RegisterLayoutStyles();
218 0 : RegisterStylesInPara();
219 :
220 0 : RegisterLinenumberStyles();
221 0 : RegisterFootnoteStyles();
222 :
223 : //Register styles in other document connected with this document: next doc, children doc
224 0 : LwpObject* pDocSock = GetSocket()->obj();
225 0 : if(pDocSock!=NULL)
226 : {
227 0 : pDocSock->RegisterStyle();
228 : }
229 0 : }
230 : /**
231 : * @descr Register all named para styles
232 : */
233 0 : void LwpDocument::RegisterTextStyles()
234 : {
235 : //Register all text styles: para styles, character styles
236 0 : LwpDLVListHeadHolder* pParaStyleHolder = dynamic_cast<LwpDLVListHeadHolder*>(m_pFoundry->GetTextStyleHead()->obj());
237 0 : if(pParaStyleHolder)
238 : {
239 0 : LwpTextStyle* pParaStyle = dynamic_cast<LwpTextStyle*> (pParaStyleHolder->GetHeadID()->obj());
240 0 : while(pParaStyle)
241 : {
242 0 : pParaStyle->SetFoundry(m_pFoundry);
243 0 : pParaStyle->RegisterStyle();
244 0 : pParaStyle = dynamic_cast<LwpParaStyle*>(pParaStyle->GetNext()->obj());
245 : }
246 : }
247 0 : ChangeStyleName();//add by ,for click here block,05/5/26
248 0 : }
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 0 : void LwpDocument::RegisterLayoutStyles()
254 : {
255 : //Register all layout styles, before register all styles in para
256 0 : m_pFoundry->RegisterAllLayouts();
257 :
258 : //set initial pagelayout in story for parsing pagelayout
259 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (m_DivInfo.obj( VO_DIVISIONINFO));
260 0 : LwpPageLayout* pPageLayout = NULL;
261 0 : if(pDivInfo)
262 : {
263 0 : pPageLayout = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID()->obj(VO_PAGELAYOUT));
264 0 : if(pPageLayout)
265 : {
266 : //In Ole division, the content of pagelayout is VO_OLEOBJECT
267 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent()->obj(VO_STORY));
268 0 : if(pStory)
269 : {
270 : //add all the pagelayout in order into the pagelayout list;
271 0 : pStory->SortPageLayout();
272 0 : pStory->SetCurrentLayout(pPageLayout);
273 : }
274 : }
275 : }
276 0 : }
277 : /**
278 : * @descr Register all styles used in para
279 : */
280 0 : void LwpDocument::RegisterStylesInPara()
281 : {
282 : //Register all automatic styles in para
283 0 : LwpHeadContent* pContent = dynamic_cast<LwpHeadContent*> (m_pFoundry->GetContentManager()->GetContentList()->obj());
284 0 : if(pContent)
285 : {
286 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(pContent->GetChildHead()->obj(VO_STORY));
287 0 : while(pStory)
288 : {
289 : //Register the child para
290 0 : pStory->SetFoundry(m_pFoundry);
291 0 : pStory->RegisterStyle();
292 0 : pStory = dynamic_cast<LwpStory*>(pStory->GetNext()->obj(VO_STORY));
293 : }
294 : }
295 0 : }
296 : /**
297 : * @descr Register all bullet styles used in this division
298 : */
299 0 : void LwpDocument::RegisterBulletStyles()
300 : {
301 : //Register bullet styles
302 : LwpDLVListHeadHolder* mBulletHead = dynamic_cast<LwpDLVListHeadHolder*>
303 0 : (m_pFoundry->GetBulletManagerID()->obj(VO_HEADHOLDER));
304 0 : if( mBulletHead )
305 : {
306 : LwpSilverBullet* pBullet = dynamic_cast<LwpSilverBullet*>
307 0 : (mBulletHead->GetHeadID()->obj());
308 0 : while(pBullet)
309 : {
310 0 : pBullet->SetFoundry(m_pFoundry);
311 0 : pBullet->RegisterStyle();
312 0 : pBullet = dynamic_cast<LwpSilverBullet*> (pBullet->GetNext()->obj());
313 : }
314 : }
315 0 : }
316 : /**
317 : * @descr Register all styles used in VO_Graphic
318 : */
319 0 : void LwpDocument::RegisterGraphicsStyles()
320 : {
321 : //Register all graphics styles, the first object should register the next;
322 0 : LwpObject* pGraphic = m_pFoundry->GetGraphicListHead()->obj(VO_GRAPHIC);
323 0 : if(pGraphic)
324 : {
325 0 : pGraphic->SetFoundry(m_pFoundry);
326 0 : pGraphic->RegisterStyle();
327 : }
328 0 : }
329 : /**
330 : * @descr Register line number styles
331 : */
332 0 : void LwpDocument::RegisterLinenumberStyles()
333 : {
334 0 : if (!m_pLnOpts)
335 0 : return;
336 0 : m_pLnOpts->RegisterStyle();
337 : }
338 :
339 : /**
340 : * @descr Register footnote/endnote configuration for the entire document
341 : */
342 0 : void LwpDocument::RegisterFootnoteStyles()
343 : {
344 : //Register footnote and endnote configuration for the entire document
345 0 : if(!m_FootnoteOpts.IsNull())
346 : {
347 0 : LwpFootnoteOptions* pFootnoteOpts = dynamic_cast<LwpFootnoteOptions*>(m_FootnoteOpts.obj());
348 0 : if (pFootnoteOpts)
349 : {
350 0 : pFootnoteOpts->SetMasterPage("Endnote");
351 0 : 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 0 : LwpDocument* pEndnoteDiv = GetLastDivisionThatHasEndnote();
357 0 : if(this == pEndnoteDiv)
358 : {
359 0 : LwpDLVListHeadTailHolder* pHeadTail = dynamic_cast<LwpDLVListHeadTailHolder*>(GetPageHintsID()->obj());
360 0 : if(pHeadTail)
361 : {
362 0 : LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetTail()->obj());
363 0 : if(pPageHint && !pPageHint->GetPageLayoutID()->IsNull())
364 : {
365 0 : LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pPageHint->GetPageLayoutID()->obj());
366 0 : if(pPageLayout)
367 : {
368 0 : pPageLayout->SetFoundry(GetFoundry());
369 0 : pPageLayout->RegisterEndnoteStyle();
370 : }
371 : }
372 : }
373 : }
374 0 : }
375 :
376 : /**
377 : * @descr Register default para styles
378 : */
379 : #include "lwpverdocument.hxx"
380 0 : void LwpDocument::RegisterDefaultParaStyles()
381 : {
382 0 : if(!IsChildDoc())
383 : {
384 : //Get First Division
385 : //LwpDocument* pFirstDoc = GetFirstDivision();
386 0 : LwpDocument* pFirstDoc = GetFirstDivisionWithContentsThatIsNotOLE();
387 0 : if(pFirstDoc)
388 : {
389 0 : LwpVerDocument* pVerDoc = dynamic_cast<LwpVerDocument*>(pFirstDoc->GetVerDoc()->obj());
390 0 : if(pVerDoc)
391 : {
392 0 : pVerDoc->RegisterStyle();
393 : }
394 : }
395 :
396 : }
397 0 : }
398 :
399 : /**
400 : * @descr Parse content in this division to IXFStream
401 : * LwpDocument->LwpDivInfo->LwpPageLayout.Parse()
402 : */
403 0 : void LwpDocument::ParseDocContent(IXFStream* pOutputStream)
404 : {
405 : //Parse content in PageLayout
406 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (m_DivInfo.obj());
407 0 : if(pDivInfo==NULL) return;
408 :
409 0 : LwpObject* pLayoutObj = pDivInfo->GetInitialLayoutID()->obj();
410 0 : if(pLayoutObj==NULL)
411 : {
412 : //master document not supported now.
413 0 : return;
414 : }
415 0 : pLayoutObj->SetFoundry(m_pFoundry);
416 0 : pLayoutObj->Parse(pOutputStream);
417 : }
418 :
419 : /**
420 : * @descr Get the footnoteoptions from the root document
421 : */
422 0 : LwpObjectID* LwpDocument::GetValidFootnoteOpts()
423 : {
424 0 : LwpDocument* pRoot = GetRootDocument();
425 0 : if(pRoot)
426 : {
427 0 : 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());
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 0 : LwpDocument* LwpDocument::GetPreviousDivision()
453 : {
454 0 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
455 0 : if(pDocSock)
456 : {
457 0 : return dynamic_cast<LwpDocument*>(pDocSock->GetPrevious()->obj());
458 : }
459 0 : return NULL;
460 : }
461 : /**
462 : * @descr Get next division
463 : */
464 0 : LwpDocument* LwpDocument::GetNextDivision()
465 : {
466 0 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
467 0 : if(pDocSock)
468 : {
469 0 : return dynamic_cast<LwpDocument*>(pDocSock->GetNext()->obj());
470 : }
471 0 : return NULL;
472 : }
473 : /**
474 : * @descr Get parent division
475 : */
476 0 : LwpDocument* LwpDocument::GetParentDivision()
477 : {
478 0 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
479 0 : if(pDocSock)
480 : {
481 0 : return dynamic_cast<LwpDocument*>(pDocSock->GetParent()->obj());
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());
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());
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 0 : LwpDocument* LwpDocument::GetPreviousDivisionWithContents()
520 : {
521 0 : if(GetPreviousDivision())
522 : {
523 0 : LwpDocument* pDoc = GetPreviousDivision()->GetLastDivisionWithContents();
524 0 : if (pDoc)
525 0 : return pDoc;
526 : }
527 0 : if(GetParentDivision())
528 0 : return GetParentDivision()->GetPreviousDivisionWithContents();
529 0 : return NULL;
530 : }
531 : /**
532 : * @descr Get last division which has contents, copy from lwp source code
533 : */
534 0 : LwpDocument* LwpDocument::GetLastDivisionWithContents()
535 : {
536 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj());
537 0 : if(pDivInfo && pDivInfo->HasContents())
538 : {
539 0 : return this;
540 : }
541 :
542 0 : LwpDocument* pDivision = GetLastDivision();
543 0 : LwpDocument* pContentDivision = NULL;
544 :
545 0 : while(pDivision)
546 : {
547 0 : pContentDivision = pDivision->GetLastDivisionWithContents();
548 0 : if(pContentDivision)
549 : {
550 0 : 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());
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 0 : LwpDocument* LwpDocument::GetLastDivision()
580 : {
581 0 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
582 0 : if(pDocSock)
583 0 : return dynamic_cast<LwpDocument*>(pDocSock->GetChildTail()->obj());
584 0 : return NULL;
585 : }
586 :
587 : /**
588 : * @descr Get first division
589 : */
590 0 : LwpDocument* LwpDocument::GetFirstDivision()
591 : {
592 0 : LwpDocSock* pDocSock = dynamic_cast<LwpDocSock*>(GetSocket()->obj());
593 0 : if(pDocSock)
594 0 : return dynamic_cast<LwpDocument*>(pDocSock->GetChildHead()->obj());
595 0 : return NULL;
596 : }
597 :
598 : /**
599 : * @descr Get root document
600 : */
601 0 : LwpDocument* LwpDocument::GetRootDocument()
602 : {
603 0 : LwpDocument* pRoot = this;
604 0 : while(pRoot)
605 : {
606 0 : if(!pRoot->IsChildDoc())
607 0 : return pRoot;
608 0 : 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 0 : LwpDocument* LwpDocument::GetFirstDivisionWithContentsThatIsNotOLE()
616 : {
617 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(GetDivInfoID()->obj());
618 0 : if(pDivInfo && pDivInfo->HasContents()
619 0 : && !pDivInfo->IsOleDivision())
620 0 : return this;
621 :
622 0 : LwpDocument* pDivision = GetFirstDivision();
623 :
624 0 : LwpDocument* pContentDivision = NULL;
625 :
626 0 : while (pDivision)
627 : {
628 0 : pContentDivision = pDivision->GetFirstDivisionWithContentsThatIsNotOLE();
629 0 : if(pContentDivision)
630 0 : return pContentDivision;
631 0 : pDivision = pDivision->GetNextDivision();
632 : }
633 0 : return NULL;
634 : }
635 : /**
636 : * @descr Get last division that has endnote
637 : */
638 0 : LwpDocument* LwpDocument::GetLastDivisionThatHasEndnote()
639 : {
640 0 : LwpDocument* pRoot = GetRootDocument();
641 0 : LwpDocument *pLastDoc = pRoot->GetLastDivisionWithContents();
642 0 : while(pLastDoc)
643 : {
644 0 : if(pLastDoc->GetEnSuperTableLayout())
645 0 : return pLastDoc;
646 0 : pLastDoc = pLastDoc->GetPreviousDivisionWithContents();
647 : }
648 0 : return NULL;
649 :
650 : }
651 : /**
652 : * @descr Get endnote supertable layout, every division has only one endnote supertable layout.
653 : */
654 0 : LwpVirtualLayout* LwpDocument::GetEnSuperTableLayout()
655 : {
656 0 : LwpHeadLayout* pHeadLayout = dynamic_cast<LwpHeadLayout*>(GetFoundry()->GetLayout()->obj());
657 0 : if(pHeadLayout)
658 : {
659 0 : 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 : sal_Bool LwpDocument::GetNumberOfPages(LwpDocument* pEndDivision, sal_uInt16& nCount)
668 : {
669 0 : if(this == pEndDivision)
670 0 : return sal_True;
671 :
672 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(m_DivInfo.obj());
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 sal_True;
683 0 : pDivision = pDivision->GetNextDivision();
684 :
685 : }
686 0 : return sal_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());
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 0 : void LwpDocument::ParseFrameInPage(IXFStream * pOutputStream)
721 : {
722 0 : if(IsChildDoc())
723 0 : return;
724 :
725 0 : XFContentContainer* pXFContainer = new XFContentContainer;
726 :
727 0 : XFConvertFrameInPage(pXFContainer);
728 :
729 0 : pXFContainer->ToXml(pOutputStream);
730 0 : delete pXFContainer;
731 0 : pXFContainer = NULL;
732 : }
733 : /**
734 : * @descr Parse the frame which anchor is to page in the entire document
735 : */
736 0 : void LwpDocument::XFConvertFrameInPage(XFContentContainer * pCont)
737 : {
738 0 : LwpDocument* pDivision = GetFirstDivision();
739 :
740 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*> (GetDivInfoID()->obj());
741 0 : if(pDivInfo)
742 : {
743 0 : LwpPageLayout* pPageLayout = dynamic_cast<LwpPageLayout*>(pDivInfo->GetInitialLayoutID()->obj());
744 0 : if(pPageLayout)
745 : {
746 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(pPageLayout->GetContent()->obj());
747 0 : if(pStory)
748 0 : pStory->XFConvertFrameInPage(pCont);
749 : }
750 : }
751 0 : while(pDivision)
752 : {
753 0 : pDivision->XFConvertFrameInPage(pCont);
754 0 : pDivision = pDivision->GetNextDivision();
755 : }
756 0 : }
757 : /**
758 : * @descr change click here to placeholder
759 : */
760 0 : void LwpDocument::ChangeStyleName()
761 : {
762 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
763 0 : XFTextStyle* pStyle = dynamic_cast<XFTextStyle*>(pXFStyleManager->FindStyle("ClickHere"));
764 0 : if (pStyle)
765 : {
766 0 : pStyle->SetStyleName("Placeholder");
767 : }
768 0 : }
769 0 : LwpDocSock::LwpDocSock(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
770 0 : :LwpDLNFVList(objHdr, pStrm)
771 0 : {}
772 :
773 : /**
774 : * @descr read VO_DOCSOCK from file
775 : */
776 0 : void LwpDocSock::Read()
777 : {
778 0 : LwpDLNFVList::Read();
779 0 : m_Doc.ReadIndexed(m_pObjStrm);
780 0 : m_pObjStrm->SkipExtra();
781 0 : }
782 : /**
783 : * @descr register styles in documents plugged
784 : */
785 0 : void LwpDocSock::RegisterStyle()
786 : {
787 0 : LwpObject* pDoc = GetNext()->obj();
788 0 : if(pDoc)
789 0 : pDoc->RegisterStyle();
790 :
791 0 : pDoc = GetChildHead()->obj();
792 0 : if(pDoc)
793 0 : pDoc->RegisterStyle();
794 0 : }
795 : /**
796 : * @descr parse contents of documents plugged
797 : */
798 0 : void LwpDocSock::Parse(IXFStream* pOutputStream)
799 : {
800 0 : LwpObject* pDoc = GetChildHead()->obj();
801 0 : if(pDoc)
802 0 : pDoc->Parse(pOutputStream);
803 :
804 0 : pDoc = GetNext()->obj();
805 0 : if(pDoc)
806 0 : pDoc->Parse(pOutputStream);
807 0 : }
808 :
809 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|