bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwpbulletstylemgr.cxx
blob597f7c0fc11850bc539027f94f6ff271c41f1260
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 ************************************************************************/
64 #include "lwpbulletstylemgr.hxx"
65 #include "lwpdoc.hxx"
66 #include "lwpstory.hxx"
67 #include "lwpdivinfo.hxx"
68 #include "lwppara.hxx"
69 #include "lwpsilverbullet.hxx"
70 #include "lwptools.hxx"
71 #include "lwpparaproperty.hxx"
72 #include "xfilter/xfliststyle.hxx"
73 #include "xfilter/xfstylemanager.hxx"
74 #include "xfilter/xflist.hxx"
75 #include "lwpglobalmgr.hxx"
77 LwpBulletStyleMgr::LwpBulletStyleMgr() :
78 m_pBulletList(NULL), m_bContinue(sal_True), m_bIsBulletSkipped(sal_False), m_nCurrentPos(0xFF)
81 LwpBulletStyleMgr::~LwpBulletStyleMgr()
83 if (m_pBulletList)
85 delete m_pBulletList;
88 m_vIDsPairList.clear();
89 m_vStyleNameList.clear();
92 /**
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 OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, LwpBulletOverride* pBullOver,
100 LwpIndentOverride* pIndent)
102 OUString aEmpty;
104 if(!pPara || !pIndent || !pBullOver)
106 return aEmpty;
109 LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
110 if (!pSilverBullet)
112 assert(false);
113 return aEmpty;
116 LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
117 if (!pBulletPara)
119 assert(false);
120 return aEmpty;
123 LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
124 LwpParaIndentProperty* pIndentProp = NULL;
125 LwpObjectID aIndentID;
126 if (pProp)
128 pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
129 aIndentID = pIndentProp->GetIndentID();
132 LwpObjectID aBulletID = pBullOver->GetSilverBullet();
133 boost::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
135 sal_uInt16 nNameIndex = 0;
136 std::vector <OverridePair>::iterator iter;
137 for(iter = m_vIDsPairList.begin(); iter != m_vIDsPairList.end(); ++iter)
139 if (iter->first->GetSilverBullet() == aBulletID && iter->second == aIndentID
140 && iter->first->IsRightAligned() == pBullOver->IsRightAligned())
142 return m_vStyleNameList[nNameIndex];
144 else
146 nNameIndex++;
150 m_vIDsPairList.push_back(std::make_pair(pBulletOver, aIndentID));
151 OUString aStyleName;
153 LwpFribPtr* pBulletParaFribs = pBulletPara->GetFribs();
154 sal_Bool bIsNumbering = (sal_Bool)(pBulletParaFribs->HasFrib(FRIB_TAG_PARANUMBER) != 0);
156 enumXFAlignType eAlign = enumXFAlignStart;
157 if (pBullOver->IsRightAligned())
159 eAlign = enumXFAlignEnd;
162 XFListStyle* pListStyle = new XFListStyle();
163 XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
165 if (!bIsNumbering)
167 for (sal_uInt8 nC = 1; nC < 11; nC++)
169 pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
170 pSilverBullet->GetPrefix(), pSilverBullet->GetSuffix());
172 if (pIndent->GetMRest() > 0.001)
174 pListStyle->SetListPosition(nC, 0.0,
175 LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMRest())), 0.0, eAlign);
177 else
179 pListStyle->SetListPosition(nC, 0.0,
180 0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMFirst())), eAlign);
184 aStyleName = pXFStyleMgr->AddStyle(pListStyle)->GetStyleName();
186 else
188 ParaNumbering aParaNumbering;
189 pBulletPara->GetParaNumber(1, &aParaNumbering);
190 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
191 if (pParaNumber)
193 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
195 if (pParaNumber->GetStyleID() != NUMCHAR_other)
197 OUString aPrefix;
198 XFNumFmt aFmt;
199 if (aParaNumbering.pPrefix)
201 aPrefix += aParaNumbering.pPrefix->GetText();
204 OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
205 if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
207 aPrefix += OUString("0");
209 aFmt.SetPrefix(aPrefix);
211 aFmt.SetFormat(aNumber);
213 if (aParaNumbering.pSuffix)
215 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
218 //set numbering format into the style-list.
219 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
222 else
224 OUString aPrefix, aSuffix;
225 if (aParaNumbering.pPrefix)
227 aPrefix = aParaNumbering.pPrefix->GetText();
229 if (aParaNumbering.pSuffix)
231 aSuffix = aParaNumbering.pSuffix->GetText();
234 pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber).toChar(),
235 OUString("Times New Roman"), aPrefix, aSuffix);
238 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
240 aStyleName = pXFStyleMgr->AddStyle(pListStyle)->GetStyleName();
242 else
243 delete pListStyle;
247 m_vStyleNameList.push_back(aStyleName);
248 return aStyleName;
252 #include "xfilter/xflistitem.hxx"
253 //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
254 //Return the inner XFItem created.
255 XFContentContainer* LwpBulletStyleMgr::AddBulletList(
256 XFContentContainer* pCont, sal_Bool bIsOrdered,
257 const OUString& rStyleName, sal_Int16 nLevel, sal_Bool bIsBulletSkiped)
259 assert(nLevel>0);
261 m_bIsBulletSkipped = bIsBulletSkiped;
263 //todo: need judge here.
264 sal_Bool bContinue = m_bContinue;
266 XFList* theList;
267 XFList* prevList = NULL;
268 XFListItem* theItem;
269 XFListItem* InnerItem = NULL;
270 for (sal_Int8 nC = nLevel-1; nC >= 0; nC--)
272 theList = new XFList();
273 theItem = new XFListItem();
274 theList->Add(theItem);
276 if (bIsOrdered)
278 theList->SetOrdered(sal_True);
280 else
282 bContinue = sal_False;
283 theList->SetOrdered(sal_False);
286 if (nC == nLevel-1)
288 theList->SetContinueNumber(bContinue);
290 //Add the outer list to pCont
291 if (nC == 0)
293 theList->SetStyleName(rStyleName);
294 pCont->Add(theList);
297 if ((nC == nLevel-1) && bIsBulletSkiped)
299 theItem->SetIsHeader(sal_True);
301 theList->SetContinueNumber(sal_True);
302 // end of add
305 if(nC == nLevel-1)
307 InnerItem = theItem;
310 if(prevList)
312 theItem->Add(prevList);
314 prevList = theList;
316 return InnerItem;
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */