1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <osl/diagnose.h>
#include <tools/debug.hxx>
#include <svl/style.hxx>
#include <com/sun/star/i18n/WordType.hpp>
#include <svl/itemset.hxx>
#include <editeng/editeng.hxx>
#include <editeng/editdata.hxx>
#include <editeng/outliner.hxx>
#include <editeng/unoedhlp.hxx>
#include <svl/poolitem.hxx>
#include <editeng/unoforou.hxx>
#include <editeng/outlobj.hxx>
#include "unofored_internal.hxx"
using namespace ::com::sun::star;
SvxOutlinerForwarder::SvxOutlinerForwarder( Outliner& rOutl, bool bOutlText /* = false */ ) :
rOutliner( rOutl ),
bOutlinerText( bOutlText ),
mnParaAttribsCache( 0 )
{
}
SvxOutlinerForwarder::~SvxOutlinerForwarder()
{
flushCache();
}
sal_Int32 SvxOutlinerForwarder::GetParagraphCount() const
{
return rOutliner.GetParagraphCount();
}
sal_Int32 SvxOutlinerForwarder::GetTextLen( sal_Int32 nParagraph ) const
{
return rOutliner.GetEditEngine().GetTextLen( nParagraph );
}
OUString SvxOutlinerForwarder::GetText( const ESelection& rSel ) const
{
//! GetText (ESelection) should probably also be in the Outliner
// in the time being use as the hack for the EditEngine:
EditEngine* pEditEngine = const_cast<EditEngine*>(&rOutliner.GetEditEngine());
return pEditEngine->GetText( rSel );
}
static SfxItemSet ImplOutlinerForwarderGetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib, EditEngine& rEditEngine )
{
if( rSel.nStartPara == rSel.nEndPara )
{
GetAttribsFlags nFlags = GetAttribsFlags::NONE;
switch( nOnlyHardAttrib )
{
case EditEngineAttribs::All:
nFlags = GetAttribsFlags::ALL;
break;
case EditEngineAttribs::OnlyHard:
nFlags = GetAttribsFlags::CHARATTRIBS;
break;
default:
OSL_FAIL("unknown flags for SvxOutlinerForwarder::GetAttribs");
}
return rEditEngine.GetAttribs( rSel.nStartPara, rSel.nStartPos, rSel.nEndPos, nFlags );
}
else
{
return rEditEngine.GetAttribs( rSel, nOnlyHardAttrib );
}
}
SfxItemSet SvxOutlinerForwarder::GetAttribs( const ESelection& rSel, EditEngineAttribs nOnlyHardAttrib ) const
{
if( moAttribsCache && ( EditEngineAttribs::All == nOnlyHardAttrib ) )
{
// have we the correct set in cache?
if( maAttribCacheSelection == rSel )
{
// yes! just return the cache
return *moAttribsCache;
}
else
{
// no, we need delete the old cache
moAttribsCache.reset();
}
}
//! Does it not exist on the Outliner?
//! and why is the GetAttribs on the EditEngine not a const?
EditEngine& rEditEngine = const_cast<EditEngine&>(rOutliner.GetEditEngine());
SfxItemSet aSet( ImplOutlinerForwarderGetAttribs( rSel, nOnlyHardAttrib, rEditEngine ) );
if( EditEngineAttribs::All == nOnlyHardAttrib )
{
moAttribsCache.emplace( aSet );
maAttribCacheSelection = rSel;
}
SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( rSel.nStartPara );
if( pStyle )
aSet.SetParent( &(pStyle->GetItemSet() ) );
return aSet;
}
SfxItemSet SvxOutlinerForwarder::GetParaAttribs( sal_Int32 nPara ) const
{
if( moParaAttribsCache )
{
// have we the correct set in cache?
if( nPara == mnParaAttribsCache )
{
// yes! just return the cache
return *moParaAttribsCache;
}
else
{
// no, we need delete the old cache
moParaAttribsCache.reset();
}
}
moParaAttribsCache.emplace( rOutliner.GetParaAttribs( nPara ) );
mnParaAttribsCache = nPara;
EditEngine& rEditEngine = const_cast<EditEngine&>(rOutliner.GetEditEngine());
SfxStyleSheet* pStyle = rEditEngine.GetStyleSheet( nPara );
if( pStyle )
moParaAttribsCache->SetParent( &(pStyle->GetItemSet() ) );
return *moParaAttribsCache;
}
void SvxOutlinerForwarder::SetParaAttribs( sal_Int32 nPara, const SfxItemSet& rSet )
{
flushCache();
const SfxItemSet* pOldParent = rSet.GetParent();
if( pOldParent )
const_cast<SfxItemSet*>(&rSet)->SetParent( nullptr );
rOutliner.SetParaAttribs( nPara, rSet );
if( pOldParent )
const_cast<SfxItemSet*>(&rSet)->SetParent( pOldParent );
}
void SvxOutlinerForwarder::RemoveAttribs( const ESelection& rSelection )
{
rOutliner.RemoveAttribs( rSelection, false/*bRemoveParaAttribs*/, 0 );
}
SfxItemPool* SvxOutlinerForwarder::GetPool() const
{
return rOutliner.GetEmptyItemSet().GetPool();
}
void SvxOutlinerForwarder::GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList ) const
{
const_cast<EditEngine&>(rOutliner.GetEditEngine()).GetPortions( nPara, rList );
}
OUString SvxOutlinerForwarder::GetStyleSheet(sal_Int32 nPara) const
{
if (auto pStyle = rOutliner.GetStyleSheet(nPara))
return pStyle->GetName();
return OUString();
}
void SvxOutlinerForwarder::SetStyleSheet(sal_Int32 nPara, const OUString& rStyleName)
{
auto pStyleSheetPool = rOutliner.GetStyleSheetPool();
if (auto pStyle = pStyleSheetPool ? pStyleSheetPool->Find(rStyleName, SfxStyleFamily::Para) : nullptr)
rOutliner.SetStyleSheet(nPara, static_cast<SfxStyleSheet*>(pStyle));
}
void SvxOutlinerForwarder::QuickInsertText( const OUString& rText, const ESelection& rSel )
{
flushCache();
if( rText.isEmpty() )
{
rOutliner.QuickDelete( rSel );
}
else
{
rOutliner.QuickInsertText( rText, rSel );
}
}
void SvxOutlinerForwarder::QuickInsertLineBreak( const ESelection& rSel )
{
flushCache();
rOutliner.QuickInsertLineBreak( rSel );
}
void SvxOutlinerForwarder::QuickInsertField( const SvxFieldItem& rFld, const ESelection& rSel )
{
flushCache();
rOutliner.QuickInsertField( rFld, rSel );
}
void SvxOutlinerForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel )
{
flushCache();
rOutliner.QuickSetAttribs( rSet, rSel );
}
OUString SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, std::optional<Color>& rpTxtColor, std::optional<Color>& rpFldColor, std::optional<FontLineStyle>& rpFldLineStyle )
{
return rOutliner.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor, rpFldLineStyle );
}
void SvxOutlinerForwarder::FieldClicked( const SvxFieldItem& /*rField*/ )
{
}
bool SvxOutlinerForwarder::IsValid() const
{
// cannot reliably query outliner state
// while in the middle of an update
return rOutliner.IsUpdateLayout();
}
SfxItemState SvxOutlinerForwarder::GetItemState( const ESelection& rSel, sal_uInt16 nWhich ) const
{
return GetSvxEditEngineItemState( rOutliner.GetEditEngine(), rSel, nWhich );
}
SfxItemState SvxOutlinerForwarder::GetItemState( sal_Int32 nPara, sal_uInt16 nWhich ) const
{
const SfxItemSet& rSet = rOutliner.GetParaAttribs( nPara );
return rSet.GetItemState( nWhich );
}
void SvxOutlinerForwarder::flushCache()
{
moAttribsCache.reset();
moParaAttribsCache.reset();
}
LanguageType SvxOutlinerForwarder::GetLanguage( sal_Int32 nPara, sal_Int32 nIndex ) const
{
return rOutliner.GetLanguage(nPara, nIndex);
}
std::vector<EFieldInfo> SvxOutlinerForwarder::GetFieldInfo( sal_Int32 nPara ) const
{
return rOutliner.GetEditEngine().GetFieldInfo( nPara );
}
EBulletInfo SvxOutlinerForwarder::GetBulletInfo( sal_Int32 nPara ) const
{
return rOutliner.GetBulletInfo( nPara );
}
tools::Rectangle SvxOutlinerForwarder::GetCharBounds( sal_Int32 nPara, sal_Int32 nIndex ) const
{
// EditEngine's 'internal' methods like GetCharacterBounds()
// don't rotate for vertical text.
Size aSize( rOutliner.CalcTextSize() );
// swap width and height
tools::Long tmp = aSize.Width();
aSize.setWidth(aSize.Height());
aSize.setHeight(tmp);
bool bIsVertical( rOutliner.IsVertical() );
// #108900# Handle virtual position one-past-the end of the string
if( nIndex >= GetTextLen(nPara) )
{
tools::Rectangle aLast;
if( nIndex )
{
// use last character, if possible
aLast = rOutliner.GetEditEngine().GetCharacterBounds( EPosition(nPara, nIndex-1) );
// move at end of this last character, make one pixel wide
aLast.Move( aLast.Right() - aLast.Left(), 0 );
aLast.SetSize( Size(1, aLast.GetHeight()) );
// take care for CTL
aLast = SvxEditSourceHelper::EEToUserSpace( aLast, aSize, bIsVertical );
}
else
{
// #109864# Bounds must lie within the paragraph
aLast = GetParaBounds( nPara );
// #109151# Don't use paragraph height, but line height
// instead. aLast is already CTL-correct
if( bIsVertical)
aLast.SetSize( Size( rOutliner.GetLineHeight(nPara), 1 ) );
else
aLast.SetSize( Size( 1, rOutliner.GetLineHeight(nPara) ) );
}
return aLast;
}
else
{
return SvxEditSourceHelper::EEToUserSpace( rOutliner.GetEditEngine().GetCharacterBounds( EPosition(nPara, nIndex) ),
aSize, bIsVertical );
}
}
tools::Rectangle SvxOutlinerForwarder::GetParaBounds( sal_Int32 nPara ) const
{
return rOutliner.GetParaBounds( nPara );
}
MapMode SvxOutlinerForwarder::GetMapMode() const
{
return rOutliner.GetRefMapMode();
}
OutputDevice* SvxOutlinerForwarder::GetRefDevice() const
{
return rOutliner.GetRefDevice();
}
bool SvxOutlinerForwarder::GetIndexAtPoint( const Point& rPos, sal_Int32& nPara, sal_Int32& nIndex ) const
{
Size aSize( rOutliner.CalcTextSize() );
// swap width and height
tools::Long tmp = aSize.Width();
aSize.setWidth(aSize.Height());
aSize.setHeight(tmp);
Point aEEPos( SvxEditSourceHelper::UserSpaceToEE( rPos,
aSize,
rOutliner.IsVertical() ));
EPosition aDocPos = rOutliner.GetEditEngine().FindDocPosition( aEEPos );
nPara = aDocPos.nPara;
nIndex = aDocPos.nIndex;
return true;
}
bool SvxOutlinerForwarder::GetWordIndices( sal_Int32 nPara, sal_Int32 nIndex, sal_Int32& nStart, sal_Int32& nEnd ) const
{
ESelection aRes = rOutliner.GetEditEngine().GetWord( ESelection(nPara, nIndex, nPara, nIndex), css::i18n::WordType::DICTIONARY_WORD );
if( aRes.nStartPara == nPara &&
aRes.nStartPara == aRes.nEndPara )
{
nStart = aRes.nStartPos;
nEnd = aRes.nEndPos;
return true;
}
return false;
}
bool SvxOutlinerForwarder::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell ) const
{
SvxEditSourceHelper::GetAttributeRun( nStartIndex, nEndIndex, rOutliner.GetEditEngine(), nPara, nIndex, bInCell );
return true;
}
sal_Int32 SvxOutlinerForwarder::GetLineCount( sal_Int32 nPara ) const
{
return rOutliner.GetLineCount(nPara);
}
sal_Int32 SvxOutlinerForwarder::GetLineLen( sal_Int32 nPara, sal_Int32 nLine ) const
{
return rOutliner.GetLineLen(nPara, nLine);
}
void SvxOutlinerForwarder::GetLineBoundaries( /*out*/sal_Int32 &rStart, /*out*/sal_Int32 &rEnd, sal_Int32 nPara, sal_Int32 nLine ) const
{
return rOutliner.GetEditEngine().GetLineBoundaries( rStart, rEnd, nPara, nLine );
}
sal_Int32 SvxOutlinerForwarder::GetLineNumberAtIndex( sal_Int32 nPara, sal_Int32 nIndex ) const
{
return rOutliner.GetEditEngine().GetLineNumberAtIndex( nPara, nIndex );
}
bool SvxOutlinerForwarder::QuickFormatDoc( bool )
{
rOutliner.QuickFormatDoc();
return true;
}
bool SvxOutlinerForwarder::Delete( const ESelection& rSelection )
{
flushCache();
rOutliner.QuickDelete( rSelection );
rOutliner.QuickFormatDoc();
return true;
}
bool SvxOutlinerForwarder::InsertText( const OUString& rStr, const ESelection& rSelection )
{
flushCache();
rOutliner.QuickInsertText( rStr, rSelection );
rOutliner.QuickFormatDoc();
return true;
}
sal_Int16 SvxOutlinerForwarder::GetDepth( sal_Int32 nPara ) const
{
DBG_ASSERT( 0 <= nPara && nPara < GetParagraphCount(), "SvxOutlinerForwarder::GetDepth: Invalid paragraph index");
Paragraph* pPara = rOutliner.GetParagraph( nPara );
sal_Int16 nLevel = -1;
if( pPara )
nLevel = rOutliner.GetDepth( nPara );
return nLevel;
}
bool SvxOutlinerForwarder::SetDepth( sal_Int32 nPara, sal_Int16 nNewDepth )
{
DBG_ASSERT( 0 <= nPara && nPara < GetParagraphCount(), "SvxOutlinerForwarder::SetDepth: Invalid paragraph index");
if( (nNewDepth >= -1) && (nNewDepth <= 9) && (0 <= nPara && nPara < GetParagraphCount()) )
{
Paragraph* pPara = rOutliner.GetParagraph( nPara );
if( pPara )
{
rOutliner.SetDepth( pPara, nNewDepth );
// const bool bOutlinerText = pSdrObject && (pSdrObject->GetObjInventor() == SdrInventor::Default) && (pSdrObject->GetObjIdentifier() == OBJ_OUTLINETEXT);
if( bOutlinerText )
rOutliner.SetLevelDependentStyleSheet( nPara );
return true;
}
}
return false;
}
sal_Int32 SvxOutlinerForwarder::GetNumberingStartValue( sal_Int32 nPara )
{
if( 0 <= nPara && nPara < GetParagraphCount() )
{
return rOutliner.GetNumberingStartValue( nPara );
}
else
{
OSL_FAIL( "SvxOutlinerForwarder::GetNumberingStartValue)(), Invalid paragraph index");
return -1;
}
}
void SvxOutlinerForwarder::SetNumberingStartValue( sal_Int32 nPara, sal_Int32 nNumberingStartValue )
{
if( 0 <= nPara && nPara < GetParagraphCount() )
{
rOutliner.SetNumberingStartValue( nPara, nNumberingStartValue );
}
else
{
OSL_FAIL( "SvxOutlinerForwarder::SetNumberingStartValue)(), Invalid paragraph index");
}
}
bool SvxOutlinerForwarder::IsParaIsNumberingRestart( sal_Int32 nPara )
{
if( 0 <= nPara && nPara < GetParagraphCount() )
{
return rOutliner.IsParaIsNumberingRestart( nPara );
}
else
{
OSL_FAIL( "SvxOutlinerForwarder::IsParaIsNumberingRestart)(), Invalid paragraph index");
return false;
}
}
void SvxOutlinerForwarder::SetParaIsNumberingRestart( sal_Int32 nPara, bool bParaIsNumberingRestart )
{
if( 0 <= nPara && nPara < GetParagraphCount() )
{
rOutliner.SetParaIsNumberingRestart( nPara, bParaIsNumberingRestart );
}
else
{
OSL_FAIL( "SvxOutlinerForwarder::SetParaIsNumberingRestart)(), Invalid paragraph index");
}
}
const SfxItemSet * SvxOutlinerForwarder::GetEmptyItemSetPtr()
{
EditEngine& rEditEngine = const_cast< EditEngine& >( rOutliner.GetEditEngine() );
return &rEditEngine.GetEmptyItemSet();
}
void SvxOutlinerForwarder::AppendParagraph()
{
EditEngine& rEditEngine = const_cast< EditEngine& >( rOutliner.GetEditEngine() );
rEditEngine.InsertParagraph( rEditEngine.GetParagraphCount(), OUString() );
}
sal_Int32 SvxOutlinerForwarder::AppendTextPortion( sal_Int32 nPara, const OUString &rText, const SfxItemSet & /*rSet*/ )
{
sal_Int32 nLen = 0;
EditEngine& rEditEngine = const_cast< EditEngine& >( rOutliner.GetEditEngine() );
sal_Int32 nParaCount = rEditEngine.GetParagraphCount();
DBG_ASSERT( 0 <= nPara && nPara < nParaCount, "paragraph index out of bounds" );
if (0 <= nPara && nPara < nParaCount)
{
nLen = rEditEngine.GetTextLen( nPara );
rEditEngine.QuickInsertText( rText, ESelection( nPara, nLen, nPara, nLen ) );
}
return nLen;
}
void SvxOutlinerForwarder::CopyText(const SvxTextForwarder& rSource)
{
const SvxOutlinerForwarder* pSourceForwarder = dynamic_cast< const SvxOutlinerForwarder* >( &rSource );
if( !pSourceForwarder )
return;
std::optional<OutlinerParaObject> pNewOutlinerParaObject = pSourceForwarder->rOutliner.CreateParaObject();
rOutliner.SetText( *pNewOutlinerParaObject );
}
sal_Int32 SvxTextForwarder::GetNumberingStartValue( sal_Int32 )
{
return -1;
}
void SvxTextForwarder::SetNumberingStartValue( sal_Int32, sal_Int32 )
{
}
bool SvxTextForwarder::IsParaIsNumberingRestart( sal_Int32 )
{
return false;
}
void SvxTextForwarder::SetParaIsNumberingRestart( sal_Int32, bool )
{
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|