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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904 | /* -*- 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 <memory>
#include <sal/config.h>
#include <sal/log.hxx>
#include <scitems.hxx>
#include <editeng/eeitem.hxx>
#include <svx/svdpool.hxx>
#include <svx/svdobj.hxx>
#include <editeng/editeng.hxx>
#include <editeng/editobj.hxx>
#include <editeng/flditem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/unoprnms.hxx>
#include <editeng/unofored.hxx>
#include <vcl/svapp.hxx>
#include <editeng/unoipset.hxx>
#include <textuno.hxx>
#include <fielduno.hxx>
#include <editsrc.hxx>
#include <docsh.hxx>
#include <editutil.hxx>
#include <miscuno.hxx>
#include <cellsuno.hxx>
#include <cellvalue.hxx>
#include <cellform.hxx>
#include <patattr.hxx>
#include <docfunc.hxx>
#include <scmod.hxx>
using namespace com::sun::star;
static const SvxItemPropertySet * lcl_GetHdFtPropertySet()
{
static SfxItemPropertyMapEntry aHdFtPropertyMap_Impl[] =
{
SVX_UNOEDIT_CHAR_PROPERTIES,
SVX_UNOEDIT_FONT_PROPERTIES,
SVX_UNOEDIT_PARA_PROPERTIES,
SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
{ OUString(), 0, css::uno::Type(), 0, 0 }
};
static bool bTwipsSet = false;
if (!bTwipsSet)
{
// modify PropertyMap to include CONVERT_TWIPS flag for font height
// (headers/footers are in twips)
SfxItemPropertyMapEntry* pEntry = aHdFtPropertyMap_Impl;
while (!pEntry->aName.isEmpty())
{
if ( ( pEntry->nWID == EE_CHAR_FONTHEIGHT ||
pEntry->nWID == EE_CHAR_FONTHEIGHT_CJK ||
pEntry->nWID == EE_CHAR_FONTHEIGHT_CTL ) &&
pEntry->nMemberId == MID_FONTHEIGHT )
{
pEntry->nMemberId |= CONVERT_TWIPS;
}
++pEntry;
}
bTwipsSet = true;
}
static SvxItemPropertySet aHdFtPropertySet_Impl( aHdFtPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
return &aHdFtPropertySet_Impl;
}
SC_SIMPLE_SERVICE_INFO( ScHeaderFooterContentObj, "ScHeaderFooterContentObj", "com.sun.star.sheet.HeaderFooterContent" )<--- There is an unknown macro here somewhere. Configuration is required. If SC_SIMPLE_SERVICE_INFO is a macro then please configure it.
SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj, "ScHeaderFooterTextObj", "stardiv.one.Text.Text" )
ScHeaderFooterContentObj::ScHeaderFooterContentObj()
{
}
ScHeaderFooterContentObj::~ScHeaderFooterContentObj() {}
const EditTextObject* ScHeaderFooterContentObj::GetLeftEditObject() const
{
return mxLeftText->GetTextObject();
}
const EditTextObject* ScHeaderFooterContentObj::GetCenterEditObject() const
{
return mxCenterText->GetTextObject();
}
const EditTextObject* ScHeaderFooterContentObj::GetRightEditObject() const
{
return mxRightText->GetTextObject();
}
// XHeaderFooterContent
uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getLeftText()
{
SolarMutexGuard aGuard;
uno::Reference<text::XText> xInt(*mxLeftText, uno::UNO_QUERY);
return xInt;
}
uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getCenterText()
{
SolarMutexGuard aGuard;
uno::Reference<text::XText> xInt(*mxCenterText, uno::UNO_QUERY);
return xInt;
}
uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getRightText()
{
SolarMutexGuard aGuard;
uno::Reference<text::XText> xInt(*mxRightText, uno::UNO_QUERY);
return xInt;
}
// XUnoTunnel
sal_Int64 SAL_CALL ScHeaderFooterContentObj::getSomething(
const uno::Sequence<sal_Int8 >& rId )
{
if ( isUnoTunnelId<ScHeaderFooterContentObj>(rId) )
{
return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
}
return 0;
}
namespace
{
class theScHeaderFooterContentObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theScHeaderFooterContentObjUnoTunnelId> {};
}
const uno::Sequence<sal_Int8>& ScHeaderFooterContentObj::getUnoTunnelId()
{
return theScHeaderFooterContentObjUnoTunnelId::get().getSeq();
}
rtl::Reference<ScHeaderFooterContentObj> ScHeaderFooterContentObj::getImplementation(
const uno::Reference<sheet::XHeaderFooterContent>& rObj)
{
return comphelper::getUnoTunnelImplementation<ScHeaderFooterContentObj>(rObj);
}
void ScHeaderFooterContentObj::Init( const EditTextObject* pLeft,
const EditTextObject* pCenter,
const EditTextObject* pRight )
{
uno::Reference<css::sheet::XHeaderFooterContent> xThis(this);
mxLeftText = rtl::Reference<ScHeaderFooterTextObj>(new ScHeaderFooterTextObj(xThis, ScHeaderFooterPart::LEFT, pLeft));
mxCenterText = rtl::Reference<ScHeaderFooterTextObj>(new ScHeaderFooterTextObj(xThis, ScHeaderFooterPart::CENTER, pCenter));
mxRightText = rtl::Reference<ScHeaderFooterTextObj>(new ScHeaderFooterTextObj(xThis, ScHeaderFooterPart::RIGHT, pRight));
}
ScHeaderFooterTextData::ScHeaderFooterTextData(
uno::WeakReference<sheet::XHeaderFooterContent> const & xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
mpTextObj(pTextObj ? pTextObj->Clone() : nullptr),
xContentObj( xContent ),
nPart( nP ),
bDataValid(false)
{
}
ScHeaderFooterTextData::~ScHeaderFooterTextData()
{
SolarMutexGuard aGuard; // needed for EditEngine dtor
pForwarder.reset();
pEditEngine.reset();
}
SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder()
{
if (!pEditEngine)
{
SfxItemPool* pEnginePool = EditEngine::CreatePool();
pEnginePool->FreezeIdRanges();
std::unique_ptr<ScHeaderEditEngine> pHdrEngine(new ScHeaderEditEngine( pEnginePool ));
pHdrEngine->EnableUndo( false );
pHdrEngine->SetRefMapMode(MapMode(MapUnit::MapTwip));
// default font must be set, independently of document
// -> use global pool from module
SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() );
const ScPatternAttr& rPattern = SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN);
rPattern.FillEditItemSet( &aDefaults );
// FillEditItemSet adjusts font height to 1/100th mm,
// but for header/footer twips is needed, as in the PatternAttr:
aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT) );
aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CJK) ) ;
aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT).CloneSetWhich(EE_CHAR_FONTHEIGHT_CTL) );
pHdrEngine->SetDefaults( aDefaults );
ScHeaderFieldData aData;
ScHeaderFooterTextObj::FillDummyFieldData( aData );
pHdrEngine->SetData( aData );
pEditEngine = std::move(pHdrEngine);
pForwarder.reset( new SvxEditEngineForwarder(*pEditEngine) );
}
if (bDataValid)
return pForwarder.get();
if (mpTextObj)
pEditEngine->SetTextCurrentDefaults(*mpTextObj);
bDataValid = true;
return pForwarder.get();
}
void ScHeaderFooterTextData::UpdateData()
{
if (pEditEngine)
{
mpTextObj = pEditEngine->CreateTextObject();
}
}
void ScHeaderFooterTextData::UpdateData(EditEngine& rEditEngine)
{
mpTextObj = rEditEngine.CreateTextObject();
bDataValid = false;
}
ScHeaderFooterTextObj::ScHeaderFooterTextObj(
const uno::WeakReference<sheet::XHeaderFooterContent>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj) :
aTextData(xContent, nP, pTextObj)
{
// ScHeaderFooterTextData acquires rContent
// pUnoText is created on demand (getString/setString work without it)
}
void ScHeaderFooterTextObj::CreateUnoText_Impl()
{
if (!mxUnoText.is())
{
// can't be aggregated because getString/setString is handled here
ScHeaderFooterEditSource aEditSrc(aTextData);
mxUnoText.set(new SvxUnoText(&aEditSrc, lcl_GetHdFtPropertySet(), uno::Reference<text::XText>()));
}
}
ScHeaderFooterTextObj::~ScHeaderFooterTextObj() {}
const EditTextObject* ScHeaderFooterTextObj::GetTextObject() const
{
return aTextData.GetTextObject();
}
const SvxUnoText& ScHeaderFooterTextObj::GetUnoText()
{
if (!mxUnoText.is())
CreateUnoText_Impl();
return *mxUnoText;
}
// XText
uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursor()
{
SolarMutexGuard aGuard;
return new ScHeaderFooterTextCursor( this );
}
uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursorByRange(
const uno::Reference<text::XTextRange>& aTextPosition )
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->createTextCursorByRange(aTextPosition);
//! like ScCellObj::createTextCursorByRange, if SvxUnoTextRange_getReflection available
}
void ScHeaderFooterTextObj::FillDummyFieldData( ScHeaderFieldData& rData )
{
OUString aDummy("???");
rData.aTitle = aDummy;
rData.aLongDocName = aDummy;
rData.aShortDocName = aDummy;
rData.aTabName = aDummy;
rData.nPageNo = 1;
rData.nTotalPages = 99;
}
OUString SAL_CALL ScHeaderFooterTextObj::getString()
{
SolarMutexGuard aGuard;
OUString aRet;
const EditTextObject* pData;
uno::Reference<css::sheet::XHeaderFooterContent> xContentObj = aTextData.GetContentObj();
if (!xContentObj.is())
throw css::uno::RuntimeException(
"ScHeaderFooterTextObj::getString: no ContentObj");
rtl::Reference<ScHeaderFooterContentObj> pObj = ScHeaderFooterContentObj::getImplementation(xContentObj);
switch ( aTextData.GetPart() )
{
case ScHeaderFooterPart::LEFT:
pData = pObj->GetLeftEditObject();
break;
case ScHeaderFooterPart::CENTER:
pData = pObj->GetCenterEditObject();
break;
case ScHeaderFooterPart::RIGHT:
pData = pObj->GetRightEditObject();
break;
default:
SAL_WARN("sc.ui","unexpected enum value of ScHeaderFooterPart");
pData = nullptr;
}
if (pData)
{
// for pure text, no font info is needed in pool defaults
ScHeaderEditEngine aEditEngine( EditEngine::CreatePool() );
ScHeaderFieldData aData;
FillDummyFieldData( aData );
aEditEngine.SetData( aData );
aEditEngine.SetTextCurrentDefaults(*pData);
aRet = ScEditUtil::GetSpaceDelimitedString( aEditEngine );
}
return aRet;
}
void SAL_CALL ScHeaderFooterTextObj::setString( const OUString& aText )
{
SolarMutexGuard aGuard;
// for pure text, no font info is needed in pool defaults
ScHeaderEditEngine aEditEngine(EditEngine::CreatePool());
aEditEngine.SetTextCurrentDefaults( aText );
aTextData.UpdateData(aEditEngine);
}
void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XTextRange>& xRange,
const OUString& aString, sal_Bool bAbsorb )
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->insertString( xRange, aString, bAbsorb );
}
void SAL_CALL ScHeaderFooterTextObj::insertControlCharacter(
const uno::Reference<text::XTextRange>& xRange,
sal_Int16 nControlCharacter, sal_Bool bAbsorb )
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->insertControlCharacter( xRange, nControlCharacter, bAbsorb );
}
void SAL_CALL ScHeaderFooterTextObj::insertTextContent(
const uno::Reference<text::XTextRange >& xRange,
const uno::Reference<text::XTextContent >& xContent,
sal_Bool bAbsorb )
{
SolarMutexGuard aGuard;
if ( xContent.is() && xRange.is() )
{
ScEditFieldObj* pHeaderField = comphelper::getUnoTunnelImplementation<ScEditFieldObj>( xContent );
SvxUnoTextRangeBase* pTextRange =
comphelper::getUnoTunnelImplementation<ScHeaderFooterTextCursor>( xRange );
if ( pHeaderField && !pHeaderField->IsInserted() && pTextRange )
{
SvxEditSource* pEditSource = pTextRange->GetEditSource();
ESelection aSelection(pTextRange->GetSelection());
if (!bAbsorb)
{
// don't replace -> append at end
aSelection.Adjust();
aSelection.nStartPara = aSelection.nEndPara;
aSelection.nStartPos = aSelection.nEndPos;
}
SvxFieldItem aItem(pHeaderField->CreateFieldItem());
SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder();
pForwarder->QuickInsertField( aItem, aSelection );
pEditSource->UpdateData();
// new selection: a digit
aSelection.Adjust();
aSelection.nEndPara = aSelection.nStartPara;
aSelection.nEndPos = aSelection.nStartPos + 1;
uno::Reference<text::XTextRange> xTextRange;
switch ( aTextData.GetPart() )
{
case ScHeaderFooterPart::LEFT:
xTextRange = aTextData.GetContentObj()->getLeftText();
break;
case ScHeaderFooterPart::CENTER:
xTextRange = aTextData.GetContentObj()->getCenterText();
break;
case ScHeaderFooterPart::RIGHT:
xTextRange = aTextData.GetContentObj()->getRightText();
break;
}
pHeaderField->InitDoc(xTextRange, std::make_unique<ScHeaderFooterEditSource>(aTextData), aSelection);
// for bAbsorb=FALSE, the new selection must be behind the inserted content
// (the xml filter relies on this)
if (!bAbsorb)
aSelection.nStartPos = aSelection.nEndPos;
pTextRange->SetSelection( aSelection );
return;
}
}
if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->insertTextContent( xRange, xContent, bAbsorb );
}
void SAL_CALL ScHeaderFooterTextObj::removeTextContent(
const uno::Reference<text::XTextContent>& xContent )
{
SolarMutexGuard aGuard;
if ( xContent.is() )
{
ScEditFieldObj* pHeaderField = comphelper::getUnoTunnelImplementation<ScEditFieldObj>(xContent);
if ( pHeaderField && pHeaderField->IsInserted() )
{
//! check if the field is in this cell
pHeaderField->DeleteField();
return;
}
}
if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->removeTextContent( xContent );
}
uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextObj::getText()
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->getText();
}
uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getStart()
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->getStart();
}
uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getEnd()
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->getEnd();
}
// XTextFieldsSupplier
uno::Reference<container::XEnumerationAccess> SAL_CALL ScHeaderFooterTextObj::getTextFields()
{
SolarMutexGuard aGuard;
// all fields
return new ScHeaderFieldsObj(aTextData);
}
uno::Reference<container::XNameAccess> SAL_CALL ScHeaderFooterTextObj::getTextFieldMasters()
{
// this does not exists in Calc (?)
return nullptr;
}
// XTextRangeMover
void SAL_CALL ScHeaderFooterTextObj::moveTextRange(
const uno::Reference<text::XTextRange>& xRange,
sal_Int16 nParagraphs )
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
mxUnoText->moveTextRange( xRange, nParagraphs );
}
// XEnumerationAccess
uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEnumeration()
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->createEnumeration();
}
// XElementAccess
uno::Type SAL_CALL ScHeaderFooterTextObj::getElementType()
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->getElementType();
}
sal_Bool SAL_CALL ScHeaderFooterTextObj::hasElements()
{
SolarMutexGuard aGuard;
if (!mxUnoText.is())
CreateUnoText_Impl();
return mxUnoText->hasElements();
}
ScCellTextCursor::ScCellTextCursor(ScCellObj& rText) :
SvxUnoTextCursor( rText.GetUnoText() ),
mxTextObj( &rText )
{
}
ScCellTextCursor::~ScCellTextCursor() throw()
{
}
// SvxUnoTextCursor methods reimplemented here to return the right objects:
uno::Reference<text::XText> SAL_CALL ScCellTextCursor::getText()
{
return mxTextObj.get();
}
uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getStart()
{
SolarMutexGuard aGuard;
//! use other object for range than cursor?
ScCellTextCursor* pNew = new ScCellTextCursor( *this );
uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
ESelection aNewSel(GetSelection());
aNewSel.nEndPara = aNewSel.nStartPara;
aNewSel.nEndPos = aNewSel.nStartPos;
pNew->SetSelection( aNewSel );
return xRange;
}
uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getEnd()
{
SolarMutexGuard aGuard;
//! use other object for range than cursor?
ScCellTextCursor* pNew = new ScCellTextCursor( *this );
uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
ESelection aNewSel(GetSelection());
aNewSel.nStartPara = aNewSel.nEndPara;
aNewSel.nStartPos = aNewSel.nEndPos;
pNew->SetSelection( aNewSel );
return xRange;
}
// XUnoTunnel
UNO3_GETIMPLEMENTATION2_IMPL(ScCellTextCursor, SvxUnoTextCursor);
ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(rtl::Reference<ScHeaderFooterTextObj> const & rText) :
SvxUnoTextCursor( rText->GetUnoText() ),
rTextObj( rText )
{}
ScHeaderFooterTextCursor::~ScHeaderFooterTextCursor() throw() {};
// SvxUnoTextCursor methods reimplemented here to return the right objects:
uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextCursor::getText()
{
SolarMutexGuard aGuard;
return rTextObj.get();
}
uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getStart()
{
SolarMutexGuard aGuard;
//! use other object for range than cursor?
ScHeaderFooterTextCursor* pNew = new ScHeaderFooterTextCursor( *this );
uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
ESelection aNewSel(GetSelection());
aNewSel.nEndPara = aNewSel.nStartPara;
aNewSel.nEndPos = aNewSel.nStartPos;
pNew->SetSelection( aNewSel );
return xRange;
}
uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getEnd()
{
SolarMutexGuard aGuard;
//! use other object for range than cursor?
ScHeaderFooterTextCursor* pNew = new ScHeaderFooterTextCursor( *this );
uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
ESelection aNewSel(GetSelection());
aNewSel.nStartPara = aNewSel.nEndPara;
aNewSel.nStartPos = aNewSel.nEndPos;
pNew->SetSelection( aNewSel );
return xRange;
}
// XUnoTunnel
UNO3_GETIMPLEMENTATION2_IMPL(ScHeaderFooterTextCursor, SvxUnoTextCursor);
ScDrawTextCursor::ScDrawTextCursor( const uno::Reference<text::XText>& xParent,
const SvxUnoTextBase& rText ) :
SvxUnoTextCursor( rText ),
xParentText( xParent )
{
}
ScDrawTextCursor::~ScDrawTextCursor() throw()
{
}
// SvxUnoTextCursor methods reimplemented here to return the right objects:
uno::Reference<text::XText> SAL_CALL ScDrawTextCursor::getText()
{
SolarMutexGuard aGuard;
return xParentText;
}
uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getStart()
{
SolarMutexGuard aGuard;
//! use other object for range than cursor?
ScDrawTextCursor* pNew = new ScDrawTextCursor( *this );
uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
ESelection aNewSel(GetSelection());
aNewSel.nEndPara = aNewSel.nStartPara;
aNewSel.nEndPos = aNewSel.nStartPos;
pNew->SetSelection( aNewSel );
return xRange;
}
uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getEnd()
{
SolarMutexGuard aGuard;
//! use other object for range than cursor?
ScDrawTextCursor* pNew = new ScDrawTextCursor( *this );
uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) );
ESelection aNewSel(GetSelection());
aNewSel.nStartPara = aNewSel.nEndPara;
aNewSel.nStartPos = aNewSel.nEndPos;
pNew->SetSelection( aNewSel );
return xRange;
}
// XUnoTunnel
UNO3_GETIMPLEMENTATION2_IMPL(ScDrawTextCursor, SvxUnoTextCursor);
ScSimpleEditSourceHelper::ScSimpleEditSourceHelper()
{
SfxItemPool* pEnginePool = EditEngine::CreatePool();
pEnginePool->SetDefaultMetric( MapUnit::Map100thMM );
pEnginePool->FreezeIdRanges();
pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) ); // TRUE: become owner of pool
pForwarder.reset( new SvxEditEngineForwarder( *pEditEngine ) );
pOriginalSource.reset( new ScSimpleEditSource( pForwarder.get() ) );
}
ScSimpleEditSourceHelper::~ScSimpleEditSourceHelper()
{
SolarMutexGuard aGuard; // needed for EditEngine dtor
pOriginalSource.reset();
pForwarder.reset();
pEditEngine.reset();
}
ScEditEngineTextObj::ScEditEngineTextObj() :
SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
{
}
ScEditEngineTextObj::~ScEditEngineTextObj() throw()
{
}
void ScEditEngineTextObj::SetText( const EditTextObject& rTextObject )
{
GetEditEngine()->SetTextCurrentDefaults( rTextObject );
ESelection aSel;
::GetSelection( aSel, GetEditSource()->GetTextForwarder() );
SetSelection( aSel );
}
std::unique_ptr<EditTextObject> ScEditEngineTextObj::CreateTextObject()
{
return GetEditEngine()->CreateTextObject();
}
ScCellTextData::ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP) :
pDocShell( pDocSh ),
aCellPos( rP ),
bDataValid( false ),
bInUpdate( false ),
bDirty( false ),
bDoUpdate( true )
{
if (pDocShell)
pDocShell->GetDocument().AddUnoObject(*this);
}
ScCellTextData::~ScCellTextData()
{
SolarMutexGuard aGuard; // needed for EditEngine dtor
if (pDocShell)
{
pDocShell->GetDocument().RemoveUnoObject(*this);
pDocShell->GetDocument().DisposeFieldEditEngine(pEditEngine);
}
else
pEditEngine.reset();
pForwarder.reset();
pOriginalSource.reset();
}
ScCellEditSource* ScCellTextData::GetOriginalSource()
{
if (!pOriginalSource)
pOriginalSource.reset( new ScCellEditSource(pDocShell, aCellPos) );
return pOriginalSource.get();
}
SvxTextForwarder* ScCellTextData::GetTextForwarder()
{
if (!pEditEngine)
{
if ( pDocShell )
{
ScDocument& rDoc = pDocShell->GetDocument();
pEditEngine = rDoc.CreateFieldEditEngine();
}
else
{
SfxItemPool* pEnginePool = EditEngine::CreatePool();
pEnginePool->FreezeIdRanges();
pEditEngine.reset( new ScFieldEditEngine(nullptr, pEnginePool, nullptr, true) );
}
// currently, GetPortions doesn't work if UpdateMode is sal_False,
// this will be fixed (in EditEngine) by src600
// pEditEngine->SetUpdateMode( sal_False );
pEditEngine->EnableUndo( false );
if (pDocShell)
pEditEngine->SetRefDevice(pDocShell->GetRefDevice());
else
pEditEngine->SetRefMapMode(MapMode(MapUnit::Map100thMM));
pForwarder.reset( new SvxEditEngineForwarder(*pEditEngine) );
}
if (bDataValid)
return pForwarder.get();
OUString aText;
if (pDocShell)
{
ScDocument& rDoc = pDocShell->GetDocument();
SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() );
if( const ScPatternAttr* pPattern =
rDoc.GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ) )
{
pPattern->FillEditItemSet( &aDefaults );
pPattern->FillEditParaItems( &aDefaults ); // including alignment etc. (for reading)
}
ScRefCellValue aCell(rDoc, aCellPos);
if (aCell.meType == CELLTYPE_EDIT)
{
const EditTextObject* pObj = aCell.mpEditText;
pEditEngine->SetTextNewDefaults(*pObj, aDefaults);
}
else
{
sal_uInt32 nFormat = rDoc.GetNumberFormat(aCellPos);
ScCellFormat::GetInputString(aCell, nFormat, aText, *rDoc.GetFormatTable(), &rDoc);
if (!aText.isEmpty())
pEditEngine->SetTextNewDefaults(aText, aDefaults);
else
pEditEngine->SetDefaults(aDefaults);
}
}
bDataValid = true;
return pForwarder.get();
}
void ScCellTextData::UpdateData()
{
if ( bDoUpdate )
{
OSL_ENSURE(pEditEngine != nullptr, "no EditEngine for UpdateData()");
if ( pDocShell && pEditEngine )
{
// during the own UpdateData call, bDataValid must not be reset,
// or things like attributes after the text would be lost
// (are not stored in the cell)
bInUpdate = true; // prevents bDataValid from being reset
pDocShell->GetDocFunc().PutData(aCellPos, *pEditEngine, true); // always as text
bInUpdate = false;
bDirty = false;
}
}
else
bDirty = true;
}
void ScCellTextData::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
const SfxHintId nId = rHint.GetId();
if ( nId == SfxHintId::Dying )
{
pDocShell = nullptr; // invalid now
pForwarder.reset();
pEditEngine.reset(); // EditEngine uses document's pool
}
else if ( nId == SfxHintId::DataChanged )
{
if (!bInUpdate) // not for own UpdateData calls
bDataValid = false; // text has to be read from the cell again
}
}
ScCellTextObj::ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP) :
ScCellTextData( pDocSh, rP ),
SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertySet(), uno::Reference<text::XText>() )
{
}
ScCellTextObj::~ScCellTextObj() COVERITY_NOEXCEPT_FALSE
{
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|