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());
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());
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() );
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(A2OUSTR(""),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(A2OUSTR("Separator"));
203 LwpIndexSection
* pIndexSection
= static_cast<LwpIndexSection
*>(m_Section
.obj());
204 XFIndexTemplate
* pTemplateSep
= new XFIndexTemplate();
205 if (pIndexSection
->IsFormatSeparator())
207 pXFIndex
->SetSeparator(sal_True
);
208 pTemplateSep
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
210 //pXFIndex->AddTemplate(A2OUSTR("separator"),A2OUSTR("Separator"),pTemplateSep);
211 pXFIndex
->AddTemplate(A2OUSTR("separator"),styleName
,pTemplateSep
);
214 styleName
= pFoundry
->FindActuralStyleName(A2OUSTR("Primary"));
216 XFIndexTemplate
* pTemplate1
= new XFIndexTemplate();
217 pTemplate1
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
218 pTemplate1
->AddEntry(enumXFIndexTemplateTab
,A2OUSTR(""));
219 pTemplate1
->AddEntry(enumXFIndexTemplatePage
,A2OUSTR(""));
220 //pXFIndex->AddTemplate(Int32ToOUString(1),A2OUSTR("Primary"),pTemplate1);
221 pXFIndex
->AddTemplate(Int32ToOUString(1),styleName
,pTemplate1
);
223 XFIndexTemplate
* pTemplate2
= new XFIndexTemplate();
224 pTemplate2
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
225 pTemplate2
->AddEntry(enumXFIndexTemplateTab
,A2OUSTR(""));
226 pTemplate2
->AddEntry(enumXFIndexTemplatePage
,A2OUSTR(""));
227 XFIndexTemplate
* pTemplate3
= new XFIndexTemplate();
228 pTemplate3
->AddEntry(enumXFIndexTemplateText
,A2OUSTR(""));
229 pTemplate3
->AddEntry(enumXFIndexTemplateTab
,A2OUSTR(""));
230 pTemplate3
->AddEntry(enumXFIndexTemplatePage
,A2OUSTR(""));
232 if (pIndexSection
->IsFormatRunin())
234 //pXFIndex->AddTemplate(Int32ToOUString(2),A2OUSTR("Primary"),pTemplate2);
235 //pXFIndex->AddTemplate(Int32ToOUString(3),A2OUSTR("Primary"),pTemplate3);
236 pXFIndex
->AddTemplate(Int32ToOUString(2),styleName
,pTemplate2
);
237 pXFIndex
->AddTemplate(Int32ToOUString(3),styleName
,pTemplate3
);
241 //pXFIndex->AddTemplate(Int32ToOUString(2),A2OUSTR("Secondary"),pTemplate2);
242 //pXFIndex->AddTemplate(Int32ToOUString(3),A2OUSTR("Secondary"),pTemplate3);
243 styleName
= pFoundry
->FindActuralStyleName(A2OUSTR("Secondary"));
244 pXFIndex
->AddTemplate(Int32ToOUString(2),styleName
,pTemplate2
);
245 pXFIndex
->AddTemplate(Int32ToOUString(3),styleName
,pTemplate3
);
250 LwpMasterPage::LwpMasterPage(LwpPara
* pPara
, LwpPageLayout
* pLayout
)
251 :m_bNewSection(sal_False
),m_pPara(pPara
),m_pLayout(pLayout
)
256 * @descr: Register master page style for para style and register section style if necessary
259 sal_Bool
LwpMasterPage::RegisterMasterPage(LwpFrib
* pFrib
)
261 //if there is no other frib after current firb, register master page in starting para of next page
262 if(IsNextPageType()&&(!pFrib
->HasNextFrib()))
264 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
265 pStory
->SetCurrentLayout(m_pLayout
);
266 RegisterFillerPageStyle();
270 m_bNewSection
= sal_False
;
271 //sal_Bool bSectionColumns = sal_False;
273 XFParaStyle
* pOverStyle
= new XFParaStyle
;
274 *pOverStyle
= *(m_pPara
->GetXFParaStyle());
275 pOverStyle
->SetStyleName(A2OUSTR(""));
277 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
280 case LwpLayout::StartWithinColume
://not support now
282 m_bNewSection
= sal_False
;
285 case LwpLayout::StartWithinPage
:
287 m_bNewSection
= sal_True
;
288 //bSectionColumns = sal_True;
291 case LwpLayout::StartOnNextPage
: //fall throught
292 case LwpLayout::StartOnOddPage
: //fall throught
293 case LwpLayout::StartOnEvenPage
:
295 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
296 pStory
->SetCurrentLayout(m_pLayout
);
297 //get odd page layout when the current pagelayout is mirror
298 m_pLayout
= pStory
->GetCurrentLayout();
299 m_bNewSection
= IsNeedSection();
300 //bSectionColumns = m_bNewSection;
301 pOverStyle
->SetMasterPage( m_pLayout
->GetStyleName());
302 RegisterFillerPageStyle();
309 //register tab style;
310 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
311 pStory
->SetTabLayout(m_pLayout
);
312 m_pPara
->RegisterTabStyle(pOverStyle
);
314 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
315 m_StyleName
= pXFStyleManager
->AddStyle(pOverStyle
)->GetStyleName();
316 //register section style here
319 XFSectionStyle
* pSectStyle
= new XFSectionStyle();
321 pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
324 LwpPageLayout
* pCurrentLayout
= pStory
->GetCurrentLayout();
325 double fLeft
= m_pLayout
->GetMarginsValue(MARGIN_LEFT
)- pCurrentLayout
->GetMarginsValue(MARGIN_LEFT
);
326 double fRight
= m_pLayout
->GetMarginsValue(MARGIN_RIGHT
)- pCurrentLayout
->GetMarginsValue(MARGIN_RIGHT
);
327 pSectStyle
->SetMarginLeft(fLeft
);
328 pSectStyle
->SetMarginRight(fRight
);
331 //if(bSectionColumns)
334 XFColumns
* pColumns
= m_pLayout
->GetXFColumns();
337 pSectStyle
->SetColumns(pColumns
);
340 m_SectionStyleName
= pXFStyleManager
->AddStyle(pSectStyle
)->GetStyleName();
346 * @descr: Whether it need create a new section
349 sal_Bool
LwpMasterPage::IsNeedSection()
351 sal_Bool bNewSection
= sal_False
;
353 LwpStory
* pStory
= static_cast<LwpStory
*>(m_pPara
->GetStoryID()->obj());
354 //if pagelayout is modified, register the pagelayout
355 if(pStory
->IsPMModified())
357 bNewSection
= pStory
->IsNeedSection();
363 * @descr: Create XFSection if necessary
366 XFSection
* LwpMasterPage::CreateXFSection()
371 XFSection
* pXFSection
= new XFSection();
372 pXFSection
->SetStyleName(m_SectionStyleName
);
379 * @descr: Parse section
382 void LwpMasterPage::ParseSection(LwpFrib
* pFrib
)
384 LwpFribPtr
* pFribPtr
= m_pPara
->GetFribs();
385 //XFParagraph * pXFPara = pFribPtr->GetXFPara();
387 //parse fillerpage text
388 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
390 XFParagraph
*pPara
= new XFParagraph();
391 pPara
->SetStyleName(GetFillerPageStyleName());
392 m_pPara
->AddXFContent(pPara
);
393 pFribPtr
->SetXFPara(pPara
);
395 m_pLayout
->ConvertFillerPageText(m_pPara
->GetXFContainer());
397 //create a new section and add it to container
398 XFContentContainer
* pContent
= CreateXFSection();
401 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID()->obj() );
402 //delete the additional blank para, 06/28/2005
403 XFParagraph
* pCurrPara
= pFribPtr
->GetXFPara();
404 if(!pCurrPara
->HasContents())
406 XFContentContainer
* pCurrContainer
= m_pPara
->GetXFContainer();
407 if(pFrib
->HasNextFrib() && (pCurrContainer
->GetLastContent() == pCurrPara
))
409 pCurrContainer
->RemoveLastContent();
413 pStory
->AddXFContent( pContent
);
417 LwpStory
* pStory
= static_cast<LwpStory
*> ( m_pPara
->GetStoryID()->obj() );
418 pContent
= pStory
->GetXFContent();
422 m_pPara
->SetXFContainer( pContent
);
424 //out put the contents after the section frib in the same para.
425 if(pFrib
->HasNextFrib())
427 XFParagraph
*pNextPara
= new XFParagraph();
428 pNextPara
->SetStyleName(GetStyleName());
429 m_pPara
->AddXFContent(pNextPara
);
430 pFribPtr
->SetXFPara(pNextPara
);
436 * @descr: Register filler page text style
439 void LwpMasterPage::RegisterFillerPageStyle()
441 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
442 if(eUserType
==LwpLayout::StartOnOddPage
443 ||eUserType
==LwpLayout::StartOnEvenPage
)
445 if(m_pLayout
->HasFillerPageText(m_pPara
->GetFoundry()))
447 XFParaStyle
* pPagebreakStyle
= new XFParaStyle
;
448 *pPagebreakStyle
= *(m_pPara
->GetXFParaStyle());
449 pPagebreakStyle
->SetStyleName(A2OUSTR(""));
450 pPagebreakStyle
->SetBreaks(enumXFBreakAftPage
);
451 XFStyleManager
* pXFStyleManager
= LwpGlobalMgr::GetInstance()->GetXFStyleManager();
452 m_FillerPageStyleName
= pXFStyleManager
->AddStyle(pPagebreakStyle
)->GetStyleName();
458 * @descr: Whether the layout is next page type
461 sal_Bool
LwpMasterPage::IsNextPageType()
463 LwpLayout::UseWhenType eUserType
= m_pLayout
->GetUseWhenType();
464 if(eUserType
== LwpLayout::StartOnNextPage
465 || eUserType
== LwpLayout::StartOnOddPage
466 || eUserType
== LwpLayout::StartOnEvenPage
)
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */