LibreOffice Module sw (master)  1
wrong.hxx
Go to the documentation of this file.
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/NoSuchElementException.hpp>
24 #include <com/sun/star/container/XStringKeyMap.hpp>
25 
26 #include <com/sun/star/util/Color.hpp>
27 #include <com/sun/star/awt/FontUnderline.hpp>
28 #include <com/sun/star/uno/Any.hxx>
29 
30 #include <vector>
31 
32 #include <optional>
33 
34 #include <tools/color.hxx>
35 #include <swtypes.hxx>
36 #include <viewopt.hxx>
37 #include "TextFrameIndex.hxx"
38 
39 #if defined _MSC_VER
40 // For MSVC (without /vmg) SwTextNode must consistently be defined for
41 // WrongListIterator::m_pGetWrongList of pointer-to-SwTextNode-member type to consistently have the
42 // same size in all translation units that include this file:
43 #include <ndtxt.hxx>
44 #endif
45 
46 class SwWrongList;
47 
49 {
55 };
56 
58 {
63 };
64 
65 // ST2
67 {
68 public:
69  OUString maType;
70  sal_Int32 mnPos;
71  sal_Int32 mnLen;
73 
76 
77  SwWrongArea( const OUString& rType,
78  WrongListType listType,
79  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
80  sal_Int32 nPos,
81  sal_Int32 nLen);
82 
83  SwWrongArea( const OUString& rType,
84  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
85  sal_Int32 nPos,
86  sal_Int32 nLen,
87  SwWrongList* pSubList);
88 private:
89 
90  static Color getGrammarColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag)
91  {
92  try
93  {
94  if (xPropertyBag.is())
95  {
96  css::uno::Any aLineColor = xPropertyBag->getValue("LineColor");
97  css::util::Color lineColor = 0;
98 
99  if (aLineColor >>= lineColor)
100  {
101  return Color( lineColor );
102  }
103  }
104  }
105  catch(const css::container::NoSuchElementException&)
106  {
107  }
108  catch(const css::uno::RuntimeException&)
109  {
110  }
111 
112  return COL_LIGHTBLUE;
113  }
114 
115  static WrongAreaLineType getGrammarLineType( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
116  {
117  try
118  {
119  if (xPropertyBag.is())
120  {
121  css::uno::Any aLineType = xPropertyBag->getValue("LineType");
122  ::sal_Int16 lineType = 0;
123 
124  if (!(aLineType >>= lineType))
125  {
126  return WRONGAREA_WAVE;
127  }
128  if (css::awt::FontUnderline::BOLDWAVE == lineType)
129  {
130  return WRONGAREA_BOLDWAVE;
131  }
132  if (css::awt::FontUnderline::BOLD == lineType)
133  {
134  return WRONGAREA_BOLD;
135  }
136  if (css::awt::FontUnderline::DASH == lineType)
137  {
138  return WRONGAREA_DASHED;
139  }
140  if (css::awt::FontUnderline::SMALLWAVE == lineType)
141  {
142  return WRONGAREA_WAVE; //Code draws wave height based on space that fits.
143  }
144  }
145  }
146  catch(const css::container::NoSuchElementException&)
147  {
148  }
149  catch(const css::uno::RuntimeException&)
150  {
151  }
152 
153  return WRONGAREA_WAVE;
154  }
155 
156  static Color getSmartColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag)
157  {
158  try
159  {
160  if (xPropertyBag.is())
161  {
162  css::uno::Any aLineColor = xPropertyBag->getValue("LineColor");
163  css::util::Color lineColor = 0;
164 
165  if (aLineColor >>= lineColor)
166  {
167  return Color( lineColor );
168  }
169  }
170  }
171  catch(const css::container::NoSuchElementException&)
172  {
173  }
174  catch(const css::uno::RuntimeException&)
175  {
176  }
177 
179  }
180 
181  static WrongAreaLineType getSmartLineType( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
182  {
183  try
184  {
185  if (xPropertyBag.is())
186  {
187  css::uno::Any aLineType = xPropertyBag->getValue("LineType");
188  ::sal_Int16 lineType = 0;
189 
190  if (!(aLineType >>= lineType))
191  {
192  return WRONGAREA_DASHED;
193  }
194  if (css::awt::FontUnderline::WAVE == lineType)
195  {
196  return WRONGAREA_WAVE;
197  }
198  if (css::awt::FontUnderline::BOLDWAVE == lineType)
199  {
200  return WRONGAREA_BOLDWAVE;
201  }
202  if (css::awt::FontUnderline::BOLD == lineType)
203  {
204  return WRONGAREA_BOLD;
205  }
206  if (css::awt::FontUnderline::SMALLWAVE == lineType)
207  {
208  return WRONGAREA_WAVE; //Code draws wave height based on space that fits.
209  }
210  }
211  }
212  catch(const css::container::NoSuchElementException&)
213  {
214  }
215  catch(const css::uno::RuntimeException&)
216  {
217  }
218 
219  return WRONGAREA_DASHED;
220  }
221 
223  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
224  {
225  if (WRONGLIST_SPELL == listType)
226  {
228  }
229  else if (WRONGLIST_GRAMMAR == listType)
230  {
231  return getGrammarColor(xPropertyBag);
232  }
233  else if (WRONGLIST_SMARTTAG == listType)
234  {
235  return getSmartColor(xPropertyBag);
236  }
237 
239  }
240 
242  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
243  {
244  if (WRONGLIST_SPELL == listType)
245  {
246  return WRONGAREA_WAVE;
247  }
248  else if (WRONGLIST_GRAMMAR == listType)
249  {
250  return getGrammarLineType(xPropertyBag);
251  }
252  else if (WRONGLIST_SMARTTAG == listType)
253  {
254  return getSmartLineType(xPropertyBag);
255  }
256 
257  return WRONGAREA_WAVE;
258  }
259 
260 };
261 
263 {
264  std::vector<SwWrongArea> maList;
266 
267  sal_Int32 mnBeginInvalid; // Start of the invalid range
268  sal_Int32 mnEndInvalid; // End of the invalid range
269 
270  static void ShiftLeft( sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd )
271  { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
272  void Invalidate_( sal_Int32 nBegin, sal_Int32 nEnd );
273 
274  void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator const & endPos);
275  void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
276 
277  SwWrongList& operator= (const SwWrongList &) = delete;
278  SwWrongList( const SwWrongList& rCpy ) = delete;
279 
280 public:
281  SwWrongList( WrongListType eType );
282 
283  virtual ~SwWrongList();
284  virtual SwWrongList* Clone();
285  virtual void CopyFrom( const SwWrongList& rCopy );
286 
288  sal_Int32 GetBeginInv() const { return mnBeginInvalid; }
289  sal_Int32 GetEndInv() const { return mnEndInvalid; }
290  void SetInvalid( sal_Int32 nBegin, sal_Int32 nEnd );
291  void Validate(){ mnBeginInvalid = mnEndInvalid = COMPLETE_STRING; }
292  void Invalidate( sal_Int32 nBegin, sal_Int32 nEnd );
293  bool InvalidateWrong();
294  enum class FreshState { FRESH, CURSOR, NOTHING };
295  FreshState Fresh( sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos,
296  sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos );
297  sal_uInt16 GetWrongPos( sal_Int32 nValue ) const;
298 
299  bool Check( sal_Int32 &rChk, sal_Int32 &rLn ) const;
300  bool InWrongWord( sal_Int32 &rChk, sal_Int32 &rLn ) const;
301  sal_Int32 NextWrong( sal_Int32 nChk ) const;
302 
303  void Move( sal_Int32 nPos, sal_Int32 nDiff );
304  void ClearList();
305 
306  // Divide the list into two part, the wrong words until nSplitPos will be
307  // removed and transferred to a new SwWrongList.
308  SwWrongList* SplitList( sal_Int32 nSplitPos );
309  // Join the next SwWrongList, nInsertPos is my own text length, where
310  // the other wrong list has to be inserted.
311  void JoinList( SwWrongList* pNext, sal_Int32 nInsertPos );
312 
313  sal_Int32 Len( sal_uInt16 nIdx ) const
314  {
315  return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
316  }
317 
318  sal_Int32 Pos( sal_uInt16 nIdx ) const
319  {
320  return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
321  }
322 
323  sal_uInt16 Count() const { return static_cast<sal_uInt16>(maList.size()); }
324 
325  void Insert( const OUString& rType,
326  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
327  sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere )
328  {
329  std::vector<SwWrongArea>::iterator i = maList.begin();
330  if ( nWhere >= maList.size() )
331  i = maList.end(); // robust
332  else
333  i += nWhere;
334 
335  maList.insert(i, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
336  }
337 
338  void Insert( const OUString& rType,
339  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
340  sal_Int32 nNewPos, sal_Int32 nNewLen );
341 
342  SwWrongList* SubList( sal_uInt16 nIdx ) const
343  {
344  return nIdx < maList.size() ? maList[nIdx].mpSubList : nullptr;
345  }
346 
347  void InsertSubList( sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
348 
349  const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
350  {
351  return nIdx < maList.size() ? &maList[nIdx] : nullptr;
352  }
353  void RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd );
354  bool LookForEntry( sal_Int32 nBegin, sal_Int32 nEnd );
355 };
356 
357 class SwTextNode;
358 class SwTextFrame;
359 
360 namespace sw {
361 
362 struct MergedPara;
363 
365 {
366 protected:
367  SwWrongList const* (SwTextNode::*const m_pGetWrongList)() const;
372 
373 public:
375  WrongListIteratorBase(SwTextFrame const& rFrame,
376  SwWrongList const* (SwTextNode::*pGetWrongList)() const);
378  WrongListIteratorBase(SwWrongList const& rWrongList);
379 };
380 
382  : public WrongListIteratorBase
383 {
384 public:
386  WrongListIterator(SwTextFrame const& rFrame,
387  SwWrongList const* (SwTextNode::*pGetWrongList)() const);
389  WrongListIterator(SwWrongList const& rWrongList);
390 
391  bool Check(TextFrameIndex &rStart, TextFrameIndex &rLen);
393 
394  bool LooksUseful() { return m_pMergedPara || m_pWrongList; }
395 };
396 
398  : public WrongListIteratorBase
399 {
400 public:
402  SwWrongList const* (SwTextNode::*pGetWrongList)() const);
403  WrongListIteratorCounter(SwWrongList const& rWrongList);
404 
405  sal_uInt16 GetElementCount();
406  std::optional<std::pair<TextFrameIndex, TextFrameIndex>> GetElementAt(sal_uInt16 nIndex);
407 };
408 
409 } // namespace sw
410 
411 #endif
412 
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 mnBeginInvalid
Definition: wrong.hxx:267
sal_Int32 Pos(sal_uInt16 nIdx) const
Definition: wrong.hxx:318
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
bool InvalidateWrong()
Definition: wrong.cxx:433
WrongListType
Definition: wrong.hxx:57
sal_Int32 nIndex
const SwWrongArea * GetWrongElement(TextFrameIndex nStart)
Definition: wrong.cxx:785
void Invalidate_(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:245
FreshState Fresh(sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos, sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos)
Remove given range of entries.
Definition: wrong.cxx:355
void Move(sal_Int32 nPos, sal_Int32 nDiff)
Change all values after the given position.
Definition: wrong.cxx:266
void Insert(const OUString &rType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag, sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere)
Definition: wrong.hxx:325
SwWrongList const *const m_pWrongList
Definition: wrong.hxx:371
void InsertSubList(sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList *pSubList)
Definition: wrong.cxx:522
WrongAreaLineType mLineType
Definition: wrong.hxx:75
Dialog to specify the properties of date form field.
static Color & GetSmarttagColor()
Definition: viewopt.cxx:423
static WrongAreaLineType getWrongAreaLineType(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:241
WrongListIteratorBase(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
for the text frame
Definition: wrong.cxx:640
void RemoveEntry(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:585
SwWrongList * SubList(sal_uInt16 nIdx) const
Definition: wrong.hxx:342
Color mColor
Definition: wrong.hxx:74
static WrongAreaLineType getGrammarLineType(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:115
virtual void CopyFrom(const SwWrongList &rCopy)
Definition: wrong.cxx:72
void Remove(sal_uInt16 nIdx, sal_uInt16 nLen)
Definition: wrong.cxx:555
void JoinList(SwWrongList *pNext, sal_Int32 nInsertPos)
Definition: wrong.cxx:489
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:947
virtual SwWrongList * Clone()
Definition: wrong.cxx:65
sal_Int32 NextWrong(sal_Int32 nChk) const
Find next incorrectly selected position.
Definition: wrong.cxx:163
SwWrongList * mpSubList
Definition: wrong.hxx:72
static Color getWrongAreaColor(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:222
SwWrongList const *(SwTextNode::*const m_pGetWrongList)() const
Definition: wrong.hxx:367
sal_uInt16 Count() const
Definition: wrong.hxx:323
SwWrongList * SplitList(sal_Int32 nSplitPos)
Definition: wrong.cxx:445
virtual ~SwWrongList()
Definition: wrong.cxx:60
int i
sw::MergedPara const *const m_pMergedPara
Definition: wrong.hxx:368
sal_Int32 mnLen
Definition: wrong.hxx:71
sal_Int32 Len(sal_uInt16 nIdx) const
Definition: wrong.hxx:313
bool LookForEntry(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:613
void Invalidate(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:425
static WrongAreaLineType getSmartLineType(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:181
bool Check(sal_Int32 &rChk, sal_Int32 &rLn) const
Calculate first incorrectly selected area.
Definition: wrong.cxx:126
sal_Int32 GetEndInv() const
Definition: wrong.hxx:289
WrongListIteratorCounter(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
Definition: wrong.cxx:823
bool Check(TextFrameIndex &rStart, TextFrameIndex &rLen)
Definition: wrong.cxx:672
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
WrongListType GetWrongListType() const
Definition: wrong.hxx:287
sal_Int32 GetBeginInv() const
Definition: wrong.hxx:288
WrongListIterator(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
for the text frame
Definition: wrong.cxx:661
WrongAreaLineType
Definition: wrong.hxx:48
OUString maType
Definition: wrong.hxx:69
sal_uInt16 GetWrongPos(sal_Int32 nValue) const
Find the first position that is greater or equal to the given value.
Definition: wrong.cxx:190
void ClearList()
Definition: wrong.cxx:85
bool InWrongWord(sal_Int32 &rChk, sal_Int32 &rLn) const
If a word is incorrectly selected, this method returns begin and length of it.
Definition: wrong.cxx:102
static void ShiftLeft(sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd)
Definition: wrong.hxx:270
const SwWrongArea * GetElement(sal_uInt16 nIdx) const
Definition: wrong.hxx:349
SwWrongList(const SwWrongList &rCpy)=delete
sal_Int32 mnPos
Definition: wrong.hxx:70
std::optional< std::pair< TextFrameIndex, TextFrameIndex > > GetElementAt(sal_uInt16 nIndex)
Definition: wrong.cxx:879
WrongListType meType
Definition: wrong.hxx:265
sal_uInt16 GetElementCount()
Definition: wrong.cxx:834
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTBLUE
static Color & GetSpellColor()
Definition: viewopt.cxx:418
SwWrongArea(const OUString &rType, WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag, sal_Int32 nPos, sal_Int32 nLen)
Definition: wrong.cxx:28
std::vector< SwWrongArea > maList
Definition: wrong.hxx:264
TextFrameIndex m_CurrentIndex
Definition: wrong.hxx:370
static Color getGrammarColor(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:90
void Insert(sal_uInt16 nWhere, std::vector< SwWrongArea >::iterator startPos, std::vector< SwWrongArea >::iterator const &endPos)
Definition: wrong.cxx:537
static Color getSmartColor(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:156
sal_Int32 mnEndInvalid
Definition: wrong.hxx:268
void Validate()
Definition: wrong.hxx:291
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
SwWrongList & operator=(const SwWrongList &)=delete
void SetInvalid(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:253