LCOV - code coverage report
Current view: top level - xmloff/source/style - backhdl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 103 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 6 0.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             :  * 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 <tools/debug.hxx>
      21             : #include <backhdl.hxx>
      22             : #include <xmloff/xmltoken.hxx>
      23             : #include <xmloff/xmluconv.hxx>
      24             : #include <sax/tools/converter.hxx>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <rtl/ustrbuf.hxx>
      27             : 
      28             : using namespace ::com::sun::star;
      29             : using namespace ::xmloff::token;
      30             : 
      31             : SvXMLEnumMapEntry pXML_BrushHorizontalPos[] =
      32             : {
      33             :     { XML_LEFT,             style::GraphicLocation_LEFT_MIDDLE   },
      34             :     { XML_RIGHT,            style::GraphicLocation_RIGHT_MIDDLE },
      35             :     { XML_TOKEN_INVALID,    0       }
      36             : };
      37             : 
      38             : SvXMLEnumMapEntry pXML_BrushVerticalPos[] =
      39             : {
      40             :     { XML_TOP,              style::GraphicLocation_MIDDLE_TOP   },
      41             :     { XML_BOTTOM,           style::GraphicLocation_MIDDLE_BOTTOM    },
      42             :     { XML_TOKEN_INVALID,    0       }
      43             : };
      44             : 
      45             : 
      46             : // class XMLBackGraphicPositionPropHdl
      47             : 
      48             : 
      49           0 : XMLBackGraphicPositionPropHdl::~XMLBackGraphicPositionPropHdl()
      50             : {
      51             :     // Nothing to do
      52           0 : }
      53             : 
      54           0 : bool XMLBackGraphicPositionPropHdl::importXML( const OUString& rStrImpValue, uno::Any& rValue, const SvXMLUnitConverter& ) const
      55             : {
      56           0 :     bool bRet = true;
      57           0 :     style::GraphicLocation ePos = style::GraphicLocation_NONE, eTmp;
      58             :     sal_uInt16 nTmp;
      59           0 :     SvXMLTokenEnumerator aTokenEnum( rStrImpValue );
      60           0 :     OUString aToken;
      61           0 :     bool bHori = false, bVert = false;
      62             : 
      63           0 :     while( bRet && aTokenEnum.getNextToken( aToken ) )
      64             :     {
      65           0 :         if( bHori && bVert )
      66             :         {
      67           0 :             bRet = false;
      68             :         }
      69           0 :         else if( -1 != aToken.indexOf( '%' ) )
      70             :         {
      71           0 :             sal_Int32 nPrc = 50;
      72           0 :             if (::sax::Converter::convertPercent( nPrc, aToken ))
      73             :             {
      74           0 :                 if( !bHori )
      75             :                 {
      76           0 :                     ePos = nPrc < 25 ? style::GraphicLocation_LEFT_TOP :
      77           0 :                                        (nPrc < 75 ? style::GraphicLocation_MIDDLE_MIDDLE :
      78           0 :                                                     style::GraphicLocation_RIGHT_BOTTOM);
      79           0 :                     bHori = true;
      80             :                 }
      81             :                 else
      82             :                 {
      83           0 :                     eTmp = nPrc < 25 ? style::GraphicLocation_LEFT_TOP:
      84           0 :                                        (nPrc < 75 ? style::GraphicLocation_LEFT_MIDDLE :
      85           0 :                                                     style::GraphicLocation_LEFT_BOTTOM);
      86           0 :                     MergeXMLVertPos( ePos, eTmp );
      87           0 :                     bVert = true;
      88             :                 }
      89             :             }
      90             :             else
      91             :             {
      92             :                 // wrong percentage
      93           0 :                 bRet = false;
      94             :             }
      95             :         }
      96           0 :         else if( IsXMLToken( aToken, XML_CENTER ) )
      97             :         {
      98           0 :             if( bHori )
      99           0 :                 MergeXMLVertPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE );
     100           0 :             else if ( bVert )
     101           0 :                 MergeXMLHoriPos( ePos, style::GraphicLocation_MIDDLE_MIDDLE );
     102             :             else
     103           0 :                 ePos = style::GraphicLocation_MIDDLE_MIDDLE;
     104             :         }
     105           0 :         else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushHorizontalPos ) )
     106             :         {
     107           0 :             if( bVert )
     108           0 :                 MergeXMLHoriPos( ePos, (style::GraphicLocation)nTmp );
     109           0 :             else if( !bHori )
     110           0 :                 ePos = (style::GraphicLocation)nTmp;
     111             :             else
     112           0 :                 bRet = false;
     113             : 
     114           0 :             bHori = true;
     115             :         }
     116           0 :         else if( SvXMLUnitConverter::convertEnum( nTmp, aToken, pXML_BrushVerticalPos ) )
     117             :         {
     118           0 :             if( bHori )
     119           0 :                 MergeXMLVertPos( ePos, (style::GraphicLocation)nTmp );
     120           0 :             else if( !bVert )
     121           0 :                 ePos = (style::GraphicLocation)nTmp;
     122             :             else
     123           0 :                 bRet = false;
     124           0 :             bVert = true;
     125             :         }
     126             :         else
     127             :         {
     128           0 :             bRet = false;
     129             :         }
     130             :     }
     131             : 
     132           0 :     bRet &= style::GraphicLocation_NONE != ePos;
     133           0 :     if( bRet )
     134           0 :         rValue <<= (style::GraphicLocation)(sal_uInt16)ePos;
     135             : 
     136           0 :     return bRet;
     137             : }
     138             : 
     139           0 : bool XMLBackGraphicPositionPropHdl::exportXML( OUString& rStrExpValue, const uno::Any& rValue, const SvXMLUnitConverter& ) const
     140             : {
     141           0 :     bool bRet = true;
     142           0 :     OUStringBuffer aOut;
     143             : 
     144             :     style::GraphicLocation eLocation;
     145           0 :     if( !( rValue >>= eLocation ) )
     146             :     {
     147           0 :         sal_Int32 nValue = 0;
     148           0 :         if( rValue >>= nValue )
     149           0 :             eLocation = (style::GraphicLocation)nValue;
     150             :         else
     151           0 :             bRet = false;
     152             :     }
     153             : 
     154           0 :     if( bRet )
     155             :     {
     156           0 :         bRet = false;
     157             : 
     158           0 :         switch( eLocation )
     159             :         {
     160             :         case style::GraphicLocation_LEFT_TOP:
     161             :         case style::GraphicLocation_MIDDLE_TOP:
     162             :         case style::GraphicLocation_RIGHT_TOP:
     163           0 :             aOut.append( GetXMLToken(XML_TOP) );
     164           0 :             bRet = true;
     165           0 :             break;
     166             :         case style::GraphicLocation_LEFT_MIDDLE:
     167             :         case style::GraphicLocation_MIDDLE_MIDDLE:
     168             :         case style::GraphicLocation_RIGHT_MIDDLE:
     169           0 :             aOut.append( GetXMLToken(XML_CENTER) );
     170           0 :             bRet = true;
     171           0 :             break;
     172             :         case style::GraphicLocation_LEFT_BOTTOM:
     173             :         case style::GraphicLocation_MIDDLE_BOTTOM:
     174             :         case style::GraphicLocation_RIGHT_BOTTOM:
     175           0 :             aOut.append( GetXMLToken(XML_BOTTOM) );
     176           0 :             bRet = true;
     177           0 :             break;
     178             :         default:
     179           0 :             break;
     180             :         }
     181             : 
     182           0 :         if( bRet )
     183             :         {
     184           0 :             aOut.append( ' ' );
     185             : 
     186           0 :             switch( eLocation )
     187             :             {
     188             :             case style::GraphicLocation_LEFT_TOP:
     189             :             case style::GraphicLocation_LEFT_BOTTOM:
     190             :             case style::GraphicLocation_LEFT_MIDDLE:
     191           0 :                 aOut.append( GetXMLToken(XML_LEFT) );
     192           0 :                 break;
     193             :             case style::GraphicLocation_MIDDLE_TOP:
     194             :             case style::GraphicLocation_MIDDLE_MIDDLE:
     195             :             case style::GraphicLocation_MIDDLE_BOTTOM:
     196           0 :                 aOut.append( GetXMLToken(XML_CENTER) );
     197           0 :                 break;
     198             :             case style::GraphicLocation_RIGHT_MIDDLE:
     199             :             case style::GraphicLocation_RIGHT_TOP:
     200             :             case style::GraphicLocation_RIGHT_BOTTOM:
     201           0 :                 aOut.append( GetXMLToken(XML_RIGHT) );
     202           0 :                 break;
     203             :             default:
     204           0 :                 break;
     205             :             }
     206             :         }
     207             :     }
     208             : 
     209           0 :     rStrExpValue = aOut.makeStringAndClear();
     210             : 
     211           0 :     return bRet;
     212             : }
     213             : 
     214           0 : void XMLBackGraphicPositionPropHdl::MergeXMLVertPos( style::GraphicLocation& ePos, style::GraphicLocation eVert )
     215             : {
     216           0 :     switch( ePos )
     217             :     {
     218             :     case style::GraphicLocation_LEFT_TOP:
     219             :     case style::GraphicLocation_LEFT_MIDDLE:
     220             :     case style::GraphicLocation_LEFT_BOTTOM:
     221             :         ePos = style::GraphicLocation_MIDDLE_TOP==eVert ?
     222             :                style::GraphicLocation_LEFT_TOP :
     223             :               (style::GraphicLocation_MIDDLE_MIDDLE==eVert ?
     224             :                style::GraphicLocation_LEFT_MIDDLE :
     225           0 :                style::GraphicLocation_LEFT_BOTTOM);
     226           0 :         break;
     227             : 
     228             :     case style::GraphicLocation_MIDDLE_TOP:
     229             :     case style::GraphicLocation_MIDDLE_MIDDLE:
     230             :     case style::GraphicLocation_MIDDLE_BOTTOM:
     231           0 :         ePos = eVert;
     232           0 :         break;
     233             : 
     234             :     case style::GraphicLocation_RIGHT_TOP:
     235             :     case style::GraphicLocation_RIGHT_MIDDLE:
     236             :     case style::GraphicLocation_RIGHT_BOTTOM:
     237             :         ePos = style::GraphicLocation_MIDDLE_TOP==eVert ?
     238             :                style::GraphicLocation_RIGHT_TOP :
     239             :               (style::GraphicLocation_MIDDLE_MIDDLE==eVert ?
     240             :                style::GraphicLocation_RIGHT_MIDDLE :
     241           0 :                style::GraphicLocation_RIGHT_BOTTOM);
     242           0 :         break;
     243             :     default:
     244           0 :         break;
     245             :     }
     246           0 : }
     247             : 
     248           0 : void XMLBackGraphicPositionPropHdl::MergeXMLHoriPos( style::GraphicLocation& ePos, style::GraphicLocation eHori )
     249             : {
     250             :     DBG_ASSERT( style::GraphicLocation_LEFT_MIDDLE==eHori || style::GraphicLocation_MIDDLE_MIDDLE==eHori || style::GraphicLocation_RIGHT_MIDDLE==eHori,
     251             :                 "lcl_frmitems_MergeXMLHoriPos: vertical pos must be middle" );
     252             : 
     253           0 :     switch( ePos )
     254             :     {
     255             :     case style::GraphicLocation_LEFT_TOP:
     256             :     case style::GraphicLocation_MIDDLE_TOP:
     257             :     case style::GraphicLocation_RIGHT_TOP:
     258             :         ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ?
     259             :                style::GraphicLocation_LEFT_TOP :
     260             :               (style::GraphicLocation_MIDDLE_MIDDLE==eHori ?
     261             :                style::GraphicLocation_MIDDLE_TOP :
     262           0 :                style::GraphicLocation_RIGHT_TOP);
     263           0 :         break;
     264             : 
     265             :     case style::GraphicLocation_LEFT_MIDDLE:
     266             :     case style::GraphicLocation_MIDDLE_MIDDLE:
     267             :     case style::GraphicLocation_RIGHT_MIDDLE:
     268           0 :         ePos = eHori;
     269           0 :         break;
     270             : 
     271             :     case style::GraphicLocation_LEFT_BOTTOM:
     272             :     case style::GraphicLocation_MIDDLE_BOTTOM:
     273             :     case style::GraphicLocation_RIGHT_BOTTOM:
     274             :         ePos = style::GraphicLocation_LEFT_MIDDLE==eHori ?
     275             :                style::GraphicLocation_LEFT_BOTTOM :
     276             :               (style::GraphicLocation_MIDDLE_MIDDLE==eHori ?
     277             :                style::GraphicLocation_MIDDLE_BOTTOM :
     278           0 :                style::GraphicLocation_RIGHT_BOTTOM);
     279           0 :         break;
     280             :     default:
     281           0 :         break;
     282             :     }
     283           0 : }
     284             : 
     285             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11