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