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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <com/sun/star/animations/XAnimationNodeSupplier.hpp>
#include <com/sun/star/animations/AnimationFill.hpp>
#include <com/sun/star/animations/AnimationRestart.hpp>
#include <com/sun/star/animations/Timing.hpp>
#include <com/sun/star/animations/Event.hpp>
#include <com/sun/star/animations/AnimationEndSync.hpp>
#include <com/sun/star/animations/EventTrigger.hpp>
#include <com/sun/star/presentation/EffectNodeType.hpp>
#include <com/sun/star/presentation/EffectPresetClass.hpp>
#include <com/sun/star/animations/AnimationNodeType.hpp>
#include <com/sun/star/animations/AnimationTransformType.hpp>
#include <com/sun/star/animations/AnimationCalcMode.hpp>
#include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/animations/AnimationAdditiveMode.hpp>
#include <com/sun/star/animations/XAnimateSet.hpp>
#include <com/sun/star/animations/XAudio.hpp>
#include <com/sun/star/animations/XTransitionFilter.hpp>
#include <com/sun/star/animations/XAnimateColor.hpp>
#include <com/sun/star/animations/XAnimateMotion.hpp>
#include <com/sun/star/animations/XAnimateTransform.hpp>
#include <com/sun/star/animations/ValuePair.hpp>
#include <com/sun/star/animations/AnimationColorSpace.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>
#include <com/sun/star/awt/FontWeight.hpp>
#include <com/sun/star/awt/FontUnderline.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/presentation/ParagraphTarget.hpp>
#include <com/sun/star/text/XSimpleText.hpp>
#include <com/sun/star/animations/XIterateContainer.hpp>
#include <com/sun/star/presentation/TextAnimationType.hpp>

#include <oox/ppt/pptfilterhelpers.hxx>
#include "pptexanimations.hxx"
#include "pptexsoundcollection.hxx"
#include "../ppt/pptanimations.hxx"
#include <filter/msfilter/escherex.hxx>
#include <osl/diagnose.h>
#include <tools/debug.hxx>

#include <algorithm>

using ::com::sun::star::uno::Any;
using ::com::sun::star::util::XCloneable;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::beans::NamedValue;
using ::com::sun::star::container::XEnumerationAccess;
using ::com::sun::star::container::XEnumeration;

using namespace ::com::sun::star::text;
using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::animations;
using namespace ::com::sun::star::presentation;

