update dev300-m57
[ooovba.git] / lotuswordpro / source / filter / lwptoc.cxx
blobe0d1b2b0a4b6b63ef9090982f090691fd49f3924
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /**
56 * @file
57 * For LWP filter architecture prototype - TOC related object
59 /*************************************************************************
60 * Change History
61 April 2005 Created
62 April 2005 Modified
63 April 2005 Modified - add LwpTocLevelData class
64 ************************************************************************/
65 #include "lwptoc.hxx"
66 #include "lwpfoundry.hxx"
67 #include "lwpdoc.hxx"
68 #include "lwpframelayout.hxx"
69 #include "lwpglobalmgr.hxx"
71 #include "xfilter/xffont.hxx"
72 #include "xfilter/xftextstyle.hxx"
73 #include "xfilter/xfstylemanager.hxx"
74 #include "xfilter/xfparagraph.hxx"
75 #include "xfilter/xfparastyle.hxx"
76 #include "xfilter/xfindex.hxx"
77 #include "xfilter/xffloatframe.hxx"
78 #include "xfilter/xfframestyle.hxx"
79 #include "xfilter/xfframe.hxx"
80 #include "xfilter/xftable.hxx"
82 LwpTocSuperLayout::LwpTocSuperLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
83 : LwpSuperTableLayout(objHdr, pStrm)
86 LwpTocSuperLayout::~LwpTocSuperLayout()
88 /**
89 * @short Read TOCSUPERTABLELAYOUT object
90 * @return none
92 void LwpTocSuperLayout::Read()
94 LwpSuperTableLayout::Read();
95 m_TextMarker.Read(m_pObjStrm);
96 m_ParentName.Read(m_pObjStrm);
97 m_DivisionName.Read(m_pObjStrm);
98 m_SectionName.Read(m_pObjStrm);
99 m_nFrom = m_pObjStrm->QuickReaduInt16();
101 m_SearchItems.Read(m_pObjStrm);
103 sal_uInt16 i;
104 sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
105 for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
106 m_DestName[i].Read(m_pObjStrm);
108 count = m_pObjStrm->QuickReaduInt16();
109 for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
110 m_DestPGName[i].Read(m_pObjStrm);
112 count = m_pObjStrm->QuickReaduInt16();
113 for (i = 0; i < count; i++)
114 m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
116 m_pObjStrm->SkipExtra();
119 * @short Register style of TOC
120 * @return none
122 void LwpTocSuperLayout::RegisterStyle()
124 LwpSuperTableLayout::RegisterStyle();
126 // Get font info of default text style and set into tab style
127 XFParaStyle* pBaseStyle = static_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*m_pFoundry->GetDefaultTextStyle()));
128 XFTextStyle*pTextStyle = new XFTextStyle;
129 pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
130 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
131 m_TabStyleName = pXFStyleManager->AddStyle(pTextStyle)->GetStyleName();
135 * @short Convert TOC
136 * @param pCont - container
137 * @return none
139 void LwpTocSuperLayout::XFConvert(XFContentContainer* pCont)
141 XFIndex* pToc = new XFIndex();
143 pToc->SetProtected(sal_False);
144 pToc->SetIndexType(enumXFIndexTOC);
146 // add TOC template
147 for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
149 LwpTocLevelData * pLevel = GetSearchLevelPtr(i);
150 XFIndexTemplate * pTemplate = new XFIndexTemplate();
152 if(!pLevel)
154 // add an blank template so that SODC won't add default style to this level
155 pToc->AddTemplate(Int32ToOUString(i), String::CreateFromAscii(""), pTemplate);
156 continue;
159 sal_Bool bInserted = sal_False;
162 // One level has 1 template
163 if (!bInserted)
165 pTemplate->SetLevel(Int32ToOUString(i));
166 if(pLevel->GetUseLeadingText())
168 pTemplate->AddEntry(enumXFIndexTemplateChapter, pLevel->GetSearchStyle());
170 if(pLevel->GetUseText())
172 pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
174 if(GetUsePageNumber(i))
176 sal_uInt16 nLeaderType = GetSeparatorType(i);
177 if (GetRightAlignPageNumber(i))
179 char cSep = ' ';
180 switch(nLeaderType)
182 default: // go through
183 case NONE: // no leaders
184 cSep = ' ';
185 break;
186 case LEADERDOTS:
187 cSep = '.';
188 break;
189 case LEADERDASHES:
190 cSep = '-';
191 break;
192 case LEADERUNDERLINE:
193 cSep = '_';
194 break;
197 pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
199 else
201 char sSep[8];
202 switch(nLeaderType)
204 default: // go through
205 case NONE: // no leaders
206 strcpy(sSep, " ");
207 break;
208 case SEPARATORCOMMA:
209 strcpy(sSep, ", ");
210 break;
211 case SEPARATORDOTS:
212 strcpy(sSep, "...");
213 break;
215 pTemplate->AddTextEntry(A2OUSTR(sSep), m_TabStyleName);
217 //"TOC Page Number Text Style" style always exists in Word Pro file
218 pTemplate->AddEntry(enumXFIndexTemplatePage, A2OUSTR("TOC Page Number Text Style"));
221 pToc->AddTemplate(Int16ToOUString(i), m_pFoundry->FindActuralStyleName(pLevel->GetSearchStyle()), pTemplate);
222 bInserted = sal_True;
225 // 1 style in WordPro may be mapped to several styles in SODC
226 LwpDocument * pDocument = m_pFoundry->GetDocument()->GetRootDocument();
227 AddSourceStyle(pToc, pLevel, pDocument->GetFoundry());
229 // one level may have several corresponding Styles
230 pLevel = GetNextSearchLevelPtr(i, pLevel); // find next LwpTocLevelData which is same index
231 }while (pLevel != NULL);
234 m_pCont = pCont;
235 // add TOC content
236 LwpSuperTableLayout::XFConvert(pToc);
238 // if current TOC is located in a cell, we must add a frame between upper level container and TOC
239 if ( !GetContainerLayout()->IsCell() )
241 pCont->Add(pToc);
246 * @short convert frame which anchor to page
247 * @param pCont -
248 * @return
250 void LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd , sal_Bool bAll)
252 if(m_pFrame)
254 XFFrame* pXFFrame = NULL;
255 if(nEnd < nStart)
257 pXFFrame = new XFFrame();
259 else
261 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
264 m_pFrame->Parse(pXFFrame, static_cast<sal_uInt16>(nStart));
266 //parse table, and add table to frame or TOC
267 LwpTableLayout * pTableLayout = GetTableLayout();
268 if (pTableLayout)
270 XFContentContainer * pTableContainer = pXFFrame;
271 // if *this is a TOCSuperTableLayout and it's located in a cell
272 // add the frame to upper level and add TOCSuperTableLayout into the frame
273 if ( GetContainerLayout()->IsCell() )
275 pTableContainer = pCont; // TOC contain table directly
276 pXFFrame->Add(pCont);
277 m_pCont->Add(pXFFrame);
279 else
281 //add frame to the container
282 pCont ->Add(pXFFrame);
284 pTableLayout->XFConvert(pTableContainer);
291 * @short Add source style into TOC
292 * @param pToc - TOC pointer
293 * @param pLevel - TOC level data
294 * @param pFoundry - foundry pointer
295 * @return sal_Bool
297 void LwpTocSuperLayout::AddSourceStyle(XFIndex* pToc, LwpTocLevelData * pLevel, LwpFoundry * pFoundry)
299 if (!pLevel)
301 return;
304 OUString sLwpStyleName = pLevel->GetSearchStyle();
306 if (pFoundry)
308 LwpDocument * pDoc = pFoundry->GetDocument();
309 if (pDoc && pDoc->IsChildDoc())
311 OUString sSodcStyleName = pFoundry->FindActuralStyleName(sLwpStyleName);
312 pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
314 else
316 pDoc = pDoc->GetFirstDivision();
317 while (pDoc)
319 AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
320 pDoc = pDoc->GetNextDivision();
327 * @short Get whether page number is right alignment
328 * @param index - TOC level
329 * @return sal_Bool
331 sal_Bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index)
333 if (index < MAX_LEVELS)
334 return (m_nFlags[index] & TS_RIGHTALIGN) ? sal_True : sal_False;
335 return sal_False;
338 * @short Get whether page number is used in TOC entries
339 * @param index - TOC level
340 * @return sal_Bool
342 sal_Bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index)
344 if (index < MAX_LEVELS)
345 return (m_nFlags[index] & TS_PAGENUMBER) ? sal_True : sal_False;
346 return sal_False;
349 * @short Get what is used for separater
350 * @param index - TOC level
351 * @return sal_uInt16 - separator type
353 sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
355 sal_uInt16 Flag = (sal_uInt16)m_nFlags[index];
357 if (Flag & TS_LEADERDOTS)
358 return LEADERDOTS;
359 else if (Flag & TS_LEADERDASHES)
360 return LEADERDASHES;
361 else if (Flag & TS_LEADERUNDERLINE)
362 return LEADERUNDERLINE;
363 else if (Flag & TS_SEPARATORCOMMA)
364 return SEPARATORCOMMA;
365 else if (Flag & TS_SEPARATORDOTS)
366 return SEPARATORDOTS;
367 else
368 return NONE;
372 * @short Get TOCLEVELDATA obj
373 * @param index - TOC level
374 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
376 LwpTocLevelData * LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index)
378 LwpObjectID * pID = m_SearchItems.GetHead(); // not necessary to check pID NULL or not
379 LwpTocLevelData * pObj = static_cast<LwpTocLevelData *>(pID->obj());
381 while(pObj)
383 if(pObj->GetLevel()== index)
385 return pObj;
388 pID = pObj->GetNext(); // not necessary to check pID NULL or not
389 pObj = static_cast<LwpTocLevelData *>(pID->obj());
392 return NULL;
395 * @short Get next TOCLEVELDATA obj from current position
396 * @param index - TOC level
397 * @param pCurData - current LwpTocLevelData
398 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
400 LwpTocLevelData * LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData * pCurData)
402 LwpObjectID * pID = pCurData->GetNext();
403 LwpTocLevelData * pObj = static_cast<LwpTocLevelData *>(pID->obj());
405 while(pObj)
407 if(pObj->GetLevel()== index)
409 return pObj;
412 pID = pObj->GetNext(); // not necessary to check pID NULL or not
413 pObj = static_cast<LwpTocLevelData *>(pID->obj());
416 return NULL;
419 LwpTocLevelData::LwpTocLevelData(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpDLVList(objHdr, pStrm)
421 m_nFlags = 0;
422 m_nLevel = 0;
424 LwpTocLevelData::~LwpTocLevelData()
428 * @short Register style
429 * @param
430 * @return
432 void LwpTocLevelData::RegisterStyle()
436 * @short Convert
437 * @param pCont - container
438 * @return none
440 void LwpTocLevelData::XFConvert(XFContentContainer* pCont)
444 * @short Read TOCLEVELDATA obj
445 * @param
446 * @return
448 void LwpTocLevelData::Read()
450 LwpDLVList::Read();
451 m_nFlags = m_pObjStrm->QuickReaduInt16();
452 m_nLevel = m_pObjStrm->QuickReaduInt16();
453 m_SearchName.Read(m_pObjStrm);
455 m_pObjStrm->SkipExtra();