summaryrefslogtreecommitdiff
path: root/framework/source/services/frame.cxx
blob: 23a03f1af8cc6087466585b7bf5a3d02fcd93882 (plain)
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
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <sal/config.h>

#include <utility>

#include <dispatch/dispatchprovider.hxx>
#include <dispatch/interceptionhelper.hxx>
#include <dispatch/closedispatcher.hxx>
#include <dispatch/windowcommanddispatch.hxx>
#include <loadenv/loadenv.hxx>
#include <helper/oframes.hxx>
#include <framework/titlehelper.hxx>
#include <svtools/openfiledroptargetlistener.hxx>
#include <classes/taskcreator.hxx>
#include <loadenv/targethelper.hxx>
#include <framework/framelistanalyzer.hxx>
#include <helper/dockingareadefaultacceptor.hxx>
#include <dispatch/dispatchinformationprovider.hxx>
#include <classes/framecontainer.hxx>
#include <general.h>

#include <pattern/window.hxx>
#include <properties.h>

#include <com/sun/star/awt/Toolkit.hpp>
#include <com/sun/star/awt/XDevice.hpp>
#include <com/sun/star/awt/XTopWindow.hpp>
#include <com/sun/star/awt/PosSize.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/beans/PropertyExistException.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
#include <com/sun/star/frame/XFrame2.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
#include <com/sun/star/frame/LayoutManager.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/task/StatusIndicatorFactory.hpp>
#include <com/sun/star/task/theJobExecutor.hpp>
#include <com/sun/star/task/XJobExecutor.hpp>
#include <com/sun/star/util/CloseVetoException.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
#include <com/sun/star/util/XCloseable.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>

#include <comphelper/sequenceashashmap.hxx>
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/weak.hxx>
#include <rtl/ref.hxx>
#include <rtl/ustrbuf.hxx>
#include <vcl/window.hxx>
#include <vcl/wrkwin.hxx>
#include <vcl/svapp.hxx>

#include <toolkit/helper/vclunohelper.hxx>
#include <toolkit/awt/vclxwindow.hxx>
#include <unotools/moduleoptions.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/menu.hxx>
#include <unotools/cmdoptions.hxx>

using namespace framework;

namespace {

// This enum can be used to set different active states of frames
enum EActiveState
{
    E_INACTIVE,   // I'am not a member of active path in tree and i don't have the focus.
    E_ACTIVE,     // I'am in the middle of an active path in tree and i don't have the focus.
    E_FOCUS       // I have the focus now. I must a member of an active path!
};

/*-************************************************************************************************************
    @short      implements a normal frame of hierarchy
    @descr      An instance of these class can be a normal node in frame tree. A frame support influencing of his
                subtree, find of subframes, activate- and deactivate-mechanism as well as
                set/get of a frame window, component or controller.
*//*-*************************************************************************************************************/
class Frame:
    private cppu::BaseMutex,
    public cppu::PartialWeakComponentImplHelper<
        css::lang::XServiceInfo, css::frame::XFrame2, css::awt::XWindowListener,
        css::awt::XTopWindowListener, css::awt::XFocusListener,
        css::document::XActionLockable, css::util::XCloseable,
        css::frame::XComponentLoader, css::frame::XTitle,
        css::frame::XTitleChangeBroadcaster, css::beans::XPropertySet,
        css::beans::XPropertySetInfo>
{
public:

    explicit Frame(const css::uno::Reference< css::uno::XComponentContext >& xContext);

    /// Initialization function after having acquire()'d.
    void initListeners();

    virtual OUString SAL_CALL getImplementationName() override
    {
        return OUString("com.sun.star.comp.framework.Frame");
    }

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

    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
    {
        return {"com.sun.star.frame.Frame"};
    }

    //  XComponentLoader

    virtual css::uno::Reference< css::lang::XComponent > SAL_CALL loadComponentFromURL(
            const OUString& sURL,
            const OUString& sTargetFrameName,
            sal_Int32 nSearchFlags,
            const css::uno::Sequence< css::beans::PropertyValue >& lArguments ) override;

    //  XFramesSupplier

    virtual css::uno::Reference < css::frame::XFrames > SAL_CALL getFrames() override;
    virtual css::uno::Reference < css::frame::XFrame > SAL_CALL getActiveFrame() override;
    virtual void SAL_CALL setActiveFrame(const css::uno::Reference < css::frame::XFrame > & xFrame) override;

    //  XFrame

    virtual void SAL_CALL initialize(const css::uno::Reference < css::awt::XWindow > & xWindow) override;
    virtual css::uno::Reference < css::awt::XWindow > SAL_CALL getContainerWindow() override;
    virtual void SAL_CALL setCreator(const css::uno::Reference < css::frame::XFramesSupplier > & xCreator) override;
    virtual css::uno::Reference < css::frame::XFramesSupplier > SAL_CALL getCreator() override;
    virtual OUString SAL_CALL getName() override;
    virtual void SAL_CALL setName(const OUString & sName) override;
    virtual css::uno::Reference < css::frame::XFrame > SAL_CALL findFrame(
            const OUString & sTargetFrameName,
            sal_Int32 nSearchFlags) override;
    virtual sal_Bool SAL_CALL isTop() override;
    virtual void SAL_CALL activate() override;
    virtual void SAL_CALL deactivate() override;
    virtual sal_Bool SAL_CALL isActive() override;
    virtual void SAL_CALL contextChanged() override;
    virtual sal_Bool SAL_CALL setComponent(
            const css::uno::Reference < css::awt::XWindow > & xComponentWindow,
            const css::uno::Reference < css::frame::XController > & xController) override;
    virtual css::uno::Reference < css::awt::XWindow > SAL_CALL getComponentWindow() override;
    virtual css::uno::Reference < css::frame::XController > SAL_CALL getController() override;
    virtual void SAL_CALL addFrameActionListener(const css::uno::Reference < css::frame::XFrameActionListener > & xListener) override;
    virtual void SAL_CALL removeFrameActionListener(const css::uno::Reference < css::frame::XFrameActionListener > & xListener) override;

    //  XComponent

    virtual void SAL_CALL disposing() override;
    virtual void SAL_CALL addEventListener(const css::uno::Reference < css::lang::XEventListener > & xListener) override;
    virtual void SAL_CALL removeEventListener(const css::uno::Reference < css::lang::XEventListener > & xListener) override;

    //  XStatusIndicatorFactory

    virtual css::uno::Reference < css::task::XStatusIndicator > SAL_CALL createStatusIndicator() override;

    //  XDispatchProvider

    virtual css::uno::Reference < css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL & aURL,
            const OUString & sTargetFrameName,
            sal_Int32 nSearchFlags) override;
    virtual css::uno::Sequence < css::uno::Reference < css::frame::XDispatch > > SAL_CALL queryDispatches(
            const css::uno::Sequence < css::frame::DispatchDescriptor > & lDescriptor) override;

    //  XDispatchProviderInterception

    virtual void SAL_CALL registerDispatchProviderInterceptor(
            const css::uno::Reference < css::frame::XDispatchProviderInterceptor > & xInterceptor) override;
    virtual void SAL_CALL releaseDispatchProviderInterceptor(
            const css::uno::Reference < css::frame::XDispatchProviderInterceptor > & xInterceptor) override;

    //  XDispatchInformationProvider

    virtual css::uno::Sequence < sal_Int16 > SAL_CALL getSupportedCommandGroups() override;
    virtual css::uno::Sequence < css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation(sal_Int16 nCommandGroup) override;

    //  XWindowListener
    //  Attention: windowResized() and windowShown() are implement only! All other are empty!

    virtual void SAL_CALL windowResized(const css::awt::WindowEvent & aEvent) override;
    virtual void SAL_CALL windowMoved(const css::awt::WindowEvent & /*aEvent*/ ) override {};
    virtual void SAL_CALL windowShown(const css::lang::EventObject & aEvent) override;
    virtual void SAL_CALL windowHidden(const css::lang::EventObject & aEvent) override;

    //  XFocusListener
    //  Attention: focusLost() not implemented yet!

    virtual void SAL_CALL focusGained(const css::awt::FocusEvent & aEvent) override;
    virtual void SAL_CALL focusLost(const css::awt::FocusEvent & /*aEvent*/ ) override {};

    //  XTopWindowListener
    //  Attention: windowActivated(), windowDeactivated() and windowClosing() are implement only! All other are empty!

    virtual void SAL_CALL windowActivated(const css::lang::EventObject & aEvent) override;
    virtual void SAL_CALL windowDeactivated(const css::lang::EventObject & aEvent) override;
    virtual void SAL_CALL windowOpened(const css::lang::EventObject & /*aEvent*/ ) override {};
    virtual void SAL_CALL windowClosing(const css::lang::EventObject & aEvent) override;
    virtual void SAL_CALL windowClosed(const css::lang::EventObject & /*aEvent*/ ) override {};
    virtual void SAL_CALL windowMinimized(const css::lang::EventObject & /*aEvent*/ ) override {};
    virtual void SAL_CALL windowNormalized(const css::lang::EventObject & /*aEvent*/ ) override {};

    //  XEventListener

    virtual void SAL_CALL disposing(const css::lang::EventObject & aEvent) override;

    //  XActionLockable

    virtual sal_Bool SAL_CALL isActionLocked() override;
    virtual void SAL_CALL addActionLock() override;
    virtual void SAL_CALL removeActionLock() override;
    virtual void SAL_CALL setActionLocks(sal_Int16 nLock) override;
    virtual sal_Int16 SAL_CALL resetActionLocks() override;

    //  XCloseable

    virtual void SAL_CALL close(sal_Bool bDeliverOwnership) override;

    //  XCloseBroadcaster

    virtual void SAL_CALL addCloseListener(const css::uno::Reference < css::util::XCloseListener > & xListener) override;
    virtual void SAL_CALL removeCloseListener(const css::uno::Reference < css::util::XCloseListener > & xListener) override;

    //  XTitle

    virtual OUString SAL_CALL getTitle() override;
    virtual void SAL_CALL setTitle(const OUString & sTitle) override;

    //  XTitleChangeBroadcaster

    virtual void SAL_CALL addTitleChangeListener(const css::uno::Reference < css::frame::XTitleChangeListener > & xListener) override;
    virtual void SAL_CALL removeTitleChangeListener(const css::uno::Reference < css::frame::XTitleChangeListener > & xListenr) override;

    //  XFrame2 attributes

    virtual css::uno::Reference < css::container::XNameContainer > SAL_CALL getUserDefinedAttributes() override;

    virtual css::uno::Reference < css::frame::XDispatchRecorderSupplier > SAL_CALL getDispatchRecorderSupplier() override;
    virtual void SAL_CALL setDispatchRecorderSupplier(const css::uno::Reference < css::frame::XDispatchRecorderSupplier > & ) override;

    virtual css::uno::Reference < css::uno::XInterface > SAL_CALL getLayoutManager() override;
    virtual void SAL_CALL setLayoutManager(const css::uno::Reference < css::uno::XInterface > & ) override;

    // XPropertySet
    virtual css::uno::Reference < css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;

    virtual void SAL_CALL setPropertyValue(const OUString & sProperty, const css::uno::Any & aValue) override;

    virtual css::uno::Any SAL_CALL getPropertyValue(const OUString & sProperty) override;

    virtual void SAL_CALL addPropertyChangeListener(
            const OUString & sProperty,
            const css::uno::Reference < css::beans::XPropertyChangeListener > & xListener) override;

    virtual void SAL_CALL removePropertyChangeListener(
            const OUString & sProperty,
            const css::uno::Reference < css::beans::XPropertyChangeListener > & xListener) override;

    virtual void SAL_CALL addVetoableChangeListener(
            const OUString & sProperty,
            const css::uno::Reference < css::beans::XVetoableChangeListener > & xListener) override;

    virtual void SAL_CALL removeVetoableChangeListener(
            const OUString & sProperty,
            const css::uno::Reference < css::beans::XVetoableChangeListener > & xListener) override;

    // XPropertySetInfo
    virtual css::uno::Sequence < css::beans::Property > SAL_CALL getProperties() override;

    virtual css::beans::Property SAL_CALL getPropertyByName(const OUString & sName) override;

    virtual sal_Bool SAL_CALL hasPropertyByName(const OUString & sName) override;


private:

    void impl_setPropertyValue(sal_Int32 nHandle,
                                        const css::uno::Any& aValue);

    css::uno::Any impl_getPropertyValue(sal_Int32 nHandle);

    /** set a new owner for this helper.
     *
     *  This owner is used as source for all broadcasted events.
     *  Further we hold it weak, because we don't wish to be disposed() .-)
     */
    void impl_setPropertyChangeBroadcaster(const css::uno::Reference< css::uno::XInterface >& xBroadcaster);

    /** add a new property info to the set of supported ones.
     *
     *  @param  aProperty
     *          describes the new property.
     *
     *  @throw  [css::beans::PropertyExistException]
     *          if a property with the same name already exists.
     *
     *  Note:   The consistence of the whole set of properties is not checked here.
     *          Means e.g. ... a handle which exists more than once is not detected.
     *          The owner of this class has to be sure, that every new property does
     *          not clash with any existing one.
     */
    void impl_addPropertyInfo(const css::beans::Property& aProperty);

    /** mark the object as "dead".
     */
    void impl_disablePropertySet();

    bool impl_existsVeto(const css::beans::PropertyChangeEvent& aEvent);

    void impl_notifyChangeListener(const css::beans::PropertyChangeEvent& aEvent);

    /*-****************************************************************************************************
        @short      helper methods
        @descr      Follow methods are needed at different points of our code (more than ones!).

        @attention  Threadsafe methods are signed by "implts_..."!
    *//*-*****************************************************************************************************/

    // threadsafe
    void implts_sendFrameActionEvent     ( const css::frame::FrameAction&                        aAction          );
    void implts_resizeComponentWindow    (                                                                        );
    void implts_setIconOnWindow          (                                                                        );
    void implts_startWindowListening     (                                                                        );
    void implts_stopWindowListening      (                                                                        );
    void implts_checkSuicide             (                                                                        );
    void implts_forgetSubFrames          (                                                                        );

    // non threadsafe
    void impl_checkMenuCloser            (                                                                        );
    void impl_setCloser                  ( const css::uno::Reference< css::frame::XFrame2 >& xFrame , bool bState );

    void disableLayoutManager(const css::uno::Reference< css::frame::XLayoutManager2 >& xLayoutManager);

    void checkDisposed() {
        osl::MutexGuard g(rBHelper.rMutex);
        if (rBHelper.bInDispose || rBHelper.bDisposed) {
            throw css::lang::DisposedException("Frame disposed");
        }
    }

//  variables
//  -threadsafe by SolarMutex

    /// reference to factory, which has create this instance
    css::uno::Reference< css::uno::XComponentContext >                      m_xContext;
    /// reference to factory helper to create status indicator objects
    css::uno::Reference< css::task::XStatusIndicatorFactory >               m_xIndicatorFactoryHelper;
    /// points to an external set progress, which should be used instead of the internal one.
    css::uno::WeakReference< css::task::XStatusIndicator >                  m_xIndicatorInterception;
    /// helper for XDispatch/Provider and interception interfaces
    css::uno::Reference< css::frame::XDispatchProvider >                    m_xDispatchHelper;
    /// helper for XFrames, XIndexAccess and XElementAccess interfaces
    css::uno::Reference< css::frame::XFrames >                              m_xFramesHelper;
    /// container for ALL Listener
    ::cppu::OMultiTypeInterfaceContainerHelper                              m_aListenerContainer;
    /// parent of this frame
    css::uno::Reference< css::frame::XFramesSupplier >                      m_xParent;
    /// containerwindow of this frame for embedded components
    css::uno::Reference< css::awt::XWindow >                                m_xContainerWindow;
    /// window of the actual component
    css::uno::Reference< css::awt::XWindow >                                m_xComponentWindow;
    /// controller of the actual frame
    css::uno::Reference< css::frame::XController >                          m_xController;
    /// listen to drag & drop
    css::uno::Reference< css::datatransfer::dnd::XDropTargetListener >      m_xDropTargetListener;
    /// state, if I am a member of active path in tree or I have the focus or...
    EActiveState                                                            m_eActiveState;
    /// name of this frame
    OUString                                                                m_sName;
    /// frame has no parent or the parent is a task or the desktop
    bool                                                                    m_bIsFrameTop;
    /// due to FrameActionEvent
    bool                                                                    m_bConnected;
    sal_Int16                                                               m_nExternalLockCount;
    /// is used for dispatch recording and will be set/get from outside. Frame provide it only!
    css::uno::Reference< css::frame::XDispatchRecorderSupplier >            m_xDispatchRecorderSupplier;
    /// ref counted class to support disabling commands defined by configuration file
    SvtCommandOptions                                                       m_aCommandOptions;
    /// in case of CloseVetoException on method close() was thrown by ourself - we must close ourself later if no internal processes are running
    bool                                                                    m_bSelfClose;
    /// indicates, if this frame is used in hidden mode or not
    bool                                                                    m_bIsHidden;
    /// The container window has WindowExtendedStyle::DocHidden set.
    bool                                                                    m_bDocHidden = false;
    /// is used to layout the child windows of the frame.
    css::uno::Reference< css::frame::XLayoutManager2 >                      m_xLayoutManager;
    css::uno::Reference< css::frame::XDispatchInformationProvider >         m_xDispatchInfoHelper;
    css::uno::Reference< css::frame::XTitle >                               m_xTitleHelper;

    WindowCommandDispatch*                                                  m_pWindowCommandDispatch;

    typedef std::unordered_map<OUString, css::beans::Property> TPropInfoHash;
    TPropInfoHash m_lProps;

    ListenerHash m_lSimpleChangeListener;
    ListenerHash m_lVetoChangeListener;

    // hold it weak ... otherwise this helper has to be "killed" explicitly .-)
    css::uno::WeakReference< css::uno::XInterface > m_xBroadcaster;

    FrameContainer                                                          m_aChildFrameContainer;   /// array of child frames
};


/*-****************************************************************************************************
    @short      standard constructor to create instance by factory
    @descr      This constructor initialize a new instance of this class by valid factory,
                and will be set valid values on his member and baseclasses.

    @attention  a)  Don't use your own reference during an UNO-Service-ctor! There is no guarantee, that you
                    will get over this. (e.g. using of your reference as parameter to initialize some member)
                    Do such things in DEFINE_INIT_SERVICE() method, which is called automatically after your ctor!!!
                b)  Baseclass OBroadcastHelper is a typedef in namespace cppu!
                    The microsoft compiler has some problems to handle it right BY using namespace explicitly ::cppu::OBroadcastHelper.
                    If we write it without a namespace or expand the typedef to OBroadcastHelperVar<...> -> it will be OK!?
                    I don't know why! (other compiler not tested .. but it works!)

    @seealso    method DEFINE_INIT_SERVICE()

    @param      xContext is the multi service manager, which creates this instance.
                    The value must be different from NULL!
    @onerror    ASSERT in debug version or nothing in release version.
*//*-*****************************************************************************************************/
Frame::Frame( const css::uno::Reference< css::uno::XComponentContext >& xContext )
        : PartialWeakComponentImplHelper(m_aMutex)
        //  init member
        , m_xContext                  ( xContext )
        , m_aListenerContainer        ( m_aMutex )
        , m_xParent                   ()
        , m_xContainerWindow          ()
        , m_xComponentWindow          ()
        , m_xController               ()
        , m_eActiveState              ( E_INACTIVE )
        , m_sName                     ()
        , m_bIsFrameTop               ( true ) // I think we are top without a parent ... and there is no parent yet!
        , m_bConnected                ( false ) // There exist no component inside of use => sal_False, we are not connected!
        , m_nExternalLockCount        ( 0 )
        , m_bSelfClose                ( false ) // Important!
        , m_bIsHidden                 ( true )
        , m_xTitleHelper              ()
        , m_pWindowCommandDispatch    ( nullptr )
        , m_lSimpleChangeListener     ( m_aMutex )
        , m_lVetoChangeListener       ( m_aMutex )
        , m_aChildFrameContainer      ()
{
}

void Frame::initListeners()
{
    css::uno::Reference< css::uno::XInterface > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY_THROW);

    // Initialize a new dispatchhelper-object to handle dispatches.
    // We use these helper as slave for our interceptor helper ... not directly!
    // But he is event listener on THIS instance!
    DispatchProvider* pDispatchHelper = new DispatchProvider( m_xContext, this );
    css::uno::Reference< css::frame::XDispatchProvider > xDispatchProvider( static_cast< ::cppu::OWeakObject* >(pDispatchHelper), css::uno::UNO_QUERY );

    DispatchInformationProvider* pInfoHelper = new DispatchInformationProvider(m_xContext, this);
    m_xDispatchInfoHelper.set( static_cast< ::cppu::OWeakObject* >(pInfoHelper), css::uno::UNO_QUERY );

    // Initialize a new interception helper object to handle dispatches and implement an interceptor mechanism.
    // Set created dispatch provider as slowest slave of it.
    // Hold interception helper by reference only - not by pointer!
    // So it's easier to destroy it.
    InterceptionHelper* pInterceptionHelper = new InterceptionHelper( this, xDispatchProvider );
    m_xDispatchHelper.set( static_cast< ::cppu::OWeakObject* >(pInterceptionHelper), css::uno::UNO_QUERY );

    // Initialize a new XFrames-helper-object to handle XIndexAccess and XElementAccess.
    // We hold member as reference ... not as pointer too!
    // Attention: We share our frame container with this helper. Container is threadsafe himself ... So I think we can do that.
    // But look on dispose() for right order of deinitialization.
    OFrames* pFramesHelper = new OFrames( this, &m_aChildFrameContainer );
    m_xFramesHelper.set( static_cast< ::cppu::OWeakObject* >(pFramesHelper), css::uno::UNO_QUERY );

    // Initialize a the drop target listener.
    // We hold member as reference ... not as pointer too!
    OpenFileDropTargetListener* pDropListener = new OpenFileDropTargetListener( m_xContext, this );
    m_xDropTargetListener.set( static_cast< ::cppu::OWeakObject* >(pDropListener), css::uno::UNO_QUERY );

    // Safe impossible cases
    // We can't work without these helpers!
    SAL_WARN_IF( !xDispatchProvider.is(), "fwk.frame", "Frame::Frame(): Slowest slave for dispatch- and interception helper "
        "is not valid. XDispatchProvider, XDispatch, XDispatchProviderInterception are not full supported!" );
    SAL_WARN_IF( !m_xDispatchHelper.is(), "fwk.frame", "Frame::Frame(): Interception helper is not valid. XDispatchProvider, "
        "XDispatch, XDispatchProviderInterception are not full supported!" );
    SAL_WARN_IF( !m_xFramesHelper.is(), "fwk.frame", "Frame::Frame(): Frames helper is not valid. XFrames, "
        "XIndexAccess and XElementAccess are not supported!" );
    SAL_WARN_IF( !m_xDropTargetListener.is(), "fwk.frame", "Frame::Frame(): DropTarget helper is not valid. "
        "Drag and drop without functionality!" );

    // establish notifies for changing of "disabled commands" configuration during runtime
    m_aCommandOptions.EstablishFrameCallback(this);

    // Create an initial layout manager
    // Create layout manager and connect it to the newly created frame
    m_xLayoutManager = css::frame::LayoutManager::create(m_xContext);

    // set information about all supported properties
    impl_setPropertyChangeBroadcaster(static_cast< css::frame::XFrame* >(this));
    impl_addPropertyInfo(
        css::beans::Property(
            FRAME_PROPNAME_ASCII_DISPATCHRECORDERSUPPLIER,
            FRAME_PROPHANDLE_DISPATCHRECORDERSUPPLIER,
            cppu::UnoType<css::frame::XDispatchRecorderSupplier>::get(),
            css::beans::PropertyAttribute::TRANSIENT));
    impl_addPropertyInfo(
        css::beans::Property(
            FRAME_PROPNAME_ASCII_INDICATORINTERCEPTION,
            FRAME_PROPHANDLE_INDICATORINTERCEPTION,
            cppu::UnoType<css::task::XStatusIndicator>::get(),
            css::beans::PropertyAttribute::TRANSIENT));
    impl_addPropertyInfo(
        css::beans::Property(
            FRAME_PROPNAME_ASCII_ISHIDDEN,
            FRAME_PROPHANDLE_ISHIDDEN,
            cppu::UnoType<bool>::get(),
            css::beans::PropertyAttribute::TRANSIENT | css::beans::PropertyAttribute::READONLY));
    impl_addPropertyInfo(
        css::beans::Property(
            FRAME_PROPNAME_ASCII_LAYOUTMANAGER,
            FRAME_PROPHANDLE_LAYOUTMANAGER,
            cppu::UnoType<css::frame::XLayoutManager>::get(),
            css::beans::PropertyAttribute::TRANSIENT));
    impl_addPropertyInfo(
        css::beans::Property(
            FRAME_PROPNAME_ASCII_TITLE,
            FRAME_PROPHANDLE_TITLE,
            cppu::UnoType<OUString>::get(),
            css::beans::PropertyAttribute::TRANSIENT));
}

/*-************************************************************************************************************
    @interface  XComponentLoader
    @short      try to load given URL into a task
    @descr      You can give us some information about the content, which you will load into a frame.
                We search or create this target for you, make a type detection of given URL and try to load it.
                As result of this operation we return the new created component or nothing, if loading failed.
    @param      "sURL"              , URL, which represent the content
    @param      "sTargetFrameName"  , name of target frame or special value like "_self", "_blank" ...
    @param      "nSearchFlags"      , optional arguments for frame search, if target is not a special one
    @param      "lArguments"        , optional arguments for loading
    @return     A valid component reference, if loading was successfully.
                A null reference otherwise.

    @onerror    We return a null reference.
    @threadsafe yes
*//*-*************************************************************************************************************/
css::uno::Reference< css::lang::XComponent > SAL_CALL Frame::loadComponentFromURL(
        const OUString& sURL,
        const OUString& sTargetFrameName,
        sal_Int32 nSearchFlags,
        const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
{
    checkDisposed();

    css::uno::Reference< css::frame::XComponentLoader > xThis(static_cast< css::frame::XComponentLoader* >(this), css::uno::UNO_QUERY);
    return LoadEnv::loadComponentFromURL(xThis, m_xContext, sURL, sTargetFrameName, nSearchFlags, lArguments);
}

/*-****************************************************************************************************
    @short      return access to append or remove children on desktop
    @descr      We don't implement these interface directly. We use a helper class to do this.
                If you wish to add or delete children to/from the container, call these method to get
                a reference to the helper.

    @seealso    class OFrames
    @return     A reference to the helper which answer your queries.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::frame::XFrames > SAL_CALL Frame::getFrames()
{
    checkDisposed();

    SolarMutexGuard g;
    // Return access to all child frames to caller.
    // Our childframe container is implemented in helper class OFrames and used as a reference m_xFramesHelper!
    return m_xFramesHelper;
}

/*-****************************************************************************************************
    @short      get the current active child frame
    @descr      It must be a frameto. Direct children of a frame are frames only! No task or desktop is accepted.
                We don't save this information directly in this class. We use our container-helper
                to do that.

    @seealso    class OFrameContainer
    @seealso    method setActiveFrame()
    @return     A reference to our current active childframe, if anyone exist.
    @return     A null reference, if nobody is active.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::frame::XFrame > SAL_CALL Frame::getActiveFrame()
{
    checkDisposed();

    SolarMutexGuard g;
    // Return current active frame.
    // This information is available on the container.
    return m_aChildFrameContainer.getActive();
}

/*-****************************************************************************************************
    @short      set the new active direct child frame
    @descr      It must be a frame to. Direct children of frame are frames only! No task or desktop is accepted.
                We don't save this information directly in this class. We use our container-helper
                to do that.

    @seealso    class OFrameContainer
    @seealso    method getActiveFrame()

    @param      "xFrame", reference to new active child. It must be an already existing child!
    @onerror    An assertion is thrown and element is ignored, if given frame isn't already a child of us.
*//*-*****************************************************************************************************/
void SAL_CALL Frame::setActiveFrame( const css::uno::Reference< css::frame::XFrame >& xFrame )
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexResettableGuard aWriteLock;

    // Copy necessary member for threadsafe access!
    // m_aChildFrameContainer is threadsafe himself and he live if we live!!!
    css::uno::Reference< css::frame::XFrame > xActiveChild = m_aChildFrameContainer.getActive();
    EActiveState                              eActiveState = m_eActiveState;

    aWriteLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    // Don't work, if "new" active frame isn't different from current one!
    // (xFrame==NULL is allowed to UNSET it!)
    if( xActiveChild != xFrame )
    {
        // ... otherwise set new and deactivate old one.
        m_aChildFrameContainer.setActive( xFrame );
        if  (
                ( eActiveState      !=  E_INACTIVE  )   &&
                xActiveChild.is()
            )
        {
            xActiveChild->deactivate();
        }
    }

    if( xFrame.is() )
    {
        // If last active frame had focus ...
        // ... reset state to ACTIVE and send right FrameActionEvent for focus lost.
        if( eActiveState == E_FOCUS )
        {
            aWriteLock.reset();
            eActiveState   = E_ACTIVE;
            m_eActiveState = eActiveState;
            aWriteLock.clear();
            implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_DEACTIVATING );
        }

        // If last active frame was active ...
        // but new one is not it ...
        // ... set it as active one.
        if ( eActiveState == E_ACTIVE && !xFrame->isActive() )
        {
            xFrame->activate();
        }
    }
    else
    // If this frame is active and has no active subframe anymore it is UI active too
    if( eActiveState == E_ACTIVE )
    {
        aWriteLock.reset();
        eActiveState   = E_FOCUS;
        m_eActiveState = eActiveState;
        aWriteLock.clear();
        implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_ACTIVATED );
    }
}

/*-****************************************************************************************************
   initialize new created layout manager
**/
void lcl_enableLayoutManager(const css::uno::Reference< css::frame::XLayoutManager2 >& xLayoutManager,
                             const css::uno::Reference< css::frame::XFrame >&         xFrame        )
{
    // Provide container window to our layout manager implementation
    xLayoutManager->attachFrame(xFrame);

    xFrame->addFrameActionListener(xLayoutManager);

    DockingAreaDefaultAcceptor* pAcceptor = new DockingAreaDefaultAcceptor(xFrame);
    css::uno::Reference< css::ui::XDockingAreaAcceptor > xDockingAreaAcceptor(
        static_cast< ::cppu::OWeakObject* >(pAcceptor), css::uno::UNO_QUERY_THROW);
    xLayoutManager->setDockingAreaAcceptor(xDockingAreaAcceptor);
}

/*-****************************************************************************************************
   deinitialize layout manager
**/
void Frame::disableLayoutManager(const css::uno::Reference< css::frame::XLayoutManager2 >& xLayoutManager)
{
    removeFrameActionListener(xLayoutManager);
    xLayoutManager->setDockingAreaAcceptor(css::uno::Reference< css::ui::XDockingAreaAcceptor >());
    xLayoutManager->attachFrame(css::uno::Reference< css::frame::XFrame >());
}

/*-****************************************************************************************************
    @short      initialize frame instance
    @descr      A frame needs a window. This method set a new one ... but should called one times only!
                We use this window to listen for window events and forward it to our set component.
                Its used as parent of component window too.

    @seealso    method getContainerWindow()
    @seealso    method setComponent()
    @seealso    member m_xContainerWindow

    @param      "xWindow", reference to new container window - must be valid!
    @onerror    We do nothing.
*//*-*****************************************************************************************************/
void SAL_CALL Frame::initialize( const css::uno::Reference< css::awt::XWindow >& xWindow )
{
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
    if (!xWindow.is())
        throw css::uno::RuntimeException(
                    "Frame::initialize() called without a valid container window reference.",
                    static_cast< css::frame::XFrame* >(this));

    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexResettableGuard aWriteLock;

    if ( m_xContainerWindow.is() )
        throw css::uno::RuntimeException(
                "Frame::initialized() is called more than once, which is not useful nor allowed.",
                static_cast< css::frame::XFrame* >(this));

    // This must be the first call of this method!
    // We should initialize our object and open it for working.
    // Set the new window.
    SAL_WARN_IF( m_xContainerWindow.is(), "fwk.frame", "Frame::initialize(): Leak detected! This state should never occur ..." );
    m_xContainerWindow = xWindow;

    // if window is initially visible, we will never get a windowShowing event
    VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow(xWindow);
    if (pWindow)
    {
        if (pWindow->IsVisible())
            m_bIsHidden = false;
        m_bDocHidden
            = static_cast<bool>(pWindow->GetExtendedStyle() & WindowExtendedStyle::DocHidden);
    }

    css::uno::Reference< css::frame::XLayoutManager2 >  xLayoutManager = m_xLayoutManager;

    // Release lock ... because we call some impl methods, which are threadsafe by himself.
    // If we hold this lock - we will produce our own deadlock!
    aWriteLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    // Avoid enabling the layout manager for hidden frames: it's expensive and
    // provides little value.
    if (xLayoutManager.is() && !m_bDocHidden)
        lcl_enableLayoutManager(xLayoutManager, this);

    // create progress helper
    css::uno::Reference< css::frame::XFrame > xThis (static_cast< css::frame::XFrame* >(this),
                                                     css::uno::UNO_QUERY_THROW);
    css::uno::Reference< css::task::XStatusIndicatorFactory > xIndicatorFactory =
        css::task::StatusIndicatorFactory::createWithFrame(m_xContext, xThis,
                                                           false/*DisableReschedule*/, true/*AllowParentShow*/ );

    // SAFE -> ----------------------------------
    aWriteLock.reset();
    m_xIndicatorFactoryHelper = xIndicatorFactory;
    aWriteLock.clear();
    // <- SAFE ----------------------------------

    // Start listening for events after setting it on helper class ...
    // So superfluous messages are filtered to NULL :-)
    implts_startWindowListening();

    m_pWindowCommandDispatch = new WindowCommandDispatch(m_xContext, this);

    // Initialize title functionality
    TitleHelper* pTitleHelper = new TitleHelper( m_xContext );
    m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pTitleHelper), css::uno::UNO_QUERY_THROW);
    pTitleHelper->setOwner(xThis);
}

/*-****************************************************************************************************
    @short      returns current set container window
    @descr      The ContainerWindow property is used as a container for the component
                in this frame. So this object implements a container interface too.
                The instantiation of the container window is done by the user of this class.
                The frame is the owner of its container window.

    @seealso    method initialize()
    @return     A reference to current set containerwindow.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::awt::XWindow > SAL_CALL Frame::getContainerWindow()
{
    SolarMutexGuard g;
    return m_xContainerWindow;
}

/*-****************************************************************************************************
    @short      set parent frame
    @descr      We need a parent to support some functionality! e.g. findFrame()
                By the way we use the chance to set an internal information about our top state.
                So we must not check this information during every isTop() call.
                We are top, if our parent is the desktop instance or we haven't any parent.

    @seealso    getCreator()
    @seealso    findFrame()
    @seealso    isTop()
    @seealos    m_bIsFrameTop

    @param      xCreator
                    valid reference to our new owner frame, which should implement a supplier interface

    @threadsafe yes
*//*-*****************************************************************************************************/
void SAL_CALL Frame::setCreator( const css::uno::Reference< css::frame::XFramesSupplier >& xCreator )
{
    checkDisposed();

    /* SAFE { */
        SolarMutexClearableGuard aWriteLock;
            m_xParent = xCreator;
        aWriteLock.clear();
    /* } SAFE */

    css::uno::Reference< css::frame::XDesktop > xIsDesktop( xCreator, css::uno::UNO_QUERY );
    m_bIsFrameTop = ( xIsDesktop.is() || ! xCreator.is() );
}

/*-****************************************************************************************************
    @short      returns current parent frame
    @descr      The Creator is the parent frame container. If it is NULL, the frame is the uppermost one.

    @seealso    method setCreator()
    @return     A reference to current set parent frame container.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::frame::XFramesSupplier > SAL_CALL Frame::getCreator()
{
    checkDisposed();
    SolarMutexGuard g;
    return m_xParent;
}

/*-****************************************************************************************************
    @short      returns current set name of frame
    @descr      This name is used to find target of findFrame() or queryDispatch() calls.

    @seealso    method setName()
    @return     Current set name of frame.

    @onerror    An empty string is returned.
*//*-*****************************************************************************************************/
OUString SAL_CALL Frame::getName()
{
    SolarMutexGuard g;
    return m_sName;
}

/*-****************************************************************************************************
    @short      set new name for frame
    @descr      This name is used to find target of findFrame() or queryDispatch() calls.

    @attention  Special names like "_blank", "_self" aren't allowed...
                "_beamer" excepts this rule!

    @seealso    method getName()

    @param      "sName", new frame name.
    @onerror    We do nothing.
*//*-*****************************************************************************************************/
void SAL_CALL Frame::setName( const OUString& sName )
{
    SolarMutexGuard g;
    // Set new name... but look for invalid special target names!
    // They are not allowed to set.
    if (TargetHelper::isValidNameForFrame(sName))
        m_sName = sName;
}

/*-****************************************************************************************************
    @short      search for frames
    @descr      This method searches for a frame with the specified name.
                Frames may contain other frames (e.g. a frameset) and may
                be contained in other frames. This hierarchy is searched by
                this method.
                First some special names are taken into account, i.e. "",
                "_self", "_top", "_blank" etc. The nSearchFlags are ignored
                when comparing these names with sTargetFrameName, further steps are
                controlled by the search flags. If allowed, the name of the frame
                itself is compared with the desired one, then ( again if allowed )
                the method findFrame() is called for all children, for siblings
                and as last for the parent frame.
                If no frame with the given name is found until the top frames container,
                a new top one is created, if this is allowed by a special
                flag. The new frame also gets the desired name.

    @param      sTargetFrameName
                    special names (_blank, _self) or real name of target frame
    @param      nSearchFlags
                    optional flags which regulate search for non special target frames

    @return     A reference to found or may be new created frame.
    @threadsafe yes
*//*-*****************************************************************************************************/
css::uno::Reference< css::frame::XFrame > SAL_CALL Frame::findFrame( const OUString& sTargetFrameName,
                                                                     sal_Int32 nSearchFlags )
{
    css::uno::Reference< css::frame::XFrame > xTarget;

    // 0) Ignore wrong parameter!
    //    We don't support search for following special targets.
    //    If we reject this requests - we must not check for such names
    //    in following code again and again. If we do not so -wrong
    //    search results can occur!

    if ( sTargetFrameName == SPECIALTARGET_DEFAULT ) // valid for dispatches - not for findFrame()!
    {
        return nullptr;
    }

    // I) check for special defined targets first which must be handled exclusive.
    //    force using of "if() else if() ..."

    // get threadsafe some necessary member which are necessary for following functionality
    /* SAFE { */
    SolarMutexResettableGuard aReadLock;
    css::uno::Reference< css::frame::XFrame > xParent ( m_xParent, css::uno::UNO_QUERY );
    bool bIsTopFrame  = m_bIsFrameTop;
    bool bIsTopWindow = WindowHelper::isTopWindow(m_xContainerWindow);
    aReadLock.clear();
    /* } SAFE */

    // I.I) "_blank"
    //  Not allowed for a normal frame - but for the desktop.
    //  Use helper class to do so. It use the desktop automatically.

    if ( sTargetFrameName==SPECIALTARGET_BLANK )
    {
        TaskCreator aCreator(m_xContext);
        xTarget = aCreator.createTask(sTargetFrameName, utl::MediaDescriptor());
    }

    // I.II) "_parent"
    //  It doesn't matter if we have a valid parent or not. User ask for him and get it.
    //  An empty result is a valid result too.

    else if ( sTargetFrameName==SPECIALTARGET_PARENT )
    {
        xTarget = xParent;
    }

    // I.III) "_top"
    //  If we are not the top frame in this hierarchy, we must forward request to our parent.
    //  Otherwise we must return ourself.

    else if ( sTargetFrameName==SPECIALTARGET_TOP )
    {
        if (bIsTopFrame)
            xTarget = this;
        else if (xParent.is()) // If we are not top - the parent MUST exist. But may it's better to check it again .-)
            xTarget = xParent->findFrame(SPECIALTARGET_TOP,0);
    }

    // I.IV) "_self", ""
    //  This mean this frame in every case.

    else if (
        ( sTargetFrameName==SPECIALTARGET_SELF ) ||
        ( sTargetFrameName.isEmpty()           )
       )
    {
        xTarget = this;
    }

    // I.V) "_beamer"
    //  This is a special sub frame of any task. We must return it if we found it on our direct children
    //  or create it there if it not already exists.
    //  Note: Such beamer exists for task(top) frames only!

    else if ( sTargetFrameName==SPECIALTARGET_BEAMER )
    {
        // We are a task => search or create the beamer
        if (bIsTopWindow)
        {
            xTarget = m_aChildFrameContainer.searchOnDirectChildrens(SPECIALTARGET_BEAMER);
            if ( ! xTarget.is() )
            {
                /* TODO
                    Creation not supported yet!
                    Wait for new layout manager service because we can't plug it
                    inside already opened document of this frame...
                */
            }
        }
        // We aren't a task => forward request to our parent or ignore it.
        else if (xParent.is())
            xTarget = xParent->findFrame(SPECIALTARGET_BEAMER,0);
    }

    else
    {

        // II) otherwise use optional given search flags
        //  force using of combinations of such flags. means no "else" part of use if() statements.
        //  But we ust break further searches if target was already found.
        //  Order of using flags is fix: SELF - CHILDREN - SIBLINGS - PARENT
        //  TASK and CREATE are handled special.

        // get threadsafe some necessary member which are necessary for following functionality
        /* SAFE { */
        aReadLock.reset();
        OUString sOwnName = m_sName;
        aReadLock.clear();
        /* } SAFE */

        // II.I) SELF
        //  Check for right name. If it's the searched one return ourself - otherwise
        //  ignore this flag.

        if (
            (nSearchFlags &  css::frame::FrameSearchFlag::SELF)  &&
            (sOwnName     == sTargetFrameName                 )
           )
        {
            xTarget = this;
        }

        // II.II) CHILDREN
        //  Search on all children for the given target name.
        //  An empty name value can't occur here - because it must be already handled as "_self"
        //  before. Used helper function of container doesn't create any frame.
        //  It makes a deep search only.

        if (
            ( ! xTarget.is()                                     ) &&
            (nSearchFlags & css::frame::FrameSearchFlag::CHILDREN)
           )
        {
            xTarget = m_aChildFrameContainer.searchOnAllChildrens(sTargetFrameName);
        }

        // II.III) TASKS
        //  This is a special flag. It regulate search on this task tree only or allow search on
        //  all other ones (which are sibling trees of us) too.
        //  Upper search must stop at this frame if we are the topest one and the TASK flag is not set
        //  or we can ignore it if we have no valid parent.

        if (
            (   bIsTopFrame && (nSearchFlags & css::frame::FrameSearchFlag::TASKS) )   ||
            ( ! bIsTopFrame                                                        )
           )
        {

            // II.III.I) SIBLINGS
            //  Search on all our direct siblings - means all children of our parent.
            //  Use this flag in combination with TASK. We must suppress such upper search if
            //  user has not set it and if we are a top frame.
            //  Attention: Don't forward this request to our parent as a findFrame() call.
            //  In such case we must protect us against recursive calls.
            //  Use snapshot of our parent. But don't use queryFrames() of XFrames interface.
            //  Because it's return all siblings and all her children including our children too
            //  if we call it with the CHILDREN flag. We don't need that - we need the direct container
            //  items of our parent only to start searches there. So we must use the container interface
            //  XIndexAccess instead of XFrames.

            if (
                ( ! xTarget.is()                                      ) &&
                (nSearchFlags &  css::frame::FrameSearchFlag::SIBLINGS) &&
                (   xParent.is()                                      ) // search on siblings is impossible without a parent
               )
            {
                css::uno::Reference< css::frame::XFramesSupplier > xSupplier( xParent, css::uno::UNO_QUERY );
                if (xSupplier.is())
                {
                    css::uno::Reference< css::container::XIndexAccess > xContainer( xSupplier->getFrames(), css::uno::UNO_QUERY );
                    if (xContainer.is())
                    {
                        sal_Int32 nCount = xContainer->getCount();
                        for( sal_Int32 i=0; i<nCount; ++i )
                        {
                            css::uno::Reference< css::frame::XFrame > xSibling;
                            if (
                                // control unpacking
                                ( !(xContainer->getByIndex(i)>>=xSibling) ) ||
                                // check for valid items
                                ( ! xSibling.is() ) ||
                                // ignore ourself! (We are a part of this container too - but search on our children was already done.)
                                ( xSibling==static_cast< ::cppu::OWeakObject* >(this) )
                            )
                            {
                                continue;
                            }

                            // Don't allow upper search here! Use right flags to regulate it.
                            // And allow deep search on children only - if it was allowed for us too.
                            sal_Int32 nRightFlags = css::frame::FrameSearchFlag::SELF;
                            if (nSearchFlags & css::frame::FrameSearchFlag::CHILDREN)
                                nRightFlags |= css::frame::FrameSearchFlag::CHILDREN;
                            xTarget = xSibling->findFrame(sTargetFrameName, nRightFlags );
                            // perform search be breaking further search if a result exist.
                            if (xTarget.is())
                                break;
                        }
                    }
                }
            }

            // II.III.II) PARENT
            //  Forward search to our parent (if he exists.)
            //  To prevent us against recursive and superfluous calls (which can occur if we allow him
            //  to search on his children too) we must change used search flags.

            if (
                ( ! xTarget.is()                                    ) &&
                (nSearchFlags &  css::frame::FrameSearchFlag::PARENT) &&
                (   xParent.is()                                    )
               )
            {
                if (xParent->getName() == sTargetFrameName)
                    xTarget = xParent;
                else
                {
                    sal_Int32 nRightFlags  = nSearchFlags;
                              nRightFlags &= ~css::frame::FrameSearchFlag::CHILDREN;
                    xTarget = xParent->findFrame(sTargetFrameName, nRightFlags);
                }
            }
        }

        // II.IV) CREATE
        //  If we haven't found any valid target frame by using normal flags - but user allowed us to create
        //  a new one ... we should do that. Used TaskCreator use Desktop instance automatically as parent!

        if (
            ( ! xTarget.is()                                   )    &&
            (nSearchFlags & css::frame::FrameSearchFlag::CREATE)
           )
        {
            TaskCreator aCreator(m_xContext);
            xTarget = aCreator.createTask(sTargetFrameName, utl::MediaDescriptor());
        }
    }

    return xTarget;
}

/*-****************************************************************************************************
    @descr      Returns sal_True, if this frame is a "top frame", otherwise sal_False.
                The "m_bIsFrameTop" member must be set in the ctor or setCreator() method.
                A top frame is a member of the top frame container or a member of the
                task frame container. Both containers can create new frames if the findFrame()
                method of their css::frame::XFrame interface is called with a frame name not yet known.

    @seealso    ctor
    @seealso    method setCreator()
    @seealso    method findFrame()
    @return     true, if is it a top frame ... false otherwise.

    @onerror    No error should occur!
*//*-*****************************************************************************************************/
sal_Bool SAL_CALL Frame::isTop()
{
    checkDisposed();
    SolarMutexGuard g;
    // This information is set in setCreator().
    // We are top, if our parent is a task or the desktop or if no parent exist!
    return m_bIsFrameTop;
}

/*-****************************************************************************************************
    @short      activate frame in hierarchy
    @descr      This feature is used to mark active paths in our frame hierarchy.
                You can be a listener for this event to react for it ... change some internal states or something else.

    @seealso    method deactivate()
    @seealso    method isActivate()
    @seealso    enum EActiveState
    @seealso    listener mechanism
*//*-*****************************************************************************************************/
void SAL_CALL Frame::activate()
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexResettableGuard aWriteLock;

    // Copy necessary member and free the lock.
    // It's not necessary for m_aChildFrameContainer ... because
    // he is threadsafe himself and live if we live.
    css::uno::Reference< css::frame::XFrame >           xActiveChild    = m_aChildFrameContainer.getActive();
    css::uno::Reference< css::frame::XFramesSupplier >  xParent         ( m_xParent, css::uno::UNO_QUERY );
    css::uno::Reference< css::frame::XFrame >           xThis           ( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
    EActiveState                                        eState          = m_eActiveState;

    aWriteLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    //  1)  If I'am not active before ...
    if( eState == E_INACTIVE )
    {
        // ... do it then.
        aWriteLock.reset();
        eState         = E_ACTIVE;
        m_eActiveState = eState;
        aWriteLock.clear();
        // Deactivate sibling path and forward activation to parent ... if any parent exist!
        if( xParent.is() )
        {
            // Every time set THIS frame as active child of parent and activate it.
            // We MUST have a valid path from bottom to top as active path!
            // But we must deactivate the old active sibling path first.

            // Attention: Deactivation of an active path, deactivate the whole path ... from bottom to top!
            // But we wish to deactivate founded sibling-tree only.
            // [ see deactivate() / step 4) for further information! ]

            xParent->setActiveFrame( xThis );

            // Then we can activate from here to top.
            // Attention: We are ACTIVE now. And the parent will call activate() at us!
            // But we do nothing then! We are already activated.
            xParent->activate();
        }
        // It's necessary to send event NOW - not before.
        // Activation goes from bottom to top!
        // That's the reason to activate parent first and send event now.
        implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_ACTIVATED );
    }

    //  2)  I was active before or current activated and there is a path from here to bottom, who CAN be active.
    //      But our direct child of path is not active yet.
    //      (It can be, if activation occur in the middle of a current path!)
    //      In these case we activate path to bottom to set focus on right frame!
    if ( eState == E_ACTIVE && xActiveChild.is() && !xActiveChild->isActive() )
    {
        xActiveChild->activate();
    }

    //  3)  I was active before or current activated. But if I have no active child => I will get the focus!
    if ( eState == E_ACTIVE && !xActiveChild.is() )
    {
        aWriteLock.reset();
        eState         = E_FOCUS;
        m_eActiveState = eState;
        aWriteLock.clear();
        implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_ACTIVATED );
    }
}

/*-****************************************************************************************************
    @short      deactivate frame in hierarchy
    @descr      This feature is used to deactive paths in our frame hierarchy.
                You can be a listener for this event to react for it ... change some internal states or something else.

    @seealso    method activate()
    @seealso    method isActivate()
    @seealso    enum EActiveState
    @seealso    listener mechanism
*//*-*****************************************************************************************************/
void SAL_CALL Frame::deactivate()
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexResettableGuard aWriteLock;

    // Copy necessary member and free the lock.
    css::uno::Reference< css::frame::XFrame > xActiveChild = m_aChildFrameContainer.getActive();
    css::uno::Reference< css::frame::XFramesSupplier > xParent ( m_xParent, css::uno::UNO_QUERY );
    css::uno::Reference< css::frame::XFrame > xThis ( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
    EActiveState eState = m_eActiveState;

    aWriteLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    // Work only, if there something to do!
    if( eState != E_INACTIVE )
    {

        //  1)  Deactivate all active children.
        if ( xActiveChild.is() && xActiveChild->isActive() )
        {
            xActiveChild->deactivate();
        }

        //  2)  If I have the focus - I will lost it now.
        if( eState == E_FOCUS )
        {
            // Set new state INACTIVE(!) and send message to all listener.
            // Don't set ACTIVE as new state. This frame is deactivated for next time - due to activate().
            aWriteLock.reset();
            eState          = E_ACTIVE;
            m_eActiveState  = eState;
            aWriteLock.clear();
            implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_UI_DEACTIVATING );
        }

        //  3)  If I'am active - I will be deactivated now.
        if( eState == E_ACTIVE )
        {
            // Set new state and send message to all listener.
            aWriteLock.reset();
            eState          = E_INACTIVE;
            m_eActiveState  = eState;
            aWriteLock.clear();
            implts_sendFrameActionEvent( css::frame::FrameAction_FRAME_DEACTIVATING );
        }

        //  4)  If there is a path from here to my parent ...
        //      ... I'am on the top or in the middle of deactivated subtree and action was started here.
        //      I must deactivate all frames from here to top, which are members of current path.
        //      Stop, if THESE frame not the active frame of our parent!
        if ( xParent.is() && xParent->getActiveFrame() == xThis )
        {
            // We MUST break the path - otherwise we will get the focus - not our parent! ...
            // Attention: Our parent don't call us again - WE ARE NOT ACTIVE YET!
            // [ see step 3 and condition "if ( m_eActiveState!=INACTIVE ) ..." in this method! ]
            xParent->deactivate();
        }
    }
}

/*-****************************************************************************************************
    @short      returns active state
    @descr      Call it to get information about current active state of this frame.

    @seealso    method activate()
    @seealso    method deactivate()
    @seealso    enum EActiveState
    @return     true if active, false otherwise.

    @onerror    No error should occur.
*//*-*****************************************************************************************************/
sal_Bool SAL_CALL Frame::isActive()
{
    checkDisposed();
    SolarMutexGuard g;
    return m_eActiveState == E_ACTIVE || m_eActiveState == E_FOCUS;
}

/*-****************************************************************************************************
    @short      ???
*//*-*****************************************************************************************************/
void SAL_CALL Frame::contextChanged()
{
    // Sometimes called during closing object...
    // Impl-method is threadsafe himself!
    // Send event to all listener for frame actions.
    implts_sendFrameActionEvent( css::frame::FrameAction_CONTEXT_CHANGED );
}

/*-****************************************************************************************************
    @short      set new component inside the frame
    @descr      A frame is a container for a component. Use this method to set, change or release it!
                We accept null references! The xComponentWindow will be a child of our container window
                and get all window events from us.

    @attention  (a) A current set component can disagree with the suspend() request!
                    We don't set the new one and return with false then.
                (b) It's possible to set:
                        (b1) a simple component here which supports the window only - no controller;
                        (b2) a full featured component which supports window and controller;
                        (b3) or both to NULL if outside code which to forget this component.

    @seealso    method getComponentWindow()
    @seealso    method getController()

    @param      xComponentWindow
                    valid reference to new component window which will be a child of internal container window
                    May <NULL/> for releasing.
    @param      xController
                    reference to new component controller
                    (may <NULL/> for releasing or setting of a simple component)

    @return     <TRUE/> if operation was successful, <FALSE/> otherwise.

    @onerror    We return <FALSE/>.
    @threadsafe yes
*//*-*****************************************************************************************************/
sal_Bool SAL_CALL Frame::setComponent(const css::uno::Reference< css::awt::XWindow >& xComponentWindow,
                                      const css::uno::Reference< css::frame::XController >& xController )
{

    // Ignore this HACK of sfx2!
    // He call us with an valid controller without a valid window... that's not allowed!
    if  ( xController.is() && ! xComponentWindow.is() )
        return true;

    checkDisposed();

    // Get threadsafe some copies of used members.
    /* SAFE { */
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::awt::XWindow > xContainerWindow = m_xContainerWindow;
    css::uno::Reference< css::awt::XWindow > xOldComponentWindow = m_xComponentWindow;
    css::uno::Reference< css::frame::XController > xOldController = m_xController;
    VclPtr<vcl::Window> pOwnWindow = VCLUnoHelper::GetWindow( xContainerWindow );
    bool bHadFocus = pOwnWindow->HasChildPathFocus();
    bool bWasConnected = m_bConnected;
    aReadLock.clear();
    /* } SAFE */

    // stop listening on old window
    // May it produce some trouble.
    // But don't forget to listen on new window again ... or reactivate listening
    // if we reject this setComponent() request and leave this method without changing the old window.
    implts_stopWindowListening();

    // Notify all listener, that this component (if current one exist) will be unloaded.
    if (bWasConnected)
        implts_sendFrameActionEvent( css::frame::FrameAction_COMPONENT_DETACHING );

    // otherwise release old component first
    // Always release controller before releasing window,
    // because controller may want to access its window!
    // But check for real changes - may the new controller is the old one.
    if (
        (xOldController.is()          )   &&
        (xOldController != xController)
       )
    {
        /* ATTENTION
            Don't suspend the old controller here. Because the outside caller must do that
            by definition. We have to dispose it here only.
         */

        // Before we dispose this controller we should hide it inside this frame instance.
        // We hold it alive for next calls by using xOldController!
        /* SAFE {*/
        SolarMutexClearableGuard aWriteLock;
        m_xController = nullptr;
        aWriteLock.clear();
        /* } SAFE */

        css::uno::Reference< css::lang::XComponent > xDisposable( xOldController, css::uno::UNO_QUERY );
        if (xDisposable.is())
        {
            try
            {
                xDisposable->dispose();
            }
            catch(const css::lang::DisposedException&)
                {}
        }
        xOldController = nullptr;
    }

    // Now it's time to release the component window.
    // If controller wasn't released successfully - this code line shouldn't be reached.
    // Because in case of "suspend()==false" we return immediately with false ...
    // see before
    // Check for real changes too.
    if (
        (xOldComponentWindow.is()               )   &&
        (xOldComponentWindow != xComponentWindow)
       )
    {
        /* SAFE { */
        SolarMutexClearableGuard aWriteLock;
        m_xComponentWindow = nullptr;
        aWriteLock.clear();
        /* } SAFE */

        css::uno::Reference< css::lang::XComponent > xDisposable( xOldComponentWindow, css::uno::UNO_QUERY );
        if (xDisposable.is())
        {
            try
            {
                xDisposable->dispose();
            }
            catch(const css::lang::DisposedException&)
            {
            }
        }
        xOldComponentWindow = nullptr;
    }

    // Now it's time to set the new component ...
    // By the way - find out our new "load state" - means if we have a valid component inside.
    /* SAFE { */
    SolarMutexResettableGuard aWriteLock;
    m_xComponentWindow = xComponentWindow;
    m_xController      = xController;
    m_bConnected       = (m_xComponentWindow.is() || m_xController.is());
    bool bIsConnected       = m_bConnected;
    aWriteLock.clear();
    /* } SAFE */

    // notifies all interest listener, that current component was changed or a new one was loaded
    if (bIsConnected && bWasConnected)
        implts_sendFrameActionEvent( css::frame::FrameAction_COMPONENT_REATTACHED );
    else if (bIsConnected && !bWasConnected)
        implts_sendFrameActionEvent( css::frame::FrameAction_COMPONENT_ATTACHED   );

    // A new component window doesn't know anything about current active/focus states.
    // Set this information on it!
    if ( bHadFocus && xComponentWindow.is() )
    {
        xComponentWindow->setFocus();
    }

    // If it was a new component window - we must resize it to fill out
    // our container window.
    implts_resizeComponentWindow();
    // New component should change our current icon ...
    implts_setIconOnWindow();
    // OK - start listening on new window again - or do nothing if it is an empty one.
    implts_startWindowListening();

    /* SAFE { */
    aWriteLock.reset();
    impl_checkMenuCloser();
    aWriteLock.clear();
    /* } SAFE */

    return true;
}

/*-****************************************************************************************************
    @short      returns current set component window
    @descr      Frames are used to display components. The actual displayed component is
                held by the m_xComponentWindow property. If the component implements only a
                XComponent interface, the communication between the frame and the
                component is very restricted. Better integration is achievable through a
                XController interface.
                If the component wants other objects to be able to get information about its
                ResourceDescriptor it has to implement a XModel interface.
                This frame is the owner of the component window.

    @seealso    method setComponent()
    @return     css::uno::Reference to current set component window.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::awt::XWindow > SAL_CALL Frame::getComponentWindow()
{
    checkDisposed();
    SolarMutexGuard g;
    return m_xComponentWindow;
}

/*-****************************************************************************************************
    @short      returns current set controller
    @descr      Frames are used to display components. The actual displayed component is
                held by the m_xComponentWindow property. If the component implements only a
                XComponent interface, the communication between the frame and the
                component is very restricted. Better integration is achievable through a
                XController interface.
                If the component wants other objects to be able to get information about its
                ResourceDescriptor it has to implement a XModel interface.
                This frame is the owner of the component window.

    @seealso    method setComponent()
    @return     css::uno::Reference to current set controller.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::frame::XController > SAL_CALL Frame::getController()
{
    SolarMutexGuard g;
    return m_xController;
}

/*-****************************************************************************************************
    @short      add/remove listener for activate/deactivate/contextChanged events
    @seealso    method activate()
    @seealso    method deactivate()
    @seealso    method contextChanged()

    @param      "xListener" reference to your listener object
    @onerror    Listener is ignored.
*//*-*****************************************************************************************************/
void SAL_CALL Frame::addFrameActionListener( const css::uno::Reference< css::frame::XFrameActionListener >& xListener )
{
    checkDisposed();
    m_aListenerContainer.addInterface( cppu::UnoType<css::frame::XFrameActionListener>::get(), xListener );
}

void SAL_CALL Frame::removeFrameActionListener( const css::uno::Reference< css::frame::XFrameActionListener >& xListener )
{
    m_aListenerContainer.removeInterface( cppu::UnoType<css::frame::XFrameActionListener>::get(), xListener );
}

/*-****************************************************************************************************
    @short      support two way mechanism to release a frame
    @descr      This method ask internal component (controller) if he accept this close request.
                In case of <TRUE/> nothing will be happen (from point of caller of this close method).
                In case of <FALSE/> a CloseVetoException is thrown. After such exception given parameter
                <var>bDeliverOwnership</var> regulate which will be the new owner of this instance.

    @attention  It's the replacement for XTask::close() which is marked as obsolete method.

    @param      bDeliverOwnership
                    If parameter is set to <FALSE/> the original caller will be the owner after thrown
                    veto exception and must try to close this frame at later time again. Otherwise the
                    source of throwed exception is the right one. May it will be the frame himself.

    @throws     CloseVetoException
                    if any internal things willn't be closed

    @threadsafe yes
*//*-*****************************************************************************************************/
void SAL_CALL Frame::close( sal_Bool bDeliverOwnership )
{
    checkDisposed();

    // At the end of this method may we must dispose ourself...
    // and may nobody from outside hold a reference to us...
    // then it's a good idea to do that by ourself.
    css::uno::Reference< css::uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) );

    // Check any close listener before we look for currently running internal processes.
    // Because if a listener disagree with this close() request - we have time to finish this
    // internal operations too...
    // Note: container is threadsafe himself.
    css::lang::EventObject             aSource    (static_cast< ::cppu::OWeakObject*>(this));
    ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer( cppu::UnoType<css::util::XCloseListener>::get());
    if (pContainer!=nullptr)
    {
        ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
        while (pIterator.hasMoreElements())
        {
            try
            {
                static_cast<css::util::XCloseListener*>(pIterator.next())->queryClosing( aSource, bDeliverOwnership );
            }
            catch( const css::uno::RuntimeException& )
            {
                pIterator.remove();
            }
        }
    }

    // Ok - no listener disagreed with this close() request
    // check if this frame is used for any load process currently
    if (isActionLocked())
    {
        if (bDeliverOwnership)
        {
            SolarMutexGuard g;
            m_bSelfClose = true;
        }

        throw css::util::CloseVetoException("Frame in use for loading document ...",static_cast< ::cppu::OWeakObject*>(this));
    }

    if ( ! setComponent(nullptr,nullptr) )
        throw css::util::CloseVetoException("Component couldn't be deattached ...",static_cast< ::cppu::OWeakObject*>(this));

    // If closing is allowed... inform all listeners and dispose this frame!
    pContainer = m_aListenerContainer.getContainer( cppu::UnoType<css::util::XCloseListener>::get());
    if (pContainer!=nullptr)
    {
        ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
        while (pIterator.hasMoreElements())
        {
            try
            {
                static_cast<css::util::XCloseListener*>(pIterator.next())->notifyClosing( aSource );
            }
            catch( const css::uno::RuntimeException& )
            {
                pIterator.remove();
            }
        }
    }

    /* SAFE { */
    SolarMutexClearableGuard aWriteLock;
    m_bIsHidden = true;
    aWriteLock.clear();
    /* } SAFE */
    impl_checkMenuCloser();

    dispose();
}

/*-****************************************************************************************************
    @short      be a listener for close events!
    @descr      Adds/remove a CloseListener at this frame instance. If the close() method is called on
                this object, the such listener are informed and can disagree with that by throwing
                a CloseVetoException.

    @seealso    Frame::close()

    @param      xListener
                    reference to your listener object

    @onerror    Listener is ignored.

    @threadsafe yes
*//*-*****************************************************************************************************/
void SAL_CALL Frame::addCloseListener( const css::uno::Reference< css::util::XCloseListener >& xListener )
{
    checkDisposed();
    m_aListenerContainer.addInterface( cppu::UnoType<css::util::XCloseListener>::get(), xListener );
}

void SAL_CALL Frame::removeCloseListener( const css::uno::Reference< css::util::XCloseListener >& xListener )
{
    m_aListenerContainer.removeInterface( cppu::UnoType<css::util::XCloseListener>::get(), xListener );
}

OUString SAL_CALL Frame::getTitle()
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::frame::XTitle > xTitle(m_xTitleHelper, css::uno::UNO_QUERY_THROW);
    aReadLock.clear();
    // <- SAFE

    return xTitle->getTitle();
}

void SAL_CALL Frame::setTitle( const OUString& sTitle )
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::frame::XTitle > xTitle(m_xTitleHelper, css::uno::UNO_QUERY_THROW);
    aReadLock.clear();
    // <- SAFE

    xTitle->setTitle(sTitle);
}

void SAL_CALL Frame::addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener)
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::frame::XTitleChangeBroadcaster > xTitle(m_xTitleHelper, css::uno::UNO_QUERY_THROW);
    aReadLock.clear();
    // <- SAFE

    xTitle->addTitleChangeListener(xListener);
}

void SAL_CALL Frame::removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener )
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::frame::XTitleChangeBroadcaster > xTitle(m_xTitleHelper, css::uno::UNO_QUERY_THROW);
    aReadLock.clear();
    // <- SAFE

    xTitle->removeTitleChangeListener(xListener);
}

css::uno::Reference<css::container::XNameContainer> SAL_CALL Frame::getUserDefinedAttributes()
{
    // optional attribute
    return nullptr;
}

css::uno::Reference<css::frame::XDispatchRecorderSupplier> SAL_CALL Frame::getDispatchRecorderSupplier()
{
    SolarMutexGuard g;
    return m_xDispatchRecorderSupplier;
}

void SAL_CALL Frame::setDispatchRecorderSupplier(const css::uno::Reference<css::frame::XDispatchRecorderSupplier>& p)
{
    checkDisposed();
    SolarMutexGuard g;
    m_xDispatchRecorderSupplier.set(p);
}

css::uno::Reference<css::uno::XInterface> SAL_CALL Frame::getLayoutManager()
{
    SolarMutexGuard g;
    return m_xLayoutManager;
}

void SAL_CALL Frame::setLayoutManager(const css::uno::Reference<css::uno::XInterface>& p1)
{
    checkDisposed();
    SolarMutexGuard g;

    css::uno::Reference<css::frame::XLayoutManager2> xOldLayoutManager = m_xLayoutManager;
    css::uno::Reference<css::frame::XLayoutManager2> xNewLayoutManager(p1, css::uno::UNO_QUERY);

    if (xOldLayoutManager != xNewLayoutManager)
    {
        m_xLayoutManager = xNewLayoutManager;
        if (xOldLayoutManager.is())
            disableLayoutManager(xOldLayoutManager);
        if (xNewLayoutManager.is() && !m_bDocHidden)
            lcl_enableLayoutManager(xNewLayoutManager, this);
    }
}

css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL Frame::getPropertySetInfo()
{
    checkDisposed();
    css::uno::Reference< css::beans::XPropertySetInfo > xInfo(
        static_cast< css::beans::XPropertySetInfo* >(this), css::uno::UNO_QUERY_THROW);
    return xInfo;
}

void SAL_CALL Frame::setPropertyValue(const OUString& sProperty,
                                                  const css::uno::Any&   aValue   )
{
    // TODO look for e.g. readonly props and reject setProp() call!

    checkDisposed();

    // SAFE ->
    SolarMutexGuard g;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    css::beans::Property aPropInfo = pIt->second;

    css::uno::Any aCurrentValue = impl_getPropertyValue(aPropInfo.Handle);

    bool bWillBeChanged = (aCurrentValue != aValue);
    if (! bWillBeChanged)
        return;

    css::beans::PropertyChangeEvent aEvent;
    aEvent.PropertyName   = aPropInfo.Name;
    aEvent.Further        = false;
    aEvent.PropertyHandle = aPropInfo.Handle;
    aEvent.OldValue       = aCurrentValue;
    aEvent.NewValue       = aValue;
    aEvent.Source.set(m_xBroadcaster.get(), css::uno::UNO_QUERY);

    if (impl_existsVeto(aEvent))
        throw css::beans::PropertyVetoException();

    impl_setPropertyValue(aPropInfo.Handle, aValue);

    impl_notifyChangeListener(aEvent);
}

css::uno::Any SAL_CALL Frame::getPropertyValue(const OUString& sProperty)
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    css::beans::Property aPropInfo = pIt->second;

    return impl_getPropertyValue(aPropInfo.Handle);
}

void SAL_CALL Frame::addPropertyChangeListener(
        const OUString& sProperty,
        const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    aReadLock.clear();
    // <- SAFE

    m_lSimpleChangeListener.addInterface(sProperty, xListener);
}

void SAL_CALL Frame::removePropertyChangeListener(
        const OUString& sProperty,
        const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
{
    // SAFE ->
    SolarMutexClearableGuard aReadLock;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    aReadLock.clear();
    // <- SAFE

    m_lSimpleChangeListener.removeInterface(sProperty, xListener);
}

void SAL_CALL Frame::addVetoableChangeListener(
        const OUString& sProperty,
        const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
{
    checkDisposed();

    // SAFE ->
    SolarMutexClearableGuard aReadLock;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    aReadLock.clear();
    // <- SAFE

    m_lVetoChangeListener.addInterface(sProperty, xListener);
}

void SAL_CALL Frame::removeVetoableChangeListener(
        const OUString& sProperty,
        const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
{
    // SAFE ->
    SolarMutexClearableGuard aReadLock;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    aReadLock.clear();
    // <- SAFE

    m_lVetoChangeListener.removeInterface(sProperty, xListener);
}

css::uno::Sequence< css::beans::Property > SAL_CALL Frame::getProperties()
{
    checkDisposed();

    SolarMutexGuard g;

    sal_Int32 c = static_cast<sal_Int32>(m_lProps.size());
    css::uno::Sequence< css::beans::Property > lProps(c);

    for (auto const& elem : m_lProps)
    {
        lProps[--c] = elem.second;
    }

    return lProps;
}

css::beans::Property SAL_CALL Frame::getPropertyByName(const OUString& sName)
{
    checkDisposed();

    SolarMutexGuard g;

    TPropInfoHash::const_iterator pIt = m_lProps.find(sName);
    if (pIt == m_lProps.end())
        throw css::beans::UnknownPropertyException();

    return pIt->second;
}

sal_Bool SAL_CALL Frame::hasPropertyByName(const OUString& sName)
{
    checkDisposed();

    SolarMutexGuard g;

    TPropInfoHash::iterator pIt    = m_lProps.find(sName);
    bool                                   bExist = (pIt != m_lProps.end());

    return bExist;
}

/*-****************************************************************************************************/
void Frame::implts_forgetSubFrames()
{
    // SAFE ->
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::container::XIndexAccess > xContainer(m_xFramesHelper, css::uno::UNO_QUERY_THROW);
    aReadLock.clear();
    // <- SAFE

    sal_Int32 c = xContainer->getCount();
    sal_Int32 i = 0;

    for (i=0; i<c; ++i)
    {
        try
        {
            css::uno::Reference< css::frame::XFrame > xFrame;
            xContainer->getByIndex(i) >>= xFrame;
            if (xFrame.is())
                xFrame->setCreator(css::uno::Reference< css::frame::XFramesSupplier >());
        }
        catch(const css::uno::Exception&)
        {
            // Ignore errors here.
            // Nobody can guarantee a stable index in multi threaded environments .-)
        }
    }

    SolarMutexGuard g;
    m_xFramesHelper.clear(); // clear uno reference
    m_aChildFrameContainer.clear(); // clear container content
}

/*-****************************************************************************************************
    @short      destroy instance
    @descr      The owner of this object calls the dispose method if the object
                should be destroyed. All other objects and components, that are registered
                as an EventListener are forced to release their references to this object.
                Furthermore this frame is removed from its parent frame container to release
                this reference. The reference attributes are disposed and released also.

    @attention  Look for globale description at beginning of file too!
                (DisposedException, FairRWLock ..., initialize, dispose)

    @seealso    method initialize()
    @seealso    baseclass FairRWLockBase!
*//*-*****************************************************************************************************/
void SAL_CALL Frame::disposing()
{
    // We should hold a reference to ourself ...
    // because our owner dispose us and release our reference ...
    // May be we will die before we could finish this method ...
    css::uno::Reference< css::frame::XFrame > xThis( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );

    SAL_INFO("fwk.frame", "[Frame] " << m_sName << " send dispose event to listener");

    // First operation should be... "stop all listening for window events on our container window".
    // These events are superfluous but can make trouble!
    // We will die, die and die...
    implts_stopWindowListening();

    css::uno::Reference<css::frame::XLayoutManager2> layoutMgr;
    {
        SolarMutexGuard g;
        layoutMgr = m_xLayoutManager;
    }
    if (layoutMgr.is()) {
        disableLayoutManager(layoutMgr);
    }

    WindowCommandDispatch * disp = nullptr;
    {
        SolarMutexGuard g;
        std::swap(disp, m_pWindowCommandDispatch);
    }
    delete disp;

    // Send message to all listener and forget her references.
    css::lang::EventObject aEvent( xThis );
    m_aListenerContainer.disposeAndClear( aEvent );

    // set "end of live" for our property set helper
    impl_disablePropertySet();

    // interception/dispatch chain must be destructed explicitly
    // Otherwise some dispatches and/or interception objects won't die.
    css::uno::Reference< css::lang::XEventListener > xDispatchHelper;
    {
        SolarMutexGuard g;
        xDispatchHelper.set(m_xDispatchHelper, css::uno::UNO_QUERY_THROW);
    }
    xDispatchHelper->disposing(aEvent);
    xDispatchHelper.clear();

    // Don't show any dialogs, errors or something else any more!
    // If somewhere called dispose() whitout close() before - normally no dialogs
    // should exist. Otherwise it's the problem of the outside caller.
    // Note:
    //      (a) Do it after stopWindowListening(). May that force some active/deactive
    //          notifications which we don't need here really.
    //      (b) Don't forget to save the old value of IsDialogCancelEnabled() to
    //          restore it afterwards (to not kill headless mode).
    Application::DialogCancelMode old = Application::GetDialogCancelMode();
    Application::SetDialogCancelMode( Application::DialogCancelMode::Silent );

    // We should be alone for ever and further dispose calls are rejected by lines before ...
    // I hope it :-)

    // Free references of our frame tree.
    // Force parent container to forget this frame too ...
    // ( It's contained in m_xParent and so no css::lang::XEventListener for m_xParent! )
    // It's important to do that before we free some other internal structures.
    // Because if our parent gets an activate and found us as last possible active frame
    // he try to deactivate us ... and we run into some trouble (DisposedExceptions!).
    css::uno::Reference<css::frame::XFramesSupplier> parent;
    {
        SolarMutexGuard g;
        std::swap(parent, m_xParent);
    }
    if( parent.is() )
    {
        parent->getFrames()->remove( xThis );
    }

    /* } SAFE */
    // Forget our internal component and her window first.
    // So we can release our container window later without problems.
    // Because this container window is the parent of the component window ...
    // Note: Dispose it hard - because suspending must be done inside close() call!
    // But try to dispose the controller first before you destroy the window.
    // Because the window is used by the controller too ...
    css::uno::Reference< css::lang::XComponent > xDisposableCtrl;
    css::uno::Reference< css::lang::XComponent > xDisposableComp;
    {
        SolarMutexGuard g;
        xDisposableCtrl.set( m_xController, css::uno::UNO_QUERY );
        xDisposableComp.set( m_xComponentWindow, css::uno::UNO_QUERY );
    }
    if (xDisposableCtrl.is())
        xDisposableCtrl->dispose();
    if (xDisposableComp.is())
        xDisposableComp->dispose();

    impl_checkMenuCloser();

    css::uno::Reference<css::awt::XWindow> contWin;
    {
        SolarMutexGuard g;
        std::swap(contWin, m_xContainerWindow);
    }
    if( contWin.is() )
    {
        contWin->setVisible( false );
        // All VclComponents are XComponents; so call dispose before discarding
        // a css::uno::Reference< XVclComponent >, because this frame is the owner of the window
        contWin->dispose();
    }

    /*ATTENTION
        Clear container after successful removing from parent container ...
        because our parent could be the desktop which stand in dispose too!
        If we have already cleared our own container we lost our child before this could be
        remove himself at this instance ...
        Release m_xFramesHelper after that ... it's the same problem between parent and child!
        "m_xParent->getFrames()->remove( xThis );" needs this helper ...
        Otherwise we get a null reference and could finish removing successfully.
        => You see: Order of calling operations is important!!!
     */
    implts_forgetSubFrames();

    {
        SolarMutexGuard g;

        // Release some other references.
        // This calls should be easy ... I hope it :-)
        m_xDispatchHelper.clear();
        m_xDropTargetListener.clear();
        m_xDispatchRecorderSupplier.clear();
        m_xLayoutManager.clear();
        m_xIndicatorFactoryHelper.clear();

        // It's important to set default values here!
        // If may be later somewhere change the disposed-behaviour of this implementation
        // and doesn't throw any DisposedExceptions we must guarantee best matching default values ...
        m_eActiveState       = E_INACTIVE;
        m_sName.clear();
        m_bIsFrameTop        = false;
        m_bConnected         = false;
        m_nExternalLockCount = 0;
        m_bSelfClose         = false;
        m_bIsHidden          = true;
    }

    // Don't forget it restore old value -
    // otherwise no dialogs can be shown anymore in other frames.
    Application::SetDialogCancelMode( old );
}

/*-****************************************************************************************************
    @short      Be a listener for dispose events!
    @descr      Adds/remove an EventListener to this object. If the dispose method is called on
                this object, the disposing method of the listener is called.
    @param      "xListener" reference to your listener object.
    @onerror    Listener is ignored.
*//*-*****************************************************************************************************/
void SAL_CALL Frame::addEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
{
    checkDisposed();
    m_aListenerContainer.addInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
}

void SAL_CALL Frame::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener )
{
    m_aListenerContainer.removeInterface( cppu::UnoType<css::lang::XEventListener>::get(), xListener );
}

/*-****************************************************************************************************
    @short      create new status indicator
    @descr      Use returned status indicator to show progresses and some text information.
                All created objects share the same dialog! Only the last one can show his information.

    @seealso    class StatusIndicatorFactory
    @seealso    class StatusIndicator
    @return     A reference to created object.

    @onerror    We return a null reference.
*//*-*****************************************************************************************************/
css::uno::Reference< css::task::XStatusIndicator > SAL_CALL Frame::createStatusIndicator()
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexClearableGuard aReadLock;

    // Make snapshot of necessary member and define default return value.
    css::uno::Reference< css::task::XStatusIndicator >        xExternal(m_xIndicatorInterception.get(), css::uno::UNO_QUERY);
    css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory = m_xIndicatorFactoryHelper;

    aReadLock.clear();
    /* UNSAFE AREA ----------------------------------------------------------------------------------------- */

    // Was set from outside to intercept any progress activities!
    if (xExternal.is())
        return xExternal;

    // Or use our own factory as fallback, to create such progress.
    if (xFactory.is())
        return xFactory->createStatusIndicator();

    return css::uno::Reference< css::task::XStatusIndicator >();
}

/*-****************************************************************************************************
    @short      search for target to load URL
    @descr      This method searches for a dispatch for the specified DispatchDescriptor.
                The FrameSearchFlags and the FrameName of the DispatchDescriptor are
                treated as described for findFrame.

    @seealso    method findFrame()
    @seealso    method queryDispatches()
    @seealso    method set/getName()
    @seealso    class TargetFinder

    @param      "aURL"              , URL for loading
    @param      "sTargetFrameName"  , name of target frame
    @param      "nSearchFlags"      , additional flags to regulate search if sTargetFrameName is not clear
    @return     css::uno::Reference to dispatch handler.

    @onerror    A null reference is returned.
*//*-*****************************************************************************************************/
css::uno::Reference< css::frame::XDispatch > SAL_CALL Frame::queryDispatch( const css::util::URL& aURL,
                                                                            const OUString& sTargetFrameName,
                                                                            sal_Int32 nSearchFlags)
{
    // Don't check incoming parameter here! Our helper do it for us and it is not a good idea to do it more than ones!

    checkDisposed();

    // Remove uno and cmd protocol part as we want to support both of them. We store only the command part
    // in our hash map. All other protocols are stored with the protocol part.
    OUString aCommand( aURL.Main );
    if ( aURL.Protocol.equalsIgnoreAsciiCase(".uno:") )
        aCommand = aURL.Path;

    // Make std::unordered_map lookup if the current URL is in the disabled list
    if ( m_aCommandOptions.Lookup( SvtCommandOptions::CMDOPTION_DISABLED, aCommand ) )
        return css::uno::Reference< css::frame::XDispatch >();
    else
    {
        // We use a helper to support these interface and an interceptor mechanism.
        css::uno::Reference<css::frame::XDispatchProvider> disp;
        {
            SolarMutexGuard g;
            disp = m_xDispatchHelper;
        }
        if (!disp.is()) {
            throw css::lang::DisposedException("Frame disposed");
        }
        return disp->queryDispatch( aURL, sTargetFrameName, nSearchFlags );
    }
}

/*-****************************************************************************************************
    @short      handle more than ones dispatches at same call
    @descr      Returns a sequence of dispatches. For details see the queryDispatch method.
                For failed dispatches we return empty items in list!

    @seealso    method queryDispatch()

    @param      "lDescriptor" list of dispatch arguments for queryDispatch()!
    @return     List of dispatch references. Some elements can be NULL!

    @onerror    An empty list is returned.
*//*-*****************************************************************************************************/
css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL Frame::queryDispatches(
        const css::uno::Sequence< css::frame::DispatchDescriptor >& lDescriptor )
{
    // Don't check incoming parameter here! Our helper do it for us and it is not a good idea to do it more than ones!

    checkDisposed();

    // We use a helper to support these interface and an interceptor mechanism.
    css::uno::Reference<css::frame::XDispatchProvider> disp;
    {
        SolarMutexGuard g;
        disp = m_xDispatchHelper;
    }
    if (!disp.is()) {
        throw css::lang::DisposedException("Frame disposed");
    }
    return disp->queryDispatches( lDescriptor );
}

/*-****************************************************************************************************
    @short      register/unregister interceptor for dispatch calls
    @descr      If you wish to handle some dispatches by himself ... you should be
                an interceptor for it. Please see class OInterceptionHelper for further information.

    @seealso    class OInterceptionHelper

    @param      "xInterceptor", reference to your interceptor implementation.
    @onerror    Interceptor is ignored.
*//*-*****************************************************************************************************/
void SAL_CALL Frame::registerDispatchProviderInterceptor(
        const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor )
{
    // We use a helper to support these interface and an interceptor mechanism.
    // This helper is threadsafe himself and check incoming parameter too.
    // I think we don't need any lock here!

    checkDisposed();

    css::uno::Reference< css::frame::XDispatchProviderInterception > xInterceptionHelper;
    {
        SolarMutexGuard g;
        xInterceptionHelper.set( m_xDispatchHelper, css::uno::UNO_QUERY );
    }
    if (xInterceptionHelper.is()) {
        xInterceptionHelper->registerDispatchProviderInterceptor( xInterceptor );
    }
}

void SAL_CALL Frame::releaseDispatchProviderInterceptor(
        const css::uno::Reference< css::frame::XDispatchProviderInterceptor >& xInterceptor )
{
    // We use a helper to support these interface and an interceptor mechanism.
    // This helper is threadsafe himself and check incoming parameter too.
    // I think we don't need any lock here!

    // Sometimes we are called during our dispose() method

    css::uno::Reference< css::frame::XDispatchProviderInterception > xInterceptionHelper;
    {
        SolarMutexGuard g;
        xInterceptionHelper.set( m_xDispatchHelper, css::uno::UNO_QUERY );
    }
    if (xInterceptionHelper.is()) {
        xInterceptionHelper->releaseDispatchProviderInterceptor( xInterceptor );
    }
}

/*-****************************************************************************************************
    @short      provides information about all possible dispatch functions
                inside the current frame environment
*//*-*****************************************************************************************************/
css::uno::Sequence< sal_Int16 > SAL_CALL Frame::getSupportedCommandGroups()
{
    return m_xDispatchInfoHelper->getSupportedCommandGroups();
}

css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL Frame::getConfigurableDispatchInformation(
        sal_Int16 nCommandGroup)
{
    return m_xDispatchInfoHelper->getConfigurableDispatchInformation(nCommandGroup);
}

/*-****************************************************************************************************
    @short      notifications for window events
    @descr      We are a listener on our container window to forward it to our component window.

    @seealso    method setComponent()
    @seealso    member m_xContainerWindow
    @seealso    member m_xComponentWindow

    @param      "aEvent" describe source of detected event
*//*-*****************************************************************************************************/
void SAL_CALL Frame::windowResized( const css::awt::WindowEvent& )
{
    // Part of dispose-mechanism

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    // Impl-method is threadsafe!
    // If we have a current component window - we must resize it!
    implts_resizeComponentWindow();
}

void SAL_CALL Frame::focusGained( const css::awt::FocusEvent& )
{
    // Part of dispose() mechanism

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexClearableGuard aReadLock;
    // Make snapshot of member!
    css::uno::Reference< css::awt::XWindow > xComponentWindow = m_xComponentWindow;
    aReadLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    if( xComponentWindow.is() )
    {
        xComponentWindow->setFocus();
    }
}

/*-****************************************************************************************************
    @short      notifications for window events
    @descr      We are a listener on our container window to forward it to our component window ...
                but a XTopWindowListener we are only if we are a top frame!

    @seealso    method setComponent()
    @seealso    member m_xContainerWindow
    @seealso    member m_xComponentWindow

    @param      "aEvent" describe source of detected event
*//*-*****************************************************************************************************/
void SAL_CALL Frame::windowActivated( const css::lang::EventObject& )
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexClearableGuard aReadLock;
    // Make snapshot of member!
    EActiveState eState = m_eActiveState;
    aReadLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
    // Activate the new active path from here to top.
    if( eState == E_INACTIVE )
    {
        setActiveFrame( css::uno::Reference< css::frame::XFrame >() );
        activate();
    }
}

void SAL_CALL Frame::windowDeactivated( const css::lang::EventObject& )
{
    // Sometimes called during dispose()

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexClearableGuard aReadLock;

    css::uno::Reference< css::frame::XFrame > xParent          ( m_xParent, css::uno::UNO_QUERY );
    css::uno::Reference< css::awt::XWindow >  xContainerWindow = m_xContainerWindow;
    EActiveState                              eActiveState     = m_eActiveState;

    aReadLock.clear();

    if( eActiveState != E_INACTIVE )
    {
        // Deactivation is always done implicitly by activation of another frame.
        // Only if no activation is done, deactivations have to be processed if the activated window
        // is a parent window of the last active Window!
        SolarMutexClearableGuard aSolarGuard;
        vcl::Window* pFocusWindow = Application::GetFocusWindow();
        if  ( xContainerWindow.is() && xParent.is() &&
              !css::uno::Reference< css::frame::XDesktop >( xParent, css::uno::UNO_QUERY ).is()
            )
        {
            css::uno::Reference< css::awt::XWindow >  xParentWindow   = xParent->getContainerWindow();
            VclPtr<vcl::Window>                       pParentWindow   = VCLUnoHelper::GetWindow( xParentWindow    );
            //#i70261#: dialogs opened from an OLE object will cause a deactivate on the frame of the OLE object
            // on Solaris/Linux at that time pFocusWindow is still NULL because the focus handling is different; right after
            // the deactivation the focus will be set into the dialog!
            // currently I see no case where a sub frame could get a deactivate with pFocusWindow being NULL permanently
            // so for now this case is omitted from handled deactivations
            if( pFocusWindow && pParentWindow->IsChild( pFocusWindow ) )
            {
                css::uno::Reference< css::frame::XFramesSupplier > xSupplier( xParent, css::uno::UNO_QUERY );
                if( xSupplier.is() )
                {
                    aSolarGuard.clear();
                    xSupplier->setActiveFrame( css::uno::Reference< css::frame::XFrame >() );
                }
            }
        }
    }
}

void SAL_CALL Frame::windowClosing( const css::lang::EventObject& )
{
    checkDisposed();

    // deactivate this frame ...
    deactivate();

    // ... and try to close it
    // But do it asynchron inside the main thread.
    // VCL has no fun to do such things outside his main thread :-(
    // Note: The used dispatch make it asynchronous for us .-)

    /*ATTENTION!
        Don't try to suspend the controller here! Because it's done inside used dispatch().
        Otherwise the dialog "would you save your changes?" will be shown more than once ...
     */

    css::util::URL aURL;
    aURL.Complete = ".uno:CloseFrame";
    css::uno::Reference< css::util::XURLTransformer > xParser(css::util::URLTransformer::create(m_xContext));
    xParser->parseStrict(aURL);

    css::uno::Reference< css::frame::XDispatch > xCloser = queryDispatch(aURL, SPECIALTARGET_SELF, 0);
    if (xCloser.is())
        xCloser->dispatch(aURL, css::uno::Sequence< css::beans::PropertyValue >());

    // Attention: If this dispatch works synchronous ... and fulfill its job ...
    // this line of code will never be reached ...
    // Or if it will be reached it will be for sure that all your member are gone .-)
}

/*-****************************************************************************************************
    @short      react for a show event for the internal container window
    @descr      Normally we don't need this information really. But we can use it to
                implement the special feature "trigger first visible task".

                Algorithm: - first we have to check if we are a top (task) frame
                             It's not enough to be a top frame! Because we MUST have the desktop as parent.
                             But frames without a parent are top too. So it's not possible to check isTop() here!
                             We have to look for the type of our parent.
                           - if we are a task frame, then we have to check if we are the first one.
                             We use a static variable to do so. They will be reset to afterwards be sure
                             that further calls of this method doesn't do anything then.
                           - Then we have to trigger the right event string on the global job executor.

    @seealso    css::task::JobExecutor

    @param      aEvent
                    describes the source of this event
                    We are not interested on this information. We are interested on the visible state only.

    @threadsafe yes
*//*-*****************************************************************************************************/
void SAL_CALL Frame::windowShown( const css::lang::EventObject& )
{
    static osl::Mutex aFirstVisibleLock;

    /* SAFE { */
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::frame::XDesktop > xDesktopCheck( m_xParent, css::uno::UNO_QUERY );
    m_bIsHidden = false;
    aReadLock.clear();
    /* } SAFE */

    impl_checkMenuCloser();

    if (xDesktopCheck.is())
    {
        static bool bFirstVisibleTask = true;
        osl::ClearableMutexGuard aGuard(aFirstVisibleLock);
        bool bMustBeTriggered = bFirstVisibleTask;
        bFirstVisibleTask = false;
        aGuard.clear();

        if (bMustBeTriggered)
        {
            css::uno::Reference< css::task::XJobExecutor > xExecutor
                = css::task::theJobExecutor::get( m_xContext );
            xExecutor->trigger( "onFirstVisibleTask" );
        }
    }
}

void SAL_CALL Frame::windowHidden( const css::lang::EventObject& )
{
    /* SAFE { */
    SolarMutexClearableGuard aReadLock;
    m_bIsHidden = true;
    aReadLock.clear();
    /* } SAFE */

    impl_checkMenuCloser();
}

/*-****************************************************************************************************
    @short      called by dispose of our windows!
    @descr      This object is forced to release all references to the interfaces given
                by the parameter source. We are a listener at our container window and
                should listen for his diposing.

    @seealso    XWindowListener
    @seealso    XTopWindowListener
    @seealso    XFocusListener
*//*-*****************************************************************************************************/
void SAL_CALL Frame::disposing( const css::lang::EventObject& aEvent )
{
    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    SolarMutexResettableGuard aWriteLock;

    if( aEvent.Source == m_xContainerWindow )
    {
        // NECESSARY: Impl-method is threadsafe by himself!
        aWriteLock.clear();
        implts_stopWindowListening();
        aWriteLock.reset();
        m_xContainerWindow.clear();
    }
}

/*-************************************************************************************************************
    @interface  com.sun.star.document.XActionLockable
    @short      implement locking of frame/task from outside
    @descr      Sometimes we have problems to decide if closing of task is allowed. Because; frame/task
                could be used for pending loading jobs. So you can lock this object from outside and
                prevent instance against closing during using! But - don't do it in a wrong or expensive manner.
                Otherwise task couldn't die anymore!!!

    @seealso    interface XActionLockable
    @seeelso    method BaseDispatcher::implts_loadIt()
    @seeelso    method Desktop::loadComponentFromURL()
    @return     true if frame/task is locked
                false otherwise
    @threadsafe yes
*//*-*************************************************************************************************************/
sal_Bool SAL_CALL Frame::isActionLocked()
{
    SolarMutexGuard g;
    return( m_nExternalLockCount!=0);
}

void SAL_CALL Frame::addActionLock()
{
    SolarMutexGuard g;
    ++m_nExternalLockCount;
}

void SAL_CALL Frame::removeActionLock()
{
    {
        SolarMutexGuard g;
        SAL_WARN_IF( m_nExternalLockCount<=0, "fwk.frame", "Frame::removeActionLock(): Frame is not locked! "
            "Possible multithreading problem detected." );
        --m_nExternalLockCount;
    }

    implts_checkSuicide();
}

void SAL_CALL Frame::setActionLocks( sal_Int16 nLock )
{
    SolarMutexGuard g;
    // Attention: If somewhere called resetActionLocks() before and get e.g. 5 locks ...
    //            and tried to set these 5 ones here after his operations ...
    //            we can't ignore set requests during these two calls!
    //            So we must add(!) these 5 locks here.
    m_nExternalLockCount = m_nExternalLockCount + nLock;
}

sal_Int16 SAL_CALL Frame::resetActionLocks()
{
    sal_Int16 nCurrentLocks = 0;
    {
        SolarMutexGuard g;
        nCurrentLocks = m_nExternalLockCount;
        m_nExternalLockCount = 0;
    }

    // Attention:
    // external lock count is 0 here every time ... but if
    // member m_bSelfClose is set to true too .... we call our own close()/dispose().
    // See close() for further information
    implts_checkSuicide();

    return nCurrentLocks;
}

void Frame::impl_setPropertyValue(sal_Int32 nHandle,
                                           const css::uno::Any& aValue)

{
    /* There is no need to lock any mutex here. Because we share the
       solar mutex with our base class. And we said to our base class: "don't release it on calling us" .-)
    */

    /* Attention: You can use nHandle only, if you are sure that all supported
                  properties has an unique handle. That must be guaranteed
                  inside method initListeners()!
    */
    switch (nHandle)
    {
        case FRAME_PROPHANDLE_TITLE :
                {
                    OUString sExternalTitle;
                    aValue >>= sExternalTitle;
                    setTitle (sExternalTitle);
                }
                break;

        case FRAME_PROPHANDLE_DISPATCHRECORDERSUPPLIER :
                aValue >>= m_xDispatchRecorderSupplier;
                break;

        case FRAME_PROPHANDLE_LAYOUTMANAGER :
                {
                    css::uno::Reference< css::frame::XLayoutManager2 > xOldLayoutManager = m_xLayoutManager;
                    css::uno::Reference< css::frame::XLayoutManager2 > xNewLayoutManager;
                    aValue >>= xNewLayoutManager;

                    if (xOldLayoutManager != xNewLayoutManager)
                    {
                        m_xLayoutManager = xNewLayoutManager;
                        if (xOldLayoutManager.is())
                            disableLayoutManager(xOldLayoutManager);
                        if (xNewLayoutManager.is() && !m_bDocHidden)
                            lcl_enableLayoutManager(xNewLayoutManager, this);
                    }
                }
                break;

        case FRAME_PROPHANDLE_INDICATORINTERCEPTION :
                {
                    css::uno::Reference< css::task::XStatusIndicator > xProgress;
                    aValue >>= xProgress;
                    m_xIndicatorInterception = xProgress;
                }
                break;

        default :
                SAL_INFO("fwk.frame",  "Frame::setFastPropertyValue_NoBroadcast(): Invalid handle detected!" );
                break;
    }
}

css::uno::Any Frame::impl_getPropertyValue(sal_Int32 nHandle)
{
    /* There is no need to lock any mutex here. Because we share the
       solar mutex with our base class. And we said to our base class: "don't release it on calling us" .-)
    */

    /* Attention: You can use nHandle only, if you are sure that all supported
                  properties has an unique handle. That must be guaranteed
                  inside method initListeners()!
    */
    css::uno::Any aValue;
    switch (nHandle)
    {
        case FRAME_PROPHANDLE_TITLE :
                aValue <<= getTitle ();
                break;

        case FRAME_PROPHANDLE_DISPATCHRECORDERSUPPLIER :
                aValue <<= m_xDispatchRecorderSupplier;
                break;

        case FRAME_PROPHANDLE_ISHIDDEN :
                aValue <<= m_bIsHidden;
                break;

        case FRAME_PROPHANDLE_LAYOUTMANAGER :
                aValue <<= m_xLayoutManager;
                break;

        case FRAME_PROPHANDLE_INDICATORINTERCEPTION :
                {
                    css::uno::Reference< css::task::XStatusIndicator > xProgress(m_xIndicatorInterception.get(),
                                                                                 css::uno::UNO_QUERY);
                    aValue <<= xProgress;
                }
                break;

        default :
                SAL_INFO("fwk.frame", "Frame::getFastPropertyValue(): Invalid handle detected!" );
                break;
    }

    return aValue;
}

void Frame::impl_setPropertyChangeBroadcaster(const css::uno::Reference< css::uno::XInterface >& xBroadcaster)
{
    SolarMutexGuard g;
    m_xBroadcaster = xBroadcaster;
}

void Frame::impl_addPropertyInfo(const css::beans::Property& aProperty)
{
    SolarMutexGuard g;

    TPropInfoHash::const_iterator pIt = m_lProps.find(aProperty.Name);
    if (pIt != m_lProps.end())
        throw css::beans::PropertyExistException();

    m_lProps[aProperty.Name] = aProperty;
}

void Frame::impl_disablePropertySet()
{
    SolarMutexGuard g;

    css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::beans::XPropertySet* >(this), css::uno::UNO_QUERY);
    css::lang::EventObject aEvent(xThis);

    m_lSimpleChangeListener.disposeAndClear(aEvent);
    m_lVetoChangeListener.disposeAndClear(aEvent);
    m_lProps.clear();
}

bool Frame::impl_existsVeto(const css::beans::PropertyChangeEvent& aEvent)
{
    /*  Don't use the lock here!
        The used helper is threadsafe and it lives for the whole lifetime of
        our own object.
    */
    ::cppu::OInterfaceContainerHelper* pVetoListener = m_lVetoChangeListener.getContainer(aEvent.PropertyName);
    if (! pVetoListener)
        return false;

    ::cppu::OInterfaceIteratorHelper pListener(*pVetoListener);
    while (pListener.hasMoreElements())
    {
        try
        {
            css::uno::Reference< css::beans::XVetoableChangeListener > xListener(
                static_cast<css::beans::XVetoableChangeListener*>(pListener.next()),
                css::uno::UNO_QUERY_THROW);
            xListener->vetoableChange(aEvent);
        }
        catch(const css::uno::RuntimeException&)
            { pListener.remove(); }
        catch(const css::beans::PropertyVetoException&)
            { return true; }
    }

    return false;
}

void Frame::impl_notifyChangeListener(const css::beans::PropertyChangeEvent& aEvent)
{
    /*  Don't use the lock here!
        The used helper is threadsafe and it lives for the whole lifetime of
        our own object.
    */
    ::cppu::OInterfaceContainerHelper* pSimpleListener = m_lSimpleChangeListener.getContainer(aEvent.PropertyName);
    if (! pSimpleListener)
        return;

    ::cppu::OInterfaceIteratorHelper pListener(*pSimpleListener);
    while (pListener.hasMoreElements())
    {
        try
        {
            css::uno::Reference< css::beans::XPropertyChangeListener > xListener(
                static_cast<css::beans::XVetoableChangeListener*>(pListener.next()),
                css::uno::UNO_QUERY_THROW);
            xListener->propertyChange(aEvent);
        }
        catch(const css::uno::RuntimeException&)
            { pListener.remove(); }
    }
}

/*-****************************************************************************************************
    @short      send frame action event to our listener
    @descr      This method is threadsafe AND can be called by our dispose method too!
    @param      "aAction", describe the event for sending
*//*-*****************************************************************************************************/
void Frame::implts_sendFrameActionEvent( const css::frame::FrameAction& aAction )
{
    // Sometimes used by dispose()

    // Log information about order of events to file!
    // (only activated in debug version!)
    SAL_INFO( "fwk.frame",
              "[Frame] " << m_sName << " send event " <<
              (aAction == css::frame::FrameAction_COMPONENT_ATTACHED ? OUString("COMPONENT ATTACHED") :
               (aAction == css::frame::FrameAction_COMPONENT_DETACHING ? OUString("COMPONENT DETACHING") :
                (aAction == css::frame::FrameAction_COMPONENT_REATTACHED ? OUString("COMPONENT REATTACHED") :
                 (aAction == css::frame::FrameAction_FRAME_ACTIVATED ? OUString("FRAME ACTIVATED") :
                  (aAction == css::frame::FrameAction_FRAME_DEACTIVATING ? OUString("FRAME DEACTIVATING") :
                   (aAction == css::frame::FrameAction_CONTEXT_CHANGED ? OUString("CONTEXT CHANGED") :
                    (aAction == css::frame::FrameAction_FRAME_UI_ACTIVATED ? OUString("FRAME UI ACTIVATED") :
                     (aAction == css::frame::FrameAction_FRAME_UI_DEACTIVATING ? OUString("FRAME UI DEACTIVATING") :
                      (aAction == css::frame::FrameAction::FrameAction_MAKE_FIXED_SIZE ? OUString("MAKE_FIXED_SIZE") :
                       OUString("*invalid*")))))))))));

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    // Send css::frame::FrameAction event to all listener.
    // Get container for right listener.
    // FOLLOW LINES ARE THREADSAFE!!!
    // ( OInterfaceContainerHelper2 is synchronized with m_aListenerContainer! )
    ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer(
        cppu::UnoType<css::frame::XFrameActionListener>::get());

    if( pContainer != nullptr )
    {
        // Build action event.
        css::frame::FrameActionEvent aFrameActionEvent( static_cast< ::cppu::OWeakObject* >(this), this, aAction );

        // Get iterator for access to listener.
        ::cppu::OInterfaceIteratorHelper aIterator( *pContainer );
        // Send message to all listener.
        while( aIterator.hasMoreElements() )
        {
            try
            {
                static_cast<css::frame::XFrameActionListener*>(aIterator.next())->frameAction( aFrameActionEvent );
            }
            catch( const css::uno::RuntimeException& )
            {
                aIterator.remove();
            }
        }
    }
}

/*-****************************************************************************************************
    @short      helper to resize our component window
    @descr      A frame contains 2 windows - a container ~ and a component window.
                This method resize inner component window to full size of outer container window.
                This method is threadsafe AND can be called by our dispose method too!
*//*-*****************************************************************************************************/
void Frame::implts_resizeComponentWindow()
{
    // usually the LayoutManager does the resizing
    // in case there is no LayoutManager resizing has to be done here
    if ( !m_xLayoutManager.is() )
    {
        css::uno::Reference< css::awt::XWindow > xComponentWindow( getComponentWindow() );
        if( xComponentWindow.is() )
        {
            css::uno::Reference< css::awt::XDevice > xDevice( getContainerWindow(), css::uno::UNO_QUERY );

            // Convert relative size to output size.
            css::awt::Rectangle  aRectangle  = getContainerWindow()->getPosSize();
            css::awt::DeviceInfo aInfo = xDevice->getInfo();
            css::awt::Size aSize( aRectangle.Width - aInfo.LeftInset - aInfo.RightInset,
                                  aRectangle.Height - aInfo.TopInset - aInfo.BottomInset );

            // Resize our component window.
            xComponentWindow->setPosSize( 0, 0, aSize.Width, aSize.Height, css::awt::PosSize::POSSIZE );
        }
    }
}

/*-****************************************************************************************************
    @short      helper to set icon on our container window (if it is a system window!)
    @descr      We use our internal set controller (if it exist) to specify which factory he represented.
                These information can be used to find right icon. But our controller can say it us directly
                too ... we should ask his optional property set first ...

    @seealso    method Window::SetIcon()
    @onerror    We do nothing.
*//*-*****************************************************************************************************/
void Frame::implts_setIconOnWindow()
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    // Make snapshot of necessary members and release lock.
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::awt::XWindow > xContainerWindow( m_xContainerWindow, css::uno::UNO_QUERY );
    css::uno::Reference< css::frame::XController > xController( m_xController, css::uno::UNO_QUERY );
    aReadLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    if( xContainerWindow.is() && xController.is() )
    {

        // a) set default value to an invalid one. So we can start further searches for right icon id, if
        //    first steps failed!
        //    We must reset it to any fallback value - if no search step returns a valid result.
        sal_Int32 nIcon = -1;

        // b) try to find information on controller propertyset directly
        //    Don't forget to catch possible exceptions - because these property is an optional one!
        css::uno::Reference< css::beans::XPropertySet > xSet( xController, css::uno::UNO_QUERY );
        if( xSet.is() )
        {
            try
            {
                css::uno::Reference< css::beans::XPropertySetInfo > const xPSI( xSet->getPropertySetInfo(),
                                                                                css::uno::UNO_SET_THROW );
                if ( xPSI->hasPropertyByName( "IconId" ) )
                    xSet->getPropertyValue( "IconId" ) >>= nIcon;
            }
            catch( css::uno::Exception& )
            {
                DBG_UNHANDLED_EXCEPTION();
            }
        }

        // c) if b) failed... analyze argument list of currently loaded document inside the frame to find the filter.
        //    He can be used to detect right factory - and these can be used to match factory to icon...
        if( nIcon == -1 )
        {
            css::uno::Reference< css::frame::XModel > xModel = xController->getModel();
            if( xModel.is() )
            {
                SvtModuleOptions::EFactory eFactory = SvtModuleOptions::ClassifyFactoryByModel(xModel);
                if (eFactory != SvtModuleOptions::EFactory::UNKNOWN_FACTORY)
                    nIcon = SvtModuleOptions().GetFactoryIcon( eFactory );
            }
        }

        // d) if all steps failed - use fallback!
        if( nIcon == -1 )
        {
            nIcon = 0;
        }

        // e) set icon on container window now
        //    Don't forget SolarMutex! We use vcl directly :-(
        //    Check window pointer for right WorkWindow class too!!!
        /* SAFE AREA ----------------------------------------------------------------------------------------------- */
        {
            SolarMutexGuard aSolarGuard;
            VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xContainerWindow );
            if(
                ( pWindow            != nullptr              ) &&
                ( pWindow->GetType() == WindowType::WORKWINDOW )
                )
            {
                WorkWindow* pWorkWindow = static_cast<WorkWindow*>(pWindow.get());
                pWorkWindow->SetIcon( static_cast<sal_uInt16>(nIcon) );
            }
        }
        /* UNSAFE AREA --------------------------------------------------------------------------------------------- */
    }
}

/*-************************************************************************************************************
    @short      helper to start/stop listeneing for window events on container window
    @descr      If we get a new container window, we must set it on internal member ...
                and stop listening at old one ... and start listening on new one!
                But sometimes (in dispose() call!) it's necessary to stop listeneing without starting
                on new connections. So we split this functionality to make it easier at use.

    @seealso    method initialize()
    @seealso    method dispose()
    @onerror    We do nothing!
    @threadsafe yes
*//*-*************************************************************************************************************/
void Frame::implts_startWindowListening()
{
    checkDisposed();

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    // Make snapshot of necessary member!
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::awt::XWindow > xContainerWindow = m_xContainerWindow;
    css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > xDragDropListener = m_xDropTargetListener;
    css::uno::Reference< css::awt::XWindowListener > xWindowListener( static_cast< ::cppu::OWeakObject* >(this),
                                                                      css::uno::UNO_QUERY );
    css::uno::Reference< css::awt::XFocusListener > xFocusListener( static_cast< ::cppu::OWeakObject* >(this),
                                                                    css::uno::UNO_QUERY );
    css::uno::Reference< css::awt::XTopWindowListener > xTopWindowListener( static_cast< ::cppu::OWeakObject* >(this),
                                                                            css::uno::UNO_QUERY );
    aReadLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    if( xContainerWindow.is() )
    {
        xContainerWindow->addWindowListener( xWindowListener);
        xContainerWindow->addFocusListener ( xFocusListener );

        css::uno::Reference< css::awt::XTopWindow > xTopWindow( xContainerWindow, css::uno::UNO_QUERY );
        if( xTopWindow.is() )
        {
            xTopWindow->addTopWindowListener( xTopWindowListener );

            css::uno::Reference< css::awt::XToolkit2 > xToolkit = css::awt::Toolkit::create( m_xContext );
            css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget = xToolkit->getDropTarget( xContainerWindow );
            if( xDropTarget.is() )
            {
                xDropTarget->addDropTargetListener( xDragDropListener );
                xDropTarget->setActive( true );
            }
        }
    }
}

void Frame::implts_stopWindowListening()
{
    // Sometimes used by dispose()

    /* SAFE AREA ----------------------------------------------------------------------------------------------- */
    // Make snapshot of necessary member!
    SolarMutexClearableGuard aReadLock;
    css::uno::Reference< css::awt::XWindow > xContainerWindow = m_xContainerWindow;
    css::uno::Reference< css::datatransfer::dnd::XDropTargetListener > xDragDropListener = m_xDropTargetListener;
    css::uno::Reference< css::awt::XWindowListener > xWindowListener( static_cast< ::cppu::OWeakObject* >(this),
                                                                      css::uno::UNO_QUERY );
    css::uno::Reference< css::awt::XFocusListener > xFocusListener( static_cast< ::cppu::OWeakObject* >(this),
                                                                    css::uno::UNO_QUERY );
    css::uno::Reference< css::awt::XTopWindowListener > xTopWindowListener( static_cast< ::cppu::OWeakObject* >(this),
                                                                            css::uno::UNO_QUERY );
    aReadLock.clear();
    /* UNSAFE AREA --------------------------------------------------------------------------------------------- */

    if( xContainerWindow.is() )
    {
        xContainerWindow->removeWindowListener( xWindowListener);
        xContainerWindow->removeFocusListener ( xFocusListener );

        css::uno::Reference< css::awt::XTopWindow > xTopWindow( xContainerWindow, css::uno::UNO_QUERY );
        if( xTopWindow.is() )
        {
            xTopWindow->removeTopWindowListener( xTopWindowListener );

            css::uno::Reference< css::awt::XToolkit2 > xToolkit = css::awt::Toolkit::create( m_xContext );
            css::uno::Reference< css::datatransfer::dnd::XDropTarget > xDropTarget =
                xToolkit->getDropTarget( xContainerWindow );
            if( xDropTarget.is() )
            {
                xDropTarget->removeDropTargetListener( xDragDropListener );
                xDropTarget->setActive( false );
            }
        }
    }
}

/*-****************************************************************************************************
    @short      helper to force breaked close() request again
    @descr      If we self disagree with a close() request, and detect that all external locks are gone ...
                then we must try to close this frame again.

    @seealso    XCloseable::close()
    @seealso    Frame::close()
    @seealso    Frame::removeActionLock()
    @seealso    Frame::resetActionLock()
    @seealso    m_bSelfClose
    @seealso    m_nExternalLockCount

    @threadsafe yes
*//*-*****************************************************************************************************/
void Frame::implts_checkSuicide()
{
    /* SAFE */
    SolarMutexClearableGuard aReadLock;
    // in case of lock==0 and safed state of previous close() request m_bSelfClose
    // we must force close() again. Because we had disagreed with that before.
    bool bSuicide = (m_nExternalLockCount==0 && m_bSelfClose);
    m_bSelfClose = false;
    aReadLock.clear();
    /* } SAFE */
    // force close and deliver ownership to source of possible throwed veto exception
    // Attention: Because this method is not designed to throw such exception we must suppress
    // it for outside code!
    try
    {
        if (bSuicide)
            close(true);
    }
    catch(const css::util::CloseVetoException&)
        {}
    catch(const css::lang::DisposedException&)
        {}
}

/** little helper to enable/disable the menu closer at the menubar of the given frame.

    @param  xFrame
            we use its layout manager to set/reset a special callback.
            Its existence regulate visibility of this closer item.

    @param  bState
                <TRUE/> enable; <FALSE/> disable this state
 */

void Frame::impl_setCloser( /*IN*/ const css::uno::Reference< css::frame::XFrame2 >& xFrame ,
                            /*IN*/       bool                                   bState  )
{
    // Note: If start module is not installed - no closer has to be shown!
    if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE))
        return;

    try
    {
        css::uno::Reference< css::beans::XPropertySet > xFrameProps(xFrame, css::uno::UNO_QUERY_THROW);
        css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
        xFrameProps->getPropertyValue(FRAME_PROPNAME_ASCII_LAYOUTMANAGER) >>= xLayoutManager;
        css::uno::Reference< css::beans::XPropertySet > xLayoutProps(xLayoutManager, css::uno::UNO_QUERY_THROW);
        xLayoutProps->setPropertyValue(LAYOUTMANAGER_PROPNAME_MENUBARCLOSER, css::uno::makeAny(bState));
    }
    catch(const css::uno::RuntimeException&)
        { throw; }
    catch(const css::uno::Exception&)
        {}
}

/** it checks, which of the top level task frames must have the special menu closer for
    switching to the backing window mode.

    It analyze the current list of visible top level frames. Only the last real document
    frame can have this symbol. Not the help frame nor the backing task itself.
    Here we do anything related to this closer. We remove it from the old frame and set it
    for the new one.
 */

void Frame::impl_checkMenuCloser()
{
    /* SAFE { */
    SolarMutexClearableGuard aReadLock;

    // only top frames, which are part of our desktop hierarchy, can
    // do so! By the way - we need the desktop instance to have access
    // to all other top level frames too.
    css::uno::Reference< css::frame::XDesktop > xDesktop (m_xParent, css::uno::UNO_QUERY);
    css::uno::Reference< css::frame::XFramesSupplier > xTaskSupplier(xDesktop , css::uno::UNO_QUERY);
    if ( !xDesktop.is() || !xTaskSupplier.is() )
        return;

    aReadLock.clear();
    /* } SAFE */

    // analyze the list of current open tasks
    // Suppress search for other views to the same model ...
    // It's not needed here and can be very expensive.
    FrameListAnalyzer aAnalyzer(
        xTaskSupplier,
        this,
        FrameAnalyzerFlags::Hidden | FrameAnalyzerFlags::Help | FrameAnalyzerFlags::BackingComponent);

    // specify the new frame, which must have this special state ...
    css::uno::Reference< css::frame::XFrame2 > xNewCloserFrame;

    // a)
    // If there exist ate least one other frame - there are two frames currently open.
    // But we can enable this closer only, if one of these two tasks includes the help module.
    // The "other frame" couldn't be the help. Because then it wouldn't be part of this "other list".
    // In such case it will be separated to the reference aAnalyzer.m_xHelp!
    // But we must check, if weself includes the help ...
    // Check aAnalyzer.m_bReferenceIsHelp!
    if (
        (aAnalyzer.m_lOtherVisibleFrames.size()==1)   &&
        (
            (aAnalyzer.m_bReferenceIsHelp  ) ||
            (aAnalyzer.m_bReferenceIsHidden)
        )
       )
    {
        // others[0] can't be the backing component!
        // Because it's set at the special member aAnalyzer.m_xBackingComponent ... :-)
        xNewCloserFrame.set( aAnalyzer.m_lOtherVisibleFrames[0], css::uno::UNO_QUERY_THROW );
    }

    // b)
    // There is no other frame ... means no other document frame. The help module
    // will be handled separately and must(!) be ignored here ... excepting weself includes the help.
    else if (
        (aAnalyzer.m_lOtherVisibleFrames.empty()) &&
        (!aAnalyzer.m_bReferenceIsHelp) &&
        (!aAnalyzer.m_bReferenceIsHidden) &&
        (!aAnalyzer.m_bReferenceIsBacking)
       )
    {
        xNewCloserFrame = this;
    }

    // Look for necessary actions ...
    // Only if the closer state must be moved from one frame to another one
    // or must be enabled/disabled at all.
    SolarMutexGuard aGuard;
    // Holds the only frame, which must show the special closer menu item (can be NULL!)
    static css::uno::WeakReference< css::frame::XFrame2 > s_xCloserFrame;
    css::uno::Reference< css::frame::XFrame2 > xCloserFrame (s_xCloserFrame.get(), css::uno::UNO_QUERY);
    if (xCloserFrame!=xNewCloserFrame)
    {
        if (xCloserFrame.is())
            impl_setCloser(xCloserFrame, false);
        if (xNewCloserFrame.is())
            impl_setCloser(xNewCloserFrame, true);
        s_xCloserFrame = xNewCloserFrame;
    }
}

}

extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
com_sun_star_comp_framework_Frame_get_implementation(
    css::uno::XComponentContext *context,
    css::uno::Sequence<css::uno::Any> const &)
{
    Frame *inst = new Frame(context);
    css::uno::XInterface *acquired_inst = cppu::acquire(inst);

    inst->initListeners();

    return acquired_inst;
}

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