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 | /* -*- 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/.
*/
#include <test/bootstrapfixture.hxx>
#include <test/helper/transferable.hxx>
#include <unotest/macros_test.hxx>
#include <test/xmltesttools.hxx>
#include <boost/property_tree/json_parser.hpp>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/DispatchHelper.hpp>
#include <com/sun/star/datatransfer/clipboard/SystemClipboard.hpp>
#include <com/sun/star/datatransfer/UnsupportedFlavorException.hpp>
#include <comphelper/dispatchcommand.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
#include <osl/conditn.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/viewfrm.hxx>
#include <svl/stritem.hxx>
#include <comphelper/lok.hxx>
#include <comphelper/propertyvalue.hxx>
#include <sfx2/childwin.hxx>
#include <sfx2/lokhelper.hxx>
#include <svx/svdpage.hxx>
#include <vcl/svapp.hxx>
#include <vcl/scheduler.hxx>
#include <vcl/vclevent.hxx>
#include <vcl/virdev.hxx>
#include <vcl/unohelp2.hxx>
#include <sc.hrc>
#include <comphelper/string.hxx>
#include <chrono>
#include <cstddef>
#include <tabvwsh.hxx>
#include <docsh.hxx>
#include <document.hxx>
#include <docuno.hxx>
#include <drwlayer.hxx>
using namespace css;
static std::ostream& operator<<(std::ostream& os, ViewShellId const & id)
{
os << static_cast<sal_Int32>(id); return os;
}
namespace
{
char const DATA_DIRECTORY[] = "/sc/qa/unit/tiledrendering/data/";
class ScTiledRenderingTest : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools
{
public:
ScTiledRenderingTest();
virtual void setUp() override;
virtual void tearDown() override;
void testRowColumnHeaders();
void testRowColumnSelections();
void testSortAscendingDescending();
void testPartHash();
void testDocumentSize();
void testEmptyColumnSelection();
void testViewCursors();
void testTextViewSelection();
void testDocumentSizeChanged();
void testViewLock();
void testColRowResize();
void testUndoShells();
void testCreateViewGraphicSelection();
void testTextEditViews();
void testTextEditViewInvalidations();
void testGraphicInvalidate();
void testAutoSum();
void testHideColRow();
void testInvalidateOnCopyPasteCells();
void testInvalidateOnInserRowCol();
void testCommentCallback();
void testUndoLimiting();
void testUndoRepairDispatch();
void testInsertGraphicInvalidations();
void testDocumentSizeWithTwoViews();
void testDisableUndoRepair();
void testDocumentRepair();
void testLanguageStatus();
void testMultiViewCopyPaste();
void testIMESupport();
void testFilterDlg();
void testVbaRangeCopyPaste();
void testInvalidationLoop();
void testPageDownInvalidation();
void testSheetChangeInvalidation();
void testInsertDeletePageInvalidation();
void testGetRowColumnHeadersInvalidation();
void testJumpHorizontallyInvalidation();
void testJumpToLastRowInvalidation();
CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
CPPUNIT_TEST(testRowColumnHeaders);
CPPUNIT_TEST(testRowColumnSelections);
CPPUNIT_TEST(testSortAscendingDescending);
CPPUNIT_TEST(testPartHash);
CPPUNIT_TEST(testDocumentSize);
CPPUNIT_TEST(testEmptyColumnSelection);
CPPUNIT_TEST(testViewCursors);
CPPUNIT_TEST(testTextViewSelection);
CPPUNIT_TEST(testDocumentSizeChanged);
CPPUNIT_TEST(testViewLock);
CPPUNIT_TEST(testColRowResize);
CPPUNIT_TEST(testUndoShells);
CPPUNIT_TEST(testCreateViewGraphicSelection);
CPPUNIT_TEST(testTextEditViews);
CPPUNIT_TEST(testTextEditViewInvalidations);
CPPUNIT_TEST(testGraphicInvalidate);
CPPUNIT_TEST(testAutoSum);
CPPUNIT_TEST(testHideColRow);
CPPUNIT_TEST(testInvalidateOnCopyPasteCells);
CPPUNIT_TEST(testInvalidateOnInserRowCol);
CPPUNIT_TEST(testCommentCallback);
CPPUNIT_TEST(testUndoLimiting);
CPPUNIT_TEST(testUndoRepairDispatch);
CPPUNIT_TEST(testInsertGraphicInvalidations);
CPPUNIT_TEST(testDocumentSizeWithTwoViews);
CPPUNIT_TEST(testDisableUndoRepair);
CPPUNIT_TEST(testDocumentRepair);
CPPUNIT_TEST(testLanguageStatus);
CPPUNIT_TEST(testMultiViewCopyPaste);
CPPUNIT_TEST(testIMESupport);
CPPUNIT_TEST(testFilterDlg);
CPPUNIT_TEST(testVbaRangeCopyPaste);
CPPUNIT_TEST(testInvalidationLoop);
CPPUNIT_TEST(testPageDownInvalidation);
CPPUNIT_TEST(testSheetChangeInvalidation);
CPPUNIT_TEST(testInsertDeletePageInvalidation);
CPPUNIT_TEST(testGetRowColumnHeadersInvalidation);
CPPUNIT_TEST(testJumpHorizontallyInvalidation);
CPPUNIT_TEST(testJumpToLastRowInvalidation);
CPPUNIT_TEST_SUITE_END();
private:
ScModelObj* createDoc(const char* pName);
static void callback(int nType, const char* pPayload, void* pData);
void callbackImpl(int nType, const char* pPayload);
/// document size changed callback.
osl::Condition m_aDocSizeCondition;
Size m_aDocumentSize;
uno::Reference<lang::XComponent> mxComponent;
};
ScTiledRenderingTest::ScTiledRenderingTest()
{
}
void ScTiledRenderingTest::setUp()
{
test::BootstrapFixture::setUp();
mxDesktop.set(css::frame::Desktop::create(comphelper::getComponentContext(getMultiServiceFactory())));
}
void ScTiledRenderingTest::tearDown()
{
if (mxComponent.is())
{
ScModelObj* pModelObj = static_cast<ScModelObj*>(mxComponent.get());
ScDocShell* pDocSh = dynamic_cast< ScDocShell* >( pModelObj->GetEmbeddedObject() );
if (pDocSh)
{
ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
if (pViewShell)
{
// The current view is unregistered here, multiple views have to be unregistered
// in the test function itself.
pViewShell->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
}
mxComponent->dispose();
}
comphelper::LibreOfficeKit::setActive(false);
test::BootstrapFixture::tearDown();
}
ScModelObj* ScTiledRenderingTest::createDoc(const char* pName)
{
if (mxComponent.is())
mxComponent->dispose();
mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) + OUString::createFromAscii(pName), "com.sun.star.sheet.SpreadsheetDocument");
ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(mxComponent.get());
CPPUNIT_ASSERT(pModelObj);
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
return pModelObj;
}
void ScTiledRenderingTest::callback(int nType, const char* pPayload, void* pData)
{
static_cast<ScTiledRenderingTest*>(pData)->callbackImpl(nType, pPayload);
}
/* TODO when needed...
static std::vector<OUString> lcl_convertSeparated(const OUString& rString, sal_Unicode nSeparator)
{
std::vector<OUString> aRet;
sal_Int32 nIndex = 0;
do
{
OUString aToken = rString.getToken(0, nSeparator, nIndex);
aToken = aToken.trim();
if (!aToken.isEmpty())
aRet.push_back(aToken);
}
while (nIndex >= 0);
return aRet;
}
static void lcl_convertRectangle(const OUString& rString, Rectangle& rRectangle)
{
uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(rString);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aSeq.getLength());
rRectangle.setX(aSeq[0].toInt32());
rRectangle.setY(aSeq[1].toInt32());
rRectangle.setWidth(aSeq[2].toInt32());
rRectangle.setHeight(aSeq[3].toInt32());
}
*/
void ScTiledRenderingTest::callbackImpl(int nType, const char* pPayload)
{
switch (nType)
{
case LOK_CALLBACK_DOCUMENT_SIZE_CHANGED:
{
OString aPayload(pPayload);
sal_Int32 nIndex = 0;
OString aToken = aPayload.getToken(0, ',', nIndex);
m_aDocumentSize.setWidth(aToken.toInt32());
aToken = aPayload.getToken(0, ',', nIndex);
m_aDocumentSize.setHeight(aToken.toInt32());
m_aDocSizeCondition.set();
}
break;
}
}
void ScTiledRenderingTest::testRowColumnSelections()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("select-row-cols.ods");
// Select the 5th row with no modifier
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "Row", uno::Any(sal_Int32(5 - 1)) },
{ "Modifier", uno::Any(sal_uInt16(0)) }
}));
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
// Check if it is selected
OString aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
OString aExpected("1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\n");
CPPUNIT_ASSERT_EQUAL(aExpected, aResult);
// Select the 10th row with shift modifier
aArgs[0].Name = "Row";
aArgs[0].Value <<= static_cast<sal_Int32>(10 - 1);
aArgs[1].Name = "Modifier";
aArgs[1].Value <<= KEY_SHIFT;
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
// Check if all the rows from 5th to 10th get selected
aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
aExpected = "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\n2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\n3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\n4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\n5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\n6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\t22\t23\t24\t25\t26\n";
CPPUNIT_ASSERT_EQUAL(aExpected, aResult);
// Select the 10th row with ctrl modifier
aArgs[0].Name = "Row";
aArgs[0].Value <<= static_cast<sal_Int32>(13 - 1);
aArgs[1].Name = "Modifier";
aArgs[1].Value <<= KEY_MOD1;
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
// When we copy this, we don't get anything useful, but we must not crash
// (used to happen)
aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
CPPUNIT_ASSERT_EQUAL(OString(), aResult);
// TODO check that we really selected what we wanted here
// Select Column 5 with ctrl modifier
aArgs[0].Name = "Col";
aArgs[0].Value <<= static_cast<sal_Int32>(5 - 1);
aArgs[1].Name = "Modifier";
aArgs[1].Value <<= KEY_MOD1;
comphelper::dispatchCommand(".uno:SelectColumn", aArgs);
// When we copy this, we don't get anything useful, but we must not crash
// (used to happen)
aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
CPPUNIT_ASSERT_EQUAL(OString(), aResult);
// TODO check that we really selected what we wanted here
// Test for deselection of already selected rows
// First Deselect Row 13 because copy doesn't work for multiple selections
aArgs[0].Name = "Row";
aArgs[0].Value <<= static_cast<sal_Int32>(13 - 1);
aArgs[1].Name = "Modifier";
aArgs[1].Value <<= KEY_MOD1;
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
// Deselect row 10
aArgs[0].Name = "Row";
aArgs[0].Value <<= static_cast<sal_Int32>(10 - 1);
aArgs[1].Name = "Modifier";
aArgs[1].Value <<= KEY_MOD1;
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
// Click at row 6 holding shift
aArgs[0].Name = "Row";
aArgs[0].Value <<= static_cast<sal_Int32>(6 - 1);
aArgs[1].Name = "Modifier";
aArgs[1].Value <<= KEY_SHIFT;
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
// only row 5 should remain selected
aResult = apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8");
aExpected = "1\t2\t3\t4\t5\t6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16\t17\t18\t19\t20\t21\n";
CPPUNIT_ASSERT_EQUAL(aExpected, aResult);
}
void ScTiledRenderingTest::testSortAscendingDescending()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("sort-range.ods");
ScDocument* pDoc = pModelObj->GetDocument();
// select the values in the first column
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, 551, 129, 1, MOUSE_LEFT, 0);
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEMOVE, 820, 1336, 1, MOUSE_LEFT, 0);
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, 820, 1359, 1, MOUSE_LEFT, 0);
Scheduler::ProcessEventsToIdle();
// sort ascending
uno::Sequence<beans::PropertyValue> aArgs;
comphelper::dispatchCommand(".uno:SortAscending", aArgs);
// check it's sorted
for (SCROW r = 0; r < 6; ++r)
{
CPPUNIT_ASSERT_EQUAL(double(r + 1), pDoc->GetValue(ScAddress(0, r, 0)));
}
// sort descending
comphelper::dispatchCommand(".uno:SortDescending", aArgs);
// check it's sorted
for (SCROW r = 0; r < 6; ++r)
{
CPPUNIT_ASSERT_EQUAL(double(6 - r), pDoc->GetValue(ScAddress(0, r, 0)));
}
// nothing else was sorted
CPPUNIT_ASSERT_EQUAL(double(1), pDoc->GetValue(ScAddress(1, 0, 0)));
CPPUNIT_ASSERT_EQUAL(double(3), pDoc->GetValue(ScAddress(1, 1, 0)));
CPPUNIT_ASSERT_EQUAL(double(2), pDoc->GetValue(ScAddress(1, 2, 0)));
}
void ScTiledRenderingTest::testPartHash()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("sort-range.ods");
int nParts = pModelObj->getParts();
for (int it = 0; it < nParts; it++)
{
CPPUNIT_ASSERT(!pModelObj->getPartHash(it).isEmpty());
}
// check part that it does not exists
CPPUNIT_ASSERT(pModelObj->getPartHash(100).isEmpty());
}
void ScTiledRenderingTest::testDocumentSize()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("sort-range.ods");
ScDocShell* pDocSh = dynamic_cast< ScDocShell* >( pModelObj->GetEmbeddedObject() );
CPPUNIT_ASSERT(pDocSh);
ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
CPPUNIT_ASSERT(pViewShell);
pViewShell->registerLibreOfficeKitViewCallback(&ScTiledRenderingTest::callback, this);
// check initial document size
Size aDocSize = pModelObj->getDocumentSize();
CPPUNIT_ASSERT(aDocSize.Width() > 0);
CPPUNIT_ASSERT(aDocSize.Height() > 0);
// Set cursor column
pViewShell->SetCursor(100, 0);
// 2 seconds
osl::Condition::Result aResult = m_aDocSizeCondition.wait(std::chrono::seconds(2));
CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok, aResult);
// Set cursor row
pViewShell->SetCursor(0, 100);
// 2 seconds
aResult = m_aDocSizeCondition.wait(std::chrono::seconds(2));
CPPUNIT_ASSERT_EQUAL(osl::Condition::result_ok, aResult);
}
void ScTiledRenderingTest::testEmptyColumnSelection()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("select-row-cols.ods");
// Select empty column, 1000
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "Col", uno::Any(sal_Int32(1000 - 1)) },
{ "Modifier", uno::Any(sal_uInt16(0)) }
}));
comphelper::dispatchCommand(".uno:SelectColumn", aArgs);
// should be an empty string
CPPUNIT_ASSERT_EQUAL(OString(), apitest::helper::transferable::getTextSelection(pModelObj->getSelection(), "text/plain;charset=utf-8"));
}
/// A view callback tracks callbacks invoked on one specific view.
class ViewCallback
{
SfxViewShell* mpViewShell;
int mnView;
public:
bool m_bOwnCursorInvalidated;
bool m_bViewCursorInvalidated;
bool m_bTextViewSelectionInvalidated;
bool m_bGraphicSelection;
bool m_bGraphicViewSelection;
bool m_bFullInvalidateTiles;
bool m_bInvalidateTiles;
std::vector<tools::Rectangle> m_aInvalidations;
std::vector<int> m_aInvalidationsParts;
bool m_bViewLock;
OString m_sCellFormula;
boost::property_tree::ptree m_aCommentCallbackResult;
ViewCallback(bool bDeleteListenerOnDestruct=true)
: m_bOwnCursorInvalidated(false),
m_bViewCursorInvalidated(false),
m_bTextViewSelectionInvalidated(false),
m_bGraphicSelection(false),
m_bGraphicViewSelection(false),
m_bFullInvalidateTiles(false),
m_bInvalidateTiles(false),
m_bViewLock(false)
{
mpViewShell = SfxViewShell::Current();
mpViewShell->registerLibreOfficeKitViewCallback(&ViewCallback::callback, this);
mnView = SfxLokHelper::getView();
if (!bDeleteListenerOnDestruct)
mpViewShell = nullptr;
}
~ViewCallback()
{
if (mpViewShell)
{
SfxLokHelper::setView(mnView);
mpViewShell->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
}
static void callback(int nType, const char* pPayload, void* pData)
{
static_cast<ViewCallback*>(pData)->callbackImpl(nType, pPayload);
}
void callbackImpl(int nType, const char* pPayload)
{
switch (nType)
{
case LOK_CALLBACK_CELL_CURSOR:
{
m_bOwnCursorInvalidated = true;
}
break;
case LOK_CALLBACK_CELL_VIEW_CURSOR:
{
m_bViewCursorInvalidated = true;
}
break;
case LOK_CALLBACK_TEXT_VIEW_SELECTION:
{
m_bTextViewSelectionInvalidated = true;
}
break;
case LOK_CALLBACK_VIEW_LOCK:
{
std::stringstream aStream(pPayload);
boost::property_tree::ptree aTree;
boost::property_tree::read_json(aStream, aTree);
m_bViewLock = aTree.get_child("rectangle").get_value<std::string>() != "EMPTY";
}
break;
case LOK_CALLBACK_GRAPHIC_SELECTION:
{
m_bGraphicSelection = true;
}
break;
case LOK_CALLBACK_GRAPHIC_VIEW_SELECTION:
{
m_bGraphicViewSelection = true;
}
break;
case LOK_CALLBACK_INVALIDATE_TILES:
{
OString text(pPayload);
if (text.startsWith("EMPTY"))
{
m_bFullInvalidateTiles = true;
}
else
{
uno::Sequence<OUString> aSeq = comphelper::string::convertCommaSeparated(OUString::createFromAscii(pPayload));
CPPUNIT_ASSERT(aSeq.getLength() == 4 || aSeq.getLength() == 5);
tools::Rectangle aInvalidationRect;
aInvalidationRect.setX(aSeq[0].toInt32());
aInvalidationRect.setY(aSeq[1].toInt32());
aInvalidationRect.setWidth(aSeq[2].toInt32());
aInvalidationRect.setHeight(aSeq[3].toInt32());
m_aInvalidations.push_back(aInvalidationRect);
if (aSeq.getLength() == 5)
m_aInvalidationsParts.push_back(aSeq[4].toInt32());
m_bInvalidateTiles = true;
}
}
break;
case LOK_CALLBACK_CELL_FORMULA:
{
m_sCellFormula = pPayload;
}
break;
case LOK_CALLBACK_COMMENT:
{
m_aCommentCallbackResult.clear();
std::stringstream aStream(pPayload);
boost::property_tree::read_json(aStream, m_aCommentCallbackResult);
m_aCommentCallbackResult = m_aCommentCallbackResult.get_child("comment");
}
break;
}
}
};
void ScTiledRenderingTest::testViewCursors()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("select-row-cols.ods");
ViewCallback aView1;
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2(/*bDeleteListenerOnDestruct*/false);
// This was false, the new view did not get the view (cell) cursor of the old view.
CPPUNIT_ASSERT(aView2.m_bViewCursorInvalidated);
CPPUNIT_ASSERT(aView2.m_bOwnCursorInvalidated);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DOWN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::DOWN);
Scheduler::ProcessEventsToIdle();
SfxLokHelper::destroyView(SfxLokHelper::getView());
CPPUNIT_ASSERT(aView1.m_bViewCursorInvalidated);
}
void ScTiledRenderingTest::testTextViewSelection()
{
comphelper::LibreOfficeKit::setActive();
// Create two views, and leave the second one current.
ScModelObj* pModelObj = createDoc("select-row-cols.ods");
ViewCallback aView1;
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
// Create a selection on two cells in the second view, that's a text selection in LOK terms.
aView1.m_bTextViewSelectionInvalidated = false;
dispatchCommand(mxComponent, ".uno:GoRightSel", {});
Scheduler::ProcessEventsToIdle();
// Make sure the first view got its notification.
CPPUNIT_ASSERT(aView1.m_bTextViewSelectionInvalidated);
}
void ScTiledRenderingTest::testDocumentSizeChanged()
{
comphelper::LibreOfficeKit::setActive();
// Load a document that doesn't have much content.
createDoc("small.ods");
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ScTiledRenderingTest::callback, this);
// Go to the A30 cell -- that will extend the document size.
uno::Sequence<beans::PropertyValue> aPropertyValues =
{
comphelper::makePropertyValue("ToPoint", OUString("$A$30")),
};
dispatchCommand(mxComponent, ".uno:GoToCell", aPropertyValues);
Scheduler::ProcessEventsToIdle();
// Assert that the size in the payload is not 0.
CPPUNIT_ASSERT(m_aDocumentSize.getWidth() > 0);
CPPUNIT_ASSERT(m_aDocumentSize.getHeight() > 0);
}
void ScTiledRenderingTest::testViewLock()
{
comphelper::LibreOfficeKit::setActive();
// Load a document that has a shape and create two views.
ScModelObj* pModelObj = createDoc("shape.ods");
ViewCallback aView1;
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
// Begin text edit in the second view and assert that the first gets a lock
// notification.
const ScViewData* pViewData = ScDocShell::GetViewData();
ScTabViewShell* pViewShell = pViewData->GetViewShell();
CPPUNIT_ASSERT(pViewShell);
SdrModel* pDrawModel = pViewData->GetDocument()->GetDrawLayer();
SdrPage* pDrawPage = pDrawModel->GetPage(0);
SdrObject* pObject = pDrawPage->GetObj(0);
SdrView* pView = pViewShell->GetScDrawView();
aView1.m_bViewLock = false;
pView->SdrBeginTextEdit(pObject);
CPPUNIT_ASSERT(aView1.m_bViewLock);
// End text edit in the second view, and assert that the lock is removed in
// the first view.
pView->SdrEndTextEdit();
CPPUNIT_ASSERT(!aView1.m_bViewLock);
}
void ScTiledRenderingTest::testColRowResize()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("sort-range.ods");
ScDocShell* pDocSh = dynamic_cast< ScDocShell* >( pModelObj->GetEmbeddedObject() );
CPPUNIT_ASSERT(pDocSh);
ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
CPPUNIT_ASSERT(pViewShell);
pViewShell->registerLibreOfficeKitViewCallback(&ScTiledRenderingTest::callback, this);
ScDocument& rDoc = pDocSh->GetDocument();
// Col 3, Tab 0
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "ColumnWidth", uno::Any(sal_uInt16(4000)) }, // 4cm
{ "Column", uno::Any(sal_Int16(3)) }
}));
comphelper::dispatchCommand(".uno:ColumnWidth", aArgs);
sal_uInt16 nWidth = rDoc.GetColWidth(static_cast<SCCOL>(2), static_cast<SCTAB>(0), false) * HMM_PER_TWIPS;
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4000), nWidth);
// Row 5, Tab 0
uno::Sequence<beans::PropertyValue> aArgs2( comphelper::InitPropertySequence({
{ "RowHeight", uno::Any(sal_uInt16(2000)) },
{ "Row", uno::Any(sal_Int16(5)) },
}));
comphelper::dispatchCommand(".uno:RowHeight", aArgs2);
sal_uInt16 nHeight = rDoc.GetRowHeight(static_cast<SCROW>(4), static_cast<SCTAB>(0), false) * HMM_PER_TWIPS;
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2000), nHeight);
}
void ScTiledRenderingTest::testUndoShells()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
// Clear the currently selected cell.
comphelper::dispatchCommand(".uno:ClearContents", {});
auto pDocShell = dynamic_cast<ScDocShell*>(pModelObj->GetEmbeddedObject());
CPPUNIT_ASSERT(pDocShell);
ScDocument& rDoc = pDocShell->GetDocument();
SfxUndoManager* pUndoManager = rDoc.GetUndoManager();
CPPUNIT_ASSERT(pUndoManager);
CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetUndoActionCount());
sal_Int32 nView1 = SfxLokHelper::getView();
// This was -1: ScSimpleUndo did not remember what view shell created it.
CPPUNIT_ASSERT_EQUAL(ViewShellId(nView1), pUndoManager->GetUndoAction()->GetViewShellId());
}
bool lcl_hasEditView(const ScViewData& rViewData)
{
bool bResult = false;
for (unsigned int i=0; i<4; i++)
{
bResult = rViewData.HasEditView( static_cast<ScSplitPos>(i) );
if (bResult) break;
}
return bResult;
}
void ScTiledRenderingTest::testTextEditViews()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
// view #1
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
// text edit a cell in view #1
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(lcl_hasEditView(*pViewData));
// view #2
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
// move cell cursor i view #2
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DOWN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::DOWN);
Scheduler::ProcessEventsToIdle();
// check that text edit view in view #1 has not be killed
CPPUNIT_ASSERT(lcl_hasEditView(*pViewData));
}
void ScTiledRenderingTest::testTextEditViewInvalidations()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
// view #1
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
// view #2
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
// text edit a cell in view #1
SfxLokHelper::setView(nView1);
aView2.m_bInvalidateTiles = false;
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(lcl_hasEditView(*pViewData));
CPPUNIT_ASSERT(aView2.m_bInvalidateTiles);
// text edit a cell in view #1 until
// we can be sure we are out of the initial tile
for (int i = 0; i < 40; ++i)
{
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
}
Scheduler::ProcessEventsToIdle();
// text edit a cell in view #1 inside the new tile and
// check that view #2 receive a tile invalidate message
aView2.m_bInvalidateTiles = false;
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView2.m_bInvalidateTiles);
// view #3
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView3;
// text edit a cell in view #1
SfxLokHelper::setView(nView1);
aView3.m_bInvalidateTiles = false;
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'y', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'y', 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView3.m_bInvalidateTiles);
}
void ScTiledRenderingTest::testCreateViewGraphicSelection()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
// Load a document that has a shape and create two views.
ScModelObj* pModelObj = createDoc("shape.ods");
ViewCallback aView1;
// Mark the graphic in the first view.
const ScViewData* pViewData = ScDocShell::GetViewData();
ScTabViewShell* pViewShell = pViewData->GetViewShell();
CPPUNIT_ASSERT(pViewShell);
SdrModel* pDrawModel = pViewData->GetDocument()->GetDrawLayer();
SdrPage* pDrawPage = pDrawModel->GetPage(0);
SdrObject* pObject = pDrawPage->GetObj(0);
SdrView* pView = pViewShell->GetScDrawView();
aView1.m_bGraphicSelection = false;
aView1.m_bGraphicViewSelection = false;
pView->MarkObj(pObject, pView->GetSdrPageView());
CPPUNIT_ASSERT(aView1.m_bGraphicSelection);
// Create a second view.
int nView1 = SfxLokHelper::getView();
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
CPPUNIT_ASSERT(aView2.m_bGraphicViewSelection);
CPPUNIT_ASSERT(aView1.m_bGraphicViewSelection);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testGraphicInvalidate()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
// Load a document that has a shape and create two views.
ScModelObj* pModelObj = createDoc("shape.ods");
ViewCallback aView;
// Click to select graphic
aView.m_bGraphicSelection = false;
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, /*x=*/ 1,/*y=*/ 1,/*count=*/ 1, /*buttons=*/ 1, /*modifier=*/0);
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, /*x=*/ 1, /*y=*/ 1, /*count=*/ 1, /*buttons=*/ 1, /*modifier=*/0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_bGraphicSelection);
// Drag Drop graphic
aView.m_bGraphicSelection = false;
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONDOWN, /*x=*/ 1,/*y=*/ 1,/*count=*/ 1, /*buttons=*/ 1, /*modifier=*/0);
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEMOVE, /*x=*/ 1,/*y=*/ 10,/*count=*/ 1, /*buttons=*/ 1, /*modifier=*/0);
pModelObj->postMouseEvent(LOK_MOUSEEVENT_MOUSEBUTTONUP, /*x=*/ 1, /*y=*/ 10, /*count=*/ 1, /*buttons=*/ 1, /*modifier=*/0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(!aView.m_bFullInvalidateTiles);
// Check again
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(!aView.m_bFullInvalidateTiles);
}
void ScTiledRenderingTest::testAutoSum()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
createDoc("small.ods");
ViewCallback aView;
uno::Sequence<beans::PropertyValue> aArgs;
comphelper::dispatchCommand(".uno:AutoSum", aArgs);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_sCellFormula.startsWith("=SUM("));
}
void ScTiledRenderingTest::testHideColRow()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
createDoc("small.ods");
{
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "Col", uno::Any(sal_Int32(2 - 1)) },
{ "Modifier", uno::Any(KEY_SHIFT) }
}));
comphelper::dispatchCommand(".uno:SelectColumn", aArgs);
uno::Sequence<beans::PropertyValue> aArgs2( comphelper::InitPropertySequence({
{ "Col", uno::Any(sal_Int32(3 - 1)) },
{ "Modifier", uno::Any(sal_uInt16(0)) }
}));
comphelper::dispatchCommand(".uno:SelectColumn", aArgs2);
Scheduler::ProcessEventsToIdle();
}
SCCOL nOldCurX = ScDocShell::GetViewData()->GetCurX();
SCROW nOldCurY = ScDocShell::GetViewData()->GetCurY();
{
uno::Sequence<beans::PropertyValue> aArgs;
comphelper::dispatchCommand(".uno:HideColumn", aArgs);
Scheduler::ProcessEventsToIdle();
}
SCCOL nNewCurX = ScDocShell::GetViewData()->GetCurX();
SCROW nNewCurY = ScDocShell::GetViewData()->GetCurY();
CPPUNIT_ASSERT(nNewCurX > nOldCurX);
CPPUNIT_ASSERT_EQUAL(nOldCurY, nNewCurY);
{
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "Row", uno::Any(sal_Int32(6 - 1)) },
{ "Modifier", uno::Any(KEY_SHIFT) }
}));
comphelper::dispatchCommand(".uno:SelectRow", aArgs);
uno::Sequence<beans::PropertyValue> aArgs2( comphelper::InitPropertySequence({
{ "Row", uno::Any(sal_Int32(7 - 1)) },
{ "Modifier", uno::Any(sal_uInt16(0)) }
}));
comphelper::dispatchCommand(".uno:SelectRow", aArgs2);
Scheduler::ProcessEventsToIdle();
}
nOldCurX = ScDocShell::GetViewData()->GetCurX();
nOldCurY = ScDocShell::GetViewData()->GetCurY();
{
uno::Sequence<beans::PropertyValue> aArgs;
comphelper::dispatchCommand(".uno:HideRow", aArgs);
Scheduler::ProcessEventsToIdle();
}
nNewCurX = ScDocShell::GetViewData()->GetCurX();
nNewCurY = ScDocShell::GetViewData()->GetCurY();
CPPUNIT_ASSERT(nNewCurY > nOldCurY);
CPPUNIT_ASSERT_EQUAL(nOldCurX, nNewCurX);
}
void ScTiledRenderingTest::testInvalidateOnCopyPasteCells()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
// view
ViewCallback aView;
uno::Sequence<beans::PropertyValue> aArgs;
// select and copy cells
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME | KEY_MOD1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME | KEY_MOD1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN | KEY_SHIFT);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN | KEY_SHIFT);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT | KEY_SHIFT);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RIGHT | KEY_SHIFT);
Scheduler::ProcessEventsToIdle();
comphelper::dispatchCommand(".uno:Copy", aArgs);
// move to destination cell
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN | KEY_MOD1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN | KEY_MOD1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_UP);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_UP);
Scheduler::ProcessEventsToIdle();
// paste cells
aView.m_bInvalidateTiles = false;
comphelper::dispatchCommand(".uno:Paste", aArgs);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_bInvalidateTiles);
}
void ScTiledRenderingTest::testInvalidateOnInserRowCol()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
// view
ViewCallback aView;
uno::Sequence<beans::PropertyValue> aArgs;
// move downward
for (int i = 0; i < 200; ++i)
{
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN);
}
Scheduler::ProcessEventsToIdle();
// insert row
aView.m_bInvalidateTiles = false;
aView.m_aInvalidations.clear();
comphelper::dispatchCommand(".uno:InsertRows", aArgs);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(2), aView.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(-75, 50985, 32212230, 63990), aView.m_aInvalidations[0]);
// move on the right
for (int i = 0; i < 200; ++i)
{
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RIGHT);
}
Scheduler::ProcessEventsToIdle();
// insert column
aView.m_bInvalidateTiles = false;
aView.m_aInvalidations.clear();
comphelper::dispatchCommand(".uno:InsertColumns", aArgs);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(2), aView.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(253650, -15, 32212230, 63990), aView.m_aInvalidations[0]);
}
void ScTiledRenderingTest::testCommentCallback()
{
// Load a document
comphelper::LibreOfficeKit::setActive();
// Comments callback are emitted only if tiled annotations are off
comphelper::LibreOfficeKit::setTiledAnnotations(false);
{
ScModelObj* pModelObj = createDoc("small.ods");
ViewCallback aView1;
int nView1 = SfxLokHelper::getView();
// Create a 2nd view
SfxLokHelper::createView();
pModelObj->initializeForTiledRendering({});
ViewCallback aView2;
SfxLokHelper::setView(nView1);
// Add a new comment
uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
{
{"Text", uno::makeAny(OUString("Comment"))},
{"Author", uno::makeAny(OUString("LOK User1"))},
}));
comphelper::dispatchCommand(".uno:InsertAnnotation", aArgs);
Scheduler::ProcessEventsToIdle();
// We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action
CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("1"), aView1.m_aCommentCallbackResult.get<std::string>("id"));
CPPUNIT_ASSERT_EQUAL(std::string("1"), aView2.m_aCommentCallbackResult.get<std::string>("id"));
CPPUNIT_ASSERT_EQUAL(std::string("0"), aView1.m_aCommentCallbackResult.get<std::string>("tab"));
CPPUNIT_ASSERT_EQUAL(std::string("0"), aView2.m_aCommentCallbackResult.get<std::string>("tab"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView1.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User1"), aView2.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView2.m_aCommentCallbackResult.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos"));
CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
std::string aCommentId = aView1.m_aCommentCallbackResult.get<std::string>("id");
// Edit a comment
// Select some random cell, we should be able to edit the cell note without
// selecting the cell
ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
if (pTabViewShell)
pTabViewShell->SetCursor(3, 100);
aArgs = comphelper::InitPropertySequence(
{
{"Id", uno::makeAny(OUString::createFromAscii(aCommentId.c_str()))},
{"Text", uno::makeAny(OUString("Edited comment"))},
{"Author", uno::makeAny(OUString("LOK User2"))},
});
comphelper::dispatchCommand(".uno:EditAnnotation", aArgs);
Scheduler::ProcessEventsToIdle();
// We received a LOK_CALLBACK_COMMENT callback with comment 'Modify' action
CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(aCommentId, aView1.m_aCommentCallbackResult.get<std::string>("id"));
CPPUNIT_ASSERT_EQUAL(aCommentId, aView2.m_aCommentCallbackResult.get<std::string>("id"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView1.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("LOK User2"), aView2.m_aCommentCallbackResult.get<std::string>("author"));
CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView1.m_aCommentCallbackResult.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("Edited comment"), aView2.m_aCommentCallbackResult.get<std::string>("text"));
CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView1.m_aCommentCallbackResult.get<std::string>("cellPos"));
CPPUNIT_ASSERT_EQUAL(std::string("0, 255, 1274, 254"), aView2.m_aCommentCallbackResult.get<std::string>("cellPos"));
// Delete the comment
if (pTabViewShell)
pTabViewShell->SetCursor(4, 43);
aArgs = comphelper::InitPropertySequence(
{
{"Id", uno::makeAny(OUString::createFromAscii(aCommentId.c_str()))}
});
comphelper::dispatchCommand(".uno:DeleteNote", aArgs);
Scheduler::ProcessEventsToIdle();
// We received a LOK_CALLBACK_COMMENT callback with comment 'Remove' action
CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView1.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(std::string("Remove"), aView2.m_aCommentCallbackResult.get<std::string>("action"));
CPPUNIT_ASSERT_EQUAL(aCommentId, aView1.m_aCommentCallbackResult.get<std::string>("id"));
CPPUNIT_ASSERT_EQUAL(aCommentId, aView2.m_aCommentCallbackResult.get<std::string>("id"));
}
comphelper::LibreOfficeKit::setTiledAnnotations(true);
}
void ScTiledRenderingTest::testUndoLimiting()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
ScDocument* pDoc = pModelObj->GetDocument();
CPPUNIT_ASSERT(pDoc);
SfxUndoManager* pUndoManager = pDoc->GetUndoManager();
CPPUNIT_ASSERT(pUndoManager);
// view #1
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
// view #2
SfxLokHelper::createView();
int nView2 = SfxLokHelper::getView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
// text edit a cell in view #1
SfxLokHelper::setView(nView1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
// check that undo action count in not 0
CPPUNIT_ASSERT_EQUAL(std::size_t(1), pUndoManager->GetUndoActionCount());
// try to execute undo in view #2
SfxLokHelper::setView(nView2);
comphelper::dispatchCommand(".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
// check that undo has not been executed on view #2
CPPUNIT_ASSERT_EQUAL(std::size_t(1), pUndoManager->GetUndoActionCount());
// try to execute undo in view #1
SfxLokHelper::setView(nView1);
comphelper::dispatchCommand(".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
// check that undo has been executed on view #1
CPPUNIT_ASSERT_EQUAL(std::size_t(0), pUndoManager->GetUndoActionCount());
// check that redo action count in not 0
CPPUNIT_ASSERT_EQUAL(std::size_t(1), pUndoManager->GetRedoActionCount());
// try to execute redo in view #2
SfxLokHelper::setView(nView2);
comphelper::dispatchCommand(".uno:Redo", {});
Scheduler::ProcessEventsToIdle();
// check that redo has not been executed on view #2
CPPUNIT_ASSERT_EQUAL(std::size_t(1), pUndoManager->GetRedoActionCount());
// try to execute redo in view #1
SfxLokHelper::setView(nView1);
comphelper::dispatchCommand(".uno:Redo", {});
Scheduler::ProcessEventsToIdle();
// check that redo has been executed on view #1
CPPUNIT_ASSERT_EQUAL(std::size_t(0), pUndoManager->GetRedoActionCount());
}
void ScTiledRenderingTest::testUndoRepairDispatch()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
ScDocument* pDoc = pModelObj->GetDocument();
CPPUNIT_ASSERT(pDoc);
SfxUndoManager* pUndoManager = pDoc->GetUndoManager();
CPPUNIT_ASSERT(pUndoManager);
// view #1
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
// view #2
SfxLokHelper::createView();
int nView2 = SfxLokHelper::getView();
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
ViewCallback aView2;
// text edit a cell in view #1
SfxLokHelper::setView(nView1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'x', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
// check that undo action count in not 0
CPPUNIT_ASSERT_EQUAL(std::size_t(1), pUndoManager->GetUndoActionCount());
// try to execute undo in view #2
SfxLokHelper::setView(nView2);
comphelper::dispatchCommand(".uno:Undo", {});
Scheduler::ProcessEventsToIdle();
// check that undo has not been executed on view #2
CPPUNIT_ASSERT_EQUAL(std::size_t(1), pUndoManager->GetUndoActionCount());
// try to execute undo in view #2 in repair mode
SfxLokHelper::setView(nView2);
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
{
{"Repair", uno::makeAny(true)}
}));
comphelper::dispatchCommand(".uno:Undo", aPropertyValues);
Scheduler::ProcessEventsToIdle();
// check that undo has been executed on view #2 in repair mode
CPPUNIT_ASSERT_EQUAL(std::size_t(0), pUndoManager->GetUndoActionCount());
}
void ScTiledRenderingTest::testInsertGraphicInvalidations()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
// view
ViewCallback aView;
// we need to paint a tile in the view for triggering the tile invalidation solution
int nCanvasWidth = 256;<--- Assignment 'nCanvasWidth=256', assigned value is 256
int nCanvasHeight = 256;
std::vector<unsigned char> aBuffer(nCanvasWidth * nCanvasHeight * 4);<--- Argument 'nCanvasWidth*nCanvasHeight*4' to function aBuffer is always 262144
ScopedVclPtrInstance<VirtualDevice> pDevice(DeviceFormat::DEFAULT);
pDevice->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(), aBuffer.data());
pModelObj->paintTile(*pDevice, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/0, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
Scheduler::ProcessEventsToIdle();
// insert an image in view and see if both views are invalidated
aView.m_bInvalidateTiles = false;
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "FileName", uno::Any(m_directories.getURLFromSrc(DATA_DIRECTORY) + "smile.png") }
}));
comphelper::dispatchCommand(".uno:InsertGraphic", aArgs);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_bInvalidateTiles);
// undo image insertion in view and see if both views are invalidated
aView.m_bInvalidateTiles = false;
uno::Sequence<beans::PropertyValue> aArgs2;
comphelper::dispatchCommand(".uno:Undo", aArgs2);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView.m_bInvalidateTiles);
}
void ScTiledRenderingTest::testDocumentSizeWithTwoViews()
{
comphelper::LibreOfficeKit::setActive();
// Open a document that has the cursor far away & paint a tile
ScModelObj* pModelObj = createDoc("cursor-away.ods");
// Set the visible area, and press page down
pModelObj->setClientVisibleArea(tools::Rectangle(750, 1861, 20583, 6997));
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::PAGEDOWN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::PAGEDOWN);
Scheduler::ProcessEventsToIdle();
int nCanvasWidth = 256;<--- Assignment 'nCanvasWidth=256', assigned value is 256
int nCanvasHeight = 256;
std::vector<unsigned char> aBuffer1(nCanvasWidth * nCanvasHeight * 4);<--- Argument 'nCanvasWidth*nCanvasHeight*4' to function aBuffer1 is always 262144
ScopedVclPtrInstance<VirtualDevice> pDevice1(DeviceFormat::DEFAULT);
pDevice1->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(), aBuffer1.data());
pModelObj->paintTile(*pDevice1, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/291840, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
Scheduler::ProcessEventsToIdle();
// Create a new view
int nView1 = SfxLokHelper::getView();
SfxLokHelper::createView();
std::vector<unsigned char> aBuffer2(nCanvasWidth * nCanvasHeight * 4);
ScopedVclPtrInstance<VirtualDevice> pDevice2(DeviceFormat::DEFAULT);
pDevice2->SetOutputSizePixelScaleOffsetAndBuffer(Size(nCanvasWidth, nCanvasHeight), Fraction(1.0), Point(), aBuffer2.data());
pModelObj->paintTile(*pDevice2, nCanvasWidth, nCanvasHeight, /*nTilePosX=*/0, /*nTilePosY=*/291840, /*nTileWidth=*/3840, /*nTileHeight=*/3840);
Scheduler::ProcessEventsToIdle();
// Check that the tiles actually have the same content
for (size_t i = 0; i < aBuffer1.size(); ++i)
CPPUNIT_ASSERT_EQUAL(aBuffer1[i], aBuffer2[i]);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testDisableUndoRepair()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("cursor-away.ods");
CPPUNIT_ASSERT(pModelObj);
// view #1
int nView1 = SfxLokHelper::getView();
SfxViewShell* pView1 = SfxViewShell::Current();
// view #2
SfxLokHelper::createView();
int nView2 = SfxLokHelper::getView();
SfxViewShell* pView2 = SfxViewShell::Current();
CPPUNIT_ASSERT(pView1 != pView2);
{
SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
pView1->GetSlotState(SID_UNDO, nullptr, &aSet1);
pView2->GetSlotState(SID_UNDO, nullptr, &aSet2);
CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, aSet1.GetItemState(SID_UNDO));
CPPUNIT_ASSERT_EQUAL(SfxItemState::DISABLED, aSet2.GetItemState(SID_UNDO));
}
// text edit a cell in view #1
SfxLokHelper::setView(nView1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'h', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'h', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
{
SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
pView1->GetSlotState(SID_UNDO, nullptr, &aSet1);
pView2->GetSlotState(SID_UNDO, nullptr, &aSet2);
CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet1.GetItemState(SID_UNDO));
CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet1.GetItem(SID_UNDO)));
CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet2.GetItemState(SID_UNDO));
CPPUNIT_ASSERT(dynamic_cast< const SfxUInt32Item* >(aSet2.GetItem(SID_UNDO)));
const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(aSet2.GetItem(SID_UNDO));
CPPUNIT_ASSERT(pUInt32Item);
CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), pUInt32Item->GetValue());
}
// text edit a cell in view #2
SfxLokHelper::setView(nView2);
pModelObj->setPart(1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
{
SfxItemSet aSet1(pView1->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
SfxItemSet aSet2(pView2->GetPool(), svl::Items<SID_UNDO, SID_UNDO>{});
pView1->GetSlotState(SID_UNDO, nullptr, &aSet1);
pView2->GetSlotState(SID_UNDO, nullptr, &aSet2);
CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet1.GetItemState(SID_UNDO));
const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(aSet1.GetItem(SID_UNDO));
CPPUNIT_ASSERT(pUInt32Item);
CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), pUInt32Item->GetValue());
CPPUNIT_ASSERT_EQUAL(SfxItemState::SET, aSet2.GetItemState(SID_UNDO));
CPPUNIT_ASSERT(dynamic_cast< const SfxStringItem* >(aSet2.GetItem(SID_UNDO)));
}
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testDocumentRepair()
{
comphelper::LibreOfficeKit::setActive();
// Create two views.
ScModelObj* pModelObj = createDoc("cursor-away.ods");
CPPUNIT_ASSERT(pModelObj);
// view #1
SfxViewShell* pView1 = SfxViewShell::Current();
// view #2
int nView1 = SfxLokHelper::getView();
SfxLokHelper::createView();
SfxViewShell* pView2 = SfxViewShell::Current();
int nView2 = SfxLokHelper::getView();
CPPUNIT_ASSERT(pView1 != pView2);
{
std::unique_ptr<SfxPoolItem> xItem1;
std::unique_ptr<SfxPoolItem> xItem2;
pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1);
pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2);
const SfxBoolItem* pItem1 = dynamic_cast< const SfxBoolItem* >(xItem1.get());
const SfxBoolItem* pItem2 = dynamic_cast< const SfxBoolItem* >(xItem2.get());
CPPUNIT_ASSERT(pItem1);
CPPUNIT_ASSERT(pItem2);
CPPUNIT_ASSERT_EQUAL(false, pItem1->GetValue());
CPPUNIT_ASSERT_EQUAL(false, pItem2->GetValue());
}
// Insert a character in the second view.
SfxLokHelper::setView(nView2);
pModelObj->setPart(1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 'c', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 'c', 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
{
std::unique_ptr<SfxPoolItem> xItem1;
std::unique_ptr<SfxPoolItem> xItem2;
pView1->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem1);
pView2->GetViewFrame()->GetBindings().QueryState(SID_DOC_REPAIR, xItem2);
const SfxBoolItem* pItem1 = dynamic_cast< const SfxBoolItem* >(xItem1.get());
const SfxBoolItem* pItem2 = dynamic_cast< const SfxBoolItem* >(xItem2.get());
CPPUNIT_ASSERT(pItem1);
CPPUNIT_ASSERT(pItem2);
CPPUNIT_ASSERT_EQUAL(true, pItem1->GetValue());
CPPUNIT_ASSERT_EQUAL(true, pItem2->GetValue());
}
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testLanguageStatus()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("small.ods");
CPPUNIT_ASSERT(pModelObj);
ScDocShell* pDocSh = dynamic_cast< ScDocShell* >( pModelObj->GetEmbeddedObject() );
CPPUNIT_ASSERT(pDocSh);
// view #1
SfxViewShell* pView1 = SfxViewShell::Current();
// view #2
int nView1 = SfxLokHelper::getView();
SfxLokHelper::createView();
SfxViewShell* pView2 = SfxViewShell::Current();
CPPUNIT_ASSERT(pView1 != pView2);
const OUString aLangBolivia("Spanish (Bolivia);es-BO");
{
std::unique_ptr<SfxPoolItem> xItem1;
std::unique_ptr<SfxPoolItem> xItem2;
pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem1);
pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem2);
const SfxStringItem* pItem1 = dynamic_cast<const SfxStringItem*>(xItem1.get());
const SfxStringItem* pItem2 = dynamic_cast<const SfxStringItem*>(xItem2.get());
CPPUNIT_ASSERT(pItem1);
CPPUNIT_ASSERT(pItem2);
CPPUNIT_ASSERT(!pItem1->GetValue().isEmpty());
CPPUNIT_ASSERT(!pItem2->GetValue().isEmpty());
}
{
SfxStringItem aLangString(SID_LANGUAGE_STATUS, "Default_Spanish (Bolivia)");
pView1->GetViewFrame()->GetDispatcher()->ExecuteList(SID_LANGUAGE_STATUS,
SfxCallMode::SYNCHRON, { &aLangString });
}
{
std::unique_ptr<SfxPoolItem> xItem1;
std::unique_ptr<SfxPoolItem> xItem2;
pView1->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem1);
pView2->GetViewFrame()->GetBindings().QueryState(SID_LANGUAGE_STATUS, xItem2);
const SfxStringItem* pItem1 = dynamic_cast<const SfxStringItem*>(xItem1.get());
const SfxStringItem* pItem2 = dynamic_cast<const SfxStringItem*>(xItem2.get());
CPPUNIT_ASSERT(pItem1);
CPPUNIT_ASSERT(pItem2);
CPPUNIT_ASSERT_EQUAL(aLangBolivia, pItem1->GetValue());
CPPUNIT_ASSERT_EQUAL(aLangBolivia, pItem2->GetValue());
}
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testMultiViewCopyPaste()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
ScDocument* pDoc = pModelObj->GetDocument();
CPPUNIT_ASSERT(pDoc);
pDoc->SetString(ScAddress(0, 0, 0), "TestCopy1");
pDoc->SetString(ScAddress(1, 0, 0), "TestCopy2");
// view #1
ScTabViewShell* pView1 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
CPPUNIT_ASSERT(pView1);
// emulate clipboard
pView1->GetViewData().GetActiveWin()->SetClipboard(css::datatransfer::clipboard::SystemClipboard::create(comphelper::getProcessComponentContext()));
// view #2
int nView1 = SfxLokHelper::getView();
SfxLokHelper::createView();
ScTabViewShell* pView2 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
// emulate clipboard
pView2->GetViewData().GetActiveWin()->SetClipboard(css::datatransfer::clipboard::SystemClipboard::create(comphelper::getProcessComponentContext()));
CPPUNIT_ASSERT(pView2);
CPPUNIT_ASSERT(pView1 != pView2);
CPPUNIT_ASSERT(pView1->GetViewData().GetActiveWin()->GetClipboard() != pView2->GetViewData().GetActiveWin()->GetClipboard());
// copy text view 1
pView1->SetCursor(0, 0);
pView1->GetViewFrame()->GetBindings().Execute(SID_COPY);
// copy text view 2
pView2->SetCursor(1, 0);
pView2->GetViewFrame()->GetBindings().Execute(SID_COPY);
// paste text view 1
pView1->SetCursor(0, 1);
pView1->GetViewFrame()->GetBindings().Execute(SID_PASTE);
// paste text view 2
pView2->SetCursor(1, 1);
pView2->GetViewFrame()->GetBindings().Execute(SID_PASTE);
CPPUNIT_ASSERT_EQUAL(OUString("TestCopy1"), pDoc->GetString(ScAddress(0, 1, 0)));
CPPUNIT_ASSERT_EQUAL(OUString("TestCopy2"), pDoc->GetString(ScAddress(1, 1, 0)));
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testIMESupport()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
VclPtr<vcl::Window> pDocWindow = pModelObj->getDocWindow();
ScDocument* pDoc = pModelObj->GetDocument();
ScTabViewShell* pView = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
CPPUNIT_ASSERT(pView);
pView->SetCursor(0, 0);
// sequence of chinese IME compositions when 'nihao' is typed in an IME
const std::vector<OString> aUtf8Inputs{ "å¹´", "ä½ ", "ä½ å¥½", "ä½ å“ˆ", "ä½ å¥½", "ä½ å¥½" };
std::vector<OUString> aInputs;
std::transform(aUtf8Inputs.begin(), aUtf8Inputs.end(),
std::back_inserter(aInputs), [](OString aInput) {
return OUString::fromUtf8(aInput);
});
for (const auto& aInput: aInputs)
{
pDocWindow->PostExtTextInputEvent(VclEventId::ExtTextInput, aInput);
}
pDocWindow->PostExtTextInputEvent(VclEventId::EndExtTextInput, "");
// commit the string to the cell
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT_EQUAL(aInputs[aInputs.size() - 1], pDoc->GetString(ScAddress(0, 0, 0)));
}
void ScTiledRenderingTest::testFilterDlg()
{
comphelper::LibreOfficeKit::setActive();
createDoc("empty.ods");
// view #1
SfxViewShell* pView1 = SfxViewShell::Current();
int nView1 = SfxLokHelper::getView();
// view #2
SfxLokHelper::createView();
SfxViewShell* pView2 = SfxViewShell::Current();
CPPUNIT_ASSERT(pView1 != pView2);
{
pView2->GetViewFrame()->GetDispatcher()->Execute(SID_FILTER,
SfxCallMode::SLOT|SfxCallMode::RECORD);
}
Scheduler::ProcessEventsToIdle();
SfxChildWindow* pRefWindow = pView2->GetViewFrame()->GetChildWindow(SID_FILTER);
CPPUNIT_ASSERT(pRefWindow);
// switch to view 1
SfxLokHelper::setView(nView1);
CPPUNIT_ASSERT_EQUAL(true, pView2->GetViewFrame()->GetDispatcher()->IsLocked());
CPPUNIT_ASSERT_EQUAL(false, pView1->GetViewFrame()->GetDispatcher()->IsLocked());
pRefWindow->GetController()->response(RET_CANCEL);
CPPUNIT_ASSERT_EQUAL(false, pView2->GetViewFrame()->GetDispatcher()->IsLocked());
CPPUNIT_ASSERT_EQUAL(false, pView1->GetViewFrame()->GetDispatcher()->IsLocked());
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
void ScTiledRenderingTest::testVbaRangeCopyPaste()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("RangeCopyPaste.ods");
ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pModelObj->GetEmbeddedObject() );
CPPUNIT_ASSERT(pDocShell);
uno::Any aRet;
uno::Sequence< uno::Any > aOutParam;
uno::Sequence< uno::Any > aParams;
uno::Sequence< sal_Int16 > aOutParamIndex;
SfxObjectShell::CallXScript(
mxComponent,
"vnd.sun.Star.script:Standard.Module1.Test_RangeCopyPaste?language=Basic&location=document",
aParams, aRet, aOutParamIndex, aOutParam);
CPPUNIT_ASSERT(!pDocShell->GetClipData().is());
}
void ScTiledRenderingTest::testInvalidationLoop()
{
// Load the document with a form control.
createDoc("invalidation-loop.fods");
// Without the accompanying fix in place, this test would have never returned due to an infinite
// invalidation loop between ScGridWindow::Paint() and vcl::Window::ImplPosSizeWindow().
Scheduler::ProcessEventsToIdle();
}
void ScTiledRenderingTest::testPageDownInvalidation()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
SfxLokHelper::setView(nView1);
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, awt::Key::PAGEDOWN, 0);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, awt::Key::PAGEDOWN, 0);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(3), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(15, 15, 1230, 225), aView1.m_aInvalidations[0]);
}
void ScTiledRenderingTest::testSheetChangeInvalidation()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("two_sheets.ods");
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
SfxLokHelper::setView(nView1);
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
aView1.m_aInvalidationsParts.clear();
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::PAGEDOWN | KEY_MOD1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::PAGEDOWN | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(2), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 0, 1310720, 268435456), aView1.m_aInvalidations[0]);
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 0, 1000000000, 1000000000), aView1.m_aInvalidations[1]);
CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidationsParts.size());
CPPUNIT_ASSERT_EQUAL(pModelObj->getPart(), aView1.m_aInvalidationsParts[0]);
}
void ScTiledRenderingTest::testInsertDeletePageInvalidation()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("insert_delete_sheet.ods");
// the document has 1 sheet
CPPUNIT_ASSERT_EQUAL(1, pModelObj->getParts());
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
SfxLokHelper::setView(nView1);
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
uno::Sequence<beans::PropertyValue> aArgs( comphelper::InitPropertySequence({
{ "Name", uno::Any(OUString("")) },
{ "Index", uno::Any(sal_Int32(1)) }
}));
comphelper::dispatchCommand(".uno:Insert", aArgs);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(6), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 0, 1000000000, 1000000000), aView1.m_aInvalidations[0]);
CPPUNIT_ASSERT_EQUAL(2, pModelObj->getParts());
// Delete sheet
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
uno::Sequence<beans::PropertyValue> aArgs2( comphelper::InitPropertySequence({
{ "Index", uno::Any(sal_Int32(1)) }
}));
comphelper::dispatchCommand(".uno:Remove", aArgs2);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(5), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 0, 1000000000, 1000000000), aView1.m_aInvalidations[0]);
CPPUNIT_ASSERT_EQUAL(1, pModelObj->getParts());
}
void ScTiledRenderingTest::testGetRowColumnHeadersInvalidation()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
SfxLokHelper::setView(nView1);
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
pModelObj->getRowColumnHeaders(tools::Rectangle(0, 15, 19650, 5400));
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(26775, 0, 49725, 13005), aView1.m_aInvalidations[0]);
// Extend area top-to-bottom
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
pModelObj->getRowColumnHeaders(tools::Rectangle(0, 5400, 19650, 9800));
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 13005, 49725, 19380), aView1.m_aInvalidations[0]);
// Extend area left-to-right
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
pModelObj->getRowColumnHeaders(tools::Rectangle(5400, 5400, 25050, 9800));
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(49725, 0, 75225, 19380), aView1.m_aInvalidations[0]);
}
void ScTiledRenderingTest::testJumpHorizontallyInvalidation()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
SfxLokHelper::setView(nView1);
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::PAGEDOWN | KEY_MOD2);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::PAGEDOWN | KEY_MOD2);
Scheduler::ProcessEventsToIdle();
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::PAGEDOWN | KEY_MOD2);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::PAGEDOWN | KEY_MOD2);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(26775, 0, 39525, 13005), aView1.m_aInvalidations[0]);
}
void ScTiledRenderingTest::testJumpToLastRowInvalidation()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
int nView1 = SfxLokHelper::getView();
ViewCallback aView1;
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
SfxLokHelper::setView(nView1);
aView1.m_bInvalidateTiles = false;
aView1.m_aInvalidations.clear();
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DOWN | KEY_MOD1);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::DOWN | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
CPPUNIT_ASSERT(aView1.m_bInvalidateTiles);
CPPUNIT_ASSERT_EQUAL(size_t(1), aView1.m_aInvalidations.size());
CPPUNIT_ASSERT_EQUAL(tools::Rectangle(0, 13005, 26775, 127500255), aView1.m_aInvalidations[0]);
}
// We need to ensure that views are not perterbed by rendering (!?) hmm ...
void ScTiledRenderingTest::testRowColumnHeaders()
{
comphelper::LibreOfficeKit::setActive();
ScModelObj* pModelObj = createDoc("empty.ods");
ScViewData* pViewData = ScDocShell::GetViewData();
CPPUNIT_ASSERT(pViewData);
// view #1
ViewCallback aView1;
int nView1 = SfxLokHelper::getView();
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView1);
CPPUNIT_ASSERT(!lcl_hasEditView(*pViewData));
// view #2
SfxLokHelper::createView();
int nView2 = SfxLokHelper::getView();
ViewCallback aView2;
pModelObj->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(&ViewCallback::callback, &aView2);
// ViewRowColumnHeaders test
SfxLokHelper::setView(nView1);
OUString aHeaders1 = pModelObj->getRowColumnHeaders(tools::Rectangle(65,723,10410,4695));
SfxLokHelper::setView(nView2);
// 50% zoom
pModelObj->setClientVisibleArea(tools::Rectangle(0, 0, 22474, 47333));
pModelObj->setClientZoom(256, 256, 6636, 6636);
OUString aHeaders2 = pModelObj->getRowColumnHeaders(tools::Rectangle(65,723,10410,4695));
// Check vs. view #1
SfxLokHelper::setView(nView1);
OUString aHeaders1_2 = pModelObj->getRowColumnHeaders(tools::Rectangle(65,723,10410,4695));
CPPUNIT_ASSERT_EQUAL(aHeaders1, aHeaders1_2);
// Check vs. view #2
SfxLokHelper::setView(nView2);
OUString aHeaders2_2 = pModelObj->getRowColumnHeaders(tools::Rectangle(65,723,10410,4695));
CPPUNIT_ASSERT_EQUAL(aHeaders2, aHeaders2_2);
SfxLokHelper::setView(nView1);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
SfxLokHelper::setView(nView2);
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|