LibreOffice Module vcl (master) 1
textdata.cxx
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#include <sal/config.h>
21#include <sal/log.hxx>
22#include <osl/diagnose.h>
23
24#include <cstddef>
25
26#include <utility>
27#include <vcl/textdata.hxx>
28#include "textdat2.hxx"
29
30
32{
33}
34
36 maStartPaM( rPaM ), maEndPaM( rPaM )
37{
38}
39
40TextSelection::TextSelection( const TextPaM& rStart, const TextPaM& rEnd ) :
41 maStartPaM( rStart ), maEndPaM( rEnd )
42{
43}
44
46{
47 if ( maEndPaM < maStartPaM )
48 {
49 TextPaM aTemp( maStartPaM );
51 maEndPaM = aTemp;
52 }
53}
54
56{
57}
58
60{
61 Reset();
62}
63
65{
66 return maPortions[ nPos ];
67}
68
69std::vector<TETextPortion>::iterator TETextPortionList::begin()
70{
71 return maPortions.begin();
72}
73
74std::vector<TETextPortion>::const_iterator TETextPortionList::begin() const
75{
76 return maPortions.begin();
77}
78
79std::vector<TETextPortion>::iterator TETextPortionList::end()
80{
81 return maPortions.end();
82}
83
84std::vector<TETextPortion>::const_iterator TETextPortionList::end() const
85{
86 return maPortions.end();
87}
88
90{
91 return maPortions.empty();
92}
93
94std::size_t TETextPortionList::size() const
95{
96 return maPortions.size();
97}
98
99std::vector<TETextPortion>::iterator TETextPortionList::erase( const std::vector<TETextPortion>::iterator& aIter )
100{
101 return maPortions.erase( aIter );
102}
103
104std::vector<TETextPortion>::iterator TETextPortionList::insert( const std::vector<TETextPortion>::iterator& aIter,
105 const TETextPortion& rTP )
106{
107 return maPortions.insert( aIter, rTP );
108}
109
111{
112 maPortions.push_back( rTP );
113}
114
116{
117 maPortions.clear();
118}
119
120void TETextPortionList::DeleteFromPortion( std::size_t nDelFrom )
121{
122 SAL_WARN_IF( ( nDelFrom >= maPortions.size() ) && ( (nDelFrom != 0) || (!maPortions.empty()) ), "vcl", "DeleteFromPortion: Out of range" );
123 maPortions.erase( maPortions.begin() + nDelFrom, maPortions.end() );
124}
125
126std::size_t TETextPortionList::FindPortion( sal_Int32 nCharPos, sal_Int32& nPortionStart, bool bPreferStartingPortion )
127{
128 // find left portion at nCharPos at portion border
129 sal_Int32 nTmpPos = 0;
130 for ( std::size_t nPortion = 0; nPortion < maPortions.size(); nPortion++ )
131 {
132 TETextPortion& rPortion = maPortions[ nPortion ];
133 nTmpPos += rPortion.GetLen();
134 if ( nTmpPos >= nCharPos )
135 {
136 // take this one if we don't prefer the starting portion, or if it's the last one
137 if ( ( nTmpPos != nCharPos ) || !bPreferStartingPortion || ( nPortion == maPortions.size() - 1 ) )
138 {
139 nPortionStart = nTmpPos - rPortion.GetLen();
140 return nPortion;
141 }
142 }
143 }
144 OSL_FAIL( "FindPortion: Not found!" );
145 return ( maPortions.size() - 1 );
146}
147
149 : mpNode {pN}
150 , mnInvalidPosStart {0}
151 , mnInvalidDiff {0}
152 , mbInvalid {true}
153 , mbSimple {false}
154{
155}
156
158{
159}
160
161void TEParaPortion::MarkInvalid( sal_Int32 nStart, sal_Int32 nDiff )
162{
163 if ( !mbInvalid )
164 {
165 mnInvalidPosStart = ( nDiff >= 0 ) ? nStart : ( nStart + nDiff );
166 mnInvalidDiff = nDiff;
167 }
168 else
169 {
170 // simple consecutive typing
171 if ( ( nDiff > 0 ) && ( mnInvalidDiff > 0 ) &&
172 ( ( mnInvalidPosStart+mnInvalidDiff ) == nStart ) )
173 {
175 }
176 // simple consecutive deleting
177 else if ( ( nDiff < 0 ) && ( mnInvalidDiff < 0 ) && ( mnInvalidPosStart == nStart ) )
178 {
181 }
182 else
183 {
184 SAL_WARN_IF( ( nDiff < 0 ) && ( (nStart+nDiff) < 0 ), "vcl", "MarkInvalid: Diff out of Range" );
185 mnInvalidPosStart = std::min( mnInvalidPosStart, nDiff < 0 ? nStart+nDiff : nDiff );
186 mnInvalidDiff = 0;
187 mbSimple = false;
188 }
189 }
190
192
193 mbInvalid = true;
194}
195
197{
198 if ( !mbInvalid )
199 {
200 mnInvalidPosStart = nStart;
201 }
202 else
203 {
204 mnInvalidPosStart = std::min( mnInvalidPosStart, nStart );
205 }
206
208
209 mnInvalidDiff = 0;
210 mbInvalid = true;
211 mbSimple = false;
212}
213
214std::vector<TextLine>::size_type TEParaPortion::GetLineNumber( sal_Int32 nChar, bool bInclEnd )
215{
216 for ( std::vector<TextLine>::size_type nLine = 0; nLine < maLines.size(); nLine++ )
217 {
218 TextLine& rLine = maLines[ nLine ];
219 if ( ( bInclEnd && ( rLine.GetEnd() >= nChar ) ) ||
220 ( rLine.GetEnd() > nChar ) )
221 {
222 return nLine;
223 }
224 }
225
226 // Then it should be at the end of the last line
227 OSL_ENSURE(nChar == maLines.back().GetEnd(), "wrong Index");
228 OSL_ENSURE(!bInclEnd, "Line not found: FindLine");
229 return ( maLines.size() - 1 );
230}
231
232void TEParaPortion::CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine )
233{
234 sal_uInt16 nLines = maLines.size();
235 SAL_WARN_IF( !nLines, "vcl", "CorrectPortionNumbersFromLine: Empty portion?" );
236 if ( nLastFormattedLine >= ( nLines - 1 ) )
237 return;
238
239 const TextLine& rLastFormatted = maLines[ nLastFormattedLine ];
240 const TextLine& rUnformatted = maLines[ nLastFormattedLine+1 ];
241 std::ptrdiff_t nPortionDiff = rUnformatted.GetStartPortion() - rLastFormatted.GetEndPortion();
242 sal_Int32 nTextDiff = rUnformatted.GetStart() - rLastFormatted.GetEnd();
243 nTextDiff++; // LastFormatted.GetEnd() was inclusive => subtracted one too much!
244
245 // The first unformatted one has to start exactly one portion past the last
246 // formatted one.
247 // If a portion got split in the changed row, nLastEnd could be > nNextStart!
248 std::ptrdiff_t nPDiff = -( nPortionDiff-1 );
249 const sal_Int32 nTDiff = -( nTextDiff-1 );
250 if ( !(nPDiff || nTDiff) )
251 return;
252
253 for ( sal_uInt16 nL = nLastFormattedLine+1; nL < nLines; nL++ )
254 {
255 TextLine& rLine = maLines[ nL ];
256
257 rLine.SetStartPortion(rLine.GetStartPortion() + nPDiff);
258 rLine.SetEndPortion(rLine.GetEndPortion() + nPDiff);
259
260 rLine.SetStart(rLine.GetStart() + nTDiff);
261 rLine.SetEnd(rLine.GetEnd() + nTDiff);
262
263 rLine.SetValid();
264 }
265}
266
268{
269}
270
272 : Idle("vcl::TextEngine mpIdleFormatter")
273 , mpView(nullptr)
274 , mnRestarts(0)
275{
277}
278
280{
281 mpView = nullptr;
282}
283
284void IdleFormatter::DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts )
285{
286 mpView = pV;
287
288 if ( IsActive() )
289 mnRestarts++;
290
291 if ( mnRestarts > nMaxRestarts )
292 {
293 mnRestarts = 0;
294 Invoke();
295 }
296 else
297 {
298 Start();
299 }
300}
301
303{
304 if ( IsActive() )
305 {
306 Stop();
307 mnRestarts = 0;
308 Invoke();
309 }
310}
311
313{
314}
315
317{
318}
319
320TEIMEInfos::TEIMEInfos( const TextPaM& rPos, OUString _aOldTextAfterStartPos )
321 : aOldTextAfterStartPos(std::move(_aOldTextAfterStartPos))
322 , aPos(rPos)
323 , nLen(0)
324 , bWasCursorOverwrite(false)
325{
326}
327
329{
330}
331
332void TEIMEInfos::CopyAttribs(const ExtTextInputAttr* pA, sal_Int32 nL)
333{
334 nLen = nL;
335 pAttribs.reset( new ExtTextInputAttr[ nL ] );
336 memcpy( pAttribs.get(), pA, nL*sizeof(ExtTextInputAttr) );
337}
338
340{
341 pAttribs.reset();
342 nLen = 0;
343}
344
345/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~IdleFormatter() override
Definition: textdata.cxx:279
void DoIdleFormat(TextView *pV, sal_uInt16 nMaxRestarts)
Definition: textdata.cxx:284
TextView * mpView
Definition: textdat2.hxx:251
sal_uInt16 mnRestarts
Definition: textdat2.hxx:252
void ForceTimeout()
Definition: textdata.cxx:302
An idle is a timer to be scheduled immediately.
Definition: idle.hxx:35
virtual void Start(bool bStartTimer=true) override
Schedules the task for execution.
Definition: idle.cxx:34
std::vector< TEWritingDirectionInfo > maWritingDirectionInfos
Definition: textdat2.hxx:177
void MarkInvalid(sal_Int32 nStart, sal_Int32 nDiff)
Definition: textdata.cxx:161
sal_Int32 mnInvalidPosStart
Definition: textdat2.hxx:179
void CorrectValuesBehindLastFormattedLine(sal_uInt16 nLastFormattedLine)
Definition: textdata.cxx:232
sal_Int32 mnInvalidDiff
Definition: textdat2.hxx:180
void MarkSelectionInvalid(sal_Int32 nStart)
Definition: textdata.cxx:196
std::vector< TextLine > maLines
Definition: textdat2.hxx:175
std::vector< TextLine >::size_type GetLineNumber(sal_Int32 nIndex, bool bInclEnd)
Definition: textdata.cxx:214
TEParaPortion(TextNode *pNode)
Definition: textdata.cxx:148
TETextPortion & operator[](std::size_t nPos)
Definition: textdata.cxx:64
std::vector< TETextPortion >::iterator end()
Definition: textdata.cxx:79
std::size_t FindPortion(sal_Int32 nCharPos, sal_Int32 &rPortionStart, bool bPreferStartingPortion=false)
Definition: textdata.cxx:126
std::size_t size() const
Definition: textdata.cxx:94
std::vector< TETextPortion >::iterator insert(const std::vector< TETextPortion >::iterator &aIter, const TETextPortion &rTP)
Definition: textdata.cxx:104
std::vector< TETextPortion >::iterator begin()
Definition: textdata.cxx:69
std::vector< TETextPortion >::iterator erase(const std::vector< TETextPortion >::iterator &aIter)
Definition: textdata.cxx:99
void DeleteFromPortion(std::size_t nDelFrom)
Definition: textdata.cxx:120
std::vector< TETextPortion > maPortions
Definition: textdat2.hxx:75
bool empty() const
Definition: textdata.cxx:89
void push_back(const TETextPortion &aTP)
Definition: textdata.cxx:110
sal_Int32 & GetLen()
Definition: textdat2.hxx:64
bool IsActive() const
Definition: task.hxx:101
void SetPriority(TaskPriority ePriority)
Definition: scheduler.cxx:606
void Stop()
Definition: scheduler.cxx:599
TextHint(SfxHintId nId)
Definition: textdata.cxx:312
void SetEndPortion(std::size_t n)
Definition: textdat2.hxx:146
void SetStartPortion(std::size_t n)
Definition: textdat2.hxx:143
std::size_t GetEndPortion() const
Definition: textdat2.hxx:147
void SetEnd(sal_Int32 n)
Definition: textdat2.hxx:140
sal_Int32 GetEnd() const
Definition: textdat2.hxx:141
sal_Int32 GetStart() const
Definition: textdat2.hxx:138
void SetStart(sal_Int32 n)
Definition: textdat2.hxx:137
void SetValid()
Definition: textdat2.hxx:154
std::size_t GetStartPortion() const
Definition: textdat2.hxx:144
void Justify()
Definition: textdata.cxx:45
TextPaM maEndPaM
Definition: textdata.hxx:83
TextPaM maStartPaM
Definition: textdata.hxx:82
virtual void Invoke() override
Calls the maInvokeHandler with the parameter this.
Definition: timer.cxx:73
ExtTextInputAttr
sal_Int16 nValue
SfxHintId
AlgAtomPtr mpNode
sal_uInt16 nPos
#define SAL_WARN_IF(condition, area, stream)
sal_uInt32 Id
UnoViewSharedPtr mpView
const double mnValue
sal_Int32 nLen
Definition: textdata.hxx:131
void CopyAttribs(const ExtTextInputAttr *pA, sal_Int32 nL)
Definition: textdata.cxx:332
std::unique_ptr< ExtTextInputAttr[]> pAttribs
Definition: textdata.hxx:129
TEIMEInfos(const TextPaM &rPos, OUString aOldTextAfterStartPos)
Definition: textdata.cxx:320
void DestroyAttribs()
Definition: textdata.cxx:339
@ HIGH_IDLE
Important idle events to be run before processing drawing events.