Line data Source code
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 : * Change History
62 : Jan 2005 Created
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"
74 :
75 0 : LwpFribSection::LwpFribSection(LwpPara *pPara)
76 0 : : LwpFrib(pPara),m_pMasterPage(NULL)
77 : {
78 :
79 0 : }
80 :
81 0 : LwpFribSection::~LwpFribSection()
82 : {
83 0 : if(m_pMasterPage)
84 : {
85 0 : delete m_pMasterPage;
86 0 : m_pMasterPage = NULL;
87 : }
88 0 : }
89 :
90 : /**
91 : * @descr: Read section frib information
92 : *
93 : */
94 0 : void LwpFribSection::Read(LwpObjectStream *pObjStrm, sal_uInt16 /*len*/)
95 : {
96 0 : m_Section.ReadIndexed(pObjStrm);
97 0 : }
98 :
99 : /**
100 : * @descr: Get section pointer
101 : *
102 : */
103 0 : LwpSection* LwpFribSection::GetSection()
104 : {
105 0 : return static_cast<LwpSection*>(m_Section.obj());
106 : }
107 :
108 : /**
109 : * @descr: Register section style
110 : *
111 : */
112 0 : void LwpFribSection::RegisterSectionStyle()
113 : {
114 0 : LwpPageLayout* pLayout = GetPageLayout();
115 0 : if(pLayout)
116 : {
117 0 : m_pMasterPage = new LwpMasterPage(m_pPara, pLayout);
118 0 : m_pMasterPage->RegisterMasterPage(this);
119 : }
120 0 : }
121 :
122 : /**
123 : * @descr: Register section style
124 : *
125 : */
126 0 : void LwpFribSection::SetSectionName()
127 : {
128 0 : LwpSection* pSection = GetSection();
129 0 : if(pSection)
130 : {
131 0 : LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
132 0 : pStory->SetSectionName(pSection->GetSectionName());
133 : }
134 0 : }
135 :
136 : /**
137 : * @descr: Get page layout that current section points
138 : *
139 : */
140 0 : LwpPageLayout* LwpFribSection::GetPageLayout()
141 : {
142 0 : if(GetSection())
143 0 : return GetSection()->GetPageLayout();
144 0 : return NULL;
145 : }
146 :
147 : /**
148 : * @descr: XFConvert section
149 : *
150 : */
151 0 : void LwpFribSection::ParseSection()
152 : {
153 0 : LwpPageLayout* pLayout = GetPageLayout();
154 0 : if(pLayout)
155 : {
156 : // StartWithinColume not support now
157 0 : LwpLayout::UseWhenType eSectionType = pLayout->GetUseWhenType();
158 0 : if(eSectionType==LwpLayout::StartWithinColume)
159 : {
160 0 : return;
161 : }
162 0 : if(m_pMasterPage)
163 : {
164 0 : m_pMasterPage->ParseSection(this);
165 : }
166 : }
167 : else
168 : {
169 0 : LwpStory* pStory = static_cast<LwpStory*> ( m_pPara->GetStoryID()->obj() );
170 0 : if (m_Section.obj()->GetTag() == VO_INDEXSECTION)
171 : {
172 : //create a new section and add it to container
173 0 : XFIndex* pIndex = new XFIndex;
174 0 : pIndex->SetIndexType(enumXFIndexAlphabetical);
175 : /*
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())
180 : bRunin = sal_True;
181 : if (pIndexSection->IsFormatSeparator())
182 : bSeparator = sal_True;
183 : pIndex->SetDefaultAlphaIndex(A2OUSTR(""),bRunin,bSeparator);
184 : */
185 0 : SetDefaultAlphaIndex(pIndex);
186 :
187 0 : pStory->AddXFContent( pIndex );
188 0 : m_pPara->SetXFContainer( pIndex );
189 : }
190 : else
191 : {
192 0 : XFContentContainer* pContent = pStory->GetXFContent();
193 0 : m_pPara->SetXFContainer( pContent );
194 : }
195 : }
196 : }
197 :
198 0 : void LwpFribSection::SetDefaultAlphaIndex(XFIndex * pXFIndex)
199 : {
200 0 : LwpFoundry* pFoundry = m_pPara->GetFoundry();
201 0 : OUString styleName = pFoundry->FindActuralStyleName(A2OUSTR("Separator"));
202 :
203 0 : LwpIndexSection* pIndexSection = static_cast<LwpIndexSection*>(m_Section.obj());
204 0 : XFIndexTemplate * pTemplateSep = new XFIndexTemplate();
205 0 : if (pIndexSection->IsFormatSeparator())
206 : {
207 0 : pXFIndex->SetSeparator(sal_True);
208 0 : pTemplateSep->AddEntry(enumXFIndexTemplateText,A2OUSTR(""));
209 : }
210 : //pXFIndex->AddTemplate(A2OUSTR("separator"),A2OUSTR("Separator"),pTemplateSep);
211 0 : pXFIndex->AddTemplate(A2OUSTR("separator"),styleName,pTemplateSep);
212 :
213 :
214 0 : styleName = pFoundry->FindActuralStyleName(A2OUSTR("Primary"));
215 :
216 0 : XFIndexTemplate * pTemplate1 = new XFIndexTemplate();
217 0 : pTemplate1->AddEntry(enumXFIndexTemplateText,A2OUSTR(""));
218 0 : pTemplate1->AddEntry(enumXFIndexTemplateTab,A2OUSTR(""));
219 0 : pTemplate1->AddEntry(enumXFIndexTemplatePage,A2OUSTR(""));
220 : //pXFIndex->AddTemplate(Int32ToOUString(1),A2OUSTR("Primary"),pTemplate1);
221 0 : pXFIndex->AddTemplate(Int32ToOUString(1),styleName,pTemplate1);
222 :
223 0 : XFIndexTemplate * pTemplate2 = new XFIndexTemplate();
224 0 : pTemplate2->AddEntry(enumXFIndexTemplateText,A2OUSTR(""));
225 0 : pTemplate2->AddEntry(enumXFIndexTemplateTab,A2OUSTR(""));
226 0 : pTemplate2->AddEntry(enumXFIndexTemplatePage,A2OUSTR(""));
227 0 : XFIndexTemplate * pTemplate3 = new XFIndexTemplate();
228 0 : pTemplate3->AddEntry(enumXFIndexTemplateText,A2OUSTR(""));
229 0 : pTemplate3->AddEntry(enumXFIndexTemplateTab,A2OUSTR(""));
230 0 : pTemplate3->AddEntry(enumXFIndexTemplatePage,A2OUSTR(""));
231 :
232 0 : if (pIndexSection->IsFormatRunin())
233 : {
234 : //pXFIndex->AddTemplate(Int32ToOUString(2),A2OUSTR("Primary"),pTemplate2);
235 : //pXFIndex->AddTemplate(Int32ToOUString(3),A2OUSTR("Primary"),pTemplate3);
236 0 : pXFIndex->AddTemplate(Int32ToOUString(2),styleName,pTemplate2);
237 0 : pXFIndex->AddTemplate(Int32ToOUString(3),styleName,pTemplate3);
238 : }
239 : else
240 : {
241 : //pXFIndex->AddTemplate(Int32ToOUString(2),A2OUSTR("Secondary"),pTemplate2);
242 : //pXFIndex->AddTemplate(Int32ToOUString(3),A2OUSTR("Secondary"),pTemplate3);
243 0 : styleName = pFoundry->FindActuralStyleName(A2OUSTR("Secondary"));
244 0 : pXFIndex->AddTemplate(Int32ToOUString(2),styleName,pTemplate2);
245 0 : pXFIndex->AddTemplate(Int32ToOUString(3),styleName,pTemplate3);
246 0 : }
247 0 : }
248 :
249 :
250 0 : LwpMasterPage::LwpMasterPage(LwpPara* pPara, LwpPageLayout* pLayout)
251 0 : :m_bNewSection(sal_False),m_pPara(pPara),m_pLayout(pLayout)
252 : {
253 0 : }
254 :
255 : /**
256 : * @descr: Register master page style for para style and register section style if necessary
257 : *
258 : */
259 0 : sal_Bool LwpMasterPage::RegisterMasterPage(LwpFrib* pFrib)
260 : {
261 : //if there is no other frib after current firb, register master page in starting para of next page
262 0 : if(IsNextPageType()&&(!pFrib->HasNextFrib()))
263 : {
264 0 : LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
265 0 : pStory->SetCurrentLayout(m_pLayout);
266 0 : RegisterFillerPageStyle();
267 0 : return sal_False;
268 : }
269 :
270 0 : m_bNewSection = sal_False;
271 : //sal_Bool bSectionColumns = sal_False;
272 :
273 0 : XFParaStyle* pOverStyle = new XFParaStyle;
274 0 : *pOverStyle = *(m_pPara->GetXFParaStyle());
275 0 : pOverStyle->SetStyleName(A2OUSTR(""));
276 :
277 0 : LwpLayout::UseWhenType eUserType = m_pLayout->GetUseWhenType();
278 0 : switch(eUserType)
279 : {
280 : case LwpLayout::StartWithinColume://not support now
281 : {
282 0 : m_bNewSection = sal_False;
283 0 : break;
284 : }
285 : case LwpLayout::StartWithinPage:
286 : {
287 0 : m_bNewSection = sal_True;
288 : //bSectionColumns = sal_True;
289 0 : break;
290 : }
291 : case LwpLayout::StartOnNextPage: //fall throught
292 : case LwpLayout::StartOnOddPage: //fall throught
293 : case LwpLayout::StartOnEvenPage:
294 : {
295 0 : LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
296 0 : pStory->SetCurrentLayout(m_pLayout);
297 : //get odd page layout when the current pagelayout is mirror
298 0 : m_pLayout = pStory->GetCurrentLayout();
299 0 : m_bNewSection = IsNeedSection();
300 : //bSectionColumns = m_bNewSection;
301 0 : pOverStyle->SetMasterPage( m_pLayout->GetStyleName());
302 0 : RegisterFillerPageStyle();
303 0 : break;
304 : }
305 : default:
306 0 : break;
307 : }
308 :
309 : //register tab style;
310 0 : LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
311 0 : pStory->SetTabLayout(m_pLayout);
312 0 : m_pPara->RegisterTabStyle(pOverStyle);
313 :
314 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
315 0 : m_StyleName = pXFStyleManager->AddStyle(pOverStyle)->GetStyleName();
316 : //register section style here
317 0 : if(m_bNewSection)
318 : {
319 0 : XFSectionStyle* pSectStyle= new XFSectionStyle();
320 : //set margin
321 0 : pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
322 0 : if(pStory)
323 : {
324 0 : LwpPageLayout* pCurrentLayout = pStory->GetCurrentLayout();
325 0 : double fLeft = m_pLayout->GetMarginsValue(MARGIN_LEFT)- pCurrentLayout->GetMarginsValue(MARGIN_LEFT);
326 0 : double fRight = m_pLayout->GetMarginsValue(MARGIN_RIGHT)- pCurrentLayout->GetMarginsValue(MARGIN_RIGHT);
327 0 : pSectStyle->SetMarginLeft(fLeft);
328 0 : pSectStyle->SetMarginRight(fRight);
329 : }
330 :
331 : //if(bSectionColumns)
332 : //{
333 : //set columns
334 0 : XFColumns* pColumns = m_pLayout->GetXFColumns();
335 0 : if(pColumns)
336 : {
337 0 : pSectStyle->SetColumns(pColumns);
338 : }
339 : //}
340 0 : m_SectionStyleName = pXFStyleManager->AddStyle(pSectStyle)->GetStyleName();
341 : }
342 0 : return sal_False;
343 : }
344 :
345 : /**
346 : * @descr: Whether it need create a new section
347 : *
348 : */
349 0 : sal_Bool LwpMasterPage::IsNeedSection()
350 : {
351 0 : sal_Bool bNewSection = sal_False;
352 : //get story
353 0 : LwpStory* pStory = static_cast<LwpStory*>(m_pPara->GetStoryID()->obj());
354 : //if pagelayout is modified, register the pagelayout
355 0 : if(pStory->IsPMModified())
356 : {
357 0 : bNewSection = pStory->IsNeedSection();
358 : }
359 0 : return bNewSection;
360 : }
361 :
362 : /**
363 : * @descr: Create XFSection if necessary
364 : *
365 : */
366 0 : XFSection* LwpMasterPage::CreateXFSection()
367 : {
368 0 : if(m_bNewSection)
369 : {
370 : //new a section
371 0 : XFSection* pXFSection = new XFSection();
372 0 : pXFSection->SetStyleName(m_SectionStyleName);
373 0 : return pXFSection;
374 : }
375 0 : return NULL;
376 : }
377 :
378 : /**
379 : * @descr: Parse section
380 : *
381 : */
382 0 : void LwpMasterPage::ParseSection(LwpFrib* pFrib)
383 : {
384 0 : LwpFribPtr* pFribPtr = m_pPara->GetFribs();
385 : //XFParagraph * pXFPara = pFribPtr->GetXFPara();
386 :
387 : //parse fillerpage text
388 0 : if(m_pLayout->HasFillerPageText(m_pPara->GetFoundry()))
389 : {
390 0 : XFParagraph *pPara = new XFParagraph();
391 0 : pPara->SetStyleName(GetFillerPageStyleName());
392 0 : m_pPara->AddXFContent(pPara);
393 0 : pFribPtr->SetXFPara(pPara);
394 :
395 0 : m_pLayout->ConvertFillerPageText(m_pPara->GetXFContainer());
396 : }
397 : //create a new section and add it to container
398 0 : XFContentContainer* pContent = CreateXFSection();
399 0 : if(pContent)
400 : {
401 0 : LwpStory* pStory = static_cast<LwpStory*> ( m_pPara->GetStoryID()->obj() );
402 : //delete the additional blank para, 06/28/2005
403 0 : XFParagraph* pCurrPara = pFribPtr->GetXFPara();
404 0 : if(!pCurrPara->HasContents())
405 : {
406 0 : XFContentContainer* pCurrContainer = m_pPara->GetXFContainer();
407 0 : if(pFrib->HasNextFrib() && (pCurrContainer->GetLastContent() == pCurrPara))
408 : {
409 0 : pCurrContainer->RemoveLastContent();
410 : }
411 : }
412 : //end,06/28/2005
413 0 : pStory->AddXFContent( pContent );
414 : }
415 : else
416 : {
417 0 : LwpStory* pStory = static_cast<LwpStory*> ( m_pPara->GetStoryID()->obj() );
418 0 : pContent = pStory->GetXFContent();
419 : }
420 0 : if(pContent)
421 : {
422 0 : m_pPara->SetXFContainer( pContent );
423 : }
424 : //out put the contents after the section frib in the same para.
425 0 : if(pFrib->HasNextFrib())
426 : {
427 0 : XFParagraph *pNextPara = new XFParagraph();
428 0 : pNextPara->SetStyleName(GetStyleName());
429 0 : m_pPara->AddXFContent(pNextPara);
430 0 : pFribPtr->SetXFPara(pNextPara);
431 : }
432 :
433 0 : }
434 :
435 : /**
436 : * @descr: Register filler page text style
437 : *
438 : */
439 0 : void LwpMasterPage::RegisterFillerPageStyle()
440 : {
441 0 : LwpLayout::UseWhenType eUserType = m_pLayout->GetUseWhenType();
442 0 : if(eUserType==LwpLayout::StartOnOddPage
443 : ||eUserType==LwpLayout::StartOnEvenPage)
444 : {
445 0 : if(m_pLayout->HasFillerPageText(m_pPara->GetFoundry()))
446 : {
447 0 : XFParaStyle* pPagebreakStyle = new XFParaStyle;
448 0 : *pPagebreakStyle = *(m_pPara->GetXFParaStyle());
449 0 : pPagebreakStyle->SetStyleName(A2OUSTR(""));
450 0 : pPagebreakStyle->SetBreaks(enumXFBreakAftPage);
451 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
452 0 : m_FillerPageStyleName= pXFStyleManager->AddStyle(pPagebreakStyle)->GetStyleName();
453 : }
454 : }
455 0 : }
456 :
457 : /**
458 : * @descr: Whether the layout is next page type
459 : *
460 : */
461 0 : sal_Bool LwpMasterPage::IsNextPageType()
462 : {
463 0 : LwpLayout::UseWhenType eUserType = m_pLayout->GetUseWhenType();
464 0 : if(eUserType == LwpLayout::StartOnNextPage
465 : || eUserType == LwpLayout::StartOnOddPage
466 : || eUserType == LwpLayout::StartOnEvenPage )
467 : {
468 0 : return sal_True;
469 : }
470 0 : return sal_False;
471 : }
472 :
473 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|