namespace ppt
{

static void ImplTranslateAttribute( OUString& rString, const TranslateMode eTranslateMode )
{
    if ( eTranslateMode == TRANSLATE_NONE )
        return;

    if ( ( eTranslateMode & TRANSLATE_VALUE ) || ( eTranslateMode & TRANSLATE_ATTRIBUTE ) )
    {
        const oox::ppt::ImplAttributeNameConversion* p = oox::ppt::getAttributeConversionList();
        while( p->mpAPIName )
        {
            if( rString.equalsAscii( p->mpAPIName ) )
                break;
            p++;
        }
        if( p->mpMSName )
        {
            if ( eTranslateMode & TRANSLATE_VALUE )
            {
                rString = "#";
                rString += OUString::createFromAscii( p->mpMSName );
            }
            else
                rString = OUString::createFromAscii( p->mpMSName );
        }
    }
    else if ( eTranslateMode & TRANSLATE_MEASURE )
    {
        const char* pDest[] = { "#ppt_x", "#ppt_y", "#ppt_w", "#ppt_h", nullptr };
        const char* pSource[] = { "x", "y", "width", "height", nullptr };
        sal_Int32 nIndex = 0;

        const char** ps = pSource;
        const char** pd = pDest;

        while( *ps )
        {
            const OUString aSearch( OUString::createFromAscii( *ps ) );
            while( (nIndex = rString.indexOf( aSearch, nIndex )) != -1  )
            {
                sal_Int32 nLength = aSearch.getLength();
                if( nIndex && ( rString[nIndex-1] == '#' ) )
                {
                    nIndex--;
                    nLength++;
                }

                const OUString aNew( OUString::createFromAscii( *pd ) );
                rString = rString.replaceAt( nIndex, nLength, aNew );
                nIndex += aNew.getLength();
            }
            ps++;
            pd++;
        }
    }
}

sal_uInt32 AnimationExporter::TranslatePresetSubType( const sal_uInt32 nPresetClass, const sal_uInt32 nPresetId, const OUString& rPresetSubType )
{
    sal_uInt32  nPresetSubType = 0;
    bool    bTranslated = false;

    if ( ( nPresetClass == sal_uInt32(EffectPresetClass::ENTRANCE) ) || ( nPresetClass == sal_uInt32(EffectPresetClass::EXIT) ) )
    {
        if ( nPresetId != 21 )
        {
            switch( nPresetId )
            {
                case 5 :
                {
                    if ( rPresetSubType == "downward" )
                    {
                        nPresetSubType = 5;
                        bTranslated = true;
                    }
                    else if ( rPresetSubType == "across" )
                    {
                        nPresetSubType = 10;
                        bTranslated = true;
                    }
                }
                break;
                case 17 :
                {
                    if ( rPresetSubType == "across" )
                    {
                        nPresetSubType = 10;
                        bTranslated = true;
                    }
                }
                break;
                case 18 :
                {
                    if ( rPresetSubType == "right-to-top" )
                    {
                        nPresetSubType = 3;
                        bTranslated = true;
                    }
                    else if ( rPresetSubType == "right-to-bottom" )
                    {
                        nPresetSubType = 6;
                        bTranslated = true;
                    }
                    else if ( rPresetSubType == "left-to-top" )
                    {
                        nPresetSubType = 9;
                        bTranslated = true;
                    }
                    else if ( rPresetSubType == "left-to-bottom" )
                    {
                        nPresetSubType = 12;
                        bTranslated = true;
                    }
                }
                break;
            }
        }
        if ( !bTranslated )
        {
            const oox::ppt::convert_subtype* p = oox::ppt::convert_subtype::getList();
            while( p->mpStrSubType )
            {
                if ( rPresetSubType.equalsAscii( p->mpStrSubType ) )
                {
                    nPresetSubType = p->mnID;
                    bTranslated = true;
                    break;
                }
                p++;
            }
        }
    }
    if ( !bTranslated )
        nPresetSubType = rPresetSubType.toUInt32();
    return nPresetSubType;
}

const char* AnimationExporter::FindTransitionName( const sal_Int16 nType, const sal_Int16 nSubType, const bool bDirection )
{
    const char* pRet = nullptr;
    int             nFit = 0;

    const oox::ppt::transition* p = oox::ppt::transition::getList();
    while( p->mpName )
    {
        int nF = 0;
        if ( nType == p->mnType )
            nF += 4;
        if ( nSubType == p->mnSubType )
            nF += 2;
        if ( bDirection == p->mbDirection )
            nF += 1;
        if ( nF > nFit )
        {
            pRet = p->mpName;
            nFit = nF;
        }
        if ( nFit == 7 )    // maximum
            break;
        p++;
    }
    return pRet;
}

SvStream& WriteAnimationNode(SvStream& rOut, AnimationNode const & rNode )
{
    rOut.WriteInt32( rNode.mnU1 );
    rOut.WriteInt32( rNode.mnRestart );
    rOut.WriteInt32( rNode.mnGroupType );
    rOut.WriteInt32( rNode.mnFill );
    rOut.WriteInt32( rNode.mnU3 );
    rOut.WriteInt32( rNode.mnU4 );
    rOut.WriteInt32( rNode.mnDuration );
    rOut.WriteInt32( rNode.mnNodeType );

    return rOut;
}

AnimationExporter::AnimationExporter( const EscherSolverContainer& rSolverContainer, ppt::ExSoundCollection& rExSoundCollection ) :
    mrSolverContainer   ( rSolverContainer ),
    mrExSoundCollection ( rExSoundCollection ),
    mnCurrentGroup(0)
{
}

sal_Int16 AnimationExporter::GetFillMode( const Reference< XAnimationNode >& xNode, const sal_Int16 nFillDefault )
{
    sal_Int16 nFill = xNode->getFill();
    //#i119699 <Animation> The animation effect "Emphasis->FlashBulb" play incorrectly in Aoo saves a .ppt to another .ppt and plays the saved one.
    //#i119740 <Animation> The animation effect "Entrance->Flash Once" fails to play in Aoo while Aoo saves a .ppt to another .ppt and plays the saved one.
    if ((xNode->getType() == AnimationNodeType::ANIMATE)
        ||(xNode->getType() == AnimationNodeType::SET)
        ||(xNode->getType() == AnimationNodeType::TRANSITIONFILTER))
    {
        if ( nFill == AnimationFill::DEFAULT )
            return nFill;
    }

    if ( nFill == AnimationFill::DEFAULT )
    {
        nFill = nFillDefault;
    }
    if( nFill == AnimationFill::AUTO )
    {
        nFill = AnimationFill::REMOVE;
        bool bIsIndefiniteTiming = true;
        Any aAny = xNode->getDuration();
        if( aAny.hasValue() )
        {
            Timing eTiming;
            if( aAny >>= eTiming )<--- Variable 'aAny' is assigned a value that is never used.
                bIsIndefiniteTiming = eTiming == Timing_INDEFINITE;
        }
        if ( bIsIndefiniteTiming )
        {
            aAny = xNode->getEnd();
            if( aAny.hasValue() )
            {
                Timing eTiming;
                if( aAny >>= eTiming )<--- Variable 'aAny' is assigned a value that is never used.
                    bIsIndefiniteTiming = eTiming == Timing_INDEFINITE;
            }
            if ( bIsIndefiniteTiming )
            {
                if ( !xNode->getRepeatCount().hasValue() )
                {
                    aAny = xNode->getRepeatDuration();
                    if( aAny.hasValue() )
                    {
                        Timing eTiming;
                        if( aAny >>= eTiming )<--- Variable 'aAny' is assigned a value that is never used.
                            bIsIndefiniteTiming = eTiming == Timing_INDEFINITE;
                    }
                    if ( bIsIndefiniteTiming )
                        nFill = AnimationFill::FREEZE;
                }
            }
        }
    }
    return nFill;
}

void AnimationExporter::doexport( const Reference< XDrawPage >& xPage, SvStream& rStrm )
{
    Reference< XAnimationNodeSupplier > xNodeSupplier( xPage, UNO_QUERY );
    if( xNodeSupplier.is() )
    {
        const Reference< XAnimationNode > xRootNode( xNodeSupplier->getAnimationNode() );
        if( xRootNode.is() )
        {
            processAfterEffectNodes( xRootNode );
            exportNode( rStrm, xRootNode, DFF_msofbtAnimGroup, 1, 0, false, AnimationFill::AUTO );
        }
    }
}

void AnimationExporter::processAfterEffectNodes( const Reference< XAnimationNode >& xRootNode )
{
    try
    {
        Reference< XEnumerationAccess > xEnumerationAccess( xRootNode, UNO_QUERY_THROW );
        Reference< XEnumeration > xEnumeration( xEnumerationAccess->createEnumeration(), css::uno::UNO_SET_THROW );
        while( xEnumeration->hasMoreElements() )
        {
            Reference< XAnimationNode > xNode( xEnumeration->nextElement(), UNO_QUERY_THROW );

            Reference< XEnumerationAccess > xEnumerationAccess2( xNode, UNO_QUERY );
            if ( xEnumerationAccess2.is() )
            {
                Reference< XEnumeration > xEnumeration2( xEnumerationAccess2->createEnumeration(), css::uno::UNO_SET_THROW );
                while( xEnumeration2->hasMoreElements() )
                {
                    Reference< XAnimationNode > xChildNode( xEnumeration2->nextElement(), UNO_QUERY_THROW );

                    Reference< XEnumerationAccess > xEnumerationAccess3( xChildNode, UNO_QUERY_THROW );
                    Reference< XEnumeration > xEnumeration3( xEnumerationAccess3->createEnumeration(), css::uno::UNO_SET_THROW );
                    while( xEnumeration3->hasMoreElements() )
                    {
                        Reference< XAnimationNode > xChildNode2( xEnumeration3->nextElement(), UNO_QUERY_THROW );

                        Reference< XEnumerationAccess > xEnumerationAccess4( xChildNode2, UNO_QUERY_THROW );
                        Reference< XEnumeration > xEnumeration4( xEnumerationAccess4->createEnumeration(), css::uno::UNO_SET_THROW );
                        while( xEnumeration4->hasMoreElements() )
                        {
                            Reference< XAnimationNode > xChildNode3( xEnumeration4->nextElement(), UNO_QUERY_THROW );

                            switch( xChildNode3->getType() )
                            {
                            // found an after effect
                            case AnimationNodeType::SET:
                            case AnimationNodeType::ANIMATECOLOR:
                                {
                                    Reference< XAnimationNode > xMaster;

                                    Sequence< NamedValue > aUserData( xChildNode3->getUserData() );
                                    const NamedValue* p = std::find_if(aUserData.begin(), aUserData.end(),
                                        [](const NamedValue& rProp) { return rProp.Name == "master-element"; });

                                    if (p != aUserData.end())
                                        p->Value >>= xMaster;

                                    AfterEffectNodePtr pAfterEffectNode = std::make_shared<AfterEffectNode>( xChildNode3, xMaster );
                                    maAfterEffectNodes.push_back( pAfterEffectNode );
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    catch( Exception& )
    {
        OSL_FAIL( "(@CL)AnimationExporter::processAfterEffectNodes(), exception caught!" );
    }
}

bool AnimationExporter::isAfterEffectNode( const Reference< XAnimationNode >& xNode ) const
{
    return std::any_of(maAfterEffectNodes.begin(), maAfterEffectNodes.end(),
        [&xNode](const AfterEffectNodePtr& rxNode) { return rxNode->mxNode == xNode; });
}

bool AnimationExporter::hasAfterEffectNode( const Reference< XAnimationNode >& xNode, Reference< XAnimationNode >& xAfterEffectNode ) const
{
    auto aIter = std::find_if(maAfterEffectNodes.begin(), maAfterEffectNodes.end(),
        [&xNode](const AfterEffectNodePtr& rxNode) { return rxNode->mxMaster == xNode; });
    if (aIter != maAfterEffectNodes.end())
    {
        xAfterEffectNode = (*aIter)->mxNode;
        return true;
    }

    return false;
}

// check if this group only contain empty groups. this may happen when
// after effect nodes are not exported at their original position
bool AnimationExporter::isEmptyNode( const Reference< XAnimationNode >& xNode ) const
{
    if( xNode.is() ) switch( xNode->getType() )
    {
    case AnimationNodeType::PAR :
    case AnimationNodeType::SEQ :
    case AnimationNodeType::ITERATE :
        {
            Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY );
            if( xEnumerationAccess.is() )
            {
                Reference< XEnumeration > xEnumeration = xEnumerationAccess->createEnumeration();
                if( xEnumeration.is() )
                {
                    while( xEnumeration->hasMoreElements() )
                    {
                        Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY );
                        if( xChildNode.is() && !isEmptyNode( xChildNode ) )
                            return false;
                    }
                }
            }
        }
        break;

    case AnimationNodeType::SET :
    case AnimationNodeType::ANIMATECOLOR :
        return isAfterEffectNode( xNode );
    default:
        return false;
    }

    return true;
}

void AnimationExporter::exportNode( SvStream& rStrm, Reference< XAnimationNode > const & xNode_in, const sal_uInt16 nContainerRecType,
                                    const sal_uInt16 nInstance, const sal_Int32 nGroupLevel, const bool bTakeBackInteractiveSequenceTiming, const sal_Int16 nFDef )
{
    auto xNode = xNode_in;

    if( (nGroupLevel == 4) && isEmptyNode( xNode ) )
        return;

    if ( ( nContainerRecType == DFF_msofbtAnimGroup ) && ( nGroupLevel == 2 ) && isEmptyNode( xNode ) )
        return;

    if( nContainerRecType == DFF_msofbtAnimGroup )
        mnCurrentGroup++;

    bool bTakeBackInteractiveSequenceTimingForChild = false;
    sal_Int16 nFillDefault = GetFillMode( xNode, nFDef );

    Reference< XAnimationNode > xAudioNode;
    static sal_uInt32 nAudioGroup;

    {
        bool bSkipChildren = false;
        EscherExContainer aContainer( rStrm, nContainerRecType, nInstance );
        switch( xNode->getType() )
        {
            case AnimationNodeType::CUSTOM :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );
                exportAnimEvent( rStrm, xNode );
                exportAnimValue( rStrm, xNode, false );
            }
            break;

            case AnimationNodeType::PAR :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );
                sal_Int32 nFlags = nGroupLevel == 2 ? 0x10 : 0;
                if ( bTakeBackInteractiveSequenceTiming )
                    nFlags |= 0x40;
                exportAnimEvent( rStrm, xNode, nFlags );
                exportAnimValue( rStrm, xNode, nGroupLevel == 4 );
            }
            break;

            case AnimationNodeType::SEQ :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                sal_Int16 nNodeType = exportAnimPropertySet( rStrm, xNode );
                sal_Int32 nFlags = 12;
                if ( ( nGroupLevel == 1 ) && ( nNodeType == css::presentation::EffectNodeType::INTERACTIVE_SEQUENCE ) )
                {
                    nFlags |= 0x20;
                    bTakeBackInteractiveSequenceTimingForChild = true;
                }
                exportAnimAction( rStrm, xNode );
                exportAnimEvent( rStrm, xNode, nFlags );
                exportAnimValue( rStrm, xNode, false );
            }
            break;

            case AnimationNodeType::ITERATE :
            {
                {
                    EscherExAtom aAnimNodeExAtom( rStrm, DFF_msofbtAnimNode );
                    AnimationNode aAnim;
                    aAnim.mnGroupType = mso_Anim_GroupType_PAR;
                    aAnim.mnNodeType = 1;
                    // attribute Restart
                    switch( xNode->getRestart() )
                    {
                        default:
                        case AnimationRestart::DEFAULT : aAnim.mnRestart = 0; break;
                        case AnimationRestart::ALWAYS  : aAnim.mnRestart = 1; break;
                        case AnimationRestart::WHEN_NOT_ACTIVE : aAnim.mnRestart = 2; break;
                        case AnimationRestart::NEVER : aAnim.mnRestart = 3; break;
                    }
                    // attribute Fill
                    switch( xNode->getFill() )
                    {
                        default:
                        case AnimationFill::DEFAULT : aAnim.mnFill = 0; break;
                        case AnimationFill::REMOVE : aAnim.mnFill = 1; break;
                        case AnimationFill::FREEZE : aAnim.mnFill = 2; break;
                        case AnimationFill::HOLD : aAnim.mnFill = 3; break;
                        case AnimationFill::TRANSITION : aAnim.mnFill = 4; break;
                    }
                    WriteAnimationNode( rStrm, aAnim );
                }
                exportIterate( rStrm, xNode );
                exportAnimPropertySet( rStrm, xNode );
                exportAnimEvent( rStrm, xNode );
                exportAnimValue( rStrm, xNode, false );
            }
            break;

            case AnimationNodeType::ANIMATE :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );
                exportAnimEvent( rStrm, xNode );
                exportAnimValue( rStrm, xNode, false );
                exportAnimate( rStrm, xNode );
            }
            break;

            case AnimationNodeType::SET :
            {
                bool bIsAfterEffectNode( isAfterEffectNode( xNode ) );
                if( (nGroupLevel != 4) || !bIsAfterEffectNode )
                {
                    exportAnimNode( rStrm, xNode, nFillDefault );
                    exportAnimPropertySet( rStrm, xNode );
                    exportAnimateSet( rStrm, xNode, bIsAfterEffectNode ? AFTEREFFECT_SET : AFTEREFFECT_NONE );
                    exportAnimEvent( rStrm, xNode );
                    exportAnimValue( rStrm, xNode, false );
                }
                else
                {
                    bSkipChildren = true;
                }
            }
            break;

            case AnimationNodeType::ANIMATEMOTION :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );
                exportAnimateMotion( rStrm, xNode );
                exportAnimEvent( rStrm, xNode );
                exportAnimValue( rStrm, xNode, false );
            }
            break;

            case AnimationNodeType::ANIMATECOLOR :
            {
                bool bIsAfterEffectNode( isAfterEffectNode( xNode ) );
                if( (nGroupLevel != 4) || !bIsAfterEffectNode )
                {
                    if( bIsAfterEffectNode )
                        xNode = createAfterEffectNodeClone( xNode );

                    exportAnimNode( rStrm, xNode, nFillDefault );
                    exportAnimPropertySet( rStrm, xNode );
                    exportAnimateColor( rStrm, xNode, bIsAfterEffectNode ? AFTEREFFECT_COLOR : AFTEREFFECT_NONE );
                    exportAnimEvent( rStrm, xNode );
                    exportAnimValue( rStrm, xNode, false );
                }
                else
                {
                    bSkipChildren = true;
                }
            }
            break;

            case AnimationNodeType::ANIMATETRANSFORM :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );
                exportAnimateTransform( rStrm, xNode );
                exportAnimEvent( rStrm, xNode );
                exportAnimValue( rStrm, xNode, false );
            }
            break;

            case AnimationNodeType::TRANSITIONFILTER :
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );
                exportAnimEvent( rStrm, xNode );
                exportAnimValue( rStrm, xNode, false );
                exportTransitionFilter( rStrm, xNode );
            }
            break;

            case AnimationNodeType::AUDIO :     // #i58428#
            {
                exportAnimNode( rStrm, xNode, nFillDefault );
                exportAnimPropertySet( rStrm, xNode );

                Reference< XAudio > xAudio( xNode, UNO_QUERY );
                if( xAudio.is() )
                {
                    Any aAny( xAudio->getSource() );
                    OUString aURL;

                    if ( ( aAny >>= aURL)  &&  !aURL.isEmpty()  )<--- Variable 'aAny' is assigned a value that is never used.
                    {
                        sal_Int32 nU1 = 2;
                        sal_Int32 nTrigger = 3;
                        sal_Int32 nU3 = nAudioGroup;
                        sal_Int32 nBegin = 0;
                        {
                            EscherExContainer aAnimEvent( rStrm, DFF_msofbtAnimEvent, 1 );
                            {
                                EscherExAtom aAnimTrigger( rStrm, DFF_msofbtAnimTrigger );
                                rStrm.WriteInt32( nU1 ).WriteInt32( nTrigger ).WriteInt32( nU3 ).WriteInt32( nBegin );
                            }
                        }
                        nU1 = 1;
                        nTrigger = 0xb;
                        nU3 = 0;
                        {
                            EscherExContainer aAnimEvent( rStrm, DFF_msofbtAnimEvent, 2 );
                            {
                                EscherExAtom aAnimTrigger( rStrm, DFF_msofbtAnimTrigger );
                                rStrm.WriteInt32( nU1 ).WriteInt32( nTrigger ).WriteInt32( nU3 ).WriteInt32( nBegin );
                            }
                        }
                        EscherExContainer aAnimateTargetElement( rStrm, DFF_msofbtAnimateTargetElement );
                        {
                            sal_uInt32 const nRefMode = 3;
                            sal_uInt32 const nRefType = 2;
                            sal_uInt32 nRefId = mrExSoundCollection.GetId( aURL );
                            sal_Int32 const begin = -1;
                            sal_Int32 const end = -1;

                            EscherExAtom aAnimReference( rStrm, DFF_msofbtAnimReference );
                            rStrm.WriteUInt32( nRefMode ).WriteUInt32( nRefType ).WriteUInt32( nRefId ).WriteInt32( begin ).WriteInt32( end );
                        }
                    }
                }
                exportAnimValue( rStrm, xNode, false );
            }
            break;
        }
        if( !bSkipChildren )
        {
            // export after effect node if one exists for this node
            Reference< XAnimationNode > xAfterEffectNode;
            if( hasAfterEffectNode( xNode, xAfterEffectNode ) )
            {
                exportNode( rStrm, xAfterEffectNode, DFF_msofbtAnimSubGoup, 1, nGroupLevel + 1, bTakeBackInteractiveSequenceTimingForChild, nFillDefault );
            }

            Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY );
            if( xEnumerationAccess.is() )
            {
                Reference< XEnumeration > xEnumeration = xEnumerationAccess->createEnumeration();
                if( xEnumeration.is() )
                {
                    while( xEnumeration->hasMoreElements() )
                    {
                        Reference< XAnimationNode > xChildNode( xEnumeration->nextElement(), UNO_QUERY );
                        if( xChildNode.is() )
                        {
                            if ( xChildNode->getType() == AnimationNodeType::AUDIO )
                            {
                                xAudioNode = xChildNode;
                                nAudioGroup = mnCurrentGroup;
                            }
                            else
                                exportNode( rStrm, xChildNode, DFF_msofbtAnimGroup, 1, nGroupLevel + 1, bTakeBackInteractiveSequenceTimingForChild, nFillDefault );
                        }
                    }
                }
            }
        }
    }
    if ( xAudioNode.is() )
        exportNode( rStrm, xAudioNode, DFF_msofbtAnimGroup, 1, nGroupLevel, bTakeBackInteractiveSequenceTimingForChild, nFillDefault );

    if( xNode->getType() == AnimationNodeType::ITERATE )
        aTarget = Any();
}

Reference< XAnimationNode > AnimationExporter::createAfterEffectNodeClone( const Reference< XAnimationNode >& xNode )
{
    try
    {
        Reference< css::util::XCloneable > xClonable( xNode, UNO_QUERY_THROW );
        Reference< XAnimationNode > xCloneNode( xClonable->createClone(), UNO_QUERY_THROW );

        Any aEmpty;
        xCloneNode->setBegin( aEmpty );

        return xCloneNode;
    }
    catch( Exception& )
    {
        OSL_FAIL("(@CL)sd::ppt::AnimationExporter::createAfterEffectNodeClone(), could not create clone!" );
    }
    return xNode;
}

bool AnimationExporter::GetNodeType( const Reference< XAnimationNode >& xNode, sal_Int16& nType )
{
    // trying to get the nodetype
    const Sequence< NamedValue > aUserData = xNode->getUserData();
    for( const NamedValue& rProp : aUserData )
    {
        if ( rProp.Name == "node-type" )
        {
            if ( rProp.Value >>= nType )
                return true;
        }
    }

    return false;
}

void AnimationExporter::exportAnimNode( SvStream& rStrm, const Reference< XAnimationNode >& xNode,
        const sal_Int16 nFillDefault )
{
    EscherExAtom    aAnimNodeExAtom( rStrm, DFF_msofbtAnimNode );
    AnimationNode   aAnim;

    // attribute Restart
    switch( xNode->getRestart() )
    {
        default:
        case AnimationRestart::DEFAULT : aAnim.mnRestart = 0; break;
        case AnimationRestart::ALWAYS  : aAnim.mnRestart = 1; break;
        case AnimationRestart::WHEN_NOT_ACTIVE : aAnim.mnRestart = 2; break;
        case AnimationRestart::NEVER : aAnim.mnRestart = 3; break;
    }

    switch( nFillDefault )
    {
        default:
        case AnimationFill::DEFAULT : aAnim.mnFill = 0; break;
        case AnimationFill::REMOVE : aAnim.mnFill = 1; break;
        case AnimationFill::FREEZE :
        case AnimationFill::HOLD :   aAnim.mnFill = 3; break;
        case AnimationFill::TRANSITION : aAnim.mnFill = 4; break;
    }
    // attribute Duration
    double fDuration = 0.0;
    css::animations::Timing eTiming;
    if ( xNode->getDuration() >>= eTiming )
    {
        if ( eTiming == Timing_INDEFINITE )
            aAnim.mnDuration = -1;
    }
    else if ( xNode->getDuration() >>= fDuration )
    {
        aAnim.mnDuration = static_cast<sal_Int32>( fDuration * 1000.0 );
    }
    else
        aAnim.mnDuration = -1;

    // NodeType, NodeGroup
    aAnim.mnNodeType = 1;
    aAnim.mnGroupType = mso_Anim_GroupType_SEQ;
    switch( xNode->getType() )
    {
        case AnimationNodeType::PAR :
            aAnim.mnGroupType = mso_Anim_GroupType_PAR;
            [[fallthrough]];
        case AnimationNodeType::SEQ :
        {
            sal_Int16 nType = 0;
            if( GetNodeType( xNode, nType ) )
                switch( nType )
                {
                    case css::presentation::EffectNodeType::TIMING_ROOT : aAnim.mnNodeType = 0x12; break;
                    case css::presentation::EffectNodeType::MAIN_SEQUENCE : aAnim.mnNodeType = 0x18; break;
                }
        }
        break;

        case AnimationNodeType::ANIMATE :
        case AnimationNodeType::SET :

        case AnimationNodeType::CUSTOM :
        case AnimationNodeType::ITERATE :
        case AnimationNodeType::ANIMATEMOTION :
        case AnimationNodeType::ANIMATECOLOR :
        case AnimationNodeType::ANIMATETRANSFORM :
        {
            aAnim.mnGroupType = mso_Anim_GroupType_NODE;
            aAnim.mnNodeType  = mso_Anim_Behaviour_ANIMATION;
        }
        break;

        case AnimationNodeType::AUDIO :
        {
            aAnim.mnGroupType = mso_Anim_GroupType_MEDIA;
            aAnim.mnNodeType  = mso_Anim_Behaviour_ANIMATION;
        }
        break;

        case AnimationNodeType::TRANSITIONFILTER :
        {
            aAnim.mnGroupType = mso_Anim_GroupType_NODE;
            aAnim.mnNodeType  = mso_Anim_Behaviour_FILTER;
        }
        break;
    }

    WriteAnimationNode( rStrm, aAnim );
}

void AnimationExporter::GetUserData( const Sequence< NamedValue >& rUserData, const Any ** pAny, std::size_t nLen )
{
    // storing user data into pAny, to allow direct access later
    memset( pAny, 0, nLen );
    if ( !rUserData.hasElements() )
        return;

    for( const NamedValue& rProp : rUserData )
    {
        if ( rProp.Name == "node-type" )
        {
            pAny[ DFF_ANIM_NODE_TYPE ] = &(rProp.Value);
        }
        else if ( rProp.Name == "preset-class" )
        {
            pAny[ DFF_ANIM_PRESET_CLASS ] = &(rProp.Value);
        }
        else if ( rProp.Name == "preset-id" )
        {
            pAny[ DFF_ANIM_PRESET_ID ] = &(rProp.Value);
        }
        else if ( rProp.Name == "preset-sub-type" )
        {
            pAny[ DFF_ANIM_PRESET_SUB_TYPE ] = &(rProp.Value);
        }
        else if ( rProp.Name == "master-element" )
        {
            pAny[ DFF_ANIM_AFTEREFFECT ] = &(rProp.Value);
        }
    }
}

sal_uInt32 AnimationExporter::GetPresetID( const OUString& rPreset, sal_uInt32 nAPIPresetClass, bool& bPresetId )
{
    sal_uInt32 nPresetId = 0;
    bPresetId = false;

    if ( rPreset.match("ppt_", 0) )
    {
    sal_Int32 nLast = rPreset.lastIndexOf( '_' );
    if ( ( nLast != -1 ) && ( ( nLast + 1 ) < rPreset.getLength() ) )
    {
        OUString aNumber( rPreset.copy( nLast + 1 ) );
        nPresetId = aNumber.toUInt32();
        bPresetId = true;
    }
    }
    else
    {
        const oox::ppt::preset_mapping* p = oox::ppt::preset_mapping::getList();
        while( p->mpStrPresetId && ((p->mnPresetClass != static_cast<sal_Int32>(nAPIPresetClass)) || !rPreset.equalsAscii( p->mpStrPresetId )) )
            p++;

        if( p->mpStrPresetId )
        {
            nPresetId = p->mnPresetId;
            bPresetId = true;
        }
    }

    return nPresetId;
}

sal_Int16 AnimationExporter::exportAnimPropertySet( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    sal_Int16 nNodeType = css::presentation::EffectNodeType::DEFAULT;

    EscherExContainer aAnimPropertySet( rStrm, DFF_msofbtAnimPropertySet );

    Reference< XAnimationNode > xMaster;

    Any aMasterRel, aOverride, aRunTimeContext;

    // storing user data into pAny, to allow direct access later
    const Sequence< NamedValue > aUserData = xNode->getUserData();
    const css::uno::Any* pAny[ DFF_ANIM_PROPERTY_ID_COUNT ];
    GetUserData( aUserData, pAny, sizeof( pAny ) );

    if( pAny[ DFF_ANIM_AFTEREFFECT ] )
        ( *pAny[ DFF_ANIM_AFTEREFFECT ] ) >>= xMaster;

    // calculate master-rel
    if( xMaster.is() )
    {
        sal_Int32 nMasterRel = 2;
        if( xNode.is() && xMaster.is() && (xNode->getParent() == xMaster->getParent() ) )
            nMasterRel = 0;

        aMasterRel <<= nMasterRel;

        pAny[ DFF_ANIM_MASTERREL ] = &aMasterRel;

        aOverride <<= sal_Int32(1);
        pAny[ DFF_ANIM_OVERRIDE ] = &aOverride;

        aRunTimeContext <<= sal_Int32(1);
        pAny[ DFF_ANIM_RUNTIMECONTEXT ] = &aRunTimeContext;
    }

    // the order is important
    if ( pAny[ DFF_ANIM_NODE_TYPE ] )
    {
        if ( *pAny[ DFF_ANIM_NODE_TYPE ] >>= nNodeType )
        {
            sal_uInt32 nPPTNodeType = DFF_ANIM_NODE_TYPE_ON_CLICK;
            switch( nNodeType )
            {
                case css::presentation::EffectNodeType::ON_CLICK : nPPTNodeType = DFF_ANIM_NODE_TYPE_ON_CLICK; break;
                case css::presentation::EffectNodeType::WITH_PREVIOUS : nPPTNodeType = DFF_ANIM_NODE_TYPE_WITH_PREVIOUS; break;
                case css::presentation::EffectNodeType::AFTER_PREVIOUS : nPPTNodeType = DFF_ANIM_NODE_TYPE_AFTER_PREVIOUS; break;
                case css::presentation::EffectNodeType::MAIN_SEQUENCE : nPPTNodeType = DFF_ANIM_NODE_TYPE_MAIN_SEQUENCE; break;
                case css::presentation::EffectNodeType::TIMING_ROOT : nPPTNodeType = DFF_ANIM_NODE_TYPE_TIMING_ROOT; break;
                case css::presentation::EffectNodeType::INTERACTIVE_SEQUENCE: nPPTNodeType = DFF_ANIM_NODE_TYPE_INTERACTIVE_SEQ; break;
            }
            exportAnimPropertyuInt32( rStrm, DFF_ANIM_NODE_TYPE, nPPTNodeType );
        }
    }
    sal_uInt32 nPresetId = 0;
    sal_uInt32 nPresetSubType = 0;
    sal_uInt32 nAPIPresetClass = EffectPresetClass::CUSTOM;
    sal_uInt32 nPresetClass = DFF_ANIM_PRESS_CLASS_USER_DEFINED;
    bool bPresetClass, bPresetId, bPresetSubType;
    bPresetId = bPresetClass = bPresetSubType = false;

    if ( pAny[ DFF_ANIM_PRESET_CLASS ] )
    {
        if ( *pAny[ DFF_ANIM_PRESET_CLASS ] >>= nAPIPresetClass )
        {
            sal_uInt8 nPPTPresetClass;
            switch( nAPIPresetClass )
            {
                case EffectPresetClass::ENTRANCE : nPPTPresetClass = DFF_ANIM_PRESS_CLASS_ENTRANCE; break;
                case EffectPresetClass::EXIT : nPPTPresetClass = DFF_ANIM_PRESS_CLASS_EXIT; break;
                case EffectPresetClass::EMPHASIS : nPPTPresetClass = DFF_ANIM_PRESS_CLASS_EMPHASIS; break;
                case EffectPresetClass::MOTIONPATH : nPPTPresetClass = DFF_ANIM_PRESS_CLASS_MOTIONPATH; break;
                case EffectPresetClass::OLEACTION : nPPTPresetClass = DFF_ANIM_PRESS_CLASS_OLE_ACTION; break;
                case EffectPresetClass::MEDIACALL : nPPTPresetClass = DFF_ANIM_PRESS_CLASS_MEDIACALL; break;
                default :
                    nPPTPresetClass = DFF_ANIM_PRESS_CLASS_USER_DEFINED;
            }
            nPresetClass = nPPTPresetClass;
            bPresetClass = true;
        }
    }
    if ( pAny[ DFF_ANIM_PRESET_ID ] )
    {
        OUString sPreset;
        if ( *pAny[ DFF_ANIM_PRESET_ID ] >>= sPreset )
            nPresetId = GetPresetID( sPreset, nAPIPresetClass, bPresetId );
    }

    if ( pAny[ DFF_ANIM_PRESET_SUB_TYPE ] )
    {
        OUString sPresetSubType;
        if ( *pAny[ DFF_ANIM_PRESET_SUB_TYPE ] >>= sPresetSubType )
        {
            nPresetSubType = TranslatePresetSubType( nPresetClass, nPresetId, sPresetSubType );
            bPresetSubType = true;
        }
    }
    if ( bPresetId )
        exportAnimPropertyuInt32( rStrm, DFF_ANIM_PRESET_ID, nPresetId );
    if ( bPresetSubType )
        exportAnimPropertyuInt32( rStrm, DFF_ANIM_PRESET_SUB_TYPE, nPresetSubType );
    if ( bPresetClass )
        exportAnimPropertyuInt32( rStrm, DFF_ANIM_PRESET_CLASS, nPresetClass );

    if ( pAny[ DFF_ANIM_ID ] )
    {
        // TODO DFF_ANIM_ID
    }

    if ( pAny[ DFF_ANIM_AFTEREFFECT ] )
    {
        bool bAfterEffect = false;
        if ( *pAny[ DFF_ANIM_AFTEREFFECT ] >>= bAfterEffect )
            exportAnimPropertyByte( rStrm, DFF_ANIM_AFTEREFFECT, int(bAfterEffect) );
    }

    if ( pAny[ DFF_ANIM_RUNTIMECONTEXT ] )
    {
        sal_Int32 nRunTimeContext = 0;
        if ( *pAny[ DFF_ANIM_RUNTIMECONTEXT ] >>= nRunTimeContext )
            exportAnimPropertyuInt32( rStrm, DFF_ANIM_RUNTIMECONTEXT, nRunTimeContext );
    }
    if ( pAny[ DFF_ANIM_PATH_EDIT_MODE ] )
    {
        // TODO DFF_ANIM_ID
    }

    if( !xMaster.is() )
    {
        Reference< XAnimateColor > xColor( xNode, UNO_QUERY );
        if( xColor.is() )
        {

            bool bDirection = !xColor->getDirection();
            exportAnimPropertyuInt32( rStrm, DFF_ANIM_DIRECTION, bDirection ? 1 : 0 );
        }
    }

    if ( pAny[ DFF_ANIM_OVERRIDE ] )
    {
        sal_Int32 nOverride = 0;
        if ( *pAny[ DFF_ANIM_OVERRIDE ] >>= nOverride )
            exportAnimPropertyuInt32( rStrm, DFF_ANIM_OVERRIDE, nOverride );
    }

    if ( pAny[ DFF_ANIM_MASTERREL ] )
    {
        sal_Int32 nMasterRel = 0;
        if ( *pAny[ DFF_ANIM_MASTERREL ] >>= nMasterRel )
            exportAnimPropertyuInt32( rStrm, DFF_ANIM_MASTERREL, nMasterRel );
    }

/* todo
    Reference< XAudio > xAudio( xNode, UNO_QUERY );
    if( xAudio.is() )
    {
        sal_Int16 nEndAfterSlide = 0;
        nEndAfterSlide = xAudio->getEndAfterSlide();
        exportAnimPropertyuInt32( rStrm, DFF_ANIM_ENDAFTERSLIDE, nEndAfterSlide, TRANSLATE_NONE );
    }
*/
    Reference< XAnimate > xAnim( xNode, UNO_QUERY );
    if( xAnim.is() )
    {
        // TODO: DFF_ANIM_TIMEFILTER
    }
    if ( pAny[ DFF_ANIM_EVENT_FILTER ] )
    {
        // TODO DFF_ANIM_EVENT_FILTER
    }
    if ( pAny[ DFF_ANIM_VOLUME ] )
    {
        // TODO DFF_ANIM_VOLUME
    }
    return nNodeType;
}

bool AnimationExporter::exportAnimProperty( SvStream& rStrm, const sal_uInt16 nPropertyId, const css::uno::Any& rAny, const TranslateMode eTranslateMode )
{
    bool bRet = false;
    if ( rAny.hasValue() )
    {
        switch( rAny.getValueType().getTypeClass() )
        {
            case css::uno::TypeClass_UNSIGNED_SHORT :
            case css::uno::TypeClass_SHORT :
            case css::uno::TypeClass_UNSIGNED_LONG :
            case css::uno::TypeClass_LONG :
            {
                sal_Int32 nVal = 0;
                if ( rAny >>= nVal )
                {
                    exportAnimPropertyuInt32( rStrm, nPropertyId, nVal );
                    bRet = true;
                }
            }
            break;

            case css::uno::TypeClass_DOUBLE :
            {
                double fVal = 0.0;
                if ( rAny >>= fVal )
                {
                    exportAnimPropertyFloat( rStrm, nPropertyId, fVal );
                    bRet = true;
                }
            }
            break;
            case css::uno::TypeClass_FLOAT :
            {
                float fVal = 0.0;
                if ( rAny >>= fVal )
                {
                    if ( eTranslateMode & TRANSLATE_NUMBER_TO_STRING )
                    {
                        OUString aNumber( OUString::number( fVal ) );
                        exportAnimPropertyString( rStrm, nPropertyId, aNumber, eTranslateMode );
                    }
                    else
                    {
                        exportAnimPropertyFloat( rStrm, nPropertyId, fVal );
                        bRet = true;
                    }
                }
            }
            break;
            case css::uno::TypeClass_STRING :
            {
                OUString aStr;
                if ( rAny >>= aStr )
                {
                    exportAnimPropertyString( rStrm, nPropertyId, aStr, eTranslateMode );
                    bRet = true;
                }
            }
            break;
            default:
                break;
        }
    }
    return bRet;
}
void AnimationExporter::exportAnimPropertyString( SvStream& rStrm, const sal_uInt16 nPropertyId, const OUString& rVal, const TranslateMode eTranslateMode )
{
    EscherExAtom aExAtom( rStrm, DFF_msofbtAnimAttributeValue, nPropertyId );
    rStrm.WriteUChar( DFF_ANIM_PROP_TYPE_UNISTRING );
    OUString aStr( rVal );
    if ( eTranslateMode != TRANSLATE_NONE )
        ImplTranslateAttribute( aStr, eTranslateMode );
    writeZString( rStrm, aStr );
}

void AnimationExporter::exportAnimPropertyFloat( SvStream& rStrm, const sal_uInt16 nPropertyId, const double& rVal )
{
    EscherExAtom aExAtom( rStrm, DFF_msofbtAnimAttributeValue, nPropertyId );
    float fFloat = static_cast<float>(rVal);
    rStrm.WriteUChar( DFF_ANIM_PROP_TYPE_FLOAT )
         .WriteFloat( fFloat );
}

void AnimationExporter::exportAnimPropertyuInt32( SvStream& rStrm, const sal_uInt16 nPropertyId, const sal_uInt32 nVal )
{
    EscherExAtom aExAtom( rStrm, DFF_msofbtAnimAttributeValue, nPropertyId );
    rStrm.WriteUChar( DFF_ANIM_PROP_TYPE_INT32 )
         .WriteUInt32( nVal );
}

void AnimationExporter::exportAnimPropertyByte( SvStream& rStrm, const sal_uInt16 nPropertyId, const sal_uInt8 nVal )
{
    EscherExAtom aExAtom( rStrm, DFF_msofbtAnimAttributeValue, nPropertyId );
    rStrm.WriteUChar( DFF_ANIM_PROP_TYPE_BYTE )
         .WriteUChar( nVal );
}

void AnimationExporter::writeZString( SvStream& rStrm, const OUString& rVal )
{
    sal_Int32 i;
    for ( i = 0; i < rVal.getLength(); i++ )
        rStrm.WriteUInt16( rVal[ i ] );
    rStrm.WriteUInt16( 0 );
}

void AnimationExporter::exportAnimAction( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    EscherExAtom aExAtom( rStrm, DFF_msofbtAnimAction );

    sal_Int32 const nConcurrent = 1;
    sal_Int32 const nNextAction = 1;
    sal_Int32 nEndSync = 0;
    sal_Int32 const nU4 = 0;
    sal_Int32 const nU5 = 3;

    sal_Int16 nAnimationEndSync = 0;
    if ( xNode->getEndSync() >>= nAnimationEndSync )
    {
        if ( nAnimationEndSync == AnimationEndSync::ALL )
            nEndSync = 1;
    }
    rStrm.WriteInt32( nConcurrent )
         .WriteInt32( nNextAction )
         .WriteInt32( nEndSync )
         .WriteInt32( nU4 )
         .WriteInt32( nU5 );

}

// nFlags Bit 6 = fixInteractiveSequenceTiming (for child)
// nFlags Bit 5 = fixInteractiveSequenceTiming (for root)
// nFlags Bit 4 = first node of main sequence -> begin event next has to be replaced to indefinite
void AnimationExporter::exportAnimEvent( SvStream& rStrm, const Reference< XAnimationNode >& xNode, const sal_Int32 nFlags )
{
    sal_uInt16 i;
    for ( i = 0; i < 4; i++ )
    {
        sal_Int32 nU1 = 0;
        sal_Int32 nTrigger = 0;
        sal_Int32 nU3 = 0;
        sal_Int32 nBegin = 0;

        bool bCreateEvent = false;
        Any aSource;

        switch( i )
        {
            case 0 :
            case 1 :
            {
                Any aAny;
                Event aEvent;
                css::animations::Timing eTiming;
                if ( i == 0 )
                {
                    if ( nFlags & 0x20 )
                    {
                        // taking the first child
                        Reference< XEnumerationAccess > xEA( xNode, UNO_QUERY_THROW );
                        Reference< XEnumeration > xE( xEA->createEnumeration(), css::uno::UNO_SET_THROW );
                        if ( xE->hasMoreElements() )
                        {
                            Reference< XAnimationNode > xClickNode( xE->nextElement(), UNO_QUERY );
                            aAny = xClickNode->getBegin();
                        }
                    }
                    else if ( nFlags & 0x40 )
                    {
                        // begin has to be replaced with void, so don't do anything
                    }
                    else
                    {
                        aAny = xNode->getBegin();
                        if ( nFlags & 0x10 )    // replace ON_NEXT with INDEFINITE
                        {
                            if ( ( aAny >>= aEvent ) && ( aEvent.Trigger == EventTrigger::ON_NEXT ) )
                            {
                                eTiming = Timing_INDEFINITE;
                                aAny <<= eTiming;
                            }
                        }
                    }
                }
                else
                    aAny = xNode->getEnd();

                double fTiming = 0.0;
                if ( aAny >>= aEvent )
                {
                    bCreateEvent = true;
                    switch( aEvent.Trigger )
                    {
                        case EventTrigger::NONE : nTrigger = 0; break;
                        case EventTrigger::ON_BEGIN : nTrigger = 1; break;
                        case EventTrigger::ON_END : nTrigger = 2; break;
                        case EventTrigger::BEGIN_EVENT : nTrigger = 3; break;
                        case EventTrigger::END_EVENT : nTrigger = 4; nU1 = 2; nU3 = mnCurrentGroup; break;
                        case EventTrigger::ON_CLICK : nTrigger = 5; break;
                        case EventTrigger::ON_DBL_CLICK : nTrigger = 6; break;
                        case EventTrigger::ON_MOUSE_ENTER : nTrigger = 7; break;
                        case EventTrigger::ON_MOUSE_LEAVE : nTrigger = 8; break;
                        case EventTrigger::ON_NEXT : nTrigger = 9; break;
                        case EventTrigger::ON_PREV : nTrigger = 10; break;
                        case EventTrigger::ON_STOP_AUDIO : nTrigger = 11; break;
                    }
                    if ( aEvent.Offset.hasValue() )
                    {
                        if ( aEvent.Offset >>= eTiming )
                        {
                            if ( eTiming == Timing_INDEFINITE )
                                nBegin = -1;
                        }
                        else if ( aEvent.Offset >>= fTiming )
                            nBegin = static_cast<sal_Int32>( fTiming * 1000.0 );
                    }
                    aSource = aEvent.Source;
                }
                else if ( aAny >>= eTiming )
                {
                    bCreateEvent = true;
                    if ( eTiming == Timing_INDEFINITE )
                        nBegin = -1;
                }
                else if ( aAny >>= fTiming )
                {
                    bCreateEvent = true;
                    nBegin = static_cast<sal_Int32>( fTiming * 1000.0 );
                }
            }
            break;

            case 2 :
            {
                if ( nFlags & ( 1 << i ) )
                {
                    bCreateEvent = true;
                    nU1 = 1;
                    nTrigger = 9;
                }
            }
            break;
            case 3 :
            {
                if ( nFlags & ( 1 << i ) )
                {
                    bCreateEvent = true;
                    nU1 = 1;
                    nTrigger = 10;
                }
            }
            break;
        }
        if ( bCreateEvent )
        {
            EscherExContainer aAnimEvent( rStrm, DFF_msofbtAnimEvent, i + 1 );
            {
                EscherExAtom aAnimTrigger( rStrm, DFF_msofbtAnimTrigger );
                rStrm.WriteInt32( nU1 )
                     .WriteInt32( nTrigger )
                     .WriteInt32( nU3 )
                     .WriteInt32( nBegin );
            }
            exportAnimateTargetElement( rStrm, aSource, ( nFlags & ( 1 << i ) ) != 0 );
        }
    }
}

Any AnimationExporter::convertAnimateValue( const Any& rSourceValue, const OUString& rAttributeName )
{
    OUString aDest;
    if ( rAttributeName == "X"
            || rAttributeName == "Y"
            || rAttributeName == "Width"
            || rAttributeName == "Height"
        )
    {
        OUString aStr;
        if ( rSourceValue >>= aStr )
        {
            ImplTranslateAttribute( aStr, TRANSLATE_MEASURE );
            aDest += aStr;
        }
    }
    else if ( rAttributeName == "Rotate"         // "r" or "style.rotation" ?
            || rAttributeName == "Opacity"
            || rAttributeName == "CharHeight"
            || rAttributeName == "SkewX"
        )
    {
        double fNumber = 0.0;
        if ( rSourceValue >>= fNumber )
            aDest += OUString::number( fNumber );
    }
    else if ( rAttributeName == "Color"
            || rAttributeName == "FillColor"     // "Fillcolor" or "FillColor" ?
            || rAttributeName == "LineColor"
            || rAttributeName == "CharColor"
        )
    {
        sal_Int32 nColor = 0;
        Sequence< double > aHSL( 3 );
        OUString aP( "," );
        if ( rSourceValue >>= aHSL )
        {
            aDest += "hsl("
                  +  OUString::number( static_cast<sal_Int32>( aHSL[ 0 ] / ( 360.0 / 255 ) ) )
                  +  aP
                  +  OUString::number( static_cast<sal_Int32>( aHSL[ 1 ] * 255.0 ) )
                  +  aP
                  +  OUString::number( static_cast<sal_Int32>( aHSL[ 2 ] * 255.0 ) )
                  +  ")";
        }
        else if ( rSourceValue >>= nColor )
        {
            aDest += "rgb("
                  +  OUString::number( static_cast<sal_Int8>(nColor) )
                  +  aP
                  +  OUString::number( static_cast<sal_Int8>( nColor >> 8 ) )
                  +  aP
                  +  OUString::number( static_cast<sal_Int8>( nColor >> 16 ) )
                  +  ")";
        }
    }
    else if ( rAttributeName == "FillStyle" )
    {
        css::drawing::FillStyle eFillStyle;
        if ( rSourceValue >>= eFillStyle )
        {
            if ( eFillStyle == css::drawing::FillStyle_NONE )
                aDest += "none";    // ?
            else
                aDest += "solid";
        }
    }
    else if (rAttributeName == "FillOn")
    {
        bool bFillOn;
        if ( rSourceValue >>= bFillOn )<--- Uninitialized variable: bFillOn
        {
            if ( bFillOn )<--- Uninitialized variable: bFillOn
                aDest += "true";
            else
                aDest += "false";
        }
    }
    else if ( rAttributeName == "LineStyle" )
    {
        css::drawing::LineStyle eLineStyle;
        if ( rSourceValue >>= eLineStyle )
        {
            if ( eLineStyle == css::drawing::LineStyle_NONE )
                aDest += "false";
            else
                aDest += "true";
        }
    }
    else if ( rAttributeName == "CharWeight" )
    {
        float fFontWeight = 0.0;
        if ( rSourceValue >>= fFontWeight )
        {
            if ( fFontWeight == css::awt::FontWeight::BOLD )
                aDest += "bold";
            else
                aDest += "normal";
        }
    }
    else if ( rAttributeName == "CharUnderline" )
    {
        sal_Int16 nFontUnderline = 0;
        if ( rSourceValue >>= nFontUnderline )
        {
            if ( nFontUnderline == css::awt::FontUnderline::NONE )
                aDest += "false";
            else
                aDest += "true";
        }
    }
    else if ( rAttributeName == "CharPosture" )
    {
        css::awt::FontSlant eFontSlant;
        if ( rSourceValue >>= eFontSlant )
        {
            if ( eFontSlant == css::awt::FontSlant_ITALIC )
                aDest += "italic";
            else
                aDest += "normal";  // ?
        }
    }
    else if ( rAttributeName == "Visibility" )
    {
        bool bVisible = true;<--- Assignment 'bVisible=true', assigned value is 1
        if ( rSourceValue >>= bVisible )
        {
            if ( bVisible )<--- Condition 'bVisible' is always true
                aDest += "visible";
            else
                aDest += "hidden";
        }
    }
    Any aRet;
    if ( !aDest.isEmpty() )
        aRet <<= aDest;
    else
        aRet = rSourceValue;
    return aRet;
}

void AnimationExporter::exportAnimateSet( SvStream& rStrm, const Reference< XAnimationNode >& xNode, int nAfterEffectType )
{
    Reference< XAnimateSet > xSet( xNode, UNO_QUERY );
    if( !xSet.is() )
        return;

    EscherExContainer aAnimateSet( rStrm, DFF_msofbtAnimateSet, 0 );
    {
        EscherExAtom aAnimateSetData( rStrm, DFF_msofbtAnimateSetData );
        sal_uInt32 const nId1 = 1;            // ??
        sal_uInt32 const nId2 = 1;            // ??
        rStrm.WriteUInt32( nId1 ).WriteUInt32( nId2 );
    }
    Any aConvertedValue( convertAnimateValue( xSet->getTo(), xSet->getAttributeName() ) );
    if ( aConvertedValue.hasValue() )
        exportAnimProperty( rStrm, 1, aConvertedValue, TRANSLATE_NONE );
    exportAnimateTarget( rStrm, xNode, 0, nAfterEffectType );
}

sal_uInt32 AnimationExporter::GetValueTypeForAttributeName( const OUString& rAttributeName )
{
    sal_uInt32 nValueType = 0;

    struct Entry
    {
        const char* pName;
        sal_uInt8 nType;
    };
    static const Entry lcl_attributeMap[] =
    {
        { "charcolor", 2 },
        { "charfontname", 0 },
        { "charheight", 1 },
        { "charposture", 0 },
        // TODO(Q1): This should prolly be changed in PPT import
        // { "charrotation", ATTRIBUTE_CHAR_ROTATION },
        { "charrotation", 1 },
        { "charunderline", 0 },
        { "charweight", 0 },
        { "color", 2 },
        { "dimcolor", 2 },
        { "fillcolor", 2 },
        { "fillstyle", 0 },
        { "height", 1 },
        { "linecolor", 2 },
        { "linestyle", 0 },
        { "opacity", 0 },
        { "rotate", 1 },
        { "skewx", 1 },
        { "skewy", 1 },
        { "visibility", 1 },
        { "width", 1 },
        { "x", 1 },
        { "y", 1 },
        { nullptr, 0 }
    };
    const Entry* pPtr = &lcl_attributeMap[ 0 ];
    while( pPtr->pName )
    {
        if ( rAttributeName.equalsIgnoreAsciiCaseAscii( pPtr->pName ) )
        {
            nValueType = pPtr->nType;
            break;
        }
        pPtr++;
    }
    DBG_ASSERT( pPtr->pName, "GetValueTypeForAttributeName, unknown property value!" );
    return nValueType;
}

void AnimationExporter::exportAnimate( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    Reference< XAnimate > xAnimate( xNode, UNO_QUERY );
    if ( !xAnimate.is() )
        return;

    Any aBy  ( xAnimate->getBy() );
    Any aFrom( xAnimate->getFrom() );
    Any aTo  ( xAnimate->getTo() );

    EscherExContainer aContainer( rStrm, DFF_msofbtAnimate, 0 );
    {
        EscherExAtom    aAnimateData( rStrm, DFF_msofbtAnimateData );
        sal_uInt32 nBits = 0x38;
        sal_Int16 nTmp = xAnimate->getCalcMode();
        sal_uInt32 nCalcMode = /* (nTmp == AnimationCalcMode::FORMULA) ? 2 : */ (nTmp == AnimationCalcMode::LINEAR) ? 1 : 0;
        sal_uInt32 nValueType = GetValueTypeForAttributeName( xAnimate->getAttributeName() );

        if ( aBy.hasValue() )
            nBits |= 1;
        if ( aFrom.hasValue() )
            nBits |= 2;
        if ( aTo.hasValue() )
            nBits |= 4;

        rStrm.WriteUInt32( nCalcMode )
             .WriteUInt32( nBits )
             .WriteUInt32( nValueType );
    }
    if ( aBy.hasValue() )
        exportAnimProperty( rStrm, 1, aBy, TRANSLATE_NUMBER_TO_STRING | TRANSLATE_MEASURE );
    if ( aFrom.hasValue() )
        exportAnimProperty( rStrm, 2, aFrom, TRANSLATE_NUMBER_TO_STRING | TRANSLATE_MEASURE );
    if ( aTo.hasValue() )
        exportAnimProperty( rStrm, 3, aTo, TRANSLATE_NUMBER_TO_STRING | TRANSLATE_MEASURE );

    exportAnimateKeyPoints( rStrm, xAnimate );
    exportAnimateTarget( rStrm, xNode );
}

void AnimationExporter::exportAnimateTarget( SvStream& rStrm, const Reference< XAnimationNode >& xNode, const sal_uInt32 nForceAttributeNames, int nAfterEffectType )
{
    EscherExContainer aAnimateTarget( rStrm, DFF_msofbtAnimateTarget, 0 );
    Reference< XAnimate > xAnimate( xNode, UNO_QUERY );
    if ( !xAnimate.is() )
        return;

    {
        EscherExAtom aAnimateTargetSettings( rStrm, DFF_msofbtAnimateTargetSettings, 0 );
        // nBits %0001: additive, %0010: accumulate, %0100: attributeName, %1000: transformtype
        // nAdditive 0 = base, 1 = sum, 2 = replace, 3 = multiply, 4 = none
        // nAccumulate 0 = none, 1 = always
        // nTransformType 0: "property" else "image"
        sal_uInt32 nBits = 0;
        sal_uInt32 nAdditive = 0;
        sal_uInt32 nAccumulate = 0;
        sal_uInt32 const nTransformType = 0;
        if ( xAnimate.is() )
        {
            if ( !xAnimate->getAttributeName().isEmpty() )
                nBits |= 4;     // what is attributeName ?, maybe this is set if a DFF_msofbtAnimateAttributeNames is written
            sal_Int16 nAdditiveMode = xAnimate->getAdditive();
            if ( nAdditiveMode != AnimationAdditiveMode::BASE )
            {
                nBits |= 1;
                switch( nAdditiveMode )
                {
                    case AnimationAdditiveMode::SUM : nAdditive = 1; break;
                    case AnimationAdditiveMode::REPLACE : nAdditive = 2; break;
                    case AnimationAdditiveMode::MULTIPLY : nAdditive = 3; break;
                    case AnimationAdditiveMode::NONE : nAdditive = 4; break;
                }
            }
            if ( xAnimate->getAccumulate() )
            {
                nBits  |= 2;
                nAccumulate = 1;
            }
        }
        rStrm.WriteUInt32( nBits )
           .WriteUInt32( nAdditive )
           .WriteUInt32( nAccumulate )
           .WriteUInt32( nTransformType );
    }
    if ( !xAnimate->getAttributeName().isEmpty() || nForceAttributeNames )
    {
        EscherExContainer aAnimateAttributeNames( rStrm, DFF_msofbtAnimateAttributeNames, 1 );
        OUString aAttributeName( xAnimate->getAttributeName() );
        if ( nForceAttributeNames )
        {
            if( nForceAttributeNames == 1 )
            {
                aAttributeName = "r";
            }
        }
        sal_Int32 nIndex = 0;
        do
        {
            OUString aToken( aAttributeName.getToken( 0, ';', nIndex ) );
            exportAnimPropertyString( rStrm, 0, aToken, TRANSLATE_ATTRIBUTE );
        }
        while ( nIndex >= 0 );
    }

    if( nAfterEffectType != AFTEREFFECT_NONE )
    {
        EscherExContainer aAnimPropertySet( rStrm, DFF_msofbtAnimPropertySet );
        exportAnimPropertyuInt32( rStrm, 6, 1 );
        if( nAfterEffectType == AFTEREFFECT_COLOR )
        {
            exportAnimPropertyuInt32( rStrm, 4, 0 );
            exportAnimPropertyuInt32( rStrm, 5, 0 );
        }
    }
    exportAnimateTargetElement( rStrm, aTarget.hasValue() ? aTarget : xAnimate->getTarget(), false );
}

Reference< XShape > AnimationExporter::getTargetElementShape( const Any& rAny, sal_Int32& rBegin, sal_Int32& rEnd, bool& rParagraphTarget )
{
    Reference< XShape > xShape;
    rAny >>= xShape;

    rParagraphTarget = false;

    if( !xShape.is() )
    {
    ParagraphTarget aParaTarget;
    if( rAny >>= aParaTarget )
        xShape = aParaTarget.Shape;
    if ( xShape.is() )
    {
        // now calculating the character range for the paragraph
        sal_Int16 nParagraph = aParaTarget.Paragraph;
        Reference< XSimpleText > xText( xShape, UNO_QUERY );
        if ( xText.is() )
        {
        rParagraphTarget = true;
        Reference< XEnumerationAccess > xTextParagraphEnumerationAccess( xText, UNO_QUERY );
        if ( xTextParagraphEnumerationAccess.is() )
        {
            Reference< XEnumeration > xTextParagraphEnumeration( xTextParagraphEnumerationAccess->createEnumeration() );
            if ( xTextParagraphEnumeration.is() )
            {
            sal_Int16 nCurrentParagraph;
            rBegin = rEnd = nCurrentParagraph = 0;
            while ( xTextParagraphEnumeration->hasMoreElements() )
            {
                Reference< XTextRange > xTextRange( xTextParagraphEnumeration->nextElement(), UNO_QUERY );
                if ( xTextRange.is() )
                {
                OUString aParaText( xTextRange->getString() );
                sal_Int32 nLength = aParaText.getLength() + 1;
                rEnd += nLength;
                if ( nCurrentParagraph == nParagraph )
                    break;
                nCurrentParagraph++;
                rBegin += nLength;
                }
            }
            }
        }
        }
    }
    }

    return xShape;
}

void AnimationExporter::exportAnimateTargetElement( SvStream& rStrm, const Any& rAny, const bool bCreate2b01Atom )
{
    sal_uInt32 nRefMode = 0;    // nRefMode == 2 -> Paragraph
    sal_Int32 begin = -1;
    sal_Int32 end = -1;
    bool bParagraphTarget;

    Reference< XShape > xShape = getTargetElementShape(rAny, begin, end, bParagraphTarget);

    if( bParagraphTarget )
        nRefMode = 2;

    if ( !(xShape.is() || bCreate2b01Atom) )
        return;

    EscherExContainer aAnimateTargetElement( rStrm, DFF_msofbtAnimateTargetElement );
    if ( xShape.is() )
    {
        EscherExAtom aAnimReference( rStrm, DFF_msofbtAnimReference );

        sal_uInt32 const nRefType = 1;    // TODO: nRefType == 2 -> Sound;
        sal_uInt32 nRefId = mrSolverContainer.GetShapeId( xShape );

        rStrm.WriteUInt32( nRefMode )
             .WriteUInt32( nRefType )
             .WriteUInt32( nRefId )
             .WriteInt32( begin )
             .WriteInt32( end );
    }
    if ( bCreate2b01Atom )
    {
        EscherExAtom a2b01Atom( rStrm, 0x2b01 );
        rStrm.WriteUInt32( 1 );     // ?
    }
}

void AnimationExporter::exportAnimateKeyPoints( SvStream& rStrm, const Reference< XAnimate >& xAnimate )
{
    Sequence< double > aKeyTimes( xAnimate->getKeyTimes() );
    Sequence< Any > aValues( xAnimate->getValues() );
    OUString aFormula( xAnimate->getFormula() );
    if ( !aKeyTimes.hasElements() )
        return;

    EscherExContainer aAnimKeyPoints( rStrm, DFF_msofbtAnimKeyPoints );
    sal_Int32 i;
    for ( i = 0; i < aKeyTimes.getLength(); i++ )
    {
        {
            EscherExAtom aAnimKeyTime( rStrm, DFF_msofbtAnimKeyTime );
            sal_Int32 nKeyTime = static_cast<sal_Int32>( aKeyTimes[ i ] * 1000.0 );
            rStrm.WriteInt32( nKeyTime );
        }
        Any aAny[ 2 ];
        if ( aValues[ i ].hasValue() )
        {
            ValuePair aPair;
            if ( aValues[ i ] >>= aPair )
            {
                aAny[ 0 ] = convertAnimateValue( aPair.First, xAnimate->getAttributeName() );
                aAny[ 1 ] = convertAnimateValue( aPair.Second, xAnimate->getAttributeName() );
            }
            else
            {
                aAny[ 0 ] = convertAnimateValue( aValues[ i ], xAnimate->getAttributeName() );
            }
            if ( !i && !aFormula.isEmpty() )
            {
                ImplTranslateAttribute( aFormula, TRANSLATE_MEASURE );
                aAny[ 1 ] <<= aFormula;
            }
            exportAnimProperty( rStrm, 0, aAny[ 0 ], TRANSLATE_NONE );
            exportAnimProperty( rStrm, 1, aAny[ 1 ], TRANSLATE_NONE );
        }
    }
}

void AnimationExporter::exportAnimValue( SvStream& rStrm, const Reference< XAnimationNode >& xNode, const bool bExportAlways )
{
    Any aAny;
    // repeat count (0)
    double fRepeat = 0.0;
    float fRepeatCount = 0.0;
    css::animations::Timing eTiming;
    aAny = xNode->getRepeatCount();
    if ( aAny >>= eTiming )
    {
        if ( eTiming == Timing_INDEFINITE )
            fRepeatCount = (float(3.40282346638528860e+38));
    }
    else if ( aAny >>= fRepeat )<--- Variable 'aAny' is assigned a value that is never used.
        fRepeatCount = static_cast<float>(fRepeat);
    if ( fRepeatCount != 0.0 )
    {
        EscherExAtom aExAtom( rStrm, DFF_msofbtAnimValue );
        sal_uInt32 const nType = 0;
        rStrm.WriteUInt32( nType )
             .WriteFloat( fRepeatCount );
    }
    // accelerate (3)
    float fAccelerate = static_cast<float>(xNode->getAcceleration());
    if ( bExportAlways || ( fAccelerate != 0.0 ) )
    {
        EscherExAtom aExAtom( rStrm, DFF_msofbtAnimValue );
        sal_uInt32 const nType = 3;
        rStrm.WriteUInt32( nType )
             .WriteFloat( fAccelerate );
    }

    // decelerate (4)
    float fDecelerate = static_cast<float>(xNode->getDecelerate());
    if ( bExportAlways || ( fDecelerate != 0.0 ) )
    {
        EscherExAtom aExAtom( rStrm, DFF_msofbtAnimValue );
        sal_uInt32 const nType = 4;
        rStrm.WriteUInt32( nType )
             .WriteFloat( fDecelerate );
    }

    // autoreverse (5)
    bool bAutoReverse = xNode->getAutoReverse();
    if ( bExportAlways || bAutoReverse )
    {
        EscherExAtom aExAtom( rStrm, DFF_msofbtAnimValue );
        sal_uInt32 const nType = 5;
        sal_uInt32 nVal  = bAutoReverse ? 1 : 0;
        rStrm.WriteUInt32( nType )
             .WriteUInt32( nVal );
    }
}

void AnimationExporter::exportTransitionFilter( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    Reference< XTransitionFilter > xFilter( xNode, UNO_QUERY );
    if ( !xFilter.is() )
        return;

    EscherExContainer aAnimateFilter( rStrm, DFF_msofbtAnimateFilter );
    {
        EscherExAtom aAnimateFilterData( rStrm, DFF_msofbtAnimateFilterData );
        sal_uInt32 const nBits = 3;       // bit 0 -> use AnimAttributeValue
                                          // bit 1 -> use nTransition

        sal_uInt32 nTransition = xFilter->getMode() ? 0 : 1;
        rStrm.WriteUInt32( nBits )
             .WriteUInt32( nTransition );
    }
    const char* pFilter = FindTransitionName( xFilter->getTransition(), xFilter->getSubtype(), xFilter->getDirection() );
    if ( pFilter )
    {
        const OUString aStr( OUString::createFromAscii( pFilter ) );
        exportAnimPropertyString( rStrm, 1, aStr, TRANSLATE_NONE );
    }
    exportAnimateTarget( rStrm, xNode );
}

void AnimationExporter::exportAnimateMotion( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    Reference< XAnimateMotion > xMotion( xNode, UNO_QUERY );
    if ( !xMotion.is() )
        return;

    EscherExContainer aAnimateMotion( rStrm, DFF_msofbtAnimateMotion );
    {
        {   //SJ: Ignored from import filter
            EscherExAtom aAnimateMotionData( rStrm, DFF_msofbtAnimateMotionData );
            sal_uInt32 const nBits = 0x98;
            sal_uInt32 const nOrigin = 0x2;
            float const fByX = 100.0; // nBits&1
            float const fByY = 100.0; // nBits&1
            float const fFromX = 0.0; // nBits&2
            float const fFromY = 0.0; // nBits&2
            float const fToX = 100.0; // nBits&4
            float const fToY = 100.0; // nBits&4
            rStrm.WriteUInt32( nBits ).WriteFloat( fByX ).WriteFloat( fByY ).WriteFloat( fFromX ).WriteFloat( fFromY ).WriteFloat( fToX ).WriteFloat( fToY ).WriteUInt32( nOrigin );
        }

        OUString aStr;
        if ( xMotion->getPath() >>= aStr )
        {
            if ( !aStr.isEmpty() )
                exportAnimPropertyString( rStrm, 1, aStr, TRANSLATE_NONE );
        }
        exportAnimateTarget( rStrm, xNode );
    }
}

void AnimationExporter::exportAnimateTransform( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    Reference< XAnimateTransform > xTransform( xNode, UNO_QUERY );
    if ( !xTransform.is() )
        return;

    if ( xTransform->getTransformType() ==  AnimationTransformType::SCALE )
    {
        EscherExContainer aAnimateScale( rStrm, DFF_msofbtAnimateScale );
        {
            EscherExAtom aAnimateScaleData( rStrm, DFF_msofbtAnimateScaleData );
            sal_uInt32 nBits = 0;
            sal_uInt32 const nZoomContents = 1;
            float fByX = 100.0;
            float fByY = 100.0;
            float fFromX = 0.0;
            float fFromY = 0.0;
            float fToX = 100.0;
            float fToY = 100.0;

            double fX = 0.0, fY = 0.0;
            ValuePair aPair;
            if ( xTransform->getBy() >>= aPair )
            {
                if ( ( aPair.First >>= fX ) && ( aPair.Second >>= fY ) )
                {
                    nBits |= 1;
                    fByX = static_cast<float>( fX * 100 );
                    fByY = static_cast<float>( fY * 100 );
                }
            }
            if ( xTransform->getFrom() >>= aPair )
            {
                if ( ( aPair.First >>= fX ) && ( aPair.Second >>= fY ) )
                {
                    nBits |= 2;
                    fFromX = static_cast<float>( fX * 100 );
                    fFromY = static_cast<float>( fY * 100 );
                }
            }
            if( xTransform->getTo() >>= aPair )
            {
                if ( ( aPair.First >>= fX ) && ( aPair.Second >>= fY ) )
                {
                    nBits |= 4;
                    fToX = static_cast<float>( fX * 100 );
                    fToY = static_cast<float>( fY * 100 );
                }
            }

            // TODO: ZoomContents:
            //if( nBits & 8 )
            //( fprintf( mpFile, " zoomContents=\"%s\"", nZoomContents ? "true" : "false" );

            rStrm.WriteUInt32( nBits ).WriteFloat( fByX ).WriteFloat( fByY ).WriteFloat( fFromX ).WriteFloat( fFromY ).WriteFloat( fToX ).WriteFloat( fToY ).WriteUInt32( nZoomContents );
        }
        exportAnimateTarget( rStrm, xNode );
    }
    else if ( xTransform->getTransformType() ==  AnimationTransformType::ROTATE )
    {
        EscherExContainer aAnimateRotation( rStrm, DFF_msofbtAnimateRotation );
        {
            EscherExAtom aAnimateRotationData( rStrm, DFF_msofbtAnimateRotationData );
            sal_uInt32 nBits = 0;
            sal_uInt32 const nU1 = 0;
            float fBy = 360.0;
            float fFrom = 0.0;
            float fTo = 360.0;

            double fVal = 0.0;
            if ( xTransform->getBy() >>= fVal )
            {
                nBits |= 1;
                fBy = static_cast<float>(fVal);
            }
            if ( xTransform->getFrom() >>= fVal )
            {
                nBits |= 2;
                fFrom = static_cast<float>(fVal);
            }
            if ( xTransform->getTo() >>= fVal )
            {
                nBits |= 4;
                fTo = static_cast<float>(fVal);
            }
            rStrm.WriteUInt32( nBits ).WriteFloat( fBy ).WriteFloat( fFrom ).WriteFloat( fTo ).WriteUInt32( nU1 );
        }
        exportAnimateTarget( rStrm, xNode, 1 );
    }
}

bool AnimationExporter::getColorAny( const Any& rAny, const sal_Int16 nColorSpace, sal_Int32& rMode, sal_Int32& rA, sal_Int32& rB, sal_Int32& rC )
{
    bool bIsColor = true;

    rMode = 0;
    if ( nColorSpace == AnimationColorSpace::HSL )
        rMode = 1;

    sal_Int32 nColor = 0;
    Sequence< double > aHSL( 3 );
    if ( rAny >>= nColor )      // RGB color
    {
        rA = static_cast<sal_uInt8>( nColor >> 16 );
        rB = static_cast<sal_uInt8>( nColor >> 8 );
        rC = static_cast<sal_uInt8>(nColor);
    }
    else if ( rAny >>= aHSL )   // HSL
    {
        rA = static_cast<sal_Int32>( aHSL[ 0 ] * 255.0 / 360.0 );
        rB = static_cast<sal_Int32>( aHSL[ 1 ] * 255.0 );
        rC = static_cast<sal_Int32>( aHSL[ 2 ] * 255.0 );
    }
    else
        bIsColor = false;
    return bIsColor;
}

void AnimationExporter::exportAnimateColor( SvStream& rStrm, const Reference< XAnimationNode >& xNode, int nAfterEffectType )
{
    Reference< XAnimateColor > xColor( xNode, UNO_QUERY );
    if ( !xColor.is() )
        return;

    EscherExContainer aAnimateColor( rStrm, DFF_msofbtAnimateColor );
    {
        EscherExAtom aAnimateColorData( rStrm, DFF_msofbtAnimateColorData );
        sal_uInt32 nBits = 8;

        sal_Int32 nByMode, nByA, nByB, nByC;
        nByMode = nByA = nByB = nByC = 0;

        sal_Int32 nFromMode, nFromA, nFromB, nFromC;
        nFromMode = nFromA = nFromB = nFromC = 0;

        sal_Int32 nToMode, nToA, nToB, nToC;
        nToMode = nToA = nToB = nToC = 0;

        sal_Int16 nColorSpace = xColor->getColorInterpolation();

        Any aAny( xColor->getBy() );
        if ( aAny.hasValue() )
        {
            if ( getColorAny( aAny, nColorSpace, nByMode, nByA, nByB, nByC ) )
                nBits |= 0x11;
        }
        aAny = xColor->getFrom();
        if ( aAny.hasValue() )
        {
            if ( getColorAny( aAny, nColorSpace, nFromMode, nFromA, nFromB, nFromC ) )
                nBits |= 0x12;
        }
        aAny = xColor->getTo();
        if ( aAny.hasValue() )
        {
            if ( getColorAny( aAny, nColorSpace, nToMode, nToA, nToB, nToC ) )
                nBits |= 0x14;
        }
        rStrm  .WriteUInt32( nBits )
               .WriteInt32( nByMode ).WriteInt32( nByA ).WriteInt32( nByB ).WriteInt32( nByC )
               .WriteInt32( nFromMode ).WriteInt32( nFromA ).WriteInt32( nFromB ).WriteInt32( nFromC )
               .WriteInt32( nToMode ).WriteInt32( nToA ).WriteInt32( nToB ).WriteInt32( nToC );
    }
    exportAnimateTarget( rStrm, xNode, 0, nAfterEffectType );
}

void AnimationExporter::exportIterate( SvStream& rStrm, const Reference< XAnimationNode >& xNode )
{
    Reference< XIterateContainer > xIterate( xNode, UNO_QUERY );
    if ( !xIterate.is() )
        return;

    EscherExAtom aAnimIteration( rStrm, DFF_msofbtAnimIteration );

    float       fInterval = 10.0;
    sal_Int32   nTextUnitEffect = 0;
    sal_Int32 const nU1 = 1;
    sal_Int32 const nU2 = 1;
    sal_Int32 const nU3 = 0xe;

    sal_Int16 nIterateType = xIterate->getIterateType();
    switch( nIterateType )
    {
        case TextAnimationType::BY_WORD : nTextUnitEffect = 1; break;
        case TextAnimationType::BY_LETTER : nTextUnitEffect = 2; break;
    }

    fInterval = static_cast<float>(xIterate->getIterateInterval());

    // convert interval from absolute to percentage
    double fDuration = 0.0;

    Reference< XEnumerationAccess > xEnumerationAccess( xNode, UNO_QUERY );
    if( xEnumerationAccess.is() )
    {
        Reference< XEnumeration > xEnumeration = xEnumerationAccess->createEnumeration();
        if( xEnumeration.is() )
        {
            while( xEnumeration->hasMoreElements() )
            {
                Reference< XAnimate > xChildNode( xEnumeration->nextElement(), UNO_QUERY );
                if( xChildNode.is() )
                {
                    double fChildBegin = 0.0;
                    double fChildDuration = 0.0;
                    xChildNode->getBegin() >>= fChildBegin;
                    xChildNode->getDuration() >>= fChildDuration;

                    fChildDuration += fChildBegin;
                    if( fChildDuration > fDuration )
                        fDuration = fChildDuration;
                }
            }
        }
    }

    if( fDuration )
        fInterval = static_cast<float>(100.0 * fInterval / fDuration);

    rStrm.WriteFloat( fInterval ).WriteInt32( nTextUnitEffect ).WriteInt32( nU1 ).WriteInt32( nU2 ).WriteInt32( nU3 );
    aTarget = xIterate->getTarget();
}

} // namespace ppt;

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */