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 ************************************************************************/
55 /*************************************************************************
57 * the class for section frib and process section and page layout
58 ************************************************************************/
59 /*************************************************************************
62 ************************************************************************/
63 #include "lwpfribsection.hxx"
64 #include "lwpfribbreaks.hxx"
65 #include "lwpstory.hxx"
66 #include "lwpsection.hxx"
67 #include "xfilter/xfstylemanager.hxx"
68 #include "xfilter/xfsectionstyle.hxx"
69 #include "xfilter/xfsection.hxx"
70 #include "xfilter/xfindex.hxx"
71 #include "lwpfribptr.hxx"
72 #include "lwpglobalmgr.hxx"
74 LwpFribSection::LwpFribSection(LwpPara
*pPara
)
75 : LwpFrib(pPara
),m_pMasterPage(NULL
)
80 LwpFribSection::~LwpFribSection()
90 * @descr: Read section frib information
93 void LwpFribSection::Read(LwpObjectStream
*pObjStrm
, sal_uInt16 len
)
95 m_Section
.ReadIndexed(pObjStrm
);
99 * @descr: Get section pointer
102 LwpSection
* LwpFribSection::GetSection()
104 return static_cast<LwpSection
*>(m_Section
.obj());
108 * @descr: Register section style
111 void LwpFribSection::RegisterSectionStyle()
113 LwpPageLayout
* pLayout
= GetPageLayout();
116 m_pMasterPage
= new LwpMasterPage(m_pPara
, pLayout
);
117 m_pMasterPage
->RegisterMasterPage(this);
122 * @descr: Register section style
125 void LwpFribSection::SetSectionName()
127 LwpSection
* pSection
= GetSection();
130 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
131 pStory
->SetSectionName(pSection
->GetSectionName());
136 * @descr: Get page layout that current section points
139 LwpPageLayout
* LwpFribSection::GetPageLayout()
142 return GetSection()->GetPageLayout();
147 * @descr: XFConvert section
150 void LwpFribSection::ParseSection()
152 LwpPageLayout
* pLayout
= GetPageLayout();
155 // StartWithinColume not support now
156 LwpLayout::UseWhenType eSectionType
= pLayout
->GetUseWhenType();
157 if(eSectionType
==LwpLayout::StartWithinColume
)
163 m_pMasterPage
->ParseSection(this);
168 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID()->obj() );
169 if (m_Section
.obj()->GetTag() == VO_INDEXSECTION
)
171 sal_Bool bRunin
= sal_False
;
172 sal_Bool bSeparator
= sal_False
;
173 //create a new section and add it to container
174 XFIndex
* pIndex
= new XFIndex
;
175 pIndex
->SetIndexType(enumXFIndexAlphabetical
);
177 LwpIndexSection* pIndexSection = static_cast<LwpIndexSection*>(m_Section.obj());
178 if (pIndexSection->IsFormatRunin())
180 if (pIndexSection->IsFormatSeparator())
181 bSeparator = sal_True;
182 pIndex->SetDefaultAlphaIndex(A2OUSTR(""),bRunin,bSeparator);
184 SetDefaultAlphaIndex(pIndex
);
186 pStory
->AddXFContent( pIndex
);
187 m_pPara
->SetXFContainer( pIndex
);
191 XFContentContainer
* pContent
= pStory
->GetXFContent();
192 m_pPara
->SetXFContainer( pContent
);
197 void LwpFribSection::SetDefaultAlphaIndex(XFIndex
* pXFIndex
)
199 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
200 OUString styleName
= pFoundry
->FindActuralStyleName(A2OUSTR("Separator"));
202 LwpIndexSection
* pIndexSection
= static_cast<LwpIndexSection
*>(m_Section
.obj());
203 XFIndexTemplate
* pTemplateSep
= new XFIndexTemplate();
204 if (pIndexSection
->IsFormatSeparator())
206 pXFIndex
->SetSeparator(sal_True
);
207 pTemplateSep
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
209 //pXFIndex->AddTemplate(A2OUSTR("separator"),A2OUSTR("Separator"),pTemplateSep);
210 pXFIndex
->AddTemplate(A2OUSTR("separator"),styleName
,pTemplateSep
);
213 styleName
= pFoundry
->FindActuralStyleName(A2OUSTR("Primary"));
215 XFIndexTemplate
* pTemplate1
= new XFIndexTemplate();
216 pTemplate1
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
217 pTemplate1
->AddEntry(enumXFIndexTemplateTab
,A2OUSTR(""));
218 pTemplate1
->AddEntry(enumXFIndexTemplatePage
,A2OUSTR(""));
219 //pXFIndex->AddTemplate(Int32ToOUString(1),A2OUSTR("Primary"),pTemplate1);
220 pXFIndex
->AddTemplate(Int32ToOUString(1),styleName
,pTemplate1
);
222 XFIndexTemplate
* pTemplate2
= new XFIndexTemplate();
223 pTemplate2
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
224 pTemplate2
->AddEntry(enumXFIndexTemplateTab
,A2OUSTR(""));
225 pTemplate2
->AddEntry(enumXFIndexTemplatePage
,A2OUSTR(""));
226 XFIndexTemplate
* pTemplate3
= new XFIndexTemplate();
227 pTemplate3
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
228 pTemplate3
->AddEntry(enumXFIndexTemplateTab
,A2OUSTR(""));
229 pTemplate3
->AddEntry(enumXFIndexTemplatePage
,A2OUSTR(""));
231 if (pIndexSection
->IsFormatRunin())
233 //pXFIndex->AddTemplate(Int32ToOUString(2),A2OUSTR("Primary"),pTemplate2);
234 //pXFIndex->AddTemplate(Int32ToOUString(3),A2OUSTR("Primary"),pTemplate3);
235 pXFIndex
->AddTemplate(Int32ToOUString(2),styleName
,pTemplate2
);
236 pXFIndex
->AddTemplate(Int32ToOUString(3),styleName
,pTemplate3
);
240 //pXFIndex->AddTemplate(Int32ToOUString(2),A2OUSTR("Secondary"),pTemplate2);
241 //pXFIndex->AddTemplate(Int32ToOUString(3),A2OUSTR("Secondary"),pTemplate3);
242 styleName
= pFoundry
->FindActuralStyleName(A2OUSTR("Secondary"));
243 pXFIndex
->AddTemplate(Int32ToOUString(2),styleName
,pTemplate2
);
244 pXFIndex
->AddTemplate(Int32ToOUString(3),styleName
,pTemplate3
);
249 LwpMasterPage::LwpMasterPage(LwpPara
* pPara
, LwpPageLayout
* pLayout
)
250 :m_pPara(pPara
),m_pLayout(pLayout
),m_bNewSection(sal_False
)
255 * @descr: Register master page style for para style and register section style if necessary
258 sal_Bool
LwpMasterPage::RegisterMasterPage(LwpFrib
* pFrib
)
260 //if there is no other frib after current firb, register master page in starting para of next page
261 if(IsNextPageType()&&(!pFrib
->HasNextFrib()))
263 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
264 pStory
->SetCurrentLayout(m_pLayout
);
265 RegisterFillerPageStyle();
269 m_bNewSection
= sal_False
;
270 //sal_Bool bSectionColumns = sal_False;
272 XFParaStyle
* pOverStyle
= new XFParaStyle
;
273 *pOverStyle
= *(m_pPara
->GetXFParaStyle());
274 pOverStyle
->SetStyleName(A2OUSTR(""));
276 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
279 case LwpLayout::StartWithinColume
://not support now
281 m_bNewSection
= sal_False
;
284 case LwpLayout::StartWithinPage
:
286 m_bNewSection
= sal_True
;
287 //bSectionColumns = sal_True;
290 case LwpLayout::StartOnNextPage
: //fall throught
291 case LwpLayout::StartOnOddPage
: //fall throught
292 case LwpLayout::StartOnEvenPage
:
294 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
295 pStory
->SetCurrentLayout(m_pLayout
);
296 //get odd page layout when the current pagelayout is mirror
297 m_pLayout
= pStory
->GetCurrentLayout();
298 m_bNewSection
= IsNeedSection();
299 //bSectionColumns = m_bNewSection;
300 pOverStyle
->SetMasterPage( m_pLayout
->GetStyleName());
301 RegisterFillerPageStyle();
308 //register tab style;
309 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
310 pStory
->SetTabLayout(m_pLayout
);
311 m_pPara
->RegisterTabStyle(pOverStyle
);
313 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
314 m_StyleName
= pXFStyleManager
->AddStyle(pOverStyle
)->GetStyleName();
315 //register section style here
318 XFSectionStyle
* pSectStyle
= new XFSectionStyle();
320 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
323 LwpPageLayout
* pCurrentLayout
= pStory
->GetCurrentLayout();
324 double fLeft
= m_pLayout
->GetMarginsValue(MARGIN_LEFT
)- pCurrentLayout
->GetMarginsValue(MARGIN_LEFT
);
325 double fRight
= m_pLayout
->GetMarginsValue(MARGIN_RIGHT
)- pCurrentLayout
->GetMarginsValue(MARGIN_RIGHT
);
326 pSectStyle
->SetMarginLeft(fLeft
);
327 pSectStyle
->SetMarginRight(fRight
);
330 //if(bSectionColumns)
333 XFColumns
* pColumns
= m_pLayout
->GetXFColumns();
336 pSectStyle
->SetColumns(pColumns
);
339 m_SectionStyleName
= pXFStyleManager
->AddStyle(pSectStyle
)->GetStyleName();
345 * @descr: Whether it need create a new section
348 sal_Bool
LwpMasterPage::IsNeedSection()
350 sal_Bool bNewSection
= sal_False
;
352 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
353 //if pagelayout is modified, register the pagelayout
354 if(pStory
->IsPMModified())
356 bNewSection
= pStory
->IsNeedSection();
362 * @descr: Create XFSection if necessary
365 XFSection
* LwpMasterPage::CreateXFSection()
370 XFSection
* pXFSection
= new XFSection();
371 pXFSection
->SetStyleName(m_SectionStyleName
);
378 * @descr: Parse section
381 void LwpMasterPage::ParseSection(LwpFrib
* pFrib
)
383 LwpFribPtr
* pFribPtr
= m_pPara
->GetFribs();
384 //XFParagraph * pXFPara = pFribPtr->GetXFPara();
386 //parse fillerpage text
387 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
389 XFParagraph
*pPara
= new XFParagraph();
390 pPara
->SetStyleName(GetFillerPageStyleName());
391 m_pPara
->AddXFContent(pPara
);
392 pFribPtr
->SetXFPara(pPara
);
394 m_pLayout
->ConvertFillerPageText(m_pPara
->GetXFContainer());
396 //create a new section and add it to container
397 XFContentContainer
* pContent
= CreateXFSection();
400 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID()->obj() );
401 //delete the additional blank para, 06/28/2005
402 XFParagraph
* pCurrPara
= pFribPtr
->GetXFPara();
403 if(!pCurrPara
->HasContents())
405 XFContentContainer
* pCurrContainer
= m_pPara
->GetXFContainer();
406 if(pFrib
->HasNextFrib() && (pCurrContainer
->GetLastContent() == pCurrPara
))
408 pCurrContainer
->RemoveLastContent();
412 pStory
->AddXFContent( pContent
);
416 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID()->obj() );
417 pContent
= pStory
->GetXFContent();
421 m_pPara
->SetXFContainer( pContent
);
423 //out put the contents after the section frib in the same para.
424 if(pFrib
->HasNextFrib())
426 XFParagraph
*pNextPara
= new XFParagraph();
427 pNextPara
->SetStyleName(GetStyleName());
428 m_pPara
->AddXFContent(pNextPara
);
429 pFribPtr
->SetXFPara(pNextPara
);
435 * @descr: Register filler page text style
438 void LwpMasterPage::RegisterFillerPageStyle()
440 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
441 if(eUserType
==LwpLayout::StartOnOddPage
442 ||eUserType
==LwpLayout::StartOnEvenPage
)
444 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
446 XFParaStyle
* pPagebreakStyle
= new XFParaStyle
;
447 *pPagebreakStyle
= *(m_pPara
->GetXFParaStyle());
448 pPagebreakStyle
->SetStyleName(A2OUSTR(""));
449 pPagebreakStyle
->SetBreaks(enumXFBreakAftPage
);
450 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
451 m_FillerPageStyleName
= pXFStyleManager
->AddStyle(pPagebreakStyle
)->GetStyleName();
457 * @descr: Whether the layout is next page type
460 sal_Bool
LwpMasterPage::IsNextPageType()
462 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
463 if(eUserType
== LwpLayout::StartOnNextPage
464 || eUserType
== LwpLayout::StartOnOddPage
465 || eUserType
== LwpLayout::StartOnEvenPage
)