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 ************************************************************************/
56 /*************************************************************************
58 * the class for section frib and process section and page layout
59 ************************************************************************/
60 /*************************************************************************
63 ************************************************************************/
64 #include "lwpfribsection.hxx"
65 #include "lwpfribbreaks.hxx"
66 #include "lwpstory.hxx"
67 #include "lwpsection.hxx"
68 #include "xfilter/xfstylemanager.hxx"
69 #include "xfilter/xfsectionstyle.hxx"
70 #include "xfilter/xfsection.hxx"
71 #include "xfilter/xfindex.hxx"
72 #include "lwpfribptr.hxx"
73 #include "lwpglobalmgr.hxx"
75 LwpFribSection::LwpFribSection(LwpPara
*pPara
)
76 : LwpFrib(pPara
),m_pMasterPage(NULL
)
81 LwpFribSection::~LwpFribSection()
91 * @descr: Read section frib information
94 void LwpFribSection::Read(LwpObjectStream
*pObjStrm
, sal_uInt16
/*len*/)
96 m_Section
.ReadIndexed(pObjStrm
);
100 * @descr: Get section pointer
103 LwpSection
* LwpFribSection::GetSection()
105 return static_cast<LwpSection
*>(m_Section
.obj().get());
109 * @descr: Register section style
112 void LwpFribSection::RegisterSectionStyle()
114 LwpPageLayout
* pLayout
= GetPageLayout();
117 m_pMasterPage
= new LwpMasterPage(m_pPara
, pLayout
);
118 m_pMasterPage
->RegisterMasterPage(this);
123 * @descr: Register section style
126 void LwpFribSection::SetSectionName()
128 LwpSection
* pSection
= GetSection();
131 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
132 pStory
->SetSectionName(pSection
->GetSectionName());
137 * @descr: Get page layout that current section points
140 LwpPageLayout
* LwpFribSection::GetPageLayout()
143 return GetSection()->GetPageLayout();
148 * @descr: XFConvert section
151 void LwpFribSection::ParseSection()
153 LwpPageLayout
* pLayout
= GetPageLayout();
156 // StartWithinColume not support now
157 LwpLayout::UseWhenType eSectionType
= pLayout
->GetUseWhenType();
158 if(eSectionType
==LwpLayout::StartWithinColume
)
164 m_pMasterPage
->ParseSection(this);
169 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID().obj().get() );
170 if (m_Section
.obj()->GetTag() == VO_INDEXSECTION
)
172 //create a new section and add it to container
173 XFIndex
* pIndex
= new XFIndex
;
174 pIndex
->SetIndexType(enumXFIndexAlphabetical
);
176 sal_Bool bRunin = sal_False;
177 sal_Bool bSeparator = sal_False;
178 LwpIndexSection* pIndexSection = static_cast<LwpIndexSection*>(m_Section.obj());
179 if (pIndexSection->IsFormatRunin())
181 if (pIndexSection->IsFormatSeparator())
182 bSeparator = sal_True;
183 pIndex->SetDefaultAlphaIndex("",bRunin,bSeparator);
185 SetDefaultAlphaIndex(pIndex
);
187 pStory
->AddXFContent( pIndex
);
188 m_pPara
->SetXFContainer( pIndex
);
192 XFContentContainer
* pContent
= pStory
->GetXFContent();
193 m_pPara
->SetXFContainer( pContent
);
198 void LwpFribSection::SetDefaultAlphaIndex(XFIndex
* pXFIndex
)
200 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
201 OUString styleName
= pFoundry
->FindActuralStyleName("Separator");
203 LwpIndexSection
* pIndexSection
= static_cast<LwpIndexSection
*>(m_Section
.obj().get());
204 XFIndexTemplate
* pTemplateSep
= new XFIndexTemplate();
205 if (pIndexSection
->IsFormatSeparator())
207 pXFIndex
->SetSeparator(true);
208 pTemplateSep
->AddEntry(enumXFIndexTemplateText
,"");
210 //pXFIndex->AddTemplate("separator","Separator",pTemplateSep);
211 pXFIndex
->AddTemplate("separator",styleName
,pTemplateSep
);
213 styleName
= pFoundry
->FindActuralStyleName("Primary");
215 XFIndexTemplate
* pTemplate1
= new XFIndexTemplate();
216 pTemplate1
->AddEntry(enumXFIndexTemplateText
,"");
217 pTemplate1
->AddEntry(enumXFIndexTemplateTab
,"");
218 pTemplate1
->AddEntry(enumXFIndexTemplatePage
,"");
219 //pXFIndex->AddTemplate(OUString::number(1),"Primary",pTemplate1);
220 pXFIndex
->AddTemplate(OUString::number(1),styleName
,pTemplate1
);
222 XFIndexTemplate
* pTemplate2
= new XFIndexTemplate();
223 pTemplate2
->AddEntry(enumXFIndexTemplateText
,"");
224 pTemplate2
->AddEntry(enumXFIndexTemplateTab
,"");
225 pTemplate2
->AddEntry(enumXFIndexTemplatePage
,"");
226 XFIndexTemplate
* pTemplate3
= new XFIndexTemplate();
227 pTemplate3
->AddEntry(enumXFIndexTemplateText
,"");
228 pTemplate3
->AddEntry(enumXFIndexTemplateTab
,"");
229 pTemplate3
->AddEntry(enumXFIndexTemplatePage
,"");
231 if (pIndexSection
->IsFormatRunin())
233 //pXFIndex->AddTemplate(OUString::number(2),"Primary",pTemplate2);
234 //pXFIndex->AddTemplate(OUString::number(3),"Primary",pTemplate3);
235 pXFIndex
->AddTemplate(OUString::number(2),styleName
,pTemplate2
);
236 pXFIndex
->AddTemplate(OUString::number(3),styleName
,pTemplate3
);
240 //pXFIndex->AddTemplate(OUString::number(2),"Secondary",pTemplate2);
241 //pXFIndex->AddTemplate(OUString::number(3),"Secondary",pTemplate3);
242 styleName
= pFoundry
->FindActuralStyleName("Secondary");
243 pXFIndex
->AddTemplate(OUString::number(2),styleName
,pTemplate2
);
244 pXFIndex
->AddTemplate(OUString::number(3),styleName
,pTemplate3
);
248 LwpMasterPage::LwpMasterPage(LwpPara
* pPara
, LwpPageLayout
* pLayout
)
249 :m_bNewSection(false),m_pPara(pPara
),m_pLayout(pLayout
)
254 * @descr: Register master page style for para style and register section style if necessary
257 bool LwpMasterPage::RegisterMasterPage(LwpFrib
* pFrib
)
259 //if there is no other frib after current firb, register master page in starting para of next page
260 if(IsNextPageType()&&(!pFrib
->HasNextFrib()))
262 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
263 pStory
->SetCurrentLayout(m_pLayout
);
264 RegisterFillerPageStyle();
268 m_bNewSection
= false;
269 //sal_Bool bSectionColumns = sal_False;
271 XFParaStyle
* pOverStyle
= new XFParaStyle
;
272 *pOverStyle
= *(m_pPara
->GetXFParaStyle());
273 pOverStyle
->SetStyleName("");
275 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
278 case LwpLayout::StartWithinColume
://not support now
280 m_bNewSection
= false;
283 case LwpLayout::StartWithinPage
:
285 m_bNewSection
= true;
286 //bSectionColumns = sal_True;
289 case LwpLayout::StartOnNextPage
://fall through
290 case LwpLayout::StartOnOddPage
: //fall through
291 case LwpLayout::StartOnEvenPage
:
293 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
294 pStory
->SetCurrentLayout(m_pLayout
);
295 //get odd page layout when the current pagelayout is mirror
296 m_pLayout
= pStory
->GetCurrentLayout();
297 m_bNewSection
= IsNeedSection();
298 //bSectionColumns = m_bNewSection;
299 pOverStyle
->SetMasterPage( m_pLayout
->GetStyleName());
300 RegisterFillerPageStyle();
307 //register tab style;
308 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
309 pStory
->SetTabLayout(m_pLayout
);
310 m_pPara
->RegisterTabStyle(pOverStyle
);
312 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
313 m_StyleName
= pXFStyleManager
->AddStyle(pOverStyle
).m_pStyle
->GetStyleName();
314 //register section style here
317 XFSectionStyle
* pSectStyle
= new XFSectionStyle();
319 pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
322 LwpPageLayout
* pCurrentLayout
= pStory
->GetCurrentLayout();
323 double fLeft
= m_pLayout
->GetMarginsValue(MARGIN_LEFT
)- pCurrentLayout
->GetMarginsValue(MARGIN_LEFT
);
324 double fRight
= m_pLayout
->GetMarginsValue(MARGIN_RIGHT
)- pCurrentLayout
->GetMarginsValue(MARGIN_RIGHT
);
325 pSectStyle
->SetMarginLeft(fLeft
);
326 pSectStyle
->SetMarginRight(fRight
);
329 //if(bSectionColumns)
332 XFColumns
* pColumns
= m_pLayout
->GetXFColumns();
335 pSectStyle
->SetColumns(pColumns
);
338 m_SectionStyleName
= pXFStyleManager
->AddStyle(pSectStyle
).m_pStyle
->GetStyleName();
344 * @descr: Whether it need create a new section
347 bool LwpMasterPage::IsNeedSection()
349 bool bNewSection
= false;
351 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
352 //if pagelayout is modified, register the pagelayout
353 if(pStory
->IsPMModified())
355 bNewSection
= pStory
->IsNeedSection();
361 * @descr: Create XFSection if necessary
364 XFSection
* LwpMasterPage::CreateXFSection()
369 XFSection
* pXFSection
= new XFSection();
370 pXFSection
->SetStyleName(m_SectionStyleName
);
377 * @descr: Parse section
380 void LwpMasterPage::ParseSection(LwpFrib
* pFrib
)
382 LwpFribPtr
& rFribPtr
= m_pPara
->GetFribs();
383 //XFParagraph * pXFPara = rFribPtr.GetXFPara();
385 //parse fillerpage text
386 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
388 XFParagraph
*pPara
= new XFParagraph();
389 pPara
->SetStyleName(GetFillerPageStyleName());
390 m_pPara
->AddXFContent(pPara
);
391 rFribPtr
.SetXFPara(pPara
);
393 m_pLayout
->ConvertFillerPageText(m_pPara
->GetXFContainer());
395 //create a new section and add it to container
396 XFContentContainer
* pContent
= CreateXFSection();
399 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID().obj().get() );
400 //delete the additional blank para, 06/28/2005
401 XFParagraph
* pCurrPara
= rFribPtr
.GetXFPara();
402 if(!pCurrPara
->HasContents())
404 XFContentContainer
* pCurrContainer
= m_pPara
->GetXFContainer();
405 if(pFrib
->HasNextFrib() && (pCurrContainer
->GetLastContent() == pCurrPara
))
407 pCurrContainer
->RemoveLastContent();
411 pStory
->AddXFContent( pContent
);
415 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID().obj().get() );
416 pContent
= pStory
->GetXFContent();
420 m_pPara
->SetXFContainer( pContent
);
422 //out put the contents after the section frib in the same para.
423 if(pFrib
->HasNextFrib())
425 XFParagraph
*pNextPara
= new XFParagraph();
426 pNextPara
->SetStyleName(GetStyleName());
427 m_pPara
->AddXFContent(pNextPara
);
428 rFribPtr
.SetXFPara(pNextPara
);
434 * @descr: Register filler page text style
437 void LwpMasterPage::RegisterFillerPageStyle()
439 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
440 if(eUserType
==LwpLayout::StartOnOddPage
441 ||eUserType
==LwpLayout::StartOnEvenPage
)
443 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
445 XFParaStyle
* pPagebreakStyle
= new XFParaStyle
;
446 *pPagebreakStyle
= *(m_pPara
->GetXFParaStyle());
447 pPagebreakStyle
->SetStyleName("");
448 pPagebreakStyle
->SetBreaks(enumXFBreakAftPage
);
449 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
450 m_FillerPageStyleName
= pXFStyleManager
->AddStyle(pPagebreakStyle
).m_pStyle
->GetStyleName();
456 * @descr: Whether the layout is next page type
459 bool LwpMasterPage::IsNextPageType()
461 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
462 if(eUserType
== LwpLayout::StartOnNextPage
463 || eUserType
== LwpLayout::StartOnOddPage
464 || eUserType
== LwpLayout::StartOnEvenPage
)
471 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */