Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <vcl/textdata.hxx>
31 : : #include <textdat2.hxx>
32 : :
33 : : #include <tools/debug.hxx>
34 : :
35 : :
36 : : // -------------------------------------------------------------------------
37 : : // (+) class TextSelection
38 : : // -------------------------------------------------------------------------
39 : :
40 : 308 : TextSelection::TextSelection()
41 : : {
42 : 308 : }
43 : :
44 : 0 : TextSelection::TextSelection( const TextPaM& rPaM ) :
45 : 0 : maStartPaM( rPaM ), maEndPaM( rPaM )
46 : : {
47 : 0 : }
48 : :
49 : 256 : TextSelection::TextSelection( const TextPaM& rStart, const TextPaM& rEnd ) :
50 : 256 : maStartPaM( rStart ), maEndPaM( rEnd )
51 : : {
52 : 256 : }
53 : :
54 : 0 : void TextSelection::Justify()
55 : : {
56 [ # # ]: 0 : if ( maEndPaM < maStartPaM )
57 : : {
58 : 0 : TextPaM aTemp( maStartPaM );
59 : 0 : maStartPaM = maEndPaM;
60 : 0 : maEndPaM = aTemp;
61 : : }
62 : 0 : }
63 : :
64 : :
65 : : // -------------------------------------------------------------------------
66 : : // (+) class TETextPortionList
67 : : // -------------------------------------------------------------------------
68 : 218 : TETextPortionList::TETextPortionList()
69 : : {
70 : 218 : }
71 : :
72 : 218 : TETextPortionList::~TETextPortionList()
73 : : {
74 [ + - ]: 218 : Reset();
75 : 218 : }
76 : :
77 : 556 : void TETextPortionList::Reset()
78 : : {
79 [ + - ][ + + ]: 1112 : for ( iterator it = begin(); it != end(); ++it )
80 : 556 : delete *it;
81 : 556 : clear();
82 : 556 : }
83 : :
84 : 92 : void TETextPortionList::DeleteFromPortion( sal_uInt16 nDelFrom )
85 : : {
86 : : DBG_ASSERT( ( nDelFrom < size() ) || ( (nDelFrom == 0) && (size() == 0) ), "DeleteFromPortion: Out of range" );
87 [ + - ][ + - ]: 132 : for ( iterator it = begin() + nDelFrom; it != end(); ++it )
[ + + ]
88 : 40 : delete *it;
89 [ + - ][ + - ]: 92 : erase( begin() + nDelFrom, end() );
90 : 92 : }
91 : :
92 : 584 : sal_uInt16 TETextPortionList::FindPortion( sal_uInt16 nCharPos, sal_uInt16& nPortionStart, sal_Bool bPreferStartingPortion )
93 : : {
94 : : // Bei nCharPos an Portion-Grenze wird die linke Portion gefunden
95 : 584 : sal_uInt16 nTmpPos = 0;
96 [ + - ]: 584 : for ( sal_uInt16 nPortion = 0; nPortion < size(); nPortion++ )
97 : : {
98 : 584 : TETextPortion* pPortion = operator[]( nPortion );
99 : 584 : nTmpPos = nTmpPos + pPortion->GetLen();
100 [ + - ]: 584 : if ( nTmpPos >= nCharPos )
101 : : {
102 : : // take this one if we don't prefer the starting portion, or if it's the last one
103 [ + + ][ + + ]: 584 : if ( ( nTmpPos != nCharPos ) || !bPreferStartingPortion || ( nPortion == size() - 1 ) )
[ + - ][ + - ]
104 : : {
105 : 584 : nPortionStart = nTmpPos - pPortion->GetLen();
106 : 584 : return nPortion;
107 : : }
108 : : }
109 : : }
110 : : OSL_FAIL( "FindPortion: Nicht gefunden!" );
111 : 584 : return ( size() - 1 );
112 : : }
113 : :
114 : :
115 : : // -------------------------------------------------------------------------
116 : : // (+) class TEParaPortion
117 : : // -------------------------------------------------------------------------
118 [ + - ][ + - ]: 218 : TEParaPortion::TEParaPortion( TextNode* pN )
119 : : {
120 : 218 : mpNode = pN;
121 : 218 : mnInvalidPosStart = mnInvalidDiff = 0;
122 : 218 : mbInvalid = sal_True;
123 : 218 : mbSimple = sal_False;
124 : 218 : }
125 : :
126 [ + - ]: 218 : TEParaPortion::~TEParaPortion()
127 : : {
128 : 218 : }
129 : :
130 : 52 : void TEParaPortion::MarkInvalid( sal_uInt16 nStart, short nDiff )
131 : : {
132 [ - + ]: 52 : if ( mbInvalid == sal_False )
133 : : {
134 [ # # ]: 0 : mnInvalidPosStart = ( nDiff >= 0 ) ? nStart : ( nStart + nDiff );
135 : 0 : mnInvalidDiff = nDiff;
136 : : }
137 : : else
138 : : {
139 : : // Einfaches hintereinander tippen
140 [ + - ][ - + ]: 52 : if ( ( nDiff > 0 ) && ( mnInvalidDiff > 0 ) &&
[ # # ]
141 : : ( ( mnInvalidPosStart+mnInvalidDiff ) == nStart ) )
142 : : {
143 : 0 : mnInvalidDiff = mnInvalidDiff + nDiff;
144 : : }
145 : : // Einfaches hintereinander loeschen
146 [ - + ][ # # ]: 52 : else if ( ( nDiff < 0 ) && ( mnInvalidDiff < 0 ) && ( mnInvalidPosStart == nStart ) )
[ # # ]
147 : : {
148 : 0 : mnInvalidPosStart = mnInvalidPosStart + nDiff;
149 : 0 : mnInvalidDiff = mnInvalidDiff + nDiff;
150 : : }
151 : : else
152 : : {
153 : : DBG_ASSERT( ( nDiff >= 0 ) || ( (nStart+nDiff) >= 0 ), "MarkInvalid: Diff out of Range" );
154 [ - + ]: 52 : mnInvalidPosStart = Min( mnInvalidPosStart, (sal_uInt16) ( (nDiff < 0) ? nStart+nDiff : nDiff ) );
155 : 52 : mnInvalidDiff = 0;
156 : 52 : mbSimple = sal_False;
157 : : }
158 : : }
159 : :
160 : 52 : maWritingDirectionInfos.clear();
161 : :
162 : 52 : mbInvalid = sal_True;
163 : 52 : }
164 : :
165 : 468 : void TEParaPortion::MarkSelectionInvalid( sal_uInt16 nStart, sal_uInt16 /*nEnd*/ )
166 : : {
167 [ + + ]: 468 : if ( mbInvalid == sal_False )
168 : : {
169 : 378 : mnInvalidPosStart = nStart;
170 : : // nInvalidPosEnd = nEnd;
171 : : }
172 : : else
173 : : {
174 : 90 : mnInvalidPosStart = Min( mnInvalidPosStart, nStart );
175 : : // nInvalidPosEnd = pNode->Len();
176 : : }
177 : :
178 : 468 : maWritingDirectionInfos.clear();
179 : :
180 : 468 : mnInvalidDiff = 0;
181 : 468 : mbInvalid = sal_True;
182 : 468 : mbSimple = sal_False;
183 : 468 : }
184 : :
185 : 0 : sal_uInt16 TEParaPortion::GetLineNumber( sal_uInt16 nChar, sal_Bool bInclEnd )
186 : : {
187 [ # # ]: 0 : for ( sal_uInt16 nLine = 0; nLine < maLines.size(); nLine++ )
188 : : {
189 : 0 : TextLine* pLine = maLines[ nLine ];
190 [ # # # # ]: 0 : if ( ( bInclEnd && ( pLine->GetEnd() >= nChar ) ) ||
[ # # ][ # # ]
191 : 0 : ( pLine->GetEnd() > nChar ) )
192 : : {
193 : 0 : return nLine;
194 : : }
195 : : }
196 : :
197 : : // Then it should be at the end of the last line
198 : : OSL_ENSURE(nChar == maLines[maLines.size() - 1]->GetEnd(), "wrong Index");
199 : : OSL_ENSURE(!bInclEnd, "Line not found: FindLine");
200 : 0 : return ( maLines.size() - 1 );
201 : : }
202 : :
203 : :
204 : 0 : void TEParaPortion::CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine )
205 : : {
206 : 0 : sal_uInt16 nLines = maLines.size();
207 : : DBG_ASSERT( nLines, "CorrectPortionNumbersFromLine: Leere Portion?" );
208 [ # # ]: 0 : if ( nLastFormattedLine < ( nLines - 1 ) )
209 : : {
210 : 0 : const TextLine* pLastFormatted = maLines[ nLastFormattedLine ];
211 : 0 : const TextLine* pUnformatted = maLines[ nLastFormattedLine+1 ];
212 : 0 : short nPortionDiff = pUnformatted->GetStartPortion() - pLastFormatted->GetEndPortion();
213 : 0 : short nTextDiff = pUnformatted->GetStart() - pLastFormatted->GetEnd();
214 : 0 : nTextDiff++; // LastFormatted->GetEnd() war incl. => 1 zuviel abgezogen!
215 : :
216 : : // Die erste unformatierte muss genau eine Portion hinter der letzten der
217 : : // formatierten beginnen:
218 : : // Wenn in der geaenderten Zeile eine Portion gesplittet wurde,
219 : : // kann nLastEnd > nNextStart sein!
220 : 0 : short nPDiff = sal::static_int_cast< short >(-( nPortionDiff-1 ));
221 : 0 : short nTDiff = sal::static_int_cast< short >(-( nTextDiff-1 ));
222 [ # # ][ # # ]: 0 : if ( nPDiff || nTDiff )
223 : : {
224 [ # # ]: 0 : for ( sal_uInt16 nL = nLastFormattedLine+1; nL < nLines; nL++ )
225 : : {
226 : 0 : TextLine* pLine = maLines[ nL ];
227 : :
228 : 0 : pLine->GetStartPortion() = pLine->GetStartPortion() + nPDiff;
229 : 0 : pLine->GetEndPortion() = pLine->GetEndPortion() + nPDiff;
230 : :
231 : 0 : pLine->GetStart() = pLine->GetStart() + nTDiff;
232 : 0 : pLine->GetEnd() = pLine->GetEnd() + nTDiff;
233 : :
234 : 0 : pLine->SetValid();
235 : : }
236 : : }
237 : : }
238 : 0 : }
239 : :
240 : : // -------------------------------------------------------------------------
241 : : // (+) class TEParaPortions
242 : : // -------------------------------------------------------------------------
243 : 218 : TEParaPortions::TEParaPortions()
244 : : {
245 : 218 : }
246 : :
247 : 218 : TEParaPortions::~TEParaPortions()
248 : : {
249 [ + - ]: 218 : Reset();
250 : 218 : }
251 : :
252 : 218 : void TEParaPortions::Reset()
253 : : {
254 : 218 : TEParaPortions::iterator aIter( begin() );
255 [ + - ][ + + ]: 436 : while ( aIter != end() )
256 [ + - ][ + - ]: 218 : delete *aIter++;
[ + - ]
257 : 218 : clear();
258 : 218 : }
259 : :
260 : : // -------------------------------------------------------------------------
261 : : // (+) class IdleFormatter
262 : : // -------------------------------------------------------------------------
263 : 90 : IdleFormatter::IdleFormatter()
264 : : {
265 : 90 : mpView = 0;
266 : 90 : mnRestarts = 0;
267 : 90 : }
268 : :
269 : 90 : IdleFormatter::~IdleFormatter()
270 : : {
271 : 90 : mpView = 0;
272 [ - + ]: 180 : }
273 : :
274 : 0 : void IdleFormatter::DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts )
275 : : {
276 : 0 : mpView = pV;
277 : :
278 [ # # ]: 0 : if ( IsActive() )
279 : 0 : mnRestarts++;
280 : :
281 [ # # ]: 0 : if ( mnRestarts > nMaxRestarts )
282 : : {
283 : 0 : mnRestarts = 0;
284 : 0 : ((Link&)GetTimeoutHdl()).Call( this );
285 : : }
286 : : else
287 : : {
288 : 0 : Start();
289 : : }
290 : 0 : }
291 : :
292 : 526 : void IdleFormatter::ForceTimeout()
293 : : {
294 [ - + ]: 526 : if ( IsActive() )
295 : : {
296 : 0 : Stop();
297 : 0 : mnRestarts = 0;
298 : 0 : ((Link&)GetTimeoutHdl()).Call( this );
299 : : }
300 : 526 : }
301 : :
302 [ + + ][ + + ]: 6295 : TYPEINIT1( TextHint, SfxSimpleHint );
303 : :
304 : 896 : TextHint::TextHint( sal_uLong Id ) : SfxSimpleHint( Id )
305 : : {
306 : 896 : mnValue = 0;
307 : 896 : }
308 : :
309 : 1099 : TextHint::TextHint( sal_uLong Id, sal_uLong nValue ) : SfxSimpleHint( Id )
310 : : {
311 : 1099 : mnValue = nValue;
312 : 1099 : }
313 : :
314 : 0 : TEIMEInfos::TEIMEInfos( const TextPaM& rPos, const String& rOldTextAfterStartPos )
315 : 0 : : aOldTextAfterStartPos( rOldTextAfterStartPos )
316 : : {
317 : 0 : aPos = rPos;
318 : 0 : nLen = 0;
319 : 0 : bCursor = sal_True;
320 : 0 : pAttribs = NULL;
321 : 0 : bWasCursorOverwrite = sal_False;
322 : 0 : }
323 : :
324 : 0 : TEIMEInfos::~TEIMEInfos()
325 : : {
326 [ # # ]: 0 : delete[] pAttribs;
327 : 0 : }
328 : :
329 : 0 : void TEIMEInfos::CopyAttribs( const sal_uInt16* pA, sal_uInt16 nL )
330 : : {
331 : 0 : nLen = nL;
332 : 0 : delete pAttribs;
333 : 0 : pAttribs = new sal_uInt16[ nL ];
334 : 0 : memcpy( pAttribs, pA, nL*sizeof(sal_uInt16) );
335 : 0 : }
336 : :
337 : 0 : void TEIMEInfos::DestroyAttribs()
338 : : {
339 : 0 : delete pAttribs;
340 : 0 : pAttribs = NULL;
341 : 0 : nLen = 0;
342 : 0 : }
343 : :
344 : :
345 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|