LCOV - code coverage report
Current view: top level - editeng/source/items - justifyitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 111 171 64.9 %
Date: 2014-11-03 Functions: 22 37 59.5 %
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             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "editeng/justifyitem.hxx"
      21             : #include "editeng/memberids.hrc"
      22             : #include "editeng/editrids.hrc"
      23             : #include "editeng/eerdll.hxx"
      24             : 
      25             : #include <tools/stream.hxx>
      26             : 
      27             : #include <com/sun/star/table/CellHoriJustify.hpp>
      28             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      29             : #include <com/sun/star/table/CellJustifyMethod.hpp>
      30             : #include <com/sun/star/table/CellVertJustify2.hpp>
      31             : #include <com/sun/star/style/VerticalAlignment.hpp>
      32             : 
      33             : 
      34       11004 : TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0) );
      35      664852 : TYPEINIT1_FACTORY( SvxVerJustifyItem, SfxEnumItem, new SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, 0) );
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : 
      40             : 
      41           0 : SvxHorJustifyItem::SvxHorJustifyItem( const sal_uInt16 nId ) :
      42           0 :     SfxEnumItem( nId, (sal_uInt16)SVX_HOR_JUSTIFY_STANDARD )
      43             : {
      44           0 : }
      45             : 
      46        6715 : SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
      47             :                                       const sal_uInt16 nId ) :
      48        6715 :     SfxEnumItem( nId, (sal_uInt16)eJustify )
      49             : {
      50        6715 : }
      51             : 
      52             : 
      53           0 : bool SvxHorJustifyItem::GetPresentation
      54             : (
      55             :     SfxItemPresentation /*ePres*/,
      56             :     SfxMapUnit          /*eCoreUnit*/,
      57             :     SfxMapUnit          /*ePresUnit*/,
      58             :     OUString&           rText, const IntlWrapper *)    const
      59             : {
      60           0 :     rText = GetValueText( GetValue() );
      61           0 :     return true;
      62             : }
      63             : 
      64             : 
      65         392 : bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
      66             : {
      67         392 :     nMemberId &= ~CONVERT_TWIPS;
      68         392 :     switch ( nMemberId )
      69             :     {
      70             :         case MID_HORJUST_HORJUST:
      71             :             {
      72         204 :                 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
      73         204 :                 switch ( (SvxCellHorJustify)GetValue() )
      74             :                 {
      75           8 :                     case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
      76          42 :                     case SVX_HOR_JUSTIFY_LEFT:     eUno = table::CellHoriJustify_LEFT;     break;
      77          80 :                     case SVX_HOR_JUSTIFY_CENTER:   eUno = table::CellHoriJustify_CENTER;   break;
      78          44 :                     case SVX_HOR_JUSTIFY_RIGHT:    eUno = table::CellHoriJustify_RIGHT;    break;
      79          30 :                     case SVX_HOR_JUSTIFY_BLOCK:    eUno = table::CellHoriJustify_BLOCK;    break;
      80           0 :                     case SVX_HOR_JUSTIFY_REPEAT:   eUno = table::CellHoriJustify_REPEAT;   break;
      81             :                 }
      82         204 :                 rVal <<= eUno;
      83             :             }
      84         204 :             break;
      85             :         case MID_HORJUST_ADJUST:
      86             :             {
      87             :                 //  ParagraphAdjust values, as in SvxAdjustItem
      88             :                 //  (same value for ParaAdjust and ParaLastLineAdjust)
      89             : 
      90         188 :                 sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
      91         188 :                 switch ( (SvxCellHorJustify)GetValue() )
      92             :                 {
      93             :                     // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
      94             :                     case SVX_HOR_JUSTIFY_STANDARD:
      95             :                     case SVX_HOR_JUSTIFY_REPEAT:
      96          26 :                     case SVX_HOR_JUSTIFY_LEFT:   nAdjust = style::ParagraphAdjust_LEFT;   break;
      97         104 :                     case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
      98          48 :                     case SVX_HOR_JUSTIFY_RIGHT:  nAdjust = style::ParagraphAdjust_RIGHT;  break;
      99          10 :                     case SVX_HOR_JUSTIFY_BLOCK:  nAdjust = style::ParagraphAdjust_BLOCK;  break;
     100             :                 }
     101         188 :                 rVal <<= nAdjust;       // as sal_Int16
     102             :             }
     103         188 :             break;
     104             :     }
     105         392 :     return true;
     106             : }
     107             : 
     108         630 : bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     109             : {
     110         630 :     nMemberId &= ~CONVERT_TWIPS;
     111         630 :     switch ( nMemberId )
     112             :     {
     113             :         case MID_HORJUST_HORJUST:
     114             :             {
     115             :                 table::CellHoriJustify eUno;
     116         614 :                 if(!(rVal >>= eUno))
     117             :                 {
     118         120 :                     sal_Int32 nValue = 0;
     119         120 :                     if(!(rVal >>= nValue))
     120         120 :                         return false;
     121           0 :                     eUno = (table::CellHoriJustify)nValue;
     122             :                 }
     123         494 :                 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
     124         494 :                 switch (eUno)
     125             :                 {
     126          24 :                     case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
     127          34 :                     case table::CellHoriJustify_LEFT:     eSvx = SVX_HOR_JUSTIFY_LEFT;     break;
     128         358 :                     case table::CellHoriJustify_CENTER:   eSvx = SVX_HOR_JUSTIFY_CENTER;   break;
     129          58 :                     case table::CellHoriJustify_RIGHT:    eSvx = SVX_HOR_JUSTIFY_RIGHT;    break;
     130          18 :                     case table::CellHoriJustify_BLOCK:    eSvx = SVX_HOR_JUSTIFY_BLOCK;    break;
     131           2 :                     case table::CellHoriJustify_REPEAT:   eSvx = SVX_HOR_JUSTIFY_REPEAT;   break;
     132             :                     default: ; //prevent warning
     133             :                 }
     134         494 :                 SetValue( (sal_uInt16)eSvx );
     135             :             }
     136         494 :             break;
     137             :         case MID_HORJUST_ADJUST:
     138             :             {
     139             :                 //  property contains ParagraphAdjust values as sal_Int16
     140          16 :                 sal_Int16 nVal = sal_Int16();
     141          16 :                 if(!(rVal >>= nVal))
     142           0 :                     return false;
     143             : 
     144          16 :                 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
     145          16 :                 switch (nVal)
     146             :                 {
     147             :                     //  STRETCH is treated as BLOCK
     148           0 :                     case style::ParagraphAdjust_LEFT:    eSvx = SVX_HOR_JUSTIFY_LEFT;   break;
     149          10 :                     case style::ParagraphAdjust_RIGHT:   eSvx = SVX_HOR_JUSTIFY_RIGHT;  break;
     150             :                     case style::ParagraphAdjust_STRETCH:
     151           4 :                     case style::ParagraphAdjust_BLOCK:   eSvx = SVX_HOR_JUSTIFY_BLOCK;  break;
     152           2 :                     case style::ParagraphAdjust_CENTER:  eSvx = SVX_HOR_JUSTIFY_CENTER; break;
     153             :                 }
     154          16 :                 SetValue( (sal_uInt16)eSvx );
     155             :             }
     156             :     }
     157         510 :     return true;
     158             : }
     159             : 
     160             : 
     161           0 : OUString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal ) const
     162             : {
     163             :     DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
     164           0 :     return EE_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
     165             : }
     166             : 
     167             : 
     168        2110 : SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
     169             : {
     170        2110 :     return new SvxHorJustifyItem( *this );
     171             : }
     172             : 
     173             : 
     174         512 : SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
     175             : {
     176             :     sal_uInt16 nVal;
     177         512 :     rStream.ReadUInt16( nVal );
     178         512 :     return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
     179             : }
     180             : 
     181             : 
     182           0 : sal_uInt16 SvxHorJustifyItem::GetValueCount() const
     183             : {
     184           0 :     return SVX_HOR_JUSTIFY_REPEAT + 1;  // Last Enum value + 1
     185             : }
     186             : 
     187             : 
     188           0 : SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
     189           0 :     SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
     190             : {
     191           0 : }
     192             : 
     193        5912 : SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
     194             :                                       const sal_uInt16 nId ) :
     195        5912 :     SfxEnumItem( nId, (sal_uInt16)eJustify )
     196             : {
     197        5912 : }
     198             : 
     199             : 
     200           0 : bool SvxVerJustifyItem::GetPresentation
     201             : (
     202             :     SfxItemPresentation /*ePres*/,
     203             :     SfxMapUnit          /*eCoreUnit*/,
     204             :     SfxMapUnit          /*ePresUnit*/,
     205             :     OUString&           rText,
     206             :     const IntlWrapper * )    const
     207             : {
     208           0 :     rText = GetValueText( GetValue() );
     209           0 :     return true;
     210             : }
     211             : 
     212             : 
     213         124 : bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
     214             : {
     215         124 :     nMemberId &= ~CONVERT_TWIPS;
     216         124 :     switch ( nMemberId )
     217             :     {
     218             :         case MID_HORJUST_ADJUST:
     219             :             {
     220           0 :                 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
     221           0 :                 switch ( (SvxCellVerJustify)GetValue() )
     222             :                 {
     223           0 :                     case SVX_VER_JUSTIFY_TOP:      eUno = style::VerticalAlignment_TOP;     break;
     224           0 :                     case SVX_VER_JUSTIFY_CENTER:   eUno = style::VerticalAlignment_MIDDLE;  break;
     225           0 :                     case SVX_VER_JUSTIFY_BOTTOM:   eUno = style::VerticalAlignment_BOTTOM;  break;
     226             :                     default: ; //prevent warning
     227             :                 }
     228           0 :                 rVal <<= eUno;
     229           0 :                 break;
     230             :             }
     231             :         default:
     232             :             {
     233         124 :                 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
     234         124 :                 switch ( (SvxCellVerJustify)GetValue() )
     235             :                 {
     236          52 :                     case SVX_VER_JUSTIFY_STANDARD: nUno = table::CellVertJustify2::STANDARD; break;
     237          22 :                     case SVX_VER_JUSTIFY_TOP:      nUno = table::CellVertJustify2::TOP;     break;
     238          24 :                     case SVX_VER_JUSTIFY_CENTER:   nUno = table::CellVertJustify2::CENTER;  break;
     239          26 :                     case SVX_VER_JUSTIFY_BOTTOM:   nUno = table::CellVertJustify2::BOTTOM;  break;
     240           0 :                     case SVX_VER_JUSTIFY_BLOCK:    nUno = table::CellVertJustify2::BLOCK;  break;
     241             :                     default: ; //prevent warning
     242             :                 }
     243         124 :                 rVal <<= nUno;
     244         124 :                 break;
     245             :             }
     246             :     }
     247         124 :     return true;
     248             : }
     249             : 
     250         132 : bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     251             : {
     252         132 :     nMemberId &= ~CONVERT_TWIPS;
     253         132 :     switch ( nMemberId )
     254             :     {
     255             :         case MID_HORJUST_ADJUST:
     256             :             {
     257             :                 //  property contains ParagraphAdjust values as sal_Int16
     258           0 :                 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
     259           0 :                 if(!(rVal >>= nVal))
     260           0 :                     return false;
     261             : 
     262           0 :                 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
     263           0 :                 switch (nVal)
     264             :                 {
     265           0 :                     case style::VerticalAlignment_TOP:      eSvx = SVX_VER_JUSTIFY_TOP;     break;
     266           0 :                     case style::VerticalAlignment_MIDDLE:   eSvx = SVX_VER_JUSTIFY_CENTER;  break;
     267           0 :                     case style::VerticalAlignment_BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;  break;
     268             :                     default:;
     269             :                 }
     270           0 :                 SetValue( (sal_uInt16)eSvx );
     271           0 :                 break;
     272             :             }
     273             :         default:
     274             :             {
     275         132 :                 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
     276         132 :                 rVal >>= eUno;
     277             : 
     278         132 :                 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
     279         132 :                 switch (eUno)
     280             :                 {
     281          22 :                     case table::CellVertJustify2::STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD;  break;
     282          14 :                     case table::CellVertJustify2::TOP:      eSvx = SVX_VER_JUSTIFY_TOP;       break;
     283          26 :                     case table::CellVertJustify2::CENTER:   eSvx = SVX_VER_JUSTIFY_CENTER;    break;
     284          62 :                     case table::CellVertJustify2::BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;    break;
     285           0 :                     case table::CellVertJustify2::BLOCK:    eSvx = SVX_VER_JUSTIFY_BLOCK;     break;
     286             :                     default: ; //prevent warning
     287             :                 }
     288         132 :                 SetValue( (sal_uInt16)eSvx );
     289         132 :                 break;
     290             :             }
     291             :     }
     292             : 
     293         132 :     return true;
     294             : }
     295             : 
     296             : 
     297           0 : OUString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal ) const
     298             : {
     299             :     DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
     300           0 :     return EE_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
     301             : }
     302             : 
     303             : 
     304         942 : SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
     305             : {
     306         942 :     return new SvxVerJustifyItem( *this );
     307             : }
     308             : 
     309             : 
     310         512 : SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
     311             : {
     312             :     sal_uInt16 nVal;
     313         512 :     rStream.ReadUInt16( nVal );
     314         512 :     return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
     315             : }
     316             : 
     317             : 
     318           0 : sal_uInt16 SvxVerJustifyItem::GetValueCount() const
     319             : {
     320           0 :     return SVX_VER_JUSTIFY_BOTTOM + 1;  // Last Enum value + 1
     321             : }
     322             : 
     323             : 
     324        9509 : SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
     325             :                                       const sal_uInt16 nId ) :
     326        9509 :     SfxEnumItem( nId, (sal_uInt16)eJustify )
     327             : {
     328        9509 : }
     329             : 
     330             : 
     331           0 : bool SvxJustifyMethodItem::GetPresentation
     332             : (
     333             :     SfxItemPresentation /*ePres*/,
     334             :     SfxMapUnit          /*eCoreUnit*/,
     335             :     SfxMapUnit          /*ePresUnit*/,
     336             :     OUString&           rText,
     337             :     const IntlWrapper * )    const
     338             : {
     339           0 :     rText = GetValueText( GetValue() );
     340           0 :     return true;
     341             : }
     342             : 
     343             : 
     344          64 : bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
     345             : {
     346          64 :     sal_Int32 nUno = table::CellJustifyMethod::AUTO;
     347          64 :     switch (static_cast<SvxCellJustifyMethod>(GetValue()))
     348             :     {
     349          64 :         case SVX_JUSTIFY_METHOD_AUTO:       nUno = table::CellJustifyMethod::AUTO;       break;
     350           0 :         case SVX_JUSTIFY_METHOD_DISTRIBUTE: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
     351             :         default:;
     352             :     }
     353          64 :     rVal <<= nUno;
     354          64 :     return true;
     355             : }
     356             : 
     357          56 : bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
     358             : {
     359          56 :     sal_Int32 nVal = table::CellJustifyMethod::AUTO;
     360          56 :     if (!(rVal >>= nVal))
     361           0 :         return false;
     362             : 
     363          56 :     SvxCellJustifyMethod eSvx = SVX_JUSTIFY_METHOD_AUTO;
     364          56 :     switch (nVal)
     365             :     {
     366             :         case table::CellJustifyMethod::AUTO:
     367          44 :             eSvx = SVX_JUSTIFY_METHOD_AUTO;
     368          44 :         break;
     369             :         case table::CellJustifyMethod::DISTRIBUTE:
     370           0 :             eSvx = SVX_JUSTIFY_METHOD_DISTRIBUTE;
     371           0 :         break;
     372             :         default:;
     373             :     }
     374          56 :     SetValue(static_cast<sal_uInt16>(eSvx));
     375          56 :     return true;
     376             : }
     377             : 
     378             : 
     379           0 : OUString SvxJustifyMethodItem::GetValueText( sal_uInt16 nVal ) const
     380             : {
     381             :     DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
     382           0 :     return EE_RESSTR(RID_SVXITEMS_JUSTMETHOD_AUTO + nVal);
     383             : }
     384             : 
     385             : 
     386         768 : SfxPoolItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
     387             : {
     388         768 :     return new SvxJustifyMethodItem( *this );
     389             : }
     390             : 
     391             : 
     392           0 : SfxPoolItem* SvxJustifyMethodItem::Create( SvStream& rStream, sal_uInt16 ) const
     393             : {
     394             :     sal_uInt16 nVal;
     395           0 :     rStream.ReadUInt16( nVal );
     396           0 :     return new SvxJustifyMethodItem( (SvxCellJustifyMethod)nVal, Which() );
     397             : }
     398             : 
     399             : 
     400           0 : sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
     401             : {
     402           0 :     return SVX_JUSTIFY_METHOD_DISTRIBUTE + 1;   // Last Enum value + 1
     403             : }
     404             : 
     405           0 : SvxJustifyMethodItem& SvxJustifyMethodItem::operator=(const SvxJustifyMethodItem& r)
     406             : {
     407           0 :     SetValue( r.GetValue() );
     408           0 :     return *this;
     409             : }
     410             : 
     411             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10