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

Generated by: LCOV version 1.10