bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwptoc.cxx
blobef4af4549ca3aa70e4cc0ec1fd9969bd6788309a
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 - TOC related object
60 /*************************************************************************
61 * Change History
62 April 2005 Created
63 April 2005 Modified
64 April 2005 Modified - add LwpTocLevelData class
65 ************************************************************************/
66 #include "lwptoc.hxx"
67 #include "lwpfoundry.hxx"
68 #include "lwpdoc.hxx"
69 #include "lwpframelayout.hxx"
70 #include "lwpglobalmgr.hxx"
72 #include "xfilter/xffont.hxx"
73 #include "xfilter/xftextstyle.hxx"
74 #include "xfilter/xfstylemanager.hxx"
75 #include "xfilter/xfparagraph.hxx"
76 #include "xfilter/xfparastyle.hxx"
77 #include "xfilter/xfindex.hxx"
78 #include "xfilter/xffloatframe.hxx"
79 #include "xfilter/xfframestyle.hxx"
80 #include "xfilter/xfframe.hxx"
81 #include "xfilter/xftable.hxx"
83 LwpTocSuperLayout::LwpTocSuperLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
84 : LwpSuperTableLayout(objHdr, pStrm)
87 LwpTocSuperLayout::~LwpTocSuperLayout()
89 /**
90 * @short Read TOCSUPERTABLELAYOUT object
91 * @return none
93 void LwpTocSuperLayout::Read()
95 LwpSuperTableLayout::Read();
96 m_TextMarker.Read(m_pObjStrm);
97 m_ParentName.Read(m_pObjStrm);
98 m_DivisionName.Read(m_pObjStrm);
99 m_SectionName.Read(m_pObjStrm);
100 m_nFrom = m_pObjStrm->QuickReaduInt16();
102 m_SearchItems.Read(m_pObjStrm);
104 sal_uInt16 i;
105 sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
106 for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
107 m_DestName[i].Read(m_pObjStrm);
109 count = m_pObjStrm->QuickReaduInt16();
110 for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
111 m_DestPGName[i].Read(m_pObjStrm);
113 count = m_pObjStrm->QuickReaduInt16();
114 for (i = 0; i < count; i++)
115 m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
117 m_pObjStrm->SkipExtra();
120 * @short Register style of TOC
121 * @return none
123 void LwpTocSuperLayout::RegisterStyle()
125 LwpSuperTableLayout::RegisterStyle();
127 // Get font info of default text style and set into tab style
128 XFParaStyle* pBaseStyle = static_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*m_pFoundry->GetDefaultTextStyle()));
129 XFTextStyle*pTextStyle = new XFTextStyle;
130 pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
131 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
132 m_TabStyleName = pXFStyleManager->AddStyle(pTextStyle)->GetStyleName();
136 * @short Convert TOC
137 * @param pCont - container
138 * @return none
140 void LwpTocSuperLayout::XFConvert(XFContentContainer* pCont)
142 XFIndex* pToc = new XFIndex();
144 pToc->SetProtected(sal_False);
145 pToc->SetIndexType(enumXFIndexTOC);
147 // add TOC template
148 for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
150 LwpTocLevelData * pLevel = GetSearchLevelPtr(i);
151 XFIndexTemplate * pTemplate = new XFIndexTemplate();
153 if(!pLevel)
155 // add an blank template so that SODC won't add default style to this level
156 pToc->AddTemplate(Int32ToOUString(i), OUString(), pTemplate);
157 continue;
160 sal_Bool bInserted = sal_False;
163 // One level has 1 template
164 if (!bInserted)
166 pTemplate->SetLevel(Int32ToOUString(i));
167 if(pLevel->GetUseLeadingText())
169 pTemplate->AddEntry(enumXFIndexTemplateChapter, pLevel->GetSearchStyle());
171 if(pLevel->GetUseText())
173 pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
175 if(GetUsePageNumber(i))
177 sal_uInt16 nLeaderType = GetSeparatorType(i);
178 if (GetRightAlignPageNumber(i))
180 char cSep = ' ';
181 switch(nLeaderType)
183 default: // go through
184 case NONE: // no leaders
185 cSep = ' ';
186 break;
187 case LEADERDOTS:
188 cSep = '.';
189 break;
190 case LEADERDASHES:
191 cSep = '-';
192 break;
193 case LEADERUNDERLINE:
194 cSep = '_';
195 break;
198 pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
200 else
202 char sSep[8];
203 switch(nLeaderType)
205 default: // go through
206 case NONE: // no leaders
207 strcpy(sSep, " ");
208 break;
209 case SEPARATORCOMMA:
210 strcpy(sSep, ", ");
211 break;
212 case SEPARATORDOTS:
213 strcpy(sSep, "...");
214 break;
216 pTemplate->AddTextEntry(A2OUSTR(sSep), m_TabStyleName);
218 //"TOC Page Number Text Style" style always exists in Word Pro file
219 pTemplate->AddEntry(enumXFIndexTemplatePage, A2OUSTR("TOC Page Number Text Style"));
222 pToc->AddTemplate(Int16ToOUString(i), m_pFoundry->FindActuralStyleName(pLevel->GetSearchStyle()), pTemplate);
223 bInserted = sal_True;
226 // 1 style in WordPro may be mapped to several styles in SODC
227 LwpDocument * pDocument = m_pFoundry->GetDocument()->GetRootDocument();
228 AddSourceStyle(pToc, pLevel, pDocument->GetFoundry());
230 // one level may have several corresponding Styles
231 pLevel = GetNextSearchLevelPtr(i, pLevel); // find next LwpTocLevelData which is same index
232 }while (pLevel != NULL);
235 m_pCont = pCont;
236 // add TOC content
237 LwpSuperTableLayout::XFConvert(pToc);
239 // if current TOC is located in a cell, we must add a frame between upper level container and TOC
240 if ( !GetContainerLayout()->IsCell() )
242 pCont->Add(pToc);
247 * @short convert frame which anchor to page
248 * @param pCont -
249 * @return
251 void LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd , sal_Bool bAll)
253 if(m_pFrame)
255 XFFrame* pXFFrame = NULL;
256 if(nEnd < nStart)
258 pXFFrame = new XFFrame();
260 else
262 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
265 m_pFrame->Parse(pXFFrame, static_cast<sal_uInt16>(nStart));
267 //parse table, and add table to frame or TOC
268 LwpTableLayout * pTableLayout = GetTableLayout();
269 if (pTableLayout)
271 XFContentContainer * pTableContainer = pXFFrame;
272 // if *this is a TOCSuperTableLayout and it's located in a cell
273 // add the frame to upper level and add TOCSuperTableLayout into the frame
274 if ( GetContainerLayout()->IsCell() )
276 pTableContainer = pCont; // TOC contain table directly
277 pXFFrame->Add(pCont);
278 m_pCont->Add(pXFFrame);
280 else
282 //add frame to the container
283 pCont ->Add(pXFFrame);
285 pTableLayout->XFConvert(pTableContainer);
292 * @short Add source style into TOC
293 * @param pToc - TOC pointer
294 * @param pLevel - TOC level data
295 * @param pFoundry - foundry pointer
296 * @return sal_Bool
298 void LwpTocSuperLayout::AddSourceStyle(XFIndex* pToc, LwpTocLevelData * pLevel, LwpFoundry * pFoundry)
300 if (!pLevel)
302 return;
305 OUString sLwpStyleName = pLevel->GetSearchStyle();
307 if (pFoundry)
309 LwpDocument * pDoc = pFoundry->GetDocument();
310 if (pDoc && pDoc->IsChildDoc())
312 OUString sSodcStyleName = pFoundry->FindActuralStyleName(sLwpStyleName);
313 pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
315 else
317 pDoc = pDoc->GetFirstDivision();
318 while (pDoc)
320 AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
321 pDoc = pDoc->GetNextDivision();
328 * @short Get whether page number is right alignment
329 * @param index - TOC level
330 * @return sal_Bool
332 sal_Bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index)
334 if (index < MAX_LEVELS)
335 return (m_nFlags[index] & TS_RIGHTALIGN) ? sal_True : sal_False;
336 return sal_False;
339 * @short Get whether page number is used in TOC entries
340 * @param index - TOC level
341 * @return sal_Bool
343 sal_Bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index)
345 if (index < MAX_LEVELS)
346 return (m_nFlags[index] & TS_PAGENUMBER) ? sal_True : sal_False;
347 return sal_False;
350 * @short Get what is used for separater
351 * @param index - TOC level
352 * @return sal_uInt16 - separator type
354 sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
356 sal_uInt16 Flag = (sal_uInt16)m_nFlags[index];
358 if (Flag & TS_LEADERDOTS)
359 return LEADERDOTS;
360 else if (Flag & TS_LEADERDASHES)
361 return LEADERDASHES;
362 else if (Flag & TS_LEADERUNDERLINE)
363 return LEADERUNDERLINE;
364 else if (Flag & TS_SEPARATORCOMMA)
365 return SEPARATORCOMMA;
366 else if (Flag & TS_SEPARATORDOTS)
367 return SEPARATORDOTS;
368 else
369 return NONE;
373 * @short Get TOCLEVELDATA obj
374 * @param index - TOC level
375 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
377 LwpTocLevelData * LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index)
379 LwpObjectID * pID = m_SearchItems.GetHead(); // not necessary to check pID NULL or not
380 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
382 while(pObj)
384 if(pObj->GetLevel()== index)
386 return pObj;
389 pID = pObj->GetNext(); // not necessary to check pID NULL or not
390 pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
393 return NULL;
396 * @short Get next TOCLEVELDATA obj from current position
397 * @param index - TOC level
398 * @param pCurData - current LwpTocLevelData
399 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
401 LwpTocLevelData * LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData * pCurData)
403 LwpObjectID * pID = pCurData->GetNext();
404 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
406 while(pObj)
408 if(pObj->GetLevel()== index)
410 return pObj;
413 pID = pObj->GetNext(); // not necessary to check pID NULL or not
414 pObj = dynamic_cast<LwpTocLevelData *>(pID->obj());
417 return NULL;
420 LwpTocLevelData::LwpTocLevelData(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpDLVList(objHdr, pStrm)
422 m_nFlags = 0;
423 m_nLevel = 0;
425 LwpTocLevelData::~LwpTocLevelData()
429 * @short Register style
430 * @param
431 * @return
433 void LwpTocLevelData::RegisterStyle()
437 * @short Convert
438 * @param pCont - container
439 * @return none
441 void LwpTocLevelData::XFConvert(XFContentContainer* /*pCont*/)
445 * @short Read TOCLEVELDATA obj
446 * @param
447 * @return
449 void LwpTocLevelData::Read()
451 LwpDLVList::Read();
452 m_nFlags = m_pObjStrm->QuickReaduInt16();
453 m_nLevel = m_pObjStrm->QuickReaduInt16();
454 m_SearchName.Read(m_pObjStrm);
456 m_pObjStrm->SkipExtra();
459 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */