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
/* -*- 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 <sal/config.h>

#include <memory>
#include <utility>

#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/presentation/ClickAction.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/PropertyState.hpp>
#include <rtl/ustrbuf.hxx>
#include <svl/itemprop.hxx>
#include <svl/style.hxx>
#include <svx/svdpool.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/app.hxx>
#include <svtools/unoimap.hxx>
#include <svtools/unoevent.hxx>
#include <sfx2/bindings.hxx>
#include <sfx2/event.hxx>
#include <sfx2/sfxsids.hrc>
#include <comphelper/extract.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <svx/unoshape.hxx>
#include <svx/svdotext.hxx>
#include <svx/unoapi.hxx>
#include <svx/svdopath.hxx>
#include <svx/svdoole2.hxx>
#include <svx/svdograf.hxx>
#include <svx/ImageMapInfo.hxx>
#include <filter/msfilter/msdffimp.hxx>
#include <svl/instrm.hxx>
#include <editeng/outlobj.hxx>
#include <Outliner.hxx>
#include <comphelper/sequence.hxx>
#include <svx/svdogrp.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <vcl/svapp.hxx>
#include <tools/debug.hxx>

#include <anminfo.hxx>
#include "unoobj.hxx"
#include <unoprnms.hxx>
#include <unomodel.hxx>
#include <drawdoc.hxx>
#include <sdmod.hxx>
#include <sdpage.hxx>
#include <ViewShell.hxx>
#include <unopage.hxx>
#include <DrawDocShell.hxx>
#include <EffectMigration.hxx>

using namespace ::sd;
using namespace ::com::sun::star;
using namespace ::com::sun::star::presentation;
using namespace ::com::sun::star::animations;

using ::com::sun::star::uno::Any;
using ::com::sun::star::drawing::XShape;

#define WID_EFFECT          1
#define WID_SPEED           2
#define WID_TEXTEFFECT      3
#define WID_BOOKMARK        4
#define WID_CLICKACTION     5
#define WID_PLAYFULL        6
#define WID_SOUNDFILE       7
#define WID_SOUNDON         8
#define WID_BLUESCREEN      9
#define WID_VERB            10
#define WID_DIMCOLOR        11
#define WID_DIMHIDE         12
#define WID_DIMPREV         13
#define WID_PRESORDER       14
#define WID_STYLE           15
#define WID_ANIMPATH        16
#define WID_IMAGEMAP        17
#define WID_ISANIMATION     18
#define WID_THAT_NEED_ANIMINFO 19

#define WID_ISEMPTYPRESOBJ  20
#define WID_ISPRESOBJ       21
#define WID_MASTERDEPEND    22

#define WID_NAVORDER        23
#define WID_PLACEHOLDERTEXT 24
#define WID_LEGACYFRAGMENT  25

        #define IMPRESS_MAP_ENTRIES \
        { OUString(UNO_NAME_OBJ_LEGACYFRAGMENT),WID_LEGACYFRAGMENT,  cppu::UnoType<drawing::XShape>::get(),                 0, 0},\
        { OUString(UNO_NAME_OBJ_ANIMATIONPATH), WID_ANIMPATH,        cppu::UnoType<drawing::XShape>::get(),                 0, 0},\
        { OUString(UNO_NAME_OBJ_BOOKMARK),      WID_BOOKMARK,        cppu::UnoType<OUString>::get(),                        0, 0},\
        { OUString(UNO_NAME_OBJ_DIMCOLOR),      WID_DIMCOLOR,        cppu::UnoType<sal_Int32>::get(),                       0, 0},\
        { OUString(UNO_NAME_OBJ_DIMHIDE),       WID_DIMHIDE,         cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString(UNO_NAME_OBJ_DIMPREV),       WID_DIMPREV,         cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString(UNO_NAME_OBJ_EFFECT),        WID_EFFECT,          cppu::UnoType<presentation::AnimationEffect>::get(),   0, 0},\
        { OUString(UNO_NAME_OBJ_ISEMPTYPRESOBJ),WID_ISEMPTYPRESOBJ,  cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString(UNO_NAME_OBJ_ISPRESOBJ),     WID_ISPRESOBJ,       cppu::UnoType<bool>::get(),                            css::beans::PropertyAttribute::READONLY, 0},\
        { OUString(UNO_NAME_OBJ_MASTERDEPENDENT),WID_MASTERDEPEND,   cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString(UNO_NAME_OBJ_CLICKACTION),   WID_CLICKACTION,     cppu::UnoType<presentation::ClickAction>::get(),       0, 0},\
        { OUString(UNO_NAME_OBJ_PLAYFULL),      WID_PLAYFULL,        cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString(UNO_NAME_OBJ_PRESORDER),     WID_PRESORDER,       cppu::UnoType<sal_Int32>::get(),                       0, 0},\
        { OUString(UNO_NAME_OBJ_STYLE),         WID_STYLE,           cppu::UnoType<style::XStyle>::get(),                   css::beans::PropertyAttribute::MAYBEVOID, 0},\
        { OUString(UNO_NAME_OBJ_SOUNDFILE),     WID_SOUNDFILE,       cppu::UnoType<OUString>::get(),                        0, 0},\
        { OUString(UNO_NAME_OBJ_SOUNDON),       WID_SOUNDON,         cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString(UNO_NAME_OBJ_SPEED),         WID_SPEED,           cppu::UnoType<presentation::AnimationSpeed>::get(),    0, 0},\
        { OUString(UNO_NAME_OBJ_TEXTEFFECT),    WID_TEXTEFFECT,      cppu::UnoType<presentation::AnimationEffect>::get(),   0, 0},\
        { OUString(UNO_NAME_OBJ_BLUESCREEN),    WID_BLUESCREEN,      cppu::UnoType<sal_Int32>::get(),                       0, 0},\
        { OUString(UNO_NAME_OBJ_VERB),          WID_VERB,            cppu::UnoType<sal_Int32>::get(),                       0, 0},\
        { OUString("IsAnimation"),              WID_ISANIMATION,     cppu::UnoType<bool>::get(),                            0, 0},\
        { OUString("NavigationOrder"),          WID_NAVORDER,        cppu::UnoType<sal_Int32>::get(),                       0, 0},\
        { OUString("PlaceholderText"),          WID_PLACEHOLDERTEXT, cppu::UnoType<OUString>::get(),                        0, 0},\
        { OUString(), 0, css::uno::Type(), 0, 0 }

    static const SfxItemPropertyMapEntry* lcl_GetImpress_SdXShapePropertyGraphicMap_Impl()
    {

        static const SfxItemPropertyMapEntry aImpress_SdXShapePropertyGraphicMap_Impl[] =
        {
            { OUString("ImageMap"),             WID_IMAGEMAP,        cppu::UnoType<container::XIndexContainer>::get(),    0, 0 },
            IMPRESS_MAP_ENTRIES
        };
        return aImpress_SdXShapePropertyGraphicMap_Impl;
    }

    static const SfxItemPropertyMapEntry* lcl_GetImpress_SdXShapePropertySimpleMap_Impl()
    {

        static const SfxItemPropertyMapEntry aImpress_SdXShapePropertySimpleMap_Impl[] =
        {
            IMPRESS_MAP_ENTRIES
        };
        return aImpress_SdXShapePropertySimpleMap_Impl;
    }

    #define DRAW_MAP_ENTRIES\
        { OUString(UNO_NAME_OBJ_BOOKMARK),      WID_BOOKMARK,       cppu::UnoType<OUString>::get(),                 0, 0},\
        { OUString(UNO_NAME_OBJ_CLICKACTION),   WID_CLICKACTION,    cppu::UnoType<presentation::ClickAction>::get(),0, 0},\
        { OUString(UNO_NAME_OBJ_STYLE),         WID_STYLE,          cppu::UnoType<style::XStyle>::get(),            css::beans::PropertyAttribute::MAYBEVOID, 0},\
        { OUString("NavigationOrder"),          WID_NAVORDER,       cppu::UnoType<sal_Int32>::get(),                0, 0},\
        { OUString(), 0, css::uno::Type(), 0, 0 }

    static const SfxItemPropertyMapEntry* lcl_GetDraw_SdXShapePropertySimpleMap_Impl()
    {
        static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyMap_Impl[] =
        {
            DRAW_MAP_ENTRIES
        };
        return aDraw_SdXShapePropertyMap_Impl;
    }
    static const SfxItemPropertyMapEntry* lcl_GetDraw_SdXShapePropertyGraphicMap_Impl()
    {
        static const SfxItemPropertyMapEntry aDraw_SdXShapePropertyGraphicMap_Impl[] =
        {
            { OUString("ImageMap"),             WID_IMAGEMAP,        cppu::UnoType<container::XIndexContainer>::get(),    0, 0 },
            DRAW_MAP_ENTRIES
        };
        return aDraw_SdXShapePropertyGraphicMap_Impl;
    }
    static const SfxItemPropertyMapEntry* lcl_ImplGetShapePropertyMap( bool bImpress, bool bGraphicObj )
    {
        const SfxItemPropertyMapEntry* pRet = nullptr;
        if( bImpress )
        {
            if( bGraphicObj )
                pRet = lcl_GetImpress_SdXShapePropertyGraphicMap_Impl();
            else
                pRet = lcl_GetImpress_SdXShapePropertySimpleMap_Impl();
        }
        else
        {
            if( bGraphicObj )
                pRet = lcl_GetDraw_SdXShapePropertyGraphicMap_Impl();
            else
                pRet = lcl_GetDraw_SdXShapePropertySimpleMap_Impl();
        }
        return pRet;

    }
    static const SvxItemPropertySet* lcl_ImplGetShapePropertySet( bool bImpress, bool bGraphicObj )
    {
        const SvxItemPropertySet* pRet = nullptr;
        if( bImpress )
        {
            if( bGraphicObj )
            {
                static SvxItemPropertySet aImpress_SdXShapePropertyGraphicSet_Impl( lcl_GetImpress_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
                pRet = &aImpress_SdXShapePropertyGraphicSet_Impl;
            }
            else
            {
                static SvxItemPropertySet aImpress_SdXShapePropertySet_Impl(lcl_GetImpress_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
                pRet = &aImpress_SdXShapePropertySet_Impl;
            }
        }
        else
        {
            if( bGraphicObj )
            {
                static SvxItemPropertySet aDraw_SdXShapePropertyGraphicSet_Impl(lcl_GetDraw_SdXShapePropertyGraphicMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
                pRet = &aDraw_SdXShapePropertyGraphicSet_Impl;
            }
            else
            {
                static SvxItemPropertySet aDraw_SdXShapePropertySet_Impl( lcl_GetDraw_SdXShapePropertySimpleMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool());
                pRet = &aDraw_SdXShapePropertySet_Impl;
            }
        }
        return pRet;
    }
    static const SfxItemPropertyMapEntry* lcl_GetEmpty_SdXShapePropertyMap_Impl()
    {
        static const SfxItemPropertyMapEntry aEmpty_SdXShapePropertyMap_Impl[] =
        {
            { OUString(), 0, css::uno::Type(), 0, 0 }
        };
        return aEmpty_SdXShapePropertyMap_Impl;
    }

    static const SvxItemPropertySet* lcl_GetEmpty_SdXShapePropertySet_Impl()
    {
        static SvxItemPropertySet aEmptyPropSet( lcl_GetEmpty_SdXShapePropertyMap_Impl(), SdrObject::GetGlobalDrawObjectItemPool() );
        return &aEmptyPropSet;
    }
const SvEventDescription* ImplGetSupportedMacroItems()
{
    static const SvEventDescription aMacroDescriptionsImpl[] =
    {
        { SvMacroItemId::OnMouseOver, "OnMouseOver" },
        { SvMacroItemId::OnMouseOut,  "OnMouseOut" },
        { SvMacroItemId::NONE, nullptr }
    };

    return aMacroDescriptionsImpl;
}

SdXShape::SdXShape(SvxShape* pShape, SdXImpressDocument* pModel)
:   mpShape( pShape ),
    mpPropSet( pModel?
                    lcl_ImplGetShapePropertySet(pModel->IsImpressDocument(), pShape->getShapeKind() == OBJ_GRAF )
                :   lcl_GetEmpty_SdXShapePropertySet_Impl() ),
    mpMap( pModel?
                    lcl_ImplGetShapePropertyMap(pModel->IsImpressDocument(), pShape->getShapeKind() == OBJ_GRAF )
                :   lcl_GetEmpty_SdXShapePropertyMap_Impl() ),
    mpModel(pModel)
{

    pShape->setMaster( this );
}

SdXShape::~SdXShape() throw()
{
}

void SdXShape::dispose()
{
    mpShape->setMaster( nullptr );
    delete this;
}

uno::Any SAL_CALL SdXShape::queryInterface( const uno::Type & rType )
{
    return mpShape->queryInterface( rType );
}

void SAL_CALL SdXShape::acquire() throw()
{
    mpShape->acquire();
}

void SAL_CALL SdXShape::release() throw()
{
    mpShape->release();
}

bool SdXShape::queryAggregation( const css::uno::Type & rType, css::uno::Any& aAny )
{
    if( mpModel && mpModel ->IsImpressDocument() )
    {
        if( rType == cppu::UnoType<document::XEventsSupplier>::get())
        {
            aAny <<= uno::Reference< document::XEventsSupplier >(this);
            return true;
        }
    }

    return false;
}

uno::Sequence< uno::Type > SAL_CALL SdXShape::getTypes()
{
    if( mpModel && !mpModel->IsImpressDocument() )
    {
        return mpShape->_getTypes();
    }
    else
    {
        sal_uInt32 nObjId = mpShape->getShapeKind();
        uno::Sequence< uno::Type > aTypes;
        SdTypesCache& gImplTypesCache = SD_MOD()->gImplTypesCache;
        SdTypesCache::iterator aIter( gImplTypesCache.find( nObjId ) );
        if( aIter == gImplTypesCache.end() )
        {
            aTypes = mpShape->_getTypes();
            sal_uInt32 nCount = aTypes.getLength();
            aTypes.realloc( nCount+1 );
            aTypes[nCount] = cppu::UnoType<lang::XTypeProvider>::get();

            gImplTypesCache.insert(std::make_pair(nObjId, aTypes));
        }
        else
        {
            // use the already computed implementation id
            aTypes = (*aIter).second;
        }
        return aTypes;
    }
}

// XPropertyState
beans::PropertyState SAL_CALL SdXShape::getPropertyState( const OUString& PropertyName )
{
    SolarMutexGuard aGuard;

    if( mpPropSet->getPropertyMapEntry(PropertyName) )
    {
        return beans::PropertyState_DIRECT_VALUE;
    }
    else
    {
        SdrObject* pObj = mpShape->GetSdrObject();
        if( pObj == nullptr || ( pObj->getSdrPageFromSdrObject()->IsMasterPage() && pObj->IsEmptyPresObj() ) )
            return beans::PropertyState_DEFAULT_VALUE;

        return mpShape->_getPropertyState( PropertyName );
    }
}

void SAL_CALL SdXShape::setPropertyToDefault( const OUString& PropertyName )
{
    SolarMutexGuard aGuard;

    if( mpPropSet->getPropertyMapEntry(PropertyName) )
    {
        return;
    }
    else
    {
        mpShape->_setPropertyToDefault(PropertyName);
    }
}

uno::Any SAL_CALL SdXShape::getPropertyDefault( const OUString& aPropertyName )
{
    SolarMutexGuard aGuard;

    if( mpPropSet->getPropertyMapEntry(aPropertyName) )
    {
        return getPropertyValue( aPropertyName );
    }
    else
    {
        uno::Any aRet( mpShape->_getPropertyDefault(aPropertyName) );
        return aRet;
    }
}

//XPropertySet
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL SdXShape::getPropertySetInfo()
{
    SfxItemPropertyMapEntry const * nObjId = mpShape->getPropertyMapEntries();
    css::uno::Reference<css::beans::XPropertySetInfo> pInfo;

    SdExtPropertySetInfoCache& rCache = (mpModel && mpModel->IsImpressDocument()) ?
        SD_MOD()->gImplImpressPropertySetInfoCache : SD_MOD()->gImplDrawPropertySetInfoCache;

    SdExtPropertySetInfoCache::iterator aIter( rCache.find( nObjId ) );
    if( aIter == rCache.end() )
    {
        uno::Reference< beans::XPropertySetInfo > xInfo( mpShape->_getPropertySetInfo() );
        pInfo = new SfxExtItemPropertySetInfo( mpMap, xInfo->getProperties() );

        rCache.insert(std::make_pair(nObjId, pInfo));
    }
    else
    {
        // use the already computed implementation id
        pInfo = (*aIter).second;
    }

    return pInfo;
}

void SAL_CALL SdXShape::setPropertyValue( const OUString& aPropertyName, const css::uno::Any& aValue )
{
    SolarMutexGuard aGuard;

    const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(aPropertyName);

    if( pEntry )
    {
        SdrObject* pObj = mpShape->GetSdrObject();
        if( pObj )
        {
            SdAnimationInfo* pInfo = GetAnimationInfo(pEntry->nWID <= WID_THAT_NEED_ANIMINFO);

            switch(pEntry->nWID)
            {
                case WID_NAVORDER:
                {
                    sal_Int32 nNavOrder = 0;<--- Assignment 'nNavOrder=0', assigned value is 0
                    if(!(aValue >>= nNavOrder))<--- Assuming condition is false
                        throw lang::IllegalArgumentException();

                    SdrObjList* pObjList = pObj->getParentSdrObjListFromSdrObject();
                    if( pObjList )
                        pObjList->SetObjectNavigationPosition( *pObj, (nNavOrder < 0) ? SAL_MAX_UINT32 : static_cast< sal_uInt32 >( nNavOrder ) );<--- Condition 'nNavOrder<0' is always false
                    break;
                }

                case WID_EFFECT:
                {
                    AnimationEffect eEffect;
                    if(!(aValue >>= eEffect))
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetAnimationEffect( mpShape, eEffect );
                    break;
                }
                case WID_TEXTEFFECT:
                {
                    AnimationEffect eEffect;
                    if(!(aValue >>= eEffect))
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetTextAnimationEffect( mpShape, eEffect );
                    break;
                }
                case WID_SPEED:
                {
                    AnimationSpeed eSpeed;
                    if(!(aValue>>=eSpeed))
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetAnimationSpeed( mpShape, eSpeed );
                    break;
                }
                case WID_ISANIMATION:
                {
                    bool bIsAnimation(false);

                    if(!(aValue >>= bIsAnimation))
                    {
                        throw lang::IllegalArgumentException();
                    }

                    if(bIsAnimation)
                    {
                        SdrObjGroup* pGroup = dynamic_cast< SdrObjGroup* >(pObj);
                        SdPage* pPage = pGroup ? dynamic_cast< SdPage* >(pGroup->getSdrPageFromSdrObject()) : nullptr;

                        if (pPage)
                        {
                            // #i42894# Animated Group object, migrate that effect
                            EffectMigration::CreateAnimatedGroup(*pGroup, *pPage);

                            // #i42894# unfortunately when doing this all group members have to
                            // be moved to the page as direct members, else the currently
                            // available forms of animation do not work. If it succeeds,
                            // the group is empty and can be removed and deleted
                            if(!pGroup->GetSubList()->GetObjCount())
                            {
                                pPage->NbcRemoveObject(pGroup->GetOrdNum());

                                // always use SdrObject::Free(...) for SdrObjects (!)
                                SdrObject* pTemp(pGroup);
                                SdrObject::Free(pTemp);
                            }
                        }
                    }
                    //pInfo->mbIsMovie = bIsAnimation;
                    break;
                }
                case WID_BOOKMARK:
                {
                    OUString aString;
                    if(!(aValue >>= aString))
                        throw lang::IllegalArgumentException();

                    pInfo->SetBookmark( SdDrawPage::getUiNameFromPageApiName( aString ) );
                    break;
                }
                case WID_CLICKACTION:
                    ::cppu::any2enum< presentation::ClickAction >( pInfo->meClickAction, aValue);
                    break;

// TODO: WID_PLAYFULL:
                case WID_SOUNDFILE:
                {
                    OUString aString;
                    if(!(aValue >>= aString))
                        throw lang::IllegalArgumentException();
                    pInfo->maSoundFile = aString;
                    EffectMigration::UpdateSoundEffect( mpShape, pInfo );
                    break;
                }

                case WID_SOUNDON:
                {
                    if( !(aValue >>= pInfo->mbSoundOn) )
                        throw lang::IllegalArgumentException();
                    EffectMigration::UpdateSoundEffect( mpShape, pInfo );
                    break;
                }
                case WID_VERB:
                {
                    sal_Int32 nVerb = 0;
                    if(!(aValue >>= nVerb))
                        throw lang::IllegalArgumentException();

                    pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
                    break;
                }
                case WID_DIMCOLOR:
                {
                    sal_Int32 nColor = 0;

                    if( !(aValue >>= nColor) )
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetDimColor( mpShape, nColor );
                    break;
                }
                case WID_DIMHIDE:
                {
                    bool bDimHide = false;
                    if( !(aValue >>= bDimHide) )
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetDimHide( mpShape, bDimHide );
                    break;
                }
                case WID_DIMPREV:
                {
                    bool bDimPrevious = false;
                    if( !(aValue >>= bDimPrevious) )
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetDimPrevious( mpShape, bDimPrevious );
                    break;
                }
                case WID_PRESORDER:
                {
                    sal_Int32 nNewPos = 0;
                    if( !(aValue >>= nNewPos) )
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetPresentationOrder( mpShape, nNewPos );
                    break;
                }
                case WID_STYLE:
                    SetStyleSheet( aValue );
                    break;
                case WID_ISEMPTYPRESOBJ:
                    SetEmptyPresObj( ::cppu::any2bool(aValue) );
                    break;
                case WID_MASTERDEPEND:
                    SetMasterDepend( ::cppu::any2bool(aValue) );
                    break;

                case WID_LEGACYFRAGMENT:
                    {
                        uno::Reference< io::XInputStream > xInputStream;
                        aValue >>= xInputStream;
                        if( xInputStream.is() )
                        {
                            SvInputStream aStream( xInputStream );
                            SdrObject* pObject = mpShape->GetSdrObject();
                            SvxMSDffManager::ReadObjText( aStream, pObject );
                        }
                    }
                    break;

                case WID_ANIMPATH:
                {
                    uno::Reference< drawing::XShape > xShape( aValue, uno::UNO_QUERY );
                    SdrPathObj* pObj2 = xShape.is() ? dynamic_cast< SdrPathObj* >( GetSdrObjectFromXShape( xShape ) ) : nullptr;

                    if( pObj2 == nullptr )
                        throw lang::IllegalArgumentException();

                    EffectMigration::SetAnimationPath( mpShape, pObj2 );
                    break;
                }
                case WID_IMAGEMAP:
                {
                    SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
                    if( pDoc )
                    {
                        ImageMap aImageMap;
                        uno::Reference< uno::XInterface > xImageMap;
                        aValue >>= xImageMap;

                        if( !xImageMap.is() || !SvUnoImageMap_fillImageMap( xImageMap, aImageMap ) )
                            throw lang::IllegalArgumentException();

                        SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(pObj);
                        if( pIMapInfo )
                        {
                            // replace existing image map
                            pIMapInfo->SetImageMap( aImageMap );
                        }
                        else
                        {
                            // insert new user data with image map
                            pObj->AppendUserData(std::unique_ptr<SdrObjUserData>(new SvxIMapInfo(aImageMap) ));
                        }
                    }
                }
                break;
            }
        }
    }
    else
    {
        mpShape->_setPropertyValue(aPropertyName, aValue);
    }

    if( mpModel )
        mpModel->SetModified();
}

css::uno::Any SAL_CALL SdXShape::getPropertyValue( const OUString& PropertyName )
{
    SolarMutexGuard aGuard;

    uno::Any aRet;

    const SfxItemPropertySimpleEntry* pEntry = mpPropSet->getPropertyMapEntry(PropertyName);

    if( pEntry && mpShape->GetSdrObject() )
    {
        SdAnimationInfo* pInfo = GetAnimationInfo();

        switch(pEntry->nWID)
        {
        case WID_NAVORDER:
            {
                const sal_uInt32 nNavOrder = mpShape->GetSdrObject()->GetNavigationPosition();
                aRet <<= nNavOrder == SAL_MAX_UINT32 ? static_cast<sal_Int32>(-1) : static_cast< sal_Int32 >(nNavOrder);
            }
            break;
        case WID_EFFECT:
            aRet <<= EffectMigration::GetAnimationEffect( mpShape );
            break;
        case WID_TEXTEFFECT:
            aRet <<= EffectMigration::GetTextAnimationEffect( mpShape );
            break;
        case WID_ISPRESOBJ:
            aRet <<= IsPresObj();
            break;
        case WID_ISEMPTYPRESOBJ:
            aRet <<= IsEmptyPresObj();
            break;
        case WID_MASTERDEPEND:
            aRet <<= IsMasterDepend();
            break;
        case WID_SPEED:
            aRet <<= EffectMigration::GetAnimationSpeed( mpShape );
            break;
        case WID_ISANIMATION:
            aRet <<= (pInfo && pInfo->mbIsMovie);
            break;
        case WID_PLACEHOLDERTEXT:
            aRet <<= GetPlaceholderText();
            break;
        case WID_BOOKMARK:
        {
            OUString aString;
            SdDrawDocument* pDoc = mpModel ? mpModel->GetDoc() : nullptr;
            if (pInfo && pDoc)
            {
                // is the bookmark a page?
                bool bIsMasterPage;
                if(pDoc->GetPageByName( pInfo->GetBookmark(), bIsMasterPage ) != SDRPAGE_NOTFOUND)
                {
                    aString = SdDrawPage::getPageApiNameFromUiName( pInfo->GetBookmark() );
                }
                else
                {
                    aString = pInfo->GetBookmark() ;
                    sal_Int32 nPos = aString.lastIndexOf( '#' );
                    if( nPos >= 0 )
                    {
                        OUString aURL( aString.copy( 0, nPos+1 ) );
                        OUString aName( aString.copy( nPos+1 ) );
                        if(pDoc->GetPageByName( aName, bIsMasterPage ) != SDRPAGE_NOTFOUND)
                        {
                            aURL += SdDrawPage::getPageApiNameFromUiName( aName );
                            aString = aURL;
                        }
                    }
                }
            }

            aRet <<= aString;
            break;
        }
        case WID_CLICKACTION:
            aRet <<= ( pInfo?pInfo->meClickAction:presentation::ClickAction_NONE );
            break;
        case WID_PLAYFULL:
            aRet <<= ( pInfo && pInfo->mbPlayFull );
            break;
        case WID_SOUNDFILE:
            aRet <<= EffectMigration::GetSoundFile( mpShape );
            break;
        case WID_SOUNDON:
            aRet <<= EffectMigration::GetSoundOn( mpShape );
            break;
        case WID_BLUESCREEN:
            aRet <<= pInfo ? pInfo->maBlueScreen : Color(0x00ffffff);
            break;
        case WID_VERB:
            aRet <<= static_cast<sal_Int32>( pInfo?pInfo->mnVerb:0 );
            break;
        case WID_DIMCOLOR:
            aRet <<= EffectMigration::GetDimColor( mpShape );
            break;
        case WID_DIMHIDE:
            aRet <<= EffectMigration::GetDimHide( mpShape );
            break;
        case WID_DIMPREV:
            aRet <<= EffectMigration::GetDimPrevious( mpShape );
            break;
        case WID_PRESORDER:
            aRet <<= EffectMigration::GetPresentationOrder( mpShape );
            break;
        case WID_STYLE:
            aRet = GetStyleSheet();
            break;
        case WID_IMAGEMAP:
            {
                uno::Reference< uno::XInterface > xImageMap;

                SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
                if( pDoc )
                {

                    SvxIMapInfo* pIMapInfo = SvxIMapInfo::GetIMapInfo(mpShape->GetSdrObject());
                    if( pIMapInfo )
                    {
                        const ImageMap& rIMap = pIMapInfo->GetImageMap();
                        xImageMap = SvUnoImageMap_createInstance( rIMap, ImplGetSupportedMacroItems() );
                    }
                    else
                    {
                        xImageMap = SvUnoImageMap_createInstance();
                    }
                }

                aRet <<= uno::Reference< container::XIndexContainer >::query( xImageMap );
                break;
            }
        }
    }
    else
    {
        aRet = mpShape->_getPropertyValue(PropertyName);
    }

    return aRet;
}

/** */
SdAnimationInfo* SdXShape::GetAnimationInfo( bool bCreate ) const
{
    SdAnimationInfo* pInfo = nullptr;

    SdrObject* pObj = mpShape->GetSdrObject();
    if(pObj)
        pInfo = SdDrawDocument::GetShapeUserData(*pObj, bCreate);

    return pInfo;
}

uno::Sequence< OUString > SAL_CALL SdXShape::getSupportedServiceNames()
{
    std::vector<OUStringLiteral> aAdd{ "com.sun.star.presentation.Shape",
                                       "com.sun.star.document.LinkTarget" };

    SdrObject* pObj = mpShape->GetSdrObject();
    if(pObj && pObj->GetObjInventor() == SdrInventor::Default )
    {
        sal_uInt32 nInventor = pObj->GetObjIdentifier();
        switch( nInventor )
        {
        case OBJ_TITLETEXT:
            aAdd.emplace_back("com.sun.star.presentation.TitleTextShape");
            break;
        case OBJ_OUTLINETEXT:
            aAdd.emplace_back("com.sun.star.presentation.OutlinerShape");
            break;
        }
    }
    return comphelper::concatSequences(mpShape->_getSupportedServiceNames(), aAdd);
}

/** checks if this is a presentation object
 */
bool SdXShape::IsPresObj() const
{
    SdrObject* pObj = mpShape->GetSdrObject();
    if(pObj)
    {
        SdPage* pPage = dynamic_cast<SdPage* >(pObj->getSdrPageFromSdrObject());
        if(pPage)
            return pPage->GetPresObjKind(pObj) != PresObjKind::NONE;
    }
    return false;
}

/** checks if this presentation object is empty
 */
bool SdXShape::IsEmptyPresObj() const
{
    SdrObject* pObj = mpShape->GetSdrObject();
    if( (pObj != nullptr) && pObj->IsEmptyPresObj() )
    {
        // check if the object is in edit, then if it's temporarily not empty
        SdrTextObj* pTextObj = dynamic_cast< SdrTextObj* >( pObj );
        if( pTextObj == nullptr )
            return true;

        return !pTextObj->CanCreateEditOutlinerParaObject();
    }

    return false;
}

OUString SdXShape::GetPlaceholderText() const
{
    // only possible if this actually *is* a presentation object
    if( !IsPresObj() )
        return OUString();

    SdrObject* pObj = mpShape->GetSdrObject();
    if( pObj == nullptr )
        return OUString();

    SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
    DBG_ASSERT( pPage, "no page?" );
    if( pPage == nullptr )
        return OUString();

    return pPage->GetPresObjText( pPage->GetPresObjKind(pObj) );
}

/** sets/reset the empty status of a presentation object
*/
void SdXShape::SetEmptyPresObj(bool bEmpty)
{
    // only possible if this actually *is* a presentation object
    if( !IsPresObj() )
        return;

    SdrObject* pObj = mpShape->GetSdrObject();
    if( pObj == nullptr )
        return;

    if( pObj->IsEmptyPresObj() == bEmpty )
        return;

    if(!bEmpty)
    {
        OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
        const bool bVertical = pOutlinerParaObject && pOutlinerParaObject->IsVertical();

        // really delete SdrOutlinerObj at pObj
        pObj->NbcSetOutlinerParaObject(nullptr);
        if( bVertical && dynamic_cast<SdrTextObj*>( pObj )  )
            static_cast<SdrTextObj*>(pObj)->SetVerticalWriting( true );

        SdrGrafObj* pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj  );
        if( pGraphicObj )
        {
            Graphic aEmpty;
            pGraphicObj->SetGraphic(aEmpty);
        }
        else
        {
            SdrOle2Obj* pOleObj = dynamic_cast< SdrOle2Obj* >( pObj );
            if( pOleObj )
            {
                pOleObj->ClearGraphic();
            }
        }
    }
    else
    {
        // now set an empty OutlinerParaObject at pObj without
        // any content but with the style of the old OutlinerParaObjects
        // first paragraph
        do
        {
            SdDrawDocument* pDoc = mpModel?mpModel->GetDoc():nullptr;
            DBG_ASSERT( pDoc, "no document?" );
            if( pDoc == nullptr)
                break;

            SdOutliner* pOutliner = pDoc->GetInternalOutliner();
            DBG_ASSERT( pOutliner, "no outliner?" );
            if( pOutliner == nullptr )
                break;

            SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
            DBG_ASSERT( pPage, "no page?" );
            if( pPage == nullptr )
                break;

            OutlinerParaObject* pOutlinerParaObject = pObj->GetOutlinerParaObject();
            pOutliner->SetText( *pOutlinerParaObject );
            const bool bVertical = pOutliner->IsVertical();

            pOutliner->Clear();
            pOutliner->SetVertical( bVertical );
            pOutliner->SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(pDoc->GetStyleSheetPool()) );
            pOutliner->SetStyleSheet( 0, pPage->GetTextStyleSheetForObject( pObj ) );
            pOutliner->Insert( pPage->GetPresObjText( pPage->GetPresObjKind(pObj) ) );
            pObj->SetOutlinerParaObject( pOutliner->CreateParaObject() );
            pOutliner->Clear();
        }
        while(false);
    }

    pObj->SetEmptyPresObj(bEmpty);
}

bool SdXShape::IsMasterDepend() const throw()
{
    SdrObject* pObj = mpShape->GetSdrObject();
    return pObj && pObj->GetUserCall() != nullptr;
}

void SdXShape::SetMasterDepend( bool bDepend ) throw()
{
    if( IsMasterDepend() == bDepend )
        return;

    SdrObject* pObj = mpShape->GetSdrObject();
    if( pObj )
    {
        if( bDepend )
        {
            SdPage* pPage = dynamic_cast< SdPage* >(pObj->getSdrPageFromSdrObject());
            pObj->SetUserCall( pPage );
        }
        else
        {
            pObj->SetUserCall( nullptr );
        }
    }
}

void SdXShape::SetStyleSheet( const uno::Any& rAny )
{
    SdrObject* pObj = mpShape->GetSdrObject();
    if( pObj == nullptr )
        throw beans::UnknownPropertyException();

    uno::Reference< style::XStyle > xStyle( rAny, uno::UNO_QUERY );
    SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle );

    const SfxStyleSheet* pOldStyleSheet = pObj->GetStyleSheet();
    if( pOldStyleSheet == pStyleSheet )
        return;

    if( pStyleSheet == nullptr || (pStyleSheet->GetFamily() != SfxStyleFamily::Para && pStyleSheet->GetFamily() != SfxStyleFamily::Page) )
        throw lang::IllegalArgumentException();

    pObj->SetStyleSheet( pStyleSheet, false );

    SdDrawDocument* pDoc = mpModel? mpModel->GetDoc() : nullptr;
    if( pDoc )
    {
        ::sd::DrawDocShell* pDocSh = pDoc->GetDocSh();
        ::sd::ViewShell* pViewSh = pDocSh ? pDocSh->GetViewShell() : nullptr;

        if( pViewSh )
            pViewSh->GetViewFrame()->GetBindings().Invalidate( SID_STYLE_FAMILY2 );
    }
}

uno::Any SdXShape::GetStyleSheet() const
{
    SdrObject* pObj = mpShape->GetSdrObject();
    if( pObj == nullptr )
        throw beans::UnknownPropertyException();

    SfxStyleSheet* pStyleSheet = pObj->GetStyleSheet();
    // it is possible for shapes inside a draw to have a presentation style
    // but we don't want this for the api
    if( (pStyleSheet == nullptr) || ((pStyleSheet->GetFamily() != SfxStyleFamily::Para) && !mpModel->IsImpressDocument()) )
        return Any();

    return Any( uno::Reference< style::XStyle >( dynamic_cast< SfxUnoStyleSheet* >( pStyleSheet ) ) );
}

class SdUnoEventsAccess : public cppu::WeakImplHelper< css::container::XNameReplace, css::lang::XServiceInfo >
{
private:
    SdXShape*   mpShape;

public:
    explicit SdUnoEventsAccess(SdXShape* pShape) throw();

    // XNameReplace
    virtual void SAL_CALL replaceByName( const OUString& aName, const css::uno::Any& aElement ) override;

    // XNameAccess
    virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getElementNames(  ) override;
    virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;

    // XElementAccess
    virtual css::uno::Type SAL_CALL getElementType(  ) override;
    virtual sal_Bool SAL_CALL hasElements(  ) override;

    // XServiceInfo
    virtual OUString SAL_CALL getImplementationName(  ) override;
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
};

// XEventsSupplier
uno::Reference< container::XNameReplace > SAL_CALL SdXShape::getEvents(  )
{
    return new SdUnoEventsAccess( this );
}

static const OUStringLiteral gaStrOnClick( "OnClick" );
static const OUStringLiteral gaStrServiceName( "com.sun.star.documents.Events" );
static const OUStringLiteral gaStrEventType( "EventType" );
static const OUStringLiteral gaStrPresentation( "Presentation" );
static const OUStringLiteral gaStrLibrary("Library");
static const OUStringLiteral gaStrMacroName("MacroName");
static const OUStringLiteral gaStrClickAction( "ClickAction" );
static const OUStringLiteral gaStrBookmark( "Bookmark" );
static const OUStringLiteral gaStrEffect( "Effect" );
static const OUStringLiteral gaStrPlayFull( "PlayFull" );
static const OUStringLiteral gaStrVerb( "Verb" );
static const OUStringLiteral gaStrSoundURL( "SoundURL" );
static const OUStringLiteral gaStrSpeed( "Speed" );
static const OUStringLiteral gaStrStarBasic( "StarBasic" );
static const OUStringLiteral gaStrScript( "Script" );

SdUnoEventsAccess::SdUnoEventsAccess( SdXShape* pShape ) throw()
  : mpShape( pShape )
{
}

namespace {

enum class FoundFlags {
    NONE          = 0x0000,
    ClickAction   = 0x0001,
    Bookmark      = 0x0002,
    Effect        = 0x0004,
    PlayFull      = 0x0008,
    Verb          = 0x0010,
    SoundUrl      = 0x0020,
    Speed         = 0x0040,
    EventType     = 0x0080,
    Macro         = 0x0100,
    Library       = 0x0200,
};

}

namespace o3tl {
    template<> struct typed_flags<FoundFlags> : is_typed_flags<FoundFlags, 0x03ff> {};
}

static void clearEventsInAnimationInfo( SdAnimationInfo* pInfo )
{
    pInfo->SetBookmark( "" );
    pInfo->mbSecondSoundOn = false;
    pInfo->mbSecondPlayFull = false;
    pInfo->meClickAction = presentation::ClickAction_NONE;
    pInfo->meSecondEffect = presentation::AnimationEffect_NONE;
    pInfo->meSecondSpeed = presentation::AnimationSpeed_MEDIUM;
    pInfo->mnVerb = 0;
}

// XNameReplace
void SAL_CALL SdUnoEventsAccess::replaceByName( const OUString& aName, const uno::Any& aElement )
{
    if( mpShape == nullptr || aName != gaStrOnClick )
        throw container::NoSuchElementException();

    uno::Sequence< beans::PropertyValue > aProperties;
    if( !aElement.hasValue() || aElement.getValueType() != getElementType() || !(aElement >>= aProperties) )
        throw lang::IllegalArgumentException();

    FoundFlags nFound = FoundFlags::NONE;

    OUString aStrEventType;
    presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
    presentation::AnimationEffect eEffect = presentation::AnimationEffect_NONE;
    presentation::AnimationSpeed eSpeed = presentation::AnimationSpeed_MEDIUM;
    OUString aStrSoundURL;
    bool bPlayFull = false;
    sal_Int32 nVerb = 0;
    OUString aStrMacro;
    OUString aStrLibrary;
    OUString aStrBookmark;

    for( const beans::PropertyValue& rProperty : std::as_const(aProperties) )
    {
        if( !( nFound & FoundFlags::EventType ) && rProperty.Name == gaStrEventType )
        {
            if( rProperty.Value >>= aStrEventType )
            {
                nFound |= FoundFlags::EventType;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::ClickAction ) && rProperty.Name == gaStrClickAction )
        {
            if( rProperty.Value >>= eClickAction )
            {
                nFound |= FoundFlags::ClickAction;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::Macro ) && ( rProperty.Name == gaStrMacroName || rProperty.Name == gaStrScript ) )
        {
            if( rProperty.Value >>= aStrMacro )
            {
                nFound |= FoundFlags::Macro;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::Library ) && rProperty.Name == gaStrLibrary )
        {
            if( rProperty.Value >>= aStrLibrary )
            {
                nFound |= FoundFlags::Library;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::Effect ) && rProperty.Name == gaStrEffect )
        {
            if( rProperty.Value >>= eEffect )
            {
                nFound |= FoundFlags::Effect;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::Bookmark ) && rProperty.Name == gaStrBookmark )
        {
            if( rProperty.Value >>= aStrBookmark )
            {
                nFound |= FoundFlags::Bookmark;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::Speed ) && rProperty.Name == gaStrSpeed )
        {
            if( rProperty.Value >>= eSpeed )
            {
                nFound |= FoundFlags::Speed;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::SoundUrl ) && rProperty.Name == gaStrSoundURL )
        {
            if( rProperty.Value >>= aStrSoundURL )
            {
                nFound |= FoundFlags::SoundUrl;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::PlayFull ) && rProperty.Name == gaStrPlayFull )
        {
            if( rProperty.Value >>= bPlayFull )
            {
                nFound |= FoundFlags::PlayFull;
                continue;
            }
        }
        else if( !( nFound & FoundFlags::Verb ) && rProperty.Name == gaStrVerb )
        {
            if( rProperty.Value >>= nVerb )
            {
                nFound |= FoundFlags::Verb;
                continue;
            }
        }

        throw lang::IllegalArgumentException();
    }

    bool bOk = false;
    do
    {
        if( !( nFound & FoundFlags::EventType ) )
            break;

        if( aStrEventType == gaStrPresentation )
        {
            if( !( nFound & FoundFlags::ClickAction ) )
                break;

            SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();
            if( presentation::ClickAction_NONE == eClickAction && nullptr == pInfo )
            {
                bOk = true;
                break;
            }

            if( nullptr == pInfo )
                pInfo = mpShape->GetAnimationInfo( true );

            DBG_ASSERT( pInfo, "shape animation info could not be created!" );
            if( nullptr == pInfo )
                break;

            clearEventsInAnimationInfo( pInfo );
            pInfo->meClickAction = eClickAction;

            switch( eClickAction )
            {
            case presentation::ClickAction_NONE:
            case presentation::ClickAction_PREVPAGE:
            case presentation::ClickAction_NEXTPAGE:
            case presentation::ClickAction_FIRSTPAGE:
            case presentation::ClickAction_LASTPAGE:
            case presentation::ClickAction_INVISIBLE:
            case presentation::ClickAction_STOPPRESENTATION:
                {
                    bOk = true;
                }
                break;

            case presentation::ClickAction_PROGRAM:
            case presentation::ClickAction_BOOKMARK:
            case presentation::ClickAction_DOCUMENT:
                if( nFound & FoundFlags::Bookmark )
                {
                    if( eClickAction == presentation::ClickAction_BOOKMARK )
                    {
                        aStrBookmark = getUiNameFromPageApiNameImpl( aStrBookmark );
                    }
                    else if( eClickAction == presentation::ClickAction_DOCUMENT )
                    {
                        sal_Int32 nPos = aStrBookmark.lastIndexOf( '#' );
                        if( nPos >= 0 )
                        {
                            OUString aURL( aStrBookmark.copy( 0, nPos+1 ) );
                            aURL += getUiNameFromPageApiNameImpl( aStrBookmark.copy( nPos+1 ) );
                            aStrBookmark = aURL;
                        }
                    }

                    pInfo->SetBookmark( aStrBookmark );
                    bOk = true;
                }
                break;

            case presentation::ClickAction_MACRO:
                if( nFound & FoundFlags::Macro )
                {
                    pInfo->SetBookmark( aStrMacro );
                    bOk = true;
                }
                break;

            case presentation::ClickAction_VERB:
                if( nFound & FoundFlags::Verb )
                {
                    pInfo->mnVerb = static_cast<sal_uInt16>(nVerb);
                    bOk = true;
                }
                break;

            case presentation::ClickAction_VANISH:
                if( !( nFound & FoundFlags::Effect ) )
                    break;

                pInfo->meSecondEffect = eEffect;
                pInfo->meSecondSpeed = nFound & FoundFlags::Speed ? eSpeed : presentation::AnimationSpeed_MEDIUM;

                bOk = true;

                [[fallthrough]];

            case presentation::ClickAction_SOUND:
                if( nFound & FoundFlags::SoundUrl )
                {
                    pInfo->SetBookmark( aStrSoundURL );
                    if( eClickAction != presentation::ClickAction_SOUND )
                        pInfo->mbSecondSoundOn = !aStrSoundURL.isEmpty();
                    pInfo->mbSecondPlayFull = (nFound & FoundFlags::PlayFull) && bPlayFull;

                    bOk = true;
                }
                break;
            default:
                break;
            }
        }
        else
        {
            SdAnimationInfo* pInfo = mpShape->GetAnimationInfo( true );

            DBG_ASSERT( pInfo, "shape animation info could not be created!" );
            if( nullptr == pInfo )
                break;

            clearEventsInAnimationInfo( pInfo );
            pInfo->meClickAction = presentation::ClickAction_MACRO;

            if ( SfxApplication::IsXScriptURL( aStrMacro ) )
            {
                pInfo->SetBookmark( aStrMacro );
            }
            else
            {
                sal_Int32 nIdx{ 0 };
                const OUString aLibName   = aStrMacro.getToken(0, '.', nIdx);
                const OUString aModulName = aStrMacro.getToken(0, '.', nIdx);
                const OUString aMacroName = aStrMacro.getToken(0, '.', nIdx);

                OUStringBuffer sBuffer;
                sBuffer.append( aMacroName );
                sBuffer.append( '.' );
                sBuffer.append( aModulName );
                sBuffer.append( '.' );
                sBuffer.append( aLibName );
                sBuffer.append( '.' );

                if ( aStrLibrary == "StarOffice" )
                {
                    sBuffer.append( "BASIC" );
                }
                else
                {
                    sBuffer.append( aStrLibrary );
                }

                pInfo->SetBookmark( sBuffer.makeStringAndClear() );
            }
            bOk = true;
        }
    }
    while(false);

    if( !bOk )
        throw lang::IllegalArgumentException();
}

// XNameAccess
uno::Any SAL_CALL SdUnoEventsAccess::getByName( const OUString& aName )
{
    if( mpShape == nullptr || aName != gaStrOnClick )
        throw container::NoSuchElementException();

    SdAnimationInfo* pInfo = mpShape->GetAnimationInfo();

    presentation::ClickAction eClickAction = presentation::ClickAction_NONE;
    if( pInfo )
        eClickAction = pInfo->meClickAction;

    sal_Int32 nPropertyCount = 2;
    switch( eClickAction )
    {
    case presentation::ClickAction_NONE:
    case presentation::ClickAction_PREVPAGE:
    case presentation::ClickAction_NEXTPAGE:
    case presentation::ClickAction_FIRSTPAGE:
    case presentation::ClickAction_LASTPAGE:
    case presentation::ClickAction_INVISIBLE:
    case presentation::ClickAction_STOPPRESENTATION:
        break;
    case presentation::ClickAction_PROGRAM:
    case presentation::ClickAction_VERB:
    case presentation::ClickAction_BOOKMARK:
    case presentation::ClickAction_DOCUMENT:
    case presentation::ClickAction_MACRO:
        if ( !SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
            nPropertyCount += 1;
        break;

    case presentation::ClickAction_SOUND:
        nPropertyCount += 2;
        break;

    case presentation::ClickAction_VANISH:
        nPropertyCount += 4;
        break;
    default:
        break;
    }

    uno::Sequence< beans::PropertyValue > aProperties( nPropertyCount );
    beans::PropertyValue* pProperties = aProperties.getArray();

    uno::Any aAny;

    if( eClickAction == presentation::ClickAction_MACRO )
    {
        if ( SfxApplication::IsXScriptURL( pInfo->GetBookmark() ) )
        {
            // Scripting Framework URL
            aAny <<= OUString(gaStrScript);
            pProperties->Name = gaStrEventType;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            pProperties++;

            aAny <<= pInfo->GetBookmark();
            pProperties->Name = gaStrScript;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            pProperties++;<--- Variable 'pProperties' is assigned a value that is never used.
        }
        else
        {
            // Old Basic macro URL
            aAny <<= OUString(gaStrStarBasic);
            pProperties->Name = gaStrEventType;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            pProperties++;

            OUString aMacro = pInfo->GetBookmark();

            // aMacro has got following format:
            // "Macroname.Modulname.Libname.Documentname" or
            // "Macroname.Modulname.Libname.Applicationname"
            sal_Int32 nIdx{ 0 };
            const OUString aMacroName = aMacro.getToken(0, '.', nIdx);
            const OUString aModulName = aMacro.getToken(0, '.', nIdx);
            const OUString aLibName   = aMacro.getToken(0, '.', nIdx);

            OUString sBuffer = aLibName +
                "."  +
                aModulName  +
                "."  +
                aMacroName;

            aAny <<= sBuffer;
            pProperties->Name = gaStrMacroName;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            pProperties++;

            aAny <<= OUString( "StarOffice" );
            pProperties->Name = gaStrLibrary;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
        }
    }
    else
    {
        aAny <<= OUString(gaStrPresentation);
        pProperties->Name = gaStrEventType;
        pProperties->Handle = -1;
        pProperties->Value = aAny;
        pProperties->State = beans::PropertyState_DIRECT_VALUE;
        pProperties++;

        aAny <<= eClickAction;
        pProperties->Name = gaStrClickAction;
        pProperties->Handle = -1;
        pProperties->Value = aAny;
        pProperties->State = beans::PropertyState_DIRECT_VALUE;
        pProperties++;

        switch( eClickAction )
        {
        case presentation::ClickAction_NONE:
        case presentation::ClickAction_PREVPAGE:
        case presentation::ClickAction_NEXTPAGE:
        case presentation::ClickAction_FIRSTPAGE:
        case presentation::ClickAction_LASTPAGE:
        case presentation::ClickAction_INVISIBLE:
        case presentation::ClickAction_STOPPRESENTATION:
            break;
        case presentation::ClickAction_BOOKMARK:
            {
                const OUString aStrBookmark( getPageApiNameFromUiName( pInfo->GetBookmark()) );
                pProperties->Name = gaStrBookmark;
                pProperties->Handle = -1;
                pProperties->Value <<= aStrBookmark;
                pProperties->State = beans::PropertyState_DIRECT_VALUE;
            }
            break;

        case presentation::ClickAction_DOCUMENT:
        case presentation::ClickAction_PROGRAM:
            {
                OUString aString( pInfo->GetBookmark());
                sal_Int32 nPos = aString.lastIndexOf( '#' );
                if( nPos >= 0 )
                {
                    OUString aURL( aString.copy( 0, nPos+1 ) );
                    aURL += getPageApiNameFromUiName( aString.copy( nPos+1 ) );
                    aString = aURL;
                }
                pProperties->Name = gaStrBookmark;
                pProperties->Handle = -1;
                pProperties->Value <<= aString;
                pProperties->State = beans::PropertyState_DIRECT_VALUE;
            }
            break;

        case presentation::ClickAction_VANISH:
            aAny <<= pInfo->meSecondEffect;
            pProperties->Name = gaStrEffect;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            pProperties++;

            aAny <<= pInfo->meSecondSpeed;
            pProperties->Name = gaStrSpeed;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            pProperties++;

            [[fallthrough]];

        case presentation::ClickAction_SOUND:
            if( eClickAction == presentation::ClickAction_SOUND || pInfo->mbSecondSoundOn )
            {
                aAny <<= pInfo->GetBookmark();
                pProperties->Name = gaStrSoundURL;
                pProperties->Handle = -1;
                pProperties->Value = aAny;
                pProperties->State = beans::PropertyState_DIRECT_VALUE;
                pProperties++;

                pProperties->Name = gaStrPlayFull;
                pProperties->Handle = -1;
                pProperties->Value <<= pInfo->mbSecondPlayFull;
                pProperties->State = beans::PropertyState_DIRECT_VALUE;
            }
            break;

        case presentation::ClickAction_VERB:
            aAny <<= static_cast<sal_Int32>(pInfo->mnVerb);
            pProperties->Name = gaStrVerb;
            pProperties->Handle = -1;
            pProperties->Value = aAny;
            pProperties->State = beans::PropertyState_DIRECT_VALUE;
            break;
        default:
            break;
        }
    }

    aAny <<= aProperties;
    return aAny;
}

uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getElementNames(  )
{
    return { gaStrOnClick };
}

sal_Bool SAL_CALL SdUnoEventsAccess::hasByName( const OUString& aName )
{
    return aName == gaStrOnClick;
}

// XElementAccess
uno::Type SAL_CALL SdUnoEventsAccess::getElementType(  )
{
    return cppu::UnoType<uno::Sequence< beans::PropertyValue >>::get();
}

sal_Bool SAL_CALL SdUnoEventsAccess::hasElements(  )
{
    return true;
}

// XServiceInfo
OUString SAL_CALL SdUnoEventsAccess::getImplementationName(  )
{
    return "SdUnoEventsAccess";
}

sal_Bool SAL_CALL SdUnoEventsAccess::supportsService( const OUString& ServiceName )
{
    return cppu::supportsService(this, ServiceName);
}

uno::Sequence< OUString > SAL_CALL SdUnoEventsAccess::getSupportedServiceNames(  )
{
    return { gaStrServiceName };
}

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