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 | /* -*- 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 <vcl/settings.hxx>
#include "PresenterSlideSorter.hxx"
#include "PresenterButton.hxx"
#include "PresenterCanvasHelper.hxx"
#include "PresenterGeometryHelper.hxx"
#include "PresenterPaintManager.hxx"
#include "PresenterPaneBase.hxx"
#include "PresenterScrollBar.hxx"
#include "PresenterUIPainter.hxx"
#include "PresenterWindowManager.hxx"
#include <com/sun/star/drawing/framework/XConfigurationController.hpp>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <com/sun/star/rendering/XBitmapCanvas.hpp>
#include <com/sun/star/rendering/CompositeOperation.hpp>
#include <com/sun/star/rendering/TextDirection.hpp>
#include <algorithm>
#include <math.h>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::drawing::framework;
namespace {
const static sal_Int32 gnVerticalGap (10);
const static sal_Int32 gnVerticalBorder (10);
const static sal_Int32 gnHorizontalGap (10);
const static sal_Int32 gnHorizontalBorder (10);
const static double gnMinimalPreviewWidth (200);
const static double gnPreferredPreviewWidth (300);
const static double gnMaximalPreviewWidth (400);
const static sal_Int32 gnPreferredColumnCount (6);
const static double gnMinimalHorizontalPreviewGap(15);
const static double gnPreferredHorizontalPreviewGap(25);
const static double gnMaximalHorizontalPreviewGap(50);
const static double gnPreferredVerticalPreviewGap(25);
const static sal_Int32 gnHorizontalLabelBorder (3);
const static sal_Int32 gnHorizontalLabelPadding (5);
const static sal_Int32 gnVerticalButtonPadding (gnVerticalGap);
}
namespace sdext::presenter {
namespace {
sal_Int32 round (const double nValue) { return sal::static_int_cast<sal_Int32>(0.5 + nValue); }
sal_Int32 floor (const double nValue) { return sal::static_int_cast<sal_Int32>(nValue); }
}
//===== PresenterSlideSorter::Layout ==========================================
class PresenterSlideSorter::Layout
{
public:
explicit Layout (const ::rtl::Reference<PresenterScrollBar>& rpVerticalScrollBar);
void Update (const geometry::RealRectangle2D& rBoundingBox, const double nSlideAspectRatio);
void SetupVisibleArea();
void UpdateScrollBars();
bool IsScrollBarNeeded (const sal_Int32 nSlideCount);
geometry::RealPoint2D GetLocalPosition (const geometry::RealPoint2D& rWindowPoint) const;
geometry::RealPoint2D GetWindowPosition(const geometry::RealPoint2D& rLocalPoint) const;
sal_Int32 GetColumn (const geometry::RealPoint2D& rLocalPoint) const;
sal_Int32 GetRow (const geometry::RealPoint2D& rLocalPoint,
const bool bReturnInvalidValue = false) const;
sal_Int32 GetSlideIndexForPosition (const css::geometry::RealPoint2D& rPoint) const;
css::geometry::RealPoint2D GetPoint (
const sal_Int32 nSlideIndex,
const sal_Int32 nRelativeHorizontalPosition,
const sal_Int32 nRelativeVerticalPosition) const;
css::awt::Rectangle GetBoundingBox (const sal_Int32 nSlideIndex) const;
void ForAllVisibleSlides (const ::std::function<void (sal_Int32)>& rAction);
sal_Int32 GetFirstVisibleSlideIndex() const;
sal_Int32 GetLastVisibleSlideIndex() const;
bool SetHorizontalOffset (const double nOffset);
bool SetVerticalOffset (const double nOffset);
css::geometry::RealRectangle2D maBoundingBox;
css::geometry::IntegerSize2D maPreviewSize;
sal_Int32 mnHorizontalOffset;
sal_Int32 mnVerticalOffset;
sal_Int32 mnHorizontalGap;
sal_Int32 mnVerticalGap;
sal_Int32 mnHorizontalBorder;
sal_Int32 mnVerticalBorder;
sal_Int32 mnRowCount;
sal_Int32 mnColumnCount;
sal_Int32 mnSlideCount;
sal_Int32 mnFirstVisibleColumn;
sal_Int32 mnLastVisibleColumn;
sal_Int32 mnFirstVisibleRow;
sal_Int32 mnLastVisibleRow;
private:
::rtl::Reference<PresenterScrollBar> mpVerticalScrollBar;
sal_Int32 GetIndex (const sal_Int32 nRow, const sal_Int32 nColumn) const;
sal_Int32 GetRow (const sal_Int32 nSlideIndex) const;
sal_Int32 GetColumn (const sal_Int32 nSlideIndex) const;
};
//==== PresenterSlideSorter::MouseOverManager =================================
class PresenterSlideSorter::MouseOverManager
{
public:
MouseOverManager (
const Reference<container::XIndexAccess>& rxSlides,
const std::shared_ptr<PresenterTheme>& rpTheme,
const Reference<awt::XWindow>& rxInvalidateTarget,
const std::shared_ptr<PresenterPaintManager>& rpPaintManager);
MouseOverManager(const MouseOverManager&) = delete;
MouseOverManager& operator=(const MouseOverManager&) = delete;
void Paint (
const sal_Int32 nSlideIndex,
const Reference<rendering::XCanvas>& rxCanvas,
const Reference<rendering::XPolyPolygon2D>& rxClip);
void SetSlide (
const sal_Int32 nSlideIndex,
const awt::Rectangle& rBox);
private:
Reference<rendering::XCanvas> mxCanvas;
const Reference<container::XIndexAccess> mxSlides;
SharedBitmapDescriptor mpLeftLabelBitmap;
SharedBitmapDescriptor mpCenterLabelBitmap;
SharedBitmapDescriptor mpRightLabelBitmap;
PresenterTheme::SharedFontDescriptor mpFont;
sal_Int32 mnSlideIndex;
awt::Rectangle maSlideBoundingBox;
OUString msText;
Reference<rendering::XBitmap> mxBitmap;
Reference<awt::XWindow> mxInvalidateTarget;
std::shared_ptr<PresenterPaintManager> mpPaintManager;
void SetCanvas (
const Reference<rendering::XCanvas>& rxCanvas);
/** Create a bitmap that shows the given text and is not wider than the
given maximal width.
*/
Reference<rendering::XBitmap> CreateBitmap (
const OUString& rsText,
const sal_Int32 nMaximalWidth) const;
void Invalidate();
geometry::IntegerSize2D CalculateLabelSize (
const OUString& rsText) const;
OUString GetFittingText (const OUString& rsText, const double nMaximalWidth) const;
void PaintButtonBackground (
const Reference<rendering::XCanvas>& rxCanvas,
const geometry::IntegerSize2D& rSize) const;
};
//==== PresenterSlideSorter::CurrentSlideFrameRenderer ========================
class PresenterSlideSorter::CurrentSlideFrameRenderer
{
public:
CurrentSlideFrameRenderer (
const css::uno::Reference<css::uno::XComponentContext>& rxContext,
const css::uno::Reference<css::rendering::XCanvas>& rxCanvas);
void PaintCurrentSlideFrame (
const awt::Rectangle& rSlideBoundingBox,
const Reference<rendering::XCanvas>& rxCanvas,
const geometry::RealRectangle2D& rClipBox);
/** Enlarge the given rectangle to include the current slide indicator.
*/
awt::Rectangle GetBoundingBox (
const awt::Rectangle& rSlideBoundingBox);
private:
SharedBitmapDescriptor mpTopLeft;
SharedBitmapDescriptor mpTop;
SharedBitmapDescriptor mpTopRight;
SharedBitmapDescriptor mpLeft;
SharedBitmapDescriptor mpRight;
SharedBitmapDescriptor mpBottomLeft;
SharedBitmapDescriptor mpBottom;
SharedBitmapDescriptor mpBottomRight;
sal_Int32 mnTopFrameSize;
sal_Int32 mnLeftFrameSize;
sal_Int32 mnRightFrameSize;
sal_Int32 mnBottomFrameSize;
static void PaintBitmapOnce(
const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
const Reference<rendering::XPolyPolygon2D>& rxClip,
const double nX,
const double nY);
static void PaintBitmapTiled(
const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
const geometry::RealRectangle2D& rClipBox,
const double nX,
const double nY,
const double nWidth,
const double nHeight);
};
//===== PresenterSlideSorter ==================================================
PresenterSlideSorter::PresenterSlideSorter (
const Reference<uno::XComponentContext>& rxContext,
const Reference<XResourceId>& rxViewId,
const Reference<frame::XController>& rxController,
const ::rtl::Reference<PresenterController>& rpPresenterController)
: PresenterSlideSorterInterfaceBase(m_aMutex),
mxComponentContext(rxContext),
mxViewId(rxViewId),
mxPane(),
mxCanvas(),
mxWindow(),
mpPresenterController(rpPresenterController),
mxSlideShowController(mpPresenterController->GetSlideShowController()),
mxPreviewCache(),
mbIsLayoutPending(true),
mpLayout(),
mpVerticalScrollBar(),
mpCloseButton(),
mpMouseOverManager(),
mnSlideIndexMousePressed(-1),
mnCurrentSlideIndex(-1),
mnSeparatorY(0),
maSeparatorColor(0x00ffffff),
maCurrentSlideFrameBoundingBox(),
mpCurrentSlideFrameRenderer(),
mxPreviewFrame()
{
if ( ! rxContext.is()
|| ! rxViewId.is()
|| ! rxController.is()
|| ! rpPresenterController)
{
throw lang::IllegalArgumentException();
}
if ( ! mxSlideShowController.is())
throw RuntimeException();
try
{
// Get pane and window.
Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
Reference<XConfigurationController> xCC (
xCM->getConfigurationController(), UNO_SET_THROW);
Reference<lang::XMultiComponentFactory> xFactory (
mxComponentContext->getServiceManager(), UNO_SET_THROW);
mxPane.set(xCC->getResource(rxViewId->getAnchor()), UNO_QUERY_THROW);
mxWindow = mxPane->getWindow();
// Add window listener.
mxWindow->addWindowListener(this);
mxWindow->addPaintListener(this);
mxWindow->addMouseListener(this);
mxWindow->addMouseMotionListener(this);
mxWindow->setVisible(true);
// Remember the current slide.
mnCurrentSlideIndex = mxSlideShowController->getCurrentSlideIndex();
// Create the scroll bar.
mpVerticalScrollBar.set(
new PresenterVerticalScrollBar(
rxContext,
mxWindow,
mpPresenterController->GetPaintManager(),
[this] (double const offset) { return this->SetVerticalOffset(offset); }));
mpCloseButton = PresenterButton::Create(
rxContext,
mpPresenterController,
mpPresenterController->GetTheme(),
mxWindow,
mxCanvas,
"SlideSorterCloser");
if (mpPresenterController->GetTheme() != nullptr)
{
PresenterTheme::SharedFontDescriptor pFont (
mpPresenterController->GetTheme()->GetFont("ButtonFont"));
if (pFont)
maSeparatorColor = pFont->mnColor;
}
// Create the layout.
mpLayout = std::make_shared<Layout>(mpVerticalScrollBar);
// Create the preview cache.
mxPreviewCache.set(
xFactory->createInstanceWithContext(
"com.sun.star.drawing.PresenterPreviewCache",
mxComponentContext),
UNO_QUERY_THROW);
Reference<container::XIndexAccess> xSlides (mxSlideShowController, UNO_QUERY);
mxPreviewCache->setDocumentSlides(xSlides, rxController->getModel());
mxPreviewCache->addPreviewCreationNotifyListener(this);
if (xSlides.is())
{
mpLayout->mnSlideCount = xSlides->getCount();
}
// Create the mouse over manager.
mpMouseOverManager.reset(new MouseOverManager(
Reference<container::XIndexAccess>(mxSlideShowController, UNO_QUERY),
mpPresenterController->GetTheme(),
mxWindow,
mpPresenterController->GetPaintManager()));
// Listen for changes of the current slide.
Reference<beans::XPropertySet> xControllerProperties (rxController, UNO_QUERY_THROW);
xControllerProperties->addPropertyChangeListener(
"CurrentPage",
this);
// Move the current slide in the center of the window.
const awt::Rectangle aCurrentSlideBBox (mpLayout->GetBoundingBox(mnCurrentSlideIndex));
const awt::Rectangle aWindowBox (mxWindow->getPosSize());
SetHorizontalOffset(aCurrentSlideBBox.X - aWindowBox.Width/2.0);
}
catch (RuntimeException&)
{
disposing();
throw;
}
}
PresenterSlideSorter::~PresenterSlideSorter()
{
}
void SAL_CALL PresenterSlideSorter::disposing()
{
mxComponentContext = nullptr;
mxViewId = nullptr;
mxPane = nullptr;
if (mpVerticalScrollBar.is())
{
Reference<lang::XComponent> xComponent (
static_cast<XWeak*>(mpVerticalScrollBar.get()), UNO_QUERY);
mpVerticalScrollBar = nullptr;
if (xComponent.is())
xComponent->dispose();
}
if (mpCloseButton.is())
{
Reference<lang::XComponent> xComponent (
static_cast<XWeak*>(mpCloseButton.get()), UNO_QUERY);
mpCloseButton = nullptr;
if (xComponent.is())
xComponent->dispose();
}
if (mxCanvas.is())
{
Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
if (xComponent.is())
xComponent->removeEventListener(static_cast<awt::XWindowListener*>(this));
mxCanvas = nullptr;
}
mpPresenterController = nullptr;
mxSlideShowController = nullptr;
mpLayout.reset();
mpMouseOverManager.reset();
if (mxPreviewCache.is())
{
mxPreviewCache->removePreviewCreationNotifyListener(this);
Reference<XComponent> xComponent (mxPreviewCache, UNO_QUERY);
mxPreviewCache = nullptr;
if (xComponent.is())
xComponent->dispose();
}
if (mxWindow.is())
{
mxWindow->removeWindowListener(this);
mxWindow->removePaintListener(this);
mxWindow->removeMouseListener(this);
mxWindow->removeMouseMotionListener(this);
}
}
//----- lang::XEventListener --------------------------------------------------
void SAL_CALL PresenterSlideSorter::disposing (const lang::EventObject& rEventObject)
{
if (rEventObject.Source == mxWindow)
{
mxWindow = nullptr;
dispose();
}
else if (rEventObject.Source == mxPreviewCache)
{
mxPreviewCache = nullptr;
dispose();
}
else if (rEventObject.Source == mxCanvas)
{
mxCanvas = nullptr;
mbIsLayoutPending = true;
mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
}
}
//----- XWindowListener -------------------------------------------------------
void SAL_CALL PresenterSlideSorter::windowResized (const awt::WindowEvent&)
{
ThrowIfDisposed();
mbIsLayoutPending = true;
mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
}
void SAL_CALL PresenterSlideSorter::windowMoved (const awt::WindowEvent&)
{
ThrowIfDisposed();
}
void SAL_CALL PresenterSlideSorter::windowShown (const lang::EventObject&)
{
ThrowIfDisposed();
mbIsLayoutPending = true;
mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
}
void SAL_CALL PresenterSlideSorter::windowHidden (const lang::EventObject&)
{
ThrowIfDisposed();
}
//----- XPaintListener --------------------------------------------------------
void SAL_CALL PresenterSlideSorter::windowPaint (const css::awt::PaintEvent& rEvent)
{
// Deactivated views must not be painted.
if ( ! mbIsPresenterViewActive)
return;
Paint(rEvent.UpdateRect);
Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
if (xSpriteCanvas.is())
xSpriteCanvas->updateScreen(false);
}
//----- XMouseListener --------------------------------------------------------
void SAL_CALL PresenterSlideSorter::mousePressed (const css::awt::MouseEvent& rEvent)
{
css::awt::MouseEvent rTemp =rEvent;
/// check whether RTL interface or not
if(AllSettings::GetLayoutRTL()){
awt::Rectangle aBox = mxWindow->getPosSize();
rTemp.X=aBox.Width-rEvent.X;
}
const geometry::RealPoint2D aPosition(rTemp.X, rEvent.Y);
mnSlideIndexMousePressed = mpLayout->GetSlideIndexForPosition(aPosition);
}
void SAL_CALL PresenterSlideSorter::mouseReleased (const css::awt::MouseEvent& rEvent)
{
css::awt::MouseEvent rTemp =rEvent;
/// check whether RTL interface or not
if(AllSettings::GetLayoutRTL()){
awt::Rectangle aBox = mxWindow->getPosSize();
rTemp.X=aBox.Width-rEvent.X;
}
const geometry::RealPoint2D aPosition(rTemp.X, rEvent.Y);
const sal_Int32 nSlideIndex (mpLayout->GetSlideIndexForPosition(aPosition));
if (nSlideIndex != mnSlideIndexMousePressed || mnSlideIndexMousePressed < 0)
return;
switch (rEvent.ClickCount)
{
case 1:
default:
GotoSlide(nSlideIndex);
break;
case 2:
OSL_ASSERT(mpPresenterController);
OSL_ASSERT(mpPresenterController->GetWindowManager());
mpPresenterController->GetWindowManager()->SetSlideSorterState(false);
GotoSlide(nSlideIndex);
break;
}
}
void SAL_CALL PresenterSlideSorter::mouseEntered (const css::awt::MouseEvent&) {}
void SAL_CALL PresenterSlideSorter::mouseExited (const css::awt::MouseEvent&)
{
mnSlideIndexMousePressed = -1;
if (mpMouseOverManager != nullptr)
mpMouseOverManager->SetSlide(mnSlideIndexMousePressed, awt::Rectangle(0,0,0,0));
}
//----- XMouseMotionListener --------------------------------------------------
void SAL_CALL PresenterSlideSorter::mouseMoved (const css::awt::MouseEvent& rEvent)
{
if (mpMouseOverManager == nullptr)
return;
css::awt::MouseEvent rTemp =rEvent;
/// check whether RTL interface or not
if(AllSettings::GetLayoutRTL()){
awt::Rectangle aBox = mxWindow->getPosSize();
rTemp.X=aBox.Width-rEvent.X;
}
const geometry::RealPoint2D aPosition(rTemp.X, rEvent.Y);
sal_Int32 nSlideIndex (mpLayout->GetSlideIndexForPosition(aPosition));
if (nSlideIndex < 0)<--- First condition
mnSlideIndexMousePressed = -1;
if (nSlideIndex < 0)<--- Second condition
{
mpMouseOverManager->SetSlide(nSlideIndex, awt::Rectangle(0,0,0,0));
}
else
{
mpMouseOverManager->SetSlide(
nSlideIndex,
mpLayout->GetBoundingBox(nSlideIndex));
}
}
void SAL_CALL PresenterSlideSorter::mouseDragged (const css::awt::MouseEvent&) {}
//----- XResourceId -----------------------------------------------------------
Reference<XResourceId> SAL_CALL PresenterSlideSorter::getResourceId()
{
ThrowIfDisposed();
return mxViewId;
}
sal_Bool SAL_CALL PresenterSlideSorter::isAnchorOnly()
{
return false;
}
//----- XPropertyChangeListener -----------------------------------------------
void SAL_CALL PresenterSlideSorter::propertyChange (
const css::beans::PropertyChangeEvent&)
{}
//----- XSlidePreviewCacheListener --------------------------------------------
void SAL_CALL PresenterSlideSorter::notifyPreviewCreation (
sal_Int32 nSlideIndex)
{
OSL_ASSERT(mpLayout != nullptr);
awt::Rectangle aBBox (mpLayout->GetBoundingBox(nSlideIndex));
mpPresenterController->GetPaintManager()->Invalidate(mxWindow, aBBox, true);
}
//----- XDrawView -------------------------------------------------------------
void SAL_CALL PresenterSlideSorter::setCurrentPage (const Reference<drawing::XDrawPage>&)
{
ThrowIfDisposed();
::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex());
if (!mxSlideShowController.is())
return;
const sal_Int32 nNewCurrentSlideIndex (mxSlideShowController->getCurrentSlideIndex());
if (nNewCurrentSlideIndex == mnCurrentSlideIndex)
return;
mnCurrentSlideIndex = nNewCurrentSlideIndex;
// Request a repaint of the previous current slide to hide its
// current slide indicator.
mpPresenterController->GetPaintManager()->Invalidate(
mxWindow,
maCurrentSlideFrameBoundingBox);
// Request a repaint of the new current slide to show its
// current slide indicator.
maCurrentSlideFrameBoundingBox = mpCurrentSlideFrameRenderer->GetBoundingBox(
mpLayout->GetBoundingBox(mnCurrentSlideIndex));
mpPresenterController->GetPaintManager()->Invalidate(
mxWindow,
maCurrentSlideFrameBoundingBox);
}
Reference<drawing::XDrawPage> SAL_CALL PresenterSlideSorter::getCurrentPage()
{
ThrowIfDisposed();
return nullptr;
}
void PresenterSlideSorter::UpdateLayout()
{
if ( ! mxWindow.is())
return;
mbIsLayoutPending = false;
const awt::Rectangle aWindowBox (mxWindow->getPosSize());
sal_Int32 nLeftBorderWidth (aWindowBox.X);
// Get border width.
PresenterPaneContainer::SharedPaneDescriptor pPane (
mpPresenterController->GetPaneContainer()->FindViewURL(
mxViewId->getResourceURL()));
do
{
if (!pPane)
break;
if ( ! pPane->mxPane.is())
break;
Reference<drawing::framework::XPaneBorderPainter> xBorderPainter (
pPane->mxPane->GetPaneBorderPainter());
if ( ! xBorderPainter.is())
break;
xBorderPainter->addBorder (
mxViewId->getAnchor()->getResourceURL(),
awt::Rectangle(0, 0, aWindowBox.Width, aWindowBox.Height),
drawing::framework::BorderType_INNER_BORDER);
}
while(false);
// Place vertical separator.
mnSeparatorY = aWindowBox.Height - mpCloseButton->GetSize().Height - gnVerticalButtonPadding;
PlaceCloseButton(pPane, aWindowBox, nLeftBorderWidth);
geometry::RealRectangle2D aUpperBox(
gnHorizontalBorder,
gnVerticalBorder,
aWindowBox.Width - 2*gnHorizontalBorder,
mnSeparatorY - gnVerticalGap);
// Determine whether the scroll bar has to be displayed.
aUpperBox = PlaceScrollBars(aUpperBox);
mpLayout->Update(aUpperBox, GetSlideAspectRatio());
mpLayout->SetupVisibleArea();
mpLayout->UpdateScrollBars();
// Tell the preview cache about some of the values.
mxPreviewCache->setPreviewSize(mpLayout->maPreviewSize);
mxPreviewCache->setVisibleRange(
mpLayout->GetFirstVisibleSlideIndex(),
mpLayout->GetLastVisibleSlideIndex());
// Clear the frame polygon so that it is re-created on the next paint.
mxPreviewFrame = nullptr;
}
geometry::RealRectangle2D PresenterSlideSorter::PlaceScrollBars (
const geometry::RealRectangle2D& rUpperBox)
{
mpLayout->Update(rUpperBox, GetSlideAspectRatio());
bool bIsScrollBarNeeded (false);
Reference<container::XIndexAccess> xSlides (mxSlideShowController, UNO_QUERY_THROW);
bIsScrollBarNeeded = mpLayout->IsScrollBarNeeded(xSlides->getCount());
if (mpVerticalScrollBar)
{
if (bIsScrollBarNeeded)
{
if(AllSettings::GetLayoutRTL())
{
mpVerticalScrollBar->SetPosSize(geometry::RealRectangle2D(
rUpperBox.X1,
rUpperBox.Y1,
rUpperBox.X1 + mpVerticalScrollBar->GetSize(),
rUpperBox.Y2));
mpVerticalScrollBar->SetVisible(true);
// Reduce area covered by the scroll bar from the available
// space.
return geometry::RealRectangle2D(
rUpperBox.X1 + gnHorizontalGap + mpVerticalScrollBar->GetSize(),
rUpperBox.Y1,
rUpperBox.X2,
rUpperBox.Y2);
}
else
{
// if it's not RTL place vertical scroll bar at right border.
mpVerticalScrollBar->SetPosSize(geometry::RealRectangle2D(
rUpperBox.X2 - mpVerticalScrollBar->GetSize(),
rUpperBox.Y1,
rUpperBox.X2,
rUpperBox.Y2));
mpVerticalScrollBar->SetVisible(true);
// Reduce area covered by the scroll bar from the available
// space.
return geometry::RealRectangle2D(
rUpperBox.X1,
rUpperBox.Y1,
rUpperBox.X2 - mpVerticalScrollBar->GetSize() - gnHorizontalGap,
rUpperBox.Y2);
}
}
else
mpVerticalScrollBar->SetVisible(false);
}
return rUpperBox;
}
void PresenterSlideSorter::PlaceCloseButton (
const PresenterPaneContainer::SharedPaneDescriptor& rpPane,
const awt::Rectangle& rCenterBox,
const sal_Int32 nLeftBorderWidth)
{
// Place button. When the callout is near the center then the button is
// centered over the callout. Otherwise it is centered with respect to
// the whole window.
sal_Int32 nCloseButtonCenter (rCenterBox.Width/2);
if (rpPane && rpPane->mxPane.is())
{
const sal_Int32 nCalloutCenter (-nLeftBorderWidth);
const sal_Int32 nDistanceFromWindowCenter (abs(nCalloutCenter - rCenterBox.Width/2));
const sal_Int32 nButtonWidth (mpCloseButton->GetSize().Width);
const static sal_Int32 nMaxDistanceForCalloutCentering (nButtonWidth * 2);
if (nDistanceFromWindowCenter < nMaxDistanceForCalloutCentering)
{
if (nCalloutCenter < nButtonWidth/2)
nCloseButtonCenter = nButtonWidth/2;
else if (nCalloutCenter > rCenterBox.Width-nButtonWidth/2)
nCloseButtonCenter = rCenterBox.Width-nButtonWidth/2;
else
nCloseButtonCenter = nCalloutCenter;
}
}
mpCloseButton->SetCenter(geometry::RealPoint2D(
nCloseButtonCenter,
rCenterBox.Height - mpCloseButton->GetSize().Height/ 2));
}
void PresenterSlideSorter::ClearBackground (
const Reference<rendering::XCanvas>& rxCanvas,
const awt::Rectangle& rUpdateBox)
{
OSL_ASSERT(rxCanvas.is());
const awt::Rectangle aWindowBox (mxWindow->getPosSize());
mpPresenterController->GetCanvasHelper()->Paint(
mpPresenterController->GetViewBackground(mxViewId->getResourceURL()),
rxCanvas,
rUpdateBox,
awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height),
awt::Rectangle());
}
double PresenterSlideSorter::GetSlideAspectRatio() const
{
double nSlideAspectRatio (28.0/21.0);
try
{
Reference<container::XIndexAccess> xSlides(mxSlideShowController, UNO_QUERY_THROW);
if (mxSlideShowController.is() && xSlides->getCount()>0)
{
Reference<beans::XPropertySet> xProperties(xSlides->getByIndex(0),UNO_QUERY_THROW);
sal_Int32 nWidth (28000);
sal_Int32 nHeight (21000);
if ((xProperties->getPropertyValue("Width") >>= nWidth)
&& (xProperties->getPropertyValue("Height") >>= nHeight)
&& nHeight > 0)
{
nSlideAspectRatio = double(nWidth) / double(nHeight);
}
}
}
catch (RuntimeException&)
{
OSL_ASSERT(false);
}
return nSlideAspectRatio;
}
Reference<rendering::XBitmap> PresenterSlideSorter::GetPreview (const sal_Int32 nSlideIndex)
{
if (nSlideIndex < 0 || nSlideIndex>=mpLayout->mnSlideCount)
return nullptr;
else if (mxPane.is())
return mxPreviewCache->getSlidePreview(nSlideIndex, mxPane->getCanvas());
else
return nullptr;
}
void PresenterSlideSorter::PaintPreview (
const Reference<rendering::XCanvas>& rxCanvas,
const css::awt::Rectangle& rUpdateBox,
const sal_Int32 nSlideIndex)
{
OSL_ASSERT(rxCanvas.is());
geometry::IntegerSize2D aSize (mpLayout->maPreviewSize);
if (PresenterGeometryHelper::AreRectanglesDisjoint(
rUpdateBox,
mpLayout->GetBoundingBox(nSlideIndex)))
{
return;
}
Reference<rendering::XBitmap> xPreview (GetPreview(nSlideIndex));
bool isRTL = AllSettings::GetLayoutRTL();
const geometry::RealPoint2D aTopLeft (
mpLayout->GetWindowPosition(
mpLayout->GetPoint(nSlideIndex, isRTL?1:-1, -1)));
PresenterBitmapContainer aContainer (
"PresenterScreenSettings/ScrollBar/Bitmaps",
std::shared_ptr<PresenterBitmapContainer>(),
mxComponentContext,
rxCanvas);
Reference<container::XIndexAccess> xIndexAccess(mxSlideShowController, UNO_QUERY);
Reference<drawing::XDrawPage> xPage( xIndexAccess->getByIndex(nSlideIndex), UNO_QUERY);
bool bTransition = PresenterController::HasTransition(xPage);
bool bCustomAnimation = PresenterController::HasCustomAnimation(xPage);
// Create clip rectangle as intersection of the current update area and
// the bounding box of all previews.
geometry::RealRectangle2D aBoundingBox (mpLayout->maBoundingBox);
aBoundingBox.Y2 += 1;
const geometry::RealRectangle2D aClipBox (
PresenterGeometryHelper::Intersection(
PresenterGeometryHelper::ConvertRectangle(rUpdateBox),
aBoundingBox));
Reference<rendering::XPolyPolygon2D> xClip (
PresenterGeometryHelper::CreatePolygon(aClipBox, rxCanvas->getDevice()));
const rendering::ViewState aViewState (geometry::AffineMatrix2D(1,0,0, 0,1,0), xClip);
rendering::RenderState aRenderState (
geometry::AffineMatrix2D(
1, 0, aTopLeft.X,
0, 1, aTopLeft.Y),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE);
// Emphasize the current slide.
if (nSlideIndex == mnCurrentSlideIndex)
{
if (mpCurrentSlideFrameRenderer != nullptr)
{
const awt::Rectangle aSlideBoundingBox(
sal::static_int_cast<sal_Int32>(0.5 + aTopLeft.X),
sal::static_int_cast<sal_Int32>(0.5 + aTopLeft.Y),
aSize.Width,
aSize.Height);
maCurrentSlideFrameBoundingBox
= mpCurrentSlideFrameRenderer->GetBoundingBox(aSlideBoundingBox);
mpCurrentSlideFrameRenderer->PaintCurrentSlideFrame (
aSlideBoundingBox,
mxCanvas,
aClipBox);
}
}
// Paint the preview.
if (xPreview.is())
{
aSize = xPreview->getSize();
if (aSize.Width > 0 && aSize.Height > 0)
{
rxCanvas->drawBitmap(xPreview, aViewState, aRenderState);
if( bCustomAnimation )
{
const awt::Rectangle aAnimationPreviewBox(aTopLeft.X+3, aTopLeft.Y+aSize.Height-40, 0, 0);
SharedBitmapDescriptor aAnimationDescriptor = aContainer.GetBitmap("Animation");
Reference<rendering::XBitmap> xAnimationIcon (aAnimationDescriptor->GetNormalBitmap());
rendering::RenderState aAnimationRenderState (
geometry::AffineMatrix2D(
1, 0, aAnimationPreviewBox.X,
0, 1, aAnimationPreviewBox.Y),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE);
rxCanvas->drawBitmap(xAnimationIcon, aViewState, aAnimationRenderState);
}
if( bTransition )
{
const awt::Rectangle aTransitionPreviewBox(aTopLeft.X+3, aTopLeft.Y+aSize.Height-20, 0, 0);
SharedBitmapDescriptor aTransitionDescriptor = aContainer.GetBitmap("Transition");
Reference<rendering::XBitmap> xTransitionIcon (aTransitionDescriptor->GetNormalBitmap());
rendering::RenderState aTransitionRenderState (
geometry::AffineMatrix2D(
1, 0, aTransitionPreviewBox.X,
0, 1, aTransitionPreviewBox.Y),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE);
rxCanvas->drawBitmap(xTransitionIcon, aViewState, aTransitionRenderState);
}
}
}
// Create a polygon that is used to paint a frame around previews. Its
// coordinates are chosen in the local coordinate system of a preview.
if ( ! mxPreviewFrame.is())
mxPreviewFrame = PresenterGeometryHelper::CreatePolygon(
awt::Rectangle(-1, -1, aSize.Width+2, aSize.Height+2),
rxCanvas->getDevice());
// Paint a border around the preview.
if (mxPreviewFrame.is())
{
const util::Color aFrameColor (0x00000000);
PresenterCanvasHelper::SetDeviceColor(aRenderState, aFrameColor);
rxCanvas->drawPolyPolygon(mxPreviewFrame, aViewState, aRenderState);
}
// Paint mouse over effect.
mpMouseOverManager->Paint(nSlideIndex, mxCanvas, xClip);
}
void PresenterSlideSorter::Paint (const awt::Rectangle& rUpdateBox)
{
const bool bCanvasChanged ( ! mxCanvas.is());
if ( ! ProvideCanvas())
return;
if (mpLayout->mnRowCount<=0 || mpLayout->mnColumnCount<=0)
{
OSL_ASSERT(mpLayout->mnRowCount>0 || mpLayout->mnColumnCount>0);
return;
}
ClearBackground(mxCanvas, rUpdateBox);
// Give the canvas to the controls.
if (bCanvasChanged)
{
if (mpVerticalScrollBar.is())
mpVerticalScrollBar->SetCanvas(mxCanvas);
if (mpCloseButton.is())
mpCloseButton->SetCanvas(mxCanvas, mxWindow);
}
// Now that the controls have a canvas we can do the layouting.
if (mbIsLayoutPending)
UpdateLayout();
// Paint the horizontal separator.
rendering::RenderState aRenderState (geometry::AffineMatrix2D(1,0,0, 0,1,0),
nullptr, Sequence<double>(4), rendering::CompositeOperation::SOURCE);
PresenterCanvasHelper::SetDeviceColor(aRenderState, maSeparatorColor);
mxCanvas->drawLine(
geometry::RealPoint2D(0, mnSeparatorY),
geometry::RealPoint2D(mxWindow->getPosSize().Width, mnSeparatorY),
rendering::ViewState(geometry::AffineMatrix2D(1,0,0, 0,1,0), nullptr),
aRenderState);
// Paint the slides.
if ( ! PresenterGeometryHelper::AreRectanglesDisjoint(
rUpdateBox,
PresenterGeometryHelper::ConvertRectangle(mpLayout->maBoundingBox)))
{
mpLayout->ForAllVisibleSlides(
[this, &rUpdateBox] (sal_Int32 const nIndex) {
return this->PaintPreview(this->mxCanvas, rUpdateBox, nIndex);
});
}
Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY);
if (xSpriteCanvas.is())
xSpriteCanvas->updateScreen(false);
}
void PresenterSlideSorter::SetHorizontalOffset (const double nXOffset)
{
if (mpLayout->SetHorizontalOffset(nXOffset))
{
mxPreviewCache->setVisibleRange(
mpLayout->GetFirstVisibleSlideIndex(),
mpLayout->GetLastVisibleSlideIndex());
mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
}
}
void PresenterSlideSorter::SetVerticalOffset (const double nYOffset)
{
if (mpLayout->SetVerticalOffset(nYOffset))
{
mxPreviewCache->setVisibleRange(
mpLayout->GetFirstVisibleSlideIndex(),
mpLayout->GetLastVisibleSlideIndex());
mpPresenterController->GetPaintManager()->Invalidate(mxWindow);
}
}
void PresenterSlideSorter::GotoSlide (const sal_Int32 nSlideIndex)
{
mxSlideShowController->gotoSlideIndex(nSlideIndex);
}
bool PresenterSlideSorter::ProvideCanvas()
{
if ( ! mxCanvas.is())
{
if (mxPane.is())
mxCanvas = mxPane->getCanvas();
// Register as event listener so that we are informed when the
// canvas is disposed (and we have to fetch another one).
Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY);
if (xComponent.is())
xComponent->addEventListener(static_cast<awt::XWindowListener*>(this));
mpCurrentSlideFrameRenderer =
std::make_shared<CurrentSlideFrameRenderer>(mxComponentContext, mxCanvas);
}
return mxCanvas.is();
}
void PresenterSlideSorter::ThrowIfDisposed()
{
if (rBHelper.bDisposed || rBHelper.bInDispose)
{
throw lang::DisposedException (
"PresenterSlideSorter has been already disposed",
static_cast<uno::XWeak*>(this));
}
}
//===== PresenterSlideSorter::Layout ==========================================
PresenterSlideSorter::Layout::Layout (
const ::rtl::Reference<PresenterScrollBar>& rpVerticalScrollBar)
: maBoundingBox(),
maPreviewSize(),
mnHorizontalOffset(0),
mnVerticalOffset(0),
mnHorizontalGap(0),
mnVerticalGap(0),
mnHorizontalBorder(0),
mnVerticalBorder(0),
mnRowCount(1),
mnColumnCount(1),
mnSlideCount(0),
mnFirstVisibleColumn(-1),
mnLastVisibleColumn(-1),
mnFirstVisibleRow(-1),
mnLastVisibleRow(-1),
mpVerticalScrollBar(rpVerticalScrollBar)
{
}
void PresenterSlideSorter::Layout::Update (
const geometry::RealRectangle2D& rBoundingBox,
const double nSlideAspectRatio)
{
maBoundingBox = rBoundingBox;
mnHorizontalBorder = gnHorizontalBorder;
mnVerticalBorder = gnVerticalBorder;
const double nWidth (rBoundingBox.X2 - rBoundingBox.X1 - 2*mnHorizontalBorder);
const double nHeight (rBoundingBox.Y2 - rBoundingBox.Y1 - 2*mnVerticalBorder);
if (nWidth<=0 || nHeight<=0)
return;
double nPreviewWidth;
// Determine column count, preview width, and horizontal gap (borders
// are half the gap). Try to use the preferred values. Try more to
// stay in the valid intervals. This last constraint may be not
// fulfilled in some cases.
const double nElementWidth = nWidth / gnPreferredColumnCount;
if (nElementWidth < gnMinimalPreviewWidth + gnMinimalHorizontalPreviewGap)
{
// The preferred column count is too large.
// Can we use the preferred preview width?
if (nWidth - gnMinimalHorizontalPreviewGap >= gnPreferredPreviewWidth)
{
// Yes.
nPreviewWidth = gnPreferredPreviewWidth;
mnColumnCount = floor((nWidth+gnPreferredHorizontalPreviewGap)
/ (nPreviewWidth+gnPreferredHorizontalPreviewGap));
mnHorizontalGap = round((nWidth - mnColumnCount*nPreviewWidth) / mnColumnCount);
}
else
{
// No. Set the column count to 1 and adapt preview width and
// gap.
mnColumnCount = 1;
mnHorizontalGap = floor(gnMinimalHorizontalPreviewGap);
if (nWidth - gnMinimalHorizontalPreviewGap >= gnPreferredPreviewWidth)
nPreviewWidth = nWidth - gnMinimalHorizontalPreviewGap;
else
nPreviewWidth = ::std::max(gnMinimalPreviewWidth, nWidth-mnHorizontalGap);
}
}
else if (nElementWidth > gnMaximalPreviewWidth + gnMaximalHorizontalPreviewGap)
{
// The preferred column count is too small.
nPreviewWidth = gnPreferredPreviewWidth;
mnColumnCount = floor((nWidth+gnPreferredHorizontalPreviewGap)
/ (nPreviewWidth+gnPreferredHorizontalPreviewGap));
mnHorizontalGap = round((nWidth - mnColumnCount*nPreviewWidth) / mnColumnCount);
}
else
{
// The preferred column count is possible. Determine gap and
// preview width.
mnColumnCount = gnPreferredColumnCount;
if (nElementWidth - gnPreferredPreviewWidth < gnMinimalHorizontalPreviewGap)
{
// Use the minimal gap and adapt the preview width.
mnHorizontalGap = floor(gnMinimalHorizontalPreviewGap);
nPreviewWidth = (nWidth - mnColumnCount*mnHorizontalGap) / mnColumnCount;
}
else if (nElementWidth - gnPreferredPreviewWidth <= gnMaximalHorizontalPreviewGap)
{
// Use the maximal gap and adapt the preview width.
mnHorizontalGap = round(gnMaximalHorizontalPreviewGap);
nPreviewWidth = (nWidth - mnColumnCount*mnHorizontalGap) / mnColumnCount;
}
else
{
// Use the preferred preview width and adapt the gap.
nPreviewWidth = gnPreferredPreviewWidth;
mnHorizontalGap = round((nWidth - mnColumnCount*nPreviewWidth) / mnColumnCount);
}
}
// Now determine the row count, preview height, and vertical gap.
const double nPreviewHeight = nPreviewWidth / nSlideAspectRatio;
mnRowCount = ::std::max(
sal_Int32(1),
sal_Int32(ceil((nHeight+gnPreferredVerticalPreviewGap)
/ (nPreviewHeight + gnPreferredVerticalPreviewGap))));
mnVerticalGap = round(gnPreferredVerticalPreviewGap);
maPreviewSize = geometry::IntegerSize2D(floor(nPreviewWidth), floor(nPreviewHeight));
// Reset the offset.
mnVerticalOffset = 0;
mnHorizontalOffset = round(-(nWidth
- mnColumnCount*maPreviewSize.Width
- (mnColumnCount-1)*mnHorizontalGap)
/ 2);
}
void PresenterSlideSorter::Layout::SetupVisibleArea()
{
geometry::RealPoint2D aPoint (GetLocalPosition(
geometry::RealPoint2D(maBoundingBox.X1, maBoundingBox.Y1)));
mnFirstVisibleColumn = 0;
mnFirstVisibleRow = ::std::max(sal_Int32(0), GetRow(aPoint));
aPoint = GetLocalPosition(geometry::RealPoint2D( maBoundingBox.X2, maBoundingBox.Y2));
mnLastVisibleColumn = mnColumnCount - 1;
mnLastVisibleRow = GetRow(aPoint, true);
}
bool PresenterSlideSorter::Layout::IsScrollBarNeeded (const sal_Int32 nSlideCount)
{
geometry::RealPoint2D aBottomRight = GetPoint(
mnColumnCount * (GetRow(nSlideCount)+1) - 1, +1, +1);
return aBottomRight.X > maBoundingBox.X2-maBoundingBox.X1
|| aBottomRight.Y > maBoundingBox.Y2-maBoundingBox.Y1;
}
geometry::RealPoint2D PresenterSlideSorter::Layout::GetLocalPosition(
const geometry::RealPoint2D& rWindowPoint) const
{
if(AllSettings::GetLayoutRTL())
{
return css::geometry::RealPoint2D(
-rWindowPoint.X + maBoundingBox.X2 + mnHorizontalOffset,
rWindowPoint.Y - maBoundingBox.Y1 + mnVerticalOffset);
}
else
{
return css::geometry::RealPoint2D(
rWindowPoint.X - maBoundingBox.X1 + mnHorizontalOffset,
rWindowPoint.Y - maBoundingBox.Y1 + mnVerticalOffset);
}
}
geometry::RealPoint2D PresenterSlideSorter::Layout::GetWindowPosition(
const geometry::RealPoint2D& rLocalPoint) const
{
if(AllSettings::GetLayoutRTL())
{
return css::geometry::RealPoint2D(
-rLocalPoint.X + mnHorizontalOffset + maBoundingBox.X2,
rLocalPoint.Y - mnVerticalOffset + maBoundingBox.Y1);
}
else
{
return css::geometry::RealPoint2D(
rLocalPoint.X - mnHorizontalOffset + maBoundingBox.X1,
rLocalPoint.Y - mnVerticalOffset + maBoundingBox.Y1);
}
}
sal_Int32 PresenterSlideSorter::Layout::GetColumn (
const css::geometry::RealPoint2D& rLocalPoint) const
{
const sal_Int32 nColumn(floor(
(rLocalPoint.X + mnHorizontalGap/2.0) / (maPreviewSize.Width+mnHorizontalGap)));
if (nColumn>=mnFirstVisibleColumn && nColumn<=mnLastVisibleColumn)
{
return nColumn;
}
else
return -1;
}
sal_Int32 PresenterSlideSorter::Layout::GetRow (
const css::geometry::RealPoint2D& rLocalPoint,
const bool bReturnInvalidValue) const
{
const sal_Int32 nRow (floor(
(rLocalPoint.Y + mnVerticalGap/2.0) / (maPreviewSize.Height+mnVerticalGap)));
if (bReturnInvalidValue
|| (nRow>=mnFirstVisibleRow && nRow<=mnLastVisibleRow))
{
return nRow;
}
else
return -1;
}
sal_Int32 PresenterSlideSorter::Layout::GetSlideIndexForPosition (
const css::geometry::RealPoint2D& rWindowPoint) const
{
if ( ! PresenterGeometryHelper::IsInside(maBoundingBox, rWindowPoint))
return -1;
const css::geometry::RealPoint2D aLocalPosition (GetLocalPosition(rWindowPoint));
const sal_Int32 nColumn (GetColumn(aLocalPosition));
const sal_Int32 nRow (GetRow(aLocalPosition));
if (nColumn < 0 || nRow < 0)
return -1;
else
{
sal_Int32 nIndex (GetIndex(nRow, nColumn));
if (nIndex >= mnSlideCount)
return -1;
else
return nIndex;
}
}
geometry::RealPoint2D PresenterSlideSorter::Layout::GetPoint (
const sal_Int32 nSlideIndex,
const sal_Int32 nRelativeHorizontalPosition,
const sal_Int32 nRelativeVerticalPosition) const
{
sal_Int32 nColumn (GetColumn(nSlideIndex));
sal_Int32 nRow (GetRow(nSlideIndex));
geometry::RealPoint2D aPosition (
mnHorizontalBorder + nColumn*(maPreviewSize.Width+mnHorizontalGap),
mnVerticalBorder + nRow*(maPreviewSize.Height+mnVerticalGap));
if (nRelativeHorizontalPosition >= 0)
{
if (nRelativeHorizontalPosition > 0)
aPosition.X += maPreviewSize.Width;
else
aPosition.X += maPreviewSize.Width / 2.0;
}
if (nRelativeVerticalPosition >= 0)
{
if (nRelativeVerticalPosition > 0)
aPosition.Y += maPreviewSize.Height;
else
aPosition.Y += maPreviewSize.Height / 2.0;
}
return aPosition;
}
awt::Rectangle PresenterSlideSorter::Layout::GetBoundingBox (const sal_Int32 nSlideIndex) const
{
bool isRTL = AllSettings::GetLayoutRTL();
const geometry::RealPoint2D aWindowPosition(GetWindowPosition(GetPoint(nSlideIndex, isRTL?1:-1, -1)));
return PresenterGeometryHelper::ConvertRectangle(
geometry::RealRectangle2D(
aWindowPosition.X,
aWindowPosition.Y,
aWindowPosition.X + maPreviewSize.Width,
aWindowPosition.Y + maPreviewSize.Height));
}
void PresenterSlideSorter::Layout::ForAllVisibleSlides(
const ::std::function<void (sal_Int32)>& rAction)
{
for (sal_Int32 nRow=mnFirstVisibleRow; nRow<=mnLastVisibleRow; ++nRow)
{
for (sal_Int32 nColumn=mnFirstVisibleColumn; nColumn<=mnLastVisibleColumn; ++nColumn)
{
const sal_Int32 nSlideIndex (GetIndex(nRow, nColumn));
if (nSlideIndex >= mnSlideCount)
return;
rAction(nSlideIndex);
}
}
}
sal_Int32 PresenterSlideSorter::Layout::GetFirstVisibleSlideIndex() const
{
return GetIndex(mnFirstVisibleRow, mnFirstVisibleColumn);
}
sal_Int32 PresenterSlideSorter::Layout::GetLastVisibleSlideIndex() const
{
return ::std::min(
GetIndex(mnLastVisibleRow, mnLastVisibleColumn),
mnSlideCount);
}
bool PresenterSlideSorter::Layout::SetHorizontalOffset (const double nOffset)
{
if (mnHorizontalOffset != nOffset)
{
mnHorizontalOffset = round(nOffset);
SetupVisibleArea();
UpdateScrollBars();
return true;
}
else
return false;
}
bool PresenterSlideSorter::Layout::SetVerticalOffset (const double nOffset)
{
if (mnVerticalOffset != nOffset)
{
mnVerticalOffset = round(nOffset);
SetupVisibleArea();
UpdateScrollBars();
return true;
}
else
return false;
}
void PresenterSlideSorter::Layout::UpdateScrollBars()
{
sal_Int32 nTotalRowCount = sal_Int32(ceil(double(mnSlideCount) / double(mnColumnCount)));
if (mpVerticalScrollBar)
{
mpVerticalScrollBar->SetTotalSize(
nTotalRowCount * maPreviewSize.Height
+ (nTotalRowCount-1) * mnVerticalGap
+ 2*mnVerticalGap);
mpVerticalScrollBar->SetThumbPosition(mnVerticalOffset, false);
mpVerticalScrollBar->SetThumbSize(maBoundingBox.Y2 - maBoundingBox.Y1 + 1);
mpVerticalScrollBar->SetLineHeight(maPreviewSize.Height);
}
// No place yet for the vertical scroll bar.
}
sal_Int32 PresenterSlideSorter::Layout::GetIndex (
const sal_Int32 nRow,
const sal_Int32 nColumn) const
{
return nRow * mnColumnCount + nColumn;
}
sal_Int32 PresenterSlideSorter::Layout::GetRow (const sal_Int32 nSlideIndex) const
{
return nSlideIndex / mnColumnCount;
}
sal_Int32 PresenterSlideSorter::Layout::GetColumn (const sal_Int32 nSlideIndex) const
{
return nSlideIndex % mnColumnCount;
}
//===== PresenterSlideSorter::MouseOverManager ================================
PresenterSlideSorter::MouseOverManager::MouseOverManager (
const Reference<container::XIndexAccess>& rxSlides,
const std::shared_ptr<PresenterTheme>& rpTheme,
const Reference<awt::XWindow>& rxInvalidateTarget,
const std::shared_ptr<PresenterPaintManager>& rpPaintManager)
: mxCanvas(),
mxSlides(rxSlides),
mpLeftLabelBitmap(),
mpCenterLabelBitmap(),
mpRightLabelBitmap(),
mpFont(),
mnSlideIndex(-1),
maSlideBoundingBox(),
mxInvalidateTarget(rxInvalidateTarget),
mpPaintManager(rpPaintManager)
{
if (rpTheme != nullptr)
{
std::shared_ptr<PresenterBitmapContainer> pBitmaps (rpTheme->GetBitmapContainer());
if (pBitmaps != nullptr)
{
mpLeftLabelBitmap = pBitmaps->GetBitmap("LabelLeft");
mpCenterLabelBitmap = pBitmaps->GetBitmap("LabelCenter");
mpRightLabelBitmap = pBitmaps->GetBitmap("LabelRight");
}
mpFont = rpTheme->GetFont("SlideSorterLabelFont");
}
}
void PresenterSlideSorter::MouseOverManager::Paint (
const sal_Int32 nSlideIndex,
const Reference<rendering::XCanvas>& rxCanvas,
const Reference<rendering::XPolyPolygon2D>& rxClip)
{
if (nSlideIndex != mnSlideIndex)
return;
if (mxCanvas != rxCanvas)
SetCanvas(rxCanvas);
if (rxCanvas == nullptr)
return;
if ( ! mxBitmap.is())
mxBitmap = CreateBitmap(msText, maSlideBoundingBox.Width);
if (!mxBitmap.is())
return;
geometry::IntegerSize2D aSize (mxBitmap->getSize());
const double nXOffset (maSlideBoundingBox.X
+ (maSlideBoundingBox.Width - aSize.Width) / 2.0);
const double nYOffset (maSlideBoundingBox.Y
+ (maSlideBoundingBox.Height - aSize.Height) / 2.0);
rxCanvas->drawBitmap(
mxBitmap,
rendering::ViewState(
geometry::AffineMatrix2D(1,0,0, 0,1,0),
rxClip),
rendering::RenderState(
geometry::AffineMatrix2D(1,0,nXOffset, 0,1,nYOffset),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE));
}
void PresenterSlideSorter::MouseOverManager::SetCanvas (
const Reference<rendering::XCanvas>& rxCanvas)
{
mxCanvas = rxCanvas;
if (mpFont)
mpFont->PrepareFont(mxCanvas);
}
void PresenterSlideSorter::MouseOverManager::SetSlide (
const sal_Int32 nSlideIndex,
const awt::Rectangle& rBox)
{
if (mnSlideIndex == nSlideIndex)
return;
mnSlideIndex = -1;
Invalidate();
maSlideBoundingBox = rBox;
mnSlideIndex = nSlideIndex;
if (nSlideIndex >= 0)
{
if (mxSlides)
{
msText.clear();
Reference<beans::XPropertySet> xSlideProperties(mxSlides->getByIndex(nSlideIndex), UNO_QUERY);
if (xSlideProperties.is())
xSlideProperties->getPropertyValue("LinkDisplayName") >>= msText;
if (msText.isEmpty())
msText = "Slide " + OUString::number(nSlideIndex + 1);
}
}
else
{
msText.clear();
}
mxBitmap = nullptr;
Invalidate();
}
Reference<rendering::XBitmap> PresenterSlideSorter::MouseOverManager::CreateBitmap (
const OUString& rsText,
const sal_Int32 nMaximalWidth) const
{
if ( ! mxCanvas.is())
return nullptr;
if (!mpFont || !mpFont->mxFont.is())
return nullptr;
// Long text has to be shortened.
const OUString sText (GetFittingText(rsText, nMaximalWidth
- 2*gnHorizontalLabelBorder
- 2*gnHorizontalLabelPadding));
// Determine the size of the label. Its height is defined by the
// bitmaps that are used to paints its background. The width is defined
// by the text.
geometry::IntegerSize2D aLabelSize (CalculateLabelSize(sText));
// Create a new bitmap that will contain the complete label.
Reference<rendering::XBitmap> xBitmap (
mxCanvas->getDevice()->createCompatibleAlphaBitmap(aLabelSize));
if ( ! xBitmap.is())
return nullptr;
Reference<rendering::XBitmapCanvas> xBitmapCanvas (xBitmap, UNO_QUERY);
if ( ! xBitmapCanvas.is())
return nullptr;
// Paint the background.
PaintButtonBackground(xBitmapCanvas, aLabelSize);
// Paint the text.
if (!sText.isEmpty())
{
const rendering::StringContext aContext (sText, 0, sText.getLength());
const Reference<rendering::XTextLayout> xLayout (mpFont->mxFont->createTextLayout(
aContext, rendering::TextDirection::WEAK_LEFT_TO_RIGHT,0));
const geometry::RealRectangle2D aTextBBox (xLayout->queryTextBounds());
const double nXOffset = (aLabelSize.Width - aTextBBox.X2 + aTextBBox.X1) / 2;
const double nYOffset = aLabelSize.Height
- (aLabelSize.Height - aTextBBox.Y2 + aTextBBox.Y1)/2 - aTextBBox.Y2;
const rendering::ViewState aViewState(
geometry::AffineMatrix2D(1,0,0, 0,1,0),
nullptr);
rendering::RenderState aRenderState (
geometry::AffineMatrix2D(1,0,nXOffset, 0,1,nYOffset),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE);
PresenterCanvasHelper::SetDeviceColor(aRenderState, mpFont->mnColor);
xBitmapCanvas->drawTextLayout (
xLayout,
aViewState,
aRenderState);
}
return xBitmap;
}
OUString PresenterSlideSorter::MouseOverManager::GetFittingText (
const OUString& rsText,
const double nMaximalWidth) const
{
const double nTextWidth (
PresenterCanvasHelper::GetTextSize(mpFont->mxFont, rsText).Width);
if (nTextWidth > nMaximalWidth)
{
// Text is too wide. Shorten it by removing characters from the end
// and replacing them by ellipses.
// Guess a start value of the final string length.
double nBestWidth (0);
OUString sBestCandidate;
sal_Int32 nLength (round(rsText.getLength() * nMaximalWidth / nTextWidth));
const OUString sEllipses ("...");
while (true)
{
const OUString sCandidate (rsText.copy(0,nLength) + sEllipses);
const double nWidth (
PresenterCanvasHelper::GetTextSize(mpFont->mxFont, sCandidate).Width);
if (nWidth > nMaximalWidth)
{
// Candidate still too wide, shorten it.
nLength -= 1;
if (nLength <= 0)
break;
}
else if (nWidth < nMaximalWidth)
{
// Candidate short enough.
if (nWidth > nBestWidth)
{
// Best length so far.
sBestCandidate = sCandidate;
nBestWidth = nWidth;
nLength += 1;
if (nLength >= rsText.getLength())
break;
}
else
break;
}
else
{
// Candidate is exactly as long as it may be. Use it
// without looking any further.
sBestCandidate = sCandidate;
break;
}
}
return sBestCandidate;
}
else
return rsText;
}
geometry::IntegerSize2D PresenterSlideSorter::MouseOverManager::CalculateLabelSize (
const OUString& rsText) const
{
// Height is specified by the label bitmaps.
sal_Int32 nHeight (32);
if (mpCenterLabelBitmap)
{
Reference<rendering::XBitmap> xBitmap (mpCenterLabelBitmap->GetNormalBitmap());
if (xBitmap.is())
nHeight = xBitmap->getSize().Height;
}
// Width is specified by text width and maximal width.
const geometry::RealSize2D aTextSize (
PresenterCanvasHelper::GetTextSize(mpFont->mxFont, rsText));
const sal_Int32 nWidth (round(aTextSize.Width + 2*gnHorizontalLabelPadding));
return geometry::IntegerSize2D(nWidth, nHeight);
}
void PresenterSlideSorter::MouseOverManager::PaintButtonBackground (
const Reference<rendering::XCanvas>& rxCanvas,
const geometry::IntegerSize2D& rSize) const
{
// Get the bitmaps for painting the label background.
Reference<rendering::XBitmap> xLeftLabelBitmap;
if (mpLeftLabelBitmap)
xLeftLabelBitmap = mpLeftLabelBitmap->GetNormalBitmap();
Reference<rendering::XBitmap> xCenterLabelBitmap;
if (mpCenterLabelBitmap)
xCenterLabelBitmap = mpCenterLabelBitmap->GetNormalBitmap();
Reference<rendering::XBitmap> xRightLabelBitmap;
if (mpRightLabelBitmap)
xRightLabelBitmap = mpRightLabelBitmap->GetNormalBitmap();
PresenterUIPainter::PaintHorizontalBitmapComposite (
rxCanvas,
awt::Rectangle(0,0, rSize.Width,rSize.Height),
awt::Rectangle(0,0, rSize.Width,rSize.Height),
xLeftLabelBitmap,
xCenterLabelBitmap,
xRightLabelBitmap);
}
void PresenterSlideSorter::MouseOverManager::Invalidate()
{
if (mpPaintManager != nullptr)
mpPaintManager->Invalidate(mxInvalidateTarget, maSlideBoundingBox, true);
}
//===== PresenterSlideSorter::CurrentSlideFrameRenderer =======================
PresenterSlideSorter::CurrentSlideFrameRenderer::CurrentSlideFrameRenderer (
const css::uno::Reference<css::uno::XComponentContext>& rxContext,
const css::uno::Reference<css::rendering::XCanvas>& rxCanvas)
: mpTopLeft(),
mpTop(),
mpTopRight(),
mpLeft(),
mpRight(),
mpBottomLeft(),
mpBottom(),
mpBottomRight(),
mnTopFrameSize(0),
mnLeftFrameSize(0),
mnRightFrameSize(0),
mnBottomFrameSize(0)
{
PresenterConfigurationAccess aConfiguration (
rxContext,
"/org.openoffice.Office.PresenterScreen/",
PresenterConfigurationAccess::READ_ONLY);
Reference<container::XHierarchicalNameAccess> xBitmaps (
aConfiguration.GetConfigurationNode(
"PresenterScreenSettings/SlideSorter/CurrentSlideBorderBitmaps"),
UNO_QUERY);
if ( ! xBitmaps.is())
return;
PresenterBitmapContainer aContainer (
"PresenterScreenSettings/SlideSorter/CurrentSlideBorderBitmaps",
std::shared_ptr<PresenterBitmapContainer>(),
rxContext,
rxCanvas);
mpTopLeft = aContainer.GetBitmap("TopLeft");
mpTop = aContainer.GetBitmap("Top");
mpTopRight = aContainer.GetBitmap("TopRight");
mpLeft = aContainer.GetBitmap("Left");
mpRight = aContainer.GetBitmap("Right");
mpBottomLeft = aContainer.GetBitmap("BottomLeft");
mpBottom = aContainer.GetBitmap("Bottom");
mpBottomRight = aContainer.GetBitmap("BottomRight");
// Determine size of frame.
if (mpTop)
mnTopFrameSize = mpTop->mnHeight;
if (mpLeft)
mnLeftFrameSize = mpLeft->mnWidth;
if (mpRight)
mnRightFrameSize = mpRight->mnWidth;
if (mpBottom)
mnBottomFrameSize = mpBottom->mnHeight;
if (mpTopLeft)
{
mnTopFrameSize = ::std::max(mnTopFrameSize, mpTopLeft->mnHeight);
mnLeftFrameSize = ::std::max(mnLeftFrameSize, mpTopLeft->mnWidth);
}
if (mpTopRight)
{
mnTopFrameSize = ::std::max(mnTopFrameSize, mpTopRight->mnHeight);
mnRightFrameSize = ::std::max(mnRightFrameSize, mpTopRight->mnWidth);
}
if (mpBottomLeft)
{
mnLeftFrameSize = ::std::max(mnLeftFrameSize, mpBottomLeft->mnWidth);
mnBottomFrameSize = ::std::max(mnBottomFrameSize, mpBottomLeft->mnHeight);
}
if (mpBottomRight)
{
mnRightFrameSize = ::std::max(mnRightFrameSize, mpBottomRight->mnWidth);
mnBottomFrameSize = ::std::max(mnBottomFrameSize, mpBottomRight->mnHeight);
}
}
void PresenterSlideSorter::CurrentSlideFrameRenderer::PaintCurrentSlideFrame (
const awt::Rectangle& rSlideBoundingBox,
const Reference<rendering::XCanvas>& rxCanvas,
const geometry::RealRectangle2D& rClipBox)
{
if ( ! rxCanvas.is())
return;
const Reference<rendering::XPolyPolygon2D> xClip (
PresenterGeometryHelper::CreatePolygon(rClipBox, rxCanvas->getDevice()));
if (mpTop)
{
PaintBitmapTiled(
mpTop->GetNormalBitmap(),
rxCanvas,
rClipBox,
rSlideBoundingBox.X,
rSlideBoundingBox.Y - mpTop->mnHeight,
rSlideBoundingBox.Width,
mpTop->mnHeight);
}
if (mpLeft)
{
PaintBitmapTiled(
mpLeft->GetNormalBitmap(),
rxCanvas,
rClipBox,
rSlideBoundingBox.X - mpLeft->mnWidth,
rSlideBoundingBox.Y,
mpLeft->mnWidth,
rSlideBoundingBox.Height);
}
if (mpRight)
{
PaintBitmapTiled(
mpRight->GetNormalBitmap(),
rxCanvas,
rClipBox,
rSlideBoundingBox.X + rSlideBoundingBox.Width,
rSlideBoundingBox.Y,
mpRight->mnWidth,
rSlideBoundingBox.Height);
}
if (mpBottom)
{
PaintBitmapTiled(
mpBottom->GetNormalBitmap(),
rxCanvas,
rClipBox,
rSlideBoundingBox.X,
rSlideBoundingBox.Y + rSlideBoundingBox.Height,
rSlideBoundingBox.Width,
mpBottom->mnHeight);
}
if (mpTopLeft)
{
PaintBitmapOnce(
mpTopLeft->GetNormalBitmap(),
rxCanvas,
xClip,
rSlideBoundingBox.X - mpTopLeft->mnWidth,
rSlideBoundingBox.Y - mpTopLeft->mnHeight);
}
if (mpTopRight)
{
PaintBitmapOnce(
mpTopRight->GetNormalBitmap(),
rxCanvas,
xClip,
rSlideBoundingBox.X + rSlideBoundingBox.Width,
rSlideBoundingBox.Y - mpTopLeft->mnHeight);
}
if (mpBottomLeft)
{
PaintBitmapOnce(
mpBottomLeft->GetNormalBitmap(),
rxCanvas,
xClip,
rSlideBoundingBox.X - mpBottomLeft->mnWidth,
rSlideBoundingBox.Y + rSlideBoundingBox.Height);
}
if (mpBottomRight)
{
PaintBitmapOnce(
mpBottomRight->GetNormalBitmap(),
rxCanvas,
xClip,
rSlideBoundingBox.X + rSlideBoundingBox.Width,
rSlideBoundingBox.Y + rSlideBoundingBox.Height);
}
}
awt::Rectangle PresenterSlideSorter::CurrentSlideFrameRenderer::GetBoundingBox (
const awt::Rectangle& rSlideBoundingBox)
{
return awt::Rectangle(
rSlideBoundingBox.X - mnLeftFrameSize,
rSlideBoundingBox.Y - mnTopFrameSize,
rSlideBoundingBox.Width + mnLeftFrameSize + mnRightFrameSize,
rSlideBoundingBox.Height + mnTopFrameSize + mnBottomFrameSize);
}
void PresenterSlideSorter::CurrentSlideFrameRenderer::PaintBitmapOnce(
const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
const Reference<rendering::XPolyPolygon2D>& rxClip,
const double nX,
const double nY)
{
OSL_ASSERT(rxCanvas.is());
if ( ! rxBitmap.is())
return;
const rendering::ViewState aViewState(
geometry::AffineMatrix2D(1,0,0, 0,1,0),
rxClip);
const rendering::RenderState aRenderState (
geometry::AffineMatrix2D(
1, 0, nX,
0, 1, nY),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE);
rxCanvas->drawBitmap(
rxBitmap,
aViewState,
aRenderState);
}
void PresenterSlideSorter::CurrentSlideFrameRenderer::PaintBitmapTiled(
const css::uno::Reference<css::rendering::XBitmap>& rxBitmap,
const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
const geometry::RealRectangle2D& rClipBox,
const double nX0,
const double nY0,
const double nWidth,
const double nHeight)
{
OSL_ASSERT(rxCanvas.is());
if ( ! rxBitmap.is())
return;
geometry::IntegerSize2D aSize (rxBitmap->getSize());
const rendering::ViewState aViewState(
geometry::AffineMatrix2D(1,0,0, 0,1,0),
PresenterGeometryHelper::CreatePolygon(
PresenterGeometryHelper::Intersection(
rClipBox,
geometry::RealRectangle2D(nX0,nY0,nX0+nWidth,nY0+nHeight)),
rxCanvas->getDevice()));
rendering::RenderState aRenderState (
geometry::AffineMatrix2D(
1, 0, nX0,
0, 1, nY0),
nullptr,
Sequence<double>(4),
rendering::CompositeOperation::SOURCE);
const double nX1 = nX0 + nWidth;
const double nY1 = nY0 + nHeight;
for (double nY=nY0; nY<nY1; nY+=aSize.Height)
for (double nX=nX0; nX<nX1; nX+=aSize.Width)
{
aRenderState.AffineTransform.m02 = nX;
aRenderState.AffineTransform.m12 = nY;
rxCanvas->drawBitmap(
rxBitmap,
aViewState,
aRenderState);
}
}
} // end of namespace ::sdext::presenter
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|