build fix
[LibreOffice.git] / lotuswordpro / source / filter / lwpbulletstylemgr.cxx
blob2366b319153ee314e1d1eac473828040c76981ad
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"
73 #include "xfilter/xflistitem.hxx"
75 LwpBulletStyleMgr::LwpBulletStyleMgr()
76 : m_pFoundry(nullptr)
77 , m_bContinue(true)
78 , m_bIsBulletSkipped(false)
82 LwpBulletStyleMgr::~LwpBulletStyleMgr()
84 m_vIDsPairList.clear();
85 m_vStyleNameList.clear();
88 /**
89 * @short Register bullet style to style-list. The function only register the bullet and single customized numbering
90 * not including the numbering sequence.
91 * @param pPara pointer to the current paragraph which has a bullet/numbering.
92 * @param pBullOver pointer to the bulletoverride of current paragraph.
93 * @param pIndent pointer to the indentoverride of current paragraph.
95 OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, LwpBulletOverride* pBullOver,
96 LwpIndentOverride* pIndent)
98 if(!pPara || !pIndent || !pBullOver)
100 return OUString();
103 LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
104 if (!pSilverBullet)
106 assert(false);
107 return OUString();
110 LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
111 if (!pBulletPara)
113 assert(false);
114 return OUString();
117 LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
118 LwpParaIndentProperty* pIndentProp = nullptr;
119 LwpObjectID aIndentID;
120 if (pProp)
122 pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
123 aIndentID = pIndentProp->GetIndentID();
126 LwpObjectID aBulletID = pBullOver->GetSilverBullet();
127 std::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
129 sal_uInt16 nNameIndex = 0;
130 std::vector <OverridePair>::iterator iter;
131 for(iter = m_vIDsPairList.begin(); iter != m_vIDsPairList.end(); ++iter)
133 if (iter->first->GetSilverBullet() == aBulletID && iter->second == aIndentID
134 && iter->first->IsRightAligned() == pBullOver->IsRightAligned())
136 return m_vStyleNameList[nNameIndex];
138 else
140 nNameIndex++;
144 m_vIDsPairList.push_back(std::make_pair(pBulletOver, aIndentID));
145 OUString aStyleName;
147 LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs();
148 bool bIsNumbering = (rBulletParaFribs.HasFrib(FRIB_TAG_PARANUMBER) != nullptr);
150 enumXFAlignType eAlign = enumXFAlignStart;
151 if (pBullOver->IsRightAligned())
153 eAlign = enumXFAlignEnd;
156 XFListStyle* pListStyle = new XFListStyle();
157 XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
159 if (!bIsNumbering)
161 for (sal_uInt8 nC = 1; nC < 11; nC++)
163 pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
164 LwpSilverBullet::GetPrefix(), LwpSilverBullet::GetSuffix());
166 if (pIndent->GetMRest() > 0) /* note: used to be 0.001, no idea why */
168 pListStyle->SetListPosition(nC, 0.0,
169 LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMRest())), 0.0, eAlign);
171 else
173 pListStyle->SetListPosition(nC, 0.0,
174 0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMFirst())), eAlign);
178 aStyleName = (pXFStyleMgr->AddStyle(pListStyle)).m_pStyle->GetStyleName();
180 else
182 ParaNumbering aParaNumbering;
183 pBulletPara->GetParaNumber(1, &aParaNumbering);
184 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
185 if (pParaNumber)
187 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
189 if (pParaNumber->GetStyleID() != NUMCHAR_other)
191 OUString aPrefix;
192 XFNumFmt aFmt;
193 if (aParaNumbering.pPrefix)
195 aPrefix += aParaNumbering.pPrefix->GetText();
198 OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
199 if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
201 aPrefix += "0";
203 aFmt.SetPrefix(aPrefix);
205 aFmt.SetFormat(aNumber);
207 if (aParaNumbering.pSuffix)
209 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
212 //set numbering format into the style-list.
213 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
216 else
218 OUString aPrefix, aSuffix;
219 if (aParaNumbering.pPrefix)
221 aPrefix = aParaNumbering.pPrefix->GetText();
223 if (aParaNumbering.pSuffix)
225 aSuffix = aParaNumbering.pSuffix->GetText();
228 pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber),
229 "Times New Roman", aPrefix, aSuffix);
232 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
234 aStyleName = (pXFStyleMgr->AddStyle(pListStyle)).m_pStyle->GetStyleName();
236 else
237 delete pListStyle;
241 m_vStyleNameList.push_back(aStyleName);
242 return aStyleName;
246 //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
247 //Return the inner XFItem created.
248 XFContentContainer* LwpBulletStyleMgr::AddBulletList(
249 XFContentContainer* pCont, bool bIsOrdered,
250 const OUString& rStyleName, sal_Int16 nLevel, bool bIsBulletSkiped)
252 assert(nLevel>0);
254 m_bIsBulletSkipped = bIsBulletSkiped;
256 //todo: need judge here.
257 bool bContinue = m_bContinue;
259 XFList* theList;
260 XFList* prevList = nullptr;
261 XFListItem* theItem;
262 XFListItem* InnerItem = nullptr;
263 for (sal_Int8 nC = nLevel-1; nC >= 0; nC--)
265 theList = new XFList();
266 theItem = new XFListItem();
267 theList->Add(theItem);
269 if (bIsOrdered)
271 theList->SetOrdered(true);
273 else
275 bContinue = false;
276 theList->SetOrdered(false);
279 if (nC == nLevel-1)
281 theList->SetContinueNumber(bContinue);
283 //Add the outer list to pCont
284 if (nC == 0 && pCont)
286 theList->SetStyleName(rStyleName);
287 pCont->Add(theList);
290 if ((nC == nLevel-1) && bIsBulletSkiped)
292 theItem->SetIsHeader();
294 theList->SetContinueNumber(true);
297 if(nC == nLevel-1)
299 InnerItem = theItem;
302 if(prevList)
304 theItem->Add(prevList);
306 prevList = theList;
308 return InnerItem;
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */