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 : * Change History
58 : Mar 2005 Created
59 : ************************************************************************/
60 : #include "lwppagelayout.hxx"
61 : #include "lwplaypiece.hxx"
62 : #include "lwpfootnote.hxx"
63 : #include "lwpdoc.hxx"
64 : #include "lwpholder.hxx"
65 : #include "lwppagehint.hxx"
66 : #include "lwpdivinfo.hxx"
67 : #include "lwpstory.hxx"
68 : #include "xfilter/xfstylemanager.hxx"
69 : #include "xfilter/xfmasterpage.hxx"
70 : #include "xfilter/xfcontentcontainer.hxx"
71 : #include "xfilter/xfheader.hxx"
72 : #include "xfilter/xfheaderstyle.hxx"
73 : #include "xfilter/xffooterstyle.hxx"
74 : #include "xfilter/xffooter.hxx"
75 : #include <sfx2/printer.hxx>
76 : #include "lwpchangemgr.hxx"
77 : #include "lwpglobalmgr.hxx"
78 :
79 8 : LwpPageLayout::LwpPageLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
80 8 : : LwpLayout(objHdr, pStrm), m_pPrinterBinName(new LwpAtomHolder),
81 16 : m_pPaperName(new LwpAtomHolder),m_pXFPageMaster(NULL)
82 : {
83 8 : }
84 :
85 24 : LwpPageLayout::~LwpPageLayout()
86 : {
87 8 : if (m_pPrinterBinName)
88 : {
89 8 : delete m_pPrinterBinName;
90 : }
91 8 : if (m_pPaperName)
92 : {
93 8 : delete m_pPaperName;
94 : }
95 16 : }
96 8 : void LwpPageLayout::Read()
97 : {
98 8 : LwpLayout::Read();
99 :
100 8 : if (LwpFileHeader::m_nFileRevision < 0x000B)
101 : {
102 : // read PreRevBLayout...
103 : }
104 :
105 8 : m_nPrinterBin = m_pObjStrm->QuickReaduInt16();
106 8 : m_pPrinterBinName->Read(m_pObjStrm);
107 :
108 8 : if (LwpFileHeader::m_nFileRevision >= 0x000B)
109 8 : m_nBdroffset = m_pObjStrm->QuickReadInt32();
110 :
111 8 : if (m_pObjStrm->CheckExtra())
112 : {
113 6 : m_pPaperName->Read(m_pObjStrm);
114 6 : m_pObjStrm->SkipExtra();
115 : }
116 :
117 8 : }
118 :
119 3 : void LwpPageLayout::Parse(IXFStream* pOutputStream)
120 : {
121 : //Only parse this layout
122 3 : LwpObject* pStory = m_Content.obj();
123 3 : if(pStory)
124 : {
125 3 : pStory->SetFoundry(m_pFoundry);
126 3 : pStory->Parse(pOutputStream); //Do not parse the next story
127 : }
128 3 : }
129 :
130 : /**
131 : * @descr: set page margins
132 : *
133 : */
134 8 : void LwpPageLayout::ParseMargins(XFPageMaster* pm1)
135 : {
136 8 : double fLeft = GetMarginsValue(MARGIN_LEFT);
137 8 : double fRight = GetMarginsValue(MARGIN_RIGHT);
138 8 : double fTop = GetMarginsValue(MARGIN_TOP);
139 8 : double fBottom = GetMarginsValue(MARGIN_BOTTOM);
140 :
141 8 : pm1->SetMargins( fLeft, fRight, fTop, fBottom );
142 :
143 8 : }
144 :
145 : /**
146 : * @descr: set page height and width
147 : *
148 : */
149 8 : void LwpPageLayout::ParseGeometry(XFPageMaster* pm1)
150 : {
151 : /*
152 : LwpLayoutGeometry* pLayoutGeo = GetGeometry();
153 : if(pLayoutGeo)
154 : {
155 : pm1->SetPageHeight( GetGeometryHeight() );
156 : pm1->SetPageWidth( GetGeometryWidth() );
157 : }
158 : */
159 8 : double fWidth =0;
160 8 : double fHeight = 0;
161 8 : GetWidthAndHeight(fWidth, fHeight);
162 8 : pm1->SetPageWidth( fWidth );
163 8 : pm1->SetPageHeight( fHeight );
164 8 : }
165 :
166 : /**
167 : * @descr: set page watermark
168 : *
169 : */
170 8 : void LwpPageLayout::ParseWaterMark(XFPageMaster *pm1)
171 : {
172 8 : XFBGImage* pXFBGImage = GetXFBGImage();
173 8 : if(pXFBGImage)
174 : {
175 0 : pm1->SetBackImage(pXFBGImage);
176 : }
177 8 : }
178 :
179 : /**
180 : * @descr: set page columns
181 : *
182 : */
183 8 : void LwpPageLayout::ParseColumns(XFPageMaster * pm1)
184 : {
185 8 : XFColumns* pColumns = GetXFColumns();
186 8 : if(pColumns)
187 : {
188 0 : pm1->SetColumns(pColumns);
189 : }
190 8 : }
191 :
192 : /**
193 : * @descr: set page borders
194 : *
195 : */
196 8 : void LwpPageLayout::ParseBorders(XFPageMaster *pm1)
197 : {
198 8 : XFBorders* pBordres = GetXFBorders();
199 8 : if(pBordres)
200 : {
201 0 : pm1->SetBorders(pBordres);
202 : }
203 8 : }
204 :
205 :
206 : /**
207 : * @descr: set page shadow
208 : *
209 : */
210 8 : void LwpPageLayout::ParseShadow(XFPageMaster *pm1)
211 : {
212 8 : XFShadow* pXFShadow = GetXFShadow();
213 8 : if(pXFShadow)
214 : {
215 0 : pm1->SetShadow(pXFShadow);
216 : }
217 8 : }
218 :
219 : /**
220 : * @descr: set page back pattern
221 : *
222 : */
223 0 : void LwpPageLayout::ParsePatternFill(XFPageMaster* pm1)
224 : {
225 0 : XFBGImage* pXFBGImage = this->GetFillPattern();
226 0 : if (pXFBGImage)
227 : {
228 0 : pm1->SetBackImage(pXFBGImage);
229 : }
230 0 : }
231 : /**
232 : * @descr: set page background
233 : *
234 : */
235 8 : void LwpPageLayout::ParseBackGround(XFPageMaster* pm1)
236 : {
237 8 : if (this->IsPatternFill())
238 : {
239 0 : ParsePatternFill(pm1);
240 : }
241 : else
242 : {
243 8 : ParseBackColor(pm1);
244 : }
245 8 : }
246 :
247 : /**
248 : * @descr: set page back color
249 : *
250 : */
251 8 : void LwpPageLayout::ParseBackColor(XFPageMaster* pm1)
252 : {
253 8 : LwpColor* pColor = GetBackColor();
254 8 : if(pColor)
255 : {
256 8 : pm1->SetBackColor(XFColor(pColor->To24Color()));
257 : }
258 8 : }
259 :
260 : /**
261 : * @descr: set page footnote separator information
262 : *
263 : */
264 8 : void LwpPageLayout::ParseFootNoteSeparator(XFPageMaster * pm1)
265 : {
266 : //Get the footnoteoptions for the root document
267 8 : LwpDocument* pDocument = m_pFoundry->GetDocument();
268 8 : if(pDocument)
269 : {
270 8 : LwpObjectID* pFontnodeId = pDocument->GetValidFootnoteOpts();
271 :
272 8 : LwpFootnoteOptions* pFootnoteOpts = pFontnodeId ? dynamic_cast<LwpFootnoteOptions*>(pFontnodeId->obj()) : NULL;
273 8 : if(pFootnoteOpts)
274 : {
275 8 : LwpFootnoteSeparatorOptions* pFootnoteSep = pFootnoteOpts->GetFootnoteSeparator();
276 : //set length
277 8 : sal_uInt32 nLengthPercent = 100;
278 8 : double fWidth = 0;
279 8 : if(pFootnoteSep->HasSeparator())
280 : {
281 8 : fWidth = pFootnoteSep->GetTopBorderWidth();
282 : }
283 8 : if(pFootnoteSep->HasCustomLength())
284 : {
285 0 : nLengthPercent = static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetLength())/GetMarginWidth());
286 0 : if(nLengthPercent > 100)
287 0 : nLengthPercent = 100;
288 : }
289 8 : double fAbove = LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetAbove());
290 8 : double fBelow = LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetBelow());
291 8 : LwpColor aColor = pFootnoteSep->GetTopBorderColor();
292 8 : enumXFAlignType eAlignType = enumXFAlignStart;
293 8 : if(pFootnoteSep->GetIndent() > 0)
294 : {
295 : //SODC don't support indent
296 0 : sal_uInt32 nIndentPercent = static_cast<sal_uInt32>(100*LwpTools::ConvertFromUnitsToMetric(pFootnoteSep->GetIndent())/GetMarginWidth());
297 0 : if(nIndentPercent + nLengthPercent >= 100)
298 0 : eAlignType = enumXFAlignEnd;
299 : }
300 8 : if(aColor.IsValidColor())
301 : {
302 8 : XFColor aXFColor(aColor.To24Color());
303 8 : pm1->SetFootNoteSeparator(eAlignType,fWidth, nLengthPercent, fAbove, fBelow, aXFColor);
304 8 : }
305 : }
306 : }
307 8 : }
308 :
309 : /**
310 : * @descr: Register master page and page master style
311 : *
312 : */
313 8 : void LwpPageLayout::RegisterStyle()
314 : {
315 8 : XFPageMaster* pm1 = new XFPageMaster();
316 8 : m_pXFPageMaster = pm1;
317 :
318 8 : ParseGeometry( pm1 );
319 : //Does not process LayoutScale, for watermark is not supported in SODC.
320 8 : ParseWaterMark( pm1);
321 8 : ParseMargins( pm1);
322 8 : ParseColumns(pm1);
323 8 : ParseBorders(pm1);
324 8 : ParseShadow(pm1);
325 : // ParseBackColor(pm1);
326 8 : ParseBackGround(pm1);
327 8 : ParseFootNoteSeparator(pm1);
328 8 : pm1->SetTextDir(GetTextDirection());
329 :
330 8 : LwpUseWhen* pUseWhen = GetUseWhen();
331 8 : if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
332 : {
333 0 : pm1->SetPageUsage(enumXFPageUsageMirror);
334 : }
335 :
336 : //Add the page master to stylemanager
337 8 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
338 8 : OUString pmname = pXFStyleManager->AddStyle(pm1)->GetStyleName();
339 :
340 : //Add master page
341 8 : XFMasterPage* mp1 = new XFMasterPage();
342 8 : mp1->SetStyleName(GetName()->str());
343 8 : mp1->SetPageMaster(pmname);
344 8 : m_StyleName = pXFStyleManager->AddStyle(mp1)->GetStyleName();
345 :
346 : //Set footer style
347 8 : LwpFooterLayout* pLayoutFooter = GetFooterLayout();
348 8 : if(pLayoutFooter)
349 : {
350 8 : pLayoutFooter->SetFoundry(m_pFoundry);
351 8 : pLayoutFooter->RegisterStyle(pm1);
352 8 : pLayoutFooter->RegisterStyle(mp1);
353 : }
354 :
355 : //Set header style
356 8 : LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
357 8 : if(pLayoutHeader)
358 : {
359 8 : pLayoutHeader->SetFoundry(m_pFoundry);
360 8 : pLayoutHeader->RegisterStyle(pm1);
361 8 : pLayoutHeader->RegisterStyle(mp1);
362 : }
363 : //register child layout style for mirror page and frame
364 8 : RegisterChildStyle();
365 8 : }
366 :
367 : /**
368 : * @descr: Register master page for endnote which name is "endnote"
369 : * @return: Return the master page name.
370 : */
371 0 : OUString LwpPageLayout::RegisterEndnoteStyle()
372 : {
373 0 : XFPageMaster* pm1 = new XFPageMaster();
374 0 : m_pXFPageMaster = pm1;
375 :
376 0 : ParseGeometry( pm1 );
377 0 : ParseWaterMark( pm1);
378 0 : ParseMargins( pm1);
379 0 : ParseColumns(pm1);
380 0 : ParseBorders(pm1);
381 0 : ParseShadow(pm1);
382 : // ParseBackColor(pm1);
383 0 : ParseBackGround(pm1);
384 : //ParseFootNoteSeparator(pm1);
385 0 : pm1->SetTextDir(GetTextDirection());
386 :
387 0 : LwpUseWhen* pUseWhen = GetUseWhen();
388 0 : if(IsComplex() ||( pUseWhen && pUseWhen->IsUseOnAllOddPages()))
389 : {
390 0 : pm1->SetPageUsage(enumXFPageUsageMirror);
391 : }
392 :
393 : //Add the page master to stylemanager
394 0 : XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
395 0 : OUString pmname = pXFStyleManager->AddStyle(pm1)->GetStyleName();
396 :
397 : //Add master page
398 0 : XFMasterPage* mp1 = new XFMasterPage();
399 0 : mp1->SetStyleName(A2OUSTR("Endnote"));
400 0 : mp1->SetPageMaster(pmname);
401 :
402 : //Set footer style
403 0 : LwpFooterLayout* pLayoutFooter = GetFooterLayout();
404 0 : if(pLayoutFooter)
405 : {
406 0 : pLayoutFooter->SetFoundry(m_pFoundry);
407 0 : pLayoutFooter->RegisterStyle(pm1);
408 0 : pLayoutFooter->RegisterStyle(mp1);
409 : }
410 :
411 : //Set header style
412 0 : LwpHeaderLayout* pLayoutHeader = GetHeaderLayout();
413 0 : if(pLayoutHeader)
414 : {
415 0 : pLayoutHeader->SetFoundry(m_pFoundry);
416 0 : pLayoutHeader->RegisterStyle(pm1);
417 0 : pLayoutHeader->RegisterStyle(mp1);
418 : }
419 :
420 0 : return pXFStyleManager->AddStyle(mp1)->GetStyleName();
421 : }
422 : /**
423 : * @descr: Whether current page layout has columns
424 : *
425 : */
426 4 : sal_Bool LwpPageLayout::HasColumns()
427 : {
428 4 : return GetNumCols() > 1 ? sal_True : sal_False;
429 : }
430 :
431 : /**
432 : * @descr: Whether has filler page text in current page layout
433 : *
434 : */
435 0 : sal_Bool LwpPageLayout::HasFillerPageText(LwpFoundry* pFoundry)
436 : {
437 0 : if(!pFoundry) return sal_False;
438 :
439 0 : sal_Bool bFillerPage = sal_False;
440 0 : LwpLayout::UseWhenType eWhenType = GetUseWhenType();
441 0 : if(eWhenType==LwpLayout::StartOnOddPage||eWhenType==LwpLayout::StartOnEvenPage)
442 : {
443 : //get pagenumber
444 0 : sal_uInt16 nPageNumber = 0;
445 :
446 : //get the page number that current page layout inserted
447 0 : nPageNumber = GetPageNumber(FIRST_LAYOUTPAGENO)-1;
448 :
449 0 : if(nPageNumber>0)
450 : {
451 0 : if((eWhenType==LwpLayout::StartOnOddPage)&&(LwpTools::IsOddNumber(nPageNumber)))
452 : {
453 0 : bFillerPage = sal_True;
454 : }
455 0 : else if((eWhenType==LwpLayout::StartOnEvenPage)&&(LwpTools::IsEvenNumber(nPageNumber)))
456 : {
457 0 : bFillerPage = sal_True;
458 : }
459 : else
460 : {
461 0 : bFillerPage = sal_False;
462 : }
463 : }
464 : }
465 :
466 0 : return bFillerPage;
467 : }
468 :
469 : /**
470 : * @descr: Parse filler page text
471 : *
472 : */
473 0 : void LwpPageLayout::ConvertFillerPageText(XFContentContainer* pCont)
474 : {
475 0 : if(HasFillerPageText(m_pFoundry))
476 : {
477 : //get filerpage story from division info
478 0 : LwpDocument* pDoc = m_pFoundry->GetDocument();
479 0 : LwpDivInfo* pDivInfo = dynamic_cast<LwpDivInfo*>(pDoc->GetDivInfoID()->obj());
480 0 : LwpStory* pStory = dynamic_cast<LwpStory*>(pDivInfo->GetFillerPageTextID()->obj());
481 :
482 : //parse fillerpage story
483 0 : if(pStory)
484 : {
485 0 : pStory->XFConvert(pCont);
486 : }
487 : }
488 0 : }
489 : /**
490 : * @descr: Clear columns style in page layout
491 : *
492 : */
493 0 : void LwpPageLayout::ResetXFColumns()
494 : {
495 0 : if(m_pXFPageMaster)
496 : {
497 0 : m_pXFPageMaster->SetColumns(NULL);
498 : }
499 0 : }
500 :
501 8 : LwpHeaderLayout* LwpPageLayout::GetHeaderLayout()
502 : {
503 8 : LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
504 24 : while(pLay)
505 : {
506 16 : if( pLay->GetLayoutType() == LWP_HEADER_LAYOUT )
507 8 : return ( static_cast<LwpHeaderLayout*> (pLay) );
508 8 : pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
509 : }
510 0 : return NULL;
511 : }
512 :
513 8 : LwpFooterLayout* LwpPageLayout::GetFooterLayout()
514 : {
515 8 : LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
516 16 : while(pLay)
517 : {
518 8 : if( pLay->GetLayoutType() == LWP_FOOTER_LAYOUT )
519 8 : return ( static_cast<LwpFooterLayout*> (pLay) );
520 0 : pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
521 : }
522 0 : return NULL;
523 : }
524 :
525 : /**
526 : * @descr: Get the odd layout if current page layout is mirror page
527 : *
528 : */
529 4 : LwpPageLayout* LwpPageLayout::GetOddChildLayout()
530 : {
531 4 : if(IsComplex())
532 : {
533 0 : LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead()->obj());
534 0 : while(pLay)
535 : {
536 0 : if( pLay->GetLayoutType() == LWP_PAGE_LAYOUT )
537 : {
538 0 : LwpPageLayout* pPageLayout = static_cast<LwpPageLayout*> (pLay);
539 0 : LwpUseWhen* pUseWhen = pPageLayout->GetUseWhen();
540 0 : if(pUseWhen && pUseWhen->IsUseOnAllOddPages())
541 : {
542 0 : return pPageLayout;
543 : }
544 : }
545 0 : pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext()->obj());
546 : }
547 : }
548 4 : return NULL;
549 : }
550 :
551 : /**
552 : * @descr: Get margin width of page
553 : *
554 : */
555 0 : double LwpPageLayout::GetMarginWidth()
556 : {
557 0 : double fPagewidth = GetGeometryWidth();
558 0 : double fLeftMargin = GetMarginsValue(MARGIN_LEFT);
559 0 : double fRightMargin = GetMarginsValue(MARGIN_RIGHT);
560 :
561 0 : return fPagewidth - (fLeftMargin + fRightMargin);
562 : }
563 :
564 : /**
565 : * @descr: Get the pagenumber
566 : * @param: if nLayoutNumber =FIRST_LAYOUTPAGENO, return the first page number that current page layout covers
567 : =LAST_LAYOUTPAGENO, return the last page number that current page layout covers
568 : else, return the specified page number that current page layout covers
569 : * @param:
570 : * @return: if reture value >=0, success to find the page number, or fail.
571 : */
572 0 : sal_Int32 LwpPageLayout::GetPageNumber(sal_uInt16 nLayoutNumber)
573 : {
574 0 : sal_Int16 nPageNumber = -1;
575 0 : LwpFoundry* pFoundry = this->GetFoundry();
576 0 : LwpDocument* pDoc = pFoundry->GetDocument();
577 0 : LwpDLVListHeadTailHolder* pHeadTail = dynamic_cast<LwpDLVListHeadTailHolder*>(pDoc->GetPageHintsID()->obj());
578 0 : if(!pHeadTail) return nPageNumber;
579 :
580 : //get first pagehint
581 0 : LwpPageHint* pPageHint = dynamic_cast<LwpPageHint*>(pHeadTail->GetHead()->obj());
582 0 : while(pPageHint)
583 : {
584 0 : if(*(this->GetObjectID()) == *(pPageHint->GetPageLayoutID()))
585 : {
586 0 : sal_uInt16 nNumber = pPageHint->GetPageNumber();
587 0 : if(nLayoutNumber==FIRST_LAYOUTPAGENO && pPageHint->GetLayoutPageNumber()==1)
588 : {
589 : //get the first page number
590 0 : nPageNumber = nNumber;
591 0 : break;
592 : }
593 0 : else if( nLayoutNumber ==LAST_LAYOUTPAGENO && nNumber >nPageNumber )
594 : {
595 : //get the last page number
596 0 : nPageNumber = nNumber;
597 0 : if(pPageHint->GetNext()->IsNull())
598 : {
599 : //if is last page number of entire document, reture directly
600 0 : return nPageNumber + pDoc->GetNumberOfPagesBefore();
601 : }
602 : }
603 0 : else if(nLayoutNumber > 0 && pPageHint->GetLayoutPageNumber() == nLayoutNumber)
604 : {
605 : //get specified page number
606 0 : nPageNumber = nNumber;
607 0 : break;
608 : }
609 :
610 : }
611 0 : pPageHint = dynamic_cast<LwpPageHint*>(pPageHint->GetNext()->obj());
612 : }
613 0 : if(nPageNumber>=0)
614 : {
615 0 : return nPageNumber + 1 + pDoc->GetNumberOfPagesBefore();
616 : }
617 0 : return -1;
618 : }
619 :
620 : /**
621 : * @descr: Get page width and height
622 : *
623 : */
624 29 : void LwpPageLayout::GetWidthAndHeight(double& fWidth, double& fHeight)
625 : {
626 : //use customized size
627 29 : LwpLayoutGeometry* pLayoutGeo = GetGeometry();
628 29 : if(pLayoutGeo)
629 : {
630 29 : fWidth = GetGeometryWidth();
631 29 : fHeight = GetGeometryHeight();
632 : }
633 :
634 29 : if(GetUsePrinterSettings())
635 : {
636 : //replaced by printer paper size
637 27 : Printer aPrinter;
638 27 : sal_Bool bScreen = aPrinter.IsDisplayPrinter();
639 27 : if (!bScreen)//Printer available
640 : {
641 0 : Size aPaperSize = aPrinter.GetPaperSize();
642 0 : aPaperSize = aPrinter.PixelToLogic( aPaperSize, MapMode( MAP_10TH_MM ) );
643 0 : fWidth = static_cast<double>(aPaperSize.Width())/100; //cm unit
644 0 : fHeight = static_cast<double>(aPaperSize.Height())/100;
645 27 : }
646 : }
647 :
648 : //Follow the former design of Lotus WordPro filter, some default will be given:
649 : //Page Width: 8.5 Inch -> 21.59 cm
650 : //Page Height: 11 Inch -> 27.94 cm
651 29 : if (fWidth < 4.39)
652 0 : fWidth = 21.59;
653 29 : if (fHeight < 4.49)
654 0 : fHeight = 27.94;
655 : //End of modification, by ZF
656 29 : }
657 :
658 : /**
659 : * @descr: Get page width
660 : *
661 : */
662 21 : double LwpPageLayout::GetWidth()
663 : {
664 21 : double fWidth =0, fHeight = 0;
665 21 : GetWidthAndHeight(fWidth, fHeight);
666 21 : return fWidth;
667 : }
668 :
669 : /**
670 : * @descr: Get page height
671 : *
672 : */
673 0 : double LwpPageLayout::GetHeight()
674 : {
675 0 : double fWidth =0, fHeight = 0;
676 0 : GetWidthAndHeight(fWidth, fHeight);
677 0 : return fHeight;
678 : }
679 : /**
680 : * @descr: Compare the position of layout. If the poistion of this layout is earlier than other layout,return ture, or return false
681 : *
682 : */
683 0 : sal_Bool LwpPageLayout::operator<(LwpPageLayout& Other)
684 : {
685 0 : LwpPara* pThisPara = GetPagePosition();
686 0 : LwpPara* pOtherPara = Other.GetPagePosition();
687 0 : if(pThisPara && pOtherPara)
688 : {
689 0 : if(pThisPara == pOtherPara)
690 : {
691 : //If the two layouts in the same para, compare which layout is earlied according to frib order
692 0 : return pThisPara->ComparePagePosition(this, &Other);
693 : }
694 : else
695 : {
696 0 : return *pThisPara < *pOtherPara;
697 : }
698 : }
699 :
700 0 : if(!pThisPara)
701 0 : return sal_True;
702 :
703 0 : return sal_False;
704 : }
705 :
706 : /**
707 : * @descr: Get the position of pagelayout
708 : *
709 : */
710 0 : LwpPara* LwpPageLayout::GetPagePosition()
711 : {
712 0 : LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition()->obj());
713 0 : if(pPara)
714 0 : return pPara;
715 : //Get the position from its related section
716 0 : LwpSection* pSection = NULL;
717 0 : LwpFoundry* pFoundry = GetFoundry();
718 0 : if(pFoundry)
719 : {
720 0 : while( (pSection = pFoundry->EnumSections(pSection)) )
721 : {
722 0 : if(pSection->GetPageLayout() == this)
723 0 : return dynamic_cast<LwpPara*>(pSection->GetPosition()->obj());
724 : }
725 : }
726 :
727 0 : return NULL;
728 : }
729 12 : LwpHeaderLayout::LwpHeaderLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
730 12 : : LwpPlacableLayout(objHdr, pStrm)
731 : {
732 12 : }
733 :
734 24 : LwpHeaderLayout::~LwpHeaderLayout()
735 : {
736 24 : }
737 :
738 12 : void LwpHeaderLayout::Read()
739 : {
740 12 : LwpPlacableLayout::Read();
741 :
742 12 : if(LwpFileHeader::m_nFileRevision >= 0x000E)
743 12 : m_nBorderOffset = m_pObjStrm->QuickReadInt32();
744 : else
745 0 : m_nBorderOffset = 0;
746 12 : m_pObjStrm->SkipExtra();
747 12 : }
748 :
749 :
750 8 : void LwpHeaderLayout::RegisterStyle(XFPageMaster* pm1)
751 : {
752 8 : XFHeaderStyle* pHeaderStyle = new XFHeaderStyle();
753 :
754 : //Modify page top margin
755 : //page top maring: from top of header to the top edge
756 8 : double top = GetMarginsValue(MARGIN_TOP);
757 8 : pm1->SetMargins(-1, -1, top, -1);
758 :
759 8 : ParseMargins(pHeaderStyle);
760 8 : ParseBorder(pHeaderStyle);
761 8 : ParseShadow(pHeaderStyle);
762 : // ParseBackColor(pHeaderStyle);
763 8 : ParseBackGround(pHeaderStyle);
764 :
765 8 : ParseWaterMark(pHeaderStyle);
766 : //End by
767 :
768 8 : pm1->SetHeaderStyle(pHeaderStyle);
769 8 : }
770 :
771 8 : void LwpHeaderLayout::ParseMargins(XFHeaderStyle* ph1)
772 : {
773 : //Set height: from top of header to top of body, including the spacing between header and body
774 8 : double height = GetGeometryHeight()- GetMarginsValue(MARGIN_TOP);
775 8 : if( IsAutoGrowDown() )
776 : {
777 0 : ph1->SetMinHeight(height);
778 : }
779 : else
780 : {
781 8 : ph1->SetHeight(height);
782 : }
783 :
784 : //Set left,right,bottom margins
785 8 : LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent()->obj());
786 : //left margin in SODC: the space from the left edge of body to the left edge of header
787 8 : double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
788 8 : if(left<=0) //The left margin in SODC can not be minus value
789 : {
790 8 : left = -1;
791 : }
792 : //left margin in SODC: the space from the right edge of header to the right edge of body
793 8 : double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
794 8 : if(right<=0)//The right margin in SODC can not be minus value
795 : {
796 8 : right = -1;
797 : }
798 8 : ph1->SetMargins( left, right, GetMarginsValue(MARGIN_BOTTOM));
799 :
800 : //Word Pro has no dynamic spacing, should be set to false
801 8 : ph1->SetDynamicSpace(sal_False);
802 8 : }
803 :
804 8 : void LwpHeaderLayout::ParseBorder(XFHeaderStyle* pHeaderStyle)
805 : {
806 8 : XFBorders* pBordres = GetXFBorders();
807 8 : if(pBordres)
808 : {
809 0 : pHeaderStyle->SetBorders(pBordres);
810 : }
811 8 : }
812 :
813 8 : void LwpHeaderLayout::ParseShadow(XFHeaderStyle* pHeaderStyle)
814 : {
815 8 : XFShadow* pXFShadow = GetXFShadow();
816 8 : if(pXFShadow)
817 : {
818 0 : pHeaderStyle->SetShadow(pXFShadow);
819 : }
820 8 : }
821 :
822 : /**
823 : * @descr: set header back pattern
824 : *
825 : */
826 0 : void LwpHeaderLayout::ParsePatternFill(XFHeaderStyle* pHeaderStyle)
827 : {
828 0 : XFBGImage* pXFBGImage = this->GetFillPattern();
829 0 : if (pXFBGImage)
830 : {
831 0 : pHeaderStyle->SetBackImage(pXFBGImage);
832 : }
833 0 : }
834 : /**
835 : * @descr: set header background
836 : *
837 : */
838 8 : void LwpHeaderLayout::ParseBackGround(XFHeaderStyle* pHeaderStyle)
839 : {
840 8 : if (this->IsPatternFill())
841 : {
842 0 : ParsePatternFill(pHeaderStyle);
843 : }
844 : else
845 : {
846 8 : ParseBackColor(pHeaderStyle);
847 : }
848 8 : }
849 :
850 8 : void LwpHeaderLayout::ParseBackColor(XFHeaderStyle* pHeaderStyle)
851 : {
852 8 : LwpColor* pColor = GetBackColor();
853 8 : if(pColor)
854 : {
855 0 : pHeaderStyle->SetBackColor(XFColor(pColor->To24Color()));
856 : }
857 8 : }
858 :
859 :
860 8 : void LwpHeaderLayout::ParseWaterMark(XFHeaderStyle * pHeaderStyle)
861 : {
862 8 : XFBGImage* pXFBGImage = GetXFBGImage();
863 8 : if(pXFBGImage)
864 : {
865 0 : pHeaderStyle->SetBackImage(pXFBGImage);
866 : }
867 8 : }
868 : //End by
869 :
870 8 : void LwpHeaderLayout::RegisterStyle(XFMasterPage* mp1)
871 : {
872 8 : XFHeader* pHeader = new XFHeader();
873 8 : LwpObject* pStory = m_Content.obj();
874 8 : if(pStory)
875 : {
876 8 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
877 8 : LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
878 8 : pChangeMgr->SetHeadFootFribMap(sal_True);
879 :
880 : //Call the RegisterStyle first to register the styles in header paras, and then XFConvert()
881 8 : pStory->SetFoundry(m_pFoundry);
882 8 : pStory->RegisterStyle();
883 : //, 06/27/2005
884 : //register child layout style for framelayout,
885 8 : RegisterChildStyle();
886 : //End
887 8 : pChangeMgr->SetHeadFootChange(pHeader);
888 8 : pStory->XFConvert(pHeader);
889 :
890 8 : pChangeMgr->SetHeadFootFribMap(sal_False);
891 : }
892 8 : mp1->SetHeader(pHeader);
893 8 : }
894 :
895 12 : LwpFooterLayout::LwpFooterLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
896 12 : : LwpPlacableLayout( objHdr, pStrm )
897 : {
898 12 : }
899 :
900 24 : LwpFooterLayout::~LwpFooterLayout()
901 : {
902 24 : }
903 :
904 12 : void LwpFooterLayout::Read()
905 : {
906 12 : LwpPlacableLayout::Read();
907 :
908 12 : if(LwpFileHeader::m_nFileRevision >= 0x000E)
909 12 : m_nBorderOffset = m_pObjStrm->QuickReadInt32();
910 : else
911 0 : m_nBorderOffset = 0;
912 12 : m_pObjStrm->SkipExtra();
913 12 : }
914 :
915 8 : void LwpFooterLayout::RegisterStyle(XFPageMaster* pm1)
916 : {
917 8 : XFFooterStyle* pFooterStyle = new XFFooterStyle();
918 :
919 : //Modify page bottom margin
920 : //page bottom maring: from bottom of footer to the bottom edge
921 8 : double bottom = GetMarginsValue(MARGIN_BOTTOM);
922 8 : pm1->SetMargins(-1, -1, -1, bottom);
923 :
924 8 : ParseMargins(pFooterStyle);
925 8 : ParseBorder(pFooterStyle);
926 8 : ParseShadow(pFooterStyle);
927 8 : ParseBackGround(pFooterStyle);
928 : // ParseBackColor(pFooterStyle);
929 :
930 8 : ParseWaterMark(pFooterStyle);
931 : //End by
932 :
933 8 : pm1->SetFooterStyle(pFooterStyle);
934 8 : }
935 :
936 8 : void LwpFooterLayout::ParseMargins(XFFooterStyle* pFooterStyle)
937 : {
938 :
939 : //Set height: from top of header to top of body, including the spacing between header and body
940 8 : double height = GetGeometryHeight() - GetMarginsValue(MARGIN_BOTTOM);
941 8 : if( IsAutoGrowUp() )
942 : {
943 0 : pFooterStyle->SetMinHeight(height);
944 : }
945 : else
946 : {
947 8 : pFooterStyle->SetHeight(height);
948 : }
949 :
950 : //Set left,right,top margins
951 8 : LwpMiddleLayout* parent = dynamic_cast<LwpMiddleLayout*> (GetParent()->obj());
952 8 : double left = GetMarginsValue(MARGIN_LEFT) - (parent ? parent->GetMarginsValue(MARGIN_LEFT) : 0);
953 8 : if(left<=0) //The left margin in SODC can not be minus value
954 : {
955 8 : left = -1;
956 : }
957 8 : double right = GetMarginsValue(MARGIN_RIGHT) - (parent ? parent->GetMarginsValue(MARGIN_RIGHT) : 0);
958 8 : if(right<=0)//The left margin in SODC can not be minus value
959 : {
960 8 : right = -1;
961 : }
962 8 : pFooterStyle->SetMargins( left, right, GetMarginsValue(MARGIN_TOP));
963 :
964 : //Word Pro has no dynamic spacing, should be set to false
965 8 : pFooterStyle->SetDynamicSpace(sal_False);
966 8 : }
967 :
968 8 : void LwpFooterLayout::ParseBorder(XFFooterStyle* pFooterStyle)
969 : {
970 8 : XFBorders* pBordres = GetXFBorders();
971 8 : if(pBordres)
972 : {
973 0 : pFooterStyle->SetBorders(pBordres);
974 : }
975 8 : }
976 :
977 8 : void LwpFooterLayout::ParseShadow(XFFooterStyle* pFooterStyle)
978 : {
979 8 : XFShadow* pXFShadow = GetXFShadow();
980 8 : if(pXFShadow)
981 : {
982 0 : pFooterStyle->SetShadow(pXFShadow);
983 : }
984 8 : }
985 : /**
986 : * @descr: set footer back pattern
987 : *
988 : */
989 0 : void LwpFooterLayout::ParsePatternFill(XFFooterStyle* pFooterStyle)
990 : {
991 0 : XFBGImage* pXFBGImage = this->GetFillPattern();
992 0 : if (pXFBGImage)
993 : {
994 0 : pFooterStyle->SetBackImage(pXFBGImage);
995 : }
996 0 : }
997 : /**
998 : * @descr: set footer background
999 : *
1000 : */
1001 8 : void LwpFooterLayout::ParseBackGround(XFFooterStyle* pFooterStyle)
1002 : {
1003 8 : if (this->IsPatternFill())
1004 : {
1005 0 : ParsePatternFill(pFooterStyle);
1006 : }
1007 : else
1008 : {
1009 8 : ParseBackColor(pFooterStyle);
1010 : }
1011 8 : }
1012 :
1013 8 : void LwpFooterLayout::ParseBackColor(XFFooterStyle* pFooterStyle)
1014 : {
1015 8 : LwpColor* pColor = GetBackColor();
1016 8 : if(pColor)
1017 : {
1018 0 : pFooterStyle->SetBackColor(XFColor(pColor->To24Color()));
1019 : }
1020 8 : }
1021 :
1022 8 : void LwpFooterLayout::RegisterStyle(XFMasterPage* mp1)
1023 : {
1024 8 : XFFooter* pFooter = new XFFooter();
1025 8 : LwpObject* pStory = m_Content.obj(VO_STORY);
1026 : //Call the RegisterStyle first to register the styles in footer paras, and then XFConvert()
1027 8 : if(pStory)
1028 : {
1029 8 : LwpGlobalMgr* pGlobal = LwpGlobalMgr::GetInstance();
1030 8 : LwpChangeMgr* pChangeMgr = pGlobal->GetLwpChangeMgr();
1031 8 : pChangeMgr->SetHeadFootFribMap(sal_True);
1032 :
1033 8 : pStory->SetFoundry(m_pFoundry);
1034 8 : pStory->RegisterStyle();
1035 : //, 06/27/2005
1036 : //register child layout style for framelayout,
1037 8 : RegisterChildStyle();
1038 : //End
1039 :
1040 8 : pChangeMgr->SetHeadFootChange(pFooter);//add by ,7/6
1041 :
1042 8 : pStory->XFConvert(pFooter);
1043 :
1044 8 : pChangeMgr->SetHeadFootFribMap(sal_False);
1045 : }
1046 8 : mp1->SetFooter(pFooter);
1047 8 : }
1048 :
1049 :
1050 8 : void LwpFooterLayout::ParseWaterMark(XFFooterStyle * pFooterStyle)
1051 : {
1052 8 : XFBGImage* pXFBGImage = GetXFBGImage();
1053 8 : if(pXFBGImage)
1054 : {
1055 0 : pFooterStyle->SetBackImage(pXFBGImage);
1056 : }
1057 8 : }
1058 : //End by
1059 :
1060 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|