Bump version to 4.3-4
[LibreOffice.git] / lotuswordpro / source / filter / lwpsilverbullet.cxx
blob8aad25581ec9840ce1eba8c7ea1b2317c70b61b7
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 "lwpglobalmgr.hxx"
65 #include "lwpsilverbullet.hxx"
66 #include "lwpdoc.hxx"
67 #include "lwpdivinfo.hxx"
68 #include "lwpfoundry.hxx"
69 #include "lwpstory.hxx"
70 #include "lwppara.hxx"
71 #include "xfilter/xfliststyle.hxx"
72 #include "xfilter/xfstylemanager.hxx"
74 LwpSilverBullet::LwpSilverBullet(LwpObjectHeader& objHdr, LwpSvStream* pStrm)
75 : LwpDLNFVList(objHdr, pStrm)
76 , m_nFlags(0)
77 , m_nUseCount(0)
78 , m_pAtomHolder(new LwpAtomHolder)
79 , m_pBulletPara(NULL)
83 LwpSilverBullet::~LwpSilverBullet()
85 if (m_pAtomHolder)
87 delete m_pAtomHolder;
91 void LwpSilverBullet::Read()
93 LwpDLNFVList::Read();
95 m_nFlags = m_pObjStrm->QuickReaduInt16();
96 m_aStory.ReadIndexed(m_pObjStrm);
98 sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
100 for (sal_uInt8 nC = 0; nC < nNumPos; nC++)
101 m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
103 m_nUseCount = m_pObjStrm->QuickReaduInt32();
105 m_pAtomHolder->Read(m_pObjStrm);
109 * @short: Register bullet or numbering style-list and store the returned
110 * name from XFStyleManager.
111 * @descr:
113 void LwpSilverBullet::RegisterStyle()
115 XFListStyle* pListStyle = new XFListStyle();
116 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
118 this->GetBulletPara();
120 if (this->IsBulletOrdered() && this->HasName())
122 //todo: find the flag in the file
123 bool bCumulative = false;
125 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
127 ParaNumbering aParaNumbering;
128 //get numbering format according to the position.
129 m_pBulletPara->GetParaNumber(nPos, &aParaNumbering);
130 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
131 if (pParaNumber)
133 if (pParaNumber->GetStyleID() != NUMCHAR_other)
135 m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
136 sal_uInt16 nDisplayLevel = this->GetDisplayLevel(nPos);
137 bCumulative = (nDisplayLevel > 1);
138 OUString aPrefix = this->GetAdditionalName(nPos);
140 XFNumFmt aFmt;
141 if (!bCumulative && aParaNumbering.pPrefix)
143 aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
146 aFmt.SetFormat(this->GetNumCharByStyleID(pParaNumber));
148 if (aParaNumbering.pSuffix)
150 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
153 //set numbering format into the style-list.
154 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
156 if (bCumulative && nPos > 1)
158 pListStyle->SetDisplayLevel(nPos, nDisplayLevel);
162 else
164 OUString aPrefix, aSuffix;
165 if (aParaNumbering.pPrefix)
167 aPrefix = aParaNumbering.pPrefix->GetText();
169 if (aParaNumbering.pSuffix)
171 aSuffix = aParaNumbering.pSuffix->GetText();
174 pListStyle->SetListBullet(nPos, this->GetNumCharByStyleID(pParaNumber).toChar(),
175 "Times New Roman", aPrefix, aSuffix);
178 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
179 aParaNumbering.clear();
184 //add style-list to style manager.
185 m_strStyleName = pXFStyleManager->AddStyle(pListStyle)->GetStyleName();
189 * @short: Get the font name of the bullet.
190 * @descr:
191 * @return: Font name of the bullet.
193 OUString LwpSilverBullet::GetBulletFontName()
195 OUString aEmpty;
197 //foundry has been set?
198 if (!m_pFoundry)
200 return aEmpty;
203 LwpFontManager* pFontMgr = m_pFoundry->GetFontManger();
204 if (!pFontMgr)
206 return aEmpty;
209 sal_uInt32 nBulletFontID = m_pBulletPara->GetBulletFontID();
210 sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
212 //final fontid is valid?
213 if (nFinalFont > 255 || nFinalFont == 0)
215 return aEmpty;
218 //get font name from font manager.
219 OUString aFontName = pFontMgr->GetNameByID(nBulletFontID);
221 return aFontName;
224 * @short: Get bullet character of the bullet vo_para.
225 * @descr:
226 * @return: An UChar32 bulle character.
228 UChar32 LwpSilverBullet::GetBulletChar()
230 OUString aBulletChar = m_pBulletPara->GetBulletChar();
232 return aBulletChar.toChar();
236 * @short: Get the LwpPara object through story id.
238 LwpPara* LwpSilverBullet::GetBulletPara()
240 if (!m_pBulletPara)
242 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY));
243 if (!pStory)
245 return NULL;
248 m_pBulletPara = dynamic_cast<LwpPara*>(pStory->GetFirstPara()->obj(VO_PARA));
251 return m_pBulletPara;
255 * @short: Get numbering character of the bullet vo_para.
256 * @descr:
257 * @param: pParaNumber a pionter to the structure LwpFribParaNumber which
258 * includes numbering prefix, format and suffix.
259 * @return: An OUString object which store the numbering character.
261 OUString LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber* pParaNumber)
263 OUString aEmpty;
265 if (!pParaNumber)
267 assert(false);
268 return aEmpty;
271 OUString strNumChar("1");
272 sal_uInt16 nStyleID = pParaNumber->GetStyleID();
273 UChar32 uC = 0x0000;
275 switch (nStyleID)
277 case NUMCHAR_1:
278 case NUMCHAR_01:
279 case NUMCHAR_Chinese4:
280 strNumChar = "1";
281 break;
282 case NUMCHAR_A :
283 strNumChar = "A";
284 break;
285 case NUMCHAR_a:
286 strNumChar = "a";
287 break;
288 case NUMCHAR_I:
289 strNumChar = "I";
290 break;
291 case NUMCHAR_i:
292 strNumChar = "i";
293 break;
294 case NUMCHAR_other:
295 uC = static_cast<UChar32>(pParaNumber->GetNumberChar());
296 strNumChar = OUString(uC);
297 break;
298 case NUMCHAR_Chinese1:
300 sal_Unicode sBuf[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
301 strNumChar = OUString(sBuf);
303 break;
304 case NUMCHAR_Chinese2:
306 sal_Unicode sBuf[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
307 strNumChar = OUString(sBuf);
309 break;
310 case NUMCHAR_Chinese3:
312 sal_Unicode sBuf[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
313 strNumChar = OUString(sBuf);
315 break;
316 case NUMCHAR_none:
317 strNumChar = aEmpty;
318 break;
319 default:
320 break;
321 }//mod end
322 return strNumChar;
326 * @short: To judge the silverbullet list is ordered or not.
327 * @descr:
328 * @return: sal_True if list is ordered, sal_False if list is unordered.
330 bool LwpSilverBullet::IsBulletOrdered()
332 if (!m_pBulletPara)
333 return false;
335 LwpFribPtr* pFribs = m_pBulletPara->GetFribs();
337 if (!pFribs)
338 return false;
340 return (pFribs->HasFrib(FRIB_TAG_PARANUMBER) != NULL);
344 * @short: Calculate the displaylevel according to the position and hidelevels.
345 * @descr:
346 * @param: nPos position of the numbering.
347 * @return: displaylevel of the position passed in.
349 sal_uInt16 LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos)
351 if (nPos > 1)
353 sal_uInt16 nHideBit = (1 << nPos);
354 for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
356 sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
357 if (!(nAttrMask & nHideBit))
359 return static_cast<sal_uInt16>(nPos - nC);
364 return static_cast<sal_uInt16>(nPos);
368 * @descr: Get the additional information, "Division name" or "Section Name" from document
369 * variable frib according to numbering position. Whether we should add a
370 * Division/Section name or not is determined by the hidelevels of the frib.
371 * @param: nPos position of the numbering.
372 * @return: Division or Section name.
374 OUString LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos)
376 OUString aRet, aEmpty;
377 sal_uInt16 nHideBit = (1 << nPos);
378 bool bDivisionName = false;
379 bool bSectionName = false;
381 LwpFrib* pParaFrib = m_pBulletPara->GetFribs()->GetFribs();
382 if (!pParaFrib)
384 return aEmpty;
387 while (pParaFrib)
389 if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
391 ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
392 if (!pMoInfo)
394 return aEmpty;
396 sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
397 sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
399 if (~nHideLevels & nHideBit)
401 if (nType == 0x000D)
403 bDivisionName = true;
405 else if (nType == 0x000E)
407 bSectionName= true;
411 pParaFrib = pParaFrib->GetNext();
414 if (bDivisionName)
416 aRet += this->GetDivisionName();
418 if (bSectionName)
420 aRet += this->GetSectionName();
423 return aRet;
426 OUString LwpSilverBullet::GetDivisionName()
428 OUString aRet;
430 if (!m_pFoundry)
432 return aRet;
435 LwpDocument* pDoc = m_pFoundry->GetDocument();
436 if (pDoc)
438 LwpObjectID* pID = pDoc->GetDivInfoID();
439 if (!pID->IsNull())
441 LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(pID->obj(VO_DIVISIONINFO));
442 if (pInfo)
443 aRet = pInfo->GetDivName();
447 return aRet;
450 OUString LwpSilverBullet::GetSectionName()
452 OUString aEmpty;
453 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY));
454 if (!pStory)
456 return aEmpty;
459 return pStory->GetSectionName();
462 bool LwpSilverBullet::HasName()
464 LwpAtomHolder* pName = this->GetName();
465 if (pName)
467 return (!pName->str().isEmpty());
469 else
471 return false;
474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */