fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / lotuswordpro / source / filter / lwpsilverbullet.cxx
blob27dedc07351240164f086567528701a3ee08d714
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), m_pAtomHolder(new LwpAtomHolder), m_pBulletPara(NULL)
79 LwpSilverBullet::~LwpSilverBullet()
81 if (m_pAtomHolder)
83 delete m_pAtomHolder;
87 void LwpSilverBullet::Read()
89 LwpDLNFVList::Read();
91 m_nFlags = m_pObjStrm->QuickReaduInt16();
92 m_aStory.ReadIndexed(m_pObjStrm);
94 sal_uInt16 nNumPos = m_pObjStrm->QuickReaduInt16();
96 for (sal_uInt8 nC = 0; nC < nNumPos; nC++)
97 m_pResetPositionFlags[nC] = m_pObjStrm->QuickReaduInt8();
99 m_nUseCount = m_pObjStrm->QuickReaduInt32();
101 m_pAtomHolder->Read(m_pObjStrm);
105 * @short: Register bullet or numbering style-list and store the returned
106 * name from XFStyleManager.
107 * @descr:
109 void LwpSilverBullet::RegisterStyle()
111 XFListStyle* pListStyle = new XFListStyle();
112 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
114 this->GetBulletPara();
116 if (this->IsBulletOrdered() && this->HasName())
118 //todo: find the flag in the file
119 sal_Bool bCumulative = sal_False;
121 for (sal_uInt8 nPos = 1; nPos < 10; nPos++)
123 ParaNumbering aParaNumbering;
124 //get numbering format according to the position.
125 m_pBulletPara->GetParaNumber(nPos, &aParaNumbering);
126 LwpFribParaNumber* pParaNumber = aParaNumbering.pParaNumber;
127 if (pParaNumber)
129 if (pParaNumber->GetStyleID() != NUMCHAR_other)
131 m_pHideLevels[nPos] = aParaNumbering.nNumLevel;
132 sal_uInt16 nDisplayLevel = this->GetDisplayLevel(nPos);
133 bCumulative = (sal_Bool)(nDisplayLevel > 1);
134 OUString aPrefix = this->GetAdditionalName(nPos);
136 XFNumFmt aFmt;
137 if (!bCumulative && aParaNumbering.pPrefix)
139 aFmt.SetPrefix(aPrefix + aParaNumbering.pPrefix->GetText());
142 aFmt.SetFormat(this->GetNumCharByStyleID(pParaNumber));
144 if (aParaNumbering.pSuffix)
146 aFmt.SetSuffix(aParaNumbering.pSuffix->GetText());
149 //set numbering format into the style-list.
150 pListStyle->SetListNumber(nPos, aFmt, pParaNumber->GetStart()+1);
152 if (bCumulative && nPos > 1)
154 pListStyle->SetDisplayLevel(nPos, nDisplayLevel);
158 else
160 OUString aPrefix, aSuffix;
161 if (aParaNumbering.pPrefix)
163 aPrefix = aParaNumbering.pPrefix->GetText();
165 if (aParaNumbering.pSuffix)
167 aSuffix = aParaNumbering.pSuffix->GetText();
170 pListStyle->SetListBullet(nPos, this->GetNumCharByStyleID(pParaNumber).toChar(),
171 OUString("Times New Roman"), aPrefix, aSuffix);
174 pListStyle->SetListPosition(nPos, 0.0, 0.635, 0.0);
175 aParaNumbering.clear();
180 //add style-list to style manager.
181 m_strStyleName = pXFStyleManager->AddStyle(pListStyle)->GetStyleName();
185 * @short: Get the font name of the bullet.
186 * @descr:
187 * @return: Font name of the bullet.
189 OUString LwpSilverBullet::GetBulletFontName()
191 OUString aEmpty;
193 //foundry has been set?
194 if (!m_pFoundry)
196 return aEmpty;
199 LwpFontManager* pFontMgr = m_pFoundry->GetFontManger();
200 if (!pFontMgr)
202 return aEmpty;
205 sal_uInt32 nBulletFontID = m_pBulletPara->GetBulletFontID();
206 sal_uInt16 nFinalFont = static_cast<sal_uInt16>((nBulletFontID >> 16) & 0xFFFF);
208 //final fontid is valid?
209 if (nFinalFont > 255 || nFinalFont == 0)
211 return aEmpty;
214 //get font name from font manager.
215 OUString aFontName = pFontMgr->GetNameByID(nBulletFontID);
217 return aFontName;
220 * @short: Get bullet character of the bullet vo_para.
221 * @descr:
222 * @return: An UChar32 bulle character.
224 UChar32 LwpSilverBullet::GetBulletChar()
226 OUString aBulletChar = m_pBulletPara->GetBulletChar();
228 return aBulletChar.toChar();
232 * @short: Get the LwpPara object through story id.
234 LwpPara* LwpSilverBullet::GetBulletPara()
236 if (!m_pBulletPara)
238 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY));
239 if (!pStory)
241 return NULL;
244 m_pBulletPara = dynamic_cast<LwpPara*>(pStory->GetFirstPara()->obj(VO_PARA));
247 return m_pBulletPara;
251 * @short: Get numbering character of the bullet vo_para.
252 * @descr:
253 * @param: pParaNumber a pionter to the structure LwpFribParaNumber which
254 * includes numbering prefix, format and suffix.
255 * @return: An OUString object which store the numbering character.
257 OUString LwpSilverBullet::GetNumCharByStyleID(LwpFribParaNumber* pParaNumber)
259 OUString aEmpty;
261 if (!pParaNumber)
263 assert(false);
264 return aEmpty;
267 OUString strNumChar("1");
268 sal_uInt16 nStyleID = pParaNumber->GetStyleID();
269 UChar32 uC = 0x0000;
271 switch (nStyleID)
273 case NUMCHAR_1:
274 case NUMCHAR_01:
275 case NUMCHAR_Chinese4:
276 strNumChar = OUString("1");
277 break;
278 case NUMCHAR_A :
279 strNumChar = OUString("A");
280 break;
281 case NUMCHAR_a:
282 strNumChar = OUString("a");
283 break;
284 case NUMCHAR_I:
285 strNumChar = OUString("I");
286 break;
287 case NUMCHAR_i:
288 strNumChar = OUString("i");
289 break;
290 case NUMCHAR_other:
291 uC = static_cast<UChar32>(pParaNumber->GetNumberChar());
292 strNumChar = OUString(uC);
293 break;
294 case NUMCHAR_Chinese1:
296 sal_Unicode sBuf[13] = {0x58f9,0x002c,0x0020,0x8d30,0x002c,0x0020,0x53c1,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
297 strNumChar = OUString(sBuf);
299 break;
300 case NUMCHAR_Chinese2:
302 sal_Unicode sBuf[13] = {0x4e00,0x002c,0x0020,0x4e8c,0x002c,0x0020,0x4e09,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
303 strNumChar = OUString(sBuf);
305 break;
306 case NUMCHAR_Chinese3:
308 sal_Unicode sBuf[13] = {0x7532,0x002c,0x0020,0x4e59,0x002c,0x0020,0x4e19,0x002c,0x0020,0x002e,0x002e,0x002e,0x0};
309 strNumChar = OUString(sBuf);
311 break;
312 case NUMCHAR_none:
313 strNumChar = aEmpty;
314 break;
315 default:
316 break;
317 }//mod end
318 return strNumChar;
322 * @short: To judge the silverbullet list is ordered or not.
323 * @descr:
324 * @return: sal_True if list is ordered, sal_False if list is unordered.
326 sal_Bool LwpSilverBullet::IsBulletOrdered()
328 if (!m_pBulletPara)
329 return sal_False;
331 LwpFribPtr* pFribs = m_pBulletPara->GetFribs();
333 if (!pFribs)
334 return sal_False;
336 return (sal_Bool)(pFribs->HasFrib(FRIB_TAG_PARANUMBER) != NULL);
340 * @short: Calculate the displaylevel according to the position and hidelevels.
341 * @descr:
342 * @param: nPos position of the numbering.
343 * @return: displaylevel of the position passed in.
345 sal_uInt16 LwpSilverBullet::GetDisplayLevel(sal_uInt8 nPos)
347 if (nPos > 1)
349 sal_uInt16 nHideBit = (1 << nPos);
350 for (sal_uInt8 nC = nPos-1; nC > 0; nC--)
352 sal_uInt16 nAttrMask = ~m_pHideLevels[nC];
353 if (!(nAttrMask & nHideBit))
355 return static_cast<sal_uInt16>(nPos - nC);
360 return static_cast<sal_uInt16>(nPos);
364 * @descr: Get the additional information, "Division name" or "Section Name" from document
365 * variable frib according to numbering position. Whether we should add a
366 * Division/Section name or not is determined by the hidelevels of the frib.
367 * @param: nPos position of the numbering.
368 * @return: Division or Section name.
370 OUString LwpSilverBullet::GetAdditionalName(sal_uInt8 nPos)
372 OUString aRet, aEmpty;
373 sal_uInt16 nHideBit = (1 << nPos);
374 sal_Bool bDivisionName = sal_False;
375 sal_Bool bSectionName = sal_False;
377 LwpFrib* pParaFrib = m_pBulletPara->GetFribs()->GetFribs();
378 if (!pParaFrib)
380 return aEmpty;
383 while (pParaFrib)
385 if (pParaFrib->GetType() == FRIB_TAG_DOCVAR)
387 ModifierInfo* pMoInfo = pParaFrib->GetModifiers();
388 if (!pMoInfo)
390 return aEmpty;
392 sal_uInt16 nHideLevels = pMoInfo->aTxtAttrOverride.GetHideLevels();
393 sal_uInt16 nType = static_cast<LwpFribDocVar*>(pParaFrib)->GetType();
395 if (~nHideLevels & nHideBit)
397 if (nType == 0x000D)
399 bDivisionName = sal_True;
401 else if (nType == 0x000E)
403 bSectionName= sal_True;
407 pParaFrib = pParaFrib->GetNext();
410 if (bDivisionName)
412 aRet += this->GetDivisionName();
414 if (bSectionName)
416 aRet += this->GetSectionName();
419 return aRet;
422 OUString LwpSilverBullet::GetDivisionName()
424 OUString aRet;
426 if (!m_pFoundry)
428 return aRet;
431 LwpDocument* pDoc = m_pFoundry->GetDocument();
432 if (pDoc)
434 LwpObjectID* pID = pDoc->GetDivInfoID();
435 if (!pID->IsNull())
437 LwpDivInfo *pInfo = dynamic_cast<LwpDivInfo*>(pID->obj(VO_DIVISIONINFO));
438 if (pInfo)
439 aRet = pInfo->GetDivName();
443 return aRet;
446 OUString LwpSilverBullet::GetSectionName()
448 OUString aEmpty;
449 LwpStory* pStory = dynamic_cast<LwpStory*>(m_aStory.obj(VO_STORY));
450 if (!pStory)
452 return aEmpty;
455 return pStory->GetSectionName();
458 sal_Bool LwpSilverBullet::HasName()
460 LwpAtomHolder* pName = this->GetName();
461 if (pName)
463 return (sal_Bool)(!pName->str().isEmpty());
465 else
467 return sal_False;
470 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */