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
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344 | /* -*- 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 <config_feature_desktop.h>
#include <ctime>
#include <rootfrm.hxx>
#include <pagefrm.hxx>
#include <viewimp.hxx>
#include <crsrsh.hxx>
#include <dflyobj.hxx>
#include <frmatr.hxx>
#include <frmtool.hxx>
#include <viewopt.hxx>
#include <dbg_lay.hxx>
#include <layouter.hxx>
#include <docstat.hxx>
#include <swevent.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include <IDocumentStatistics.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <sfx2/event.hxx>
#include <ftnidx.hxx>
#include <editeng/opaqitem.hxx>
#include <SwSmartTagMgr.hxx>
#include <sal/log.hxx>
#include <layact.hxx>
#include <swwait.hxx>
#include <fmtsrnd.hxx>
#include <docsh.hxx>
#include <anchoreddrawobject.hxx>
#include <ndtxt.hxx>
#include <tabfrm.hxx>
#include <ftnfrm.hxx>
#include <txtfrm.hxx>
#include <notxtfrm.hxx>
#include <flyfrms.hxx>
#include <mdiexp.hxx>
#include <sectfrm.hxx>
#include <acmplwrd.hxx>
#include <sortedobjs.hxx>
#include <objectformatter.hxx>
#include <fntcache.hxx>
#include <vector>
#include <tools/diagnose_ex.h>
// Save some typing work to avoid accessing destroyed pages.
#define XCHECKPAGE \
{ if ( IsAgain() ) \
{ \
if( bNoLoop ) \
rLayoutAccess.GetLayouter()->EndLoopControl(); \
return; \
} \
}
void SwLayAction::CheckWaitCursor()
{
if (IsReschedule())
{
::RescheduleProgress(m_pImp->GetShell()->GetDoc()->GetDocShell());
}
if ( !m_pWait && IsWaitAllowed() && IsPaint() &&
((std::clock() - m_nStartTicks) * 1000 / CLOCKS_PER_SEC >= CLOCKS_PER_SEC/2) )
{
m_pWait.reset( new SwWait( *m_pRoot->GetFormat()->GetDoc()->GetDocShell(), true ) );
}
}
void SwLayAction::SetStatBar( bool bNew )
{
if ( bNew )
{
m_nEndPage = m_pRoot->GetPageNum();
m_nEndPage += m_nEndPage * 10 / 100;
}
else
m_nEndPage = USHRT_MAX;
}
bool SwLayAction::PaintWithoutFlys( const SwRect &rRect, const SwContentFrame *pCnt,
const SwPageFrame *pPage )
{
SwRegionRects aTmp( rRect );
const SwSortedObjs &rObjs = *pPage->GetSortedObjs();
const SwFlyFrame *pSelfFly = pCnt->FindFlyFrame();
for ( size_t i = 0; i < rObjs.size() && !aTmp.empty(); ++i )
{
SdrObject *pO = rObjs[i]->DrawObj();
if ( dynamic_cast< const SwVirtFlyDrawObj *>( pO ) == nullptr )
continue;
// do not consider invisible objects
const IDocumentDrawModelAccess& rIDDMA = pPage->GetFormat()->getIDocumentDrawModelAccess();
if ( !rIDDMA.IsVisibleLayerId( pO->GetLayer() ) )
{
continue;
}
SwFlyFrame *pFly = static_cast<SwVirtFlyDrawObj*>(pO)->GetFlyFrame();
if ( pFly == pSelfFly || !rRect.IsOver( pFly->getFrameArea() ) )
continue;
if ( pSelfFly && pSelfFly->IsLowerOf( pFly ) )
continue;
if ( pFly->GetVirtDrawObj()->GetLayer() == rIDDMA.GetHellId() )
continue;
if ( pSelfFly )
{
const SdrObject *pTmp = pSelfFly->GetVirtDrawObj();
if ( pO->GetLayer() == pTmp->GetLayer() )
{
if ( pO->GetOrdNumDirect() < pTmp->GetOrdNumDirect() )
// Only look at things above us, if inside the same layer
continue;
}
else
{
const bool bLowerOfSelf = pFly->IsLowerOf( pSelfFly );
if ( !bLowerOfSelf && !pFly->GetFormat()->GetOpaque().GetValue() )
// Things from other layers are only interesting to us if
// they're not transparent or lie inwards
continue;
}
}
// Fly frame without a lower have to be subtracted from paint region.
// For checking, if fly frame contains transparent graphic or
// has surrounded contour, assure that fly frame has a lower
if ( pFly->Lower() &&
pFly->Lower()->IsNoTextFrame() &&
( static_cast<SwNoTextFrame*>(pFly->Lower())->IsTransparent() ||
pFly->GetFormat()->GetSurround().IsContour() )
)
{
continue;
}
// vcl::Region of a fly frame with transparent background or a transparent
// shadow have not to be subtracted from paint region
if ( pFly->IsBackgroundTransparent() )
{
continue;
}
aTmp -= pFly->getFrameArea();
}
bool bRetPaint = false;
for ( const auto& rRegionRect : aTmp )
bRetPaint |= m_pImp->GetShell()->AddPaintRect( rRegionRect );
return bRetPaint;
}
inline bool SwLayAction::PaintContent_( const SwContentFrame *pContent,
const SwPageFrame *pPage,
const SwRect &rRect )
{
if ( rRect.HasArea() )
{
if ( pPage->GetSortedObjs() )
return PaintWithoutFlys( rRect, pContent, pPage );
else
return m_pImp->GetShell()->AddPaintRect( rRect );
}
return false;
}
/**
* Depending of the type, the Content is output according to its changes, or the area
* to be outputted is registered with the region, respectively.
*/
void SwLayAction::PaintContent( const SwContentFrame *pCnt,
const SwPageFrame *pPage,
const SwRect &rOldRect,
long nOldBottom )
{
SwRectFnSet aRectFnSet(pCnt);
if ( pCnt->IsCompletePaint() || !pCnt->IsTextFrame() )
{
SwRect aPaint( pCnt->GetPaintArea() );
if ( !PaintContent_( pCnt, pPage, aPaint ) )
pCnt->ResetCompletePaint();
}
else
{
// paint the area between printing bottom and frame bottom and
// the area left and right beside the frame, if its height changed.
long nOldHeight = aRectFnSet.GetHeight(rOldRect);
long nNewHeight = aRectFnSet.GetHeight(pCnt->getFrameArea());
const bool bHeightDiff = nOldHeight != nNewHeight;
if( bHeightDiff )
{
// consider whole potential paint area.
SwRect aDrawRect( pCnt->GetPaintArea() );
if( nOldHeight > nNewHeight )
nOldBottom = aRectFnSet.GetPrtBottom(*pCnt);
aRectFnSet.SetTop( aDrawRect, nOldBottom );
PaintContent_( pCnt, pPage, aDrawRect );
}
// paint content area
SwRect aPaintRect = static_cast<SwTextFrame*>(const_cast<SwContentFrame*>(pCnt))->GetPaintSwRect();
PaintContent_( pCnt, pPage, aPaintRect );
}
if ( pCnt->IsRetouche() && !pCnt->GetNext() )
{
const SwFrame *pTmp = pCnt;
if( pCnt->IsInSct() )
{
const SwSectionFrame* pSct = pCnt->FindSctFrame();
if( pSct->IsRetouche() && !pSct->GetNext() )
pTmp = pSct;
}
SwRect aRect( pTmp->GetUpper()->GetPaintArea() );
aRectFnSet.SetTop( aRect, aRectFnSet.GetPrtBottom(*pTmp) );
if ( !PaintContent_( pCnt, pPage, aRect ) )
pCnt->ResetRetouche();
}
}
SwLayAction::SwLayAction(SwRootFrame *pRt, SwViewShellImp *pI, TaskStopwatch* pWatch)
: m_pRoot(pRt),
m_pImp( pI ),
m_pWatch(pWatch),
m_pOptTab( nullptr ),
m_nPreInvaPage( USHRT_MAX ),
m_nStartTicks( std::clock() ),
m_nEndPage( USHRT_MAX ),
m_nCheckPageNum( USHRT_MAX ),
m_pCurPage( nullptr ),
m_nTabLevel( 0 ),
m_nCallCount( 0 )
{
m_bPaintExtraData = ::IsExtraData( m_pImp->GetShell()->GetDoc() );
m_bPaint = m_bComplete = m_bWaitAllowed = m_bCheckPages = true;
m_bInterrupt = m_bAgain = m_bNextCycle = m_bCalcLayout = m_bReschedule =
m_bUpdateExpFields = m_bBrowseActionStop = m_bActionInProgress = false;
// init new flag <mbFormatContentOnInterrupt>.
mbFormatContentOnInterrupt = false;
assert(!m_pImp->m_pLayAction); // there can be only one SwLayAction
m_pImp->m_pLayAction = this; // register there
}
SwLayAction::~SwLayAction()
{
OSL_ENSURE( !m_pWait, "Wait object not destroyed" );
m_pImp->m_pLayAction = nullptr; // unregister
}
bool SwLayAction::IsInterrupt()
{
return m_bInterrupt || (m_pWatch && m_pWatch->exceededRuntime());
}
void SwLayAction::Reset()
{
m_pOptTab = nullptr;
m_nStartTicks = std::clock();
m_nEndPage = m_nPreInvaPage = m_nCheckPageNum = USHRT_MAX;
m_bPaint = m_bComplete = m_bWaitAllowed = m_bCheckPages = true;
m_bInterrupt = m_bAgain = m_bNextCycle = m_bCalcLayout = m_bReschedule =
m_bUpdateExpFields = m_bBrowseActionStop = false;
m_pCurPage = nullptr;
}
bool SwLayAction::RemoveEmptyBrowserPages()
{
// switching from the normal to the browser mode, empty pages may be
// retained for an annoyingly long time, so delete them here
bool bRet = false;
const SwViewShell *pSh = m_pRoot->GetCurrShell();
if( pSh && pSh->GetViewOptions()->getBrowseMode() )
{
SwPageFrame *pPage = static_cast<SwPageFrame*>(m_pRoot->Lower());
do
{
if ( (pPage->GetSortedObjs() && pPage->GetSortedObjs()->size()) ||
pPage->ContainsContent() )
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
else
{
bRet = true;
SwPageFrame *pDel = pPage;
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
pDel->Cut();
SwFrame::DestroyFrame(pDel);
}
} while ( pPage );
}
return bRet;
}
void SwLayAction::Action(OutputDevice* pRenderContext)
{
m_bActionInProgress = true;
//TurboMode? Hands-off during idle-format
if ( IsPaint() && !IsIdle() && TurboAction() )
{
m_pWait.reset();
m_pRoot->ResetTurboFlag();
m_bActionInProgress = false;
m_pRoot->DeleteEmptySct();
return;
}
else if ( m_pRoot->GetTurbo() )
{
m_pRoot->DisallowTurbo();
const SwFrame *pFrame = m_pRoot->GetTurbo();
m_pRoot->ResetTurbo();
pFrame->InvalidatePage();
}
m_pRoot->DisallowTurbo();
if ( IsCalcLayout() )
SetCheckPages( false );
InternalAction(pRenderContext);
m_bAgain |= RemoveEmptyBrowserPages();
while ( IsAgain() )
{
m_bAgain = m_bNextCycle = false;
InternalAction(pRenderContext);
m_bAgain |= RemoveEmptyBrowserPages();
}
m_pRoot->DeleteEmptySct();
m_pWait.reset();
//Turbo-Action permitted again for all cases.
m_pRoot->ResetTurboFlag();
m_pRoot->ResetTurbo();
SetCheckPages( true );
m_bActionInProgress = false;
}
SwPageFrame* SwLayAction::CheckFirstVisPage( SwPageFrame *pPage )
{
SwContentFrame *pCnt = pPage->FindFirstBodyContent();
SwContentFrame *pChk = pCnt;
bool bPageChgd = false;
while ( pCnt && pCnt->IsFollow() )
pCnt = pCnt->FindMaster();
if ( pCnt && pChk != pCnt )
{ bPageChgd = true;
pPage = pCnt->FindPageFrame();
}
if ( !pPage->GetFormat()->GetDoc()->GetFootnoteIdxs().empty() )
{
SwFootnoteContFrame *pCont = pPage->FindFootnoteCont();
if ( pCont )
{
pCnt = pCont->ContainsContent();
pChk = pCnt;
while ( pCnt && pCnt->IsFollow() )
pCnt = static_cast<SwContentFrame*>(pCnt->FindPrev());
if ( pCnt && pCnt != pChk )
{
if ( bPageChgd )
{
// Use the 'topmost' page
SwPageFrame *pTmp = pCnt->FindPageFrame();
if ( pPage->GetPhyPageNum() > pTmp->GetPhyPageNum() )
pPage = pTmp;
}
else
pPage = pCnt->FindPageFrame();
}
}
}
return pPage;
}
// unlock position on start and end of page
// layout process.
static void unlockPositionOfObjects( SwPageFrame *pPageFrame )
{
assert( pPageFrame );
SwSortedObjs* pObjs = pPageFrame->GetSortedObjs();
if ( pObjs )
{
for (SwAnchoredObject* pObj : *pObjs)
{
pObj->UnlockPosition();
}
}
}
void SwLayAction::InternalAction(OutputDevice* pRenderContext)
{
OSL_ENSURE( m_pRoot->Lower()->IsPageFrame(), ":-( No page below the root.");
m_pRoot->Calc(pRenderContext);
// Figure out the first invalid page or the first one to be formatted,
// respectively. A complete-action means the first invalid page.
// However, the first page to be formatted might be the one having the
// number 1. If we're doing a fake formatting, the number of the first
// page is the number of the first visible page.
SwPageFrame *pPage = IsComplete() ? static_cast<SwPageFrame*>(m_pRoot->Lower()) :
m_pImp->GetFirstVisPage(pRenderContext);
if ( !pPage )
pPage = static_cast<SwPageFrame*>(m_pRoot->Lower());
// If there's a first-flow-Content in the first visible page that's also a Follow,
// we switch the page back to the original master of that Content.
if ( !IsComplete() )
pPage = CheckFirstVisPage( pPage );
sal_uInt16 nFirstPageNum = pPage->GetPhyPageNum();
while ( pPage && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
IDocumentLayoutAccess& rLayoutAccess = m_pRoot->GetFormat()->getIDocumentLayoutAccess();
bool bNoLoop = pPage && SwLayouter::StartLoopControl( m_pRoot->GetFormat()->GetDoc(), pPage );
sal_uInt16 nPercentPageNum = 0;
while ((!IsInterrupt() && pPage) || (m_nCheckPageNum != USHRT_MAX))
{
if (!pPage && m_nCheckPageNum != USHRT_MAX)
{
SwPageFrame *pPg = static_cast<SwPageFrame*>(m_pRoot->Lower());
while (pPg && pPg->GetPhyPageNum() < m_nCheckPageNum)
pPg = static_cast<SwPageFrame*>(pPg->GetNext());
if (pPg)
pPage = pPg;
if (!pPage)
break;
SwPageFrame *pTmp = pPage->GetPrev() ?
static_cast<SwPageFrame*>(pPage->GetPrev()) : pPage;
SetCheckPages( true );
SwFrame::CheckPageDescs( pPage, true, &pTmp );
SetCheckPages( false );
m_nCheckPageNum = USHRT_MAX;
pPage = pTmp;
continue;
}
if ( m_nEndPage != USHRT_MAX && pPage->GetPhyPageNum() > nPercentPageNum )
{
nPercentPageNum = pPage->GetPhyPageNum();
::SetProgressState( nPercentPageNum, m_pImp->GetShell()->GetDoc()->GetDocShell());
}
m_pOptTab = nullptr;
// No Shortcut for Idle or CalcLayout
if ( !IsIdle() && !IsComplete() && IsShortCut( pPage ) )
{
m_pRoot->DeleteEmptySct();
XCHECKPAGE;
if ( !IsInterrupt() &&
(m_pRoot->IsSuperfluous() || m_pRoot->IsAssertFlyPages()) )
{
if ( m_pRoot->IsAssertFlyPages() )
m_pRoot->AssertFlyPages();
if ( m_pRoot->IsSuperfluous() )
{
bool bOld = IsAgain();
m_pRoot->RemoveSuperfluous();
m_bAgain = bOld;
}
if ( IsAgain() )
{
if( bNoLoop )
rLayoutAccess.GetLayouter()->EndLoopControl();
return;
}
pPage = static_cast<SwPageFrame*>(m_pRoot->Lower());
while ( pPage && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
while ( pPage && pPage->GetNext() &&
pPage->GetPhyPageNum() < nFirstPageNum )
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
continue;
}
break;
}
else
{
m_pRoot->DeleteEmptySct();
XCHECKPAGE;
while ( !IsInterrupt() && !IsNextCycle() &&
((pPage->GetSortedObjs() && pPage->IsInvalidFly()) || pPage->IsInvalid()) )
{
unlockPositionOfObjects( pPage );
SwObjectFormatter::FormatObjsAtFrame( *pPage, *pPage, this );
if ( !pPage->GetSortedObjs() )
{
// If there are no (more) Flys, the flags are superfluous.
pPage->ValidateFlyLayout();
pPage->ValidateFlyContent();
}
// change condition
while ( !IsInterrupt() && !IsNextCycle() &&
( pPage->IsInvalid() ||
(pPage->GetSortedObjs() && pPage->IsInvalidFly()) ) )
{
PROTOCOL( pPage, PROT::FileInit, DbgAction::NONE, nullptr)
XCHECKPAGE;
// new loop control
int nLoopControlRuns_1 = 0;
const int nLoopControlMax = 20;
while ( !IsNextCycle() && pPage->IsInvalidLayout() )
{
pPage->ValidateLayout();
if ( ++nLoopControlRuns_1 > nLoopControlMax )
{
OSL_FAIL( "LoopControl_1 in SwLayAction::InternalAction" );
break;
}
FormatLayout( pRenderContext, pPage );
XCHECKPAGE;
}
// change condition
if ( !IsNextCycle() &&
( pPage->IsInvalidContent() ||
(pPage->GetSortedObjs() && pPage->IsInvalidFly()) ) )
{
pPage->ValidateFlyInCnt();
pPage->ValidateContent();
pPage->ValidateFlyLayout();
pPage->ValidateFlyContent();
if ( !FormatContent( pPage ) )
{
XCHECKPAGE;
pPage->InvalidateContent();
pPage->InvalidateFlyInCnt();
pPage->InvalidateFlyLayout();
pPage->InvalidateFlyContent();
if ( IsBrowseActionStop() )
m_bInterrupt = true;
}
}
if( bNoLoop )
rLayoutAccess.GetLayouter()->LoopControl( pPage );
}
unlockPositionOfObjects( pPage );
}
// A previous page may be invalid again.
XCHECKPAGE;
if ( !pPage->GetSortedObjs() )
{
// If there are no (more) Flys, the flags are superfluous.
pPage->ValidateFlyLayout();
pPage->ValidateFlyContent();
}
if (!IsInterrupt())
{
SetNextCycle( false );
if ( m_nPreInvaPage != USHRT_MAX )
{
if( !IsComplete() && m_nPreInvaPage + 2 < nFirstPageNum )
{
m_pImp->SetFirstVisPageInvalid();
SwPageFrame *pTmpPage = m_pImp->GetFirstVisPage(pRenderContext);
nFirstPageNum = pTmpPage->GetPhyPageNum();
if( m_nPreInvaPage < nFirstPageNum )
{
m_nPreInvaPage = nFirstPageNum;
pPage = pTmpPage;
}
}
while ( pPage->GetPrev() && pPage->GetPhyPageNum() > m_nPreInvaPage )
pPage = static_cast<SwPageFrame*>(pPage->GetPrev());
m_nPreInvaPage = USHRT_MAX;
}
while ( pPage->GetPrev() &&
( static_cast<SwPageFrame*>(pPage->GetPrev())->IsInvalid() ||
( static_cast<SwPageFrame*>(pPage->GetPrev())->GetSortedObjs() &&
static_cast<SwPageFrame*>(pPage->GetPrev())->IsInvalidFly())) &&
(static_cast<SwPageFrame*>(pPage->GetPrev())->GetPhyPageNum() >=
nFirstPageNum) )
{
pPage = static_cast<SwPageFrame*>(pPage->GetPrev());
}
// Continue to the next invalid page
while ( pPage && !pPage->IsInvalid() &&
(!pPage->GetSortedObjs() || !pPage->IsInvalidFly()) )
{
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
}
if( bNoLoop )
rLayoutAccess.GetLayouter()->LoopControl( pPage );
}
}
if ( !pPage && !IsInterrupt() &&
(m_pRoot->IsSuperfluous() || m_pRoot->IsAssertFlyPages()) )
{
if ( m_pRoot->IsAssertFlyPages() )
m_pRoot->AssertFlyPages();
if ( m_pRoot->IsSuperfluous() )
{
bool bOld = IsAgain();
m_pRoot->RemoveSuperfluous();
m_bAgain = bOld;
}
if ( IsAgain() )
{
if( bNoLoop )
rLayoutAccess.GetLayouter()->EndLoopControl();
return;
}
pPage = static_cast<SwPageFrame*>(m_pRoot->Lower());
while ( pPage && !pPage->IsInvalid() && !pPage->IsInvalidFly() )
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
while ( pPage && pPage->GetNext() &&
pPage->GetPhyPageNum() < nFirstPageNum )
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
}
}
if ( IsInterrupt() && pPage )
{
// If we have input, we don't want to format content anymore, but
// we still should clean the layout.
// Otherwise, the following situation might arise:
// The user enters some text at the end of the paragraph of the last
// page, causing the paragraph to create a Follow for the next page.
// Meanwhile the user continues typing, so we have input while
// still formatting.
// The paragraph on the new page has already been partially formatted,
// and the new page has been fully formatted and is set to CompletePaint,
// but hasn't added itself to the area to be output. Then we paint,
// the CompletePaint of the page is reset because the new paragraph
// already added itself, but the borders of the page haven't been painted
// yet.
// Oh well, with the inevitable following LayAction, the page doesn't
// register itself, because it's (LayoutFrame) flags have been reset
// already - the border of the page will never be painted.
SwPageFrame *pPg = pPage;
XCHECKPAGE;
const SwRect &rVis = m_pImp->GetShell()->VisArea();
while( pPg && pPg->getFrameArea().Bottom() < rVis.Top() )
pPg = static_cast<SwPageFrame*>(pPg->GetNext());
if( pPg != pPage )
pPg = pPg ? static_cast<SwPageFrame*>(pPg->GetPrev()) : pPage;
// set flag for interrupt content formatting
mbFormatContentOnInterrupt = IsInterrupt();
long nBottom = rVis.Bottom();
// #i42586# - format current page, if idle action is active
// This is an optimization for the case that the interrupt is created by
// the move of a form control object, which is represented by a window.
while ( pPg && ( pPg->getFrameArea().Top() < nBottom ||
( IsIdle() && pPg == pPage ) ) )
{
unlockPositionOfObjects( pPg );
XCHECKPAGE;
// new loop control
int nLoopControlRuns_2 = 0;
const int nLoopControlMax = 20;
// special case: interrupt content formatting
// conditions are incorrect and are too strict.
// adjust interrupt formatting to normal page formatting - see above.
while ( ( mbFormatContentOnInterrupt &&
( pPg->IsInvalid() ||
( pPg->GetSortedObjs() && pPg->IsInvalidFly() ) ) ) ||
( !mbFormatContentOnInterrupt && pPg->IsInvalidLayout() ) )
{
XCHECKPAGE;
// format also at-page anchored objects
SwObjectFormatter::FormatObjsAtFrame( *pPg, *pPg, this );
if ( !pPg->GetSortedObjs() )
{
pPg->ValidateFlyLayout();
pPg->ValidateFlyContent();
}
// new loop control
int nLoopControlRuns_3 = 0;
while ( pPg->IsInvalidLayout() )
{
pPg->ValidateLayout();
if ( ++nLoopControlRuns_3 > nLoopControlMax )
{
OSL_FAIL( "LoopControl_3 in Interrupt formatting in SwLayAction::InternalAction" );
break;
}
FormatLayout( pRenderContext, pPg );
XCHECKPAGE;
}
if ( mbFormatContentOnInterrupt &&
( pPg->IsInvalidContent() ||
( pPg->GetSortedObjs() && pPg->IsInvalidFly() ) ) )
{
pPg->ValidateFlyInCnt();
pPg->ValidateContent();
pPg->ValidateFlyLayout();
pPg->ValidateFlyContent();
if ( ++nLoopControlRuns_2 > nLoopControlMax )
{
OSL_FAIL( "LoopControl_2 in Interrupt formatting in SwLayAction::InternalAction" );
break;
}
if ( !FormatContent( pPg ) )
{
XCHECKPAGE;
pPg->InvalidateContent();
pPg->InvalidateFlyInCnt();
pPg->InvalidateFlyLayout();
pPg->InvalidateFlyContent();
}
// we are satisfied if the content is formatted once complete.
else
{
break;
}
}
}
unlockPositionOfObjects( pPg );
pPg = static_cast<SwPageFrame*>(pPg->GetNext());
}
// reset flag for special interrupt content formatting.
mbFormatContentOnInterrupt = false;
}
m_pOptTab = nullptr;
if( bNoLoop )
rLayoutAccess.GetLayouter()->EndLoopControl();
}
bool SwLayAction::TurboAction_( const SwContentFrame *pCnt )
{
const SwPageFrame *pPage = nullptr;
if ( !pCnt->isFrameAreaDefinitionValid() || pCnt->IsCompletePaint() || pCnt->IsRetouche() )
{
const SwRect aOldRect( pCnt->UnionFrame( true ) );
const long nOldBottom = pCnt->getFrameArea().Top() + pCnt->getFramePrintArea().Bottom();
pCnt->Calc(m_pImp->GetShell()->GetOut());
if ( pCnt->getFrameArea().Bottom() < aOldRect.Bottom() )
pCnt->SetRetouche();
pPage = pCnt->FindPageFrame();
PaintContent( pCnt, pPage, aOldRect, nOldBottom );
if ( !pCnt->GetValidLineNumFlag() && pCnt->IsTextFrame() )
{
const sal_uLong nAllLines = static_cast<const SwTextFrame*>(pCnt)->GetAllLines();
const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pCnt))->RecalcAllLines();
if ( nAllLines != static_cast<const SwTextFrame*>(pCnt)->GetAllLines() )
{
if ( IsPaintExtraData() )
m_pImp->GetShell()->AddPaintRect( pCnt->getFrameArea() );
// This is to calculate the remaining LineNums on the page,
// and we don't stop processing here. To perform this inside RecalcAllLines
// would be expensive, because we would have to notify the page even
// in unnecessary cases (normal actions).
const SwContentFrame *pNxt = pCnt->GetNextContentFrame();
while ( pNxt &&
(pNxt->IsInTab() || pNxt->IsInDocBody() != pCnt->IsInDocBody()) )
pNxt = pNxt->GetNextContentFrame();
if ( pNxt )
pNxt->InvalidatePage();
}
return false;
}
if ( pPage->IsInvalidLayout() || (pPage->GetSortedObjs() && pPage->IsInvalidFly()) )
return false;
}
if ( !pPage )
pPage = pCnt->FindPageFrame();
// format floating screen objects at content frame.
if ( pCnt->IsTextFrame() &&
!SwObjectFormatter::FormatObjsAtFrame( *const_cast<SwContentFrame*>(pCnt),
*pPage, this ) )
{
return false;
}
if ( pPage->IsInvalidContent() )
return false;
return true;
}
bool SwLayAction::TurboAction()
{
bool bRet = true;
if ( m_pRoot->GetTurbo() )
{
if ( !TurboAction_( m_pRoot->GetTurbo() ) )
bRet = false;
m_pRoot->ResetTurbo();
}
else
bRet = false;
return bRet;
}
static bool lcl_IsInvaLay( const SwFrame *pFrame, long nBottom )
{
return !pFrame->isFrameAreaDefinitionValid() ||
(pFrame->IsCompletePaint() && ( pFrame->getFrameArea().Top() < nBottom ) );
}
static const SwFrame *lcl_FindFirstInvaLay( const SwFrame *pFrame, long nBottom )
{
OSL_ENSURE( pFrame->IsLayoutFrame(), "FindFirstInvaLay, no LayFrame" );
if (lcl_IsInvaLay(pFrame, nBottom))
return pFrame;
pFrame = static_cast<const SwLayoutFrame*>(pFrame)->Lower();
while ( pFrame )
{
if ( pFrame->IsLayoutFrame() )
{
if (lcl_IsInvaLay(pFrame, nBottom))
return pFrame;
const SwFrame *pTmp = lcl_FindFirstInvaLay( pFrame, nBottom );
if ( nullptr != pTmp )
return pTmp;
}
pFrame = pFrame->GetNext();
}
return nullptr;
}
static const SwFrame *lcl_FindFirstInvaContent( const SwLayoutFrame *pLay, long nBottom,
const SwContentFrame *pFirst )
{
const SwContentFrame *pCnt = pFirst ? pFirst->GetNextContentFrame() :
pLay->ContainsContent();
while ( pCnt )
{
if ( !pCnt->isFrameAreaDefinitionValid() || pCnt->IsCompletePaint() )
{
if ( pCnt->getFrameArea().Top() <= nBottom )
return pCnt;
}
if ( pCnt->GetDrawObjs() )
{
const SwSortedObjs &rObjs = *pCnt->GetDrawObjs();
for (SwAnchoredObject* pObj : rObjs)
{
if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pObj ) )
{
if ( pFly->IsFlyInContentFrame() )
{
if ( static_cast<const SwFlyInContentFrame*>(pFly)->IsInvalid() ||
pFly->IsCompletePaint() )
{
if ( pFly->getFrameArea().Top() <= nBottom )
return pFly;
}
const SwFrame *pFrame = lcl_FindFirstInvaContent( pFly, nBottom, nullptr );
if ( pFrame && pFrame->getFrameArea().Bottom() <= nBottom )
return pFrame;
}
}
}
}
if ( pCnt->getFrameArea().Top() > nBottom && !pCnt->IsInTab() )
return nullptr;
pCnt = pCnt->GetNextContentFrame();
if ( !pLay->IsAnLower( pCnt ) )
break;
}
return nullptr;
}
// consider drawing objects
static const SwAnchoredObject* lcl_FindFirstInvaObj( const SwPageFrame* _pPage,
long _nBottom )
{
OSL_ENSURE( _pPage->GetSortedObjs(), "FindFirstInvaObj, no Objs" );
for (SwAnchoredObject* pObj : *_pPage->GetSortedObjs())
{
if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pObj ) )
{
if ( pFly->getFrameArea().Top() <= _nBottom )
{
if ( pFly->IsInvalid() || pFly->IsCompletePaint() )
return pFly;
const SwFrame* pTmp;
if ( nullptr != (pTmp = lcl_FindFirstInvaContent( pFly, _nBottom, nullptr )) &&
pTmp->getFrameArea().Top() <= _nBottom )
return pFly;
}
}
else if ( auto pDrawObject = dynamic_cast< const SwAnchoredDrawObject *>( pObj ) )
{
if ( !pDrawObject->IsValidPos() )
{
return pObj;
}
}
}
return nullptr;
}
/* Returns True if the page lies directly below or right of the visible area.
*
* It's possible for things to change in such a way that the processing
* (of the caller!) has to continue with the predecessor of the passed page.
* The parameter might therefore get modified!
* For BrowseMode, you may even activate the ShortCut if the invalid content
* of the page lies below the visible area.
*/
bool SwLayAction::IsShortCut( SwPageFrame *&prPage )
{
vcl::RenderContext* pRenderContext = m_pImp->GetShell()->GetOut();
bool bRet = false;
const SwViewShell *pSh = m_pRoot->GetCurrShell();
const bool bBrowse = pSh && pSh->GetViewOptions()->getBrowseMode();
// If the page is not valid, we quickly format it, otherwise
// there's gonna be no end of trouble
if ( !prPage->isFrameAreaDefinitionValid() )
{
if ( bBrowse )
{
// format complete page
// Thus, loop on all lowers of the page <prPage>, instead of only
// format its first lower.
// NOTE: In online layout (bBrowse == true) a page can contain
// a header frame and/or a footer frame beside the body frame.
prPage->Calc(pRenderContext);
SwFrame* pPageLowerFrame = prPage->Lower();
while ( pPageLowerFrame )
{
pPageLowerFrame->Calc(pRenderContext);
pPageLowerFrame = pPageLowerFrame->GetNext();
}
}
else
FormatLayout( pSh ? pSh->GetOut() : nullptr, prPage );
if ( IsAgain() )
return false;
}
const SwRect &rVis = m_pImp->GetShell()->VisArea();
if ( (prPage->getFrameArea().Top() >= rVis.Bottom()) ||
(prPage->getFrameArea().Left()>= rVis.Right()) )
{
bRet = true;
// This is going to be a bit nasty: The first ContentFrame of this
// page in the Body text needs formatting; if it changes the page during
// that process, I need to start over a page further back, because we
// have been processing a PageBreak.
// Even more uncomfortable: The next ContentFrame must be formatted,
// because it's possible for empty pages to exist temporarily (for example
// a paragraph across multiple pages gets deleted or reduced in size).
// This is irrelevant for the browser, if the last Cnt above it
// isn't visible anymore.
const SwPageFrame *p2ndPage = prPage;
const SwContentFrame *pContent;
const SwLayoutFrame* pBody = p2ndPage->FindBodyCont();
if( p2ndPage->IsFootnotePage() && pBody )
pBody = static_cast<const SwLayoutFrame*>(pBody->GetNext());
pContent = pBody ? pBody->ContainsContent() : nullptr;
while ( p2ndPage && !pContent )
{
p2ndPage = static_cast<const SwPageFrame*>(p2ndPage->GetNext());
if( p2ndPage )
{
pBody = p2ndPage->FindBodyCont();
if( p2ndPage->IsFootnotePage() && pBody )
pBody = static_cast<const SwLayoutFrame*>(pBody->GetNext());
pContent = pBody ? pBody->ContainsContent() : nullptr;
}
}
if ( pContent )
{
bool bTstCnt = true;
if ( bBrowse )
{
// Is the Cnt before already invisible?
const SwFrame *pLst = pContent;
if ( pLst->IsInTab() )
pLst = pContent->FindTabFrame();
if ( pLst->IsInSct() )
pLst = pContent->FindSctFrame();
pLst = pLst->FindPrev();
if ( pLst &&
(pLst->getFrameArea().Top() >= rVis.Bottom() ||
pLst->getFrameArea().Left()>= rVis.Right()) )
{
bTstCnt = false;
}
}
if ( bTstCnt )
{
// check after each frame calculation,
// if the content frame has changed the page. If yes, no other
// frame calculation is performed
bool bPageChg = false;
if ( pContent->IsInSct() )
{
const SwSectionFrame *pSct = const_cast<SwFrame*>(static_cast<SwFrame const *>(pContent))->ImplFindSctFrame();
if ( !pSct->isFrameAreaDefinitionValid() )
{
pSct->Calc(pRenderContext);
pSct->SetCompletePaint();
if ( IsAgain() )
return false;
bPageChg = pContent->FindPageFrame() != p2ndPage &&
prPage->GetPrev();
}
}
if ( !bPageChg && !pContent->isFrameAreaDefinitionValid() )
{
pContent->Calc(pRenderContext);
pContent->SetCompletePaint();
if ( IsAgain() )
return false;
bPageChg = pContent->FindPageFrame() != p2ndPage &&
prPage->GetPrev();
}
if ( !bPageChg && pContent->IsInTab() )
{
const SwTabFrame *pTab = const_cast<SwFrame*>(static_cast<SwFrame const *>(pContent))->ImplFindTabFrame();
if ( !pTab->isFrameAreaDefinitionValid() )
{
pTab->Calc(pRenderContext);
pTab->SetCompletePaint();
if ( IsAgain() )
return false;
bPageChg = pContent->FindPageFrame() != p2ndPage &&
prPage->GetPrev();
}
}
if ( !bPageChg && pContent->IsInSct() )
{
const SwSectionFrame *pSct = const_cast<SwFrame*>(static_cast<SwFrame const *>(pContent))->ImplFindSctFrame();
if ( !pSct->isFrameAreaDefinitionValid() )
{
pSct->Calc(pRenderContext);
pSct->SetCompletePaint();
if ( IsAgain() )
return false;
bPageChg = pContent->FindPageFrame() != p2ndPage &&
prPage->GetPrev();
}
}
if ( bPageChg )
{
bRet = false;
const SwPageFrame* pTmp = pContent->FindPageFrame();
if ( pTmp->GetPhyPageNum() < prPage->GetPhyPageNum() &&
pTmp->IsInvalid() )
{
prPage = const_cast<SwPageFrame*>(pTmp);
}
else
{
prPage = static_cast<SwPageFrame*>(prPage->GetPrev());
}
}
// no shortcut, if at previous page
// an anchored object is registered, whose anchor is <pContent>.
else if ( prPage->GetPrev() )
{
SwSortedObjs* pObjs =
static_cast<SwPageFrame*>(prPage->GetPrev())->GetSortedObjs();
if ( pObjs )
{
for (SwAnchoredObject* pObj : *pObjs)
{
if ( pObj->GetAnchorFrameContainingAnchPos() == pContent )
{
bRet = false;
break;
}
}
}
}
}
}
}
if ( !bRet && bBrowse )
{
const long nBottom = rVis.Bottom();
const SwAnchoredObject* pObj( nullptr );
if ( prPage->GetSortedObjs() &&
(prPage->IsInvalidFlyLayout() || prPage->IsInvalidFlyContent()) &&
nullptr != (pObj = lcl_FindFirstInvaObj( prPage, nBottom )) &&
pObj->GetObjRect().Top() <= nBottom )
{
return false;
}
const SwFrame* pFrame( nullptr );
if ( prPage->IsInvalidLayout() &&
nullptr != (pFrame = lcl_FindFirstInvaLay( prPage, nBottom )) &&
pFrame->getFrameArea().Top() <= nBottom )
{
return false;
}
if ( (prPage->IsInvalidContent() || prPage->IsInvalidFlyInCnt()) &&
nullptr != (pFrame = lcl_FindFirstInvaContent( prPage, nBottom, nullptr )) &&
pFrame->getFrameArea().Top() <= nBottom )
{
return false;
}
bRet = true;
}
return bRet;
}
// introduce support for vertical layout
bool SwLayAction::FormatLayout( OutputDevice *pRenderContext, SwLayoutFrame *pLay, bool bAddRect )
{
// save page for loop control
if( pLay->IsPageFrame() && static_cast<SwPageFrame*>(pLay) != m_pCurPage )
{
m_nCallCount = 0;
m_pCurPage = static_cast<SwPageFrame*>(pLay);
}
OSL_ENSURE( !IsAgain(), "Attention to the invalid page." );
if ( IsAgain() )
return false;
bool bChanged = false;
bool bAlreadyPainted = false;
// remember frame at complete paint
SwRect aFrameAtCompletePaint;
if ( !pLay->isFrameAreaDefinitionValid() || pLay->IsCompletePaint() )
{
if ( pLay->GetPrev() && !pLay->GetPrev()->isFrameAreaDefinitionValid() )
pLay->GetPrev()->SetCompletePaint();
SwRect aOldFrame( pLay->getFrameArea() );
SwRect aOldRect( aOldFrame );
if( pLay->IsPageFrame() )
{
aOldRect = static_cast<SwPageFrame*>(pLay)->GetBoundRect(pRenderContext);
}
{
SwFrameDeleteGuard aDeleteGuard(pLay);
pLay->Calc(pRenderContext);
}
if ( aOldFrame != pLay->getFrameArea() )
bChanged = true;
bool bNoPaint = false;
if ( pLay->IsPageBodyFrame() &&
pLay->getFrameArea().Pos() == aOldRect.Pos() &&
pLay->Lower() )
{
const SwViewShell *pSh = pLay->getRootFrame()->GetCurrShell();
// Limitations because of headers / footers
if( pSh && pSh->GetViewOptions()->getBrowseMode() &&
!( pLay->IsCompletePaint() && pLay->FindPageFrame()->FindFootnoteCont() ) )
bNoPaint = true;
}
if ( !bNoPaint && IsPaint() && bAddRect && (pLay->IsCompletePaint() || bChanged) )
{
SwRect aPaint( pLay->getFrameArea() );
// consider border and shadow for
// page frames -> enlarge paint rectangle correspondingly.
if ( pLay->IsPageFrame() )
{
SwPageFrame* pPageFrame = static_cast<SwPageFrame*>(pLay);
aPaint = pPageFrame->GetBoundRect(pRenderContext);
}
bool bPageInBrowseMode = pLay->IsPageFrame();
if( bPageInBrowseMode )
{
const SwViewShell *pSh = pLay->getRootFrame()->GetCurrShell();
if( !pSh || !pSh->GetViewOptions()->getBrowseMode() )
bPageInBrowseMode = false;
}
if( bPageInBrowseMode )
{
// NOTE: no vertical layout in online layout
// Is the change even visible?
if ( pLay->IsCompletePaint() )
{
m_pImp->GetShell()->AddPaintRect( aPaint );
bAddRect = false;
}
else
{
SwRegionRects aRegion( aOldRect );
aRegion -= aPaint;
for ( size_t i = 0; i < aRegion.size(); ++i )
m_pImp->GetShell()->AddPaintRect( aRegion[i] );
aRegion.ChangeOrigin( aPaint );
aRegion.clear();
aRegion.push_back( aPaint );
aRegion -= aOldRect;
for ( size_t i = 0; i < aRegion.size(); ++i )
m_pImp->GetShell()->AddPaintRect( aRegion[i] );
}
}
else
{
m_pImp->GetShell()->AddPaintRect( aPaint );
bAlreadyPainted = true;
// remember frame at complete paint
aFrameAtCompletePaint = pLay->getFrameArea();
}
// provide paint of spacing
// between pages (not only for in online mode).
if ( pLay->IsPageFrame() )
{
const SwViewShell *pSh = pLay->getRootFrame()->GetCurrShell();
const SwTwips nHalfDocBorder = pSh ? pSh->GetViewOptions()->GetGapBetweenPages()
: SwViewOption::defGapBetweenPages;
const bool bLeftToRightViewLayout = m_pRoot->IsLeftToRightViewLayout();
const bool bPrev = bLeftToRightViewLayout ? pLay->GetPrev() : pLay->GetNext();
const bool bNext = bLeftToRightViewLayout ? pLay->GetNext() : pLay->GetPrev();
SwPageFrame* pPageFrame = static_cast<SwPageFrame*>(pLay);
SwRect aPageRect( pLay->getFrameArea() );
if(pSh)
{
SwPageFrame::GetBorderAndShadowBoundRect(aPageRect, pSh,
pRenderContext,
aPageRect, pPageFrame->IsLeftShadowNeeded(), pPageFrame->IsRightShadowNeeded(),
pPageFrame->SidebarPosition() == sw::sidebarwindows::SidebarPosition::RIGHT);
}
if ( bPrev )
{
// top
SwRect aSpaceToPrevPage( aPageRect );
aSpaceToPrevPage.Top( aSpaceToPrevPage.Top() - nHalfDocBorder );
aSpaceToPrevPage.Bottom( pLay->getFrameArea().Top() );
if(!aSpaceToPrevPage.IsEmpty())
m_pImp->GetShell()->AddPaintRect( aSpaceToPrevPage );
// left
aSpaceToPrevPage = aPageRect;
aSpaceToPrevPage.Left( aSpaceToPrevPage.Left() - nHalfDocBorder );
aSpaceToPrevPage.Right( pLay->getFrameArea().Left() );
if(!aSpaceToPrevPage.IsEmpty())
m_pImp->GetShell()->AddPaintRect( aSpaceToPrevPage );
}
if ( bNext )
{
// bottom
SwRect aSpaceToNextPage( aPageRect );
aSpaceToNextPage.Bottom( aSpaceToNextPage.Bottom() + nHalfDocBorder );
aSpaceToNextPage.Top( pLay->getFrameArea().Bottom() );
if(!aSpaceToNextPage.IsEmpty())
m_pImp->GetShell()->AddPaintRect( aSpaceToNextPage );
// right
aSpaceToNextPage = aPageRect;
aSpaceToNextPage.Right( aSpaceToNextPage.Right() + nHalfDocBorder );
aSpaceToNextPage.Left( pLay->getFrameArea().Right() );
if(!aSpaceToNextPage.IsEmpty())
m_pImp->GetShell()->AddPaintRect( aSpaceToNextPage );
}
}
}
pLay->ResetCompletePaint();
}
if ( IsPaint() && bAddRect &&
!pLay->GetNext() && pLay->IsRetoucheFrame() && pLay->IsRetouche() )
{
// vertical layout support
SwRectFnSet aRectFnSet(pLay);
SwRect aRect( pLay->GetUpper()->GetPaintArea() );
aRectFnSet.SetTop( aRect, aRectFnSet.GetPrtBottom(*pLay) );
if ( !m_pImp->GetShell()->AddPaintRect( aRect ) )
pLay->ResetRetouche();
}
if( bAlreadyPainted )
bAddRect = false;
CheckWaitCursor();
if ( IsAgain() )
return false;
// Now, deal with the lowers that are LayoutFrames
if ( pLay->IsFootnoteFrame() ) // no LayFrames as Lower
return bChanged;
SwFrame *pLow = pLay->Lower();
bool bTabChanged = false;
while ( pLow && pLow->GetUpper() == pLay )
{
SwFrame* pNext = nullptr;
if ( pLow->IsLayoutFrame() )
{
if ( pLow->IsTabFrame() )
{
// loop control for embedded tables
if ( m_nTabLevel > 0 && ++m_nCallCount > 50 ) {
static_cast<SwTabFrame*>(pLow)->SetSplitRowDisabled();
}
++m_nTabLevel;
// Remember what was the next of the lower. Formatting may move it to the previous
// page, in which case it looses its next.
pNext = pLow->GetNext();
if (pNext && pNext->IsTabFrame())
{
auto pTab = static_cast<SwTabFrame*>(pNext);
if (pTab->IsFollow())
{
// The next frame is a follow of the previous frame, SwTabFrame::Join() will
// delete this one as part of formatting, so forget about it.
pNext = nullptr;
}
}
bTabChanged |= FormatLayoutTab( static_cast<SwTabFrame*>(pLow), bAddRect );
--m_nTabLevel;
}
// Skip the ones already registered for deletion
else if( !pLow->IsSctFrame() || static_cast<SwSectionFrame*>(pLow)->GetSection() )
bChanged |= FormatLayout( pRenderContext, static_cast<SwLayoutFrame*>(pLow), bAddRect );
}
else if ( m_pImp->GetShell()->IsPaintLocked() )
// Shortcut to minimize the cycles. With Lock, the
// paint is coming either way (primarily for browse)
pLow->OptCalc();
if ( IsAgain() )
return false;
if (!pNext)
{
pNext = pLow->GetNext();
}
pLow = pNext;
}
// add complete frame area as paint area, if frame
// area has been already added and after formatting its lowers the frame area
// is enlarged.
SwRect aBoundRect(pLay->IsPageFrame() ? static_cast<SwPageFrame*>(pLay)->GetBoundRect(pRenderContext) : pLay->getFrameArea() );
if ( bAlreadyPainted &&
( aBoundRect.Width() > aFrameAtCompletePaint.Width() ||
aBoundRect.Height() > aFrameAtCompletePaint.Height() )
)
{
m_pImp->GetShell()->AddPaintRect( aBoundRect );
}
return bChanged || bTabChanged;
}
void SwLayAction::FormatLayoutFly( SwFlyFrame* pFly )
{
vcl::RenderContext* pRenderContext = m_pImp->GetShell()->GetOut();
OSL_ENSURE( !IsAgain(), "Attention to the invalid page." );
if ( IsAgain() )
return;
bool bChanged = false;<--- Variable 'bChanged' is assigned a value that is never used.
bool bAddRect = true;
if ( !pFly->isFrameAreaDefinitionValid() || pFly->IsCompletePaint() || pFly->IsInvalid() )
{
// The Frame has changed, now it's getting formatted.
const SwRect aOldRect( pFly->getFrameArea() );
pFly->Calc(pRenderContext);
bChanged = aOldRect != pFly->getFrameArea();
if ( IsPaint() && (pFly->IsCompletePaint() || bChanged) &&
pFly->getFrameArea().Top() > 0 && pFly->getFrameArea().Left() > 0 )
m_pImp->GetShell()->AddPaintRect( pFly->getFrameArea() );
if ( bChanged )
pFly->Invalidate();
else
pFly->Validate();
bAddRect = false;
pFly->ResetCompletePaint();
}
if ( IsAgain() )
return;
// Now, deal with the lowers that are LayoutFrames
bool bTabChanged = false;<--- Variable 'bTabChanged' is assigned a value that is never used.
SwFrame *pLow = pFly->Lower();
while ( pLow )
{
if ( pLow->IsLayoutFrame() )
{
if ( pLow->IsTabFrame() )
bTabChanged |= FormatLayoutTab( static_cast<SwTabFrame*>(pLow), bAddRect );<--- Variable 'bTabChanged' is assigned a value that is never used.
else
bChanged |= FormatLayout( m_pImp->GetShell()->GetOut(), static_cast<SwLayoutFrame*>(pLow), bAddRect );<--- Variable 'bChanged' is assigned a value that is never used.
}
pLow = pLow->GetNext();
}
}
// Implement vertical layout support
bool SwLayAction::FormatLayoutTab( SwTabFrame *pTab, bool bAddRect )
{
OSL_ENSURE( !IsAgain(), "8-) Attention to the invalid page." );
if ( IsAgain() || !pTab->Lower() )
return false;
vcl::RenderContext* pRenderContext = m_pImp->GetShell()->GetOut();
IDocumentTimerAccess& rTimerAccess = m_pRoot->GetFormat()->getIDocumentTimerAccess();
rTimerAccess.BlockIdling();
bool bChanged = false;
bool bPainted = false;
const SwPageFrame *pOldPage = pTab->FindPageFrame();
// vertical layout support
SwRectFnSet aRectFnSet(pTab);
if ( !pTab->isFrameAreaDefinitionValid() || pTab->IsCompletePaint() || pTab->IsComplete() )
{
if ( pTab->GetPrev() && !pTab->GetPrev()->isFrameAreaDefinitionValid() )
{
pTab->GetPrev()->SetCompletePaint();
}
const SwRect aOldRect( pTab->getFrameArea() );
pTab->SetLowersFormatted( false );
pTab->Calc(pRenderContext);
if ( aOldRect != pTab->getFrameArea() )
{
bChanged = true;
}
const SwRect aPaintFrame = pTab->GetPaintArea();
if ( IsPaint() && bAddRect )
{
// add condition <pTab->getFrameArea().HasArea()>
if ( !pTab->IsCompletePaint() &&
pTab->IsComplete() &&
( pTab->getFrameArea().SSize() != pTab->getFramePrintArea().SSize() ||
// vertical layout support
aRectFnSet.GetLeftMargin(*pTab) ) &&
pTab->getFrameArea().HasArea()
)
{
// re-implement calculation of margin rectangles.
SwRect aMarginRect;
SwTwips nLeftMargin = aRectFnSet.GetLeftMargin(*pTab);
if ( nLeftMargin > 0)
{
aMarginRect = pTab->getFrameArea();
aRectFnSet.SetWidth( aMarginRect, nLeftMargin );
m_pImp->GetShell()->AddPaintRect( aMarginRect );
}
if ( aRectFnSet.GetRightMargin(*pTab) > 0)
{
aMarginRect = pTab->getFrameArea();
aRectFnSet.SetLeft( aMarginRect, aRectFnSet.GetPrtRight(*pTab) );
m_pImp->GetShell()->AddPaintRect( aMarginRect );
}
SwTwips nTopMargin = aRectFnSet.GetTopMargin(*pTab);
if ( nTopMargin > 0)
{
aMarginRect = pTab->getFrameArea();
aRectFnSet.SetHeight( aMarginRect, nTopMargin );
m_pImp->GetShell()->AddPaintRect( aMarginRect );
}
if ( aRectFnSet.GetBottomMargin(*pTab) > 0)
{
aMarginRect = pTab->getFrameArea();
aRectFnSet.SetTop( aMarginRect, aRectFnSet.GetPrtBottom(*pTab) );
m_pImp->GetShell()->AddPaintRect( aMarginRect );
}
}
else if ( pTab->IsCompletePaint() )
{
m_pImp->GetShell()->AddPaintRect( aPaintFrame );
bAddRect = false;
bPainted = true;
}
if ( pTab->IsRetouche() && !pTab->GetNext() )
{
SwRect aRect( pTab->GetUpper()->GetPaintArea() );
// vertical layout support
aRectFnSet.SetTop( aRect, aRectFnSet.GetPrtBottom(*pTab) );
if ( !m_pImp->GetShell()->AddPaintRect( aRect ) )
pTab->ResetRetouche();
}
}
else
bAddRect = false;
if ( pTab->IsCompletePaint() && !m_pOptTab )
m_pOptTab = pTab;
pTab->ResetCompletePaint();
}
if ( IsPaint() && bAddRect && pTab->IsRetouche() && !pTab->GetNext() )
{
// set correct rectangle for retouche: area between bottom of table frame
// and bottom of paint area of the upper frame.
SwRect aRect( pTab->GetUpper()->GetPaintArea() );
// vertical layout support
aRectFnSet.SetTop( aRect, aRectFnSet.GetPrtBottom(*pTab) );
if ( !m_pImp->GetShell()->AddPaintRect( aRect ) )
pTab->ResetRetouche();
}
CheckWaitCursor();
rTimerAccess.UnblockIdling();
// Ugly shortcut!
if ( pTab->IsLowersFormatted() &&
(bPainted || !m_pImp->GetShell()->VisArea().IsOver( pTab->getFrameArea())) )
return false;
// Now, deal with the lowers
if ( IsAgain() )
return false;
// for safety reasons:
// check page number before formatting lowers.
if ( pOldPage->GetPhyPageNum() > (pTab->FindPageFrame()->GetPhyPageNum() + 1) )
SetNextCycle( true );
// format lowers, only if table frame is valid
if ( pTab->isFrameAreaDefinitionValid() )
{
FlowFrameJoinLockGuard tabG(pTab); // tdf#124675 prevent Join() if pTab becomes empty
SwLayoutFrame *pLow = static_cast<SwLayoutFrame*>(pTab->Lower());
while ( pLow )
{
SwFrameDeleteGuard rowG(pLow); // tdf#124675 prevent RemoveFollowFlowLine()
bChanged |= FormatLayout( m_pImp->GetShell()->GetOut(), pLow, bAddRect );
if ( IsAgain() )
return false;
pLow = static_cast<SwLayoutFrame*>(pLow->GetNext());
}
}
return bChanged;
}
bool SwLayAction::FormatContent( const SwPageFrame *pPage )
{
const SwContentFrame *pContent = pPage->ContainsContent();
const SwViewShell *pSh = m_pRoot->GetCurrShell();
const bool bBrowse = pSh && pSh->GetViewOptions()->getBrowseMode();
while ( pContent && pPage->IsAnLower( pContent ) )
{
// If the content didn't change, we can use a few shortcuts.
const bool bFull = !pContent->isFrameAreaDefinitionValid() || pContent->IsCompletePaint() ||
pContent->IsRetouche() || pContent->GetDrawObjs();
if ( bFull )
{
// We do this so we don't have to search later on.
const bool bNxtCnt = IsCalcLayout() && !pContent->GetFollow();
const SwContentFrame *pContentNext = bNxtCnt ? pContent->GetNextContentFrame() : nullptr;
const SwContentFrame *pContentPrev = pContent->GetPrev() ? pContent->GetPrevContentFrame() : nullptr;
const SwLayoutFrame*pOldUpper = pContent->GetUpper();
const SwTabFrame *pTab = pContent->FindTabFrame();
const bool bInValid = !pContent->isFrameAreaDefinitionValid() || pContent->IsCompletePaint();
const bool bOldPaint = IsPaint();
m_bPaint = bOldPaint && !(pTab && pTab == m_pOptTab);
FormatContent_( pContent, pPage );
// reset <bPaint> before format objects
m_bPaint = bOldPaint;
// format floating screen object at content frame.
// No format, if action flag <bAgain> is set or action is interrupted.
// allow format on interruption of action, if
// it's the format for this interrupt
// pass correct page frame
// to the object formatter.
if ( !IsAgain() &&
( !IsInterrupt() || mbFormatContentOnInterrupt ) &&
pContent->IsTextFrame() &&
!SwObjectFormatter::FormatObjsAtFrame( *const_cast<SwContentFrame*>(pContent),
*(pContent->FindPageFrame()), this ) )
{
return false;
}
if ( !pContent->GetValidLineNumFlag() && pContent->IsTextFrame() )
{
const sal_uLong nAllLines = static_cast<const SwTextFrame*>(pContent)->GetAllLines();
const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pContent))->RecalcAllLines();
if ( IsPaintExtraData() && IsPaint() &&
nAllLines != static_cast<const SwTextFrame*>(pContent)->GetAllLines() )
m_pImp->GetShell()->AddPaintRect( pContent->getFrameArea() );
}
if ( IsAgain() )
return false;
// Temporarily interrupt processing if layout or Flys become invalid again.
// However not for the BrowseView: The layout is getting invalid
// all the time because the page height gets adjusted.
// The same applies if the user wants to continue working and at least one
// paragraph has been processed.
if (!pTab || !bInValid)
{
// consider interrupt formatting.
if ( ( IsInterrupt() && !mbFormatContentOnInterrupt ) ||
( !bBrowse && pPage->IsInvalidLayout() ) ||
// consider interrupt formatting
( pPage->GetSortedObjs() && pPage->IsInvalidFly() && !mbFormatContentOnInterrupt )
)
return false;
}
if ( pOldUpper != pContent->GetUpper() )
{
const sal_uInt16 nCurNum = pContent->FindPageFrame()->GetPhyPageNum();
if ( nCurNum < pPage->GetPhyPageNum() )
m_nPreInvaPage = nCurNum;
// If the frame flowed backwards more than one page, we need to
// start over again from the beginning, so nothing gets left out.
if ( !IsCalcLayout() && pPage->GetPhyPageNum() > nCurNum+1 )
{
SetNextCycle( true );
// consider interrupt formatting
if ( !mbFormatContentOnInterrupt )
{
return false;
}
}
}
// If the frame moved forwards to the next page, we re-run through
// the predecessor.
// This way, we catch predecessors which are now responsible for
// retouching, but the footers will be touched also.
bool bSetContent = true;
if ( pContentPrev )
{
if ( !pContentPrev->isFrameAreaDefinitionValid() && pPage->IsAnLower( pContentPrev ) )
{
pPage->InvalidateContent();
}
if ( pOldUpper != pContent->GetUpper() &&
pPage->GetPhyPageNum() < pContent->FindPageFrame()->GetPhyPageNum() )
{
pContent = pContentPrev;
bSetContent = false;
}
}
if ( bSetContent )
{
if ( bBrowse && !IsIdle() && !IsCalcLayout() && !IsComplete() &&
pContent->getFrameArea().Top() > m_pImp->GetShell()->VisArea().Bottom())
{
const long nBottom = m_pImp->GetShell()->VisArea().Bottom();
const SwFrame *pTmp = lcl_FindFirstInvaContent( pPage,
nBottom, pContent );
if ( !pTmp )
{
if ( (!(pPage->GetSortedObjs() && pPage->IsInvalidFly()) ||
!lcl_FindFirstInvaObj( pPage, nBottom )) &&
(!pPage->IsInvalidLayout() ||
!lcl_FindFirstInvaLay( pPage, nBottom )))
SetBrowseActionStop( true );
// consider interrupt formatting.
if ( !mbFormatContentOnInterrupt )
{
return false;
}
}
}
pContent = bNxtCnt ? pContentNext : pContent->GetNextContentFrame();
}
if (IsReschedule())
{
::RescheduleProgress(m_pImp->GetShell()->GetDoc()->GetDocShell());
}
}
else
{
if ( !pContent->GetValidLineNumFlag() && pContent->IsTextFrame() )
{
const sal_uLong nAllLines = static_cast<const SwTextFrame*>(pContent)->GetAllLines();
const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pContent))->RecalcAllLines();
if ( IsPaintExtraData() && IsPaint() &&
nAllLines != static_cast<const SwTextFrame*>(pContent)->GetAllLines() )
m_pImp->GetShell()->AddPaintRect( pContent->getFrameArea() );
}
// Do this if the frame has been formatted before.
if ( pContent->IsTextFrame() && static_cast<const SwTextFrame*>(pContent)->HasRepaint() &&
IsPaint() )
PaintContent( pContent, pPage, pContent->getFrameArea(), pContent->getFrameArea().Bottom());
if ( IsIdle() )
{
// consider interrupt formatting.
if ( IsInterrupt() && !mbFormatContentOnInterrupt )
return false;
}
if ( bBrowse && !IsIdle() && !IsCalcLayout() && !IsComplete() &&
pContent->getFrameArea().Top() > m_pImp->GetShell()->VisArea().Bottom())
{
const long nBottom = m_pImp->GetShell()->VisArea().Bottom();
const SwFrame *pTmp = lcl_FindFirstInvaContent( pPage,
nBottom, pContent );
if ( !pTmp )
{
if ( (!(pPage->GetSortedObjs() && pPage->IsInvalidFly()) ||
!lcl_FindFirstInvaObj( pPage, nBottom )) &&
(!pPage->IsInvalidLayout() ||
!lcl_FindFirstInvaLay( pPage, nBottom )))
SetBrowseActionStop( true );
// consider interrupt formatting.
if ( !mbFormatContentOnInterrupt )
{
return false;
}
}
}
pContent = pContent->GetNextContentFrame();
}
}
CheckWaitCursor();
// consider interrupt formatting.
return !IsInterrupt() || mbFormatContentOnInterrupt;
}
void SwLayAction::FormatContent_( const SwContentFrame *pContent, const SwPageFrame *pPage )
{
// We probably only ended up here because the Content holds DrawObjects.
const bool bDrawObjsOnly = pContent->isFrameAreaDefinitionValid() && !pContent->IsCompletePaint() && !pContent->IsRetouche();
SwRectFnSet aRectFnSet(pContent);
if ( !bDrawObjsOnly && IsPaint() )
{
const SwRect aOldRect( pContent->UnionFrame() );
const long nOldBottom = aRectFnSet.GetPrtBottom(*pContent);
pContent->OptCalc();
if( IsAgain() )
return;
if( aRectFnSet.YDiff( aRectFnSet.GetBottom(pContent->getFrameArea()),
aRectFnSet.GetBottom(aOldRect) ) < 0 )
{
pContent->SetRetouche();
}
PaintContent( pContent, pContent->FindPageFrame(), aOldRect, nOldBottom);
}
else
{
if ( IsPaint() && pContent->IsTextFrame() && static_cast<const SwTextFrame*>(pContent)->HasRepaint() )
PaintContent( pContent, pPage, pContent->getFrameArea(),
aRectFnSet.GetBottom(pContent->getFrameArea()) );
pContent->OptCalc();
}
}
void SwLayAction::FormatFlyContent( const SwFlyFrame *pFly )
{
const SwContentFrame *pContent = pFly->ContainsContent();
while ( pContent )
{
FormatContent_( pContent, pContent->FindPageFrame() );
// format floating screen objects at content text frame
// pass correct page frame to the object formatter.
if ( pContent->IsTextFrame() &&
!SwObjectFormatter::FormatObjsAtFrame(
*const_cast<SwContentFrame*>(pContent),
*(pContent->FindPageFrame()), this ) )
{
// restart format with first content
pContent = pFly->ContainsContent();
continue;
}
if ( !pContent->GetValidLineNumFlag() && pContent->IsTextFrame() )
{
const sal_uLong nAllLines = static_cast<const SwTextFrame*>(pContent)->GetAllLines();
const_cast<SwTextFrame*>(static_cast<const SwTextFrame*>(pContent))->RecalcAllLines();
if ( IsPaintExtraData() && IsPaint() &&
nAllLines != static_cast<const SwTextFrame*>(pContent)->GetAllLines() )
m_pImp->GetShell()->AddPaintRect( pContent->getFrameArea() );
}
if ( IsAgain() )
return;
// If there's input, we interrupt processing.
if ( !pFly->IsFlyInContentFrame() )
{
// consider interrupt formatting.
if ( IsInterrupt() && !mbFormatContentOnInterrupt )
return;
}
pContent = pContent->GetNextContentFrame();
}
CheckWaitCursor();
}
bool SwLayIdle::IsInterrupt()
{
return m_aWatch.exceededRuntime();
}
bool SwLayIdle::DoIdleJob_( const SwContentFrame *pCnt, IdleJobType eJob )
{
OSL_ENSURE( pCnt->IsTextFrame(), "NoText neighbour of Text" );
// robust against misuse by e.g. #i52542#
if( !pCnt->IsTextFrame() )
return false;
SwTextFrame const*const pTextFrame(static_cast<SwTextFrame const*>(pCnt));
// sw_redlinehide: spell check only the nodes with visible content?
SwTextNode* pTextNode = const_cast<SwTextNode*>(pTextFrame->GetTextNodeForParaProps());
bool bProcess = false;
for (size_t i = 0; pTextNode; )
{
switch ( eJob )
{
case ONLINE_SPELLING :
bProcess = pTextNode->IsWrongDirty(); break;
case AUTOCOMPLETE_WORDS :
bProcess = pTextNode->IsAutoCompleteWordDirty(); break;
case WORD_COUNT :
bProcess = pTextNode->IsWordCountDirty(); break;
case SMART_TAGS :
bProcess = pTextNode->IsSmartTagDirty(); break;
}
if (bProcess)
{
break;
}
if (sw::MergedPara const* pMerged = pTextFrame->GetMergedPara())
{
while (true)
{
++i;
if (i < pMerged->extents.size())
{
if (pMerged->extents[i].pNode != pTextNode)
{
pTextNode = pMerged->extents[i].pNode;
break;
}
}
else
{
pTextNode = nullptr;
break;
}
}
}
else
pTextNode = nullptr;
}
if( bProcess )
{
assert(pTextNode);
SwViewShell *pSh = pImp->GetShell();
if( COMPLETE_STRING == nTextPos )
{
--nTextPos;
if( dynamic_cast< const SwCursorShell *>( pSh ) != nullptr && !static_cast<SwCursorShell*>(pSh)->IsTableMode() )
{
SwPaM *pCursor = static_cast<SwCursorShell*>(pSh)->GetCursor();
if( !pCursor->HasMark() && !pCursor->IsMultiSelection() )
{
pContentNode = pCursor->GetContentNode();
nTextPos = pCursor->GetPoint()->nContent.GetIndex();
}
}
}
sal_Int32 const nPos((pContentNode && pTextNode == pContentNode)
? nTextPos
: COMPLETE_STRING);
switch ( eJob )
{
case ONLINE_SPELLING :
{
SwRect aRepaint( const_cast<SwTextFrame*>(pTextFrame)->AutoSpell_(*pTextNode, nPos) );
// PENDING should stop idle spell checking
bPageValid = bPageValid && (SwTextNode::WrongState::TODO != pTextNode->GetWrongDirty());
if ( aRepaint.HasArea() )
pImp->GetShell()->InvalidateWindows( aRepaint );
if (IsInterrupt())
return true;
break;
}
case AUTOCOMPLETE_WORDS :
const_cast<SwTextFrame*>(pTextFrame)->CollectAutoCmplWrds(*pTextNode, nPos);
// note: bPageValid remains true here even if the cursor
// position is skipped, so no PENDING state needed currently
if (IsInterrupt())
return true;
break;
case WORD_COUNT :
{
const sal_Int32 nEnd = pTextNode->GetText().getLength();
SwDocStat aStat;
pTextNode->CountWords( aStat, 0, nEnd );
if (IsInterrupt())
return true;
break;
}
case SMART_TAGS :
{
try {
const SwRect aRepaint( const_cast<SwTextFrame*>(pTextFrame)->SmartTagScan(*pTextNode) );
bPageValid = bPageValid && !pTextNode->IsSmartTagDirty();
if ( aRepaint.HasArea() )
pImp->GetShell()->InvalidateWindows( aRepaint );
} catch( const css::uno::RuntimeException&) {
// handle smarttag problems gracefully and provide diagnostics
TOOLS_WARN_EXCEPTION( "sw.core", "SMART_TAGS");
}
if (IsInterrupt())
return true;
break;
}
}
}
// The Flys that are anchored to the paragraph need to be considered too.
if ( pCnt->GetDrawObjs() )
{
const SwSortedObjs &rObjs = *pCnt->GetDrawObjs();
for (SwAnchoredObject* pObj : rObjs)
{
if ( dynamic_cast< const SwFlyFrame *>( pObj ) != nullptr )
{
SwFlyFrame* pFly = static_cast<SwFlyFrame*>(pObj);
if ( pFly->IsFlyInContentFrame() )
{
const SwContentFrame *pC = pFly->ContainsContent();
while( pC )
{
if ( pC->IsTextFrame() )
{
if ( DoIdleJob_( pC, eJob ) )
return true;
}
pC = pC->GetNextContentFrame();
}
}
}
}
}
return false;
}
bool SwLayIdle::DoIdleJob( IdleJobType eJob, bool bVisAreaOnly )
{
// Spellcheck all contents of the pages. Either only the
// visible ones or all of them.
const SwViewShell* pViewShell = pImp->GetShell();
const SwViewOption* pViewOptions = pViewShell->GetViewOptions();
const SwDoc* pDoc = pViewShell->GetDoc();
switch ( eJob )
{
case ONLINE_SPELLING :
if( !pViewOptions->IsOnlineSpell() )
return false;
break;
case AUTOCOMPLETE_WORDS :
if( !SwViewOption::IsAutoCompleteWords() ||
SwDoc::GetAutoCompleteWords().IsLockWordLstLocked())
return false;
break;
case WORD_COUNT :
if ( !pViewShell->getIDocumentStatistics().GetDocStat().bModified )
return false;
break;
case SMART_TAGS :
if ( pDoc->GetDocShell()->IsHelpDocument() ||
pDoc->isXForms() ||
!SwSmartTagMgr::Get().IsSmartTagsEnabled() )
return false;
break;
default: OSL_FAIL( "Unknown idle job type" );
}
SwPageFrame *pPage;
if ( bVisAreaOnly )
pPage = pImp->GetFirstVisPage(pViewShell->GetOut());
else
pPage = static_cast<SwPageFrame*>(pRoot->Lower());
pContentNode = nullptr;
nTextPos = COMPLETE_STRING;
while ( pPage )
{
bPageValid = true;
const SwContentFrame *pCnt = pPage->ContainsContent();
while( pCnt && pPage->IsAnLower( pCnt ) )
{
if ( DoIdleJob_( pCnt, eJob ) )
return true;
pCnt = pCnt->GetNextContentFrame();
}
if ( pPage->GetSortedObjs() )
{
for ( size_t i = 0; pPage->GetSortedObjs() &&
i < pPage->GetSortedObjs()->size(); ++i )
{
const SwAnchoredObject* pObj = (*pPage->GetSortedObjs())[i];
if ( auto pFly = dynamic_cast< const SwFlyFrame *>( pObj ) )
{
const SwContentFrame *pC = pFly->ContainsContent();
while( pC )
{
if ( pC->IsTextFrame() )
{
if ( DoIdleJob_( pC, eJob ) )
return true;
}
pC = pC->GetNextContentFrame();
}
}
}
}
if( bPageValid )
{
switch ( eJob )
{
case ONLINE_SPELLING : pPage->ValidateSpelling(); break;
case AUTOCOMPLETE_WORDS : pPage->ValidateAutoCompleteWords(); break;
case WORD_COUNT : pPage->ValidateWordCount(); break;
case SMART_TAGS : pPage->ValidateSmartTags(); break;
}
}
pPage = static_cast<SwPageFrame*>(pPage->GetNext());
if ( pPage && bVisAreaOnly &&
!pPage->getFrameArea().IsOver( pImp->GetShell()->VisArea()))
break;
}
return false;
}
#if HAVE_FEATURE_DESKTOP && defined DBG_UTIL
void SwLayIdle::ShowIdle( Color eColor )
{
if ( !m_bIndicator )
{
m_bIndicator = true;
vcl::Window *pWin = pImp->GetShell()->GetWin();
if (pWin && !pWin->SupportsDoubleBuffering()) // FIXME make this work with double-buffering
{
tools::Rectangle aRect( 0, 0, 5, 5 );
aRect = pWin->PixelToLogic( aRect );
// Depending on if idle layout is in progress or not, draw a "red square" or a "green square".
pWin->Push( PushFlags::FILLCOLOR|PushFlags::LINECOLOR );
pWin->SetFillColor( eColor );
pWin->SetLineColor();
pWin->DrawRect( aRect );
pWin->Pop();
}
}
}
#define SHOW_IDLE( Color ) ShowIdle( Color )
#else
#define SHOW_IDLE( Color )
#endif // DBG_UTIL
SwLayIdle::SwLayIdle( SwRootFrame *pRt, SwViewShellImp *pI ) :
pRoot( pRt ),
pImp( pI )
#ifdef DBG_UTIL
, m_bIndicator( false )
#endif
{
SAL_INFO("sw.idle", "SwLayIdle() entry");
pImp->m_pIdleAct = this;
SHOW_IDLE( COL_LIGHTRED );
pImp->GetShell()->EnableSmooth( false );
// First, spellcheck the visible area. Only if there's nothing
// to do there, we trigger the IdleFormat.
if ( !DoIdleJob( SMART_TAGS, true ) &&
!DoIdleJob( ONLINE_SPELLING, true ) &&
!DoIdleJob( AUTOCOMPLETE_WORDS, true ) )
{
// Format, then register repaint rectangles with the SwViewShell if necessary.
// This requires running artificial actions, so we don't get undesired
// effects when for instance the page count gets changed.
// We remember the shells where the cursor is visible, so we can make
// it visible again if needed after a document change.
std::vector<bool> aBools;
for(SwViewShell& rSh : pImp->GetShell()->GetRingContainer())
{
++rSh.mnStartAction;
bool bVis = false;
if ( dynamic_cast<const SwCursorShell*>( &rSh) != nullptr )
{
bVis = static_cast<SwCursorShell*>(&rSh)->GetCharRect().IsOver(rSh.VisArea());
}
aBools.push_back( bVis );
}
bool bInterrupt(false);
{
SwLayAction aAction(pRoot, pImp, &m_aWatch);
aAction.SetWaitAllowed( false );
aAction.Action(pImp->GetShell()->GetOut());
bInterrupt = aAction.IsInterrupt();
}
// Further start/end actions only happen if there were paints started
// somewhere or if the visibility of the CharRects has changed.
bool bActions = false;
size_t nBoolIdx = 0;
for(SwViewShell& rSh : pImp->GetShell()->GetRingContainer())
{
--rSh.mnStartAction;
if ( rSh.Imp()->GetRegion() )
bActions = true;
else
{
SwRect aTmp( rSh.VisArea() );
rSh.UISizeNotify();
// Are we supposed to crash if rSh isn't a cursor shell?!
// bActions |= aTmp != rSh.VisArea() ||
// aBools[nBoolIdx] != ((SwCursorShell*)&rSh)->GetCharRect().IsOver( rSh.VisArea() );
// aBools[ i ] is true, if the i-th shell is a cursor shell (!!!)
// and the cursor is visible.
bActions |= aTmp != rSh.VisArea();
if ( aTmp == rSh.VisArea() && dynamic_cast<const SwCursorShell*>( &rSh) != nullptr )
{
bActions |= aBools[nBoolIdx] !=
static_cast<SwCursorShell*>(&rSh)->GetCharRect().IsOver( rSh.VisArea() );
}
}
++nBoolIdx;
}
if ( bActions )
{
// Prepare start/end actions via CursorShell, so the cursor, selection
// and VisArea can be set correctly.
nBoolIdx = 0;
for(SwViewShell& rSh : pImp->GetShell()->GetRingContainer())
{
SwCursorShell* pCursorShell = nullptr;
if(dynamic_cast<const SwCursorShell*>( &rSh) != nullptr)
pCursorShell = static_cast<SwCursorShell*>(&rSh);
if ( pCursorShell )
pCursorShell->SttCursorMove();
// If there are accrued paints, it's best to simply invalidate
// the whole window. Otherwise there would arise paint problems whose
// solution would be disproportionally expensive.
SwViewShellImp *pViewImp = rSh.Imp();
bool bUnlock = false;
if ( pViewImp->GetRegion() )
{
pViewImp->DelRegion();
// Cause a repaint with virtual device.
rSh.LockPaint();
bUnlock = true;
}
if ( pCursorShell )
// If the Cursor was visible, we need to make it visible again.
// Otherwise, EndCursorMove with true for IdleEnd
pCursorShell->EndCursorMove( !aBools[nBoolIdx] );
if( bUnlock )
{
if( pCursorShell )
{
// UnlockPaint overwrite the selection from the
// CursorShell and calls the virtual method paint
// to fill the virtual device. This fill don't have
// paint the selection! -> Set the focus flag at
// CursorShell and it doesn't paint the selection.
pCursorShell->ShellLoseFocus();
pCursorShell->UnlockPaint( true );
pCursorShell->ShellGetFocus();
}
else
rSh.UnlockPaint( true );
}
++nBoolIdx;
}
}
if (!bInterrupt)
{
if ( !DoIdleJob( WORD_COUNT, false ) )
if ( !DoIdleJob( SMART_TAGS, false ) )
if ( !DoIdleJob( ONLINE_SPELLING, false ) )
DoIdleJob( AUTOCOMPLETE_WORDS, false );
}
bool bInValid = false;
const SwViewOption& rVOpt = *pImp->GetShell()->GetViewOptions();
const SwViewShell* pViewShell = pImp->GetShell();
// See conditions in DoIdleJob()
const bool bSpell = rVOpt.IsOnlineSpell();
const bool bACmplWrd = SwViewOption::IsAutoCompleteWords();
const bool bWordCount = pViewShell->getIDocumentStatistics().GetDocStat().bModified;
const bool bSmartTags = !pViewShell->GetDoc()->GetDocShell()->IsHelpDocument() &&
!pViewShell->GetDoc()->isXForms() &&
SwSmartTagMgr::Get().IsSmartTagsEnabled();
SwPageFrame *pPg = static_cast<SwPageFrame*>(pRoot->Lower());
do
{
bInValid = pPg->IsInvalidContent() || pPg->IsInvalidLayout() ||
pPg->IsInvalidFlyContent() || pPg->IsInvalidFlyLayout() ||
pPg->IsInvalidFlyInCnt() ||
(bSpell && pPg->IsInvalidSpelling()) ||
(bACmplWrd && pPg->IsInvalidAutoCompleteWords()) ||
(bWordCount && pPg->IsInvalidWordCount()) ||
(bSmartTags && pPg->IsInvalidSmartTags());
pPg = static_cast<SwPageFrame*>(pPg->GetNext());
} while ( pPg && !bInValid );
if ( !bInValid )
{
pRoot->ResetIdleFormat();
SfxObjectShell* pDocShell = pImp->GetShell()->GetDoc()->GetDocShell();
pDocShell->Broadcast( SfxEventHint( SfxEventHintId::SwEventLayoutFinished, SwDocShell::GetEventName(STR_SW_EVENT_LAYOUT_FINISHED), pDocShell ) );
// Limit lifetime of the text glyphs cache to a single run of the
// layout.
SwClearFntCacheTextGlyphs();
}
}
pImp->GetShell()->EnableSmooth( true );
if( pImp->IsAccessible() )
pImp->FireAccessibleEvents();
SAL_INFO("sw.idle", "SwLayIdle() return");
#ifdef DBG_UTIL
if ( m_bIndicator && pImp->GetShell()->GetWin() )
{
// Do not invalidate indicator, this may cause an endless loop. Instead, just repaint it
// This should be replaced by an overlay object in the future, anyways. Since it's only for debug
// purposes, it is not urgent.
m_bIndicator = false; SHOW_IDLE( COL_LIGHTGREEN );
}
#endif
}
SwLayIdle::~SwLayIdle()
{
pImp->m_pIdleAct = nullptr;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|