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,
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 /*************************************************************************
57 * For LWP filter architecture prototype
58 ************************************************************************/
59 /*************************************************************************
62 ************************************************************************/
63 #include "lwpbulletstylemgr.hxx"
65 #include "lwpstory.hxx"
66 #include "lwpdivinfo.hxx"
67 #include "lwppara.hxx"
68 #include "lwpsilverbullet.hxx"
69 #include "lwptools.hxx"
70 #include "lwpparaproperty.hxx"
71 #include "xfilter/xfliststyle.hxx"
72 #include "xfilter/xfstylemanager.hxx"
73 #include "xfilter/xflist.hxx"
74 #include "lwpglobalmgr.hxx"
76 LwpBulletStyleMgr::LwpBulletStyleMgr() :
77 m_pBulletList(NULL
), m_bContinue(sal_True
), m_bIsBulletSkipped(sal_False
), m_nCurrentPos(0xFF)
81 LwpBulletStyleMgr::~LwpBulletStyleMgr()
88 m_vIDsPairList
.clear();
89 m_vStyleNameList
.clear();
93 * @short Register bullet style to style-list. The function only register the bullet and single customized numbering
94 * not inluding the numbering sequence.
95 * @param pPara pointer to the current paragraph which has a bullet/numbering.
96 * @param pBullOver pointer to the bulletoverride of current paragraph.
97 * @param pIndent pointer to the indentoverride of current paragraph.
99 rtl::OUString
LwpBulletStyleMgr::RegisterBulletStyle(LwpPara
* pPara
, LwpBulletOverride
* pBullOver
,
100 LwpIndentOverride
* pIndent
)
102 if(!pPara
|| !pIndent
|| !pBullOver
)
105 return rtl::OUString::createFromAscii("");
108 LwpSilverBullet
* pSilverBullet
= pPara
->GetSilverBullet();
112 return rtl::OUString::createFromAscii("");
115 LwpPara
* pBulletPara
= pSilverBullet
->GetBulletPara();
119 return rtl::OUString::createFromAscii("");
122 LwpParaProperty
* pProp
= pPara
->GetProperty(PP_LOCAL_INDENT
);
123 LwpParaIndentProperty
* pIndentProp
= NULL
;
124 LwpObjectID aIndentID
;
127 pIndentProp
= static_cast<LwpParaIndentProperty
*>(pProp
);
128 aIndentID
= pIndentProp
->GetIndentID();
131 LwpObjectID aBulletID
= pBullOver
->GetSilverBullet();
132 LwpBulletOverride aBulletOver
= *pBullOver
;
134 sal_uInt16 nNameIndex
= 0;
135 std::vector
<OverridePair
>::iterator iter
;
136 for(iter
= m_vIDsPairList
.begin(); iter
!= m_vIDsPairList
.end(); iter
++)
138 if (iter
->first
.GetSilverBullet() == aBulletID
&& iter
->second
== aIndentID
139 && iter
->first
.IsRightAligned() == pBullOver
->IsRightAligned())
141 return m_vStyleNameList
[nNameIndex
];
149 m_vIDsPairList
.push_back(std::make_pair(aBulletOver
, aIndentID
));
150 rtl::OUString aStyleName
;
152 LwpFribPtr
* pBulletParaFribs
= pBulletPara
->GetFribs();
153 sal_Bool bIsNumbering
= (sal_Bool
)(pBulletParaFribs
->HasFrib(FRIB_TAG_PARANUMBER
) != 0);
155 enumXFAlignType eAlign
= enumXFAlignStart
;
156 if (pBullOver
->IsRightAligned())
158 eAlign
= enumXFAlignEnd
;
161 XFListStyle
* pListStyle
= new XFListStyle();
162 XFStyleManager
* pXFStyleMgr
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
166 for (sal_uInt8 nC
= 1; nC
< 11; nC
++)
168 pListStyle
->SetListBullet(nC
, pSilverBullet
->GetBulletChar(), pSilverBullet
->GetBulletFontName(),
169 pSilverBullet
->GetPrefix(), pSilverBullet
->GetSuffix());
171 if (pIndent
->GetMRest() > 0.001)
173 pListStyle
->SetListPosition(nC
, 0.0,
174 LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent
->GetMRest())), 0.0, eAlign
);
178 pListStyle
->SetListPosition(nC
, 0.0,
179 0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent
->GetMFirst())), eAlign
);
183 aStyleName
= pXFStyleMgr
->AddStyle(pListStyle
)->GetStyleName();
187 rtl::OUString aPrefix
= rtl::OUString::createFromAscii("");
189 LwpFrib
* pFrib
= pBulletParaFribs
->HasFrib(FRIB_TAG_DOCVAR
);
190 LwpFribDocVar
* pDocVarFrib
= NULL
;
193 pDocVarFrib
= static_cast<LwpFribDocVar
*>(pFrib
);
194 // ModifierInfo* pInfo = pDocVarFrib->GetModifiers();
195 switch (pDocVarFrib
->GetType())
197 case 0x000D: // division name
198 aPrefix
= this->GetDivisionName();
200 case 0x000E: // section name
201 aPrefix
= this->GetSectionName(pPara
);
205 ParaNumbering aParaNumbering
;
206 pBulletPara
->GetParaNumber(1, &aParaNumbering
);
207 LwpFribParaNumber
* pParaNumber
= aParaNumbering
.pParaNumber
;
210 for (sal_uInt8 nPos
= 1; nPos
< 10; nPos
++)
212 aPrefix
= rtl::OUString::createFromAscii("");
213 if (pParaNumber
->GetStyleID() != NUMCHAR_other
)
216 if (aParaNumbering
.pPrefix
)
218 aPrefix
+= aParaNumbering
.pPrefix
->GetText();
219 // aFmt.SetPrefix(aParaNumbering.pPrefix->GetText() + aAdditionalInfoName);
222 rtl::OUString aNumber
= LwpSilverBullet::GetNumCharByStyleID(pParaNumber
);
223 if (pParaNumber
->GetStyleID() == NUMCHAR_01
|| pParaNumber
->GetStyleID() == NUMCHAR_Chinese4
)
225 aPrefix
+= rtl::OUString::createFromAscii("0");
227 aFmt
.SetPrefix(aPrefix
);
229 aFmt
.SetFormat(aNumber
);
231 if (aParaNumbering
.pSuffix
)
233 aFmt
.SetSuffix(aParaNumbering
.pSuffix
->GetText());
236 //set numbering format into the style-list.
237 pListStyle
->SetListNumber(nPos
, aFmt
, pParaNumber
->GetStart()+1);
242 rtl::OUString aPrefix
, aSuffix
;
243 if (aParaNumbering
.pPrefix
)
245 aPrefix
= aParaNumbering
.pPrefix
->GetText();
247 if (aParaNumbering
.pSuffix
)
249 aSuffix
= aParaNumbering
.pSuffix
->GetText();
252 pListStyle
->SetListBullet(nPos
, LwpSilverBullet::GetNumCharByStyleID(pParaNumber
).toChar(),
253 rtl::OUString::createFromAscii("Times New Roman"), aPrefix
, aSuffix
);
256 pListStyle
->SetListPosition(nPos
, 0.0, 0.635, 0.0);
258 aStyleName
= pXFStyleMgr
->AddStyle(pListStyle
)->GetStyleName();
263 m_vStyleNameList
.push_back(aStyleName
);
274 /*rtl::OUString LwpBulletStyleMgr::RegisterBulletStyle(const rtl::OUString& rContent, sal_uInt32 nFontID, LwpIndentOverride* pIndent)
283 return rtl::OUString::createFromAscii("");
285 LwpFontManager* pFontMgr = m_pFoundry->GetFontManger();
287 rtl::OUString aFontName = pFontMgr->GetNameByID(nFontID);
288 UChar32 cBulletChar = rContent.toChar();
289 rtl::OUString aSuffix = rContent.copy(1);
290 XFListStyle* pListStyle = new XFListStyle();
291 XFStyleManager* pXFStyleMgr = XFStyleManager::Instance();
293 for (sal_uInt8 nC = 1; nC < 11; nC++)
295 pListStyle->SetListBullet(nC, cBulletChar, aFontName, rtl::OUString::createFromAscii(""), aSuffix);
297 if (pIndent->GetMRest() > 0.001)
299 pListStyle->SetListPosition(nC, 0.0,
300 LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMRest())), 0.0);
304 pListStyle->SetListPosition(nC, 0.0,
305 0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMFirst())));
308 return pXFStyleMgr->AddStyle(pListStyle);
316 /*void LwpBulletStyleMgr::CreateNewListStyle(XFListStyle*& pListStyle, XFStyleManager* pXFStyleMgr)
318 pListStyle = new XFListStyle();
319 m_aBulletStyleList.push_back(pListStyle);
320 m_aCurrentStyleName = pXFStyleMgr->AddStyle(pListStyle);
325 * @param pSilverBullet
328 /*rtl::OUString LwpBulletStyleMgr::AddStyleToList(LwpSilverBullet* pSilverBullet, sal_uInt16 nLevel)
330 XFListStyle* pListStyle = NULL;
331 XFStyleManager* pXFStyleMgr = XFStyleManager::Instance();
333 if (m_aBulletStyleList.empty())
335 // pListStyle = new XFListStyle();
336 // m_aBulletStyleList.push_back(pListStyle);
337 // m_aCurrentStyleName = pXFStyleMgr->AddStyle(pListStyle);
338 // this->CreateNewListStyle(pListStyle, pXFStyleMgr);
339 if (pSilverBullet->IsBulletOrdered())
341 m_strCurrentNumberingName = pSilverBullet->GetNumberingName();
345 m_nCurrentChar = pSilverBullet->GetBulletChar();
346 m_strCurrentFontName = pSilverBullet->GetBulletFontName();
349 else if (nLevel == 1)
351 if (pSilverBullet->IsBulletOrdered())
353 if (m_strCurrentNumberingName == pSilverBullet->GetNumberingName())
355 pListStyle = m_aBulletStyleList.back();
359 this->CreateNewListStyle(pListStyle, pXFStyleMgr);
364 if ((m_nCurrentChar == pSilverBullet->GetBulletChar()) &&
365 (m_strCurrentFontName == pSilverBullet->GetBulletFontName()))
367 pListStyle = m_aBulletStyleList.back();
371 this->CreateNewListStyle(pListStyle, pXFStyleMgr);
377 pListStyle = m_aBulletStyleList.back();
380 if (pSilverBullet->IsBulletOrdered())
382 // pListStyle->SetListNumber(int level, XFNumFmt & fmt, sal_Int16 start);
386 pListStyle->SetListBullet(nLevel, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
387 pSilverBullet->GetPrefix(), pSilverBullet->GetSuffix());
390 return m_aCurrentStyleName;
394 * @short Output bullet list header, such as <text:ordered-list> and <text:list-item>
395 * @param pOutputStream pointer of XFstream to be written in.
396 * @param bIsOrdered if the list if ordered or not.
397 * @param rStyleName style name of the list
398 * @param nLevel level of the paragraph
400 void LwpBulletStyleMgr::OutputBulletListHeader(IXFStream
* pOutputStream
, sal_Bool bIsOrdered
,
401 const rtl::OUString
& rStyleName
, sal_Int16 nLevel
, sal_Bool bIsBulletSkiped
)
408 m_bIsBulletSkipped
= bIsBulletSkiped
;
412 delete m_pBulletList
;
415 m_pBulletList
= new XFList();
417 //todo: need judge here.
418 sal_Bool bContinue
= m_bContinue
;
422 m_pBulletList
->SetOrdered(sal_True
);
426 bContinue
= sal_False
;
427 m_pBulletList
->SetOrdered(sal_False
);
429 m_pBulletList
->SetStyleName(rStyleName
);
432 // m_pBulletList->StartList(pOutputStream);
436 for (sal_uInt8 nC
= 0; nC
< nLevel
; nC
++)
441 m_pBulletList
->StartList(pOutputStream
, bContinue
);
445 m_pBulletList
->StartList(pOutputStream
);
447 if ((nC
== nLevel
-1) && bIsBulletSkiped
)
449 XFList::StartListHeader(pOutputStream
);
453 XFList::StartListItem(pOutputStream
);
459 #include "xfilter/xflistitem.hxx"
460 //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
461 //Return the inner XFItem created.
462 XFContentContainer
* LwpBulletStyleMgr::AddBulletList(
463 XFContentContainer
* pCont
, sal_Bool bIsOrdered
,
464 const rtl::OUString
& rStyleName
, sal_Int16 nLevel
, sal_Bool bIsBulletSkiped
)
468 m_bIsBulletSkipped
= bIsBulletSkiped
;
470 //todo: need judge here.
471 sal_Bool bContinue
= m_bContinue
;
474 XFList
* prevList
= NULL
;
476 XFListItem
* InnerItem
= NULL
;
477 for (sal_Int8 nC
= nLevel
-1; nC
>= 0; nC
--)
479 theList
= new XFList();
480 theItem
= new XFListItem();
481 theList
->Add(theItem
);
485 theList
->SetOrdered(sal_True
);
489 bContinue
= sal_False
;
490 theList
->SetOrdered(sal_False
);
495 theList
->SetContinueNumber(bContinue
);
497 //Add the outer list to pCont
500 theList
->SetStyleName(rStyleName
);
504 if ((nC
== nLevel
-1) && bIsBulletSkiped
)
506 theItem
->SetIsHeader(sal_True
);
508 theList
->SetContinueNumber(sal_True
);
519 theItem
->Add(prevList
);
527 * @short Output bullet list header, such as </text:ordered-list> and </text:list-item>
528 * @param pOutputStream pointer of XFstream to be written in.
529 * @param nLevel level of the paragraph
531 void LwpBulletStyleMgr::OutputBulletListTail(IXFStream
* pOutputStream
, sal_uInt16 nLevel
)
533 if ( !m_pBulletList
)
538 for (sal_uInt8 nC
= 0; nC
< nLevel
; nC
++)
540 if (m_bIsBulletSkipped
)
542 XFList::EndListHeader(pOutputStream
);
543 m_bIsBulletSkipped
= sal_False
;
547 XFList::EndListItem(pOutputStream
);
549 m_pBulletList
->EndList(pOutputStream
);
553 rtl::OUString
LwpBulletStyleMgr::GetDivisionName()
557 return rtl::OUString::createFromAscii("");
560 rtl::OUString aRet
= rtl::OUString::createFromAscii("");
562 LwpDocument
* pDoc
= m_pFoundry
->GetDocument();
565 LwpObjectID
* pID
= pDoc
->GetDivInfoID();
568 aRet
= static_cast<LwpDivInfo
*>(pID
->obj(VO_DIVISIONINFO
))->GetDivName();
575 rtl::OUString
LwpBulletStyleMgr::GetSectionName(LwpPara
* pPara
)
577 LwpObjectID
* pStoryID
= pPara
->GetStoryID();
578 if (pStoryID
->IsNull())
580 return rtl::OUString::createFromAscii("");
583 LwpStory
* pStory
= static_cast<LwpStory
*>(pStoryID
->obj(VO_STORY
));
586 return rtl::OUString::createFromAscii("");
589 return pStory
->GetSectionName();