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,
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 ************************************************************************/
58 * For LWP filter architecture prototype - TOC related object
60 /*************************************************************************
64 April 2005 Modified - add LwpTocLevelData class
65 ************************************************************************/
67 #include "lwpfoundry.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
)
90 LwpTocSuperLayout::~LwpTocSuperLayout()
95 * @short Read TOCSUPERTABLELAYOUT object
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
);
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
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();
142 * @param pCont - container
145 void LwpTocSuperLayout::XFConvert(XFContentContainer
* pCont
)
147 XFIndex
* pToc
= new XFIndex();
149 pToc
->SetProtected(false);
150 pToc
->SetIndexType(enumXFIndexTOC
);
153 for (sal_uInt16 i
= 1; i
<= MAX_LEVELS
; i
++)
155 LwpTocLevelData
* pLevel
= GetSearchLevelPtr(i
);
156 XFIndexTemplate
* pTemplate
= new XFIndexTemplate();
160 // add an blank template so that SODC won't add default style to this level
161 pToc
->AddTemplate(OUString::number(i
), OUString(), pTemplate
);
165 bool bInserted
= false;
168 // One level has 1 template
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
))
188 default: // go through
189 case NONE
: // no leaders
198 case LEADERUNDERLINE
:
203 pTemplate
->AddTabEntry(enumXFTabRight
, 0, cSep
, 'd', m_TabStyleName
);
210 default: // go through
211 case NONE
: // no leaders
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
);
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
);
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() )
252 * @short convert frame which anchor to page
256 void LwpTocSuperLayout::XFConvertFrame(XFContentContainer
* pCont
, sal_Int32 nStart
, sal_Int32 nEnd
, bool bAll
)
260 XFFrame
* pXFFrame
= NULL
;
263 pXFFrame
= new XFFrame();
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();
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
);
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
303 void LwpTocSuperLayout::AddSourceStyle(XFIndex
* pToc
, LwpTocLevelData
* pLevel
, LwpFoundry
* pFoundry
)
310 OUString sLwpStyleName
= pLevel
->GetSearchStyle();
314 LwpDocument
* pDoc
= pFoundry
->GetDocument();
315 if (pDoc
&& pDoc
->IsChildDoc())
317 OUString sSodcStyleName
= pFoundry
->FindActuralStyleName(sLwpStyleName
);
318 pToc
->AddTocSource(pLevel
->GetLevel(), sSodcStyleName
);
322 pDoc
= pDoc
->GetFirstDivision();
325 AddSourceStyle(pToc
, pLevel
, pDoc
->GetFoundry() );
326 pDoc
= pDoc
->GetNextDivision();
333 * @short Get whether page number is right alignment
334 * @param index - TOC level
337 bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index
)
339 if (index
< MAX_LEVELS
)
340 return (m_nFlags
[index
] & TS_RIGHTALIGN
) != 0;
344 * @short Get whether page number is used in TOC entries
345 * @param index - TOC level
348 bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index
)
350 if (index
< MAX_LEVELS
)
351 return (m_nFlags
[index
] & TS_PAGENUMBER
) != 0;
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
)
364 sal_uInt16 Flag
= (sal_uInt16
)m_nFlags
[index
];
366 if (Flag
& TS_LEADERDOTS
)
368 else if (Flag
& TS_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
;
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());
392 if(pObj
->GetLevel()== index
)
397 rID
= pObj
->GetNext();
398 pObj
= dynamic_cast<LwpTocLevelData
*>(rID
.obj().get());
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());
416 if(pObj
->GetLevel()== index
)
421 rID
= pObj
->GetNext();
422 pObj
= dynamic_cast<LwpTocLevelData
*>(rID
.obj().get());
428 LwpTocLevelData::LwpTocLevelData(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
):LwpDLVList(objHdr
, pStrm
)
433 LwpTocLevelData::~LwpTocLevelData()
437 * @short Register style
441 void LwpTocLevelData::RegisterStyle()
446 * @param pCont - container
449 void LwpTocLevelData::XFConvert(XFContentContainer
* /*pCont*/)
453 * @short Read TOCLEVELDATA obj
457 void LwpTocLevelData::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: */