android: Update app-specific/MIME type icons
[LibreOffice.git] / lotuswordpro / source / filter / lwpfribsection.cxx
bloba65763f38bd070eca974af4efc49a3e244c208cf
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,
29 * MA 02111-1307 USA
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 /*************************************************************************
57 * @file
58 * the class for section frib and process section and page layout
59 ************************************************************************/
61 #include "lwpfribsection.hxx"
62 #include "lwpstory.hxx"
63 #include "lwpsection.hxx"
64 #include <xfilter/xfstylemanager.hxx>
65 #include <xfilter/xfsectionstyle.hxx>
66 #include <xfilter/xfsection.hxx>
67 #include <xfilter/xfindex.hxx>
68 #include "lwpfribptr.hxx"
69 #include <lwpglobalmgr.hxx>
71 LwpFribSection::LwpFribSection(LwpPara* pPara)
72 : LwpFrib(pPara)
76 LwpFribSection::~LwpFribSection() {}
78 /**
79 * @descr: Read section frib information
82 void LwpFribSection::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
84 m_Section.ReadIndexed(pObjStrm);
87 /**
88 * @descr: Get section pointer
91 LwpSection* LwpFribSection::GetSection()
93 return dynamic_cast<LwpSection*>(m_Section.obj().get());
96 /**
97 * @descr: Register section style
100 void LwpFribSection::RegisterSectionStyle()
102 LwpPageLayout* pLayout = GetPageLayout();
103 if (pLayout)
105 m_pMasterPage.reset(new LwpMasterPage(m_pPara, pLayout));
106 m_pMasterPage->RegisterMasterPage(this);
111 * @descr: Register section style
114 void LwpFribSection::SetSectionName()
116 LwpSection* pSection = GetSection();
117 if (!pSection)
118 return;
119 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
120 if (!pStory)
121 return;
122 pStory->SetSectionName(pSection->GetSectionName());
126 * @descr: Get page layout that current section points
129 LwpPageLayout* LwpFribSection::GetPageLayout()
131 if (LwpSection* pSection = GetSection())
132 return pSection->GetPageLayout();
133 return nullptr;
137 * @descr: XFConvert section
140 void LwpFribSection::ParseSection()
142 LwpPageLayout* pLayout = GetPageLayout();
143 if (pLayout)
145 // StartWithinColume not support now
146 LwpLayout::UseWhenType eSectionType = pLayout->GetUseWhenType();
147 if (eSectionType == LwpLayout::StartWithinColume)
149 return;
151 if (m_pMasterPage)
153 m_pMasterPage->ParseSection(this);
156 else if (LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get()))
158 rtl::Reference<LwpObject> xObj(m_Section.obj());
159 if (xObj.is() && xObj->GetTag() == VO_INDEXSECTION)
161 //create a new section and add it to container
162 XFIndex* pIndex = new XFIndex;
163 pIndex->SetIndexType(enumXFIndexAlphabetical);
164 SetDefaultAlphaIndex(pIndex);
166 pStory->AddXFContent(pIndex);
167 m_pPara->SetXFContainer(pIndex);
169 else
171 XFContentContainer* pContent = pStory->GetXFContent();
172 m_pPara->SetXFContainer(pContent);
177 void LwpFribSection::SetDefaultAlphaIndex(XFIndex* pXFIndex)
179 LwpFoundry* pFoundry = m_pPara->GetFoundry();
180 OUString styleName = pFoundry->FindActualStyleName("Separator");
182 LwpIndexSection* pIndexSection = dynamic_cast<LwpIndexSection*>(m_Section.obj().get());
183 XFIndexTemplate* pTemplateSep = new XFIndexTemplate();
184 if (pIndexSection && pIndexSection->IsFormatSeparator())
186 pXFIndex->SetSeparator(true);
187 pTemplateSep->AddEntry(enumXFIndexTemplateText, "");
189 //pXFIndex->AddTemplate("separator","Separator",pTemplateSep);
190 pXFIndex->AddTemplate("separator", styleName, pTemplateSep);
192 styleName = pFoundry->FindActualStyleName("Primary");
194 XFIndexTemplate* pTemplate1 = new XFIndexTemplate();
195 pTemplate1->AddEntry(enumXFIndexTemplateText, "");
196 pTemplate1->AddEntry(enumXFIndexTemplateTab, "");
197 pTemplate1->AddEntry(enumXFIndexTemplatePage, "");
198 //pXFIndex->AddTemplate(OUString::number(1),"Primary",pTemplate1);
199 pXFIndex->AddTemplate(OUString::number(1), styleName, pTemplate1);
201 XFIndexTemplate* pTemplate2 = new XFIndexTemplate();
202 pTemplate2->AddEntry(enumXFIndexTemplateText, "");
203 pTemplate2->AddEntry(enumXFIndexTemplateTab, "");
204 pTemplate2->AddEntry(enumXFIndexTemplatePage, "");
205 XFIndexTemplate* pTemplate3 = new XFIndexTemplate();
206 pTemplate3->AddEntry(enumXFIndexTemplateText, "");
207 pTemplate3->AddEntry(enumXFIndexTemplateTab, "");
208 pTemplate3->AddEntry(enumXFIndexTemplatePage, "");
210 if (pIndexSection && pIndexSection->IsFormatRunin())
212 //pXFIndex->AddTemplate(OUString::number(2),"Primary",pTemplate2);
213 //pXFIndex->AddTemplate(OUString::number(3),"Primary",pTemplate3);
214 pXFIndex->AddTemplate(OUString::number(2), styleName, pTemplate2);
215 pXFIndex->AddTemplate(OUString::number(3), styleName, pTemplate3);
217 else
219 //pXFIndex->AddTemplate(OUString::number(2),"Secondary",pTemplate2);
220 //pXFIndex->AddTemplate(OUString::number(3),"Secondary",pTemplate3);
221 styleName = pFoundry->FindActualStyleName("Secondary");
222 pXFIndex->AddTemplate(OUString::number(2), styleName, pTemplate2);
223 pXFIndex->AddTemplate(OUString::number(3), styleName, pTemplate3);
227 LwpMasterPage::LwpMasterPage(LwpPara* pPara, LwpPageLayout* pLayout)
228 : m_bNewSection(false)
229 , m_pPara(pPara)
230 , m_pLayout(pLayout)
235 * @descr: Register master page style for para style and register section style if necessary
238 void LwpMasterPage::RegisterMasterPage(LwpFrib* pFrib)
240 //if there is no other frib after current frib, register master page in starting para of next page
241 LwpStory* pStory = nullptr;
242 if (IsNextPageType() && (!pFrib->HasNextFrib()))
243 pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
245 if (pStory)
247 pStory->SetCurrentLayout(m_pLayout);
248 RegisterFillerPageStyle();
249 return;
252 m_bNewSection = false;
253 //sal_Bool bSectionColumns = sal_False;
255 std::unique_ptr<XFParaStyle> xOverStyle(new XFParaStyle);
256 *xOverStyle = *(m_pPara->GetXFParaStyle());
257 xOverStyle->SetStyleName("");
259 LwpLayout::UseWhenType eUserType = m_pLayout->GetUseWhenType();
260 switch (eUserType)
262 case LwpLayout::StartWithinColume: //not support now
264 m_bNewSection = false;
265 break;
267 case LwpLayout::StartWithinPage:
269 m_bNewSection = true;
270 //bSectionColumns = sal_True;
271 break;
273 case LwpLayout::StartOnNextPage: //fall through
274 case LwpLayout::StartOnOddPage: //fall through
275 case LwpLayout::StartOnEvenPage:
277 pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
278 if (pStory)
280 pStory->SetCurrentLayout(m_pLayout);
281 //get odd page layout when the current pagelayout is mirror
282 m_pLayout = pStory->GetCurrentLayout();
283 m_bNewSection = IsNeedSection();
284 //bSectionColumns = m_bNewSection;
285 xOverStyle->SetMasterPage(m_pLayout->GetStyleName());
286 RegisterFillerPageStyle();
288 break;
290 default:
291 break;
294 //register tab style;
295 pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
296 if (!pStory)
297 return;
299 pStory->SetTabLayout(m_pLayout);
300 m_pPara->RegisterTabStyle(xOverStyle.get());
302 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
303 m_StyleName = pXFStyleManager->AddStyle(std::move(xOverStyle)).m_pStyle->GetStyleName();
304 //register section style here
305 if (!m_bNewSection)
306 return;
308 std::unique_ptr<XFSectionStyle> pSectStyle(new XFSectionStyle());
309 //set margin
310 pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
311 LwpPageLayout* pCurrentLayout = pStory ? pStory->GetCurrentLayout() : nullptr;
312 if (pCurrentLayout)
314 double fLeft = m_pLayout->GetMarginsValue(MARGIN_LEFT)
315 - pCurrentLayout->GetMarginsValue(MARGIN_LEFT);
316 double fRight = m_pLayout->GetMarginsValue(MARGIN_RIGHT)
317 - pCurrentLayout->GetMarginsValue(MARGIN_RIGHT);
318 pSectStyle->SetMarginLeft(fLeft);
319 pSectStyle->SetMarginRight(fRight);
322 XFColumns* pColumns = m_pLayout->GetXFColumns();
323 if (pColumns)
325 pSectStyle->SetColumns(pColumns);
327 m_SectionStyleName = pXFStyleManager->AddStyle(std::move(pSectStyle)).m_pStyle->GetStyleName();
331 * @descr: Whether it needs to create a new section
334 bool LwpMasterPage::IsNeedSection()
336 bool bNewSection = false;
337 //get story
338 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
339 //if pagelayout is modified, register the pagelayout
340 if (pStory && pStory->IsPMModified())
342 bNewSection = pStory->IsNeedSection();
344 return bNewSection;
348 * @descr: Create XFSection if necessary
351 XFSection* LwpMasterPage::CreateXFSection()
353 if (m_bNewSection)
355 //new a section
356 XFSection* pXFSection = new XFSection();
357 pXFSection->SetStyleName(m_SectionStyleName);
358 return pXFSection;
360 return nullptr;
364 * @descr: Parse section
367 void LwpMasterPage::ParseSection(LwpFrib* pFrib)
369 LwpFribPtr& rFribPtr = m_pPara->GetFribs();
370 //XFParagraph * pXFPara = rFribPtr.GetXFPara();
372 //parse fillerpage text
373 if (m_pLayout->HasFillerPageText(m_pPara->GetFoundry()))
375 XFParagraph* pPara = new XFParagraph();
376 pPara->SetStyleName(m_FillerPageStyleName);
377 m_pPara->AddXFContent(pPara);
378 rFribPtr.SetXFPara(pPara);
380 m_pLayout->ConvertFillerPageText(m_pPara->GetXFContainer());
382 //create a new section and add it to container
383 XFContentContainer* pContent = CreateXFSection();
384 if (pContent)
386 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
387 //delete the additional blank para
388 XFParagraph* pCurrPara = rFribPtr.GetXFPara();
389 if (!pCurrPara->HasContents())
391 XFContentContainer* pCurrContainer = m_pPara->GetXFContainer();
392 if (pFrib->HasNextFrib() && (pCurrContainer->GetLastContent() == pCurrPara))
394 pCurrContainer->RemoveLastContent();
397 if (pStory)
398 pStory->AddXFContent(pContent);
400 else
402 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
403 pContent = pStory ? pStory->GetXFContent() : nullptr;
405 if (pContent)
407 m_pPara->SetXFContainer(pContent);
409 //out put the contents after the section frib in the same para.
410 if (pFrib->HasNextFrib())
412 XFParagraph* pNextPara = new XFParagraph();
413 pNextPara->SetStyleName(m_StyleName);
414 m_pPara->AddXFContent(pNextPara);
415 rFribPtr.SetXFPara(pNextPara);
420 * @descr: Register filler page text style
423 void LwpMasterPage::RegisterFillerPageStyle()
425 LwpLayout::UseWhenType eUserType = m_pLayout->GetUseWhenType();
426 if (eUserType != LwpLayout::StartOnOddPage && eUserType != LwpLayout::StartOnEvenPage)
427 return;
429 if (m_pLayout->HasFillerPageText(m_pPara->GetFoundry()))
431 std::unique_ptr<XFParaStyle> pPagebreakStyle(new XFParaStyle);
432 *pPagebreakStyle = *(m_pPara->GetXFParaStyle());
433 pPagebreakStyle->SetStyleName("");
434 pPagebreakStyle->SetBreaks(enumXFBreakAftPage);
435 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
436 m_FillerPageStyleName
437 = pXFStyleManager->AddStyle(std::move(pPagebreakStyle)).m_pStyle->GetStyleName();
442 * @descr: Whether the layout is next page type
445 bool LwpMasterPage::IsNextPageType()
447 LwpLayout::UseWhenType eUserType = m_pLayout->GetUseWhenType();
448 return eUserType == LwpLayout::StartOnNextPage || eUserType == LwpLayout::StartOnOddPage
449 || eUserType == LwpLayout::StartOnEvenPage;
452 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */