update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwppara1.cxx
blob115afc6e1330839166189996d0f3ca389a6ff709
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 "lwppara.hxx"
65 #include "lwpglobalmgr.hxx"
66 #include "lwpfilehdr.hxx"
67 #include "lwpparaproperty.hxx"
68 #include "lwptools.hxx"
69 #include "lwpparastyle.hxx"
70 #include "xfilter/xffont.hxx"
71 #include "xfilter/xftextstyle.hxx"
72 #include "xfilter/xfstylemanager.hxx"
73 #include "xfilter/xfparagraph.hxx"
74 #include "xfilter/xftextcontent.hxx"
75 #include "xfilter/xftextspan.hxx"
76 #include "xfilter/xfmargins.hxx"
77 #include "xfilter/xftabstop.hxx"
78 #include "xfilter/xflinebreak.hxx"
79 #include "xfilter/xfsection.hxx"
80 #include "xfilter/xfsectionstyle.hxx"
81 #include "xfilter/xfcolor.hxx"
82 #include "xfilter/xfhyperlink.hxx"
83 #include "lwpcharsetmgr.hxx"
84 #include "lwpsection.hxx"
85 #include "lwplayout.hxx"
86 #include "lwpusewhen.hxx"
88 #include "lwpbulletstylemgr.hxx"
89 #include "lwpstory.hxx"
90 #include "lwpsilverbullet.hxx"
91 #include "xfilter/xflist.hxx"
92 #include "xfilter/xfframe.hxx"
94 #include "lwpdivinfo.hxx"
95 #include "lwpdoc.hxx"
96 #include "lwpholder.hxx"
97 #include "lwppagehint.hxx"
99 #include "lwpdropcapmgr.hxx"
100 #include "lwptable.hxx"
101 #include "lwpcelllayout.hxx"
103 * @short get text of paragraph
105 OUString LwpPara::GetContentText(sal_Bool bAllText)
107 // rFont = m_FontID;
108 if (bAllText)
110 m_Fribs.SetPara(this);
111 m_Fribs.GatherAllText();
112 return m_AllText;
114 else
115 return m_Content;
119 * @short set text of paragraph
121 void LwpPara::SetAllText(OUString sText)
123 m_AllText+=sText;
127 * @short set first frib content
129 void LwpPara::SetFirstFrib(rtl::OUString Content,sal_uInt32 FontID)
131 m_FontID= FontID;
132 m_Content=Content;
135 * @short get paragraph xfstyle
137 XFParaStyle* LwpPara::GetXFParaStyle()
139 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
140 return pXFStyleManager->FindParaStyle(m_StyleName);
143 * @short get drop cap info
145 #include "lwpframelayout.hxx"
146 void LwpPara::GatherDropcapInfo()
148 SetDropcapLines(m_pDropcapLayout->GetLines());
149 SetDropcapChars(m_pDropcapLayout->GetChars());
152 * @short get parent paragraph
154 LwpPara* LwpPara::GetParent()
156 LwpPara* pPara;
157 sal_uInt16 otherlevel;
158 sal_uInt16 level = GetLevel();
160 if (level != 1)
162 pPara = static_cast<LwpPara*>(GetPrevious()->obj());
163 while (pPara)
165 otherlevel = pPara->GetLevel();
166 if ((otherlevel < level) || (otherlevel && (level == 0)))
167 return pPara;
168 pPara = static_cast<LwpPara*>(pPara->GetPrevious()->obj());
171 return NULL;
175 * @short: Offer prefix, paranumber and suffix according to position.
176 * @param: nPosition index of wanted paranumbering in the style-list.
177 * @param: pParaNumbering a pointer to the structure which contains prefix, paranumber and
178 * suffix.
180 void LwpPara::GetParaNumber(sal_uInt16 nPosition, ParaNumbering* pParaNumbering)
182 if (nPosition > 9)
184 return;
186 sal_uInt16 nCurrentPos = 0;
188 LwpFrib* pPreFrib = NULL;
189 LwpFrib* pFrib = m_Fribs.GetFribs();
190 if (!pFrib)
192 return;
195 while (pFrib)
197 sal_uInt8 nFribType = pFrib->GetType();
198 if (nFribType == FRIB_TAG_PARANUMBER)
200 nCurrentPos++;
201 ModifierInfo* pModInfo = pFrib->GetModifiers();
202 if (pModInfo)
204 sal_uInt16 nHideLevels = pModInfo->aTxtAttrOverride.GetHideLevels();
205 if (nCurrentPos == nPosition)
207 //get prefix text frib
208 if (pPreFrib)
210 if ((pPreFrib->GetType() == FRIB_TAG_TEXT) &&
211 (pPreFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels))
213 pParaNumbering->pPrefix = static_cast<LwpFribText*>(pPreFrib);
217 //get para numbering
218 pParaNumbering->pParaNumber = static_cast<LwpFribParaNumber*>(pFrib);
219 pParaNumbering->nNumLevel = nHideLevels;
221 //get suffix text frib
222 if (pFrib = pFrib->GetNext())
224 // if((pFrib->GetType() == FRIB_TAG_TEXT) &&
225 // (pFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels))
226 if( pFrib->GetType() == FRIB_TAG_TEXT )
228 if ((pFrib->GetNext()->GetType() == FRIB_TAG_TEXT ) ||
229 (pFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels))
231 pParaNumbering->pSuffix = static_cast<LwpFribText*>(pFrib);
236 break;
239 else
241 if (nCurrentPos == nPosition)
243 //get prefix text frib
244 if (pPreFrib)
246 if (pPreFrib->GetType() == FRIB_TAG_TEXT)
248 pParaNumbering->pPrefix = static_cast<LwpFribText*>(pPreFrib);
252 //get para numbering
253 pParaNumbering->pParaNumber = static_cast<LwpFribParaNumber*>(pFrib);
255 //get suffix text frib
256 if (pFrib = pFrib->GetNext())
258 if (pFrib->GetType() == FRIB_TAG_TEXT)
260 pParaNumbering->pSuffix = static_cast<LwpFribText*>(pFrib);
267 pPreFrib = pFrib;
268 if (pFrib)
270 pFrib = pFrib->GetNext();
275 * @short override alignment
277 //override style, add by 1-24
278 void LwpPara::OverrideAlignment(LwpAlignmentOverride* base,LwpAlignmentOverride* over,XFParaStyle* pOverStyle)
280 if (base)//the latter two parameter never be null
282 over->Override(base);
283 LwpParaStyle::ApplyAlignment(pOverStyle,base);
285 else
286 LwpParaStyle::ApplyAlignment(pOverStyle,over);
289 * @short override indent attribute
291 void LwpPara::OverrideIndent(LwpIndentOverride* base,LwpIndentOverride* over,XFParaStyle* pOverStyle)
293 if (base)//the latter two parameter never be null
295 over->Override(base);
296 LwpParaStyle::ApplyIndent(this,pOverStyle,base);
298 else
300 LwpParaStyle::ApplyIndent(this,pOverStyle,over);
304 * @short override spacing
306 void LwpPara::OverrideSpacing(LwpSpacingOverride* base,LwpSpacingOverride* over,XFParaStyle* pOverStyle)
308 if (base)//the latter two parameter never be null
310 over->Override(base);
311 LwpParaStyle::ApplySpacing(this,pOverStyle,base);
313 else
314 LwpParaStyle::ApplySpacing(this,pOverStyle,over);
317 //add by , 01/25/2005
319 * @short: Get parastyle object according to the objID.
320 * @return: pointer to the parastyle.
322 LwpParaStyle* LwpPara::GetParaStyle()
324 return static_cast<LwpParaStyle*>(m_ParaStyle.obj(VO_PARASTYLE));
328 * @short: Override paraborder style.
329 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
330 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
332 void LwpPara::OverrideParaBorder(LwpParaProperty* pProps, XFParaStyle* pOverStyle)
334 // get paraborder in parastyle
335 LwpParaStyle* pParaStyle = this->GetParaStyle();
336 if (!pParaStyle)
338 return;
341 LwpOverride* pBorder = pParaStyle->GetParaBorder();
342 LwpParaBorderOverride aFinalBorder;
343 if (pBorder)
345 aFinalBorder = *pBorder;
348 // get local border
349 pBorder = static_cast<LwpParaBorderProperty*>(pProps)->GetLocalParaBorder();
350 if (pBorder)
352 LwpParaBorderOverride aLocalBorder;
353 aLocalBorder = *pBorder;
354 aLocalBorder.Override(&aFinalBorder);
357 pParaStyle->ApplyParaBorder(pOverStyle, &aFinalBorder);
360 * @short: Override parabreaks style.
361 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
362 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
364 void LwpPara::OverrideParaBreaks(LwpParaProperty* pProps, XFParaStyle* pOverStyle)
366 // get breaks in parastyle
367 LwpParaStyle* pParaStyle = this->GetParaStyle();
368 if (!pParaStyle)
370 return;
373 LwpOverride* pBreaks = pParaStyle->GetBreaks();
374 LwpBreaksOverride* pFinalBreaks = new LwpBreaksOverride();
375 if (pBreaks)
377 *pFinalBreaks = *pBreaks;
380 // get local breaks
381 pBreaks = static_cast<LwpParaBreaksProperty*>(pProps)->GetLocalParaBreaks();
382 if (pBreaks)
384 LwpBreaksOverride aLocalBreaks;
385 aLocalBreaks = *pBreaks;
386 aLocalBreaks.Override(pFinalBreaks);
389 // save the breaks
390 m_pBreaks = pFinalBreaks;
392 //add by 1/31
393 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
394 if (m_pBreaks->IsKeepWithNext())
396 pOverStyle->SetBreaks(enumXFBreakKeepWithNext);
398 if (m_pBreaks->IsPageBreakBefore())
400 XFParaStyle* pStyle = new XFParaStyle();
401 pStyle->SetBreaks(enumXFBreakAftPage);
402 m_BefPageBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
404 if (m_pBreaks->IsPageBreakAfter())
406 XFParaStyle* pStyle = new XFParaStyle();
407 pStyle->SetBreaks(enumXFBreakAftPage);
408 m_AftPageBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
410 if (m_pBreaks->IsColumnBreakBefore())
412 XFParaStyle* pStyle = new XFParaStyle();
413 pStyle->SetBreaks(enumXFBreakAftColumn);//tmp after, should change when layout read,note by 1/31
414 m_BefColumnBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
416 if (m_pBreaks->IsColumnBreakAfter())
418 XFParaStyle* pStyle = new XFParaStyle();
419 pStyle->SetBreaks(enumXFBreakAftColumn);
420 m_AftColumnBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
422 //add end
424 // pParaStyle->ApplyBreaks(pOverStyle, &aFinalBreaks);
428 * @short: Override bullet styles.
429 * @param: pProps pointer to the LwpParaProperty and we can get local bullet through it.
431 void LwpPara::OverrideParaBullet(LwpParaProperty* pProps)
433 // get bulletoverride in parastyle
434 LwpParaStyle* pParaStyle = this->GetParaStyle();
435 if (!pParaStyle)
437 return;
440 if (pProps)
442 m_pBullOver = new LwpBulletOverride();
443 // get local bulletoverride
444 LwpBulletOverride* pLocalBullet = static_cast<LwpParaBulletProperty*>(pProps)->GetLocalParaBullet();
445 if (!pLocalBullet)
447 return;
450 LwpObjectID aSilverBulletID = pLocalBullet->GetSilverBullet();
451 if (aSilverBulletID.IsNull())
453 return;
455 else
457 m_bHasBullet = sal_True;
459 LwpOverride* pBullet= pParaStyle->GetBulletOverride();
460 LwpBulletOverride aFinalBullet;
461 if (pBullet)
463 aFinalBullet = *pBullet;
466 LwpBulletOverride aLocalBullet;
467 aLocalBullet = *pLocalBullet;
468 aLocalBullet.Override(&aFinalBullet);
470 *m_pBullOver = aFinalBullet;
471 aSilverBulletID = aFinalBullet.GetSilverBullet();
472 if (!aSilverBulletID.IsNull())
474 m_pSilverBullet = static_cast<LwpSilverBullet*>(aSilverBulletID.obj(VO_SILVERBULLET));
475 m_pSilverBullet->SetFoundry(m_pFoundry);
478 m_aSilverBulletID = aSilverBulletID;
481 else
483 // m_pBullOver = pParaStyle->GetBulletOverride();
484 LwpBulletOverride* pBullOver = pParaStyle->GetBulletOverride();
485 if (pBullOver)
487 m_aSilverBulletID = pBullOver->GetSilverBullet();
488 if (!m_aSilverBulletID.IsNull())
490 m_bHasBullet = sal_True;
492 m_pSilverBullet = static_cast<LwpSilverBullet*>(m_aSilverBulletID.obj(VO_SILVERBULLET));
493 m_pSilverBullet->SetFoundry(m_pFoundry);
496 m_pBullOver = new LwpBulletOverride();
497 *m_pBullOver = *pBullOver;
502 * @short: Override paranumbering properties.
503 * @param: pProps pointer to the LwpParaProperty and we can get local paranumbering through it.
505 void LwpPara::OverrideParaNumbering(LwpParaProperty* pProps)
507 // get numbering override in parastyle
508 LwpParaStyle* pParaStyle = this->GetParaStyle();
509 if (!pParaStyle)
511 return;
514 LwpNumberingOverride* pParaNumbering = pParaStyle->GetNumberingOverride();
515 LwpNumberingOverride aOver;
516 //Override with the local numbering, if any
517 if (pProps)
519 LwpNumberingOverride* pPropNumbering = static_cast<LwpParaNumberingProperty*>(pProps)->GetLocalNumbering();
520 if (pPropNumbering)
522 aOver = *pPropNumbering;
525 else
527 if (pParaNumbering)
529 aOver = *pParaNumbering;
533 if (m_nFlags & VALID_LEVEL)
535 aOver.OverrideLevel(m_nLevel);
538 m_aParaNumbering = aOver;
542 /**************************************************************************
543 * @short:
544 * @descr:
545 * @param:
546 * @param:
547 * @return:
548 **************************************************************************/
549 void LwpPara::OverrideTab(LwpTabOverride *base, LwpTabOverride *over, XFParaStyle *pOverStyle)
551 if (base)
553 over->Override(base);
554 LwpParaStyle::ApplyTab(pOverStyle,base);
556 else
557 LwpParaStyle::ApplyTab(pOverStyle,over);
560 void LwpPara::FindLayouts()
562 m_Fribs.SetPara(this);
563 m_Fribs.FindLayouts();
564 LwpPara* pNextPara = static_cast<LwpPara*>(GetNext()->obj());
565 if(pNextPara)
567 pNextPara->FindLayouts();
571 /**************************************************************************
572 * @descr: Get property according to the property type
573 * @param:
574 * @param:
575 * @return:
576 **************************************************************************/
577 LwpParaProperty* LwpPara::GetProperty(sal_uInt32 nPropType)
579 LwpParaProperty* pProps = m_pProps;
580 while(pProps)
582 if(pProps->GetType() == nPropType)
584 return pProps;
586 pProps = pProps->GetNext();
589 return NULL;
592 /**************************************************************************
593 * @descr: Get local tab rack
594 * @param:
595 * @param:
596 * @return:
597 **************************************************************************/
598 LwpTabOverride* LwpPara::GetLocalTabOverride()
600 LwpParaProperty* pProp = GetProperty(PP_LOCAL_TABRACK);
601 if(pProp)
603 return static_cast<LwpParaTabRackProperty*>(pProp)->GetTab();
605 return NULL;
609 * @descr: Determined which para is earlier in position
612 sal_Bool LwpPara::operator< (LwpPara& Other)
614 return m_nOrdinal < Other.GetOrdinal();
618 * @descr: If the two layouts in the same para, compare which layout is earlied according to frib order
621 sal_Bool LwpPara::ComparePagePosition(LwpVirtualLayout * pPreLayout, LwpVirtualLayout * pNextLayout)
623 m_Fribs.SetPara(this);
624 return m_Fribs.ComparePagePosition(pPreLayout, pNextLayout);
627 sal_Bool LwpPara::IsNeedTabForTOC()
629 LwpStory* pStory = GetStory();
630 if(pStory)
632 if(GetNext()->IsNull())
634 LwpVirtualLayout* pLayout = pStory->GetLayout(NULL);
635 if(pLayout && pLayout->IsCell())
637 LwpCellLayout * pCell = static_cast<LwpCellLayout *>(pStory->GetLayout(NULL));
638 if (pCell->GetLeaderChar() == 0)
640 return sal_False;
642 return sal_True;
646 return sal_False;
649 void LwpPara::AddTabStyleForTOC( )
651 if(IsNeedTabForTOC())
653 XFParaStyle* pParaStyle = new XFParaStyle;
654 *pParaStyle = *GetXFParaStyle();
655 pParaStyle->ClearTabStyles();
656 //Add Tab Style;
657 enumXFTab eType = enumXFTabRight;
659 LwpCellLayout * pCell = static_cast<LwpCellLayout *>(GetStory()->GetLayout(NULL));
660 double dLen = pCell->GetActualWidth(); /// todo: get from table
661 sal_Unicode cLeader = static_cast<sal_Unicode>(pCell->GetLeaderChar());
662 pParaStyle->AddTabStyle(eType, dLen, cLeader );
663 m_StyleName = XFStyleManager::AddStyle(pParaStyle)->GetStyleName();
665 // Get font info of default text style and set into tab style
666 XFParaStyle* pBaseStyle = static_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*m_pFoundry->GetDefaultTextStyle()));
667 XFTextStyle*pTextStyle = new XFTextStyle;
668 pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
669 m_TabStyleName = XFStyleManager::AddStyle(pTextStyle)->GetStyleName();
673 void LwpPara::AddTabStopForTOC()
675 if(IsNeedTabForTOC())
677 XFParagraph* pXFPara = GetFribs()->GetXFPara();
678 pXFPara->SetStyleName(m_StyleName);
680 XFParaStyle* pParaStyle = static_cast<XFParaStyle*>(XFStyleManager::FindStyle(m_StyleName));
681 if(pParaStyle)
683 XFTextSpan *pSpan = new XFTextSpan;
684 XFTabStop *pTab = new XFTabStop;
685 pSpan->Add(pTab);
686 pSpan->SetStyleName(m_TabStyleName);
687 enumXFAlignType eType = pParaStyle->GetAlighType();
689 if(eType == enumXFAlignStart || eType == enumXFAlignJustify || eType == enumXFAlignNone)
691 pXFPara->Add(pSpan);
693 else if(eType == enumXFAlignEnd)
695 pXFPara->InsertAtBegin(pSpan);
697 else
699 delete pSpan; // pTabl will be delete inside XFTextSpan
708 * @short check paragraph alignment
710 sal_Bool LwpPara::IsNumberRight()
712 LwpObject* pObj = m_ParaStyle.obj();
713 if (pObj)
715 LwpParaStyle* pStyle = static_cast<LwpParaStyle*>(pObj);
716 return pStyle->IsNumberRight();
718 else
719 return sal_False;
722 * @short check paragraph in cell or not
724 sal_Bool LwpPara::IsInCell()
726 LwpVirtualLayout* pLayout = GetStory()->GetLayout(NULL);
727 if(pLayout && pLayout->IsCell())
728 return sal_True;
729 return sal_False;