LCOV - code coverage report
Current view: top level - lotuswordpro/source/filter - lwplayout.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 491 870 56.4 %
Date: 2014-11-03 Functions: 90 119 75.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*************************************************************************
       3             :  *
       4             :  *  The Contents of this file are made available subject to the terms of
       5             :  *  either of the following licenses
       6             :  *
       7             :  *         - GNU Lesser General Public License Version 2.1
       8             :  *         - Sun Industry Standards Source License Version 1.1
       9             :  *
      10             :  *  Sun Microsystems Inc., October, 2000
      11             :  *
      12             :  *  GNU Lesser General Public License Version 2.1
      13             :  *  =============================================
      14             :  *  Copyright 2000 by Sun Microsystems, Inc.
      15             :  *  901 San Antonio Road, Palo Alto, CA 94303, USA
      16             :  *
      17             :  *  This library is free software; you can redistribute it and/or
      18             :  *  modify it under the terms of the GNU Lesser General Public
      19             :  *  License version 2.1, as published by the Free Software Foundation.
      20             :  *
      21             :  *  This library is distributed in the hope that it will be useful,
      22             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      23             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      24             :  *  Lesser General Public License for more details.
      25             :  *
      26             :  *  You should have received a copy of the GNU Lesser General Public
      27             :  *  License along with this library; if not, write to the Free Software
      28             :  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
      29             :  *  MA  02111-1307  USA
      30             :  *
      31             :  *
      32             :  *  Sun Industry Standards Source License Version 1.1
      33             :  *  =================================================
      34             :  *  The contents of this file are subject to the Sun Industry Standards
      35             :  *  Source License Version 1.1 (the "License"); You may not use this file
      36             :  *  except in compliance with the License. You may obtain a copy of the
      37             :  *  License at http://www.openoffice.org/license.html.
      38             :  *
      39             :  *  Software provided under this License is provided on an "AS IS" basis,
      40             :  *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
      41             :  *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
      42             :  *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
      43             :  *  See the License for the specific provisions governing your rights and
      44             :  *  obligations concerning the Software.
      45             :  *
      46             :  *  The Initial Developer of the Original Code is: IBM Corporation
      47             :  *
      48             :  *  Copyright: 2008 by IBM Corporation
      49             :  *
      50             :  *  All Rights Reserved.
      51             :  *
      52             :  *  Contributor(s): _______________________________________
      53             :  *
      54             :  *
      55             :  ************************************************************************/
      56             : /*************************************************************************
      57             :  * @file
      58             :  *  For LWP filter architecture prototype
      59             :  ************************************************************************/
      60             : /*************************************************************************
      61             :  * Change History
      62             :  Jan 2005           Created
      63             :  Feb 2005           Process gemotry, margins
      64             :  ************************************************************************/
      65             : 
      66             : #include "lwplayout.hxx"
      67             : #include "lwpusewhen.hxx"
      68             : #include "lwptools.hxx"
      69             : #include "xfilter/xfcolumns.hxx"
      70             : #include "lwpstory.hxx"
      71             : #include "lwpparastyle.hxx"
      72             : #include "lwpholder.hxx"
      73             : #include "lwpdoc.hxx"
      74             : #include "lwppagehint.hxx"
      75             : #include "lwpdivinfo.hxx"
      76             : #include "lwpgrfobj.hxx"
      77             : #include <osl/thread.h>
      78             : 
      79         266 : LwpVirtualLayout::LwpVirtualLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
      80             :     : LwpDLNFPVList(objHdr, pStrm)
      81             :     , m_nAttributes(0)
      82             :     , m_nAttributes2(0)
      83             :     , m_nAttributes3(0)
      84             :     , m_nOverrideFlag(0)
      85             :     , m_nDirection(0)
      86         266 :     , m_nEditorID(0)
      87             : {
      88         266 : }
      89             : 
      90         266 : void LwpVirtualLayout::Read()
      91             : {
      92         266 :     LwpDLNFPVList::Read();
      93             : 
      94         266 :     LwpObjectStream* pStrm = m_pObjStrm;
      95         266 :     m_nAttributes = pStrm->QuickReaduInt32();
      96         266 :     m_nAttributes2 = pStrm->QuickReaduInt32();
      97         266 :     m_nAttributes3 = pStrm->QuickReaduInt32();
      98         266 :     m_nOverrideFlag = pStrm->QuickReaduInt32();
      99         266 :     m_nDirection = pStrm->QuickReaduInt16();
     100             : 
     101             :     //Note that two bytes is read into m_nEditorID instead of one byte.
     102         266 :     m_nEditorID = pStrm->QuickReaduInt16();
     103             : 
     104         266 :     m_NextEnumerated.ReadIndexed(pStrm);
     105         266 :     m_PreviousEnumerated.ReadIndexed(pStrm);
     106             : 
     107         266 :     pStrm->SkipExtra();
     108         266 : }
     109             : 
     110        2010 : bool LwpVirtualLayout::MarginsSameAsParent()
     111             : {
     112        2010 :     return m_nAttributes2 & STYLE2_MARGINSSAMEASPARENT ? sal_True : sal_False;
     113             : }
     114             : 
     115             : /**
     116             : * @descr:   Get column width
     117             : *
     118             : */
     119           0 : double LwpVirtualLayout::GetColWidth(sal_uInt16 /*nIndex*/)
     120             : {
     121             :     //return GetContentWidth(); //not support now
     122             :     //return LwpTools::ConvertToMetric(5); //test
     123           0 :     return 0; //test
     124             : }
     125             : 
     126             : /**
     127             : * @descr:   Get the gap between columns
     128             : *
     129             : */
     130           0 : double LwpVirtualLayout::GetColGap(sal_uInt16 /*nIndex*/)
     131             : {
     132             :     //return DEFAULTGAPSIZE;
     133             :     //return LwpTools::ConvertToMetric(0.17);//DEFAULTGAPSIZE=0.17
     134           0 :     return LwpTools::ConvertToMetric(0.17);
     135             : }
     136             : 
     137             : /**
     138             : * @descr:   Whether it is honoring protection
     139             : *
     140             : */
     141         222 : bool LwpVirtualLayout::HonorProtection()
     142             : {
     143         222 :     if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
     144           0 :         return false;
     145             : 
     146         222 :     LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
     147         222 :     if(pParent && !pParent->IsHeader())
     148             :     {
     149           0 :         return pParent->HonorProtection();
     150             :     }
     151             : 
     152         222 :     if(m_pFoundry)//is null now
     153             :     {
     154         218 :         LwpDocument* pDoc = m_pFoundry->GetDocument();
     155             :         /*if(pDoc)
     156             :         {
     157             :             return pDoc->HonorProtection();
     158             :         }*/
     159         218 :         if(pDoc && pDoc->GetRootDocument())
     160         218 :             return pDoc->GetRootDocument()->HonorProtection();
     161             :     }
     162             : 
     163           4 :     return true;
     164             : }
     165             : 
     166             : /**
     167             : * @descr:   Whether it is protected
     168             : *
     169             : */
     170         222 : bool LwpVirtualLayout::IsProtected()
     171             : {
     172         222 :     bool bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
     173             : 
     174         222 :     LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
     175         222 :     if(pParent && !pParent->IsHeader())
     176             :     {
     177           0 :         if(pParent->HonorProtection()&&(pParent->HasProtection()||bProtected))
     178             :         {
     179           0 :             return true;
     180             :         }
     181             :     }
     182         222 :     else if(m_pFoundry)//is null now
     183             :     {
     184         218 :         LwpDocument* pDoc = m_pFoundry->GetDocument();
     185         218 :         if(pDoc)
     186             :         {
     187         218 :             if (pDoc->HonorProtection() && bProtected)
     188             :             {
     189           0 :                 return true;
     190             :             }
     191             :         }
     192             :     }
     193             : 
     194         222 :     return false;
     195             : }
     196             : 
     197             : /**
     198             : * @descr:   Whether it has protection
     199             : *
     200             : */
     201           0 : bool LwpVirtualLayout::HasProtection()
     202             : {
     203           0 :     if(m_nAttributes & STYLE_PROTECTED)
     204           0 :         return true;
     205             : 
     206           0 :     LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
     207           0 :     if(pParent && !pParent->IsHeader())
     208             :     {
     209           0 :         return pParent->HasProtection();
     210             :     }
     211             : 
     212           0 :     return false;
     213             : }
     214             : 
     215             : /**
     216             : * @descr:   Whether it is a mirror layout
     217             : *
     218             : */
     219          24 : bool LwpVirtualLayout::IsComplex()
     220             : {
     221          24 :     return m_nAttributes & STYLE_COMPLEX ? sal_True : sal_False;
     222             : }
     223             : 
     224             : /**
     225             : * @descr:   Get usewhen pointer
     226             : *
     227             : */
     228          24 : LwpUseWhen* LwpVirtualLayout::GetUseWhen()
     229             : {
     230             :     /*
     231             :         If we have a parent, and I'm not a page layout,
     232             :         use my parents information.
     233             :     */
     234          24 :     if(GetLayoutType()!=LWP_PAGE_LAYOUT)
     235             :     {
     236             :         //get parent
     237           0 :         LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
     238           0 :         if(pParent && !pParent->IsHeader()&& (pParent->GetLayoutType()!=LWP_PAGE_LAYOUT))
     239           0 :             return pParent->GetUseWhen();
     240             : 
     241             :     }
     242             : 
     243          24 :     return VirtualGetUseWhen();
     244             : }
     245             : /**
     246             :  * @descr:  Whether this layout is page layout or not
     247             :  * @param:
     248             :  * @return:
     249             : */
     250          66 : bool LwpVirtualLayout::IsPage()
     251             : {
     252          66 :     return (GetLayoutType() == LWP_PAGE_LAYOUT);
     253             : }
     254             : /**
     255             :  * @descr:  Whether this layout is heaer layout or not
     256             :  * @param:
     257             :  * @return:
     258             : */
     259         304 : bool LwpVirtualLayout::IsHeader()
     260             : {
     261         304 :     return (GetLayoutType() == LWP_HEADER_LAYOUT);
     262             : }
     263             : /**
     264             :  * @descr:  Whether this layout is footer layout or not
     265             :  * @param:
     266             :  * @return:
     267             : */
     268          12 : bool LwpVirtualLayout::IsFooter()
     269             : {
     270          12 :     return (GetLayoutType() == LWP_FOOTER_LAYOUT);
     271             : }
     272             : /**
     273             :  * @descr:  Whether this layout is frame layout or not
     274             :  * @param:
     275             :  * @return:
     276             : */
     277          90 : bool LwpVirtualLayout::IsFrame()
     278             : {
     279          90 :     return (GetLayoutType() == LWP_FRAME_LAYOUT);
     280             : }
     281             : 
     282             : /**
     283             :  * @descr:  Whether this layout is cell layout or not
     284             :  * @param:
     285             :  * @return:
     286             : */
     287         558 : bool LwpVirtualLayout::IsCell()
     288             : {
     289         558 :     return (GetLayoutType() == LWP_CELL_LAYOUT
     290         556 :         || GetLayoutType() == LWP_CONNECTED_CELL_LAYOUT
     291        1114 :         || GetLayoutType() == LWP_HIDDEN_CELL_LAYOUT);
     292             : }
     293             : /**
     294             :  * @descr:  Whether this layout is supertable layout or not
     295             :  * @param:
     296             :  * @return:
     297             : */
     298          12 : bool LwpVirtualLayout::IsSuperTable()
     299             : {
     300          12 :     return (GetLayoutType() == LWP_SUPERTABLE_LAYOUT);
     301             : }
     302             : /**
     303             :  * @descr:  Whether this layout is group layout or not
     304             :  * @param:
     305             :  * @return:
     306             : */
     307          50 : bool LwpVirtualLayout::IsGroupHead()
     308             : {
     309          50 :     return (GetLayoutType() == LWP_GROUP_LAYOUT);
     310             : }
     311             : /**
     312             :  * @descr:  get the relative type
     313             :  * @param:
     314             :  * @return:
     315             : */
     316          54 : sal_uInt8 LwpVirtualLayout::GetRelativeType()
     317             : {
     318          54 :     return LwpLayoutRelativityGuts::LAY_PARENT_RELATIVE;
     319             : }
     320             : /**
     321             :  * @descr:  whether it is relative anchored layout
     322             :  * @param:
     323             :  * @return:
     324             : */
     325         352 : bool LwpVirtualLayout::IsRelativeAnchored()
     326             : {
     327             :     sal_uInt8 nType;
     328             : 
     329         352 :     nType = GetRelativeType();
     330         246 :     return (nType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE)
     331         598 :     || (nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE) || (nType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL);
     332             : }
     333             : /**
     334             :  * @descr:  whether it is MinimumHeight layout
     335             :  * @param:
     336             :  * @return:
     337             : */
     338           0 : bool LwpVirtualLayout::IsMinimumHeight()
     339             : {
     340           0 :     return ((m_nAttributes3& STYLE3_MINHEIGHTVALID) != 0);
     341             : }
     342             : 
     343             : /**
     344             : * @descr:   Get parent layout
     345             : *
     346             : */
     347          56 : LwpVirtualLayout* LwpVirtualLayout::GetParentLayout()
     348             : {
     349          56 :     return dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
     350             : }
     351             : 
     352             : /**
     353             : * @descr:   Register child layout style
     354             : *
     355             : */
     356          96 : void LwpVirtualLayout::RegisterChildStyle()
     357             : {
     358             :     //Register all children styles
     359          96 :     LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
     360         224 :     while(pLayout)
     361             :     {
     362          32 :         pLayout->SetFoundry(m_pFoundry);
     363          32 :         pLayout->RegisterStyle();
     364          32 :         pLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
     365             :     }
     366          96 : }
     367             : 
     368           0 : bool LwpVirtualLayout::NoContentReference()
     369             : {
     370           0 :     return (m_nAttributes2 & STYLE2_NOCONTENTREFERENCE) != 0;
     371             : }
     372             : 
     373           0 : bool LwpVirtualLayout::IsStyleLayout()
     374             : {
     375           0 :     if (m_nAttributes3 & STYLE3_STYLELAYOUT)
     376           0 :         return true;
     377             : 
     378           0 :     LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*>(GetParent().obj().get());
     379           0 :     if (pParent)
     380           0 :         return pParent->IsStyleLayout();
     381           0 :     return false;
     382             : }
     383             : 
     384             : /**
     385             : * @descr:   Find child layout by layout type
     386             : *
     387             : */
     388           0 : LwpVirtualLayout* LwpVirtualLayout::FindChildByType(LWP_LAYOUT_TYPE eType)
     389             : {
     390           0 :     LwpObjectID& rID = GetChildHead();
     391             : 
     392           0 :     while(!rID.IsNull())
     393             :     {
     394           0 :         LwpVirtualLayout * pLayout = dynamic_cast<LwpVirtualLayout *>(rID.obj().get());
     395           0 :         if(!pLayout)
     396             :         {
     397           0 :             break;
     398             :         }
     399             : 
     400           0 :         if (pLayout && pLayout->GetLayoutType() == eType)
     401             :         {
     402           0 :             return pLayout;
     403             :         }
     404           0 :         rID = pLayout->GetNext();
     405             :     }
     406             : 
     407           0 :     return NULL;
     408             : }
     409             : 
     410             : /**
     411             : * @descr:   Whether the size of layout is fit the graphic
     412             : *
     413             : */
     414          50 : bool LwpVirtualLayout::IsFitGraphic()
     415             : {
     416          50 :     return IsAutoGrowRight() && !IsAutoGrowLeft() && IsAutoGrowDown();
     417             : }
     418             : 
     419             : /**
     420             : * @descr:   Whether the width of layout is auto grow
     421             : *
     422             : */
     423           0 : bool LwpVirtualLayout::IsAutoGrowWidth()
     424             : {
     425           0 :     return IsAutoGrowLeft() || IsAutoGrowRight();
     426             : }
     427             : 
     428             : /**
     429             : * @descr:   Determine whether the layout width is to margin
     430             : *
     431             : */
     432          84 : bool LwpVirtualLayout::IsInlineToMargin()
     433             : {
     434          84 :     return (m_nAttributes3 & STYLE3_INLINETOMARGIN) != 0;
     435             : }
     436             : 
     437         166 : void LwpAssociatedLayouts::Read(LwpObjectStream* pStrm)
     438             : {
     439         166 :     m_OnlyLayout.ReadIndexed(pStrm);
     440         166 :     m_Layouts.Read(pStrm);
     441         166 :     pStrm->SkipExtra();
     442         166 : }
     443             : 
     444             : /**
     445             : * @descr:   Looking for the layout which follows the pStartLayout
     446             : * @param:   pStartLayout - the layout which is used for looking for its following layout
     447             : */
     448         924 : LwpVirtualLayout* LwpAssociatedLayouts::GetLayout(LwpVirtualLayout *pStartLayout)
     449             : {
     450         924 :     LwpVirtualLayout* pLayout = NULL;
     451             : 
     452         924 :     if (!pStartLayout && !m_OnlyLayout.IsNull())
     453             :         /* Looking for the first layout and there's only one layout in  the list.*/
     454         750 :         return dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj().get());
     455             : 
     456         174 :     LwpObjectHolder* pObjHolder = dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead().obj().get());
     457         174 :     if(pObjHolder)
     458             :     {
     459           0 :         pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
     460           0 :         if(!pStartLayout )
     461           0 :             return pLayout;
     462             : 
     463           0 :         while(pObjHolder && pStartLayout != pLayout)
     464             :         {
     465           0 :             pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext().obj().get());
     466           0 :             if(pObjHolder)
     467             :             {
     468           0 :                 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
     469             :             }
     470             :         }
     471             : 
     472           0 :         if(pObjHolder)
     473             :         {
     474           0 :             pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext().obj().get());
     475           0 :             if(pObjHolder)
     476             :             {
     477           0 :                 pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
     478           0 :                 return pLayout;
     479             :             }
     480             :         }
     481             : 
     482             :         //return pLayout;
     483             :     }
     484             : 
     485         174 :     return NULL;
     486             : }
     487             : 
     488          64 : LwpHeadLayout::LwpHeadLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
     489          64 :     : LwpVirtualLayout(objHdr, pStrm)
     490          64 : {}
     491             : 
     492          64 : void LwpHeadLayout::Read()
     493             : {
     494          64 :     LwpVirtualLayout::Read();
     495             :     //For PermissiveLayout
     496          64 :     m_pObjStrm->SkipExtra();
     497             :     //For me
     498          64 :     m_pObjStrm->SkipExtra();
     499          64 : }
     500             : 
     501          64 : void LwpHeadLayout::RegisterStyle()
     502             : {
     503             :     //Register all children styles
     504          64 :     LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
     505         272 :     while(pLayout)
     506             :     {
     507         144 :         pLayout->SetFoundry(m_pFoundry);
     508             :         //if the layout is relative to para, the layout will be registered in para
     509         144 :         if(!pLayout->IsRelativeAnchored())
     510             :         {
     511          70 :             if (pLayout == this)
     512             :             {
     513             :                 OSL_FAIL("Layout points to itself");
     514           0 :                 break;
     515             :             }
     516          70 :             pLayout->RegisterStyle();
     517             :         }
     518         144 :         LwpVirtualLayout *pNext = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
     519         144 :         if (pNext == pLayout)
     520             :         {
     521             :             OSL_FAIL("Layout points to itself");
     522           0 :             break;
     523             :         }
     524         144 :         pLayout = pNext;
     525             :     }
     526          64 : }
     527             : 
     528             : /**
     529             :  * @descr   find endnote supertable layout from the child layout list. Suppose that there is only one endnote supertablelayout in one division
     530             :  * @return pointer to endnote supertable layout
     531             :  */
     532          14 : LwpVirtualLayout* LwpHeadLayout::FindEnSuperTableLayout()
     533             : {
     534          14 :     LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
     535         122 :     while(pLayout)
     536             :     {
     537          94 :         if(pLayout->GetLayoutType() == LWP_ENDNOTE_SUPERTABLE_LAYOUT)
     538             :         {
     539           0 :             return pLayout;
     540             :         }
     541          94 :         pLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
     542             :     }
     543          14 :     return NULL;
     544             : }
     545             : 
     546         190 : LwpLayoutStyle::LwpLayoutStyle()
     547             :     : m_nStyleDefinition(0)
     548         190 :     , m_pDescription(new LwpAtomHolder)
     549         380 :     , m_nKey(0)
     550             : {
     551         190 : }
     552             : 
     553         380 : LwpLayoutStyle::~LwpLayoutStyle()
     554             : {
     555         190 :     delete m_pDescription;
     556         380 : }
     557             : 
     558          56 : void LwpLayoutStyle::Read(LwpObjectStream* pStrm)
     559             : {
     560          56 :     m_nStyleDefinition = pStrm->QuickReaduInt32();
     561          56 :     m_pDescription->Read(pStrm);
     562          56 :     if (pStrm->CheckExtra())
     563             :     {
     564          42 :         m_nKey = pStrm->QuickReaduInt16();
     565          42 :         pStrm->SkipExtra();
     566             :     }
     567          56 : }
     568             : 
     569         190 : LwpLayoutMisc::LwpLayoutMisc() :
     570             : m_nGridDistance(0), m_nGridType(0),
     571         190 : m_pContentStyle(new LwpAtomHolder)
     572             : {
     573         190 : }
     574             : 
     575         380 : LwpLayoutMisc::~LwpLayoutMisc()
     576             : {
     577         190 :     if (m_pContentStyle)
     578             :     {
     579         190 :         delete m_pContentStyle;
     580             :     }
     581         380 : }
     582             : 
     583          78 : void LwpLayoutMisc::Read(LwpObjectStream* pStrm)
     584             : {
     585          78 :     m_nGridType = pStrm->QuickReaduInt16();
     586          78 :     m_nGridDistance = pStrm->QuickReadInt32();
     587          78 :     m_pContentStyle->Read(pStrm);
     588          78 :     pStrm->SkipExtra();
     589          78 : }
     590             : 
     591         190 : LwpMiddleLayout::LwpMiddleLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
     592             :     : LwpVirtualLayout(objHdr, pStrm),
     593         190 :       m_pStyleStuff(new LwpLayoutStyle), m_pMiscStuff(new LwpLayoutMisc)
     594         190 : {}
     595             : 
     596         380 : LwpMiddleLayout::~LwpMiddleLayout()
     597             : {
     598         190 :     if (m_pStyleStuff)
     599             :     {
     600         190 :         delete m_pStyleStuff;
     601             :     }
     602         190 :     if (m_pMiscStuff)
     603             :     {
     604         190 :         delete m_pMiscStuff;
     605             :     }
     606         190 : }
     607         190 : void LwpMiddleLayout::Read()
     608             : {
     609         190 :     LwpObjectStream* pStrm = m_pObjStrm;
     610             : 
     611         190 :     LwpVirtualLayout::Read();
     612             : 
     613             :     //skip CLiteLayout data;
     614         190 :     LwpAtomHolder ContentClass;
     615         190 :     ContentClass.Read(pStrm);
     616         190 :     pStrm->SkipExtra();
     617             : 
     618             :     // before layout hierarchy rework
     619         190 :     if(LwpFileHeader::m_nFileRevision < 0x000B)
     620         190 :         return;
     621             : 
     622         190 :     m_Content.ReadIndexed(pStrm);
     623             : 
     624             :     // 01/20/2005
     625         190 :     m_BasedOnStyle.ReadIndexed(pStrm);
     626         190 :     m_TabPiece.ReadIndexed(pStrm);
     627             : 
     628         190 :     sal_uInt8 nWhatsItGot = pStrm->QuickReaduInt8();
     629             : 
     630         190 :     if (nWhatsItGot & DISK_GOT_STYLE_STUFF)
     631             :     {
     632          56 :         m_pStyleStuff->Read(pStrm);
     633             :     }
     634         190 :     if (nWhatsItGot & DISK_GOT_MISC_STUFF)
     635             :     {
     636          78 :         m_pMiscStuff->Read(pStrm);
     637             :     }
     638             : 
     639         190 :     m_LayGeometry.ReadIndexed(pStrm);
     640         190 :     m_LayScale.ReadIndexed(pStrm);
     641         190 :     m_LayMargins.ReadIndexed(pStrm);
     642         190 :     m_LayBorderStuff.ReadIndexed(pStrm);
     643         190 :     m_LayBackgroundStuff.ReadIndexed(pStrm);
     644             : 
     645         190 :     if (pStrm->CheckExtra())
     646             :     {
     647         158 :         m_LayExtBorderStuff.ReadIndexed(pStrm);
     648         158 :         pStrm->SkipExtra();
     649         190 :     }
     650             :     //end
     651             : }
     652             : 
     653             : #include "lwplaypiece.hxx"
     654             : 
     655             : /**
     656             : * @descr:   Get the geometry of current layout
     657             : *
     658             : */
     659         616 : LwpLayoutGeometry* LwpMiddleLayout::GetGeometry()
     660             : {
     661         616 :     if( !m_LayGeometry.IsNull() )
     662             :     {
     663         478 :         return ( dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj().get()) );
     664             :     }
     665         138 :     else if( !m_BasedOnStyle.IsNull() )
     666             :     {
     667         138 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
     668         138 :         return pLay ? pLay->GetGeometry() : NULL;
     669             :     }
     670           0 :     return NULL;
     671             : }
     672             : 
     673             : /**
     674             : * @descr:   Get layout height, measured by "cm"
     675             : *
     676             : */
     677         130 : double LwpMiddleLayout::GetGeometryHeight()
     678             : {
     679         130 :     LwpLayoutGeometry* pGeo = GetGeometry();
     680         130 :     if(pGeo)
     681             :     {
     682         130 :         return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetHeight() ) );
     683             :     }
     684             :     else
     685           0 :         return -1;
     686             : }
     687             : 
     688             : /**
     689             : * @descr:   Get layout width, measured by "cm"
     690             : *
     691             : */
     692         144 : double LwpMiddleLayout::GetGeometryWidth()
     693             : {
     694         144 :     LwpLayoutGeometry* pGeo = GetGeometry();
     695         144 :     if(pGeo)
     696             :     {
     697         144 :         return ( LwpTools::ConvertFromUnitsToMetric( pGeo->GetWidth() ) );
     698             :     }
     699             :     else
     700           0 :         return -1;
     701             : }
     702             : 
     703             : /**
     704             : * @descr:   Whether the margins is same as parent layout
     705             : *
     706             : */
     707        2010 : bool LwpMiddleLayout::MarginsSameAsParent()
     708             : {
     709        2010 :     if(m_nOverrideFlag & OVER_MARGINS)
     710             :     {
     711        1280 :         return LwpVirtualLayout::MarginsSameAsParent();
     712             :     }
     713         730 :     if(!m_BasedOnStyle.IsNull())
     714             :     {
     715         710 :         LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
     716         710 :         if (pLay)
     717         710 :             pLay->MarginsSameAsParent();
     718             :     }
     719         730 :     return LwpVirtualLayout::MarginsSameAsParent();
     720             : 
     721             : }
     722             : 
     723             : /**
     724             : * @descr:   Get margin
     725             : * @param:   nWhichSide - 0: left, 1: right, 2:top, 3: bottom
     726             : */
     727        2344 : double LwpMiddleLayout::GetMarginsValue(const sal_uInt8 &nWhichSide)
     728             : {
     729        2344 :     double fValue = 0;
     730        2344 :     if((nWhichSide==MARGIN_LEFT)||(nWhichSide==MARGIN_RIGHT))
     731             :     {
     732        1300 :         if ( MarginsSameAsParent() )
     733             :         {
     734          68 :             LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
     735          68 :             if(pParent && !pParent->IsHeader())
     736             :             {
     737          68 :                 fValue = pParent->GetMarginsValue(nWhichSide);
     738          68 :                 return fValue;
     739             :             }
     740             :         }
     741             :     }
     742             : 
     743        2276 :     if(m_nOverrideFlag & OVER_MARGINS)
     744             :     {
     745        1354 :         LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj().get());
     746        1354 :         if(pMar1)
     747             :         {
     748        1354 :             fValue = pMar1->GetMargins().GetMarginsValue(nWhichSide);
     749        1354 :             return fValue;
     750             :         }
     751             :     }
     752         922 :     LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
     753         922 :     if(pStyle)
     754             :     {
     755         912 :         fValue = pStyle->GetMarginsValue(nWhichSide);
     756         912 :         return fValue;
     757             :     }
     758          10 :     return LwpVirtualLayout::GetMarginsValue(nWhichSide);
     759             : }
     760             : /**
     761             :  * @descr:  Get extmargin value
     762             :  * @param:  nWhichSide - 0: left, 1: right, 2:top, 3: bottom
     763             :  * @param:
     764             :  * @return:
     765             : */
     766         768 : double LwpMiddleLayout::GetExtMarginsValue(const sal_uInt8 &nWhichSide)
     767             : {
     768         768 :     double fValue = 0;
     769         768 :     if(m_nOverrideFlag & OVER_MARGINS)
     770             :     {
     771         288 :         LwpLayoutMargins* pMar1 = dynamic_cast<LwpLayoutMargins*> (m_LayMargins.obj().get());
     772         288 :         if(pMar1)
     773             :         {
     774         288 :             fValue = pMar1->GetExtMargins().GetMarginsValue(nWhichSide);
     775         288 :             return fValue;
     776             :         }
     777             :     }
     778         480 :     LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
     779         480 :     if(pStyle)
     780             :     {
     781         480 :         fValue = pStyle->GetExtMarginsValue(nWhichSide);
     782         480 :         return fValue;
     783             :     }
     784           0 :     return LwpVirtualLayout::GetExtMarginsValue(nWhichSide);
     785             : }
     786             : /**
     787             :  * @descr:  Get the LwpBorderStuff object according to m_LayBorderStuff id.
     788             :  * @param:
     789             :  * @param:
     790             :  * @return:
     791             : */
     792         410 : LwpBorderStuff* LwpMiddleLayout::GetBorderStuff()
     793             : {
     794         410 :     if(m_nOverrideFlag & OVER_BORDERS)
     795             :     {
     796         248 :         LwpLayoutBorder* pLayoutBorder = dynamic_cast<LwpLayoutBorder*>(m_LayBorderStuff.obj().get());
     797         248 :         return pLayoutBorder ? &pLayoutBorder->GetBorderStuff() : NULL;
     798             :     }
     799         162 :     else if( !m_BasedOnStyle.IsNull() )
     800             :     {
     801          66 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
     802          66 :         return pLay ? pLay->GetBorderStuff() :  NULL;
     803             :     }
     804          96 :     return NULL;
     805             : }
     806             : 
     807             : /**
     808             :  * @descr:  Get LwpBackgroundStuff object according to m_LayBackgroundStuff id;
     809             :  * @param:
     810             :  * @param:
     811             :  * @return:
     812             : */
     813         640 : LwpBackgroundStuff* LwpMiddleLayout::GetBackgroundStuff()
     814             : {
     815         640 :     if(m_nOverrideFlag & OVER_BACKGROUND)
     816             :     {
     817         348 :         LwpLayoutBackground* pLayoutBackground = dynamic_cast<LwpLayoutBackground*>(m_LayBackgroundStuff.obj().get());
     818         348 :         return pLayoutBackground ? &pLayoutBackground->GetBackgoudStuff() : NULL;
     819             :     }
     820         292 :     else if( !m_BasedOnStyle.IsNull() )
     821             :     {
     822         292 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
     823         292 :         return pLay ? pLay->GetBackgroundStuff() : NULL;
     824             :     }
     825           0 :     return NULL;
     826             : }
     827             : /**
     828             :  * @descr:  create xfborder.
     829             :  * @param:
     830             :  * @param:
     831             :  * @return:
     832             : */
     833         344 : XFBorders* LwpMiddleLayout::GetXFBorders()
     834             : {
     835         344 :     LwpBorderStuff* pBorderStuff = GetBorderStuff();
     836         344 :     if(pBorderStuff&&pBorderStuff->GetSide() != 0)
     837             :     {
     838             :         //copy from lwpparastyle.
     839         166 :         XFBorders   *pXFBorders = new XFBorders();
     840             :         // apply 4 borders respectively
     841             :         LwpBorderStuff::BorderType pType[] = { LwpBorderStuff::LEFT, LwpBorderStuff::RIGHT,
     842         166 :             LwpBorderStuff::TOP, LwpBorderStuff::BOTTOM };
     843             : 
     844         830 :         for (sal_uInt8 nC = 0; nC < 4; nC++)
     845             :         {
     846         664 :             if (pBorderStuff->HasSide(pType[nC]))
     847             :             {
     848         664 :                 LwpParaStyle::ApplySubBorder(pBorderStuff, pType[nC], pXFBorders);
     849             :             }
     850             :         }
     851         166 :         return pXFBorders;
     852             :     }
     853         178 :     return NULL;
     854             : }
     855             : 
     856             : /**
     857             :  * @descr:  Get text direction settings.
     858             :  * @param:
     859             :  * @param:
     860             :  * @return:
     861             : */
     862          66 : enumXFTextDir LwpMiddleLayout::GetTextDirection()
     863             : {
     864          66 :     enumXFTextDir eTextDir = enumXFTextDirNone;
     865          66 :     sal_uInt8 nDirection = GetContentOrientation();
     866          66 :     switch(nDirection)
     867             :     {
     868             :         case TEXT_ORIENT_LRTB:
     869             :         {
     870          66 :             eTextDir = enumXFTextDirLR_TB;
     871          66 :             break;
     872             :         }
     873             :         case TEXT_ORIENT_TBRL:
     874             :         {
     875           0 :             eTextDir = enumXFTextDirTB_RL;
     876           0 :             break;
     877             :         }
     878             :         case TEXT_ORIENT_RLBT: // not supported now
     879             :         {
     880           0 :             eTextDir = enumXFTextDirNone;
     881           0 :             break;
     882             :         }
     883             :         case TEXT_ORIENT_BTLR: // not supported now
     884             :         {
     885           0 :             eTextDir = enumXFTextDirNone;
     886           0 :             break;
     887             :         }
     888             :         default:
     889           0 :             break;
     890             :     }
     891          66 :     return eTextDir;
     892             : }
     893             : /**
     894             :  * @descr: Get back ground color.
     895             :  * @param:
     896             :  * @param:
     897             :  * @return:
     898             : */
     899         248 : LwpColor* LwpMiddleLayout::GetBackColor()
     900             : {
     901         248 :     LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
     902         248 :     if(pBackgroundStuff && !pBackgroundStuff->IsTransparent())
     903             :     {
     904          70 :         LwpColor* pColor = pBackgroundStuff->GetFillColor();
     905          70 :         if(pColor->IsValidColor())
     906             :         {
     907          70 :             return pColor;
     908             :         }
     909             :     }
     910         178 :     return NULL;
     911             : }
     912             : 
     913             : /**
     914             :  * @descr:  Add back color settings into xfpagemaster.
     915             :  * @param:
     916             :  * @param:
     917             :  * @return:
     918             : */
     919          50 : LwpTabOverride* LwpMiddleLayout::GetTabOverride()
     920             : {
     921          50 :     if(m_nAttributes & OVER_TABS)
     922             :     {
     923          50 :         if(!m_TabPiece.IsNull())
     924             :         {
     925          10 :             LwpTabPiece *pPiece = dynamic_cast<LwpTabPiece*>(m_TabPiece.obj().get());
     926          10 :             return static_cast<LwpTabOverride*>(pPiece ? pPiece->GetOverride() : NULL);
     927             :         }
     928          40 :         return NULL;
     929             :     }
     930           0 :     else if( !m_BasedOnStyle.IsNull() )
     931             :     {
     932           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
     933           0 :         return pLay ? pLay->GetTabOverride() : NULL;
     934             :     }
     935           0 :     return NULL;
     936             : }
     937             : 
     938             : /**
     939             :  * @descr:   Layscale for graphic & watermark
     940             :  * @param:
     941             :  * @param:
     942             :  * @return:
     943             : */
     944           0 : sal_uInt16 LwpMiddleLayout::GetScaleMode(void)
     945             : {
     946           0 :     if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
     947           0 :         return GetLayoutScale()->GetScaleMode();
     948           0 :     else if (m_BasedOnStyle.obj().is())
     949           0 :         return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleMode();
     950             :     else
     951           0 :         return (LwpLayoutScale::FIT_IN_FRAME | LwpLayoutScale::MAINTAIN_ASPECT_RATIO);
     952             : }
     953             : 
     954           6 : sal_uInt16 LwpMiddleLayout::GetScaleTile(void)
     955             : {
     956           6 :     if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
     957           6 :         return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::TILED)
     958           6 :             ? 1 : 0;
     959           0 :     else if (m_BasedOnStyle.obj().is())
     960           0 :         return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleTile();
     961             :     else
     962           0 :         return 0;
     963             : }
     964             : 
     965          12 : sal_uInt16 LwpMiddleLayout::GetScaleCenter(void)
     966             : {
     967          12 :     if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
     968          12 :         return (GetLayoutScale()->GetPlacement() & LwpLayoutScale::CENTERED)
     969          12 :             ? 1 : 0;
     970           0 :     else if (m_BasedOnStyle.obj().is())
     971           0 :         return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleCenter();
     972             :     else
     973           0 :         return 0;
     974             : }
     975             : 
     976           0 : sal_uInt32 LwpMiddleLayout::GetScalePercentage(void)
     977             : {
     978           0 :     if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
     979           0 :         return GetLayoutScale()->GetScalePercentage()/10;//m_nScalePercentage 1000 = 100%
     980           0 :     else if (m_BasedOnStyle.obj().is())
     981           0 :         return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScalePercentage();
     982             :     else
     983           0 :         return 100;
     984             : }
     985             : 
     986           0 : double LwpMiddleLayout::GetScaleWidth(void)
     987             : {
     988           0 :     if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
     989           0 :         return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleWidth());
     990           0 :     else if (m_BasedOnStyle.obj().is())
     991           0 :         return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleWidth();
     992             :     else
     993           0 :         return 0;
     994             : }
     995             : 
     996           0 : double LwpMiddleLayout::GetScaleHeight(void)
     997             : {
     998           0 :     if ((m_nOverrideFlag & OVER_SCALING) && m_LayScale.obj().is())
     999           0 :         return LwpTools::ConvertFromUnits(GetLayoutScale()->GetScaleHeight());
    1000           0 :     else if (m_BasedOnStyle.obj().is())
    1001           0 :         return dynamic_cast<LwpMiddleLayout*>(m_BasedOnStyle.obj().get())->GetScaleHeight();
    1002             :     else
    1003           0 :         return 0;
    1004             : }
    1005           8 : bool LwpMiddleLayout::CanSizeRight(void)
    1006             : {
    1007           8 :     sal_uInt8 RelType = GetRelativeType();
    1008             : 
    1009           8 :     if (RelType == LwpLayoutRelativityGuts::LAY_INLINE || RelType == LwpLayoutRelativityGuts::LAY_PARA_RELATIVE
    1010           8 :     || RelType == LwpLayoutRelativityGuts::LAY_INLINE_VERTICAL)
    1011             :     {
    1012           0 :         return false;
    1013             :     }
    1014           8 :     return true;
    1015             : }
    1016           4 : sal_Int32 LwpMiddleLayout::GetMinimumWidth()
    1017             : {
    1018           4 :     if (((m_nAttributes3 & STYLE3_WIDTHVALID) != 0) && GetGeometry())
    1019             :     {
    1020           4 :         return GetGeometry()->GetWidth();
    1021             :     }
    1022           0 :     else if (m_nOverrideFlag & OVER_SIZE)
    1023             :     {
    1024           0 :         return DetermineWidth();
    1025             :     }
    1026           0 :     return 0;
    1027             : }
    1028           0 : sal_Int32 LwpMiddleLayout::DetermineWidth()
    1029             : {
    1030           0 :     if (IsSizeRightToContent())
    1031             :     {
    1032             :         assert(false);
    1033             :     }
    1034           0 :     else if (IsSizeRightToContainer())
    1035             :     {
    1036             :         assert(false);
    1037             :     }
    1038             :     else
    1039             :     {
    1040           0 :         m_nAttributes3 |= STYLE3_WIDTHVALID;
    1041           0 :         return GetGeometry()->GetWidth();
    1042             :     }
    1043           0 :     return 0;
    1044             : }
    1045           0 : bool LwpMiddleLayout::IsSizeRightToContainer(void)
    1046             : {
    1047           0 :     if (!CanSizeRight())
    1048           0 :         return false;
    1049             : 
    1050           0 :     if (m_nOverrideFlag & OVER_SIZE)
    1051             :     {
    1052           0 :         return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
    1053             :                         << SHIFT_RIGHT))
    1054           0 :         == ((LAY_USEDIRECTION | LAY_TOCONTAINER | LAY_AUTOSIZE) << SHIFT_RIGHT);
    1055             :     }
    1056           0 :     else if (m_BasedOnStyle.obj().is())
    1057             :     {
    1058           0 :         LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj().get());
    1059           0 :         return pLayout ? pLayout->IsSizeRightToContainer() : sal_False;
    1060             :     }
    1061             :     else
    1062           0 :         return false;
    1063             : }
    1064           8 : bool LwpMiddleLayout::IsSizeRightToContent(void)
    1065             : {
    1066           8 :     if (!CanSizeRight())
    1067           0 :         return false;
    1068             : 
    1069           8 :     if (m_nOverrideFlag & OVER_SIZE)
    1070             :     {
    1071           4 :         return (m_nDirection & ((LAY_USEDIRECTION|LAY_AUTOSIZE|LAY_TOCONTAINER)
    1072             :                             << SHIFT_RIGHT))
    1073           4 :                 == ((LAY_USEDIRECTION | LAY_AUTOSIZE) << SHIFT_RIGHT);
    1074             :     }
    1075           4 :     else if (m_BasedOnStyle.obj().is())
    1076             :     {
    1077           4 :         LwpMiddleLayout * pLayout = dynamic_cast<LwpMiddleLayout *>(m_BasedOnStyle.obj().get());
    1078           4 :         return pLayout ? pLayout->IsSizeRightToContent() : sal_False;
    1079             :     }
    1080             :     else
    1081           0 :         return false;
    1082             : }
    1083             : 
    1084             : /**
    1085             : * @descr:   Get layout height
    1086             : *
    1087             : */
    1088          40 : double LwpMiddleLayout::GetHeight()
    1089             : {
    1090          40 :     return GetGeometryHeight();
    1091             : }
    1092             : 
    1093             : /**
    1094             : * @descr:   Get layout height
    1095             : *
    1096             : */
    1097          86 : double LwpMiddleLayout::GetWidth()
    1098             : {
    1099          86 :     return GetGeometryWidth();
    1100             : }
    1101             : /**
    1102             : * @descr:   Get layout orgin point
    1103             : *
    1104             : */
    1105          44 : LwpPoint LwpMiddleLayout::GetOrigin()
    1106             : {
    1107          44 :     LwpLayoutGeometry* pGeo = GetGeometry();
    1108          44 :     if(pGeo)
    1109             :     {
    1110          44 :         sal_uInt8 nType = GetRelativeType();
    1111          44 :         if(nType == LwpLayoutRelativityGuts::LAY_INLINE
    1112          44 :             || nType == LwpLayoutRelativityGuts::LAY_INLINE_NEWLINE )
    1113             :         {
    1114          32 :             return pGeo->GetAbsoluteOrigin();
    1115             :         }
    1116             :         else
    1117          12 :             return pGeo->GetOrigin();
    1118             : 
    1119             :     }
    1120             : 
    1121           0 :     return LwpPoint();
    1122             : }
    1123             : 
    1124             : /**
    1125             : * @descr:   Whether the fill is pattern fill or not
    1126             : * @return:  True if yes, false if not.
    1127             : */
    1128         100 : bool LwpMiddleLayout::IsPatternFill()
    1129             : {
    1130         100 :     LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
    1131         100 :     if (pBackgroundStuff)
    1132             :     {
    1133         100 :         return pBackgroundStuff->IsPatternFill();
    1134             :     }
    1135             : 
    1136           0 :     return false;
    1137             : }
    1138             : 
    1139             : /**
    1140             : * @descr:   Get the fill pattern style. Data are saved in a XFBGImage object
    1141             : * @return:  the fill pattern style.
    1142             : */
    1143           0 : XFBGImage* LwpMiddleLayout::GetFillPattern()
    1144             : {
    1145           0 :     LwpBackgroundStuff* pBackgroundStuff = GetBackgroundStuff();
    1146           0 :     if (pBackgroundStuff)
    1147             :     {
    1148           0 :         return pBackgroundStuff->GetFillPattern();
    1149             :     }
    1150             : 
    1151           0 :     return NULL;
    1152             : 
    1153             : }
    1154             : 
    1155             : /**
    1156             : * @descr:   Whether the height and width of layout is auto grow
    1157             : *
    1158             : */
    1159          26 : bool LwpMiddleLayout::IsAutoGrow()
    1160             : {
    1161          26 :     if(m_nOverrideFlag & OVER_SIZE)
    1162             :     {
    1163          26 :         return m_nDirection &
    1164             :             ((LAY_AUTOGROW << SHIFT_UP) | (LAY_AUTOGROW << SHIFT_DOWN) |
    1165             :             (LAY_AUTOGROW << SHIFT_RIGHT) | (LAY_AUTOGROW << SHIFT_LEFT))
    1166          26 :             ? sal_True : sal_False;
    1167             :     }
    1168           0 :     else if( !m_BasedOnStyle.IsNull() )
    1169             :     {
    1170           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1171           0 :         return pLay ? pLay->IsAutoGrow() : sal_False;
    1172             :     }
    1173           0 :     return LwpVirtualLayout::IsAutoGrow();
    1174             : }
    1175             : 
    1176             : /**
    1177             : * @descr:   Whether the height of layout is auto grow down
    1178             : *
    1179             : */
    1180          42 : bool LwpMiddleLayout::IsAutoGrowDown()
    1181             : {
    1182          42 :     if(m_nOverrideFlag & OVER_SIZE)
    1183             :     {
    1184          42 :         return m_nDirection & (LAY_AUTOGROW << SHIFT_DOWN) ? sal_True : sal_False;
    1185             :     }
    1186           0 :     else if( !m_BasedOnStyle.IsNull() )
    1187             :     {
    1188           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1189           0 :         return pLay ? pLay->IsAutoGrowDown() : sal_False;
    1190             :     }
    1191           0 :     return LwpVirtualLayout::IsAutoGrowDown();
    1192             : }
    1193             : 
    1194             : /**
    1195             : * @descr:   Whether the height of layout is auto grow up
    1196             : *
    1197             : */
    1198          30 : bool LwpMiddleLayout::IsAutoGrowUp()
    1199             : {
    1200          30 :     if(m_nOverrideFlag & OVER_SIZE)
    1201             :     {
    1202          30 :         return m_nDirection & (LAY_AUTOGROW << SHIFT_UP) ? sal_True : sal_False;
    1203             :     }
    1204           0 :     else if( !m_BasedOnStyle.IsNull() )
    1205             :     {
    1206           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1207           0 :         return pLay ? pLay->IsAutoGrowUp() : sal_False;
    1208             :     }
    1209           0 :     return LwpVirtualLayout::IsAutoGrowUp();
    1210             : }
    1211             : 
    1212             : /**
    1213             : * @descr:   Whether the height of layout is auto grow down
    1214             : *
    1215             : */
    1216          26 : bool LwpMiddleLayout::IsAutoGrowLeft()
    1217             : {
    1218          26 :     if(m_nOverrideFlag & OVER_SIZE)
    1219             :     {
    1220          26 :         return m_nDirection & (LAY_AUTOGROW << SHIFT_LEFT) ? sal_True : sal_False;
    1221             :     }
    1222           0 :     else if( !m_BasedOnStyle.IsNull() )
    1223             :     {
    1224           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1225           0 :         if (pLay)
    1226           0 :             return pLay->IsAutoGrowLeft();
    1227             :     }
    1228           0 :     return LwpVirtualLayout::IsAutoGrowLeft();
    1229             : }
    1230             : 
    1231             : /**
    1232             : * @descr:   Whether the height of layout is auto grow down
    1233             : *
    1234             : */
    1235          64 : bool LwpMiddleLayout::IsAutoGrowRight()
    1236             : {
    1237          64 :     if(m_nOverrideFlag & OVER_SIZE)
    1238             :     {
    1239          64 :         return m_nDirection & (LAY_AUTOGROW << SHIFT_RIGHT) ? sal_True : sal_False;
    1240             :     }
    1241           0 :     else if( !m_BasedOnStyle.IsNull() )
    1242             :     {
    1243           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1244           0 :         return pLay ? pLay->IsAutoGrowRight() : sal_False;
    1245             :     }
    1246           0 :     return LwpVirtualLayout::IsAutoGrowRight();
    1247             : }
    1248             : 
    1249             : /**
    1250             : * @descr:   Get contents orientation
    1251             : *
    1252             : */
    1253         166 : sal_uInt8 LwpMiddleLayout::GetContentOrientation()
    1254             : {
    1255             :     //content orientation in Graphic objects and OLE objects not supported now
    1256         166 :     if((m_nOverrideFlag & OVER_ROTATION)&& !m_LayGeometry.IsNull())
    1257             :     {
    1258          66 :         LwpLayoutGeometry* pLayGeometry = dynamic_cast<LwpLayoutGeometry*> (m_LayGeometry.obj().get());
    1259          66 :         if (pLayGeometry)
    1260          66 :             return pLayGeometry->GetContentOrientation();
    1261             :     }
    1262         100 :     else if( !m_BasedOnStyle.IsNull() )
    1263             :     {
    1264         100 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1265         100 :         if (pLay)
    1266         100 :             return pLay->GetContentOrientation();
    1267             :     }
    1268           0 :     return LwpVirtualLayout::GetContentOrientation();
    1269             : }
    1270             : 
    1271             : /**
    1272             : * @descr:   Whether it is honoring protection
    1273             : *
    1274             : */
    1275           0 : bool LwpMiddleLayout::HonorProtection()
    1276             : {
    1277           0 :     if(m_nOverrideFlag & OVER_MISC)
    1278             :     {
    1279           0 :         if(!(m_nAttributes2 & STYLE2_HONORPROTECTION))
    1280           0 :             return false;
    1281             : 
    1282           0 :         LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
    1283           0 :         if(pParent && !pParent->IsHeader())
    1284             :         {
    1285           0 :             return pParent->HonorProtection();
    1286             :         }
    1287             : 
    1288           0 :         if(m_pFoundry)//is null now
    1289             :         {
    1290           0 :             LwpDocument* pDoc = m_pFoundry->GetDocument();
    1291           0 :             if(pDoc)
    1292             :             {
    1293           0 :                 return pDoc->HonorProtection();
    1294             :             }
    1295             :         }
    1296             :     }
    1297           0 :     else if( !m_BasedOnStyle.IsNull() )
    1298             :     {
    1299           0 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1300           0 :         if (pLay)
    1301           0 :             return pLay->HonorProtection();
    1302             :     }
    1303             : 
    1304           0 :     return LwpVirtualLayout::HonorProtection();
    1305             : }
    1306             : 
    1307             : /**
    1308             : * @descr:   Whether it is pretected
    1309             : *
    1310             : */
    1311         222 : bool LwpMiddleLayout::IsProtected()
    1312             : {
    1313         222 :     bool bProtected = false;
    1314         222 :     if(m_nOverrideFlag & OVER_MISC)
    1315             :     {
    1316         130 :         bProtected = (m_nAttributes & STYLE_PROTECTED)!=0;
    1317             :     }
    1318          92 :     else if( !m_BasedOnStyle.IsNull() )
    1319             :     {
    1320          92 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1321          92 :         bProtected = pLay ? pLay->IsProtected() : sal_False;
    1322             :     }
    1323             :     else
    1324           0 :         bProtected = LwpVirtualLayout::IsProtected();
    1325             : 
    1326         222 :     LwpVirtualLayout* pParent = dynamic_cast<LwpVirtualLayout*> (GetParent().obj().get());
    1327         222 :     if(pParent && !pParent->IsHeader())
    1328             :     {
    1329             :         /* If a parent's protected then none of its children can be accessed. */
    1330         222 :         if(pParent->IsProtected())
    1331           0 :             return true;
    1332             : 
    1333         222 :         if(pParent->HonorProtection())
    1334         222 :             return bProtected;
    1335             : 
    1336             :         /* If our parent isn't honoring protection then we aren't protected. */
    1337           0 :         return false;
    1338             : 
    1339             :     }
    1340           0 :     if(m_pFoundry)//is null now
    1341             :     {
    1342           0 :         LwpDocument* pDoc = m_pFoundry->GetDocument();
    1343           0 :         if(pDoc)
    1344             :         {
    1345           0 :             if (pDoc->HonorProtection())
    1346           0 :                 return bProtected;
    1347             : 
    1348             :             /* If the document isn't honoring protection then we aren't protected.*/
    1349           0 :             return false;
    1350             :         }
    1351             :     }
    1352             : 
    1353           0 :     return bProtected;
    1354             : }
    1355             : 
    1356             : /**
    1357             : * @descr:   Get watermark layout
    1358             : *
    1359             : */
    1360         244 : LwpVirtualLayout* LwpMiddleLayout::GetWaterMarkLayout()
    1361             : {
    1362         244 :     LwpVirtualLayout* pLay = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
    1363         522 :     while(pLay)
    1364             :     {
    1365          34 :         if( pLay->IsForWaterMark())
    1366             :         {
    1367           0 :             return pLay;
    1368             :         }
    1369          34 :         pLay = dynamic_cast<LwpVirtualLayout*> (pLay->GetNext().obj().get());
    1370             :     }
    1371         244 :     return NULL;
    1372             : }
    1373             : 
    1374             : /**
    1375             : * @descr:   Create and reture xfbgimage object for watermark
    1376             : *
    1377             : */
    1378         244 : XFBGImage* LwpMiddleLayout::GetXFBGImage()
    1379             : {
    1380         244 :     LwpMiddleLayout* pLay = static_cast<LwpMiddleLayout*>(GetWaterMarkLayout());
    1381         244 :     if(pLay)
    1382             :     {
    1383             :         //test BGImage
    1384           0 :         LwpGraphicObject* pGrfObj = dynamic_cast<LwpGraphicObject*>(pLay->GetContent().obj().get());
    1385           0 :         if(pGrfObj)
    1386             :         {
    1387           0 :             XFBGImage* pXFBGImage = new XFBGImage();
    1388             : 
    1389           0 :             if(pGrfObj->IsLinked())
    1390             :             {
    1391             :                 //set file link
    1392           0 :                 OUString linkedfilepath = pGrfObj->GetLinkedFilePath();
    1393           0 :                 OUString fileURL = LwpTools::convertToFileUrl(OUStringToOString(linkedfilepath, osl_getThreadTextEncoding()));
    1394           0 :                 pXFBGImage->SetFileLink(fileURL);
    1395             :             }
    1396             :             else
    1397             :             {
    1398           0 :                 sal_uInt8* pGrafData = NULL;
    1399           0 :                 sal_uInt32 nDataLen = pGrfObj->GetRawGrafData(pGrafData);
    1400           0 :                 pXFBGImage->SetImageData(pGrafData, nDataLen);
    1401           0 :                 if(pGrafData)
    1402             :                 {
    1403           0 :                     delete[] pGrafData;
    1404           0 :                     pGrafData = NULL;
    1405             :                 }
    1406             :             }
    1407             : 
    1408             :             //automatic, top left
    1409           0 :             pXFBGImage->SetPosition(enumXFAlignStart,enumXFAlignTop);
    1410           0 :             if(pLay->GetScaleCenter())
    1411             :             {
    1412             :                 //center
    1413           0 :                 pXFBGImage->SetPosition(enumXFAlignCenter,enumXFAlignCenter);
    1414             :             }
    1415           0 :             else if(pLay->GetScaleTile())
    1416             :             {
    1417             :                 //tile
    1418           0 :                 pXFBGImage->SetRepeate();
    1419             :             }
    1420             :             //fit type, area type
    1421           0 :             if((pLay->GetScaleMode()& LwpLayoutScale::FIT_IN_FRAME)!=0)
    1422             :             {
    1423           0 :                 if((pLay->GetScaleMode()& LwpLayoutScale::MAINTAIN_ASPECT_RATIO)==0)
    1424             :                 {
    1425           0 :                     pXFBGImage->SetStretch();
    1426             :                 }
    1427             :             }
    1428           0 :             return pXFBGImage;
    1429             :         }
    1430             :     }
    1431         244 :     return NULL;
    1432             : }
    1433             : 
    1434             : /**
    1435             : * @descr:   Whether the page uses the printer setting
    1436             : *
    1437             : */
    1438         104 : bool LwpMiddleLayout::GetUsePrinterSettings()
    1439             : {
    1440         104 :     if(m_nOverrideFlag & OVER_SIZE)
    1441             :     {
    1442          58 :         return (m_nAttributes3 & STYLE3_USEPRINTERSETTINGS) != 0;
    1443             :     }
    1444          46 :     else if( !m_BasedOnStyle.IsNull() )
    1445             :     {
    1446          46 :         LwpMiddleLayout* pLay = dynamic_cast<LwpMiddleLayout*> ( m_BasedOnStyle.obj().get() );
    1447          46 :         return pLay ? pLay->GetUsePrinterSettings() : sal_False;
    1448             :     }
    1449           0 :     return false;
    1450             : }
    1451             : 
    1452             : //Check whether there are contents in the layout
    1453           0 : bool LwpMiddleLayout::HasContent()
    1454             : {
    1455           0 :     rtl::Reference<LwpObject> content = m_Content.obj();
    1456           0 :     if(content.is())
    1457           0 :         return true;
    1458           0 :     return false;
    1459             : }
    1460             : //End by
    1461             : 
    1462         144 : LwpLayout::LwpLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm ) :
    1463         144 :     LwpMiddleLayout(objHdr, pStrm), m_pUseWhen(new LwpUseWhen)
    1464         144 : {}
    1465             : 
    1466         288 : LwpLayout::~LwpLayout()
    1467             : {
    1468         144 :     if (m_pUseWhen)
    1469             :     {
    1470         144 :         delete m_pUseWhen;
    1471             :     }
    1472         144 : }
    1473             : 
    1474         144 : void LwpLayout::Read()
    1475             : {
    1476         144 :     LwpObjectStream* pStrm = m_pObjStrm;
    1477             : 
    1478         144 :     LwpMiddleLayout::Read();
    1479         144 :     if (LwpFileHeader::m_nFileRevision < 0x000B)
    1480             :     {
    1481             :         // read PreRevBLayout...
    1482             :     }
    1483             :     else
    1484             :     {
    1485         144 :         sal_uInt16 nSimple = pStrm->QuickReaduInt16();
    1486             : 
    1487         144 :         if (!nSimple)
    1488             :         {
    1489         138 :             m_pUseWhen->Read(pStrm);
    1490             : 
    1491         138 :             sal_uInt8 nFlag = pStrm->QuickReaduInt8();
    1492         138 :             if (nFlag)
    1493          52 :                 m_Positon.ReadIndexed(pStrm);
    1494             :         }
    1495             : 
    1496         144 :         m_LayColumns.ReadIndexed(pStrm);
    1497         144 :         m_LayGutterStuff.ReadIndexed(pStrm);
    1498         144 :         m_LayJoinStuff.ReadIndexed(pStrm);
    1499         144 :         m_LayShadow.ReadIndexed(pStrm);
    1500             : 
    1501         144 :         if (pStrm->CheckExtra())
    1502             :         {
    1503         120 :             m_LayExtJoinStuff.ReadIndexed(pStrm);
    1504         120 :             pStrm->SkipExtra();
    1505             :         }
    1506             :     }
    1507         144 : }
    1508             : 
    1509             : /**
    1510             : * @descr:   Get columns number
    1511             : *
    1512             : */
    1513         170 : sal_uInt16 LwpLayout::GetNumCols()
    1514             : {
    1515         170 :     if(m_nOverrideFlag & OVER_COLUMNS)
    1516             :     {
    1517          74 :         LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
    1518          74 :         if(pLayColumns)
    1519             :         {
    1520          74 :             return pLayColumns->GetNumCols();
    1521             :         }
    1522             :     }
    1523             : 
    1524          96 :     LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
    1525          96 :     if(pStyle)
    1526             :     {
    1527          96 :         return pStyle->GetNumCols();
    1528             :     }
    1529             : 
    1530           0 :     return LwpVirtualLayout::GetNumCols();
    1531             : 
    1532             : }
    1533             : 
    1534             : /**
    1535             : * @descr:   Get column width
    1536             : * @param:   the order of column
    1537             : */
    1538           0 : double LwpLayout::GetColWidth(sal_uInt16 nIndex)
    1539             : {
    1540           0 :     if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
    1541             :     {
    1542           0 :         LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
    1543           0 :         if(pLayColumns)
    1544             :         {
    1545           0 :             return pLayColumns->GetColWidth(nIndex);
    1546             :         }
    1547             :     }
    1548             : 
    1549           0 :     LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
    1550           0 :     if(pStyle)
    1551             :     {
    1552           0 :         return pStyle->GetColWidth(nIndex);
    1553             :     }
    1554             : 
    1555           0 :     return LwpVirtualLayout::GetColWidth(nIndex);
    1556             : 
    1557             : }
    1558             : 
    1559             : /**
    1560             : * @descr:   Get gap between columns
    1561             : * @param:   the order of column
    1562             : */
    1563           0 : double LwpLayout::GetColGap(sal_uInt16 nIndex)
    1564             : {
    1565           0 :     if((m_nOverrideFlag & OVER_COLUMNS)||(m_nAttributes2 & STYLE2_LOCALCOLUMNINFO))
    1566             :     {
    1567           0 :         LwpLayoutColumns* pLayColumns = dynamic_cast<LwpLayoutColumns*>(m_LayColumns.obj().get());
    1568           0 :         if(pLayColumns)
    1569             :         {
    1570           0 :             return pLayColumns->GetColGap(nIndex);
    1571             :         }
    1572             :     }
    1573             : 
    1574           0 :     LwpVirtualLayout* pStyle = dynamic_cast<LwpVirtualLayout*> (m_BasedOnStyle.obj().get());
    1575           0 :     if(pStyle)
    1576             :     {
    1577           0 :         return pStyle->GetColGap(nIndex);
    1578             :     }
    1579             : 
    1580           0 :     return LwpVirtualLayout::GetColGap(nIndex);
    1581             : }
    1582             : 
    1583             : /**
    1584             : * @descr:   Create and return XFColumns object
    1585             : *
    1586             : */
    1587          66 : XFColumns* LwpLayout::GetXFColumns()
    1588             : {
    1589             :     //if there is only one column, do not need insert columns
    1590          66 :     sal_uInt16 nCols = GetNumCols();
    1591          66 :     if(nCols==1)
    1592             :     {
    1593          66 :         return NULL;
    1594             :     }
    1595             : 
    1596           0 :     XFColumns* pColumns = new XFColumns();
    1597             :     //set XFColumnSep
    1598           0 :     boost::scoped_ptr<XFColumnSep> pColumnSep(GetColumnSep());
    1599           0 :     if(pColumnSep)
    1600             :     {
    1601           0 :         pColumns->SetSeparator(*pColumnSep);
    1602             :     }
    1603             : 
    1604             :     //set column count and column gap
    1605           0 :     pColumns->SetCount(nCols);
    1606           0 :     double fGap = GetColGap(0);
    1607           0 :     pColumns->SetGap(fGap);
    1608             : 
    1609             :     //set xfcolumn
    1610           0 :     for(sal_uInt16 nIndex = 0; nIndex<nCols; nIndex++)
    1611             :     {
    1612           0 :         XFColumn aColumn;
    1613           0 :         sal_Int32 nWidth = static_cast<sal_Int32>(GetColWidth(nIndex));
    1614           0 :         nWidth=8305/nCols;  //relative width
    1615           0 :         aColumn.SetRelWidth(nWidth);
    1616             : 
    1617             :         //the left and right margins is 0;
    1618           0 :         double nGap = GetColGap(nIndex)/2;
    1619             :         //nGap=0;
    1620           0 :         aColumn.SetMargins(nGap,nGap);
    1621           0 :         if(nIndex==0)
    1622             :         {
    1623           0 :             aColumn.SetMargins(0,nGap);
    1624             :         }
    1625           0 :         if(nIndex==(nCols-1))
    1626             :         {
    1627           0 :             aColumn.SetMargins(nGap,0);
    1628             :         }
    1629           0 :         pColumns->AddColumn(aColumn);
    1630             :     }
    1631             : 
    1632           0 :     return pColumns;
    1633             : }
    1634             : 
    1635             : /**
    1636             : * @descr:   Create and return XFColumnSep object
    1637             : *
    1638             : */
    1639           0 : XFColumnSep* LwpLayout::GetColumnSep()
    1640             : {
    1641             : 
    1642             :     //Get LwpLayoutGutters
    1643           0 :     LwpLayoutGutters* pLayoutGutters = dynamic_cast<LwpLayoutGutters*>(m_LayGutterStuff.obj().get());
    1644           0 :     if(!pLayoutGutters)
    1645             :     {
    1646           0 :         return NULL;
    1647             :     }
    1648             : 
    1649           0 :     LwpBorderStuff* pBorderStuff = pLayoutGutters->GetBorderStuff();
    1650             : 
    1651           0 :     if(pBorderStuff)
    1652             :     {
    1653           0 :         LwpBorderStuff::BorderType eType = LwpBorderStuff::LEFT;
    1654           0 :         LwpColor    aColor = pBorderStuff->GetSideColor(eType);
    1655           0 :         double  fWidth = pBorderStuff->GetSideWidth(eType);
    1656             :         //sal_uInt16    nType = pBorderStuff->GetSideType(eType);
    1657             : 
    1658           0 :         XFColumnSep* pColumnSep = new XFColumnSep();
    1659           0 :         XFColor aXFColor(aColor.To24Color());
    1660           0 :         pColumnSep->SetColor(aXFColor);
    1661           0 :         pColumnSep->SetWidth(fWidth);
    1662           0 :         pColumnSep->SetRelHeight(100);
    1663           0 :         pColumnSep->SetVerticalAlign(enumXFAlignTop);
    1664             : 
    1665           0 :         return pColumnSep;
    1666             :     }
    1667           0 :     return NULL;
    1668             : 
    1669             : }
    1670             : 
    1671             : /**
    1672             : * @descr:   Get use when type
    1673             : *
    1674             : */
    1675           8 : LwpLayout::UseWhenType LwpLayout::GetUseWhenType()
    1676             : {
    1677           8 :     UseWhenType eType = StartWithinPage;
    1678           8 :     LwpUseWhen* pUseWhen = GetUseWhen();
    1679           8 :     if(pUseWhen)
    1680             :     {
    1681           8 :         if(pUseWhen->IsStartOnThisHF())
    1682             :         {
    1683           0 :             eType =  StartWithinColume;
    1684             :         }
    1685           8 :         else if(pUseWhen->IsStartOnThisPage())
    1686             :         {
    1687           0 :             eType =  StartWithinPage;
    1688             :         }
    1689           8 :         else if(pUseWhen->IsStartOnNextPage())
    1690             :         {
    1691           8 :             eType = StartOnNextPage;
    1692             :         }
    1693           0 :         else if(pUseWhen->IsStartOnNextOddPage())
    1694             :         {
    1695           0 :             eType =  StartOnOddPage;
    1696             :         }
    1697           0 :         else if(pUseWhen->IsStartOnNextEvenPage())
    1698             :         {
    1699           0 :             eType =   StartOnEvenPage;
    1700             :         }
    1701             : 
    1702             :     }
    1703             :     else
    1704             :     {
    1705           0 :         eType =   StartOnNextPage;
    1706             :     }
    1707           8 :     return eType;
    1708             : }
    1709             : 
    1710             : /**
    1711             : * @descr:   Get use page
    1712             : *
    1713             : */
    1714           0 : sal_uInt16 LwpLayout::GetUsePage()
    1715             : {
    1716           0 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1717             :     {
    1718           0 :         LwpUseWhen* pUseWhen = GetUseWhen();
    1719           0 :         if(pUseWhen)
    1720           0 :             return pUseWhen->GetUsePage();
    1721             :         else
    1722           0 :             return 0;
    1723             :     }
    1724           0 :     else if( !m_BasedOnStyle.IsNull() )
    1725             :     {
    1726           0 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1727           0 :         return pLay ? pLay->GetUsePage() : 0;
    1728             :     }
    1729           0 :     return 0;
    1730             : }
    1731             : 
    1732             : /**
    1733             : * @descr:   Get usewhen pointer
    1734             : *
    1735             : */
    1736          32 : LwpUseWhen* LwpLayout::VirtualGetUseWhen()
    1737             : {
    1738          32 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1739             :     {
    1740          24 :         return m_pUseWhen;
    1741             :     }
    1742           8 :     else if( !m_BasedOnStyle.IsNull() )
    1743             :     {
    1744           8 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1745           8 :         return pLay ? pLay->VirtualGetUseWhen() : NULL;
    1746             :     }
    1747           0 :     return LwpVirtualLayout::VirtualGetUseWhen();
    1748             : }
    1749             : 
    1750             : /**
    1751             : * @descr:   Whether it is use on all pages
    1752             : *
    1753             : */
    1754           0 : bool LwpLayout::IsUseOnAllPages()
    1755             : {
    1756           0 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1757             :     {
    1758           0 :         LwpUseWhen* pUseWhen = GetUseWhen();
    1759           0 :         if(pUseWhen)
    1760           0 :             return pUseWhen->IsUseOnAllPages();
    1761             :         else
    1762           0 :             return false;
    1763             :     }
    1764           0 :     else if( !m_BasedOnStyle.IsNull() )
    1765             :     {
    1766           0 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1767           0 :         if (pLay)
    1768           0 :             return pLay->IsUseOnAllPages();
    1769             :     }
    1770           0 :     return LwpVirtualLayout::IsUseOnAllPages();
    1771             : }
    1772             : 
    1773             : /**
    1774             : * @descr:   Whether it is use on all even pages
    1775             : *
    1776             : */
    1777           0 : bool LwpLayout::IsUseOnAllEvenPages()
    1778             : {
    1779           0 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1780             :     {
    1781           0 :         LwpUseWhen* pUseWhen = GetUseWhen();
    1782           0 :         if(pUseWhen)
    1783           0 :             return pUseWhen->IsUseOnAllEvenPages();
    1784             :         else
    1785           0 :             return false;
    1786             :     }
    1787           0 :     else if( !m_BasedOnStyle.IsNull() )
    1788             :     {
    1789           0 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1790           0 :         if (pLay)
    1791           0 :             return pLay->IsUseOnAllEvenPages();
    1792             :     }
    1793           0 :     return LwpVirtualLayout::IsUseOnAllEvenPages();
    1794             : }
    1795             : 
    1796             : /**
    1797             : * @descr:   Whether it is use on all odd pages
    1798             : *
    1799             : */
    1800           0 : bool LwpLayout::IsUseOnAllOddPages()
    1801             : {
    1802           0 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1803             :     {
    1804           0 :         LwpUseWhen* pUseWhen = GetUseWhen();
    1805           0 :         if(pUseWhen)
    1806           0 :             return pUseWhen->IsUseOnAllOddPages();
    1807             :         else
    1808           0 :             return false;
    1809             :     }
    1810           0 :     else if( !m_BasedOnStyle.IsNull() )
    1811             :     {
    1812           0 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1813           0 :         if (pLay)
    1814           0 :             return pLay->IsUseOnAllOddPages();
    1815             :     }
    1816           0 :     return LwpVirtualLayout::IsUseOnAllOddPages();
    1817             : }
    1818             : 
    1819             : /**
    1820             : * @descr:   Whether it is use on current page
    1821             : *
    1822             : */
    1823           0 : bool LwpLayout::IsUseOnPage()
    1824             : {
    1825           0 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1826             :     {
    1827           0 :         LwpUseWhen* pUseWhen = GetUseWhen();
    1828           0 :         if(pUseWhen)
    1829           0 :             return pUseWhen->IsUseOnPage();
    1830             :         else
    1831           0 :             return false;
    1832             :     }
    1833           0 :     else if( !m_BasedOnStyle.IsNull() )
    1834             :     {
    1835           0 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1836           0 :         if (pLay)
    1837           0 :             return pLay->IsUseOnPage();
    1838             :     }
    1839           0 :     return LwpVirtualLayout::IsUseOnPage();
    1840             : }
    1841             : 
    1842             : /**
    1843             :  * @descr:  Get the LwpShadow object according to m_LayShadow id.
    1844             :  * @param:
    1845             :  * @param:
    1846             :  * @return:
    1847             : */
    1848         234 : LwpShadow* LwpLayout::GetShadow()
    1849             : {
    1850         234 :     if(m_nOverrideFlag & OVER_SHADOW)
    1851             :     {
    1852          98 :         LwpLayoutShadow* pLayoutShadow = dynamic_cast<LwpLayoutShadow*>(m_LayShadow.obj().get());
    1853          98 :         return pLayoutShadow ? &pLayoutShadow->GetShadow() : NULL;
    1854             :     }
    1855         136 :     else if( !m_BasedOnStyle.IsNull() )
    1856             :     {
    1857         134 :         LwpLayout* pLay = dynamic_cast<LwpLayout*> ( m_BasedOnStyle.obj().get() );
    1858         134 :         return pLay ? pLay->GetShadow() : NULL;
    1859             :     }
    1860           2 :     return NULL;
    1861             : }
    1862             : 
    1863             : /**
    1864             :  * @descr:  create xfshadow
    1865             :  * @param:
    1866             :  * @param:
    1867             :  * @return:
    1868             : */
    1869         100 : XFShadow* LwpLayout::GetXFShadow()
    1870             : {
    1871         100 :     LwpShadow* pShadow = GetShadow();
    1872         100 :     if( pShadow )
    1873             :     {
    1874          98 :         LwpColor color = pShadow->GetColor();
    1875          98 :         double  offsetX = pShadow->GetOffsetX();
    1876          98 :         double  offsetY = pShadow->GetOffsetY();
    1877             : 
    1878          98 :         if( offsetX && offsetY && color.IsValidColor() )
    1879             :         {
    1880           0 :             XFShadow* pXFShadow = new XFShadow();
    1881           0 :             enumXFShadowPos eXFShadowPos = enumXFShadowLeftTop;
    1882           0 :             double fOffset = 0;
    1883             : 
    1884           0 :             bool left = false;
    1885           0 :             bool top = false;
    1886           0 :             if( offsetX < 0 )
    1887           0 :                 left = true;
    1888           0 :             if( offsetY < 0 )
    1889           0 :                 top = true;
    1890           0 :             if( left )
    1891             :             {
    1892           0 :                 fOffset = -offsetX;
    1893           0 :                 if( top )
    1894           0 :                     eXFShadowPos = enumXFShadowLeftTop;
    1895             :                 else
    1896           0 :                     eXFShadowPos = enumXFShadowLeftBottom;
    1897             :             }
    1898             :             else
    1899             :             {
    1900           0 :                 fOffset = offsetX;
    1901           0 :                 if( top )
    1902           0 :                     eXFShadowPos = enumXFShadowRightTop;
    1903             :                 else
    1904           0 :                     eXFShadowPos = enumXFShadowRightBottom;
    1905             :             }
    1906             : 
    1907           0 :             pXFShadow->SetPosition(eXFShadowPos);
    1908           0 :             pXFShadow->SetOffset(fOffset);
    1909           0 :             pXFShadow->SetColor(XFColor(color.To24Color()));
    1910             : 
    1911           0 :             return pXFShadow;
    1912          98 :         }
    1913             :     }
    1914         100 :     return NULL;
    1915             : }
    1916             : 
    1917             : /**
    1918             :  * @descr get the layout that containers the current frame layout
    1919             :  *
    1920             :  */
    1921         134 : LwpVirtualLayout* LwpLayout::GetContainerLayout()
    1922             : {
    1923         134 :     if(IsRelativeAnchored())
    1924             :     {
    1925             :         //get position
    1926         134 :         LwpPara* pPara = dynamic_cast<LwpPara*>(GetPosition().obj().get());
    1927         134 :         if(pPara)
    1928             :         {
    1929         134 :             LwpStory* pStory = pPara->GetStory();
    1930         134 :             return pStory ? pStory->GetTabLayout() : NULL;
    1931             :         }
    1932             :     }
    1933           0 :     return GetParentLayout();
    1934             : }
    1935             : 
    1936         124 : LwpPlacableLayout::LwpPlacableLayout( LwpObjectHeader &objHdr, LwpSvStream* pStrm )
    1937             :     : LwpLayout(objHdr, pStrm)
    1938             :     , m_nWrapType(0)
    1939             :     , m_nBuoyancy(0)
    1940             :     , m_nBaseLineOffset(0)
    1941         124 :     , m_nPageNumber(0)
    1942         124 : {}
    1943             : 
    1944         124 : LwpPlacableLayout::~LwpPlacableLayout()
    1945         124 : {}
    1946             : 
    1947         124 : void LwpPlacableLayout::Read()
    1948             : {
    1949         124 :     LwpObjectStream* pStrm = m_pObjStrm;
    1950         124 :     LwpLayout::Read();
    1951         124 :     if(LwpFileHeader::m_nFileRevision < 0x000B)
    1952             :     {
    1953             :         assert(false);
    1954             :     }
    1955             :     else
    1956             :     {
    1957         124 :         sal_uInt16 simple = pStrm->QuickReaduInt16();
    1958         124 :         if(!simple)
    1959             :         {
    1960          60 :             m_nWrapType = pStrm->QuickReaduInt8();
    1961          60 :             m_nBuoyancy = pStrm->QuickReaduInt8();
    1962          60 :             m_nBaseLineOffset = pStrm->QuickReadInt32();
    1963          60 :             m_Script.Read( pStrm);
    1964             :         }
    1965             :         else
    1966             :         {
    1967          64 :             m_nWrapType = LAY_WRAP_AROUND;
    1968          64 :             m_nBuoyancy = LAY_BUOYNEUTRAL;
    1969          64 :             m_nBaseLineOffset    = 0;
    1970             :         }
    1971         124 :         m_LayRelativity.ReadIndexed( pStrm);
    1972         124 :         if(pStrm->CheckExtra())
    1973             :         {
    1974         104 :             sal_uInt16 count = pStrm->QuickReaduInt16();
    1975         104 :             if(count)
    1976             :             {
    1977             :                 // temporily added by  to avoid assertion
    1978           0 :                 while (count)
    1979             :                 {
    1980           0 :                     LwpPoint aPoint;
    1981           0 :                     aPoint.Read(pStrm);
    1982           0 :                     count--;
    1983             :                 }
    1984             :                 // end added by
    1985             :             }
    1986         104 :             pStrm->SkipExtra();
    1987             :         }
    1988             :     }
    1989         124 : }
    1990             : /**
    1991             :  * @descr:  get wrap type
    1992             :  * @param:
    1993             :  * @param:
    1994             :  * @return:
    1995             : */
    1996          50 : sal_uInt8 LwpPlacableLayout::GetWrapType()
    1997             : {
    1998          50 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    1999             :     {
    2000          50 :         return m_nWrapType;
    2001             :     }
    2002           0 :     else if( !m_BasedOnStyle.IsNull() )
    2003             :     {
    2004           0 :         LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj().get() );
    2005           0 :         if (pLay)
    2006           0 :             return pLay->GetWrapType();
    2007             :     }
    2008           0 :     return LAY_WRAP_AROUND;
    2009             : }
    2010             : /**
    2011             :  * @descr:  get LayoutRelativity
    2012             :  * @param:
    2013             :  * @param:
    2014             :  * @return:
    2015             : */
    2016         566 : LwpLayoutRelativity* LwpPlacableLayout::GetRelativityPiece()
    2017             : {
    2018         566 :     if(!m_LayRelativity.IsNull())
    2019             :     {
    2020         566 :         if(m_nOverrideFlag & OVER_PLACEMENT)
    2021             :         {
    2022         566 :             return dynamic_cast<LwpLayoutRelativity*>(m_LayRelativity.obj().get());
    2023             :         }
    2024             :     }
    2025           0 :     else if( !m_BasedOnStyle.IsNull() )
    2026             :     {
    2027           0 :         LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj().get() );
    2028           0 :         return pLay ? pLay->GetRelativityPiece() : NULL;
    2029             :     }
    2030           0 :     return NULL;
    2031             : }
    2032             : /**
    2033             : * @descr:   Get relative type
    2034             : *
    2035             : */
    2036         566 : sal_uInt8 LwpPlacableLayout::GetRelativeType()
    2037             : {
    2038         566 :     LwpLayoutRelativity* pLayRel = GetRelativityPiece();
    2039         566 :     if(pLayRel)
    2040             :     {
    2041         566 :         return pLayRel->GetRelGuts().GetRelativeType();
    2042             :     }
    2043           0 :     return LwpVirtualLayout::GetRelativeType();
    2044             : }
    2045             : /**
    2046             : * @descr:   Get offset from the baseline
    2047             : *
    2048             : */
    2049           0 : sal_Int32 LwpPlacableLayout::GetBaseLineOffset()
    2050             : {
    2051             :     /* The baseline is only valid if this is flow-with-text */
    2052           0 :     if(GetRelativeType()!=LwpLayoutRelativityGuts::LAY_INLINE)
    2053             :     {
    2054           0 :         return 0;
    2055             :     }
    2056             : 
    2057             :     // First, ask our content if it has a baseline, ignore now
    2058             :     /*
    2059             :     if (Content && Content->GetBaseLineOffset(&Baseline))
    2060             :         return Baseline;
    2061             :     */
    2062             : 
    2063           0 :     if(m_nOverrideFlag & OVER_PLACEMENT)
    2064             :     {
    2065           0 :         return m_nBaseLineOffset;
    2066             :     }
    2067           0 :     else if( !m_BasedOnStyle.IsNull() )
    2068             :     {
    2069           0 :         LwpPlacableLayout* pLay = dynamic_cast<LwpPlacableLayout*> ( m_BasedOnStyle.obj().get() );
    2070           0 :         return pLay ? pLay->GetBaseLineOffset() : 0;
    2071             :     }
    2072           0 :     return 0;
    2073             : 
    2074             : }
    2075             : /**
    2076             : * @descr:   whether the parent layout is page layout
    2077             : *
    2078             : */
    2079          24 : bool LwpPlacableLayout::IsAnchorPage()
    2080             : {
    2081          24 :     if(IsRelativeAnchored())
    2082           0 :         return false;
    2083             : 
    2084          24 :     LwpVirtualLayout* pLayout = GetParentLayout();
    2085          24 :     if(pLayout && (pLayout->IsPage() || pLayout->IsHeader() || pLayout->IsFooter()))
    2086             :     //if(pLayout && pLayout->IsPage())
    2087             :     {
    2088          24 :         return true;
    2089             :     }
    2090           0 :     return false;
    2091             : }
    2092             : /**
    2093             : * @descr:   whether the parent layout is frame layout
    2094             : *
    2095             : */
    2096          12 : bool LwpPlacableLayout::IsAnchorFrame()
    2097             : {
    2098          12 :     if(IsRelativeAnchored())
    2099           0 :         return false;
    2100             : 
    2101          12 :     LwpVirtualLayout* pLayout = GetParentLayout();
    2102          12 :     if(pLayout && (pLayout->IsFrame()||pLayout->IsGroupHead()))
    2103             :     {
    2104           0 :         return true;
    2105             :     }
    2106          12 :     return false;
    2107             : }
    2108             : /**
    2109             : * @descr:   whether the parent layout is cell layout
    2110             : *
    2111             : */
    2112          12 : bool LwpPlacableLayout::IsAnchorCell()
    2113             : {
    2114          12 :     if(IsRelativeAnchored())
    2115           0 :         return false;
    2116             : 
    2117          12 :     LwpVirtualLayout* pLayout = GetParentLayout();
    2118          12 :     if(pLayout && pLayout->IsCell())
    2119             :     {
    2120           0 :         return true;
    2121             :     }
    2122          12 :     return false;
    2123             : }
    2124             : 
    2125             : /**
    2126             : * @descr:   Set font style for setting position of frame
    2127             : *
    2128             : */
    2129          50 : void LwpPlacableLayout::SetFont(rtl::Reference<XFFont> const & pFont)
    2130             : {
    2131          50 :     m_pFont = pFont;
    2132          56 : }
    2133             : 
    2134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10