xref: /aoo41x/main/sw/source/core/inc/wrong.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef	_WRONG_HXX
25 #define	_WRONG_HXX
26 
27 #ifndef _COM_SUN_STAR_SMARTTAGS_XSMARTTAGPROPERTIES_HPP_
28 #include <com/sun/star/container/XStringKeyMap.hpp>
29 #endif
30 
31 #include <vector>
32 
33 #include <tools/string.hxx>
34 
35 class SwWrongList;
36 
37 // ST2
38 class SwWrongArea
39 {
40 public:
41     rtl::OUString maType;
42     com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > mxPropertyBag;
43     xub_StrLen mnPos;
44     xub_StrLen mnLen;
45     SwWrongList* mpSubList;
46 
47     SwWrongArea() : mnPos(0), mnLen(0), mpSubList(NULL) {}
48     SwWrongArea( const rtl::OUString& rType,
49                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
50                  xub_StrLen nPos,
51                  xub_StrLen nLen,
52                  SwWrongList* pSubList )
53         : maType(rType), mxPropertyBag(xPropertyBag), mnPos(nPos), mnLen(nLen), mpSubList(pSubList) {}
54 };
55 
56 enum WrongListType
57 {
58     WRONGLIST_SPELL,
59     WRONGLIST_GRAMMAR,
60     WRONGLIST_SMARTTAG,
61     WRONGLIST_CHANGETRACKING
62 };
63 
64 class SwWrongList
65 {
66     std::vector<SwWrongArea> maList;
67     WrongListType            meType;
68 
69     xub_StrLen nBeginInvalid;   // Start des ungueltigen Bereichs
70     xub_StrLen nEndInvalid;     // Ende des ungueltigen Bereichs
71 
72     void ShiftLeft( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd )
73     { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
74     void ShiftRight( xub_StrLen &rPos, xub_StrLen nStart, xub_StrLen nEnd )
75     { if( rPos >= nStart ) rPos += nStart - nEnd; }
76     void _Invalidate( xub_StrLen nBegin, xub_StrLen nEnd );
77 
78     void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator endPos);
79     void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
80 
81     // forbidden and not implemented
82     SwWrongList& operator= (const SwWrongList &);
83     SwWrongList( const SwWrongList& rCpy );
84 
85 public:
86     SwWrongList( WrongListType eType );
87 
88     virtual ~SwWrongList();
89     virtual SwWrongList* Clone();
90     virtual void CopyFrom( const SwWrongList& rCopy );
91 
92     inline WrongListType GetWrongListType() const { return meType; }
93     inline xub_StrLen GetBeginInv() const { return nBeginInvalid; }
94     inline xub_StrLen GetEndInv() const { return nEndInvalid; }
95     inline sal_Bool InsideInvalid( xub_StrLen nChk ) const
96         { return nChk >= nBeginInvalid && nChk <= nEndInvalid; }
97     void SetInvalid( xub_StrLen nBegin, xub_StrLen nEnd );
98     inline void Validate(){ nBeginInvalid = STRING_LEN; }
99     void Invalidate( xub_StrLen nBegin, xub_StrLen nEnd );
100     sal_Bool InvalidateWrong();
101     sal_Bool Fresh( xub_StrLen &rStart, xub_StrLen &rEnd, xub_StrLen nPos,
102             xub_StrLen nLen, sal_uInt16 nIndex, xub_StrLen nCursorPos );
103     sal_uInt16 GetWrongPos( xub_StrLen nValue ) const;
104 
105     sal_Bool Check( xub_StrLen &rChk, xub_StrLen &rLn ) const;
106     sal_Bool InWrongWord( xub_StrLen &rChk, xub_StrLen &rLn ) const;
107     xub_StrLen NextWrong( xub_StrLen nChk ) const;
108 
109     void Move( xub_StrLen nPos, long nDiff );
110     void ClearList();
111 
112     // Divide the list into two part, the wrong words until nSplitPos will be
113     // removed and transferred to a new SwWrongList.
114     SwWrongList* SplitList( xub_StrLen nSplitPos );
115     // Join the next SwWrongList, nInsertPos is my own text length, where
116     // the other wrong list has to be inserted.
117     void JoinList( SwWrongList* pNext, xub_StrLen nInsertPos );
118 
119     inline xub_StrLen Len( sal_uInt16 nIdx ) const
120     {
121         return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
122     }
123 
124     inline xub_StrLen Pos( sal_uInt16 nIdx ) const
125     {
126         return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
127     }
128 
129     inline sal_uInt16 Count() const { return (sal_uInt16)maList.size(); }
130 
131     inline void Insert( const rtl::OUString& rType,
132                         com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
133                         xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere )
134     {
135         std::vector<SwWrongArea>::iterator i = maList.begin();
136         if ( nWhere >= maList.size() )
137             i = maList.end(); // robust
138         else
139             i += nWhere;
140         maList.insert(i, SwWrongArea( rType, xPropertyBag, nNewPos, nNewLen, 0 ) );
141     }
142 
143     void Insert( const rtl::OUString& rType,
144                  com::sun::star::uno::Reference< com::sun::star::container::XStringKeyMap > xPropertyBag,
145                  xub_StrLen nNewPos, xub_StrLen nNewLen );
146 
147     inline SwWrongList* SubList( sal_uInt16 nIdx ) const
148     {
149         return nIdx < maList.size() ? maList[nIdx].mpSubList : 0;
150     }
151 
152     void InsertSubList( xub_StrLen nNewPos, xub_StrLen nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
153 
154     inline const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
155     {
156         return nIdx < maList.size() ? &maList[nIdx] : 0;
157     }
158     void RemoveEntry( xub_StrLen nBegin, xub_StrLen nEnd );
159     bool LookForEntry( xub_StrLen nBegin, xub_StrLen nEnd );
160 };
161 
162 #endif
163