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 ************************************************************************/
61 #include "lwpfribsection.hxx"
62 #include "lwpfribbreaks.hxx"
63 #include "lwpstory.hxx"
64 #include "lwpsection.hxx"
65 #include "xfilter/xfstylemanager.hxx"
66 #include "xfilter/xfsectionstyle.hxx"
67 #include "xfilter/xfsection.hxx"
68 #include "xfilter/xfindex.hxx"
69 #include "lwpfribptr.hxx"
70 #include "lwpglobalmgr.hxx"
72 LwpFribSection::LwpFribSection(LwpPara
*pPara
)
73 : LwpFrib(pPara
),m_pMasterPage(nullptr)
78 LwpFribSection::~LwpFribSection()
83 m_pMasterPage
= nullptr;
88 * @descr: Read section frib information
91 void LwpFribSection::Read(LwpObjectStream
*pObjStrm
, sal_uInt16
/*len*/)
93 m_Section
.ReadIndexed(pObjStrm
);
97 * @descr: Get section pointer
100 LwpSection
* LwpFribSection::GetSection()
102 return dynamic_cast<LwpSection
*>(m_Section
.obj().get());
106 * @descr: Register section style
109 void LwpFribSection::RegisterSectionStyle()
111 LwpPageLayout
* pLayout
= GetPageLayout();
114 m_pMasterPage
= new LwpMasterPage(m_pPara
, pLayout
);
115 m_pMasterPage
->RegisterMasterPage(this);
120 * @descr: Register section style
123 void LwpFribSection::SetSectionName()
125 LwpSection
* pSection
= GetSection();
128 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
131 pStory
->SetSectionName(pSection
->GetSectionName());
135 * @descr: Get page layout that current section points
138 LwpPageLayout
* LwpFribSection::GetPageLayout()
141 return GetSection()->GetPageLayout();
146 * @descr: XFConvert section
149 void LwpFribSection::ParseSection()
151 LwpPageLayout
* pLayout
= GetPageLayout();
154 // StartWithinColume not support now
155 LwpLayout::UseWhenType eSectionType
= pLayout
->GetUseWhenType();
156 if(eSectionType
==LwpLayout::StartWithinColume
)
162 m_pMasterPage
->ParseSection(this);
165 else if (LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get()))
167 rtl::Reference
<LwpObject
> xObj(m_Section
.obj());
168 if (xObj
.is() && xObj
->GetTag() == VO_INDEXSECTION
)
170 //create a new section and add it to container
171 XFIndex
* pIndex
= new XFIndex
;
172 pIndex
->SetIndexType(enumXFIndexAlphabetical
);
173 SetDefaultAlphaIndex(pIndex
);
175 pStory
->AddXFContent( pIndex
);
176 m_pPara
->SetXFContainer( pIndex
);
180 XFContentContainer
* pContent
= pStory
->GetXFContent();
181 m_pPara
->SetXFContainer( pContent
);
186 void LwpFribSection::SetDefaultAlphaIndex(XFIndex
* pXFIndex
)
188 LwpFoundry
* pFoundry
= m_pPara
->GetFoundry();
189 OUString styleName
= pFoundry
->FindActuralStyleName("Separator");
191 LwpIndexSection
* pIndexSection
= dynamic_cast<LwpIndexSection
*>(m_Section
.obj().get());
192 XFIndexTemplate
* pTemplateSep
= new XFIndexTemplate();
193 if (pIndexSection
&& pIndexSection
->IsFormatSeparator())
195 pXFIndex
->SetSeparator(true);
196 pTemplateSep
->AddEntry(enumXFIndexTemplateText
,"");
198 //pXFIndex->AddTemplate("separator","Separator",pTemplateSep);
199 pXFIndex
->AddTemplate("separator",styleName
,pTemplateSep
);
201 styleName
= pFoundry
->FindActuralStyleName("Primary");
203 XFIndexTemplate
* pTemplate1
= new XFIndexTemplate();
204 pTemplate1
->AddEntry(enumXFIndexTemplateText
,"");
205 pTemplate1
->AddEntry(enumXFIndexTemplateTab
,"");
206 pTemplate1
->AddEntry(enumXFIndexTemplatePage
,"");
207 //pXFIndex->AddTemplate(OUString::number(1),"Primary",pTemplate1);
208 pXFIndex
->AddTemplate(OUString::number(1),styleName
,pTemplate1
);
210 XFIndexTemplate
* pTemplate2
= new XFIndexTemplate();
211 pTemplate2
->AddEntry(enumXFIndexTemplateText
,"");
212 pTemplate2
->AddEntry(enumXFIndexTemplateTab
,"");
213 pTemplate2
->AddEntry(enumXFIndexTemplatePage
,"");
214 XFIndexTemplate
* pTemplate3
= new XFIndexTemplate();
215 pTemplate3
->AddEntry(enumXFIndexTemplateText
,"");
216 pTemplate3
->AddEntry(enumXFIndexTemplateTab
,"");
217 pTemplate3
->AddEntry(enumXFIndexTemplatePage
,"");
219 if (pIndexSection
&& pIndexSection
->IsFormatRunin())
221 //pXFIndex->AddTemplate(OUString::number(2),"Primary",pTemplate2);
222 //pXFIndex->AddTemplate(OUString::number(3),"Primary",pTemplate3);
223 pXFIndex
->AddTemplate(OUString::number(2),styleName
,pTemplate2
);
224 pXFIndex
->AddTemplate(OUString::number(3),styleName
,pTemplate3
);
228 //pXFIndex->AddTemplate(OUString::number(2),"Secondary",pTemplate2);
229 //pXFIndex->AddTemplate(OUString::number(3),"Secondary",pTemplate3);
230 styleName
= pFoundry
->FindActuralStyleName("Secondary");
231 pXFIndex
->AddTemplate(OUString::number(2),styleName
,pTemplate2
);
232 pXFIndex
->AddTemplate(OUString::number(3),styleName
,pTemplate3
);
236 LwpMasterPage::LwpMasterPage(LwpPara
* pPara
, LwpPageLayout
* pLayout
)
237 :m_bNewSection(false),m_pPara(pPara
),m_pLayout(pLayout
)
242 * @descr: Register master page style for para style and register section style if necessary
245 void LwpMasterPage::RegisterMasterPage(LwpFrib
* pFrib
)
247 //if there is no other frib after current frib, register master page in starting para of next page
248 LwpStory
* pStory
= nullptr;
249 if (IsNextPageType()&&(!pFrib
->HasNextFrib()))
250 pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
254 pStory
->SetCurrentLayout(m_pLayout
);
255 RegisterFillerPageStyle();
259 m_bNewSection
= false;
260 //sal_Bool bSectionColumns = sal_False;
262 XFParaStyle
* pOverStyle
= new XFParaStyle
;
263 *pOverStyle
= *(m_pPara
->GetXFParaStyle());
264 pOverStyle
->SetStyleName("");
266 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
269 case LwpLayout::StartWithinColume
://not support now
271 m_bNewSection
= false;
274 case LwpLayout::StartWithinPage
:
276 m_bNewSection
= true;
277 //bSectionColumns = sal_True;
280 case LwpLayout::StartOnNextPage
://fall through
281 case LwpLayout::StartOnOddPage
: //fall through
282 case LwpLayout::StartOnEvenPage
:
284 pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
287 pStory
->SetCurrentLayout(m_pLayout
);
288 //get odd page layout when the current pagelayout is mirror
289 m_pLayout
= pStory
->GetCurrentLayout();
290 m_bNewSection
= IsNeedSection();
291 //bSectionColumns = m_bNewSection;
292 pOverStyle
->SetMasterPage( m_pLayout
->GetStyleName());
293 RegisterFillerPageStyle();
301 //register tab style;
302 pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
306 pStory
->SetTabLayout(m_pLayout
);
307 m_pPara
->RegisterTabStyle(pOverStyle
);
309 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
310 m_StyleName
= pXFStyleManager
->AddStyle(pOverStyle
).m_pStyle
->GetStyleName();
311 //register section style here
314 XFSectionStyle
* pSectStyle
= new XFSectionStyle();
316 pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
317 LwpPageLayout
* pCurrentLayout
= pStory
? pStory
->GetCurrentLayout() : nullptr;
320 double fLeft
= m_pLayout
->GetMarginsValue(MARGIN_LEFT
) - pCurrentLayout
->GetMarginsValue(MARGIN_LEFT
);
321 double fRight
= m_pLayout
->GetMarginsValue(MARGIN_RIGHT
) - pCurrentLayout
->GetMarginsValue(MARGIN_RIGHT
);
322 pSectStyle
->SetMarginLeft(fLeft
);
323 pSectStyle
->SetMarginRight(fRight
);
326 //if(bSectionColumns)
329 XFColumns
* pColumns
= m_pLayout
->GetXFColumns();
332 pSectStyle
->SetColumns(pColumns
);
335 m_SectionStyleName
= pXFStyleManager
->AddStyle(pSectStyle
).m_pStyle
->GetStyleName();
340 * @descr: Whether it need create a new section
343 bool LwpMasterPage::IsNeedSection()
345 bool bNewSection
= false;
347 LwpStory
* pStory
= dynamic_cast<LwpStory
*>(m_pPara
->GetStoryID().obj().get());
348 //if pagelayout is modified, register the pagelayout
349 if (pStory
&& pStory
->IsPMModified())
351 bNewSection
= pStory
->IsNeedSection();
357 * @descr: Create XFSection if necessary
360 XFSection
* LwpMasterPage::CreateXFSection()
365 XFSection
* pXFSection
= new XFSection();
366 pXFSection
->SetStyleName(m_SectionStyleName
);
373 * @descr: Parse section
376 void LwpMasterPage::ParseSection(LwpFrib
* pFrib
)
378 LwpFribPtr
& rFribPtr
= m_pPara
->GetFribs();
379 //XFParagraph * pXFPara = rFribPtr.GetXFPara();
381 //parse fillerpage text
382 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
384 XFParagraph
*pPara
= new XFParagraph();
385 pPara
->SetStyleName(GetFillerPageStyleName());
386 m_pPara
->AddXFContent(pPara
);
387 rFribPtr
.SetXFPara(pPara
);
389 m_pLayout
->ConvertFillerPageText(m_pPara
->GetXFContainer());
391 //create a new section and add it to container
392 XFContentContainer
* pContent
= CreateXFSection();
395 LwpStory
* pStory
= dynamic_cast<LwpStory
*> ( m_pPara
->GetStoryID().obj().get() );
396 //delete the additional blank para
397 XFParagraph
* pCurrPara
= rFribPtr
.GetXFPara();
398 if(!pCurrPara
->HasContents())
400 XFContentContainer
* pCurrContainer
= m_pPara
->GetXFContainer();
401 if(pFrib
->HasNextFrib() && (pCurrContainer
->GetLastContent() == pCurrPara
))
403 pCurrContainer
->RemoveLastContent();
407 pStory
->AddXFContent( pContent
);
411 LwpStory
* pStory
= dynamic_cast<LwpStory
*> ( m_pPara
->GetStoryID().obj().get() );
412 pContent
= pStory
? pStory
->GetXFContent() : nullptr;
416 m_pPara
->SetXFContainer( pContent
);
418 //out put the contents after the section frib in the same para.
419 if(pFrib
->HasNextFrib())
421 XFParagraph
*pNextPara
= new XFParagraph();
422 pNextPara
->SetStyleName(GetStyleName());
423 m_pPara
->AddXFContent(pNextPara
);
424 rFribPtr
.SetXFPara(pNextPara
);
430 * @descr: Register filler page text style
433 void LwpMasterPage::RegisterFillerPageStyle()
435 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
436 if(eUserType
==LwpLayout::StartOnOddPage
437 ||eUserType
==LwpLayout::StartOnEvenPage
)
439 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
441 XFParaStyle
* pPagebreakStyle
= new XFParaStyle
;
442 *pPagebreakStyle
= *(m_pPara
->GetXFParaStyle());
443 pPagebreakStyle
->SetStyleName("");
444 pPagebreakStyle
->SetBreaks(enumXFBreakAftPage
);
445 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
446 m_FillerPageStyleName
= pXFStyleManager
->AddStyle(pPagebreakStyle
).m_pStyle
->GetStyleName();
452 * @descr: Whether the layout is next page type
455 bool LwpMasterPage::IsNextPageType()
457 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
458 if(eUserType
== LwpLayout::StartOnNextPage
459 || eUserType
== LwpLayout::StartOnOddPage
460 || eUserType
== LwpLayout::StartOnEvenPage
)
467 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */