update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwpfribptr.cxx
blob1aaebc6069dc5356b4de547f661e3ba416e620b1
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
56 * @file
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
60 * Change History
61 Jan 2005 Created
62 ************************************************************************/
64 #include "lwpfribptr.hxx"
66 #include "lwpfribheader.hxx"
67 #include "lwpfribtext.hxx"
68 #include "lwppara.hxx"
69 #include "lwpstory.hxx"
70 #include "xfilter/xftextspan.hxx"
71 #include "xfilter/xftextcontent.hxx"
72 #include "xfilter/xftabstop.hxx"
73 #include "xfilter/xflinebreak.hxx"
74 #include "lwpfribsection.hxx"
75 #include "lwpsection.hxx"
76 #include "lwpfribbreaks.hxx"
77 #include "lwpfribframe.hxx"
78 #include "lwpfribtable.hxx"
79 #include "xfilter/xfstylemanager.hxx"
80 #include "lwphyperlinkmgr.hxx"
81 #include "xfilter/xfhyperlink.hxx"
82 #include "lwpfootnote.hxx"
83 #include "lwpnotes.hxx"
84 #include "lwpfribmark.hxx"
85 #include "xfilter/xfchange.hxx"
86 #include "lwpchangemgr.hxx"
87 #include "lwpglobalmgr.hxx"
90 LwpFribPtr::LwpFribPtr()
91 : m_pFribs(NULL),m_pPara(NULL),m_pXFPara(NULL)
94 LwpFribPtr::~LwpFribPtr()
96 LwpFrib* pNextFrib = m_pFribs;
97 LwpFrib* pCurFrib = m_pFribs;
98 while(pCurFrib)
100 pNextFrib = pCurFrib -> GetNext();
101 delete pCurFrib;
102 pCurFrib = pNextFrib;
106 void LwpFribPtr::ReadPara(LwpObjectStream* pObjStrm)
108 sal_uInt8 FribTag=0;
109 sal_uInt8 FribType;
110 sal_uInt8 FribEditor;
111 BOOL ProblemFrib;
113 LwpFrib* pCurFrib = m_pFribs = NULL;
114 for(;;)
116 ProblemFrib = FALSE;
117 // Get the frib type
118 pObjStrm->QuickRead(&FribTag, sizeof(FribTag));
120 FribType = FribTag & ~FRIB_TAG_TYPEMASK;
122 // Stop when we hit Elvis
123 if (FribType == FRIB_TAG_ELVIS)
124 break;
126 // skip the editor ID
127 //pObjStrm->SeekRel(sizeof(sal_uInt8));
128 pObjStrm->QuickRead(&FribEditor, sizeof(FribEditor));
129 if( FribType != FT_MAXIMUM )
131 LwpFrib* pFrib = LwpFrib::CreateFrib( m_pPara, pObjStrm, FribTag,FribEditor);
132 if(!m_pFribs)
134 m_pFribs = pFrib;
136 if(pCurFrib)
138 pCurFrib->SetNext(pFrib);
140 else//frist frib in the para,add by 2/1
142 if (pFrib->GetType() == FRIB_TAG_TEXT)
144 LwpFribText* pText = static_cast<LwpFribText*>(pFrib);
145 if (pFrib->GetModifiers())
146 m_pPara->SetFirstFrib(pText->GetText(),pText->GetModifiers()->FontID);
147 else
148 m_pPara->SetFirstFrib(pText->GetText(),0);
151 pCurFrib = pFrib;
153 else
154 ProblemFrib = TRUE;
158 /*String LwpFribPtr::GetText()
160 LwpFrib* pFrib = m_pFribs;
161 String content;
162 while(pFrib)
164 if(pFrib->GetType() == FRIB_TAG_TEXT)
166 content+= static_cast<LwpFribText*>(pFrib)->GetText();
168 pFrib = pFrib->GetNext();
170 return (content);
173 #include "lwpdropcapmgr.hxx"
174 void LwpFribPtr::XFConvert()
176 LwpFrib* pFrib = m_pFribs;
177 while(pFrib)
179 sal_uInt8 nFribType = pFrib->GetType();
180 sal_Bool bRevisionFlag = pFrib->GetRevisionFlag();
181 sal_uInt8 nRevisionType;
182 OUString sChangeID;
183 if (bRevisionFlag)
185 if ( nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
186 && nFribType != FRIB_TAG_FRAME)
188 nRevisionType = pFrib->GetRevisionType();
189 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
190 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
191 sChangeID = pChangeMgr->GetChangeID(pFrib);
192 if (sChangeID.getLength())
194 /// if (nRevisionType == LwpFrib::REV_INSERT)
195 /// {
196 XFChangeStart* pChangeStart = new XFChangeStart;
197 pChangeStart->SetChangeID(sChangeID);
198 m_pXFPara->Add(pChangeStart);
199 /// }
200 /// else if (nRevisionType == LwpFrib::REV_DELETE)
201 /// {
202 /// XFChange* pChange = new XFChange;
203 /// pChange->SetChangeID(sChangeID);
204 /// m_pXFPara->Add(pChange);
205 /// pFrib = pFrib->GetNext();
206 /// continue;
207 /// }
212 switch(nFribType)
214 case FRIB_TAG_TEXT:
216 LwpFribText* textFrib= static_cast<LwpFribText*>(pFrib);
217 textFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
219 break;
220 case FRIB_TAG_TAB:
222 LwpFribTab* tabFrib = static_cast<LwpFribTab*>(pFrib);
223 if (pFrib->m_ModFlag)
225 XFTextSpan *pSpan = new XFTextSpan();
226 pSpan->SetStyleName(tabFrib->GetStyleName());
227 XFTabStop *pTab = new XFTabStop();
228 pSpan->Add(pTab);
229 m_pXFPara->Add(pSpan);
231 else
233 XFTabStop *pTab = new XFTabStop();
234 m_pXFPara->Add(pTab);
237 break;
238 case FRIB_TAG_SECTION:
240 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
241 pSectionFrib->ParseSection();
243 break;
245 case FRIB_TAG_PAGEBREAK:
247 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
248 LwpPageLayout* pLayout = static_cast<LwpPageLayout*>(pPageBreak->GetLayout()->obj());
249 if(pLayout)
251 pPageBreak->ParseLayout();
253 else
255 if (pPageBreak->IsLastFrib() == sal_True)
257 m_pXFPara->SetStyleName( pPageBreak->GetStyleName() );
259 else
261 //parse pagebreak
262 XFParagraph *pPara = new XFParagraph();
263 pPara->SetStyleName(pFrib->GetStyleName());
264 SetXFPara(pPara);
265 m_pPara->AddXFContent(pPara);
269 break;
270 case FRIB_TAG_COLBREAK:
272 XFParagraph *pPara = new XFParagraph();
273 pPara->SetStyleName(pFrib->GetStyleName());
274 SetXFPara(pPara);
275 m_pPara->AddXFContent(pPara);
277 break;
278 case FRIB_TAG_LINEBREAK:
280 XFLineBreak *pLineBreak = new XFLineBreak();
281 m_pXFPara->Add(pLineBreak);
283 break;
284 case FRIB_TAG_UNICODE: //fall through
285 case FRIB_TAG_UNICODE2: //fall through
286 case FRIB_TAG_UNICODE3: //fall through
288 LwpFribUnicode* unicodeFrib= static_cast<LwpFribUnicode*>(pFrib);
289 unicodeFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
291 break;
292 case FRIB_TAG_HARDSPACE:
294 rtl::OUString sHardSpace(sal_Unicode(0x00a0));
295 LwpHyperlinkMgr* pHyperlink =
296 m_pPara->GetStory()->GetHyperlinkMgr();
297 if (pHyperlink->GetHyperlinkFlag())
298 pFrib->ConvertHyperLink(m_pXFPara,pHyperlink,sHardSpace);
299 else
300 pFrib->ConvertChars(m_pXFPara,sHardSpace);
302 break;
303 case FRIB_TAG_SOFTHYPHEN:
305 rtl::OUString sSoftHyphen(sal_Unicode(0x00ad));
306 pFrib->ConvertChars(m_pXFPara,sSoftHyphen);
308 break;
309 case FRIB_TAG_FRAME:
311 LwpFribFrame* frameFrib= static_cast<LwpFribFrame*>(pFrib);
312 LwpObject* pLayout = frameFrib->GetLayout();
313 if (pLayout->GetTag() == VO_DROPCAPLAYOUT)
315 m_pPara->GetFoundry()->GetDropcapMgr()->SetXFPara(m_pXFPara);
316 //LwpObject* pDropCap = frameFrib->GetLayout();
317 //pDropCap ->XFConvert(m_pXFPara);
319 //pLayout->XFConvert(m_pXFPara);
320 frameFrib->XFConvert(m_pXFPara);
322 break;
323 case FRIB_TAG_CHBLOCK:
325 LwpFribCHBlock* chbFrib = static_cast<LwpFribCHBlock*>(pFrib);
326 chbFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
328 break;
329 case FRIB_TAG_TABLE:
331 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
332 //tableFrib->XFConvert(m_pPara->GetXFContainer());
333 tableFrib->XFConvert(m_pXFPara);
335 break;
336 case FRIB_TAG_BOOKMARK:
338 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
339 bookmarkFrib->XFConvert(m_pXFPara);
341 break;
342 case FRIB_TAG_FOOTNOTE:
344 LwpFribFootnote* pFootnoteFrib = static_cast<LwpFribFootnote*>(pFrib);
345 pFootnoteFrib->XFConvert(m_pXFPara);
346 break;
348 case FRIB_TAG_FIELD:
350 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
351 fieldFrib->XFConvert(m_pXFPara);
352 break;
354 case FRIB_TAG_NOTE:
356 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
357 pNoteFrib->XFConvert(m_pXFPara);
358 break;
360 case FRIB_TAG_PAGENUMBER:
362 LwpFribPageNumber* pagenumFrib = static_cast<LwpFribPageNumber*>(pFrib);
363 pagenumFrib->XFConvert(m_pXFPara);
364 break;
366 case FRIB_TAG_DOCVAR:
368 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
369 docFrib->XFConvert(m_pXFPara);
370 break;
372 case FRIB_TAG_RUBYMARKER:
374 LwpFribRubyMarker* rubyFrib = static_cast<LwpFribRubyMarker*>(pFrib);
375 rubyFrib->XFConvert(m_pXFPara);
376 break;
378 case FRIB_TAG_RUBYFRAME:
380 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
381 rubyfrmeFrib->XFConvert(m_pXFPara);
382 break;
384 default :
385 break;
388 if (bRevisionFlag )//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
390 if (nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
391 && nFribType != FRIB_TAG_FRAME)
393 if (sChangeID.getLength())
395 XFChangeEnd* pChangeEnd = new XFChangeEnd;
396 pChangeEnd->SetChangeID(sChangeID);
397 m_pXFPara->Add(pChangeEnd);
401 pFrib = pFrib->GetNext();
406 void LwpFribPtr::FindLayouts()
408 LwpFrib* pFrib = m_pFribs;
409 while(pFrib)
411 switch(pFrib->GetType())
413 case FRIB_TAG_SECTION:
415 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
416 LwpSection* pSection = pSectionFrib->GetSection();
417 if(pSection)
419 LwpPageLayout* pLayout = pSection->GetPageLayout();
420 if(pLayout)
422 LwpLayout::UseWhenType eSectionType = pLayout->GetUseWhenType();
423 if(eSectionType==LwpLayout::StartWithinColume)
425 //StartWithinColume type not support now
426 break;
428 LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
429 pStory->AddPageLayout(pSection->GetPageLayout());
433 break;
435 case FRIB_TAG_PAGEBREAK:
437 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
438 LwpPageLayout* pLayout = static_cast<LwpPageLayout*>(pPageBreak->GetLayout()->obj());
439 if(pLayout)
441 LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
442 pStory->AddPageLayout(pLayout);
444 break;
446 default:
447 break;
449 pFrib = pFrib->GetNext();
452 /**************************************************************************
453 * @descr: Whether has a frib which type is nType
454 * @param:
455 * @param:
456 * @return:
457 **************************************************************************/
458 LwpFrib* LwpFribPtr::HasFrib(sal_uInt8 nType)
460 LwpFrib* pFrib = m_pFribs;
461 while(pFrib)
463 if(pFrib->GetType()==nType)
465 return pFrib;
467 pFrib = pFrib->GetNext();
469 return NULL;
472 void LwpFribPtr::GatherAllText()
474 LwpFrib* pFrib = m_pFribs;
475 while(pFrib)
477 switch(pFrib->GetType())
479 case FRIB_TAG_TEXT:
481 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
482 m_pPara->SetAllText(sText);
483 break;
485 case FRIB_TAG_UNICODE: //fall through
486 case FRIB_TAG_UNICODE2: //fall through
487 case FRIB_TAG_UNICODE3: //fall through :
489 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
490 m_pPara->SetAllText(sText);
491 break;
493 default :
494 break;
496 pFrib = pFrib->GetNext();
500 void LwpFribPtr::RegisterStyle()
502 LwpFrib* pFrib = m_pFribs;
503 while(pFrib)
505 switch(pFrib->GetType())
507 case FRIB_TAG_TEXT:
509 pFrib->RegisterStyle(m_pPara->GetFoundry());
510 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
511 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
512 break;
514 case FRIB_TAG_TAB:
515 pFrib->RegisterStyle(m_pPara->GetFoundry());
516 break;
517 case FRIB_TAG_SECTION:
519 //section registerstyle here;
520 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
521 pSectionFrib->RegisterSectionStyle();
522 //for bullet
523 pSectionFrib->SetSectionName();
525 break;
526 case FRIB_TAG_PAGEBREAK:
528 LwpFribPageBreak* breakFrib = static_cast<LwpFribPageBreak*>(pFrib);
529 breakFrib->RegisterBreakStyle(m_pPara);
531 break;
532 case FRIB_TAG_COLBREAK:
534 LwpFribColumnBreak* breakFrib = static_cast<LwpFribColumnBreak*>(pFrib);
535 breakFrib->RegisterBreakStyle(m_pPara);
537 break;
538 case FRIB_TAG_UNICODE: //fall through
539 case FRIB_TAG_UNICODE2: //fall through
540 case FRIB_TAG_UNICODE3: //fall through :
542 pFrib->RegisterStyle(m_pPara->GetFoundry());
543 OUString sText = static_cast<LwpFribUnicode*>(pFrib)->GetText();
544 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
545 break;
547 case FRIB_TAG_HARDSPACE:
548 pFrib->RegisterStyle(m_pPara->GetFoundry());
549 ProcessDropcap(m_pPara->GetStory(),pFrib,1);
550 break;
551 case FRIB_TAG_SOFTHYPHEN:
552 pFrib->RegisterStyle(m_pPara->GetFoundry());
553 break;
554 case FRIB_TAG_FRAME:
556 LwpFribFrame* frameFrib = static_cast<LwpFribFrame*>(pFrib);
557 frameFrib->SetParaDropcap(m_pPara);
558 frameFrib->RegisterStyle(m_pPara->GetFoundry());
559 //register framelayout style, ,03/09/2005
560 //frameFrib->GetLayout()->RegisterStyle();
562 break;
563 case FRIB_TAG_CHBLOCK:
564 break;
565 case FRIB_TAG_TABLE:
567 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
568 tableFrib->RegisterStyle();
570 break;
571 case FRIB_TAG_FOOTNOTE:
573 LwpFribFootnote* pFribFootnote = static_cast<LwpFribFootnote*>(pFrib);
574 pFribFootnote->RegisterStyle();
576 break;
577 case FRIB_TAG_NOTE:
579 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
580 pNoteFrib->RegisterStyle();
581 break;
583 case FRIB_TAG_PAGENUMBER:
585 pFrib->RegisterStyle(m_pPara->GetFoundry());
586 break;
588 case FRIB_TAG_DOCVAR:
590 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
591 docFrib->RegisterStyle(m_pPara->GetFoundry());
592 break;
594 case FRIB_TAG_FIELD:
596 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
597 fieldFrib->RegisterStyle(m_pPara->GetFoundry());
598 break;
600 case FRIB_TAG_BOOKMARK:
602 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
603 bookmarkFrib->RegisterStyle(m_pPara->GetFoundry());
604 break;
606 case FRIB_TAG_RUBYFRAME:
608 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
609 rubyfrmeFrib->RegisterStyle(m_pPara->GetFoundry());
610 break;
612 default :
613 break;
615 if (pFrib->GetRevisionFlag() && pFrib->GetType()!= FRIB_TAG_FIELD)
617 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
618 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
619 pChangeMgr->AddChangeFrib(pFrib);
622 pFrib = pFrib->GetNext();
626 void LwpFribPtr::ProcessDropcap(LwpStory* pStory,LwpFrib* pFrib,sal_uInt32 nLen)
628 if (pStory)
630 if (pStory->GetDropcapFlag() == sal_True)
632 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
633 XFTextStyle* pFribStyle = pXFStyleManager->FindTextStyle(pFrib->GetStyleName());
634 pFribStyle->GetFont()->SetFontSize(0);
636 LwpObject* pObj= pStory->GetLayoutsWithMe()->GetOnlyLayout()->obj();
637 if (pObj)
638 static_cast<LwpDropcapLayout*>(pObj)->SetChars(nLen);
643 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, defalut return true
646 sal_Bool LwpFribPtr::ComparePagePosition(LwpVirtualLayout* pPreLayout, LwpVirtualLayout* pNextLayout)
648 if(!pPreLayout || !pNextLayout)
649 return sal_True;
651 LwpFrib* pFrib = m_pFribs;
652 LwpVirtualLayout* pLayout = NULL;
653 while(pFrib)
655 switch(pFrib->GetType())
657 case FRIB_TAG_SECTION:
659 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
660 LwpSection* pSection = pSectionFrib->GetSection();
661 if(pSection)
663 pLayout = pSection->GetPageLayout();
666 break;
668 case FRIB_TAG_PAGEBREAK:
670 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
671 pLayout = static_cast<LwpVirtualLayout*>(pPageBreak->GetLayout()->obj());
672 break;
674 default:
675 break;
678 if(pLayout)
680 if(pPreLayout == pLayout)
681 return sal_True;
682 if(pNextLayout == pLayout)
683 return sal_False;
685 pFrib = pFrib->GetNext();
688 return sal_True;