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 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404
|
/* -*- 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 <tools/diagnose_ex.h>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/interfacecontainer.h>
#include <comphelper/scopeguard.hxx>
#include <comphelper/servicedecl.hxx>
#include <comphelper/storagehelper.hxx>
#include <cppcanvas/polypolygon.hxx>
#include <tools/debug.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <sal/log.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
#include <com/sun/star/awt/SystemPointer.hpp>
#include <com/sun/star/presentation/XSlideShow.hpp>
#include <com/sun/star/presentation/XSlideShowListener.hpp>
#include <com/sun/star/lang/NoSupportException.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/drawing/PointSequenceSequence.hpp>
#include <com/sun/star/drawing/PointSequence.hpp>
#include <com/sun/star/drawing/XLayer.hpp>
#include <com/sun/star/drawing/XLayerSupplier.hpp>
#include <com/sun/star/drawing/XLayerManager.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/loader/CannotActivateFactoryException.hpp>
#include <unoviewcontainer.hxx>
#include <transitionfactory.hxx>
#include <eventmultiplexer.hxx>
#include <usereventqueue.hxx>
#include <eventqueue.hxx>
#include <cursormanager.hxx>
#include <mediafilemanager.hxx>
#include <slideshowcontext.hxx>
#include <activitiesqueue.hxx>
#include <activitiesfactory.hxx>
#include <interruptabledelayevent.hxx>
#include <slide.hxx>
#include <shapemaps.hxx>
#include <slideview.hxx>
#include <tools.hxx>
#include <unoview.hxx>
#include "rehearsetimingsactivity.hxx"
#include "waitsymbol.hxx"
#include "effectrewinder.hxx"
#include <framerate.hxx>
#include "pointersymbol.hxx"
#include <map>
#include <vector>
#include <algorithm>
using namespace com::sun::star;
using namespace ::slideshow::internal;
namespace {
/** During animations the update() method tells its caller to call it as
soon as possible. This gives us more time to render the next frame and
still maintain a steady frame rate. This class is responsible for
synchronizing the display of new frames and thus keeping the frame rate
steady.
*/
class FrameSynchronization
{
public:
/** Create new object with a predefined duration between two frames.
@param nFrameDuration
The preferred duration between the display of two frames in
seconds.
*/
explicit FrameSynchronization (const double nFrameDuration);
/** Set the current time as the time at which the current frame is
displayed. From this the target time of the next frame is derived.
*/
void MarkCurrentFrame();
/** When there is time left until the next frame is due then wait.
Otherwise return without delay.
*/
void Synchronize();
/** Activate frame synchronization when an animation is active and
frames are to be displayed in a steady rate. While active
Synchronize() will wait until the frame duration time has passed.
*/
void Activate();
/** Deactivate frame sychronization when no animation is active and the
time between frames depends on user actions and other external
sources. While deactivated Synchronize() will return without delay.
*/
void Deactivate();
private:
/** The timer that is used for synchronization is independent from the
one used by SlideShowImpl: it is not paused or modified by
animations.
*/
canvas::tools::ElapsedTime maTimer;
/** Time between the display of frames. Enforced only when mbIsActive
is <TRUE/>.
*/
const double mnFrameDuration;
/** Time (of maTimer) when the next frame shall be displayed.
Synchronize() will wait until this time.
*/
double mnNextFrameTargetTime;
/** Synchronize() will wait only when this flag is <TRUE/>. Otherwise
it returns immediately.
*/
bool mbIsActive;
};
/******************************************************************************
SlideShowImpl
This class encapsulates the slideshow presentation viewer.
With an instance of this class, it is possible to statically
and dynamically show a presentation, as defined by the
constructor-provided draw model (represented by a sequence
of css::drawing::XDrawPage objects).
It is possible to show the presentation on multiple views
simultaneously (e.g. for a multi-monitor setup). Since this
class also relies on user interaction, the corresponding
XSlideShowView interface provides means to register some UI
event listeners (mostly borrowed from awt::XWindow interface).
Since currently (mid 2004), OOo isn't very well suited to
multi-threaded rendering, this class relies on <em>very
frequent</em> external update() calls, which will render the
next frame of animations. This works as follows: after the
displaySlide() has been successfully called (which setup and
starts an actual slide show), the update() method must be
called until it returns false.
Effectively, this puts the burden of providing
concurrency to the clients of this class, which, as noted
above, is currently unavoidable with the current state of
affairs (I've actually tried threading here, but failed
miserably when using the VCL canvas as the render backend -
deadlocked).
******************************************************************************/
typedef cppu::WeakComponentImplHelper<presentation::XSlideShow> SlideShowImplBase;
typedef ::std::vector< ::cppcanvas::PolyPolygonSharedPtr> PolyPolygonVector;
/// Maps XDrawPage for annotations persistence
typedef ::std::map< css::uno::Reference<
css::drawing::XDrawPage>,
PolyPolygonVector> PolygonMap;
class SlideShowImpl : private cppu::BaseMutex,
public CursorManager,
public MediaFileManager,
public SlideShowImplBase
{
public:
explicit SlideShowImpl(
uno::Reference<uno::XComponentContext> const& xContext );
/** Notify that the transition phase of the current slide
has ended.
The life of a slide has three phases: the transition
phase, when the previous slide vanishes, and the
current slide becomes visible, the shape animation
phase, when shape effects are running, and the phase
after the last shape animation has ended, but before
the next slide transition starts.
This method notifies the end of the first phase.
@param bPaintSlide
When true, Slide::show() is passed a true as well, denoting
explicit paint of slide content. Pass false here, if e.g. a
slide transition has already rendered the initial slide image.
*/
void notifySlideTransitionEnded( bool bPaintSlide );
/** Notify that the shape animation phase of the current slide
has ended.
The life of a slide has three phases: the transition
phase, when the previous slide vanishes, and the
current slide becomes visible, the shape animation
phase, when shape effects are running, and the phase
after the last shape animation has ended, but before
the next slide transition starts.
This method notifies the end of the second phase.
*/
void notifySlideAnimationsEnded();
/** Notify that the slide has ended.
The life of a slide has three phases: the transition
phase, when the previous slide vanishes, and the
current slide becomes visible, the shape animation
phase, when shape effects are running, and the phase
after the last shape animation has ended, but before
the next slide transition starts.
This method notifies the end of the third phase.
*/
void notifySlideEnded (const bool bReverse);
/** Notification from eventmultiplexer that a hyperlink
has been clicked.
*/
bool notifyHyperLinkClicked( OUString const& hyperLink );
/** Notification from eventmultiplexer that an animation event has occurred.
This will be forwarded to all registered XSlideShowListener
*/
bool handleAnimationEvent( const AnimationNodeSharedPtr& rNode );
/** Obtain a MediaTempFile for the specified url. */
virtual std::shared_ptr<avmedia::MediaTempFile> getMediaTempFile(const OUString& aUrl) override;
private:
// XSlideShow:
virtual sal_Bool SAL_CALL nextEffect() override;
virtual sal_Bool SAL_CALL previousEffect() override;
virtual sal_Bool SAL_CALL startShapeActivity(
uno::Reference<drawing::XShape> const& xShape ) override;
virtual sal_Bool SAL_CALL stopShapeActivity(
uno::Reference<drawing::XShape> const& xShape ) override;
virtual sal_Bool SAL_CALL pause( sal_Bool bPauseShow ) override;
virtual uno::Reference<drawing::XDrawPage> SAL_CALL getCurrentSlide() override;
virtual void SAL_CALL displaySlide(
uno::Reference<drawing::XDrawPage> const& xSlide,
uno::Reference<drawing::XDrawPagesSupplier> const& xDrawPages,
uno::Reference<animations::XAnimationNode> const& xRootNode,
uno::Sequence<beans::PropertyValue> const& rProperties ) override;
virtual void SAL_CALL registerUserPaintPolygons( const css::uno::Reference< css::lang::XMultiServiceFactory >& xDocFactory ) override;
virtual sal_Bool SAL_CALL setProperty(
beans::PropertyValue const& rProperty ) override;
virtual sal_Bool SAL_CALL addView(
uno::Reference<presentation::XSlideShowView> const& xView ) override;
virtual sal_Bool SAL_CALL removeView(
uno::Reference<presentation::XSlideShowView> const& xView ) override;
virtual sal_Bool SAL_CALL update( double & nNextTimeout ) override;
virtual void SAL_CALL addSlideShowListener(
uno::Reference<presentation::XSlideShowListener> const& xListener ) override;
virtual void SAL_CALL removeSlideShowListener(
uno::Reference<presentation::XSlideShowListener> const& xListener ) override;
virtual void SAL_CALL addShapeEventListener(
uno::Reference<presentation::XShapeEventListener> const& xListener,
uno::Reference<drawing::XShape> const& xShape ) override;
virtual void SAL_CALL removeShapeEventListener(
uno::Reference<presentation::XShapeEventListener> const& xListener,
uno::Reference<drawing::XShape> const& xShape ) override;
virtual void SAL_CALL setShapeCursor(
uno::Reference<drawing::XShape> const& xShape, sal_Int16 nPointerShape ) override;
// CursorManager
virtual bool requestCursor( sal_Int16 nCursorShape ) override;
virtual void resetCursor() override;
/** This is somewhat similar to displaySlide when called for the current
slide. It has been simplified to take advantage of that no slide
change takes place. Furthermore it does not show the slide
transition.
*/
void redisplayCurrentSlide();
protected:
// WeakComponentImplHelperBase
virtual void SAL_CALL disposing() override;
bool isDisposed() const
{
return (rBHelper.bDisposed || rBHelper.bInDispose);
}
private:
struct SeparateListenerImpl; friend struct SeparateListenerImpl;
class PrefetchPropertiesFunc; friend class PrefetchPropertiesFunc;
/// Stop currently running show.
void stopShow();
///Find a polygons vector in maPolygons (map)
PolygonMap::iterator findPolygons( uno::Reference<drawing::XDrawPage> const& xDrawPage);
/// Creates a new slide.
SlideSharedPtr makeSlide(
uno::Reference<drawing::XDrawPage> const& xDrawPage,
uno::Reference<drawing::XDrawPagesSupplier> const& xDrawPages,
uno::Reference<animations::XAnimationNode> const& xRootNode );
/// Checks whether the given slide/animation node matches mpPrefetchSlide
static bool matches(
SlideSharedPtr const& pSlide,
uno::Reference<drawing::XDrawPage> const& xSlide,
uno::Reference<animations::XAnimationNode> const& xNode )
{
if (pSlide)
return (pSlide->getXDrawPage() == xSlide &&
pSlide->getXAnimationNode() == xNode);
else
return (!xSlide.is() && !xNode.is());
}
/// Resets the current slide transition sound object with a new one:
SoundPlayerSharedPtr resetSlideTransitionSound(
uno::Any const& url, bool bLoopSound );
/// stops the current slide transition sound
void stopSlideTransitionSound();
/** Prepare a slide transition
This method registers all necessary events and
activities for a slide transition.
@return the slide change activity, or NULL for no transition effect
*/
ActivitySharedPtr createSlideTransition(
const uno::Reference< drawing::XDrawPage >& xDrawPage,
const SlideSharedPtr& rLeavingSlide,
const SlideSharedPtr& rEnteringSlide,
const EventSharedPtr& rTransitionEndEvent );
/** Request/release the wait symbol. The wait symbol is displayed when
there are more requests then releases. Locking the wait symbol
helps to avoid intermediate repaints.
Do not call this method directly. Use WaitSymbolLock instead.
*/
void requestWaitSymbol();
void releaseWaitSymbol();
class WaitSymbolLock {public:
explicit WaitSymbolLock(SlideShowImpl& rSlideShowImpl) : mrSlideShowImpl(rSlideShowImpl)
{ mrSlideShowImpl.requestWaitSymbol(); }
~WaitSymbolLock()
{ mrSlideShowImpl.releaseWaitSymbol(); }
private: SlideShowImpl& mrSlideShowImpl;
};
/// Filter requested cursor shape against hard slideshow cursors (wait, etc.)
sal_Int16 calcActiveCursor( sal_Int16 nCursorShape ) const;
/** This method is called asynchronously to finish the rewinding of an
effect to the previous slide that was initiated earlier.
*/
void rewindEffectToPreviousSlide();
/// all registered views
UnoViewContainer maViewContainer;
/// all registered slide show listeners
comphelper::OInterfaceContainerHelper2 maListenerContainer;
/// map of vectors, containing all registered listeners for a shape
ShapeEventListenerMap maShapeEventListeners;
/// map of sal_Int16 values, specifying the mouse cursor for every shape
ShapeCursorMap maShapeCursors;
//map of vector of Polygons, containing polygons drawn on each slide.
PolygonMap maPolygons;
std::optional<RGBColor> maUserPaintColor;
double maUserPaintStrokeWidth;
//changed for the eraser project
std::optional<bool> maEraseAllInk;
std::optional<sal_Int32> maEraseInk;
//end changed
std::shared_ptr<canvas::tools::ElapsedTime> mpPresTimer;
ScreenUpdater maScreenUpdater;
EventQueue maEventQueue;
EventMultiplexer maEventMultiplexer;
ActivitiesQueue maActivitiesQueue;
UserEventQueue maUserEventQueue;
SubsettableShapeManagerSharedPtr mpDummyPtr;
std::shared_ptr<SeparateListenerImpl> mpListener;
std::shared_ptr<RehearseTimingsActivity> mpRehearseTimingsActivity;
std::shared_ptr<WaitSymbol> mpWaitSymbol;
std::shared_ptr<PointerSymbol> mpPointerSymbol;
/// the current slide transition sound object:
SoundPlayerSharedPtr mpCurrentSlideTransitionSound;
uno::Reference<uno::XComponentContext> mxComponentContext;
uno::Reference<
presentation::XTransitionFactory> mxOptionalTransitionFactory;
/// the previously running slide
SlideSharedPtr mpPreviousSlide;
/// the currently running slide
SlideSharedPtr mpCurrentSlide;
/// the already prefetched slide: best candidate for upcoming slide
SlideSharedPtr mpPrefetchSlide;
/// slide to be prefetched: best candidate for upcoming slide
uno::Reference<drawing::XDrawPage> mxPrefetchSlide;
/// save the XDrawPagesSupplier to retrieve polygons
uno::Reference<drawing::XDrawPagesSupplier> mxDrawPagesSupplier;
/// Used by MediaFileManager, for media files with package url.
uno::Reference<document::XStorageBasedDocument> mxSBD;
/// slide animation to be prefetched:
uno::Reference<animations::XAnimationNode> mxPrefetchAnimationNode;
sal_Int16 mnCurrentCursor;
sal_Int32 mnWaitSymbolRequestCount;
bool mbAutomaticAdvancementMode;
bool mbImageAnimationsAllowed;
bool mbNoSlideTransitions;
bool mbMouseVisible;
bool mbForceManualAdvance;
bool mbShowPaused;
bool mbSlideShowIdle;
bool mbDisableAnimationZOrder;
EffectRewinder maEffectRewinder;
FrameSynchronization maFrameSynchronization;
};
/** Separate event listener for animation, view and hyperlink events.
This handler is registered for slide animation end, view and
hyperlink events at the global EventMultiplexer, and forwards
notifications to the SlideShowImpl
*/
struct SlideShowImpl::SeparateListenerImpl : public EventHandler,
public ViewRepaintHandler,
public HyperlinkHandler,
public AnimationEventHandler
{
SlideShowImpl& mrShow;
ScreenUpdater& mrScreenUpdater;
EventQueue& mrEventQueue;
SeparateListenerImpl( SlideShowImpl& rShow,
ScreenUpdater& rScreenUpdater,
EventQueue& rEventQueue ) :
mrShow( rShow ),
mrScreenUpdater( rScreenUpdater ),
mrEventQueue( rEventQueue )
{}
SeparateListenerImpl( const SeparateListenerImpl& ) = delete;
SeparateListenerImpl& operator=( const SeparateListenerImpl& ) = delete;
// EventHandler
virtual bool handleEvent() override
{
// DON't call notifySlideAnimationsEnded()
// directly, but queue an event. handleEvent()
// might be called from e.g.
// showNext(), and notifySlideAnimationsEnded() must not be called
// in recursion. Note that the event is scheduled for the next
// frame so that its expensive execution does not come in between
// sprite hiding and shape redraw (at the end of the animation of a
// shape), which would cause a flicker.
mrEventQueue.addEventForNextRound(
makeEvent( [this] () { this->mrShow.notifySlideAnimationsEnded(); },
"SlideShowImpl::notifySlideAnimationsEnded"));
return true;
}
// ViewRepaintHandler
virtual void viewClobbered( const UnoViewSharedPtr& rView ) override
{
// given view needs repaint, request update
mrScreenUpdater.notifyUpdate(rView, true);
}
// HyperlinkHandler
virtual bool handleHyperlink( OUString const& rLink ) override
{
return mrShow.notifyHyperLinkClicked(rLink);
}
// AnimationEventHandler
virtual bool handleAnimationEvent( const AnimationNodeSharedPtr& rNode ) override
{
return mrShow.handleAnimationEvent(rNode);
}
};
SlideShowImpl::SlideShowImpl(
uno::Reference<uno::XComponentContext> const& xContext )
: SlideShowImplBase(m_aMutex),
maViewContainer(),
maListenerContainer( m_aMutex ),
maShapeEventListeners(),
maShapeCursors(),
maUserPaintColor(),
maUserPaintStrokeWidth(4.0),
mpPresTimer( std::make_shared<canvas::tools::ElapsedTime>() ),
maScreenUpdater(maViewContainer),
maEventQueue( mpPresTimer ),
maEventMultiplexer( maEventQueue,
maViewContainer ),
maActivitiesQueue( mpPresTimer ),
maUserEventQueue( maEventMultiplexer,
maEventQueue,
*this ),
mpDummyPtr(),
mpListener(),
mpRehearseTimingsActivity(),
mpWaitSymbol(),
mpPointerSymbol(),
mpCurrentSlideTransitionSound(),
mxComponentContext( xContext ),
mxOptionalTransitionFactory(),
mpCurrentSlide(),
mpPrefetchSlide(),
mxPrefetchSlide(),
mxDrawPagesSupplier(),
mxSBD(),
mxPrefetchAnimationNode(),
mnCurrentCursor(awt::SystemPointer::ARROW),
mnWaitSymbolRequestCount(0),
mbAutomaticAdvancementMode(false),
mbImageAnimationsAllowed( true ),
mbNoSlideTransitions( false ),
mbMouseVisible( true ),
mbForceManualAdvance( false ),
mbShowPaused( false ),
mbSlideShowIdle( true ),
mbDisableAnimationZOrder( false ),
maEffectRewinder(maEventMultiplexer, maEventQueue, maUserEventQueue),
maFrameSynchronization(1.0 / FrameRate::PreferredFramesPerSecond)
{
// keep care not constructing any UNO references to this inside ctor,
// shift that code to create()!
uno::Reference<lang::XMultiComponentFactory> xFactory(
mxComponentContext->getServiceManager() );
if( xFactory.is() )
{
try
{
// #i82460# try to retrieve special transition factory
mxOptionalTransitionFactory.set(
xFactory->createInstanceWithContext(
"com.sun.star.presentation.TransitionFactory",
mxComponentContext ),
uno::UNO_QUERY );
}
catch (loader::CannotActivateFactoryException const&)
{
}
}
mpListener = std::make_shared<SeparateListenerImpl>(
*this,
maScreenUpdater,
maEventQueue );
maEventMultiplexer.addSlideAnimationsEndHandler( mpListener );
maEventMultiplexer.addViewRepaintHandler( mpListener );
maEventMultiplexer.addHyperlinkHandler( mpListener, 0.0 );
maEventMultiplexer.addAnimationStartHandler( mpListener );
maEventMultiplexer.addAnimationEndHandler( mpListener );
}
// we are about to be disposed (someone call dispose() on us)
void SlideShowImpl::disposing()
{
osl::MutexGuard const guard( m_aMutex );
maEffectRewinder.dispose();
// stop slide transition sound, if any:
stopSlideTransitionSound();
mxComponentContext.clear();
if( mpCurrentSlideTransitionSound )
{
mpCurrentSlideTransitionSound->dispose();
mpCurrentSlideTransitionSound.reset();
}
mpWaitSymbol.reset();
mpPointerSymbol.reset();
if( mpRehearseTimingsActivity )
{
mpRehearseTimingsActivity->dispose();
mpRehearseTimingsActivity.reset();
}
if( mpListener )
{
maEventMultiplexer.removeSlideAnimationsEndHandler(mpListener);
maEventMultiplexer.removeViewRepaintHandler(mpListener);
maEventMultiplexer.removeHyperlinkHandler(mpListener);
maEventMultiplexer.removeAnimationStartHandler( mpListener );
maEventMultiplexer.removeAnimationEndHandler( mpListener );
mpListener.reset();
}
maUserEventQueue.clear();
maActivitiesQueue.clear();
maEventMultiplexer.clear();
maEventQueue.clear();
mpPresTimer.reset();
maShapeCursors.clear();
maShapeEventListeners.clear();
// send all listeners a disposing() that we are going down:
maListenerContainer.disposeAndClear(
lang::EventObject( static_cast<cppu::OWeakObject *>(this) ) );
maViewContainer.dispose();
// release slides:
mxPrefetchAnimationNode.clear();
mxPrefetchSlide.clear();
mpPrefetchSlide.reset();
mpCurrentSlide.reset();
mpPreviousSlide.reset();
}
/// stops the current slide transition sound
void SlideShowImpl::stopSlideTransitionSound()
{
if (mpCurrentSlideTransitionSound)
{
mpCurrentSlideTransitionSound->stopPlayback();
mpCurrentSlideTransitionSound->dispose();
mpCurrentSlideTransitionSound.reset();
}
}
SoundPlayerSharedPtr SlideShowImpl::resetSlideTransitionSound( const uno::Any& rSound, bool bLoopSound )
{
bool bStopSound = false;
OUString url;
if( !(rSound >>= bStopSound) )
bStopSound = false;
rSound >>= url;
if( !bStopSound && url.isEmpty() )
return SoundPlayerSharedPtr();
stopSlideTransitionSound();
if (!url.isEmpty())
{
try
{
mpCurrentSlideTransitionSound = SoundPlayer::create(
maEventMultiplexer, url, mxComponentContext, *this);
mpCurrentSlideTransitionSound->setPlaybackLoop( bLoopSound );
}
catch (lang::NoSupportException const&)
{
// catch possible exceptions from SoundPlayer, since
// being not able to playback the sound is not a hard
// error here (still, the slide transition should be
// shown).
}
}
return mpCurrentSlideTransitionSound;
}
ActivitySharedPtr SlideShowImpl::createSlideTransition(
const uno::Reference< drawing::XDrawPage >& xDrawPage,
const SlideSharedPtr& rLeavingSlide,
const SlideSharedPtr& rEnteringSlide,
const EventSharedPtr& rTransitionEndEvent)
{
ENSURE_OR_THROW( !maViewContainer.empty(),
"createSlideTransition(): No views" );
ENSURE_OR_THROW( rEnteringSlide,
"createSlideTransition(): No entering slide" );
// return empty transition, if slide transitions
// are disabled.
if (mbNoSlideTransitions)
return ActivitySharedPtr();
// retrieve slide change parameters from XDrawPage
uno::Reference< beans::XPropertySet > xPropSet( xDrawPage,
uno::UNO_QUERY );
if( !xPropSet.is() )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"Slide has no PropertySet - assuming no transition" );
return ActivitySharedPtr();
}
sal_Int16 nTransitionType(0);
if( !getPropertyValue( nTransitionType,
xPropSet,
"TransitionType") )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"Could not extract slide transition type from XDrawPage - assuming no transition" );
return ActivitySharedPtr();
}
sal_Int16 nTransitionSubType(0);
if( !getPropertyValue( nTransitionSubType,
xPropSet,
"TransitionSubtype") )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"Could not extract slide transition subtype from XDrawPage - assuming no transition" );
return ActivitySharedPtr();
}
bool bTransitionDirection(false);
if( !getPropertyValue( bTransitionDirection,
xPropSet,
"TransitionDirection") )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"Could not extract slide transition direction from XDrawPage - assuming default direction" );
}
sal_Int32 aUnoColor(0);
if( !getPropertyValue( aUnoColor,
xPropSet,
"TransitionFadeColor") )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"Could not extract slide transition fade color from XDrawPage - assuming black" );
}
const RGBColor aTransitionFadeColor( unoColor2RGBColor( aUnoColor ));
uno::Any aSound;
bool bLoopSound = false;
if( !getPropertyValue( aSound, xPropSet, "Sound") )
SAL_INFO("slideshow", "createSlideTransition(): Could not determine transition sound effect URL from XDrawPage - using no sound" );
if( !getPropertyValue( bLoopSound, xPropSet, "LoopSound" ) )
SAL_INFO("slideshow", "createSlideTransition(): Could not get slide property 'LoopSound' - using no sound" );
NumberAnimationSharedPtr pTransition(
TransitionFactory::createSlideTransition(
rLeavingSlide,
rEnteringSlide,
maViewContainer,
maScreenUpdater,
maEventMultiplexer,
mxOptionalTransitionFactory,
nTransitionType,
nTransitionSubType,
bTransitionDirection,
aTransitionFadeColor,
resetSlideTransitionSound( aSound, bLoopSound ) ));
if( !pTransition )
return ActivitySharedPtr(); // no transition effect has been
// generated. Normally, that means
// that simply no transition is
// set on this slide.
double nTransitionDuration(0.0);
if( !getPropertyValue( nTransitionDuration,
xPropSet,
"TransitionDuration") )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"Could not extract slide transition duration from XDrawPage - assuming no transition" );
return ActivitySharedPtr();
}
sal_Int32 nMinFrames(5);
if( !getPropertyValue( nMinFrames,
xPropSet,
"MinimalFrameNumber") )
{
SAL_INFO("slideshow", "createSlideTransition(): "
"No minimal number of frames given - assuming 5" );
}
// prefetch slide transition bitmaps, but postpone it after
// displaySlide() has finished - sometimes, view size has not yet
// reached final size
maEventQueue.addEvent(
makeEvent( [pTransition] () {
pTransition->prefetch(); },
"Animation::prefetch"));
return ActivitySharedPtr(
ActivitiesFactory::createSimpleActivity(
ActivitiesFactory::CommonParameters(
rTransitionEndEvent,
maEventQueue,
maActivitiesQueue,
nTransitionDuration,
nMinFrames,
false,
std::optional<double>(1.0),
0.0,
0.0,
ShapeSharedPtr(),
basegfx::B2DSize( rEnteringSlide->getSlideSize() ) ),
pTransition,
true ));
}
PolygonMap::iterator SlideShowImpl::findPolygons( uno::Reference<drawing::XDrawPage> const& xDrawPage)
{
// TODO(P2): optimize research in the map.
return maPolygons.find(xDrawPage);
}
SlideSharedPtr SlideShowImpl::makeSlide(
uno::Reference<drawing::XDrawPage> const& xDrawPage,
uno::Reference<drawing::XDrawPagesSupplier> const& xDrawPages,
uno::Reference<animations::XAnimationNode> const& xRootNode )
{
if( !xDrawPage.is() )
return SlideSharedPtr();
//Retrieve polygons for the current slide
PolygonMap::iterator aIter = findPolygons(xDrawPage);
const SlideSharedPtr pSlide( createSlide(xDrawPage,
xDrawPages,
xRootNode,
maEventQueue,
maEventMultiplexer,
maScreenUpdater,
maActivitiesQueue,
maUserEventQueue,
*this,
*this,
maViewContainer,
mxComponentContext,
maShapeEventListeners,
maShapeCursors,
(aIter != maPolygons.end()) ? aIter->second : PolyPolygonVector(),
maUserPaintColor ? *maUserPaintColor : RGBColor(),
maUserPaintStrokeWidth,
!!maUserPaintColor,
mbImageAnimationsAllowed,
mbDisableAnimationZOrder) );
// prefetch show content (reducing latency for slide
// bitmap and effect start later on)
pSlide->prefetch();
return pSlide;
}
void SlideShowImpl::requestWaitSymbol()
{
++mnWaitSymbolRequestCount;
OSL_ASSERT(mnWaitSymbolRequestCount>0);
if (mnWaitSymbolRequestCount == 1)
{
if( !mpWaitSymbol )
{
// fall back to cursor
requestCursor(calcActiveCursor(mnCurrentCursor));
}
else
mpWaitSymbol->show();
}
}
void SlideShowImpl::releaseWaitSymbol()
{
--mnWaitSymbolRequestCount;
OSL_ASSERT(mnWaitSymbolRequestCount>=0);
if (mnWaitSymbolRequestCount == 0)
{
if( !mpWaitSymbol )
{
// fall back to cursor
requestCursor(calcActiveCursor(mnCurrentCursor));
}
else
mpWaitSymbol->hide();
}
}
sal_Int16 SlideShowImpl::calcActiveCursor( sal_Int16 nCursorShape ) const
{
if( mnWaitSymbolRequestCount>0 && !mpWaitSymbol ) // enforce wait cursor
nCursorShape = awt::SystemPointer::WAIT;
else if( !mbMouseVisible ) // enforce INVISIBLE
nCursorShape = awt::SystemPointer::INVISIBLE;
else if( maUserPaintColor &&
nCursorShape == awt::SystemPointer::ARROW )
nCursorShape = awt::SystemPointer::PEN;
return nCursorShape;
}
void SlideShowImpl::stopShow()
{
// Force-end running animation
// ===========================
if (mpCurrentSlide)
{
mpCurrentSlide->hide();
//Register polygons in the map
if(findPolygons(mpCurrentSlide->getXDrawPage()) != maPolygons.end())
maPolygons.erase(mpCurrentSlide->getXDrawPage());
maPolygons.insert(make_pair(mpCurrentSlide->getXDrawPage(),mpCurrentSlide->getPolygons()));
}
// clear all queues
maEventQueue.clear();
maActivitiesQueue.clear();
// Attention: we MUST clear the user event queue here,
// this is because the current slide might have registered
// shape events (click or enter/leave), which might
// otherwise dangle forever in the queue (because of the
// shared ptr nature). If someone needs to change this:
// somehow unregister those shapes at the user event queue
// on notifySlideEnded().
maUserEventQueue.clear();
// re-enable automatic effect advancement
// (maEventQueue.clear() above might have killed
// maEventMultiplexer's tick events)
if (mbAutomaticAdvancementMode)
{
// toggle automatic mode (enabling just again is
// ignored by EventMultiplexer)
maEventMultiplexer.setAutomaticMode( false );
maEventMultiplexer.setAutomaticMode( true );
}
}
class SlideShowImpl::PrefetchPropertiesFunc
{
public:
PrefetchPropertiesFunc( SlideShowImpl * that_,
bool& rbSkipAllMainSequenceEffects,
bool& rbSkipSlideTransition)
: mpSlideShowImpl(that_),
mrbSkipAllMainSequenceEffects(rbSkipAllMainSequenceEffects),
mrbSkipSlideTransition(rbSkipSlideTransition)
{}
void operator()( beans::PropertyValue const& rProperty ) const {
if (rProperty.Name == "Prefetch" )
{
uno::Sequence<uno::Any> seq;
if ((rProperty.Value >>= seq) && seq.getLength() == 2)
{
seq[0] >>= mpSlideShowImpl->mxPrefetchSlide;
seq[1] >>= mpSlideShowImpl->mxPrefetchAnimationNode;
}
}
else if ( rProperty.Name == "SkipAllMainSequenceEffects" )
{
rProperty.Value >>= mrbSkipAllMainSequenceEffects;
}
else if ( rProperty.Name == "SkipSlideTransition" )
{
rProperty.Value >>= mrbSkipSlideTransition;
}
else
{
SAL_WARN( "slideshow", rProperty.Name );
}
}
private:
SlideShowImpl *const mpSlideShowImpl;
bool& mrbSkipAllMainSequenceEffects;
bool& mrbSkipSlideTransition;
};
void SlideShowImpl::displaySlide(
uno::Reference<drawing::XDrawPage> const& xSlide,
uno::Reference<drawing::XDrawPagesSupplier> const& xDrawPages,
uno::Reference<animations::XAnimationNode> const& xRootNode,
uno::Sequence<beans::PropertyValue> const& rProperties )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return;
maEffectRewinder.setRootAnimationNode(xRootNode);
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
mxDrawPagesSupplier = xDrawPages;
mxSBD = uno::Reference<document::XStorageBasedDocument>(mxDrawPagesSupplier, uno::UNO_QUERY);
stopShow(); // MUST call that: results in
// maUserEventQueue.clear(). What's more,
// stopShow()'s currSlide->hide() call is
// now also required, notifySlideEnded()
// relies on that
// unconditionally. Otherwise, genuine
// shape animations (drawing layer and
// GIF) will not be stopped.
bool bSkipAllMainSequenceEffects (false);
bool bSkipSlideTransition (false);
std::for_each( rProperties.begin(),
rProperties.end(),
PrefetchPropertiesFunc(this, bSkipAllMainSequenceEffects, bSkipSlideTransition) );
OSL_ENSURE( !maViewContainer.empty(), "### no views!" );
if (maViewContainer.empty())
return;
// this here might take some time
{
WaitSymbolLock aLock (*this);
mpPreviousSlide = mpCurrentSlide;
mpCurrentSlide.reset();
if (matches( mpPrefetchSlide, xSlide, xRootNode ))
{
// prefetched slide matches:
mpCurrentSlide = mpPrefetchSlide;
}
else
mpCurrentSlide = makeSlide( xSlide, xDrawPages, xRootNode );
OSL_ASSERT( mpCurrentSlide );
if (mpCurrentSlide)
{
basegfx::B2DSize oldSlideSize;
if( mpPreviousSlide )
oldSlideSize = basegfx::B2DSize( mpPreviousSlide->getSlideSize() );
basegfx::B2DSize const slideSize( mpCurrentSlide->getSlideSize() );
// push new transformation to all views, if size changed
if( !mpPreviousSlide || oldSlideSize != slideSize )
{
for( const auto& pView : maViewContainer )
pView->setViewSize( slideSize );
// explicitly notify view change here,
// because transformation might have changed:
// optimization, this->notifyViewChange() would
// repaint slide which is not necessary.
maEventMultiplexer.notifyViewsChanged();
}
// create slide transition, and add proper end event
// (which then starts the slide effects
// via CURRENT_SLIDE.show())
ActivitySharedPtr pSlideChangeActivity (
createSlideTransition(
mpCurrentSlide->getXDrawPage(),
mpPreviousSlide,
mpCurrentSlide,
makeEvent(
[this] () { this->notifySlideTransitionEnded(false); },
"SlideShowImpl::notifySlideTransitionEnded")));
if (bSkipSlideTransition)
{
// The transition activity was created for the side effects
// (like sound transitions). Because we want to skip the
// actual transition animation we do not need the activity
// anymore.
pSlideChangeActivity.reset();
}
if (pSlideChangeActivity)
{
// factory generated a slide transition - activate it!
maActivitiesQueue.addActivity( pSlideChangeActivity );
}
else
{
// no transition effect on this slide - schedule slide
// effect start event right away.
maEventQueue.addEvent(
makeEvent(
[this] () { this->notifySlideTransitionEnded(true); },
"SlideShowImpl::notifySlideTransitionEnded"));
}
}
} // finally
maListenerContainer.forEach<presentation::XSlideShowListener>(
[](uno::Reference<presentation::XSlideShowListener> const& xListener)
{
xListener->slideTransitionStarted();
});
// We are currently rewinding an effect. This lead us from the next
// slide to this one. To complete this we have to play back all main
// sequence effects on this slide.
if (bSkipAllMainSequenceEffects)
maEffectRewinder.skipAllMainSequenceEffects();
}
void SlideShowImpl::redisplayCurrentSlide()
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
stopShow();
OSL_ENSURE( !maViewContainer.empty(), "### no views!" );
if (maViewContainer.empty())
return;
// No transition effect on this slide - schedule slide
// effect start event right away.
maEventQueue.addEvent(
makeEvent( [this] () { this->notifySlideTransitionEnded(true); },
"SlideShowImpl::notifySlideTransitionEnded"));
maListenerContainer.forEach<presentation::XSlideShowListener>(
[](uno::Reference<presentation::XSlideShowListener> const& xListener)
{
xListener->slideTransitionStarted();
});
}
sal_Bool SlideShowImpl::nextEffect()
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return false;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
if (mbShowPaused)
return true;
else
return maEventMultiplexer.notifyNextEffect();
}
sal_Bool SlideShowImpl::previousEffect()
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return false;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
if (mbShowPaused)
return true;
else
{
return maEffectRewinder.rewind(
maScreenUpdater.createLock(),
[this]() { return this->redisplayCurrentSlide(); },
[this]() { return this->rewindEffectToPreviousSlide(); } );
}
}
void SlideShowImpl::rewindEffectToPreviousSlide()
{
// Show the wait symbol now and prevent it from showing temporary slide
// content while effects are played back.
WaitSymbolLock aLock (*this);
// A previous call to EffectRewinder::Rewind could not rewind the current
// effect because there are no effects on the current slide or none has
// yet been displayed. Go to the previous slide.
notifySlideEnded(true);
// Process pending events once more in order to have the following
// screen update show the last effect. Not sure whether this should be
// necessary.
maEventQueue.forceEmpty();
// We have to call the screen updater before the wait symbol is turned
// off. Otherwise the wait symbol would force the display of an
// intermediate state of the slide (before the effects are replayed.)
maScreenUpdater.commitUpdates();
}
sal_Bool SlideShowImpl::startShapeActivity(
uno::Reference<drawing::XShape> const& /*xShape*/ )
{
osl::MutexGuard const guard( m_aMutex );
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
// TODO(F3): NYI
OSL_FAIL( "not yet implemented!" );
return false;
}
sal_Bool SlideShowImpl::stopShapeActivity(
uno::Reference<drawing::XShape> const& /*xShape*/ )
{
osl::MutexGuard const guard( m_aMutex );
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
// TODO(F3): NYI
OSL_FAIL( "not yet implemented!" );
return false;
}
sal_Bool SlideShowImpl::pause( sal_Bool bPauseShow )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return false;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
if (bPauseShow)
mpPresTimer->pauseTimer();
else
mpPresTimer->continueTimer();
maEventMultiplexer.notifyPauseMode(bPauseShow);
mbShowPaused = bPauseShow;
return true;
}
uno::Reference<drawing::XDrawPage> SlideShowImpl::getCurrentSlide()
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return uno::Reference<drawing::XDrawPage>();
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
if (mpCurrentSlide)
return mpCurrentSlide->getXDrawPage();
else
return uno::Reference<drawing::XDrawPage>();
}
sal_Bool SlideShowImpl::addView(
uno::Reference<presentation::XSlideShowView> const& xView )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return false;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
// first of all, check if view has a valid canvas
ENSURE_OR_RETURN_FALSE( xView.is(), "addView(): Invalid view" );
ENSURE_OR_RETURN_FALSE( xView->getCanvas().is(),
"addView(): View does not provide a valid canvas" );
UnoViewSharedPtr const pView( createSlideView(
xView,
maEventQueue,
maEventMultiplexer ));
if (!maViewContainer.addView( pView ))
return false; // view already added
// initialize view content
// =======================
if (mpCurrentSlide)
{
// set view transformation
const basegfx::B2ISize slideSize = mpCurrentSlide->getSlideSize();
pView->setViewSize( basegfx::B2DSize( slideSize.getX(),
slideSize.getY() ) );
}
// clear view area (since it's newly added,
// we need a clean slate)
pView->clearAll();
// broadcast newly added view
maEventMultiplexer.notifyViewAdded( pView );
// set current mouse ptr
pView->setCursorShape( calcActiveCursor(mnCurrentCursor) );
return true;
}
sal_Bool SlideShowImpl::removeView(
uno::Reference<presentation::XSlideShowView> const& xView )
{
osl::MutexGuard const guard( m_aMutex );
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
ENSURE_OR_RETURN_FALSE( xView.is(), "removeView(): Invalid view" );
UnoViewSharedPtr const pView( maViewContainer.removeView( xView ) );
if( !pView )
return false; // view was not added in the first place
// remove view from EventMultiplexer (mouse events etc.)
maEventMultiplexer.notifyViewRemoved( pView );
pView->_dispose();
return true;
}
void SlideShowImpl::registerUserPaintPolygons( const uno::Reference< lang::XMultiServiceFactory >& xDocFactory )
{
//Retrieve Polygons if user ends presentation by context menu
if (mpCurrentSlide)
{
if(findPolygons(mpCurrentSlide->getXDrawPage()) != maPolygons.end())
maPolygons.erase(mpCurrentSlide->getXDrawPage());
maPolygons.insert(make_pair(mpCurrentSlide->getXDrawPage(),mpCurrentSlide->getPolygons()));
}
//Creating the layer for shapes drawn during slideshow
// query for the XLayerManager
uno::Reference< drawing::XLayerSupplier > xLayerSupplier(xDocFactory, uno::UNO_QUERY);
uno::Reference< container::XNameAccess > xNameAccess = xLayerSupplier->getLayerManager();
uno::Reference< drawing::XLayerManager > xLayerManager(xNameAccess, uno::UNO_QUERY);
// create layer
uno::Reference< drawing::XLayer > xDrawnInSlideshow;
uno::Any aPropLayer;
OUString sLayerName = "DrawnInSlideshow";
if (xNameAccess->hasByName(sLayerName))
{
xNameAccess->getByName(sLayerName) >>= xDrawnInSlideshow;
}
else
{
xDrawnInSlideshow = xLayerManager->insertNewByIndex(xLayerManager->getCount());
aPropLayer <<= sLayerName;
xDrawnInSlideshow->setPropertyValue("Name", aPropLayer);
}
// ODF defaults from ctor of SdrLayer are not automatically set on the here
// created XLayer. Need to be done explicitly here.
aPropLayer <<= true;
xDrawnInSlideshow->setPropertyValue("IsVisible", aPropLayer);
xDrawnInSlideshow->setPropertyValue("IsPrintable", aPropLayer);
aPropLayer <<= false;
xDrawnInSlideshow->setPropertyValue("IsLocked", aPropLayer);
//Register polygons for each slide
for( const auto& rPoly : maPolygons )
{
PolyPolygonVector aPolygons = rPoly.second;
//Get shapes for the slide
css::uno::Reference< css::drawing::XShapes > Shapes = rPoly.first;
//Retrieve polygons for one slide
for( const auto& pPolyPoly : aPolygons )
{
::basegfx::B2DPolyPolygon b2DPolyPoly = ::basegfx::unotools::b2DPolyPolygonFromXPolyPolygon2D(pPolyPoly->getUNOPolyPolygon());
//Normally there is only one polygon
for(sal_uInt32 i=0; i< b2DPolyPoly.count();i++)
{
const ::basegfx::B2DPolygon& aPoly = b2DPolyPoly.getB2DPolygon(i);
sal_uInt32 nPoints = aPoly.count();
if( nPoints > 1)
{
//create the PolyLineShape
uno::Reference< uno::XInterface > polyshape(xDocFactory->createInstance(
"com.sun.star.drawing.PolyLineShape" ) );
uno::Reference< drawing::XShape > rPolyShape(polyshape, uno::UNO_QUERY);
//Add the shape to the slide
Shapes->add(rPolyShape);
//Retrieve shape properties
uno::Reference< beans::XPropertySet > aXPropSet( rPolyShape, uno::UNO_QUERY );
//Construct a sequence of points sequence
drawing::PointSequenceSequence aRetval;
//Create only one sequence for one polygon
aRetval.realloc( 1 );
// Retrieve the sequence of points from aRetval
drawing::PointSequence* pOuterSequence = aRetval.getArray();
// Create 2 points in this sequence
pOuterSequence->realloc(nPoints);
// Get these points which are in an array
awt::Point* pInnerSequence = pOuterSequence->getArray();
for( sal_uInt32 n = 0; n < nPoints; n++ )
{
//Create a point from the polygon
*pInnerSequence++ = awt::Point(
basegfx::fround(aPoly.getB2DPoint(n).getX()),
basegfx::fround(aPoly.getB2DPoint(n).getY()));
}
//Fill the properties
//Give the built PointSequenceSequence.
uno::Any aParam;
aParam <<= aRetval;
aXPropSet->setPropertyValue("PolyPolygon", aParam );
//LineStyle : SOLID by default
drawing::LineStyle eLS;
eLS = drawing::LineStyle_SOLID;
aXPropSet->setPropertyValue("LineStyle", uno::Any(eLS) );
//LineColor
sal_uInt32 nLineColor;
nLineColor = pPolyPoly->getRGBALineColor();
//Transform polygon color from RRGGBBAA to AARRGGBB
aXPropSet->setPropertyValue("LineColor", uno::Any(RGBAColor2UnoColor(nLineColor)) );
//LineWidth
double fLineWidth;
fLineWidth = pPolyPoly->getStrokeWidth();
aXPropSet->setPropertyValue("LineWidth", uno::Any(static_cast<sal_Int32>(fLineWidth)) );
// make polygons special
xLayerManager->attachShapeToLayer(rPolyShape, xDrawnInSlideshow);
}
}
}
}
}
sal_Bool SlideShowImpl::setProperty( beans::PropertyValue const& rProperty )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return false;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
if ( rProperty.Name == "AutomaticAdvancement" )
{
double nTimeout(0.0);
mbAutomaticAdvancementMode = (rProperty.Value >>= nTimeout);
if (mbAutomaticAdvancementMode)
{
maEventMultiplexer.setAutomaticTimeout( nTimeout );
}
maEventMultiplexer.setAutomaticMode( mbAutomaticAdvancementMode );
return true;
}
if ( rProperty.Name == "UserPaintColor" )
{
sal_Int32 nColor(0);
if (rProperty.Value >>= nColor)
{
OSL_ENSURE( mbMouseVisible,
"setProperty(): User paint overrides invisible mouse" );
// enable user paint
maUserPaintColor = unoColor2RGBColor(nColor);
if( mpCurrentSlide && !mpCurrentSlide->isPaintOverlayActive() )
mpCurrentSlide->enablePaintOverlay();
maEventMultiplexer.notifyUserPaintColor( *maUserPaintColor );
}
else
{
// disable user paint
maUserPaintColor.reset();
maEventMultiplexer.notifyUserPaintDisabled();
}
resetCursor();
return true;
}
//adding support for erasing features in UserPaintOverlay
if ( rProperty.Name == "EraseAllInk" )
{
bool bEraseAllInk(false);
if (rProperty.Value >>= bEraseAllInk)
{
OSL_ENSURE( mbMouseVisible,
"setProperty(): User paint overrides invisible mouse" );
// enable user paint
maEraseAllInk = bEraseAllInk;
maEventMultiplexer.notifyEraseAllInk( *maEraseAllInk );
}
return true;
}
if ( rProperty.Name == "SwitchPenMode" )
{
bool bSwitchPenMode(false);
if (rProperty.Value >>= bSwitchPenMode)
{
OSL_ENSURE( mbMouseVisible,
"setProperty(): User paint overrides invisible mouse" );
if(bSwitchPenMode){
// Switch to Pen Mode
maEventMultiplexer.notifySwitchPenMode();
}
}
return true;
}
if ( rProperty.Name == "SwitchEraserMode" )
{
bool bSwitchEraserMode(false);
if (rProperty.Value >>= bSwitchEraserMode)
{
OSL_ENSURE( mbMouseVisible,
"setProperty(): User paint overrides invisible mouse" );
if(bSwitchEraserMode){
// switch to Eraser mode
maEventMultiplexer.notifySwitchEraserMode();
}
}
return true;
}
if ( rProperty.Name == "EraseInk" )
{
sal_Int32 nEraseInk(100);
if (rProperty.Value >>= nEraseInk)
{
OSL_ENSURE( mbMouseVisible,
"setProperty(): User paint overrides invisible mouse" );
// enable user paint
maEraseInk = nEraseInk;
maEventMultiplexer.notifyEraseInkWidth( *maEraseInk );
}
return true;
}
// new Property for pen's width
if ( rProperty.Name == "UserPaintStrokeWidth" )
{
double nWidth(4.0);
if (rProperty.Value >>= nWidth)
{
OSL_ENSURE( mbMouseVisible,"setProperty(): User paint overrides invisible mouse" );
// enable user paint stroke width
maUserPaintStrokeWidth = nWidth;
maEventMultiplexer.notifyUserPaintStrokeWidth( maUserPaintStrokeWidth );
}
return true;
}
if ( rProperty.Name == "AdvanceOnClick" )
{
bool bAdvanceOnClick = false;
if (! (rProperty.Value >>= bAdvanceOnClick))
return false;
maUserEventQueue.setAdvanceOnClick( bAdvanceOnClick );
return true;
}
if ( rProperty.Name == "DisableAnimationZOrder" )
{
bool bDisableAnimationZOrder = false;
if (! (rProperty.Value >>= bDisableAnimationZOrder))
return false;
mbDisableAnimationZOrder = bDisableAnimationZOrder;
return true;
}
if ( rProperty.Name == "ImageAnimationsAllowed" )
{
if (! (rProperty.Value >>= mbImageAnimationsAllowed))
return false;
// TODO(F3): Forward to slides!
return true;
}
if ( rProperty.Name == "MouseVisible" )
{
if (! (rProperty.Value >>= mbMouseVisible))
return false;
requestCursor(mnCurrentCursor);
return true;
}
if ( rProperty.Name == "ForceManualAdvance" )
{
return (rProperty.Value >>= mbForceManualAdvance);
}
if ( rProperty.Name == "RehearseTimings" )
{
bool bRehearseTimings = false;
if (! (rProperty.Value >>= bRehearseTimings))
return false;
if (bRehearseTimings)
{
// TODO(Q3): Move to slide
mpRehearseTimingsActivity = RehearseTimingsActivity::create(
SlideShowContext(
mpDummyPtr,
maEventQueue,
maEventMultiplexer,
maScreenUpdater,
maActivitiesQueue,
maUserEventQueue,
*this,
*this,
maViewContainer,
mxComponentContext) );
}
else if (mpRehearseTimingsActivity)
{
// removes timer from all views:
mpRehearseTimingsActivity->dispose();
mpRehearseTimingsActivity.reset();
}
return true;
}
if ( rProperty.Name == "WaitSymbolBitmap" )
{
uno::Reference<rendering::XBitmap> xBitmap;
if (! (rProperty.Value >>= xBitmap))
return false;
mpWaitSymbol = WaitSymbol::create( xBitmap,
maScreenUpdater,
maEventMultiplexer,
maViewContainer );
return true;
}
if ( rProperty.Name == "PointerSymbolBitmap" )
{
uno::Reference<rendering::XBitmap> xBitmap;
if (! (rProperty.Value >>= xBitmap))
return false;
mpPointerSymbol = PointerSymbol::create( xBitmap,
maScreenUpdater,
maEventMultiplexer,
maViewContainer );
return true;
}
if ( rProperty.Name == "PointerVisible" )
{
bool visible;
if (!(rProperty.Value >>= visible))
return false;
mpPointerSymbol->setVisible(visible);
return true;
}
if ( rProperty.Name == "PointerPosition")
{
css::geometry::RealPoint2D pos;
if (! (rProperty.Value >>= pos))
return false;
mpPointerSymbol->viewsChanged(pos);
return true;
}
if (rProperty.Name == "NoSlideTransitions" )
{
return (rProperty.Value >>= mbNoSlideTransitions);
}
if ( rProperty.Name == "IsSoundEnabled" )
{
uno::Sequence<uno::Any> aValues;
uno::Reference<presentation::XSlideShowView> xView;
bool bValue (false);
if ((rProperty.Value >>= aValues)
&& aValues.getLength()==2
&& (aValues[0] >>= xView)
&& (aValues[1] >>= bValue))
{
// Look up the view.
auto iView = std::find_if(maViewContainer.begin(), maViewContainer.end(),
[&xView](const UnoViewSharedPtr& rxView) { return rxView && rxView->getUnoView() == xView; });
if (iView != maViewContainer.end())
{
// Store the flag at the view so that media shapes have
// access to it.
(*iView)->setIsSoundEnabled(bValue);
return true;
}
}
}
return false;
}
void SlideShowImpl::addSlideShowListener(
uno::Reference<presentation::XSlideShowListener> const& xListener )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return;
// container syncs with passed mutex ref
maListenerContainer.addInterface(xListener);
}
void SlideShowImpl::removeSlideShowListener(
uno::Reference<presentation::XSlideShowListener> const& xListener )
{
osl::MutexGuard const guard( m_aMutex );
// container syncs with passed mutex ref
maListenerContainer.removeInterface(xListener);
}
void SlideShowImpl::addShapeEventListener(
uno::Reference<presentation::XShapeEventListener> const& xListener,
uno::Reference<drawing::XShape> const& xShape )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
ShapeEventListenerMap::iterator aIter;
if( (aIter=maShapeEventListeners.find( xShape )) ==
maShapeEventListeners.end() )
{
// no entry for this shape -> create one
aIter = maShapeEventListeners.emplace(
xShape,
std::make_shared<comphelper::OInterfaceContainerHelper2>(
m_aMutex)).first;
}
// add new listener to broadcaster
if( aIter->second )
aIter->second->addInterface( xListener );
maEventMultiplexer.notifyShapeListenerAdded(xShape);
}
void SlideShowImpl::removeShapeEventListener(
uno::Reference<presentation::XShapeEventListener> const& xListener,
uno::Reference<drawing::XShape> const& xShape )
{
osl::MutexGuard const guard( m_aMutex );
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
ShapeEventListenerMap::iterator aIter;
if( (aIter = maShapeEventListeners.find( xShape )) !=
maShapeEventListeners.end() )
{
// entry for this shape found -> remove listener from
// helper object
ENSURE_OR_THROW(
aIter->second.get(),
"SlideShowImpl::removeShapeEventListener(): "
"listener map contains NULL broadcast helper" );
aIter->second->removeInterface( xListener );
}
maEventMultiplexer.notifyShapeListenerRemoved(xShape);
}
void SlideShowImpl::setShapeCursor(
uno::Reference<drawing::XShape> const& xShape, sal_Int16 nPointerShape )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return;
// precondition: must only be called from the main thread!
DBG_TESTSOLARMUTEX();
ShapeCursorMap::iterator aIter;
if( (aIter=maShapeCursors.find( xShape )) == maShapeCursors.end() )
{
// no entry for this shape -> create one
if( nPointerShape != awt::SystemPointer::ARROW )
{
// add new entry, unless shape shall display
// normal pointer arrow -> no need to handle that
// case
maShapeCursors.emplace(xShape, nPointerShape);
}
}
else if( nPointerShape == awt::SystemPointer::ARROW )
{
// shape shall display normal cursor -> can disable
// the cursor and clear the entry
maShapeCursors.erase( xShape );
}
else
{
// existing entry found, update with new cursor ID
aIter->second = nPointerShape;
}
}
bool SlideShowImpl::requestCursor( sal_Int16 nCursorShape )
{
mnCurrentCursor = nCursorShape;
const sal_Int16 nActualCursor = calcActiveCursor(mnCurrentCursor);
// change all views to the requested cursor ID
for( const auto& pView : maViewContainer )
pView->setCursorShape( nActualCursor );
return nActualCursor==nCursorShape;
}
void SlideShowImpl::resetCursor()
{
mnCurrentCursor = awt::SystemPointer::ARROW;
const sal_Int16 nActualCursor = calcActiveCursor( mnCurrentCursor );
// change all views to the default cursor ID
for( const auto& pView : maViewContainer )
pView->setCursorShape( nActualCursor );
}
sal_Bool SlideShowImpl::update( double & nNextTimeout )
{
osl::MutexGuard const guard( m_aMutex );
if (isDisposed())
return false;
// precondition: update() must only be called from the
// main thread!
DBG_TESTSOLARMUTEX();
if( mbShowPaused )
{
// commit frame (might be repaints pending)
maScreenUpdater.commitUpdates();
return false;
}
else
{
// TODO(F2): re-evaluate whether that timer lagging makes
// sense.
// hold timer, while processing the queues:
// 1. when there is more than one active activity this ensures the
// same time for all activities and events
// 2. processing of events may lead to creation of further events
// that have zero delay. While the timer is stopped these events
// are processed in the same run.
{
//Get a shared-ptr that outlives the scope-guard which will
//ensure that the pointed-to-item exists in the case of a
//::dispose clearing mpPresTimer
std::shared_ptr<canvas::tools::ElapsedTime> xTimer(mpPresTimer);
comphelper::ScopeGuard scopeGuard(
[&xTimer]() { return xTimer->releaseTimer(); } );
xTimer->holdTimer();
// process queues
maEventQueue.process();
// #i118671# the call above may execute a macro bound to an object. In
// that case this macro may have destroyed this local slideshow so that it
// is disposed (see bugdoc at task). In that case, detect this and exit
// gently from this slideshow. Do not forget to disable the scoped
// call to mpPresTimer, this will be deleted if we are disposed.
if (isDisposed())
{
scopeGuard.dismiss();
return false;
}
maActivitiesQueue.process();
// commit frame to screen
maFrameSynchronization.Synchronize();
maScreenUpdater.commitUpdates();
// TODO(Q3): remove need to call dequeued() from
// activities. feels like a wart.
// Rationale for ActivitiesQueue::processDequeued(): when
// an activity ends, it usually pushed the end state to
// the animated shape in question, and ends the animation
// (which, in turn, will usually disable shape sprite
// mode). Disabling shape sprite mode causes shape
// repaint, which, depending on slide content, takes
// considerably more time than sprite updates. Thus, the
// last animation step tends to look delayed. To
// camouflage this, reaching end position and disabling
// sprite mode is split into two (normal Activity::end(),
// and Activity::dequeued()). Now, the reason to call
// commitUpdates() twice here is caused by the unrelated
// fact that during wait cursor display/hide, the screen
// is updated, and shows hidden sprites, but, in case of
// leaving the second commitUpdates() call out and punting
// that to the next round, no updated static slide
// content. In short, the last shape animation of a slide
// tends to blink at its end.
// process dequeued activities _after_ commit to screen
maActivitiesQueue.processDequeued();
// commit frame to screen
maScreenUpdater.commitUpdates();
}
// Time held until here
const bool bActivitiesLeft = ! maActivitiesQueue.isEmpty();
const bool bTimerEventsLeft = ! maEventQueue.isEmpty();
const bool bRet = (bActivitiesLeft || bTimerEventsLeft);
if (bRet)
{
// calc nNextTimeout value:
if (bActivitiesLeft)
{
// Activity queue is not empty. Tell caller that we would
// like to render another frame.
// Return a zero time-out to signal our caller to call us
// back as soon as possible. The actual timing, waiting the
// appropriate amount of time between frames, is then done
// by the maFrameSynchronization object.
nNextTimeout = 0;
maFrameSynchronization.Activate();
}
else
{
// timer events left:
// difference from current time (nota bene:
// time no longer held here!) to the next event in
// the event queue.
// #i61190# Retrieve next timeout only _after_
// processing activity queue
// ensure positive value:
nNextTimeout = std::max( 0.0, maEventQueue.nextTimeout() );
// There is no active animation so the frame rate does not
// need to be synchronized.
maFrameSynchronization.Deactivate();
}
mbSlideShowIdle = false;
}
#if defined(DBG_UTIL)
// when slideshow is idle, issue an XUpdatable::update() call
// exactly once after a previous animation sequence finished -
// this might trigger screen dumps on some canvas
// implementations
if( !mbSlideShowIdle &&
(!bRet ||
nNextTimeout > 1.0) )
{
for( const auto& pView : maViewContainer )
{
try
{
uno::Reference< presentation::XSlideShowView > xView( pView->getUnoView(),
uno::UNO_SET_THROW );
uno::Reference<util::XUpdatable> const xUpdatable(
xView->getCanvas(), uno::UNO_QUERY);
if (xUpdatable.is()) // not supported in PresenterCanvas
{
xUpdatable->update();
}
}
catch( uno::RuntimeException& )
{
throw;
}
catch( uno::Exception& )
{
TOOLS_WARN_EXCEPTION( "slideshow", "" );
}
}
mbSlideShowIdle = true;
}
#endif
return bRet;
}
}
void SlideShowImpl::notifySlideTransitionEnded( bool bPaintSlide )
{
osl::MutexGuard const guard( m_aMutex );
OSL_ENSURE( !isDisposed(), "### already disposed!" );
OSL_ENSURE( mpCurrentSlide,
"notifySlideTransitionEnded(): Invalid current slide" );
if (mpCurrentSlide)
{
mpCurrentSlide->update_settings( !!maUserPaintColor, maUserPaintColor ? *maUserPaintColor : RGBColor(), maUserPaintStrokeWidth );
// first init show, to give the animations
// the chance to register SlideStartEvents
const bool bBackgroundLayerRendered( !bPaintSlide );
mpCurrentSlide->show( bBackgroundLayerRendered );
maEventMultiplexer.notifySlideStartEvent();
}
}
void queryAutomaticSlideTransition( uno::Reference<drawing::XDrawPage> const& xDrawPage,
double& nAutomaticNextSlideTimeout,
bool& bHasAutomaticNextSlide )
{
// retrieve slide change parameters from XDrawPage
// ===============================================
uno::Reference< beans::XPropertySet > xPropSet( xDrawPage,
uno::UNO_QUERY );
sal_Int32 nChange(0);
if( !xPropSet.is() ||
!getPropertyValue( nChange,
xPropSet,
"Change") )
{
SAL_INFO("slideshow",
"queryAutomaticSlideTransition(): "
"Could not extract slide change mode from XDrawPage - assuming <none>" );
}
bHasAutomaticNextSlide = nChange == 1;
if( !xPropSet.is() ||
!getPropertyValue( nAutomaticNextSlideTimeout,
xPropSet,
"HighResDuration") )
{
SAL_INFO("slideshow",
"queryAutomaticSlideTransition(): "
"Could not extract slide transition timeout from "
"XDrawPage - assuming 1 sec" );
}
}
void SlideShowImpl::notifySlideAnimationsEnded()
{
osl::MutexGuard const guard( m_aMutex );
//Draw polygons above animations
mpCurrentSlide->drawPolygons();
OSL_ENSURE( !isDisposed(), "### already disposed!" );
// This struct will receive the (interruptable) event,
// that triggers the notifySlideEnded() method.
InterruptableEventPair aNotificationEvents;
if( maEventMultiplexer.getAutomaticMode() )
{
OSL_ENSURE( ! mpRehearseTimingsActivity,
"unexpected: RehearseTimings mode!" );
// schedule a slide end event, with automatic mode's
// delay
aNotificationEvents = makeInterruptableDelay(
[this]() { return this->notifySlideEnded( false ); },
maEventMultiplexer.getAutomaticTimeout() );
}
else
{
OSL_ENSURE( mpCurrentSlide,
"notifySlideAnimationsEnded(): Invalid current slide!" );
bool bHasAutomaticNextSlide=false;
double nAutomaticNextSlideTimeout=0.0;
queryAutomaticSlideTransition(mpCurrentSlide->getXDrawPage(),
nAutomaticNextSlideTimeout,
bHasAutomaticNextSlide);
// check whether slide transition should happen
// 'automatically'. If yes, simply schedule the
// specified timeout.
// NOTE: mbForceManualAdvance and mpRehearseTimingsActivity
// override any individual slide setting, to always
// step slides manually.
if( !mbForceManualAdvance &&
!mpRehearseTimingsActivity &&
bHasAutomaticNextSlide )
{
aNotificationEvents = makeInterruptableDelay(
[this]() { return this->notifySlideEnded( false ); },
nAutomaticNextSlideTimeout);
// TODO(F2): Provide a mechanism to let the user override
// this automatic timeout via next()
}
else
{
if (mpRehearseTimingsActivity)
mpRehearseTimingsActivity->start();
// generate click event. Thus, the user must
// trigger the actual end of a slide. No need to
// generate interruptable event here, there's no
// timeout involved.
aNotificationEvents.mpImmediateEvent =
makeEvent( [this] () { this->notifySlideEnded(false); },
"SlideShowImpl::notifySlideEnded");
}
}
// register events on the queues. To make automatic slide
// changes interruptable, register the interruption event
// as a nextEffectEvent target. Note that the timeout
// event is optional (e.g. manual slide changes don't
// generate a timeout)
maUserEventQueue.registerNextEffectEvent(
aNotificationEvents.mpImmediateEvent );
if( aNotificationEvents.mpTimeoutEvent )
maEventQueue.addEvent( aNotificationEvents.mpTimeoutEvent );
// current slide's main sequence is over. Now should be
// the time to prefetch the next slide (if any), and
// prepare the initial slide bitmap (speeds up slide
// change setup time a lot). Show the wait cursor, this
// indeed might take some seconds.
{
WaitSymbolLock aLock (*this);
if (! matches( mpPrefetchSlide,
mxPrefetchSlide, mxPrefetchAnimationNode ))
{
mpPrefetchSlide = makeSlide( mxPrefetchSlide, mxDrawPagesSupplier,
mxPrefetchAnimationNode );
}
if (mpPrefetchSlide)
{
// ignore return value, this is just to populate
// Slide's internal bitmap buffer, such that the time
// needed to generate the slide bitmap is not spent
// when the slide change is requested.
mpPrefetchSlide->getCurrentSlideBitmap( *maViewContainer.begin() );
}
} // finally
maListenerContainer.forEach<presentation::XSlideShowListener>(
[](uno::Reference<presentation::XSlideShowListener> const& xListener)
{
xListener->slideAnimationsEnded();
});
}
void SlideShowImpl::notifySlideEnded (const bool bReverse)
{
osl::MutexGuard const guard( m_aMutex );
OSL_ENSURE( !isDisposed(), "### already disposed!" );
if (mpRehearseTimingsActivity && !bReverse)
{
const double time = mpRehearseTimingsActivity->stop();
if (mpRehearseTimingsActivity->hasBeenClicked())
{
// save time at current drawpage:
uno::Reference<beans::XPropertySet> xPropSet(
mpCurrentSlide->getXDrawPage(), uno::UNO_QUERY );
OSL_ASSERT( xPropSet.is() );
if (xPropSet.is())
{
xPropSet->setPropertyValue(
"Change",
uno::Any( static_cast<sal_Int32>(1) ) );
xPropSet->setPropertyValue(
"Duration",
uno::Any( static_cast<sal_Int32>(time) ) );
}
}
}
if (bReverse)
maEventMultiplexer.notifySlideEndEvent();
stopShow(); // MUST call that: results in
// maUserEventQueue.clear(). What's more,
// stopShow()'s currSlide->hide() call is
// now also required, notifySlideEnded()
// relies on that
// unconditionally. Otherwise, genuine
// shape animations (drawing layer and
// GIF) will not be stopped.
maListenerContainer.forEach<presentation::XSlideShowListener>(
[&bReverse]( const uno::Reference< presentation::XSlideShowListener >& xListener )
{ return xListener->slideEnded( bReverse ); } );
}
bool SlideShowImpl::notifyHyperLinkClicked( OUString const& hyperLink )
{
osl::MutexGuard const guard( m_aMutex );
maListenerContainer.forEach<presentation::XSlideShowListener>(
[&hyperLink]( const uno::Reference< presentation::XSlideShowListener >& xListener )
{ return xListener->hyperLinkClicked( hyperLink ); } );
return true;
}
/** Notification from eventmultiplexer that an animation event has occurred.
This will be forwarded to all registered XSlideShoeListener
*/
bool SlideShowImpl::handleAnimationEvent( const AnimationNodeSharedPtr& rNode )
{
osl::MutexGuard const guard( m_aMutex );
uno::Reference<animations::XAnimationNode> xNode( rNode->getXAnimationNode() );
switch( rNode->getState() )
{
case AnimationNode::ACTIVE:
maListenerContainer.forEach<presentation::XSlideShowListener>(
[&xNode]( const uno::Reference< animations::XAnimationListener >& xListener )
{ return xListener->beginEvent( xNode ); } );
break;
case AnimationNode::FROZEN:
case AnimationNode::ENDED:
maListenerContainer.forEach<presentation::XSlideShowListener>(
[&xNode]( const uno::Reference< animations::XAnimationListener >& xListener )
{ return xListener->endEvent( xNode ); } );
if(mpCurrentSlide->isPaintOverlayActive())
mpCurrentSlide->drawPolygons();
break;
default:
break;
}
return true;
}
std::shared_ptr<avmedia::MediaTempFile> SlideShowImpl::getMediaTempFile(const OUString& aUrl)
{
std::shared_ptr<avmedia::MediaTempFile> aRet;
if (!mxSBD.is())
return aRet;
comphelper::LifecycleProxy aProxy;
uno::Reference<io::XStream> xStream =
comphelper::OStorageHelper::GetStreamAtPackageURL(mxSBD->getDocumentStorage(), aUrl,
css::embed::ElementModes::READ, aProxy);
uno::Reference<io::XInputStream> xInStream = xStream->getInputStream();
if (xInStream.is())
{
sal_Int32 nLastDot = aUrl.lastIndexOf('.');
sal_Int32 nLastSlash = aUrl.lastIndexOf('/');
OUString sDesiredExtension;
if (nLastDot > nLastSlash && nLastDot+1 < aUrl.getLength())
sDesiredExtension = aUrl.copy(nLastDot);
OUString sTempUrl;
if (::avmedia::CreateMediaTempFile(xInStream, sTempUrl, sDesiredExtension))
aRet = std::make_shared<avmedia::MediaTempFile>(sTempUrl);
xInStream->closeInput();
}
return aRet;
}
//===== FrameSynchronization ==================================================
FrameSynchronization::FrameSynchronization (const double nFrameDuration)
: maTimer(),
mnFrameDuration(nFrameDuration),
mnNextFrameTargetTime(0),
mbIsActive(false)
{
MarkCurrentFrame();
}
void FrameSynchronization::MarkCurrentFrame()
{
mnNextFrameTargetTime = maTimer.getElapsedTime() + mnFrameDuration;
}
void FrameSynchronization::Synchronize()
{
if (mbIsActive)
{
// Do busy waiting for now.
while (maTimer.getElapsedTime() < mnNextFrameTargetTime)
;
}
MarkCurrentFrame();
}
void FrameSynchronization::Activate()
{
mbIsActive = true;
}
void FrameSynchronization::Deactivate()
{
mbIsActive = false;
}
} // anon namespace
namespace sdecl = comphelper::service_decl;
const sdecl::ServiceDecl slideShowDecl(
sdecl::class_<SlideShowImpl>(),
"com.sun.star.comp.presentation.SlideShow",
"com.sun.star.presentation.SlideShow" );
// The C shared lib entry points
extern "C"
SAL_DLLPUBLIC_EXPORT void* slideshow_component_getFactory( char const* pImplName,
void*, void* )
{
return sdecl::component_getFactoryHelper( pImplName, {&slideShowDecl} );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|