fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / lotuswordpro / source / filter / lwptoc.cxx
blob75b9aa7ef7fa737c5f6524937a56df37bfa78c7a
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)
85 , m_nFrom(0)
86 , m_pCont(NULL)
90 LwpTocSuperLayout::~LwpTocSuperLayout()
94 /**
95 * @short Read TOCSUPERTABLELAYOUT object
96 * @return none
98 void LwpTocSuperLayout::Read()
100 LwpSuperTableLayout::Read();
101 m_TextMarker.Read(m_pObjStrm);
102 m_ParentName.Read(m_pObjStrm);
103 m_DivisionName.Read(m_pObjStrm);
104 m_SectionName.Read(m_pObjStrm);
105 m_nFrom = m_pObjStrm->QuickReaduInt16();
107 m_SearchItems.Read(m_pObjStrm);
109 sal_uInt16 i;
110 sal_uInt16 count = m_pObjStrm->QuickReaduInt16();
111 for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
112 m_DestName[i].Read(m_pObjStrm);
114 count = m_pObjStrm->QuickReaduInt16();
115 for (i = 0; (i < MAX_LEVELS) && (count > 0); i++, count--)
116 m_DestPGName[i].Read(m_pObjStrm);
118 count = m_pObjStrm->QuickReaduInt16();
119 for (i = 0; i < count; i++)
120 m_nFlags[i] = m_pObjStrm->QuickReaduInt32();
122 m_pObjStrm->SkipExtra();
125 * @short Register style of TOC
126 * @return none
128 void LwpTocSuperLayout::RegisterStyle()
130 LwpSuperTableLayout::RegisterStyle();
132 // Get font info of default text style and set into tab style
133 XFParaStyle* pBaseStyle = static_cast<XFParaStyle*>(m_pFoundry->GetStyleManager()->GetStyle(*m_pFoundry->GetDefaultTextStyle()));
134 XFTextStyle*pTextStyle = new XFTextStyle;
135 pTextStyle->SetFont(pBaseStyle->GetFont()); // who delete this font?????
136 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
137 m_TabStyleName = pXFStyleManager->AddStyle(pTextStyle).m_pStyle->GetStyleName();
141 * @short Convert TOC
142 * @param pCont - container
143 * @return none
145 void LwpTocSuperLayout::XFConvert(XFContentContainer* pCont)
147 XFIndex* pToc = new XFIndex();
149 pToc->SetProtected(false);
150 pToc->SetIndexType(enumXFIndexTOC);
152 // add TOC template
153 for (sal_uInt16 i = 1; i<= MAX_LEVELS; i++)
155 LwpTocLevelData * pLevel = GetSearchLevelPtr(i);
156 XFIndexTemplate * pTemplate = new XFIndexTemplate();
158 if(!pLevel)
160 // add an blank template so that SODC won't add default style to this level
161 pToc->AddTemplate(OUString::number(i), OUString(), pTemplate);
162 continue;
165 bool bInserted = false;
168 // One level has 1 template
169 if (!bInserted)
171 pTemplate->SetLevel(OUString::number(i));
172 if(pLevel->GetUseLeadingText())
174 pTemplate->AddEntry(enumXFIndexTemplateChapter, pLevel->GetSearchStyle());
176 if(pLevel->GetUseText())
178 pTemplate->AddEntry(enumXFIndexTemplateText, pLevel->GetSearchStyle());
180 if(GetUsePageNumber(i))
182 sal_uInt16 nLeaderType = GetSeparatorType(i);
183 if (GetRightAlignPageNumber(i))
185 char cSep = ' ';
186 switch(nLeaderType)
188 default: // go through
189 case NONE: // no leaders
190 cSep = ' ';
191 break;
192 case LEADERDOTS:
193 cSep = '.';
194 break;
195 case LEADERDASHES:
196 cSep = '-';
197 break;
198 case LEADERUNDERLINE:
199 cSep = '_';
200 break;
203 pTemplate->AddTabEntry(enumXFTabRight, 0, cSep, 'd', m_TabStyleName);
205 else
207 OUString sSep;
208 switch(nLeaderType)
210 default: // go through
211 case NONE: // no leaders
212 sSep = " ";
213 break;
214 case SEPARATORCOMMA:
215 sSep = ", ";
216 break;
217 case SEPARATORDOTS:
218 sSep = "...";
219 break;
221 pTemplate->AddTextEntry(sSep, m_TabStyleName);
223 //"TOC Page Number Text Style" style always exists in Word Pro file
224 pTemplate->AddEntry(enumXFIndexTemplatePage, "TOC Page Number Text Style");
227 pToc->AddTemplate(OUString::number((sal_Int32)i), m_pFoundry->FindActuralStyleName(pLevel->GetSearchStyle()), pTemplate);
228 bInserted = true;
231 // 1 style in WordPro may be mapped to several styles in SODC
232 LwpDocument * pDocument = m_pFoundry->GetDocument()->GetRootDocument();
233 AddSourceStyle(pToc, pLevel, pDocument->GetFoundry());
235 // one level may have several corresponding Styles
236 pLevel = GetNextSearchLevelPtr(i, pLevel); // find next LwpTocLevelData which is same index
237 }while (pLevel != NULL);
240 m_pCont = pCont;
241 // add TOC content
242 LwpSuperTableLayout::XFConvert(pToc);
244 // if current TOC is located in a cell, we must add a frame between upper level container and TOC
245 if ( !GetContainerLayout()->IsCell() )
247 pCont->Add(pToc);
252 * @short convert frame which anchor to page
253 * @param pCont -
254 * @return
256 void LwpTocSuperLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart, sal_Int32 nEnd, bool bAll)
258 if(m_pFrame)
260 XFFrame* pXFFrame = NULL;
261 if(nEnd < nStart)
263 pXFFrame = new XFFrame();
265 else
267 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
270 m_pFrame->Parse(pXFFrame, static_cast<sal_uInt16>(nStart));
272 //parse table, and add table to frame or TOC
273 LwpTableLayout * pTableLayout = GetTableLayout();
274 if (pTableLayout)
276 XFContentContainer * pTableContainer = pXFFrame;
277 // if *this is a TOCSuperTableLayout and it's located in a cell
278 // add the frame to upper level and add TOCSuperTableLayout into the frame
279 if ( GetContainerLayout()->IsCell() )
281 pTableContainer = pCont; // TOC contain table directly
282 pXFFrame->Add(pCont);
283 m_pCont->Add(pXFFrame);
285 else
287 //add frame to the container
288 pCont ->Add(pXFFrame);
290 pTableLayout->XFConvert(pTableContainer);
297 * @short Add source style into TOC
298 * @param pToc - TOC pointer
299 * @param pLevel - TOC level data
300 * @param pFoundry - foundry pointer
301 * @return sal_Bool
303 void LwpTocSuperLayout::AddSourceStyle(XFIndex* pToc, LwpTocLevelData * pLevel, LwpFoundry * pFoundry)
305 if (!pLevel)
307 return;
310 OUString sLwpStyleName = pLevel->GetSearchStyle();
312 if (pFoundry)
314 LwpDocument * pDoc = pFoundry->GetDocument();
315 if (pDoc && pDoc->IsChildDoc())
317 OUString sSodcStyleName = pFoundry->FindActuralStyleName(sLwpStyleName);
318 pToc->AddTocSource(pLevel->GetLevel(), sSodcStyleName);
320 else
322 pDoc = pDoc->GetFirstDivision();
323 while (pDoc)
325 AddSourceStyle(pToc, pLevel, pDoc->GetFoundry() );
326 pDoc = pDoc->GetNextDivision();
333 * @short Get whether page number is right alignment
334 * @param index - TOC level
335 * @return sal_Bool
337 bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index)
339 if (index < MAX_LEVELS)
340 return (m_nFlags[index] & TS_RIGHTALIGN) != 0;
341 return false;
344 * @short Get whether page number is used in TOC entries
345 * @param index - TOC level
346 * @return sal_Bool
348 bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index)
350 if (index < MAX_LEVELS)
351 return (m_nFlags[index] & TS_PAGENUMBER) != 0;
352 return false;
355 * @short Get what is used for separater
356 * @param index - TOC level
357 * @return sal_uInt16 - separator type
359 sal_uInt16 LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index)
361 if (index >= MAX_LEVELS)
362 return NONE;
364 sal_uInt16 Flag = (sal_uInt16)m_nFlags[index];
366 if (Flag & TS_LEADERDOTS)
367 return LEADERDOTS;
368 else if (Flag & TS_LEADERDASHES)
369 return LEADERDASHES;
370 else if (Flag & TS_LEADERUNDERLINE)
371 return LEADERUNDERLINE;
372 else if (Flag & TS_SEPARATORCOMMA)
373 return SEPARATORCOMMA;
374 else if (Flag & TS_SEPARATORDOTS)
375 return SEPARATORDOTS;
376 else
377 return NONE;
381 * @short Get TOCLEVELDATA obj
382 * @param index - TOC level
383 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
385 LwpTocLevelData * LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index)
387 LwpObjectID& rID = m_SearchItems.GetHead();
388 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
390 while(pObj)
392 if(pObj->GetLevel()== index)
394 return pObj;
397 rID = pObj->GetNext();
398 pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
401 return NULL;
404 * @short Get next TOCLEVELDATA obj from current position
405 * @param index - TOC level
406 * @param pCurData - current LwpTocLevelData
407 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
409 LwpTocLevelData * LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index, LwpTocLevelData * pCurData)
411 LwpObjectID& rID = pCurData->GetNext();
412 LwpTocLevelData * pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
414 while(pObj)
416 if(pObj->GetLevel()== index)
418 return pObj;
421 rID = pObj->GetNext();
422 pObj = dynamic_cast<LwpTocLevelData *>(rID.obj().get());
425 return NULL;
428 LwpTocLevelData::LwpTocLevelData(LwpObjectHeader &objHdr, LwpSvStream* pStrm):LwpDLVList(objHdr, pStrm)
430 m_nFlags = 0;
431 m_nLevel = 0;
433 LwpTocLevelData::~LwpTocLevelData()
437 * @short Register style
438 * @param
439 * @return
441 void LwpTocLevelData::RegisterStyle()
445 * @short Convert
446 * @param pCont - container
447 * @return none
449 void LwpTocLevelData::XFConvert(XFContentContainer* /*pCont*/)
453 * @short Read TOCLEVELDATA obj
454 * @param
455 * @return
457 void LwpTocLevelData::Read()
459 LwpDLVList::Read();
460 m_nFlags = m_pObjStrm->QuickReaduInt16();
461 m_nLevel = m_pObjStrm->QuickReaduInt16();
462 m_SearchName.Read(m_pObjStrm);
464 m_pObjStrm->SkipExtra();
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */