1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705 | /* -*- 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 "newhelp.hxx"
#include <sfx2/sfxresid.hxx>
#include "helpinterceptor.hxx"
#include <helper.hxx>
#include <srchdlg.hxx>
#include <sfx2/sfxhelp.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include <sfx2/strings.hrc>
#include <helpids.h>
#include <bitmaps.hlst>
#include <rtl/ustrbuf.hxx>
#include <comphelper/configurationhelper.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <com/sun/star/awt/PosSize.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySetInfo.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
#include <com/sun/star/frame/XTitle.hpp>
#include <com/sun/star/frame/XLayoutManager.hpp>
#include <com/sun/star/frame/XController.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/frame/Frame.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
#include <com/sun/star/text/XText.hpp>
#include <com/sun/star/text/XTextCursor.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
#include <com/sun/star/text/XTextViewCursor.hpp>
#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
#include <com/sun/star/ucb/CommandAbortedException.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/util/XSearchable.hpp>
#include <com/sun/star/util/XSearchDescriptor.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/util/XModifiable.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/util/CloseVetoException.hpp>
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <com/sun/star/view/XViewSettingsSupplier.hpp>
#include <unotools/historyoptions.hxx>
#include <svtools/menuoptions.hxx>
#include <unotools/viewoptions.hxx>
#include <tools/urlobj.hxx>
#include <svtools/imagemgr.hxx>
#include <svtools/miscopt.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <vcl/i18nhelp.hxx>
#include <vcl/layout.hxx>
#include <vcl/taskpanelist.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
#include <vcl/unohelp.hxx>
#include <vcl/weld.hxx>
#include <ucbhelper/content.hxx>
#include <unotools/ucbhelper.hxx>
#include <unordered_map>
#include <vector>
using namespace ::ucbhelper;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::style;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::view;
using namespace ::com::sun::star::ui;
using namespace ::comphelper;
// defines ---------------------------------------------------------------
#define CONFIGNAME_HELPWIN "OfficeHelp"
#define CONFIGNAME_INDEXWIN "OfficeHelpIndex"
#define CONFIGNAME_SEARCHPAGE "OfficeHelpSearch"
#define IMAGE_URL "private:factory/"
#define PROPERTY_KEYWORDLIST "KeywordList"
#define PROPERTY_KEYWORDREF "KeywordRef"
#define PROPERTY_ANCHORREF "KeywordAnchorForRef"
#define PROPERTY_TITLEREF "KeywordTitleForRef"
#define PROPERTY_TITLE "Title"
#define HELP_URL "vnd.sun.star.help://"
#define HELP_SEARCH_TAG "/?Query="
#define USERITEM_NAME "UserItem"
#define PACKAGE_SETUP "/org.openoffice.Setup"
#define PATH_OFFICE_FACTORIES "Office/Factories/"
#define KEY_HELP_ON_OPEN "ooSetupFactoryHelpOnOpen"
#define KEY_UI_NAME "ooSetupFactoryUIName"
namespace sfx2
{
/** Prepare a search string for searching or selecting.
For searching every search word needs the postfix '*' and the delimiter ' ' if necessary.
For selecting the delimiter '|' is required to search with regular expressions.
Samples:
search string | output for searching | output for selecting
-----------------------------------------------------------
"text" | "text*" | "text"
"text*" | "text*" | "text"
"text menu" | "text* menu*" | "text|menu"
*/
static OUString PrepareSearchString( const OUString& rSearchString,
const Reference< XBreakIterator >& xBreak, bool bForSearch )
{
OUStringBuffer sSearchStr;
sal_Int32 nStartPos = 0;
const lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
Boundary aBoundary = xBreak->getWordBoundary(
rSearchString, nStartPos, aLocale, WordType::ANYWORD_IGNOREWHITESPACES, true );
while ( aBoundary.startPos < aBoundary.endPos )
{
nStartPos = aBoundary.endPos;
OUString sSearchToken( rSearchString.copy(
static_cast<sal_uInt16>(aBoundary.startPos), static_cast<sal_uInt16>(aBoundary.endPos) - static_cast<sal_uInt16>(aBoundary.startPos) ) );
if ( !sSearchToken.isEmpty() && ( sSearchToken.getLength() > 1 || sSearchToken[0] != '.' ) )
{
if ( bForSearch && sSearchToken[ sSearchToken.getLength() - 1 ] != '*' )
sSearchToken += "*";
if ( sSearchToken.getLength() > 1 ||
( sSearchToken.getLength() > 0 && sSearchToken[ 0 ] != '*' ) )
{
if ( !sSearchStr.isEmpty() )
{
if ( bForSearch )
sSearchStr.append(" ");
else
sSearchStr.append("|");
}
sSearchStr.append(sSearchToken);
}
}
aBoundary = xBreak->nextWord( rSearchString, nStartPos,
aLocale, WordType::ANYWORD_IGNOREWHITESPACES );
}
return sSearchStr.makeStringAndClear();
}
// namespace sfx2
}
// struct IndexEntry_Impl ------------------------------------------------
namespace {
struct IndexEntry_Impl
{
bool m_bSubEntry;
OUString m_aURL;
IndexEntry_Impl( const OUString& rURL, bool bSubEntry ) :
m_bSubEntry( bSubEntry ), m_aURL( rURL ) {}
};
// struct ContentEntry_Impl ----------------------------------------------
struct ContentEntry_Impl
{
OUString aURL;
bool bIsFolder;
ContentEntry_Impl( const OUString& rURL, bool bFolder ) :
aURL( rURL ), bIsFolder( bFolder ) {}
};
}
void ContentTabPage_Impl::InitRoot()
{
std::vector< OUString > aList =
SfxContentHelper::GetHelpTreeViewContents( "vnd.sun.star.hier://com.sun.star.help.TreeView/" );
for (const OUString & aRow : aList)
{
sal_Int32 nIdx = 0;
OUString aTitle = aRow.getToken( 0, '\t', nIdx );
OUString aURL = aRow.getToken( 0, '\t', nIdx );
sal_Unicode cFolder = aRow.getToken( 0, '\t', nIdx )[0];
bool bIsFolder = ( '1' == cFolder );
OUString sId;
if (bIsFolder)
sId = OUString::number(reinterpret_cast<sal_Int64>(new ContentEntry_Impl(aURL, true)));
m_xContentBox->insert(nullptr, -1, &aTitle, &sId, nullptr, nullptr, true, m_xScratchIter.get());
m_xContentBox->set_image(*m_xScratchIter, aClosedBookImage);
}
}
void ContentTabPage_Impl::ClearChildren(weld::TreeIter* pParent)
{
std::unique_ptr<weld::TreeIter> xEntry = m_xContentBox->make_iterator(pParent);
bool bEntry = m_xContentBox->iter_children(*xEntry);
while (bEntry)
{
ClearChildren(xEntry.get());
delete reinterpret_cast<ContentEntry_Impl*>(m_xContentBox->get_id(*xEntry).toInt64());
bEntry = m_xContentBox->iter_next_sibling(*xEntry);
}
}
IMPL_LINK(ContentTabPage_Impl, ExpandingHdl, const weld::TreeIter&, rIter, bool)
{
ContentEntry_Impl* pContentEntry = reinterpret_cast<ContentEntry_Impl*>(m_xContentBox->get_id(rIter).toInt64());
if (!m_xContentBox->iter_has_child(rIter))
{
try
{
if (pContentEntry)
{
std::vector<OUString > aList = SfxContentHelper::GetHelpTreeViewContents(pContentEntry->aURL);
for (const OUString & aRow : aList)
{
sal_Int32 nIdx = 0;
OUString aTitle = aRow.getToken( 0, '\t', nIdx );
OUString aURL = aRow.getToken( 0, '\t', nIdx );
sal_Unicode cFolder = aRow.getToken( 0, '\t', nIdx )[0];
bool bIsFolder = ( '1' == cFolder );
if ( bIsFolder )
{
OUString sId = OUString::number(reinterpret_cast<sal_Int64>(new ContentEntry_Impl(aURL, true)));
m_xContentBox->insert(&rIter, -1, &aTitle, &sId, nullptr, nullptr, true, m_xScratchIter.get());
m_xContentBox->set_image(*m_xScratchIter, aClosedBookImage);
}
else
{
Any aAny( ::utl::UCBContentHelper::GetProperty( aURL, "TargetURL" ) );
OUString sId;
OUString aTargetURL;
if ( aAny >>= aTargetURL )
sId = OUString::number(reinterpret_cast<sal_Int64>(new ContentEntry_Impl(aTargetURL, false)));
m_xContentBox->insert(&rIter, -1, &aTitle, &sId, nullptr, nullptr, false, m_xScratchIter.get());
m_xContentBox->set_image(*m_xScratchIter, aDocumentImage);
}
}
}
}
catch (const Exception&)
{
OSL_FAIL( "ContentListBox_Impl::RequestingChildren(): unexpected exception" );
}
}
if (!pContentEntry || pContentEntry->bIsFolder)
m_xContentBox->set_image(rIter, aOpenBookImage);
return true;
}
IMPL_LINK(ContentTabPage_Impl, CollapsingHdl, const weld::TreeIter&, rIter, bool)
{
ContentEntry_Impl* pContentEntry = reinterpret_cast<ContentEntry_Impl*>(m_xContentBox->get_id(rIter).toInt64());
if (!pContentEntry || pContentEntry->bIsFolder)
m_xContentBox->set_image(rIter, aClosedBookImage);
return true;
}
OUString ContentTabPage_Impl::GetSelectedEntry() const
{
OUString aRet;
ContentEntry_Impl* pEntry = reinterpret_cast<ContentEntry_Impl*>(m_xContentBox->get_selected_id().toInt64());
if (pEntry && !pEntry->bIsFolder)
aRet = pEntry->aURL;
return aRet;
}
// class HelpTabPage_Impl ------------------------------------------------
HelpTabPage_Impl::HelpTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin,
const OString& rID, const OUString& rUIXMLDescription)
: BuilderPage(pParent, nullptr, rUIXMLDescription, rID)
, m_pIdxWin(pIdxWin)
{
}
HelpTabPage_Impl::~HelpTabPage_Impl()
{
}
// class ContentTabPage_Impl ---------------------------------------------
ContentTabPage_Impl::ContentTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin)
: HelpTabPage_Impl(pParent, pIdxWin, "HelpContentPage",
"sfx/ui/helpcontentpage.ui")
, m_xContentBox(m_xBuilder->weld_tree_view("content"))
, m_xScratchIter(m_xContentBox->make_iterator())
, aOpenBookImage(BMP_HELP_CONTENT_BOOK_OPEN)
, aClosedBookImage(BMP_HELP_CONTENT_BOOK_CLOSED)
, aDocumentImage(BMP_HELP_CONTENT_DOC)
{
m_xContentBox->set_size_request(m_xContentBox->get_approximate_digit_width() * 30,
m_xContentBox->get_height_rows(20));
m_xContentBox->connect_row_activated(LINK(this, ContentTabPage_Impl, DoubleClickHdl));
m_xContentBox->connect_expanding(LINK(this, ContentTabPage_Impl, ExpandingHdl));
m_xContentBox->connect_collapsing(LINK(this, ContentTabPage_Impl, CollapsingHdl));
InitRoot();
}
IMPL_LINK_NOARG(ContentTabPage_Impl, DoubleClickHdl, weld::TreeView&, bool)
{
aDoubleClickHdl.Call(nullptr);
return false;
}
void ContentTabPage_Impl::SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink)
{
aDoubleClickHdl = rLink;
}
ContentTabPage_Impl::~ContentTabPage_Impl()
{
std::unique_ptr<weld::TreeIter> xEntry = m_xContentBox->make_iterator();
bool bEntry = m_xContentBox->get_iter_first(*xEntry);
while (bEntry)
{
ClearChildren(xEntry.get());
delete reinterpret_cast<ContentEntry_Impl*>(m_xContentBox->get_id(*xEntry).toInt64());
bEntry = m_xContentBox->iter_next_sibling(*xEntry);
}
}
weld::Widget* ContentTabPage_Impl::GetLastFocusControl()<--- The function 'GetLastFocusControl' is never used.
{
return m_xContentBox.get();
}
void IndexTabPage_Impl::SelectExecutableEntry()
{
sal_Int32 nPos = m_xIndexList->find_text(m_xIndexEntry->get_text());
if (nPos == -1)
return;
sal_Int32 nOldPos = nPos;
OUString aEntryText;
IndexEntry_Impl* pEntry = reinterpret_cast<IndexEntry_Impl*>(m_xIndexList->get_id(nPos).toInt64());
sal_Int32 nCount = m_xIndexList->n_children();
while ( nPos < nCount && ( !pEntry || pEntry->m_aURL.isEmpty() ) )
{
pEntry = reinterpret_cast<IndexEntry_Impl*>(m_xIndexList->get_id(++nPos).toInt64());
aEntryText = m_xIndexList->get_text(nPos);
}
if ( nOldPos != nPos )
m_xIndexEntry->set_text(aEntryText);
}
// class IndexTabPage_Impl -----------------------------------------------
IndexTabPage_Impl::IndexTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin)
: HelpTabPage_Impl(pParent, pIdxWin, "HelpIndexPage", "sfx/ui/helpindexpage.ui")
, m_xIndexEntry(m_xBuilder->weld_entry("termentry"))
, m_xIndexList(m_xBuilder->weld_tree_view("termlist"))
, m_xOpenBtn(m_xBuilder->weld_button("display"))
, aFactoryIdle("sfx2 appl IndexTabPage_Impl Factory")
, aAutoCompleteIdle("sfx2 appl IndexTabPage_Impl AutoComplete")
, bIsActivated(false)
, nRowHeight(m_xIndexList->get_height_rows(1))
, nAllHeight(0)
{
m_xIndexList->set_size_request(m_xIndexList->get_approximate_digit_width() * 30, -1);
m_xOpenBtn->connect_clicked(LINK(this, IndexTabPage_Impl, OpenHdl));
aFactoryIdle.SetInvokeHandler( LINK(this, IndexTabPage_Impl, IdleHdl ));
aAutoCompleteIdle.SetInvokeHandler( LINK(this, IndexTabPage_Impl, AutoCompleteHdl ));
aKeywordTimer.SetInvokeHandler( LINK( this, IndexTabPage_Impl, TimeoutHdl ) );
m_xIndexList->connect_row_activated(LINK(this, IndexTabPage_Impl, DoubleClickHdl));
m_xIndexList->connect_changed(LINK(this, IndexTabPage_Impl, TreeChangeHdl));
m_xIndexList->connect_custom_get_size(LINK(this, IndexTabPage_Impl, CustomGetSizeHdl));
m_xIndexList->connect_custom_render(LINK(this, IndexTabPage_Impl, CustomRenderHdl));
m_xIndexList->set_column_custom_renderer(0, true);
m_xIndexList->connect_size_allocate(LINK(this, IndexTabPage_Impl, ResizeHdl));
m_xIndexEntry->connect_key_press(LINK(this, IndexTabPage_Impl, KeyInputHdl));
m_xIndexEntry->connect_changed(LINK(this, IndexTabPage_Impl, EntryChangeHdl));
m_xIndexEntry->connect_activate(LINK(this, IndexTabPage_Impl, ActivateHdl));
}
IMPL_LINK(IndexTabPage_Impl, ResizeHdl, const Size&, rSize, void)
{
nAllHeight = rSize.Height();
}
IMPL_LINK_NOARG(IndexTabPage_Impl, CustomGetSizeHdl, weld::TreeView::get_size_args, Size)
{
return Size(m_xIndexList->get_size_request().Width(), nRowHeight);
}
IMPL_LINK(IndexTabPage_Impl, CustomRenderHdl, weld::TreeView::render_args, aPayload, void)
{
vcl::RenderContext& rRenderContext = std::get<0>(aPayload);
const ::tools::Rectangle& rRect = std::get<1>(aPayload);
bool bSelected = std::get<2>(aPayload);
const OUString& rId = std::get<3>(aPayload);
rRenderContext.Push(PushFlags::TEXTCOLOR);
const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
if (bSelected)
rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
else
rRenderContext.SetTextColor(rStyleSettings.GetDialogTextColor());
Point aPos(rRect.TopLeft());
aPos.AdjustY((rRect.GetHeight() - rRenderContext.GetTextHeight()) / 2);
int nIndex = m_xIndexList->find_id(rId);
OUString aEntry(m_xIndexList->get_text(nIndex));
IndexEntry_Impl* pEntry = reinterpret_cast<IndexEntry_Impl*>(rId.toInt64());
if (pEntry && pEntry->m_bSubEntry)
{
// indent sub entries
aPos.AdjustX(8);
sal_Int32 nPos = aEntry.indexOf(';');
rRenderContext.DrawText(aPos, (nPos !=-1) ? aEntry.copy(nPos + 1) : aEntry);
}
else
rRenderContext.DrawText(aPos, aEntry);
rRenderContext.Pop();
}
IMPL_LINK_NOARG(IndexTabPage_Impl, TreeChangeHdl, weld::TreeView&, void)
{
m_xIndexEntry->set_text(m_xIndexList->get_selected_text());
}
IMPL_LINK_NOARG(IndexTabPage_Impl, EntryChangeHdl, weld::Entry&, void)
{
aAutoCompleteIdle.Start();
}
IMPL_LINK(IndexTabPage_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
const vcl::KeyCode& rKCode = rKEvt.GetKeyCode();
if (rKCode.GetModifier()) // only with no modifiers held
return false;
sal_uInt16 nCode = rKCode.GetCode();
if (nCode == KEY_UP || nCode == KEY_PAGEUP ||
nCode == KEY_DOWN || nCode == KEY_PAGEDOWN)
{
// disable_notify_events();
sal_Int32 nIndex = m_xIndexList->get_selected_index();
sal_Int32 nOrigIndex = nIndex;
sal_Int32 nCount = m_xIndexList->n_children();
if (nIndex == -1)
{
m_xIndexList->set_cursor(0);
m_xIndexList->select(0);
m_xIndexEntry->set_text(m_xIndexList->get_selected_text());
}
else
{
if (nCode == KEY_UP)
--nIndex;
else if (nCode == KEY_DOWN)
++nIndex;
else if (nCode == KEY_PAGEUP)
{
int nVisRows = nAllHeight / nRowHeight;
nIndex -= nVisRows;
}
else if (nCode == KEY_PAGEDOWN)
{
int nVisRows = nAllHeight / nRowHeight;
nIndex += nVisRows;
}
if (nIndex < 0)
nIndex = 0;
if (nIndex >= nCount)
nIndex = nCount - 1;
if (nIndex != nOrigIndex)
{
m_xIndexList->set_cursor(nIndex);
m_xIndexList->select(nIndex);
m_xIndexEntry->set_text(m_xIndexList->get_selected_text());
}
// m_xIndexList->grab_focus();
// g_signal_emit_by_name(pWidget, "key-press-event", pEvent, &ret);
// m_xIndexEntry->set_text(m_xIndexList->get_selected_text());
// m_xIndexEntry->grab_focus();
}
m_xIndexEntry->select_region(0, -1);
// enable_notify_events();
// m_bTreeChange = true;
// m_pEntry->fire_signal_changed();
// m_bTreeChange = false;
return true;
}
return false;
}
IndexTabPage_Impl::~IndexTabPage_Impl()
{
ClearIndex();
}
namespace sfx2 {
typedef std::unordered_map< OUString, int > KeywordInfo;
}
void IndexTabPage_Impl::InitializeIndex()
{
weld::WaitObject aWaitCursor(m_pIdxWin->GetFrameWeld());
// By now more than 256 equal entries are not allowed
sal_Unicode append[256];
for(sal_Unicode & k : append)
k = ' ';<--- Consider using std::fill algorithm instead of a raw loop.
sfx2::KeywordInfo aInfo;
m_xIndexList->freeze();
try
{
OUStringBuffer aURL = HELP_URL;
aURL.append(sFactory);
AppendConfigToken(aURL, true);
Content aCnt( aURL.makeStringAndClear(), Reference< css::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
css::uno::Reference< css::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
if ( xInfo->hasPropertyByName( PROPERTY_ANCHORREF ) )
{
css::uno::Sequence< OUString > aPropSeq( 4 );
aPropSeq[0] = PROPERTY_KEYWORDLIST;
aPropSeq[1] = PROPERTY_KEYWORDREF;
aPropSeq[2] = PROPERTY_ANCHORREF;
aPropSeq[3] = PROPERTY_TITLEREF;
// abi: use one possibly remote call only
css::uno::Sequence< css::uno::Any > aAnySeq =
aCnt.getPropertyValues( aPropSeq );
css::uno::Sequence< OUString > aKeywordList;
css::uno::Sequence< css::uno::Sequence< OUString > > aKeywordRefList;
css::uno::Sequence< css::uno::Sequence< OUString > > aAnchorRefList;
css::uno::Sequence< css::uno::Sequence< OUString > > aTitleRefList;
if ( ( aAnySeq[0] >>= aKeywordList ) && ( aAnySeq[1] >>= aKeywordRefList ) &&
( aAnySeq[2] >>= aAnchorRefList ) && ( aAnySeq[3] >>= aTitleRefList ) )
{
int ndx,tmp;<--- The scope of the variable 'ndx' can be reduced. [+]The scope of the variable 'ndx' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
OUString aIndex, aTempString;
OUStringBuffer aData( 128 ); // Capacity of up to 128 characters
sfx2::KeywordInfo::iterator it;
for ( int i = 0; i < aKeywordList.getLength(); ++i )
{
// abi: Do not copy, but use references
const OUString& aKeywordPair = aKeywordList[i];
DBG_ASSERT( !aKeywordPair.isEmpty(), "invalid help index" );
const css::uno::Sequence< OUString >& aRefList = aKeywordRefList[i];
const css::uno::Sequence< OUString >& aAnchorList = aAnchorRefList[i];
const css::uno::Sequence< OUString >& aTitleList = aTitleRefList[i];
DBG_ASSERT( aRefList.getLength() == aAnchorList.getLength(),"reference list and title list of different length" );
ndx = aKeywordPair.indexOf( ';' );
const bool insert = ndx != -1;
OUString sId;
if ( insert )
{
aTempString = aKeywordPair.copy( 0, ndx );
if ( aIndex != aTempString )
{
aIndex = aTempString;
it = aInfo.emplace(aTempString, 0).first;
sId = OUString::number(reinterpret_cast<sal_Int64>(new IndexEntry_Impl(OUString(), false)));
if ( (tmp = it->second++) != 0)
m_xIndexList->append(sId, aTempString + OUString(append, tmp));
else
m_xIndexList->append(sId, aTempString);
}
}
else
aIndex.clear();
sal_uInt32 nRefListLen = aRefList.getLength();
DBG_ASSERT( aAnchorList.hasElements(), "*IndexTabPage_Impl::InitializeIndex(): AnchorList is empty!" );
DBG_ASSERT( nRefListLen, "*IndexTabPage_Impl::InitializeIndex(): RefList is empty!" );
if ( aAnchorList.hasElements() && nRefListLen )
{
if ( aAnchorList[0].getLength() > 0 )
{
aData.append( aRefList[0] ).append( '#' ).append( aAnchorList[0] );
sId = OUString::number(reinterpret_cast<sal_Int64>(new IndexEntry_Impl(aData.makeStringAndClear(), insert)));
}
else
sId = OUString::number(reinterpret_cast<sal_Int64>(new IndexEntry_Impl(aRefList[0], insert)));
}
// Assume the token is trimmed
it = aInfo.emplace(aKeywordPair, 0).first;
if ((tmp = it->second++) != 0)
m_xIndexList->append(sId, aKeywordPair + OUString(append, tmp));
else
m_xIndexList->append(sId, aKeywordPair);
for ( sal_uInt32 j = 1; j < nRefListLen ; ++j )
{
aData
.append( aKeywordPair )
.append( ' ' )
.append( '-' )
.append( ' ' )
.append( aTitleList[j] );
aTempString = aData.makeStringAndClear();
if ( aAnchorList[j].getLength() > 0 )
{
aData.append( aRefList[j] ).append( '#' ).append( aAnchorList[j] );
sId = OUString::number(reinterpret_cast<sal_Int64>(new IndexEntry_Impl(aData.makeStringAndClear(), insert)));
}
else
sId = OUString::number(reinterpret_cast<sal_Int64>(new IndexEntry_Impl(aRefList[j], insert)));
it = aInfo.emplace(aTempString, 0).first;
if ( (tmp = it->second++) != 0 )
m_xIndexList->append(sId, aTempString + OUString(append, tmp));
else
m_xIndexList->append(sId, aTempString);
}
}
}
}
}
catch( Exception& )
{
OSL_FAIL( "IndexTabPage_Impl::InitializeIndex(): unexpected exception" );
}
m_xIndexList->thaw();
if ( !sKeyword.isEmpty() )
aKeywordLink.Call( *this );
}
void IndexTabPage_Impl::ClearIndex()
{
const sal_Int32 nCount = m_xIndexList->n_children();
for ( sal_Int32 i = 0; i < nCount; ++i )
delete reinterpret_cast<IndexEntry_Impl*>(m_xIndexList->get_id(i).toInt64());
m_xIndexList->clear();
}
IMPL_LINK_NOARG(IndexTabPage_Impl, OpenHdl, weld::Button&, void)
{
aDoubleClickHdl.Call(nullptr);
}
IMPL_LINK_NOARG(IndexTabPage_Impl, ActivateHdl, weld::Entry&, bool)
{
aDoubleClickHdl.Call(nullptr);
return true;
}
IMPL_LINK_NOARG(IndexTabPage_Impl, DoubleClickHdl, weld::TreeView&, bool)
{
aDoubleClickHdl.Call(nullptr);
return true;
}
IMPL_LINK_NOARG(IndexTabPage_Impl, IdleHdl, Timer*, void)
{
InitializeIndex();
}
int IndexTabPage_Impl::starts_with(const OUString& rStr, int nStartRow, bool bCaseSensitive)
{
const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetUILocaleI18nHelper();
int nRet = nStartRow;
int nCount = m_xIndexList->n_children();
while (nRet < nCount)
{
OUString aStr(m_xIndexList->get_text(nRet));
const bool bMatch = !bCaseSensitive ? rI18nHelper.MatchString(rStr, aStr) : aStr.startsWith(rStr);
if (bMatch)
return nRet;
++nRet;
}
return -1;
}
IMPL_LINK_NOARG(IndexTabPage_Impl, AutoCompleteHdl, Timer*, void)
{
OUString aStartText = m_xIndexEntry->get_text();
int nStartPos, nEndPos;
m_xIndexEntry->get_selection_bounds(nStartPos, nEndPos);
int nMaxSelection = std::max(nStartPos, nEndPos);
if (nMaxSelection != aStartText.getLength())
return;
int nActive = m_xIndexList->get_selected_index();
int nStart = nActive;
if (nStart == -1)
nStart = 0;
// Try match case insensitive from current position
int nPos = starts_with(aStartText, nStart, false);
if (nPos == -1 && nStart != 0)
{
// Try match case insensitive, but from start
nPos = starts_with(aStartText, 0, false);
}
if (nPos == -1)
{
// Try match case sensitive from current position
nPos = starts_with(aStartText, nStart, true);
if (nPos == -1 && nStart != 0)
{
// Try match case sensitive, but from start
nPos = starts_with(aStartText, 0, true);
}
}
if (nPos != -1)
{
m_xIndexList->set_cursor(nPos);
m_xIndexList->select(nPos);
OUString aText = m_xIndexList->get_text(nPos);
if (aText != aStartText)
m_xIndexEntry->set_text(aText);
m_xIndexEntry->select_region(aText.getLength(), aStartText.getLength());
}
}
IMPL_LINK( IndexTabPage_Impl, TimeoutHdl, Timer*, pTimer, void)
{
if(&aKeywordTimer == pTimer && !sKeyword.isEmpty())
aKeywordLink.Call(*this);
}
void IndexTabPage_Impl::Activate()
{
if ( !bIsActivated )
{
bIsActivated = true;
aFactoryIdle.Start();
}
}
weld::Widget* IndexTabPage_Impl::GetLastFocusControl()
{
return m_xOpenBtn.get();
}
void IndexTabPage_Impl::SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink)
{
aDoubleClickHdl = rLink;
}
void IndexTabPage_Impl::SetFactory( const OUString& rFactory )
{
OUString sNewFactory( rFactory );
DBG_ASSERT( !sNewFactory.isEmpty(), "empty factory" );
bool bValid = m_pIdxWin->IsValidFactory( rFactory );
if ( sFactory.isEmpty() && !bValid )
{
sNewFactory = SfxHelp::GetDefaultHelpModule();
bValid = true;
}
if ( sNewFactory != sFactory && bValid )
{
sFactory = sNewFactory;
ClearIndex();
if ( bIsActivated )
aFactoryIdle.Start();
}
}
OUString IndexTabPage_Impl::GetSelectedEntry() const
{
OUString aRet;
IndexEntry_Impl* pEntry = reinterpret_cast<IndexEntry_Impl*>(m_xIndexList->get_id(m_xIndexList->find_text(m_xIndexEntry->get_text())).toInt64());
if (pEntry)
aRet = pEntry->m_aURL;
return aRet;
}
void IndexTabPage_Impl::SetKeyword( const OUString& rKeyword )
{
sKeyword = rKeyword;
if (m_xIndexList->n_children() > 0)
aKeywordTimer.Start();
else if ( !bIsActivated )
aFactoryIdle.Start();
}
bool IndexTabPage_Impl::HasKeyword() const
{
bool bRet = false;
if ( !sKeyword.isEmpty() )
{
sal_Int32 nPos = m_xIndexList->find_text( sKeyword );
bRet = nPos != -1;
}
return bRet;
}
bool IndexTabPage_Impl::HasKeywordIgnoreCase()
{
bool bRet = false;
if ( !sKeyword.isEmpty() )
{
sal_Int32 nEntries = m_xIndexList->n_children();
const vcl::I18nHelper& rI18nHelper = Application::GetSettings().GetLocaleI18nHelper();
for ( sal_Int32 n = 0; n < nEntries; n++)
{
const OUString sIndexItem {m_xIndexList->get_text(n)};
if (rI18nHelper.MatchString( sIndexItem, sKeyword ))
{
sKeyword = sIndexItem;
bRet = true;
}
}
}
return bRet;
}
void IndexTabPage_Impl::OpenKeyword()
{
if ( !sKeyword.isEmpty() )
{
m_xIndexEntry->set_text(sKeyword);
aDoubleClickHdl.Call(nullptr);
sKeyword.clear();
}
}
IMPL_LINK_NOARG(SearchTabPage_Impl, ActivateHdl, weld::ComboBox&, bool)
{
Search();
return true;
}
// class SearchTabPage_Impl ----------------------------------------------
SearchTabPage_Impl::SearchTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* pIdxWin)
: HelpTabPage_Impl(pParent, pIdxWin, "HelpSearchPage",
"sfx/ui/helpsearchpage.ui")
, m_xSearchED(m_xBuilder->weld_combo_box("search"))
, m_xSearchBtn(m_xBuilder->weld_button("find"))
, m_xFullWordsCB(m_xBuilder->weld_check_button("completewords"))
, m_xScopeCB(m_xBuilder->weld_check_button("headings"))
, m_xResultsLB(m_xBuilder->weld_tree_view("results"))
, m_xOpenBtn(m_xBuilder->weld_button("display"))
, xBreakIterator(vcl::unohelper::CreateBreakIterator())
{
m_xResultsLB->set_size_request(m_xResultsLB->get_approximate_digit_width() * 30,
m_xResultsLB->get_height_rows(15));
m_xSearchBtn->connect_clicked(LINK(this, SearchTabPage_Impl, ClickHdl));
m_xSearchED->connect_changed(LINK(this, SearchTabPage_Impl, ModifyHdl));
m_xSearchED->connect_entry_activate(LINK(this, SearchTabPage_Impl, ActivateHdl));
m_xOpenBtn->connect_clicked(LINK(this, SearchTabPage_Impl, OpenHdl));
m_xResultsLB->connect_row_activated(LINK(this, SearchTabPage_Impl, DoubleClickHdl));
SvtViewOptions aViewOpt( EViewType::TabPage, CONFIGNAME_SEARCHPAGE );
if ( aViewOpt.Exists() )
{
OUString aUserData;
Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
if ( aUserItem >>= aUserData )<--- Variable 'aUserItem' is assigned a value that is never used.
{
sal_Int32 nIdx {0};
bool bChecked = aUserData.getToken(0, ';', nIdx).toInt32() == 1;
m_xFullWordsCB->set_active(bChecked);
bChecked = aUserData.getToken(0, ';', nIdx).toInt32() == 1;
m_xScopeCB->set_active(bChecked);
while ( nIdx > 0 )
{
m_xSearchED->append_text( INetURLObject::decode(
aUserData.getToken(0, ';', nIdx),
INetURLObject::DecodeMechanism::WithCharset ) );
}
}
}
ModifyHdl(*m_xSearchED);
}
SearchTabPage_Impl::~SearchTabPage_Impl()
{
SvtViewOptions aViewOpt( EViewType::TabPage, CONFIGNAME_SEARCHPAGE );
OUStringBuffer aUserData;
aUserData.append(OUString::number(m_xFullWordsCB->get_active() ? 1 : 0))
.append(";")
.append(OUString::number( m_xScopeCB->get_active() ? 1 : 0 ));
sal_Int32 nCount = std::min(m_xSearchED->get_count(), 10); // save only 10 entries
for ( sal_Int32 i = 0; i < nCount; ++i )
{
aUserData.append(";").append(INetURLObject::encode(
m_xSearchED->get_text(i),
INetURLObject::PART_UNO_PARAM_VALUE,
INetURLObject::EncodeMechanism::All ));
}
Any aUserItem = makeAny( aUserData.makeStringAndClear() );
aViewOpt.SetUserItem( USERITEM_NAME, aUserItem );
m_xSearchED.reset();
m_xSearchBtn.reset();
m_xFullWordsCB.reset();
m_xScopeCB.reset();
m_xResultsLB.reset();
m_xOpenBtn.reset();
}
void SearchTabPage_Impl::ClearSearchResults()
{
m_xResultsLB->clear();
}
void SearchTabPage_Impl::RememberSearchText( const OUString& rSearchText )
{
for (sal_Int32 i = 0, nEntryCount = m_xSearchED->get_count(); i < nEntryCount; ++i)
{
if (rSearchText == m_xSearchED->get_text(i))
{
m_xSearchED->remove(i);
break;
}
}
m_xSearchED->insert_text(0, rSearchText);
}
IMPL_LINK_NOARG(SearchTabPage_Impl, ClickHdl, weld::Button&, void)
{
Search();
}
void SearchTabPage_Impl::Search()
{
OUString aSearchText = comphelper::string::strip(m_xSearchED->get_active_text(), ' ');
if ( aSearchText.isEmpty() )
return;
std::unique_ptr<weld::WaitObject> xWaitCursor(new weld::WaitObject(m_pIdxWin->GetFrameWeld()));
ClearSearchResults();
RememberSearchText( aSearchText );
OUStringBuffer aSearchURL(HELP_URL);
aSearchURL.append(aFactory);
aSearchURL.append(HELP_SEARCH_TAG);
if (!m_xFullWordsCB->get_active())
aSearchText = sfx2::PrepareSearchString( aSearchText, xBreakIterator, true );
aSearchURL.append(aSearchText);
AppendConfigToken(aSearchURL, false);
if (m_xScopeCB->get_active())
aSearchURL.append("&Scope=Heading");
std::vector< OUString > aFactories = SfxContentHelper::GetResultSet(aSearchURL.makeStringAndClear());
for (const OUString & rRow : aFactories)
{
sal_Int32 nIdx = 0;
OUString aTitle = rRow.getToken(0, '\t', nIdx);
OUString sURL(rRow.getToken(1, '\t', nIdx));
m_xResultsLB->append(sURL, aTitle);
}
xWaitCursor.reset();
if ( aFactories.empty() )
{
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xContainer.get(),
VclMessageType::Info, VclButtonsType::Ok,
SfxResId(STR_INFO_NOSEARCHRESULTS)));
xBox->run();
}
}
IMPL_LINK_NOARG(SearchTabPage_Impl, OpenHdl, weld::Button&, void)
{
aDoubleClickHdl.Call(nullptr);
}
IMPL_LINK(SearchTabPage_Impl, ModifyHdl, weld::ComboBox&, rComboBox, void)
{
OUString aSearchText = comphelper::string::strip(m_xSearchED->get_active_text(), ' ');
m_xSearchBtn->set_sensitive(!aSearchText.isEmpty());
if (rComboBox.changed_by_direct_pick())
Search();
}
weld::Widget* SearchTabPage_Impl::GetLastFocusControl()
{
return m_xOpenBtn.get();
}
IMPL_LINK_NOARG(SearchTabPage_Impl, DoubleClickHdl, weld::TreeView&, bool)
{
aDoubleClickHdl.Call(nullptr);
return true;
}
void SearchTabPage_Impl::SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink)
{
aDoubleClickHdl = rLink;
}
OUString SearchTabPage_Impl::GetSelectedEntry() const
{
return m_xResultsLB->get_selected_id();
}
void SearchTabPage_Impl::ClearPage()
{
ClearSearchResults();
m_xSearchED->set_entry_text(OUString());
}
bool SearchTabPage_Impl::OpenKeyword( const OUString& rKeyword )
{
bool bRet = false;
m_xSearchED->set_entry_text(rKeyword);
Search();
if (m_xResultsLB->n_children() > 0)
{
// found keyword -> open it
m_xResultsLB->select(0);
OpenHdl(*m_xOpenBtn);
bRet = true;
}
return bRet;
}
// class BookmarksTabPage_Impl -------------------------------------------
static void GetBookmarkEntry_Impl
(
const Sequence< PropertyValue >& aBookmarkEntry,
OUString& rTitle,<--- Parameter 'rTitle' can be declared with const
OUString& rURL<--- Parameter 'rURL' can be declared with const
)
{
for ( const PropertyValue& aValue : aBookmarkEntry )
{
if ( aValue.Name == HISTORY_PROPERTYNAME_URL )
aValue.Value >>= rURL;
else if ( aValue.Name == HISTORY_PROPERTYNAME_TITLE )
aValue.Value >>= rTitle;
}
}
void BookmarksTabPage_Impl::DoAction(const OString& rAction)
{
if (rAction == "display")
aDoubleClickHdl.Call(nullptr);
else if (rAction == "rename")
{
sal_Int32 nPos = m_xBookmarksBox->get_selected_index();
if (nPos != -1)
{
SfxAddHelpBookmarkDialog_Impl aDlg(m_xBookmarksBox.get(), true);
aDlg.SetTitle(m_xBookmarksBox->get_text(nPos));
if (aDlg.run() == RET_OK)
{
OUString sURL = m_xBookmarksBox->get_id(nPos);
m_xBookmarksBox->remove(nPos);
m_xBookmarksBox->append(sURL, aDlg.GetTitle(), SvFileInformationManager::GetImageId(INetURLObject(IMAGE_URL+INetURLObject(sURL).GetHost())));
m_xBookmarksBox->select(m_xBookmarksBox->n_children() - 1);
}
}
}
else if (rAction == "delete")
{
sal_Int32 nPos = m_xBookmarksBox->get_selected_index();
if (nPos != -1)
{
m_xBookmarksBox->remove(nPos);
const sal_Int32 nCount = m_xBookmarksBox->n_children();
if (nCount)
{
if (nPos >= nCount)
nPos = nCount - 1;
m_xBookmarksBox->select(nPos);
}
}
}
}
IMPL_LINK(BookmarksTabPage_Impl, CommandHdl, const CommandEvent&, rCEvt, bool)
{
if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
return false;
std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(m_xBookmarksBox.get(), "sfx/ui/bookmarkmenu.ui"));
std::unique_ptr<weld::Menu> xMenu = xBuilder->weld_menu("menu");
OString sIdent = xMenu->popup_at_rect(m_xBookmarksBox.get(), ::tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)));
if (!sIdent.isEmpty())
DoAction(sIdent);
return true;
}
IMPL_LINK(BookmarksTabPage_Impl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
{
bool bHandled = false;
sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
if (KEY_DELETE == nCode && m_xBookmarksBox->n_children() > 0)
{
DoAction("delete");
bHandled = true;
}
return bHandled;
}
// class BookmarksTabPage_Impl -------------------------------------------
BookmarksTabPage_Impl::BookmarksTabPage_Impl(weld::Widget* pParent, SfxHelpIndexWindow_Impl* _pIdxWin)
: HelpTabPage_Impl(pParent, _pIdxWin, "HelpBookmarkPage",
"sfx/ui/helpbookmarkpage.ui")
, m_xBookmarksBox(m_xBuilder->weld_tree_view("bookmarks"))
, m_xBookmarksPB(m_xBuilder->weld_button("display"))
{
m_xBookmarksBox->set_size_request(m_xBookmarksBox->get_approximate_digit_width() * 30,
m_xBookmarksBox->get_height_rows(20));
m_xBookmarksPB->connect_clicked( LINK(this, BookmarksTabPage_Impl, OpenHdl));
m_xBookmarksBox->connect_row_activated(LINK(this, BookmarksTabPage_Impl, DoubleClickHdl));
m_xBookmarksBox->connect_popup_menu(LINK(this, BookmarksTabPage_Impl, CommandHdl));
m_xBookmarksBox->connect_key_press(LINK(this, BookmarksTabPage_Impl, KeyInputHdl));
// load bookmarks from configuration
const Sequence< Sequence< PropertyValue > > aBookmarkSeq = SvtHistoryOptions().GetList( eHELPBOOKMARKS );
OUString aTitle;
OUString aURL;
for ( const auto& rBookmark : aBookmarkSeq )
{
GetBookmarkEntry_Impl( rBookmark, aTitle, aURL );
AddBookmarks( aTitle, aURL );
}
}
BookmarksTabPage_Impl::~BookmarksTabPage_Impl()
{
// save bookmarks to configuration
SvtHistoryOptions aHistOpt;
aHistOpt.Clear( eHELPBOOKMARKS );
const sal_Int32 nCount = m_xBookmarksBox->n_children();
for (sal_Int32 i = 0; i < nCount; ++i)
aHistOpt.AppendItem(eHELPBOOKMARKS, m_xBookmarksBox->get_id(i), "", m_xBookmarksBox->get_text(i), std::nullopt);
m_xBookmarksBox.reset();
m_xBookmarksPB.reset();
}
IMPL_LINK_NOARG(BookmarksTabPage_Impl, OpenHdl, weld::Button&, void)
{
aDoubleClickHdl.Call(nullptr);
}
weld::Widget* BookmarksTabPage_Impl::GetLastFocusControl()
{
return m_xBookmarksPB.get();
}
IMPL_LINK_NOARG(BookmarksTabPage_Impl, DoubleClickHdl, weld::TreeView&, bool)
{
aDoubleClickHdl.Call(nullptr);
return true;
}
void BookmarksTabPage_Impl::SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink)
{
aDoubleClickHdl = rLink;
}
OUString BookmarksTabPage_Impl::GetSelectedEntry() const
{
return m_xBookmarksBox->get_selected_id();
}
void BookmarksTabPage_Impl::AddBookmarks(const OUString& rTitle, const OUString& rURL)
{
const OUString aImageURL {IMAGE_URL + INetURLObject(rURL).GetHost()};
m_xBookmarksBox->append(rURL, rTitle, SvFileInformationManager::GetImageId(INetURLObject(aImageURL)));
}
OUString SfxHelpWindow_Impl::buildHelpURL(const OUString& sFactory ,
const OUString& sContent ,
const OUString& sAnchor)
{
OUStringBuffer sHelpURL(256);
sHelpURL.append(HELP_URL);
sHelpURL.append(sFactory);
sHelpURL.append(sContent);
AppendConfigToken(sHelpURL, true/*bUseQuestionMark*/);
if (!sAnchor.isEmpty())
sHelpURL.append(sAnchor);
return sHelpURL.makeStringAndClear();
}
void SfxHelpWindow_Impl::loadHelpContent(const OUString& sHelpURL, bool bAddToHistory)
{
Reference< XComponentLoader > xLoader(getTextFrame(), UNO_QUERY);
if (!xLoader.is())
return;
// If a print job runs do not open a new page
Reference< XFrame2 > xTextFrame = pTextWin->getFrame();
Reference< XController > xTextController ;
if (xTextFrame.is())
xTextController = xTextFrame->getController ();
if ( xTextController.is() && !xTextController->suspend( true ) )
{
xTextController->suspend( false );
return;
}
// save url to history
if (bAddToHistory)
pHelpInterceptor->addURL(sHelpURL);
if ( !IsWait() )
EnterWait();
bool bSuccess = false;
// TODO implement locale fallback ... see below while(true)
{
try
{
Reference< XComponent > xContent = xLoader->loadComponentFromURL(sHelpURL, "_self", 0, Sequence< PropertyValue >());
if (xContent.is())
{
bSuccess = true;
}
}
catch(const RuntimeException&)
{ throw; }
catch(const Exception&)
{ /*break;*/ }
/* TODO try next locale ...
no further locale available? => break loop and show error page
*/
}
openDone(sHelpURL, bSuccess);
if ( IsWait() )
LeaveWait();
}
IMPL_LINK(SfxHelpIndexWindow_Impl, ActivatePageHdl, const OString&, rPage, void)
{
GetPage(rPage)->Activate();
}
SfxHelpIndexWindow_Impl::SfxHelpIndexWindow_Impl(SfxHelpWindow_Impl* _pParent, weld::Container* pContainer)
: m_xBuilder(Application::CreateBuilder(pContainer, "sfx/ui/helpcontrol.ui"))
, m_xContainer(m_xBuilder->weld_container("HelpControl"))
, m_xActiveLB(m_xBuilder->weld_combo_box("active"))
, m_xTabCtrl(m_xBuilder->weld_notebook("tabcontrol"))
, aIdle("sfx2 appl SfxHelpIndexWindow_Impl")
, aIndexKeywordLink(LINK(this, SfxHelpIndexWindow_Impl, KeywordHdl))
, pParentWin(_pParent)
, bIsInitDone(false)
{
// create the pages
GetContentPage();
GetIndexPage();
GetSearchPage();
GetBookmarksPage();
OString sPageId("index");
SvtViewOptions aViewOpt( EViewType::TabDialog, CONFIGNAME_INDEXWIN );
if ( aViewOpt.Exists() )
sPageId = aViewOpt.GetPageID();
m_xTabCtrl->set_current_page(sPageId);
ActivatePageHdl(sPageId);
m_xActiveLB->connect_changed(LINK(this, SfxHelpIndexWindow_Impl, SelectHdl));
m_xTabCtrl->connect_enter_page(LINK(this, SfxHelpIndexWindow_Impl, ActivatePageHdl));
aIdle.SetInvokeHandler( LINK( this, SfxHelpIndexWindow_Impl, InitHdl ) );
aIdle.Start();
m_xContainer->show();
}
SfxHelpIndexWindow_Impl::~SfxHelpIndexWindow_Impl()
{
SvtViewOptions aViewOpt(EViewType::TabDialog, CONFIGNAME_INDEXWIN);
aViewOpt.SetPageID(m_xTabCtrl->get_current_page_ident());
xCPage.reset();
xIPage.reset();
xSPage.reset();
xBPage.reset();
}
void SfxHelpIndexWindow_Impl::Initialize()
{
OUStringBuffer aHelpURL(HELP_URL);
AppendConfigToken(aHelpURL, true);
std::vector<OUString> aFactories = SfxContentHelper::GetResultSet(aHelpURL.makeStringAndClear());
for (const OUString & rRow : aFactories)
{
sal_Int32 nIdx = 0;
OUString aTitle = rRow.getToken( 0, '\t', nIdx ); // token 0
OUString aURL = rRow.getToken( 1, '\t', nIdx ); // token 2
OUString aFactory(INetURLObject(aURL).GetHost());
m_xActiveLB->append(aFactory, aTitle);
}
if (m_xActiveLB->get_active() == -1)
SetActiveFactory();
}
void SfxHelpIndexWindow_Impl::SetActiveFactory()
{
DBG_ASSERT( xIPage, "index page not initialized" );
if (!bIsInitDone && !m_xActiveLB->get_count())
{
aIdle.Stop();
InitHdl( nullptr );
}
for (sal_Int32 i = 0, nEntryCount = m_xActiveLB->get_count(); i < nEntryCount; ++i)
{
OUString aFactory = m_xActiveLB->get_id(i);
aFactory = aFactory.toAsciiLowerCase();
if (aFactory == xIPage->GetFactory())
{
if (m_xActiveLB->get_active() != i)
{
m_xActiveLB->set_active(i);
aSelectFactoryLink.Call(nullptr);
}
break;
}
}
}
HelpTabPage_Impl* SfxHelpIndexWindow_Impl::GetPage(const OString& rName)
{
HelpTabPage_Impl* pPage = nullptr;
if (rName == "contents")
pPage = GetContentPage();
else if (rName == "index")
pPage = GetIndexPage();
else if (rName == "find")
pPage = GetSearchPage();
else if (rName == "bookmarks")
pPage = GetBookmarksPage();
assert(pPage && "SfxHelpIndexWindow_Impl::GetCurrentPage(): no current page");
return pPage;
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, SelectHdl, weld::ComboBox&, void)
{
aIdle.Start();
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, InitHdl, Timer *, void)
{
bIsInitDone = true;
Initialize();
// now use the timer for selection
aIdle.SetInvokeHandler( LINK( this, SfxHelpIndexWindow_Impl, SelectFactoryHdl ) );
aIdle.SetPriority( TaskPriority::LOWEST );
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, SelectFactoryHdl, Timer *, void)
{
OUString aFactory = m_xActiveLB->get_active_id();
if (!aFactory.isEmpty())
{
SetFactory(aFactory.toAsciiLowerCase(), false);
aSelectFactoryLink.Call(this);
}
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, KeywordHdl, IndexTabPage_Impl&, void)
{
// keyword found on index?
bool bIndex = xIPage->HasKeyword();
if( !bIndex)
bIndex = xIPage->HasKeywordIgnoreCase();
// then set index or search page as current.
OString sPageId = bIndex ? "index" : "find";
if (sPageId != m_xTabCtrl->get_current_page_ident())
m_xTabCtrl->set_current_page(sPageId);
// at last we open the keyword
if ( bIndex )
xIPage->OpenKeyword();
else if ( !xSPage->OpenKeyword( sKeyword ) )
pParentWin->ShowStartPage();
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, IndexTabPageDoubleClickHdl, LinkParamNone*, void)
{
aPageDoubleClickLink.Call(nullptr);
}
void SfxHelpIndexWindow_Impl::SetDoubleClickHdl(const Link<LinkParamNone*, void>& rLink)
{
aPageDoubleClickLink = rLink;
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, ContentTabPageDoubleClickHdl, LinkParamNone*, void)
{
aPageDoubleClickLink.Call(nullptr);
}
IMPL_LINK_NOARG(SfxHelpIndexWindow_Impl, TabPageDoubleClickHdl, LinkParamNone*, void)
{
aPageDoubleClickLink.Call(nullptr);
}
void SfxHelpIndexWindow_Impl::SetFactory( const OUString& rFactory, bool bActive )
{
if ( !rFactory.isEmpty() )
{
GetIndexPage()->SetFactory( rFactory );
// the index page made a check if rFactory is valid,
// so the index page always returns a valid factory
GetSearchPage()->SetFactory( GetIndexPage()->GetFactory() );
if ( bActive )
SetActiveFactory();
}
}
OUString SfxHelpIndexWindow_Impl::GetSelectedEntry() const
{
OUString sRet;
OString sName(m_xTabCtrl->get_current_page_ident());
if (sName == "contents")
{
sRet = xCPage->GetSelectedEntry();
}
else if (sName == "index")
{
sRet = xIPage->GetSelectedEntry();
}
else if (sName == "find")
{
sRet = xSPage->GetSelectedEntry();
}
else if (sName == "bookmarks")
{
sRet = xBPage->GetSelectedEntry();
}
return sRet;
}
void SfxHelpIndexWindow_Impl::AddBookmarks( const OUString& rTitle, const OUString& rURL )
{
GetBookmarksPage()->AddBookmarks( rTitle, rURL );
}
bool SfxHelpIndexWindow_Impl::IsValidFactory( const OUString& _rFactory )
{
bool bValid = false;
for (sal_Int32 i = 0, nEntryCount = m_xActiveLB->get_count(); i < nEntryCount; ++i)
{
OUString aFactory = m_xActiveLB->get_id(i);
if (aFactory == _rFactory)
{
bValid = true;
break;
}
}
return bValid;
}
void SfxHelpIndexWindow_Impl::ClearSearchPage()
{
if ( xSPage )
xSPage->ClearPage();
}
void SfxHelpIndexWindow_Impl::GrabFocusBack()
{
OString sName(m_xTabCtrl->get_current_page_ident());
if (sName == "contents" && xCPage)
xCPage->SetFocusOnBox();
else if (sName == "index" && xIPage)
xIPage->SetFocusOnBox();
else if (sName == "find" && xSPage)
xSPage->SetFocusOnBox();
else if (sName == "bookmarks" && xBPage)
xBPage->SetFocusOnBox();
}
bool SfxHelpIndexWindow_Impl::HasFocusOnEdit() const
{
bool bRet = false;
OString sName(m_xTabCtrl->get_current_page_ident());
if (sName == "index" && xIPage)
bRet = xIPage->HasFocusOnEdit();
else if (sName == "find" && xSPage)
bRet = xSPage->HasFocusOnEdit();
return bRet;
}
OUString SfxHelpIndexWindow_Impl::GetSearchText() const
{
OUString sRet;
OString sName(m_xTabCtrl->get_current_page_ident());
if (sName == "find" && xSPage)
sRet = xSPage->GetSearchText();
return sRet;
}
bool SfxHelpIndexWindow_Impl::IsFullWordSearch() const
{
bool bRet = false;
OString sName(m_xTabCtrl->get_current_page_ident());
if (sName == "find" && xSPage)
bRet = xSPage->IsFullWordSearch();
return bRet;
}
void SfxHelpIndexWindow_Impl::OpenKeyword( const OUString& rKeyword )
{
sKeyword = rKeyword;
DBG_ASSERT( xIPage, "invalid index page" );
xIPage->SetKeyword( sKeyword );
}
void SfxHelpIndexWindow_Impl::SelectExecutableEntry()
{
OString sName(m_xTabCtrl->get_current_page_ident());
if (sName == "index" && xIPage )
xIPage->SelectExecutableEntry();
}
weld::Window* SfxHelpIndexWindow_Impl::GetFrameWeld() const
{
return pParentWin->GetFrameWeld();
}
// class TextWin_Impl ----------------------------------------------------
TextWin_Impl::TextWin_Impl( vcl::Window* p ) : DockingWindow( p, 0 )
{
}
bool TextWin_Impl::EventNotify( NotifyEvent& rNEvt )
{
if( ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) && rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_TAB )
return GetParent()->EventNotify( rNEvt );
else
return DockingWindow::EventNotify( rNEvt );
}
// remove docking area acceptor from layoutmanager, so it will not layout anything further .-)
static void lcl_disableLayoutOfFrame(const Reference< XFrame2 >& xFrame)
{
xFrame->setLayoutManager( Reference< XLayoutManager >() );
}
// class SfxHelpTextWindow_Impl ------------------------------------------
SfxHelpTextWindow_Impl::SfxHelpTextWindow_Impl(SfxHelpWindow_Impl* pHelpWin, weld::Builder& rBuilder, vcl::Window* pParent) :
Window( pParent, WB_CLIPCHILDREN | WB_TABSTOP | WB_DIALOGCONTROL ),
xToolBox ( rBuilder.weld_toolbar("toolbar") ),
xOnStartupCB ( rBuilder.weld_check_button("checkbutton") ),
xMenu ( rBuilder.weld_menu("menu") ),
aSelectIdle ( "sfx2 appl SfxHelpTextWindow_Impl Select" ),
aIndexOnImage ( BMP_HELP_TOOLBOX_INDEX_ON ),
aIndexOffImage ( BMP_HELP_TOOLBOX_INDEX_OFF ),
aIndexOnText ( SfxResId( STR_HELP_BUTTON_INDEX_ON ) ),
aIndexOffText ( SfxResId( STR_HELP_BUTTON_INDEX_OFF ) ),
aOnStartupText ( SfxResId( RID_HELP_ONSTARTUP_TEXT ) ),
xHelpWin ( pHelpWin ),
pTextWin ( VclPtr<TextWin_Impl>::Create( this ) ),
bIsDebug ( false ),
bIsIndexOn ( false ),
bIsInClose ( false ),
bIsFullWordSearch ( false )
{
xFrame = Frame::create( ::comphelper::getProcessComponentContext() );<--- Variable 'xFrame' is assigned in constructor body. Consider performing initialization in initialization list. [+]When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'xFrame' a value by passing the value to the constructor in the initialization list.
xFrame->initialize( VCLUnoHelper::GetInterface ( pTextWin ) );
xFrame->setName( "OFFICE_HELP" );
lcl_disableLayoutOfFrame(xFrame);
xToolBox->set_help_id(HID_HELP_TOOLBOX);
xToolBox->set_item_tooltip_text("index", aIndexOffText );
xToolBox->set_item_help_id("index", HID_HELP_TOOLBOXITEM_INDEX);
xToolBox->set_item_help_id("backward", HID_HELP_TOOLBOXITEM_BACKWARD);
xToolBox->set_item_help_id("forward", HID_HELP_TOOLBOXITEM_FORWARD);
xToolBox->set_item_help_id("start", HID_HELP_TOOLBOXITEM_START);
xToolBox->set_item_help_id("print", HID_HELP_TOOLBOXITEM_PRINT);
xToolBox->set_item_help_id("bookmarks", HID_HELP_TOOLBOXITEM_BOOKMARKS );
xToolBox->set_item_help_id("searchdialog", HID_HELP_TOOLBOXITEM_SEARCHDIALOG);
InitToolBoxImages();
InitOnStartupBox();
xOnStartupCB->connect_clicked(LINK(this, SfxHelpTextWindow_Impl, CheckHdl));
aSelectIdle.SetInvokeHandler( LINK( this, SfxHelpTextWindow_Impl, SelectHdl ) );
aSelectIdle.SetPriority( TaskPriority::LOWEST );
char* pEnv = getenv( "help_debug" );
if ( pEnv )
bIsDebug = true;
SvtMiscOptions().AddListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
}
SfxHelpTextWindow_Impl::~SfxHelpTextWindow_Impl()
{
disposeOnce();
}
void SfxHelpTextWindow_Impl::dispose()
{
bIsInClose = true;
SvtMiscOptions().RemoveListenerLink( LINK( this, SfxHelpTextWindow_Impl, NotifyHdl ) );
m_xSrchDlg.reset();
xToolBox.reset();
xOnStartupCB.reset();
xHelpWin.clear();
pTextWin.disposeAndClear();
vcl::Window::dispose();
}
bool SfxHelpTextWindow_Impl::HasSelection() const
{
// is there any selection in the text and not only a cursor?
bool bRet = false;
Reference < XTextRange > xRange = getCursor();
if ( xRange.is() )
{
Reference < XText > xText = xRange->getText();
Reference < XTextCursor > xCursor = xText->createTextCursorByRange( xRange );
bRet = !xCursor->isCollapsed();
}
return bRet;
}
void SfxHelpTextWindow_Impl::InitToolBoxImages()
{
xToolBox->set_item_icon_name("index", bIsIndexOn ? aIndexOffImage : aIndexOnImage);
}
void SfxHelpTextWindow_Impl::InitOnStartupBox()
{
sCurrentFactory = SfxHelp::GetCurrentModuleIdentifier();
Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext();
const OUString sPath { PATH_OFFICE_FACTORIES + sCurrentFactory };
// Attention: This check boy knows two states:
// 1) Reading of the config key fails with an exception or by getting an empty Any (!) => check box must be hidden
// 2) We read sal_True/sal_False => check box must be shown and enabled/disabled
bool bHideBox = true;
bool bHelpAtStartup = false;
try
{
xConfiguration = ConfigurationHelper::openConfig(
xContext, PACKAGE_SETUP, EConfigurationModes::Standard );
if ( xConfiguration.is() )
{
Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, KEY_HELP_ON_OPEN );
if (aAny >>= bHelpAtStartup)
bHideBox = false;
}
}
catch( Exception& )
{
bHideBox = true;
}
if ( bHideBox )
xOnStartupCB->hide();
else
{
// detect module name
OUString sModuleName;
if ( xConfiguration.is() )
{
OUString sTemp;
try
{
Any aAny = ConfigurationHelper::readRelativeKey( xConfiguration, sPath, KEY_UI_NAME );
aAny >>= sTemp;
}
catch( Exception const & )
{
TOOLS_WARN_EXCEPTION( "sfx.appl", "SfxHelpTextWindow_Impl::InitOnStartupBox()" );
}
sModuleName = sTemp;
}
if ( !sModuleName.isEmpty() )
{
// set module name in checkbox text
xOnStartupCB->set_label(aOnStartupText.replaceFirst("%MODULENAME", sModuleName));
// and show it
xOnStartupCB->show();
// set check state
xOnStartupCB->set_active(bHelpAtStartup);
xOnStartupCB->save_state();
}
}
}
Reference< XBreakIterator > const & SfxHelpTextWindow_Impl::GetBreakIterator()
{
if ( !xBreakIterator.is() )
xBreakIterator = vcl::unohelper::CreateBreakIterator();
DBG_ASSERT( xBreakIterator.is(), "Could not create BreakIterator" );
return xBreakIterator;
}
Reference< XTextRange > SfxHelpTextWindow_Impl::getCursor() const
{
// return the current cursor
Reference< XTextRange > xCursor;
try
{
Reference < XSelectionSupplier > xSelSup( xFrame->getController(), UNO_QUERY );
if ( xSelSup.is() )
{
Any aAny = xSelSup->getSelection();
Reference < XIndexAccess > xSelection;
if ( aAny >>= xSelection )
{
if ( xSelection->getCount() == 1 )
{
aAny = xSelection->getByIndex(0);
aAny >>= xCursor;
}
}
}
}
catch( Exception& )
{
OSL_FAIL( "SfxHelpTextWindow_Impl::getCursor(): unexpected exception" );
}
return xCursor;
}
bool SfxHelpTextWindow_Impl::isHandledKey( const vcl::KeyCode& _rKeyCode )
{
bool bRet = false;
sal_uInt16 nCode = _rKeyCode.GetCode();
// the keys <CTRL><A> (select all), <CTRL><C> (copy),
// <CTRL><F> (find), <CTRL><P> (print) and <CTRL><W> (close window)
// were handled in help
if ( _rKeyCode.IsMod1() &&
( KEY_A == nCode || KEY_C == nCode || KEY_F == nCode || KEY_P == nCode || KEY_W == nCode ) )
{
if ( KEY_F == nCode )
DoSearch();
else
bRet = true;
}
return bRet;
}
IMPL_LINK_NOARG(SfxHelpTextWindow_Impl, SelectHdl, Timer *, void)
{
try
{
// select the words, which are equal to the search text of the search page
Reference < XController > xController = xFrame->getController();
if ( xController.is() )
{
// get document
Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
if ( xSearchable.is() )
{
// create descriptor, set string and find all words
Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
xSrchDesc->setPropertyValue( "SearchRegularExpression", makeAny( true ) );
if ( bIsFullWordSearch )
xSrchDesc->setPropertyValue( "SearchWords", makeAny( true ) );
xSrchDesc->setSearchString( sfx2::PrepareSearchString( aSearchText, GetBreakIterator(), false ) );
Reference< XIndexAccess > xSelection = xSearchable->findAll( xSrchDesc );
// then select all found words
Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
if ( xSelectionSup.is() )
{
xSelectionSup->select( Any(xSelection) );
}
}
}
}
catch( Exception& )
{
OSL_FAIL( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
}
}
IMPL_LINK_NOARG( SfxHelpTextWindow_Impl, NotifyHdl, LinkParamNone*, void )
{
InitToolBoxImages();
Resize();
}
IMPL_LINK( SfxHelpTextWindow_Impl, FindHdl, sfx2::SearchDialog&, rDlg, void )
{
FindHdl(&rDlg);
}
void SfxHelpTextWindow_Impl::FindHdl(sfx2::SearchDialog* pDlg)
{
bool bWrapAround = ( nullptr == pDlg );
if ( bWrapAround )
pDlg = m_xSrchDlg.get();
DBG_ASSERT( pDlg, "invalid search dialog" );
try
{
// select the words, which are equal to the search text of the search page
Reference < XController > xController = xFrame->getController();
if ( xController.is() )
{
// get document
Reference < XSearchable > xSearchable( xController->getModel(), UNO_QUERY );
if ( xSearchable.is() )
{
// create descriptor, set string and find all words
Reference < XSearchDescriptor > xSrchDesc = xSearchable->createSearchDescriptor();
xSrchDesc->setPropertyValue( "SearchWords", makeAny(pDlg->IsOnlyWholeWords()) );
xSrchDesc->setPropertyValue( "SearchCaseSensitive", makeAny(pDlg->IsMarchCase()) );
xSrchDesc->setPropertyValue( "SearchBackwards", makeAny(pDlg->IsSearchBackwards()) );
xSrchDesc->setSearchString( pDlg->GetSearchText() );
Reference< XInterface > xSelection;
Reference< XTextRange > xCursor = getCursor();
if ( xCursor.is() )
{
if ( pDlg->IsSearchBackwards() )
xCursor = xCursor->getStart();
xSelection = xSearchable->findNext( xCursor, xSrchDesc );
}
else
xSelection = xSearchable->findFirst( xSrchDesc );
// then select the found word
if ( xSelection.is() )
{
Reference < XSelectionSupplier > xSelectionSup( xController, UNO_QUERY );
if ( xSelectionSup.is() )
{
xSelectionSup->select( Any(xSelection) );
}
}
else if ( pDlg->IsWrapAround() && !bWrapAround )
{
Reference < text::XTextViewCursorSupplier > xCrsrSupp( xController, uno::UNO_QUERY );
Reference < text::XTextViewCursor > xTVCrsr = xCrsrSupp->getViewCursor();
if ( xTVCrsr.is() )
{
Reference < text::XTextDocument > xDoc( xController->getModel(), uno::UNO_QUERY );
Reference < text::XText > xText = xDoc->getText();
if ( xText.is() )
{
if ( pDlg->IsSearchBackwards() )
xTVCrsr->gotoRange( xText->getEnd(), false );
else
xTVCrsr->gotoRange( xText->getStart(), false );
FindHdl( nullptr );
}
}
}
else
{
assert(m_xSrchDlg && "no search dialog");
std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(m_xSrchDlg->getDialog(),
VclMessageType::Info, VclButtonsType::Ok, SfxResId(STR_INFO_NOSEARCHTEXTFOUND)));
xBox->run();
m_xSrchDlg->SetFocusOnEdit();
}
}
}
}
catch( Exception& )
{
OSL_FAIL( "SfxHelpTextWindow_Impl::SelectHdl(): unexpected exception" );
}
}
IMPL_LINK_NOARG(SfxHelpTextWindow_Impl, CloseHdl, LinkParamNone*, void)
{
m_xSrchDlg.reset();
}
IMPL_LINK_NOARG(SfxHelpTextWindow_Impl, CheckHdl, weld::Button&, void)
{
if ( !xConfiguration.is() )
return;
bool bChecked = xOnStartupCB->get_active();
try
{
ConfigurationHelper::writeRelativeKey(
xConfiguration, PATH_OFFICE_FACTORIES + sCurrentFactory, KEY_HELP_ON_OPEN, makeAny( bChecked ) );
ConfigurationHelper::flush( xConfiguration );
}
catch( Exception const & )
{
TOOLS_WARN_EXCEPTION( "sfx.appl", "SfxHelpTextWindow_Impl::CheckHdl()" );
}
}
void SfxHelpTextWindow_Impl::Resize()
{
Size aSize = GetOutputSizePixel();
pTextWin->SetPosSizePixel( Point(0, 0), aSize );
}
bool SfxHelpTextWindow_Impl::PreNotify( NotifyEvent& rNEvt )
{
bool bDone = false;
MouseNotifyEvent nType = rNEvt.GetType();
if ( MouseNotifyEvent::COMMAND == nType && rNEvt.GetCommandEvent() )
{
const CommandEvent* pCmdEvt = rNEvt.GetCommandEvent();
vcl::Window* pCmdWin = rNEvt.GetWindow();
if ( pCmdEvt->GetCommand() == CommandEventId::ContextMenu && pCmdWin != this )
{
Point aPos;
if ( pCmdEvt->IsMouseEvent() )
aPos = pCmdEvt->GetMousePosPixel();
else
aPos = Point( pTextWin->GetPosPixel().X() + 20, 20 );
xMenu->clear();
if (bIsIndexOn)
xMenu->append("index", aIndexOffText, BMP_HELP_TOOLBOX_INDEX_OFF);
else
xMenu->append("index", aIndexOnText, BMP_HELP_TOOLBOX_INDEX_ON);
xMenu->append_separator("separator1");
xMenu->append("backward", SfxResId(STR_HELP_BUTTON_PREV), BMP_HELP_TOOLBOX_PREV);
xMenu->set_sensitive("backward", xHelpWin->HasHistoryPredecessor());
xMenu->append("forward", SfxResId(STR_HELP_BUTTON_NEXT), BMP_HELP_TOOLBOX_NEXT);
xMenu->set_sensitive("forward", xHelpWin->HasHistorySuccessor());
xMenu->append("start", SfxResId(STR_HELP_BUTTON_START), BMP_HELP_TOOLBOX_START);
xMenu->append_separator("separator2");
xMenu->append("print", SfxResId(STR_HELP_BUTTON_PRINT), BMP_HELP_TOOLBOX_PRINT);
xMenu->append("bookmarks", SfxResId(STR_HELP_BUTTON_ADDBOOKMARK), BMP_HELP_TOOLBOX_BOOKMARKS);
xMenu->append("searchdialog", SfxResId(STR_HELP_BUTTON_SEARCHDIALOG), BMP_HELP_TOOLBOX_SEARCHDIALOG);
xMenu->append_separator("separator3");
xMenu->append_check("selectionmode", SfxResId(STR_HELP_MENU_TEXT_SELECTION_MODE));
URL aURL;
aURL.Complete = ".uno:SelectTextMode";
Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
xTrans->parseStrict(aURL);
Reference < XDispatch > xDisp = xFrame->queryDispatch( aURL, OUString(), 0 );
if(xDisp.is())
{
rtl::Reference<HelpStatusListener_Impl> pStateListener =
new HelpStatusListener_Impl(xDisp, aURL );
FeatureStateEvent rEvent = pStateListener->GetStateEvent();
bool bCheck = false;
rEvent.State >>= bCheck;
xMenu->set_active("selectionmode", bCheck);
}
xMenu->append_separator("separator4");
xMenu->append("copy", SfxResId(STR_HELP_MENU_TEXT_COPY), BMP_HELP_TOOLBOX_COPY);
xMenu->set_sensitive("copy", HasSelection());
if ( bIsDebug )
{
xMenu->append_separator("separator5");
xMenu->append("sourceview", SfxResId(STR_HELP_BUTTON_SOURCEVIEW));
}
int x, y, width, height;
weld::Window* pTopLevel = GetFrameWeld();
xHelpWin->GetContainer()->get_extents_relative_to(*pTopLevel, x, y, width, height);
aPos.AdjustX(x);
aPos.AdjustY(y);
xHelpWin->DoAction(xMenu->popup_at_rect(pTopLevel, tools::Rectangle(aPos, Size(1,1))));
bDone = true;
}
}
else if ( MouseNotifyEvent::KEYINPUT == nType && rNEvt.GetKeyEvent() )
{
const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
const vcl::KeyCode& rKeyCode = pKEvt->GetKeyCode();
sal_uInt16 nKeyGroup = rKeyCode.GetGroup();
sal_uInt16 nKey = rKeyCode.GetCode();
if ( KEYGROUP_ALPHA == nKeyGroup && !isHandledKey( rKeyCode ) )
{
// do nothing disables the writer accelerators
bDone = true;
}
else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
{
// <CTRL><F4> or <CTRL><W> -> close top frame
xHelpWin->CloseWindow();
bDone = true;
}
else if ( KEY_TAB == nKey && xOnStartupCB->has_focus() )
{
xToolBox->grab_focus();
bDone = true;
}
}
return bDone || Window::PreNotify( rNEvt );
}
void SfxHelpTextWindow_Impl::GetFocus()
{
if ( bIsInClose )
return;
try
{
if( xFrame.is() )
{
Reference< css::awt::XWindow > xWindow = xFrame->getComponentWindow();
if( xWindow.is() )
xWindow->setFocus();
}
}
catch( Exception const & )
{
TOOLS_WARN_EXCEPTION( "sfx.appl", "SfxHelpTextWindow_Impl::GetFocus()" );
}
}
void SfxHelpTextWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
{
Window::DataChanged( rDCEvt );
if ( ( ( rDCEvt.GetType() == DataChangedEventType::SETTINGS ) ||
( rDCEvt.GetType() == DataChangedEventType::DISPLAY ) ) &&
( rDCEvt.GetFlags() & AllSettingsFlags::STYLE ) )
{
SetBackground( Wallpaper( GetSettings().GetStyleSettings().GetFaceColor() ) );
InitToolBoxImages();
}
}
void SfxHelpTextWindow_Impl::ToggleIndex( bool bOn )
{
bIsIndexOn = bOn;
if ( bIsIndexOn )
{
xToolBox->set_item_icon_name("index", aIndexOffImage);
xToolBox->set_item_tooltip_text("index", aIndexOffText);
}
else
{
xToolBox->set_item_icon_name("index", aIndexOnImage);
xToolBox->set_item_tooltip_text("index", aIndexOnText);
}
}
void SfxHelpTextWindow_Impl::SelectSearchText( const OUString& rSearchText, bool _bIsFullWordSearch )
{
aSearchText = rSearchText;
bIsFullWordSearch = _bIsFullWordSearch;
aSelectIdle.Start();
}
void SfxHelpTextWindow_Impl::SetPageStyleHeaderOff() const
{
bool bSetOff = false;
// set off the pagestyle header to prevent print output of the help URL
try
{
Reference < XController > xController = xFrame->getController();
Reference < XSelectionSupplier > xSelSup( xController, UNO_QUERY );
if ( xSelSup.is() )
{
Reference < XIndexAccess > xSelection;
if ( xSelSup->getSelection() >>= xSelection )
{
Reference < XTextRange > xRange;
if ( xSelection->getByIndex(0) >>= xRange )
{
Reference < XText > xText = xRange->getText();
Reference < XPropertySet > xProps( xText->createTextCursorByRange( xRange ), UNO_QUERY );
OUString sStyleName;
if ( xProps->getPropertyValue( "PageStyleName" ) >>= sStyleName )
{
Reference < XStyleFamiliesSupplier > xStyles( xController->getModel(), UNO_QUERY );
Reference < XNameContainer > xContainer;
if ( xStyles->getStyleFamilies()->getByName( "PageStyles" )
>>= xContainer )
{
Reference < XStyle > xStyle;
if ( xContainer->getByName( sStyleName ) >>= xStyle )
{
Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
xPropSet->setPropertyValue( "HeaderIsOn", makeAny( false ) );
Reference< XModifiable > xReset(xStyles, UNO_QUERY);
xReset->setModified(false);
bSetOff = true;
}
}
}
}
}
}
}
catch( Exception const & )
{
TOOLS_WARN_EXCEPTION( "sfx.appl", "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff()" );
}
SAL_WARN_IF( !bSetOff, "sfx.appl", "SfxHelpTextWindow_Impl::SetPageStyleHeaderOff(): set off failed" );
}
void SfxHelpTextWindow_Impl::CloseFrame()
{
bIsInClose = true;
try
{
css::uno::Reference< css::util::XCloseable > xCloseable ( xFrame, css::uno::UNO_QUERY );
if (xCloseable.is())
xCloseable->close(true);
}
catch( css::util::CloseVetoException& )
{
}
}
void SfxHelpTextWindow_Impl::DoSearch()
{
if (m_xSrchDlg)
return;
// create the search dialog
m_xSrchDlg = std::make_shared<sfx2::SearchDialog>(pTextWin->GetFrameWeld(), "HelpSearchDialog");
// set handler
m_xSrchDlg->SetFindHdl( LINK( this, SfxHelpTextWindow_Impl, FindHdl ) );
m_xSrchDlg->SetCloseHdl( LINK( this, SfxHelpTextWindow_Impl, CloseHdl ) );
// get selected text of the help page to set it as the search text
Reference< XTextRange > xCursor = getCursor();
if ( xCursor.is() )
{
OUString sText = xCursor->getString();
if ( !sText.isEmpty() )
m_xSrchDlg->SetSearchText( sText );
}
sfx2::SearchDialog::runAsync(m_xSrchDlg);
}
void SfxHelpWindow_Impl::GetFocus()
{
if (pTextWin)
pTextWin->GrabFocus();
else
DockingWindow::GetFocus();
}
void SfxHelpWindow_Impl::MakeLayout()
{
Split();
m_xHelpPaneWindow->set_visible(bIndex);
}
IMPL_LINK(SfxHelpWindow_Impl, ResizeHdl, const Size&, rSize, void)
{
int nNewWidth = rSize.Width();
if (!nNewWidth)
return;
if (bSplit)
nIndexSize = round(m_xContainer->get_position() * 100.0 / nNewWidth);
nWidth = nNewWidth;
Split();
nIndexSize = round(m_xContainer->get_position() * 100.0 / nWidth);
}
void SfxHelpWindow_Impl::Split()
{
if (!nWidth)
return;
m_xContainer->set_position(nWidth * nIndexSize / 100);
bSplit = true;
}
void SfxHelpWindow_Impl::LoadConfig()
{
SvtViewOptions aViewOpt( EViewType::Window, CONFIGNAME_HELPWIN );
if ( !aViewOpt.Exists() )
return;
bIndex = aViewOpt.IsVisible();
Any aUserItem = aViewOpt.GetUserItem( USERITEM_NAME );
OUString aUserData;
if ( aUserItem >>= aUserData )<--- Variable 'aUserItem' is assigned a value that is never used.
{
DBG_ASSERT( comphelper::string::getTokenCount(aUserData, ';') == 6, "invalid user data" );
sal_Int32 nIdx = 0;
nIndexSize = aUserData.getToken( 0, ';', nIdx ).toInt32();
aUserData.getToken(0, ';', nIdx); // ignore nTextSize
sal_Int32 nOldWidth = aUserData.getToken( 0, ';', nIdx ).toInt32();
sal_Int32 nOldHeight = aUserData.getToken( 0, ';', nIdx ).toInt32();
aWinSize = Size(nOldWidth, nOldHeight);
aWinPos.setX( aUserData.getToken( 0, ';', nIdx ).toInt32() );
aWinPos.setY( aUserData.getToken( 0, ';', nIdx ).toInt32() );
}
pTextWin->ToggleIndex( bIndex );
}
void SfxHelpWindow_Impl::SaveConfig()
{
SvtViewOptions aViewOpt( EViewType::Window, CONFIGNAME_HELPWIN );
sal_Int32 nW = 0, nH = 0;
if ( xWindow.is() )
{
css::awt::Rectangle aRect = xWindow->getPosSize();
nW = aRect.Width;
nH = aRect.Height;
}
aViewOpt.SetVisible( bIndex );
VclPtr<vcl::Window> pScreenWin = VCLUnoHelper::GetWindow( xWindow );
aWinPos = pScreenWin->GetWindowExtentsRelative( nullptr ).TopLeft();
if (bSplit)
nIndexSize = round(m_xContainer->get_position() * 100.0 / nWidth);
const OUString aUserData = OUString::number( nIndexSize )
+ ";" + OUString::number( 100 - nIndexSize )
+ ";" + OUString::number( nW )
+ ";" + OUString::number( nH )
+ ";" + OUString::number( aWinPos.X() )
+ ";" + OUString::number( aWinPos.Y() );
aViewOpt.SetUserItem( USERITEM_NAME, makeAny( aUserData ) );
}
void SfxHelpWindow_Impl::ShowStartPage()
{
loadHelpContent(SfxHelpWindow_Impl::buildHelpURL(xIndexWin->GetFactory(), "/start", OUString()));
}
IMPL_LINK(SfxHelpWindow_Impl, SelectHdl, const OString&, rCurItem, void)
{
bGrabFocusToToolBox = pTextWin->GetToolBox().has_focus();
DoAction(rCurItem);
}
IMPL_LINK_NOARG(SfxHelpWindow_Impl, OpenHdl, LinkParamNone*, void)
{
xIndexWin->SelectExecutableEntry();
OUString aEntry = xIndexWin->GetSelectedEntry();
if ( aEntry.isEmpty() )
return;
OUString sHelpURL;
bool bComplete = aEntry.toAsciiLowerCase().match("vnd.sun.star.help");
if (bComplete)
sHelpURL = aEntry;
else
{
OUString aId;
OUString aAnchor('#');
if ( comphelper::string::getTokenCount(aEntry, '#') == 2 )
{
sal_Int32 nIdx{ 0 };
aId = aEntry.getToken( 0, '#', nIdx );
aAnchor += aEntry.getToken( 0, '#', nIdx );
}
else
aId = aEntry;
sHelpURL = SfxHelpWindow_Impl::buildHelpURL(xIndexWin->GetFactory(), "/" + aId, aAnchor);
}
loadHelpContent(sHelpURL);
}
IMPL_LINK( SfxHelpWindow_Impl, SelectFactoryHdl, SfxHelpIndexWindow_Impl* , pWin, void )
{
if ( sTitle.isEmpty() )
sTitle = GetParent()->GetText();
Reference< XTitle > xTitle(xFrame, UNO_QUERY);
if (xTitle.is ())
xTitle->setTitle(sTitle + " - " + xIndexWin->GetActiveFactoryTitle());
if ( pWin )
ShowStartPage();
xIndexWin->ClearSearchPage();
}
IMPL_LINK( SfxHelpWindow_Impl, ChangeHdl, HelpListener_Impl&, rListener, void )
{
SetFactory( rListener.GetFactory() );
}
void SfxHelpWindow_Impl::openDone(const OUString& sURL ,
bool bSuccess)
{
INetURLObject aObj( sURL );
if ( aObj.GetProtocol() == INetProtocol::VndSunStarHelp )
SetFactory( aObj.GetHost() );
if ( IsWait() )
LeaveWait();
if ( bGrabFocusToToolBox )
{
pTextWin->GetToolBox().grab_focus();
bGrabFocusToToolBox = false;
}
else
xIndexWin->GrabFocusBack();
if ( !bSuccess )
return;
// set some view settings: "prevent help tips" and "helpid == 68245"
try
{
Reference < XController > xController = pTextWin->getFrame()->getController();
if ( xController.is() )
{
Reference < XViewSettingsSupplier > xSettings( xController, UNO_QUERY );
Reference < XPropertySet > xViewProps = xSettings->getViewSettings();
Reference< XPropertySetInfo > xInfo = xViewProps->getPropertySetInfo();
xViewProps->setPropertyValue( "ShowContentTips", makeAny( false ) );
xViewProps->setPropertyValue( "ShowGraphics", makeAny( true ) );
xViewProps->setPropertyValue( "ShowTables", makeAny( true ) );
xViewProps->setPropertyValue( "HelpURL", makeAny( OUString("HID:SFX2_HID_HELP_ONHELP") ) );
OUString sProperty( "IsExecuteHyperlinks" );
if ( xInfo->hasPropertyByName( sProperty ) )
xViewProps->setPropertyValue( sProperty, makeAny( true ) );
xController->restoreViewData(Any());
}
}
catch( Exception& )
{
OSL_FAIL( "SfxHelpWindow_Impl::OpenDoneHdl(): unexpected exception" );
}
// When the SearchPage opens the help doc, then select all words, which are equal to its text
OUString sSearchText = comphelper::string::strip(xIndexWin->GetSearchText(), ' ');
if ( !sSearchText.isEmpty() )
pTextWin->SelectSearchText( sSearchText, xIndexWin->IsFullWordSearch() );
// no page style header -> this prevents a print output of the URL
pTextWin->SetPageStyleHeaderOff();
}
SfxHelpWindow_Impl::SfxHelpWindow_Impl(
const css::uno::Reference < css::frame::XFrame2 >& rFrame,
vcl::Window* pParent ) :
DockingWindow(pParent, "DockingWindow", "sfx/ui/dockingwindow.ui"),
xFrame ( rFrame ),
pTextWin ( nullptr ),
pHelpInterceptor ( new HelpInterceptor_Impl() ),
pHelpListener ( new HelpListener_Impl( pHelpInterceptor ) ),
bIndex ( true ),
bGrabFocusToToolBox ( false ),
bSplit ( false ),
nWidth ( 0 ),
nIndexSize ( 40 ), // % of width
aWinPos ( 0, 0 ),
aWinSize ( 0, 0 ),
sTitle ( pParent->GetText() )
{
SetStyle(GetStyle() & ~WB_DOCKABLE);
SetHelpId( HID_HELP_WINDOW );
m_xVclContentArea = VclPtr<VclVBox>::Create(this);
m_xVclContentArea->Show();
m_xBuilder.reset(Application::CreateInterimBuilder(m_xVclContentArea, "sfx/ui/helpwindow.ui"));
m_xContainer = m_xBuilder->weld_paned("HelpWindow");
m_xContainer->connect_size_allocate(LINK(this, SfxHelpWindow_Impl, ResizeHdl));
m_xHelpPaneWindow = m_xBuilder->weld_container("helppanewindow");
m_xHelpTextWindow = m_xBuilder->weld_container("helptextwindow");
m_xHelpTextWindow->set_size_request(m_xHelpTextWindow->get_approximate_digit_width() * 120, -1);
m_xHelpTextXWindow = m_xHelpTextWindow->CreateChildFrame();
pHelpInterceptor->InitWaiter( this );
xIndexWin.reset(new SfxHelpIndexWindow_Impl(this, m_xHelpPaneWindow.get()));
xIndexWin->SetDoubleClickHdl( LINK( this, SfxHelpWindow_Impl, OpenHdl ) );
xIndexWin->SetSelectFactoryHdl( LINK( this, SfxHelpWindow_Impl, SelectFactoryHdl ) );
pTextWin = VclPtr<SfxHelpTextWindow_Impl>::Create(this, *m_xBuilder, VCLUnoHelper::GetWindow(m_xHelpTextXWindow));
Reference < XFrames > xFrames = rFrame->getFrames();
xFrames->append( Reference<XFrame>(pTextWin->getFrame(), UNO_QUERY_THROW) );
pTextWin->SetSelectHdl( LINK( this, SfxHelpWindow_Impl, SelectHdl ) );
pTextWin->Show();
pHelpInterceptor->setInterception( Reference<XFrame>(pTextWin->getFrame(), UNO_QUERY_THROW) );
pHelpListener->SetChangeHdl( LINK( this, SfxHelpWindow_Impl, ChangeHdl ) );
LoadConfig();
}
SfxHelpWindow_Impl::~SfxHelpWindow_Impl()
{
disposeOnce();
}
void SfxHelpWindow_Impl::dispose()
{
SaveConfig();
xIndexWin.reset();
pTextWin->CloseFrame();
pTextWin.disposeAndClear();
m_xHelpTextXWindow->dispose();
m_xHelpTextXWindow.clear();
m_xHelpTextWindow.reset();
m_xHelpPaneWindow.reset();
m_xContainer.reset();
m_xBuilder.reset();
m_xVclContentArea.disposeAndClear();
DockingWindow::dispose();
}
bool SfxHelpWindow_Impl::PreNotify( NotifyEvent& rNEvt )
{
bool bHandled = false;
if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
{
// Backward == <ALT><LEFT> or <BACKSPACE> Forward == <ALT><RIGHT>
const vcl::KeyCode& rKeyCode = rNEvt.GetKeyEvent()->GetKeyCode();
sal_uInt16 nKey = rKeyCode.GetCode();
if ( ( rKeyCode.IsMod2() && ( KEY_LEFT == nKey || KEY_RIGHT == nKey ) ) ||
( !rKeyCode.GetModifier() && KEY_BACKSPACE == nKey && !xIndexWin->HasFocusOnEdit() ) )
{
DoAction( rKeyCode.GetCode() == KEY_RIGHT ? "forward" : "backward" );
bHandled = true;
}
else if ( rKeyCode.IsMod1() && ( KEY_F4 == nKey || KEY_W == nKey ) )
{
// <CTRL><F4> or <CTRL><W> -> close top frame
CloseWindow();
bHandled = true;
}
}
return bHandled || Window::PreNotify( rNEvt );
}
void SfxHelpWindow_Impl::setContainerWindow( const Reference < css::awt::XWindow >& xWin )
{
xWindow = xWin;
MakeLayout();
if (xWindow.is())
{
VclPtr<vcl::Window> pScreenWin = VCLUnoHelper::GetWindow(xWindow);
if (aWinSize.Width() && aWinSize.Height())
pScreenWin->SetPosSizePixel(aWinPos, aWinSize);
else
pScreenWin->SetPosPixel(aWinPos);
}
}
void SfxHelpWindow_Impl::SetFactory( const OUString& rFactory )
{
xIndexWin->SetFactory( rFactory, true );
}
void SfxHelpWindow_Impl::SetHelpURL( const OUString& rURL )
{
INetURLObject aObj( rURL );
if ( aObj.GetProtocol() == INetProtocol::VndSunStarHelp )
SetFactory( aObj.GetHost() );
}
void SfxHelpWindow_Impl::DoAction(const OString& rActionId)
{
if (rActionId == "index")
{
bIndex = !bIndex;
MakeLayout();
pTextWin->ToggleIndex( bIndex );
}
else if (rActionId == "start")
{
ShowStartPage();
}
else if (rActionId == "backward" || rActionId == "forward")
{
URL aURL;
aURL.Complete = ".uno:Backward";
if (rActionId == "forward")
aURL.Complete = ".uno:Forward";
Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
xTrans->parseStrict(aURL);
pHelpInterceptor->dispatch( aURL, Sequence < PropertyValue >() );
}
else if (rActionId == "searchdialog")
{
pTextWin->DoSearch();
}
else if (rActionId == "print" || rActionId == "sourceview" || rActionId == "copy" || rActionId == "selectionmode")
{
Reference < XDispatchProvider > xProv = pTextWin->getFrame();
if ( xProv.is() )
{
URL aURL;
if (rActionId == "print")
aURL.Complete = ".uno:Print";
else if (rActionId == "sourceview")
aURL.Complete = ".uno:SourceView";
else if (rActionId == "copy")
aURL.Complete = ".uno:Copy";
else // rActionId == "selectionmode"
aURL.Complete = ".uno:SelectTextMode";
Reference< util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
xTrans->parseStrict(aURL);
Reference < XDispatch > xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
if ( xDisp.is() )
xDisp->dispatch( aURL, Sequence < PropertyValue >() );
}
}
else if (rActionId == "bookmarks")
{
OUString aURL = pHelpInterceptor->GetCurrentURL();
if ( !aURL.isEmpty() )
{
try
{
Content aCnt( aURL, Reference< css::ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
css::uno::Reference< css::beans::XPropertySetInfo > xInfo = aCnt.getProperties();
if ( xInfo->hasPropertyByName( PROPERTY_TITLE ) )
{
css::uno::Any aAny = aCnt.getPropertyValue( PROPERTY_TITLE );
OUString aValue;
if ( aAny >>= aValue )
{
SfxAddHelpBookmarkDialog_Impl aDlg(GetFrameWeld(), false);
aDlg.SetTitle(aValue);
if (aDlg.run() == RET_OK )
{
xIndexWin->AddBookmarks( aDlg.GetTitle(), aURL );
}
}
}
}
catch( Exception& )
{
OSL_FAIL( "SfxHelpWindow_Impl::DoAction(): unexpected exception" );
}
}
}
}
void SfxHelpWindow_Impl::CloseWindow()
{
try
{
// search for top frame
Reference< XFramesSupplier > xCreator = getTextFrame()->getCreator();
while ( xCreator.is() && !xCreator->isTop() )
{
xCreator = xCreator->getCreator();
}
// when found, close it
if ( xCreator.is() && xCreator->isTop() )
{
Reference < XCloseable > xCloser( xCreator, UNO_QUERY );
if ( xCloser.is() )
xCloser->close( false );
}
}
catch( Exception const & )
{
TOOLS_WARN_EXCEPTION( "sfx.appl", "SfxHelpWindow_Impl::CloseWindow()" );
}
}
void SfxHelpWindow_Impl::UpdateToolbox()
{
pTextWin->GetToolBox().set_item_sensitive("backward", pHelpInterceptor->HasHistoryPred());
pTextWin->GetToolBox().set_item_sensitive("forward", pHelpInterceptor->HasHistorySucc());
}
bool SfxHelpWindow_Impl::HasHistoryPredecessor() const
{
return pHelpInterceptor->HasHistoryPred();
}
bool SfxHelpWindow_Impl::HasHistorySuccessor() const
{
return pHelpInterceptor->HasHistorySucc();
}
// class SfxAddHelpBookmarkDialog_Impl -----------------------------------
SfxAddHelpBookmarkDialog_Impl::SfxAddHelpBookmarkDialog_Impl(weld::Widget* pParent, bool bRename)
: GenericDialogController(pParent, "sfx/ui/bookmarkdialog.ui", "BookmarkDialog")
, m_xTitleED(m_xBuilder->weld_entry("entry"))
, m_xAltTitle(m_xBuilder->weld_label("alttitle"))
{
if (bRename)
m_xDialog->set_title(m_xAltTitle->get_label());
}
void SfxAddHelpBookmarkDialog_Impl::SetTitle(const OUString& rTitle)
{
m_xTitleED->set_text(rTitle);
m_xTitleED->select_region(0, -1);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|