build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribptr.cxx
blobf6e6f62ab2f87f9954dd878bdc37e525b3c9a49e
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 /*************************************************************************
57 * @file
58 * For LWP filter architecture prototype
59 ************************************************************************/
61 #include "lwpfribptr.hxx"
63 #include "lwpfribheader.hxx"
64 #include "lwpfribtext.hxx"
65 #include "lwppara.hxx"
66 #include "lwpstory.hxx"
67 #include "xfilter/xftextspan.hxx"
68 #include "xfilter/xftextcontent.hxx"
69 #include "xfilter/xftabstop.hxx"
70 #include "xfilter/xflinebreak.hxx"
71 #include "lwpfribsection.hxx"
72 #include "lwpsection.hxx"
73 #include "lwpfribbreaks.hxx"
74 #include "lwpfribframe.hxx"
75 #include "lwpfribtable.hxx"
76 #include "xfilter/xfstylemanager.hxx"
77 #include "lwphyperlinkmgr.hxx"
78 #include "xfilter/xfhyperlink.hxx"
79 #include "lwpfootnote.hxx"
80 #include "lwpnotes.hxx"
81 #include "lwpfribmark.hxx"
82 #include "xfilter/xfchange.hxx"
83 #include "lwpchangemgr.hxx"
84 #include "lwpglobalmgr.hxx"
85 #include "lwpdropcapmgr.hxx"
87 LwpFribPtr::LwpFribPtr()
88 : m_pFribs(nullptr),m_pXFPara(nullptr),m_pPara(nullptr)
92 LwpFribPtr::~LwpFribPtr()
94 for (LwpFrib* pCurFrib = m_pFribs; pCurFrib;)
96 LwpFrib* pNextFrib = pCurFrib -> GetNext();
97 delete pCurFrib;
98 pCurFrib = pNextFrib;
102 void LwpFribPtr::ReadPara(LwpObjectStream* pObjStrm)
104 LwpFrib* pCurFrib = m_pFribs = nullptr;
105 for(;;)
107 // Get the frib type
108 sal_uInt8 FribTag = pObjStrm->QuickReaduInt8();
110 sal_uInt8 FribType = FribTag & ~FRIB_TAG_TYPEMASK;
112 // Stop when we hit Elvis
113 if (FribType == FRIB_TAG_ELVIS)
114 break;
116 // skip the editor ID
117 //pObjStrm->SeekRel(sizeof(sal_uInt8));
118 sal_uInt8 FribEditor = pObjStrm->QuickReaduInt8();
119 if( FribType != FT_MAXIMUM )
121 LwpFrib* pFrib = LwpFrib::CreateFrib( m_pPara, pObjStrm, FribTag,FribEditor);
122 if(!m_pFribs)
124 m_pFribs = pFrib;
126 if(pCurFrib)
128 pCurFrib->SetNext(pFrib);
130 else//frist frib in the para
132 if (pFrib->GetType() == FRIB_TAG_TEXT)
134 LwpFribText* pText = static_cast<LwpFribText*>(pFrib);
135 if (pFrib->GetModifiers())
136 m_pPara->SetFirstFrib(pText->GetText(),pText->GetModifiers()->FontID);
137 else
138 m_pPara->SetFirstFrib(pText->GetText(),0);
141 pCurFrib = pFrib;
146 void LwpFribPtr::XFConvert()
148 LwpFrib* pFrib = m_pFribs;
149 while(pFrib)
151 sal_uInt8 nFribType = pFrib->GetType();
152 bool bRevisionFlag = pFrib->GetRevisionFlag();
153 OUString sChangeID;
154 if (bRevisionFlag)
156 if ( nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
157 && nFribType != FRIB_TAG_FRAME)
159 //sal_uInt8 nRevisionType = pFrib->GetRevisionType();
160 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
161 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
162 sChangeID = pChangeMgr->GetChangeID(pFrib);
163 if (!sChangeID.isEmpty())
165 /// if (nRevisionType == LwpFrib::REV_INSERT)
166 /// {
167 XFChangeStart* pChangeStart = new XFChangeStart;
168 pChangeStart->SetChangeID(sChangeID);
169 m_pXFPara->Add(pChangeStart);
170 /// }
171 /// else if (nRevisionType == LwpFrib::REV_DELETE)
172 /// {
173 /// XFChange* pChange = new XFChange;
174 /// pChange->SetChangeID(sChangeID);
175 /// m_pXFPara->Add(pChange);
176 /// pFrib = pFrib->GetNext();
177 /// continue;
178 /// }
183 switch(nFribType)
185 case FRIB_TAG_TEXT:
187 LwpFribText* textFrib= static_cast<LwpFribText*>(pFrib);
188 textFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
190 break;
191 case FRIB_TAG_TAB:
193 LwpFribTab* tabFrib = static_cast<LwpFribTab*>(pFrib);
194 if (pFrib->m_ModFlag)
196 XFTextSpan *pSpan = new XFTextSpan();
197 pSpan->SetStyleName(tabFrib->GetStyleName());
198 XFTabStop *pTab = new XFTabStop();
199 pSpan->Add(pTab);
200 m_pXFPara->Add(pSpan);
202 else
204 XFTabStop *pTab = new XFTabStop();
205 m_pXFPara->Add(pTab);
208 break;
209 case FRIB_TAG_SECTION:
211 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
212 pSectionFrib->ParseSection();
214 break;
216 case FRIB_TAG_PAGEBREAK:
218 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
219 LwpPageLayout* pLayout = dynamic_cast<LwpPageLayout*>(pPageBreak->GetLayout().obj().get());
220 if(pLayout)
222 pPageBreak->ParseLayout();
224 else
226 if (pPageBreak->IsLastFrib())
228 m_pXFPara->SetStyleName( pPageBreak->GetStyleName() );
230 else
232 //parse pagebreak
233 XFParagraph *pPara = new XFParagraph();
234 pPara->SetStyleName(pFrib->GetStyleName());
235 SetXFPara(pPara);
236 m_pPara->AddXFContent(pPara);
240 break;
241 case FRIB_TAG_COLBREAK:
243 XFParagraph *pPara = new XFParagraph();
244 pPara->SetStyleName(pFrib->GetStyleName());
245 SetXFPara(pPara);
246 m_pPara->AddXFContent(pPara);
248 break;
249 case FRIB_TAG_LINEBREAK:
251 XFLineBreak *pLineBreak = new XFLineBreak();
252 m_pXFPara->Add(pLineBreak);
254 break;
255 case FRIB_TAG_UNICODE: //fall through
256 case FRIB_TAG_UNICODE2: //fall through
257 case FRIB_TAG_UNICODE3: //fall through
259 LwpFribUnicode* unicodeFrib= static_cast<LwpFribUnicode*>(pFrib);
260 unicodeFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
262 break;
263 case FRIB_TAG_HARDSPACE:
265 OUString sHardSpace(sal_Unicode(0x00a0));
266 LwpStory *pStory = m_pPara->GetStory();
267 LwpHyperlinkMgr* pHyperlink = pStory ? pStory->GetHyperlinkMgr() : nullptr;
268 if (pHyperlink && pHyperlink->GetHyperlinkFlag())
269 pFrib->ConvertHyperLink(m_pXFPara,pHyperlink,sHardSpace);
270 else
271 pFrib->ConvertChars(m_pXFPara,sHardSpace);
273 break;
274 case FRIB_TAG_SOFTHYPHEN:
276 OUString sSoftHyphen(sal_Unicode(0x00ad));
277 pFrib->ConvertChars(m_pXFPara,sSoftHyphen);
279 break;
280 case FRIB_TAG_FRAME:
282 LwpFribFrame* frameFrib= static_cast<LwpFribFrame*>(pFrib);
283 rtl::Reference<LwpObject> pLayout = frameFrib->GetLayout();
284 if (pLayout.is() && pLayout->GetTag() == VO_DROPCAPLAYOUT)
286 LwpFoundry* pFoundry = m_pPara->GetFoundry();
287 LwpDropcapMgr* pMgr = pFoundry ? pFoundry->GetDropcapMgr() : nullptr;
288 if (pMgr)
289 pMgr->SetXFPara(m_pXFPara);
291 frameFrib->XFConvert(m_pXFPara);
292 break;
294 case FRIB_TAG_CHBLOCK:
296 LwpFribCHBlock* chbFrib = static_cast<LwpFribCHBlock*>(pFrib);
297 chbFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
299 break;
300 case FRIB_TAG_TABLE:
302 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
303 //tableFrib->XFConvert(m_pPara->GetXFContainer());
304 tableFrib->XFConvert(m_pXFPara);
306 break;
307 case FRIB_TAG_BOOKMARK:
309 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
310 bookmarkFrib->XFConvert(m_pXFPara);
312 break;
313 case FRIB_TAG_FOOTNOTE:
315 LwpFribFootnote* pFootnoteFrib = static_cast<LwpFribFootnote*>(pFrib);
316 pFootnoteFrib->XFConvert(m_pXFPara);
317 break;
319 case FRIB_TAG_FIELD:
321 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
322 fieldFrib->XFConvert(m_pXFPara);
323 break;
325 case FRIB_TAG_NOTE:
327 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
328 pNoteFrib->XFConvert(m_pXFPara);
329 break;
331 case FRIB_TAG_PAGENUMBER:
333 LwpFribPageNumber* pagenumFrib = static_cast<LwpFribPageNumber*>(pFrib);
334 pagenumFrib->XFConvert(m_pXFPara);
335 break;
337 case FRIB_TAG_DOCVAR:
339 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
340 docFrib->XFConvert(m_pXFPara);
341 break;
343 case FRIB_TAG_RUBYMARKER:
345 LwpFribRubyMarker* rubyFrib = static_cast<LwpFribRubyMarker*>(pFrib);
346 rubyFrib->XFConvert(m_pXFPara);
347 break;
349 case FRIB_TAG_RUBYFRAME:
351 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
352 rubyfrmeFrib->XFConvert(m_pXFPara);
353 break;
355 default :
356 break;
359 if (bRevisionFlag )//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
361 if (nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
362 && nFribType != FRIB_TAG_FRAME)
364 if (!sChangeID.isEmpty())
366 XFChangeEnd* pChangeEnd = new XFChangeEnd;
367 pChangeEnd->SetChangeID(sChangeID);
368 m_pXFPara->Add(pChangeEnd);
372 pFrib = pFrib->GetNext();
377 void LwpFribPtr::FindLayouts()
379 LwpFrib* pFrib = m_pFribs;
380 while(pFrib)
382 switch(pFrib->GetType())
384 case FRIB_TAG_SECTION:
386 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
387 LwpSection* pSection = pSectionFrib->GetSection();
388 if(pSection)
390 LwpPageLayout* pLayout = pSection->GetPageLayout();
391 if(pLayout)
393 LwpLayout::UseWhenType eSectionType = pLayout->GetUseWhenType();
394 if(eSectionType==LwpLayout::StartWithinColume)
396 //StartWithinColume type not support now
397 break;
399 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
400 if (pStory)
401 pStory->AddPageLayout(pSection->GetPageLayout());
405 break;
407 case FRIB_TAG_PAGEBREAK:
409 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
410 LwpPageLayout* pLayout = dynamic_cast<LwpPageLayout*>(pPageBreak->GetLayout().obj().get());
411 if(pLayout)
413 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
414 if (pStory)
415 pStory->AddPageLayout(pLayout);
417 break;
419 default:
420 break;
422 pFrib = pFrib->GetNext();
425 /**************************************************************************
426 * @descr: Whether has a frib which type is nType
427 **************************************************************************/
428 LwpFrib* LwpFribPtr::HasFrib(sal_uInt8 nType)
430 LwpFrib* pFrib = m_pFribs;
431 while(pFrib)
433 if(pFrib->GetType()==nType)
435 return pFrib;
437 pFrib = pFrib->GetNext();
439 return nullptr;
442 void LwpFribPtr::GatherAllText()
444 LwpFrib* pFrib = m_pFribs;
445 while(pFrib)
447 switch(pFrib->GetType())
449 case FRIB_TAG_TEXT:
451 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
452 m_pPara->SetAllText(sText);
453 break;
455 case FRIB_TAG_UNICODE: //fall through
456 case FRIB_TAG_UNICODE2: //fall through
457 case FRIB_TAG_UNICODE3: //fall through :
459 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
460 m_pPara->SetAllText(sText);
461 break;
463 default :
464 break;
466 pFrib = pFrib->GetNext();
470 void LwpFribPtr::RegisterStyle()
472 LwpFrib* pFrib = m_pFribs;
473 while(pFrib)
475 switch(pFrib->GetType())
477 case FRIB_TAG_TEXT:
479 pFrib->RegisterStyle(m_pPara->GetFoundry());
480 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
481 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
482 break;
484 case FRIB_TAG_TAB:
485 pFrib->RegisterStyle(m_pPara->GetFoundry());
486 break;
487 case FRIB_TAG_SECTION:
489 //section registerstyle here;
490 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
491 pSectionFrib->RegisterSectionStyle();
492 //for bullet
493 pSectionFrib->SetSectionName();
495 break;
496 case FRIB_TAG_PAGEBREAK:
498 LwpFribPageBreak* breakFrib = static_cast<LwpFribPageBreak*>(pFrib);
499 breakFrib->RegisterBreakStyle(m_pPara);
501 break;
502 case FRIB_TAG_COLBREAK:
504 LwpFribColumnBreak* breakFrib = static_cast<LwpFribColumnBreak*>(pFrib);
505 breakFrib->RegisterBreakStyle(m_pPara);
507 break;
508 case FRIB_TAG_UNICODE: //fall through
509 case FRIB_TAG_UNICODE2: //fall through
510 case FRIB_TAG_UNICODE3: //fall through :
512 pFrib->RegisterStyle(m_pPara->GetFoundry());
513 OUString sText = static_cast<LwpFribUnicode*>(pFrib)->GetText();
514 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
515 break;
517 case FRIB_TAG_HARDSPACE:
518 pFrib->RegisterStyle(m_pPara->GetFoundry());
519 ProcessDropcap(m_pPara->GetStory(),pFrib,1);
520 break;
521 case FRIB_TAG_SOFTHYPHEN:
522 pFrib->RegisterStyle(m_pPara->GetFoundry());
523 break;
524 case FRIB_TAG_FRAME:
526 LwpFribFrame* frameFrib = static_cast<LwpFribFrame*>(pFrib);
527 frameFrib->SetParaDropcap(m_pPara);
528 frameFrib->RegisterStyle(m_pPara->GetFoundry());
529 //register framelayout style, ,03/09/2005
530 //frameFrib->GetLayout()->RegisterStyle();
532 break;
533 case FRIB_TAG_CHBLOCK:
534 break;
535 case FRIB_TAG_TABLE:
537 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
538 tableFrib->RegisterNewStyle();
540 break;
541 case FRIB_TAG_FOOTNOTE:
543 LwpFribFootnote* pFribFootnote = static_cast<LwpFribFootnote*>(pFrib);
544 pFribFootnote->RegisterNewStyle();
546 break;
547 case FRIB_TAG_NOTE:
549 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
550 pNoteFrib->RegisterNewStyle();
551 break;
553 case FRIB_TAG_PAGENUMBER:
555 pFrib->RegisterStyle(m_pPara->GetFoundry());
556 break;
558 case FRIB_TAG_DOCVAR:
560 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
561 docFrib->RegisterStyle(m_pPara->GetFoundry());
562 break;
564 case FRIB_TAG_FIELD:
566 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
567 fieldFrib->RegisterStyle(m_pPara->GetFoundry());
568 break;
570 case FRIB_TAG_BOOKMARK:
572 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
573 bookmarkFrib->RegisterStyle(m_pPara->GetFoundry());
574 break;
576 case FRIB_TAG_RUBYFRAME:
578 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
579 rubyfrmeFrib->RegisterStyle(m_pPara->GetFoundry());
580 break;
582 default :
583 break;
585 if (pFrib->GetRevisionFlag() && pFrib->GetType()!= FRIB_TAG_FIELD)
587 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
588 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
589 pChangeMgr->AddChangeFrib(pFrib);
592 pFrib = pFrib->GetNext();
596 void LwpFribPtr::ProcessDropcap(LwpStory* pStory,LwpFrib* pFrib,sal_uInt32 nLen)
598 if (pStory)
600 if (pStory->GetDropcapFlag())
602 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
603 XFTextStyle* pFribStyle = pXFStyleManager->FindTextStyle(pFrib->GetStyleName());
604 pFribStyle->GetFont()->SetFontSize(0);
606 LwpDropcapLayout* pObj = dynamic_cast<LwpDropcapLayout*>(pStory->GetLayoutsWithMe().GetOnlyLayout().obj().get());
607 if (pObj)
608 pObj->SetChars(nLen);
613 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, default return true
616 bool LwpFribPtr::ComparePagePosition(LwpVirtualLayout* pPreLayout, LwpVirtualLayout* pNextLayout)
618 if(!pPreLayout || !pNextLayout)
619 return true;
621 LwpFrib* pFrib = m_pFribs;
622 LwpVirtualLayout* pLayout = nullptr;
623 while(pFrib)
625 switch(pFrib->GetType())
627 case FRIB_TAG_SECTION:
629 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
630 LwpSection* pSection = pSectionFrib->GetSection();
631 if(pSection)
633 pLayout = pSection->GetPageLayout();
636 break;
638 case FRIB_TAG_PAGEBREAK:
640 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
641 pLayout = dynamic_cast<LwpVirtualLayout*>(pPageBreak->GetLayout().obj().get());
642 break;
644 default:
645 break;
648 if(pLayout)
650 if(pPreLayout == pLayout)
651 return true;
652 if(pNextLayout == pLayout)
653 return false;
655 pFrib = pFrib->GetNext();
658 return true;
661 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */