merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpframelayout.cxx
blobc7d953f7a7c6276f121a6cfa6c157ec00a7b210d
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*************************************************************************
56 * @file
57 * the class for VO_FrameLayout
58 ************************************************************************/
59 /*************************************************************************
60 * Change History
61 Mar 2005 Created
62 ************************************************************************/
63 #include "lwpframelayout.hxx"
64 #include "lwppara.hxx"
65 #include "xfilter/xfstylemanager.hxx"
66 #include "xfilter/xfparagraph.hxx"
67 #include "xfilter/xffloatframe.hxx"
68 #include "xfilter/xfrubystyle.hxx"
69 #include "lwppagelayout.hxx"
70 #include "lwpoleobject.hxx"
71 #include "lwptablelayout.hxx"
72 #include "lwpgrfobj.hxx"
73 #include "lwpglobalmgr.hxx"
75 LwpFrame::LwpFrame(LwpPlacableLayout* pLayout):m_pLayout(pLayout)
79 LwpFrame::~LwpFrame()
82 /**
83 * @descr: parse frame
84 * @param: register frame style
85 * @param: pFrameStyle - Frame Style object
88 void LwpFrame::RegisterStyle(XFFrameStyle* pFrameStyle)
90 ApplyWrapType(pFrameStyle);
91 ApplyMargins(pFrameStyle);
92 ApplyPadding(pFrameStyle);
93 ApplyBorders(pFrameStyle);
94 ApplyColumns(pFrameStyle);
95 ApplyShadow(pFrameStyle);
96 ApplyBackGround(pFrameStyle);
97 ApplyWatermark(pFrameStyle);
98 // ApplyBackColor(pFrameStyle);
99 ApplyProtect(pFrameStyle);
100 ApplyTextDir(pFrameStyle);
101 ApplyPosType(pFrameStyle);
103 pFrameStyle->SetStyleName(m_pLayout->GetName()->str());
104 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
105 m_StyleName = pXFStyleManager->AddStyle(pFrameStyle)->GetStyleName();
106 m_pLayout->SetStyleName(m_StyleName);
109 * @descr: parse frame and set frame properties
110 * @param: pXFFrame - XFFrame object
111 * @param: nPageNo - the page number that the frame anchors
114 void LwpFrame::Parse(XFFrame* pXFFrame, sal_Int32 nPageNo)
116 //set the frame style name
117 pXFFrame->SetStyleName(m_StyleName);
119 //SetAnchorType and position,if it's page anchor,set the page number.
120 ParseAnchorType(pXFFrame);
121 if(nPageNo>0)
123 pXFFrame->SetAnchorPage(nPageNo);
126 //Set frame Name
127 OUString aFrameName = m_pLayout->GetName()->str();
128 if(aFrameName.getLength())
130 //cause the bug of SODC, the linkframe name can not be "Frame1", so I change the frame name
131 /*if(aFrameName.equals(A2OUSTR("Frame1")))
133 aFrameName = A2OUSTR("Frame1_COPY");
135 pXFFrame->SetName(aFrameName);*/
136 pXFFrame->SetName(m_StyleName);
139 LwpLayoutGeometry* pLayoutGeo = m_pLayout->GetGeometry();
140 //Set frame Width and height
141 if(pLayoutGeo)
143 double fWidth = m_pLayout->GetWidth();
144 double fHeight = m_pLayout->GetHeight();
146 pXFFrame->SetWidth( fWidth );
147 pXFFrame->SetHeight( fHeight );
149 //Get content obj;
150 LwpObject* pObj = m_pLayout->GetContent()->obj();
151 if(m_pLayout->IsGroupHead()&&(m_pLayout->IsMinimumHeight()))
153 //process grouplayout height. there is problems now
154 pXFFrame->SetHeight( fHeight );
157 else if(m_pLayout->IsFitGraphic() && pObj && pObj->GetTag() == VO_GRAPHIC)
159 //If is graphic, get original size and set it;
160 LwpGraphicObject* pGrpObj = static_cast<LwpGraphicObject*>(pObj);
161 long nHeight =0, nWidth =0;
162 pGrpObj->GetGrafOrgSize(nWidth, nHeight);
163 //add margins to the width and height;
164 fWidth = (double)nWidth/TWIPS_PER_CM + m_pLayout->GetMarginsValue(MARGIN_LEFT) + m_pLayout->GetMarginsValue(MARGIN_RIGHT);
165 fHeight = (double)nHeight/TWIPS_PER_CM + m_pLayout->GetMarginsValue(MARGIN_TOP) + m_pLayout->GetMarginsValue(MARGIN_BOTTOM);
166 pXFFrame->SetWidth(fWidth);
167 pXFFrame->SetHeight(fHeight);
170 else if(m_pLayout->IsAutoGrow())
172 pXFFrame->SetMinHeight( fHeight );
176 if(m_pLayout->IsFrame())
178 //Set frame link. Only frame layout has this feature
179 LwpFrameLayout* pLayout= static_cast<LwpFrameLayout*>(m_pLayout);
180 pXFFrame->SetNextLink(pLayout->GetNextLinkName());
185 * @descr: parse frame relative to page, frame or cell
186 * @param: pCont - content container which contains the frame
189 void LwpFrame::XFConvert(XFContentContainer* pCont)
191 //parse the frame which anchor to page
192 LwpVirtualLayout* pParent = m_pLayout->GetParentLayout();
193 if(pParent->IsPage()&& pParent->GetParentLayout()->IsPage())
195 //for mirror page, problems exist if the parent layout is header or footer layout,
196 pParent = pParent->GetParentLayout();
198 if(m_pLayout->IsAnchorPage()&& pParent->IsPage())
200 //get parent layout
201 if(m_pLayout->IsUseOnPage())
203 sal_Int32 nPageNo = pParent->GetPageNumber(m_pLayout->GetUsePage());
204 if(nPageNo>0)
205 m_pLayout->XFConvertFrame(pCont, nPageNo);
207 else if(m_pLayout->IsUseOnAllPages())
209 sal_Int32 nFirst = pParent->GetPageNumber(FIRST_LAYOUTPAGENO);
210 sal_Int32 nLast = pParent->GetPageNumber(LAST_LAYOUTPAGENO);
211 if(nLast > 0)
212 m_pLayout->XFConvertFrame(pCont, nFirst, nLast, sal_True);
215 else if(m_pLayout->IsUseOnAllOddPages()||m_pLayout->IsUseOnAllEvenPages())
217 sal_Int32 nFirst = pParent->GetPageNumber(FIRST_LAYOUTPAGENO);
218 sal_Int32 nLast = pParent->GetPageNumber(LAST_LAYOUTPAGENO);
219 if(nLast > 0)
221 sal_uInt16 first = static_cast<sal_uInt16>(nFirst);
222 if((m_pLayout->IsUseOnAllOddPages() && !LwpTools::IsOddNumber(first))
223 || (m_pLayout->IsUseOnAllEvenPages() && !LwpTools::IsEvenNumber(first)))
224 nFirst++;
225 if(nFirst <= nLast)
227 m_pLayout->XFConvertFrame(pCont, nFirst, nLast, sal_False);
232 else
234 m_pLayout->XFConvertFrame(pCont);
239 * @descr: set frame wrap type style
240 * @param: pFrameStyle - Frame Style object
243 void LwpFrame::ApplyWrapType(XFFrameStyle *pFrameStyle)
245 enumXFWrap eWrap = enumXFWrapNone;
246 switch(m_pLayout->GetWrapType())
248 case LwpPlacableLayout::LAY_WRAP_AROUND: //fall throught
249 case LwpPlacableLayout::LAY_WRAP_IRREG_BIGGEST:
251 //In SODC, if Optimal wrap type is used and the distance between the frame object
252 //and page margins is less than 2cm, the text is not wraped. While there is no this feature in Word Pro
253 //So the optimal wrap type is translated to left side or right side wrap type according to the distance
254 //between the frame object and page margins
256 eWrap = enumXFWrapBest;
257 LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
258 if(pParent)
260 if(IsLeftWider())
261 eWrap = enumXFWrapLeft;
262 else
263 eWrap = enumXFWrapRight;
265 break;
267 case LwpPlacableLayout::LAY_NO_WRAP_BESIDE:
269 eWrap = enumXFWrapNone;
270 break;
272 case LwpPlacableLayout::LAY_NO_WRAP_AROUND:
274 eWrap = enumXFWrapRunThrough;
275 if(!m_pLayout->GetBackColor() && !m_pLayout->GetWaterMarkLayout())
277 //pFrameStyle->SetBackGround(sal_True);
278 XFColor aXFColor(0xffffff); //white color
279 pFrameStyle->SetBackColor(aXFColor);
280 pFrameStyle->SetTransparency(100); //transparency
282 break;
284 case LwpPlacableLayout::LAY_WRAP_LEFT: //fall throught
285 case LwpPlacableLayout::LAY_WRAP_IRREG_LEFT:
287 eWrap = enumXFWrapLeft;
288 break;
290 case LwpPlacableLayout::LAY_WRAP_RIGHT: //fall throught
291 case LwpPlacableLayout::LAY_WRAP_IRREG_RIGHT:
293 eWrap = enumXFWrapRight;
294 break;
296 case LwpPlacableLayout::LAY_WRAP_BOTH: //fall throught
297 case LwpPlacableLayout::LAY_WRAP_IRREG_BOTH:
299 eWrap = enumXFWrapParallel;
300 break;
302 default:
303 break;
306 //If it is the type of with para above, wrap type is enumXFWrapNone
307 if(m_pLayout->GetRelativeType()==LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE)
309 eWrap = enumXFWrapNone;
312 pFrameStyle->SetWrapType(eWrap);
315 * @descr: set frame margins style
316 * @param: pFrameStyle - Frame Style object
319 void LwpFrame::ApplyMargins(XFFrameStyle *pFrameStyle)
321 double fLeft = m_pLayout->GetExtMarginsValue(MARGIN_LEFT);
322 double fRight = m_pLayout->GetExtMarginsValue(MARGIN_RIGHT);
323 double fTop = m_pLayout->GetExtMarginsValue(MARGIN_TOP);
324 double fBottom = m_pLayout->GetExtMarginsValue(MARGIN_BOTTOM);
325 pFrameStyle->SetMargins(fLeft,fRight,fTop,fBottom);
328 * @descr: set padding border style
329 * @param: pFrameStyle - Frame Style object
332 void LwpFrame::ApplyPadding(XFFrameStyle *pFrameStyle)
334 double fLeft = m_pLayout->GetMarginsValue(MARGIN_LEFT);
335 double fRight = m_pLayout->GetMarginsValue(MARGIN_RIGHT);
336 double fTop = m_pLayout->GetMarginsValue(MARGIN_TOP);
337 double fBottom = m_pLayout->GetMarginsValue(MARGIN_BOTTOM);
338 pFrameStyle->SetPadding(fLeft,fRight,fTop,fBottom);
341 * @descr: set frame border style
342 * @param: pFrameStyle - Frame Style object
345 void LwpFrame::ApplyBorders(XFFrameStyle *pFrameStyle)
347 XFBorders* pBordres = m_pLayout->GetXFBorders();
348 if(pBordres)
350 pFrameStyle->SetBorders(pBordres);
354 * @descr: set frame colums style
355 * @param: pFrameStyle - Frame Style object
358 void LwpFrame::ApplyColumns(XFFrameStyle *pFrameStyle)
360 XFColumns* pColumns = m_pLayout->GetXFColumns();
361 if(pColumns)
363 pFrameStyle->SetColumns(pColumns);
367 * @descr: set frame shadow style
368 * @param: pFrameStyle - Frame Style object
371 void LwpFrame::ApplyShadow(XFFrameStyle* pFrameStyle)
373 XFShadow* pXFShadow = m_pLayout->GetXFShadow();
374 if(pXFShadow)
376 pFrameStyle->SetShadow(pXFShadow);
380 * @descr: set frame back color style
381 * @param: pFrameStyle - Frame Style object
384 void LwpFrame::ApplyBackColor(XFFrameStyle* pFrameStyle)
386 LwpColor* pColor = m_pLayout->GetBackColor();
387 if(pColor)
389 XFColor aXFColor(pColor->To24Color());
390 pFrameStyle->SetBackColor(aXFColor);
394 * @descr: set frame protect style
395 * @param: pFrameStyle - Frame Style object
398 void LwpFrame::ApplyProtect(XFFrameStyle* pFrameStyle)
400 if(m_pLayout->IsProtected())
402 pFrameStyle->SetProtect(sal_True,sal_True,sal_True);
406 * @descr: set frame text direction style
407 * @param: pFrameStyle - Frame Style object
410 void LwpFrame::ApplyTextDir(XFFrameStyle* pFrameStyle)
412 pFrameStyle->SetTextDir(m_pLayout->GetTextDirection());
415 * @descr: set frame position type style
416 * @param: pFrameStyle - Frame Style object
419 void LwpFrame::ApplyPosType(XFFrameStyle* pFrameStyle)
421 enumXFFrameXPos eXPos = enumXFFrameXPosCenter;
422 enumXFFrameXRel eXRel = enumXFFrameXRelPara;
423 enumXFFrameYPos eYPos = enumXFFrameYPosMiddle;
424 enumXFFrameYRel eYRel = enumXFFrameYRelPara;
425 sal_uInt8 nType = m_pLayout->GetRelativeType();
426 switch(nType)
428 case LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE://fall throught
429 case LwpLayoutRelativityGuts::LAY_CONTENT_RELATIVE:
431 //anchor to page, frame and cell
432 eXPos = enumXFFrameXPosFromLeft;
433 eXRel = enumXFFrameXRelPage;
434 //set vertical position
435 if(m_pLayout->IsAnchorPage())//in page
437 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
438 if(pContainer && (pContainer->IsHeader() || pContainer->IsFooter()))
440 //Only anchor to para, the frame can display in header and footer of each page
441 eYPos = enumXFFrameYPosFromTop; //from top
442 eYRel = enumXFFrameYRelPara; //from margin
444 else
446 eYPos = enumXFFrameYPosFromTop;
447 eYRel = enumXFFrameYRelPage;
450 if(m_pLayout->IsAnchorFrame()) //in frame
452 eYPos = enumXFFrameYPosFromTop;
453 eYRel = enumXFFrameYRelPage;
455 if(m_pLayout->IsAnchorCell())
457 //SODC has no this type, simulate this feature
458 eYPos = enumXFFrameYPosFromTop; //from top
459 eYRel = enumXFFrameYRelPara; //from margin
461 break;
463 case LwpLayoutRelativityGuts::LAY_PARA_RELATIVE: //same page as text
465 eXPos = enumXFFrameXPosFromLeft;
466 eXRel = enumXFFrameXRelPage;
467 eYPos = enumXFFrameYPosBelow; //below
468 eYRel = enumXFFrameYRelChar; //from char
469 //set vertical position
470 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
471 if(pContainer && pContainer->IsPage())//in page
473 //eYPos = enumXFFrameYPosFromTop;
474 //eYRel = enumXFFrameYRelPage;
475 eYPos = enumXFFrameYPosBelow;
476 eYRel = enumXFFrameYRelChar;
478 else if(pContainer && pContainer->IsFrame()) //in frame
480 eYPos = enumXFFrameYPosFromTop;
481 eYRel = enumXFFrameYRelPage;
483 else
485 eYPos = enumXFFrameYPosFromTop; //from top
486 eYRel = enumXFFrameYRelPara; //from margin
488 break;
490 case LwpLayoutRelativityGuts::LAY_INLINE: //in text
492 eXPos = enumXFFrameXPosFromLeft; //need not be set
493 eXRel = enumXFFrameXRelParaContent; //need not be set
494 eYPos = enumXFFrameYPosTop; //should be from top
495 eYRel = enumXFFrameYRelBaseLine;
496 sal_Int32 nOffset = m_pLayout->GetBaseLineOffset();
497 if(nOffset>0)
499 eYPos = enumXFFrameYPosFromTop;
501 break;
503 case LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE: //with para above
505 eXPos = enumXFFrameXPosFromLeft;
506 eXRel = enumXFFrameXRelParaContent;
507 //eYPos = enumXFFrameYPosTop;
508 eYPos = enumXFFrameYPosBottom;
509 eYRel = enumXFFrameYRelParaContent;
510 break;
512 case LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL: //in text - vertical
514 eXPos = enumXFFrameXPosFromLeft;
515 eXRel = enumXFFrameXRelPage;
516 eYPos = enumXFFrameYPosFromTop; //should be below position
517 eYRel = enumXFFrameYRelChar;
518 break;
520 default:
521 break;
524 pFrameStyle->SetXPosType(eXPos,eXRel);
525 pFrameStyle->SetYPosType(eYPos,eYRel);
528 * @descr: set frame watermark style
529 * @param: pFrameStyle - Frame Style object
532 void LwpFrame::ApplyWatermark(XFFrameStyle *pFrameStyle)
534 XFBGImage* pBGImage = m_pLayout->GetXFBGImage();
535 if(pBGImage)
537 pFrameStyle->SetBackImage(pBGImage);
538 //set watermark transparent
539 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*>(m_pLayout->GetWaterMarkLayout());
540 LwpBackgroundStuff* pBackgroundStuff = pLay->GetBackgroundStuff();
541 if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
543 pFrameStyle->SetTransparency(100);
549 * @short Apply pattern fill to frame style
550 * @param pFrameStyle - pointer of XFFrameStyle
551 * @return
553 void LwpFrame::ApplyPatternFill(XFFrameStyle* pFrameStyle)
555 XFBGImage* pXFBGImage = m_pLayout->GetFillPattern();
556 if (pXFBGImage)
558 pFrameStyle->SetBackImage(pXFBGImage);
563 * @short Apply background to frame style
564 * @param pFrameStyle - pointer of XFFrameStyle
565 * @return
567 void LwpFrame::ApplyBackGround(XFFrameStyle* pFrameStyle)
569 if (!m_pLayout)
571 return;
574 if (m_pLayout->IsPatternFill())
576 ApplyPatternFill(pFrameStyle);
578 else
580 ApplyBackColor(pFrameStyle);
585 * @descr: set frame size, anchor type, anchored page number
586 * @param: pXFFrame - XFFrame object
589 void LwpFrame::ParseAnchorType(XFFrame *pXFFrame)
591 //set position
592 double fXOffset = 0;
593 double fYOffset = 0;
594 //page number
595 sal_uInt16 nPageNum = 0;
596 //set anchor type
597 enumXFAnchor eAnchor = enumXFAnchorNone;
599 LwpLayoutGeometry* pLayoutGeo = m_pLayout->GetGeometry();
600 if(pLayoutGeo)
602 LwpPoint aPoint = pLayoutGeo->GetOrigin();
603 fXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
604 fYOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetY());
606 //set anchor type
607 eAnchor = enumXFAnchorNone;
608 sal_uInt8 nType = m_pLayout->GetRelativeType();
609 switch(nType)
611 case LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE://fall throught
612 case LwpLayoutRelativityGuts::LAY_CONTENT_RELATIVE:
614 //anchor to page, frame and cell
615 if(m_pLayout->IsAnchorPage())//in page
617 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
618 if(pContainer && (pContainer->IsHeader() || pContainer->IsFooter()))
620 eAnchor = enumXFAnchorPara;
621 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
623 else
624 eAnchor = enumXFAnchorPage;
626 if(m_pLayout->IsAnchorFrame()) //in frame
628 eAnchor = enumXFAnchorFrame;
630 if(m_pLayout->IsAnchorCell()) //in cell
632 //eAnchor = enumXFAnchorChar;
633 eAnchor = enumXFAnchorPara;
634 LwpMiddleLayout* pContainer = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
635 if(pContainer)
637 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
640 break;
642 case LwpLayoutRelativityGuts::LAY_PARA_RELATIVE: //same page as text
644 eAnchor = enumXFAnchorChar;
645 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
646 if(pContainer && pContainer->IsPage())//in page
648 //eAnchor = enumXFAnchorPage;
649 eAnchor = enumXFAnchorChar;// to character
651 else if(pContainer && pContainer->IsFrame()) //in frame
653 eAnchor = enumXFAnchorFrame;
655 else if(pContainer && pContainer->IsCell()) //in cell
657 //eAnchor = enumXFAnchorChar;
658 eAnchor = enumXFAnchorPara;
659 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
661 else if(pContainer && (pContainer->IsHeader() || pContainer->IsFooter()))//in header or footer
663 eAnchor = enumXFAnchorPara;
664 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
666 break;
668 case LwpLayoutRelativityGuts::LAY_INLINE: //in text
670 eAnchor = enumXFAnchorAsChar;
671 sal_Int32 nOffset = m_pLayout->GetBaseLineOffset();
672 if(nOffset>0 && pLayoutGeo)
674 //experiential value
675 fYOffset =-(m_pLayout->GetGeometryHeight()+2*m_pLayout->GetExtMarginsValue(MARGIN_BOTTOM)-LwpTools::ConvertFromUnitsToMetric(nOffset));
677 break;
679 case LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE: //with para above
681 eAnchor = enumXFAnchorPara;
682 break;
684 case LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL: //in text - vertical
686 eAnchor = enumXFAnchorChar;
687 //set vertical position
688 double offset = 0;
690 //because of the different feature between Word Pro and SODC, I simulate the vertical base offset
691 //between anchor and frame orgin using the font height.
692 //LwpPara* pPara = static_cast<LwpPara*>(m_pLayout->GetPosition()->obj());
693 XFFont* pFont = m_pLayout->GetFont();
694 if(pFont)
696 offset = (double)(pFont->GetFontSize())*CM_PER_INCH/POINTS_PER_INCH;
698 fYOffset = offset-fYOffset;
699 break;
701 default:
702 break;
705 pXFFrame->SetX(fXOffset);
706 pXFFrame->SetY(fYOffset);
707 pXFFrame->SetAnchorPage(nPageNum);
708 pXFFrame->SetAnchorType(eAnchor);
712 * @descr Calculate the distance between the frame object and the page margins.
713 * And determine which side(left or right) is wider
715 sal_Bool LwpFrame::IsLeftWider()
717 //LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
718 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*>(m_pLayout->GetContainerLayout());
719 if(pParent)
721 LwpPoint aPoint = m_pLayout->GetOrigin();
722 double fXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
723 double fWidth = m_pLayout->GetWidth();
724 double fWrapLeft = m_pLayout->GetExtMarginsValue(MARGIN_LEFT);
725 double fWrapRight = m_pLayout->GetExtMarginsValue(MARGIN_RIGHT);
727 //LwpPoint aParentPoint = pParent->GetOrigin();
728 //double fParentXOffset = LwpTools::ConvertFromUnitsToMetric(aParentPoint.GetX());
729 double fParentWidth = pParent->GetWidth();
730 if(pParent->IsCell())
732 //Get actual width of this cell layout
733 fParentWidth = static_cast<LwpCellLayout*>(pParent)->GetActualWidth();
735 double fParentMarginLeft = pParent->GetMarginsValue(MARGIN_LEFT);
736 double fParentMarginRight = pParent->GetMarginsValue(MARGIN_RIGHT);
738 double fLeft = fXOffset - fWrapLeft -fParentMarginLeft;
739 double fRight = fParentWidth - fParentMarginRight -(fXOffset + fWidth + fWrapRight);
740 if(fLeft > fRight)
741 return sal_True;
743 return sal_False;
746 LwpFrameLink::LwpFrameLink()
749 LwpFrameLink::~LwpFrameLink()
753 * @descr frame link information
756 void LwpFrameLink::Read(LwpObjectStream* pStrm)
758 m_PreviousLayout.ReadIndexed(pStrm);
759 m_NextLayout.ReadIndexed(pStrm);
760 pStrm->SkipExtra();
763 LwpFrameLayout::LwpFrameLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
764 : LwpPlacableLayout(objHdr, pStrm), m_pFrame(NULL)
769 LwpFrameLayout::~LwpFrameLayout()
771 if(m_pFrame)
773 delete m_pFrame;
774 m_pFrame = NULL;
779 * @descr read frame layout object
782 void LwpFrameLayout::Read()
784 LwpPlacableLayout::Read();
785 if(LwpFileHeader::m_nFileRevision >= 0x000B)
787 if(m_pObjStrm->QuickReaduInt16())
789 m_Link.Read(m_pObjStrm);
792 m_pObjStrm->SkipExtra();
796 * @descr create a xfframe and add into content container
797 * @param: pCont - content container that contains the frame.
800 void LwpFrameLayout::XFConvert(XFContentContainer* pCont)
802 if(m_pFrame)
804 //parse the frame which anchor to paragraph
805 if(IsRelativeAnchored())
807 XFConvertFrame(pCont);
809 else
811 m_pFrame->XFConvert(pCont);
817 * @descr create a xfframe and add into content container, called by XFConvert
818 * @param: pCont - content container that contains the frame.
819 * @param: nPageNo - the page number that the frame anchors
822 void LwpFrameLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd, sal_Bool bAll )
824 if(m_pFrame)
826 XFFrame* pXFFrame = NULL;
827 if(nEnd < nStart)
829 pXFFrame = new XFFrame();
831 else
833 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
836 m_pFrame->Parse(pXFFrame, nStart);
837 //if it is a link frame, parse contents only once
838 if(!HasPreviousLinkLayout())
840 LwpObject* content = m_Content.obj();
841 if (content)
843 content->XFConvert(pXFFrame);
844 //set frame size according to ole size
845 ApplyGraphicSize(pXFFrame);
848 pCont ->Add(pXFFrame);
852 * @descr register frame style
855 void LwpFrameLayout::RegisterStyle()
857 //if it is for water mark, don't register style
858 if(IsForWaterMark())
860 return;
862 //register frame style
863 XFFrameStyle* pFrameStyle = new XFFrameStyle();
864 m_pFrame = new LwpFrame(this);
865 m_pFrame->RegisterStyle(pFrameStyle);
867 //register content style
868 LwpObject* content = m_Content.obj();
869 if (content)
871 content->SetFoundry(m_pFoundry);
872 content->RegisterStyle();
875 //register child frame style
876 RegisterChildStyle();
881 * @descr get the name of the frame that current frame links
884 OUString LwpFrameLayout::GetNextLinkName()
886 OUString aName;
887 LwpObjectID* pObjectID = m_Link.GetNextLayout();
888 if(!pObjectID->IsNull())
890 LwpLayout* pLayout = static_cast<LwpLayout*>(pObjectID->obj());
891 aName = pLayout->GetName()->str();
892 //for division name confict
893 if(pLayout->GetStyleName().getLength() > 0)
894 aName = pLayout->GetStyleName();
896 return aName;
899 * @descr whether current frame is linked by other frame
902 sal_Bool LwpFrameLayout::HasPreviousLinkLayout()
904 LwpObjectID* pObjectID = m_Link.GetPreviousLayout();
905 if(pObjectID->IsNull())
906 return sal_False;
907 return sal_True;
910 * @descr whether current frame is for water mark. Problem maybe exsits by this method, must be tracking
913 sal_Bool LwpFrameLayout::IsForWaterMark()
915 if(m_nBuoyancy >=LAY_BUOYLAYER)
917 if(!m_Content.IsNull() && (m_Content.obj()->GetTag()==VO_GRAPHIC) )
919 return sal_True;
922 return sal_False;
926 * @descr Get frame width
929 double LwpFrameLayout::GetWidth()
931 double fWidth = LwpMiddleLayout::GetWidth();
932 if(IsInlineToMargin() && IsAutoGrowWidth())
934 //for text field entry when choosing maximize field length
935 fWidth = GetMaxWidth();
937 return fWidth;
941 * @descr Get frame width when the text field chooses maximize field length
944 double LwpFrameLayout::GetMaxWidth()
946 double fActualWidth = 0;
947 LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(GetContainerLayout());
948 if(pParent)
950 LwpPoint aPoint = GetOrigin();
951 double fXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
952 double fWrapRight = GetExtMarginsValue(MARGIN_RIGHT);
954 //Get parent layout width
955 double fParentWidth = pParent->GetWidth();
956 if(pParent->IsCell())
958 //Get actual width of this cell layout
959 fParentWidth = static_cast<LwpCellLayout*>(pParent)->GetActualWidth();
962 double fParentMarginRight = 0;
963 sal_uInt8 nType = GetRelativeType();
964 if(nType == LwpLayoutRelativityGuts::LAY_INLINE
965 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
967 fParentMarginRight = pParent->GetMarginsValue(MARGIN_RIGHT);
970 fActualWidth = fParentWidth - fXOffset - fParentMarginRight - fWrapRight;
973 return fActualWidth;
977 * @descr Set frame size according to graphic size
980 void LwpFrameLayout::ApplyGraphicSize(XFFrame * pXFFrame)
982 LwpObject* content = m_Content.obj();
983 if(content && (content->GetTag() == VO_GRAPHIC
984 || content->GetTag() == VO_OLEOBJECT ))
986 LwpGraphicOleObject* pGraOle = static_cast<LwpGraphicOleObject*>(content);
987 //Get frame geometry size
988 double fWidth = 0;
989 double fHeight = 0;
990 pGraOle->GetGrafScaledSize(fWidth, fHeight);
991 if( IsFitGraphic())
993 //graphic scaled sze
994 fWidth += GetMarginsValue(MARGIN_LEFT) + GetMarginsValue(MARGIN_RIGHT);
995 fHeight += GetMarginsValue(MARGIN_TOP) + GetMarginsValue(MARGIN_BOTTOM);
997 else if(IsAutoGrowDown() || IsAutoGrowUp())
999 fWidth = GetWidth();
1000 fHeight += GetMarginsValue(MARGIN_TOP) + GetMarginsValue(MARGIN_BOTTOM);
1002 else if( IsAutoGrowLeft() || IsAutoGrowRight())
1004 fHeight = GetHeight();
1005 fWidth += GetMarginsValue(MARGIN_LEFT) + GetMarginsValue(MARGIN_RIGHT);
1007 else
1009 fWidth = GetWidth();
1010 fHeight = GetHeight();
1012 pXFFrame->SetWidth(fWidth);
1013 pXFFrame->SetHeight(fHeight);
1017 LwpGroupLayout::LwpGroupLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1018 : LwpPlacableLayout(objHdr, pStrm),m_pFrame(NULL)
1023 LwpGroupLayout::~LwpGroupLayout()
1025 if(m_pFrame)
1027 delete m_pFrame;
1028 m_pFrame = NULL;
1032 * @descr read group layout object
1035 void LwpGroupLayout::Read()
1037 LwpPlacableLayout::Read();
1038 m_pObjStrm->SkipExtra();
1041 * @descr register group frame style
1044 void LwpGroupLayout::RegisterStyle()
1046 //register frame style
1047 XFFrameStyle* pFrameStyle = new XFFrameStyle();
1048 m_pFrame = new LwpFrame(this);
1049 m_pFrame->RegisterStyle(pFrameStyle);
1051 //register child frame style
1052 RegisterChildStyle();
1054 LwpVirtualLayout* pLayout = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
1055 while(pLayout)
1057 pLayout->SetFoundry(m_pFoundry);
1058 pLayout->RegisterStyle();
1059 pLayout = static_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
1064 * @descr create a xfframe and add into content container
1065 * @param: pCont - content container that contains the frame.
1068 void LwpGroupLayout::XFConvert(XFContentContainer *pCont)
1070 if(m_pFrame)
1072 //parse the frame which anchor to paragraph
1073 if(IsRelativeAnchored())
1075 XFConvertFrame(pCont);
1077 else
1079 m_pFrame->XFConvert(pCont);
1085 * @descr create a xfframe and add into content container, called by XFConvert
1086 * @param: pCont - content container that contains the frame.
1087 * @param: nPageNo - the page number that the frame anchors
1090 void LwpGroupLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd, sal_Bool bAll)
1092 if(m_pFrame)
1094 XFFrame* pXFFrame = NULL;
1095 if(nEnd < nStart)
1097 pXFFrame = new XFFrame();
1099 else
1101 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
1104 m_pFrame->Parse(pXFFrame, nStart);
1106 //add child frame into group
1107 LwpVirtualLayout* pLayout = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
1108 while(pLayout)
1110 pLayout->XFConvert(pXFFrame);
1111 pLayout = static_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
1114 pCont ->Add(pXFFrame);
1118 LwpGroupFrame::LwpGroupFrame(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1119 :LwpContent(objHdr, pStrm)
1122 LwpGroupFrame::~LwpGroupFrame()
1125 void LwpGroupFrame::Read()
1127 LwpContent::Read();
1128 m_pObjStrm->SkipExtra();
1131 void LwpGroupFrame::RegisterStyle()
1134 void LwpGroupFrame::XFConvert(XFContentContainer* pCont)
1138 LwpDropcapLayout::LwpDropcapLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1139 : LwpFrameLayout(objHdr, pStrm)
1141 m_nChars = 1;
1142 m_nLines = 3;
1145 void LwpDropcapLayout::Read()
1147 LwpFrameLayout::Read();
1148 m_nLines = m_pObjStrm->QuickReaduInt16();
1149 m_pObjStrm->SeekRel(1);
1150 m_pObjStrm->SkipExtra();
1153 void LwpDropcapLayout::Parse(IXFStream* pOutputStream)
1155 LwpStory* pStory = static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1156 if (!pStory)
1157 return;
1158 LwpObject* pPara = pStory->GetFirstPara()->obj(VO_PARA);
1159 if(pPara)
1161 pPara->SetFoundry(m_pFoundry);
1162 pPara->Parse(pOutputStream);
1166 void LwpDropcapLayout::XFConvert(XFContentContainer* pCont)
1168 LwpStory* pStory = static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1169 if (pStory)
1171 pStory->SetFoundry(m_pFoundry);
1172 pStory->XFConvert(pCont);
1176 LwpStory* LwpDropcapLayout::GetContentStory()
1178 return static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1181 void LwpDropcapLayout::RegisterStyle(LwpFoundry* pFoundry)
1183 LwpStory* pStory = GetContentStory();
1184 if (pStory)
1186 pStory->SetDropcapFlag(sal_True);
1187 pStory->SetFoundry(pFoundry);
1188 LwpPara* pPara = static_cast<LwpPara*>(pStory->GetFirstPara()->obj());
1189 while(pPara)
1191 pPara->SetFoundry(pFoundry);
1192 pPara->RegisterStyle();
1193 pPara = static_cast<LwpPara*>(pPara->GetNext()->obj());
1199 * @descr do nothing
1202 void LwpDropcapLayout::RegisterStyle()
1206 LwpRubyLayout::LwpRubyLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1207 : LwpFrameLayout(objHdr, pStrm)
1211 void LwpRubyLayout::Read()
1213 LwpFrameLayout::Read();
1214 m_nPlacement = m_pObjStrm->QuickReaduInt8();
1215 m_nAlignment = m_pObjStrm->QuickReaduInt8();;
1216 m_nStateFlag = m_pObjStrm->QuickReaduInt16();;
1217 m_nXOffset = m_pObjStrm->QuickReadInt32();
1218 m_nYOffset = m_pObjStrm->QuickReadInt32();
1219 m_objRubyMarker.ReadIndexed(m_pObjStrm);
1220 m_pObjStrm->SkipExtra();
1223 LwpRubyMarker* LwpRubyLayout::GetMarker()
1225 return static_cast<LwpRubyMarker*>(m_objRubyMarker.obj(VO_RUBYMARKER));
1228 LwpStory* LwpRubyLayout::GetContentStory()
1230 return static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1233 void LwpRubyLayout::ConvertContentText()
1235 LwpStory* pStory = GetContentStory();
1236 LwpRubyMarker* pMarker = GetMarker();
1237 if (pStory && pMarker)
1238 pMarker->SetRubyText(pStory->GetContentText(sal_True));
1241 void LwpRubyLayout::RegisterStyle()
1243 LwpRubyMarker* pMarker = GetMarker();
1245 XFRubyStyle* pRubyStyle = new XFRubyStyle;
1247 enumXFRubyPosition eType = enumXFRubyLeft;
1248 if (m_nAlignment == LEFT)
1250 eType = enumXFRubyLeft;
1252 else if(m_nAlignment == RIGHT)
1254 eType = enumXFRubyRight;
1256 else if(m_nAlignment == CENTER)
1258 eType = enumXFRubyCenter;
1260 pRubyStyle->SetAlignment(eType);
1262 eType = enumXFRubyTop;
1263 if (m_nPlacement == TOP)
1265 eType = enumXFRubyTop;
1267 else if(m_nPlacement == BOTTOM)
1269 eType = enumXFRubyBottom;
1271 pRubyStyle->SetPosition(eType);
1273 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1274 OUString rubyStyle = pXFStyleManager->AddStyle(pRubyStyle)->GetStyleName();
1275 pMarker->SetRubyStyleName(rubyStyle);
1277 LwpStory* pStory = GetContentStory();
1278 pStory->SetFoundry(m_pFoundry);
1279 OUString textStyle = pStory->RegisterFirstFribStyle();
1280 pMarker->SetTextStyleName(textStyle);