Update ooo320-m1
[ooovba.git] / sw / source / core / inc / wrong.hxx
blob50aa25d1a5b6f7732074e011f58567892912d3bb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: wrong.hxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _WRONG_HXX
32 #define _WRONG_HXX
34 #ifndef _COM_SUN_STAR_SMARTTAGS_XSMARTTAGPROPERTIES_HPP_
35 #include <com/sun/star/container/XStringKeyMap.hpp>
36 #endif
38 #include <vector>
40 #include <tools/string.hxx>
42 class SwWrongList;
44 // ST2
45 class SwWrongArea
47 public:
48 rtl::OUString maType;
49 com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > mxPropertyBag;
50 xub_StrLen mnPos;
51 xub_StrLen mnLen;
52 SwWrongList* mpSubList;
54 SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL) {}
55 SwWrongArea( const rtl::OUString& rType,
56 com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
57 xub_StrLen nPos,
58 xub_StrLen nLen,
59 SwWrongList* pSubList )
60 : maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(pSubList) {}
63 enum WrongListType { WRONGLIST_SPELL, WRONGLIST_GRAMMAR, WRONGLIST_SMARTTAG };
65 class SwWrongList
67 std::vector<SwWrongArea> maList;
68 WrongListType meType;
70 xub_StrLen nBeginInvalid; // Start des ungueltigen Bereichs
71 xub_StrLen nEndInvalid; // Ende des ungueltigen Bereichs
73 void ShiftLeft( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd )
74 { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
75 void ShiftRight( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd )
76 { if( rPos >= nStart ) rPos += nStart - nEnd; }
77 void _Invalidate( xub_StrLen nBegin, xub_StrLen nEnd );
79 void Insert(USHORT nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos);
80 void Remove( USHORT nIdx, USHORT nLen );
82 // forbidden and not implemented
83 SwWrongList& operator= (const SwWrongList &);
84 SwWrongList( const SwWrongList& rCpy );
86 public:
87 SwWrongList( WrongListType eType );
89 virtual ~SwWrongList();
90 virtual SwWrongList* Clone();
91 virtual void CopyFrom( const SwWrongList& rCopy );
93 inline WrongListType GetWrongListType() const { return meType; }
94 inline xub_StrLen GetBeginInv() const { return nBeginInvalid; }
95 inline xub_StrLen GetEndInv() const { return nEndInvalid; }
96 inline BOOL InsideInvalid( xub_StrLen nChk ) const
97 { return nChk >= nBeginInvalid && nChk <= nEndInvalid; }
98 void SetInvalid( xub_StrLen nBegin, xub_StrLen nEnd );
99 inline void Validate(){ nBeginInvalid = STRING_LEN; }
100 void Invalidate( xub_StrLen nBegin, xub_StrLen nEnd );
101 BOOL InvalidateWrong();
102 BOOL Fresh( xub_StrLen &rStart, xub_StrLen &rEnd, xub_StrLen nPos,
103 xub_StrLen nLen, USHORT nIndex, xub_StrLen nCursorPos );
104 USHORT GetWrongPos( xub_StrLen nValue ) const;
106 sal_Bool Check( xub_StrLen &rChk, xub_StrLen &rLn ) const;
107 sal_Bool InWrongWord( xub_StrLen &rChk, xub_StrLen &rLn ) const;
108 xub_StrLen NextWrong( xub_StrLen nChk ) const;
110 void Move( xub_StrLen nPos, long nDiff );
111 void ClearList();
113 // Divide the list into two part, the wrong words until nSplitPos will be
114 // removed and transferred to a new SwWrongList.
115 SwWrongList* SplitList( xub_StrLen nSplitPos );
116 // Join the next SwWrongList, nInsertPos is my own text length, where
117 // the other wrong list has to be inserted.
118 void JoinList( SwWrongList* pNext, xub_StrLen nInsertPos );
120 inline xub_StrLen Len( USHORT nIdx ) const
122 return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
125 inline xub_StrLen Pos( USHORT nIdx ) const
127 return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
130 inline USHORT Count() const { return (USHORT)maList.size(); }
132 inline void Insert( const rtl::OUString& rType,
133 com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
134 xub_StrLen nNewPos, xub_StrLen nNewLen, USHORT nWhere )
136 std::vector<SwWrongArea>::iterator i = maList.begin();
137 if ( nWhere >= maList.size() )
138 i = maList.end(); // robust
139 else
140 i += nWhere;
141 maList.insert(i, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) );
144 void Insert( const rtl::OUString& rType,
145 com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
146 xub_StrLen nNewPos, xub_StrLen nNewLen );
148 inline SwWrongList* SubList( USHORT nIdx ) const
150 return nIdx < maList.size() ? maList[nIdx].mpSubList : 0;
153 void InsertSubList( xub_StrLen nNewPos, xub_StrLen nNewLen, USHORT nWhere, SwWrongList* pSubList );
155 inline const SwWrongArea* GetElement( USHORT nIdx ) const
157 return nIdx < maList.size() ? &maList[nIdx] : 0;
159 void RemoveEntry( xub_StrLen nBegin, xub_StrLen nEnd );
160 bool LookForEntry( xub_StrLen nBegin, xub_StrLen nEnd );
163 #endif