bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwppara1.cxx
blob06690f8e43f8eb18642ba9cefa694204d036de10
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 <memory>
67 #include <boost/cast.hpp>
69 #include "lwppara.hxx"
70 #include "lwpglobalmgr.hxx"
71 #include "lwpfilehdr.hxx"
72 #include "lwpparaproperty.hxx"
73 #include "lwptools.hxx"
74 #include "lwpparastyle.hxx"
75 #include "xfilter/xffont.hxx"
76 #include "xfilter/xftextstyle.hxx"
77 #include "xfilter/xfstylemanager.hxx"
78 #include "xfilter/xfparagraph.hxx"
79 #include "xfilter/xftextcontent.hxx"
80 #include "xfilter/xftextspan.hxx"
81 #include "xfilter/xfmargins.hxx"
82 #include "xfilter/xftabstop.hxx"
83 #include "xfilter/xflinebreak.hxx"
84 #include "xfilter/xfsection.hxx"
85 #include "xfilter/xfsectionstyle.hxx"
86 #include "xfilter/xfcolor.hxx"
87 #include "xfilter/xfhyperlink.hxx"
88 #include "lwpcharsetmgr.hxx"
89 #include "lwpsection.hxx"
90 #include "lwplayout.hxx"
91 #include "lwpusewhen.hxx"
93 #include "lwpbulletstylemgr.hxx"
94 #include "lwpstory.hxx"
95 #include "lwpsilverbullet.hxx"
96 #include "xfilter/xflist.hxx"
97 #include "xfilter/xfframe.hxx"
99 #include "lwpdivinfo.hxx"
100 #include "lwpdoc.hxx"
101 #include "lwpholder.hxx"
102 #include "lwppagehint.hxx"
104 #include "lwpdropcapmgr.hxx"
105 #include "lwptable.hxx"
106 #include "lwpcelllayout.hxx"
108 // boost::polymorphic_downcast checks and reports (using assert), if the
109 // cast is incorrect. We want this in debug builds.
110 #if OSL_DEBUG_LEVEL > 0
111 # undef NDEBUG
112 #elif !defined(NDEBUG)
113 # define NDEBUG 1
114 #endif
116 using boost::polymorphic_downcast;
119 * @short get text of paragraph
121 OUString LwpPara::GetContentText(sal_Bool bAllText)
123 // rFont = m_FontID;
124 if (bAllText)
126 m_Fribs.SetPara(this);
127 m_Fribs.GatherAllText();
128 return m_AllText;
130 else
131 return m_Content;
135 * @short set text of paragraph
137 void LwpPara::SetAllText(OUString sText)
139 m_AllText+=sText;
143 * @short set first frib content
145 void LwpPara::SetFirstFrib(OUString Content,sal_uInt32 FontID)
147 m_FontID= FontID;
148 m_Content=Content;
151 * @short get paragraph xfstyle
153 XFParaStyle* LwpPara::GetXFParaStyle()
155 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
156 return pXFStyleManager->FindParaStyle(m_StyleName);
159 * @short get drop cap info
161 #include "lwpframelayout.hxx"
162 void LwpPara::GatherDropcapInfo()
164 SetDropcapLines(m_pDropcapLayout->GetLines());
165 SetDropcapChars(m_pDropcapLayout->GetChars());
168 * @short get parent paragraph
170 LwpPara* LwpPara::GetParent()
172 LwpPara* pPara;
173 sal_uInt16 otherlevel;
174 sal_uInt16 level = GetLevel();
176 if (level != 1)
178 pPara = dynamic_cast<LwpPara*>(GetPrevious()->obj());
179 while (pPara)
181 otherlevel = pPara->GetLevel();
182 if ((otherlevel < level) || (otherlevel && (level == 0)))
183 return pPara;
184 pPara = dynamic_cast<LwpPara*>(pPara->GetPrevious()->obj());
187 return NULL;
191 * @short: Offer prefix, paranumber and suffix according to position.
192 * @param: nPosition index of wanted paranumbering in the style-list.
193 * @param: pParaNumbering a pointer to the structure which contains prefix, paranumber and
194 * suffix.
196 void LwpPara::GetParaNumber(sal_uInt16 nPosition, ParaNumbering* pParaNumbering)
198 if (nPosition > 9)
200 return;
202 sal_uInt16 nCurrentPos = 0;
204 LwpFrib* pPreFrib = NULL;
205 LwpFrib* pFrib = m_Fribs.GetFribs();
206 if (!pFrib)
208 return;
211 while (pFrib)
213 sal_uInt8 nFribType = pFrib->GetType();
214 if (nFribType == FRIB_TAG_PARANUMBER)
216 nCurrentPos++;
217 ModifierInfo* pModInfo = pFrib->GetModifiers();
218 if (pModInfo)
220 sal_uInt16 nHideLevels = pModInfo->aTxtAttrOverride.GetHideLevels();
221 if (nCurrentPos == nPosition)
223 //get prefix text frib
224 if (pPreFrib)
226 if ((pPreFrib->GetType() == FRIB_TAG_TEXT) &&
227 (pPreFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels))
229 pParaNumbering->pPrefix = static_cast<LwpFribText*>(pPreFrib);
233 //get para numbering
234 pParaNumbering->pParaNumber = static_cast<LwpFribParaNumber*>(pFrib);
235 pParaNumbering->nNumLevel = nHideLevels;
237 //get suffix text frib
238 if ( (pFrib = pFrib->GetNext()) )
240 if( pFrib->GetType() == FRIB_TAG_TEXT )
242 if (
243 (pFrib->GetNext() && pFrib->GetNext()->GetType() == FRIB_TAG_TEXT) ||
244 (pFrib->GetModifiers()->aTxtAttrOverride.GetHideLevels() == nHideLevels)
247 pParaNumbering->pSuffix = static_cast<LwpFribText*>(pFrib);
252 break;
255 else
257 if (nCurrentPos == nPosition)
259 //get prefix text frib
260 if (pPreFrib)
262 if (pPreFrib->GetType() == FRIB_TAG_TEXT)
264 pParaNumbering->pPrefix = static_cast<LwpFribText*>(pPreFrib);
268 //get para numbering
269 pParaNumbering->pParaNumber = static_cast<LwpFribParaNumber*>(pFrib);
271 //get suffix text frib
272 if ( (pFrib = pFrib->GetNext()) )
274 if (pFrib->GetType() == FRIB_TAG_TEXT)
276 pParaNumbering->pSuffix = static_cast<LwpFribText*>(pFrib);
283 pPreFrib = pFrib;
284 if (pFrib)
286 pFrib = pFrib->GetNext();
291 * @short override alignment
293 //override style, add by 1-24
294 void LwpPara::OverrideAlignment(LwpAlignmentOverride* base,LwpAlignmentOverride* over,XFParaStyle* pOverStyle)
296 if (base)//the latter two parameter never be null
298 over->Override(base);
299 LwpParaStyle::ApplyAlignment(pOverStyle,base);
301 else
302 LwpParaStyle::ApplyAlignment(pOverStyle,over);
305 * @short override indent attribute
307 void LwpPara::OverrideIndent(LwpIndentOverride* base,LwpIndentOverride* over,XFParaStyle* pOverStyle)
309 if (base)//the latter two parameter never be null
311 over->Override(base);
312 LwpParaStyle::ApplyIndent(this,pOverStyle,base);
314 else
316 LwpParaStyle::ApplyIndent(this,pOverStyle,over);
320 * @short override spacing
322 void LwpPara::OverrideSpacing(LwpSpacingOverride* base,LwpSpacingOverride* over,XFParaStyle* pOverStyle)
324 if (base)//the latter two parameter never be null
326 if (over)
327 over->Override(base);
328 LwpParaStyle::ApplySpacing(this,pOverStyle,base);
330 else
331 LwpParaStyle::ApplySpacing(this,pOverStyle,over);
335 * @short: Get parastyle object according to the objID.
336 * @return: pointer to the parastyle.
338 LwpParaStyle* LwpPara::GetParaStyle()
340 return dynamic_cast<LwpParaStyle*>(m_ParaStyle.obj(VO_PARASTYLE));
344 * @short: Override paraborder style.
345 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
346 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
348 void LwpPara::OverrideParaBorder(LwpParaProperty* pProps, XFParaStyle* pOverStyle)
350 // get paraborder in parastyle
351 LwpParaStyle* pParaStyle = this->GetParaStyle();
352 if (!pParaStyle)
354 return;
357 LwpOverride* pBorder = pParaStyle->GetParaBorder();
358 SAL_WNODEPRECATED_DECLARATIONS_PUSH
359 boost::scoped_ptr<LwpParaBorderOverride> pFinalBorder(
360 pBorder
361 ? polymorphic_downcast<LwpParaBorderOverride*>(pBorder->clone())
362 : new LwpParaBorderOverride)
364 SAL_WNODEPRECATED_DECLARATIONS_POP
366 // get local border
367 pBorder = static_cast<LwpParaBorderProperty*>(pProps)->GetLocalParaBorder();
368 if (pBorder)
370 boost::scoped_ptr<LwpParaBorderOverride> pLocalBorder(
371 polymorphic_downcast<LwpParaBorderOverride*>(pBorder->clone()));
372 pLocalBorder->Override(pFinalBorder.get());
375 pParaStyle->ApplyParaBorder(pOverStyle, pFinalBorder.get());
378 * @short: Override parabreaks style.
379 * @param: pProps pointer to the LwpParaProperty and we can get local breaks through it.
380 * @param: pOverStyle pointer to XFParaStyle which contains the parastyle for XFilter.
382 void LwpPara::OverrideParaBreaks(LwpParaProperty* pProps, XFParaStyle* pOverStyle)
384 // get breaks in parastyle
385 LwpParaStyle* pParaStyle = this->GetParaStyle();
386 if (!pParaStyle)
388 return;
391 LwpOverride* pBreaks = pParaStyle->GetBreaks();
392 SAL_WNODEPRECATED_DECLARATIONS_PUSH
393 std::auto_ptr<LwpBreaksOverride> pFinalBreaks(
394 pBreaks
395 ? polymorphic_downcast<LwpBreaksOverride*>(pBreaks->clone())
396 : new LwpBreaksOverride)
398 SAL_WNODEPRECATED_DECLARATIONS_POP
400 // get local breaks
401 pBreaks = static_cast<LwpParaBreaksProperty*>(pProps)->GetLocalParaBreaks();
402 if (pBreaks)
404 boost::scoped_ptr<LwpBreaksOverride> const pLocalBreaks(
405 polymorphic_downcast<LwpBreaksOverride*>(pBreaks->clone()));
406 pLocalBreaks->Override(pFinalBreaks.get());
409 // save the breaks
410 delete m_pBreaks;
411 m_pBreaks = pFinalBreaks.release();
413 //add by 1/31
414 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
415 if (m_pBreaks->IsKeepWithNext())
417 pOverStyle->SetBreaks(enumXFBreakKeepWithNext);
419 if (m_pBreaks->IsPageBreakBefore())
421 XFParaStyle* pStyle = new XFParaStyle();
422 pStyle->SetBreaks(enumXFBreakAftPage);
423 m_BefPageBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
425 if (m_pBreaks->IsPageBreakAfter())
427 XFParaStyle* pStyle = new XFParaStyle();
428 pStyle->SetBreaks(enumXFBreakAftPage);
429 m_AftPageBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
431 if (m_pBreaks->IsColumnBreakBefore())
433 XFParaStyle* pStyle = new XFParaStyle();
434 pStyle->SetBreaks(enumXFBreakAftColumn);//tmp after, should change when layout read,note by 1/31
435 m_BefColumnBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
437 if (m_pBreaks->IsColumnBreakAfter())
439 XFParaStyle* pStyle = new XFParaStyle();
440 pStyle->SetBreaks(enumXFBreakAftColumn);
441 m_AftColumnBreakName = pXFStyleManager->AddStyle(pStyle)->GetStyleName();
443 //add end
445 // pParaStyle->ApplyBreaks(pOverStyle, &aFinalBreaks);
449 * @short: Override bullet styles.
450 * @param: pProps pointer to the LwpParaProperty and we can get local bullet through it.
452 void LwpPara::OverrideParaBullet(LwpParaProperty* pProps)
454 // get bulletoverride in parastyle
455 LwpParaStyle* pParaStyle = this->GetParaStyle();
456 if (!pParaStyle)
458 return;
461 if (pProps)
463 m_pBullOver = new LwpBulletOverride();
464 // get local bulletoverride
465 LwpBulletOverride* pLocalBullet = static_cast<LwpParaBulletProperty*>(pProps)->GetLocalParaBullet();
466 if (!pLocalBullet)
468 return;
471 LwpObjectID aSilverBulletID = pLocalBullet->GetSilverBullet();
472 if (aSilverBulletID.IsNull())
474 return;
476 else
478 m_bHasBullet = sal_True;
480 LwpOverride* pBullet= pParaStyle->GetBulletOverride();
481 SAL_WNODEPRECATED_DECLARATIONS_PUSH
482 std::auto_ptr<LwpBulletOverride> pFinalBullet(
483 pBullet
484 ? polymorphic_downcast<LwpBulletOverride*>(pBullet->clone())
485 : new LwpBulletOverride)
487 SAL_WNODEPRECATED_DECLARATIONS_POP
489 boost::scoped_ptr<LwpBulletOverride> const pLocalBullet2(pLocalBullet->clone());
490 pLocalBullet2->Override(pFinalBullet.get());
492 aSilverBulletID = pFinalBullet->GetSilverBullet();
493 delete m_pBullOver;
494 m_pBullOver = pFinalBullet.release();
495 if (!aSilverBulletID.IsNull())
497 m_pSilverBullet = dynamic_cast<LwpSilverBullet*>(aSilverBulletID.obj(VO_SILVERBULLET));
498 if (m_pSilverBullet)
499 m_pSilverBullet->SetFoundry(m_pFoundry);
502 m_aSilverBulletID = aSilverBulletID;
505 else
507 // m_pBullOver = pParaStyle->GetBulletOverride();
508 LwpBulletOverride* pBullOver = pParaStyle->GetBulletOverride();
509 if (pBullOver)
511 m_aSilverBulletID = pBullOver->GetSilverBullet();
512 if (!m_aSilverBulletID.IsNull())
514 m_bHasBullet = sal_True;
516 m_pSilverBullet = dynamic_cast<LwpSilverBullet*>(m_aSilverBulletID.obj(VO_SILVERBULLET));
517 if (m_pSilverBullet)
518 m_pSilverBullet->SetFoundry(m_pFoundry);
521 SAL_WNODEPRECATED_DECLARATIONS_PUSH
522 std::auto_ptr<LwpBulletOverride> pBulletOverride(pBullOver->clone());
523 SAL_WNODEPRECATED_DECLARATIONS_POP
524 delete m_pBullOver;
525 m_pBullOver = pBulletOverride.release();
530 * @short: Override paranumbering properties.
531 * @param: pProps pointer to the LwpParaProperty and we can get local paranumbering through it.
533 void LwpPara::OverrideParaNumbering(LwpParaProperty* pProps)
535 // get numbering override in parastyle
536 LwpParaStyle* pParaStyle = this->GetParaStyle();
537 if (!pParaStyle)
539 return;
542 LwpNumberingOverride* pParaNumbering = pParaStyle->GetNumberingOverride();
543 SAL_WNODEPRECATED_DECLARATIONS_PUSH
544 std::auto_ptr<LwpNumberingOverride> pOver(new LwpNumberingOverride);
545 SAL_WNODEPRECATED_DECLARATIONS_POP
546 //Override with the local numbering, if any
547 if (pProps)
549 LwpNumberingOverride* pPropNumbering = static_cast<LwpParaNumberingProperty*>(pProps)->GetLocalNumbering();
550 if (pPropNumbering)
552 pOver.reset(pPropNumbering->clone());
555 else
557 if (pParaNumbering)
559 pOver.reset(pParaNumbering->clone());
563 if (m_nFlags & VALID_LEVEL)
565 pOver->OverrideLevel(m_nLevel);
568 m_pParaNumbering.reset(pOver.release());
571 void LwpPara::FindLayouts()
573 m_Fribs.SetPara(this);
574 m_Fribs.FindLayouts();
575 LwpPara* pNextPara = dynamic_cast<LwpPara*>(GetNext()->obj());
576 if(pNextPara)
578 pNextPara->FindLayouts();
582 /**************************************************************************
583 * @descr: Get property according to the property type
584 * @param:
585 * @param:
586 * @return:
587 **************************************************************************/
588 LwpParaProperty* LwpPara::GetProperty(sal_uInt32 nPropType)
590 LwpParaProperty* pProps = m_pProps;
591 while(pProps)
593 if(pProps->GetType() == nPropType)
595 return pProps;
597 pProps = pProps->GetNext();
600 return NULL;
603 /**************************************************************************
604 * @descr: Get local tab rack
605 * @param:
606 * @param:
607 * @return:
608 **************************************************************************/
609 LwpTabOverride* LwpPara::GetLocalTabOverride()
611 LwpParaProperty* pProp = GetProperty(PP_LOCAL_TABRACK);
612 if(pProp)
614 return static_cast<LwpParaTabRackProperty*>(pProp)->GetTab();
616 return NULL;
620 * @descr: Determined which para is earlier in position
623 sal_Bool LwpPara::operator< (LwpPara& Other)
625 return m_nOrdinal < Other.GetOrdinal();
629 * @descr: If the two layouts in the same para, compare which layout is earlied according to frib order
632 sal_Bool LwpPara::ComparePagePosition(LwpVirtualLayout * pPreLayout, LwpVirtualLayout * pNextLayout)
634 m_Fribs.SetPara(this);
635 return m_Fribs.ComparePagePosition(pPreLayout, pNextLayout);
639 * @short check paragraph in cell or not
641 sal_Bool LwpPara::IsInCell()
643 LwpStory *pStory = GetStory();
644 LwpVirtualLayout* pLayout = pStory ? pStory->GetLayout(NULL) : NULL;
645 if(pLayout && pLayout->IsCell())
646 return sal_True;
647 return sal_False;
650 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */