LCOV - code coverage report
Current view: top level - libreoffice/lotuswordpro/source/filter/xfilter - xfcellstyle.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 87 126 69.0 %
Date: 2012-12-27 Functions: 8 10 80.0 %
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             :  * Table cell style. Number format, string value, and so on...
      59             :  ************************************************************************/
      60             : #include    "xfcellstyle.hxx"
      61             : #include    "xfborders.hxx"
      62             : #include    "xffont.hxx"
      63             : #include    "xfbgimage.hxx"
      64             : 
      65             : 
      66          75 : XFCellStyle::XFCellStyle()
      67             : {
      68          75 :     m_eHoriAlign = enumXFAlignNone;
      69          75 :     m_eVertAlign = enumXFAlignNone;
      70          75 :     m_fTextIndent = 0;
      71          75 :     m_pBorders = NULL;
      72          75 :     m_pFont = NULL;
      73          75 :     m_pBackImage = NULL;
      74          75 :     m_bWrapText = sal_False;
      75          75 : }
      76             : 
      77         225 : XFCellStyle::~XFCellStyle()
      78             : {
      79          75 :     if( m_pBorders )
      80          19 :         delete m_pBorders;
      81         150 : }
      82             : 
      83          75 : void XFCellStyle::SetPadding(double left, double right,double top, double bottom)
      84             : {
      85          75 :     if( left != -1 )
      86          75 :         m_aPadding.SetLeft(left);
      87          75 :     if( right != -1 )
      88          75 :         m_aPadding.SetRight(right);
      89          75 :     if( top != -1 )
      90          75 :         m_aPadding.SetTop(top);
      91          75 :     if( bottom != -1 )
      92          75 :         m_aPadding.SetBottom( bottom );
      93          75 : }
      94             : 
      95           0 : void    XFCellStyle::SetBackColor(XFColor& color)
      96             : {
      97           0 :     m_aBackColor = color;
      98           0 : }
      99             : 
     100           0 : void    XFCellStyle::SetBackImage(XFBGImage *pImage)
     101             : {
     102           0 :     if( m_pBackImage )
     103           0 :         delete m_pBackImage;
     104           0 :     m_pBackImage = pImage;
     105           0 : }
     106             : 
     107          19 : void    XFCellStyle::SetBorders(XFBorders *pBorders)
     108             : {
     109          19 :     if( m_pBorders )
     110           0 :         delete m_pBorders;
     111          19 :     m_pBorders = pBorders;
     112          19 : }
     113             : 
     114        1487 : enumXFStyle XFCellStyle::GetStyleFamily()
     115             : {
     116        1487 :     return enumXFStyleTableCell;
     117             : }
     118             : 
     119             : /**
     120             :  *Affirm whether two XFCellStyle objects are equal.
     121             :  */
     122         212 : sal_Bool    XFCellStyle::Equal(IXFStyle *pStyle)
     123             : {
     124         212 :     if( this == pStyle )
     125           0 :         return sal_True;
     126         212 :     if( !pStyle || pStyle->GetStyleFamily() != enumXFStyleTableCell )
     127           0 :         return sal_False;
     128             : 
     129         212 :     XFCellStyle *pOther = static_cast<XFCellStyle*>(pStyle);
     130         212 :     if( !pOther )
     131           0 :         return sal_False;
     132             : 
     133         212 :     if( m_strDataStyle != pOther->m_strDataStyle )
     134          81 :         return sal_False;
     135             : 
     136         131 :     if( m_strParentStyleName != pOther->m_strParentStyleName )
     137           0 :         return sal_False;
     138         131 :     if( m_fTextIndent != pOther->m_fTextIndent )
     139           0 :         return sal_False;
     140             : 
     141             :     //align:
     142         131 :     if( m_eHoriAlign != pOther->m_eHoriAlign )
     143           0 :         return sal_False;
     144         131 :     if( m_eVertAlign != pOther->m_eVertAlign )
     145           0 :         return sal_False;
     146             : 
     147         131 :     if( m_aBackColor != pOther->m_aBackColor )
     148           0 :         return sal_False;
     149             :     //shadow:
     150         131 :     if( m_aShadow != pOther->m_aShadow )
     151           0 :         return sal_False;
     152             :     //margin:
     153         131 :     if( m_aMargin != pOther->m_aMargin )
     154           0 :         return sal_False;
     155             :     //padding:
     156         131 :     if( m_aPadding != pOther->m_aPadding )
     157          48 :         return sal_False;
     158             : 
     159             :     //wrap:
     160          83 :     if( m_bWrapText != pOther->m_bWrapText )
     161           0 :         return sal_False;
     162             : 
     163             :     //font:
     164          83 :     if( m_pFont )
     165             :     {
     166           0 :         if( !pOther->m_pFont )
     167           0 :             return sal_False;
     168           0 :         if(*m_pFont != *pOther->m_pFont )
     169           0 :             return sal_False;
     170             :     }
     171          83 :     else if( pOther->m_pFont )
     172           0 :         return sal_False;
     173             : 
     174             :     //border:
     175          83 :     if( m_pBorders )
     176             :     {
     177          33 :         if( !pOther->m_pBorders )
     178           0 :             return sal_False;
     179          33 :         if( *m_pBorders != *pOther->m_pBorders )
     180          30 :             return sal_False;
     181             :     }
     182          50 :     else if( pOther->m_pBorders )
     183           8 :         return sal_False;
     184             : 
     185             :     //if there is backimage
     186          45 :     if( m_pBackImage )
     187             :     {
     188           0 :         if( !pOther->m_pBackImage )
     189           0 :             return sal_False;
     190           0 :         if( !m_pBackImage->Equal(pOther) )
     191           0 :             return sal_False;
     192             :     }
     193             :     else
     194             :     {
     195          45 :         if( pOther->m_pBackImage )
     196           0 :             return sal_False;
     197             :     }
     198             : 
     199          45 :     return sal_True;
     200             : }
     201             : 
     202          22 : void XFCellStyle::ToXml(IXFStream *pStrm)
     203             : {
     204          22 :     IXFAttrList *pAttrList = pStrm->GetAttrList();
     205          22 :     rtl::OUString style = GetStyleName();
     206             : 
     207          22 :     pAttrList->Clear();
     208          22 :     if( !style.isEmpty() )
     209          22 :         pAttrList->AddAttribute(A2OUSTR("style:name"),GetStyleName());
     210          22 :     if( !GetParentStyleName().isEmpty() )
     211           0 :         pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),GetParentStyleName());
     212             : 
     213          22 :     pAttrList->AddAttribute(A2OUSTR("style:family"), A2OUSTR("table-cell"));
     214          22 :     if( !m_strParentStyleName.isEmpty() )
     215           0 :         pAttrList->AddAttribute(A2OUSTR("style:parent-style-name"),m_strParentStyleName);
     216          22 :     if( !m_strDataStyle.isEmpty() )
     217          13 :         pAttrList->AddAttribute( A2OUSTR("style:data-style-name"), m_strDataStyle );
     218             : 
     219          22 :     pStrm->StartElement(A2OUSTR("style:style"));
     220             : 
     221             :     //Paragraph properties:
     222          22 :     pAttrList->Clear();
     223             : 
     224             :     //text indent:
     225          22 :     if( m_fTextIndent>FLOAT_MIN )
     226             :     {
     227           0 :         pAttrList->AddAttribute(A2OUSTR("fo:text-indent"), DoubleToOUString(m_fTextIndent) + A2OUSTR("cm") );
     228             :     }
     229             :     //padding:
     230          22 :     m_aPadding.ToXml(pStrm);
     231             :     //margin:
     232          22 :     m_aMargin.ToXml(pStrm);
     233             : 
     234             :     //text horizontal align:
     235          22 :     if( m_eHoriAlign != enumXFAlignNone )
     236             :     {
     237           0 :         pAttrList->AddAttribute(A2OUSTR("fo:text-align"), GetAlignName(m_eHoriAlign) );
     238             :     }
     239             :     //text vertical align
     240          22 :     if( m_eVertAlign != enumXFAlignNone )
     241          22 :         pAttrList->AddAttribute( A2OUSTR("fo:vertical-align"), GetAlignName(m_eVertAlign) );
     242             : 
     243             :     //wrap text:
     244          22 :     if( m_bWrapText )
     245           0 :         pAttrList->AddAttribute( A2OUSTR("fo:wrap-option"), A2OUSTR("wrap") );
     246             : 
     247             :     //shadow:
     248          22 :     m_aShadow.ToXml(pStrm);
     249             :     //borders:
     250          22 :     if( m_pBorders )
     251          12 :         m_pBorders->ToXml(pStrm);
     252             : 
     253             :     //background color:
     254          22 :     if( m_aBackColor.IsValid() && !m_pBackImage )
     255             :     {
     256           0 :         pAttrList->AddAttribute(A2OUSTR("fo:background-color"), m_aBackColor.ToString() );
     257             :     }
     258             :     //Font properties:
     259          22 :     if( m_pFont )
     260           0 :         m_pFont->ToXml(pStrm);
     261             : 
     262          22 :     pStrm->StartElement(A2OUSTR("style:properties"));
     263             : 
     264          22 :     if( m_pBackImage )
     265           0 :         m_pBackImage->ToXml(pStrm);
     266             : 
     267          22 :     pStrm->EndElement(A2OUSTR("style:properties"));
     268             : 
     269          22 :     pStrm->EndElement(A2OUSTR("style:style"));
     270          22 : }
     271             : 
     272             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10