fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / lotuswordpro / source / filter / lwpframelayout.cxx
blob7b7f2caad55c8973ce3251ec21a119f68833330a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /*************************************************************************
57 * @file
58 * the class for VO_FrameLayout
59 ************************************************************************/
60 /*************************************************************************
61 * Change History
62 Mar 2005 Created
63 ************************************************************************/
64 #include "lwpframelayout.hxx"
65 #include "lwppara.hxx"
66 #include "xfilter/xfstylemanager.hxx"
67 #include "xfilter/xfparagraph.hxx"
68 #include "xfilter/xffloatframe.hxx"
69 #include "xfilter/xfrubystyle.hxx"
70 #include "lwppagelayout.hxx"
71 #include "lwpoleobject.hxx"
72 #include "lwptablelayout.hxx"
73 #include "lwpgrfobj.hxx"
74 #include "lwpglobalmgr.hxx"
76 LwpFrame::LwpFrame(LwpPlacableLayout* pLayout):m_pLayout(pLayout)
80 LwpFrame::~LwpFrame()
83 /**
84 * @descr: parse frame
85 * @param: register frame style
86 * @param: pFrameStyle - Frame Style object
89 void LwpFrame::RegisterStyle(XFFrameStyle* pFrameStyle)
91 ApplyWrapType(pFrameStyle);
92 ApplyMargins(pFrameStyle);
93 ApplyPadding(pFrameStyle);
94 ApplyBorders(pFrameStyle);
95 ApplyColumns(pFrameStyle);
96 ApplyShadow(pFrameStyle);
97 ApplyBackGround(pFrameStyle);
98 ApplyWatermark(pFrameStyle);
99 // ApplyBackColor(pFrameStyle);
100 ApplyProtect(pFrameStyle);
101 ApplyTextDir(pFrameStyle);
102 ApplyPosType(pFrameStyle);
104 pFrameStyle->SetStyleName(m_pLayout->GetName()->str());
105 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
106 m_StyleName = pXFStyleManager->AddStyle(pFrameStyle)->GetStyleName();
107 m_pLayout->SetStyleName(m_StyleName);
110 * @descr: parse frame and set frame properties
111 * @param: pXFFrame - XFFrame object
112 * @param: nPageNo - the page number that the frame anchors
115 void LwpFrame::Parse(XFFrame* pXFFrame, sal_Int32 nPageNo)
117 //set the frame style name
118 pXFFrame->SetStyleName(m_StyleName);
120 //SetAnchorType and position,if it's page anchor,set the page number.
121 ParseAnchorType(pXFFrame);
122 if(nPageNo>0)
124 pXFFrame->SetAnchorPage(nPageNo);
127 //Set frame Name
128 OUString aFrameName = m_pLayout->GetName()->str();
129 if(!aFrameName.isEmpty())
131 //cause the bug of SODC, the linkframe name can not be "Frame1", so I change the frame name
132 /*if(aFrameName.equals(A2OUSTR("Frame1")))
134 aFrameName = A2OUSTR("Frame1_COPY");
136 pXFFrame->SetName(aFrameName);*/
137 pXFFrame->SetName(m_StyleName);
140 LwpLayoutGeometry* pLayoutGeo = m_pLayout->GetGeometry();
141 //Set frame Width and height
142 if(pLayoutGeo)
144 double fWidth = m_pLayout->GetWidth();
145 double fHeight = m_pLayout->GetHeight();
147 pXFFrame->SetWidth( fWidth );
148 pXFFrame->SetHeight( fHeight );
150 //Get content obj;
151 /*LwpObject* pObj =*/ m_pLayout->GetContent()->obj();
152 if(m_pLayout->IsGroupHead()&&(m_pLayout->IsMinimumHeight()))
154 //process grouplayout height. there is problems now
155 pXFFrame->SetHeight( fHeight );
158 else if(m_pLayout->IsFitGraphic() && pObj && pObj->GetTag() == VO_GRAPHIC)
160 //If is graphic, get original size and set it;
161 LwpGraphicObject* pGrpObj = static_cast<LwpGraphicObject*>(pObj);
162 long nHeight =0, nWidth =0;
163 pGrpObj->GetGrafOrgSize(nWidth, nHeight);
164 //add margins to the width and height;
165 fWidth = (double)nWidth/TWIPS_PER_CM + m_pLayout->GetMarginsValue(MARGIN_LEFT) + m_pLayout->GetMarginsValue(MARGIN_RIGHT);
166 fHeight = (double)nHeight/TWIPS_PER_CM + m_pLayout->GetMarginsValue(MARGIN_TOP) + m_pLayout->GetMarginsValue(MARGIN_BOTTOM);
167 pXFFrame->SetWidth(fWidth);
168 pXFFrame->SetHeight(fHeight);
171 else if(m_pLayout->IsAutoGrow())
173 pXFFrame->SetMinHeight( fHeight );
177 if(m_pLayout->IsFrame())
179 //Set frame link. Only frame layout has this feature
180 LwpFrameLayout* pLayout= static_cast<LwpFrameLayout*>(m_pLayout);
181 pXFFrame->SetNextLink(pLayout->GetNextLinkName());
186 * @descr: parse frame relative to page, frame or cell
187 * @param: pCont - content container which contains the frame
190 void LwpFrame::XFConvert(XFContentContainer* pCont)
192 //parse the frame which anchor to page
193 LwpVirtualLayout* pParent = m_pLayout->GetParentLayout();
194 if(pParent->IsPage()&& pParent->GetParentLayout()->IsPage())
196 //for mirror page, problems exist if the parent layout is header or footer layout,
197 pParent = pParent->GetParentLayout();
199 if(m_pLayout->IsAnchorPage()&& pParent->IsPage())
201 //get parent layout
202 if(m_pLayout->IsUseOnPage())
204 sal_Int32 nPageNo = pParent->GetPageNumber(m_pLayout->GetUsePage());
205 if(nPageNo>0)
206 m_pLayout->XFConvertFrame(pCont, nPageNo);
208 else if(m_pLayout->IsUseOnAllPages())
210 sal_Int32 nFirst = pParent->GetPageNumber(FIRST_LAYOUTPAGENO);
211 sal_Int32 nLast = pParent->GetPageNumber(LAST_LAYOUTPAGENO);
212 if(nLast > 0)
213 m_pLayout->XFConvertFrame(pCont, nFirst, nLast, sal_True);
216 else if(m_pLayout->IsUseOnAllOddPages()||m_pLayout->IsUseOnAllEvenPages())
218 sal_Int32 nFirst = pParent->GetPageNumber(FIRST_LAYOUTPAGENO);
219 sal_Int32 nLast = pParent->GetPageNumber(LAST_LAYOUTPAGENO);
220 if(nLast > 0)
222 sal_uInt16 first = static_cast<sal_uInt16>(nFirst);
223 if((m_pLayout->IsUseOnAllOddPages() && !LwpTools::IsOddNumber(first))
224 || (m_pLayout->IsUseOnAllEvenPages() && !LwpTools::IsEvenNumber(first)))
225 nFirst++;
226 if(nFirst <= nLast)
228 m_pLayout->XFConvertFrame(pCont, nFirst, nLast, sal_False);
233 else
235 m_pLayout->XFConvertFrame(pCont);
240 * @descr: set frame wrap type style
241 * @param: pFrameStyle - Frame Style object
244 void LwpFrame::ApplyWrapType(XFFrameStyle *pFrameStyle)
246 enumXFWrap eWrap = enumXFWrapNone;
247 switch(m_pLayout->GetWrapType())
249 case LwpPlacableLayout::LAY_WRAP_AROUND: //fall throught
250 case LwpPlacableLayout::LAY_WRAP_IRREG_BIGGEST:
252 //In SODC, if Optimal wrap type is used and the distance between the frame object
253 //and page margins is less than 2cm, the text is not wraped. While there is no this feature in Word Pro
254 //So the optimal wrap type is translated to left side or right side wrap type according to the distance
255 //between the frame object and page margins
257 eWrap = enumXFWrapBest;
258 LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
259 if(pParent)
261 if(IsLeftWider())
262 eWrap = enumXFWrapLeft;
263 else
264 eWrap = enumXFWrapRight;
266 break;
268 case LwpPlacableLayout::LAY_NO_WRAP_BESIDE:
270 eWrap = enumXFWrapNone;
271 break;
273 case LwpPlacableLayout::LAY_NO_WRAP_AROUND:
275 eWrap = enumXFWrapRunThrough;
276 if(!m_pLayout->GetBackColor() && !m_pLayout->GetWaterMarkLayout())
278 //pFrameStyle->SetBackGround(sal_True);
279 XFColor aXFColor(0xffffff); //white color
280 pFrameStyle->SetBackColor(aXFColor);
281 pFrameStyle->SetTransparency(100); //transparency
283 break;
285 case LwpPlacableLayout::LAY_WRAP_LEFT: //fall throught
286 case LwpPlacableLayout::LAY_WRAP_IRREG_LEFT:
288 eWrap = enumXFWrapLeft;
289 break;
291 case LwpPlacableLayout::LAY_WRAP_RIGHT: //fall throught
292 case LwpPlacableLayout::LAY_WRAP_IRREG_RIGHT:
294 eWrap = enumXFWrapRight;
295 break;
297 case LwpPlacableLayout::LAY_WRAP_BOTH: //fall throught
298 case LwpPlacableLayout::LAY_WRAP_IRREG_BOTH:
300 eWrap = enumXFWrapParallel;
301 break;
303 default:
304 break;
307 //If it is the type of with para above, wrap type is enumXFWrapNone
308 if(m_pLayout->GetRelativeType()==LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE)
310 eWrap = enumXFWrapNone;
313 pFrameStyle->SetWrapType(eWrap);
316 * @descr: set frame margins style
317 * @param: pFrameStyle - Frame Style object
320 void LwpFrame::ApplyMargins(XFFrameStyle *pFrameStyle)
322 double fLeft = m_pLayout->GetExtMarginsValue(MARGIN_LEFT);
323 double fRight = m_pLayout->GetExtMarginsValue(MARGIN_RIGHT);
324 double fTop = m_pLayout->GetExtMarginsValue(MARGIN_TOP);
325 double fBottom = m_pLayout->GetExtMarginsValue(MARGIN_BOTTOM);
326 pFrameStyle->SetMargins(fLeft,fRight,fTop,fBottom);
329 * @descr: set padding border style
330 * @param: pFrameStyle - Frame Style object
333 void LwpFrame::ApplyPadding(XFFrameStyle *pFrameStyle)
335 double fLeft = m_pLayout->GetMarginsValue(MARGIN_LEFT);
336 double fRight = m_pLayout->GetMarginsValue(MARGIN_RIGHT);
337 double fTop = m_pLayout->GetMarginsValue(MARGIN_TOP);
338 double fBottom = m_pLayout->GetMarginsValue(MARGIN_BOTTOM);
339 pFrameStyle->SetPadding(fLeft,fRight,fTop,fBottom);
342 * @descr: set frame border style
343 * @param: pFrameStyle - Frame Style object
346 void LwpFrame::ApplyBorders(XFFrameStyle *pFrameStyle)
348 XFBorders* pBordres = m_pLayout->GetXFBorders();
349 if(pBordres)
351 pFrameStyle->SetBorders(pBordres);
355 * @descr: set frame colums style
356 * @param: pFrameStyle - Frame Style object
359 void LwpFrame::ApplyColumns(XFFrameStyle *pFrameStyle)
361 XFColumns* pColumns = m_pLayout->GetXFColumns();
362 if(pColumns)
364 pFrameStyle->SetColumns(pColumns);
368 * @descr: set frame shadow style
369 * @param: pFrameStyle - Frame Style object
372 void LwpFrame::ApplyShadow(XFFrameStyle* pFrameStyle)
374 XFShadow* pXFShadow = m_pLayout->GetXFShadow();
375 if(pXFShadow)
377 pFrameStyle->SetShadow(pXFShadow);
381 * @descr: set frame back color style
382 * @param: pFrameStyle - Frame Style object
385 void LwpFrame::ApplyBackColor(XFFrameStyle* pFrameStyle)
387 LwpColor* pColor = m_pLayout->GetBackColor();
388 if(pColor)
390 XFColor aXFColor(pColor->To24Color());
391 pFrameStyle->SetBackColor(aXFColor);
395 * @descr: set frame protect style
396 * @param: pFrameStyle - Frame Style object
399 void LwpFrame::ApplyProtect(XFFrameStyle* pFrameStyle)
401 if(m_pLayout->IsProtected())
403 pFrameStyle->SetProtect(sal_True,sal_True,sal_True);
407 * @descr: set frame text direction style
408 * @param: pFrameStyle - Frame Style object
411 void LwpFrame::ApplyTextDir(XFFrameStyle* pFrameStyle)
413 pFrameStyle->SetTextDir(m_pLayout->GetTextDirection());
416 * @descr: set frame position type style
417 * @param: pFrameStyle - Frame Style object
420 void LwpFrame::ApplyPosType(XFFrameStyle* pFrameStyle)
422 enumXFFrameXPos eXPos = enumXFFrameXPosCenter;
423 enumXFFrameXRel eXRel = enumXFFrameXRelPara;
424 enumXFFrameYPos eYPos = enumXFFrameYPosMiddle;
425 enumXFFrameYRel eYRel = enumXFFrameYRelPara;
426 sal_uInt8 nType = m_pLayout->GetRelativeType();
427 switch(nType)
429 case LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE://fall throught
430 case LwpLayoutRelativityGuts::LAY_CONTENT_RELATIVE:
432 //anchor to page, frame and cell
433 eXPos = enumXFFrameXPosFromLeft;
434 eXRel = enumXFFrameXRelPage;
435 //set vertical position
436 if(m_pLayout->IsAnchorPage())//in page
438 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
439 if(pContainer && (pContainer->IsHeader() || pContainer->IsFooter()))
441 //Only anchor to para, the frame can display in header and footer of each page
442 eYPos = enumXFFrameYPosFromTop; //from top
443 eYRel = enumXFFrameYRelPara; //from margin
445 else
447 eYPos = enumXFFrameYPosFromTop;
448 eYRel = enumXFFrameYRelPage;
451 if(m_pLayout->IsAnchorFrame()) //in frame
453 eYPos = enumXFFrameYPosFromTop;
454 eYRel = enumXFFrameYRelPage;
456 if(m_pLayout->IsAnchorCell())
458 //SODC has no this type, simulate this feature
459 eYPos = enumXFFrameYPosFromTop; //from top
460 eYRel = enumXFFrameYRelPara; //from margin
462 break;
464 case LwpLayoutRelativityGuts::LAY_PARA_RELATIVE: //same page as text
466 eXPos = enumXFFrameXPosFromLeft;
467 eXRel = enumXFFrameXRelPage;
468 eYPos = enumXFFrameYPosBelow; //below
469 eYRel = enumXFFrameYRelChar; //from char
470 //set vertical position
471 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
472 if(pContainer && pContainer->IsPage())//in page
474 //eYPos = enumXFFrameYPosFromTop;
475 //eYRel = enumXFFrameYRelPage;
476 eYPos = enumXFFrameYPosBelow;
477 eYRel = enumXFFrameYRelChar;
479 else if(pContainer && pContainer->IsFrame()) //in frame
481 eYPos = enumXFFrameYPosFromTop;
482 eYRel = enumXFFrameYRelPage;
484 else
486 eYPos = enumXFFrameYPosFromTop; //from top
487 eYRel = enumXFFrameYRelPara; //from margin
489 break;
491 case LwpLayoutRelativityGuts::LAY_INLINE: //in text
493 eXPos = enumXFFrameXPosFromLeft; //need not be set
494 eXRel = enumXFFrameXRelParaContent; //need not be set
495 eYPos = enumXFFrameYPosTop; //should be from top
496 eYRel = enumXFFrameYRelBaseLine;
497 sal_Int32 nOffset = m_pLayout->GetBaseLineOffset();
498 if(nOffset>0)
500 eYPos = enumXFFrameYPosFromTop;
502 break;
504 case LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE: //with para above
506 eXPos = enumXFFrameXPosFromLeft;
507 eXRel = enumXFFrameXRelParaContent;
508 //eYPos = enumXFFrameYPosTop;
509 eYPos = enumXFFrameYPosBottom;
510 eYRel = enumXFFrameYRelParaContent;
511 break;
513 case LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL: //in text - vertical
515 eXPos = enumXFFrameXPosFromLeft;
516 eXRel = enumXFFrameXRelPage;
517 eYPos = enumXFFrameYPosFromTop; //should be below position
518 eYRel = enumXFFrameYRelChar;
519 break;
521 default:
522 break;
525 pFrameStyle->SetXPosType(eXPos,eXRel);
526 pFrameStyle->SetYPosType(eYPos,eYRel);
529 * @descr: set frame watermark style
530 * @param: pFrameStyle - Frame Style object
533 void LwpFrame::ApplyWatermark(XFFrameStyle *pFrameStyle)
535 XFBGImage* pBGImage = m_pLayout->GetXFBGImage();
536 if(pBGImage)
538 pFrameStyle->SetBackImage(pBGImage);
539 //set watermark transparent
540 LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*>(m_pLayout->GetWaterMarkLayout());
541 LwpBackgroundStuff* pBackgroundStuff = pLay->GetBackgroundStuff();
542 if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
544 pFrameStyle->SetTransparency(100);
550 * @short Apply pattern fill to frame style
551 * @param pFrameStyle - pointer of XFFrameStyle
552 * @return
554 void LwpFrame::ApplyPatternFill(XFFrameStyle* pFrameStyle)
556 XFBGImage* pXFBGImage = m_pLayout->GetFillPattern();
557 if (pXFBGImage)
559 pFrameStyle->SetBackImage(pXFBGImage);
564 * @short Apply background to frame style
565 * @param pFrameStyle - pointer of XFFrameStyle
566 * @return
568 void LwpFrame::ApplyBackGround(XFFrameStyle* pFrameStyle)
570 if (!m_pLayout)
572 return;
575 if (m_pLayout->IsPatternFill())
577 ApplyPatternFill(pFrameStyle);
579 else
581 ApplyBackColor(pFrameStyle);
586 * @descr: set frame size, anchor type, anchored page number
587 * @param: pXFFrame - XFFrame object
590 void LwpFrame::ParseAnchorType(XFFrame *pXFFrame)
592 //set position
593 double fXOffset = 0;
594 double fYOffset = 0;
595 //page number
596 sal_uInt16 nPageNum = 0;
597 //set anchor type
598 enumXFAnchor eAnchor = enumXFAnchorNone;
600 LwpLayoutGeometry* pLayoutGeo = m_pLayout->GetGeometry();
601 if(pLayoutGeo)
603 LwpPoint aPoint = pLayoutGeo->GetOrigin();
604 fXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
605 fYOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetY());
607 //set anchor type
608 eAnchor = enumXFAnchorNone;
609 sal_uInt8 nType = m_pLayout->GetRelativeType();
610 switch(nType)
612 case LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE://fall throught
613 case LwpLayoutRelativityGuts::LAY_CONTENT_RELATIVE:
615 //anchor to page, frame and cell
616 if(m_pLayout->IsAnchorPage())//in page
618 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
619 if(pContainer && (pContainer->IsHeader() || pContainer->IsFooter()))
621 eAnchor = enumXFAnchorPara;
622 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
624 else
625 eAnchor = enumXFAnchorPage;
627 if(m_pLayout->IsAnchorFrame()) //in frame
629 eAnchor = enumXFAnchorFrame;
631 if(m_pLayout->IsAnchorCell()) //in cell
633 //eAnchor = enumXFAnchorChar;
634 eAnchor = enumXFAnchorPara;
635 LwpMiddleLayout* pContainer = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
636 if(pContainer)
638 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
641 break;
643 case LwpLayoutRelativityGuts::LAY_PARA_RELATIVE: //same page as text
645 eAnchor = enumXFAnchorChar;
646 LwpVirtualLayout* pContainer = m_pLayout->GetContainerLayout();
647 if(pContainer && pContainer->IsPage())//in page
649 //eAnchor = enumXFAnchorPage;
650 eAnchor = enumXFAnchorChar;// to character
652 else if(pContainer && pContainer->IsFrame()) //in frame
654 eAnchor = enumXFAnchorFrame;
656 else if(pContainer && pContainer->IsCell()) //in cell
658 //eAnchor = enumXFAnchorChar;
659 eAnchor = enumXFAnchorPara;
660 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
662 else if(pContainer && (pContainer->IsHeader() || pContainer->IsFooter()))//in header or footer
664 eAnchor = enumXFAnchorPara;
665 fYOffset -= pContainer->GetMarginsValue(MARGIN_TOP);
667 break;
669 case LwpLayoutRelativityGuts::LAY_INLINE: //in text
671 eAnchor = enumXFAnchorAsChar;
672 sal_Int32 nOffset = m_pLayout->GetBaseLineOffset();
673 if(nOffset>0 && pLayoutGeo)
675 //experiential value
676 fYOffset =-(m_pLayout->GetGeometryHeight()+2*m_pLayout->GetExtMarginsValue(MARGIN_BOTTOM)-LwpTools::ConvertFromUnitsToMetric(nOffset));
678 break;
680 case LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE: //with para above
682 eAnchor = enumXFAnchorPara;
683 break;
685 case LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL: //in text - vertical
687 eAnchor = enumXFAnchorChar;
688 //set vertical position
689 double offset = 0;
691 //because of the different feature between Word Pro and SODC, I simulate the vertical base offset
692 //between anchor and frame orgin using the font height.
693 //LwpPara* pPara = static_cast<LwpPara*>(m_pLayout->GetPosition()->obj());
694 XFFont* pFont = m_pLayout->GetFont();
695 if(pFont)
697 offset = (double)(pFont->GetFontSize())*CM_PER_INCH/POINTS_PER_INCH;
699 fYOffset = offset-fYOffset;
700 break;
702 default:
703 break;
706 pXFFrame->SetX(fXOffset);
707 pXFFrame->SetY(fYOffset);
708 pXFFrame->SetAnchorPage(nPageNum);
709 pXFFrame->SetAnchorType(eAnchor);
713 * @descr Calculate the distance between the frame object and the page margins.
714 * And determine which side(left or right) is wider
716 sal_Bool LwpFrame::IsLeftWider()
718 //LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(m_pLayout->GetContainerLayout());
719 LwpVirtualLayout* pParent = static_cast<LwpVirtualLayout*>(m_pLayout->GetContainerLayout());
720 if(pParent)
722 LwpPoint aPoint = m_pLayout->GetOrigin();
723 double fXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
724 double fWidth = m_pLayout->GetWidth();
725 double fWrapLeft = m_pLayout->GetExtMarginsValue(MARGIN_LEFT);
726 double fWrapRight = m_pLayout->GetExtMarginsValue(MARGIN_RIGHT);
728 //LwpPoint aParentPoint = pParent->GetOrigin();
729 //double fParentXOffset = LwpTools::ConvertFromUnitsToMetric(aParentPoint.GetX());
730 double fParentWidth = pParent->GetWidth();
731 if(pParent->IsCell())
733 //Get actual width of this cell layout
734 fParentWidth = static_cast<LwpCellLayout*>(pParent)->GetActualWidth();
736 double fParentMarginLeft = pParent->GetMarginsValue(MARGIN_LEFT);
737 double fParentMarginRight = pParent->GetMarginsValue(MARGIN_RIGHT);
739 double fLeft = fXOffset - fWrapLeft -fParentMarginLeft;
740 double fRight = fParentWidth - fParentMarginRight -(fXOffset + fWidth + fWrapRight);
741 if(fLeft > fRight)
742 return sal_True;
744 return sal_False;
747 LwpFrameLink::LwpFrameLink()
750 LwpFrameLink::~LwpFrameLink()
754 * @descr frame link information
757 void LwpFrameLink::Read(LwpObjectStream* pStrm)
759 m_PreviousLayout.ReadIndexed(pStrm);
760 m_NextLayout.ReadIndexed(pStrm);
761 pStrm->SkipExtra();
764 LwpFrameLayout::LwpFrameLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
765 : LwpPlacableLayout(objHdr, pStrm), m_pFrame(NULL)
769 LwpFrameLayout::~LwpFrameLayout()
771 delete m_pFrame;
775 * @descr read frame layout object
778 void LwpFrameLayout::Read()
780 LwpPlacableLayout::Read();
781 if(LwpFileHeader::m_nFileRevision >= 0x000B)
783 if(m_pObjStrm->QuickReaduInt16())
785 m_Link.Read(m_pObjStrm);
788 m_pObjStrm->SkipExtra();
792 * @descr create a xfframe and add into content container
793 * @param: pCont - content container that contains the frame.
796 void LwpFrameLayout::XFConvert(XFContentContainer* pCont)
798 if(m_pFrame)
800 //parse the frame which anchor to paragraph
801 if(IsRelativeAnchored())
803 XFConvertFrame(pCont);
805 else
807 m_pFrame->XFConvert(pCont);
813 * @descr create a xfframe and add into content container, called by XFConvert
814 * @param: pCont - content container that contains the frame.
815 * @param: nPageNo - the page number that the frame anchors
818 void LwpFrameLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd, sal_Bool bAll )
820 if(m_pFrame)
822 XFFrame* pXFFrame = NULL;
823 if(nEnd < nStart)
825 pXFFrame = new XFFrame();
827 else
829 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
832 m_pFrame->Parse(pXFFrame, nStart);
833 //if it is a link frame, parse contents only once
834 if(!HasPreviousLinkLayout())
836 LwpObject* content = m_Content.obj();
837 if (content)
839 content->XFConvert(pXFFrame);
840 //set frame size according to ole size
841 ApplyGraphicSize(pXFFrame);
844 pCont ->Add(pXFFrame);
848 * @descr register frame style
851 void LwpFrameLayout::RegisterStyle()
853 //if it is for water mark, don't register style
854 if (IsForWaterMark())
855 return;
857 if (m_pFrame)
858 return;
860 //register frame style
861 XFFrameStyle* pFrameStyle = new XFFrameStyle();
862 m_pFrame = new LwpFrame(this);
863 m_pFrame->RegisterStyle(pFrameStyle);
865 //register content style
866 LwpObject* content = m_Content.obj();
867 if (content)
869 content->SetFoundry(m_pFoundry);
870 content->RegisterStyle();
873 //register child frame style
874 RegisterChildStyle();
878 * @descr get the name of the frame that current frame links
881 OUString LwpFrameLayout::GetNextLinkName()
883 OUString aName;
884 LwpObjectID* pObjectID = m_Link.GetNextLayout();
885 if(!pObjectID->IsNull())
887 LwpLayout* pLayout = dynamic_cast<LwpLayout*>(pObjectID->obj());
888 if (pLayout)
890 LwpAtomHolder *pHolder = pLayout->GetName();
891 if (pHolder)
892 aName = pHolder->str();
893 //for division name confict
894 if(!pLayout->GetStyleName().isEmpty())
895 aName = pLayout->GetStyleName();
898 return aName;
901 * @descr whether current frame is linked by other frame
904 sal_Bool LwpFrameLayout::HasPreviousLinkLayout()
906 LwpObjectID* pObjectID = m_Link.GetPreviousLayout();
907 if(pObjectID->IsNull())
908 return sal_False;
909 return sal_True;
912 * @descr whether current frame is for water mark. Problem maybe exsits by this method, must be tracking
915 sal_Bool LwpFrameLayout::IsForWaterMark()
917 if(m_nBuoyancy >=LAY_BUOYLAYER)
919 if(!m_Content.IsNull() && (m_Content.obj()->GetTag()==VO_GRAPHIC) )
921 return sal_True;
924 return sal_False;
928 * @descr Get frame width
931 double LwpFrameLayout::GetWidth()
933 double fWidth = LwpMiddleLayout::GetWidth();
934 if(IsInlineToMargin() && IsAutoGrowWidth())
936 //for text field entry when choosing maximize field length
937 fWidth = GetMaxWidth();
939 return fWidth;
943 * @descr Get frame width when the text field chooses maximize field length
946 double LwpFrameLayout::GetMaxWidth()
948 double fActualWidth = 0;
949 LwpMiddleLayout* pParent = static_cast<LwpMiddleLayout*>(GetContainerLayout());
950 if(pParent)
952 LwpPoint aPoint = GetOrigin();
953 double fXOffset = LwpTools::ConvertFromUnitsToMetric(aPoint.GetX());
954 double fWrapRight = GetExtMarginsValue(MARGIN_RIGHT);
956 //Get parent layout width
957 double fParentWidth = pParent->GetWidth();
958 if(pParent->IsCell())
960 //Get actual width of this cell layout
961 fParentWidth = static_cast<LwpCellLayout*>(pParent)->GetActualWidth();
964 double fParentMarginRight = 0;
965 sal_uInt8 nType = GetRelativeType();
966 if(nType == LwpLayoutRelativityGuts::LAY_INLINE
967 || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
969 fParentMarginRight = pParent->GetMarginsValue(MARGIN_RIGHT);
972 fActualWidth = fParentWidth - fXOffset - fParentMarginRight - fWrapRight;
975 return fActualWidth;
979 * @descr Set frame size according to graphic size
982 void LwpFrameLayout::ApplyGraphicSize(XFFrame * pXFFrame)
984 LwpObject* content = m_Content.obj();
985 if(content && (content->GetTag() == VO_GRAPHIC
986 || content->GetTag() == VO_OLEOBJECT ))
988 LwpGraphicOleObject* pGraOle = static_cast<LwpGraphicOleObject*>(content);
989 //Get frame geometry size
990 double fWidth = 0;
991 double fHeight = 0;
992 pGraOle->GetGrafScaledSize(fWidth, fHeight);
993 if( IsFitGraphic())
995 //graphic scaled sze
996 fWidth += GetMarginsValue(MARGIN_LEFT) + GetMarginsValue(MARGIN_RIGHT);
997 fHeight += GetMarginsValue(MARGIN_TOP) + GetMarginsValue(MARGIN_BOTTOM);
999 else if(IsAutoGrowDown() || IsAutoGrowUp())
1001 fWidth = GetWidth();
1002 fHeight += GetMarginsValue(MARGIN_TOP) + GetMarginsValue(MARGIN_BOTTOM);
1004 else if( IsAutoGrowLeft() || IsAutoGrowRight())
1006 fHeight = GetHeight();
1007 fWidth += GetMarginsValue(MARGIN_LEFT) + GetMarginsValue(MARGIN_RIGHT);
1009 else
1011 fWidth = GetWidth();
1012 fHeight = GetHeight();
1014 pXFFrame->SetWidth(fWidth);
1015 pXFFrame->SetHeight(fHeight);
1019 LwpGroupLayout::LwpGroupLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1020 : LwpPlacableLayout(objHdr, pStrm)
1021 , m_pFrame(NULL)
1026 LwpGroupLayout::~LwpGroupLayout()
1028 delete m_pFrame;
1031 * @descr read group layout object
1034 void LwpGroupLayout::Read()
1036 LwpPlacableLayout::Read();
1037 m_pObjStrm->SkipExtra();
1040 * @descr register group frame style
1043 void LwpGroupLayout::RegisterStyle()
1045 if (m_pFrame)
1046 return;
1048 //register frame style
1049 XFFrameStyle* pFrameStyle = new XFFrameStyle();
1050 m_pFrame = new LwpFrame(this);
1051 m_pFrame->RegisterStyle(pFrameStyle);
1053 //register child frame style
1054 RegisterChildStyle();
1057 * @descr create a xfframe and add into content container
1058 * @param: pCont - content container that contains the frame.
1061 void LwpGroupLayout::XFConvert(XFContentContainer *pCont)
1063 if(m_pFrame)
1065 //parse the frame which anchor to paragraph
1066 if(IsRelativeAnchored())
1068 XFConvertFrame(pCont);
1070 else
1072 m_pFrame->XFConvert(pCont);
1078 * @descr create a xfframe and add into content container, called by XFConvert
1079 * @param: pCont - content container that contains the frame.
1080 * @param: nPageNo - the page number that the frame anchors
1083 void LwpGroupLayout::XFConvertFrame(XFContentContainer* pCont, sal_Int32 nStart , sal_Int32 nEnd, sal_Bool bAll)
1085 if(m_pFrame)
1087 XFFrame* pXFFrame = NULL;
1088 if(nEnd < nStart)
1090 pXFFrame = new XFFrame();
1092 else
1094 pXFFrame = new XFFloatFrame(nStart, nEnd, bAll);
1097 m_pFrame->Parse(pXFFrame, nStart);
1099 //add child frame into group
1100 LwpVirtualLayout* pLayout = static_cast<LwpVirtualLayout*>(GetChildHead()->obj());
1101 while(pLayout)
1103 pLayout->XFConvert(pXFFrame);
1104 pLayout = static_cast<LwpVirtualLayout*>(pLayout->GetNext()->obj());
1107 pCont ->Add(pXFFrame);
1111 LwpGroupFrame::LwpGroupFrame(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1112 :LwpContent(objHdr, pStrm)
1115 LwpGroupFrame::~LwpGroupFrame()
1118 void LwpGroupFrame::Read()
1120 LwpContent::Read();
1121 m_pObjStrm->SkipExtra();
1125 void LwpGroupFrame::RegisterStyle()
1129 void LwpGroupFrame::XFConvert(XFContentContainer* /*pCont*/)
1133 LwpDropcapLayout::LwpDropcapLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1134 : LwpFrameLayout(objHdr, pStrm)
1136 m_nChars = 1;
1137 m_nLines = 3;
1140 void LwpDropcapLayout::Read()
1142 LwpFrameLayout::Read();
1143 m_nLines = m_pObjStrm->QuickReaduInt16();
1144 m_pObjStrm->SeekRel(1);
1145 m_pObjStrm->SkipExtra();
1148 void LwpDropcapLayout::Parse(IXFStream* pOutputStream)
1150 LwpStory* pStory = static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1151 if (!pStory)
1152 return;
1153 LwpObject* pPara = pStory->GetFirstPara()->obj(VO_PARA);
1154 if(pPara)
1156 pPara->SetFoundry(m_pFoundry);
1157 pPara->Parse(pOutputStream);
1161 void LwpDropcapLayout::XFConvert(XFContentContainer* pCont)
1163 LwpStory* pStory = static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1164 if (pStory)
1166 pStory->SetFoundry(m_pFoundry);
1167 pStory->XFConvert(pCont);
1171 LwpStory* LwpDropcapLayout::GetContentStory()
1173 return static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1176 void LwpDropcapLayout::RegisterStyle(LwpFoundry* pFoundry)
1178 LwpStory* pStory = GetContentStory();
1179 if (pStory)
1181 pStory->SetDropcapFlag(sal_True);
1182 pStory->SetFoundry(pFoundry);
1183 LwpPara* pPara = static_cast<LwpPara*>(pStory->GetFirstPara()->obj());
1184 while(pPara)
1186 pPara->SetFoundry(pFoundry);
1187 pPara->RegisterStyle();
1188 pPara = static_cast<LwpPara*>(pPara->GetNext()->obj());
1194 * @descr do nothing
1197 void LwpDropcapLayout::RegisterStyle()
1201 LwpRubyLayout::LwpRubyLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
1202 : LwpFrameLayout(objHdr, pStrm)
1206 void LwpRubyLayout::Read()
1208 LwpFrameLayout::Read();
1209 m_nPlacement = m_pObjStrm->QuickReaduInt8();
1210 m_nAlignment = m_pObjStrm->QuickReaduInt8();;
1211 m_nStateFlag = m_pObjStrm->QuickReaduInt16();;
1212 m_nXOffset = m_pObjStrm->QuickReadInt32();
1213 m_nYOffset = m_pObjStrm->QuickReadInt32();
1214 m_objRubyMarker.ReadIndexed(m_pObjStrm);
1215 m_pObjStrm->SkipExtra();
1218 LwpRubyMarker* LwpRubyLayout::GetMarker()
1220 return static_cast<LwpRubyMarker*>(m_objRubyMarker.obj(VO_RUBYMARKER));
1223 LwpStory* LwpRubyLayout::GetContentStory()
1225 return static_cast<LwpStory*>(m_Content.obj(VO_STORY));
1228 void LwpRubyLayout::ConvertContentText()
1230 LwpStory* pStory = GetContentStory();
1231 LwpRubyMarker* pMarker = GetMarker();
1232 if (pStory && pMarker)
1233 pMarker->SetRubyText(pStory->GetContentText(sal_True));
1236 void LwpRubyLayout::RegisterStyle()
1238 LwpRubyMarker* pMarker = GetMarker();
1240 XFRubyStyle* pRubyStyle = new XFRubyStyle;
1242 enumXFRubyPosition eType = enumXFRubyLeft;
1243 if (m_nAlignment == LEFT)
1245 eType = enumXFRubyLeft;
1247 else if(m_nAlignment == RIGHT)
1249 eType = enumXFRubyRight;
1251 else if(m_nAlignment == CENTER)
1253 eType = enumXFRubyCenter;
1255 pRubyStyle->SetAlignment(eType);
1257 eType = enumXFRubyTop;
1258 if (m_nPlacement == TOP)
1260 eType = enumXFRubyTop;
1262 else if(m_nPlacement == BOTTOM)
1264 eType = enumXFRubyBottom;
1266 pRubyStyle->SetPosition(eType);
1268 XFStyleManager* pXFStyleManager = LwpGlobalMgr::GetInstance()->GetXFStyleManager();
1269 OUString rubyStyle = pXFStyleManager->AddStyle(pRubyStyle)->GetStyleName();
1270 pMarker->SetRubyStyleName(rubyStyle);
1272 LwpStory* pStory = GetContentStory();
1273 pStory->SetFoundry(m_pFoundry);
1274 OUString textStyle = pStory->RegisterFirstFribStyle();
1275 pMarker->SetTextStyleName(textStyle);
1278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */