LibreOffice Module lotuswordpro (master) 1
lwptoc.cxx
Go to the documentation of this file.
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 ************************************************************************/
61#include "lwptoc.hxx"
62#include <lwpfoundry.hxx>
63#include "lwpdoc.hxx"
64#include "lwpframelayout.hxx"
65#include <lwpglobalmgr.hxx>
66
70#include <xfilter/xfindex.hxx>
72#include <xfilter/xfframe.hxx>
73
75 : LwpSuperTableLayout(objHdr, pStrm)
76 , m_nFrom(0)
77 , m_pCont(nullptr)
78{
79}
80
82{
83}
84
90{
96 m_nFrom = m_pObjStrm->QuickReaduInt16();
97
99
100 sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
101 if (count > MAX_LEVELS)
102 throw std::range_error("corrupt LwpTocSuperLayout");
103 for (sal_uInt16 i = 0; i < count; ++i)
104 m_DestName[i].Read(m_pObjStrm.get());
105
106 count = m_pObjStrm->QuickReaduInt16();
107 if (count > MAX_LEVELS)
108 throw std::range_error("corrupt LwpTocSuperLayout");
109 for (sal_uInt16 i = 0; i < count; ++i)
111
112 count = m_pObjStrm->QuickReaduInt16();
113 if (count > MAX_LEVELS)
114 throw std::range_error("corrupt LwpTocSuperLayout");
115 for (sal_uInt16 i = 0; i < count; ++i)
116 m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
117
118 m_pObjStrm->SkipExtra();
119}
125{
127
128 // Get font info of default text style and set into tab style
129 const LwpObjectID *pDefaultTextStyle = m_pFoundry ? m_pFoundry->GetDefaultTextStyle() : nullptr;
130 XFParaStyle* pBaseStyle = pDefaultTextStyle ? dynamic_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*pDefaultTextStyle)) : nullptr;
131 std::unique_ptr<XFTextStyle> pTextStyle(new XFTextStyle);
132 if (pBaseStyle)
133 pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
135 m_TabStyleName = pXFStyleManager->AddStyle(std::move(pTextStyle)).m_pStyle->GetStyleName();
136
137}
144{
146
147 xToc->SetProtected(false);
148 xToc->SetIndexType(enumXFIndexTOC);
149
150 // add TOC template
151 for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
152 {
154 XFIndexTemplate * pTemplate = new XFIndexTemplate();
155
156 if(!pLevel)
157 {
158 // add a blank template so that SODC won't add default style to this level
159 xToc->AddTemplate(OUString::number(i), OUString(), pTemplate);
160 continue;
161 }
162
163 bool bInserted = false;
164 do
165 {
166 // One level has 1 template
167 if (!bInserted)
168 {
169 pTemplate->SetLevel(OUString::number(i));
170 if(pLevel->GetUseLeadingText())
171 {
173 }
174 if(pLevel->GetUseText())
175 {
176 pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
177 }
179 {
180 sal_uInt16 nLeaderType = GetSeparatorType(i);
182 {
183 char cSep = ' ';
184 switch(nLeaderType)
185 {
186 default: // go through
187 case NONE: // no leaders
188 cSep = ' ';
189 break;
190 case LEADERDOTS:
191 cSep = '.';
192 break;
193 case LEADERDASHES:
194 cSep = '-';
195 break;
196 case LEADERUNDERLINE:
197 cSep = '_';
198 break;
199 }
200
201 pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
202 }
203 else
204 {
205 OUString sSep;
206 switch(nLeaderType)
207 {
208 default: // go through
209 case NONE: // no leaders
210 sSep = " ";
211 break;
212 case SEPARATORCOMMA:
213 sSep = ", ";
214 break;
215 case SEPARATORDOTS:
216 sSep = "...";
217 break;
218 }
219 pTemplate->AddTextEntry(sSep, m_TabStyleName);
220 }
221 //"TOC Page Number Text Style" style always exists in Word Pro file
222 pTemplate->AddEntry(enumXFIndexTemplatePage, "TOC Page Number Text Style");
223 }
224
225 xToc->AddTemplate(OUString::number(static_cast<sal_Int32>(i)), m_pFoundry->FindActualStyleName(pLevel->GetSearchStyle()), pTemplate);
226 bInserted = true;
227 }
228
229 // 1 style in WordPro may be mapped to several styles in SODC
231 AddSourceStyle(xToc.get(), pLevel, pDocument->GetFoundry());
232
233 // one level may have several corresponding Styles
234 pLevel = GetNextSearchLevelPtr(i, pLevel); // find next LwpTocLevelData which is same index
235 }while (pLevel != nullptr);
236 }
237
238 m_pCont = pCont;
239 // add TOC content
241
243 if (!xContainer.is())
244 return;
245
246 // if current TOC is located in a cell, we must add a frame between upper level container and TOC
247 if (!xContainer->IsCell())
248 {
249 pCont->Add(xToc.get());
250 }
251}
252
258void LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart, sal_Int32 nEnd, bool bAll)
259{
260 if (!m_pFrame)
261 return;
262
264 if(nEnd < nStart)
265 {
266 xXFFrame.set(new XFFrame);
267 }
268 else
269 {
270 xXFFrame.set(new XFFloatFrame(nStart, nEnd, bAll));
271 }
272
273 m_pFrame->Parse(xXFFrame.get(), static_cast<sal_uInt16>(nStart));
274
275 //parse table, and add table to frame or TOC
276 LwpTableLayout * pTableLayout = GetTableLayout();
277 if (!pTableLayout)
278 return;
279
280 XFContentContainer* pTableContainer = xXFFrame.get();
281 // if *this is a TOCSuperTableLayout and it's located in a cell
282 // add the frame to upper level and add TOCSuperTableLayout into the frame
284 if (!xContainer.is())
285 return;
286 if (xContainer->IsCell())
287 {
288 pTableContainer = pCont; // TOC contain table directly
289 xXFFrame->Add(pCont);
290 m_pCont->Add(xXFFrame.get());
291 }
292 else
293 {
294 //add frame to the container
295 pCont->Add(xXFFrame.get());
296 }
297 pTableLayout->XFConvert(pTableContainer);
298
299}
300
309{
310 if (!pLevel)
311 {
312 return;
313 }
314
315 OUString sLwpStyleName = pLevel->GetSearchStyle();
316
317 if (!pFoundry)
318 return;
319
320 LwpDocument * pDoc = pFoundry->GetDocument();
321 if (pDoc && pDoc->IsChildDoc())
322 {
323 OUString sSodcStyleName = pFoundry->FindActualStyleName(sLwpStyleName);
324 pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
325 }
326 else
327 {
328 pDoc = pDoc->GetFirstDivision();
329 while (pDoc)
330 {
331 AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
332 pDoc = pDoc->GetNextDivision();
333 }
334 }
335}
336
343{
344 if (index < MAX_LEVELS)
345 return (m_nFlags[index] & TS_RIGHTALIGN) != 0;
346 return false;
347}
354{
355 if (index < MAX_LEVELS)
356 return (m_nFlags[index] & TS_PAGENUMBER) != 0;
357 return false;
358}
364sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
365{
366 if (index >= MAX_LEVELS)
367 return NONE;
368
369 sal_uInt16 Flag = static_cast<sal_uInt16>(m_nFlags[index]);
370
371 if (Flag & TS_LEADERDOTS)
372 return LEADERDOTS;
373 else if (Flag & TS_LEADERDASHES)
374 return LEADERDASHES;
375 else if (Flag & TS_LEADERUNDERLINE)
376 return LEADERUNDERLINE;
377 else if (Flag & TS_SEPARATORCOMMA)
378 return SEPARATORCOMMA;
379 else if (Flag & TS_SEPARATORDOTS)
380 return SEPARATORDOTS;
381 else
382 return NONE;
383}
384
391{
392 LwpObjectID * pID = &m_SearchItems.GetHead(); // not necessary to check pID NULL or not
393 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
394
395 while(pObj)
396 {
397 if(pObj->GetLevel()== index)
398 {
399 return pObj;
400 }
401
402 pID = &pObj->GetNext(); // not necessary to check pID NULL or not
403 pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
404 }
405
406 return nullptr;
407}
415{
416 LwpObjectID * pID = &pCurData->GetNext();
417 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
418
419 while(pObj)
420 {
421 if(pObj->GetLevel()== index)
422 {
423 return pObj;
424 }
425
426 pID = &pObj->GetNext(); // not necessary to check pID NULL or not
427 pObj = dynamic_cast<LwpTocLevelData *>(pID->obj().get());
428 }
429
430 return nullptr;
431}
432
434 : LwpDLVList(objHdr, pStrm), m_nFlags(0), m_nLevel(0)
435{
436}
438{
439}
446{
447}
454{
455}
462{
464 m_nFlags = m_pObjStrm->QuickReaduInt16();
465 m_nLevel = m_pObjStrm->QuickReaduInt16();
467
468 m_pObjStrm->SkipExtra();
469}
470
471/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nLevel
virtual OUString GetStyleName()=0
@descr: return the style name.
void Read(LwpObjectStream *pStrm)
@descr read atomholder from object stream the default encoding used in Word Pro is 1252
LwpObjectID & GetHead()
Definition: lwpdlvlist.hxx:148
void Read(LwpObjectStream *pObjStrm)
@descr Read head id and tail id
Definition: lwpdlvlist.cxx:160
Double Linked Virtual List.
Definition: lwpdlvlist.hxx:72
void Read() override
@descr Read LwpDLVList data from object stream
Definition: lwpdlvlist.cxx:72
LwpObjectID & GetNext()
Definition: lwpdlvlist.hxx:75
Document object, represent document and division.
Definition: lwpdoc.hxx:76
LwpDocument * GetNextDivision()
@descr Get next division
Definition: lwpdoc.cxx:485
LwpFoundry * GetFoundry()
Definition: lwpdoc.hxx:182
bool IsChildDoc() const
Definition: lwpdoc.hxx:176
LwpDocument * GetRootDocument()
@descr Get root document
Definition: lwpdoc.cxx:637
LwpDocument * GetFirstDivision()
@descr Get first division
Definition: lwpdoc.cxx:626
OUString FindActualStyleName(const OUString &name)
@descr: Get style name registered according the original style name
Definition: lwpfoundry.cxx:288
LwpObjectID * GetDefaultTextStyle()
@descr: Get default text style id
Definition: lwpfoundry.cxx:253
LwpStyleManager * GetStyleManager()
Definition: lwpfoundry.hxx:262
LwpDocument * GetDocument()
Definition: lwpfoundry.hxx:254
XFStyleManager * GetXFStyleManager()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
virtual rtl::Reference< LwpVirtualLayout > GetContainerLayout() override
@descr get the layout that containers the current frame layout
Definition: lwplayout.cxx:1909
Base class of all Lwp VO objects.
Definition: lwpobjhdr.hxx:71
object id class
Definition: lwpobjid.hxx:79
rtl::Reference< LwpObject > obj(VO_TYPE tag=VO_INVALID) const
@descr get object from object factory per the object id
Definition: lwpobjid.cxx:183
LwpFoundry * m_pFoundry
Definition: lwpobj.hxx:91
virtual void RegisterStyle()
@descr default register style function
Definition: lwpobj.cxx:100
std::unique_ptr< LwpObjectStream > m_pObjStrm
Definition: lwpobj.hxx:90
IXFStyle * GetStyle(const LwpObjectID &styleObjID)
Definition: lwpfoundry.cxx:522
VO_SUPERTABLELAYOUT object.
void Read() override
Read super table layout record.
void XFConvert(XFContentContainer *pCont) override
Add table to container.
std::unique_ptr< LwpFrame > m_pFrame
LwpTableLayout * GetTableLayout()
Get child table layout.
encapsulate XInputStream to provide SvStream like interfaces
Definition: lwpsvstream.hxx:69
VO_TABLELAYOUT object and functions for registering styles and converting tables.
void XFConvert(XFContentContainer *pCont) override
Convert table.
VO_TOCLEVELDATA object.
Definition: lwptoc.hxx:145
bool GetUseText() const
Definition: lwptoc.hxx:156
void RegisterStyle() override
Register style.
Definition: lwptoc.cxx:445
sal_uInt16 m_nFlags
Definition: lwptoc.hxx:163
LwpAtomHolder m_SearchName
Definition: lwptoc.hxx:165
sal_uInt16 GetLevel() const
Definition: lwptoc.hxx:155
void Read() override
Read TOCLEVELDATA obj.
Definition: lwptoc.cxx:461
sal_uInt16 m_nLevel
Definition: lwptoc.hxx:164
virtual ~LwpTocLevelData() override
Definition: lwptoc.cxx:437
virtual void XFConvert(XFContentContainer *pCont) override
Convert.
Definition: lwptoc.cxx:453
bool GetUseLeadingText() const
Definition: lwptoc.hxx:158
LwpTocLevelData(LwpObjectHeader const &objHdr, LwpSvStream *pStrm)
Definition: lwptoc.cxx:433
OUString const & GetSearchStyle() const
Definition: lwptoc.hxx:157
LwpAtomHolder m_SectionName
Definition: lwptoc.hxx:129
XFContentContainer * m_pCont
Definition: lwptoc.hxx:138
virtual void XFConvertFrame(XFContentContainer *pCont, sal_Int32 nStart=0, sal_Int32 nEnd=0, bool bAll=false) override
convert frame which anchor to page
Definition: lwptoc.cxx:258
virtual ~LwpTocSuperLayout() override
Definition: lwptoc.cxx:81
sal_uInt16 m_nFrom
Definition: lwptoc.hxx:130
LwpAtomHolder m_DestName[MAX_LEVELS]
Definition: lwptoc.hxx:132
LwpAtomHolder m_ParentName
Definition: lwptoc.hxx:127
virtual void XFConvert(XFContentContainer *pCont) override
Convert TOC.
Definition: lwptoc.cxx:143
LwpTocSuperLayout(LwpObjectHeader const &objHdr, LwpSvStream *pStrm)
Definition: lwptoc.cxx:74
void RegisterStyle() override
Register style of TOC.
Definition: lwptoc.cxx:124
OUString m_TabStyleName
Definition: lwptoc.hxx:136
static LwpTocLevelData * GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData *pCurData)
Get next TOCLEVELDATA obj from current position.
Definition: lwptoc.cxx:414
LwpAtomHolder m_TextMarker
Definition: lwptoc.hxx:126
sal_uInt16 GetSeparatorType(sal_uInt16 index)
Get what is used for separator.
Definition: lwptoc.cxx:364
sal_uInt32 m_nFlags[MAX_LEVELS]
Definition: lwptoc.hxx:134
bool GetUsePageNumber(sal_uInt16 index)
Get whether page number is used in TOC entries.
Definition: lwptoc.cxx:353
LwpAtomHolder m_DestPGName[MAX_LEVELS]
Definition: lwptoc.hxx:133
LwpAtomHolder m_DivisionName
Definition: lwptoc.hxx:128
void AddSourceStyle(XFIndex *pToc, LwpTocLevelData *pLevel, LwpFoundry *pFoundry)
Add source style into TOC.
Definition: lwptoc.cxx:308
LwpDLVListHeadTail m_SearchItems
Definition: lwptoc.hxx:131
void Read() override
Read TOCSUPERTABLELAYOUT object.
Definition: lwptoc.cxx:89
bool GetRightAlignPageNumber(sal_uInt16 index)
Get whether page number is right alignment.
Definition: lwptoc.cxx:342
LwpTocLevelData * GetSearchLevelPtr(sal_uInt16 index)
Get TOCLEVELDATA obj.
Definition: lwptoc.cxx:390
A container for content.
virtual void Add(XFContent *pContent)
@descr Add content.
Floating frame on any page.
Base class for all frame object,include drawing,image,text-box.
Definition: xfframe.hxx:79
Index template.
Definition: xfindex.hxx:79
void AddEntry(enumXFIndexTemplate entry, const OUString &styleName)
@descr Add an entry in the template.
Definition: xfindex.hxx:198
void AddTabEntry(enumXFTab type, double len, sal_Unicode leader, sal_Unicode delimiter, const OUString &styleName)
@descr Add a tab entry in the template.
Definition: xfindex.hxx:204
void SetLevel(const OUString &level)
@descr Set template level.
Definition: xfindex.hxx:184
void AddTextEntry(const OUString &sSpan, const OUString &styleName)
@descr Add an entry in the template.
Definition: xfindex.hxx:214
Index, include index template, index body.
Definition: xfindex.hxx:134
void AddTocSource(sal_uInt16 nLevel, const OUString &sStyleName)
Definition: xfindex.cxx:93
Style object for aragraph.
Definition: xfparastyle.hxx:93
const rtl::Reference< XFFont > & GetFont() const
@descr get the font object.
Style manager for the filter.
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
sal_Int32 m_nFlags
int i
index
IXFStyle * m_pStyle
Definition: xfstylecont.hxx:71
@ enumXFIndexTOC
Definition: xfdefs.hxx:442
@ enumXFIndexTemplateText
Definition: xfdefs.hxx:454
@ enumXFIndexTemplateChapter
Definition: xfdefs.hxx:453
@ enumXFIndexTemplatePage
Definition: xfdefs.hxx:456
@ enumXFTabRight
Definition: xfdefs.hxx:234