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 <boost/optional.hpp>
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  const OUString colorKey("LineColor");
97  css::uno::Any aLineColor = xPropertyBag->getValue(colorKey);
98  css::util::Color lineColor = 0;
99 
100  if (aLineColor >>= lineColor)
101  {
102  return Color( lineColor );
103  }
104  }
105  }
106  catch(const css::container::NoSuchElementException&)
107  {
108  }
109  catch(const css::uno::RuntimeException&)
110  {
111  }
112 
113  return COL_LIGHTBLUE;
114  }
115 
116  static WrongAreaLineType getGrammarLineType( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
117  {
118  try
119  {
120  if (xPropertyBag.is())
121  {
122  const OUString typeKey("LineType");
123  css::uno::Any aLineType = xPropertyBag->getValue(typeKey);
124  ::sal_Int16 lineType = 0;
125 
126  if (!(aLineType >>= lineType))
127  {
128  return WRONGAREA_WAVE;
129  }
130  if (css::awt::FontUnderline::BOLDWAVE == lineType)
131  {
132  return WRONGAREA_BOLDWAVE;
133  }
134  if (css::awt::FontUnderline::BOLD == lineType)
135  {
136  return WRONGAREA_BOLD;
137  }
138  if (css::awt::FontUnderline::DASH == lineType)
139  {
140  return WRONGAREA_DASHED;
141  }
142  if (css::awt::FontUnderline::SMALLWAVE == lineType)
143  {
144  return WRONGAREA_WAVE; //Code draws wave height based on space that fits.
145  }
146  }
147  }
148  catch(const css::container::NoSuchElementException&)
149  {
150  }
151  catch(const css::uno::RuntimeException&)
152  {
153  }
154 
155  return WRONGAREA_WAVE;
156  }
157 
158  static Color getSmartColor ( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag)
159  {
160  try
161  {
162  if (xPropertyBag.is())
163  {
164  const OUString colorKey("LineColor");
165  css::uno::Any aLineColor = xPropertyBag->getValue(colorKey);
166  css::util::Color lineColor = 0;
167 
168  if (aLineColor >>= lineColor)
169  {
170  return Color( lineColor );
171  }
172  }
173  }
174  catch(const css::container::NoSuchElementException&)
175  {
176  }
177  catch(const css::uno::RuntimeException&)
178  {
179  }
180 
182  }
183 
184  static WrongAreaLineType getSmartLineType( css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
185  {
186  try
187  {
188  if (xPropertyBag.is())
189  {
190  const OUString typeKey("LineType");
191  css::uno::Any aLineType = xPropertyBag->getValue(typeKey);
192  ::sal_Int16 lineType = 0;
193 
194  if (!(aLineType >>= lineType))
195  {
196  return WRONGAREA_DASHED;
197  }
198  if (css::awt::FontUnderline::WAVE == lineType)
199  {
200  return WRONGAREA_WAVE;
201  }
202  if (css::awt::FontUnderline::BOLDWAVE == lineType)
203  {
204  return WRONGAREA_BOLDWAVE;
205  }
206  if (css::awt::FontUnderline::BOLD == lineType)
207  {
208  return WRONGAREA_BOLD;
209  }
210  if (css::awt::FontUnderline::SMALLWAVE == lineType)
211  {
212  return WRONGAREA_WAVE; //Code draws wave height based on space that fits.
213  }
214  }
215  }
216  catch(const css::container::NoSuchElementException&)
217  {
218  }
219  catch(const css::uno::RuntimeException&)
220  {
221  }
222 
223  return WRONGAREA_DASHED;
224  }
225 
227  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
228  {
229  if (WRONGLIST_SPELL == listType)
230  {
232  }
233  else if (WRONGLIST_GRAMMAR == listType)
234  {
235  return getGrammarColor(xPropertyBag);
236  }
237  else if (WRONGLIST_SMARTTAG == listType)
238  {
239  return getSmartColor(xPropertyBag);
240  }
241 
243  }
244 
246  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag )
247  {
248  if (WRONGLIST_SPELL == listType)
249  {
250  return WRONGAREA_WAVE;
251  }
252  else if (WRONGLIST_GRAMMAR == listType)
253  {
254  return getGrammarLineType(xPropertyBag);
255  }
256  else if (WRONGLIST_SMARTTAG == listType)
257  {
258  return getSmartLineType(xPropertyBag);
259  }
260 
261  return WRONGAREA_WAVE;
262  }
263 
264 };
265 
267 {
268  std::vector<SwWrongArea> maList;
270 
271  sal_Int32 mnBeginInvalid; // Start of the invalid range
272  sal_Int32 mnEndInvalid; // End of the invalid range
273 
274  static void ShiftLeft( sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd )
275  { if( rPos > nStart ) rPos = rPos > nEnd ? rPos - nEnd + nStart : nStart; }
276  void Invalidate_( sal_Int32 nBegin, sal_Int32 nEnd );
277 
278  void Insert(sal_uInt16 nWhere, std::vector<SwWrongArea>::iterator startPos, std::vector<SwWrongArea>::iterator const & endPos);
279  void Remove( sal_uInt16 nIdx, sal_uInt16 nLen );
280 
281  SwWrongList& operator= (const SwWrongList &) = delete;
282  SwWrongList( const SwWrongList& rCpy ) = delete;
283 
284 public:
285  SwWrongList( WrongListType eType );
286 
287  virtual ~SwWrongList();
288  virtual SwWrongList* Clone();
289  virtual void CopyFrom( const SwWrongList& rCopy );
290 
292  sal_Int32 GetBeginInv() const { return mnBeginInvalid; }
293  sal_Int32 GetEndInv() const { return mnEndInvalid; }
294  void SetInvalid( sal_Int32 nBegin, sal_Int32 nEnd );
295  void Validate(){ mnBeginInvalid = mnEndInvalid = COMPLETE_STRING; }
296  void Invalidate( sal_Int32 nBegin, sal_Int32 nEnd );
297  bool InvalidateWrong();
298  enum class FreshState { FRESH, CURSOR, NOTHING };
299  FreshState Fresh( sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos,
300  sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos );
301  sal_uInt16 GetWrongPos( sal_Int32 nValue ) const;
302 
303  bool Check( sal_Int32 &rChk, sal_Int32 &rLn ) const;
304  bool InWrongWord( sal_Int32 &rChk, sal_Int32 &rLn ) const;
305  sal_Int32 NextWrong( sal_Int32 nChk ) const;
306 
307  void Move( sal_Int32 nPos, sal_Int32 nDiff );
308  void ClearList();
309 
310  // Divide the list into two part, the wrong words until nSplitPos will be
311  // removed and transferred to a new SwWrongList.
312  SwWrongList* SplitList( sal_Int32 nSplitPos );
313  // Join the next SwWrongList, nInsertPos is my own text length, where
314  // the other wrong list has to be inserted.
315  void JoinList( SwWrongList* pNext, sal_Int32 nInsertPos );
316 
317  sal_Int32 Len( sal_uInt16 nIdx ) const
318  {
319  return nIdx < maList.size() ? maList[nIdx].mnLen : 0;
320  }
321 
322  sal_Int32 Pos( sal_uInt16 nIdx ) const
323  {
324  return nIdx < maList.size() ? maList[nIdx].mnPos : 0;
325  }
326 
327  sal_uInt16 Count() const { return static_cast<sal_uInt16>(maList.size()); }
328 
329  void Insert( const OUString& rType,
330  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
331  sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere )
332  {
333  std::vector<SwWrongArea>::iterator i = maList.begin();
334  if ( nWhere >= maList.size() )
335  i = maList.end(); // robust
336  else
337  i += nWhere;
338 
339  maList.insert(i, SwWrongArea( rType, meType, xPropertyBag, nNewPos, nNewLen) );
340  }
341 
342  void Insert( const OUString& rType,
343  css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
344  sal_Int32 nNewPos, sal_Int32 nNewLen );
345 
346  SwWrongList* SubList( sal_uInt16 nIdx ) const
347  {
348  return nIdx < maList.size() ? maList[nIdx].mpSubList : nullptr;
349  }
350 
351  void InsertSubList( sal_Int32 nNewPos, sal_Int32 nNewLen, sal_uInt16 nWhere, SwWrongList* pSubList );
352 
353  const SwWrongArea* GetElement( sal_uInt16 nIdx ) const
354  {
355  return nIdx < maList.size() ? &maList[nIdx] : nullptr;
356  }
357  void RemoveEntry( sal_Int32 nBegin, sal_Int32 nEnd );
358  bool LookForEntry( sal_Int32 nBegin, sal_Int32 nEnd );
359 };
360 
361 class SwTextNode;
362 class SwTextFrame;
363 
364 namespace sw {
365 
366 struct MergedPara;
367 
369 {
370 protected:
371  SwWrongList const* (SwTextNode::*const m_pGetWrongList)() const;
376 
377 public:
379  WrongListIteratorBase(SwTextFrame const& rFrame,
380  SwWrongList const* (SwTextNode::*pGetWrongList)() const);
382  WrongListIteratorBase(SwWrongList const& rWrongList);
383 };
384 
386  : public WrongListIteratorBase
387 {
388 public:
390  WrongListIterator(SwTextFrame const& rFrame,
391  SwWrongList const* (SwTextNode::*pGetWrongList)() const);
393  WrongListIterator(SwWrongList const& rWrongList);
394 
395  bool Check(TextFrameIndex &rStart, TextFrameIndex &rLen);
397 
398  bool LooksUseful() { return m_pMergedPara || m_pWrongList; }
399 };
400 
402  : public WrongListIteratorBase
403 {
404 public:
406  SwWrongList const* (SwTextNode::*pGetWrongList)() const);
407  WrongListIteratorCounter(SwWrongList const& rWrongList);
408 
409  sal_uInt16 GetElementCount();
411 };
412 
413 } // namespace sw
414 
415 #endif
416 
417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 mnBeginInvalid
Definition: wrong.hxx:271
sal_Int32 Pos(sal_uInt16 nIdx) const
Definition: wrong.hxx:322
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:149
bool InvalidateWrong()
Definition: wrong.cxx:433
WrongListType
Definition: wrong.hxx:57
const SwWrongArea * GetWrongElement(TextFrameIndex nStart)
Definition: wrong.cxx:787
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:329
SwWrongList const *const m_pWrongList
Definition: wrong.hxx:375
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.
Definition: accfrmobj.cxx:40
static Color & GetSmarttagColor()
Definition: viewopt.cxx:418
static WrongAreaLineType getWrongAreaLineType(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:245
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:346
Color mColor
Definition: wrong.hxx:74
static WrongAreaLineType getGrammarLineType(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:116
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:954
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:226
SwWrongList const *(SwTextNode::*const m_pGetWrongList)() const
Definition: wrong.hxx:371
sal_uInt16 Count() const
Definition: wrong.hxx:327
SwWrongList * SplitList(sal_Int32 nSplitPos)
Definition: wrong.cxx:445
virtual ~SwWrongList()
Definition: wrong.cxx:60
sw::MergedPara const *const m_pMergedPara
Definition: wrong.hxx:372
sal_Int32 mnLen
Definition: wrong.hxx:71
int i
sal_Int32 Len(sal_uInt16 nIdx) const
Definition: wrong.hxx:317
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:184
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:293
WrongListIteratorCounter(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
Definition: wrong.cxx:825
bool Check(TextFrameIndex &rStart, TextFrameIndex &rLen)
Definition: wrong.cxx:672
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
boost::optional< std::pair< TextFrameIndex, TextFrameIndex > > GetElementAt(sal_uInt16 nIndex)
Definition: wrong.cxx:881
WrongListType GetWrongListType() const
Definition: wrong.hxx:291
sal_Int32 GetBeginInv() const
Definition: wrong.hxx:292
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:274
const SwWrongArea * GetElement(sal_uInt16 nIdx) const
Definition: wrong.hxx:353
SwWrongList(const SwWrongList &rCpy)=delete
sal_Int32 mnPos
Definition: wrong.hxx:70
WrongListType meType
Definition: wrong.hxx:269
constexpr::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
sal_uInt16 GetElementCount()
Definition: wrong.cxx:836
static Color & GetSpellColor()
Definition: viewopt.cxx:413
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:268
TextFrameIndex m_CurrentIndex
Definition: wrong.hxx:374
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:158
sal_Int32 mnEndInvalid
Definition: wrong.hxx:272
void Validate()
Definition: wrong.hxx:295
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