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
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986 | /* -*- 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 <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/EmbedVerbs.hpp>
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/chart2/XChartDocument.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <hintids.hxx>
#include <sot/exchange.hxx>
#include <svx/hdft.hxx>
#include <svx/svdview.hxx>
#include <svl/itemiter.hxx>
#include <tools/bigint.hxx>
#include <svtools/insdlg.hxx>
#include <sfx2/ipclient.hxx>
#include <editeng/formatbreakitem.hxx>
#include <editeng/svxacorr.hxx>
#include <editeng/ulspitem.hxx>
#include <vcl/graph.hxx>
#include <unotools/charclass.hxx>
#include <comphelper/storagehelper.hxx>
#include <svx/svxdlg.hxx>
#include <svx/extrusionbar.hxx>
#include <svx/fontworkbar.hxx>
#include <dialoghelp.hxx>
#include <frmfmt.hxx>
#include <fmtftn.hxx>
#include <fmthdft.hxx>
#include <fmtpdsc.hxx>
#include <txtfrm.hxx>
#include <wdocsh.hxx>
#include <swmodule.hxx>
#include <wrtsh.hxx>
#include <view.hxx>
#include <cmdid.h>
#include <pagedesc.hxx>
#include <frmmgr.hxx>
#include <swundo.hxx>
#include <swcli.hxx>
#include <poolfmt.hxx>
#include <edtwin.hxx>
#include <fmtcol.hxx>
#include <swtable.hxx>
#include <viscrs.hxx>
#include <swdtflvr.hxx>
#include <doc.hxx>
#include <IDocumentSettingAccess.hxx>
#include <SwCapObjType.hxx>
#include <SwStyleNameMapper.hxx>
#include <sfx2/request.hxx>
#include <paratr.hxx>
#include <ndtxt.hxx>
#include <editeng/acorrcfg.hxx>
#include <IMark.hxx>
#include <sfx2/bindings.hxx>
#include <flyfrm.hxx>
// -> #111827#
#include <SwRewriter.hxx>
#include <strings.hrc>
// <- #111827#
#include <toolkit/helper/vclunohelper.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/uitest/logger.hxx>
#include <vcl/uitest/eventdescription.hxx>
#include <PostItMgr.hxx>
#include <FrameControlsManager.hxx>
#include <fldmgr.hxx>
#include <docufld.hxx>
#include <IDocumentFieldsAccess.hxx>
#include <fmtfld.hxx>
#include <sfx2/msgpool.hxx>
#include <sfx2/msg.hxx>
#include <svtools/embedhlp.hxx>
#include <svx/postattr.hxx>
#include <comphelper/lok.hxx>
#include <memory>
using namespace sw::mark;
using namespace com::sun::star;
namespace {
void collectUIInformation(const OUString& rAction, const OUString& aParameters)
{
EventDescription aDescription;
aDescription.aAction = rAction;
aDescription.aParameters = {{"parameters", aParameters}};
aDescription.aID = "writer_edit";
aDescription.aKeyWord = "SwEditWinUIObject";
aDescription.aParent = "MainWindow";
UITestLogger::getInstance().logEvent(aDescription);
}
}
#define BITFLD_INI_LIST \
m_bClearMark = \
m_bIns = true;\
m_bAddMode = \
m_bBlockMode = \
m_bExtMode = \
m_bInSelect = \
m_bLayoutMode = \
m_bSelWrd = \
m_bSelLn = \
m_bRetainSelection = false; \
m_bIsInClickToEdit = false;
static SvxAutoCorrect* lcl_IsAutoCorr()
{
SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
if( pACorr && !pACorr->IsAutoCorrFlag( ACFlags::CapitalStartSentence | ACFlags::CapitalStartWord |
ACFlags::AddNonBrkSpace | ACFlags::ChgOrdinalNumber | ACFlags::TransliterateRTL |
ACFlags::ChgToEnEmDash | ACFlags::SetINetAttr | ACFlags::Autocorrect ))
pACorr = nullptr;
return pACorr;
}
void SwWrtShell::NoEdit(bool bHideCursor)
{
if(bHideCursor)
HideCursor();
}
void SwWrtShell::Edit()
{
if (CanInsert())
{
ShowCursor();
}
}
bool SwWrtShell::IsEndWrd()
{
SwMvContext aMvContext(this);
if(IsEndPara() && !IsSttPara())
return true;
return IsEndWord();
}
// Insert string
void SwWrtShell::InsertByWord( const OUString & rStr)
{
if( !rStr.isEmpty() )
{
bool bDelim = GetAppCharClass().isLetterNumeric( rStr, 0 );
sal_Int32 nPos = 0, nStt = 0;
for( ; nPos < rStr.getLength(); nPos++ )
{
bool bTmpDelim = GetAppCharClass().isLetterNumeric( rStr, nPos );
if( bTmpDelim != bDelim )
{
Insert( rStr.copy( nStt, nPos - nStt ));
nStt = nPos;
}
}
if( nStt != nPos )
Insert( rStr.copy( nStt, nPos - nStt ));
}
}
void SwWrtShell::Insert( const OUString &rStr )
{
ResetCursorStack();
if( !CanInsert() )
return;
bool bStarted = false;
bool bHasSel = HasSelection(),
bCallIns = m_bIns /*|| bHasSel*/;
bool bDeleted = false;
typedef svl::Items<RES_CHRATR_BEGIN, RES_CHRATR_RSID - 1,
RES_CHRATR_RSID + 1, RES_CHRATR_END - 1,
RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT> CharItems;
SfxItemSet aCharAttrSet(GetAttrPool(), CharItems{});
if( bHasSel || ( !m_bIns && SelectHiddenRange() ) )
{
// Only here parenthesizing, because the normal
// insert is already in parentheses at Editshell.
StartAllAction();
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, GetCursorDescr());
aRewriter.AddRule(UndoArg2, SwResId(STR_YIELDS));
{
OUString aTmpStr = SwResId(STR_START_QUOTE) +
rStr + SwResId(STR_END_QUOTE);
aRewriter.AddRule(UndoArg3, aTmpStr);
}
// tdf#79717 Save character formatting of the start of the selection
const SwPosition *pStart = GetCursor()->Start();
SwPaM aPaM(pStart->nNode.GetNode(), pStart->nContent.GetIndex(),
pStart->nNode.GetNode(), pStart->nContent.GetIndex() + 1);
GetPaMAttr(&aPaM, aCharAttrSet);
StartUndo(SwUndoId::REPLACE, &aRewriter);
bStarted = true;
bDeleted = DelRight();
}
bCallIns ?
SwEditShell::Insert2( rStr, bDeleted ) : SwEditShell::Overwrite( rStr );
if( bDeleted )
{
// tdf#79717 Restore formatting of the deleted selection
SwPosition* pEnd = GetCursor()->Start();
SwPaM aPaM(pEnd->nNode.GetNode(), pEnd->nContent.GetIndex() - rStr.getLength(),
pEnd->nNode.GetNode(), pEnd->nContent.GetIndex());
std::set<sal_uInt16> aAttribs;
for (sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; ++i)
if (i != sal_uInt16(RES_CHRATR_RSID))
aAttribs.insert(aAttribs.end(), i);
aAttribs.insert(aAttribs.end(), RES_TXTATR_CHARFMT);
ResetAttr(aAttribs, &aPaM);
SetAttrSet(aCharAttrSet, SetAttrMode::DEFAULT, &aPaM);
}
if( bStarted )
{
EndUndo();
EndAllAction();
}
}
// Maximum height limit not possible, because the maximum height
// of the current frame can not be obtained.
void SwWrtShell::Insert( const OUString &rPath, const OUString &rFilter,
const Graphic &rGrf, SwFlyFrameAttrMgr *pFrameMgr,
RndStdIds nAnchorType )
{
ResetCursorStack();
if ( !CanInsert() )
return;
StartAllAction();
SwRewriter aRewriter;
aRewriter.AddRule(UndoArg1, SwResId(STR_GRAPHIC));
StartUndo(SwUndoId::INSERT, &aRewriter);
if ( HasSelection() )
DelRight();
// Inserted graphics in its own paragraph,
// if at the end of a non-empty paragraph.
//For i120928,avoid to split node
EnterSelFrameMode();
bool bSetGrfSize = true;
bool bOwnMgr = false;
if ( !pFrameMgr )
{
bOwnMgr = true;
pFrameMgr = new SwFlyFrameAttrMgr( true, this, Frmmgr_Type::GRF );
// CAUTION
// GetAttrSet makes an adjustment
// While pasting is a SwFrameSize present
// because of the DEF-Framesize
// These must be removed explicitly for the optimal size.
pFrameMgr->DelAttr(RES_FRM_SIZE);
if (nAnchorType != RndStdIds::FLY_AT_PARA)
// Something other than at-para was requested.
pFrameMgr->SetAnchor(nAnchorType);
}
else
{
Size aSz( pFrameMgr->GetSize() );
if ( !aSz.Width() || !aSz.Height() )
{
aSz.setWidth(567);
aSz.setHeight( 567);
pFrameMgr->SetSize( aSz );
}
else if ( aSz.Width() != DFLT_WIDTH && aSz.Height() != DFLT_HEIGHT )
bSetGrfSize = false;
pFrameMgr->SetHeightSizeType(SwFrameSize::Fixed);
}
// Insert the graphic
SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrameMgr->GetAttrSet());
if ( bOwnMgr )
pFrameMgr->UpdateAttrMgr();
if( bSetGrfSize )
{
Size aGrfSize, aBound = GetGraphicDefaultSize();
GetGrfSize( aGrfSize );
// Add the margin attributes to GrfSize,
// because these counts at the margin additionally
aGrfSize.AdjustWidth(pFrameMgr->CalcWidthBorder() );
aGrfSize.AdjustHeight(pFrameMgr->CalcHeightBorder() );
const BigInt aTempWidth( aGrfSize.Width() );
const BigInt aTempHeight( aGrfSize.Height());
// Fit width if necessary, scale down the height proportional thereafter.
if( aGrfSize.Width() > aBound.Width() )
{
aGrfSize.setWidth( aBound.Width() );
aGrfSize.setHeight( BigInt(aBound.Width()) * aTempHeight / aTempWidth );
}
// Fit height if necessary, scale down the width proportional thereafter.
if( aGrfSize.Height() > aBound.Height() )
{
aGrfSize.setHeight( aBound.Height() );
aGrfSize.setWidth( BigInt(aBound.Height()) * aTempWidth / aTempHeight );
}
pFrameMgr->SetSize( aGrfSize );
pFrameMgr->UpdateFlyFrame();
}
if ( bOwnMgr )
delete pFrameMgr;
EndUndo();
EndAllAction();
}
// Insert an OLE-Object into the CORE.
// if no object is transferred, then one will be created.
void SwWrtShell::InsertObject( const svt::EmbeddedObjectRef& xRef, SvGlobalName const *pName,
sal_uInt16 nSlotId )
{
ResetCursorStack();
if( !CanInsert() )
return;
if( !xRef.is() )
{
// temporary storage
svt::EmbeddedObjectRef xObj;
uno::Reference < embed::XStorage > xStor = comphelper::OStorageHelper::GetTemporaryStorage();
bool bDoVerb = true;
if ( pName )
{
comphelper::EmbeddedObjectContainer aCnt( xStor );
OUString aName;
// TODO/LATER: get aspect?
xObj.Assign( aCnt.CreateEmbeddedObject( pName->GetByteSequence(), aName ), embed::Aspects::MSOLE_CONTENT );
}
else
{
SvObjectServerList aServerList;
switch (nSlotId)
{
case SID_INSERT_OBJECT:
{
aServerList.FillInsertObjects();
aServerList.Remove( SwDocShell::Factory().GetClassId() );
[[fallthrough]];
}
// TODO/LATER: recording! Convert properties to items
case SID_INSERT_FLOATINGFRAME:
{
SfxSlotPool* pSlotPool = SW_MOD()->GetSlotPool();
const SfxSlot* pSlot = pSlotPool->GetSlot(nSlotId);
OString aCmd = OStringLiteral(".uno:") + pSlot->GetUnoName();
SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
ScopedVclPtr<SfxAbstractInsertObjectDialog> pDlg(pFact->CreateInsertObjectDialog(GetFrameWeld(mxDoc->GetDocShell()),
OUString::fromUtf8( aCmd ), xStor, &aServerList));
if (pDlg)
{
pDlg->Execute();
bDoVerb = pDlg->IsCreateNew();
OUString aIconMediaType;
uno::Reference< io::XInputStream > xIconMetaFile = pDlg->GetIconIfIconified( &aIconMediaType );
xObj.Assign( pDlg->GetObject(),
xIconMetaFile.is() ? embed::Aspects::MSOLE_ICON : embed::Aspects::MSOLE_CONTENT );
if ( xIconMetaFile.is() )
xObj.SetGraphicStream( xIconMetaFile, aIconMediaType );
}
break;
}
default:
break;
}
}
if ( xObj.is() )
{
if( InsertOleObject( xObj ) && bDoVerb )
{
SfxInPlaceClient* pClient = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
if ( !pClient )
{
pClient = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
SetCheckForOLEInCaption( true );
}
if ( xObj.GetViewAspect() == embed::Aspects::MSOLE_ICON )
{
SwRect aArea = GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, xObj.GetObject() );
aArea.Pos() += GetAnyCurRect( CurRectType::FlyEmbedded, nullptr, xObj.GetObject() ).Pos();
MapMode aMapMode( MapUnit::MapTwip );
Size aSize = xObj.GetSize( &aMapMode );
aArea.Width( aSize.Width() );
aArea.Height( aSize.Height() );
RequestObjectResize( aArea, xObj.GetObject() );
}
else
CalcAndSetScale( xObj );
//#50270# We don't need to handle error, this is handled by the
//DoVerb in the SfxViewShell
pClient->DoVerb(embed::EmbedVerbs::MS_OLEVERB_SHOW);
// TODO/LATER: set document name - should be done in Client
}
}
}
else
{
if( HasSelection() )
DelRight();
InsertOleObject( xRef );
}
}
// Insert object into the Core.
// From ClipBoard or Insert
bool SwWrtShell::InsertOleObject( const svt::EmbeddedObjectRef& xRef, SwFlyFrameFormat **pFlyFrameFormat )
{
//tdf#125100 Ensure that ole object is initially shown as pictogram
comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = mxDoc->GetDocShell()->getEmbeddedObjectContainer();
bool bSaveUserAllowsLinkUpdate = rEmbeddedObjectContainer.getUserAllowsLinkUpdate();
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true);
ResetCursorStack();
StartAllAction();
StartUndo(SwUndoId::INSERT);
//Some differences between StarMath and any other objects:
//1. Selections should be deleted. For StarMath the Text should be
// passed to the Object
//2. If the cursor is at the end of a non empty paragraph a paragraph
// break should be inserted. StarMath objects are character bound and
// no break should be inserted.
//3. If an selection is passed to a StarMath object, this object should
// not be activated. false should be returned then.
bool bStarMath = true;
bool bActivate = true;
// set parent to get correct VisArea(in case of object needing parent printer)
uno::Reference < container::XChild > xChild( xRef.GetObject(), uno::UNO_QUERY );
if ( xChild.is() )
xChild->setParent( mxDoc->GetDocShell()->GetModel() );
SvGlobalName aCLSID( xRef->getClassID() );
bStarMath = ( SotExchange::IsMath( aCLSID ) != 0 );
if( IsSelection() )
{
if( bStarMath )
{
OUString aMathData;
GetSelectedText( aMathData, ParaBreakType::ToOnlyCR );
if( !aMathData.isEmpty() && svt::EmbeddedObjectRef::TryRunningState( xRef.GetObject() ) )
{
uno::Reference < beans::XPropertySet > xSet( xRef->getComponent(), uno::UNO_QUERY );
if ( xSet.is() )
{
try
{
xSet->setPropertyValue("Formula", uno::makeAny( aMathData ) );
bActivate = false;
}
catch (const uno::Exception&)
{
}
}
}
}
DelRight();
}
if ( !bStarMath )
SwFEShell::SplitNode( false, false );
EnterSelFrameMode();
SwFlyFrameAttrMgr aFrameMgr( true, this, Frmmgr_Type::OLE );
aFrameMgr.SetHeightSizeType(SwFrameSize::Fixed);
SwRect aBound;
CalcBoundRect( aBound, aFrameMgr.GetAnchor() );
//The Size should be suggested by the OLE server
MapMode aMapMode( MapUnit::MapTwip );
Size aSz = xRef.GetSize( &aMapMode );
//Object size can be limited
if ( aSz.Width() > aBound.Width() )
{
//Always limit proportional.
aSz.setHeight( aSz.Height() * aBound.Width() / aSz.Width() );
aSz.setWidth( aBound.Width() );
}
aFrameMgr.SetSize( aSz );
SwFlyFrameFormat *pFormat = SwFEShell::InsertObject( xRef, &aFrameMgr.GetAttrSet() );
// --> #i972#
if ( bStarMath && mxDoc->getIDocumentSettingAccess().get( DocumentSettingId::MATH_BASELINE_ALIGNMENT ) )
AlignFormulaToBaseline( xRef.GetObject() );
if (pFlyFrameFormat)
*pFlyFrameFormat = pFormat;
if ( SotExchange::IsChart( aCLSID ) )
{
uno::Reference< embed::XEmbeddedObject > xEmbeddedObj = xRef.GetObject();
if ( xEmbeddedObj.is() )
{
bool bDisableDataTableDialog = false;<--- Assignment 'bDisableDataTableDialog=false', assigned value is 0
svt::EmbeddedObjectRef::TryRunningState( xEmbeddedObj );
uno::Reference< beans::XPropertySet > xProps( xEmbeddedObj->getComponent(), uno::UNO_QUERY );
if ( xProps.is() &&
( xProps->getPropertyValue("DisableDataTableDialog") >>= bDisableDataTableDialog ) &&
bDisableDataTableDialog )<--- Condition 'bDisableDataTableDialog' is always false
{
xProps->setPropertyValue("DisableDataTableDialog",
uno::makeAny( false ) );
xProps->setPropertyValue("DisableComplexChartTypes",
uno::makeAny( false ) );
uno::Reference< util::XModifiable > xModifiable( xProps, uno::UNO_QUERY );
if ( xModifiable.is() )
{
xModifiable->setModified( true );
}
}
}
}
EndAllAction();
GetView().AutoCaption(OLE_CAP, &aCLSID);
SwRewriter aRewriter;
if ( bStarMath )
aRewriter.AddRule(UndoArg1, SwResId(STR_MATH_FORMULA));
else if ( SotExchange::IsChart( aCLSID ) )
aRewriter.AddRule(UndoArg1, SwResId(STR_CHART));
else
aRewriter.AddRule(UndoArg1, SwResId(STR_OLE));
EndUndo(SwUndoId::INSERT, &aRewriter);
rEmbeddedObjectContainer.setUserAllowsLinkUpdate(bSaveUserAllowsLinkUpdate);
return bActivate;
}
// The current selected OLE object will be loaded with the
// verb into the server.
void SwWrtShell::LaunchOLEObj( long nVerb )
{
if ( GetCntType() == CNT_OLE &&
!GetView().GetViewFrame()->GetFrame().IsInPlace() )
{
svt::EmbeddedObjectRef& xRef = GetOLEObject();
OSL_ENSURE( xRef.is(), "OLE not found" );
// LOK: we don't want to handle any other embedded objects than
// charts, there are too many problems with eg. embedded spreadsheets
// (like it creates a separate view for the calc sheet)
if (comphelper::LibreOfficeKit::isActive() && !SotExchange::IsChart(xRef->getClassID()))
return;
SfxInPlaceClient* pCli = GetView().FindIPClient( xRef.GetObject(), &GetView().GetEditWin() );
if ( !pCli )
pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xRef );
static_cast<SwOleClient*>(pCli)->SetInDoVerb( true );
CalcAndSetScale( xRef );
pCli->DoVerb( nVerb );
static_cast<SwOleClient*>(pCli)->SetInDoVerb( false );
CalcAndSetScale( xRef );
}
}
void SwWrtShell::MoveObjectIfActive( svt::EmbeddedObjectRef& xObj, const Point& rOffset )
{
try
{
sal_Int32 nState = xObj->getCurrentState();
if ( nState == css::embed::EmbedStates::INPLACE_ACTIVE
|| nState == css::embed::EmbedStates::UI_ACTIVE )
{
SfxInPlaceClient* pCli =
GetView().FindIPClient( xObj.GetObject(), &(GetView().GetEditWin()) );
if ( pCli )
{
tools::Rectangle aArea = pCli->GetObjArea();
aArea += rOffset;
pCli->SetObjArea( aArea );
}
}
}
catch (const uno::Exception&)
{
}
}
void SwWrtShell::CalcAndSetScale( svt::EmbeddedObjectRef& xObj,
const SwRect *pFlyPrtRect,
const SwRect *pFlyFrameRect,
const bool bNoTextFramePrtAreaChanged )
{
// Setting the scale of the client. This arises from the difference
// between the VisArea of the object and the ObjArea.
OSL_ENSURE( xObj.is(), "ObjectRef not valid" );
sal_Int64 nAspect = xObj.GetViewAspect();
if ( nAspect == embed::Aspects::MSOLE_ICON )
return; // the replacement image is completely controlled by container in this case
sal_Int64 nMisc = 0;
bool bLinkingChart = false;
try
{
nMisc = xObj->getStatus( nAspect );
// This can surely only be a non-active object, if desired they
// get the new size set as VisArea (StarChart).
if( embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE & nMisc )
{
// TODO/MBA: testing
SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
: GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, xObj.GetObject() ));
if( !aRect.IsEmpty() )
{
// TODO/LEAN: getMapUnit can switch object to running state
// xObj.TryRunningState();
MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
// TODO/LATER: needs complete VisArea?!
Size aSize( OutputDevice::LogicToLogic(aRect.SVRect(), MapMode(MapUnit::MapTwip), MapMode(aUnit)).GetSize() );
awt::Size aSz;
aSz.Width = aSize.Width();
aSz.Height = aSize.Height();
// Action 'setVisualAreaSize' doesn't have to turn on the
// modified state of the document, either.
bool bModified = false;
uno::Reference<util::XModifiable> xModifiable(xObj->getComponent(), uno::UNO_QUERY);
if (xModifiable.is())
bModified = xModifiable->isModified();
xObj->setVisualAreaSize( nAspect, aSz );
xModifiable.set(xObj->getComponent(), uno::UNO_QUERY);
if (xModifiable.is() && xModifiable->isModified() && !bModified)
xModifiable->setModified(bModified);
// #i48419# - action 'UpdateReplacement' doesn't
// have to change the modified state of the document.
// This is only a workaround for the defect, that this action
// modifies a document after load, because unnecessarily the
// replacement graphic is updated, in spite of the fact that
// nothing has been changed.
// If the replacement graphic changes by this action, the document
// will be already modified via other mechanisms.
{
bool bResetEnableSetModified(false);
if ( GetDoc()->GetDocShell()->IsEnableSetModified() )
{
GetDoc()->GetDocShell()->EnableSetModified( false );
bResetEnableSetModified = true;
}
//#i79576# don't destroy chart replacement images on load
//#i79578# don't request a new replacement image for charts to often
//a chart sends a modified call to the framework if it was changed
//thus the replacement update is already handled elsewhere
if ( !SotExchange::IsChart( xObj->getClassID() ) )
xObj.UpdateReplacement();
if ( bResetEnableSetModified )
{
GetDoc()->GetDocShell()->EnableSetModified();
}
}
}
// TODO/LATER: this is only a workaround,
uno::Reference< chart2::XChartDocument > xChartDocument( xObj->getComponent(), uno::UNO_QUERY );
bLinkingChart = ( xChartDocument.is() && !xChartDocument->hasInternalDataProvider() );
}
}
catch (const uno::Exception&)
{
// TODO/LATER: handle the error
return;
}
SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin() );
if ( !pCli )
{
if ( (embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY & nMisc)
|| bLinkingChart
// --> OD #i117189# - refine condition for non-resizable objects
// non-resizable objects need to be set the size back by this method
|| ( bNoTextFramePrtAreaChanged && nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
{
pCli = new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
}
else
return;
}
// TODO/LEAN: getMapUnit can switch object to running state
// xObj.TryRunningState();
awt::Size aSize;
try
{
aSize = xObj->getVisualAreaSize( nAspect );
}
catch (const embed::NoVisualAreaSizeException&)
{
OSL_FAIL("Can't get visual area size!" );
// the scaling will not be done
}
catch (const uno::Exception&)
{
// TODO/LATER: handle the error
OSL_FAIL("Can't get visual area size!" );
return;
}
Size _aVisArea( aSize.Width, aSize.Height );
Fraction aScaleWidth( 1, 1 );
Fraction aScaleHeight( 1, 1 );
bool bUseObjectSize = false;
// As long as there comes no reasonable size from the object,
// nothing can be scaled.
if( _aVisArea.Width() && _aVisArea.Height() )
{
const MapMode aTmp( MapUnit::MapTwip );
MapUnit aUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
_aVisArea = OutputDevice::LogicToLogic(_aVisArea, MapMode(aUnit), aTmp);
Size aObjArea;
if ( pFlyPrtRect )
aObjArea = pFlyPrtRect->SSize();
else
aObjArea = GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, xObj.GetObject() ).SSize();
// differ the aObjArea and _aVisArea by 1 Pixel then set new VisArea
long nX, nY;
SwSelPaintRects::Get1PixelInLogic( *this, &nX, &nY );
if( !( _aVisArea.Width() - nX <= aObjArea.Width() &&
_aVisArea.Width() + nX >= aObjArea.Width() &&
_aVisArea.Height()- nY <= aObjArea.Height()&&
_aVisArea.Height()+ nY >= aObjArea.Height() ))
{
if ( nMisc & embed::EmbedMisc::EMBED_NEVERRESIZE )
{
// the object must not be scaled,
// the size stored in object must be used for restoring
bUseObjectSize = true;
}
else
{
aScaleWidth = Fraction( aObjArea.Width(), _aVisArea.Width() );
aScaleHeight = Fraction( aObjArea.Height(), _aVisArea.Height());
}
}
}
// Now is the favorable time to set the ObjArea.
// The Scaling must be considered.
SwRect aArea;
if ( pFlyPrtRect )
{
aArea = *pFlyPrtRect;
aArea += pFlyFrameRect->Pos();
}
else
{
aArea = GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, xObj.GetObject() );
aArea.Pos() += GetAnyCurRect( CurRectType::FlyEmbedded, nullptr, xObj.GetObject() ).Pos();
}
if ( bUseObjectSize )
{
// --> this moves non-resizable object so that when adding borders the baseline remains the same
const SwFlyFrameFormat *pFlyFrameFormat = dynamic_cast< const SwFlyFrameFormat * >( GetFlyFrameFormat() );
OSL_ENSURE( pFlyFrameFormat, "Could not find fly frame." );
if ( pFlyFrameFormat )
{
const Point &rPoint = pFlyFrameFormat->GetLastFlyFramePrtRectPos();
SwRect aRect( pFlyPrtRect ? *pFlyPrtRect
: GetAnyCurRect( CurRectType::FlyEmbeddedPrt, nullptr, xObj.GetObject() ));
aArea += rPoint - aRect.Pos(); // adjust area by diff of printing area position in order to keep baseline alignment correct.
}
aArea.Width ( _aVisArea.Width() );
aArea.Height( _aVisArea.Height() );
RequestObjectResize( aArea, xObj.GetObject() );
}
else
{
aArea.Width ( long( aArea.Width() / pCli->GetScaleWidth() ) );
aArea.Height( long( aArea.Height() / pCli->GetScaleHeight() ) );
}
pCli->SetObjAreaAndScale( aArea.SVRect(), aScaleWidth, aScaleHeight );
}
void SwWrtShell::ConnectObj( svt::EmbeddedObjectRef& xObj, const SwRect &rPrt,
const SwRect &rFrame )
{
SfxInPlaceClient* pCli = GetView().FindIPClient( xObj.GetObject(), &GetView().GetEditWin());
if ( !pCli )
new SwOleClient( &GetView(), &GetView().GetEditWin(), xObj );
CalcAndSetScale( xObj, &rPrt, &rFrame );
}
// Insert hard page break;
// Selections will be overwritten
void SwWrtShell::InsertPageBreak(const OUString *pPageDesc, const ::std::optional<sal_uInt16>& oPgNum )
{
ResetCursorStack();
if( CanInsert() )
{
SwActContext aActContext(this);
StartUndo(SwUndoId::UI_INSERT_PAGE_BREAK);
if ( !IsCursorInTable() )
{
if(HasSelection())
DelRight();
SwFEShell::SplitNode();
// delete the numbered attribute of the last line if the last line is empty
GetDoc()->ClearLineNumAttrs( *GetCursor()->GetPoint() );
}
const SwPageDesc *pDesc = pPageDesc
? FindPageDescByName( *pPageDesc, true ) : nullptr;
if( pDesc )
{
SwFormatPageDesc aDesc( pDesc );
aDesc.SetNumOffset( oPgNum );
SetAttrItem( aDesc );
}
else
SetAttrItem( SvxFormatBreakItem(SvxBreak::PageBefore, RES_BREAK) );
EndUndo(SwUndoId::UI_INSERT_PAGE_BREAK);
}
collectUIInformation("BREAK_PAGE", "parameter");
}
// Insert hard page break;
// Selections will be overwritten
void SwWrtShell::InsertLineBreak()
{
ResetCursorStack();
if( CanInsert() )
{
if(HasSelection())
DelRight();
const sal_Unicode cIns = 0x0A;
SvxAutoCorrect* pACorr = lcl_IsAutoCorr();
if( pACorr )
AutoCorrect( *pACorr, cIns );
else
SwWrtShell::Insert( OUString( cIns ) );
}
}
// Insert hard column break;
// Selections will be overwritten
void SwWrtShell::InsertColumnBreak()
{
SwActContext aActContext(this);
ResetCursorStack();
if( CanInsert() )
{
StartUndo(SwUndoId::UI_INSERT_COLUMN_BREAK);
if ( !IsCursorInTable() )
{
if(HasSelection())
DelRight();
SwFEShell::SplitNode( false, false );
}
SetAttrItem(SvxFormatBreakItem(SvxBreak::ColumnBefore, RES_BREAK));
EndUndo(SwUndoId::UI_INSERT_COLUMN_BREAK);
}
}
// Insert footnote
// rStr - optional footnote mark
void SwWrtShell::InsertFootnote(const OUString &rStr, bool bEndNote, bool bEdit )
{
ResetCursorStack();
if( CanInsert() )
{
if(HasSelection())
{
//collapse cursor to the end
if(!IsCursorPtAtEnd())
SwapPam();
ClearMark();
}
SwPosition aPos = *GetCursor()->GetPoint();
SwFormatFootnote aFootNote( bEndNote );
if(!rStr.isEmpty())
aFootNote.SetNumStr( rStr );
SetAttrItem(aFootNote);
if( bEdit )
{
// For editing the footnote text.
Left(CRSR_SKIP_CHARS, false, 1, false );
GotoFootnoteText();
}
m_aNavigationMgr.addEntry(aPos);
}
}
// SplitNode; also, because
// - of deleting selected content;
// - of reset of the Cursorstack if necessary.
void SwWrtShell::SplitNode( bool bAutoFormat )
{
ResetCursorStack();
if( CanInsert() )
{
SwActContext aActContext(this);
m_rView.GetEditWin().FlushInBuffer();
bool bHasSel = HasSelection();
if( bHasSel )
{
StartUndo( SwUndoId::INSERT );
DelRight();
}
SwFEShell::SplitNode( bAutoFormat );
if( bHasSel )
EndUndo( SwUndoId::INSERT );
}
}
// Turn on numbering
// Parameter: Optional specification of a name for the named list;
// this indicates a position if it is possible to convert them
// into a number and less than nMaxRules.
// To test the CharFormats at the numbering
// external void SetNumChrFormat( SwWrtShell*, SwNumRules& );
// -> #i40041#
// Preconditions (as far as OD has figured out):
// - <SwEditShell::HasNumber()> is false, if <bNum> is true
// - <SwEditShell::HasBullet()> is false, if <bNum> is false
// Behavior of method is determined by the current situation at the current
// cursor position in the document.
void SwWrtShell::NumOrBulletOn(bool bNum)
{
// determine numbering rule found at current cursor position in the document.
const SwNumRule* pCurRule = GetNumRuleAtCurrCursorPos();
StartUndo(SwUndoId::NUMORNONUM);
const SwNumRule * pNumRule = pCurRule;
// - activate outline rule respectively turning on outline rule for
// current text node. But, only for turning on a numbering (<bNum> == true).
// - overwrite found numbering rule at current cursor position, if
// no numbering rule can be retrieved from the paragraph style.
bool bContinueFoundNumRule( false );
bool bActivateOutlineRule( false );
int nActivateOutlineLvl( MAXLEVEL ); // only relevant, if <bActivateOutlineRule> == true
SwTextFormatColl * pColl = GetCurTextFormatColl();
if ( pColl )
{
// retrieve numbering rule at paragraph
// style, which is found at current cursor position in the document.
SwNumRule* pCollRule = mxDoc->FindNumRulePtr(pColl->GetNumRule().GetValue());
// #125993# - The outline numbering rule isn't allowed
// to be derived from a parent paragraph style to a derived one.
// Thus check, if the found outline numbering rule is directly
// set at the paragraph style <pColl>. If not, set <pCollRule> to NULL
if ( pCollRule && pCollRule == GetDoc()->GetOutlineNumRule() )
{
const SwNumRule* pDirectCollRule =
mxDoc->FindNumRulePtr(pColl->GetNumRule( false ).GetValue());
if ( !pDirectCollRule )
{
pCollRule = nullptr;
}
}
if ( !pCollRule )
{
pNumRule = pCollRule;
}
// no activation or continuation of outline numbering in Writer/Web document
else if ( bNum &&
!dynamic_cast<SwWebDocShell*>(GetDoc()->GetDocShell()) &&
pCollRule == GetDoc()->GetOutlineNumRule() )
{
if ( pNumRule == pCollRule )
{
// check, if text node at current cursor positioned is counted.
// If not, let it been counted. Then it has to be checked,
// of the outline numbering has to be activated or continued.
SwTextNode const*const pTextNode = sw::GetParaPropsNode(
*GetLayout(), GetCursor()->GetPoint()->nNode);
if ( pTextNode && !pTextNode->IsCountedInList() )
{
// check, if numbering of the outline level of the paragraph
// style is active. If not, activate this outline level.
nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
OSL_ENSURE( pColl->IsAssignedToListLevelOfOutlineStyle(),
"<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&
pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
== SVX_NUM_NUMBER_NONE )
{
// activate outline numbering
bActivateOutlineRule = true;
}
else
{
// turning on outline numbering at current cursor position
bContinueFoundNumRule = true;
}
}
else
{
// #i101234#
// activate outline numbering, because from the precondition
// it's known, that <SwEdit::HasNumber()> == false
bActivateOutlineRule = true;
nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
}
}
else if ( !pNumRule )
{
// #i101234#
// Check, if corresponding list level of the outline numbering
// has already a numbering format set.
nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
if ( pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
== SVX_NUM_NUMBER_NONE )
{
// activate outline numbering, because from the precondition
// it's known, that <SwEdit::HasNumber()> == false
bActivateOutlineRule = true;
}
else
{
// turning on outline numbering at current cursor position
bContinueFoundNumRule = true;
}
}
else
{
// check, if numbering of the outline level of the paragraph
// style is active. If not, activate this outline level.
nActivateOutlineLvl = pColl->GetAssignedOutlineStyleLevel();
OSL_ENSURE( pColl->IsAssignedToListLevelOfOutlineStyle(),
"<SwWrtShell::NumOrBulletOn(..)> - paragraph style with outline rule, but no outline level" );
if ( pColl->IsAssignedToListLevelOfOutlineStyle() &&
pCollRule->Get( static_cast<sal_uInt16>(nActivateOutlineLvl) ).GetNumberingType()
== SVX_NUM_NUMBER_NONE )
{
// activate outline numbering
bActivateOutlineRule = true;
}
else
{
// turning on outline numbering at current cursor position
bContinueFoundNumRule = true;
}
}
pNumRule = pCollRule;
}
}
// Only automatic numbering/bullet rules should be changed.
// Note: The outline numbering rule is also an automatic one. It's only
// changed, if it has to be activated.
if ( pNumRule )
{
if ( !pNumRule->IsAutoRule() )
{
pNumRule = nullptr;
}
else if ( pNumRule == GetDoc()->GetOutlineNumRule() &&
!bActivateOutlineRule && !bContinueFoundNumRule )
{
pNumRule = nullptr;
}
}
// Search for a previous numbering/bullet rule to continue it.
OUString sContinuedListId;
if ( !pNumRule )
{
pNumRule = GetDoc()->SearchNumRule( *GetCursor()->GetPoint(),
false, bNum, false, 0,
sContinuedListId, GetLayout() );
bContinueFoundNumRule = pNumRule != nullptr;
}
if (pNumRule)
{
SwNumRule aNumRule(*pNumRule);
// do not change found numbering/bullet rule, if it should only be continued.
if ( !bContinueFoundNumRule )
{
SwTextNode const*const pTextNode = sw::GetParaPropsNode(
*GetLayout(), GetCursor()->GetPoint()->nNode);
if (pTextNode)
{
// use above retrieve outline level, if outline numbering has to be activated.
int nLevel = bActivateOutlineRule
? nActivateOutlineLvl
: pTextNode->GetActualListLevel();
if (nLevel < 0)
nLevel = 0;
if (nLevel >= MAXLEVEL)
nLevel = MAXLEVEL - 1;
SwNumFormat aFormat(aNumRule.Get(static_cast<sal_uInt16>(nLevel)));
if (bNum)
aFormat.SetNumberingType(SVX_NUM_ARABIC);
else
{
// #i63395# Only apply user defined default bullet font
if ( numfunc::IsDefBulletFontUserDefined() )
{
const vcl::Font* pFnt = &numfunc::GetDefBulletFont();
aFormat.SetBulletFont( pFnt );
}
aFormat.SetBulletChar( numfunc::GetBulletChar(static_cast<sal_uInt8>(nLevel)));
aFormat.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
// #i93908# clear suffix for bullet lists
aFormat.SetPrefix(OUString());
aFormat.SetSuffix(OUString());
}
aNumRule.Set(static_cast<sal_uInt16>(nLevel), aFormat);
}
}
// reset indent attribute on applying list style
SetCurNumRule( aNumRule, false, sContinuedListId, true );
}
else
{
// #i95907#
const SvxNumberFormat::SvxNumPositionAndSpaceMode ePosAndSpaceMode(
numfunc::GetDefaultPositionAndSpaceMode() );
SwNumRule aNumRule( GetUniqueNumRuleName(), ePosAndSpaceMode );
// Append the character template at the numbering.
SwCharFormat* pChrFormat;
SwDocShell* pDocSh = GetView().GetDocShell();
// #i63395#
// Only apply user defined default bullet font
const vcl::Font* pFnt = numfunc::IsDefBulletFontUserDefined()
? &numfunc::GetDefBulletFont()
: nullptr;
if (bNum)
{
pChrFormat = GetCharFormatFromPool( RES_POOLCHR_NUM_LEVEL );
}
else
{
pChrFormat = GetCharFormatFromPool( RES_POOLCHR_BULLET_LEVEL );
}
const SwTextNode *const pTextNode = sw::GetParaPropsNode(*GetLayout(),
GetCursor()->GetPoint()->nNode);
const SwTwips nWidthOfTabs = pTextNode
? pTextNode->GetWidthOfLeadingTabs()
: 0;
GetDoc()->getIDocumentContentOperations().RemoveLeadingWhiteSpace( *GetCursor()->GetPoint() );
const bool bHtml = dynamic_cast<SwWebDocShell*>( pDocSh ) != nullptr;
const bool bRightToLeft = IsInRightToLeftText();
for( sal_uInt8 nLvl = 0; nLvl < MAXLEVEL; ++nLvl )
{
SwNumFormat aFormat( aNumRule.Get( nLvl ) );
aFormat.SetCharFormat( pChrFormat );
if (! bNum)
{
// #i63395#
// Only apply user defined default bullet font
if ( pFnt )
{
aFormat.SetBulletFont( pFnt );
}
aFormat.SetBulletChar( numfunc::GetBulletChar(nLvl) );
aFormat.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
// #i93908# clear suffix for bullet lists
aFormat.SetPrefix(OUString());
aFormat.SetSuffix(OUString());
}
// #i95907#
if ( ePosAndSpaceMode == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{
if(bHtml && nLvl)
{
// 1/2" for HTML
aFormat.SetAbsLSpace(nLvl * 720);
}
else if ( nWidthOfTabs > 0 )
{
aFormat.SetAbsLSpace(nWidthOfTabs + nLvl * 720);
}
}
// #i38904# Default alignment for
// numbering/bullet should be rtl in rtl paragraph:
if ( bRightToLeft )
{
aFormat.SetNumAdjust( SvxAdjust::Right );
}
aNumRule.Set( nLvl, aFormat );
}
// #i95907#
if ( pTextNode &&
ePosAndSpaceMode == SvxNumberFormat::LABEL_ALIGNMENT )
{
const SwTwips nTextNodeIndent = pTextNode->GetAdditionalIndentForStartingNewList();
if ( ( nTextNodeIndent + nWidthOfTabs ) != 0 )
{
// #i111172#/fdo#85666
// If text node is already inside a list, assure that the indents
// are the same. Thus, adjust the indent change value by subtracting
// indents of to be applied list style.
SwTwips nIndentChange = nTextNodeIndent + nWidthOfTabs;
if ( pTextNode->GetNumRule() )
{
int nLevel = pTextNode->GetActualListLevel();
if (nLevel < 0)
nLevel = 0;
if (nLevel >= MAXLEVEL)
nLevel = MAXLEVEL - 1;
const SwNumFormat& aFormat( aNumRule.Get( nLevel ) );
if ( aFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
{
nIndentChange -= aFormat.GetIndentAt() + aFormat.GetFirstLineIndent();
}
}
aNumRule.ChangeIndent( nIndentChange );
}
}
// reset indent attribute on applying list style
// start new list
SetCurNumRule( aNumRule, true, OUString(), true );
}
EndUndo(SwUndoId::NUMORNONUM);
}
// <- #i40041#
void SwWrtShell::NumOn()
{
NumOrBulletOn(true);
}
void SwWrtShell::NumOrBulletOff()
{
const SwNumRule * pCurNumRule = GetNumRuleAtCurrCursorPos();
if (pCurNumRule)
{
if (pCurNumRule->IsOutlineRule())
{
SwNumRule aNumRule(*pCurNumRule);<--- The scope of the variable 'aNumRule' can be reduced. [+]The scope of the variable 'aNumRule' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
SwTextNode * pTextNode =
sw::GetParaPropsNode(*GetLayout(), GetCursor()->GetPoint()->nNode);
if (pTextNode)
{
int nLevel = pTextNode->GetActualListLevel();
if (nLevel < 0)
nLevel = 0;
if (nLevel >= MAXLEVEL)
nLevel = MAXLEVEL - 1;
SwNumFormat aFormat(aNumRule.Get(static_cast<sal_uInt16>(nLevel)));
aFormat.SetNumberingType(SVX_NUM_NUMBER_NONE);
aNumRule.Set(nLevel, aFormat);
// no start or continuation of a list - the outline style is only changed.
SetCurNumRule( aNumRule, false );
}
}
else
{
DelNumRules();
}
// #126346# - Cursor can not be anymore in front of
// a label, because numbering/bullet is switched off.
SetInFrontOfLabel( false );
}
}
// <- #i29560#
// Request Default-Bulletlist
void SwWrtShell::BulletOn()
{
NumOrBulletOn(false);
}
SelectionType SwWrtShell::GetSelectionType() const
{
// ContentType cannot be determined within a Start-/EndAction.
// Because there is no invalid value TEXT will be returned.
// The value does not matter, it may be updated in EndAction anyway.
if (ActionPend())
return IsSelFrameMode() ? SelectionType::Frame : SelectionType::Text;
SwView &_rView = const_cast<SwView&>(GetView());
if (_rView.GetPostItMgr() && _rView.GetPostItMgr()->HasActiveSidebarWin() )
return SelectionType::PostIt;
// Inserting a frame is not a DrawMode
SelectionType nCnt;
if ( !_rView.GetEditWin().IsFrameAction() &&
(IsObjSelected() || (_rView.IsDrawMode() && !IsFrameSelected()) ))
{
if (GetDrawView()->IsTextEdit())
nCnt = SelectionType::DrawObjectEditMode;
else
{
if (GetView().IsFormMode()) // Only Form selected
nCnt = SelectionType::DbForm;
else
nCnt = SelectionType::DrawObject; // Any draw object
if (_rView.IsBezierEditMode())
nCnt |= SelectionType::Ornament;
else if( GetDrawView()->GetContext() == SdrViewContext::Media )
nCnt |= SelectionType::Media;
if (svx::checkForSelectedCustomShapes( GetDrawView(), true /* bOnlyExtruded */ ))
{
nCnt |= SelectionType::ExtrudedCustomShape;
}
sal_uInt32 nCheckStatus = 0;
if (svx::checkForSelectedFontWork( GetDrawView(), nCheckStatus ))
{
nCnt |= SelectionType::FontWork;
}
}
return nCnt;
}
nCnt = static_cast<SelectionType>(GetCntType());
if ( IsFrameSelected() )
{
if (_rView.IsDrawMode())
_rView.LeaveDrawCreate(); // clean up (Bug #45639)
if ( !(nCnt & (SelectionType::Graphic | SelectionType::Ole)) )
return SelectionType::Frame;
}
if ( IsCursorInTable() )
nCnt |= SelectionType::Table;
if ( IsTableMode() )
{
nCnt |= SelectionType::Table | SelectionType::TableCell;
SwTable::SearchType eTableSel = GetEnhancedTableSelection();
if ( eTableSel == SwTable::SEARCH_ROW )
nCnt |= SelectionType::TableRow;
else if ( eTableSel == SwTable::SEARCH_COL )
nCnt |= SelectionType::TableCol;
}
// Do not pop up numbering toolbar, if the text node has a numbering of type SVX_NUM_NUMBER_NONE.
const SwNumRule* pNumRule = GetNumRuleAtCurrCursorPos();
if ( pNumRule )
{
const SwTextNode* pTextNd =
sw::GetParaPropsNode(*GetLayout(), GetCursor()->GetPoint()->nNode);
if ( pTextNd && pTextNd->IsInList() )
{
int nLevel = pTextNd->GetActualListLevel();
if (nLevel < 0)
nLevel = 0;
if (nLevel >= MAXLEVEL)
nLevel = MAXLEVEL - 1;
const SwNumFormat& rFormat = pNumRule->Get(nLevel);
if ( SVX_NUM_NUMBER_NONE != rFormat.GetNumberingType() )
nCnt |= SelectionType::NumberList;
}
}
return nCnt;
}
// Find the text collection with the name rCollname
// Returns: Pointer at the collection or 0, if no
// text collection with this name exists, or
// this is a default template.
SwTextFormatColl *SwWrtShell::GetParaStyle(const OUString &rCollName, GetStyle eCreate )
{
SwTextFormatColl* pColl = FindTextFormatCollByName( rCollName );
if( !pColl && GETSTYLE_NOCREATE != eCreate )
{
sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, SwGetPoolIdFromName::TxtColl );
if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
pColl = GetTextCollFromPool( nId );
}
return pColl;
}
// Find the text collection with the name rCollname
// Returns: Pointer at the collection or 0, if no
// character template with this name exists, or
// this is a default template or template is automatic.
SwCharFormat *SwWrtShell::GetCharStyle(const OUString &rFormatName, GetStyle eCreate )
{
SwCharFormat* pFormat = FindCharFormatByName( rFormatName );
if( !pFormat && GETSTYLE_NOCREATE != eCreate )
{
sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rFormatName, SwGetPoolIdFromName::ChrFmt );
if( USHRT_MAX != nId || GETSTYLE_CREATEANY == eCreate )
pFormat = static_cast<SwCharFormat*>(GetFormatFromPool( nId ));
}
return pFormat;
}
// Find the table format with the name rFormatname
// Returns: Pointer at the collection or 0, if no
// frame format with this name exists or
// this is a default format or the format is automatic.
SwFrameFormat *SwWrtShell::GetTableStyle(const OUString &rFormatName)
{
for( size_t i = GetTableFrameFormatCount(); i; )
{
SwFrameFormat *pFormat = &GetTableFrameFormat( --i );
if( !pFormat->IsDefault() &&
pFormat->GetName() == rFormatName && IsUsed( *pFormat ) )
return pFormat;
}
return nullptr;
}
void SwWrtShell::addCurrentPosition() {
SwPaM* pPaM = GetCursor();
m_aNavigationMgr.addEntry(*pPaM->GetPoint());
}
// Applying templates
void SwWrtShell::SetPageStyle(const OUString &rCollName)
{
if( !SwCursorShell::HasSelection() && !IsSelFrameMode() && !IsObjSelected() )
{
SwPageDesc* pDesc = FindPageDescByName( rCollName, true );
if( pDesc )
ChgCurPageDesc( *pDesc );
}
}
// Access templates
OUString const & SwWrtShell::GetCurPageStyle() const
{
return GetPageDesc(GetCurPageDesc( false/*bCalcFrame*/ )).GetName();
}
// Change the current template referring to the existing change.
void SwWrtShell::QuickUpdateStyle()
{
SwTextFormatColl *pColl = GetCurTextFormatColl();
// Default cannot be changed
if(pColl && !pColl->IsDefault())
{
FillByEx(pColl);
// Also apply the template to remove hard attribute assignment.
SetTextFormatColl(pColl);
}
}
void SwWrtShell::AutoUpdatePara(SwTextFormatColl* pColl, const SfxItemSet& rStyleSet, SwPaM* pPaM )
{
SwPaM* pCursor = pPaM ? pPaM : GetCursor( );
SfxItemSet aCoreSet(
GetAttrPool(),
svl::Items<
RES_CHRATR_BEGIN, RES_CHRATR_END - 1,
RES_PARATR_BEGIN, RES_PARATR_END - 1,
RES_FRMATR_BEGIN, RES_FRMATR_END - 1,
SID_ATTR_TABSTOP_DEFAULTS,SID_ATTR_TABSTOP_OFFSET,
SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER,
SID_ATTR_PARA_MODEL, SID_ATTR_PARA_KEEP,
SID_ATTR_PARA_PAGENUM, SID_ATTR_PARA_PAGENUM>{});
GetPaMAttr( pCursor, aCoreSet );
bool bReset = false;
SfxItemIter aParaIter( aCoreSet );
for (auto pParaItem = aParaIter.GetCurItem(); pParaItem; pParaItem = aParaIter.NextItem())
{
if(!IsInvalidItem(pParaItem))
{
sal_uInt16 nWhich = pParaItem->Which();
if(SfxItemState::SET == aCoreSet.GetItemState(nWhich) &&
SfxItemState::SET == rStyleSet.GetItemState(nWhich))
{
aCoreSet.ClearItem(nWhich);
bReset = true;
}
}
}
StartAction();
if(bReset)
{
ResetAttr( std::set<sal_uInt16>(), pCursor );
SetAttrSet(aCoreSet, SetAttrMode::DEFAULT, pCursor);
}
mxDoc->ChgFormat(*pColl, rStyleSet );
EndAction();
}
void SwWrtShell::AutoUpdateFrame( SwFrameFormat* pFormat, const SfxItemSet& rStyleSet )
{
StartAction();
ResetFlyFrameAttr( &rStyleSet );
pFormat->SetFormatAttr( rStyleSet );
EndAction();
}
void SwWrtShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Unicode cChar )
{
ResetCursorStack();
if(CanInsert())
{
bool bStarted = false;
SwRewriter aRewriter;
if(HasSelection())
{
// Only parentheses here, because the regular insert
// is already clipped to the editshell
StartAllAction();
OUString aTmpStr1 = SwResId(STR_START_QUOTE) +
GetSelText() +
SwResId(STR_END_QUOTE);
OUString aTmpStr3 = SwResId(STR_START_QUOTE) +
OUStringChar(cChar) +
SwResId(STR_END_QUOTE);
aRewriter.AddRule( UndoArg1, aTmpStr1 );
aRewriter.AddRule( UndoArg2, SwResId(STR_YIELDS) );
aRewriter.AddRule( UndoArg3, aTmpStr3 );
StartUndo( SwUndoId::REPLACE, &aRewriter );
bStarted = true;
DelRight();
}
SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar );
if(bStarted)
{
EndAllAction();
EndUndo( SwUndoId::REPLACE, &aRewriter );
}
}
}
// Some kind of controlled copy ctor
SwWrtShell::SwWrtShell( SwWrtShell& rSh, vcl::Window *_pWin, SwView &rShell )
: SwFEShell(rSh, _pWin)
, m_rView(rShell)
, m_aNavigationMgr(*this)
{
BITFLD_INI_LIST
SET_CURR_SHELL( this );
SetSfxViewShell( static_cast<SfxViewShell *>(&rShell) );
SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
// place the cursor on the first field...
IFieldmark *pBM = nullptr;
if ( IsFormProtected() && ( pBM = GetFieldmarkAfter( ) ) !=nullptr ) {
GotoFieldmark(pBM);
}
}
SwWrtShell::SwWrtShell( SwDoc& rDoc, vcl::Window *_pWin, SwView &rShell,
const SwViewOption *pViewOpt )
: SwFEShell(rDoc, _pWin, pViewOpt)
, m_rView(rShell)
, m_aNavigationMgr(*this)
{
BITFLD_INI_LIST
SET_CURR_SHELL( this );
SetSfxViewShell( static_cast<SfxViewShell *>(&rShell) );
SetFlyMacroLnk( LINK(this, SwWrtShell, ExecFlyMac) );
// place the cursor on the first field...
IFieldmark *pBM = nullptr;
if ( IsFormProtected() && ( pBM = GetFieldmarkAfter( ) ) !=nullptr ) {
GotoFieldmark(pBM);
}
}
SwWrtShell::~SwWrtShell()
{
SET_CURR_SHELL( this );
while(IsModePushed())
PopMode();
while(PopCursor(false))
;
SwTransferable::ClearSelection( *this );
}
bool SwWrtShell::Pop(SwCursorShell::PopMode const eDelete)
{
bool bRet = SwCursorShell::Pop(eDelete);
if( bRet && IsSelection() )
{
m_fnSetCursor = &SwWrtShell::SetCursorKillSel;
m_fnKillSel = &SwWrtShell::ResetSelect;
}
return bRet;
}
bool SwWrtShell::CanInsert()
{
if(IsSelFrameMode())
{
return false;
}
if(IsObjSelected())
{
return false;
}
if(GetView().GetDrawFuncPtr())
{
return false;
}
if(GetView().GetPostItMgr()->GetActiveSidebarWin())
{
return false;
}
return true;
}
void SwWrtShell::ChgDBData(const SwDBData& aDBData)
{
SwEditShell::ChgDBData(aDBData);
//notify the db-beamer if available
GetView().NotifyDBChanged();
}
OUString SwWrtShell::GetSelDescr() const
{
OUString aResult;
SelectionType nSelType = GetSelectionType();
switch (nSelType)
{
case SelectionType::Graphic:
aResult = SwResId(STR_GRAPHIC);
break;
case SelectionType::Frame:
{
const SwFrameFormat * pFrameFormat = GetSelectedFrameFormat();
if (pFrameFormat)
aResult = pFrameFormat->GetDescription();
}
break;
case SelectionType::DrawObject:
{
aResult = SwResId(STR_DRAWING_OBJECTS);
}
break;
default:
if (mxDoc)
aResult = GetCursorDescr();
}
return aResult;
}
void SwWrtShell::ApplyViewOptions( const SwViewOption &rOpt )
{
SwFEShell::ApplyViewOptions( rOpt );
//#i115062# invalidate meta character slot
GetView().GetViewFrame()->GetBindings().Invalidate( FN_VIEW_META_CHARS );
}
void SwWrtShell::SetReadonlyOption(bool bSet)
{
GetView().GetEditWin().GetFrameControlsManager().SetReadonlyControls( bSet );
SwViewShell::SetReadonlyOption( bSet );
}
// Switch on/off header or footer of a page style - if an empty name is
// given all styles are changed
void SwWrtShell::ChangeHeaderOrFooter(
const OUString& rStyleName, bool bHeader, bool bOn, bool bShowWarning)
{
SdrView *const pSdrView = GetDrawView();
if (pSdrView && pSdrView->IsTextEdit())
{ // tdf#107474 deleting header may delete active drawing object
pSdrView->SdrEndTextEdit(true);
}
addCurrentPosition();
StartAllAction();
StartUndo( SwUndoId::HEADER_FOOTER ); // #i7983#
bool bExecute = true;
bool bCursorSet = false;
for( size_t nFrom = 0, nTo = GetPageDescCnt();
nFrom < nTo; ++nFrom )
{
SwPageDesc aDesc( GetPageDesc( nFrom ));
OUString sTmp(aDesc.GetName());
if( rStyleName.isEmpty() || rStyleName == sTmp )
{
bool bChgd = false;
if( bShowWarning && !bOn && GetActiveView() && GetActiveView() == &GetView() &&
( (bHeader && aDesc.GetMaster().GetHeader().IsActive()) ||
(!bHeader && aDesc.GetMaster().GetFooter().IsActive()) ) )
{
bShowWarning = false;
//Actions have to be closed while the dialog is showing
EndAllAction();
weld::Window* pParent = GetView().GetFrameWeld();
short nResult;
if (bHeader) {
nResult = DeleteHeaderDialog(pParent).run();
} else {
nResult = DeleteFooterDialog(pParent).run();
}
bExecute = nResult == RET_YES;
StartAllAction();
if (nResult == RET_YES)
ToggleHeaderFooterEdit();
}
if( bExecute )
{
bChgd = true;
SwFrameFormat &rMaster = aDesc.GetMaster();
if(bHeader)
rMaster.SetFormatAttr( SwFormatHeader( bOn ));
else
rMaster.SetFormatAttr( SwFormatFooter( bOn ));
if( bOn )
{
SvxULSpaceItem aUL(bHeader ? 0 : MM50, bHeader ? MM50 : 0, RES_UL_SPACE );
SwFrameFormat* pFormat = bHeader ?
const_cast<SwFrameFormat*>(rMaster.GetHeader().GetHeaderFormat()) :
const_cast<SwFrameFormat*>(rMaster.GetFooter().GetFooterFormat());
pFormat->SetFormatAttr( aUL );
}
}
if( bChgd )
{
ChgPageDesc( nFrom, aDesc );
if( !bCursorSet && bOn )
{
if ( !IsHeaderFooterEdit() )
ToggleHeaderFooterEdit();
bCursorSet = SetCursorInHdFt(
rStyleName.isEmpty() ? SIZE_MAX : nFrom,
bHeader );
}
}
}
}
EndUndo( SwUndoId::HEADER_FOOTER ); // #i7983#
EndAllAction();
}
void SwWrtShell::SetShowHeaderFooterSeparator( FrameControlType eControl, bool bShow )
{
SwViewShell::SetShowHeaderFooterSeparator( eControl, bShow );
if ( !bShow )
GetView().GetEditWin().GetFrameControlsManager().HideControls( eControl );
}
void SwWrtShell::InsertPostIt(SwFieldMgr& rFieldMgr, const SfxRequest& rReq)
{
SwPostItField* pPostIt = dynamic_cast<SwPostItField*>(rFieldMgr.GetCurField());
bool bNew = !(pPostIt && pPostIt->GetTyp()->Which() == SwFieldIds::Postit);
if (bNew || GetView().GetPostItMgr()->IsAnswer())
{
const SvxPostItAuthorItem* pAuthorItem = rReq.GetArg<SvxPostItAuthorItem>(SID_ATTR_POSTIT_AUTHOR);
OUString sAuthor;
if ( pAuthorItem )
sAuthor = pAuthorItem->GetValue();
else
{
std::size_t nAuthor = SW_MOD()->GetRedlineAuthor();
sAuthor = SW_MOD()->GetRedlineAuthor(nAuthor);
}
const SvxPostItTextItem* pTextItem = rReq.GetArg<SvxPostItTextItem>(SID_ATTR_POSTIT_TEXT);
OUString sText;
if ( pTextItem )
sText = pTextItem->GetValue();
// If we have a text already registered for answer, use that
if (GetView().GetPostItMgr()->IsAnswer() && !GetView().GetPostItMgr()->GetAnswerText().isEmpty())
{
sText = GetView().GetPostItMgr()->GetAnswerText();
GetView().GetPostItMgr()->RegisterAnswerText(OUString());
}
if ( HasSelection() && !IsTableMode() )
{
KillPams();
}
// #i120513# Inserting a comment into an autocompletion crashes
// --> suggestion has to be removed before
GetView().GetEditWin().StopQuickHelp();
SwInsertField_Data aData(SwFieldTypesEnum::Postit, 0, sAuthor, sText, 0);
if (IsSelFrameMode())
{
SwFlyFrame* pFly = GetSelectedFlyFrame();
// Remember the anchor of the selected object before deletion.
std::unique_ptr<SwPosition> pAnchor;
if (pFly)
{
SwFrameFormat* pFormat = pFly->GetFormat();
if (pFormat)
{
RndStdIds eAnchorId = pFormat->GetAnchor().GetAnchorId();
if ((eAnchorId == RndStdIds::FLY_AS_CHAR || eAnchorId == RndStdIds::FLY_AT_CHAR) && pFormat->GetAnchor().GetContentAnchor())
{
pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor()));
}
}
}
// A frame is selected, end frame selection.
EnterStdMode();
GetView().AttrChangedNotify(nullptr);
// Set up text selection, so the anchor of the frame will be the anchor of the
// comment.
if (pFly)
{
*GetCurrentShellCursor().GetPoint() = *pAnchor;
SwFrameFormat* pFormat = pFly->GetFormat();
if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR)
{
Right(CRSR_SKIP_CELLS, /*bSelect=*/true, 1, /*bBasicCall=*/false, /*bVisual=*/true);
}
else if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_CHAR)
{
aData.m_pAnnotationRange.reset(new SwPaM(*GetCurrentShellCursor().Start(),
*GetCurrentShellCursor().End()));
}
}
}
rFieldMgr.InsertField( aData );
Push();
SwCursorShell::Left(1, CRSR_SKIP_CHARS);
pPostIt = static_cast<SwPostItField*>(rFieldMgr.GetCurField());
Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore cursor position
}
// Client has disabled annotations rendering, no need to
// focus the postit field
if (comphelper::LibreOfficeKit::isActive() && !comphelper::LibreOfficeKit::isTiledAnnotations())
return;
if (pPostIt)
{
SwFieldType* pType = GetDoc()->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false);
if(auto pFormat = pType->FindFormatForField(pPostIt))
pFormat->Broadcast( SwFormatFieldHint( nullptr, SwFormatFieldHintWhich::FOCUS, &GetView() ) );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|