fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribptr.cxx
blob4f3211a61dc041d13d8c5c2aa586ac9d2b102839
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 ************************************************************************/
60 /*************************************************************************
61 * Change History
62 Jan 2005 Created
63 ************************************************************************/
65 #include "lwpfribptr.hxx"
67 #include "lwpfribheader.hxx"
68 #include "lwpfribtext.hxx"
69 #include "lwppara.hxx"
70 #include "lwpstory.hxx"
71 #include "xfilter/xftextspan.hxx"
72 #include "xfilter/xftextcontent.hxx"
73 #include "xfilter/xftabstop.hxx"
74 #include "xfilter/xflinebreak.hxx"
75 #include "lwpfribsection.hxx"
76 #include "lwpsection.hxx"
77 #include "lwpfribbreaks.hxx"
78 #include "lwpfribframe.hxx"
79 #include "lwpfribtable.hxx"
80 #include "xfilter/xfstylemanager.hxx"
81 #include "lwphyperlinkmgr.hxx"
82 #include "xfilter/xfhyperlink.hxx"
83 #include "lwpfootnote.hxx"
84 #include "lwpnotes.hxx"
85 #include "lwpfribmark.hxx"
86 #include "xfilter/xfchange.hxx"
87 #include "lwpchangemgr.hxx"
88 #include "lwpglobalmgr.hxx"
90 LwpFribPtr::LwpFribPtr()
91 : m_pFribs(NULL),m_pXFPara(NULL),m_pPara(NULL)
95 LwpFribPtr::~LwpFribPtr()
97 LwpFrib* pNextFrib = m_pFribs;
98 LwpFrib* pCurFrib = m_pFribs;
99 while(pCurFrib)
101 pNextFrib = pCurFrib -> GetNext();
102 delete pCurFrib;
103 pCurFrib = pNextFrib;
107 void LwpFribPtr::ReadPara(LwpObjectStream* pObjStrm)
109 LwpFrib* pCurFrib = m_pFribs = NULL;
110 for(;;)
112 // Get the frib type
113 sal_uInt8 FribTag = pObjStrm->QuickReaduInt8();
115 sal_uInt8 FribType = FribTag & ~FRIB_TAG_TYPEMASK;
117 // Stop when we hit Elvis
118 if (FribType == FRIB_TAG_ELVIS)
119 break;
121 // skip the editor ID
122 //pObjStrm->SeekRel(sizeof(sal_uInt8));
123 sal_uInt8 FribEditor = pObjStrm->QuickReaduInt8();
124 if( FribType != FT_MAXIMUM )
126 LwpFrib* pFrib = LwpFrib::CreateFrib( m_pPara, pObjStrm, FribTag,FribEditor);
127 if(!m_pFribs)
129 m_pFribs = pFrib;
131 if(pCurFrib)
133 pCurFrib->SetNext(pFrib);
135 else//frist frib in the para,add by 2/1
137 if (pFrib->GetType() == FRIB_TAG_TEXT)
139 LwpFribText* pText = static_cast<LwpFribText*>(pFrib);
140 if (pFrib->GetModifiers())
141 m_pPara->SetFirstFrib(pText->GetText(),pText->GetModifiers()->FontID);
142 else
143 m_pPara->SetFirstFrib(pText->GetText(),0);
146 pCurFrib = pFrib;
151 #include "lwpdropcapmgr.hxx"
152 void LwpFribPtr::XFConvert()
154 LwpFrib* pFrib = m_pFribs;
155 while(pFrib)
157 sal_uInt8 nFribType = pFrib->GetType();
158 bool bRevisionFlag = pFrib->GetRevisionFlag();
159 OUString sChangeID;
160 if (bRevisionFlag)
162 if ( nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
163 && nFribType != FRIB_TAG_FRAME)
165 //sal_uInt8 nRevisionType = pFrib->GetRevisionType();
166 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
167 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
168 sChangeID = pChangeMgr->GetChangeID(pFrib);
169 if (!sChangeID.isEmpty())
171 /// if (nRevisionType == LwpFrib::REV_INSERT)
172 /// {
173 XFChangeStart* pChangeStart = new XFChangeStart;
174 pChangeStart->SetChangeID(sChangeID);
175 m_pXFPara->Add(pChangeStart);
176 /// }
177 /// else if (nRevisionType == LwpFrib::REV_DELETE)
178 /// {
179 /// XFChange* pChange = new XFChange;
180 /// pChange->SetChangeID(sChangeID);
181 /// m_pXFPara->Add(pChange);
182 /// pFrib = pFrib->GetNext();
183 /// continue;
184 /// }
189 switch(nFribType)
191 case FRIB_TAG_TEXT:
193 LwpFribText* textFrib= static_cast<LwpFribText*>(pFrib);
194 textFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
196 break;
197 case FRIB_TAG_TAB:
199 LwpFribTab* tabFrib = static_cast<LwpFribTab*>(pFrib);
200 if (pFrib->m_ModFlag)
202 XFTextSpan *pSpan = new XFTextSpan();
203 pSpan->SetStyleName(tabFrib->GetStyleName());
204 XFTabStop *pTab = new XFTabStop();
205 pSpan->Add(pTab);
206 m_pXFPara->Add(pSpan);
208 else
210 XFTabStop *pTab = new XFTabStop();
211 m_pXFPara->Add(pTab);
214 break;
215 case FRIB_TAG_SECTION:
217 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
218 pSectionFrib->ParseSection();
220 break;
222 case FRIB_TAG_PAGEBREAK:
224 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
225 LwpPageLayout* pLayout = dynamic_cast<LwpPageLayout*>(pPageBreak->GetLayout().obj().get());
226 if(pLayout)
228 pPageBreak->ParseLayout();
230 else
232 if (pPageBreak->IsLastFrib())
234 m_pXFPara->SetStyleName( pPageBreak->GetStyleName() );
236 else
238 //parse pagebreak
239 XFParagraph *pPara = new XFParagraph();
240 pPara->SetStyleName(pFrib->GetStyleName());
241 SetXFPara(pPara);
242 m_pPara->AddXFContent(pPara);
246 break;
247 case FRIB_TAG_COLBREAK:
249 XFParagraph *pPara = new XFParagraph();
250 pPara->SetStyleName(pFrib->GetStyleName());
251 SetXFPara(pPara);
252 m_pPara->AddXFContent(pPara);
254 break;
255 case FRIB_TAG_LINEBREAK:
257 XFLineBreak *pLineBreak = new XFLineBreak();
258 m_pXFPara->Add(pLineBreak);
260 break;
261 case FRIB_TAG_UNICODE: //fall through
262 case FRIB_TAG_UNICODE2: //fall through
263 case FRIB_TAG_UNICODE3: //fall through
265 LwpFribUnicode* unicodeFrib= static_cast<LwpFribUnicode*>(pFrib);
266 unicodeFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
268 break;
269 case FRIB_TAG_HARDSPACE:
271 OUString sHardSpace(sal_Unicode(0x00a0));
272 LwpHyperlinkMgr* pHyperlink =
273 m_pPara->GetStory()->GetHyperlinkMgr();
274 if (pHyperlink->GetHyperlinkFlag())
275 pFrib->ConvertHyperLink(m_pXFPara,pHyperlink,sHardSpace);
276 else
277 pFrib->ConvertChars(m_pXFPara,sHardSpace);
279 break;
280 case FRIB_TAG_SOFTHYPHEN:
282 OUString sSoftHyphen(sal_Unicode(0x00ad));
283 pFrib->ConvertChars(m_pXFPara,sSoftHyphen);
285 break;
286 case FRIB_TAG_FRAME:
288 LwpFribFrame* frameFrib= static_cast<LwpFribFrame*>(pFrib);
289 rtl::Reference<LwpObject> pLayout = frameFrib->GetLayout();
290 if (pLayout.is() && pLayout->GetTag() == VO_DROPCAPLAYOUT)
291 m_pPara->GetFoundry()->GetDropcapMgr()->SetXFPara(m_pXFPara);
292 frameFrib->XFConvert(m_pXFPara);
294 break;
295 case FRIB_TAG_CHBLOCK:
297 LwpFribCHBlock* chbFrib = static_cast<LwpFribCHBlock*>(pFrib);
298 chbFrib->XFConvert(m_pXFPara,m_pPara->GetStory());
300 break;
301 case FRIB_TAG_TABLE:
303 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
304 //tableFrib->XFConvert(m_pPara->GetXFContainer());
305 tableFrib->XFConvert(m_pXFPara);
307 break;
308 case FRIB_TAG_BOOKMARK:
310 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
311 bookmarkFrib->XFConvert(m_pXFPara);
313 break;
314 case FRIB_TAG_FOOTNOTE:
316 LwpFribFootnote* pFootnoteFrib = static_cast<LwpFribFootnote*>(pFrib);
317 pFootnoteFrib->XFConvert(m_pXFPara);
318 break;
320 case FRIB_TAG_FIELD:
322 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
323 fieldFrib->XFConvert(m_pXFPara);
324 break;
326 case FRIB_TAG_NOTE:
328 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
329 pNoteFrib->XFConvert(m_pXFPara);
330 break;
332 case FRIB_TAG_PAGENUMBER:
334 LwpFribPageNumber* pagenumFrib = static_cast<LwpFribPageNumber*>(pFrib);
335 pagenumFrib->XFConvert(m_pXFPara);
336 break;
338 case FRIB_TAG_DOCVAR:
340 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
341 docFrib->XFConvert(m_pXFPara);
342 break;
344 case FRIB_TAG_RUBYMARKER:
346 LwpFribRubyMarker* rubyFrib = static_cast<LwpFribRubyMarker*>(pFrib);
347 rubyFrib->XFConvert(m_pXFPara);
348 break;
350 case FRIB_TAG_RUBYFRAME:
352 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
353 rubyfrmeFrib->XFConvert(m_pXFPara);
354 break;
356 default :
357 break;
360 if (bRevisionFlag )//&& pFrib->GetRevisionType() == LwpFrib::REV_INSERT)
362 if (nFribType!= FRIB_TAG_TABLE && nFribType != FRIB_TAG_FIELD
363 && nFribType != FRIB_TAG_FRAME)
365 if (!sChangeID.isEmpty())
367 XFChangeEnd* pChangeEnd = new XFChangeEnd;
368 pChangeEnd->SetChangeID(sChangeID);
369 m_pXFPara->Add(pChangeEnd);
373 pFrib = pFrib->GetNext();
378 void LwpFribPtr::FindLayouts()
380 LwpFrib* pFrib = m_pFribs;
381 while(pFrib)
383 switch(pFrib->GetType())
385 case FRIB_TAG_SECTION:
387 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
388 LwpSection* pSection = pSectionFrib->GetSection();
389 if(pSection)
391 LwpPageLayout* pLayout = pSection->GetPageLayout();
392 if(pLayout)
394 LwpLayout::UseWhenType eSectionType = pLayout->GetUseWhenType();
395 if(eSectionType==LwpLayout::StartWithinColume)
397 //StartWithinColume type not support now
398 break;
400 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
401 if (pStory)
402 pStory->AddPageLayout(pSection->GetPageLayout());
406 break;
408 case FRIB_TAG_PAGEBREAK:
410 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
411 LwpPageLayout* pLayout = dynamic_cast<LwpPageLayout*>(pPageBreak->GetLayout().obj().get());
412 if(pLayout)
414 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
415 if (pStory)
416 pStory->AddPageLayout(pLayout);
418 break;
420 default:
421 break;
423 pFrib = pFrib->GetNext();
426 /**************************************************************************
427 * @descr: Whether has a frib which type is nType
428 * @param:
429 * @param:
430 * @return:
431 **************************************************************************/
432 LwpFrib* LwpFribPtr::HasFrib(sal_uInt8 nType)
434 LwpFrib* pFrib = m_pFribs;
435 while(pFrib)
437 if(pFrib->GetType()==nType)
439 return pFrib;
441 pFrib = pFrib->GetNext();
443 return NULL;
446 void LwpFribPtr::GatherAllText()
448 LwpFrib* pFrib = m_pFribs;
449 while(pFrib)
451 switch(pFrib->GetType())
453 case FRIB_TAG_TEXT:
455 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
456 m_pPara->SetAllText(sText);
457 break;
459 case FRIB_TAG_UNICODE: //fall through
460 case FRIB_TAG_UNICODE2: //fall through
461 case FRIB_TAG_UNICODE3: //fall through :
463 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
464 m_pPara->SetAllText(sText);
465 break;
467 default :
468 break;
470 pFrib = pFrib->GetNext();
474 void LwpFribPtr::RegisterStyle()
476 LwpFrib* pFrib = m_pFribs;
477 while(pFrib)
479 switch(pFrib->GetType())
481 case FRIB_TAG_TEXT:
483 pFrib->RegisterStyle(m_pPara->GetFoundry());
484 OUString sText = static_cast<LwpFribText*>(pFrib)->GetText();
485 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
486 break;
488 case FRIB_TAG_TAB:
489 pFrib->RegisterStyle(m_pPara->GetFoundry());
490 break;
491 case FRIB_TAG_SECTION:
493 //section registerstyle here;
494 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
495 pSectionFrib->RegisterSectionStyle();
496 //for bullet
497 pSectionFrib->SetSectionName();
499 break;
500 case FRIB_TAG_PAGEBREAK:
502 LwpFribPageBreak* breakFrib = static_cast<LwpFribPageBreak*>(pFrib);
503 breakFrib->RegisterBreakStyle(m_pPara);
505 break;
506 case FRIB_TAG_COLBREAK:
508 LwpFribColumnBreak* breakFrib = static_cast<LwpFribColumnBreak*>(pFrib);
509 breakFrib->RegisterBreakStyle(m_pPara);
511 break;
512 case FRIB_TAG_UNICODE: //fall through
513 case FRIB_TAG_UNICODE2: //fall through
514 case FRIB_TAG_UNICODE3: //fall through :
516 pFrib->RegisterStyle(m_pPara->GetFoundry());
517 OUString sText = static_cast<LwpFribUnicode*>(pFrib)->GetText();
518 ProcessDropcap(m_pPara->GetStory(), pFrib,sText.getLength());
519 break;
521 case FRIB_TAG_HARDSPACE:
522 pFrib->RegisterStyle(m_pPara->GetFoundry());
523 ProcessDropcap(m_pPara->GetStory(),pFrib,1);
524 break;
525 case FRIB_TAG_SOFTHYPHEN:
526 pFrib->RegisterStyle(m_pPara->GetFoundry());
527 break;
528 case FRIB_TAG_FRAME:
530 LwpFribFrame* frameFrib = static_cast<LwpFribFrame*>(pFrib);
531 frameFrib->SetParaDropcap(m_pPara);
532 frameFrib->RegisterStyle(m_pPara->GetFoundry());
533 //register framelayout style, ,03/09/2005
534 //frameFrib->GetLayout()->RegisterStyle();
536 break;
537 case FRIB_TAG_CHBLOCK:
538 break;
539 case FRIB_TAG_TABLE:
541 LwpFribTable* tableFrib = static_cast<LwpFribTable*>(pFrib);
542 tableFrib->RegisterNewStyle();
544 break;
545 case FRIB_TAG_FOOTNOTE:
547 LwpFribFootnote* pFribFootnote = static_cast<LwpFribFootnote*>(pFrib);
548 pFribFootnote->RegisterNewStyle();
550 break;
551 case FRIB_TAG_NOTE:
553 LwpFribNote* pNoteFrib = static_cast<LwpFribNote*>(pFrib);
554 pNoteFrib->RegisterNewStyle();
555 break;
557 case FRIB_TAG_PAGENUMBER:
559 pFrib->RegisterStyle(m_pPara->GetFoundry());
560 break;
562 case FRIB_TAG_DOCVAR:
564 LwpFribDocVar* docFrib = static_cast<LwpFribDocVar*>(pFrib);
565 docFrib->RegisterStyle(m_pPara->GetFoundry());
566 break;
568 case FRIB_TAG_FIELD:
570 LwpFribField* fieldFrib = static_cast<LwpFribField*>(pFrib);
571 fieldFrib->RegisterStyle(m_pPara->GetFoundry());
572 break;
574 case FRIB_TAG_BOOKMARK:
576 LwpFribBookMark* bookmarkFrib = static_cast<LwpFribBookMark*>(pFrib);
577 bookmarkFrib->RegisterStyle(m_pPara->GetFoundry());
578 break;
580 case FRIB_TAG_RUBYFRAME:
582 LwpFribRubyFrame* rubyfrmeFrib = static_cast<LwpFribRubyFrame*>(pFrib);
583 rubyfrmeFrib->RegisterStyle(m_pPara->GetFoundry());
584 break;
586 default :
587 break;
589 if (pFrib->GetRevisionFlag() && pFrib->GetType()!= FRIB_TAG_FIELD)
591 LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
592 LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
593 pChangeMgr->AddChangeFrib(pFrib);
596 pFrib = pFrib->GetNext();
600 void LwpFribPtr::ProcessDropcap(LwpStory* pStory,LwpFrib* pFrib,sal_uInt32 nLen)
602 if (pStory)
604 if (pStory->GetDropcapFlag())
606 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
607 XFTextStyle* pFribStyle = pXFStyleManager->FindTextStyle(pFrib->GetStyleName());
608 pFribStyle->GetFont()->SetFontSize(0);
610 LwpDropcapLayout* pObj = dynamic_cast<LwpDropcapLayout*>(pStory->GetLayoutsWithMe().GetOnlyLayout().obj().get());
611 if (pObj)
612 pObj->SetChars(nLen);
617 * @descr: If the position of pPreLayout is earlier than pNextLayout, return true, or return false, defalut return true
620 bool LwpFribPtr::ComparePagePosition(LwpVirtualLayout* pPreLayout, LwpVirtualLayout* pNextLayout)
622 if(!pPreLayout || !pNextLayout)
623 return true;
625 LwpFrib* pFrib = m_pFribs;
626 LwpVirtualLayout* pLayout = NULL;
627 while(pFrib)
629 switch(pFrib->GetType())
631 case FRIB_TAG_SECTION:
633 LwpFribSection* pSectionFrib = static_cast<LwpFribSection*>(pFrib);
634 LwpSection* pSection = pSectionFrib->GetSection();
635 if(pSection)
637 pLayout = pSection->GetPageLayout();
640 break;
642 case FRIB_TAG_PAGEBREAK:
644 LwpFribPageBreak* pPageBreak = static_cast<LwpFribPageBreak*>(pFrib);
645 pLayout = dynamic_cast<LwpVirtualLayout*>(pPageBreak->GetLayout().obj().get());
646 break;
648 default:
649 break;
652 if(pLayout)
654 if(pPreLayout == pLayout)
655 return true;
656 if(pNextLayout == pLayout)
657 return false;
659 pFrib = pFrib->GetNext();
662 return true;
665 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */