Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / lotuswordpro / source / filter / lwpbulletstylemgr.cxx
blob358655a9f8ad15f641844eaf7c18d04db7a8b4a8
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 "lwpbulletstylemgr.hxx"
62 #include "lwpdoc.hxx"
63 #include "lwpstory.hxx"
64 #include "lwpdivinfo.hxx"
65 #include "lwppara.hxx"
66 #include "lwpsilverbullet.hxx"
67 #include "lwptools.hxx"
68 #include "lwpparaproperty.hxx"
69 #include "xfilter/xfliststyle.hxx"
70 #include "xfilter/xfstylemanager.hxx"
71 #include "xfilter/xflist.hxx"
72 #include "lwpglobalmgr.hxx"
74 LwpBulletStyleMgr::LwpBulletStyleMgr()
75 : m_pFoundry(nullptr)
76 , m_pBulletList(nullptr)
77 , m_bContinue(true)
78 , m_bIsBulletSkipped(false)
82 LwpBulletStyleMgr::~LwpBulletStyleMgr()
84 if (m_pBulletList)
86 delete m_pBulletList;
89 m_vIDsPairList.clear();
90 m_vStyleNameList.clear();
93 /**
94 * @short Register bullet style to style-list. The function only register the bullet and single customized numbering
95 * not including the numbering sequence.
96 * @param pPara pointer to the current paragraph which has a bullet/numbering.
97 * @param pBullOver pointer to the bulletoverride of current paragraph.
98 * @param pIndent pointer to the indentoverride of current paragraph.
100 OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, LwpBulletOverride* pBullOver,
101 LwpIndentOverride* pIndent)
103 if(!pPara || !pIndent || !pBullOver)
105 return OUString();
108 LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
109 if (!pSilverBullet)
111 assert(false);
112 return OUString();
115 LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
116 if (!pBulletPara)
118 assert(false);
119 return OUString();
122 LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
123 LwpParaIndentProperty* pIndentProp = nullptr;
124 LwpObjectID aIndentID;
125 if (pProp)
127 pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
128 aIndentID = pIndentProp->GetIndentID();
131 LwpObjectID aBulletID = pBullOver->GetSilverBullet();
132 std::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
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];
143 else
145 nNameIndex++;
149 m_vIDsPairList.push_back(std::make_pair(pBulletOver, aIndentID));
150 OUString aStyleName;
152 LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs();
153 bool bIsNumbering = (rBulletParaFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
155 enumXFAlignType eAlign = enumXFAlignStart;
156 if (pBullOver->IsRightAligned())
158 eAlign = enumXFAlignEnd;
161 XFListStyle* pListStyle = new XFListStyle();
162 XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
164 if (!bIsNumbering)
166 for (sal_uInt8 nC = 1; nC < 11; nC++)
168 pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
169 LwpSilverBullet::GetPrefix(), LwpSilverBullet::GetSuffix());
171 if (pIndent->GetMRest() > 0) /* note: used to be 0.001, no idea why */
173 pListStyle->SetListPosition(nC, 0.0,
174 LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMRest())), 0.0, eAlign);
176 else
178 pListStyle->SetListPosition(nC, 0.0,
179 0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMFirst())), eAlign);
183 aStyleName = (pXFStyleMgr->AddStyle(pListStyle)).m_pStyle->GetStyleName();
185 else
187 ParaNumbering aParaNumbering;
188 pBulletPara->GetParaNumber(1, &aParaNumbering);
189 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
190 if (pParaNumber)
192 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
194 if (pParaNumber->GetStyleID() != NUMCHAR_other)
196 OUString aPrefix;
197 XFNumFmt aFmt;
198 if (aParaNumbering.pPrefix)
200 aPrefix += aParaNumbering.pPrefix->GetText();
203 OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
204 if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
206 aPrefix += "0";
208 aFmt.SetPrefix(aPrefix);
210 aFmt.SetFormat(aNumber);
212 if (aParaNumbering.pSuffix)
214 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
217 //set numbering format into the style-list.
218 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
221 else
223 OUString aPrefix, aSuffix;
224 if (aParaNumbering.pPrefix)
226 aPrefix = aParaNumbering.pPrefix->GetText();
228 if (aParaNumbering.pSuffix)
230 aSuffix = aParaNumbering.pSuffix->GetText();
233 pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber),
234 "Times New Roman", aPrefix, aSuffix);
237 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
239 aStyleName = (pXFStyleMgr->AddStyle(pListStyle)).m_pStyle->GetStyleName();
241 else
242 delete pListStyle;
246 m_vStyleNameList.push_back(aStyleName);
247 return aStyleName;
251 #include "xfilter/xflistitem.hxx"
252 //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
253 //Return the inner XFItem created.
254 XFContentContainer* LwpBulletStyleMgr::AddBulletList(
255 XFContentContainer* pCont, bool bIsOrdered,
256 const OUString& rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
258 assert(nLevel>0);
260 m_bIsBulletSkipped = bIsBulletSkiped;
262 //todo: need judge here.
263 bool bContinue = m_bContinue;
265 XFList* theList;
266 XFList* prevList = nullptr;
267 XFListItem* theItem;
268 XFListItem* InnerItem = nullptr;
269 for (sal_Int8 nC = nLevel-1; nC >= 0; nC--)
271 theList = new XFList();
272 theItem = new XFListItem();
273 theList->Add(theItem);
275 if (bIsOrdered)
277 theList->SetOrdered(true);
279 else
281 bContinue = false;
282 theList->SetOrdered(false);
285 if (nC == nLevel-1)
287 theList->SetContinueNumber(bContinue);
289 //Add the outer list to pCont
290 if (nC == 0 && pCont)
292 theList->SetStyleName(rStyleName);
293 pCont->Add(theList);
296 if ((nC == nLevel-1) && bIsBulletSkiped)
298 theItem->SetIsHeader();
300 theList->SetContinueNumber(true);
303 if(nC == nLevel-1)
305 InnerItem = theItem;
308 if(prevList)
310 theItem->Add(prevList);
312 prevList = theList;
314 return InnerItem;
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */