LCOV - code coverage report
Current view: top level - sw/source/core/inc - wrong.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 26 65 40.0 %
Date: 2014-04-11 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        1587 : 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 :     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 ::rtl::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 :     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 ::rtl::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         305 :     Color getWrongAreaColor(WrongListType listType,
     141             :                             com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
     142             :     {
     143         305 :         if (WRONGLIST_SPELL == listType)
     144             :         {
     145         305 :             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         305 :     WrongAreaLineType getWrongAreaLineType(WrongListType listType,
     160             :                                            com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag )
     161             :     {
     162         305 :         if (WRONGLIST_SPELL == listType)
     163             :         {
     164         305 :             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        1194 :     void ShiftLeft( sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd )
     189        1194 :     { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
     190             :     void ShiftRight( sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd )
     191             :     { if( rPos >= nStart ) rPos += nStart - nEnd; }
     192             :     void _Invalidate( sal_Int32 nBegin, sal_Int32 nEnd );
     193             : 
     194             :     void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos);
     195             :     void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
     196             : 
     197             :     // forbidden and not implemented
     198             :     SwWrongList& operator= (const SwWrongList &);
     199             :     SwWrongList( const SwWrongList& rCpy );
     200             : 
     201             : public:
     202             :     SwWrongList( WrongListType eType );
     203             : 
     204             :     virtual ~SwWrongList();
     205             :     virtual SwWrongList* Clone();
     206             :     virtual void CopyFrom( const SwWrongList& rCopy );
     207             : 
     208           2 :     inline WrongListType GetWrongListType() const { return meType; }
     209        9502 :     inline sal_Int32 GetBeginInv() const { return nBeginInvalid; }
     210        3795 :     inline sal_Int32 GetEndInv() const { return nEndInvalid; }
     211             :     inline bool InsideInvalid( sal_Int32 nChk ) const
     212             :         { return nChk >= nBeginInvalid && nChk <= nEndInvalid; }
     213             :     void SetInvalid( sal_Int32 nBegin, sal_Int32 nEnd );
     214           0 :     inline void Validate(){ nBeginInvalid = COMPLETE_STRING; }
     215             :     void Invalidate( sal_Int32 nBegin, sal_Int32 nEnd );
     216             :     bool InvalidateWrong();
     217             :     bool Fresh( sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos,
     218             :             sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos );
     219             :     sal_uInt16 GetWrongPos( sal_Int32 nValue ) const;
     220             : 
     221             :     bool Check( sal_Int32 &rChk, sal_Int32 &rLn ) const;
     222             :     bool InWrongWord( sal_Int32 &rChk, sal_Int32 &rLn ) const;
     223             :     sal_Int32 NextWrong( sal_Int32 nChk ) const;
     224             : 
     225             :     void Move( sal_Int32 nPos, sal_Int32 nDiff );
     226             :     void ClearList();
     227             : 
     228             :     // Divide the list into two part, the wrong words until nSplitPos will be
     229             :     // removed and transferred to a new SwWrongList.
     230             :     SwWrongList* SplitList( sal_Int32 nSplitPos );
     231             :     // Join the next SwWrongList, nInsertPos is my own text length, where
     232             :     // the other wrong list has to be inserted.
     233             :     void JoinList( SwWrongList* pNext, sal_Int32 nInsertPos );
     234             : 
     235        3468 :     inline sal_Int32 Len( sal_uInt16 nIdx ) const
     236             :     {
     237        3468 :         return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
     238             :     }
     239             : 
     240        5982 :     inline sal_Int32 Pos( sal_uInt16 nIdx ) const
     241             :     {
     242        5982 :         return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
     243             :     }
     244             : 
     245       35671 :     inline sal_uInt16 Count() const { return (sal_uInt16)maList.size(); }
     246             : 
     247         305 :     inline void Insert( const OUString& rType,
     248             :                         com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     249             :                         sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere )
     250             :     {
     251         305 :         std::vector<SwWrongArea>::iterator i = maList.begin();
     252         305 :         if ( nWhere >= maList.size() )
     253         284 :             i = maList.end(); // robust
     254             :         else
     255          21 :             i += nWhere;
     256             : 
     257         305 :         maList.insert(i, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
     258         305 :     }
     259             : 
     260             :     void Insert( const OUString& rType,
     261             :                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
     262             :                  sal_Int32 nNewPos, sal_Int32 nNewLen );
     263             : 
     264           0 :     inline SwWrongList* SubList( sal_uInt16 nIdx ) const
     265             :     {
     266           0 :         return nIdx < maList.size() ? maList[nIdx].mpSubList : 0;
     267             :     }
     268             : 
     269             :     void InsertSubList( sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
     270             : 
     271         576 :     inline const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
     272             :     {
     273         576 :         return nIdx < maList.size() ? &maList[nIdx] : 0;
     274             :     }
     275             :     void RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd );
     276             :     bool LookForEntry( sal_Int32 nBegin, sal_Int32 nEnd );
     277             : };
     278             : 
     279             : #endif
     280             : 
     281             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10