LibreOffice Module lotuswordpro (master) 1
lwpfribsection.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*************************************************************************
3 *
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
6 *
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
9 *
10 * Sun Microsystems Inc., October, 2000
11 *
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
16 *
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.
20 *
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.
25 *
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
30 *
31 *
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.
38 *
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.
45 *
46 * The Initial Developer of the Original Code is: IBM Corporation
47 *
48 * Copyright: 2008 by IBM Corporation
49 *
50 * All Rights Reserved.
51 *
52 * Contributor(s): _______________________________________
53 *
54 *
55 ************************************************************************/
56/*************************************************************************
57 * @file
58 * the class for section frib and process section and page layout
59 ************************************************************************/
60
61#include "lwpfribsection.hxx"
62#include "lwpstory.hxx"
63#include "lwpsection.hxx"
66#include <xfilter/xfsection.hxx>
67#include <xfilter/xfindex.hxx>
68#include "lwpfribptr.hxx"
69#include <lwpglobalmgr.hxx>
70
72 : LwpFrib(pPara)
73{
74}
75
77
82void LwpFribSection::Read(LwpObjectStream* pObjStrm, sal_uInt16 /*len*/)
83{
84 m_Section.ReadIndexed(pObjStrm);
85}
86
92{
93 return dynamic_cast<LwpSection*>(m_Section.obj().get());
94}
95
101{
102 LwpPageLayout* pLayout = GetPageLayout();
103 if (pLayout)
104 {
105 m_pMasterPage.reset(new LwpMasterPage(m_pPara, pLayout));
106 m_pMasterPage->RegisterMasterPage(this);
107 }
108}
109
115{
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());
123}
124
130{
131 if (LwpSection* pSection = GetSection())
132 return pSection->GetPageLayout();
133 return nullptr;
134}
135
141{
142 LwpPageLayout* pLayout = GetPageLayout();
143 if (pLayout)
144 {
145 // StartWithinColume not support now
146 LwpLayout::UseWhenType eSectionType = pLayout->GetUseWhenType();
147 if (eSectionType == LwpLayout::StartWithinColume)
148 {
149 return;
150 }
151 if (m_pMasterPage)
152 {
153 m_pMasterPage->ParseSection(this);
154 }
155 }
156 else if (LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get()))
157 {
159 if (xObj.is() && xObj->GetTag() == VO_INDEXSECTION)
160 {
161 //create a new section and add it to container
162 XFIndex* pIndex = new XFIndex;
164 SetDefaultAlphaIndex(pIndex);
165
166 pStory->AddXFContent(pIndex);
167 m_pPara->SetXFContainer(pIndex);
168 }
169 else
170 {
171 XFContentContainer* pContent = pStory->GetXFContent();
172 m_pPara->SetXFContainer(pContent);
173 }
174 }
175}
176
178{
179 LwpFoundry* pFoundry = m_pPara->GetFoundry();
180 OUString styleName = pFoundry->FindActualStyleName("Separator");
181
182 LwpIndexSection* pIndexSection = dynamic_cast<LwpIndexSection*>(m_Section.obj().get());
183 XFIndexTemplate* pTemplateSep = new XFIndexTemplate();
184 if (pIndexSection && pIndexSection->IsFormatSeparator())
185 {
186 pXFIndex->SetSeparator(true);
187 pTemplateSep->AddEntry(enumXFIndexTemplateText, "");
188 }
189 //pXFIndex->AddTemplate("separator","Separator",pTemplateSep);
190 pXFIndex->AddTemplate("separator", styleName, pTemplateSep);
191
192 styleName = pFoundry->FindActualStyleName("Primary");
193
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);
200
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, "");
209
210 if (pIndexSection && pIndexSection->IsFormatRunin())
211 {
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);
216 }
217 else
218 {
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);
224 }
225}
226
228 : m_bNewSection(false)
229 , m_pPara(pPara)
230 , m_pLayout(pLayout)
231{
232}
233
239{
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());
244
245 if (pStory)
246 {
249 return;
250 }
251
252 m_bNewSection = false;
253 //sal_Bool bSectionColumns = sal_False;
254
255 std::unique_ptr<XFParaStyle> xOverStyle(new XFParaStyle);
256 *xOverStyle = *(m_pPara->GetXFParaStyle());
257 xOverStyle->SetStyleName("");
258
260 switch (eUserType)
261 {
262 case LwpLayout::StartWithinColume: //not support now
263 {
264 m_bNewSection = false;
265 break;
266 }
268 {
269 m_bNewSection = true;
270 //bSectionColumns = sal_True;
271 break;
272 }
273 case LwpLayout::StartOnNextPage: //fall through
274 case LwpLayout::StartOnOddPage: //fall through
276 {
277 pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
278 if (pStory)
279 {
281 //get odd page layout when the current pagelayout is mirror
282 m_pLayout = pStory->GetCurrentLayout();
284 //bSectionColumns = m_bNewSection;
285 xOverStyle->SetMasterPage(m_pLayout->GetStyleName());
287 }
288 break;
289 }
290 default:
291 break;
292 }
293
294 //register tab style;
295 pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
296 if (!pStory)
297 return;
298
299 pStory->SetTabLayout(m_pLayout);
300 m_pPara->RegisterTabStyle(xOverStyle.get());
301
303 m_StyleName = pXFStyleManager->AddStyle(std::move(xOverStyle)).m_pStyle->GetStyleName();
304 //register section style here
305 if (!m_bNewSection)
306 return;
307
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)
313 {
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);
320 }
321
322 XFColumns* pColumns = m_pLayout->GetXFColumns();
323 if (pColumns)
324 {
325 pSectStyle->SetColumns(pColumns);
326 }
327 m_SectionStyleName = pXFStyleManager->AddStyle(std::move(pSectStyle)).m_pStyle->GetStyleName();
328}
329
335{
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())
341 {
342 bNewSection = pStory->IsNeedSection();
343 }
344 return bNewSection;
345}
346
352{
353 if (m_bNewSection)
354 {
355 //new a section
356 XFSection* pXFSection = new XFSection();
357 pXFSection->SetStyleName(m_SectionStyleName);
358 return pXFSection;
359 }
360 return nullptr;
361}
362
368{
369 LwpFribPtr& rFribPtr = m_pPara->GetFribs();
370 //XFParagraph * pXFPara = rFribPtr.GetXFPara();
371
372 //parse fillerpage text
374 {
375 XFParagraph* pPara = new XFParagraph();
377 m_pPara->AddXFContent(pPara);
378 rFribPtr.SetXFPara(pPara);
379
381 }
382 //create a new section and add it to container
384 if (pContent)
385 {
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())
390 {
391 XFContentContainer* pCurrContainer = m_pPara->GetXFContainer();
392 if (pFrib->HasNextFrib() && (pCurrContainer->GetLastContent() == pCurrPara))
393 {
394 pCurrContainer->RemoveLastContent();
395 }
396 }
397 if (pStory)
398 pStory->AddXFContent(pContent);
399 }
400 else
401 {
402 LwpStory* pStory = dynamic_cast<LwpStory*>(m_pPara->GetStoryID().obj().get());
403 pContent = pStory ? pStory->GetXFContent() : nullptr;
404 }
405 if (pContent)
406 {
407 m_pPara->SetXFContainer(pContent);
408 }
409 //out put the contents after the section frib in the same para.
410 if (pFrib->HasNextFrib())
411 {
412 XFParagraph* pNextPara = new XFParagraph();
413 pNextPara->SetStyleName(m_StyleName);
414 m_pPara->AddXFContent(pNextPara);
415 rFribPtr.SetXFPara(pNextPara);
416 }
417}
418
424{
426 if (eUserType != LwpLayout::StartOnOddPage && eUserType != LwpLayout::StartOnEvenPage)
427 return;
428
430 {
431 std::unique_ptr<XFParaStyle> pPagebreakStyle(new XFParaStyle);
432 *pPagebreakStyle = *(m_pPara->GetXFParaStyle());
433 pPagebreakStyle->SetStyleName("");
434 pPagebreakStyle->SetBreaks(enumXFBreakAftPage);
437 = pXFStyleManager->AddStyle(std::move(pPagebreakStyle)).m_pStyle->GetStyleName();
438 }
439}
440
446{
448 return eUserType == LwpLayout::StartOnNextPage || eUserType == LwpLayout::StartOnOddPage
449 || eUserType == LwpLayout::StartOnEvenPage;
450}
451
452/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual OUString GetStyleName()=0
@descr: return the style name.
OUString FindActualStyleName(const OUString &name)
@descr: Get style name registered according the original style name
Definition: lwpfoundry.cxx:288
XFParagraph * GetXFPara()
Definition: lwpfribptr.hxx:86
void SetXFPara(XFParagraph *Para)
Definition: lwpfribptr.hxx:85
void ParseSection()
@descr: XFConvert section
void SetDefaultAlphaIndex(XFIndex *pXFIndex)
LwpObjectID m_Section
LwpPageLayout * GetPageLayout()
@descr: Get page layout that current section points
LwpSection * GetSection()
@descr: Get section pointer
LwpFribSection(LwpPara *pPara)
std::unique_ptr< LwpMasterPage > m_pMasterPage
void Read(LwpObjectStream *pObjStrm, sal_uInt16 len) override
@descr: Read section frib information
void RegisterSectionStyle()
@descr: Register section style
virtual ~LwpFribSection() override
void SetSectionName()
@descr: Register section style
LwpPara * m_pPara
Definition: lwpfrib.hxx:104
bool HasNextFrib()
@descr: Whether there are other fribs following current frib.
Definition: lwpfrib.cxx:378
XFStyleManager * GetXFStyleManager()
static LwpGlobalMgr * GetInstance(LwpSvStream *pSvStream=nullptr)
bool IsFormatRunin() const
Definition: lwpsection.cxx:137
bool IsFormatSeparator() const
Definition: lwpsection.cxx:139
UseWhenType GetUseWhenType()
@descr: Get use when type
Definition: lwplayout.cxx:1651
@ StartWithinPage
Definition: lwplayout.hxx:439
@ StartWithinColume
Definition: lwplayout.hxx:438
@ StartOnNextPage
Definition: lwplayout.hxx:440
@ StartOnEvenPage
Definition: lwplayout.hxx:442
@ StartOnOddPage
Definition: lwplayout.hxx:441
XFColumns * GetXFColumns()
@descr: Create and return XFColumns object
Definition: lwplayout.cxx:1570
Process page layout for inserting pagelayout or section.
bool IsNextPageType()
@descr: Whether the layout is next page type
LwpPageLayout * m_pLayout
XFSection * CreateXFSection()
@descr: Create XFSection if necessary
OUString m_FillerPageStyleName
void ParseSection(LwpFrib *pFrib)
@descr: Parse section
OUString m_StyleName
void RegisterFillerPageStyle()
@descr: Register filler page text style
LwpMasterPage(LwpPara *pPara, LwpPageLayout *pLayout)
void RegisterMasterPage(LwpFrib *pFrib)
@descr: Register master page style for para style and register section style if necessary
LwpPara * m_pPara
OUString m_SectionStyleName
bool IsNeedSection()
@descr: Whether it needs to create a new section
void ReadIndexed(LwpSvStream *pStrm)
@descr Read object id with indexed format from stream if index>0, lowid is get from time table per th...
Definition: lwpobjid.cxx:96
rtl::Reference< LwpObject > obj(VO_TYPE tag=VO_INVALID) const
@descr get object from object factory per the object id
Definition: lwpobjid.cxx:183
stream class for LwpObject body data provide stream like interface to read object data
Definition: lwpobjstrm.hxx:77
LwpFoundry * GetFoundry()
Definition: lwpobj.hxx:136
bool HasFillerPageText(LwpFoundry const *pFoundry)
@descr: Whether has filler page text in current page layout
void ConvertFillerPageText(XFContentContainer *pCont)
@descr: Parse filler page text
LwpFribPtr & GetFribs()
Definition: lwppara.hxx:303
void AddXFContent(XFContent *pCont)
Definition: lwppara.hxx:315
void RegisterTabStyle(XFParaStyle *pXFParaStyle)
Definition: lwppara.cxx:708
void SetXFContainer(XFContentContainer *pCont)
Definition: lwppara.hxx:321
LwpObjectID & GetStoryID()
Definition: lwppara.hxx:333
XFContentContainer * GetXFContainer()
Definition: lwppara.hxx:307
XFParaStyle * GetXFParaStyle()
get paragraph xfstyle
Definition: lwppara1.cxx:118
OUString const & GetSectionName() const
Definition: lwpsection.hxx:96
void SetTabLayout(LwpLayout *pLayout)
Definition: lwpstory.hxx:149
bool IsPMModified() const
Definition: lwpstory.hxx:119
bool IsNeedSection()
Definition: lwpstory.cxx:246
void SetSectionName(const OUString &StyleName)
Definition: lwpstory.hxx:150
XFContentContainer * GetXFContent()
Definition: lwpstory.cxx:401
void SetCurrentLayout(LwpPageLayout *pPageLayout)
Definition: lwpstory.cxx:168
void AddXFContent(XFContent *pContent)
Definition: lwpstory.cxx:395
LwpPageLayout * GetCurrentLayout()
Definition: lwpstory.hxx:114
const OUString & GetStyleName() const
Definition: lwplayout.hxx:171
double GetMarginsValue(sal_uInt8 nWhichSide)
Definition: lwplayout.hxx:153
A container for content.
rtl::Reference< XFContent > GetLastContent()
virtual void SetStyleName(const OUString &style)
: All content except XFTextContent can have a style.
Definition: xfcontent.hxx:90
Index template.
Definition: xfindex.hxx:79
void AddEntry(enumXFIndexTemplate entry, const OUString &styleName)
@descr Add an entry in the template.
Definition: xfindex.hxx:198
Index, include index template, index body.
Definition: xfindex.hxx:134
void SetSeparator(bool sep)
@descr Set separator.
Definition: xfindex.cxx:88
void AddTemplate(const OUString &level, const OUString &style, XFIndexTemplate *templ)
@descr Add index template entry.
Definition: xfindex.cxx:73
void SetIndexType(enumXFIndex type)
@descr Set index type.
Definition: xfindex.hxx:222
Style object for aragraph.
Definition: xfparastyle.hxx:93
Paragraph object for SODC.
Definition: xfparagraph.hxx:73
bool HasContents() const
Definition: xfparagraph.cxx:94
Section object.
Definition: xfsection.hxx:70
Style manager for the filter.
IXFStyleRet AddStyle(std::unique_ptr< IXFStyle > pStyle)
@ VO_INDEXSECTION
Definition: lwpdefs.hxx:119
const sal_uInt8 MARGIN_RIGHT
Definition: lwpmargins.hxx:64
const sal_uInt8 MARGIN_LEFT
Definition: lwpmargins.hxx:63
IXFStyle * m_pStyle
Definition: xfstylecont.hxx:71
@ enumXFIndexAlphabetical
Definition: xfdefs.hxx:443
@ enumXFBreakAftPage
Definition: xfdefs.hxx:224
@ enumXFIndexTemplateTab
Definition: xfdefs.hxx:455
@ enumXFIndexTemplateText
Definition: xfdefs.hxx:454
@ enumXFIndexTemplatePage
Definition: xfdefs.hxx:456