LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/items - justifyitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 179 35.8 %
Date: 2012-12-27 Functions: 18 37 48.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * 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         747 : TYPEINIT1_FACTORY( SvxHorJustifyItem, SfxEnumItem, new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, 0) );
      35       16892 : 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        1092 : SvxHorJustifyItem::SvxHorJustifyItem( const SvxCellHorJustify eJustify,
      47             :                                       const sal_uInt16 nId ) :
      48        1092 :     SfxEnumItem( nId, (sal_uInt16)eJustify )
      49             : {
      50        1092 : }
      51             : 
      52             : 
      53           0 : SfxItemPresentation SvxHorJustifyItem::GetPresentation
      54             : (
      55             :     SfxItemPresentation ePres,
      56             :     SfxMapUnit          /*eCoreUnit*/,
      57             :     SfxMapUnit          /*ePresUnit*/,
      58             :     XubString&              rText, const IntlWrapper *)    const
      59             : {
      60           0 :     switch ( ePres )
      61             :     {
      62             :         case SFX_ITEM_PRESENTATION_NONE:
      63           0 :             rText.Erase();
      64           0 :             return SFX_ITEM_PRESENTATION_NONE;
      65             :         case SFX_ITEM_PRESENTATION_NAMELESS:
      66             :         case SFX_ITEM_PRESENTATION_COMPLETE:
      67           0 :             rText = GetValueText( GetValue() );
      68           0 :             return SFX_ITEM_PRESENTATION_COMPLETE;
      69             :         default: ; //prevent warning
      70             :     }
      71           0 :     return SFX_ITEM_PRESENTATION_NONE;
      72             : }
      73             : 
      74             : 
      75           6 : bool SvxHorJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
      76             : {
      77           6 :     nMemberId &= ~CONVERT_TWIPS;
      78           6 :     switch ( nMemberId )
      79             :     {
      80             :         case MID_HORJUST_HORJUST:
      81             :             {
      82           2 :                 table::CellHoriJustify eUno = table::CellHoriJustify_STANDARD;
      83           2 :                 switch ( (SvxCellHorJustify)GetValue() )
      84             :                 {
      85           0 :                     case SVX_HOR_JUSTIFY_STANDARD: eUno = table::CellHoriJustify_STANDARD; break;
      86           0 :                     case SVX_HOR_JUSTIFY_LEFT:     eUno = table::CellHoriJustify_LEFT;     break;
      87           2 :                     case SVX_HOR_JUSTIFY_CENTER:   eUno = table::CellHoriJustify_CENTER;   break;
      88           0 :                     case SVX_HOR_JUSTIFY_RIGHT:    eUno = table::CellHoriJustify_RIGHT;    break;
      89           0 :                     case SVX_HOR_JUSTIFY_BLOCK:    eUno = table::CellHoriJustify_BLOCK;    break;
      90           0 :                     case SVX_HOR_JUSTIFY_REPEAT:   eUno = table::CellHoriJustify_REPEAT;   break;
      91             :                 }
      92           2 :                 rVal <<= eUno;
      93             :             }
      94           2 :             break;
      95             :         case MID_HORJUST_ADJUST:
      96             :             {
      97             :                 //  ParagraphAdjust values, as in SvxAdjustItem
      98             :                 //  (same value for ParaAdjust and ParaLastLineAdjust)
      99             : 
     100           4 :                 sal_Int16 nAdjust = style::ParagraphAdjust_LEFT;
     101           4 :                 switch ( (SvxCellHorJustify)GetValue() )
     102             :                 {
     103             :                     // ParagraphAdjust_LEFT is used for STANDARD and REPEAT
     104             :                     case SVX_HOR_JUSTIFY_STANDARD:
     105             :                     case SVX_HOR_JUSTIFY_REPEAT:
     106           0 :                     case SVX_HOR_JUSTIFY_LEFT:   nAdjust = style::ParagraphAdjust_LEFT;   break;
     107           4 :                     case SVX_HOR_JUSTIFY_CENTER: nAdjust = style::ParagraphAdjust_CENTER; break;
     108           0 :                     case SVX_HOR_JUSTIFY_RIGHT:  nAdjust = style::ParagraphAdjust_RIGHT;  break;
     109           0 :                     case SVX_HOR_JUSTIFY_BLOCK:  nAdjust = style::ParagraphAdjust_BLOCK;  break;
     110             :                 }
     111           4 :                 rVal <<= nAdjust;       // as sal_Int16
     112             :             }
     113           4 :             break;
     114             :     }
     115           6 :     return true;
     116             : }
     117             : 
     118          41 : bool SvxHorJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     119             : {
     120          41 :     nMemberId &= ~CONVERT_TWIPS;
     121          41 :     switch ( nMemberId )
     122             :     {
     123             :         case MID_HORJUST_HORJUST:
     124             :             {
     125             :                 table::CellHoriJustify eUno;
     126          41 :                 if(!(rVal >>= eUno))
     127             :                 {
     128           0 :                     sal_Int32 nValue = 0;
     129           0 :                     if(!(rVal >>= nValue))
     130           0 :                         return false;
     131           0 :                     eUno = (table::CellHoriJustify)nValue;
     132             :                 }
     133          41 :                 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
     134          41 :                 switch (eUno)
     135             :                 {
     136          11 :                     case table::CellHoriJustify_STANDARD: eSvx = SVX_HOR_JUSTIFY_STANDARD; break;
     137           2 :                     case table::CellHoriJustify_LEFT:     eSvx = SVX_HOR_JUSTIFY_LEFT;     break;
     138          24 :                     case table::CellHoriJustify_CENTER:   eSvx = SVX_HOR_JUSTIFY_CENTER;   break;
     139           2 :                     case table::CellHoriJustify_RIGHT:    eSvx = SVX_HOR_JUSTIFY_RIGHT;    break;
     140           2 :                     case table::CellHoriJustify_BLOCK:    eSvx = SVX_HOR_JUSTIFY_BLOCK;    break;
     141           0 :                     case table::CellHoriJustify_REPEAT:   eSvx = SVX_HOR_JUSTIFY_REPEAT;   break;
     142             :                     default: ; //prevent warning
     143             :                 }
     144          41 :                 SetValue( (sal_uInt16)eSvx );
     145             :             }
     146          41 :             break;
     147             :         case MID_HORJUST_ADJUST:
     148             :             {
     149             :                 //  property contains ParagraphAdjust values as sal_Int16
     150           0 :                 sal_Int16 nVal = sal_Int16();
     151           0 :                 if(!(rVal >>= nVal))
     152           0 :                     return false;
     153             : 
     154           0 :                 SvxCellHorJustify eSvx = SVX_HOR_JUSTIFY_STANDARD;
     155           0 :                 switch (nVal)
     156             :                 {
     157             :                     //  STRETCH is treated as BLOCK
     158           0 :                     case style::ParagraphAdjust_LEFT:    eSvx = SVX_HOR_JUSTIFY_LEFT;   break;
     159           0 :                     case style::ParagraphAdjust_RIGHT:   eSvx = SVX_HOR_JUSTIFY_RIGHT;  break;
     160             :                     case style::ParagraphAdjust_STRETCH:
     161           0 :                     case style::ParagraphAdjust_BLOCK:   eSvx = SVX_HOR_JUSTIFY_BLOCK;  break;
     162           0 :                     case style::ParagraphAdjust_CENTER:  eSvx = SVX_HOR_JUSTIFY_CENTER; break;
     163             :                 }
     164           0 :                 SetValue( (sal_uInt16)eSvx );
     165             :             }
     166             :     }
     167          41 :     return true;
     168             : }
     169             : 
     170             : 
     171           0 : XubString SvxHorJustifyItem::GetValueText( sal_uInt16 nVal ) const
     172             : {
     173             :     DBG_ASSERT( nVal <= SVX_HOR_JUSTIFY_REPEAT, "enum overflow!" );
     174           0 :     return EE_RESSTR(RID_SVXITEMS_HORJUST_STANDARD + nVal);
     175             : }
     176             : 
     177             : 
     178         180 : SfxPoolItem* SvxHorJustifyItem::Clone( SfxItemPool* ) const
     179             : {
     180         180 :     return new SvxHorJustifyItem( *this );
     181             : }
     182             : 
     183             : 
     184           0 : SfxPoolItem* SvxHorJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
     185             : {
     186             :     sal_uInt16 nVal;
     187           0 :     rStream >> nVal;
     188           0 :     return new SvxHorJustifyItem( (SvxCellHorJustify)nVal, Which() );
     189             : }
     190             : 
     191             : 
     192           0 : sal_uInt16 SvxHorJustifyItem::GetValueCount() const
     193             : {
     194           0 :     return SVX_HOR_JUSTIFY_REPEAT + 1;  // Last Enum value + 1
     195             : }
     196             : 
     197             : 
     198           0 : SvxVerJustifyItem::SvxVerJustifyItem( const sal_uInt16 nId ) :
     199           0 :     SfxEnumItem( nId, (sal_uInt16)SVX_VER_JUSTIFY_STANDARD )
     200             : {
     201           0 : }
     202             : 
     203        1009 : SvxVerJustifyItem::SvxVerJustifyItem( const SvxCellVerJustify eJustify,
     204             :                                       const sal_uInt16 nId ) :
     205        1009 :     SfxEnumItem( nId, (sal_uInt16)eJustify )
     206             : {
     207        1009 : }
     208             : 
     209             : 
     210           0 : SfxItemPresentation SvxVerJustifyItem::GetPresentation
     211             : (
     212             :     SfxItemPresentation ePres,
     213             :     SfxMapUnit          /*eCoreUnit*/,
     214             :     SfxMapUnit          /*ePresUnit*/,
     215             :     XubString&              rText,
     216             :     const IntlWrapper * )    const
     217             : {
     218           0 :     switch ( ePres )
     219             :     {
     220             :         case SFX_ITEM_PRESENTATION_NONE:
     221           0 :             rText.Erase();
     222           0 :             return SFX_ITEM_PRESENTATION_NONE;
     223             :         case SFX_ITEM_PRESENTATION_NAMELESS:
     224             :         case SFX_ITEM_PRESENTATION_COMPLETE:
     225           0 :             rText = GetValueText( GetValue() );
     226           0 :             return SFX_ITEM_PRESENTATION_COMPLETE;
     227             :         default: ; //prevent warning
     228             :     }
     229           0 :     return SFX_ITEM_PRESENTATION_NONE;
     230             : }
     231             : 
     232             : 
     233           0 : bool SvxVerJustifyItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
     234             : {
     235           0 :     nMemberId &= ~CONVERT_TWIPS;
     236           0 :     switch ( nMemberId )
     237             :     {
     238             :         case MID_HORJUST_ADJUST:
     239             :             {
     240           0 :                 style::VerticalAlignment eUno = style::VerticalAlignment_TOP;
     241           0 :                 switch ( (SvxCellVerJustify)GetValue() )
     242             :                 {
     243           0 :                     case SVX_VER_JUSTIFY_TOP:      eUno = style::VerticalAlignment_TOP;     break;
     244           0 :                     case SVX_VER_JUSTIFY_CENTER:   eUno = style::VerticalAlignment_MIDDLE;  break;
     245           0 :                     case SVX_VER_JUSTIFY_BOTTOM:   eUno = style::VerticalAlignment_BOTTOM;  break;
     246             :                     default: ; //prevent warning
     247             :                 }
     248           0 :                 rVal <<= eUno;
     249             :                 break;
     250             :             }
     251             :         default:
     252             :             {
     253           0 :                 sal_Int32 nUno = table::CellVertJustify2::STANDARD;
     254           0 :                 switch ( (SvxCellVerJustify)GetValue() )
     255             :                 {
     256           0 :                     case SVX_VER_JUSTIFY_STANDARD: nUno = table::CellVertJustify2::STANDARD; break;
     257           0 :                     case SVX_VER_JUSTIFY_TOP:      nUno = table::CellVertJustify2::TOP;     break;
     258           0 :                     case SVX_VER_JUSTIFY_CENTER:   nUno = table::CellVertJustify2::CENTER;  break;
     259           0 :                     case SVX_VER_JUSTIFY_BOTTOM:   nUno = table::CellVertJustify2::BOTTOM;  break;
     260           0 :                     case SVX_VER_JUSTIFY_BLOCK:    nUno = table::CellVertJustify2::BLOCK;  break;
     261             :                     default: ; //prevent warning
     262             :                 }
     263           0 :                 rVal <<= nUno;
     264             :                 break;
     265             :             }
     266             :     }
     267           0 :     return true;
     268             : }
     269             : 
     270          11 : bool SvxVerJustifyItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
     271             : {
     272          11 :     nMemberId &= ~CONVERT_TWIPS;
     273          11 :     switch ( nMemberId )
     274             :     {
     275             :         case MID_HORJUST_ADJUST:
     276             :             {
     277             :                 //  property contains ParagraphAdjust values as sal_Int16
     278           0 :                 style::VerticalAlignment nVal = style::VerticalAlignment_TOP;
     279           0 :                 if(!(rVal >>= nVal))
     280           0 :                     return false;
     281             : 
     282           0 :                 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
     283           0 :                 switch (nVal)
     284             :                 {
     285           0 :                     case style::VerticalAlignment_TOP:      eSvx = SVX_VER_JUSTIFY_TOP;     break;
     286           0 :                     case style::VerticalAlignment_MIDDLE:   eSvx = SVX_VER_JUSTIFY_CENTER;  break;
     287           0 :                     case style::VerticalAlignment_BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;  break;
     288             :                     default:;
     289             :                 }
     290           0 :                 SetValue( (sal_uInt16)eSvx );
     291             :                 break;
     292             :             }
     293             :         default:
     294             :             {
     295          11 :                 sal_Int32 eUno = table::CellVertJustify2::STANDARD;
     296          11 :                 rVal >>= eUno;
     297             : 
     298          11 :                 SvxCellVerJustify eSvx = SVX_VER_JUSTIFY_STANDARD;
     299          11 :                 switch (eUno)
     300             :                 {
     301           0 :                     case table::CellVertJustify2::STANDARD: eSvx = SVX_VER_JUSTIFY_STANDARD;  break;
     302           0 :                     case table::CellVertJustify2::TOP:      eSvx = SVX_VER_JUSTIFY_TOP;       break;
     303           0 :                     case table::CellVertJustify2::CENTER:   eSvx = SVX_VER_JUSTIFY_CENTER;    break;
     304          11 :                     case table::CellVertJustify2::BOTTOM:   eSvx = SVX_VER_JUSTIFY_BOTTOM;    break;
     305           0 :                     case table::CellVertJustify2::BLOCK:    eSvx = SVX_VER_JUSTIFY_BLOCK;     break;
     306             :                     default: ; //prevent warning
     307             :                 }
     308          11 :                 SetValue( (sal_uInt16)eSvx );
     309             :                 break;
     310             :             }
     311             :     }
     312             : 
     313          11 :     return true;
     314             : }
     315             : 
     316             : 
     317           0 : XubString SvxVerJustifyItem::GetValueText( sal_uInt16 nVal ) const
     318             : {
     319             :     DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
     320           0 :     return EE_RESSTR(RID_SVXITEMS_VERJUST_STANDARD + nVal);
     321             : }
     322             : 
     323             : 
     324          57 : SfxPoolItem* SvxVerJustifyItem::Clone( SfxItemPool* ) const
     325             : {
     326          57 :     return new SvxVerJustifyItem( *this );
     327             : }
     328             : 
     329             : 
     330           0 : SfxPoolItem* SvxVerJustifyItem::Create( SvStream& rStream, sal_uInt16 ) const
     331             : {
     332             :     sal_uInt16 nVal;
     333           0 :     rStream >> nVal;
     334           0 :     return new SvxVerJustifyItem( (SvxCellVerJustify)nVal, Which() );
     335             : }
     336             : 
     337             : 
     338           0 : sal_uInt16 SvxVerJustifyItem::GetValueCount() const
     339             : {
     340           0 :     return SVX_VER_JUSTIFY_BOTTOM + 1;  // Last Enum value + 1
     341             : }
     342             : 
     343             : 
     344        1982 : SvxJustifyMethodItem::SvxJustifyMethodItem( const SvxCellJustifyMethod eJustify,
     345             :                                       const sal_uInt16 nId ) :
     346        1982 :     SfxEnumItem( nId, (sal_uInt16)eJustify )
     347             : {
     348        1982 : }
     349             : 
     350             : 
     351           0 : SfxItemPresentation SvxJustifyMethodItem::GetPresentation
     352             : (
     353             :     SfxItemPresentation ePres,
     354             :     SfxMapUnit          /*eCoreUnit*/,
     355             :     SfxMapUnit          /*ePresUnit*/,
     356             :     XubString&              rText,
     357             :     const IntlWrapper * )    const
     358             : {
     359           0 :     switch ( ePres )
     360             :     {
     361             :         case SFX_ITEM_PRESENTATION_NONE:
     362           0 :             rText.Erase();
     363           0 :             return SFX_ITEM_PRESENTATION_NONE;
     364             :         case SFX_ITEM_PRESENTATION_NAMELESS:
     365             :         case SFX_ITEM_PRESENTATION_COMPLETE:
     366           0 :             rText = GetValueText( GetValue() );
     367           0 :             return SFX_ITEM_PRESENTATION_COMPLETE;
     368             :         default: ; //prevent warning
     369             :     }
     370           0 :     return SFX_ITEM_PRESENTATION_NONE;
     371             : }
     372             : 
     373             : 
     374           0 : bool SvxJustifyMethodItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
     375             : {
     376           0 :     sal_Int32 nUno = table::CellJustifyMethod::AUTO;
     377           0 :     switch (static_cast<SvxCellJustifyMethod>(GetValue()))
     378             :     {
     379           0 :         case SVX_JUSTIFY_METHOD_AUTO:       nUno = table::CellJustifyMethod::AUTO;       break;
     380           0 :         case SVX_JUSTIFY_METHOD_DISTRIBUTE: nUno = table::CellJustifyMethod::DISTRIBUTE; break;
     381             :         default:;
     382             :     }
     383           0 :     rVal <<= nUno;
     384           0 :     return true;
     385             : }
     386             : 
     387          22 : bool SvxJustifyMethodItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
     388             : {
     389          22 :     sal_Int32 nVal = table::CellJustifyMethod::AUTO;
     390          22 :     if (!(rVal >>= nVal))
     391           0 :         return false;
     392             : 
     393          22 :     SvxCellJustifyMethod eSvx = SVX_JUSTIFY_METHOD_AUTO;
     394          22 :     switch (nVal)
     395             :     {
     396             :         case table::CellJustifyMethod::AUTO:
     397          22 :             eSvx = SVX_JUSTIFY_METHOD_AUTO;
     398          22 :         break;
     399             :         case table::CellJustifyMethod::DISTRIBUTE:
     400           0 :             eSvx = SVX_JUSTIFY_METHOD_DISTRIBUTE;
     401           0 :         break;
     402             :         default:;
     403             :     }
     404          22 :     SetValue(static_cast<sal_uInt16>(eSvx));
     405          22 :     return true;
     406             : }
     407             : 
     408             : 
     409           0 : XubString SvxJustifyMethodItem::GetValueText( sal_uInt16 nVal ) const
     410             : {
     411             :     DBG_ASSERT( nVal <= SVX_VER_JUSTIFY_BOTTOM, "enum overflow!" );
     412           0 :     return EE_RESSTR(RID_SVXITEMS_JUSTMETHOD_AUTO + nVal);
     413             : }
     414             : 
     415             : 
     416          75 : SfxPoolItem* SvxJustifyMethodItem::Clone( SfxItemPool* ) const
     417             : {
     418          75 :     return new SvxJustifyMethodItem( *this );
     419             : }
     420             : 
     421             : 
     422           0 : SfxPoolItem* SvxJustifyMethodItem::Create( SvStream& rStream, sal_uInt16 ) const
     423             : {
     424             :     sal_uInt16 nVal;
     425           0 :     rStream >> nVal;
     426           0 :     return new SvxJustifyMethodItem( (SvxCellJustifyMethod)nVal, Which() );
     427             : }
     428             : 
     429             : 
     430           0 : sal_uInt16 SvxJustifyMethodItem::GetValueCount() const
     431             : {
     432           0 :     return SVX_JUSTIFY_METHOD_DISTRIBUTE + 1;   // Last Enum value + 1
     433             : }
     434             : 
     435           0 : SvxJustifyMethodItem& SvxJustifyMethodItem::operator=(const SvxJustifyMethodItem& r)
     436             : {
     437           0 :     SetValue( r.GetValue() );
     438           0 :     return *this;
     439             : }
     440             : 
     441             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10