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
62 #include "lwpfoundry.hxx"
64 #include "lwpframelayout.hxx"
65 #include "lwpglobalmgr.hxx"
67 #include "xfilter/xffont.hxx"
68 #include "xfilter/xftextstyle.hxx"
69 #include "xfilter/xfstylemanager.hxx"
70 #include "xfilter/xfparagraph.hxx"
71 #include "xfilter/xfparastyle.hxx"
72 #include "xfilter/xfindex.hxx"
73 #include "xfilter/xffloatframe.hxx"
74 #include "xfilter/xfframestyle.hxx"
75 #include "xfilter/xfframe.hxx"
76 #include "xfilter/xftable.hxx"
78 LwpTocSuperLayout::LwpTocSuperLayout(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
)
79 : LwpSuperTableLayout(objHdr
, pStrm
)
85 LwpTocSuperLayout::~LwpTocSuperLayout()
90 * @short Read TOCSUPERTABLELAYOUT object
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 count
= m_pObjStrm
->QuickReaduInt16();
105 if (count
> MAX_LEVELS
)
106 throw std::range_error("corrupt LwpTocSuperLayout");
107 for (sal_uInt16 i
= 0; i
< count
; ++i
)
108 m_DestName
[i
].Read(m_pObjStrm
);
110 count
= m_pObjStrm
->QuickReaduInt16();
111 if (count
> MAX_LEVELS
)
112 throw std::range_error("corrupt LwpTocSuperLayout");
113 for (sal_uInt16 i
= 0; i
< count
; ++i
)
114 m_DestPGName
[i
].Read(m_pObjStrm
);
116 count
= m_pObjStrm
->QuickReaduInt16();
117 if (count
> MAX_LEVELS
)
118 throw std::range_error("corrupt LwpTocSuperLayout");
119 for (sal_uInt16 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 const LwpObjectID
*pDefaultTextStyle
= m_pFoundry
? m_pFoundry
->GetDefaultTextStyle() : nullptr;
134 XFParaStyle
* pBaseStyle
= pDefaultTextStyle
? dynamic_cast<XFParaStyle
*>(m_pFoundry
->GetStyleManager()->GetStyle(*pDefaultTextStyle
)) : nullptr;
135 XFTextStyle
*pTextStyle
= new XFTextStyle
;
137 pTextStyle
->SetFont(pBaseStyle
->GetFont()); // who delete this font?????
138 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
139 m_TabStyleName
= pXFStyleManager
->AddStyle(pTextStyle
).m_pStyle
->GetStyleName();
144 * @param pCont - container
147 void LwpTocSuperLayout::XFConvert(XFContentContainer
* pCont
)
149 XFIndex
* pToc
= new XFIndex();
151 pToc
->SetProtected(false);
152 pToc
->SetIndexType(enumXFIndexTOC
);
155 for (sal_uInt16 i
= 1; i
<= MAX_LEVELS
; i
++)
157 LwpTocLevelData
* pLevel
= GetSearchLevelPtr(i
);
158 XFIndexTemplate
* pTemplate
= new XFIndexTemplate();
162 // add an blank template so that SODC won't add default style to this level
163 pToc
->AddTemplate(OUString::number(i
), OUString(), pTemplate
);
167 bool bInserted
= false;
170 // One level has 1 template
173 pTemplate
->SetLevel(OUString::number(i
));
174 if(pLevel
->GetUseLeadingText())
176 pTemplate
->AddEntry(enumXFIndexTemplateChapter
, pLevel
->GetSearchStyle());
178 if(pLevel
->GetUseText())
180 pTemplate
->AddEntry(enumXFIndexTemplateText
, pLevel
->GetSearchStyle());
182 if(GetUsePageNumber(i
))
184 sal_uInt16 nLeaderType
= GetSeparatorType(i
);
185 if (GetRightAlignPageNumber(i
))
190 default: // go through
191 case NONE
: // no leaders
200 case LEADERUNDERLINE
:
205 pTemplate
->AddTabEntry(enumXFTabRight
, 0, cSep
, 'd', m_TabStyleName
);
212 default: // go through
213 case NONE
: // no leaders
223 pTemplate
->AddTextEntry(sSep
, m_TabStyleName
);
225 //"TOC Page Number Text Style" style always exists in Word Pro file
226 pTemplate
->AddEntry(enumXFIndexTemplatePage
, "TOC Page Number Text Style");
229 pToc
->AddTemplate(OUString::number((sal_Int32
)i
), m_pFoundry
->FindActuralStyleName(pLevel
->GetSearchStyle()), pTemplate
);
233 // 1 style in WordPro may be mapped to several styles in SODC
234 LwpDocument
* pDocument
= m_pFoundry
->GetDocument()->GetRootDocument();
235 AddSourceStyle(pToc
, pLevel
, pDocument
->GetFoundry());
237 // one level may have several corresponding Styles
238 pLevel
= GetNextSearchLevelPtr(i
, pLevel
); // find next LwpTocLevelData which is same index
239 }while (pLevel
!= nullptr);
244 LwpSuperTableLayout::XFConvert(pToc
);
246 rtl::Reference
<LwpVirtualLayout
> xContainer(GetContainerLayout());
247 if (!xContainer
.is())
250 // if current TOC is located in a cell, we must add a frame between upper level container and TOC
251 if (!xContainer
->IsCell())
258 * @short convert frame which anchor to page
262 void LwpTocSuperLayout::XFConvertFrame(XFContentContainer
* pCont
, sal_Int32 nStart
, sal_Int32 nEnd
, bool bAll
)
266 XFFrame
* pXFFrame
= nullptr;
269 pXFFrame
= new XFFrame();
273 pXFFrame
= new XFFloatFrame(nStart
, nEnd
, bAll
);
276 m_pFrame
->Parse(pXFFrame
, static_cast<sal_uInt16
>(nStart
));
278 //parse table, and add table to frame or TOC
279 LwpTableLayout
* pTableLayout
= GetTableLayout();
282 XFContentContainer
* pTableContainer
= pXFFrame
;
283 // if *this is a TOCSuperTableLayout and it's located in a cell
284 // add the frame to upper level and add TOCSuperTableLayout into the frame
285 rtl::Reference
<LwpVirtualLayout
> xContainer(GetContainerLayout());
286 if (!xContainer
.is())
288 if (xContainer
->IsCell())
290 pTableContainer
= pCont
; // TOC contain table directly
291 pXFFrame
->Add(pCont
);
292 m_pCont
->Add(pXFFrame
);
296 //add frame to the container
297 pCont
->Add(pXFFrame
);
299 pTableLayout
->XFConvert(pTableContainer
);
306 * @short Add source style into TOC
307 * @param pToc - TOC pointer
308 * @param pLevel - TOC level data
309 * @param pFoundry - foundry pointer
312 void LwpTocSuperLayout::AddSourceStyle(XFIndex
* pToc
, LwpTocLevelData
* pLevel
, LwpFoundry
* pFoundry
)
319 OUString sLwpStyleName
= pLevel
->GetSearchStyle();
323 LwpDocument
* pDoc
= pFoundry
->GetDocument();
324 if (pDoc
&& pDoc
->IsChildDoc())
326 OUString sSodcStyleName
= pFoundry
->FindActuralStyleName(sLwpStyleName
);
327 pToc
->AddTocSource(pLevel
->GetLevel(), sSodcStyleName
);
331 pDoc
= pDoc
->GetFirstDivision();
334 AddSourceStyle(pToc
, pLevel
, pDoc
->GetFoundry() );
335 pDoc
= pDoc
->GetNextDivision();
342 * @short Get whether page number is right alignment
343 * @param index - TOC level
346 bool LwpTocSuperLayout::GetRightAlignPageNumber(sal_uInt16 index
)
348 if (index
< MAX_LEVELS
)
349 return (m_nFlags
[index
] & TS_RIGHTALIGN
) != 0;
353 * @short Get whether page number is used in TOC entries
354 * @param index - TOC level
357 bool LwpTocSuperLayout::GetUsePageNumber(sal_uInt16 index
)
359 if (index
< MAX_LEVELS
)
360 return (m_nFlags
[index
] & TS_PAGENUMBER
) != 0;
364 * @short Get what is used for separater
365 * @param index - TOC level
366 * @return sal_uInt16 - separator type
368 sal_uInt16
LwpTocSuperLayout::GetSeparatorType(sal_uInt16 index
)
370 if (index
>= MAX_LEVELS
)
373 sal_uInt16 Flag
= (sal_uInt16
)m_nFlags
[index
];
375 if (Flag
& TS_LEADERDOTS
)
377 else if (Flag
& TS_LEADERDASHES
)
379 else if (Flag
& TS_LEADERUNDERLINE
)
380 return LEADERUNDERLINE
;
381 else if (Flag
& TS_SEPARATORCOMMA
)
382 return SEPARATORCOMMA
;
383 else if (Flag
& TS_SEPARATORDOTS
)
384 return SEPARATORDOTS
;
390 * @short Get TOCLEVELDATA obj
391 * @param index - TOC level
392 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
394 LwpTocLevelData
* LwpTocSuperLayout::GetSearchLevelPtr(sal_uInt16 index
)
396 LwpObjectID
& rID
= m_SearchItems
.GetHead();
397 LwpTocLevelData
* pObj
= dynamic_cast<LwpTocLevelData
*>(rID
.obj().get());
401 if(pObj
->GetLevel()== index
)
406 rID
= pObj
->GetNext();
407 pObj
= dynamic_cast<LwpTocLevelData
*>(rID
.obj().get());
413 * @short Get next TOCLEVELDATA obj from current position
414 * @param index - TOC level
415 * @param pCurData - current LwpTocLevelData
416 * @return LwpTocLevelData * - pointer to TOCLEVELDATA obj
418 LwpTocLevelData
* LwpTocSuperLayout::GetNextSearchLevelPtr(sal_uInt16 index
, LwpTocLevelData
* pCurData
)
420 LwpObjectID
& rID
= pCurData
->GetNext();
421 LwpTocLevelData
* pObj
= dynamic_cast<LwpTocLevelData
*>(rID
.obj().get());
425 if(pObj
->GetLevel()== index
)
430 rID
= pObj
->GetNext();
431 pObj
= dynamic_cast<LwpTocLevelData
*>(rID
.obj().get());
437 LwpTocLevelData::LwpTocLevelData(LwpObjectHeader
&objHdr
, LwpSvStream
* pStrm
):LwpDLVList(objHdr
, pStrm
)
442 LwpTocLevelData::~LwpTocLevelData()
446 * @short Register style
450 void LwpTocLevelData::RegisterStyle()
455 * @param pCont - container
458 void LwpTocLevelData::XFConvert(XFContentContainer
* /*pCont*/)
462 * @short Read TOCLEVELDATA obj
466 void LwpTocLevelData::Read()
469 m_nFlags
= m_pObjStrm
->QuickReaduInt16();
470 m_nLevel
= m_pObjStrm
->QuickReaduInt16();
471 m_SearchName
.Read(m_pObjStrm
);
473 m_pObjStrm
->SkipExtra();
476 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */