1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
|
/* -*- 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 <svx/svdoole2.hxx>
#include <com/sun/star/util/XModifyBroadcaster.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/ElementModes.hpp>
#include <com/sun/star/embed/EmbedMisc.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/embed/XInplaceClient.hpp>
#include <com/sun/star/embed/XInplaceObject.hpp>
#include <com/sun/star/embed/XLinkageSupport.hpp>
#include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
#include <com/sun/star/embed/XWindowSupplier.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/container/XChild.hpp>
#include "com/sun/star/document/XStorageBasedDocument.hpp"
#include <comphelper/processfactory.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <unotools/ucbstreamhelper.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include <toolkit/helper/convert.hxx>
#include <vcl/graphicfilter.hxx>
#include <svtools/embedhlp.hxx>
#include <sfx2/objsh.hxx>
#include <sfx2/ipclient.hxx>
#include <sfx2/lnkbase.hxx>
#include <tools/stream.hxx>
#include <comphelper/anytostring.hxx>
#include <svx/svdpagv.hxx>
#include <tools/globname.hxx>
#include <vcl/jobset.hxx>
#include <comphelper/classids.hxx>
#include <sot/formats.hxx>
#include <sfx2/linkmgr.hxx>
#include <svtools/transfer.hxx>
#include <cppuhelper/implbase5.hxx>
#include <svl/solar.hrc>
#include <svl/urihelper.hxx>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <svx/svdmodel.hxx>
#include "svx/svdglob.hxx"
#include "svx/svdstr.hrc"
#include <svx/svdetc.hxx>
#include <svx/svdview.hxx>
#include "unomlstr.hxx"
#include <svx/charthelper.hxx>
#include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
#include <svx/svdograf.hxx>
#include <svx/sdr/properties/oleproperties.hxx>
// #i100710#
#include <svx/xlnclit.hxx>
#include <svx/xbtmpit.hxx>
#include <svx/xflbmtit.hxx>
#include <svx/xflbstit.hxx>
// #i118485#
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
#include <editeng/outlobj.hxx>
#include <svx/svdpage.hxx>
using namespace ::rtl;
using namespace ::com::sun::star;
static uno::Reference < beans::XPropertySet > lcl_getFrame_throw(const SdrOle2Obj* _pObject)
{
uno::Reference < beans::XPropertySet > xFrame;
if ( _pObject )
{
uno::Reference< frame::XController> xController = _pObject->GetParentXModel()->getCurrentController();
if ( xController.is() )
{
xFrame.set( xController->getFrame(),uno::UNO_QUERY_THROW);
}
} // if ( _pObject )
return xFrame;
}
class SdrLightEmbeddedClient_Impl : public ::cppu::WeakImplHelper5
< embed::XStateChangeListener
, document::XEventListener
, embed::XInplaceClient
, embed::XEmbeddedClient
, embed::XWindowSupplier
>
{
uno::Reference< awt::XWindow > m_xWindow;
SdrOle2Obj* mpObj;
Fraction m_aScaleWidth;
Fraction m_aScaleHeight;
public:
SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj );
void Release();
void SetSizeScale( const Fraction& aScaleWidth, const Fraction& aScaleHeight )
{
m_aScaleWidth = aScaleWidth;
m_aScaleHeight = aScaleHeight;
}
Fraction GetScaleWidth() const { return m_aScaleWidth; }
Fraction GetScaleHeight() const { return m_aScaleHeight; }
void setWindow(const uno::Reference< awt::XWindow >& _xWindow);
private:
Rectangle impl_getScaledRect_nothrow() const;
// XStateChangeListener
virtual void SAL_CALL changingState( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL stateChanged( const ::com::sun::star::lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
// document::XEventListener
virtual void SAL_CALL notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException );
// XEmbeddedClient
virtual void SAL_CALL saveObject() throw ( embed::ObjectSaveVetoException, uno::Exception, uno::RuntimeException );
virtual void SAL_CALL visibilityChanged( sal_Bool bVisible ) throw ( embed::WrongStateException, uno::RuntimeException );
// XComponentSupplier
virtual uno::Reference< util::XCloseable > SAL_CALL getComponent() throw ( uno::RuntimeException );
// XInplaceClient
virtual sal_Bool SAL_CALL canInplaceActivate() throw ( uno::RuntimeException );
virtual void SAL_CALL activatingInplace() throw ( embed::WrongStateException, uno::RuntimeException );
virtual void SAL_CALL activatingUI() throw ( embed::WrongStateException, uno::RuntimeException );
virtual void SAL_CALL deactivatedInplace() throw ( embed::WrongStateException, uno::RuntimeException );
virtual void SAL_CALL deactivatedUI() throw ( embed::WrongStateException, uno::RuntimeException );
virtual uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL getLayoutManager() throw ( embed::WrongStateException, uno::RuntimeException );
virtual uno::Reference< frame::XDispatchProvider > SAL_CALL getInplaceDispatchProvider() throw ( embed::WrongStateException, uno::RuntimeException );
virtual awt::Rectangle SAL_CALL getPlacement() throw ( embed::WrongStateException, uno::RuntimeException );
virtual awt::Rectangle SAL_CALL getClipRectangle() throw ( embed::WrongStateException, uno::RuntimeException );
virtual void SAL_CALL translateAccelerators( const uno::Sequence< awt::KeyEvent >& aKeys ) throw ( embed::WrongStateException, uno::RuntimeException );
virtual void SAL_CALL scrollObject( const awt::Size& aOffset ) throw ( embed::WrongStateException, uno::RuntimeException );
virtual void SAL_CALL changedPlacement( const awt::Rectangle& aPosRect ) throw ( embed::WrongStateException, uno::Exception, uno::RuntimeException );
// XWindowSupplier
virtual uno::Reference< awt::XWindow > SAL_CALL getWindow() throw ( uno::RuntimeException );
};
//--------------------------------------------------------------------
SdrLightEmbeddedClient_Impl::SdrLightEmbeddedClient_Impl( SdrOle2Obj* pObj )
: mpObj( pObj )
{
}
Rectangle SdrLightEmbeddedClient_Impl::impl_getScaledRect_nothrow() const
{
Rectangle aLogicRect( mpObj->GetLogicRect() );
// apply scaling to object area and convert to pixels
aLogicRect.SetSize( Size( Fraction( aLogicRect.GetWidth() ) * m_aScaleWidth,
Fraction( aLogicRect.GetHeight() ) * m_aScaleHeight ) );
return aLogicRect;
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::changingState( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 /*nOldState*/, ::sal_Int32 /*nNewState*/ ) throw (::com::sun::star::embed::WrongStateException, ::com::sun::star::uno::RuntimeException)
{
}
//--------------------------------------------------------------------
void SdrLightEmbeddedClient_Impl::Release()
{
{
SolarMutexGuard aGuard;
mpObj = NULL;
}
release();
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::stateChanged( const ::com::sun::star::lang::EventObject& /*aEvent*/, ::sal_Int32 nOldState, ::sal_Int32 nNewState ) throw (::com::sun::star::uno::RuntimeException)
{
SolarMutexGuard aGuard;
if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
{
mpObj->ObjectLoaded();
GetSdrGlobalData().GetOLEObjCache().InsertObj(mpObj);
}
else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
{
GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
}
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::disposing( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
{
SolarMutexGuard aGuard;
GetSdrGlobalData().GetOLEObjCache().RemoveObj(mpObj);
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( const document::EventObject& aEvent ) throw( uno::RuntimeException )
{
// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
SolarMutexGuard aGuard;
// the code currently makes sense only in case there is no other client
if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && aEvent.EventName == "OnVisAreaChanged"
&& mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == uno::Reference< embed::XEmbeddedClient >( this ) )
{
try
{
MapUnit aContainerMapUnit( MAP_100TH_MM );
uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
if ( xParentVis.is() )
aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
Rectangle aVisArea;
awt::Size aSz;
try
{
aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
}
catch( embed::NoVisualAreaSizeException& )
{
OSL_FAIL( "No visual area size!\n" );
aSz.Width = 5000;
aSz.Height = 5000;
}
catch( uno::Exception& )
{
OSL_FAIL( "Unexpected exception!\n" );
aSz.Width = 5000;
aSz.Height = 5000;
}
aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
aVisArea = OutputDevice::LogicToLogic( aVisArea, aObjMapUnit, aContainerMapUnit );
Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( aVisArea.GetWidth() ) ),
static_cast< long >( m_aScaleHeight * Fraction( aVisArea.GetHeight() ) ) );
Rectangle aLogicRect( mpObj->GetLogicRect() );
// react to the change if the difference is bigger than one pixel
Size aPixelDiff =
Application::GetDefaultDevice()->LogicToPixel(
Size( aLogicRect.GetWidth() - aScaledSize.Width(),
aLogicRect.GetHeight() - aScaledSize.Height() ),
aContainerMapUnit );
if( aPixelDiff.Width() || aPixelDiff.Height() )
{
mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aScaledSize ) );
mpObj->BroadcastObjectChange();
}
else
mpObj->ActionChanged();
}
catch( uno::Exception& )
{
OSL_FAIL( "Unexpected exception!\n" );
}
}
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::saveObject()
throw ( embed::ObjectSaveVetoException,
uno::Exception,
uno::RuntimeException )
{
// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
uno::Reference< embed::XCommonEmbedPersist > xPersist;
uno::Reference< util::XModifiable > xModifiable;
{
SolarMutexGuard aGuard;
if ( !mpObj )
throw embed::ObjectSaveVetoException();
// the common persistence is supported by objects and links
xPersist = uno::Reference< embed::XCommonEmbedPersist >( mpObj->GetObjRef(), uno::UNO_QUERY_THROW );
xModifiable = uno::Reference< util::XModifiable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
}
xPersist->storeOwn();
if ( xModifiable.is() )
xModifiable->setModified( sal_True );
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::visibilityChanged( sal_Bool /*bVisible*/ )
throw ( embed::WrongStateException,
uno::RuntimeException )
{
// nothing to do currently
// TODO/LATER: when writer uses this implementation the code could be shared with SfxInPlaceClient_Impl
if ( mpObj )
{
Rectangle aLogicRect( mpObj->GetLogicRect() );
Size aLogicSize( aLogicRect.GetWidth(), aLogicRect.GetHeight() );
if( mpObj->IsChart() )
{
//charts never should be stretched see #i84323# for example
mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aLogicSize ) );
mpObj->BroadcastObjectChange();
} // if( mpObj->IsChart() )
}
}
//--------------------------------------------------------------------
uno::Reference< util::XCloseable > SAL_CALL SdrLightEmbeddedClient_Impl::getComponent()
throw ( uno::RuntimeException )
{
uno::Reference< util::XCloseable > xResult;
SolarMutexGuard aGuard;
if ( mpObj )
xResult = uno::Reference< util::XCloseable >( mpObj->GetParentXModel(), uno::UNO_QUERY );
return xResult;
}
// XInplaceClient
//--------------------------------------------------------------------
sal_Bool SAL_CALL SdrLightEmbeddedClient_Impl::canInplaceActivate()
throw ( uno::RuntimeException )
{
sal_Bool bRet = sal_False;
SolarMutexGuard aGuard;
if ( mpObj )
{
uno::Reference< embed::XEmbeddedObject > xObject = mpObj->GetObjRef();
if ( !xObject.is() )
throw uno::RuntimeException();
// we don't want to switch directly from outplace to inplace mode
bRet = !( xObject->getCurrentState() == embed::EmbedStates::ACTIVE || mpObj->GetAspect() == embed::Aspects::MSOLE_ICON );
} // if ( mpObj )
return bRet;
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::activatingInplace()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::activatingUI()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
SolarMutexGuard aGuard;
uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
uno::Reference < frame::XFrame > xOwnFrame( xFrame,uno::UNO_QUERY);
uno::Reference < frame::XFramesSupplier > xParentFrame( xOwnFrame->getCreator(), uno::UNO_QUERY );
if ( xParentFrame.is() )
xParentFrame->setActiveFrame( xOwnFrame );
OLEObjCache& rObjCache = GetSdrGlobalData().GetOLEObjCache();
const sal_uIntPtr nCount = rObjCache.size();
for(sal_Int32 i = nCount-1 ; i >= 0;--i)
{
SdrOle2Obj* pObj = rObjCache[i];
if ( pObj != mpObj )
{
// only deactivate ole objects which belongs to the same frame
if ( xFrame == lcl_getFrame_throw(pObj) )
{
uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
try
{
if ( xObject->getStatus( pObj->GetAspect() ) & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE )
xObject->changeState( embed::EmbedStates::INPLACE_ACTIVE );
else
{
// the links should not stay in running state for long time because of locking
uno::Reference< embed::XLinkageSupport > xLink( xObject, uno::UNO_QUERY );
if ( xLink.is() && xLink->isLink() )
xObject->changeState( embed::EmbedStates::LOADED );
else
xObject->changeState( embed::EmbedStates::RUNNING );
}
}
catch (com::sun::star::uno::Exception& )
{}
}
}
} // for(sal_Int32 i = nCount-1 ; i >= 0;--i)
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedInplace()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::deactivatedUI()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
SolarMutexGuard aGuard;
com::sun::star::uno::Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager(getLayoutManager());
if ( xLayoutManager.is() )
{
const static OUString aMenuBarURL( "private:resource/menubar/menubar" );
if ( !xLayoutManager->isElementVisible( aMenuBarURL ) )
xLayoutManager->createElement( aMenuBarURL );
}
}
//--------------------------------------------------------------------
uno::Reference< ::com::sun::star::frame::XLayoutManager > SAL_CALL SdrLightEmbeddedClient_Impl::getLayoutManager()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
uno::Reference< ::com::sun::star::frame::XLayoutManager > xMan;
SolarMutexGuard aGuard;
uno::Reference < beans::XPropertySet > xFrame( lcl_getFrame_throw(mpObj));
try
{
xMan.set(xFrame->getPropertyValue("LayoutManager"),uno::UNO_QUERY);
}
catch ( uno::Exception& )
{
throw uno::RuntimeException();
}
return xMan;
}
//--------------------------------------------------------------------
uno::Reference< frame::XDispatchProvider > SAL_CALL SdrLightEmbeddedClient_Impl::getInplaceDispatchProvider()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
SolarMutexGuard aGuard;
return uno::Reference < frame::XDispatchProvider >( lcl_getFrame_throw(mpObj), uno::UNO_QUERY_THROW );
}
//--------------------------------------------------------------------
awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getPlacement()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
SolarMutexGuard aGuard;
if ( !mpObj )
throw uno::RuntimeException();
Rectangle aLogicRect = impl_getScaledRect_nothrow();
MapUnit aContainerMapUnit( MAP_100TH_MM );
uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
if ( xParentVis.is() )
aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
aLogicRect = Application::GetDefaultDevice()->LogicToPixel(aLogicRect,aContainerMapUnit);
return AWTRectangle( aLogicRect );
}
//--------------------------------------------------------------------
awt::Rectangle SAL_CALL SdrLightEmbeddedClient_Impl::getClipRectangle()
throw ( embed::WrongStateException,
uno::RuntimeException )
{
return getPlacement();
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::translateAccelerators( const uno::Sequence< awt::KeyEvent >& /*aKeys*/ )
throw ( embed::WrongStateException,
uno::RuntimeException )
{
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::scrollObject( const awt::Size& /*aOffset*/ )
throw ( embed::WrongStateException,
uno::RuntimeException )
{
}
//--------------------------------------------------------------------
void SAL_CALL SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangle& aPosRect )
throw ( embed::WrongStateException,
uno::Exception,
uno::RuntimeException )
{
SolarMutexGuard aGuard;
if ( !mpObj )
throw uno::RuntimeException();
uno::Reference< embed::XInplaceObject > xInplace( mpObj->GetObjRef(), uno::UNO_QUERY );
if ( !xInplace.is() )
throw uno::RuntimeException();
// check if the change is at least one pixel in size
awt::Rectangle aOldRect = getPlacement();
Rectangle aNewPixelRect = VCLRectangle( aPosRect );
Rectangle aOldPixelRect = VCLRectangle( aOldRect );
if ( aOldPixelRect == aNewPixelRect )
// nothing has changed
return;
// new scaled object area
MapUnit aContainerMapUnit( MAP_100TH_MM );
uno::Reference< embed::XVisualObject > xParentVis( mpObj->GetParentXModel(), uno::UNO_QUERY );
if ( xParentVis.is() )
aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xParentVis->getMapUnit( mpObj->GetAspect() ) );
Rectangle aNewLogicRect = Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect,aContainerMapUnit);
Rectangle aLogicRect = impl_getScaledRect_nothrow();
if ( aNewLogicRect != aLogicRect )
{
// the calculation of the object area has not changed the object size
// it should be done here then
//SfxBooleanFlagGuard aGuard( m_bResizeNoScale, sal_True );
// new size of the object area without scaling
Size aNewObjSize( Fraction( aNewLogicRect.GetWidth() ) / m_aScaleWidth,
Fraction( aNewLogicRect.GetHeight() ) / m_aScaleHeight );
// now remove scaling from new placement and keep this a the new object area
aNewLogicRect.SetSize( aNewObjSize );
// react to the change if the difference is bigger than one pixel
Size aPixelDiff =
Application::GetDefaultDevice()->LogicToPixel(
Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
aLogicRect.GetHeight() - aNewObjSize.Height() ),
aContainerMapUnit );
if( aPixelDiff.Width() || aPixelDiff.Height() )
{
mpObj->SetLogicRect( Rectangle( aLogicRect.TopLeft(), aNewObjSize ) );
mpObj->BroadcastObjectChange();
}
else
mpObj->ActionChanged();
}
}
// XWindowSupplier
//--------------------------------------------------------------------
uno::Reference< awt::XWindow > SAL_CALL SdrLightEmbeddedClient_Impl::getWindow()
throw ( uno::RuntimeException )
{
SolarMutexGuard aGuard;
uno::Reference< awt::XWindow > xCurrent = m_xWindow;
if ( !xCurrent.is() )
{
if ( !mpObj )
throw uno::RuntimeException();
uno::Reference< frame::XFrame> xFrame(lcl_getFrame_throw(mpObj),uno::UNO_QUERY_THROW);
xCurrent = xFrame->getComponentWindow();
} // if ( !xCurrent.is() )
return xCurrent;
}
void SdrLightEmbeddedClient_Impl::setWindow(const uno::Reference< awt::XWindow >& _xWindow)
{
m_xWindow = _xWindow;
}
////////////////////////////////////////////////////////////////////////////////////////////////////
class SdrEmbedObjectLink : public sfx2::SvBaseLink
{
SdrOle2Obj* pObj;
public:
SdrEmbedObjectLink(SdrOle2Obj* pObj);
virtual ~SdrEmbedObjectLink();
virtual void Closed();
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
const OUString& rMimeType, const ::com::sun::star::uno::Any & rValue );
bool Connect() { return GetRealObject() != NULL; }
};
// -----------------------------------------------------------------------------
SdrEmbedObjectLink::SdrEmbedObjectLink(SdrOle2Obj* pObject):
::sfx2::SvBaseLink( ::sfx2::LINKUPDATE_ONCALL, SOT_FORMATSTR_ID_SVXB ),
pObj(pObject)
{
SetSynchron( sal_False );
}
// -----------------------------------------------------------------------------
SdrEmbedObjectLink::~SdrEmbedObjectLink()
{
}
// -----------------------------------------------------------------------------
::sfx2::SvBaseLink::UpdateResult SdrEmbedObjectLink::DataChanged(
const OUString& /*rMimeType*/, const ::com::sun::star::uno::Any & /*rValue*/ )
{
if ( !pObj->UpdateLinkURL_Impl() )
{
// the link URL was not changed
uno::Reference< embed::XEmbeddedObject > xObject = pObj->GetObjRef();
OSL_ENSURE( xObject.is(), "The object must exist always!\n" );
if ( xObject.is() )
{
// let the object reload the link
// TODO/LATER: reload call could be used for this case
try
{
sal_Int32 nState = xObject->getCurrentState();
if ( nState != embed::EmbedStates::LOADED )
{
// in some cases the linked file probably is not locked so it could be changed
xObject->changeState( embed::EmbedStates::LOADED );
xObject->changeState( nState );
}
}
catch ( uno::Exception& )
{
}
}
}
pObj->GetNewReplacement();
pObj->SetChanged();
return SUCCESS;
}
// -----------------------------------------------------------------------------
void SdrEmbedObjectLink::Closed()
{
pObj->BreakFileLink_Impl();
SvBaseLink::Closed();
}
////////////////////////////////////////////////////////////////////////////////////////////////////
class SdrOle2ObjImpl
{
public:
// TODO/LATER: do we really need this pointer?
GraphicObject* pGraphicObject;
OUString aPersistName; // name of object in persist
SdrLightEmbeddedClient_Impl* pLightClient; // must be registered as client only using AddOwnLightClient() call
// New local var to avoid repeated loading if load of OLE2 fails
bool mbLoadingOLEObjectFailed;
bool mbConnected;
SdrEmbedObjectLink* mpObjectLink;
OUString maLinkURL;
SdrOle2ObjImpl()
: pGraphicObject( NULL )
, pLightClient ( NULL )
// init to start situation, loading did not fail
, mbLoadingOLEObjectFailed( false )
, mbConnected( false )
, mpObjectLink( NULL )
{
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
// Predicate determining whether the given OLE is an internal math
// object
static bool ImplIsMathObj( const uno::Reference < embed::XEmbeddedObject >& rObjRef )
{
if ( !rObjRef.is() )
return false;
SvGlobalName aClassName( rObjRef->getClassID() );
if( aClassName == SvGlobalName(SO3_SM_CLASSID_30) ||
aClassName == SvGlobalName(SO3_SM_CLASSID_40) ||
aClassName == SvGlobalName(SO3_SM_CLASSID_50) ||
aClassName == SvGlobalName(SO3_SM_CLASSID_60) ||
aClassName == SvGlobalName(SO3_SM_CLASSID) )
{
return true;
}
else
{
return false;
}
}
//////////////////////////////////////////////////////////////////////////////
// BaseProperties section
sdr::properties::BaseProperties* SdrOle2Obj::CreateObjectSpecificProperties()
{
return new sdr::properties::OleProperties(*this);
}
//////////////////////////////////////////////////////////////////////////////
// DrawContact section
sdr::contact::ViewContact* SdrOle2Obj::CreateObjectSpecificViewContact()
{
return new sdr::contact::ViewContactOfSdrOle2Obj(*this);
}
// -----------------------------------------------------------------------------
TYPEINIT1(SdrOle2Obj,SdrRectObj);
DBG_NAME(SdrOle2Obj)
SdrOle2Obj::SdrOle2Obj(bool bFrame_) : m_bTypeAsked(false)
,m_bChart(false)
{
DBG_CTOR( SdrOle2Obj,NULL);
bInDestruction = false;
mbSuppressSetVisAreaSize = false;
Init();
bFrame=bFrame_;
}
// -----------------------------------------------------------------------------
SdrOle2Obj::SdrOle2Obj( const svt::EmbeddedObjectRef& rNewObjRef, const OUString& rNewObjName, const Rectangle& rNewRect, bool bFrame_)
: SdrRectObj(rNewRect)
, xObjRef( rNewObjRef )
, m_bTypeAsked(false)
, m_bChart(false)
{
DBG_CTOR( SdrOle2Obj,NULL);
bInDestruction = false;
mbSuppressSetVisAreaSize = false;
Init();
mpImpl->aPersistName = rNewObjName;
bFrame=bFrame_;
if ( xObjRef.is() && (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
SetResizeProtect(sal_True);
// For math objects, set closed state to transparent
SetClosedObj(!ImplIsMathObj( xObjRef.GetObject() ));
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::Init()
{
mpImpl = new SdrOle2ObjImpl;
pModifyListener = NULL;
pGraphic=NULL;
mpImpl->pGraphicObject=NULL;
mpImpl->pLightClient = 0;
xObjRef.Lock( sal_True );
}
// -----------------------------------------------------------------------------
SdrOle2Obj::~SdrOle2Obj()
{
DBG_DTOR( SdrOle2Obj,NULL);
bInDestruction = true;
if ( mpImpl->mbConnected )
Disconnect();
delete pGraphic;
delete mpImpl->pGraphicObject;
if(pModifyListener)
{
pModifyListener->invalidate();
pModifyListener->release();
}
DisconnectFileLink_Impl();
if ( mpImpl->pLightClient )
{
mpImpl->pLightClient->Release();
mpImpl->pLightClient = NULL;
}
delete mpImpl;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetAspect( sal_Int64 nAspect )
{
xObjRef.SetViewAspect( nAspect );
}
// -----------------------------------------------------------------------------
bool SdrOle2Obj::isInplaceActive() const
{
return xObjRef.is() && embed::EmbedStates::INPLACE_ACTIVE == xObjRef->getCurrentState();
}
// -----------------------------------------------------------------------------
bool SdrOle2Obj::isUiActive() const
{
return xObjRef.is() && embed::EmbedStates::UI_ACTIVE == xObjRef->getCurrentState();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetGraphic_Impl(const Graphic* pGrf)
{
if ( pGraphic )
{
delete pGraphic;
pGraphic = NULL;
delete mpImpl->pGraphicObject;
mpImpl->pGraphicObject = NULL;
}
if (pGrf!=NULL)
{
pGraphic = new Graphic(*pGrf);
mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
}
SetChanged();
BroadcastObjectChange();
}
void SdrOle2Obj::SetGraphic(const Graphic* pGrf)
{
// only for setting a preview graphic
SetGraphic_Impl( pGrf );
}
// -----------------------------------------------------------------------------
bool SdrOle2Obj::IsEmpty() const
{
return !(xObjRef.is());
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::Connect()
{
if( IsEmptyPresObj() )
return;
if( mpImpl->mbConnected )
{
// currently there are situations where it seems to be unavoidable to have multiple connects
// changing this would need a larger code rewrite, so for now I remove the assertion
// OSL_FAIL("Connect() called on connected object!");
return;
}
Connect_Impl();
AddListeners_Impl();
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::UpdateLinkURL_Impl()
{
sal_Bool bResult = sal_False;
if ( mpImpl->mpObjectLink )
{
sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
if ( pLinkManager )
{
OUString aNewLinkURL;
pLinkManager->GetDisplayNames( mpImpl->mpObjectLink, 0, &aNewLinkURL, 0, 0 );
if ( !aNewLinkURL.equalsIgnoreAsciiCase( mpImpl->maLinkURL ) )
{
const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObjRef.GetObject(), uno::UNO_QUERY );
OSL_ENSURE( xPersObj.is(), "The object must exist!\n" );
if ( xPersObj.is() )
{
try
{
sal_Int32 nCurState = xObjRef->getCurrentState();
if ( nCurState != embed::EmbedStates::LOADED )
xObjRef->changeState( embed::EmbedStates::LOADED );
// TODO/LATER: there should be possible to get current mediadescriptor settings from the object
uno::Sequence< beans::PropertyValue > aArgs( 1 );
aArgs[0].Name = "URL";
aArgs[0].Value <<= OUString( aNewLinkURL );
xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
mpImpl->maLinkURL = aNewLinkURL;
bResult = sal_True;
if ( nCurState != embed::EmbedStates::LOADED )
xObjRef->changeState( nCurState );
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::UpdateLinkURL_Impl(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
if ( !bResult )
{
// TODO/LATER: return the old name to the link manager, is it possible?
}
}
}
}
return bResult;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::BreakFileLink_Impl()
{
uno::Reference<document::XStorageBasedDocument> xDoc;
if ( pModel )
xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
if ( xDoc.is() )
{
uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
if ( xStorage.is() )
{
try
{
uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY_THROW );
xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
DisconnectFileLink_Impl();
mpImpl->maLinkURL = "";
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::BreakFileLink_Impl(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::DisconnectFileLink_Impl()
{
sfx2::LinkManager* pLinkManager = pModel ? pModel->GetLinkManager() : NULL;
if ( pLinkManager && mpImpl->mpObjectLink )
{
pLinkManager->Remove( mpImpl->mpObjectLink );
mpImpl->mpObjectLink = NULL;
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::CheckFileLink_Impl()
{
if ( pModel && xObjRef.GetObject().is() && !mpImpl->mpObjectLink )
{
try
{
uno::Reference< embed::XLinkageSupport > xLinkSupport( xObjRef.GetObject(), uno::UNO_QUERY );
if ( xLinkSupport.is() && xLinkSupport->isLink() )
{
OUString aLinkURL = xLinkSupport->getLinkURL();
if ( !aLinkURL.isEmpty() )
{
// this is a file link so the model link manager should handle it
sfx2::LinkManager* pLinkManager = pModel->GetLinkManager();
if ( pLinkManager )
{
mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
mpImpl->maLinkURL = aLinkURL;
pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL, NULL, NULL );
mpImpl->mpObjectLink->Connect();
}
}
}
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::CheckFileLink_Impl(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::Reconnect_Impl()
{
DBG_ASSERT( mpImpl->mbConnected, "Assigned unconnected object?!" );
Connect_Impl();
}
void SdrOle2Obj::Connect_Impl()
{
if( pModel && !mpImpl->aPersistName.isEmpty() )
{
try
{
::comphelper::IEmbeddedHelper* pPers = pModel->GetPersist();
if ( pPers )
{
comphelper::EmbeddedObjectContainer& rContainer = pPers->getEmbeddedObjectContainer();
if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
|| ( xObjRef.is() && !rContainer.HasEmbeddedObject( xObjRef.GetObject() ) ) )
{
// object not known to container document
// No object -> disaster!
DBG_ASSERT( xObjRef.is(), "No object in connect!");
if ( xObjRef.is() )
{
// object came from the outside, now add it to the container
OUString aTmp;
rContainer.InsertEmbeddedObject( xObjRef.GetObject(), aTmp );
mpImpl->aPersistName = aTmp;
}
}
else if ( !xObjRef.is() )
{
xObjRef.Assign( rContainer.GetEmbeddedObject( mpImpl->aPersistName ), xObjRef.GetViewAspect() );
m_bTypeAsked = false;
}
if ( xObjRef.GetObject().is() )
{
xObjRef.AssignToContainer( &rContainer, mpImpl->aPersistName );
mpImpl->mbConnected = true;
xObjRef.Lock( sal_True );
}
}
if ( xObjRef.is() )
{
if ( !mpImpl->pLightClient )
{
mpImpl->pLightClient = new SdrLightEmbeddedClient_Impl( this );
mpImpl->pLightClient->acquire();
}
xObjRef->addStateChangeListener( mpImpl->pLightClient );
xObjRef->addEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
if ( xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
CheckFileLink_Impl();
uno::Reference< container::XChild > xChild( xObjRef.GetObject(), uno::UNO_QUERY );
if( xChild.is() )
{
uno::Reference< uno::XInterface > xParent( pModel->getUnoModel());
if( xParent.is())
xChild->setParent( pModel->getUnoModel() );
}
}
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::Connect_Impl(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
//TODO/LATER: wait for definition of MiscStatus RESIZEONPRINTERCHANGE
//if ( xObjRef.is() && (*ppObjRef)->GetMiscStatus() & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
{
//TODO/LATER: needs a new handling for OnPrinterChanged
/*
if (pModel && pModel->GetRefDevice() &&
pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
{
// Kein RefDevice oder RefDevice kein Printer
sal_Bool bModified = (*ppObjRef)->IsModified();
Printer* pPrinter = (Printer*) pModel->GetRefDevice();
(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
(*ppObjRef)->SetModified( bModified );
}*/
}
}
void SdrOle2Obj::ObjectLoaded()
{
AddListeners_Impl();
}
void SdrOle2Obj::AddListeners_Impl()
{
if( xObjRef.is() && xObjRef->getCurrentState() != embed::EmbedStates::LOADED )
{
// register modify listener
if( !pModifyListener )
{
((SdrOle2Obj*)this)->pModifyListener = new SvxUnoShapeModifyListener( (SdrOle2Obj*)this );
pModifyListener->acquire();
}
uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
if( xBC.is() && pModifyListener )
{
uno::Reference< util::XModifyListener > xListener( pModifyListener );
xBC->addModifyListener( xListener );
}
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::Disconnect()
{
if( IsEmptyPresObj() )
return;
if( !mpImpl->mbConnected )
{
OSL_FAIL("Disconnect() called on disconnected object!");
return;
}
RemoveListeners_Impl();
Disconnect_Impl();
}
void SdrOle2Obj::RemoveListeners_Impl()
{
if( xObjRef.is() && !mpImpl->aPersistName.isEmpty() )
{
try
{
sal_Int32 nState = xObjRef->getCurrentState();
if ( nState != embed::EmbedStates::LOADED )
{
uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), uno::UNO_QUERY );
if( xBC.is() && pModifyListener )
{
uno::Reference< util::XModifyListener > xListener( pModifyListener );
xBC->removeModifyListener( xListener );
}
}
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::RemoveListeners_Impl(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
}
void SdrOle2Obj::Disconnect_Impl()
{
try
{
if ( pModel && !mpImpl->aPersistName.isEmpty() )
{
if( pModel->IsInDestruction() )
{
// TODO/LATER: here we must assume that the destruction of the model is enough to make clear that we will not
// remove the object from the container, even if the DrawingObject itself is not destroyed (unfortunately this
// There is no real need to do the following removing of the object from the container
// in case the model has correct persistence, but in case of problems such a removing
// would make the behavior of the office more stable
comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
if ( pContainer )
{
pContainer->CloseEmbeddedObject( xObjRef.GetObject() );
xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
}
// happens later than the destruction of the model, so we can't assert that).
//DBG_ASSERT( bInDestruction, "Model is destroyed, but not me?!" );
//TODO/LATER: should be make sure that the ObjectShell also forgets the object, because we will close it soon?
/*
uno::Reference < util::XCloseable > xClose( xObjRef, uno::UNO_QUERY );
if ( xClose.is() )
{
try
{
xClose->close( sal_True );
}
catch ( util::CloseVetoException& )
{
// there's still someone who needs the object!
}
}
xObjRef = NULL;*/
}
else if ( xObjRef.is() )
{
if ( pModel->getUnoModel().is() )
{
// remove object, but don't close it (that's up to someone else)
comphelper::EmbeddedObjectContainer* pContainer = xObjRef.GetContainer();
if ( pContainer )
{
pContainer->RemoveEmbeddedObject( xObjRef.GetObject(), sal_False);
// TODO/LATER: mpImpl->aPersistName contains outdated information, to keep it updated
// it should be returned from RemoveEmbeddedObject call. Currently it is no problem,
// since no container is adjusted, actually the empty string could be provided as a name here
xObjRef.AssignToContainer( NULL, mpImpl->aPersistName );
}
DisconnectFileLink_Impl();
}
}
}
if ( xObjRef.is() && mpImpl->pLightClient )
{
xObjRef->removeStateChangeListener ( mpImpl->pLightClient );
xObjRef->removeEventListener( uno::Reference< document::XEventListener >( mpImpl->pLightClient ) );
xObjRef->setClientSite( NULL );
GetSdrGlobalData().GetOLEObjCache().RemoveObj(this);
}
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::Disconnect_Impl(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
mpImpl->mbConnected = false;
}
// -----------------------------------------------------------------------------
SdrObject* SdrOle2Obj::createSdrGrafObjReplacement(bool bAddText, bool /* bUseHCGraphic */) const
{
const Graphic* pOLEGraphic = GetGraphic();
if(pOLEGraphic)
{
// #i118485# allow creating a SdrGrafObj representation
SdrGrafObj* pClone = new SdrGrafObj(*pOLEGraphic);
pClone->SetModel(GetModel());
// copy transformation
basegfx::B2DHomMatrix aMatrix;
basegfx::B2DPolyPolygon aPolyPolygon;
TRGetBaseGeometry(aMatrix, aPolyPolygon);
pClone->TRSetBaseGeometry(aMatrix, aPolyPolygon);
// copy all attributes to support graphic styles for OLEs
pClone->SetStyleSheet(GetStyleSheet(), false);
pClone->SetMergedItemSet(GetMergedItemSet());
if(bAddText)
{
// #i118485# copy text (Caution! Model needed, as guaranteed in aw080)
OutlinerParaObject* pOPO = GetOutlinerParaObject();
if(pOPO && GetModel())
{
pClone->NbcSetOutlinerParaObject(new OutlinerParaObject(*pOPO));
}
}
return pClone;
}
else
{
// #i100710# pOLEGraphic may be zero (no visualisation available),
// so we need to use the OLE replacement graphic
SdrRectObj* pClone = new SdrRectObj(GetSnapRect());
pClone->SetModel(GetModel());
// gray outline
pClone->SetMergedItem(XLineStyleItem(XLINE_SOLID));
const svtools::ColorConfig aColorConfig;
const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES));
pClone->SetMergedItem(XLineColorItem(OUString(), aColor.nColor));
// bitmap fill
pClone->SetMergedItem(XFillStyleItem(XFILL_BITMAP));
pClone->SetMergedItem(XFillBitmapItem(OUString(), GetEmptyOLEReplacementGraphic()));
pClone->SetMergedItem(XFillBmpTileItem(false));
pClone->SetMergedItem(XFillBmpStretchItem(false));
return pClone;
}
}
SdrObject* SdrOle2Obj::DoConvertToPolyObj(sal_Bool bBezier, bool bAddText) const
{
// #i118485# missing converter added
if(GetModel())
{
SdrObject* pRetval = createSdrGrafObjReplacement(true, false);
if(pRetval)
{
SdrObject* pRetval2 = pRetval->DoConvertToPolyObj(bBezier, bAddText);
SdrObject::Free(pRetval);
return pRetval2;
}
}
return 0;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetModel(SdrModel* pNewModel)
{
::comphelper::IEmbeddedHelper* pDestPers = pNewModel ? pNewModel->GetPersist() : 0;
::comphelper::IEmbeddedHelper* pSrcPers = pModel ? pModel->GetPersist() : 0;
if ( pNewModel == pModel )
{
// don't know if this is necessary or if it will ever happen, but who knows?!
SdrRectObj::SetModel( pNewModel );
return;
}
// assignment to model has changed
DBG_ASSERT( pSrcPers || !mpImpl->mbConnected, "Connected object without a model?!" );
DBG_ASSERT( pDestPers, "The destination model must have a persistence! Please submit an issue!" );
DBG_ASSERT( pDestPers != pSrcPers, "The source and the destination models should have different persistences! Problems are possible!" );
// this is a bug if the target model has no persistence
// no error handling is possible so just do nothing in this method
if ( !pDestPers )
return;
RemoveListeners_Impl();
if( pDestPers && pSrcPers && !IsEmptyPresObj() )
{
try
{
// move the object's storage; ObjectRef remains the same, but PersistName may change
OUString aTmp;
comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
DBG_ASSERT( !xObjRef.is() || xObjRef.GetObject() == xObj, "Wrong object identity!" );
if ( xObj.is() )
{
pDestPers->getEmbeddedObjectContainer().MoveEmbeddedObject( rContainer, xObj, aTmp );
mpImpl->aPersistName = aTmp;
xObjRef.AssignToContainer( &pDestPers->getEmbeddedObjectContainer(), aTmp );
}
DBG_ASSERT( !aTmp.isEmpty(), "Copying embedded object failed!" );
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::SetModel(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
SdrRectObj::SetModel( pNewModel );
// #i43086#
// #i85304 redo the change for charts for the above bugfix, as #i43086# does not occur anymore
//so maybe the ImpSetVisAreaSize call can be removed here completely
//Nevertheless I leave it in for other objects as I am not sure about the side effects when removing now
if( pModel && !pModel->isLocked() && !IsChart() )
ImpSetVisAreaSize();
if( pDestPers && !IsEmptyPresObj() )
{
if ( !pSrcPers || IsEmptyPresObj() )
// object wasn't connected, now it should be
Connect_Impl();
else
Reconnect_Impl();
}
AddListeners_Impl();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetPage(SdrPage* pNewPage)
{
bool bRemove=pNewPage==NULL && pPage!=NULL;
bool bInsert=pNewPage!=NULL && pPage==NULL;
if (bRemove && mpImpl->mbConnected )
Disconnect();
if(!pModel && !GetStyleSheet() && pNewPage->GetModel())
{
// #i119287# Set default StyleSheet for SdrGrafObj here, it is different from 'Default'. This
// needs to be done before the style 'Default' is set from the :SetModel() call which is triggered
// from the following :SetPage().
// TTTT: Needs to be moved in branch aw080 due to having a SdrModel from the beginning, is at this
// place for convenience currently (works in both versions, is not in the way)
SfxStyleSheet* pSheet = pNewPage->GetModel()->GetDefaultStyleSheetForSdrGrafObjAndSdrOle2Obj();
if(pSheet)
{
SetStyleSheet(pSheet, false);
}
else
{
SetMergedItem(XFillStyleItem(XFILL_NONE));
SetMergedItem(XLineStyleItem(XLINE_NONE));
}
}
SdrRectObj::SetPage(pNewPage);
if (bInsert && !mpImpl->mbConnected )
Connect();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetObjRef( const com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >& rNewObjRef )
{
DBG_ASSERT( !rNewObjRef.is() || !xObjRef.GetObject().is(), "SetObjRef called on already initialized object!");
if( rNewObjRef == xObjRef.GetObject() )
return;
// the caller of the method is responsible to control the old object, it will not be closed here
// Otherwise WW8 import crashes because it transfers control to OLENode by this method
if ( xObjRef.GetObject().is() )
xObjRef.Lock( sal_False );
// avoid removal of object in Disconnect! It is definitely a HACK to call SetObjRef(0)!
// This call will try to close the objects; so if anybody else wants to keep it, it must be locked by a CloseListener
xObjRef.Clear();
if ( mpImpl->mbConnected )
Disconnect();
xObjRef.Assign( rNewObjRef, GetAspect() );
m_bTypeAsked = false;
if ( xObjRef.is() )
{
DELETEZ( pGraphic );
if ( (xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::EMBED_NEVERRESIZE ) )
SetResizeProtect(sal_True);
// For math objects, set closed state to transparent
SetClosedObj(!ImplIsMathObj( rNewObjRef ));
Connect();
}
SetChanged();
BroadcastObjectChange();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetClosedObj( bool bIsClosed )
{
// TODO/LATER: do we still need this hack?
// Allow changes to the closed state of OLE objects
bClosedObj = bIsClosed;
}
// -----------------------------------------------------------------------------
SdrObject* SdrOle2Obj::getFullDragClone() const
{
// #i118485# use central replacement generator
return createSdrGrafObjReplacement(false, true);
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetPersistName( const OUString& rPersistName )
{
DBG_ASSERT( mpImpl->aPersistName.isEmpty(), "Persist name changed!");
mpImpl->aPersistName = rPersistName;
mpImpl->mbLoadingOLEObjectFailed = false;
Connect();
SetChanged();
}
void SdrOle2Obj::AbandonObject()
{
mpImpl->aPersistName = "";
mpImpl->mbLoadingOLEObjectFailed = false;
SetObjRef(0);
}
// -----------------------------------------------------------------------------
OUString SdrOle2Obj::GetPersistName() const
{
return mpImpl->aPersistName;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
{
// #i118485# Allowing much more attributes for OLEs
rInfo.bRotateFreeAllowed = true;
rInfo.bRotate90Allowed = true;
rInfo.bMirrorFreeAllowed = true;
rInfo.bMirror45Allowed = true;
rInfo.bMirror90Allowed = true;
rInfo.bTransparenceAllowed = true;
rInfo.bGradientAllowed = true;
rInfo.bShearAllowed = true;
rInfo.bEdgeRadiusAllowed = false;
rInfo.bNoOrthoDesired = false;
rInfo.bCanConvToPath = true;
rInfo.bCanConvToPoly = true;
rInfo.bCanConvToPathLineToArea = false;
rInfo.bCanConvToPolyLineToArea = false;
rInfo.bCanConvToContour = true;
}
// -----------------------------------------------------------------------------
sal_uInt16 SdrOle2Obj::GetObjIdentifier() const
{
return bFrame ? sal_uInt16(OBJ_FRAME) : sal_uInt16(OBJ_OLE2);
}
// -----------------------------------------------------------------------------
OUString SdrOle2Obj::TakeObjNameSingul() const
{
OUStringBuffer sName(ImpGetResStr(bFrame ? STR_ObjNameSingulFrame : STR_ObjNameSingulOLE2));
const OUString aName(GetName());
if (!aName.isEmpty())
{
sName.append(" '");
sName.append(aName);
sName.append('\'');
}
return sName.makeStringAndClear();
}
// -----------------------------------------------------------------------------
OUString SdrOle2Obj::TakeObjNamePlural() const
{
return ImpGetResStr(bFrame ? STR_ObjNamePluralFrame : STR_ObjNamePluralOLE2);
}
// -----------------------------------------------------------------------------
SdrOle2Obj* SdrOle2Obj::Clone() const
{
return CloneHelper< SdrOle2Obj >();
}
SdrOle2Obj& SdrOle2Obj::operator=(const SdrOle2Obj& rObj)
{
//TODO/LATER: who takes over control of my old object?!
if( &rObj != this )
{
// #116235#
// ImpAssign( rObj );
const SdrOle2Obj& rOle2Obj = static_cast< const SdrOle2Obj& >( rObj );
uno::Reference < util::XCloseable > xClose( xObjRef.GetObject(), uno::UNO_QUERY );
if( pModel && mpImpl->mbConnected )
Disconnect();
SdrRectObj::operator=( rObj );
// Manually copying bClosedObj attribute
SetClosedObj( rObj.IsClosedObj() );
mpImpl->aPersistName = rOle2Obj.mpImpl->aPersistName;
aProgName = rOle2Obj.aProgName;
bFrame = rOle2Obj.bFrame;
if( rOle2Obj.pGraphic )
{
if( pGraphic )
{
delete pGraphic;
delete mpImpl->pGraphicObject;
}
pGraphic = new Graphic( *rOle2Obj.pGraphic );
mpImpl->pGraphicObject = new GraphicObject( *pGraphic );
}
if( pModel && rObj.GetModel() && !IsEmptyPresObj() )
{
::comphelper::IEmbeddedHelper* pDestPers = pModel->GetPersist();
::comphelper::IEmbeddedHelper* pSrcPers = rObj.GetModel()->GetPersist();
if( pDestPers && pSrcPers )
{
DBG_ASSERT( !xObjRef.is(), "Object already existing!" );
comphelper::EmbeddedObjectContainer& rContainer = pSrcPers->getEmbeddedObjectContainer();
uno::Reference < embed::XEmbeddedObject > xObj = rContainer.GetEmbeddedObject( mpImpl->aPersistName );
if ( xObj.is() )
{
OUString aTmp;
xObjRef.Assign( pDestPers->getEmbeddedObjectContainer().CopyAndGetEmbeddedObject( rContainer, xObj, aTmp ), rOle2Obj.GetAspect() );
m_bTypeAsked = false;
mpImpl->aPersistName = aTmp;
CheckFileLink_Impl();
}
Connect();
}
}
}
return *this;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::ImpSetVisAreaSize()
{
// #i118524# do not again set VisAreaSize when the call comes from OLE client (e.g. ObjectAreaChanged)
if(mbSuppressSetVisAreaSize)
return;
// currently there is no need to recalculate scaling for iconified objects
// TODO/LATER: it might be needed in future when it is possible to change the icon
if ( GetAspect() == embed::Aspects::MSOLE_ICON )
return;
// the object area of an embedded object was changed, e.g. by user interaction an a selected object
GetObjRef();
if ( xObjRef.is() )
{
OSL_ASSERT( pModel );
sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
// the client is required to get access to scaling
SfxInPlaceClient* pClient = SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() );
bool bHasOwnClient =
( mpImpl->pLightClient
&& xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) );
if ( pClient || bHasOwnClient )
{
// TODO: IMHO we need to do similar things when object is UIActive or OutplaceActive?!
if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ))
|| xObjRef->getCurrentState() == embed::EmbedStates::INPLACE_ACTIVE
)
{
Fraction aScaleWidth;
Fraction aScaleHeight;
if ( pClient )
{
aScaleWidth = pClient->GetScaleWidth();
aScaleHeight = pClient->GetScaleHeight();
}
else
{
aScaleWidth = mpImpl->pLightClient->GetScaleWidth();
aScaleHeight = mpImpl->pLightClient->GetScaleHeight();
}
// The object wants to resize itself (f.e. Chart wants to recalculate the layout)
// or object is inplace active and so has a window that must be resized also
// In these cases the change in the object area size will be reflected in a change of the
// objects' visual area. The scaling will not change, but it might exist already and must
// be used in calculations
MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
Size aVisSize( (long)( Fraction( aRect.GetWidth() ) / aScaleWidth ),
(long)( Fraction( aRect.GetHeight() ) / aScaleHeight ) );
aVisSize = OutputDevice::LogicToLogic( aVisSize, pModel->GetScaleUnit(), aMapUnit);
awt::Size aSz;
aSz.Width = aVisSize.Width();
aSz.Height = aVisSize.Height();
xObjRef->setVisualAreaSize( GetAspect(), aSz );
try
{
aSz = xObjRef->getVisualAreaSize( GetAspect() );
}
catch( embed::NoVisualAreaSizeException& )
{}
Rectangle aAcceptedVisArea;
aAcceptedVisArea.SetSize( Size( (long)( Fraction( long( aSz.Width ) ) * aScaleWidth ),
(long)( Fraction( long( aSz.Height ) ) * aScaleHeight ) ) );
if (aVisSize != aAcceptedVisArea.GetSize())
{
// server changed VisArea to its liking and the VisArea is different than the suggested one
// store the new value as given by the object
MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
aRect.SetSize(OutputDevice::LogicToLogic( aAcceptedVisArea.GetSize(), aNewMapUnit, pModel->GetScaleUnit()));
}
// make the new object area known to the client
// compared to the "else" branch aRect might have been changed by the object and no additional scaling was applied
// WHY this -> OSL_ASSERT( pClient );
if( pClient )
pClient->SetObjArea(aRect);
// we need a new replacement image as the object has resized itself
//#i79578# don't request a new replacement image for charts to often
//a chart sends a modified call to the framework if it was changed
//thus the replacement update is already handled there
if( !IsChart() )
xObjRef.UpdateReplacement();
}
else
{
// The object isn't active and does not want to resize itself so the changed object area size
// will be reflected in a changed object scaling
Fraction aScaleWidth;
Fraction aScaleHeight;
Size aObjAreaSize;
if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
{
if ( pClient )
{
Rectangle aScaleRect(aRect.TopLeft(), aObjAreaSize);
pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, aScaleHeight);
}
else
{
mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
}
}
}
}
else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
svt::EmbeddedObjectRef::TryRunningState( xObjRef.GetObject() ) )
{
//also handle not sfx based ole objects e.g. charts
//#i83860# resizing charts in impress distorts fonts
uno::Reference< embed::XVisualObject > xVisualObject( this->getXModel(), uno::UNO_QUERY );
if( xVisualObject.is() )
{
MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObjRef->getMapUnit( GetAspect() ) );
Point aTL( aRect.TopLeft() );
Point aBR( aRect.BottomRight() );
Point aTL2( OutputDevice::LogicToLogic( aTL, pModel->GetScaleUnit(), aMapUnit) );
Point aBR2( OutputDevice::LogicToLogic( aBR, pModel->GetScaleUnit(), aMapUnit) );
Rectangle aNewRect( aTL2, aBR2 );
xVisualObject->setVisualAreaSize( GetAspect(), awt::Size( aNewRect.GetWidth(), aNewRect.GetHeight() ) );
}
}
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
{
if( pModel && !pModel->isLocked() )
{
GetObjRef();
if ( xObjRef.is() && ( xObjRef->getStatus( GetAspect() ) & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE ) )
{
// if the object needs recompose on resize
// the client site should be created before the resize will take place
// check whether there is no client site and create it if necessary
AddOwnLightClient();
}
}
SdrRectObj::NbcResize(rRef,xFact,yFact);
if( pModel && !pModel->isLocked() )
ImpSetVisAreaSize();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetGeoData(const SdrObjGeoData& rGeo)
{
SdrRectObj::SetGeoData(rGeo);
if( pModel && !pModel->isLocked() )
ImpSetVisAreaSize();
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::NbcSetSnapRect(const Rectangle& rRect)
{
SdrRectObj::NbcSetSnapRect(rRect);
if( pModel && !pModel->isLocked() )
ImpSetVisAreaSize();
if ( xObjRef.is() && IsChart() )
{
//#i103460# charts do not necessarily have an own size within ODF files,
//for this case they need to use the size settings from the surrounding frame,
//which is made available with this method as there is no other way
xObjRef.SetDefaultSizeForChart( Size( rRect.GetWidth(), rRect.GetHeight() ) );
}
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
{
SdrRectObj::NbcSetLogicRect(rRect);
if( pModel && !pModel->isLocked() )
ImpSetVisAreaSize();
}
const Graphic* SdrOle2Obj::GetGraphic() const
{
if ( xObjRef.is() )
return xObjRef.GetGraphic();
return pGraphic;
}
void SdrOle2Obj::GetNewReplacement()
{
if ( xObjRef.is() )
xObjRef.UpdateReplacement();
}
// -----------------------------------------------------------------------------
Size SdrOle2Obj::GetOrigObjSize( MapMode* pTargetMapMode ) const
{
return xObjRef.GetSize( pTargetMapMode );
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::NbcMove(const Size& rSize)
{
SdrRectObj::NbcMove(rSize);
if( pModel && !pModel->isLocked() )
ImpSetVisAreaSize();
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::CanUnloadRunningObj( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
{
sal_Bool bResult = sal_False;
sal_Int32 nState = xObj->getCurrentState();
if ( nState == embed::EmbedStates::LOADED )
{
// the object is already unloaded
bResult = sal_True;
}
else
{
uno::Reference < util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
if ( !xModifiable.is() )
bResult = sal_True;
else
{
sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
if ( embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) &&
!( xModifiable.is() && xModifiable->isModified() ) &&
!( nState == embed::EmbedStates::INPLACE_ACTIVE || nState == embed::EmbedStates::UI_ACTIVE || nState == embed::EmbedStates::ACTIVE ) )
{
bResult = sal_True;
}
}
}
return bResult;
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::Unload( const uno::Reference< embed::XEmbeddedObject >& xObj, sal_Int64 nAspect )
{
sal_Bool bResult = sal_False;
if ( CanUnloadRunningObj( xObj, nAspect ) )
{
try
{
xObj->changeState( embed::EmbedStates::LOADED );
bResult = sal_True;
}
catch( ::com::sun::star::uno::Exception& )
{
OSL_FAIL(
OString(OString("SdrOle2Obj::Unload=(), "
"exception caught: ") +
OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 )).getStr() );
}
}
return bResult;
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::Unload()
{
sal_Bool bUnloaded = sal_False;
if( xObjRef.is() )
{
//TODO/LATER: no refcounting tricks anymore!
//"customers" must register as state change listeners
// Not necessary in Doc DTor (MM)
//sal_uIntPtr nRefCount = (*ppObjRef)->GetRefCount();
// prevent Unload if there are external references
//if( nRefCount > 2 )
// return sal_False;
//DBG_ASSERT( nRefCount == 2, "Wrong RefCount for unload" );
}
else
bUnloaded = sal_True;
if ( pModel && xObjRef.is() )
{
bUnloaded = Unload( xObjRef.GetObject(), GetAspect() );
}
return bUnloaded;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::GetObjRef_Impl()
{
if ( !xObjRef.is() && !mpImpl->aPersistName.isEmpty() && pModel && pModel->GetPersist() )
{
// Only try loading if it did not went wrong up to now
if(!mpImpl->mbLoadingOLEObjectFailed)
{
xObjRef.Assign( pModel->GetPersist()->getEmbeddedObjectContainer().GetEmbeddedObject( mpImpl->aPersistName ), GetAspect() );
m_bTypeAsked = false;
CheckFileLink_Impl();
// If loading of OLE object failed, remember that to not invoke a endless
// loop trying to load it again and again.
if( xObjRef.is() )
{
mpImpl->mbLoadingOLEObjectFailed = true;
}
// For math objects, set closed state to transparent
SetClosedObj(!ImplIsMathObj( xObjRef.GetObject() ));
}
if ( xObjRef.is() )
{
if( !IsEmptyPresObj() )
{
// remember modified status of model
const sal_Bool bWasChanged(pModel ? pModel->IsChanged() : sal_False);
// perhaps preview not valid anymore
// This line changes the modified state of the model
SetGraphic_Impl( NULL );
// if status was not set before, force it back
// to not set, so that SetGraphic(0L) above does not
// set the modified state of the model.
if(!bWasChanged && pModel && pModel->IsChanged())
{
pModel->SetChanged( sal_False );
}
}
sal_Int64 nMiscStatus = xObjRef->getStatus( GetAspect() );
(void)nMiscStatus;
//TODO/LATER: wait until ResizeOnPrinterChange is defined
//if ( nMiscStatus & SVOBJ_MISCSTATUS_RESIZEONPRINTERCHANGE )
{
if (pModel && pModel->GetRefDevice() &&
pModel->GetRefDevice()->GetOutDevType() == OUTDEV_PRINTER)
{
if(!bInDestruction)
{
//TODO/LATER: printerchange notification
/*
// prevent SetModified (don't want no update here)
sal_Bool bWasEnabled = (*ppObjRef)->IsEnableSetModified();
if ( bWasEnabled )
(*ppObjRef)->EnableSetModified( sal_False );
// Kein RefDevice oder RefDevice kein Printer
Printer* pPrinter = (Printer*) pModel->GetRefDevice();
(*ppObjRef)->OnDocumentPrinterChanged( pPrinter );
// reset state
(*ppObjRef)->EnableSetModified( bWasEnabled );*/
}
}
}
}
if ( xObjRef.is() )
Connect();
}
if ( mpImpl->mbConnected )
// move object to first position in cache
GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
}
uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef() const
{
const_cast<SdrOle2Obj*>(this)->GetObjRef_Impl();
return xObjRef.GetObject();
}
uno::Reference < embed::XEmbeddedObject > SdrOle2Obj::GetObjRef_NoInit() const
{
return xObjRef.GetObject();
}
// -----------------------------------------------------------------------------
uno::Reference< frame::XModel > SdrOle2Obj::getXModel() const
{
GetObjRef();
if ( svt::EmbeddedObjectRef::TryRunningState(xObjRef.GetObject()) )
return uno::Reference< frame::XModel >( xObjRef->getComponent(), uno::UNO_QUERY );
else
return uno::Reference< frame::XModel >();
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::IsChart() const
{
if ( !m_bTypeAsked )
{
m_bChart = ChartHelper::IsChart(xObjRef);
m_bTypeAsked = true;
}
return m_bChart;
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetGraphicToObj( const Graphic& aGraphic, const OUString& aMediaType )
{
xObjRef.SetGraphic( aGraphic, aMediaType );
}
// -----------------------------------------------------------------------------
void SdrOle2Obj::SetGraphicToObj( const uno::Reference< io::XInputStream >& xGrStream, const OUString& aMediaType )
{
xObjRef.SetGraphicStream( xGrStream, aMediaType );
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::IsCalc() const
{
if ( !xObjRef.is() )
return false;
SvGlobalName aObjClsId( xObjRef->getClassID() );
if( SvGlobalName(SO3_SC_CLASSID_30) == aObjClsId
|| SvGlobalName(SO3_SC_CLASSID_40) == aObjClsId
|| SvGlobalName(SO3_SC_CLASSID_50) == aObjClsId
|| SvGlobalName(SO3_SC_CLASSID_60) == aObjClsId
|| SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_60) == aObjClsId
|| SvGlobalName(SO3_SC_OLE_EMBED_CLASSID_8) == aObjClsId
|| SvGlobalName(SO3_SC_CLASSID) == aObjClsId )
{
return sal_True;
}
return sal_False;
}
// -----------------------------------------------------------------------------
uno::Reference< frame::XModel > SdrOle2Obj::GetParentXModel() const
{
uno::Reference< frame::XModel > xDoc;
if ( pModel )
xDoc.set( pModel->getUnoModel(),uno::UNO_QUERY);
return xDoc;
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::CalculateNewScaling( Fraction& aScaleWidth, Fraction& aScaleHeight, Size& aObjAreaSize )
{
// TODO/LEAN: to avoid rounding errors scaling always uses the VisArea.
// If we don't cache it for own objects also we must load the object here
if ( !xObjRef.is() || !pModel )
return sal_False;
MapMode aMapMode( pModel->GetScaleUnit() );
aObjAreaSize = xObjRef.GetSize( &aMapMode );
Size aSize = aRect.GetSize();
aScaleWidth = Fraction(aSize.Width(), aObjAreaSize.Width() );
aScaleHeight = Fraction(aSize.Height(), aObjAreaSize.Height() );
// reduce to 10 binary digits
Kuerzen(aScaleHeight, 10);
Kuerzen(aScaleWidth, 10);
return sal_True;
}
// -----------------------------------------------------------------------------
sal_Bool SdrOle2Obj::AddOwnLightClient()
{
// The Own Light Client must be registered in object only using this method!
if ( !SfxInPlaceClient::GetClient( dynamic_cast<SfxObjectShell*>(pModel->GetPersist()), xObjRef.GetObject() )
&& !( mpImpl->pLightClient && xObjRef->getClientSite() == uno::Reference< embed::XEmbeddedClient >( mpImpl->pLightClient ) ) )
{
Connect();
if ( xObjRef.is() && mpImpl->pLightClient )
{
Fraction aScaleWidth;
Fraction aScaleHeight;
Size aObjAreaSize;
if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize ) )
{
mpImpl->pLightClient->SetSizeScale( aScaleWidth, aScaleHeight );
try {
xObjRef->setClientSite( mpImpl->pLightClient );
return sal_True;
} catch( uno::Exception& )
{}
}
}
return sal_False;
}
return sal_True;
}
//////////////////////////////////////////////////////////////////////////////
Graphic SdrOle2Obj::GetEmptyOLEReplacementGraphic()
{
return Graphic(BitmapEx(ResId(BMP_SVXOLEOBJ, *ImpGetResMgr())));
}
//////////////////////////////////////////////////////////////////////////////
void SdrOle2Obj::SetWindow(const com::sun::star::uno::Reference < com::sun::star::awt::XWindow >& _xWindow)
{
if ( xObjRef.is() && mpImpl->pLightClient )
{
mpImpl->pLightClient->setWindow(_xWindow);
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|