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/awt/FontUnderline.hpp>
27#include <com/sun/star/uno/Any.hxx>
28
29#include <vector>
30#include <memory>
31#include <optional>
32
33#include <tools/color.hxx>
34#include <swtypes.hxx>
35#include <viewopt.hxx>
36#include "TextFrameIndex.hxx"
37
38#if defined _MSC_VER
39// For MSVC (without /vmg) SwTextNode must consistently be defined for
40// WrongListIterator::m_pGetWrongList of pointer-to-SwTextNode-member type to consistently have the
41// same size in all translation units that include this file:
42#include <ndtxt.hxx>
43#endif
44
45class SwWrongList;
46
48{
54};
55
57{
62};
63
64// ST2
66{
67public:
68 OUString maType;
69 css::uno::Reference< css::container::XStringKeyMap > mxPropertyBag;
70 sal_Int32 mnPos;
71 sal_Int32 mnLen;
73
76
77 SwWrongArea( OUString aType,
78 WrongListType listType,
79 css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
80 sal_Int32 nPos,
81 sal_Int32 nLen);
82
83 SwWrongArea( OUString aType,
84 css::uno::Reference< css::container::XStringKeyMap > const & xPropertyBag,
85 sal_Int32 nPos,
86 sal_Int32 nLen,
87 SwWrongList* pSubList);
88private:
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 ::Color lineColor;
98
99 if (aLineColor >>= lineColor)
100 {
101 return lineColor;
102 }
103 }
104 }
105 catch(const css::container::NoSuchElementException&)
106 {
107 }
108 catch(const css::uno::RuntimeException&)
109 {
110 }
111
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 ::Color lineColor;
164
165 if (aLineColor >>= lineColor)
166 {
167 return 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
262class SAL_DLLPUBLIC_RTTI SwWrongList
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
280public:
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 std::unique_ptr<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 o3tl::narrowing<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
357class SwTextNode;
358class SwTextFrame;
359
360namespace sw {
361
362struct MergedPara;
363
365{
366protected:
367 SwWrongList const* (SwTextNode::*const m_pGetWrongList)() const;
372
373public:
376 SwWrongList const* (SwTextNode::*pGetWrongList)() const);
378 WrongListIteratorBase(SwWrongList const& rWrongList);
379};
380
382 : public WrongListIteratorBase
383{
384public:
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
395};
396
398 : public WrongListIteratorBase
399{
400public:
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: */
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:168
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
static const SwViewOption & GetCurrentViewOptions()
Definition: viewopt.cxx:605
const Color & GetSpellColor() const
Definition: viewopt.cxx:497
const Color & GetGrammarColor() const
Definition: viewopt.cxx:502
const Color & GetSmarttagColor() const
Definition: viewopt.cxx:507
Color mColor
Definition: wrong.hxx:74
sal_Int32 mnPos
Definition: wrong.hxx:70
static Color getWrongAreaColor(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:222
WrongAreaLineType mLineType
Definition: wrong.hxx:75
static WrongAreaLineType getSmartLineType(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:181
OUString maType
Definition: wrong.hxx:68
SwWrongList * mpSubList
Definition: wrong.hxx:72
static WrongAreaLineType getGrammarLineType(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:115
SwWrongArea(OUString aType, WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag, sal_Int32 nPos, sal_Int32 nLen)
Definition: wrong.cxx:29
css::uno::Reference< css::container::XStringKeyMap > mxPropertyBag
Definition: wrong.hxx:69
static Color getSmartColor(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:156
static Color getGrammarColor(css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:90
sal_Int32 mnLen
Definition: wrong.hxx:71
static WrongAreaLineType getWrongAreaLineType(WrongListType listType, css::uno::Reference< css::container::XStringKeyMap > const &xPropertyBag)
Definition: wrong.hxx:241
sal_uInt16 Count() const
Definition: wrong.hxx:323
sal_Int32 GetEndInv() const
Definition: wrong.hxx:289
void Validate()
Definition: wrong.hxx:291
WrongListType GetWrongListType() const
Definition: wrong.hxx:287
const SwWrongArea * GetElement(sal_uInt16 nIdx) const
Definition: wrong.hxx:349
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
std::vector< SwWrongArea > maList
Definition: wrong.hxx:264
sal_Int32 mnEndInvalid
Definition: wrong.hxx:268
sal_Int32 Pos(sal_uInt16 nIdx) const
Definition: wrong.hxx:318
SwWrongList(const SwWrongList &rCpy)=delete
SwWrongList * SubList(sal_uInt16 nIdx) const
Definition: wrong.hxx:342
static void ShiftLeft(sal_Int32 &rPos, sal_Int32 nStart, sal_Int32 nEnd)
Definition: wrong.hxx:270
sal_Int32 GetBeginInv() const
Definition: wrong.hxx:288
WrongListType meType
Definition: wrong.hxx:265
sal_Int32 mnBeginInvalid
Definition: wrong.hxx:267
sal_Int32 Len(sal_uInt16 nIdx) const
Definition: wrong.hxx:313
sw::MergedPara const *const m_pMergedPara
Definition: wrong.hxx:368
SwWrongList const *(SwTextNode::*const m_pGetWrongList)() const
Definition: wrong.hxx:367
WrongListIteratorBase(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
for the text frame
Definition: wrong.cxx:641
SwWrongList const *const m_pWrongList
Definition: wrong.hxx:371
TextFrameIndex m_CurrentIndex
Definition: wrong.hxx:370
sal_uInt16 GetElementCount()
Definition: wrong.cxx:835
std::optional< std::pair< TextFrameIndex, TextFrameIndex > > GetElementAt(sal_uInt16 nIndex)
Definition: wrong.cxx:880
WrongListIteratorCounter(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
Definition: wrong.cxx:824
bool Check(TextFrameIndex &rStart, TextFrameIndex &rLen)
Definition: wrong.cxx:673
WrongListIterator(SwTextFrame const &rFrame, SwWrongList const *(SwTextNode::*pGetWrongList)() const)
for the text frame
Definition: wrong.cxx:662
const SwWrongArea * GetWrongElement(TextFrameIndex nStart)
Definition: wrong.cxx:786
virtual void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName) override
sal_Int32 nIndex
int i
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
Dialog to specify the properties of date form field.
Describes parts of multiple text nodes, which will form a text frame, even when redlines are hidden a...
Definition: txtfrm.hxx:991
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57
RedlineType meType
WrongListType
Definition: wrong.hxx:57
@ WRONGLIST_CHANGETRACKING
Definition: wrong.hxx:61
@ WRONGLIST_SPELL
Definition: wrong.hxx:58
@ WRONGLIST_SMARTTAG
Definition: wrong.hxx:60
@ WRONGLIST_GRAMMAR
Definition: wrong.hxx:59
WrongAreaLineType
Definition: wrong.hxx:48
@ WRONGAREA_BOLDWAVE
Definition: wrong.hxx:51
@ WRONGAREA_NONE
Definition: wrong.hxx:49
@ WRONGAREA_WAVE
Definition: wrong.hxx:50
@ WRONGAREA_DASHED
Definition: wrong.hxx:53
@ WRONGAREA_BOLD
Definition: wrong.hxx:52