LCOV - code coverage report
Current view: top level - sw/source/core/inc - wrong.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 65 40.0 %
Date: 2015-06-13 12:38:46 Functions: 15 20 75.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             : #ifndef INCLUDED_SW_SOURCE_CORE_INC_WRONG_HXX
      21             : #define INCLUDED_SW_SOURCE_CORE_INC_WRONG_HXX
      22             : 
      23             : #include <com/sun/star/container/XStringKeyMap.hpp>
      24             : 
      25             : #include <com/sun/star/util/Color.hpp>
      26             : #include <com/sun/star/awt/FontUnderline.hpp>
      27             : #include <com/sun/star/uno/Any.hxx>
      28             : 
      29             : #include <vector>
      30             : 
      31             : #include <tools/color.hxx>
      32             : #include <swtypes.hxx>
      33             : #include <viewopt.hxx>
      34             : 
      35             : class SwWrongList;
      36             : 
      37             : enum WrongAreaLineType
      38             : {
      39             :     WRONGAREA_DASHED,
      40             :     WRONGAREA_WAVE,
      41             :     WRONGAREA_NONE
      42             : };
      43             : 
      44             : enum WrongListType
      45             : {
      46             :     WRONGLIST_SPELL,
      47             :     WRONGLIST_GRAMMAR,
      48             :     WRONGLIST_SMARTTAG,
      49             :     WRONGLIST_CHANGETRACKING
      50             : };
      51             : 
      52             : // ST2
      53    67659615 : class SwWrongArea
      54             : {
      55             : public:
      56             :     OUString maType;
      57             :     com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > mxPropertyBag;
      58             :     sal_Int32 mnPos;
      59             :     sal_Int32 mnLen;
      60             :     SwWrongList* mpSubList;
      61             : 
      62             :     Color mColor;
      63             :     WrongAreaLineType mLineType;
      64             : 
      65             :     SwWrongArea( const OUString& rType,
      66             :                  WrongListType listType,
      67             :                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
      68             :                  sal_Int32 nPos,
      69             :                  sal_Int32 nLen);
      70             : 
      71             :     SwWrongArea( const OUString& rType,
      72             :                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
      73             :                  sal_Int32 nPos,
      74             :                  sal_Int32 nLen,
      75             :                  SwWrongList* pSubList);
      76             : private:
      77             : 
      78             :     SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL), mColor(0,0,0), mLineType(WRONGAREA_WAVE) {}
      79             : 
      80           0 :     static Color getSmartColor ( com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag)
      81             :     {
      82             :         try
      83             :         {
      84           0 :             if (xPropertyBag.is())
      85             :             {
      86           0 :                 const OUString colorKey("LineColor");
      87           0 :                 com::sun::star::uno::Any aLineColor = xPropertyBag->getValue(colorKey).get< com::sun::star::uno::Any>();
      88           0 :                 com::sun::star::util::Color lineColor = 0;
      89             : 
      90           0 :                 if (aLineColor >>= lineColor)
      91             :                 {
      92           0 :                     return Color( lineColor );
      93           0 :                 }
      94             :             }
      95             :         }
      96           0 :         catch(const ::com::sun::star::container::NoSuchElementException&)
      97             :         {
      98             :         }
      99           0 :         catch(const ::com::sun::star::uno::RuntimeException&)
     100             :         {
     101             :         }
     102             : 
     103           0 :         return SwViewOption::GetSmarttagColor( );
     104             :     }
     105             : 
     106           0 :     static WrongAreaLineType getSmartLineType( com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
     107             :     {
     108             :         try
     109             :         {
     110           0 :             if (xPropertyBag.is())
     111             :             {
     112           0 :                 const OUString typeKey("LineType");
     113           0 :                 com::sun::star::uno::Any aLineType = xPropertyBag->getValue(typeKey).get< com::sun::star::uno::Any>();
     114           0 :                 ::sal_Int16 lineType = 0;
     115             : 
     116           0 :                 if (!(aLineType >>= lineType))
     117             :                 {
     118           0 :                     return WRONGAREA_DASHED;
     119             :                 }
     120           0 :                 if (::com::sun::star::awt::FontUnderline::WAVE == lineType)
     121             :                 {
     122           0 :                     return WRONGAREA_WAVE;
     123             :                 }
     124           0 :                 if (::com::sun::star::awt::FontUnderline::SMALLWAVE == lineType)
     125             :                 {
     126           0 :                     return WRONGAREA_WAVE; //Code draws wave height based on space that fits.
     127           0 :                 }
     128             :             }
     129             :         }
     130           0 :         catch(const ::com::sun::star::container::NoSuchElementException&)
     131             :         {
     132             :         }
     133           0 :         catch(const ::com::sun::star::uno::RuntimeException&)
     134             :         {
     135             :         }
     136             : 
     137           0 :         return WRONGAREA_DASHED;
     138             :     }
     139             : 
     140    22553035 :     static Color getWrongAreaColor(WrongListType listType,
     141             :                             com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
     142             :     {
     143    22553035 :         if (WRONGLIST_SPELL == listType)
     144             :         {
     145    22553035 :             return SwViewOption::GetSpellColor();
     146             :         }
     147           0 :         else if (WRONGLIST_GRAMMAR == listType)
     148             :         {
     149           0 :             return Color( COL_LIGHTBLUE );
     150             :         }
     151           0 :         else if (WRONGLIST_SMARTTAG == listType)
     152             :         {
     153           0 :             return  getSmartColor(xPropertyBag);
     154             :         }
     155             : 
     156           0 :         return SwViewOption::GetSpellColor();
     157             :     }
     158             : 
     159    22553035 :     static WrongAreaLineType getWrongAreaLineType(WrongListType listType,
     160             :                                            com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
     161             :     {
     162    22553035 :         if (WRONGLIST_SPELL == listType)
     163             :         {
     164    22553035 :             return WRONGAREA_WAVE;
     165             :         }
     166           0 :         else if (WRONGLIST_GRAMMAR == listType)
     167             :         {
     168           0 :             return WRONGAREA_WAVE;
     169             :         }
     170           0 :         else if (WRONGLIST_SMARTTAG == listType)
     171             :         {
     172           0 :             return getSmartLineType(xPropertyBag);
     173             :         }
     174             : 
     175           0 :         return WRONGAREA_WAVE;
     176             :     }
     177             : 
     178             : };
     179             : 
     180             : class SwWrongList
     181             : {
     182             :     std::vector<SwWrongArea> maList;
     183             :     WrongListType            meType;
     184             : 
     185             :     sal_Int32 nBeginInvalid;   // Start of the invalid range
     186             :     sal_Int32 nEndInvalid;     // End of the invalid range
     187             : 
     188          46 :     static void ShiftLeft( sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd )
     189          46 :     { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
     190             :     void _Invalidate( sal_Int32 nBegin, sal_Int32 nEnd );
     191             : 
     192             :     void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos);
     193             :     void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
     194             : 
     195             :     SwWrongList& operator= (const SwWrongList &) SAL_DELETED_FUNCTION;
     196             :     SwWrongList( const SwWrongList& rCpy ) SAL_DELETED_FUNCTION;
     197             : 
     198             : public:
     199             :     SwWrongList( WrongListType eType );
     200             : 
     201             :     virtual ~SwWrongList();
     202             :     virtual SwWrongList* Clone();
     203             :     virtual void CopyFrom( const SwWrongList& rCopy );
     204             : 
     205           8 :     inline WrongListType GetWrongListType() const { return meType; }
     206    97033510 :     inline sal_Int32 GetBeginInv() const { return nBeginInvalid; }
     207    48516806 :     inline sal_Int32 GetEndInv() const { return nEndInvalid; }
     208             :     inline bool InsideInvalid( sal_Int32 nChk ) const
     209             :         { return nChk >= nBeginInvalid && nChk <= nEndInvalid; }
     210             :     void SetInvalid( sal_Int32 nBegin, sal_Int32 nEnd );
     211           0 :     inline void Validate(){ nBeginInvalid = nEndInvalid = COMPLETE_STRING; }
     212             :     void Invalidate( sal_Int32 nBegin, sal_Int32 nEnd );
     213             :     bool InvalidateWrong();
     214             :     bool Fresh( sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos,
     215             :             sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos );
     216             :     sal_uInt16 GetWrongPos( sal_Int32 nValue ) const;
     217             : 
     218             :     bool Check( sal_Int32 &rChk, sal_Int32 &rLn ) const;
     219             :     bool InWrongWord( sal_Int32 &rChk, sal_Int32 &rLn ) const;
     220             :     sal_Int32 NextWrong( sal_Int32 nChk ) const;
     221             : 
     222             :     void Move( sal_Int32 nPos, sal_Int32 nDiff );
     223             :     void ClearList();
     224             : 
     225             :     // Divide the list into two part, the wrong words until nSplitPos will be
     226             :     // removed and transferred to a new SwWrongList.
     227             :     SwWrongList* SplitList( sal_Int32 nSplitPos );
     228             :     // Join the next SwWrongList, nInsertPos is my own text length, where
     229             :     // the other wrong list has to be inserted.
     230             :     void JoinList( SwWrongList* pNext, sal_Int32 nInsertPos );
     231             : 
     232   161336588 :     inline sal_Int32 Len( sal_uInt16 nIdx ) const
     233             :     {
     234   161336588 :         return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
     235             :     }
     236             : 
     237   206445977 :     inline sal_Int32 Pos( sal_uInt16 nIdx ) const
     238             :     {
     239   206445977 :         return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
     240             :     }
     241             : 
     242   743471450 :     inline sal_uInt16 Count() const { return (sal_uInt16)maList.size(); }
     243             : 
     244    22553035 :     inline void Insert( const OUString& rType,
     245             :                         com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     246             :                         sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere )
     247             :     {
     248    22553035 :         std::vector<SwWrongArea>::iterator i = maList.begin();
     249    22553035 :         if ( nWhere >= maList.size() )
     250    22553009 :             i = maList.end(); // robust
     251             :         else
     252          26 :             i += nWhere;
     253             : 
     254    22553035 :         maList.insert(i, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
     255    22553035 :     }
     256             : 
     257             :     void Insert( const OUString& rType,
     258             :                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     259             :                  sal_Int32 nNewPos, sal_Int32 nNewLen );
     260             : 
     261           0 :     inline SwWrongList* SubList( sal_uInt16 nIdx ) const
     262             :     {
     263           0 :         return nIdx < maList.size() ? maList[nIdx].mpSubList : 0;
     264             :     }
     265             : 
     266             :     void InsertSubList( sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
     267             : 
     268         967 :     inline const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
     269             :     {
     270         967 :         return nIdx < maList.size() ? &maList[nIdx] : 0;
     271             :     }
     272             :     void RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd );
     273             :     bool LookForEntry( sal_Int32 nBegin, sal_Int32 nEnd );
     274             : };
     275             : 
     276             : #endif
     277             : 
     278             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11