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,
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 ************************************************************************/
57 * For LWP filter architecture prototype - TOC related object
59 /*************************************************************************
63 April 2005 Modified - add LwpTocLevelData class
64 ************************************************************************/
66 #include "lwpfoundry.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()
89 * @short Read TOCSUPERTABLELAYOUT object
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
);
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
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();
136 * @param pCont - container
139 void LwpTocSuperLayout::XFConvert(XFContentContainer
* pCont
)
141 XFIndex
* pToc
= new XFIndex();
143 pToc
->SetProtected(sal_False
);
144 pToc
->SetIndexType(enumXFIndexTOC
);
147 for (sal_uInt16 i
= 1; i
<= MAX_LEVELS
; i
++)
149 LwpTocLevelData
* pLevel
= GetSearchLevelPtr(i
);
150 XFIndexTemplate
* pTemplate
= new XFIndexTemplate();
154 // add an blank template so that SODC won't add default style to this level
155 pToc
->AddTemplate(Int32ToOUString(i
), String::CreateFromAscii(""), pTemplate
);
159 sal_Bool bInserted
= sal_False
;
162 // One level has 1 template
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
))
182 default: // go through
183 case NONE
: // no leaders
192 case LEADERUNDERLINE
:
197 pTemplate
->AddTabEntry(enumXFTabRight
, 0, cSep
, 'd', m_TabStyleName
);
204 default: // go through
205 case NONE
: // no leaders
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
);
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() )
246 * @short convert frame which anchor to page
250 void LwpTocSuperLayout::XFConvertFrame(XFContentContainer
* pCont
, sal_Int32 nStart
, sal_Int32 nEnd
, sal_Bool bAll
)
254 XFFrame
* pXFFrame
= NULL
;
257 pXFFrame
= new XFFrame();
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();
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
);
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
297 void LwpTocSuperLayout::AddSourceStyle(XFIndex
* pToc
, LwpTocLevelData
* pLevel
, LwpFoundry
* pFoundry
)
304 OUString sLwpStyleName
= pLevel
->GetSearchStyle();
308 LwpDocument
* pDoc
= pFoundry
->GetDocument();
309 if (pDoc
&& pDoc
->IsChildDoc())
311 OUString sSodcStyleName
= pFoundry
->FindActuralStyleName(sLwpStyleName
);
312 pToc
->AddTocSource(pLevel
->GetLevel(), sSodcStyleName
);
316 pDoc
= pDoc
->GetFirstDivision();
319 AddSourceStyle(pToc
, pLevel
, pDoc
->GetFoundry() );
320 pDoc
= pDoc
->GetNextDivision();
327 * @short Get whether page number is right alignment
328 * @param index - TOC level
331 sal_Bool
LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index
)
333 if (index
< MAX_LEVELS
)
334 return (m_nFlags
[index
] & TS_RIGHTALIGN
) ? sal_True
: sal_False
;
338 * @short Get whether page number is used in TOC entries
339 * @param index - TOC level
342 sal_Bool
LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index
)
344 if (index
< MAX_LEVELS
)
345 return (m_nFlags
[index
] & TS_PAGENUMBER
) ? sal_True
: 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
)
359 else if (Flag
& TS_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
;
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());
383 if(pObj
->GetLevel()== index
)
388 pID
= pObj
->GetNext(); // not necessary to check pID NULL or not
389 pObj
= static_cast<LwpTocLevelData
*>(pID
->obj());
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());
407 if(pObj
->GetLevel()== index
)
412 pID
= pObj
->GetNext(); // not necessary to check pID NULL or not
413 pObj
= static_cast<LwpTocLevelData
*>(pID
->obj());
419 LwpTocLevelData::LwpTocLevelData(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
):LwpDLVList(objHdr
, pStrm
)
424 LwpTocLevelData::~LwpTocLevelData()
428 * @short Register style
432 void LwpTocLevelData::RegisterStyle()
437 * @param pCont - container
440 void LwpTocLevelData::XFConvert(XFContentContainer
* pCont
)
444 * @short Read TOCLEVELDATA obj
448 void LwpTocLevelData::Read()
451 m_nFlags
= m_pObjStrm
->QuickReaduInt16();
452 m_nLevel
= m_pObjStrm
->QuickReaduInt16();
453 m_SearchName
.Read(m_pObjStrm
);
455 m_pObjStrm
->SkipExtra();