/src/libreoffice/editeng/source/uno/unoedprx.cxx
Line | Count | Source |
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 | | |
21 | | // Global header |
22 | | |
23 | | |
24 | | #include <utility> |
25 | | #include <memory> |
26 | | #include <vector> |
27 | | #include <algorithm> |
28 | | #include <osl/diagnose.h> |
29 | | #include <svl/itemset.hxx> |
30 | | #include <tools/debug.hxx> |
31 | | |
32 | | |
33 | | // Project-local header |
34 | | |
35 | | |
36 | | #include <editeng/unoedprx.hxx> |
37 | | #include <editeng/editdata.hxx> |
38 | | #include <editeng/editeng.hxx> |
39 | | #include <AccessibleStringWrap.hxx> |
40 | | #include <editeng/outliner.hxx> |
41 | | |
42 | | using namespace ::com::sun::star; |
43 | | |
44 | | namespace { |
45 | | |
46 | | class SvxAccessibleTextIndex |
47 | | { |
48 | | public: |
49 | | SvxAccessibleTextIndex() : |
50 | 0 | mnPara(0), |
51 | 0 | mnIndex(0), |
52 | 0 | mnEEIndex(0), |
53 | 0 | mnFieldOffset(0), |
54 | 0 | mnFieldLen(0), |
55 | 0 | mnBulletOffset(0), |
56 | 0 | mnBulletLen(0), |
57 | 0 | mbInField(false), |
58 | 0 | mbInBullet(false) {}; |
59 | | |
60 | | // Get/Set current paragraph |
61 | | void SetParagraph( sal_Int32 nPara ) |
62 | 0 | { |
63 | 0 | mnPara = nPara; |
64 | 0 | } |
65 | 0 | sal_Int32 GetParagraph() const { return mnPara; } |
66 | | |
67 | | /** Set the index in the UAA semantic |
68 | | |
69 | | @param nIndex |
70 | | The index from the UA API (fields and bullets are expanded) |
71 | | |
72 | | @param rTF |
73 | | The text forwarder to use in the calculations |
74 | | */ |
75 | | void SetIndex( sal_Int32 nIndex, const SvxTextForwarder& rTF ); |
76 | 0 | void SetIndex( sal_Int32 nPara, sal_Int32 nIndex, const SvxTextForwarder& rTF ) { SetParagraph(nPara); SetIndex(nIndex, rTF); } |
77 | 0 | sal_Int32 GetIndex() const { return mnIndex; } |
78 | | |
79 | | /** Set the index in the edit engine semantic |
80 | | |
81 | | Update the object state to reflect the given index position in |
82 | | EditEngine/Outliner index values |
83 | | |
84 | | @param nEEIndex |
85 | | The index from the edit engine (fields span exactly one index increment) |
86 | | |
87 | | @param rTF |
88 | | The text forwarder to use in the calculations |
89 | | */ |
90 | | void SetEEIndex( sal_Int32 nEEIndex, const SvxTextForwarder& rTF ); |
91 | 0 | void SetEEIndex( sal_Int32 nPara, sal_Int32 nEEIndex, const SvxTextForwarder& rTF ) { SetParagraph(nPara); SetEEIndex(nEEIndex, rTF); } |
92 | | sal_Int32 GetEEIndex() const; |
93 | | |
94 | 0 | void SetFieldOffset( sal_Int32 nOffset, sal_Int32 nLen ) { mnFieldOffset = nOffset; mnFieldLen = nLen; } |
95 | 0 | sal_Int32 GetFieldOffset() const { return mnFieldOffset; } |
96 | 0 | sal_Int32 GetFieldLen() const { return mnFieldLen; } |
97 | 0 | void AreInField() { mbInField = true; } |
98 | 0 | bool InField() const { return mbInField; } |
99 | | |
100 | 0 | void SetBulletOffset( sal_Int32 nOffset, sal_Int32 nLen ) { mnBulletOffset = nOffset; mnBulletLen = nLen; } |
101 | 0 | sal_Int32 GetBulletOffset() const { return mnBulletOffset; } |
102 | 0 | sal_Int32 GetBulletLen() const { return mnBulletLen; } |
103 | 0 | bool InBullet() const { return mbInBullet; } |
104 | | |
105 | | /// returns false if the given range is non-editable (e.g. contains bullets or _parts_ of fields) |
106 | | bool IsEditableRange( const SvxAccessibleTextIndex& rEnd ) const; |
107 | | |
108 | | private: |
109 | | sal_Int32 mnPara; |
110 | | sal_Int32 mnIndex; |
111 | | sal_Int32 mnEEIndex; |
112 | | sal_Int32 mnFieldOffset; |
113 | | sal_Int32 mnFieldLen; |
114 | | sal_Int32 mnBulletOffset; |
115 | | sal_Int32 mnBulletLen; |
116 | | bool mbInField; |
117 | | bool mbInBullet; |
118 | | }; |
119 | | |
120 | | } |
121 | | |
122 | | static ESelection MakeEESelection( const SvxAccessibleTextIndex& rStart, const SvxAccessibleTextIndex& rEnd ) |
123 | 0 | { |
124 | | // deal with field special case: to really get a field contained |
125 | | // within a selection, the start index must be before or on the |
126 | | // field, the end index after it. |
127 | | |
128 | | // The SvxAccessibleTextIndex.GetEEIndex method gives the index on |
129 | | // the field, as long the input index is on the field. Thus, |
130 | | // correction necessary for the end index |
131 | | |
132 | | // Therefore, for _ranges_, if part of the field is touched, all |
133 | | // of the field must be selected |
134 | 0 | if( rStart.GetParagraph() <= rEnd.GetParagraph() || |
135 | 0 | (rStart.GetParagraph() == rEnd.GetParagraph() && |
136 | 0 | rStart.GetEEIndex() <= rEnd.GetEEIndex()) ) |
137 | 0 | { |
138 | 0 | if( rEnd.InField() && rEnd.GetFieldOffset() ) |
139 | 0 | return ESelection( rStart.GetParagraph(), rStart.GetEEIndex(), |
140 | 0 | rEnd.GetParagraph(), rEnd.GetEEIndex()+1 ); |
141 | 0 | } |
142 | 0 | else if( rStart.GetParagraph() > rEnd.GetParagraph() || |
143 | 0 | (rStart.GetParagraph() == rEnd.GetParagraph() && |
144 | 0 | rStart.GetEEIndex() > rEnd.GetEEIndex()) ) |
145 | 0 | { |
146 | 0 | if( rStart.InField() && rStart.GetFieldOffset() ) |
147 | 0 | return ESelection( rStart.GetParagraph(), rStart.GetEEIndex()+1, |
148 | 0 | rEnd.GetParagraph(), rEnd.GetEEIndex() ); |
149 | 0 | } |
150 | | |
151 | 0 | return ESelection( rStart.GetParagraph(), rStart.GetEEIndex(), |
152 | 0 | rEnd.GetParagraph(), rEnd.GetEEIndex() ); |
153 | 0 | } |
154 | | |
155 | | static ESelection MakeEESelection( const SvxAccessibleTextIndex& rIndex ) |
156 | 0 | { |
157 | 0 | return ESelection( rIndex.GetParagraph(), rIndex.GetEEIndex(), |
158 | 0 | rIndex.GetParagraph(), rIndex.GetEEIndex() + 1 ); |
159 | 0 | } |
160 | | |
161 | | sal_Int32 SvxAccessibleTextIndex::GetEEIndex() const |
162 | 0 | { |
163 | 0 | DBG_ASSERT(mnEEIndex >= 0, |
164 | 0 | "SvxAccessibleTextIndex::GetEEIndex: index value overflow"); |
165 | |
|
166 | 0 | return mnEEIndex; |
167 | 0 | } |
168 | | |
169 | | void SvxAccessibleTextIndex::SetEEIndex( sal_Int32 nEEIndex, const SvxTextForwarder& rTF ) |
170 | 0 | { |
171 | | // reset |
172 | 0 | mnFieldOffset = 0; |
173 | 0 | mbInField = false; |
174 | 0 | mnFieldLen = 0; |
175 | 0 | mnBulletOffset = 0; |
176 | 0 | mbInBullet = false; |
177 | 0 | mnBulletLen = 0; |
178 | | |
179 | | // set known values |
180 | 0 | mnEEIndex = nEEIndex; |
181 | | |
182 | | // calculate unknowns |
183 | |
|
184 | 0 | mnIndex = nEEIndex; |
185 | |
|
186 | 0 | EBulletInfo aBulletInfo = rTF.GetBulletInfo( GetParagraph() ); |
187 | | |
188 | | // any text bullets? |
189 | 0 | if( aBulletInfo.nParagraph != EE_PARA_MAX && |
190 | 0 | aBulletInfo.bVisible && |
191 | 0 | aBulletInfo.nType != SVX_NUM_BITMAP ) |
192 | 0 | { |
193 | 0 | mnIndex += aBulletInfo.aText.getLength(); |
194 | 0 | } |
195 | |
|
196 | 0 | std::vector<EFieldInfo> aFieldInfos = rTF.GetFieldInfo( GetParagraph() ); |
197 | 0 | for( const EFieldInfo& rFieldInfo : aFieldInfos ) |
198 | 0 | { |
199 | 0 | if( rFieldInfo.aPosition.nIndex > nEEIndex ) |
200 | 0 | break; |
201 | | |
202 | 0 | if( rFieldInfo.aPosition.nIndex == nEEIndex ) |
203 | 0 | { |
204 | 0 | AreInField(); |
205 | 0 | break; |
206 | 0 | } |
207 | | |
208 | 0 | mnIndex += std::max(rFieldInfo.aCurrentText.getLength()-1, sal_Int32(0)); |
209 | 0 | } |
210 | 0 | } |
211 | | |
212 | | void SvxAccessibleTextIndex::SetIndex( sal_Int32 nIndex, const SvxTextForwarder& rTF ) |
213 | 0 | { |
214 | | // reset |
215 | 0 | mnFieldOffset = 0; |
216 | 0 | mbInField = false; |
217 | 0 | mnFieldLen = 0; |
218 | 0 | mnBulletOffset = 0; |
219 | 0 | mbInBullet = false; |
220 | 0 | mnBulletLen = 0; |
221 | | |
222 | | // set known values |
223 | 0 | mnIndex = nIndex; |
224 | | |
225 | | // calculate unknowns |
226 | |
|
227 | 0 | DBG_ASSERT(nIndex >= 0, |
228 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
229 | |
|
230 | 0 | mnEEIndex = nIndex; |
231 | |
|
232 | 0 | EBulletInfo aBulletInfo = rTF.GetBulletInfo( GetParagraph() ); |
233 | | |
234 | | // any text bullets? |
235 | 0 | if( aBulletInfo.nParagraph != EE_PARA_MAX && |
236 | 0 | aBulletInfo.bVisible && |
237 | 0 | aBulletInfo.nType != SVX_NUM_BITMAP ) |
238 | 0 | { |
239 | 0 | sal_Int32 nBulletLen = aBulletInfo.aText.getLength(); |
240 | |
|
241 | 0 | if( nIndex < nBulletLen ) |
242 | 0 | { |
243 | 0 | mbInBullet = true; |
244 | 0 | SetBulletOffset( nIndex, nBulletLen ); |
245 | 0 | mnEEIndex = 0; |
246 | 0 | return; |
247 | 0 | } |
248 | | |
249 | 0 | mnEEIndex = mnEEIndex - nBulletLen; |
250 | 0 | } |
251 | | |
252 | 0 | std::vector<EFieldInfo> aFieldInfos = rTF.GetFieldInfo( GetParagraph() ); |
253 | 0 | for( const EFieldInfo& rFieldInfo : aFieldInfos ) |
254 | 0 | { |
255 | | // we're before a field |
256 | 0 | if( rFieldInfo.aPosition.nIndex > mnEEIndex ) |
257 | 0 | break; |
258 | | |
259 | 0 | mnEEIndex -= std::max(rFieldInfo.aCurrentText.getLength()-1, sal_Int32(0)); |
260 | | |
261 | | // we're within a field |
262 | 0 | if( rFieldInfo.aPosition.nIndex >= mnEEIndex ) |
263 | 0 | { |
264 | 0 | AreInField(); |
265 | 0 | SetFieldOffset( std::max(rFieldInfo.aCurrentText.getLength()-1, sal_Int32(0)) - (rFieldInfo.aPosition.nIndex - mnEEIndex), |
266 | 0 | rFieldInfo.aCurrentText.getLength() ); |
267 | 0 | mnEEIndex = rFieldInfo.aPosition.nIndex ; |
268 | 0 | break; |
269 | 0 | } |
270 | 0 | } |
271 | 0 | } |
272 | | |
273 | | bool SvxAccessibleTextIndex::IsEditableRange( const SvxAccessibleTextIndex& rEnd ) const |
274 | 0 | { |
275 | 0 | if( GetIndex() > rEnd.GetIndex() ) |
276 | 0 | return rEnd.IsEditableRange( *this ); |
277 | | |
278 | 0 | if( InBullet() || rEnd.InBullet() ) |
279 | 0 | return false; |
280 | | |
281 | 0 | if( InField() && GetFieldOffset() ) |
282 | 0 | return false; // within field |
283 | | |
284 | 0 | if( rEnd.InField() && rEnd.GetFieldOffset() >= rEnd.GetFieldLen() - 1 ) |
285 | 0 | return false; // within field |
286 | | |
287 | 0 | return true; |
288 | 0 | } |
289 | | |
290 | | |
291 | 0 | SvxEditSourceAdapter::SvxEditSourceAdapter() : mbEditSourceValid( false ) |
292 | 0 | { |
293 | 0 | } |
294 | | |
295 | | SvxEditSourceAdapter::~SvxEditSourceAdapter() |
296 | 0 | { |
297 | 0 | } |
298 | | |
299 | | std::unique_ptr<SvxEditSource> SvxEditSourceAdapter::Clone() const |
300 | 0 | { |
301 | 0 | if( mbEditSourceValid && mpAdaptee ) |
302 | 0 | { |
303 | 0 | std::unique_ptr< SvxEditSource > pClonedAdaptee( mpAdaptee->Clone() ); |
304 | |
|
305 | 0 | if (pClonedAdaptee) |
306 | 0 | { |
307 | 0 | std::unique_ptr<SvxEditSourceAdapter> pClone(new SvxEditSourceAdapter()); |
308 | 0 | pClone->SetEditSource( std::move(pClonedAdaptee) ); |
309 | 0 | return std::unique_ptr< SvxEditSource >(pClone.release()); |
310 | 0 | } |
311 | 0 | } |
312 | | |
313 | 0 | return nullptr; |
314 | 0 | } |
315 | | |
316 | | SvxAccessibleTextAdapter* SvxEditSourceAdapter::GetTextForwarderAdapter() |
317 | 0 | { |
318 | 0 | if( mbEditSourceValid && mpAdaptee ) |
319 | 0 | { |
320 | 0 | SvxTextForwarder* pTextForwarder = mpAdaptee->GetTextForwarder(); |
321 | |
|
322 | 0 | if( pTextForwarder ) |
323 | 0 | { |
324 | 0 | maTextAdapter.SetForwarder(*pTextForwarder); |
325 | |
|
326 | 0 | return &maTextAdapter; |
327 | 0 | } |
328 | 0 | } |
329 | | |
330 | 0 | return nullptr; |
331 | 0 | } |
332 | | |
333 | | SvxTextForwarder* SvxEditSourceAdapter::GetTextForwarder() |
334 | 0 | { |
335 | 0 | return GetTextForwarderAdapter(); |
336 | 0 | } |
337 | | |
338 | | SvxViewForwarder* SvxEditSourceAdapter::GetViewForwarder() |
339 | 0 | { |
340 | 0 | if( mbEditSourceValid && mpAdaptee ) |
341 | 0 | return mpAdaptee->GetViewForwarder(); |
342 | | |
343 | 0 | return nullptr; |
344 | 0 | } |
345 | | |
346 | | SvxAccessibleTextEditViewAdapter* SvxEditSourceAdapter::GetEditViewForwarderAdapter( bool bCreate ) |
347 | 0 | { |
348 | 0 | if( mbEditSourceValid && mpAdaptee ) |
349 | 0 | { |
350 | 0 | SvxEditViewForwarder* pEditViewForwarder = mpAdaptee->GetEditViewForwarder(bCreate); |
351 | |
|
352 | 0 | if( pEditViewForwarder ) |
353 | 0 | { |
354 | 0 | SvxAccessibleTextAdapter* pTextAdapter = GetTextForwarderAdapter(); |
355 | |
|
356 | 0 | if( pTextAdapter ) |
357 | 0 | { |
358 | 0 | maEditViewAdapter.SetForwarder(*pEditViewForwarder, *pTextAdapter); |
359 | |
|
360 | 0 | return &maEditViewAdapter; |
361 | 0 | } |
362 | 0 | } |
363 | 0 | } |
364 | | |
365 | 0 | return nullptr; |
366 | 0 | } |
367 | | |
368 | | SvxEditViewForwarder* SvxEditSourceAdapter::GetEditViewForwarder( bool bCreate ) |
369 | 0 | { |
370 | 0 | return GetEditViewForwarderAdapter( bCreate ); |
371 | 0 | } |
372 | | |
373 | | void SvxEditSourceAdapter::UpdateData() |
374 | 0 | { |
375 | 0 | if( mbEditSourceValid && mpAdaptee ) |
376 | 0 | mpAdaptee->UpdateData(); |
377 | 0 | } |
378 | | |
379 | | SfxBroadcaster& SvxEditSourceAdapter::GetBroadcaster() const |
380 | 0 | { |
381 | 0 | if( mbEditSourceValid && mpAdaptee ) |
382 | 0 | return mpAdaptee->GetBroadcaster(); |
383 | | |
384 | 0 | return maDummyBroadcaster; |
385 | 0 | } |
386 | | |
387 | | void SvxEditSourceAdapter::SetEditSource( std::unique_ptr< SvxEditSource > && pAdaptee ) |
388 | 0 | { |
389 | 0 | if (pAdaptee) |
390 | 0 | { |
391 | 0 | mpAdaptee = std::move(pAdaptee); |
392 | 0 | mbEditSourceValid = true; |
393 | 0 | } |
394 | 0 | else |
395 | 0 | { |
396 | | // do a lazy delete (prevents us from deleting the broadcaster |
397 | | // from within a broadcast in |
398 | | // AccessibleTextHelper_Impl::Notify) |
399 | 0 | mbEditSourceValid = false; |
400 | 0 | } |
401 | 0 | } |
402 | | |
403 | | SvxAccessibleTextAdapter::SvxAccessibleTextAdapter() |
404 | 0 | : mpTextForwarder(nullptr) |
405 | 0 | { |
406 | 0 | } |
407 | | |
408 | | SvxAccessibleTextAdapter::~SvxAccessibleTextAdapter() |
409 | 0 | { |
410 | 0 | } |
411 | | |
412 | | sal_Int32 SvxAccessibleTextAdapter::GetParagraphCount() const |
413 | 0 | { |
414 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
415 | |
|
416 | 0 | return mpTextForwarder->GetParagraphCount(); |
417 | 0 | } |
418 | | |
419 | | sal_Int32 SvxAccessibleTextAdapter::GetTextLen( sal_Int32 nParagraph ) const |
420 | 0 | { |
421 | 0 | SvxAccessibleTextIndex aIndex; |
422 | 0 | aIndex.SetEEIndex( nParagraph, mpTextForwarder->GetTextLen( nParagraph ), *this ); |
423 | |
|
424 | 0 | return aIndex.GetIndex(); |
425 | 0 | } |
426 | | |
427 | | OUString SvxAccessibleTextAdapter::GetText( const ESelection& rSel ) const |
428 | 0 | { |
429 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
430 | |
|
431 | 0 | SvxAccessibleTextIndex aStartIndex; |
432 | 0 | SvxAccessibleTextIndex aEndIndex; |
433 | |
|
434 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
435 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
436 | | |
437 | | // normalize selection |
438 | 0 | if (!rSel.IsAdjusted()) |
439 | 0 | { |
440 | 0 | std::swap( aStartIndex, aEndIndex ); |
441 | 0 | } |
442 | |
|
443 | 0 | OUString sStr = mpTextForwarder->GetText( MakeEESelection(aStartIndex, aEndIndex) ); |
444 | | |
445 | | // trim field text, if necessary |
446 | 0 | if( aStartIndex.InField() ) |
447 | 0 | { |
448 | 0 | DBG_ASSERT(aStartIndex.GetFieldOffset() >= 0, |
449 | 0 | "SvxAccessibleTextIndex::GetText: index value overflow"); |
450 | |
|
451 | 0 | sStr = sStr.copy( aStartIndex.GetFieldOffset() ); |
452 | 0 | } |
453 | 0 | if( aEndIndex.InField() && aEndIndex.GetFieldOffset() ) |
454 | 0 | { |
455 | 0 | DBG_ASSERT(sStr.getLength() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset()) >= 0, |
456 | 0 | "SvxAccessibleTextIndex::GetText: index value overflow"); |
457 | |
|
458 | 0 | sStr = sStr.copy(0, sStr.getLength() - (aEndIndex.GetFieldLen() - aEndIndex.GetFieldOffset()) ); |
459 | 0 | } |
460 | |
|
461 | 0 | EBulletInfo aBulletInfo2 = GetBulletInfo( aEndIndex.GetParagraph() ); |
462 | |
|
463 | 0 | if( aEndIndex.InBullet() ) |
464 | 0 | { |
465 | | // append trailing bullet |
466 | 0 | sStr += aBulletInfo2.aText; |
467 | |
|
468 | 0 | DBG_ASSERT(sStr.getLength() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) >= 0, |
469 | 0 | "SvxAccessibleTextIndex::GetText: index value overflow"); |
470 | |
|
471 | 0 | sStr = sStr.copy(0, sStr.getLength() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) ); |
472 | 0 | } |
473 | 0 | else if( aStartIndex.GetParagraph() != aEndIndex.GetParagraph() && |
474 | 0 | HaveTextBullet( aEndIndex.GetParagraph() ) ) |
475 | 0 | { |
476 | 0 | OUString sBullet = aBulletInfo2.aText; |
477 | |
|
478 | 0 | DBG_ASSERT(sBullet.getLength() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) >= 0, |
479 | 0 | "SvxAccessibleTextIndex::GetText: index value overflow"); |
480 | |
|
481 | 0 | sBullet = sBullet.copy(0, sBullet.getLength() - (aEndIndex.GetBulletLen() - aEndIndex.GetBulletOffset()) ); |
482 | | |
483 | | // insert bullet |
484 | 0 | sStr = sStr.replaceAt( GetTextLen(aStartIndex.GetParagraph()) - aStartIndex.GetIndex(), 0, sBullet ); |
485 | 0 | } |
486 | |
|
487 | 0 | return sStr; |
488 | 0 | } |
489 | | |
490 | | SfxItemSet SvxAccessibleTextAdapter::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib ) const |
491 | 0 | { |
492 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
493 | |
|
494 | 0 | SvxAccessibleTextIndex aStartIndex; |
495 | 0 | SvxAccessibleTextIndex aEndIndex; |
496 | |
|
497 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
498 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
499 | |
|
500 | 0 | return mpTextForwarder->GetAttribs( MakeEESelection(aStartIndex, aEndIndex), nOnlyHardAttrib ); |
501 | 0 | } |
502 | | |
503 | | SfxItemSet SvxAccessibleTextAdapter::GetParaAttribs( sal_Int32 nPara ) const |
504 | 0 | { |
505 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
506 | |
|
507 | 0 | return mpTextForwarder->GetParaAttribs( nPara ); |
508 | 0 | } |
509 | | |
510 | | void SvxAccessibleTextAdapter::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet ) |
511 | 0 | { |
512 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
513 | |
|
514 | 0 | mpTextForwarder->SetParaAttribs( nPara, rSet ); |
515 | 0 | } |
516 | | |
517 | | void SvxAccessibleTextAdapter::RemoveAttribs( const ESelection& ) |
518 | 0 | { |
519 | 0 | } |
520 | | |
521 | | void SvxAccessibleTextAdapter::GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const |
522 | 0 | { |
523 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
524 | |
|
525 | 0 | mpTextForwarder->GetPortions( nPara, rList ); |
526 | 0 | } |
527 | | |
528 | | OUString SvxAccessibleTextAdapter::GetStyleSheet(sal_Int32 nPara) const |
529 | 0 | { |
530 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
531 | |
|
532 | 0 | return mpTextForwarder->GetStyleSheet(nPara); |
533 | 0 | } |
534 | | |
535 | | void SvxAccessibleTextAdapter::SetStyleSheet(sal_Int32 nPara, const OUString& rStyleName) |
536 | 0 | { |
537 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
538 | |
|
539 | 0 | mpTextForwarder->SetStyleSheet(nPara, rStyleName); |
540 | 0 | } |
541 | | |
542 | | SfxItemState SvxAccessibleTextAdapter::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const |
543 | 0 | { |
544 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
545 | |
|
546 | 0 | SvxAccessibleTextIndex aStartIndex; |
547 | 0 | SvxAccessibleTextIndex aEndIndex; |
548 | |
|
549 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
550 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
551 | |
|
552 | 0 | return mpTextForwarder->GetItemState( MakeEESelection(aStartIndex, aEndIndex), |
553 | 0 | nWhich ); |
554 | 0 | } |
555 | | |
556 | | SfxItemState SvxAccessibleTextAdapter::GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const |
557 | 0 | { |
558 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
559 | |
|
560 | 0 | return mpTextForwarder->GetItemState( nPara, nWhich ); |
561 | 0 | } |
562 | | |
563 | | void SvxAccessibleTextAdapter::QuickInsertText( const OUString& rText, const ESelection& rSel ) |
564 | 0 | { |
565 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
566 | |
|
567 | 0 | SvxAccessibleTextIndex aStartIndex; |
568 | 0 | SvxAccessibleTextIndex aEndIndex; |
569 | |
|
570 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
571 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
572 | |
|
573 | 0 | mpTextForwarder->QuickInsertText( rText, |
574 | 0 | MakeEESelection(aStartIndex, aEndIndex) ); |
575 | 0 | } |
576 | | |
577 | | void SvxAccessibleTextAdapter::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel ) |
578 | 0 | { |
579 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
580 | |
|
581 | 0 | SvxAccessibleTextIndex aStartIndex; |
582 | 0 | SvxAccessibleTextIndex aEndIndex; |
583 | |
|
584 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
585 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
586 | |
|
587 | 0 | mpTextForwarder->QuickInsertField( rFld, |
588 | 0 | MakeEESelection(aStartIndex, aEndIndex) ); |
589 | 0 | } |
590 | | |
591 | | void SvxAccessibleTextAdapter::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) |
592 | 0 | { |
593 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
594 | |
|
595 | 0 | SvxAccessibleTextIndex aStartIndex; |
596 | 0 | SvxAccessibleTextIndex aEndIndex; |
597 | |
|
598 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
599 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
600 | |
|
601 | 0 | mpTextForwarder->QuickSetAttribs( rSet, |
602 | 0 | MakeEESelection(aStartIndex, aEndIndex) ); |
603 | 0 | } |
604 | | |
605 | | void SvxAccessibleTextAdapter::QuickInsertLineBreak( const ESelection& rSel ) |
606 | 0 | { |
607 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
608 | |
|
609 | 0 | SvxAccessibleTextIndex aStartIndex; |
610 | 0 | SvxAccessibleTextIndex aEndIndex; |
611 | |
|
612 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
613 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
614 | |
|
615 | 0 | mpTextForwarder->QuickInsertLineBreak( MakeEESelection(aStartIndex, aEndIndex) ); |
616 | 0 | } |
617 | | |
618 | | SfxItemPool* SvxAccessibleTextAdapter::GetPool() const |
619 | 0 | { |
620 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
621 | |
|
622 | 0 | return mpTextForwarder->GetPool(); |
623 | 0 | } |
624 | | |
625 | | OUString SvxAccessibleTextAdapter::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rpTxtColor, std::optional<Color>& rpFldColor, std::optional<FontLineStyle>& rpFldLineStyle ) |
626 | 0 | { |
627 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
628 | |
|
629 | 0 | return mpTextForwarder->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor, rpFldLineStyle ); |
630 | 0 | } |
631 | | |
632 | | void SvxAccessibleTextAdapter::FieldClicked( const SvxFieldItem& rField ) |
633 | 0 | { |
634 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
635 | |
|
636 | 0 | mpTextForwarder->FieldClicked( rField ); |
637 | 0 | } |
638 | | |
639 | | sal_Int32 SvxAccessibleTextAdapter::CalcEditEngineIndex( sal_Int32 nPara, sal_Int32 nLogicalIndex ) |
640 | 0 | { |
641 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
642 | |
|
643 | 0 | SvxAccessibleTextIndex aIndex; |
644 | 0 | aIndex.SetIndex(nPara, nLogicalIndex, *mpTextForwarder); |
645 | 0 | return aIndex.GetEEIndex(); |
646 | 0 | } |
647 | | |
648 | | bool SvxAccessibleTextAdapter::IsValid() const |
649 | 0 | { |
650 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
651 | |
|
652 | 0 | if( mpTextForwarder ) |
653 | 0 | return mpTextForwarder->IsValid(); |
654 | 0 | else |
655 | 0 | return false; |
656 | 0 | } |
657 | | |
658 | | LanguageType SvxAccessibleTextAdapter::GetLanguage( sal_Int32 nPara, sal_Int32 nPos ) const |
659 | 0 | { |
660 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
661 | |
|
662 | 0 | SvxAccessibleTextIndex aIndex; |
663 | |
|
664 | 0 | aIndex.SetIndex( nPara, nPos, *this ); |
665 | |
|
666 | 0 | return mpTextForwarder->GetLanguage( nPara, aIndex.GetEEIndex() ); |
667 | 0 | } |
668 | | |
669 | | std::vector<EFieldInfo> SvxAccessibleTextAdapter::GetFieldInfo( sal_Int32 nPara ) const |
670 | 0 | { |
671 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
672 | |
|
673 | 0 | return mpTextForwarder->GetFieldInfo( nPara ); |
674 | 0 | } |
675 | | |
676 | | EBulletInfo SvxAccessibleTextAdapter::GetBulletInfo( sal_Int32 nPara ) const |
677 | 0 | { |
678 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
679 | |
|
680 | 0 | return mpTextForwarder->GetBulletInfo( nPara ); |
681 | 0 | } |
682 | | |
683 | | tools::Rectangle SvxAccessibleTextAdapter::GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const |
684 | 0 | { |
685 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
686 | |
|
687 | 0 | SvxAccessibleTextIndex aIndex; |
688 | 0 | aIndex.SetIndex( nPara, nIndex, *this ); |
689 | | |
690 | | // preset if anything goes wrong below |
691 | | // n-th char in GetParagraphIndex's paragraph |
692 | 0 | tools::Rectangle aRect = mpTextForwarder->GetCharBounds( nPara, aIndex.GetEEIndex() ); |
693 | |
|
694 | 0 | if( aIndex.InBullet() ) |
695 | 0 | { |
696 | 0 | EBulletInfo aBulletInfo = GetBulletInfo( nPara ); |
697 | |
|
698 | 0 | OutputDevice* pOutDev = GetRefDevice(); |
699 | |
|
700 | 0 | DBG_ASSERT(pOutDev!=nullptr, "SvxAccessibleTextAdapter::GetCharBounds: No ref device"); |
701 | | |
702 | | // preset if anything goes wrong below |
703 | 0 | aRect = aBulletInfo.aBounds; // better than nothing |
704 | 0 | if( pOutDev ) |
705 | 0 | { |
706 | 0 | AccessibleStringWrap aStringWrap( *pOutDev, aBulletInfo.aFont, aBulletInfo.aText ); |
707 | |
|
708 | 0 | aStringWrap.GetCharacterBounds( aIndex.GetBulletOffset(), aRect ); |
709 | 0 | aRect.Move( aBulletInfo.aBounds.Left(), aBulletInfo.aBounds.Top() ); |
710 | 0 | } |
711 | 0 | } |
712 | 0 | else |
713 | 0 | { |
714 | | // handle field content manually |
715 | 0 | if( aIndex.InField() ) |
716 | 0 | { |
717 | 0 | OutputDevice* pOutDev = GetRefDevice(); |
718 | |
|
719 | 0 | DBG_ASSERT(pOutDev!=nullptr, "SvxAccessibleTextAdapter::GetCharBounds: No ref device"); |
720 | |
|
721 | 0 | if( pOutDev ) |
722 | 0 | { |
723 | 0 | ESelection aSel = MakeEESelection( aIndex ); |
724 | |
|
725 | 0 | SvxFont aFont = EditEngine::CreateSvxFontFromItemSet( mpTextForwarder->GetAttribs( aSel ) ); |
726 | 0 | AccessibleStringWrap aStringWrap( *pOutDev, |
727 | 0 | aFont, |
728 | 0 | mpTextForwarder->GetText( aSel ) ); |
729 | |
|
730 | 0 | tools::Rectangle aStartRect = mpTextForwarder->GetCharBounds( nPara, aIndex.GetEEIndex() ); |
731 | |
|
732 | 0 | aStringWrap.GetCharacterBounds( aIndex.GetFieldOffset(), aRect ); |
733 | 0 | aRect.Move( aStartRect.Left(), aStartRect.Top() ); |
734 | 0 | } |
735 | 0 | } |
736 | 0 | } |
737 | |
|
738 | 0 | return aRect; |
739 | 0 | } |
740 | | |
741 | | tools::Rectangle SvxAccessibleTextAdapter::GetParaBounds( sal_Int32 nPara ) const |
742 | 0 | { |
743 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
744 | |
|
745 | 0 | EBulletInfo aBulletInfo = GetBulletInfo( nPara ); |
746 | |
|
747 | 0 | if( aBulletInfo.nParagraph != EE_PARA_MAX && |
748 | 0 | aBulletInfo.bVisible && |
749 | 0 | aBulletInfo.nType != SVX_NUM_BITMAP ) |
750 | 0 | { |
751 | | // include bullet in para bounding box |
752 | 0 | tools::Rectangle aRect( mpTextForwarder->GetParaBounds( nPara ) ); |
753 | |
|
754 | 0 | aRect.Union( aBulletInfo.aBounds ); |
755 | |
|
756 | 0 | return aRect; |
757 | 0 | } |
758 | | |
759 | 0 | return mpTextForwarder->GetParaBounds( nPara ); |
760 | 0 | } |
761 | | |
762 | | MapMode SvxAccessibleTextAdapter::GetMapMode() const |
763 | 0 | { |
764 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
765 | |
|
766 | 0 | return mpTextForwarder->GetMapMode(); |
767 | 0 | } |
768 | | |
769 | | OutputDevice* SvxAccessibleTextAdapter::GetRefDevice() const |
770 | 0 | { |
771 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
772 | |
|
773 | 0 | return mpTextForwarder->GetRefDevice(); |
774 | 0 | } |
775 | | |
776 | | bool SvxAccessibleTextAdapter::GetIndexAtPoint( const Point& rPoint, sal_Int32& nPara, sal_Int32& nIndex ) const |
777 | 0 | { |
778 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
779 | |
|
780 | 0 | if( !mpTextForwarder->GetIndexAtPoint( rPoint, nPara, nIndex ) ) |
781 | 0 | return false; |
782 | | |
783 | 0 | SvxAccessibleTextIndex aIndex; |
784 | 0 | aIndex.SetEEIndex(nPara, nIndex, *this); |
785 | |
|
786 | 0 | DBG_ASSERT(aIndex.GetIndex() >= 0, |
787 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
788 | |
|
789 | 0 | nIndex = aIndex.GetIndex(); |
790 | |
|
791 | 0 | EBulletInfo aBulletInfo = GetBulletInfo( nPara ); |
792 | | |
793 | | // any text bullets? |
794 | 0 | if( aBulletInfo.nParagraph != EE_PARA_MAX && |
795 | 0 | aBulletInfo.bVisible && |
796 | 0 | aBulletInfo.nType != SVX_NUM_BITMAP ) |
797 | 0 | { |
798 | 0 | if( aBulletInfo.aBounds.Contains( rPoint) ) |
799 | 0 | { |
800 | 0 | OutputDevice* pOutDev = GetRefDevice(); |
801 | |
|
802 | 0 | DBG_ASSERT(pOutDev!=nullptr, "SvxAccessibleTextAdapter::GetIndexAtPoint: No ref device"); |
803 | |
|
804 | 0 | if( !pOutDev ) |
805 | 0 | return false; |
806 | | |
807 | 0 | AccessibleStringWrap aStringWrap( *pOutDev, aBulletInfo.aFont, aBulletInfo.aText ); |
808 | |
|
809 | 0 | Point aPoint = rPoint; |
810 | 0 | aPoint.Move( -aBulletInfo.aBounds.Left(), -aBulletInfo.aBounds.Top() ); |
811 | |
|
812 | 0 | DBG_ASSERT(aStringWrap.GetIndexAtPoint( aPoint ) >= 0, |
813 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
814 | |
|
815 | 0 | nIndex = aStringWrap.GetIndexAtPoint( aPoint ); |
816 | 0 | return true; |
817 | 0 | } |
818 | 0 | } |
819 | | |
820 | 0 | if( !aIndex.InField() ) |
821 | 0 | return true; |
822 | | |
823 | 0 | OutputDevice* pOutDev = GetRefDevice(); |
824 | |
|
825 | 0 | DBG_ASSERT(pOutDev!=nullptr, "SvxAccessibleTextAdapter::GetIndexAtPoint: No ref device"); |
826 | |
|
827 | 0 | if( !pOutDev ) |
828 | 0 | return false; |
829 | | |
830 | 0 | ESelection aSelection = MakeEESelection( aIndex ); |
831 | 0 | SvxFont aFont = EditEngine::CreateSvxFontFromItemSet( mpTextForwarder->GetAttribs( aSelection ) ); |
832 | 0 | AccessibleStringWrap aStringWrap( *pOutDev, |
833 | 0 | aFont, |
834 | 0 | mpTextForwarder->GetText( aSelection ) ); |
835 | |
|
836 | 0 | tools::Rectangle aRect = mpTextForwarder->GetCharBounds( nPara, aIndex.GetEEIndex() ); |
837 | 0 | Point aPoint = rPoint; |
838 | 0 | aPoint.Move( -aRect.Left(), -aRect.Top() ); |
839 | |
|
840 | 0 | DBG_ASSERT(aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( rPoint ) >= 0, |
841 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
842 | |
|
843 | 0 | nIndex = (aIndex.GetIndex() + aStringWrap.GetIndexAtPoint( aPoint )); |
844 | 0 | return true; |
845 | 0 | } |
846 | | |
847 | | bool SvxAccessibleTextAdapter::GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd ) const |
848 | 0 | { |
849 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
850 | |
|
851 | 0 | SvxAccessibleTextIndex aIndex; |
852 | 0 | aIndex.SetIndex(nPara, nIndex, *this); |
853 | 0 | nIndex = aIndex.GetEEIndex(); |
854 | |
|
855 | 0 | if( aIndex.InBullet() ) |
856 | 0 | { |
857 | 0 | DBG_ASSERT(aIndex.GetBulletLen() >= 0, |
858 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
859 | | |
860 | | // always treat bullet as separate word |
861 | 0 | nStart = 0; |
862 | 0 | nEnd = aIndex.GetBulletLen(); |
863 | |
|
864 | 0 | return true; |
865 | 0 | } |
866 | | |
867 | 0 | if( aIndex.InField() ) |
868 | 0 | { |
869 | 0 | DBG_ASSERT(aIndex.GetIndex() - aIndex.GetFieldOffset() >= 0 && |
870 | 0 | nStart + aIndex.GetFieldLen() >= 0, |
871 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
872 | | |
873 | | // always treat field as separate word |
874 | | // TODO: to circumvent this, _we_ would have to do the break iterator stuff! |
875 | 0 | nStart = aIndex.GetIndex() - aIndex.GetFieldOffset(); |
876 | 0 | nEnd = nStart + aIndex.GetFieldLen(); |
877 | |
|
878 | 0 | return true; |
879 | 0 | } |
880 | | |
881 | 0 | if( !mpTextForwarder->GetWordIndices( nPara, nIndex, nStart, nEnd ) ) |
882 | 0 | return false; |
883 | | |
884 | 0 | aIndex.SetEEIndex( nPara, nStart, *this ); |
885 | 0 | DBG_ASSERT(aIndex.GetIndex() >= 0, |
886 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
887 | 0 | nStart = aIndex.GetIndex(); |
888 | |
|
889 | 0 | aIndex.SetEEIndex( nPara, nEnd, *this ); |
890 | 0 | DBG_ASSERT(aIndex.GetIndex() >= 0, |
891 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
892 | 0 | nEnd = aIndex.GetIndex(); |
893 | |
|
894 | 0 | return true; |
895 | 0 | } |
896 | | |
897 | | bool SvxAccessibleTextAdapter::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool /* bInCell */ ) const |
898 | 0 | { |
899 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
900 | |
|
901 | 0 | SvxAccessibleTextIndex aIndex; |
902 | 0 | aIndex.SetIndex(nPara, nIndex, *this); |
903 | 0 | nIndex = aIndex.GetEEIndex(); |
904 | |
|
905 | 0 | if( aIndex.InBullet() ) |
906 | 0 | { |
907 | 0 | DBG_ASSERT(aIndex.GetBulletLen() >= 0, |
908 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
909 | | |
910 | | // always treat bullet as distinct attribute |
911 | 0 | nStartIndex = 0; |
912 | 0 | nEndIndex = aIndex.GetBulletLen(); |
913 | |
|
914 | 0 | return true; |
915 | 0 | } |
916 | | |
917 | 0 | if( aIndex.InField() ) |
918 | 0 | { |
919 | 0 | DBG_ASSERT(aIndex.GetIndex() - aIndex.GetFieldOffset() >= 0, |
920 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
921 | | |
922 | | // always treat field as distinct attribute |
923 | 0 | nStartIndex = aIndex.GetIndex() - aIndex.GetFieldOffset(); |
924 | 0 | nEndIndex = nStartIndex + aIndex.GetFieldLen(); |
925 | |
|
926 | 0 | return true; |
927 | 0 | } |
928 | | |
929 | 0 | if( !mpTextForwarder->GetAttributeRun( nStartIndex, nEndIndex, nPara, nIndex ) ) |
930 | 0 | return false; |
931 | | |
932 | 0 | aIndex.SetEEIndex( nPara, nStartIndex, *this ); |
933 | 0 | DBG_ASSERT(aIndex.GetIndex() >= 0, |
934 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
935 | 0 | nStartIndex = aIndex.GetIndex(); |
936 | |
|
937 | 0 | aIndex.SetEEIndex( nPara, nEndIndex, *this ); |
938 | 0 | DBG_ASSERT(aIndex.GetIndex() >= 0, |
939 | 0 | "SvxAccessibleTextIndex::SetIndex: index value overflow"); |
940 | 0 | nEndIndex = aIndex.GetIndex(); |
941 | |
|
942 | 0 | return true; |
943 | 0 | } |
944 | | |
945 | | sal_Int32 SvxAccessibleTextAdapter::GetLineCount( sal_Int32 nPara ) const |
946 | 0 | { |
947 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
948 | |
|
949 | 0 | return mpTextForwarder->GetLineCount( nPara ); |
950 | 0 | } |
951 | | |
952 | | sal_Int32 SvxAccessibleTextAdapter::GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const |
953 | 0 | { |
954 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
955 | |
|
956 | 0 | SvxAccessibleTextIndex aEndIndex; |
957 | 0 | sal_Int32 nCurrLine; |
958 | 0 | sal_Int32 nCurrIndex, nLastIndex; |
959 | 0 | for( nCurrLine=0, nCurrIndex=0, nLastIndex=0; nCurrLine<=nLine; ++nCurrLine ) |
960 | 0 | { |
961 | 0 | nLastIndex = nCurrIndex; |
962 | 0 | nCurrIndex = |
963 | 0 | nCurrIndex + mpTextForwarder->GetLineLen( nPara, nCurrLine ); |
964 | 0 | } |
965 | |
|
966 | 0 | aEndIndex.SetEEIndex( nPara, nCurrIndex, *this ); |
967 | 0 | if( nLine > 0 ) |
968 | 0 | { |
969 | 0 | SvxAccessibleTextIndex aStartIndex; |
970 | 0 | aStartIndex.SetEEIndex( nPara, nLastIndex, *this ); |
971 | |
|
972 | 0 | return aEndIndex.GetIndex() - aStartIndex.GetIndex(); |
973 | 0 | } |
974 | 0 | else |
975 | 0 | return aEndIndex.GetIndex(); |
976 | 0 | } |
977 | | |
978 | | void SvxAccessibleTextAdapter::GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nParagraph, sal_Int32 nLine ) const |
979 | 0 | { |
980 | 0 | mpTextForwarder->GetLineBoundaries( rStart, rEnd, nParagraph, nLine ); |
981 | 0 | } |
982 | | |
983 | | sal_Int32 SvxAccessibleTextAdapter::GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const |
984 | 0 | { |
985 | 0 | return mpTextForwarder->GetLineNumberAtIndex( nPara, nIndex ); |
986 | 0 | } |
987 | | |
988 | | bool SvxAccessibleTextAdapter::Delete( const ESelection& rSel ) |
989 | 0 | { |
990 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
991 | |
|
992 | 0 | SvxAccessibleTextIndex aStartIndex; |
993 | 0 | SvxAccessibleTextIndex aEndIndex; |
994 | |
|
995 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
996 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
997 | |
|
998 | 0 | return mpTextForwarder->Delete( MakeEESelection(aStartIndex, aEndIndex ) ); |
999 | 0 | } |
1000 | | |
1001 | | bool SvxAccessibleTextAdapter::InsertText( const OUString& rStr, const ESelection& rSel ) |
1002 | 0 | { |
1003 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
1004 | |
|
1005 | 0 | SvxAccessibleTextIndex aStartIndex; |
1006 | 0 | SvxAccessibleTextIndex aEndIndex; |
1007 | |
|
1008 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
1009 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
1010 | |
|
1011 | 0 | return mpTextForwarder->InsertText( rStr, MakeEESelection(aStartIndex, aEndIndex) ); |
1012 | 0 | } |
1013 | | |
1014 | | bool SvxAccessibleTextAdapter::QuickFormatDoc( bool bFull ) |
1015 | 0 | { |
1016 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
1017 | |
|
1018 | 0 | return mpTextForwarder->QuickFormatDoc( bFull ); |
1019 | 0 | } |
1020 | | |
1021 | | bool SvxAccessibleTextAdapter::SupportsOutlineDepth() const |
1022 | 0 | { |
1023 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
1024 | |
|
1025 | 0 | return mpTextForwarder->SupportsOutlineDepth(); |
1026 | 0 | } |
1027 | | |
1028 | | sal_Int16 SvxAccessibleTextAdapter::GetDepth( sal_Int32 nPara ) const |
1029 | 0 | { |
1030 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
1031 | |
|
1032 | 0 | return mpTextForwarder->GetDepth( nPara ); |
1033 | 0 | } |
1034 | | |
1035 | | bool SvxAccessibleTextAdapter::SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth ) |
1036 | 0 | { |
1037 | 0 | assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder"); |
1038 | |
|
1039 | 0 | return mpTextForwarder->SetDepth( nPara, nNewDepth ); |
1040 | 0 | } |
1041 | | |
1042 | | void SvxAccessibleTextAdapter::SetForwarder( SvxTextForwarder& rForwarder ) |
1043 | 0 | { |
1044 | 0 | mpTextForwarder = &rForwarder; |
1045 | 0 | } |
1046 | | |
1047 | | bool SvxAccessibleTextAdapter::HaveImageBullet( sal_Int32 nPara ) const |
1048 | 0 | { |
1049 | 0 | EBulletInfo aBulletInfo = GetBulletInfo( nPara ); |
1050 | |
|
1051 | 0 | return ( aBulletInfo.nParagraph != EE_PARA_MAX && |
1052 | 0 | aBulletInfo.bVisible && |
1053 | 0 | aBulletInfo.nType == SVX_NUM_BITMAP ); |
1054 | 0 | } |
1055 | | |
1056 | | bool SvxAccessibleTextAdapter::HaveTextBullet( sal_Int32 nPara ) const |
1057 | 0 | { |
1058 | 0 | EBulletInfo aBulletInfo = GetBulletInfo( nPara ); |
1059 | |
|
1060 | 0 | return ( aBulletInfo.nParagraph != EE_PARA_MAX && |
1061 | 0 | aBulletInfo.bVisible && |
1062 | 0 | aBulletInfo.nType != SVX_NUM_BITMAP ); |
1063 | 0 | } |
1064 | | |
1065 | | bool SvxAccessibleTextAdapter::IsEditable( const ESelection& rSel ) const |
1066 | 0 | { |
1067 | 0 | SvxAccessibleTextIndex aStartIndex; |
1068 | 0 | SvxAccessibleTextIndex aEndIndex; |
1069 | |
|
1070 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *this ); |
1071 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *this ); |
1072 | | |
1073 | | // normalize selection |
1074 | 0 | if (!rSel.IsAdjusted()) |
1075 | 0 | { |
1076 | 0 | std::swap( aStartIndex, aEndIndex ); |
1077 | 0 | } |
1078 | |
|
1079 | 0 | return aStartIndex.IsEditableRange( aEndIndex ); |
1080 | 0 | } |
1081 | | |
1082 | | const SfxItemSet * SvxAccessibleTextAdapter::GetEmptyItemSetPtr() |
1083 | 0 | { |
1084 | 0 | OSL_FAIL( "not implemented" ); |
1085 | 0 | return nullptr; |
1086 | 0 | } |
1087 | | |
1088 | | void SvxAccessibleTextAdapter::AppendParagraph() |
1089 | 0 | { |
1090 | 0 | OSL_FAIL( "not implemented" ); |
1091 | 0 | } |
1092 | | |
1093 | | sal_Int32 SvxAccessibleTextAdapter::AppendTextPortion( sal_Int32, const OUString &, const SfxItemSet & ) |
1094 | 0 | { |
1095 | 0 | OSL_FAIL( "not implemented" ); |
1096 | 0 | return 0; |
1097 | 0 | } |
1098 | | void SvxAccessibleTextAdapter::CopyText(const SvxTextForwarder&) |
1099 | 0 | { |
1100 | 0 | OSL_FAIL( "not implemented" ); |
1101 | 0 | } |
1102 | | |
1103 | | SvxAccessibleTextEditViewAdapter::SvxAccessibleTextEditViewAdapter() |
1104 | 0 | : mpViewForwarder(nullptr) |
1105 | 0 | , mpTextForwarder(nullptr) |
1106 | 0 | { |
1107 | 0 | } |
1108 | | |
1109 | | SvxAccessibleTextEditViewAdapter::~SvxAccessibleTextEditViewAdapter() |
1110 | 0 | { |
1111 | 0 | } |
1112 | | |
1113 | | bool SvxAccessibleTextEditViewAdapter::IsValid() const |
1114 | 0 | { |
1115 | 0 | DBG_ASSERT(mpViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1116 | |
|
1117 | 0 | if( mpViewForwarder ) |
1118 | 0 | return mpViewForwarder->IsValid(); |
1119 | 0 | else |
1120 | 0 | return false; |
1121 | 0 | } |
1122 | | |
1123 | | Point SvxAccessibleTextEditViewAdapter::LogicToPixel( const Point& rPoint, const MapMode& rMapMode ) const |
1124 | 0 | { |
1125 | 0 | assert(mpViewForwarder && "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1126 | |
|
1127 | 0 | return mpViewForwarder->LogicToPixel(rPoint, rMapMode); |
1128 | 0 | } |
1129 | | |
1130 | | Point SvxAccessibleTextEditViewAdapter::PixelToLogic( const Point& rPoint, const MapMode& rMapMode ) const |
1131 | 0 | { |
1132 | 0 | assert(mpViewForwarder && "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1133 | |
|
1134 | 0 | return mpViewForwarder->PixelToLogic(rPoint, rMapMode); |
1135 | 0 | } |
1136 | | |
1137 | | bool SvxAccessibleTextEditViewAdapter::GetSelection( ESelection& rSel ) const |
1138 | 0 | { |
1139 | 0 | assert(mpViewForwarder && "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1140 | |
|
1141 | 0 | ESelection aSelection; |
1142 | |
|
1143 | 0 | if( !mpViewForwarder->GetSelection( aSelection ) ) |
1144 | 0 | return false; |
1145 | | |
1146 | 0 | SvxAccessibleTextIndex aStartIndex; |
1147 | 0 | SvxAccessibleTextIndex aEndIndex; |
1148 | |
|
1149 | 0 | aStartIndex.SetEEIndex( aSelection.start.nPara, aSelection.start.nIndex, *mpTextForwarder ); |
1150 | 0 | aEndIndex.SetEEIndex( aSelection.end.nPara, aSelection.end.nIndex, *mpTextForwarder ); |
1151 | |
|
1152 | 0 | DBG_ASSERT(aStartIndex.GetIndex() >= 0 && |
1153 | 0 | aEndIndex.GetIndex() >= 0, |
1154 | 0 | "SvxAccessibleTextEditViewAdapter::GetSelection: index value overflow"); |
1155 | |
|
1156 | 0 | rSel = ESelection( aStartIndex.GetParagraph(), aStartIndex.GetIndex(), |
1157 | 0 | aEndIndex.GetParagraph(), aEndIndex.GetIndex() ); |
1158 | |
|
1159 | 0 | return true; |
1160 | 0 | } |
1161 | | |
1162 | | bool SvxAccessibleTextEditViewAdapter::SetSelection( const ESelection& rSel ) |
1163 | 0 | { |
1164 | 0 | assert(mpViewForwarder && "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1165 | |
|
1166 | 0 | SvxAccessibleTextIndex aStartIndex; |
1167 | 0 | SvxAccessibleTextIndex aEndIndex; |
1168 | |
|
1169 | 0 | aStartIndex.SetIndex( rSel.start.nPara, rSel.start.nIndex, *mpTextForwarder ); |
1170 | 0 | aEndIndex.SetIndex( rSel.end.nPara, rSel.end.nIndex, *mpTextForwarder ); |
1171 | |
|
1172 | 0 | return mpViewForwarder->SetSelection( MakeEESelection(aStartIndex, aEndIndex) ); |
1173 | 0 | } |
1174 | | |
1175 | | bool SvxAccessibleTextEditViewAdapter::Copy() |
1176 | 0 | { |
1177 | 0 | DBG_ASSERT(mpViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1178 | |
|
1179 | 0 | return mpViewForwarder->Copy(); |
1180 | 0 | } |
1181 | | |
1182 | | bool SvxAccessibleTextEditViewAdapter::Cut() |
1183 | 0 | { |
1184 | 0 | DBG_ASSERT(mpViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1185 | |
|
1186 | 0 | return mpViewForwarder->Cut(); |
1187 | 0 | } |
1188 | | |
1189 | | bool SvxAccessibleTextEditViewAdapter::Paste() |
1190 | 0 | { |
1191 | 0 | DBG_ASSERT(mpViewForwarder, "SvxAccessibleTextEditViewAdapter: no forwarder"); |
1192 | |
|
1193 | 0 | return mpViewForwarder->Paste(); |
1194 | 0 | } |
1195 | | |
1196 | | void SvxAccessibleTextEditViewAdapter::SetForwarder( SvxEditViewForwarder& rForwarder, |
1197 | | SvxAccessibleTextAdapter& rTextForwarder ) |
1198 | 0 | { |
1199 | 0 | mpViewForwarder = &rForwarder; |
1200 | 0 | mpTextForwarder = &rTextForwarder; |
1201 | 0 | } |
1202 | | |
1203 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |