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
1987
1988
1989
1990
|
/* -*- 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 <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <editeng/eeitem.hxx>
#include <math.h>
#include <svl/itemiter.hxx>
#include <svl/whiter.hxx>
#include <tools/bigint.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
#include <getallcharpropids.hxx>
#include <svx/dialmgr.hxx>
#include <svx/svditer.hxx>
#include <svx/strings.hrc>
#include <AffineMatrixItem.hxx>
#include <svx/e3dsceneupdater.hxx>
#include <svx/obj3d.hxx>
#include <svx/rectenum.hxx>
#include <svx/sdr/contact/viewcontact.hxx>
#include <svx/sdooitm.hxx>
#include <svx/sderitm.hxx>
#include <svx/sdtagitm.hxx>
#include <svx/svdedtv.hxx>
#include <svx/svdetc.hxx>
#include <svx/svdopath.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdpagv.hxx>
#include <svx/svdtrans.hxx>
#include <svx/svdundo.hxx>
#include <svx/svxids.hrc>
#include <sxallitm.hxx>
#include <sxmovitm.hxx>
#include <sxreaitm.hxx>
#include <sxreoitm.hxx>
#include <sxroaitm.hxx>
#include <sxrooitm.hxx>
#include <sxsalitm.hxx>
#include <sxsoitm.hxx>
#include <sxtraitm.hxx>
#include <svx/xlnedwit.hxx>
#include <svx/xlnstwit.hxx>
#include <svx/xlnwtit.hxx>
#include <svx/xlnclit.hxx>
#include <svx/xflclit.hxx>
#include <svx/xlntrit.hxx>
#include <svx/xfltrit.hxx>
#include <svx/sdprcitm.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <rtl/ustring.hxx>
#include <sfx2/viewsh.hxx>
#include <comphelper/lok.hxx>
// EditView
void SdrEditView::SetMarkedObjRect(const tools::Rectangle& rRect)
{
DBG_ASSERT(!rRect.IsEmpty(),"SetMarkedObjRect() with an empty Rect does not make sense.");
if (rRect.IsEmpty()) return;
const size_t nCount=GetMarkedObjectCount();
if (nCount==0) return;
tools::Rectangle aR0(GetMarkedObjRect());
DBG_ASSERT(!aR0.IsEmpty(),"SetMarkedObjRect(): GetMarkedObjRect() is empty.");
if (aR0.IsEmpty()) return;
long x0=aR0.Left();
long y0=aR0.Top();
long w0=aR0.Right()-x0;
long h0=aR0.Bottom()-y0;
long x1=rRect.Left();
long y1=rRect.Top();
long w1=rRect.Right()-x1;
long h1=rRect.Bottom()-y1;
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
BegUndo(ImpGetDescriptionString(STR_EditPosSize));
}
for (size_t nm=0; nm<nCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
tools::Rectangle aR1(pO->GetSnapRect());
if (!aR1.IsEmpty())
{
if (aR1==aR0)
{
aR1=rRect;
}
else
{ // transform aR1 to aR0 after rRect
aR1.Move(-x0,-y0);
BigInt l(aR1.Left());
BigInt r(aR1.Right());
BigInt t(aR1.Top());
BigInt b(aR1.Bottom());
if (w0!=0) {
l*=w1; l/=w0;
r*=w1; r/=w0;
} else {
l=0; r=w1;
}
if (h0!=0) {
t*=h1; t/=h0;
b*=h1; b/=h0;
} else {
t=0; b=h1;
}
aR1.SetLeft(long(l) );
aR1.SetRight(long(r) );
aR1.SetTop(long(t) );
aR1.SetBottom(long(b) );
aR1.Move(x1,y1);
}
pO->SetSnapRect(aR1);
} else {
OSL_FAIL("SetMarkedObjRect(): pObj->GetSnapRect() returns empty Rect");
}
}
if( bUndo )
EndUndo();
}
std::vector< std::unique_ptr<SdrUndoAction> > SdrEditView::CreateConnectorUndo( SdrObject& rO )
{
std::vector< std::unique_ptr<SdrUndoAction> > vUndoActions;
if ( rO.GetBroadcaster() )
{
const SdrPage* pPage = rO.getSdrPageFromSdrObject();
if ( pPage )
{
SdrObjListIter aIter(pPage, SdrIterMode::DeepWithGroups);
while( aIter.IsMore() )
{
SdrObject* pPartObj = aIter.Next();
if ( dynamic_cast<const SdrEdgeObj*>( pPartObj) != nullptr )
{
if ( ( pPartObj->GetConnectedNode( false ) == &rO ) ||
( pPartObj->GetConnectedNode( true ) == &rO ) )
{
vUndoActions.push_back( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject( *pPartObj ) );
}
}
}
}
}
return vUndoActions;
}
void SdrEditView::AddUndoActions( std::vector< std::unique_ptr<SdrUndoAction> > aUndoActions )
{
for (auto & rAction : aUndoActions)
AddUndo( std::move(rAction) );
}
void SdrEditView::MoveMarkedObj(const Size& rSiz, bool bCopy)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr(SvxResId(STR_EditMove));
if (bCopy)
aStr += SvxResId(STR_EditWithCopy);
// needs its own UndoGroup because of its parameters
BegUndo(aStr,GetDescriptionOfMarkedObjects(),SdrRepeatFunc::Move);
}
if (bCopy)
CopyMarkedObj();
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
{
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pO,rSiz));
}
pO->Move(rSiz);
}
if( bUndo )
EndUndo();
}
void SdrEditView::ResizeMarkedObj(const Point& rRef, const Fraction& xFact, const Fraction& yFact, bool bCopy)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr {ImpGetDescriptionString(STR_EditResize)};
if (bCopy)
aStr+=SvxResId(STR_EditWithCopy);
BegUndo(aStr);
}
if (bCopy)
CopyMarkedObj();
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
{
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
}
pO->Resize(rRef,xFact,yFact);
}
if( bUndo )
EndUndo();
}
void SdrEditView::ResizeMultMarkedObj(const Point& rRef,
const Fraction& xFact,
const Fraction& yFact,
const bool bWdh,
const bool bHgt)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
BegUndo(ImpGetDescriptionString(STR_EditResize));
}
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
{
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
}
Fraction aFrac(1,1);
if (bWdh && xFact.IsValid() && bHgt && yFact.IsValid())
pO->Resize(rRef, xFact, yFact);
else if (bWdh && xFact.IsValid())
pO->Resize(rRef, xFact, aFrac);
else if (bHgt && yFact.IsValid())
pO->Resize(rRef, aFrac, yFact);
}
if( bUndo )
EndUndo();
}
long SdrEditView::GetMarkedObjRotate() const
{
long nRetval(0);
if(GetMarkedObjectCount())
{
SdrMark* pM = GetSdrMarkByIndex(0);
SdrObject* pO = pM->GetMarkedSdrObj();
nRetval = pO->GetRotateAngle();
}
return nRetval;
//sal_Bool b1st=true;
//sal_Bool bOk=true;
//long nAngle=0;
//sal_uIntPtr nMarkCount=GetMarkedObjectCount();
//for (sal_uIntPtr nm=0; nm<nMarkCount && bOk; nm++) {
// SdrMark* pM=GetSdrMarkByIndex(nm);
// SdrObject* pO=pM->GetMarkedSdrObj();
// long nAngle2=pO->GetRotateAngle();
// if (b1st) nAngle=nAngle2;
// else if (nAngle2!=nAngle) bOk=false;
// b1st=false;
//}
//if (!bOk) nAngle=0;
//return nAngle;
}
void SdrEditView::RotateMarkedObj(const Point& rRef, long nAngle, bool bCopy)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr {ImpGetDescriptionString(STR_EditRotate)};
if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
BegUndo(aStr);
}
if (bCopy)
CopyMarkedObj();
double nSin = sin(nAngle * F_PI18000);
double nCos = cos(nAngle * F_PI18000);
const size_t nMarkCount(GetMarkedObjectCount());
if(nMarkCount)
{
std::vector< E3DModifySceneSnapRectUpdater* > aUpdaters;
for(size_t nm = 0; nm < nMarkCount; ++nm)
{
SdrMark* pM = GetSdrMarkByIndex(nm);
SdrObject* pO = pM->GetMarkedSdrObj();
if( bUndo )
{
// extra undo actions for changed connector which now may hold its laid out path (SJ)
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
}
// set up a scene updater if object is a 3d object
if(dynamic_cast< E3dObject* >(pO))
{
aUpdaters.push_back(new E3DModifySceneSnapRectUpdater(pO));
}
pO->Rotate(rRef,nAngle,nSin,nCos);
}
// fire scene updaters
while(!aUpdaters.empty())
{
delete aUpdaters.back();
aUpdaters.pop_back();
}
}
if( bUndo )
EndUndo();
}
void SdrEditView::MirrorMarkedObj(const Point& rRef1, const Point& rRef2, bool bCopy)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr;
Point aDif(rRef2-rRef1);
if (aDif.X()==0)
aStr = ImpGetDescriptionString(STR_EditMirrorHori);
else if (aDif.Y()==0)
aStr = ImpGetDescriptionString(STR_EditMirrorVert);
else if (std::abs(aDif.X()) == std::abs(aDif.Y()))
aStr = ImpGetDescriptionString(STR_EditMirrorDiag);
else
aStr = ImpGetDescriptionString(STR_EditMirrorFree);
if (bCopy) aStr+=SvxResId(STR_EditWithCopy);
BegUndo(aStr);
}
if (bCopy)
CopyMarkedObj();
const size_t nMarkCount(GetMarkedObjectCount());
if(nMarkCount)
{
std::vector< E3DModifySceneSnapRectUpdater* > aUpdaters;
for(size_t nm = 0; nm < nMarkCount; ++nm)
{
SdrMark* pM = GetSdrMarkByIndex(nm);
SdrObject* pO = pM->GetMarkedSdrObj();
if( bUndo )
{
// extra undo actions for changed connector which now may hold its laid out path (SJ)
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
}
// set up a scene updater if object is a 3d object
if(dynamic_cast< E3dObject* >(pO))
{
aUpdaters.push_back(new E3DModifySceneSnapRectUpdater(pO));
}
pO->Mirror(rRef1,rRef2);
}
// fire scene updaters
while(!aUpdaters.empty())
{
delete aUpdaters.back();
aUpdaters.pop_back();
}
}
if( bUndo )
EndUndo();
}
void SdrEditView::MirrorMarkedObjHorizontal()
{
Point aCenter(GetMarkedObjRect().Center());
Point aPt2(aCenter);
aPt2.AdjustY( 1 );
MirrorMarkedObj(aCenter,aPt2);
}
void SdrEditView::MirrorMarkedObjVertical()
{
Point aCenter(GetMarkedObjRect().Center());
Point aPt2(aCenter);
aPt2.AdjustX( 1 );
MirrorMarkedObj(aCenter,aPt2);
}
long SdrEditView::GetMarkedObjShear() const
{
bool b1st=true;
bool bOk=true;
long nAngle=0;
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount && bOk; ++nm) {
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
long nAngle2=pO->GetShearAngle();
if (b1st) nAngle=nAngle2;
else if (nAngle2!=nAngle) bOk=false;
b1st=false;
}
if (nAngle>SDRMAXSHEAR) nAngle=SDRMAXSHEAR;
if (nAngle<-SDRMAXSHEAR) nAngle=-SDRMAXSHEAR;
if (!bOk) nAngle=0;
return nAngle;
}
void SdrEditView::ShearMarkedObj(const Point& rRef, long nAngle, bool bVShear, bool bCopy)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr {ImpGetDescriptionString(STR_EditShear)};
if (bCopy)
aStr+=SvxResId(STR_EditWithCopy);
BegUndo(aStr);
}
if (bCopy)
CopyMarkedObj();
double nTan = tan(nAngle * F_PI18000);
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
{
AddUndoActions( CreateConnectorUndo( *pO ) );
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
}
pO->Shear(rRef,nAngle,nTan,bVShear);
}
if( bUndo )
EndUndo();
}
void SdrEditView::ImpCrookObj(SdrObject* pO, const Point& rRef, const Point& rRad,
SdrCrookMode eMode, bool bVertical, bool bNoContortion, bool bRotate, const tools::Rectangle& rMarkRect)
{
SdrPathObj* pPath=dynamic_cast<SdrPathObj*>( pO );
bool bDone = false;
if(pPath!=nullptr && !bNoContortion)
{
XPolyPolygon aXPP(pPath->GetPathPoly());
switch (eMode) {
case SdrCrookMode::Rotate : CrookRotatePoly (aXPP,rRef,rRad,bVertical); break;
case SdrCrookMode::Slant : CrookSlantPoly (aXPP,rRef,rRad,bVertical); break;
case SdrCrookMode::Stretch: CrookStretchPoly(aXPP,rRef,rRad,bVertical,rMarkRect); break;
} // switch
pPath->SetPathPoly(aXPP.getB2DPolyPolygon());
bDone = true;
}
if(!bDone && !pPath && pO->IsPolyObj() && 0 != pO->GetPointCount())
{
// for PolyObj's, but NOT for SdrPathObj's, e.g. the measurement object
sal_uInt32 nPointCount(pO->GetPointCount());
XPolygon aXP(static_cast<sal_uInt16>(nPointCount));
sal_uInt32 nPtNum;
for(nPtNum = 0; nPtNum < nPointCount; nPtNum++)
{
Point aPt(pO->GetPoint(nPtNum));
aXP[static_cast<sal_uInt16>(nPtNum)]=aPt;
}
switch (eMode)
{
case SdrCrookMode::Rotate : CrookRotatePoly (aXP,rRef,rRad,bVertical); break;
case SdrCrookMode::Slant : CrookSlantPoly (aXP,rRef,rRad,bVertical); break;
case SdrCrookMode::Stretch: CrookStretchPoly(aXP,rRef,rRad,bVertical,rMarkRect); break;
}
for(nPtNum = 0; nPtNum < nPointCount; nPtNum++)
{
// broadcasting could be optimized here, but for the
// current two points of the measurement object, it's fine
pO->SetPoint(aXP[static_cast<sal_uInt16>(nPtNum)],nPtNum);
}
bDone = true;
}
if(!bDone)
{
// for all others or if bNoContortion
Point aCtr0(pO->GetSnapRect().Center());
Point aCtr1(aCtr0);
bool bRotOk(false);
double nSin(0.0), nCos(1.0);
double nAngle(0.0);
if(0 != rRad.X() && 0 != rRad.Y())
{
bRotOk = bRotate;
switch (eMode)
{
case SdrCrookMode::Rotate : nAngle=CrookRotateXPoint (aCtr1,nullptr,nullptr,rRef,rRad,nSin,nCos,bVertical); bRotOk=bRotate; break;
case SdrCrookMode::Slant : nAngle=CrookSlantXPoint (aCtr1,nullptr,nullptr,rRef,rRad,nSin,nCos,bVertical); break;
case SdrCrookMode::Stretch: nAngle=CrookStretchXPoint(aCtr1,nullptr,nullptr,rRef,rRad,nSin,nCos,bVertical,rMarkRect); break;
}
}
aCtr1 -= aCtr0;
if(bRotOk)
pO->Rotate(aCtr0, FRound(nAngle / F_PI18000), nSin, nCos);
pO->Move(Size(aCtr1.X(),aCtr1.Y()));
}
}
void SdrEditView::CrookMarkedObj(const Point& rRef, const Point& rRad, SdrCrookMode eMode,
bool bVertical, bool bNoContortion, bool bCopy)
{
tools::Rectangle aMarkRect(GetMarkedObjRect());
const bool bUndo = IsUndoEnabled();
bool bRotate=bNoContortion && eMode==SdrCrookMode::Rotate && IsRotateAllowed();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr {ImpGetDescriptionString(bNoContortion ? STR_EditCrook : STR_EditCrookContortion)};
if (bCopy)
aStr+=SvxResId(STR_EditWithCopy);
BegUndo(aStr);
}
if (bCopy)
CopyMarkedObj();
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
const SdrObjList* pOL=pO->GetSubList();
if (bNoContortion || pOL==nullptr) {
ImpCrookObj(pO,rRef,rRad,eMode,bVertical,bNoContortion,bRotate,aMarkRect);
} else {
SdrObjListIter aIter(pOL,SdrIterMode::DeepNoGroups);
while (aIter.IsMore()) {
SdrObject* pO1=aIter.Next();
ImpCrookObj(pO1,rRef,rRad,eMode,bVertical,bNoContortion,bRotate,aMarkRect);
}
}
}
if( bUndo )
EndUndo();
}
void SdrEditView::ImpDistortObj(SdrObject* pO, const tools::Rectangle& rRef, const XPolygon& rDistortedRect, bool bNoContortion)
{
SdrPathObj* pPath = dynamic_cast<SdrPathObj*>( pO );
if(!bNoContortion && pPath)
{
XPolyPolygon aXPP(pPath->GetPathPoly());
aXPP.Distort(rRef, rDistortedRect);
pPath->SetPathPoly(aXPP.getB2DPolyPolygon());
}
else if(pO->IsPolyObj())
{
// e. g. for the measurement object
sal_uInt32 nPointCount(pO->GetPointCount());
XPolygon aXP(static_cast<sal_uInt16>(nPointCount));
sal_uInt32 nPtNum;
for(nPtNum = 0; nPtNum < nPointCount; nPtNum++)
{
Point aPt(pO->GetPoint(nPtNum));
aXP[static_cast<sal_uInt16>(nPtNum)]=aPt;
}
aXP.Distort(rRef, rDistortedRect);
for(nPtNum = 0; nPtNum < nPointCount; nPtNum++)
{
// broadcasting could be optimized here, but for the
// current two points of the measurement object it's fine
pO->SetPoint(aXP[static_cast<sal_uInt16>(nPtNum)],nPtNum);
}
}
}
void SdrEditView::DistortMarkedObj(const tools::Rectangle& rRef, const XPolygon& rDistortedRect, bool bNoContortion, bool bCopy)
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr {ImpGetDescriptionString(STR_EditDistort)};
if (bCopy)
aStr+=SvxResId(STR_EditWithCopy);
BegUndo(aStr);
}
if (bCopy)
CopyMarkedObj();
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pO=pM->GetMarkedSdrObj();
if( bUndo )
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pO));
tools::Rectangle aRefRect(rRef);
const SdrObjList* pOL=pO->GetSubList();
if (bNoContortion || pOL==nullptr) {
ImpDistortObj(pO,aRefRect,rDistortedRect,bNoContortion);
} else {
SdrObjListIter aIter(pOL,SdrIterMode::DeepNoGroups);
while (aIter.IsMore()) {
SdrObject* pO1=aIter.Next();
ImpDistortObj(pO1,aRefRect,rDistortedRect,bNoContortion);
}
}
}
if( bUndo )
EndUndo();
}
void SdrEditView::SetNotPersistAttrToMarked(const SfxItemSet& rAttr)
{
// bReplaceAll has no effect here
tools::Rectangle aAllSnapRect(GetMarkedObjRect());
const SfxPoolItem *pPoolItem=nullptr;
if (rAttr.GetItemState(SDRATTR_TRANSFORMREF1X,true,&pPoolItem)==SfxItemState::SET) {
long n=static_cast<const SdrTransformRef1XItem*>(pPoolItem)->GetValue();
SetRef1(Point(n,GetRef1().Y()));
}
if (rAttr.GetItemState(SDRATTR_TRANSFORMREF1Y,true,&pPoolItem)==SfxItemState::SET) {
long n=static_cast<const SdrTransformRef1YItem*>(pPoolItem)->GetValue();
SetRef1(Point(GetRef1().X(),n));
}
if (rAttr.GetItemState(SDRATTR_TRANSFORMREF2X,true,&pPoolItem)==SfxItemState::SET) {
long n=static_cast<const SdrTransformRef2XItem*>(pPoolItem)->GetValue();
SetRef2(Point(n,GetRef2().Y()));
}
if (rAttr.GetItemState(SDRATTR_TRANSFORMREF2Y,true,&pPoolItem)==SfxItemState::SET) {
long n=static_cast<const SdrTransformRef2YItem*>(pPoolItem)->GetValue();
SetRef2(Point(GetRef2().X(),n));
}
long nAllPosX=0; bool bAllPosX=false;
long nAllPosY=0; bool bAllPosY=false;
long nAllWdt=0; bool bAllWdt=false;
long nAllHgt=0; bool bAllHgt=false;
bool bDoIt=false;
if (rAttr.GetItemState(SDRATTR_ALLPOSITIONX,true,&pPoolItem)==SfxItemState::SET) {
nAllPosX=static_cast<const SdrAllPositionXItem*>(pPoolItem)->GetValue();
bAllPosX=true; bDoIt=true;
}
if (rAttr.GetItemState(SDRATTR_ALLPOSITIONY,true,&pPoolItem)==SfxItemState::SET) {
nAllPosY=static_cast<const SdrAllPositionYItem*>(pPoolItem)->GetValue();
bAllPosY=true; bDoIt=true;
}
if (rAttr.GetItemState(SDRATTR_ALLSIZEWIDTH,true,&pPoolItem)==SfxItemState::SET) {
nAllWdt=static_cast<const SdrAllSizeWidthItem*>(pPoolItem)->GetValue();
bAllWdt=true; bDoIt=true;
}
if (rAttr.GetItemState(SDRATTR_ALLSIZEHEIGHT,true,&pPoolItem)==SfxItemState::SET) {
nAllHgt=static_cast<const SdrAllSizeHeightItem*>(pPoolItem)->GetValue();
bAllHgt=true; bDoIt=true;
}
if (bDoIt) {
tools::Rectangle aRect(aAllSnapRect); // TODO: change this for PolyPt's and GluePt's!!!
if (bAllPosX) aRect.Move(nAllPosX-aRect.Left(),0);
if (bAllPosY) aRect.Move(0,nAllPosY-aRect.Top());
if (bAllWdt) aRect.SetRight(aAllSnapRect.Left()+nAllWdt );
if (bAllHgt) aRect.SetBottom(aAllSnapRect.Top()+nAllHgt );
SetMarkedObjRect(aRect);
}
if (rAttr.GetItemState(SDRATTR_RESIZEXALL,true,&pPoolItem)==SfxItemState::SET) {
Fraction aXFact=static_cast<const SdrResizeXAllItem*>(pPoolItem)->GetValue();
ResizeMarkedObj(aAllSnapRect.TopLeft(),aXFact,Fraction(1,1));
}
if (rAttr.GetItemState(SDRATTR_RESIZEYALL,true,&pPoolItem)==SfxItemState::SET) {
Fraction aYFact=static_cast<const SdrResizeYAllItem*>(pPoolItem)->GetValue();
ResizeMarkedObj(aAllSnapRect.TopLeft(),Fraction(1,1),aYFact);
}
if (rAttr.GetItemState(SDRATTR_ROTATEALL,true,&pPoolItem)==SfxItemState::SET) {
long nAngle=static_cast<const SdrRotateAllItem*>(pPoolItem)->GetValue();
RotateMarkedObj(aAllSnapRect.Center(),nAngle);
}
if (rAttr.GetItemState(SDRATTR_HORZSHEARALL,true,&pPoolItem)==SfxItemState::SET) {
long nAngle=static_cast<const SdrHorzShearAllItem*>(pPoolItem)->GetValue();
ShearMarkedObj(aAllSnapRect.Center(),nAngle);
}
if (rAttr.GetItemState(SDRATTR_VERTSHEARALL,true,&pPoolItem)==SfxItemState::SET) {
long nAngle=static_cast<const SdrVertShearAllItem*>(pPoolItem)->GetValue();
ShearMarkedObj(aAllSnapRect.Center(),nAngle,true);
}
const bool bUndo = IsUndoEnabled();
// TODO: check if WhichRange is necessary.
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
const SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pObj=pM->GetMarkedSdrObj();
if( bUndo )
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
pObj->ApplyNotPersistAttr(rAttr);
}
}
void SdrEditView::MergeNotPersistAttrFromMarked(SfxItemSet& rAttr) const
{
// TODO: Take into account the origin and PvPos.
tools::Rectangle aAllSnapRect(GetMarkedObjRect()); // TODO: change this for PolyPt's and GluePt's!!!
long nAllSnapPosX=aAllSnapRect.Left();
long nAllSnapPosY=aAllSnapRect.Top();
long nAllSnapWdt=aAllSnapRect.GetWidth()-1;
long nAllSnapHgt=aAllSnapRect.GetHeight()-1;
// TODO: could go into CheckPossibilities
bool bMovProtect = false, bMovProtectDC = false;
bool bSizProtect = false, bSizProtectDC = false;
bool bPrintable = true, bPrintableDC = false;
bool bVisible = true, bVisibleDC = false;
SdrLayerID nLayerId(0);
bool bLayerDC=false;
long nSnapPosX=0; bool bSnapPosXDC=false;
long nSnapPosY=0; bool bSnapPosYDC=false;
long nSnapWdt=0; bool bSnapWdtDC=false;
long nSnapHgt=0; bool bSnapHgtDC=false;
long nLogicWdt=0; bool bLogicWdtDC=false,bLogicWdtDiff=false;
long nLogicHgt=0; bool bLogicHgtDC=false,bLogicHgtDiff=false;
long nRotAngle=0; bool bRotAngleDC=false;
long nShrAngle=0; bool bShrAngleDC=false;
tools::Rectangle aSnapRect;
tools::Rectangle aLogicRect;
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm) {
const SdrMark* pM=GetSdrMarkByIndex(nm);
const SdrObject* pObj=pM->GetMarkedSdrObj();
if (nm==0) {
nLayerId=pObj->GetLayer();
bMovProtect=pObj->IsMoveProtect();
bSizProtect=pObj->IsResizeProtect();
bPrintable =pObj->IsPrintable();
bVisible = pObj->IsVisible();
tools::Rectangle aSnapRect2(pObj->GetSnapRect());
tools::Rectangle aLogicRect2(pObj->GetLogicRect());
nSnapPosX=aSnapRect2.Left();
nSnapPosY=aSnapRect2.Top();
nSnapWdt=aSnapRect2.GetWidth()-1;
nSnapHgt=aSnapRect2.GetHeight()-1;
nLogicWdt=aLogicRect2.GetWidth()-1;
nLogicHgt=aLogicRect2.GetHeight()-1;
bLogicWdtDiff=nLogicWdt!=nSnapWdt;
bLogicHgtDiff=nLogicHgt!=nSnapHgt;
nRotAngle=pObj->GetRotateAngle();
nShrAngle=pObj->GetShearAngle();
} else {
if (!bLayerDC && nLayerId !=pObj->GetLayer()) bLayerDC = true;
if (!bMovProtectDC && bMovProtect!=pObj->IsMoveProtect()) bMovProtectDC = true;
if (!bSizProtectDC && bSizProtect!=pObj->IsResizeProtect()) bSizProtectDC = true;
if (!bPrintableDC && bPrintable !=pObj->IsPrintable()) bPrintableDC = true;
if (!bVisibleDC && bVisible !=pObj->IsVisible()) bVisibleDC=true;
if (!bRotAngleDC && nRotAngle !=pObj->GetRotateAngle()) bRotAngleDC=true;
if (!bShrAngleDC && nShrAngle !=pObj->GetShearAngle()) bShrAngleDC=true;
if (!bSnapWdtDC || !bSnapHgtDC || !bSnapPosXDC || !bSnapPosYDC || !bLogicWdtDiff || !bLogicHgtDiff) {
aSnapRect=pObj->GetSnapRect();
if (nSnapPosX!=aSnapRect.Left()) bSnapPosXDC=true;
if (nSnapPosY!=aSnapRect.Top()) bSnapPosYDC=true;
if (nSnapWdt!=aSnapRect.GetWidth()-1) bSnapWdtDC=true;
if (nSnapHgt!=aSnapRect.GetHeight()-1) bSnapHgtDC=true;
}
if (!bLogicWdtDC || !bLogicHgtDC || !bLogicWdtDiff || !bLogicHgtDiff) {
aLogicRect=pObj->GetLogicRect();
if (nLogicWdt!=aLogicRect.GetWidth()-1) bLogicWdtDC=true;
if (nLogicHgt!=aLogicRect.GetHeight()-1) bLogicHgtDC=true;
if (!bLogicWdtDiff && aSnapRect.GetWidth()!=aLogicRect.GetWidth()) bLogicWdtDiff=true;
if (!bLogicHgtDiff && aSnapRect.GetHeight()!=aLogicRect.GetHeight()) bLogicHgtDiff=true;
}
}
}
if (bSnapPosXDC || nAllSnapPosX!=nSnapPosX) rAttr.Put(SdrAllPositionXItem(nAllSnapPosX));
if (bSnapPosYDC || nAllSnapPosY!=nSnapPosY) rAttr.Put(SdrAllPositionYItem(nAllSnapPosY));
if (bSnapWdtDC || nAllSnapWdt !=nSnapWdt ) rAttr.Put(SdrAllSizeWidthItem(nAllSnapWdt));
if (bSnapHgtDC || nAllSnapHgt !=nSnapHgt ) rAttr.Put(SdrAllSizeHeightItem(nAllSnapHgt));
// items for pure transformations
rAttr.Put(SdrMoveXItem());
rAttr.Put(SdrMoveYItem());
rAttr.Put(SdrResizeXOneItem());
rAttr.Put(SdrResizeYOneItem());
rAttr.Put(SdrRotateOneItem());
rAttr.Put(SdrHorzShearOneItem());
rAttr.Put(SdrVertShearOneItem());
if (nMarkCount>1) {
rAttr.Put(SdrResizeXAllItem());
rAttr.Put(SdrResizeYAllItem());
rAttr.Put(SdrRotateAllItem());
rAttr.Put(SdrHorzShearAllItem());
rAttr.Put(SdrVertShearAllItem());
}
if(meDragMode == SdrDragMode::Rotate || meDragMode == SdrDragMode::Mirror)
{
rAttr.Put(SdrTransformRef1XItem(GetRef1().X()));
rAttr.Put(SdrTransformRef1YItem(GetRef1().Y()));
}
if(meDragMode == SdrDragMode::Mirror)
{
rAttr.Put(SdrTransformRef2XItem(GetRef2().X()));
rAttr.Put(SdrTransformRef2YItem(GetRef2().Y()));
}
}
SfxItemSet SdrEditView::GetAttrFromMarked(bool bOnlyHardAttr) const
{
SfxItemSet aSet(mpModel->GetItemPool());
MergeAttrFromMarked(aSet,bOnlyHardAttr);
//the EE_FEATURE items should not be set with SetAttrToMarked (see error message there)
//so we do not set them here
// #i32448#
// Do not disable, but clear the items.
aSet.ClearItem(EE_FEATURE_TAB);
aSet.ClearItem(EE_FEATURE_LINEBR);
aSet.ClearItem(EE_FEATURE_NOTCONV);
aSet.ClearItem(EE_FEATURE_FIELD);
return aSet;
}
void SdrEditView::MergeAttrFromMarked(SfxItemSet& rAttr, bool bOnlyHardAttr) const
{
const size_t nMarkCount(GetMarkedObjectCount());
for(size_t a = 0; a < nMarkCount; ++a)
{
// #80277# merging was done wrong in the prev version
const SfxItemSet& rSet = GetMarkedObjectByIndex(a)->GetMergedItemSet();
SfxWhichIter aIter(rSet);
sal_uInt16 nWhich(aIter.FirstWhich());
while(nWhich)
{
if(!bOnlyHardAttr)
{
if(SfxItemState::DONTCARE == rSet.GetItemState(nWhich, false))
rAttr.InvalidateItem(nWhich);
else
rAttr.MergeValue(rSet.Get(nWhich), true);
}
else if(SfxItemState::SET == rSet.GetItemState(nWhich, false))
{
const SfxPoolItem& rItem = rSet.Get(nWhich);
rAttr.MergeValue(rItem, true);
}
if (comphelper::LibreOfficeKit::isActive())
{
OUString sPayload;
switch(nWhich)
{
case XATTR_LINECOLOR:
{
const SfxPoolItem* pItem = rSet.GetItem(XATTR_LINECOLOR);
if (pItem)
{
Color aColor = static_cast<const XLineColorItem*>(pItem)->GetColorValue();
sPayload = OUString::number(static_cast<sal_uInt32>(aColor));
sPayload = ".uno:XLineColor=" + sPayload;
}
break;
}
case XATTR_FILLCOLOR:
{
const SfxPoolItem* pItem = rSet.GetItem(XATTR_FILLCOLOR);
if (pItem)
{
Color aColor = static_cast<const XFillColorItem*>(pItem)->GetColorValue();
sPayload = OUString::number(static_cast<sal_uInt32>(aColor));
sPayload = ".uno:FillColor=" + sPayload;
}
break;
}
case XATTR_FILLTRANSPARENCE:
{
const SfxPoolItem* pItem = rSet.GetItem(XATTR_FILLTRANSPARENCE);
if (pItem)
{
sal_uInt16 nTransparency = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
sPayload = OUString::number(nTransparency);
sPayload = ".uno:FillTransparence=" + sPayload;
}
break;
}
case XATTR_LINETRANSPARENCE:
{
const SfxPoolItem* pItem = rSet.GetItem(XATTR_LINETRANSPARENCE);
if (pItem)
{
sal_uInt16 nTransparency = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
sPayload = OUString::number(nTransparency);
sPayload = ".uno:LineTransparence=" + sPayload;
}
break;
}
case XATTR_LINEWIDTH:
{
const SfxPoolItem* pItem = rSet.GetItem(XATTR_LINEWIDTH);
if (pItem)
{
sal_uInt32 nWidth = static_cast<const XLineWidthItem*>(pItem)->GetValue();
sPayload = OUString::number(nWidth);
sPayload = ".uno:LineWidth=" + sPayload;
}
break;
}
case SDRATTR_SHADOWTRANSPARENCE:
{
const SfxPoolItem* pItem = rSet.GetItem(SDRATTR_SHADOWTRANSPARENCE);
if (pItem)
{
sal_uInt16 nWidth = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
sPayload = OUString::number(nWidth);
sPayload = ".uno:FillShadowTransparency=" + sPayload;
}
break;
}
}
if (!sPayload.isEmpty())
GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED,
OUStringToOString(sPayload, RTL_TEXTENCODING_ASCII_US).getStr());
}
nWhich = aIter.NextWhich();
}
}
}
std::vector<sal_uInt16> GetAllCharPropIds(const SfxItemSet& rSet)
{
std::vector<sal_uInt16> aCharWhichIds;
{
SfxItemIter aIter(rSet);
for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
{
if (!IsInvalidItem(pItem))
{
sal_uInt16 nWhich = pItem->Which();
if (nWhich>=EE_CHAR_START && nWhich<=EE_CHAR_END)
aCharWhichIds.push_back( nWhich );
}
}
}
return aCharWhichIds;
}
void SdrEditView::SetAttrToMarked(const SfxItemSet& rAttr, bool bReplaceAll)
{
if (!AreObjectsMarked())
return;
#ifdef DBG_UTIL
{
bool bHasEEFeatureItems=false;
SfxItemIter aIter(rAttr);
for (const SfxPoolItem* pItem = aIter.GetCurItem(); !bHasEEFeatureItems && pItem;
pItem = aIter.NextItem())
{
if (!IsInvalidItem(pItem)) {
sal_uInt16 nW=pItem->Which();
if (nW>=EE_FEATURE_START && nW<=EE_FEATURE_END) bHasEEFeatureItems=true;
}
}
if(bHasEEFeatureItems)
{
const OUString aMessage("SdrEditView::SetAttrToMarked(): Setting EE_FEATURE items at the SdrView does not make sense! It only leads to overhead and unreadable documents.");
std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(nullptr,
VclMessageType::Info, VclButtonsType::Ok,
aMessage));
xInfoBox->run();
}
}
#endif
// #103836# if the user sets character attributes to the complete shape,
// we want to remove all hard set character attributes with same
// which ids from the text. We do that later but here we remember
// all character attribute which id's that are set.
std::vector<sal_uInt16> aCharWhichIds(GetAllCharPropIds(rAttr));
// To make Undo reconstruct text attributes correctly after Format.Standard
bool bHasEEItems=SearchOutlinerItems(rAttr,bReplaceAll);
// save additional geometry information when paragraph or character attributes
// are changed and the geometrical shape of the text object might be changed
bool bPossibleGeomChange(false);
SfxWhichIter aIter(rAttr);
sal_uInt16 nWhich = aIter.FirstWhich();
while(!bPossibleGeomChange && nWhich)
{
SfxItemState eState = rAttr.GetItemState(nWhich);
if(eState == SfxItemState::SET)
{
if((nWhich >= SDRATTR_TEXT_MINFRAMEHEIGHT && nWhich <= SDRATTR_TEXT_CONTOURFRAME)
|| nWhich == SDRATTR_3DOBJ_PERCENT_DIAGONAL
|| nWhich == SDRATTR_3DOBJ_BACKSCALE
|| nWhich == SDRATTR_3DOBJ_DEPTH
|| nWhich == SDRATTR_3DOBJ_END_ANGLE
|| nWhich == SDRATTR_3DSCENE_DISTANCE)
{
bPossibleGeomChange = true;
}
}
nWhich = aIter.NextWhich();
}
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
BegUndo(ImpGetDescriptionString(STR_EditSetAttributes));
}
const size_t nMarkCount(GetMarkedObjectCount());
std::vector< E3DModifySceneSnapRectUpdater* > aUpdaters;
// create ItemSet without SfxItemState::DONTCARE. Put()
// uses its second parameter (bInvalidAsDefault) to
// remove all such items to set them to default.
SfxItemSet aAttr(*rAttr.GetPool(), rAttr.GetRanges());
aAttr.Put(rAttr);
// #i38135#
bool bResetAnimationTimer(false);
const bool bLineStartWidthExplicitChange(SfxItemState::SET
== aAttr.GetItemState(XATTR_LINESTARTWIDTH));
const bool bLineEndWidthExplicitChange(SfxItemState::SET
== aAttr.GetItemState(XATTR_LINEENDWIDTH));
// check if LineWidth is part of the change
const bool bAdaptStartEndWidths(!(bLineStartWidthExplicitChange && bLineEndWidthExplicitChange)
&& SfxItemState::SET == aAttr.GetItemState(XATTR_LINEWIDTH));
sal_Int32 nNewLineWidth(0);
if(bAdaptStartEndWidths)
{
nNewLineWidth = aAttr.Get(XATTR_LINEWIDTH).GetValue();
}
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pObj = pM->GetMarkedSdrObj();
if( bUndo )
{
SdrEdgeObj* pEdgeObj = dynamic_cast< SdrEdgeObj* >( pObj );
if ( pEdgeObj )
bPossibleGeomChange = true;
else
AddUndoActions( CreateConnectorUndo( *pObj ) );
}
// new geometry undo
if(bPossibleGeomChange && bUndo)
{
// save position and size of object, too
AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
}
if( bUndo )
{
// #i8508#
// If this is a text object also rescue the OutlinerParaObject since
// applying attributes to the object may change text layout when
// multiple portions exist with multiple formats. If an OutlinerParaObject
// really exists and needs to be rescued is evaluated in the undo
// implementation itself.
const bool bRescueText = dynamic_cast< SdrTextObj* >(pObj) != nullptr;
// add attribute undo
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoAttrObject(*pObj,false,bHasEEItems || bPossibleGeomChange || bRescueText));
}
// set up a scene updater if object is a 3d object
if(dynamic_cast< E3dObject* >(pObj))
{
aUpdaters.push_back(new E3DModifySceneSnapRectUpdater(pObj));
}
sal_Int32 nOldLineWidth(0);
if (bAdaptStartEndWidths)
{
nOldLineWidth = pObj->GetMergedItem(XATTR_LINEWIDTH).GetValue();
}
// set attributes at object
pObj->SetMergedItemSetAndBroadcast(aAttr, bReplaceAll);
if(bAdaptStartEndWidths)
{
const SfxItemSet& rSet = pObj->GetMergedItemSet();
if(nOldLineWidth != nNewLineWidth)
{
if(SfxItemState::DONTCARE != rSet.GetItemState(XATTR_LINESTARTWIDTH))
{
const sal_Int32 nValAct(rSet.Get(XATTR_LINESTARTWIDTH).GetValue());
const sal_Int32 nValNewStart(std::max(sal_Int32(0), nValAct + (((nNewLineWidth - nOldLineWidth) * 15) / 10)));
pObj->SetMergedItem(XLineStartWidthItem(nValNewStart));
}
if(SfxItemState::DONTCARE != rSet.GetItemState(XATTR_LINEENDWIDTH))
{
const sal_Int32 nValAct(rSet.Get(XATTR_LINEENDWIDTH).GetValue());
const sal_Int32 nValNewEnd(std::max(sal_Int32(0), nValAct + (((nNewLineWidth - nOldLineWidth) * 15) / 10)));
pObj->SetMergedItem(XLineEndWidthItem(nValNewEnd));
}
}
}
if(dynamic_cast<const SdrTextObj*>( pObj) != nullptr)
{
SdrTextObj* pTextObj = static_cast<SdrTextObj*>(pObj);
if(!aCharWhichIds.empty())
{
tools::Rectangle aOldBoundRect = pTextObj->GetLastBoundRect();
// #110094#-14 pTextObj->SendRepaintBroadcast(pTextObj->GetBoundRect());
pTextObj->RemoveOutlinerCharacterAttribs( aCharWhichIds );
// object has changed, should be called from
// RemoveOutlinerCharacterAttribs. This will change when the text
// object implementation changes.
pTextObj->SetChanged();
pTextObj->BroadcastObjectChange();
pTextObj->SendUserCall(SdrUserCallType::ChangeAttr, aOldBoundRect);
}
}
// #i38495#
if(!bResetAnimationTimer)
{
if(pObj->GetViewContact().isAnimatedInAnyViewObjectContact())
{
bResetAnimationTimer = true;
}
}
}
// fire scene updaters
while(!aUpdaters.empty())
{
delete aUpdaters.back();
aUpdaters.pop_back();
}
// #i38135#
if(bResetAnimationTimer)
{
SetAnimationTimer(0);
}
// better check before what to do:
// pObj->SetAttr() or SetNotPersistAttr()
// TODO: missing implementation!
SetNotPersistAttrToMarked(rAttr);
if( bUndo )
EndUndo();
}
SfxStyleSheet* SdrEditView::GetStyleSheetFromMarked() const
{
SfxStyleSheet* pRet=nullptr;
bool b1st=true;
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm) {
SdrMark* pM=GetSdrMarkByIndex(nm);
SfxStyleSheet* pSS=pM->GetMarkedSdrObj()->GetStyleSheet();
if (b1st) pRet=pSS;
else if (pRet!=pSS) return nullptr; // different stylesheets
b1st=false;
}
return pRet;
}
void SdrEditView::SetStyleSheetToMarked(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
{
if (AreObjectsMarked())
{
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr;
if (pStyleSheet!=nullptr)
aStr = ImpGetDescriptionString(STR_EditSetStylesheet);
else
aStr = ImpGetDescriptionString(STR_EditDelStylesheet);
BegUndo(aStr);
}
const size_t nMarkCount=GetMarkedObjectCount();
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
if( bUndo )
{
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pM->GetMarkedSdrObj()));
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoAttrObject(*pM->GetMarkedSdrObj(),true,true));
}
pM->GetMarkedSdrObj()->SetStyleSheet(pStyleSheet,bDontRemoveHardAttr);
}
if( bUndo )
EndUndo();
}
}
void SdrEditView::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAttr) const
{
if(GetMarkedObjectCount())
{
rTargetSet.Put(GetAttrFromMarked(bOnlyHardAttr), false);
}
else
{
SdrMarkView::GetAttributes(rTargetSet, bOnlyHardAttr);
}
}
void SdrEditView::SetAttributes(const SfxItemSet& rSet, bool bReplaceAll)
{
if (GetMarkedObjectCount()!=0) {
SetAttrToMarked(rSet,bReplaceAll);
} else {
SdrMarkView::SetAttributes(rSet,bReplaceAll);
}
}
SfxStyleSheet* SdrEditView::GetStyleSheet() const
{
if (GetMarkedObjectCount()!=0) {
return GetStyleSheetFromMarked();
} else {
return SdrMarkView::GetStyleSheet();
}
}
void SdrEditView::SetStyleSheet(SfxStyleSheet* pStyleSheet, bool bDontRemoveHardAttr)
{
if (GetMarkedObjectCount()!=0) {
SetStyleSheetToMarked(pStyleSheet,bDontRemoveHardAttr);
} else {
SdrMarkView::SetStyleSheet(pStyleSheet,bDontRemoveHardAttr);
}
}
SfxItemSet SdrEditView::GetGeoAttrFromMarked() const
{
SfxItemSet aRetSet(
mpModel->GetItemPool(),
svl::Items< // SID_ATTR_TRANSFORM_... from s:svxids.hrc
SDRATTR_ECKENRADIUS, SDRATTR_ECKENRADIUS,
SID_ATTR_TRANSFORM_POS_X, SID_ATTR_TRANSFORM_ANGLE,
SID_ATTR_TRANSFORM_PROTECT_POS, SID_ATTR_TRANSFORM_AUTOHEIGHT>{});
if (AreObjectsMarked())
{
SfxItemSet aMarkAttr(GetAttrFromMarked(false)); // because of AutoGrowHeight and corner radius
tools::Rectangle aRect(GetMarkedObjRect());
if(GetSdrPageView())
{
GetSdrPageView()->LogicToPagePos(aRect);
}
// position
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_X,aRect.Left()));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_POS_Y,aRect.Top()));
// size
long nResizeRefX=aRect.Left();
long nResizeRefY=aRect.Top();
if (meDragMode==SdrDragMode::Rotate) { // use rotation axis as a reference for resizing, too
nResizeRefX=maRef1.X();
nResizeRefY=maRef1.Y();
}
aRetSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_WIDTH,aRect.Right()-aRect.Left()));
aRetSet.Put(SfxUInt32Item(SID_ATTR_TRANSFORM_HEIGHT,aRect.Bottom()-aRect.Top()));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_RESIZE_REF_X,nResizeRefX));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_RESIZE_REF_Y,nResizeRefY));
Point aRotateAxe(maRef1);
if(GetSdrPageView())
{
GetSdrPageView()->LogicToPagePos(aRotateAxe);
}
// rotation
long nRotateRefX=aRect.Center().X();
long nRotateRefY=aRect.Center().Y();
if (meDragMode==SdrDragMode::Rotate) {
nRotateRefX=aRotateAxe.X();
nRotateRefY=aRotateAxe.Y();
}
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_ANGLE,GetMarkedObjRotate()));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_ROT_X,nRotateRefX));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_ROT_Y,nRotateRefY));
// shearing
long nShearRefX=aRect.Left();
long nShearRefY=aRect.Bottom();
if (meDragMode==SdrDragMode::Rotate) { // use rotation axis as a reference for shearing, too
nShearRefX=aRotateAxe.X();
nShearRefY=aRotateAxe.Y();
}
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR,GetMarkedObjShear()));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_X,nShearRefX));
aRetSet.Put(SfxInt32Item(SID_ATTR_TRANSFORM_SHEAR_Y,nShearRefY));
// check every object whether it is protected
const SdrMarkList& rMarkList=GetMarkedObjectList();
const size_t nMarkCount=rMarkList.GetMarkCount();
SdrObject* pObj=rMarkList.GetMark(0)->GetMarkedSdrObj();
bool bPosProt=pObj->IsMoveProtect();
bool bSizProt=pObj->IsResizeProtect();
bool bPosProtDontCare=false;
bool bSizProtDontCare=false;
for (size_t i=1; i<nMarkCount && (!bPosProtDontCare || !bSizProtDontCare); ++i)
{
pObj=rMarkList.GetMark(i)->GetMarkedSdrObj();
if (bPosProt!=pObj->IsMoveProtect()) bPosProtDontCare=true;
if (bSizProt!=pObj->IsResizeProtect()) bSizProtDontCare=true;
}
// InvalidateItem sets item to DONT_CARE
if (bPosProtDontCare) {
aRetSet.InvalidateItem(SID_ATTR_TRANSFORM_PROTECT_POS);
} else {
aRetSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_PROTECT_POS,bPosProt));
}
if (bSizProtDontCare) {
aRetSet.InvalidateItem(SID_ATTR_TRANSFORM_PROTECT_SIZE);
} else {
aRetSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_PROTECT_SIZE,bSizProt));
}
SfxItemState eState=aMarkAttr.GetItemState(SDRATTR_TEXT_AUTOGROWWIDTH);
bool bAutoGrow=aMarkAttr.Get(SDRATTR_TEXT_AUTOGROWWIDTH).GetValue();
if (eState==SfxItemState::DONTCARE) {
aRetSet.InvalidateItem(SID_ATTR_TRANSFORM_AUTOWIDTH);
} else if (eState==SfxItemState::SET) {
aRetSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_AUTOWIDTH,bAutoGrow));
}
eState=aMarkAttr.GetItemState(SDRATTR_TEXT_AUTOGROWHEIGHT);
bAutoGrow=aMarkAttr.Get(SDRATTR_TEXT_AUTOGROWHEIGHT).GetValue();
if (eState==SfxItemState::DONTCARE) {
aRetSet.InvalidateItem(SID_ATTR_TRANSFORM_AUTOHEIGHT);
} else if (eState==SfxItemState::SET) {
aRetSet.Put(SfxBoolItem(SID_ATTR_TRANSFORM_AUTOHEIGHT,bAutoGrow));
}
eState=aMarkAttr.GetItemState(SDRATTR_ECKENRADIUS);
long nRadius=aMarkAttr.Get(SDRATTR_ECKENRADIUS).GetValue();
if (eState==SfxItemState::DONTCARE) {
aRetSet.InvalidateItem(SDRATTR_ECKENRADIUS);
} else if (eState==SfxItemState::SET) {
aRetSet.Put(makeSdrEckenradiusItem(nRadius));
}
basegfx::B2DHomMatrix aTransformation;
if(nMarkCount > 1)
{
// multiple objects, range is collected in aRect
aTransformation = basegfx::utils::createScaleTranslateB2DHomMatrix(
aRect.Left(), aRect.Top(),
aRect.getWidth(), aRect.getHeight());
}
else
{
// single object, get homogen transformation
basegfx::B2DPolyPolygon aPolyPolygon;
pObj->TRGetBaseGeometry(aTransformation, aPolyPolygon);
}
if(aTransformation.isIdentity())
{
aRetSet.InvalidateItem(SID_ATTR_TRANSFORM_MATRIX);
}
else
{
css::geometry::AffineMatrix2D aAffineMatrix2D;
Point aPageOffset(0, 0);
if(GetSdrPageView())
{
aPageOffset = GetSdrPageView()->GetPageOrigin();
}
aAffineMatrix2D.m00 = aTransformation.get(0, 0);
aAffineMatrix2D.m01 = aTransformation.get(0, 1);
aAffineMatrix2D.m02 = aTransformation.get(0, 2) - aPageOffset.X();
aAffineMatrix2D.m10 = aTransformation.get(1, 0);
aAffineMatrix2D.m11 = aTransformation.get(1, 1);
aAffineMatrix2D.m12 = aTransformation.get(1, 2) - aPageOffset.Y();
aRetSet.Put(AffineMatrixItem(&aAffineMatrix2D));
}
}
return aRetSet;
}
static Point ImpGetPoint(const tools::Rectangle& rRect, RectPoint eRP)
{
switch(eRP) {
case RectPoint::LT: return rRect.TopLeft();
case RectPoint::MT: return rRect.TopCenter();
case RectPoint::RT: return rRect.TopRight();
case RectPoint::LM: return rRect.LeftCenter();
case RectPoint::MM: return rRect.Center();
case RectPoint::RM: return rRect.RightCenter();
case RectPoint::LB: return rRect.BottomLeft();
case RectPoint::MB: return rRect.BottomCenter();
case RectPoint::RB: return rRect.BottomRight();
}
return Point(); // Should not happen!
}
void SdrEditView::SetGeoAttrToMarked(const SfxItemSet& rAttr)
{
const bool bTiledRendering = comphelper::LibreOfficeKit::isActive();
tools::Rectangle aRect(GetMarkedObjRect());
if(GetSdrPageView())
{
GetSdrPageView()->LogicToPagePos(aRect);
}
long nOldRotateAngle=GetMarkedObjRotate();
long nOldShearAngle=GetMarkedObjShear();
const SdrMarkList& rMarkList=GetMarkedObjectList();
const size_t nMarkCount=rMarkList.GetMarkCount();
SdrObject* pObj=nullptr;
RectPoint eSizePoint=RectPoint::MM;
long nPosDX=0;
long nPosDY=0;
long nSizX=0;
long nSizY=0;
long nRotateAngle=0;
bool bModeIsRotate(meDragMode == SdrDragMode::Rotate);
long nRotateX(0);
long nRotateY(0);
long nOldRotateX(0);
long nOldRotateY(0);
if(bModeIsRotate)
{
Point aRotateAxe(maRef1);
if(GetSdrPageView())
{
GetSdrPageView()->LogicToPagePos(aRotateAxe);
}
nRotateX = nOldRotateX = aRotateAxe.X();
nRotateY = nOldRotateY = aRotateAxe.Y();
}
long nShearAngle=0;
long nShearX=0;
long nShearY=0;
bool bShearVert=false;
bool bChgPos=false;
bool bChgSiz=false;
bool bChgWdh=false;
bool bChgHgt=false;
bool bRotate=false;
bool bShear =false;
bool bSetAttr=false;
SfxItemSet aSetAttr(mpModel->GetItemPool());
const SfxPoolItem* pPoolItem=nullptr;
// position
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_POS_X,true,&pPoolItem)) {
nPosDX=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue() - aRect.Left();
bChgPos=true;
}
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_POS_Y,true,&pPoolItem)){
nPosDY=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue() - aRect.Top();
bChgPos=true;
}
// size
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_WIDTH,true,&pPoolItem)) {
nSizX=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
bChgSiz=true;
bChgWdh=true;
}
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_HEIGHT,true,&pPoolItem)) {
nSizY=static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
bChgSiz=true;
bChgHgt=true;
}
if (bChgSiz) {
if (bTiledRendering && SfxItemState::SET != rAttr.GetItemState(SID_ATTR_TRANSFORM_SIZE_POINT, true, &pPoolItem))
eSizePoint = RectPoint::LT;
else
eSizePoint = static_cast<RectPoint>(rAttr.Get(SID_ATTR_TRANSFORM_SIZE_POINT).GetValue());
}
// rotation
if (SfxItemState::SET == rAttr.GetItemState(SID_ATTR_TRANSFORM_DELTA_ANGLE, true, &pPoolItem)) {
nRotateAngle = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
bRotate = (nRotateAngle != 0);
}
// rotation
if (SfxItemState::SET == rAttr.GetItemState(SID_ATTR_TRANSFORM_ANGLE, true, &pPoolItem)) {
nRotateAngle = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue() - nOldRotateAngle;
bRotate = (nRotateAngle != 0);
}
// position rotation point x
if(bRotate || SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_ROT_X, true ,&pPoolItem))
nRotateX = rAttr.Get(SID_ATTR_TRANSFORM_ROT_X).GetValue();
// position rotation point y
if(bRotate || SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_ROT_Y, true ,&pPoolItem))
nRotateY = rAttr.Get(SID_ATTR_TRANSFORM_ROT_Y).GetValue();
// shearing
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_SHEAR,true,&pPoolItem)) {
long nNewShearAngle=static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
if (nNewShearAngle>SDRMAXSHEAR) nNewShearAngle=SDRMAXSHEAR;
if (nNewShearAngle<-SDRMAXSHEAR) nNewShearAngle=-SDRMAXSHEAR;
if (nNewShearAngle!=nOldShearAngle) {
bShearVert=static_cast<const SfxBoolItem&>(rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_VERTICAL)).GetValue();
if (bShearVert) {
nShearAngle=nNewShearAngle;
} else {
if (nNewShearAngle!=0 && nOldShearAngle!=0) {
// bug fix
double nOld = tan(static_cast<double>(nOldShearAngle) * F_PI18000);
double nNew = tan(static_cast<double>(nNewShearAngle) * F_PI18000);
nNew-=nOld;
nNew = atan(nNew) / F_PI18000;
nShearAngle=FRound(nNew);
} else {
nShearAngle=nNewShearAngle-nOldShearAngle;
}
}
bShear=nShearAngle!=0;
if (bShear) {
nShearX=static_cast<const SfxInt32Item&>(rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_X)).GetValue();
nShearY=static_cast<const SfxInt32Item&>(rAttr.Get(SID_ATTR_TRANSFORM_SHEAR_Y)).GetValue();
}
}
}
// AutoGrow
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_AUTOWIDTH,true,&pPoolItem)) {
bool bAutoGrow=static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
aSetAttr.Put(makeSdrTextAutoGrowWidthItem(bAutoGrow));
bSetAttr=true;
}
if (SfxItemState::SET==rAttr.GetItemState(SID_ATTR_TRANSFORM_AUTOHEIGHT,true,&pPoolItem)) {
bool bAutoGrow=static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
aSetAttr.Put(makeSdrTextAutoGrowHeightItem(bAutoGrow));
bSetAttr=true;
}
// corner radius
if (m_bEdgeRadiusAllowed && SfxItemState::SET==rAttr.GetItemState(SDRATTR_ECKENRADIUS,true,&pPoolItem)) {
long nRadius=static_cast<const SdrMetricItem*>(pPoolItem)->GetValue();
aSetAttr.Put(makeSdrEckenradiusItem(nRadius));
bSetAttr=true;
}
ForcePossibilities();
BegUndo(SvxResId(STR_EditTransform),GetDescriptionOfMarkedObjects());
if (bSetAttr) {
SetAttrToMarked(aSetAttr,false);
}
// change size and height
if (bChgSiz && (m_bResizeFreeAllowed || m_bResizePropAllowed)) {
Fraction aWdt(nSizX,aRect.Right()-aRect.Left());
Fraction aHgt(nSizY,aRect.Bottom()-aRect.Top());
Point aRef(ImpGetPoint(aRect,eSizePoint));
if(GetSdrPageView())
{
GetSdrPageView()->PagePosToLogic(aRef);
}
ResizeMultMarkedObj(aRef, aWdt, aHgt, bChgWdh, bChgHgt);
}
// rotate
if (bRotate && (m_bRotateFreeAllowed || m_bRotate90Allowed)) {
Point aRef(nRotateX,nRotateY);
if(GetSdrPageView())
{
GetSdrPageView()->PagePosToLogic(aRef);
}
RotateMarkedObj(aRef,nRotateAngle);
}
// set rotation point position
if(bModeIsRotate && (nRotateX != nOldRotateX || nRotateY != nOldRotateY))
{
Point aNewRef1(nRotateX, nRotateY);
if(GetSdrPageView())
{
GetSdrPageView()->PagePosToLogic(aNewRef1);
}
SetRef1(aNewRef1);
}
// shear
if (bShear && m_bShearAllowed) {
Point aRef(nShearX,nShearY);
if(GetSdrPageView())
{
GetSdrPageView()->PagePosToLogic(aRef);
}
ShearMarkedObj(aRef,nShearAngle,bShearVert);
// #i74358#
// ShearMarkedObj creates a linear combination of the existing transformation and
// the new shear to apply. If the object is already transformed (e.g. rotated) the
// linear combination will not decompose to the same start values again, but to a
// new combination. Thus it makes no sense to check if the wanted shear is reached
// or not. Taking out.
}
// change position
if (bChgPos && m_bMoveAllowed) {
MoveMarkedObj(Size(nPosDX,nPosDY));
}
// protect position
if(SfxItemState::SET == rAttr.GetItemState(SID_ATTR_TRANSFORM_PROTECT_POS, true, &pPoolItem))
{
const bool bProtPos(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
bool bChanged(false);
for(size_t i = 0; i < nMarkCount; ++i)
{
pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
if(pObj->IsMoveProtect() != bProtPos)
{
bChanged = true;
pObj->SetMoveProtect(bProtPos);
if(bProtPos)
{
pObj->SetResizeProtect(true);
}
}
}
if(bChanged)
{
m_bMoveProtect = bProtPos;
if(bProtPos)
{
m_bResizeProtect = true;
}
// #i77187# there is no simple method to get the toolbars updated
// in the application. The App is listening to selection change and i
// will use it here (even if not true). It's acceptable since changing
// this model data is pretty rare and only possible using the F4 dialog
MarkListHasChanged();
}
}
if(!m_bMoveProtect)
{
// protect size
if(SfxItemState::SET == rAttr.GetItemState(SID_ATTR_TRANSFORM_PROTECT_SIZE, true, &pPoolItem))
{
const bool bProtSize(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
bool bChanged(false);
for(size_t i = 0; i < nMarkCount; ++i)
{
pObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
if(pObj->IsResizeProtect() != bProtSize)
{
bChanged = true;
pObj->SetResizeProtect(bProtSize);
}
}
if(bChanged)
{
m_bResizeProtect = bProtSize;
// #i77187# see above
MarkListHasChanged();
}
}
}
EndUndo();
}
bool SdrEditView::IsAlignPossible() const
{ // at least two selected objects, at least one of them movable
ForcePossibilities();
const size_t nCount=GetMarkedObjectCount();
if (nCount==0) return false; // nothing selected!
if (nCount==1) return m_bMoveAllowed; // align single object to page
return m_bOneOrMoreMovable; // otherwise: MarkCount>=2
}
void SdrEditView::AlignMarkedObjects(SdrHorAlign eHor, SdrVertAlign eVert)
{
if (eHor==SdrHorAlign::NONE && eVert==SdrVertAlign::NONE)
return;
SortMarkedObjects();
if (!GetMarkedObjectCount())
return;
const bool bUndo = IsUndoEnabled();
if( bUndo )
{
EndTextEditAllViews();
OUString aStr(GetDescriptionOfMarkedObjects());
if (eHor==SdrHorAlign::NONE)
{
switch (eVert)
{
case SdrVertAlign::Top:
aStr = ImpGetDescriptionString(STR_EditAlignVTop);
break;
case SdrVertAlign::Bottom:
aStr = ImpGetDescriptionString(STR_EditAlignVBottom);
break;
case SdrVertAlign::Center:
aStr = ImpGetDescriptionString(STR_EditAlignVCenter);
break;
default: break;
}
}
else if (eVert==SdrVertAlign::NONE)
{
switch (eHor)
{
case SdrHorAlign::Left:
aStr = ImpGetDescriptionString(STR_EditAlignHLeft);
break;
case SdrHorAlign::Right:
aStr = ImpGetDescriptionString(STR_EditAlignHRight);
break;
case SdrHorAlign::Center:
aStr = ImpGetDescriptionString(STR_EditAlignHCenter);
break;
default: break;
}
}
else if (eHor==SdrHorAlign::Center && eVert==SdrVertAlign::Center)
{
aStr = ImpGetDescriptionString(STR_EditAlignCenter);
}
else
{
aStr = ImpGetDescriptionString(STR_EditAlign);
}
BegUndo(aStr);
}
tools::Rectangle aBound;
const size_t nMarkCount=GetMarkedObjectCount();
bool bHasFixed=false;
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pObj=pM->GetMarkedSdrObj();
SdrObjTransformInfoRec aInfo;
pObj->TakeObjInfo(aInfo);
if (!aInfo.bMoveAllowed || pObj->IsMoveProtect())
{
tools::Rectangle aObjRect(pObj->GetSnapRect());
aBound.Union(aObjRect);
bHasFixed=true;
}
}
if (!bHasFixed)
{
if (nMarkCount==1)
{ // align single object to page
const SdrObject* pObj=GetMarkedObjectByIndex(0);
const SdrPage* pPage=pObj->getSdrPageFromSdrObject();
const SdrPageGridFrameList* pGFL=pPage->GetGridFrameList(GetSdrPageViewOfMarkedByIndex(0),&(pObj->GetSnapRect()));
const SdrPageGridFrame* pFrame=nullptr;
if (pGFL!=nullptr && pGFL->GetCount()!=0)
{ // Writer
pFrame=&((*pGFL)[0]);
}
if (pFrame!=nullptr)
{ // Writer
aBound=pFrame->GetUserArea();
}
else
{
aBound=tools::Rectangle(pPage->GetLeftBorder(),pPage->GetUpperBorder(),
pPage->GetWidth()-pPage->GetRightBorder(),
pPage->GetHeight()-pPage->GetLowerBorder());
}
}
else
{
aBound=GetMarkedObjRect();
}
}
Point aCenter(aBound.Center());
for (size_t nm=0; nm<nMarkCount; ++nm)
{
SdrMark* pM=GetSdrMarkByIndex(nm);
SdrObject* pObj=pM->GetMarkedSdrObj();
SdrObjTransformInfoRec aInfo;
pObj->TakeObjInfo(aInfo);
if (aInfo.bMoveAllowed && !pObj->IsMoveProtect())
{
long nXMov=0;
long nYMov=0;
tools::Rectangle aObjRect(pObj->GetSnapRect());
switch (eVert)
{
case SdrVertAlign::Top : nYMov=aBound.Top() -aObjRect.Top() ; break;
case SdrVertAlign::Bottom: nYMov=aBound.Bottom()-aObjRect.Bottom() ; break;
case SdrVertAlign::Center: nYMov=aCenter.Y() -aObjRect.Center().Y(); break;
default: break;
}
switch (eHor)
{
case SdrHorAlign::Left : nXMov=aBound.Left() -aObjRect.Left() ; break;
case SdrHorAlign::Right : nXMov=aBound.Right() -aObjRect.Right() ; break;
case SdrHorAlign::Center: nXMov=aCenter.X() -aObjRect.Center().X(); break;
default: break;
}
if (nXMov!=0 || nYMov!=0)
{
// SdrEdgeObj needs an extra SdrUndoGeoObj since the
// connections may need to be saved
if( bUndo )
{
if( dynamic_cast<SdrEdgeObj*>(pObj) )
{
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
}
AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pObj,Size(nXMov,nYMov)));
}
pObj->Move(Size(nXMov,nYMov));
}
}
}
if( bUndo )
EndUndo();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|