Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * The Contents of this file are made available subject to the terms of
5 : * either of the following licenses
6 : *
7 : * - GNU Lesser General Public License Version 2.1
8 : * - Sun Industry Standards Source License Version 1.1
9 : *
10 : * Sun Microsystems Inc., October, 2000
11 : *
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
16 : *
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.
20 : *
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.
25 : *
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
30 : *
31 : *
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.
38 : *
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.
45 : *
46 : * The Initial Developer of the Original Code is: IBM Corporation
47 : *
48 : * Copyright: 2008 by IBM Corporation
49 : *
50 : * All Rights Reserved.
51 : *
52 : * Contributor(s): _______________________________________
53 : *
54 : *
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"
76 :
77 9 : LwpBulletStyleMgr::LwpBulletStyleMgr() :
78 9 : m_pBulletList(NULL), m_bContinue(sal_True), m_bIsBulletSkipped(sal_False), m_nCurrentPos(0xFF)
79 : {
80 9 : }
81 24 : LwpBulletStyleMgr::~LwpBulletStyleMgr()
82 : {
83 8 : if (m_pBulletList)
84 : {
85 0 : delete m_pBulletList;
86 : }
87 :
88 8 : m_vIDsPairList.clear();
89 8 : m_vStyleNameList.clear();
90 16 : }
91 :
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.
98 : */
99 2 : rtl::OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, LwpBulletOverride* pBullOver,
100 : LwpIndentOverride* pIndent)
101 : {
102 2 : rtl::OUString aEmpty;
103 :
104 2 : if(!pPara || !pIndent || !pBullOver)
105 : {
106 0 : return aEmpty;
107 : }
108 :
109 2 : LwpSilverBullet* pSilverBullet = pPara->GetSilverBullet();
110 2 : if (!pSilverBullet)
111 : {
112 : assert(false);
113 0 : return aEmpty;
114 : }
115 :
116 2 : LwpPara* pBulletPara = pSilverBullet->GetBulletPara();
117 2 : if (!pBulletPara)
118 : {
119 : assert(false);
120 0 : return aEmpty;
121 : }
122 :
123 2 : LwpParaProperty* pProp = pPara->GetProperty(PP_LOCAL_INDENT);
124 2 : LwpParaIndentProperty* pIndentProp = NULL;
125 2 : LwpObjectID aIndentID;
126 2 : if (pProp)
127 : {
128 0 : pIndentProp = static_cast<LwpParaIndentProperty*>(pProp);
129 0 : aIndentID = pIndentProp->GetIndentID();
130 : }
131 :
132 2 : LwpObjectID aBulletID = pBullOver->GetSilverBullet();
133 2 : boost::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone());
134 :
135 2 : sal_uInt16 nNameIndex = 0;
136 2 : std::vector <OverridePair>::iterator iter;
137 2 : for(iter = m_vIDsPairList.begin(); iter != m_vIDsPairList.end(); ++iter)
138 : {
139 2 : if (iter->first->GetSilverBullet() == aBulletID && iter->second == aIndentID
140 1 : && iter->first->IsRightAligned() == pBullOver->IsRightAligned())
141 : {
142 1 : return m_vStyleNameList[nNameIndex];
143 : }
144 : else
145 : {
146 0 : nNameIndex++;
147 : }
148 : }
149 :
150 1 : m_vIDsPairList.push_back(std::make_pair(pBulletOver, aIndentID));
151 1 : rtl::OUString aStyleName;
152 :
153 1 : LwpFribPtr* pBulletParaFribs = pBulletPara->GetFribs();
154 1 : sal_Bool bIsNumbering = (sal_Bool)(pBulletParaFribs->HasFrib(FRIB_TAG_PARANUMBER) != 0);
155 :
156 1 : enumXFAlignType eAlign = enumXFAlignStart;
157 1 : if (pBullOver->IsRightAligned())
158 : {
159 0 : eAlign = enumXFAlignEnd;
160 : }
161 :
162 1 : XFListStyle* pListStyle = new XFListStyle();
163 1 : XFStyleManager* pXFStyleMgr = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
164 :
165 1 : if (!bIsNumbering)
166 : {
167 0 : for (sal_uInt8 nC = 1; nC < 11; nC++)
168 : {
169 : pListStyle->SetListBullet(nC, pSilverBullet->GetBulletChar(), pSilverBullet->GetBulletFontName(),
170 0 : pSilverBullet->GetPrefix(), pSilverBullet->GetSuffix());
171 :
172 0 : if (pIndent->GetMRest() > 0.001)
173 : {
174 : pListStyle->SetListPosition(nC, 0.0,
175 0 : LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMRest())), 0.0, eAlign);
176 : }
177 : else
178 : {
179 : pListStyle->SetListPosition(nC, 0.0,
180 0 : 0.0, LwpTools::ConvertToMetric(LwpTools::ConvertFromUnits(pIndent->GetMFirst())), eAlign);
181 : }
182 : }
183 :
184 0 : aStyleName = pXFStyleMgr->AddStyle(pListStyle)->GetStyleName();
185 : }
186 : else
187 : {
188 1 : ParaNumbering aParaNumbering;
189 1 : pBulletPara->GetParaNumber(1, &aParaNumbering);
190 1 : LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
191 1 : if (pParaNumber)
192 : {
193 10 : for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
194 : {
195 9 : if (pParaNumber->GetStyleID() != NUMCHAR_other)
196 : {
197 9 : rtl::OUString aPrefix;
198 9 : XFNumFmt aFmt;
199 9 : if (aParaNumbering.pPrefix)
200 : {
201 0 : aPrefix += aParaNumbering.pPrefix->GetText();
202 : }
203 :
204 9 : rtl::OUString aNumber = LwpSilverBullet::GetNumCharByStyleID(pParaNumber);
205 9 : if (pParaNumber->GetStyleID() == NUMCHAR_01 || pParaNumber->GetStyleID() == NUMCHAR_Chinese4)
206 : {
207 0 : aPrefix += rtl::OUString("0");
208 : }
209 9 : aFmt.SetPrefix(aPrefix);
210 :
211 9 : aFmt.SetFormat(aNumber);
212 :
213 9 : if (aParaNumbering.pSuffix)
214 : {
215 0 : aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
216 : }
217 :
218 : //set numbering format into the style-list.
219 9 : pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
220 :
221 : }
222 : else
223 : {
224 0 : rtl::OUString aPrefix, aSuffix;
225 0 : if (aParaNumbering.pPrefix)
226 : {
227 0 : aPrefix = aParaNumbering.pPrefix->GetText();
228 : }
229 0 : if (aParaNumbering.pSuffix)
230 : {
231 0 : aSuffix = aParaNumbering.pSuffix->GetText();
232 : }
233 :
234 0 : pListStyle->SetListBullet(nPos, LwpSilverBullet::GetNumCharByStyleID(pParaNumber).toChar(),
235 0 : rtl::OUString("Times New Roman"), aPrefix, aSuffix);
236 : }
237 :
238 9 : pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
239 : }
240 1 : aStyleName = pXFStyleMgr->AddStyle(pListStyle)->GetStyleName();
241 : }
242 :
243 : }
244 :
245 1 : m_vStyleNameList.push_back(aStyleName);
246 1 : return aStyleName;
247 :
248 : }
249 :
250 : #include "xfilter/xflistitem.hxx"
251 : //Create nested XFList and XFItems and then add it to XFContentContainer(pCont)
252 : //Return the inner XFItem created.
253 5 : XFContentContainer* LwpBulletStyleMgr::AddBulletList(
254 : XFContentContainer* pCont, sal_Bool bIsOrdered,
255 : const rtl::OUString& rStyleName, sal_Int16 nLevel, sal_Bool bIsBulletSkiped)
256 : {
257 : assert(nLevel>0);
258 :
259 5 : m_bIsBulletSkipped = bIsBulletSkiped;
260 :
261 : //todo: need judge here.
262 5 : sal_Bool bContinue = m_bContinue;
263 :
264 : XFList* theList;
265 5 : XFList* prevList = NULL;
266 : XFListItem* theItem;
267 5 : XFListItem* InnerItem = NULL;
268 18 : for (sal_Int8 nC = nLevel-1; nC >= 0; nC--)
269 : {
270 13 : theList = new XFList();
271 13 : theItem = new XFListItem();
272 13 : theList->Add(theItem);
273 :
274 13 : if (bIsOrdered)
275 : {
276 13 : theList->SetOrdered(sal_True);
277 : }
278 : else
279 : {
280 0 : bContinue = sal_False;
281 0 : theList->SetOrdered(sal_False);
282 : }
283 :
284 13 : if (nC == nLevel-1)
285 : {
286 5 : theList->SetContinueNumber(bContinue);
287 : }
288 : //Add the outer list to pCont
289 13 : if (nC == 0)
290 : {
291 5 : theList->SetStyleName(rStyleName);
292 5 : pCont->Add(theList);
293 : }
294 :
295 13 : if ((nC == nLevel-1) && bIsBulletSkiped)
296 : {
297 0 : theItem->SetIsHeader(sal_True);
298 :
299 0 : theList->SetContinueNumber(sal_True);
300 : // end of add
301 : }
302 :
303 13 : if(nC == nLevel-1)
304 : {
305 5 : InnerItem = theItem;
306 : }
307 :
308 13 : if(prevList)
309 : {
310 8 : theItem->Add(prevList);
311 : }
312 13 : prevList = theList;
313 : }
314 5 : return InnerItem;
315 : }
316 :
317 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|