11d2dbeb0SAndrew Rist /************************************************************** 21d2dbeb0SAndrew Rist * 31d2dbeb0SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 41d2dbeb0SAndrew Rist * or more contributor license agreements. See the NOTICE file 51d2dbeb0SAndrew Rist * distributed with this work for additional information 61d2dbeb0SAndrew Rist * regarding copyright ownership. The ASF licenses this file 71d2dbeb0SAndrew Rist * to you under the Apache License, Version 2.0 (the 81d2dbeb0SAndrew Rist * "License"); you may not use this file except in compliance 91d2dbeb0SAndrew Rist * with the License. You may obtain a copy of the License at 101d2dbeb0SAndrew Rist * 111d2dbeb0SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 121d2dbeb0SAndrew Rist * 131d2dbeb0SAndrew Rist * Unless required by applicable law or agreed to in writing, 141d2dbeb0SAndrew Rist * software distributed under the License is distributed on an 151d2dbeb0SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 161d2dbeb0SAndrew Rist * KIND, either express or implied. See the License for the 171d2dbeb0SAndrew Rist * specific language governing permissions and limitations 181d2dbeb0SAndrew Rist * under the License. 191d2dbeb0SAndrew Rist * 201d2dbeb0SAndrew Rist *************************************************************/ 211d2dbeb0SAndrew Rist 221d2dbeb0SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _WRONG_HXX 25cdf0e10cSrcweir #define _WRONG_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SMARTTAGS_XSMARTTAGPROPERTIES_HPP_ 28cdf0e10cSrcweir #include <com/sun/star/container/XStringKeyMap.hpp> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 3146f38707SJürgen Schmidt #include <com/sun/star/util/Color.hpp> 3246f38707SJürgen Schmidt #include <com/sun/star/awt/FontUnderline.hpp> 3346f38707SJürgen Schmidt #include <com/sun/star/uno/Any.hxx> 3446f38707SJürgen Schmidt 35cdf0e10cSrcweir #include <vector> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <tools/string.hxx> 3846f38707SJürgen Schmidt #include <tools/color.hxx> 3946f38707SJürgen Schmidt #include <viewopt.hxx> 40cdf0e10cSrcweir 41cdf0e10cSrcweir class SwWrongList; 42cdf0e10cSrcweir 4346f38707SJürgen Schmidt enum WrongAreaLineType 4446f38707SJürgen Schmidt { 4546f38707SJürgen Schmidt WRONGAREA_DASHED, 4646f38707SJürgen Schmidt WRONGAREA_WAVE, 4746f38707SJürgen Schmidt WRONGAREA_WAVE_NORMAL, 4846f38707SJürgen Schmidt WRONGAREA_WAVE_SMALL, 4946f38707SJürgen Schmidt WRONGAREA_WAVE_FLAT, 5046f38707SJürgen Schmidt WRONGAREA_NONE 5146f38707SJürgen Schmidt }; 5246f38707SJürgen Schmidt 5346f38707SJürgen Schmidt enum WrongListType 5446f38707SJürgen Schmidt { 5546f38707SJürgen Schmidt WRONGLIST_SPELL, 5646f38707SJürgen Schmidt WRONGLIST_GRAMMAR, 5746f38707SJürgen Schmidt WRONGLIST_SMARTTAG, 5846f38707SJürgen Schmidt WRONGLIST_CHANGETRACKING 5946f38707SJürgen Schmidt }; 6046f38707SJürgen Schmidt 6146f38707SJürgen Schmidt 62cdf0e10cSrcweir // ST2 63cdf0e10cSrcweir class SwWrongArea 64cdf0e10cSrcweir { 65cdf0e10cSrcweir public: 66cdf0e10cSrcweir rtl::OUString maType; 67cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > mxPropertyBag; 68cdf0e10cSrcweir xub_StrLen mnPos; 69cdf0e10cSrcweir xub_StrLen mnLen; 70cdf0e10cSrcweir SwWrongList* mpSubList; 71cdf0e10cSrcweir 7246f38707SJürgen Schmidt Color mColor; 7346f38707SJürgen Schmidt WrongAreaLineType mLineType; 7446f38707SJürgen Schmidt 7546f38707SJürgen Schmidt SwWrongArea( const rtl::OUString& rType, 7646f38707SJürgen Schmidt WrongListType listType, 7746f38707SJürgen Schmidt com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag, 7846f38707SJürgen Schmidt xub_StrLen nPos, 7946f38707SJürgen Schmidt xub_StrLen nLen); 8046f38707SJürgen Schmidt 81cdf0e10cSrcweir SwWrongArea( const rtl::OUString& rType, 82cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag, 83cdf0e10cSrcweir xub_StrLen nPos, 84cdf0e10cSrcweir xub_StrLen nLen, 8546f38707SJürgen Schmidt SwWrongList* pSubList); 8646f38707SJürgen Schmidt private: 8746f38707SJürgen Schmidt SwWrongArea()8846f38707SJürgen Schmidt SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL), mColor(0,0,0), mLineType(WRONGAREA_WAVE) {} 8946f38707SJürgen Schmidt getSmartColor(com::sun::star::uno::Reference<com::sun::star::container::XStringKeyMap> xPropertyBag)9046f38707SJürgen Schmidt Color getSmartColor ( com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag) 9146f38707SJürgen Schmidt { 9246f38707SJürgen Schmidt try 9346f38707SJürgen Schmidt { 9446f38707SJürgen Schmidt if (xPropertyBag.is()) 9546f38707SJürgen Schmidt { 9646f38707SJürgen Schmidt const ::rtl::OUString colorKey = ::rtl::OUString::createFromAscii ("LineColor"); 9746f38707SJürgen Schmidt com::sun::star::uno::Any aLineColor = xPropertyBag->getValue(colorKey).get< com::sun::star::uno::Any>(); 9846f38707SJürgen Schmidt com::sun::star::util::Color lineColor = 0; 9946f38707SJürgen Schmidt 10046f38707SJürgen Schmidt if (aLineColor >>= lineColor) 10146f38707SJürgen Schmidt { 10246f38707SJürgen Schmidt return Color( lineColor ); 10346f38707SJürgen Schmidt } 10446f38707SJürgen Schmidt } 10546f38707SJürgen Schmidt } 106*c0286415SOliver-Rainer Wittmann catch(::com::sun::star::container::NoSuchElementException& ) 10746f38707SJürgen Schmidt { 10846f38707SJürgen Schmidt } 109*c0286415SOliver-Rainer Wittmann catch(::com::sun::star::uno::RuntimeException& ) 11046f38707SJürgen Schmidt { 11146f38707SJürgen Schmidt } 11246f38707SJürgen Schmidt 11346f38707SJürgen Schmidt return SwViewOption::GetSmarttagColor( ); 11446f38707SJürgen Schmidt } 11546f38707SJürgen Schmidt getSmartLineType(com::sun::star::uno::Reference<com::sun::star::container::XStringKeyMap> xPropertyBag)11646f38707SJürgen Schmidt WrongAreaLineType getSmartLineType( com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag ) 11746f38707SJürgen Schmidt { 11846f38707SJürgen Schmidt try 11946f38707SJürgen Schmidt { 12046f38707SJürgen Schmidt if (xPropertyBag.is()) 12146f38707SJürgen Schmidt { 12246f38707SJürgen Schmidt const ::rtl::OUString typeKey = ::rtl::OUString::createFromAscii ("LineType"); 12346f38707SJürgen Schmidt com::sun::star::uno::Any aLineType = xPropertyBag->getValue(typeKey).get< com::sun::star::uno::Any>(); 12446f38707SJürgen Schmidt ::sal_Int16 lineType = 0; 12546f38707SJürgen Schmidt 12646f38707SJürgen Schmidt if (!(aLineType >>= lineType)) 12746f38707SJürgen Schmidt { 12846f38707SJürgen Schmidt return WRONGAREA_DASHED; 12946f38707SJürgen Schmidt } 13046f38707SJürgen Schmidt if (::com::sun::star::awt::FontUnderline::WAVE == lineType) 13146f38707SJürgen Schmidt { 13246f38707SJürgen Schmidt return WRONGAREA_WAVE_NORMAL; 13346f38707SJürgen Schmidt } 13446f38707SJürgen Schmidt if (::com::sun::star::awt::FontUnderline::SMALLWAVE == lineType) 13546f38707SJürgen Schmidt { 13646f38707SJürgen Schmidt return WRONGAREA_WAVE_SMALL; 13746f38707SJürgen Schmidt } 13846f38707SJürgen Schmidt } 13946f38707SJürgen Schmidt } 140*c0286415SOliver-Rainer Wittmann catch(::com::sun::star::container::NoSuchElementException& ) 14146f38707SJürgen Schmidt { 14246f38707SJürgen Schmidt } 143*c0286415SOliver-Rainer Wittmann catch(::com::sun::star::uno::RuntimeException& ) 14446f38707SJürgen Schmidt { 14546f38707SJürgen Schmidt } 14646f38707SJürgen Schmidt 14746f38707SJürgen Schmidt return WRONGAREA_DASHED; 14846f38707SJürgen Schmidt } 14946f38707SJürgen Schmidt getWrongAreaColor(WrongListType listType,com::sun::star::uno::Reference<com::sun::star::container::XStringKeyMap> xPropertyBag)15046f38707SJürgen Schmidt Color getWrongAreaColor(WrongListType listType, 15146f38707SJürgen Schmidt com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag ) 15246f38707SJürgen Schmidt { 15346f38707SJürgen Schmidt if (WRONGLIST_SPELL == listType) 15446f38707SJürgen Schmidt { 15546f38707SJürgen Schmidt return SwViewOption::GetSpellColor(); 15646f38707SJürgen Schmidt } 15746f38707SJürgen Schmidt else if (WRONGLIST_GRAMMAR == listType) 15846f38707SJürgen Schmidt { 15946f38707SJürgen Schmidt return Color( COL_LIGHTBLUE ); 16046f38707SJürgen Schmidt } 16146f38707SJürgen Schmidt else if (WRONGLIST_SMARTTAG == listType) 16246f38707SJürgen Schmidt { 16346f38707SJürgen Schmidt return getSmartColor(xPropertyBag); 16446f38707SJürgen Schmidt } 16546f38707SJürgen Schmidt 16646f38707SJürgen Schmidt return SwViewOption::GetSpellColor(); 16746f38707SJürgen Schmidt } 16846f38707SJürgen Schmidt getWrongAreaLineType(WrongListType listType,com::sun::star::uno::Reference<com::sun::star::container::XStringKeyMap> xPropertyBag)16946f38707SJürgen Schmidt WrongAreaLineType getWrongAreaLineType(WrongListType listType, 17046f38707SJürgen Schmidt com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag ) 17146f38707SJürgen Schmidt { 17246f38707SJürgen Schmidt if (WRONGLIST_SPELL == listType) 17346f38707SJürgen Schmidt { 17446f38707SJürgen Schmidt return WRONGAREA_WAVE; 17546f38707SJürgen Schmidt } 17646f38707SJürgen Schmidt else if (WRONGLIST_GRAMMAR == listType) 17746f38707SJürgen Schmidt { 17846f38707SJürgen Schmidt return WRONGAREA_WAVE; 17946f38707SJürgen Schmidt } 18046f38707SJürgen Schmidt else if (WRONGLIST_SMARTTAG == listType) 18146f38707SJürgen Schmidt { 18246f38707SJürgen Schmidt return getSmartLineType(xPropertyBag); 18346f38707SJürgen Schmidt } 18446f38707SJürgen Schmidt 18546f38707SJürgen Schmidt return WRONGAREA_WAVE; 18646f38707SJürgen Schmidt } 187cdf0e10cSrcweir 188cdf0e10cSrcweir }; 189cdf0e10cSrcweir 190cdf0e10cSrcweir class SwWrongList 191cdf0e10cSrcweir { 192cdf0e10cSrcweir std::vector<SwWrongArea> maList; 193cdf0e10cSrcweir WrongListType meType; 194cdf0e10cSrcweir 195cdf0e10cSrcweir xub_StrLen nBeginInvalid; // Start des ungueltigen Bereichs 196cdf0e10cSrcweir xub_StrLen nEndInvalid; // Ende des ungueltigen Bereichs 197cdf0e10cSrcweir ShiftLeft(xub_StrLen & rPos,xub_StrLen nStart,xub_StrLen nEnd)198cdf0e10cSrcweir void ShiftLeft( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd ) 199cdf0e10cSrcweir { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; } ShiftRight(xub_StrLen & rPos,xub_StrLen nStart,xub_StrLen nEnd)200cdf0e10cSrcweir void ShiftRight( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd ) 201cdf0e10cSrcweir { if( rPos >= nStart ) rPos += nStart - nEnd; } 202cdf0e10cSrcweir void _Invalidate( xub_StrLen nBegin, xub_StrLen nEnd ); 203cdf0e10cSrcweir 204cdf0e10cSrcweir void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos); 205cdf0e10cSrcweir void Remove( sal_uInt16 nIdx, sal_uInt16 nLen ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir // forbidden and not implemented 208cdf0e10cSrcweir SwWrongList& operator= (const SwWrongList &); 209cdf0e10cSrcweir SwWrongList( const SwWrongList& rCpy ); 210cdf0e10cSrcweir 211cdf0e10cSrcweir public: 212cdf0e10cSrcweir SwWrongList( WrongListType eType ); 213cdf0e10cSrcweir 214cdf0e10cSrcweir virtual ~SwWrongList(); 215cdf0e10cSrcweir virtual SwWrongList* Clone(); 216cdf0e10cSrcweir virtual void CopyFrom( const SwWrongList& rCopy ); 217cdf0e10cSrcweir GetWrongListType() const218cdf0e10cSrcweir inline WrongListType GetWrongListType() const { return meType; } GetBeginInv() const219cdf0e10cSrcweir inline xub_StrLen GetBeginInv() const { return nBeginInvalid; } GetEndInv() const220cdf0e10cSrcweir inline xub_StrLen GetEndInv() const { return nEndInvalid; } InsideInvalid(xub_StrLen nChk) const221cdf0e10cSrcweir inline sal_Bool InsideInvalid( xub_StrLen nChk ) const 222cdf0e10cSrcweir { return nChk >= nBeginInvalid && nChk <= nEndInvalid; } 223cdf0e10cSrcweir void SetInvalid( xub_StrLen nBegin, xub_StrLen nEnd ); Validate()224cdf0e10cSrcweir inline void Validate(){ nBeginInvalid = STRING_LEN; } 225cdf0e10cSrcweir void Invalidate( xub_StrLen nBegin, xub_StrLen nEnd ); 226cdf0e10cSrcweir sal_Bool InvalidateWrong(); 227cdf0e10cSrcweir sal_Bool Fresh( xub_StrLen &rStart, xub_StrLen &rEnd, xub_StrLen nPos, 228cdf0e10cSrcweir xub_StrLen nLen, sal_uInt16 nIndex, xub_StrLen nCursorPos ); 229cdf0e10cSrcweir sal_uInt16 GetWrongPos( xub_StrLen nValue ) const; 230cdf0e10cSrcweir 231cdf0e10cSrcweir sal_Bool Check( xub_StrLen &rChk, xub_StrLen &rLn ) const; 232cdf0e10cSrcweir sal_Bool InWrongWord( xub_StrLen &rChk, xub_StrLen &rLn ) const; 233cdf0e10cSrcweir xub_StrLen NextWrong( xub_StrLen nChk ) const; 234cdf0e10cSrcweir 235cdf0e10cSrcweir void Move( xub_StrLen nPos, long nDiff ); 236cdf0e10cSrcweir void ClearList(); 237cdf0e10cSrcweir 238cdf0e10cSrcweir // Divide the list into two part, the wrong words until nSplitPos will be 239cdf0e10cSrcweir // removed and transferred to a new SwWrongList. 240cdf0e10cSrcweir SwWrongList* SplitList( xub_StrLen nSplitPos ); 241cdf0e10cSrcweir // Join the next SwWrongList, nInsertPos is my own text length, where 242cdf0e10cSrcweir // the other wrong list has to be inserted. 243cdf0e10cSrcweir void JoinList( SwWrongList* pNext, xub_StrLen nInsertPos ); 244cdf0e10cSrcweir Len(sal_uInt16 nIdx) const245cdf0e10cSrcweir inline xub_StrLen Len( sal_uInt16 nIdx ) const 246cdf0e10cSrcweir { 247cdf0e10cSrcweir return nIdx < maList.size() ? maList[nIdx].mnLen : 0; 248cdf0e10cSrcweir } 249cdf0e10cSrcweir Pos(sal_uInt16 nIdx) const250cdf0e10cSrcweir inline xub_StrLen Pos( sal_uInt16 nIdx ) const 251cdf0e10cSrcweir { 252cdf0e10cSrcweir return nIdx < maList.size() ? maList[nIdx].mnPos : 0; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir Count() const255cdf0e10cSrcweir inline sal_uInt16 Count() const { return (sal_uInt16)maList.size(); } 256cdf0e10cSrcweir Insert(const rtl::OUString & rType,com::sun::star::uno::Reference<com::sun::star::container::XStringKeyMap> xPropertyBag,xub_StrLen nNewPos,xub_StrLen nNewLen,sal_uInt16 nWhere)257cdf0e10cSrcweir inline void Insert( const rtl::OUString& rType, 258cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag, 259cdf0e10cSrcweir xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere ) 260cdf0e10cSrcweir { 261cdf0e10cSrcweir std::vector<SwWrongArea>::iterator i = maList.begin(); 262cdf0e10cSrcweir if ( nWhere >= maList.size() ) 263cdf0e10cSrcweir i = maList.end(); // robust 264cdf0e10cSrcweir else 265cdf0e10cSrcweir i += nWhere; 26646f38707SJürgen Schmidt 26746f38707SJürgen Schmidt maList.insert(i, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) ); 268cdf0e10cSrcweir } 269cdf0e10cSrcweir 270cdf0e10cSrcweir void Insert( const rtl::OUString& rType, 271cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag, 272cdf0e10cSrcweir xub_StrLen nNewPos, xub_StrLen nNewLen ); 273cdf0e10cSrcweir SubList(sal_uInt16 nIdx) const274cdf0e10cSrcweir inline SwWrongList* SubList( sal_uInt16 nIdx ) const 275cdf0e10cSrcweir { 276cdf0e10cSrcweir return nIdx < maList.size() ? maList[nIdx].mpSubList : 0; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir void InsertSubList( xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList ); 280cdf0e10cSrcweir GetElement(sal_uInt16 nIdx) const281cdf0e10cSrcweir inline const SwWrongArea* GetElement( sal_uInt16 nIdx ) const 282cdf0e10cSrcweir { 283cdf0e10cSrcweir return nIdx < maList.size() ? &maList[nIdx] : 0; 284cdf0e10cSrcweir } 285cdf0e10cSrcweir void RemoveEntry( xub_StrLen nBegin, xub_StrLen nEnd ); 286cdf0e10cSrcweir bool LookForEntry( xub_StrLen nBegin, xub_StrLen nEnd ); 287cdf0e10cSrcweir }; 288cdf0e10cSrcweir 289cdf0e10cSrcweir #endif 290