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
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
|
/*************************************************************************
*
* $RCSfile: fmshimp.cxx,v $
*
* $Revision: 1.40 $
*
* last change: $Author: fs $ $Date: 2002-11-12 11:28:01 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#pragma hdrstop
#if STLPORT_VERSION>=321
#include <math.h> // prevent conflict between exception and std::exception
#endif
#ifndef _SVX_GRIDCOLS_HXX
#include "gridcols.hxx"
#endif
#ifndef _E3D_OBJ3D_HXX
#include <obj3d.hxx>
#endif
#ifndef _SVX_FMVWIMP_HXX
#include "fmvwimp.hxx"
#endif
#ifndef _SVX_FMSHIMP_HXX
#include "fmshimp.hxx"
#endif
#ifndef _SVDPAGV_HXX //autogen
#include "svdpagv.hxx"
#endif
#ifndef _SVX_FMPAGE_HXX
#include "fmpage.hxx"
#endif
#ifndef _ISOLANG_HXX
#include <tools/isolang.hxx>
#endif
#ifndef _SHL_HXX
#include <tools/shl.hxx>
#endif
#ifndef _SV_MSGBOX_HXX //autogen
#include <vcl/msgbox.hxx>
#endif
#ifndef _SVX_DIALMGR_HXX //autogen
#include <dialmgr.hxx>
#endif
#ifndef _SVX_FMRESIDS_HRC
#include "fmresids.hrc"
#endif // _SVX_FMRESIDS_HRC
#ifndef _SVX_FMITEMS_HXX
#include "fmitems.hxx"
#endif
#ifndef _SVX_FMOBJ_HXX
#include "fmobj.hxx"
#endif
#ifndef _MULTIPRO_HXX
#include "multipro.hxx"
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XLOADABLE_HPP_
#include <com/sun/star/form/XLoadable.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XCONTAINER_HPP_
#include <com/sun/star/container/XContainer.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATION_HPP_
#include <com/sun/star/container/XEnumeration.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XINDEXACCESS_HPP_
#include <com/sun/star/container/XIndexAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XENUMERATIONACCESS_HPP_
#include <com/sun/star/container/XEnumerationAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#endif
#ifndef _COM_SUN_STAR_AWT_XTEXTCOMPONENT_HPP_
#include <com/sun/star/awt/XTextComponent.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XBOUNDCOMPONENT_HPP_
#include <com/sun/star/form/XBoundComponent.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_LISTSOURCETYPE_HPP_
#include <com/sun/star/form/ListSourceType.hpp>
#endif
#ifndef _COM_SUN_STAR_VIEW_XSELECTIONSUPPLIER_HPP_
#include <com/sun/star/view/XSelectionSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SCRIPT_XEVENTATTACHERMANAGER_HPP_
#include <com/sun/star/script/XEventAttacherManager.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XBOUNDCONTROL_HPP_
#include <com/sun/star/form/XBoundControl.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XRESET_HPP_
#include <com/sun/star/form/XReset.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XGRID_HPP_
#include <com/sun/star/form/XGrid.hpp>
#endif
#ifndef _COM_SUN_STAR_FORM_XGRIDPEER_HPP_
#include <com/sun/star/form/XGridPeer.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
#include <com/sun/star/util/XNumberFormatter.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XMODESELECTOR_HPP_
#include <com/sun/star/util/XModeSelector.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XMODIFYBROADCASTER_HPP_
#include <com/sun/star/util/XModifyBroadcaster.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XCANCELLABLE_HPP_
#include <com/sun/star/util/XCancellable.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
#include <com/sun/star/beans/PropertyAttribute.hpp>
#endif
#ifndef _SVX_FMGLOB_HXX
#include <fmglob.hxx>
#endif
#ifndef _SVDITER_HXX //autogen
#include <svditer.hxx>
#endif
#ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx>
#endif
#ifndef _SFXVIEWSH_HXX //autogen wg. SfxViewShell
#include <sfx2/viewsh.hxx>
#endif
#ifndef _SFXVIEWFRM_HXX //autogen wg. SfxViewFrame
#include <sfx2/viewfrm.hxx>
#endif
#ifndef _SFXFRAME_HXX //autogen wg. SfxFrame
#include <sfx2/frame.hxx>
#endif
#ifndef _SVX_FMSERVS_HXX
#include "fmservs.hxx"
#endif // _SVX_FMSERVS_HXX
#ifndef _TOOLS_COLOR_HXX
#include <tools/color.hxx>
#endif
#ifndef _SVX_FMUNOPGE_HXX
#include "fmpgeimp.hxx"
#endif
#ifndef _SVX_FMTOOLS_HXX
#include "fmtools.hxx"
#endif
#ifndef _SVX_FMPROP_HRC
#include "fmprop.hrc"
#endif
#ifndef _SVX_FMSHELL_HXX
#include "fmshell.hxx"
#endif
#ifndef _SVX_SVXIDS_HRC
#include "svxids.hrc"
#endif
#ifndef _SVX_FMMODEL_HXX
#include "fmmodel.hxx"
#endif
#ifndef _SVX_FMUNDO_HXX
#include "fmundo.hxx"
#endif
#ifndef _SVX_FMURL_HXX
#include "fmurl.hxx"
#endif
#ifndef _URLOBJ_HXX //autogen wg. INetURLObject
#include <tools/urlobj.hxx>
#endif
#ifndef _COMPHELPER_PROPERTY_HXX_
#include <comphelper/property.hxx>
#endif
#ifndef _CONNECTIVITY_DBTOOLS_HXX_
#include <connectivity/dbtools.hxx>
#endif
#ifndef _COMPHELPER_GUARDING_HXX_
#include <comphelper/guarding.hxx>
#endif
#ifndef _COMPHELPER_STLTYPES_HXX_
#include <comphelper/stl_types.hxx>
#endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif
#ifndef _CPPUHELPER_SERVICEFACTORY_HXX_
#include <cppuhelper/servicefactory.hxx>
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
#endif
extern sal_Int16 ControllerSlotMap[];
extern sal_Int16 AutoSlotMap[];
// wird fuer Invalidate verwendet -> mitpflegen
extern sal_uInt16 DatabaseSlotMap[];
// wird fuer Invalidate verwendet -> mitpflegen
// aufsteigend sortieren !!!!!!
sal_Int16 DlgSlotMap[] = // slots des Controllers
{
SID_FM_CTL_PROPERTIES,
SID_FM_PROPERTIES,
SID_FM_TAB_DIALOG,
SID_FM_ADD_FIELD,
SID_FM_SHOW_FMEXPLORER,
SID_FM_FIELDS_CONTROL,
SID_FM_SHOW_PROPERTIES,
SID_FM_PROPERTY_CONTROL,
SID_FM_FMEXPLORER_CONTROL,
0
};
sal_uInt16 ModifySlotMap[] = // slots des Controllers
{
SID_FM_RECORD_NEXT,
SID_FM_RECORD_NEW,
SID_FM_RECORD_SAVE,
SID_FM_RECORD_UNDO,
0
};
sal_Int16 SelObjectSlotMap[] = // vom SelObject abhaengige Slots
{
SID_FM_CONVERTTO_EDIT,
SID_FM_CONVERTTO_BUTTON,
SID_FM_CONVERTTO_FIXEDTEXT,
SID_FM_CONVERTTO_LISTBOX,
SID_FM_CONVERTTO_CHECKBOX,
SID_FM_CONVERTTO_RADIOBUTTON,
SID_FM_CONVERTTO_GROUPBOX,
SID_FM_CONVERTTO_COMBOBOX,
SID_FM_CONVERTTO_GRID,
SID_FM_CONVERTTO_IMAGEBUTTON,
SID_FM_CONVERTTO_FILECONTROL,
SID_FM_CONVERTTO_DATE,
SID_FM_CONVERTTO_TIME,
SID_FM_CONVERTTO_NUMERIC,
SID_FM_CONVERTTO_CURRENCY,
SID_FM_CONVERTTO_PATTERN,
SID_FM_CONVERTTO_IMAGECONTROL,
SID_FM_CONVERTTO_FORMATTED,
SID_FM_FMEXPLORER_CONTROL,
0
};
// die folgenden Arrays muessen kosistent sein, also einander entsprechende Eintraege an der selben relativen Position
// innerhalb ihres jeweiligen Arrays stehen
sal_Int16 nConvertSlots[] =
{
SID_FM_CONVERTTO_EDIT,
SID_FM_CONVERTTO_BUTTON,
SID_FM_CONVERTTO_FIXEDTEXT,
SID_FM_CONVERTTO_LISTBOX,
SID_FM_CONVERTTO_CHECKBOX,
SID_FM_CONVERTTO_RADIOBUTTON,
SID_FM_CONVERTTO_GROUPBOX,
SID_FM_CONVERTTO_COMBOBOX,
SID_FM_CONVERTTO_GRID,
SID_FM_CONVERTTO_IMAGEBUTTON,
SID_FM_CONVERTTO_FILECONTROL,
SID_FM_CONVERTTO_DATE,
SID_FM_CONVERTTO_TIME,
SID_FM_CONVERTTO_NUMERIC,
SID_FM_CONVERTTO_CURRENCY,
SID_FM_CONVERTTO_PATTERN,
SID_FM_CONVERTTO_IMAGECONTROL,
SID_FM_CONVERTTO_FORMATTED
};
sal_Int16 nCreateSlots[] =
{
SID_FM_EDIT,
SID_FM_PUSHBUTTON,
SID_FM_FIXEDTEXT,
SID_FM_LISTBOX,
SID_FM_CHECKBOX,
SID_FM_RADIOBUTTON,
SID_FM_GROUPBOX,
SID_FM_COMBOBOX,
SID_FM_DBGRID,
SID_FM_IMAGEBUTTON,
SID_FM_FILECONTROL,
SID_FM_DATEFIELD,
SID_FM_TIMEFIELD,
SID_FM_NUMERICFIELD,
SID_FM_CURRENCYFIELD,
SID_FM_PATTERNFIELD,
SID_FM_IMAGECONTROL,
SID_FM_FORMATTEDFIELD
};
sal_Int16 nObjectTypes[] =
{
OBJ_FM_EDIT,
OBJ_FM_BUTTON,
OBJ_FM_FIXEDTEXT,
OBJ_FM_LISTBOX,
OBJ_FM_CHECKBOX,
OBJ_FM_RADIOBUTTON,
OBJ_FM_GROUPBOX,
OBJ_FM_COMBOBOX,
OBJ_FM_GRID,
OBJ_FM_IMAGEBUTTON,
OBJ_FM_FILECONTROL,
OBJ_FM_DATEFIELD,
OBJ_FM_TIMEFIELD,
OBJ_FM_NUMERICFIELD,
OBJ_FM_CURRENCYFIELD,
OBJ_FM_PATTERNFIELD,
OBJ_FM_IMAGECONTROL,
OBJ_FM_FORMATTEDFIELD
};
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::sdb;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::form;
using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::util;
using namespace ::svxform;
//------------------------------------------------------------------------------
sal_Bool FmXBoundFormFieldIterator::ShouldStepInto(const Reference< XInterface>& _rContainer) const
{
if (_rContainer == m_xStartingPoint)
// would be quite stupid to step over the root ....
return sal_True;
return Reference< XControlModel>(_rContainer, UNO_QUERY).is();
}
//------------------------------------------------------------------------------
sal_Bool FmXBoundFormFieldIterator::ShouldHandleElement(const Reference< XInterface>& _rElement)
{
if (!_rElement.is())
// NULL element
return sal_False;
if (Reference< XForm>(_rElement, UNO_QUERY).is() || Reference< XGrid>(_rElement, UNO_QUERY).is())
// a forms or a grid
return sal_False;
Reference< XPropertySet> xSet(_rElement, UNO_QUERY);
if (!xSet.is() || !::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xSet))
// no "BoundField" property
return sal_False;
Any aVal( xSet->getPropertyValue(FM_PROP_BOUNDFIELD) );
if (aVal.getValueTypeClass() != TypeClass_INTERFACE)
// void or invalid property value
return sal_False;
return aVal.hasValue();
}
//==============================================================================
DECL_CURSOR_ACTION_THREAD(FmMoveToLastThread);
IMPL_CURSOR_ACTION_THREAD(FmMoveToLastThread, SVX_RES(RID_STR_MOVING_CURSOR), last());
//------------------------------------------------------------------------------
sal_Bool isControlList(const SdrMarkList& rMarkList)
{
// enthaelt die liste nur Controls und mindestens ein control
sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
sal_Bool bControlList = nMarkCount != 0;
sal_Bool bHadAnyLeafs = sal_False;
for (sal_uInt32 i = 0; i < nMarkCount && bControlList; i++)
{
SdrObject *pObj = rMarkList.GetMark(i)->GetObj();
E3dObject* pAs3DObject = PTR_CAST(E3dObject, pObj);
// E3dObject's do not contain any 2D-objects (by definition)
// we need this extra check here : an E3dObject->IsGroupObject says "YES", but an SdrObjListIter working
// with an E3dObject doesn't give me any Nodes (E3dObject has a sub list, but no members in that list,
// cause there implementation differs from the one of "normal" SdrObject's. Unfortunally SdrObject::IsGroupObject
// doesn't check the element count of the sub list, which is simply a bug in IsGroupObject we can't fix at the moment).
// So at the end of this function bControlList would have the same value it was initialized with above : sal_True
// And this would be wrong :)
// 03.02.00 - 72529 - FS
if (!pAs3DObject)
if (pObj->IsGroupObject())
{
SdrObjListIter aIter(*pObj->GetSubList());
while (aIter.IsMore() && bControlList)
{
bControlList = FmFormInventor == aIter.Next()->GetObjInventor();
bHadAnyLeafs = sal_True;
}
}
else
{
bHadAnyLeafs = sal_True;
bControlList = FmFormInventor == pObj->GetObjInventor();
}
}
return bControlList && bHadAnyLeafs;
}
//------------------------------------------------------------------------
Reference< XForm> GetForm(const Reference< XInterface>& xElement)
{
Reference< XChild> xChild(xElement, UNO_QUERY);
Reference< XInterface> xParent;
if (xChild.is())
xParent = xChild->getParent();
Reference< XForm> xForm(xParent, UNO_QUERY);
if (!xForm.is() && xParent.is())
xForm = GetForm(xParent);
return xForm;
}
//------------------------------------------------------------------------
Reference< XForm> GetForm(const FmFormObj* pObj)
{
Reference< XForm> xForm;
if (pObj)
{
Reference< XFormComponent> xFormComponent(pObj->GetUnoControlModel(), UNO_QUERY);
if (xFormComponent.is())
xForm = Reference< XForm>(xFormComponent->getParent(), UNO_QUERY);
}
return xForm;
}
//------------------------------------------------------------------------
Reference< XForm> FmXFormShell::DetermineCurForm(const SdrMarkList& rMarkList, sal_Bool& bMixedWithFormControls)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// gibt es eine aktuelle Form, wird ermittelt aus den selektierten Objekten
Reference< XForm> xReferenceForm;
bMixedWithFormControls = sal_False;
sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
sal_Bool bHasFormControls = sal_False;
sal_Bool bHasForeignControls = sal_False;
Reference< XForm> xForm;
for (sal_uInt32 i=0; i<nMarkCount; i++)
{
SdrObject* pObj = rMarkList.GetMark(i)->GetObj();
if (pObj->GetObjInventor() == FmFormInventor)
{
FmFormObj* pFormObj = PTR_CAST(FmFormObj, pObj);
xForm = GetForm(pFormObj);
if (!xReferenceForm.is())
{
xReferenceForm = xForm;
bHasFormControls = sal_True;
}
else if (xForm.is() && (XForm*)xReferenceForm.get() != (XForm*)xForm.get())
{
// mehr als eine Form selektiert
bMixedWithFormControls = sal_True;
return Reference< XForm>();
}
}
else if (pObj->IsGroupObject())
{
SdrObjListIter aIter(*pObj->GetSubList());
while (aIter.IsMore())
{
SdrObject* pObj = aIter.Next();
if (pObj->GetObjInventor() == FmFormInventor)
{
FmFormObj* pFormObj = PTR_CAST(FmFormObj, pObj);
xForm = GetForm(pFormObj);
if (!xReferenceForm.is())
{
xReferenceForm = xForm;
bHasFormControls = sal_True;
}
else if (xForm.is() && (XForm*)xReferenceForm.get() != (XForm*)xForm.get())
{
// mehr als eine Form selektiert
bMixedWithFormControls = sal_True;
return Reference< XForm>();
}
} else
// irgendein Nicht-Form-Control
bHasForeignControls = sal_True;
}
} else
bHasForeignControls = sal_True;
}
// hierher komme ich nicht mehr, wenn Controls aus mindestens zwei Forms selektiert sind, also ermittelt sich
// bMixedWithFormControls wie folgt
bMixedWithFormControls = bHasForeignControls && bHasFormControls;
return xReferenceForm;
}
//========================================================================
// class FmXFormShell_Base_Disambiguation
//========================================================================
FmXFormShell_Base_Disambiguation::FmXFormShell_Base_Disambiguation( ::osl::Mutex& _rMutex )
:FmXFormShell_BD_BASE( _rMutex )
{
}
void SAL_CALL FmXFormShell_Base_Disambiguation::disposing()
{
WeakComponentImplHelperBase::disposing();
// Note:
// This is a HACK.
// Normally it should be sufficient to call the "disposing" of our direct
// base class, but SUN PRO 5 does not like this and claims there is a conflict
// with the XEventListener::disposing(EventObject) of our various listener
// base classes.
}
//========================================================================
// class FmXFormShell
//========================================================================
DBG_NAME(FmXFormShell);
//------------------------------------------------------------------------
FmXFormShell::FmXFormShell( FmFormShell* _pShell, SfxViewFrame* _pViewFrame )
:FmXFormShell_BASE(m_aMutex)
,FmXFormShell_CFGBASE(::rtl::OUString::createFromAscii("Office.Common/Misc"), CONFIG_MODE_DELAYED_UPDATE)
,m_pShell(_pShell)
,m_bDatabaseBar(sal_False)
,m_eNavigate(NavigationBarMode_NONE)
,m_bActiveModified(sal_False)
,m_bTrackProperties(sal_True)
,m_bInActivate(sal_False)
,m_bSetFocus(sal_False)
,m_nLockSlotInvalidation(0)
,m_nInvalidationEvent(0)
,m_bFilterMode(sal_False)
,m_bHadPropBrw(sal_False)
,m_pMainFrameInterceptor(NULL)
,m_pExternalViewInterceptor(NULL)
,m_bChangingDesignMode(sal_False)
,m_bUseWizards(sal_True)
,m_bPreparedClose( sal_False )
{
DBG_CTOR(FmXFormShell,NULL);
m_aMarkTimer.SetTimeout(100);
m_aMarkTimer.SetTimeoutHdl(LINK(this,FmXFormShell,OnTimeOut));
// we are a DispatchInterceptor, so we want to be inserted into the frame's dispatch chain, thus having
// a chance for frame-spanning communication (via UNO, not slots)
SfxFrame* pFrame = _pViewFrame ? _pViewFrame->GetFrame() : NULL;
Reference< ::com::sun::star::frame::XFrame> xUnoFrame;
if( pFrame)
xUnoFrame = pFrame->GetFrameInterface();
else
xUnoFrame = Reference< ::com::sun::star::frame::XFrame>(NULL);
// to prevent deletion of this we acquire our refcounter once
::comphelper::increment(FmXFormShell_BASE::m_refCount);
// dispatch interception for the frame
Reference< ::com::sun::star::frame::XDispatchProviderInterception> xSupplier(xUnoFrame, UNO_QUERY);
::rtl::OUString sInterceptorScheme = FMURL_FORMSLOTS_PREFIX;
sInterceptorScheme += ::rtl::OUString::createFromAscii("*");
m_pMainFrameInterceptor = new FmXDispatchInterceptorImpl(xSupplier, this, 0, Sequence< ::rtl::OUString >(&sInterceptorScheme, 1));
m_pMainFrameInterceptor->acquire();
m_xAttachedFrame = xUnoFrame;
// correct the refcounter
::comphelper::decrement(FmXFormShell_BASE::m_refCount);
// cache the current configuration settings we're interested in
implAdjustConfigCache();
// and register for changes on this settings
Sequence< ::rtl::OUString > aNames(1);
aNames[0] = ::rtl::OUString::createFromAscii("FormControlPilotsEnabled");
EnableNotification(aNames);
}
//------------------------------------------------------------------------
FmXFormShell::~FmXFormShell()
{
DBG_DTOR(FmXFormShell,NULL);
}
//------------------------------------------------------------------
Any SAL_CALL FmXFormShell::queryInterface( const Type& type) throw ( RuntimeException )
{
return FmXFormShell_BASE::queryInterface(type);
}
//------------------------------------------------------------------------------
Sequence< Type > SAL_CALL FmXFormShell::getTypes( ) throw(RuntimeException)
{
return FmXFormShell_BASE::getTypes();
}
//------------------------------------------------------------------------------
Sequence< sal_Int8 > SAL_CALL FmXFormShell::getImplementationId() throw(RuntimeException)
{
return ::form::OImplementationIds::getImplementationId(getTypes());
}
// EventListener
//------------------------------------------------------------------------------
void SAL_CALL FmXFormShell::disposing(const EventObject& e) throw( RuntimeException )
{
if (m_xActiveController == e.Source)
{
// wird der Controller freigeben dann alles loslassen
stopListening();
m_xActiveForm = NULL;
m_xActiveController = NULL;
m_xNavigationController = NULL;
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
}
if (e.Source == m_xExternalViewController)
{
Reference< XFormController> xFormController(m_xExternalViewController, UNO_QUERY);
if (xFormController.is())
xFormController->removeActivateListener((XFormControllerListener*)this);
Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
if (xComp.is())
xComp->removeEventListener((XEventListener*)(XPropertyChangeListener*)this);
m_xExternalViewController = NULL;
m_xExternalDisplayedForm = NULL;
m_xExtViewTriggerController = NULL;
InvalidateSlot(SID_FM_VIEW_AS_GRID, sal_True, sal_False);
}
}
//------------------------------------------------------------------------------
void SAL_CALL FmXFormShell::propertyChange(const PropertyChangeEvent& evt) throw(::com::sun::star::uno::RuntimeException)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (evt.PropertyName == FM_PROP_ISMODIFIED)
{
m_bPreparedClose = sal_False;
// the "modification state" of the current for changed -> the next PrepareClose call
// must do the full check
if (!::comphelper::getBOOL(evt.NewValue))
m_bActiveModified = sal_False;
}
else if (evt.PropertyName == FM_PROP_ISNEW)
{
if (!::comphelper::getBOOL(evt.NewValue))
m_bActiveModified = sal_False;
}
else if (evt.PropertyName == FM_PROP_ROWCOUNT)
{
// Das gleich folgenden Update erzwingt ein Neu-Painten der entsprechenden Slots. Wenn ich mich aber hier nicht
// in dem HauptThread der Applikation befinde (weil zum Beispiel ein Cursor gerade Datensaetze zaehlt und mir dabei
// immer diese PropertyChanges beschert), kann sich das mit en normalen Paints im HauptThread der Applikation beissen.
// (Solche Paints passieren zum Beispiel, wenn man einfach nur eine andere Applikation ueber das Office legt und wieder
// zurueckschaltet).
// Deshalb die Benutzung des SolarMutex, der sichert das ab.
::vos::IMutex& rSolarSafety = Application::GetSolarMutex();
if (rSolarSafety.tryToAcquire())
{
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(SID_FM_RECORD_TOTAL , sal_True, sal_False);
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(SID_FM_RECORD_TOTAL);
rSolarSafety.release();
}
else
{
// with the following the slot is invalidated asynchron
LockSlotInvalidation(sal_True);
InvalidateSlot(SID_FM_RECORD_TOTAL , sal_True, sal_False);
LockSlotInvalidation(sal_False);
}
}
else if (m_xParser.is())
{
try
{
if (evt.PropertyName == FM_PROP_ACTIVECOMMAND)
m_xParser->setQuery(::comphelper::getString(evt.NewValue));
else if (evt.PropertyName == FM_PROP_FILTER_CRITERIA)
{
if (m_xParser->getFilter() != ::comphelper::getString(evt.NewValue))
m_xParser->setFilter(::comphelper::getString(evt.NewValue));
}
else if (evt.PropertyName == FM_PROP_SORT)
{
if (m_xParser->getOrder() != ::comphelper::getString(evt.NewValue))
m_xParser->setOrder(::comphelper::getString(evt.NewValue));
}
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::propertyChange: Exception occured!");
}
}
// this may be called from a non-main-thread so invalidate the shell asynchronously
LockSlotInvalidation(sal_True);
InvalidateSlot(0, 0, 0); // special meaning : invalidate m_pShell
LockSlotInvalidation(sal_False);
}
// XModifyListener
//------------------------------------------------------------------------------
void SAL_CALL FmXFormShell::modified(const EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (!m_bActiveModified)
{
m_bActiveModified = sal_True;
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(ModifySlotMap);
m_bPreparedClose = sal_False;
// the "modification state" of the current for changed -> the next PrepareClose call
// must do the full check
}
}
//------------------------------------------------------------------------------
Reference< ::com::sun::star::frame::XDispatch> FmXFormShell::interceptedQueryDispatch(sal_uInt16 _nId, const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aAsyncSafety);
if (!m_pShell)
return Reference< ::com::sun::star::frame::XDispatch>();
// if we have no shell we are disposed, so we disposed all our dispatchers, too, so there is no need to supply a dispatcher
// (and no possibility : without our shell, methods like GetPageForms won't work properly)
// check if it is one of the form navigation urls
static ::rtl::OUString sFormNavUrls[] = {
FMURL_RECORD_MOVEFIRST,
FMURL_RECORD_MOVEPREV,
FMURL_RECORD_MOVENEXT,
FMURL_RECORD_MOVELAST,
FMURL_RECORD_MOVETONEW,
FMURL_RECORD_UNDO
};
static sal_Int16 nAccordingSlots[] = {
SID_FM_RECORD_FIRST,
SID_FM_RECORD_PREV,
SID_FM_RECORD_NEXT,
SID_FM_RECORD_LAST,
SID_FM_RECORD_NEW,
SID_FM_RECORD_UNDO
};
::rtl::OUString sMark;
UniString sAccessPath,sExternalCheck,sPageId;
for (sal_Int16 i=0; i<sizeof(sFormNavUrls)/sizeof(sFormNavUrls[0]); ++i)
{
if (aURL.Main.equals(sFormNavUrls[i]))
{
sMark = aURL.Mark;
DBG_ASSERT(sMark.getLength(), "FmXFormShell::queryDispatch : invalid URL !");
// form navigation slots should always have a mark describing their form model's access paths (FmXFormController builds such a mark)
sAccessPath = sMark.getStr();
// check if it comes from our external form grid view
String sComponentName = (::rtl::OUString)FMURL_COMPONENT_FORMGRIDVIEW;
sExternalCheck = sComponentName;
INetURLObject aExternalCheck(sExternalCheck);
if (String(aExternalCheck.GetURLPath()) == sAccessPath)
{ // it comes from the external dispatcher
// -> correct the access path
DBG_ASSERT(m_xExternalDisplayedForm.is() && m_xExternalViewController.is(),
"FmXFormShell::queryDispatch : where did this dispatch request come from ?");
sAccessPath = GetAccessPathFromForm(m_xExternalDisplayedForm, GetPageId(m_xExternalDisplayedForm));
sMark = sAccessPath;
DBG_ASSERT(_nId == 1, "FmXFormShell::queryDispatch : where did this came from ?");
// the FmXDispatchInterceptorImpl which forwarded this request should be m_pExternalViewInterceptor, and this interceptor
// should have ID 1 ...
}
#if DBG_UTIL
else
{
DBG_ASSERT(_nId == 0, "FmXFormShell::queryDispatch : where did this came from ?");
// the FmXDispatchInterceptorImpl which forwarded this request should be m_pMainFrameInterceptor, and this interceptor
// should have ID 0 ...
}
#endif
// get the form the dispatcher is requested for
// first the page id
String sOriginalPathWithPagePrefix = sAccessPath;
xub_StrLen nSepPos = sAccessPath.Search('\\');
DBG_ASSERT(nSepPos != STRING_NOTFOUND, "FmXFormShell::queryDispatch : invalid URL mark (no page prefix) !");
sPageId = sAccessPath.Copy(0, nSepPos);
sAccessPath = sAccessPath.Copy(nSepPos + 1, STRING_LEN);
// from this id the forms collection and the form
Reference< XIndexAccess> xPageForms(GetPageForms(sPageId), UNO_QUERY);
Reference< XResultSet> xAffectedForm(getElementFromAccessPath(xPageForms, UniString(sAccessPath)), UNO_QUERY);
DBG_ASSERT(xAffectedForm.is(), "FmXFormShell::queryDispatch : could not retrieve a form for the request !");
Reference< XPropertySet> xFormProps(xAffectedForm, UNO_QUERY);
NavigationBarMode eMode = NavigationBarMode_CURRENT;
if ( !xFormProps.is()
|| !( xFormProps->getPropertyValue( FM_PROP_NAVIGATION ) >>= eMode )
|| ( NavigationBarMode_CURRENT != eMode )
)
{ // we can't supply a dispatcher for that : else we would have to listen to all operations on the parent
// form and to all ops on the affected form itself, just to keep the state up-to-date. This would be too much to do ...
// 73233 - 22.02.00 - FS
return Reference< ::com::sun::star::frame::XDispatch>();
}
// get the dispatcher array for the form
SingleFormDispatchers& aDispatchers = m_aNavigationDispatcher[sMark];
// the [] operator will create a new one if it didn't exist before
if (!aDispatchers.size())
{ // it was a new one -> fill it with initial NULL values
for (sal_Int16 j=0; j<sizeof(sFormNavUrls)/sizeof(sFormNavUrls[0]); ++j)
aDispatchers.insert(aDispatchers.begin(), (FmFormNavigationDispatcher*)NULL);
}
FmFormNavigationDispatcher*& pRequestedDispatcher = aDispatchers[i];
if (!pRequestedDispatcher)
{
// nobody requested a dispatcher for this form and this slot before -> create a new one
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().DENTERREGISTRATIONS();
pRequestedDispatcher = new FmFormNavigationDispatcher(aURL, nAccordingSlots[i], m_pShell->GetViewShell()->GetViewFrame()->GetBindings(), xAffectedForm, sOriginalPathWithPagePrefix);
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().DLEAVEREGISTRATIONS();
DBG_ASSERT(((sPageId += '\\') += sAccessPath) == GetAccessPathFromForm(xAffectedForm, GetPageId(xAffectedForm)),
"FmXFormShell::queryDispatch : hmmm ... what does this access path mean ?");
pRequestedDispatcher->acquire();
pRequestedDispatcher->setExecutor(LINK(this, FmXFormShell, OnExecuteNavSlot));
}
Reference< XResultSet> xNavigationForm;
if (m_xNavigationController.is())
xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
// xNavigationForm is the form which our navigation bar belongs to
// activate the new dispatcher if (and only if) it belongs to the same form
if (xAffectedForm == xNavigationForm)
{
pRequestedDispatcher->SetActive(sal_True);
}
else
{
pRequestedDispatcher->SetActive(sal_False);
UpdateFormDispatcher(pRequestedDispatcher);
}
return (::com::sun::star::frame::XDispatch*)pRequestedDispatcher;
}
}
return Reference< ::com::sun::star::frame::XDispatch>();
}
//------------------------------------------------------------------------------
void SAL_CALL FmXFormShell::formActivated(const EventObject& rEvent) throw( RuntimeException )
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(rEvent.Source == m_xExternalViewController, "FmXFormShell::formActivated : where did this come from ?");
setActiveController(Reference< XFormController>(rEvent.Source, UNO_QUERY));
}
//------------------------------------------------------------------------------
void SAL_CALL FmXFormShell::formDeactivated(const EventObject& rEvent) throw( RuntimeException )
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(rEvent.Source == m_xExternalViewController, "FmXFormShell::formDeactivated : where did this come from ?");
}
//------------------------------------------------------------------------------
void FmXFormShell::disposing()
{
FmXFormShell_BASE::disposing();
if ( m_pShell && !m_pShell->IsDesignMode() )
setActiveController( NULL, sal_True );
// do NOT save the content of the old form (the second parameter tells this)
// if we're here, then we expect that PrepareClose has been called, and thus the user
// got a chance to commit or reject any changes. So in case we're here and the there
// are still uncommitted changes, the user explicitly wanted this.
// 2002-11-11 - 104702 - fs@openoffice.org
// dispose our interceptor helpers
if (m_pMainFrameInterceptor)
{
m_pMainFrameInterceptor->dispose();
m_pMainFrameInterceptor->release();
m_pMainFrameInterceptor = NULL;
}
if (m_pExternalViewInterceptor)
{
m_pExternalViewInterceptor->dispose();
m_pExternalViewInterceptor->release();
m_pExternalViewInterceptor = NULL;
}
m_xAttachedFrame = NULL;
CloseExternalFormViewer();
while ( m_aLoadingPages.size() )
{
Application::RemoveUserEvent( m_aLoadingPages.front().nEventId );
m_aLoadingPages.pop();
}
// dispose all our navigation dispatchers
for ( FormsDispatchersIterator aFormIter = m_aNavigationDispatcher.begin();
aFormIter != m_aNavigationDispatcher.end();
++aFormIter
)
{
for ( SingleFormDispatchersIterator aDispIter = (*aFormIter).second.begin();
aDispIter < (*aFormIter).second.end();
++aDispIter
)
{
FmFormNavigationDispatcher* pCurDispatcher = *aDispIter;
if (pCurDispatcher)
{
pCurDispatcher->dispose();
pCurDispatcher->release();
*aDispIter = NULL;
}
}
}
m_aNavigationDispatcher.clear();
{
::osl::MutexGuard aGuard(m_aInvalidationSafety);
if (m_nInvalidationEvent)
{
Application::RemoveUserEvent(m_nInvalidationEvent);
m_nInvalidationEvent = 0;
}
}
{
::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
if (HasAnyPendingCursorAction())
CancelAnyPendingCursorAction();
aGuard.clear();
DBG_ASSERT(!m_nInvalidationEvent, "FmXFormShell::~FmXFormShell : still have an invalidation event !");
// should habe been deleted while beeing disposed
m_aMarkTimer.Stop();
}
// we are disposed from within the destructor of our shell, so now the shell pointer is invalid ....
m_pShell = NULL;
m_xActiveController = NULL;
m_xNavigationController = NULL;
m_xActiveForm = NULL;
m_xParser = NULL;
m_xForms = NULL;
m_xSelObject = NULL;
m_xCurControl = NULL;
m_xCurForm = NULL;
m_xLastGridFound = NULL;
m_xAttachedFrame = NULL;
m_xExternalViewController = NULL;
m_xExtViewTriggerController = NULL;
m_xExternalDisplayedForm = NULL;
m_xLastGridFound = NULL;
}
//------------------------------------------------------------------------------
void FmXFormShell::InvalidateSlot(sal_Int16 nId, sal_Bool bWithItem, sal_Bool bWithId)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aInvalidationSafety);
if (m_nLockSlotInvalidation)
{
m_arrInvalidSlots.Insert(nId, m_arrInvalidSlots.Count());
BYTE nFlags = (bWithItem ? 0x02 :0) + (bWithId ? 0x01 : 0);
m_arrInvalidSlots_Flags.Insert(nFlags, m_arrInvalidSlots_Flags.Count());
}
else
if (nId)
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(nId, bWithItem, bWithId);
else
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
}
//------------------------------------------------------------------------------
void FmXFormShell::LockSlotInvalidation(sal_Bool bLock)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aInvalidationSafety);
DBG_ASSERT(bLock || m_nLockSlotInvalidation>0, "FmXFormShell::LockSlotInvalidation : invalid call !");
if (bLock)
++m_nLockSlotInvalidation;
else if (!--m_nLockSlotInvalidation)
{
// alles, was sich waehrend der gelockten Phase angesammelt hat, (asynchron) invalidieren
if (!m_nInvalidationEvent)
m_nInvalidationEvent = Application::PostUserEvent(LINK(this, FmXFormShell, OnInvalidateSlots));
}
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnInvalidateSlots, void*, EMPTYARG)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aInvalidationSafety);
m_nInvalidationEvent = 0;
DBG_ASSERT(m_arrInvalidSlots.Count() == m_arrInvalidSlots_Flags.Count(),
"FmXFormShell::OnInvalidateSlots : inconsistent slot arrays !");
BYTE nFlags;
for (sal_Int16 i=0; i<m_arrInvalidSlots.Count(); ++i)
{
nFlags = m_arrInvalidSlots_Flags[i];
if (m_arrInvalidSlots[i])
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(m_arrInvalidSlots[i], (nFlags & 0x02), (nFlags & 0x01));
else
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
}
m_arrInvalidSlots.Remove(0, m_arrInvalidSlots.Count());
m_arrInvalidSlots_Flags.Remove(0, m_arrInvalidSlots_Flags.Count());
return 0L;
}
//------------------------------------------------------------------------------
void FmXFormShell::ForceUpdateSelection(sal_Bool bAllowInvalidation)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (IsSelectionUpdatePending())
{
m_aMarkTimer.Stop();
// die Invalidierung der Slots, die implizit von SetSelection besorgt wird, eventuell abschalten
if (!bAllowInvalidation)
LockSlotInvalidation(sal_True);
SetSelection(m_pShell->GetFormView()->GetMarkList());
if (!bAllowInvalidation)
LockSlotInvalidation(sal_False);
}
}
//------------------------------------------------------------------------------
PopupMenu* FmXFormShell::GetConversionMenu()
{
const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
BOOL bIsHiContrastMode = rSettings.GetMenuColor().IsDark();
PopupMenu* pNewMenu = new PopupMenu(SVX_RES( RID_FMSHELL_CONVERSIONMENU ));
ImageList aImageList( SVX_RES( bIsHiContrastMode ? RID_SVXIMGLIST_FMEXPL_HC : RID_SVXIMGLIST_FMEXPL) );
for (int i=0; i<sizeof(nConvertSlots)/sizeof(nConvertSlots[0]); ++i)
{
// das entsprechende Image dran
pNewMenu->SetItemImage(nConvertSlots[i], aImageList.GetImage(nCreateSlots[i]));
}
return pNewMenu;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::IsControlConversionSlot(sal_uInt16 nSlotId)
{
for (int i=0; i<sizeof(nConvertSlots)/sizeof(nConvertSlots[0]); ++i)
if (nConvertSlots[i] == nSlotId)
return sal_True;
return sal_False;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::ExecuteControlConversionSlot(const Reference< XFormComponent>& xContext, sal_uInt16 nSlotId)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
for (int i=0; i<sizeof(nConvertSlots)/sizeof(nConvertSlots[0]); ++i)
{
if (nConvertSlots[i] == nSlotId)
return ConvertControlTo(xContext, nObjectTypes[i]);
}
return sal_False;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::IsConversionPossible(const Reference< XPropertySet>& xContext, sal_Int16 nConversionSlot)
{
Reference< XServiceInfo> xInfo(xContext, UNO_QUERY);
if (!xInfo.is())
return sal_False;
sal_Int16 nObjectType = getControlTypeByObject(xInfo);
if ((OBJ_FM_HIDDEN == nObjectType) || (OBJ_FM_CONTROL == nObjectType) || (OBJ_FM_GRID == nObjectType))
return sal_False; // hiddens koennen nicht konvertiert werden
DBG_ASSERT(sizeof(nConvertSlots)/sizeof(nConvertSlots[0]) == sizeof(nObjectTypes)/sizeof(nObjectTypes[0]),
"FmXFormShell::IsConversionPossible : nConvertSlots & nObjectTypes must have the same size !");
for (sal_Int16 i=0; i<sizeof(nConvertSlots)/sizeof(nConvertSlots[0]); ++i)
if (nConvertSlots[i] == nConversionSlot)
return nObjectTypes[i] != nObjectType;
return sal_True; // alle anderen Slots nehmen wir als gueltig an
}
//------------------------------------------------------------------------------
void FmXFormShell::CheckControlConversionSlots(const Reference< XPropertySet>& xContext, Menu& rMenu)
{
for (sal_Int16 i=0; i<rMenu.GetItemCount(); ++i)
// der Context ist schon von einem Typ, der dem Eitnrag entspricht -> disable
rMenu.EnableItem(rMenu.GetItemId(i), IsConversionPossible(xContext, rMenu.GetItemId(i)));
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::ConvertControlTo(const Reference< XFormComponent>& xModel, sal_uInt16 nTargetObjectId)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (!xModel.is())
// das wuerde ausser einem Performance-Verlust nix machen, aber trotzdem ...
return sal_False;
FmFormPage* pCurrentPage = m_pShell->GetCurPage();
SdrUnoObj* pFound = NULL;
for (sal_uInt32 i=0; i<pCurrentPage->GetObjCount(); ++i)
{
SdrObject* pCurrent = pCurrentPage->GetObj(i);
// wenn das Ding eine Gruppierung ist -> durchiterieren
SdrObjListIter* pGroupIterator = NULL;
if (pCurrent->IsGroupObject())
{
pGroupIterator = new SdrObjListIter(*pCurrent->GetSubList());
pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
}
while (pCurrent)
{
if (pCurrent->IsUnoObj())
{
Reference< XFormComponent> xCurrent(((SdrUnoObj*)pCurrent)->GetUnoControlModel(), UNO_QUERY);
if ((XFormComponent*)xCurrent.get() == (XFormComponent*)xModel.get())
break;
}
if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls
pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
else
pCurrent = NULL;
}
delete pGroupIterator;
if (pCurrent)
{
pFound = (SdrUnoObj*)pCurrent;
break;
}
}
if (!pFound)
return sal_False;
::rtl::OUString uNewName(getServiceNameByControlType(nTargetObjectId));
Reference< XControlModel> xNewModel(::comphelper::getProcessServiceFactory()->createInstance(uNewName), UNO_QUERY);
if (!xNewModel.is())
return sal_False;
Reference< XControlModel> xOldModel(pFound->GetUnoControlModel());
Reference< XServiceInfo> xModelInfo(xOldModel, UNO_QUERY);
sal_Int16 nOldModelType = xModelInfo.is() ? getControlTypeByObject(xModelInfo) : OBJ_FM_CONTROL;
// Properties uebertragen
Reference< XPropertySet> xOldSet(xOldModel, UNO_QUERY);
Reference< XPropertySet> xNewSet(xNewModel, UNO_QUERY);
Locale aNewLanguage = Application::GetSettings().GetUILocale();
TransferFormComponentProperties(xOldSet, xNewSet, aNewLanguage);
Sequence< ::com::sun::star::script::ScriptEventDescriptor> aOldScripts;
Reference< XChild> xChild(xOldModel, UNO_QUERY);
if (xChild.is())
{
Reference< XIndexAccess> xParent(xChild->getParent(), UNO_QUERY);
// remember old script events
Reference< ::com::sun::star::script::XEventAttacherManager> xEvManager(xChild->getParent(), UNO_QUERY);
if (xParent.is() && xEvManager.is())
{
sal_Int32 nIndex = getElementPos(xParent, xOldModel);
if (nIndex>=0 && nIndex<xParent->getCount())
aOldScripts = xEvManager->getScriptEvents(nIndex);
}
// replace the mdoel within the parent container
Reference< XIndexContainer> xIndexParent(xChild->getParent(), UNO_QUERY); //Modified by BerryJia for fixing Bug102516 Time(China):2002-9-5 16:00
if (xIndexParent.is())
{
// the form container works with FormComponents
Reference< XFormComponent> xComponent(xNewModel, UNO_QUERY);
DBG_ASSERT(xComponent.is(), "FmXFormShell::ConvertControlTo : the new model is no form component !");
Any aNewModel(makeAny(xComponent));
try
{
//Modified by BerryJia for fixing Bug102516 Time(China):2002-9-5 16:00
sal_Int32 nIndex = getElementPos(xParent, xOldModel);
if (nIndex>=0 && nIndex<xParent->getCount())
xIndexParent->replaceByIndex(nIndex, aNewModel);
else
{
DBG_ERROR("FmXFormShell::ConvertControlTo : could not replace the model !");
Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
if (xNewComponent.is())
xNewComponent->dispose();
return sal_False;
}
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::ConvertControlTo : could not replace the model !");
Reference< ::com::sun::star::lang::XComponent> xNewComponent(xNewModel, UNO_QUERY);
if (xNewComponent.is())
xNewComponent->dispose();
return sal_False;
}
}
}
// special handling for the LabelControl-property : can only be set when the model is placed
// within the forms hierarchy
if (::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xOldSet) && ::comphelper::hasProperty(FM_PROP_CONTROLLABEL, xNewSet))
{
try
{
xNewSet->setPropertyValue(FM_PROP_CONTROLLABEL, xOldSet->getPropertyValue(FM_PROP_CONTROLLABEL));
}
catch(Exception&)
{
}
}
// neues Model setzen
pFound->SetChanged();
pFound->SetUnoControlModel(xNewModel);
// transfer script events
// (do this _after_ SetUnoControlModel as we need the new (implicitly created) control)
if (aOldScripts.getLength())
{
// das Control zum Model suchen
SdrPageView* pPageView = m_pShell->GetFormView()->GetPageViewPvNum(0);
DBG_ASSERT(pPageView->GetWinList().GetCount() > 0, "FmXFormShell::ConvertControlTo : no SdrPageViewWinRecs");
const SdrPageViewWinRec& rViewWinRec = pPageView->GetWinList()[0];
Reference< XControlContainer> xControlContainer(rViewWinRec.GetControlContainerRef());
Sequence< Reference< XControl> > aControls( xControlContainer->getControls() );
const Reference< XControl>* pControls = aControls.getConstArray();
sal_uInt32 nLen = aControls.getLength();
Reference< XControl> xControl;
for (sal_uInt32 i=0 ; i<nLen; ++i)
{
if (pControls[i]->getModel() == xNewModel)
{
xControl = pControls[i];
break;
}
}
TransferEventScripts(xNewModel, xControl, aOldScripts);
}
// create an undo action
FmFormModel* pModel = m_pShell->GetFormModel();
DBG_ASSERT(pModel != NULL, "FmXFormShell::ConvertControlTo : my shell has no model !");
if (pModel)
pModel->AddUndo(new FmUndoModelReplaceAction(*pModel, pFound, xOldModel));
return sal_True;
}
//------------------------------------------------------------------------------
void FmXFormShell::LoopGrids(sal_Int16 nWhat)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XIndexContainer> xControlModels(m_xActiveForm, UNO_QUERY);
if (xControlModels.is())
for (sal_Int16 i=0; i<xControlModels->getCount(); ++i)
{
Reference< XPropertySet> xModelSet;
xControlModels->getByIndex(i) >>= xModelSet;
if (!xModelSet.is())
continue;
if (!::comphelper::hasProperty(FM_PROP_CLASSID, xModelSet))
continue;
sal_Int16 nClassId = ::comphelper::getINT16(xModelSet->getPropertyValue(FM_PROP_CLASSID));
if (FormComponentType::GRIDCONTROL != nClassId)
continue;
if (!::comphelper::hasProperty(FM_PROP_CURSORCOLOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_ALWAYSSHOWCURSOR, xModelSet) || !::comphelper::hasProperty(FM_PROP_DISPLAYSYNCHRON, xModelSet))
continue;
switch (nWhat & GA_SYNC_MASK)
{
case GA_DISABLE_SYNC:
{
sal_Bool bB(sal_False);
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
}
break;
case GA_FORCE_SYNC:
{
Any aOldVal( xModelSet->getPropertyValue(FM_PROP_DISPLAYSYNCHRON) );
sal_Bool bB(sal_True);
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, aOldVal);
}
break;
case GA_ENABLE_SYNC:
{
sal_Bool bB(sal_True);
xModelSet->setPropertyValue(FM_PROP_DISPLAYSYNCHRON, Any(&bB,getBooleanCppuType()));
}
break;
}
if (nWhat & GA_DISABLE_ROCTRLR)
{
sal_Bool bB(sal_False);
xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
Reference< XPropertyState> xModelPropState(xModelSet, UNO_QUERY);
if (xModelPropState.is())
xModelPropState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
else
xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any()); // this should be the default
}
else if (nWhat & GA_ENABLE_ROCTRLR)
{
sal_Bool bB(sal_True);
xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, makeAny(sal_Int32(COL_LIGHTRED)));
}
}
/* // alle Controls der Page durchiterieren und nach GridControls suchen ...
SdrPageView* pCurPageView = m_pShell->GetFormView()->GetPageViewPvNum(0);
// deren ViewWinRec-Liste, daraus das erste Element
DBG_ASSERT(pCurPageView->GetWinList().GetCount() > 0, "FmXFormShell::LoopGrids : unexpected : no SdrPageViewWinRecs");
const SdrPageViewWinRec& rViewWinRec = pCurPageView->GetWinList()[0];
// von dem bekomme ich alle Controls ...
Reference< XControlContainer> xControlContainer( rViewWinRec.GetControlContainerRef());
Sequence< Reference< XControl> > seqControls = xControlContainer->getControls();
const Reference< XControl>* pControls = seqControls.getConstArray();
// ... die ich dann durchsuchen kann
for (int i=0; i<seqControls.getLength(); ++i)
{
Reference<XGridPeer> xGridPeer(pControls[i]->getPeer(), UNO_QUERY);
if (!xGridPeer.is())
continue;
FmXGridPeer* pPeer = (FmXGridPeer*)xGridPeer->getImplementation(FmXGridPeer_getReflection());
if (!pPeer)
continue;
FmGridControl* pGrid = (FmGridControl*)pPeer->GetWindow();
// what to do ?
// display synchronisation ?
switch (nWhat & GA_SYNC_MASK)
{
case GA_DISABLE_SYNC:
pGrid->setDisplaySynchron(sal_False); break;
case GA_FORCE_SYNC:
pGrid->forceSyncDisplay(); break;
case GA_ENABLE_SYNC:
pGrid->setDisplaySynchron(sal_True); break;
}
if (nWhat & GA_DISABLE_ROCTRLR)
pGrid->forceROController(sal_False);
else if (nWhat & GA_ENABLE_ROCTRLR)
pGrid->forceROController(sal_True);
}
*/
}
//------------------------------------------------------------------------------
void FmXFormShell::ExecuteSearch()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
UniString sTestContexts;
// m_arrSearchContexts.Remove(0, m_arrSearchContexts.Count());
m_arrSearchContexts.clear();
// eine Sammlung aller (logischen) Formulare
Reference< XInterface> xAllForms(m_pShell->GetCurPage()->GetForms(),UNO_QUERY);
// ::fml::convertIFace((XInterface*),xAllForms);
CollectFormContexts(xAllForms, String(), sTestContexts);
sTestContexts.EraseLeadingChars(';');
// hier sind jetzt dummerweise noch alle Forms drin, die ueberhaupt keine gueltigen Controls enthalten
// um das auszufiltern, benutze ich einfach meinen OnSearchContextRequest-Handler, der genau die gueltigen Controls einer Form sammelt
FmFormArray::reverse_iterator aIter = m_arrSearchContexts.rbegin();
sal_Int32 i = m_arrSearchContexts.size();
for (; aIter != m_arrSearchContexts.rend(); ++aIter,i--)
{
FmSearchContext fmscTest;
fmscTest.nContext = i-1;
sal_uInt32 lValidControls = LINK(this, FmXFormShell, OnSearchContextRequest).Call(&fmscTest);
if (lValidControls == 0)
{
m_arrSearchContexts.erase(aIter.base()-1);
sTestContexts.SetToken(i-1, ';', String());
}
}
// jetzt enthaelt die Context-Liste noch ein paar Leer-Token
UniString strRealContexts,strCurrentToken;
for (xub_StrLen j=0; j<sTestContexts.GetTokenCount(';'); ++j)
{
strCurrentToken = sTestContexts.GetToken(j);
if (strCurrentToken.Len() != 0)
{
strRealContexts += ';';
strRealContexts += strCurrentToken;
}
}
strRealContexts.EraseLeadingChars(';');
if (m_arrSearchContexts.size() == 0)
{ // es gibt keine Controls, die alle Bedingungen fuer eine Suche erfuellen
ErrorBox(NULL, WB_OK, SVX_RESSTR(RID_STR_NODATACONTROLS)).Execute();
return;
}
// jetzt brauche ich noch einen 'initial context'
sal_Int16 nInitialContext = 0;
Reference< XForm> xActiveForm( getActiveForm());
for (i=0; i<(sal_Int32)m_arrSearchContexts.size(); ++i)
{
if (m_arrSearchContexts.at(i) == xActiveForm)
{
nInitialContext = (sal_Int16)i;
break;
}
}
// wenn der Dialog initial den Text des aktiven Controls anbieten soll, muss dieses ein XTextComponent-Interface habe,
// ausserdem macht das nur Sinn, wenn das aktuelle Feld auch an ein Tabellen- (oder was-auch-immer-)Feld gebunden ist
UniString strActiveField;
UniString strInitialText;
// ... das bekomme ich von meinem FormController
DBG_ASSERT(m_xActiveController.is(), "FmXFormShell::ExecuteSearch : no active controller !");
Reference< XControl> xActiveControl( m_xActiveController->getCurrentControl());
if (xActiveControl.is())
{
// das Control kann mir sein Model sagen ...
Reference< XControlModel> xActiveModel( xActiveControl->getModel());
DBG_ASSERT(xActiveModel.is(), "FmXFormShell::ExecuteSearch : active control has no model !");
// das Model frage ich nach der ControlSource-Eigenschaft ...
Reference< XPropertySet> xProperties(xActiveControl->getModel(), UNO_QUERY);
if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
{
Reference< XPropertySet> xField;
xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
if (xField.is()) // (nur wenn das Ding wirklich gebunden ist)
{
// und das Control selber nach einem TextComponent-Interface (damit ich mir dort den Text abholen kann)
Reference< XTextComponent> xText(xActiveControl, UNO_QUERY);
if (xText.is())
{
strActiveField = getLabelName(xProperties).getStr();
strInitialText = xText->getText().getStr();
}
}
}
else
{
// das Control selber hat keine ControlSource, aber vielleicht ist es ein GridControl
Reference< XGrid> xGrid(xActiveControl, UNO_QUERY);
if (xGrid.is())
{
// fuer strActiveField brauche ich die die ControlSource der Column, dafuer den Columns-Container, dafuer die
// GridPeer
Reference< XGridPeer> xGridPeer(xActiveControl->getPeer(), UNO_QUERY);
Reference< XIndexAccess> xColumns;
if (xGridPeer.is())
xColumns = Reference< XIndexAccess>(xGridPeer->getColumns(),UNO_QUERY);
sal_Int16 nViewCol = xGrid->getCurrentColumnPosition();
sal_Int16 nModelCol = GridView2ModelPos(xColumns, nViewCol);
Reference< XPropertySet> xCurrentCol;
if(xColumns.is())
xColumns->getByIndex(nModelCol) >>= xCurrentCol;
if (xCurrentCol.is())
strActiveField = ::comphelper::getString(xCurrentCol->getPropertyValue(FM_PROP_LABEL)).getStr();
// the text fo the current column
Reference< XIndexAccess> xColControls(xGridPeer, UNO_QUERY);
Reference< XInterface> xCurControl;
xColControls->getByIndex(nViewCol) >>= xCurControl;
::rtl::OUString sInitialText;
if (IsSearchableControl(xCurControl, &sInitialText))
strInitialText = sInitialText.getStr();
}
}
}
// um eventuelle GridControls, die ich kenne, kuemmern
LoopGrids(GA_DISABLE_SYNC /*| GA_ENABLE_ROCTRLR*/);
// jetzt bin ich reif fuer den Dialog
FmSearchDialog dlg(&m_pShell->GetViewShell()->GetViewFrame()->GetWindow(), strInitialText, strRealContexts, nInitialContext, LINK(this, FmXFormShell, OnSearchContextRequest),
FmSearchDialog::SM_ALLOWSCHEDULE);
// wenn die potentiellen Deadlocks, die durch die Benutzung des Solar-Mutex in MTs VCLX...-Klasen entstehen, irgendwann mal
// ausgeraeumt sind, sollte hier ein SM_USETHREAD rein, denn die Suche in einem eigenen Thread ist doch etwas fluessiger
// sollte allerdings irgendwie von dem unterliegenden Cursor abhaengig gemacht werden, DAO zum Beispiel ist nicht thread-sicher
dlg.SetActiveField(strActiveField);
dlg.SetFoundHandler(LINK(this, FmXFormShell, OnFoundData));
dlg.SetCanceledNotFoundHdl(LINK(this, FmXFormShell, OnCanceledNotFound));
dlg.Execute();
// GridControls wieder restaurieren
LoopGrids(GA_ENABLE_SYNC | GA_DISABLE_ROCTRLR);
m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetPageViewPvNum(0));
// da ich in OnFoundData (fals ich dort war) Controls markiert habe
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::GetY2KState(sal_uInt16& n)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (m_pShell->IsDesignMode())
// im Design-Modus (ohne aktive Controls) soll sich das Haupt-Dokument darum kuemmern
return sal_False;
Reference< XForm> xForm( getActiveForm());
if (!xForm.is())
// kein aktuelles Formular (also insbesondere kein aktuelles Control) -> das Haupt-Dokument soll sich kuemmern
return sal_False;
Reference< XRowSet> xDB(xForm, UNO_QUERY);
DBG_ASSERT(xDB.is(), "FmXFormShell::GetY2KState : current form has no dbform-interface !");
Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(OStaticDataAccessTools().getRowSetConnection(xDB), sal_False));
if (xSupplier.is())
{
Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
if (xSet.is())
{
try
{
Any aVal( xSet->getPropertyValue(::rtl::OUString::createFromAscii("TwoDigitDateStart")) );
aVal >>= n;
return sal_True;
}
catch(Exception&)
{
}
}
}
return sal_False;
}
//------------------------------------------------------------------------------
void FmXFormShell::SetY2KState(sal_uInt16 n)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XForm> xActiveForm( getActiveForm());
Reference< XRowSet> xDB(xActiveForm, UNO_QUERY);
if (xDB.is())
{
Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(getRowSetConnection(xDB), sal_False));
if (xSupplier.is())
{
Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
if (xSet.is())
{
try
{
Any aVal;
aVal <<= n;
xSet->setPropertyValue(::rtl::OUString::createFromAscii("TwoDigitDateStart"), aVal);
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::SetY2KState: Exception occured!");
}
}
return;
}
}
// kein aktives Formular gefunden -> alle aktuell vorhandenen Formulare durchiterieren
Reference< XIndexAccess> xCurrentForms( m_xForms);
if (!xCurrentForms.is())
{ // im alive-Modus sind meine Forms nicht gesetzt, wohl aber die an der Page
if (m_pShell->GetCurPage())
xCurrentForms = Reference< XIndexAccess>(m_pShell->GetCurPage()->GetForms(), UNO_QUERY);
}
if (!xCurrentForms.is())
return;
::comphelper::IndexAccessIterator aIter(xCurrentForms);
Reference< XInterface> xCurrentElement( aIter.Next());
while (xCurrentElement.is())
{
// ist das aktuelle Element eine DatabaseForm ?
Reference< XRowSet> xDB(xCurrentElement, UNO_QUERY);
if (xDB.is())
{
Reference< XNumberFormatsSupplier> xSupplier( getNumberFormats(getRowSetConnection(xDB), sal_False));
if (!xSupplier.is())
continue;
Reference< XPropertySet> xSet(xSupplier->getNumberFormatSettings());
if (xSet.is())
{
try
{
Any aVal;
aVal <<= n;
xSet->setPropertyValue(::rtl::OUString::createFromAscii("TwoDigitDateStart"), aVal);
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::SetY2KState: Exception occured!");
}
}
}
xCurrentElement = aIter.Next();
}
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::CanMoveLeft(const Reference< XFormController>& xController)
{
if (!xController.is())
return sal_False;
Reference< XPropertySet> xSet(xController->getModel(), UNO_QUERY);
return CanMoveLeft(xSet);
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::CanMoveLeft(const Reference< XPropertySet>& _xControllerModel)
{
if (!_xControllerModel.is())
return sal_False;
Reference< XResultSet> xCursor(_xControllerModel, UNO_QUERY);
sal_Bool bIsNew = ::comphelper::getBOOL(_xControllerModel->getPropertyValue(FM_PROP_ISNEW));
sal_Int32 nCount = ::comphelper::getINT32(_xControllerModel->getPropertyValue(FM_PROP_ROWCOUNT));
return nCount && (!xCursor->isFirst() || bIsNew);
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::CanMoveRight(const Reference< XFormController>& xController)
{
if (!xController.is())
return sal_False;
Reference< XPropertySet> xSet(xController->getModel(), UNO_QUERY);
return CanMoveRight(xSet);
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::CanMoveRight(const Reference< XPropertySet>& _xControllerModel)
{
if (!_xControllerModel.is())
return sal_False;
Reference< XResultSet> xCursor(_xControllerModel, UNO_QUERY);
sal_Int32 nCount = ::comphelper::getINT32(_xControllerModel->getPropertyValue(FM_PROP_ROWCOUNT));
sal_Bool bIsModified = ::comphelper::getBOOL(_xControllerModel->getPropertyValue(FM_PROP_ISMODIFIED));
sal_Bool bIsNew = ::comphelper::getBOOL(_xControllerModel->getPropertyValue(FM_PROP_ISNEW));
sal_Bool bCanInsert = OStaticDataAccessTools().canInsert(_xControllerModel);
return (
( nCount
&& !xCursor->isLast()
&& !bIsNew
)
)
||
(
bCanInsert && (!bIsNew || bIsModified)
);
}
//------------------------------------------------------------------------
sal_Bool FmXFormShell::CommitCurrent(const Reference< XFormController>& _xController)
{
// mu noch ein Control commitet werden
Reference< XControl> xActiveControl(_xController->getCurrentControl());
Reference< XBoundControl> xLockingTest(xActiveControl, UNO_QUERY);
sal_Bool bControlIsLocked = xLockingTest.is() && xLockingTest->getLock();
sal_Bool bResult = sal_True;
if (xActiveControl.is() && !bControlIsLocked)
{
// zunaechst das Control fragen ob es das IFace unterstuetzt
Reference< XBoundComponent> xBound(xActiveControl, UNO_QUERY);
if (!xBound.is())
xBound = Reference< XBoundComponent>(xActiveControl->getModel(), UNO_QUERY);
if (xBound.is() && !xBound->commit())
bResult = sal_False;
}
return bResult;
}
//------------------------------------------------------------------------
void FmXFormShell::ResetCurrent(const Reference< XFormController>& _xController)
{
Reference< XControl> xActiveControl( _xController->getCurrentControl());
if (xActiveControl.is())
{
Reference< XReset> xReset(xActiveControl->getModel(), UNO_QUERY);
if (xReset.is())
xReset->reset();
}
}
//------------------------------------------------------------------------
void FmXFormShell::ResetAll(const Reference< XForm>& _xForm)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XIndexAccess> xContainer(_xForm, UNO_QUERY);
for (sal_Int16 nBothViews=0; nBothViews<2; ++nBothViews)
{
if (xContainer.is())
{
Reference< XReset> xReset;
for (sal_Int32 i=0; i<xContainer->getCount(); ++i)
{
xContainer->getByIndex(i) >>= xReset;
if (xReset.is())
{
Reference< XForm> xAsForm(xReset, UNO_QUERY);
if (!xAsForm.is()) // no resets on the form
xReset->reset();
}
}
}
xContainer = NULL;
if ((nBothViews == 0) && (getInternalForm(_xForm) == m_xExternalDisplayedForm))
{
Reference< XFormController> xExternalFormController(m_xExternalViewController, UNO_QUERY);
if (xExternalFormController.is())
xContainer = Reference< XIndexAccess>(xExternalFormController->getModel(), UNO_QUERY);
}
}
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::SaveModified(const Reference< XResultSetUpdate>& _xCursor, Reference< XPropertySet>& _xSet, sal_Bool& _rRecordInserted)
{
_rRecordInserted = sal_False;
if (!_xCursor.is())
return sal_False;
_xSet = Reference< XPropertySet>(_xCursor, UNO_QUERY);
if (!_xSet.is())
return sal_False;
// mu gespeichert werden ?
sal_Bool bIsNew = ::comphelper::getBOOL(_xSet->getPropertyValue(FM_PROP_ISNEW));
sal_Bool bIsModified = ::comphelper::getBOOL(_xSet->getPropertyValue(FM_PROP_ISMODIFIED));
sal_Bool bResult = !bIsModified;
if (bIsModified)
{
try
{
if (bIsNew)
_xCursor->insertRow();
else
_xCursor->updateRow();
bResult = sal_True;
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::SaveModified: Exception occured!");
}
_rRecordInserted = bIsNew && bResult;
}
return bResult;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::SaveModified(const Reference< XFormController>& xController,
Reference< XResultSetUpdate>& xCursor,
Reference< XPropertySet>& xSet,
sal_Bool& rRecordInserted)
{
rRecordInserted = sal_False;
if (!xController.is())
return sal_False;
xCursor = Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY);
return SaveModified(xCursor, xSet, rRecordInserted);
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::IsModified(const Reference< XFormController>& xController)
{
if (!xController.is())
return sal_False;
Reference< XPropertySet> xSet(xController->getModel(), UNO_QUERY);
if (!xSet.is())
return sal_False;
// Modifiziert
if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED)))
return sal_True;
return sal_False;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::SaveModified(const Reference< XFormController>& xController, sal_Bool bCommit)
{
if (!bCommit || CommitCurrent(xController))
{
Reference< XResultSetUpdate> xCursor;
Reference< XPropertySet> xSet;
sal_Bool bInserted;
return SaveModified(xController,
xCursor,
xSet,
bInserted);
}
else
return sal_False;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::MoveRight(const Reference< XResultSetUpdate>& _xCursor)
{
if (!_xCursor.is())
return sal_False;
Reference< XPropertySet> xSet;
Reference< XResultSet> xReadCursor(_xCursor, UNO_QUERY);
DBG_ASSERT(xReadCursor.is(), "FmXFormShell::MoveRight : invalid cursor !");
sal_Bool bInserted;
sal_Bool bSuccess = SaveModified(_xCursor, xSet, bInserted);
if (bSuccess)
{
try
{
if (bInserted)
{
// go to insert row
_xCursor->moveToInsertRow();
}
else
{
if (xReadCursor->isLast())
_xCursor->moveToInsertRow();
else
xReadCursor->next();
}
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::MoveRight: Exception occured!");
}
}
return bSuccess;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::MoveRight(const Reference< XFormController>& xController)
{
if (!xController.is())
return sal_False;
return MoveRight(Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY));
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::MoveLeft(const Reference< XResultSetUpdate>& _xCursor)
{
if (!_xCursor.is())
return sal_False;
Reference< XPropertySet> xSet;
Reference< XResultSet> xReadCursor(_xCursor, UNO_QUERY);
DBG_ASSERT(xReadCursor.is(), "FmXFormShell::MoveLeft : invalid cursor !");
sal_Bool bInserted;
sal_Bool bSuccess = SaveModified(_xCursor, xSet, bInserted);
if (bSuccess)
{
try
{
if (bInserted)
{
// retrieve the bookmark of the new record and move previous to that bookmark
Reference< XRowLocate> xLocate(xReadCursor, UNO_QUERY);
xLocate->moveRelativeToBookmark(xLocate->getBookmark(), -1);
}
else if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)))
{
// we assume that the inserted record is now the last record in the
// result set
xReadCursor->last();
}
else
xReadCursor->previous();
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::MoveLeft: Exception occured!");
}
}
return bSuccess;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::MoveLeft(const Reference< XFormController>& xController)
{
if (!xController.is())
return sal_False;
return MoveLeft(Reference< XResultSetUpdate>(xController->getModel(), UNO_QUERY));
}
// XRowSetListener
//------------------------------------------------------------------------------
void SAL_CALL FmXFormShell::cursorMoved(const EventObject& event) throw( RuntimeException )
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
m_bActiveModified = sal_False;
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(DatabaseSlotMap);
}
//------------------------------------------------------------------------------
void FmXFormShell::CloseExternalFormViewer()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (!m_xExternalViewController.is())
return;
Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame( m_xExternalViewController->getFrame());
Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
if (!xCommLink.is())
return;
xExternalViewFrame->setComponent(NULL,NULL);
::comphelper::disposeComponent(xExternalViewFrame);
// URL aCloseUrl;
// // tool windows (like the task local beamer used for the grid) are assumed to close when dispatching an empty URL
//
// Reference< ::com::sun::star::frame::XDispatch> xCloser(xCommLink->queryDispatch(aCloseUrl, ::rtl::OUString::createFromAscii("_self"), 0));
// DBG_ASSERT(xCloser.is(), "FmXFormShell::CloseExternalFormViewer : don't know how to close the tool frame !");
// if (xCloser.is())
// xCloser->dispatch(aCloseUrl, Sequence< PropertyValue>());
m_xExternalViewController = NULL;
m_xExtViewTriggerController = NULL;
m_xExternalDisplayedForm = NULL;
}
//------------------------------------------------------------------------------
Reference< XResultSet> FmXFormShell::getInternalForm(const Reference< XResultSet>& _xForm) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XFormController> xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
{
DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
return m_xExternalDisplayedForm;
}
return _xForm;
}
//------------------------------------------------------------------------------
Reference< XForm> FmXFormShell::getInternalForm(const Reference< XForm>& _xForm) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XFormController> xExternalCtrlr(m_xExternalViewController, UNO_QUERY);
if (xExternalCtrlr.is() && (_xForm == xExternalCtrlr->getModel()))
{
DBG_ASSERT(m_xExternalDisplayedForm.is(), "FmXFormShell::getInternalForm : invalid external form !");
return Reference< XForm>(m_xExternalDisplayedForm, UNO_QUERY);
}
return _xForm;
}
//------------------------------------------------------------------------------
void FmXFormShell::ActivateDispatchers(const UniString& _sNavFormAccess, sal_Bool _bActivate)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
for ( ConstFormsDispatchersIterator aFormIter = m_aNavigationDispatcher.begin();
aFormIter != m_aNavigationDispatcher.end();
++aFormIter
)
{
UniString sPath = aFormIter->first;
if (sPath == _sNavFormAccess)
{
for ( ConstSingleFormDispatchersIterator aDispIter = (*aFormIter).second.begin();
aDispIter < (*aFormIter).second.end();
++aDispIter
)
{
FmFormNavigationDispatcher* pCurDispatcher = *aDispIter;
if (pCurDispatcher)
pCurDispatcher->SetActive(_bActivate);
}
}
}
}
//------------------------------------------------------------------------------
UniString FmXFormShell::GetAccessPathFromForm(const Reference< XResultSet>& _xForm, const UniString& rAssumedPagePrefix) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
UniString sReturn;
if (!_xForm.is())
return sReturn;
Reference< XResultSet> xForm(getInternalForm(_xForm));
sReturn = getFormComponentAccessPath(xForm);
// prepend the page ident to the path
UniString sPrefix( rAssumedPagePrefix );
if (!sPrefix.Len())
{
FmFormPage* pPage = m_pShell->GetCurPage();
DBG_ASSERT(pPage, "FmXFormShell::GetAccessPathFromForm : have no current page !");
if (pPage && pPage->GetImpl())
sPrefix = pPage->GetImpl()->GetPageId();
else
sPrefix.AssignAscii("no page");
}
sPrefix += '\\';
sPrefix += sReturn;
sReturn = sPrefix;
return sReturn;
}
//------------------------------------------------------------------------------
UniString FmXFormShell::GetPageId(const Reference< XResultSet>& _xForm) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
UniString sEmptyReturn;
FmFormModel* pModel = m_pShell->GetFormModel();
if (!pModel)
{
DBG_ERROR("FmXFormShell::GetPageId : have no form model !");
return sEmptyReturn;
}
// search the top level forms collection
Reference< XInterface> xTopLevelContainer( getInternalForm(_xForm));
Reference< XResultSet> xAsResultSet(xTopLevelContainer, UNO_QUERY);
while (xAsResultSet.is())
{
Reference< XChild> xChild(xTopLevelContainer, UNO_QUERY);
xTopLevelContainer = xChild->getParent();
xAsResultSet = Reference< XResultSet>(xTopLevelContainer, UNO_QUERY);
}
// search all pages of my model
for (sal_Int16 i=0; i<pModel->GetPageCount(); ++i)
{
FmFormPage* pCurrent = PTR_CAST(FmFormPage, pModel->GetPage(i));
if (!pCurrent)
continue;
if (pCurrent->GetForms() == xTopLevelContainer)
return pCurrent->GetImpl()->GetPageId();
}
return sEmptyReturn;
}
//------------------------------------------------------------------------------
Reference< XNameContainer> FmXFormShell::GetPageForms(const UniString sPageId) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XNameContainer> aEmptyReturn;
FmFormModel* pModel = m_pShell->GetFormModel();
if (!pModel)
{
DBG_ERROR("FmXFormShell::GetPageForms : have no form model !");
return aEmptyReturn;
}
for (sal_uInt16 i=0; i<pModel->GetPageCount(); ++i)
{
FmFormPage* pCurrent = PTR_CAST(FmFormPage, pModel->GetPage(i));
if (!pCurrent)
continue;
if (pCurrent->GetImpl()->GetPageId() == sPageId)
return pCurrent->GetForms();
}
return aEmptyReturn;
}
//------------------------------------------------------------------------------
void FmXFormShell::UpdateAllFormDispatchers(const UniString& _rPath)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
for ( FormsDispatchersIterator aDispIter = m_aNavigationDispatcher.begin();
aDispIter != m_aNavigationDispatcher.end();
++aDispIter
)
{
UniString sThisRoundPath = aDispIter->first;
if (PathsInterfere(sThisRoundPath, _rPath))
// child or anchestor
{
SingleFormDispatchers& rDisp = (*aDispIter).second;
for ( SingleFormDispatchersIterator aIter = rDisp.begin();
aIter != rDisp.end();
++aIter
)
{
FmFormNavigationDispatcher* pCurrent = *aIter;
if (pCurrent)
UpdateFormDispatcher(pCurrent);
}
}
}
}
//------------------------------------------------------------------------------
void FmXFormShell::UpdateFormDispatcher(FmFormNavigationDispatcher* _pDisp)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
sal_Bool bEnable = sal_False;
if (!_pDisp)
return;
// all navigation slots are disabled if the form is blocked because of a pending move
if (!HasPendingCursorAction(_pDisp->getForm()))
{
Reference< XPropertySet> xSet(_pDisp->getForm(), UNO_QUERY);
switch (_pDisp->getSlot())
{
case SID_FM_RECORD_UNDO:
bEnable = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED));
break;
case SID_FM_RECORD_PREV:
case SID_FM_RECORD_FIRST:
bEnable = CanMoveLeft(xSet);
break;
case SID_FM_RECORD_NEXT:
bEnable = CanMoveRight(xSet);
break;
case SID_FM_RECORD_LAST:
{
Reference< XResultSet> xCursor(xSet, UNO_QUERY);
sal_Int32 nCount = ::comphelper::getINT32(xSet->getPropertyValue(FM_PROP_ROWCOUNT));
bEnable = nCount && (!xCursor->isLast() || ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)));
}
break;
case SID_FM_RECORD_NEW:
{
if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)))
bEnable = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED));
else
bEnable = canInsert(xSet);
}
break;
}
}
_pDisp->SetStatus(bEnable ? SFX_ITEM_AVAILABLE : SFX_ITEM_DISABLED, NULL);
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnExecuteNavSlot, FmFormNavigationDispatcher*, pDispatcher)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(pDispatcher, "FmXFormShell::OnExecuteNavSlot : invalid argument !");
Reference< XResultSet > xCursor( pDispatcher->getForm() );
Reference< XResultSetUpdate > xUpdateCursor( xCursor, UNO_QUERY );
// all slots except undo need a SaveModified
if ( pDispatcher->getSlot() != SID_FM_RECORD_UNDO )
{
Reference< XPropertySet> xCursorSet;
sal_Bool bDoneSomething = sal_False;
if ( !SaveModified( xUpdateCursor, xCursorSet, bDoneSomething ) )
return 1L;
}
switch ( pDispatcher->getSlot() )
{
case SID_FM_RECORD_UNDO:
{
Reference< XPropertySet> xSet(xCursor, UNO_QUERY);
sal_Bool bInserting = xSet.is() && ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW));
if (!bInserting)
xUpdateCursor->cancelRowUpdates();
ResetAll(getActiveForm());
if (bInserting) // wieder in den EinfuegeModus
DO_SAFE( xUpdateCursor->moveToInsertRow(); );
if (xCursor == getActiveForm())
m_bActiveModified = sal_False;
}
break;
case SID_FM_RECORD_FIRST:
DO_SAFE( xCursor->first(); );
break;
case SID_FM_RECORD_PREV:
MoveLeft(xUpdateCursor);
break;
case SID_FM_RECORD_NEXT:
MoveRight(xUpdateCursor);
break;
case SID_FM_RECORD_LAST:
{
// run in an own thread if ...
Reference< XPropertySet> xCursorProps(xCursor, UNO_QUERY);
// ... the data source is thread safe ...
sal_Bool bAllowOwnThread = ::comphelper::hasProperty(FM_PROP_THREADSAFE, xCursorProps) && ::comphelper::getBOOL(xCursorProps->getPropertyValue(FM_PROP_THREADSAFE));
// ... the record count is unknown
sal_Bool bNeedOwnThread = ::comphelper::hasProperty(FM_PROP_ROWCOUNTFINAL, xCursorProps) && !::comphelper::getBOOL(xCursorProps->getPropertyValue(FM_PROP_ROWCOUNTFINAL));
if (bNeedOwnThread && bAllowOwnThread)
DoAsyncCursorAction(pDispatcher->getForm(), FmXFormShell::CA_MOVE_TO_LAST);
else
DO_SAFE( xCursor->last(); );
}
break;
case SID_FM_RECORD_NEW:
{
Reference< XResultSet > xCursor( xUpdateCursor, UNO_QUERY );
DBG_ASSERT( xCursor.is(), "FmXFormShell:OnExecuteNavSlot: invalid cursor (no XResultSet)!" );
if ( xCursor.is() )
{
// move to the last row before moving to the insert row
// 21.01.2002 - 96480 - fs@openoffice.org
DO_SAFE( xCursor->last(); );
DO_SAFE( xUpdateCursor->moveToInsertRow(); );
// TODO: here, the same comments as in FmFormShell::Execute( SID_FM_RECORD_NEW ) apply
// think about this DO_SAFE
}
}
break;
}
if (xCursor == getActiveForm())
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(DatabaseSlotMap);
UpdateAllFormDispatchers(pDispatcher->getFormAccessPath());
return 0L;
}
//------------------------------------------------------------------------------
void FmXFormShell::setActiveController( const Reference< XFormController>& xController, sal_Bool _bNoSaveOldContent )
{
DBG_ASSERT(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (m_bChangingDesignMode)
return;
DBG_ASSERT(!m_pShell->IsDesignMode(), "nur im alive mode verwenden");
// Ist die Routine ein zweites Mal gerufen worden,
// dann sollte der Focus nicht mehr umgesetzt werden
if (m_bInActivate)
{
m_bSetFocus = xController != m_xActiveController;
return;
}
if (xController != m_xActiveController)
{
// if there is a async cursor action running we have to restore the locking state of the controls of the old controller
if (HasPendingCursorAction(Reference< XResultSet>(m_xActiveForm, UNO_QUERY)))
restoreControlLocks();
::osl::ClearableMutexGuard aGuard(m_aAsyncSafety);
// switch all nav dispatchers belonging to the form of the current nav controller to 'non active'
Reference< XResultSet> xNavigationForm;
if (m_xNavigationController.is())
xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
if (xNavigationForm.is())
ActivateDispatchers(GetAccessPathFromForm(xNavigationForm), sal_False);
aGuard.clear();
m_bInActivate = sal_True;
// check if the 2 controllers serve different forms
Reference< XResultSet> xOldForm;
if (m_xActiveController.is())
xOldForm = Reference< XResultSet>(m_xActiveController->getModel(), UNO_QUERY);
Reference< XResultSet> xNewForm;
if (xController.is())
xNewForm = Reference< XResultSet>(xController->getModel(), UNO_QUERY);
xOldForm = getInternalForm(xOldForm);
xNewForm = getInternalForm(xNewForm);
sal_Bool bDifferentForm = ( xOldForm.get() != xNewForm.get() );
sal_Bool bNeedSave = bDifferentForm && !_bNoSaveOldContent;
// we save the content of the old form if we move to a new form, and saving old content is allowed
if ( m_xActiveController.is() && bNeedSave )
{
// beim Wechsel des Controllers den Inhalt speichern, ein Commit
// wurde bereits ausgefuehrt
Reference< XControl> xCurrentControl(m_xActiveController->getCurrentControl());
if (xCurrentControl.is())
{
m_bSetFocus = sal_True;
Reference< XPropertySet> xSet(getActiveForm(), UNO_QUERY);
if (IsModified(m_xActiveController))
{
sal_Bool bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW));
sal_Bool bResult = sal_False;
Reference< XResultSetUpdate> xCursor(getActiveForm(), UNO_QUERY);
try
{
if (bIsNew)
xCursor->insertRow();
else
xCursor->updateRow();
bResult = sal_True;
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::setActiveController: Exception occured!");
}
// Konnte nicht gespeichert werden, dann den Focus wieder zurueck setzen
if (!bResult && m_bSetFocus)
{
Reference< XWindow> xWindow(xCurrentControl, UNO_QUERY);
xWindow->setFocus();
m_bInActivate = sal_False;
return;
}
if (bResult && bIsNew)
{
DO_SAFE( Reference< XResultSet>(xCursor, UNO_QUERY)->last(); );
}
}
}
}
stopListening();
m_xActiveController = xController;
if (m_xActiveController.is())
{
// set eventlistener to know when it is disposed
Reference< ::com::sun::star::lang::XComponent> xComp(m_xActiveController, UNO_QUERY);
if (xComp.is())
xComp->addEventListener((XEventListener*)(XPropertyChangeListener*)this);
m_xActiveForm = getInternalForm(Reference< XForm>(m_xActiveController->getModel(), UNO_QUERY));
}
else
m_xActiveForm = NULL;
startListening();
// activate all dispatchers belonging to form of the new navigation controller
xNavigationForm = NULL;
if (m_xNavigationController.is())
xNavigationForm = Reference< XResultSet>(m_xNavigationController->getModel(), UNO_QUERY);
if (xNavigationForm.is())
ActivateDispatchers(GetAccessPathFromForm(xNavigationForm), sal_True);
// if there is a async cursor action running we have to lock the controls of the new controller
if (HasPendingCursorAction(Reference< XResultSet>(m_xActiveForm, UNO_QUERY)))
setControlLocks();
m_bInActivate = sal_False;
m_pShell->UIFeatureChanged();
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
InvalidateSlot(SID_FM_FILTER_NAVIGATOR_CONTROL, sal_True, sal_True);
}
}
//------------------------------------------------------------------------------
void FmXFormShell::setCurControl( const SdrMarkList& rMarkList )
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (isControlList(rMarkList))
{
// Aktuell selektiertes Objekt setzen
sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
FmFormObj* pSelFormObj = NULL;
if (nMarkCount==1)
{
SdrObject *pObj=rMarkList.GetMark(0)->GetObj();
if( pObj->IsGroupObject() ) // Mehrfachselektion
{
Reference< XPropertyState> xMultiIFace(FmXMultiSet::Create( rMarkList ));
setCurControl( xMultiIFace );
}
else
{
pSelFormObj = PTR_CAST(FmFormObj, rMarkList.GetMark(0)->GetObj());
if ( pSelFormObj ) // Einfachselektion
{
Reference< XFormComponent> xFormComponent(pSelFormObj->GetUnoControlModel(), UNO_QUERY);
if (xFormComponent.is())
setCurControl(xFormComponent);
else
setCurControl( Reference< XInterface>() );
}
else
setCurControl( Reference< XInterface>() );
}
}
else if (nMarkCount > 1) // Mehrfachselektion
{
Reference< XPropertyState> xMultiIFace(FmXMultiSet::Create( rMarkList ));
setCurControl( xMultiIFace );
}
}
else // Keine Selektion oder gemischt
setCurControl( Reference< XInterface>() );
}
//------------------------------------------------------------------------------
void FmXFormShell::setCurControl(const Reference< XInterface>& xNewControl)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(m_pShell->IsDesignMode(), "nur im designmode verwenden");
if (m_xCurControl == xNewControl)
return;
// Stammen beide Objecte vom gleichen Container
if (m_xCurControl.is())
{
Reference< XChild> xCur(m_xCurControl, UNO_QUERY);
Reference< XChild> xNew(xNewControl, UNO_QUERY);
// wenn nichts selektiert oder unterschiedliche Vter und der Vater von xCurControl ist ein XSelectionSupplier
// dann mu dieser deselektieren.
if (!xNew.is() || xCur->getParent() != xNew->getParent())
{
Reference< ::com::sun::star::view::XSelectionSupplier> xSel(xCur->getParent(), UNO_QUERY);
if (xSel.is())
{
xSel->select(Any());
}
}
}
m_xCurControl = xNewControl;
InvalidateSlot(SID_FM_CTL_PROPERTIES);
}
//------------------------------------------------------------------------------
void FmXFormShell::setSelObject(const Reference< XInterface>& xNewObj)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(m_pShell->IsDesignMode(), "nur im designmode verwenden");
if (m_xSelObject != xNewObj)
{
m_xSelObject = xNewObj;
for (sal_Int16 i = 0; i<sizeof(SelObjectSlotMap)/sizeof(SelObjectSlotMap[0]); ++i)
InvalidateSlot(SelObjectSlotMap[i]);
}
}
//------------------------------------------------------------------------------
void FmXFormShell::setCurForm(const Reference< XForm>& xF)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(m_pShell->IsDesignMode(), "nur im designmode verwenden");
if (xF != m_xCurForm)
{
m_xCurForm = xF;
FmFormPage* pPage = m_pShell->GetCurPage();
if (pPage)
pPage->GetImpl()->setCurForm( xF );
for (sal_Int16 i = 0; i<sizeof(DlgSlotMap)/sizeof(DlgSlotMap[0]); ++i)
InvalidateSlot(DlgSlotMap[i]);
}
}
//------------------------------------------------------------------------------
void FmXFormShell::startListening()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
if (xDatabaseForm.is() && getRowSetConnection(xDatabaseForm).is())
{
Reference< XPropertySet> xActiveFormSet(m_xActiveForm, UNO_QUERY);
if (xActiveFormSet.is())
{
// wenn es eine Datenquelle gibt, dann den Listener aufbauen
::rtl::OUString aSource = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_COMMAND));
if (aSource.getLength())
{
// we have to recognize any change roset change
xDatabaseForm->addRowSetListener(this);
// Modify
Reference< XModifyBroadcaster> xBroadCaster(m_xActiveController, UNO_QUERY);
if (xBroadCaster.is())
xBroadCaster->addModifyListener(this);
sal_Bool bUseEscapeProcessing = ::comphelper::getBOOL(xActiveFormSet->getPropertyValue(FM_PROP_ESCAPE_PROCESSING));
if (bUseEscapeProcessing)
{
Reference< XSQLQueryComposerFactory> xFactory(getRowSetConnection(xDatabaseForm), UNO_QUERY);
if (xFactory.is())
m_xParser = xFactory->createQueryComposer();
}
m_bDatabaseBar = sal_True;
xActiveFormSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
xActiveFormSet->addPropertyChangeListener(FM_PROP_ISMODIFIED,this);
xActiveFormSet->addPropertyChangeListener(FM_PROP_ISNEW, this);
switch (m_eNavigate)
{
case NavigationBarMode_PARENT:
{
// suchen des Controllers, ueber den eine Navigation moeglich ist
Reference< XChild> xChild(m_xActiveController, UNO_QUERY);
Reference< XFormController> xParent;
while (xChild.is())
{
xChild = Reference< XChild>(xChild->getParent(), UNO_QUERY);
xParent = Reference< XFormController>(xChild, UNO_QUERY);
Reference< XPropertySet> xParentSet;
if (xParent.is())
xParentSet = Reference< XPropertySet>(xParent->getModel(), UNO_QUERY);
if (xParentSet.is())
{
xParentSet->getPropertyValue(FM_PROP_NAVIGATION) >>= m_eNavigate;
if (m_eNavigate == NavigationBarMode_CURRENT)
break;
}
}
m_xNavigationController = xParent;
} break;
case NavigationBarMode_CURRENT:
m_xNavigationController = m_xActiveController;
break;
default:
m_xNavigationController = NULL;
m_bDatabaseBar = sal_False;
}
// an dem Controller, der die Navigation regelt, wg. RecordCount lauschen
Reference< XPropertySet> xNavigationSet;
if (m_xNavigationController.is())
{
xNavigationSet = Reference< XPropertySet>(m_xNavigationController->getModel(), UNO_QUERY);
if (xNavigationSet.is())
xNavigationSet->addPropertyChangeListener(FM_PROP_ROWCOUNT,this);
}
// und dem Parser die Query-/Filter-/Sort-Einstellungen der aktiven Form
if (m_xParser.is())
{
Reference< XLoadable> xLoad(m_xActiveForm,UNO_QUERY);
if ( xLoad.is() && xLoad->isLoaded() )
{
::rtl::OUString aStatement = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_ACTIVECOMMAND));
::rtl::OUString aFilter = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_FILTER_CRITERIA));
::rtl::OUString aSort = ::comphelper::getString(xActiveFormSet->getPropertyValue(FM_PROP_SORT));
try
{
m_xParser->setQuery(aStatement);
m_xParser->setFilter(aFilter);
m_xParser->setOrder(aSort);
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::startListening: Exception occured!");
}
}
// nothing to do, change the parser on a reload
xActiveFormSet->addPropertyChangeListener(FM_PROP_ACTIVECOMMAND,this);
xActiveFormSet->addPropertyChangeListener(FM_PROP_FILTER_CRITERIA, this);
xActiveFormSet->addPropertyChangeListener(FM_PROP_SORT, this);
}
m_bActiveModified = sal_False;
return;
}
}
}
m_eNavigate = NavigationBarMode_NONE;
m_bDatabaseBar = sal_False;
m_xNavigationController = NULL;
m_bActiveModified = sal_False;
}
//------------------------------------------------------------------------------
void FmXFormShell::stopListening()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XRowSet> xDatabaseForm(m_xActiveForm, UNO_QUERY);
if (xDatabaseForm.is() && m_bDatabaseBar)
{
// datensatzwechsel mitbekommen
xDatabaseForm->removeRowSetListener(this);
// Modify
Reference< XModifyBroadcaster> xBroadCaster(m_xActiveController, UNO_QUERY);
if (xBroadCaster.is())
xBroadCaster->removeModifyListener(this);
// satzstatus
Reference< XPropertySet> xActiveFormSet(m_xActiveForm, UNO_QUERY);
if (xActiveFormSet.is())
{
xActiveFormSet->removePropertyChangeListener(FM_PROP_ISMODIFIED,this);
xActiveFormSet->removePropertyChangeListener(FM_PROP_ISNEW, this);
if (m_xParser.is())
{
xActiveFormSet->removePropertyChangeListener(FM_PROP_FILTER_CRITERIA, this);
xActiveFormSet->removePropertyChangeListener(FM_PROP_ACTIVECOMMAND,this);
xActiveFormSet->removePropertyChangeListener(FM_PROP_SORT,this);
}
}
Reference< ::com::sun::star::lang::XComponent> xComp(m_xParser, UNO_QUERY);
if (xComp.is())
xComp->dispose();
m_xParser = NULL;
if (m_xNavigationController.is())
{
Reference< XPropertySet> xSet(m_xNavigationController->getModel(), UNO_QUERY);
if (xSet.is())
xSet->removePropertyChangeListener(FM_PROP_ROWCOUNT, this);
}
}
m_bDatabaseBar = sal_False;
m_eNavigate = NavigationBarMode_NONE;
m_xNavigationController = NULL;
m_bActiveModified = sal_False;
}
//------------------------------------------------------------------------------
void FmXFormShell::ShowProperties(const Reference< XInterface>& rxObject, sal_Bool bShow)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// Evtl. noch aktuelles Objekt umsetzen
if (rxObject != m_xSelObject)
setSelObject( rxObject );
// Wenn Fenster bereits angezeigt wird, nur StatusUpdate
sal_Bool bHasChild = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES);
if (bHasChild && bShow)
InvalidateSlot(SID_FM_PROPERTY_CONTROL, sal_True, sal_True);
// Ansonsten Fenster ein-/ausblenden
else
m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
InvalidateSlot(SID_FM_PROPERTIES);
InvalidateSlot(SID_FM_CTL_PROPERTIES);
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnFoundData, FmFoundRecordInformation*, pfriWhere)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_arrSearchContexts.size()),
"FmXFormShell::OnFoundData : ungueltiger Kontext !");
Reference< XForm> xForm( m_arrSearchContexts.at(pfriWhere->nContext));
DBG_ASSERT(xForm.is(), "FmXFormShell::OnFoundData : ungueltige Form !");
Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
if (!xCursor.is())
return 0; // was soll ich da machen ?
// zum Datensatz
xCursor->moveToBookmark(pfriWhere->aPosition);
LoopGrids(GA_FORCE_SYNC);
// und zum Feld (dazu habe ich vor dem Start des Suchens die XVclComponent-Interfaces eingesammelt)
DBG_ASSERT(pfriWhere->nFieldPos < m_arrSearchedControls.Count(), "FmXFormShell::OnFoundData : ungueltige Daten uebergeben !");
SdrObject* pObject = m_arrSearchedControls.GetObject(pfriWhere->nFieldPos);
DBG_ASSERT(pObject != NULL, "FmXFormShell::OnFoundData : unerwartet : ungueltiges VclControl-Interface");
m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetPageView(m_pShell->GetCurPage()));
m_pShell->GetFormView()->MarkObj(pObject, m_pShell->GetFormView()->GetPageView(m_pShell->GetCurPage()));
DBG_ASSERT(pObject->IsUnoObj(), "FmXFormShell::OnFoundData : ungueltiges Control !");
Reference< XControlModel> xControlModel( ((SdrUnoObj*)pObject)->GetUnoControlModel());
DBG_ASSERT(xControlModel.is(), "FmXFormShell::OnFoundData : ungueltiges Control !");
// disable the permanent cursor for the last grid we found a record
if (m_xLastGridFound.is() && (m_xLastGridFound != xControlModel))
{
Reference< XPropertySet> xOldSet(m_xLastGridFound, UNO_QUERY);
sal_Bool bB(sal_False);
xOldSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, makeAny( (sal_Bool)sal_False ) );
Reference< XPropertyState> xOldSetState(xOldSet, UNO_QUERY);
if (xOldSetState.is())
xOldSetState->setPropertyToDefault(FM_PROP_CURSORCOLOR);
else
xOldSet->setPropertyValue(FM_PROP_CURSORCOLOR, Any());
}
// wenn das Feld sich in einem GridControl befindet, muss ich dort noch in die entsprechende Spalte gehen
sal_Int32 nGridColumn = m_arrRelativeGridColumn.GetObject(pfriWhere->nFieldPos);
if (nGridColumn != -1)
{ // dummer weise muss ich mir das Control erst wieder besorgen
Reference< XControl> xControl( GetControlFromModel(xControlModel));
Reference< XGrid> xGrid(xControl, UNO_QUERY);
DBG_ASSERT(xGrid.is(), "FmXFormShell::OnFoundData : ungueltiges Control !");
// wenn eine der Asserts anschlaegt, habe ich beim Aufbauen von m_arrSearchedControls wohl was falsch gemacht
// enable a permanent cursor for the grid so we can see the found text
Reference< XPropertySet> xModelSet(xControlModel, UNO_QUERY);
DBG_ASSERT(xModelSet.is(), "FmXFormShell::OnFoundData : invalid control model (no property set) !");
sal_Bool bB(sal_True);
xModelSet->setPropertyValue(FM_PROP_ALWAYSSHOWCURSOR, Any(&bB,getBooleanCppuType()));
xModelSet->setPropertyValue(FM_PROP_CURSORCOLOR, makeAny(sal_Int32(COL_LIGHTRED)));
m_xLastGridFound = xControlModel;
xGrid->setCurrentColumnPosition((sal_Int16)nGridColumn);
}
// als der Cursor neu positioniert wurde, habe ich (in positioned) meine Formularleisten-Slots invalidiert, aber das greift
// hier dummerweise nicht, da i.A. ja der (modale) Suchdialog oben ist ... also Gewalt ...
sal_uInt16 nPos = 0;
while (DatabaseSlotMap[nPos])
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Update(DatabaseSlotMap[nPos++]);
// leider geht das Update im Gegensatz zum Invalidate nur mit einzelnen Slots)
return 0;
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnCanceledNotFound, FmFoundRecordInformation*, pfriWhere)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT((pfriWhere->nContext >= 0) && (pfriWhere->nContext < (sal_Int16)m_arrSearchContexts.size()),
"FmXFormShell::OnCanceledNotFound : ungueltiger Kontext !");
Reference< XForm> xForm( m_arrSearchContexts.at(pfriWhere->nContext));
DBG_ASSERT(xForm.is(), "FmXFormShell::OnCanceledNotFound : ungueltige Form !");
Reference< XRowLocate> xCursor(xForm, UNO_QUERY);
if (!xCursor.is())
return 0; // was soll ich da machen ?
// zum Datensatz
xCursor->moveToBookmark(pfriWhere->aPosition);
m_pShell->GetFormView()->UnMarkAll(m_pShell->GetFormView()->GetPageViewPvNum(0));
return 0L;
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnSearchContextRequest, FmSearchContext*, pfmscContextInfo)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(pfmscContextInfo->nContext < (sal_Int16)m_arrSearchContexts.size(), "FmXFormShell::OnSearchContextRequest : invalid parameter !");
Reference< XForm> xForm( m_arrSearchContexts.at(pfmscContextInfo->nContext));
DBG_ASSERT(xForm.is(), "FmXFormShell::OnSearchContextRequest : unexpected : invalid context !");
Reference< XResultSet> xIter(xForm, UNO_QUERY);
DBG_ASSERT(xIter.is(), "FmXFormShell::OnSearchContextRequest : unexpected : context has no iterator !");
// --------------------------------------------------------------------------------------------
// die Liste der zu involvierenden Felder zusammenstellen (sind die ControlSources aller Felder, die eine solche Eigenschaft habe)
UniString strFieldList, sFieldDisplayNames;
m_arrSearchedControls.Remove(0, m_arrSearchedControls.Count());
m_arrRelativeGridColumn.Remove(0, m_arrRelativeGridColumn.Count());
// folgendes kleines Problem : Ich brauche, um gefundene Felder zu markieren, SdrObjekte. Um hier festzustellen, welche Controls
// ich in die Suche einbeziehen soll, brauche ich Controls (also XControl-Interfaces). Ich muss also ueber eines von beiden
// iterieren und mir das jeweils andere besorgen. Dummerweise gibt es keine direkte Verbindung zwischen beiden Welten (abgesehen
// von einem GetUnoControl an SdrUnoObject, das aber ein OutputDevice verlangt, womit ich nichts anfangen kann).
// Allerdings komme ich sowohl von einem Control als auch von einem SdrObject zum Model, und damit ist mir mit einer doppelten
// Schleife die Zuordnung SdrObject<->Control moeglich.
// Die Alternative zu dieser (unschoenen und sicher auch nicht ganz fixen) Loesung waere, auf das Cachen der SdrObjects zu
// verzichten, was dann aber in OnFoundData zu wesentlicher Mehrarbeit fuehren wuerde (da ich mir dort jedesmal das SdrObject
// erst besorgen muesste). Da aber OnFoundData i.d.R. oefter aufgerufen wird als ExecuteSearch, erledige ich das hier.
Reference< XNameAccess> xValidFormFields;
Reference< XColumnsSupplier> xSupplyCols(xIter, UNO_QUERY);
DBG_ASSERT(xSupplyCols.is(), "FmXFormShell::OnSearchContextRequest : invalid cursor : no columns supplier !");
if (xSupplyCols.is())
xValidFormFields = xSupplyCols->getColumns();
DBG_ASSERT(xValidFormFields.is(), "FmXFormShell::OnSearchContextRequest : form has no fields !");
// aktuelle(r) Page/Controller
FmFormPage* pCurrentPage = m_pShell->GetCurPage();
DBG_ASSERT(pCurrentPage!=NULL, "FmXFormShell::OnSearchContextRequest : no page !");
// alle Sdr-Controls dieser Seite durchsuchen ...
::rtl::OUString sControlSource, sCompareString,aName;
for (sal_Int32 i=0; i<(sal_Int32)pCurrentPage->GetObjCount(); ++i)
{
SdrObject* pCurrent = pCurrentPage->GetObj(i);
// wenn das Ding eine Gruppierung ist -> durchiterieren
SdrObjListIter* pGroupIterator = NULL;
if (pCurrent->IsGroupObject())
{
pGroupIterator = new SdrObjListIter(*pCurrent->GetSubList());
pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
}
while (pCurrent)
{
if (pCurrent->IsUnoObj())
{
// das Model zum aktuellen Object ...
Reference< XControlModel> xControlModel( ((SdrUnoObj*)pCurrent)->GetUnoControlModel());
DBG_ASSERT(xControlModel.is(), "FmXFormShell::OnSearchContextRequest : invalid objects !");
// ... als FormComponent
Reference< XFormComponent> xCurrentAsFormComponent(xControlModel, UNO_QUERY);
if (!xCurrentAsFormComponent.is())
{
if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls
pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
else
pCurrent = NULL;
continue;
}
// gehoert diese FormComponent ueberhaupt zu der Form, um die es geht ?
Reference< XInterface> xParentOfCurrent( xCurrentAsFormComponent->getParent());
if (xParentOfCurrent != xForm) // vergleich fuehrt zu richtigem Ergebnis, seit TF_ONE
{
if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls
pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
else
pCurrent = NULL;
continue;
}
// ... nach der ControlSource-Eigenschaft fragen
SearchableControlIterator iter(xCurrentAsFormComponent);
Reference< XControl> xControlBehindModel;
// das Control, das als Model xControlModel hat
// (das folgende while kann mehrmals durchlaufen werden, ohne dass das Control sich aendert, dann muss
// ich nicht jedesmal neu suchen)
Reference< XInterface> xCurrent( iter.Next());
while (xCurrent.is())
{
sControlSource = iter.getCurrentValue();
if (sControlSource == sCompareString)
{ // das aktuelle Element hat keine ControlSource, also ist es ein GridControl (das ist das einzige, was
// der SearchableControlIterator noch zulaesst)
xControlBehindModel = GetControlFromModel(xControlModel);
DBG_ASSERT(xControlBehindModel.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
Reference< XGridPeer> xGridPeer(xControlBehindModel->getPeer(), UNO_QUERY);
do
{
if (!xGridPeer.is())
break;
Reference< XIndexAccess> xPeerContainer(xGridPeer, UNO_QUERY);
if (!xPeerContainer.is())
break;
Reference< XIndexAccess> xModelColumns(xGridPeer->getColumns(), UNO_QUERY);
DBG_ASSERT(xModelColumns.is(), "FmXFormShell::OnSearchContextRequest : there is a grid control without columns !");
// the case 'no columns' should be indicated with an empty container, I think ...
DBG_ASSERT(xModelColumns->getCount() >= xPeerContainer->getCount(), "FmXFormShell::OnSearchContextRequest : impossible : have more view than model columns !");
Reference< XInterface> xCurrentColumn;
for (sal_Int16 nViewPos=0; nViewPos<xPeerContainer->getCount(); ++nViewPos)
{
xPeerContainer->getByIndex(nViewPos) >>= xCurrentColumn;
if (!xCurrentColumn.is())
continue;
// can we use this column control fo searching ?
if (!IsSearchableControl(xCurrentColumn))
continue;
sal_Int16 nModelPos = GridView2ModelPos(xModelColumns, nViewPos);
Reference< XPropertySet> xCurrentColModel;
xModelColumns->getByIndex(nModelPos) >>= xCurrentColModel;
aName = ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_CONTROLSOURCE));
// the cursor has a field matching the control source ?
if (xValidFormFields->hasByName(aName))
{
strFieldList += aName.getStr();
strFieldList += ';';
sFieldDisplayNames += ::comphelper::getString(xCurrentColModel->getPropertyValue(FM_PROP_LABEL)).getStr();
sFieldDisplayNames += ';';
pfmscContextInfo->arrFields.push_back(xCurrentColumn);
// und das SdrObjekt zum Feld
m_arrSearchedControls.C40_INSERT(SdrObject, pCurrent, m_arrSearchedControls.Count());
// die Nummer der Spalte
m_arrRelativeGridColumn.Insert(nViewPos, m_arrRelativeGridColumn.Count());
}
}
} while (sal_False);
}
else
{
if (sControlSource.getLength() && xValidFormFields->hasByName(sControlSource))
{
// jetzt brauche ich das Control zum SdrObject
if (!xControlBehindModel.is())
{
xControlBehindModel = GetControlFromModel(xControlModel);
DBG_ASSERT(xControlBehindModel.is(), "FmXFormShell::OnSearchContextRequest : didn't ::std::find a control with requested model !");
}
if (IsSearchableControl(xControlBehindModel))
{ // alle Tests ueberstanden -> in die Liste mit aufnehmen
strFieldList += sControlSource.getStr();
strFieldList += ';';
// the label which should appear for the control :
sFieldDisplayNames += getLabelName(Reference< XPropertySet>(xControlModel, UNO_QUERY)).getStr();
sFieldDisplayNames += ';';
// das SdrObjekt merken (beschleunigt die Behandlung in OnFoundData)
m_arrSearchedControls.C40_INSERT(SdrObject, pCurrent, m_arrSearchedControls.Count());
// die Nummer der Spalte (hier ein Dummy, nur fuer GridControls interesant)
m_arrRelativeGridColumn.Insert(-1, m_arrRelativeGridColumn.Count());
// und fuer die formatierte Suche ...
pfmscContextInfo->arrFields.push_back(Reference< XInterface>(xControlBehindModel, UNO_QUERY));
}
}
}
xCurrent = iter.Next();
}
}
if (pGroupIterator) // ich iteriere gerade durch eine Gruppe von Controls
pCurrent = pGroupIterator->IsMore() ? pGroupIterator->Next() : NULL;
else
pCurrent = NULL;
}
delete pGroupIterator;
}
strFieldList.EraseTrailingChars(';');
sFieldDisplayNames.EraseTrailingChars(';');
if (!pfmscContextInfo->arrFields.size())
{
pfmscContextInfo->arrFields.clear();
pfmscContextInfo->xCursor = NULL;
pfmscContextInfo->strUsedFields.Erase();
return 0L;
}
pfmscContextInfo->xCursor = xIter;
pfmscContextInfo->strUsedFields = strFieldList;
pfmscContextInfo->sFieldDisplayNames = sFieldDisplayNames;
// 66463 - 31.05.99 - FS
// wenn der Cursor sich in einem anderen RecordMode als STANDARD befindet, ruecksetzen
Reference< XPropertySet> xCursorSet(pfmscContextInfo->xCursor, UNO_QUERY);
Reference< XResultSetUpdate> xUpdateCursor(pfmscContextInfo->xCursor, UNO_QUERY);
if (xUpdateCursor.is() && xCursorSet.is() && xCursorSet.is())
if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISNEW)))
xUpdateCursor->moveToCurrentRow();
else
if (::comphelper::getBOOL(xCursorSet->getPropertyValue(FM_PROP_ISMODIFIED)))
xUpdateCursor->cancelRowUpdates();
return pfmscContextInfo->arrFields.size();
}
// XContainerListener
//------------------------------------------------------------------------------
void FmXFormShell::elementInserted(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// neues Object zum lauschen
Reference< XInterface> xTemp;
evt.Element >>= xTemp;
AddElement(xTemp);
m_pShell->DetermineForms(sal_True);
}
//------------------------------------------------------------------------------
void FmXFormShell::elementReplaced(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XInterface> xTemp;
evt.ReplacedElement >>= xTemp;
RemoveElement(xTemp);
evt.Element >>= xTemp;
AddElement(xTemp);
}
//------------------------------------------------------------------------------
void FmXFormShell::elementRemoved(const ContainerEvent& evt) throw(::com::sun::star::uno::RuntimeException)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XInterface> xTemp;
evt.Element >>= xTemp;
RemoveElement(xTemp);
m_pShell->DetermineForms(sal_True);
}
//------------------------------------------------------------------------------
void FmXFormShell::ResetForms(const Reference< XIndexAccess>& _xForms, sal_Bool bInvalidate)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (m_xForms != _xForms)
{
RemoveElement(m_xForms);
m_xForms = _xForms;
AddElement(m_xForms);
}
m_pShell->DetermineForms(bInvalidate);
}
//------------------------------------------------------------------------------
void FmXFormShell::AddElement(const Reference< XInterface>& Element)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// am Container horchen
Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
if (xContainer.is())
{
sal_uInt32 nCount = xContainer->getCount();
Reference< XInterface> xElement;
for (sal_uInt32 i = 0; i < nCount; i++)
{
xContainer->getByIndex(i) >>= xElement;
AddElement(xElement);
}
Reference< XContainer> xCont(Element, UNO_QUERY);
if (xCont.is())
xCont->addContainerListener(this);
}
Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
if (xSelSupplier.is())
xSelSupplier->addSelectionChangeListener(this);
}
//------------------------------------------------------------------------------
void FmXFormShell::RemoveElement(const Reference< XInterface>& Element)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< ::com::sun::star::view::XSelectionSupplier> xSelSupplier(Element, UNO_QUERY);
if (xSelSupplier.is())
xSelSupplier->removeSelectionChangeListener(this);
// Verbindung zu Kindern aufheben
Reference< XIndexContainer> xContainer(Element, UNO_QUERY);
if (xContainer.is())
{
Reference< XContainer> xCont(Element, UNO_QUERY);
if (xCont.is())
xCont->removeContainerListener(this);
sal_uInt32 nCount = xContainer->getCount();
Reference< XInterface> xElement;
for (sal_uInt32 i = 0; i < nCount; i++)
{
xContainer->getByIndex(i) >>= xElement;
RemoveElement(xElement);
}
}
}
//------------------------------------------------------------------------------
void FmXFormShell::selectionChanged(const EventObject& rEvent) throw(::com::sun::star::uno::RuntimeException)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< ::com::sun::star::view::XSelectionSupplier> xSupplier(rEvent.Source, UNO_QUERY);
Any aSelObj( xSupplier->getSelection() );
if (aSelObj.getValueTypeClass() != TypeClass_INTERFACE)
return;
Reference< XInterface> xSelObj;
aSelObj >>= xSelObj;
// es wurde eine Selektion weggenommen, dieses kann nur durch die Shell vorgenommen werden
if (!xSelObj.is())
return;
Reference< XInterface> xPreviousObject( getSelObject());
EnableTrackProperties(sal_False);
sal_Bool bMarkChanged = m_pShell->GetFormView()->checkUnMarkAll(rEvent.Source);
Reference< XForm> xNewForm( GetForm(rEvent.Source));
setCurControl(xSelObj);
setCurForm(xNewForm);
// wurde vorher Form angezeigt, dann wieder die Form anzeigen
Reference< XForm> xOldForm(xPreviousObject, UNO_QUERY);
if (xOldForm.is())
setSelObject(m_xCurForm);
else
setSelObject(m_xCurControl);
if (IsPropBrwOpen() && m_xSelObject != xPreviousObject)
ShowProperties(m_xSelObject, sal_True);
EnableTrackProperties(sal_True);
if ( bMarkChanged )
m_pShell->NotifyMarkListChanged(m_pShell->GetFormView());
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnTimeOut, void*, EMPTYTAG)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (m_pShell->IsDesignMode() && m_pShell->GetFormView())
SetSelection(m_pShell->GetFormView()->GetMarkList());
return 0;
}
//------------------------------------------------------------------------
void FmXFormShell::SetSelectionDelayed(FmFormView* pView)
{
if (m_pShell->IsDesignMode() && IsTrackPropertiesEnabled() && !m_aMarkTimer.IsActive())
m_aMarkTimer.Start();
}
//------------------------------------------------------------------------
void FmXFormShell::SetSelection(const SdrMarkList& rMarkList)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DetermineSelection(rMarkList);
m_pShell->NotifyMarkListChanged(m_pShell->GetFormView());
}
//------------------------------------------------------------------------
void FmXFormShell::DetermineSelection(const SdrMarkList& rMarkList)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// Aktuelles Objekt setzen
Reference< XInterface> xPreviousObject( m_xSelObject);
sal_Bool bMixedWithFormControls = sal_True;
Reference< XForm> xNewForm( DetermineCurForm(rMarkList, bMixedWithFormControls));
// Aktuelle Form anpassen
if (xNewForm.is() || bMixedWithFormControls)
{
// die Form wird nur angepasst, wenn eine eindeutige From gefunden wurde oder eine gemischte Selektion existiert,
// die auch FormControls enthaelt (NICHT bei einer Selektion ohne solche oder bei leerer Selektion)
if ((XForm*)xNewForm.get() != (XForm*)m_xCurForm.get())
setCurForm( xNewForm );
}
setCurControl(rMarkList);
// wurde vorher Form angezeigt, dann wieder die Form anzeigen
Reference< XForm> xOldForm(m_xSelObject, UNO_QUERY);
if (xOldForm.is())
setSelObject(xNewForm);
else
setSelObject(m_xCurControl);
// Falls ein Propertybrowser angezeigt wird, diesen invalidieren
if (IsPropBrwOpen() && xPreviousObject != m_xSelObject)
ShowProperties(m_xSelObject, sal_True);
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::IsPropBrwOpen() const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
return( ( m_pShell->GetViewShell() && m_pShell->GetViewShell()->GetViewFrame() ) ?
m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES) : sal_False );
}
//------------------------------------------------------------------------------
class FmXFormShell::SuspendPropertyTracking
{
private:
FmXFormShell* m_pShell;
sal_Bool m_bEnabled;
public:
SuspendPropertyTracking( FmXFormShell* _pShell )
:m_pShell( _pShell )
,m_bEnabled( sal_False )
{
if ( m_pShell && m_pShell->IsTrackPropertiesEnabled() )
{
m_pShell->EnableTrackProperties( sal_False );
m_bEnabled = sal_True;
}
}
~SuspendPropertyTracking( )
{
if ( m_bEnabled ) // note that ( sal_False != m_bEnabled ) implies ( NULL != m_pShell )
m_pShell->EnableTrackProperties( sal_True );
}
};
//------------------------------------------------------------------------------
void FmXFormShell::SetDesignMode(sal_Bool bDesign)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(m_pShell && m_pShell->GetFormView(), "FmXFormShell::SetDesignMode : invalid call (have no shell or no view) !");
m_bChangingDesignMode = sal_True;
// 67506 - 15.07.99 - FS
// if we're switching off the design mode we have to force the property browser to be closed
// so it can commit it's changes _before_ we load the forms
if (!bDesign)
{
m_bHadPropBrw = m_pShell->GetViewShell()->GetViewFrame()->HasChildWindow(SID_FM_SHOW_PROPERTIES);
if (m_bHadPropBrw)
m_pShell->GetViewShell()->GetViewFrame()->ToggleChildWindow(SID_FM_SHOW_PROPERTIES);
}
FmFormView* pFormView = m_pShell->GetFormView();
if (bDesign)
{
// we are currently filtering, so stop filtering
if (m_bFilterMode)
stopFiltering(sal_False);
// an den Objekten meiner MarkList als Listener abmelden
pFormView->GetImpl()->stopMarkListWatching();
}
else
{
m_aMarkTimer.Stop();
SuspendPropertyTracking aSuspend( this );
pFormView->GetImpl()->saveMarkList( sal_True );
}
if (bDesign && m_xExternalViewController.is())
CloseExternalFormViewer();
pFormView->ChangeDesignMode(bDesign);
// Listener benachrichtigen
FmDesignModeChangedHint aChangedHint( bDesign );
m_pShell->Broadcast(aChangedHint);
FmFormPage* pPage = m_pShell->GetCurPage();
if (pPage)
{
if (bDesign)
{
Reference< XIndexAccess> xIndex(pPage->GetForms(), UNO_QUERY);
ResetForms(xIndex, sal_False);
}
else
ResetForms();
}
m_pShell->m_bDesignMode = bDesign;
if (bDesign)
{
SdrMarkList aList;
{
// during changing the mark list, don't track the selected objects in the property browser
SuspendPropertyTracking aSuspend( this );
// restore the marks
pFormView->GetImpl()->restoreMarkList( aList );
}
// synchronize with the restored mark list
if ( aList.GetMarkCount() )
SetSelection( aList );
}
else
{
// am Model der View als Listener anmelden (damit ich mitbekomme, wenn jemand waehrend des Alive-Modus
// Controls loescht, die ich eigentlich mit saveMarkList gespeichert habe) (60343)
pFormView->GetImpl()->startMarkListWatching();
}
m_pShell->UIFeatureChanged();
// 67506 - 15.07.99 - FS
if (bDesign && m_bHadPropBrw)
{
// The UIFeatureChanged performes an update (a check of the available features) asynchronously.
// So we can't call ShowProperties directly as the according feature isn't enabled yet.
// That's why we use an asynchron execution on the dispatcher.
// (And that's why this has to be done AFTER the UIFeatureChanged.)
FmInterfaceItem aInterfaceItem( SID_FM_SHOW_PROPERTY_BROWSER, getSelObject() );
m_pShell->GetViewShell()->GetViewFrame()->GetDispatcher()->Execute( SID_FM_SHOW_PROPERTY_BROWSER, SFX_CALLMODE_ASYNCHRON,
&aInterfaceItem, 0L );
}
m_bChangingDesignMode = sal_False;
}
//------------------------------------------------------------------------------
Reference< XControl> FmXFormShell::GetControlFromModel(const Reference< XControlModel>& xModel)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// die View ...
SdrPageView* pCurPageView = m_pShell->GetFormView()->GetPageViewPvNum(0);
// deren ViewWinRec-Liste, daraus das erste Element
DBG_ASSERT(pCurPageView->GetWinList().GetCount() > 0, "FmXFormShell::GetControlFromModel : unexpected : no SdrPageViewWinRecs");
const SdrPageViewWinRec& rViewWinRec = pCurPageView->GetWinList()[0];
// von dem bekomme ich alle Controls ...
Reference< XControlContainer> xControlContainer(rViewWinRec.GetControlContainerRef());
Sequence< Reference< XControl> > seqControls( xControlContainer->getControls() );
Reference< XControl>* pControls = seqControls.getArray();
// ... die ich dann durchsuchen kann
for (int i=0; i<seqControls.getLength(); ++i)
{
Reference< XControlModel> xSearchLoopModel( pControls[i]->getModel());
if ((XControlModel*)xSearchLoopModel.get() == (XControlModel*)xModel.get())
return pControls[i];
}
return Reference< XControl>(NULL);
}
//------------------------------------------------------------------------------
void FmXFormShell::CollectFormContexts(const Reference< XInterface>& xStartingPoint, const UniString& sCurrentLevelPrefix, UniString& sNames)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XIndexAccess> xAllComponentIndizies(xStartingPoint, UNO_QUERY);
if (xAllComponentIndizies.is() && xAllComponentIndizies->getCount())
{
// work through all children
UniString sCurrentFormName, sNextLevelPrefix;
Reference< XForm> xCurrentAsForm;
for (sal_Int32 i=0; i<xAllComponentIndizies->getCount(); ++i)
{
xAllComponentIndizies->getByIndex(i) >>= xCurrentAsForm;;
// is the current child a form?
if (xCurrentAsForm.is())
{
Reference< XPropertySet> xAskForName(xCurrentAsForm, UNO_QUERY);
if (xAskForName.is())
{
try { sCurrentFormName = ::comphelper::getString(xAskForName->getPropertyValue(FM_PROP_NAME)).getStr(); }
catch(Exception&)
{
DBG_ERROR("FmXFormShell::CollectFormContexts: Exception occured!");
}
}
// den Namen an die Aufzaehlung haengen
sNames += ';';
sNames += sCurrentFormName;
if (sCurrentLevelPrefix.Len() != 0)
{
sNames.AppendAscii(" (");
sNames += sCurrentLevelPrefix;
sNames += ')';
}
// den Prefix fuer den naechsten Level
sNextLevelPrefix = sCurrentLevelPrefix;
if (sCurrentLevelPrefix.Len() != 0)
sNextLevelPrefix += '/';
sNextLevelPrefix += sCurrentFormName;
// das Interface merken
m_arrSearchContexts.push_back(xCurrentAsForm);
// und absteigen
CollectFormContexts(xCurrentAsForm, sNextLevelPrefix, sNames);
}
}
}
}
//------------------------------------------------------------------------------
Reference< XPropertySet> FmXFormShell::GetBoundField(const Reference< XControl>& _xControl, const Reference< XForm>& _xForm) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// sonderbehandlung fuer databaseGrid
Reference< XGrid> xGrid(_xControl, UNO_QUERY);
Reference< XPropertySet> xModel, xField;
if (xGrid.is())
{
sal_Int16 nCurrentPos = xGrid->getCurrentColumnPosition();
Reference< XIndexAccess> xCols(_xControl->getModel(), UNO_QUERY);
nCurrentPos = GridView2ModelPos(xCols, nCurrentPos);
if (nCurrentPos != (sal_Int16)-1)
xCols->getByIndex(nCurrentPos) >>= xModel;
}
else if (_xControl.is())
{
xModel = Reference< XPropertySet>(_xControl->getModel(), UNO_QUERY);
}
// Das gebundene Feld ist jetzt eine extra Eigenschaft, nicht mehr indirekt ueber die ControlSource zu besorgen,
// da das Control selber durchaus entscheiden kann, dass es sich trotz gueltiger ControlSource nicht binden will.
// (zum Beispiel ein TextControl an ein Bild-Feld)
// (FS - 64265)
if (xModel.is() && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xModel))
xModel->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
return xField;
}
//------------------------------------------------------------------------------
//void FmXFormShell::SetWizardUsing(sal_Bool bUseThem)
//{
// OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
//
// m_bUseWizards = bUseThem;
//
// // forward this to the configuration
// Sequence< ::rtl::OUString > aNames(1);
// aNames[0] = ::rtl::OUString::createFromAscii("FormControlPilotsEnabled");
// Sequence< Any > aValues(1);
// aValues[0] = bool2any(m_bUseWizards);
// m_aWizardUsing.SetProperties(aNames, aValues);
//}
//------------------------------------------------------------------------------
void FmXFormShell::startFiltering()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
// setting all forms in filter mode
FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
// if the active controller is our external one we have to use the trigger controller
Reference< XControlContainer> xContainer;
if (getActiveController() == m_xExternalViewController)
{
DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but noone triggered this !");
xContainer = m_xExtViewTriggerController->getContainer();
}
else
xContainer = getActiveController()->getContainer();
FmWinRecList::iterator i = pXView->findWindow(xContainer);
if (i != pXView->getWindowList().end())
{
const ::std::vector< Reference< XFormController> >& rControllerList = (*i)->GetList();
for (::std::vector< Reference< XFormController> >::const_iterator j = rControllerList.begin();
j != rControllerList.end(); ++j)
{
Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
if (xModeSelector.is())
xModeSelector->setMode(FILTER_MODE);
}
}
m_bFilterMode = sal_True;
m_pShell->UIFeatureChanged();
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
}
//------------------------------------------------------------------------------
void saveFilter(const Reference< XFormController>& _rxController)
{
Reference< XPropertySet> xFormAsSet(_rxController->getModel(), UNO_QUERY);
Reference< XPropertySet> xControllerAsSet(_rxController, UNO_QUERY);
Reference< XIndexAccess> xControllerAsIndex(_rxController, UNO_QUERY);
// call the subcontroller
Reference< XFormController> xController;
for (sal_Int32 i = 0, nCount = xControllerAsIndex->getCount(); i < nCount; ++i)
{
xControllerAsIndex->getByIndex(i) >>= xController;
saveFilter(xController);
}
try
{
xFormAsSet->setPropertyValue(FM_PROP_FILTER_CRITERIA, xControllerAsSet->getPropertyValue(FM_PROP_FILTER_CRITERIA));
sal_Bool bB(sal_True);
xFormAsSet->setPropertyValue(FM_PROP_APPLYFILTER, Any(&bB,getBooleanCppuType()));
}
catch(Exception&)
{
DBG_ERROR("saveFilter: Exception occured!");
}
}
//------------------------------------------------------------------------------
void FmXFormShell::stopFiltering(sal_Bool bSave)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
m_bFilterMode = sal_False;
FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
// if the active controller is our external one we have to use the trigger controller
Reference< XControlContainer> xContainer;
if (getActiveController() == m_xExternalViewController)
{
DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but noone triggered this !");
xContainer = m_xExtViewTriggerController->getContainer();
}
else
xContainer = getActiveController()->getContainer();
FmWinRecList::iterator i = pXView->findWindow(xContainer);
if (i != pXView->getWindowList().end())
{
const ::std::vector< Reference< XFormController> >& rControllerList = (*i)->GetList();
::std::vector < ::rtl::OUString > aOriginalFilters;
::std::vector < sal_Bool > aOriginalApplyFlags;
if (bSave)
{
for (::std::vector< Reference< XFormController> > ::const_iterator j = rControllerList.begin();
j != rControllerList.end(); ++j)
{
if (bSave)
{ // remember the current filter settings in case we're goin to reload the forms below (which may fail)
try
{
Reference< XPropertySet > xFormAsSet((*j)->getModel(), UNO_QUERY);
aOriginalFilters.push_back(::comphelper::getString(xFormAsSet->getPropertyValue(FM_PROP_FILTER_CRITERIA)));
aOriginalApplyFlags.push_back(::comphelper::getBOOL(xFormAsSet->getPropertyValue(FM_PROP_APPLYFILTER)));
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::stopFiltering : could not get the original filter !");
// put dummies into the arrays so the they have the right size
if (aOriginalFilters.size() == aOriginalApplyFlags.size())
// the first getPropertyValue failed -> use two dummies
aOriginalFilters.push_back( ::rtl::OUString() );
aOriginalApplyFlags.push_back( sal_False );
}
}
saveFilter(*j);
}
}
for (::std::vector< Reference< XFormController> > ::const_iterator j = rControllerList.begin();
j != rControllerList.end(); ++j)
{
Reference< XModeSelector> xModeSelector(*j, UNO_QUERY);
if (xModeSelector.is())
xModeSelector->setMode(DATA_MODE);
}
if (bSave) // execute the filter
{
const ::std::vector< Reference< XFormController> > & rControllerList = (*i)->GetList();
for (::std::vector< Reference< XFormController> > ::const_iterator j = rControllerList.begin();
j != rControllerList.end(); ++j)
{
Reference< XLoadable> xReload((*j)->getModel(), UNO_QUERY);
if (!xReload.is())
continue;
Reference< XPropertySet > xFormSet(xReload, UNO_QUERY);
try
{
xReload->reload();
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::stopFiltering: Exception occured!");
}
if (!isRowSetAlive(xFormSet))
{ // something went wrong -> restore the original state
::rtl::OUString sOriginalFilter = aOriginalFilters[ j - rControllerList.begin() ];
sal_Bool bOriginalApplyFlag = aOriginalApplyFlags[ j - rControllerList.begin() ];
try
{
xFormSet->setPropertyValue(FM_PROP_FILTER_CRITERIA, makeAny(sOriginalFilter));
xFormSet->setPropertyValue(FM_PROP_APPLYFILTER, makeAny(bOriginalApplyFlag));
xReload->reload();
}
catch(Exception&)
{
DBG_ERROR("FmXFormShell::stopFiltering: Exception occured!");
}
}
}
}
}
m_pShell->UIFeatureChanged();
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().InvalidateShell(*m_pShell);
}
//------------------------------------------------------------------------------
void clearFilter(const Reference< XFormController>& _rxController)
{
Reference< XPropertySet> xControllerAsSet(_rxController, UNO_QUERY);
Reference< XIndexAccess> xControllerAsIndex(_rxController, UNO_QUERY);
// call the subcontroller
Reference< XFormController> xController;
for (sal_Int32 i = 0, nCount = xControllerAsIndex->getCount();
i < nCount; i++)
{
xControllerAsIndex->getByIndex(i) >>= xController;
clearFilter(xController);
}
// clear the filter
Reference< XIndexContainer> xContainer;
xControllerAsSet->getPropertyValue(FM_PROP_FILTERSUPPLIER) >>= xContainer;
if (xContainer.is())
{
// clear the current filter
Sequence< PropertyValue> aCondition;
// as there is always an empty row, if we have a filter:
if (xContainer->getCount())
{
xControllerAsSet->setPropertyValue(FM_PROP_CURRENTFILTER, makeAny(sal_Int32(xContainer->getCount() - 1)));
while (xContainer->getCount() > 1)
xContainer->removeByIndex(0);
}
}
}
//------------------------------------------------------------------------------
void FmXFormShell::clearFilter()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
FmXFormView* pXView = m_pShell->GetFormView()->GetImpl();
// if the active controller is our external one we have to use the trigger controller
Reference< XControlContainer> xContainer;
if (getActiveController() == m_xExternalViewController)
{
DBG_ASSERT(m_xExtViewTriggerController.is(), "FmXFormShell::startFiltering : inconsistent : active external controller, but noone triggered this !");
xContainer = m_xExtViewTriggerController->getContainer();
}
else
xContainer = getActiveController()->getContainer();
FmWinRecList::iterator i = pXView->findWindow(xContainer);
if (i != pXView->getWindowList().end())
{
const ::std::vector< Reference< XFormController> > & rControllerList = (*i)->GetList();
for (::std::vector< Reference< XFormController> > ::const_iterator j = rControllerList.begin();
j != rControllerList.end(); ++j)
{
::clearFilter(*j);
}
}
}
//------------------------------------------------------------------------------
void FmXFormShell::setControlLocks()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XTabController> xCtrler(getActiveController(), UNO_QUERY);
if (!xCtrler.is())
return;
Reference< XControlContainer> xControls(xCtrler->getContainer(), UNO_QUERY);
if (!xControls.is())
return;
DBG_ASSERT(m_aControlLocks.Count() == 0, "FmXFormShell::setControlLocks : locking state array isn't empty (called me twice ?) !");
Sequence< Reference< XControl> > aControls = xControls->getControls();
const Reference< XControl>* pControls = aControls.getConstArray();
// iterate through all bound controls, remember the old locking state, set the lock
for (sal_Int32 i=0; i<aControls.getLength(); ++i)
{
Reference< XBoundControl> xCtrl(pControls[i], UNO_QUERY);
if (!xCtrl.is())
{
// it may be a container of controls
Reference< XIndexAccess> xContainer(pControls[i], UNO_QUERY);
if (xContainer.is())
{ // no recursion. we only know top level control containers (e.g. grid controls)
for (sal_Int16 i=0; i<xContainer->getCount(); ++i)
{
xContainer->getByIndex(i) >>= xCtrl;
if (!xCtrl.is())
continue;
m_aControlLocks.Insert(xCtrl->getLock(), m_aControlLocks.Count());
xCtrl->setLock(sal_True);
}
}
continue;
}
m_aControlLocks.Insert(xCtrl->getLock(), m_aControlLocks.Count());
xCtrl->setLock(sal_True);
}
}
//------------------------------------------------------------------------------
void FmXFormShell::restoreControlLocks()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
Reference< XTabController> xCtrler(getActiveController(), UNO_QUERY);
if (!xCtrler.is())
return;
Reference< XControlContainer> xControls(xCtrler->getContainer(), UNO_QUERY);
if (!xControls.is())
return;
Sequence< Reference< XControl> > aControls(xControls->getControls());
const Reference< XControl>* pControls = aControls.getConstArray();
// iterate through all bound controls, restore the old locking state
sal_Int32 nBoundControl = 0;
for (sal_Int32 i=0; i<aControls.getLength(); ++i)
{
Reference< XBoundControl> xCtrl(pControls[i], UNO_QUERY);
if (!xCtrl.is())
{
// it may be a container of controls
Reference< XIndexAccess> xContainer(pControls[i], UNO_QUERY);
if (xContainer.is())
{ // no recursion. we only know top level control containers (e.g. grid controls)
for (sal_Int16 i=0; i<xContainer->getCount(); ++i)
{
xContainer->getByIndex(i) >>= xCtrl;
if (!xCtrl.is())
continue;
DBG_ASSERT(nBoundControl < m_aControlLocks.Count(), "FmXFormShell::restoreControlLocks : m_aControlLocks is invalid !");
xCtrl->setLock(m_aControlLocks.GetObject((sal_uInt16)nBoundControl));
++nBoundControl;
}
}
continue;
}
DBG_ASSERT(nBoundControl < m_aControlLocks.Count(), "FmXFormShell::restoreControlLocks : m_aControlLocks is invalid !");
// a violation of this condition would mean a) setControlLocks hasn't been called or b) the ControlContainer
// has changed since the last call to setControlLocks.
// a) clearly is a fault of the programmer and b) shouldn't be possible (as we are in alive mode)
xCtrl->setLock(m_aControlLocks.GetObject((sal_uInt16)nBoundControl));
++nBoundControl;
}
m_aControlLocks.Remove(0, m_aControlLocks.Count());
}
//------------------------------------------------------------------------------
void FmXFormShell::DoAsyncCursorAction(const Reference< XFormController>& _xController, CURSOR_ACTION _eWhat)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(_xController.is(), "FmXFormShell::DoAsyncCursorAction : invalid argument !");
DoAsyncCursorAction(Reference< XResultSet>(_xController->getModel(), UNO_QUERY), _eWhat);
}
//------------------------------------------------------------------------------
void FmXFormShell::DoAsyncCursorAction(const Reference< XResultSet>& _xForm, CURSOR_ACTION _eWhat)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aAsyncSafety);
DBG_ASSERT(_xForm.is(), "FmXFormShell::DoAsyncCursorAction : invalid argument !");
// get the id of the page the form belongs to
UniString sFormPageId = GetPageId(_xForm);
DBG_ASSERT(sFormPageId.Len(), "FmXFormShell::DoAsyncCursorAction : could not ::std::find the page the form belongs to !");
// build the access path for the form
if (HasPendingCursorAction(_xForm))
{
DBG_ERROR("FmXFormShell::DoAsyncCursorAction : invalid call !");
return;
}
UniString sPath = GetAccessPathFromForm(_xForm, sFormPageId);
DBG_ASSERT(sPath.Len(), "FmXFormShell::DoAsyncCursorAction : could not ::std::find a page for the form !");
CursorActionDescription& rDesc = m_aCursorActions[sPath];
// [] will create a new one if non-existent
DBG_ASSERT(rDesc.pThread == NULL, "FmXFormShell::DoAsyncCursorAction : the cursor action thread for this form is still alive !");
Reference< XResultSet> xCursor(getInternalForm(_xForm), UNO_QUERY);
switch (_eWhat)
{
case CA_MOVE_TO_LAST :
rDesc.pThread = new FmMoveToLastThread(xCursor, sPath);
break;
case CA_MOVE_ABSOLUTE:
DBG_ERROR("FmXFormShell::DoAsyncCursorAction : CA_MOVE_ABSOLUTE not supported yet !");
return;
}
rDesc.pThread->SetTerminationHdl(LINK(this, FmXFormShell, OnCursorActionDone));
rDesc.pThread->EnableSelfDelete(sal_False);
rDesc.bCanceling = sal_False;
// set the control locks before starting the thread
DBG_ASSERT(getInternalForm(m_xActiveForm) == m_xActiveForm, "FmXFormShell::DoAsyncCursorAction : the active form should always be a internal one !");
if (getInternalForm(_xForm) == m_xActiveForm)
setControlLocks();
// go ...
rDesc.pThread->create();
// set a priority slightly below normal
rDesc.pThread->setPriority(::vos::OThread::TPriority_BelowNormal);
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::HasPendingCursorAction(const UniString& _rAccessPath) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(((FmXFormShell*)this)->m_aAsyncSafety);
for ( ConstCursorActionsIterator aIter = m_aCursorActions.begin();
aIter != m_aCursorActions.end();
++aIter
)
{
if (!(*aIter).second.pThread && !(*aIter).second.nFinishedEvent)
continue;
UniString sThisThreadPath = (*aIter).second.pThread->getAccessPath();
// we have found a running thread. it blocks the form given by the access path if
// one of the two forms (the thread's or the given) is an anestor of the other
// this is the case if and only if one path is a prefix of the other
if (PathsInterfere(sThisThreadPath, _rAccessPath))
return sal_True;
}
return sal_False;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::HasPendingCursorAction(const Reference< XResultSet>& _xForm) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (!_xForm.is())
return sal_False;
return HasPendingCursorAction(GetAccessPathFromForm(_xForm, GetPageId(_xForm)));
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::HasPendingCursorAction(const Reference< XFormController>& xController) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
if (!xController.is())
return sal_False;
return HasPendingCursorAction(Reference< XResultSet>(xController->getModel(), UNO_QUERY));
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::HasAnyPendingCursorAction() const
{
::osl::MutexGuard aGuard(((FmXFormShell*)this)->m_aAsyncSafety);
for (ConstCursorActionsIterator aIter = m_aCursorActions.begin(); aIter != m_aCursorActions.end(); ++aIter)
{
if (((*aIter).second.pThread != NULL) || ((*aIter).second.nFinishedEvent != 0))
return sal_True;
}
return sal_False;
}
//------------------------------------------------------------------------------
void FmXFormShell::CancelAnyPendingCursorAction()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::comphelper::OReusableGuard< ::osl::Mutex> aGuard(m_aAsyncSafety);
CursorActionsIterator aIter;
for (aIter = m_aCursorActions.begin(); aIter != m_aCursorActions.end(); ++aIter)
{
if (!(*aIter).second.nFinishedEvent && (*aIter).second.pThread)
{ // the thread is really running
(*aIter).second.bCanceling = sal_True;
aGuard.clear();
(*aIter).second.pThread->StopItWait();
// StopItWait returns after the termination handler (our OnCursorActionDone) has been called
aGuard.attach(m_aAsyncSafety);
}
}
// all threads are finished (means canceled), now do the cleanup
for (aIter = m_aCursorActions.begin(); aIter != m_aCursorActions.end(); ++aIter)
{
if ((*aIter).second.pThread)
{
LINK(this, FmXFormShell, OnCursorActionDoneMainThread).Call((*aIter).second.pThread);
DBG_ASSERT((*aIter).second.pThread == NULL, "FmXFormShell::CancelAnyPendingCursorAction : strange behaviour of OnCursorActionDoneMainThread !");
}
}
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnCursorActionDone, FmCursorActionThread*, pThread)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aAsyncSafety);
// search the pos of the thread within m_aCursorActions
CursorActionsIterator aIter;
for (aIter = m_aCursorActions.begin(); aIter != m_aCursorActions.end(); ++aIter)
{
if ((*aIter).second.pThread == pThread)
break;
}
DBG_ASSERT(aIter != m_aCursorActions.end(), "FmXFormShell::OnCursorActionDone : could not ::std::find the thread !");
DBG_ASSERT((*aIter).second.nFinishedEvent == 0, "FmXFormShell::OnCursorActionDone : another 'ActionDone' for this thread is pending !");
// as we allow only one async action at a time (per form) this shouldn't happen
if (!(*aIter).second.bCanceling)
(*aIter).second.nFinishedEvent = Application::PostUserEvent(LINK(this, FmXFormShell, OnCursorActionDoneMainThread), pThread);
// if bCanceling is sal_True an other thread's execution is in CancelAnyPendingCursorAction
return 0L;
}
//------------------------------------------------------------------------------
sal_Bool FmXFormShell::PathsInterfere(const UniString& _rPathLeft, const UniString& _rPathRight) const
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
return ((_rPathLeft.Search(_rPathRight) == 0) || (_rPathRight.Search(_rPathLeft) == 0));
}
//------------------------------------------------------------------------------
IMPL_LINK(FmXFormShell, OnCursorActionDoneMainThread, FmCursorActionThread*, pThread)
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
::osl::MutexGuard aGuard(m_aAsyncSafety);
// search the pos of the thread within m_aCursorActions
CursorActionsIterator aIter = m_aCursorActions.find(pThread->getAccessPath());
DBG_ASSERT(aIter != m_aCursorActions.end(), "FmXFormShell::OnCursorActionDoneMainThread : could not ::std::find the thread data !");
DBG_ASSERT((*aIter).second.pThread == pThread, "FmXFormShell::OnCursorActionDoneMainThread : invalid thread data !");
// remember some thread parameters
UniString sPath = pThread->getAccessPath();
Reference< XResultSet> xForm(pThread->getDataSource(), UNO_QUERY);
// throw away the thread
delete (*aIter).second.pThread;
(*aIter).second.pThread = NULL;
(*aIter).second.nFinishedEvent = 0;
(*aIter).second.bCanceling = sal_False;
// as we allow exactly one thread per form we may remove this ones data from m_aCursorActions
m_aCursorActions.erase(aIter);
// there may be several dispatchers affected (one async move locks not only the form itself, but all forms
// which are an ancestor or a child)
// -> update their status
UpdateAllFormDispatchers(sPath);
DBG_ASSERT(getInternalForm(m_xActiveForm) == m_xActiveForm, "FmXFormShell::DoAsyncCursorAction : the active form should always be a internal one !");
DBG_ASSERT(getInternalForm(xForm) == xForm, "FmXFormShell::DoAsyncCursorAction : the thread's form should always be a internal one !");
// if one of the two asserts above fails the upcoming comparison is senseless
if (xForm == m_xActiveForm)
{
// the active controller belongs to the form where the action is finished
// -> re-enable the controls if they are not locked because of another running thread
if (!HasPendingCursorAction(xForm))
restoreControlLocks();
}
m_pShell->GetViewShell()->GetViewFrame()->GetBindings().Invalidate(DatabaseSlotMap);
// it may not be neccessary but me thinks it's faster without the check if we really have to do this
return 0L;
}
//------------------------------------------------------------------------------
void FmXFormShell::CreateExternalView()
{
OSL_ENSURE(!FmXFormShell_BASE::rBHelper.bDisposed,"FmXFormShell: Object already disposed!");
DBG_ASSERT(m_xAttachedFrame.is(), "FmXFormShell::CreateExternalView : no frame !");
// the frame the external view is displayed in
sal_Bool bAlreadyExistent = m_xExternalViewController.is();
Reference< ::com::sun::star::frame::XFrame> xExternalViewFrame;
::rtl::OUString sFrameName = ::rtl::OUString::createFromAscii("_beamer");
sal_Int32 nSearchFlags = ::com::sun::star::frame::FrameSearchFlag::CHILDREN | ::com::sun::star::frame::FrameSearchFlag::CREATE;
Reference< XFormController> xCurrentNavController( getNavController());
// the creation of the "partwindow" may cause a deactivate of the document which will result in our nav controller to be set to NULL
// _first_ check if we have any valid fields we can use for the grid view
// FS - 21.10.99 - 69219
FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
Reference< XPropertySet> xCurrentModelSet;
sal_Bool bHaveUsableControls = sal_False;
while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
{
// the FmXBoundFormFieldIterator only supplies controls with a valid control source
// so we just have to check the field type
sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
switch (nClassId)
{
case FormComponentType::IMAGECONTROL:
case FormComponentType::CONTROL:
continue;
}
bHaveUsableControls = sal_True;
break;
}
if (!bHaveUsableControls)
{
ErrorBox(NULL, WB_OK, SVX_RESSTR(RID_STR_NOCONTROLS_FOR_EXTERNALDISPLAY)).Execute();
return;
}
// load the component for external form views
if (!bAlreadyExistent)
{
URL aWantToDispatch;
aWantToDispatch.Complete = FMURL_COMPONENT_FORMGRIDVIEW;
Reference< ::com::sun::star::frame::XDispatchProvider> xProv(m_xAttachedFrame, UNO_QUERY);
Reference< ::com::sun::star::frame::XDispatch> xDisp;
if (xProv.is())
xDisp = xProv->queryDispatch(aWantToDispatch, sFrameName, nSearchFlags);
if (xDisp.is())
{
xDisp->dispatch(aWantToDispatch, Sequence< PropertyValue>());
}
// with this the component should be loaded, now search the frame where it resides in
xExternalViewFrame = m_xAttachedFrame->findFrame(sFrameName, ::com::sun::star::frame::FrameSearchFlag::CHILDREN);
if (xExternalViewFrame.is())
{
m_xExternalViewController = xExternalViewFrame->getController();
Reference< ::com::sun::star::lang::XComponent> xComp(m_xExternalViewController, UNO_QUERY);
if (xComp.is())
xComp->addEventListener((XEventListener*)(XPropertyChangeListener*)this);
}
}
else
{
xExternalViewFrame = m_xExternalViewController->getFrame();
Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
// if we display the active form we interpret the slot as "remove it"
Reference< XForm> xCurrentModel(xCurrentNavController->getModel(), UNO_QUERY);
if ((xCurrentModel == m_xExternalDisplayedForm) || (getInternalForm(xCurrentModel) == m_xExternalDisplayedForm))
{
if (m_xExternalViewController == getActiveController())
CommitCurrent(Reference< XFormController>(m_xExternalViewController, UNO_QUERY));
Reference< XFormController> xNewController(m_xExtViewTriggerController);
CloseExternalFormViewer();
setActiveController(xNewController);
return;
}
URL aClearURL;
aClearURL.Complete = FMURL_GRIDVIEW_CLEARVIEW;
Reference< ::com::sun::star::frame::XDispatch> xClear( xCommLink->queryDispatch(aClearURL, ::rtl::OUString::createFromAscii(""), 0));
if (xClear.is())
xClear->dispatch(aClearURL, Sequence< PropertyValue>());
}
// interception of slots of the external view
if (m_pExternalViewInterceptor)
{ // already intercepting ...
if (m_pExternalViewInterceptor->getIntercepted() != xExternalViewFrame)
{ // ... but another frame -> create a new interceptor
m_pExternalViewInterceptor->dispose();
m_pExternalViewInterceptor->release();
m_pExternalViewInterceptor = NULL;
}
}
if (!m_pExternalViewInterceptor)
{
Reference< ::com::sun::star::frame::XDispatchProviderInterception> xSupplier(xExternalViewFrame, UNO_QUERY);
::rtl::OUString sInterceptorScheme = FMURL_FORMSLOTS_PREFIX;
sInterceptorScheme += ::rtl::OUString::createFromAscii("*");
m_pExternalViewInterceptor = new FmXDispatchInterceptorImpl(xSupplier, this, 1, Sequence< ::rtl::OUString >(&sInterceptorScheme, 1));
m_pExternalViewInterceptor->acquire();
}
// get the dispatch interface of the frame so we can communicate (interceptable) with the controller
Reference< ::com::sun::star::frame::XDispatchProvider> xCommLink(xExternalViewFrame, UNO_QUERY);
if (m_xExternalViewController.is())
{
DBG_ASSERT(xCommLink.is(), "FmXFormShell::CreateExternalView : the component doesn't have the necessary interfaces !");
// collect the dispatchers we will need
URL aAddColumnURL;
aAddColumnURL.Complete = FMURL_GRIDVIEW_ADDCOLUMN;
Reference< ::com::sun::star::frame::XDispatch> xAddColumnDispatch( xCommLink->queryDispatch(aAddColumnURL, ::rtl::OUString::createFromAscii(""), 0));
URL aAttachURL;
aAttachURL.Complete = FMURL_GRIDVIEW_ATTACHTOFORM;
Reference< ::com::sun::star::frame::XDispatch> xAttachDispatch( xCommLink->queryDispatch(aAttachURL, ::rtl::OUString::createFromAscii(""), 0));
if (xAddColumnDispatch.is() && xAttachDispatch.is())
{
DBG_ASSERT(xCurrentNavController.is(), "FmXFormShell::CreateExternalView : invalid call : have no nav controller !");
// first : dispatch the descriptions for the columns to add
Sequence< Reference< XControl> > aCurrentControls(xCurrentNavController->getControls());
const Reference< XControl>* pCurrentControl = aCurrentControls.getConstArray();
sal_Int16 nAddedColumns = 0;
// for radio buttons we need some special structures
DECLARE_STL_USTRINGACCESS_MAP(Sequence< ::rtl::OUString>, MapUString2UstringSeq);
DECLARE_STL_ITERATORS(MapUString2UstringSeq);
DECLARE_STL_USTRINGACCESS_MAP(::rtl::OUString, FmMapUString2UString);
DECLARE_STL_USTRINGACCESS_MAP(sal_Int16, FmMapUString2Int16);
DECLARE_STL_ITERATORS(FmMapUString2Int16);
MapUString2UstringSeq aRadioValueLists;
MapUString2UstringSeq aRadioListSources;
FmMapUString2UString aRadioControlSources;
FmMapUString2Int16 aRadioPositions;
FmXBoundFormFieldIterator aModelIterator(xCurrentNavController->getModel());
Reference< XPropertySet> xCurrentModelSet;
Any aCurrentBoundField;
::rtl::OUString sColumnType,aGroupName,sControlSource;
Sequence< Property> aProps;
Reference< XPropertySet> xCurrentBoundField;
while ((xCurrentModelSet = Reference< XPropertySet>(aModelIterator.Next(), UNO_QUERY)).is())
{
xCurrentModelSet->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xCurrentBoundField;
OSL_ENSURE(xCurrentModelSet.is(),"xCurrentModelSet is null!");
// create a description of the column to be created
// first : determine it's type
sal_Int16 nClassId = ::comphelper::getINT16(xCurrentModelSet->getPropertyValue(FM_PROP_CLASSID));
switch (nClassId)
{
case FormComponentType::RADIOBUTTON:
{
// get the label of the button (this is the access key for our structures)
aGroupName = getLabelName(xCurrentModelSet);
// add the reference value of the radio button to the list source sequence
Sequence< ::rtl::OUString>& aThisGroupLabels = aRadioListSources[aGroupName];
sal_Int32 nNewSizeL = aThisGroupLabels.getLength() + 1;
aThisGroupLabels.realloc(nNewSizeL);
aThisGroupLabels.getArray()[nNewSizeL - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_REFVALUE));
// add the label to the value list sequence
Sequence< ::rtl::OUString>& aThisGroupControlSources = aRadioValueLists[aGroupName];
sal_Int32 nNewSizeC = aThisGroupControlSources.getLength() + 1;
aThisGroupControlSources.realloc(nNewSizeC);
aThisGroupControlSources.getArray()[nNewSizeC - 1] = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_LABEL));
// remember the controls source of the radio group
sControlSource = ::comphelper::getString(xCurrentModelSet->getPropertyValue(FM_PROP_CONTROLSOURCE));
if (aRadioControlSources.find(aGroupName) == aRadioControlSources.end())
aRadioControlSources[aGroupName] = sControlSource;
#ifdef DBG_UTIL
else
DBG_ASSERT(aRadioControlSources[aGroupName] == sControlSource,
"FmXFormShell::CreateExternalView : inconsistent radio buttons detected !");
// (radio buttons with the same name should have the same control source)
#endif
// remember the position within the columns
if (aRadioPositions.find(aGroupName) == aRadioPositions.end())
aRadioPositions[aGroupName] = (sal_Int16)nAddedColumns;
// any further handling is done below
continue;
}
break;
case FormComponentType::IMAGECONTROL:
case FormComponentType::CONTROL:
// no grid columns for these types (though they have a control source)
continue;
case FormComponentType::CHECKBOX:
sColumnType = FM_COL_CHECKBOX; break;
case FormComponentType::LISTBOX:
sColumnType = FM_COL_LISTBOX; break;
case FormComponentType::COMBOBOX:
sColumnType = FM_COL_COMBOBOX; break;
case FormComponentType::DATEFIELD:
sColumnType = FM_COL_DATEFIELD; break;
case FormComponentType::TIMEFIELD:
sColumnType = FM_COL_TIMEFIELD; break;
case FormComponentType::NUMERICFIELD:
sColumnType = FM_COL_NUMERICFIELD; break;
case FormComponentType::CURRENCYFIELD:
sColumnType = FM_COL_CURRENCYFIELD; break;
case FormComponentType::PATTERNFIELD:
sColumnType = FM_COL_PATTERNFIELD; break;
case FormComponentType::TEXTFIELD:
{
sColumnType = FM_COL_TEXTFIELD;
// we know at least two different controls which are TextFields : the basic edit field and the formatted
// field. we distinguish them by their service name
Reference< XServiceInfo> xInfo(xCurrentModelSet, UNO_QUERY);
if (xInfo.is())
{
sal_Int16 nObjectType = getControlTypeByObject(xInfo);
if (OBJ_FM_FORMATTEDFIELD == nObjectType)
sColumnType = FM_COL_FORMATTEDFIELD;
}
}
break;
default:
sColumnType = FM_COL_TEXTFIELD; break;
}
const sal_Int16 nDispatchArgs = 3;
Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
// properties describing "meta data" about the column
// the type
pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
pDispatchArgs->Value <<= sColumnType;
++pDispatchArgs;
// the pos : append the col
pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
pDispatchArgs->Value <<= nAddedColumns;
++pDispatchArgs;
// the properties to forward to the new column
Sequence< PropertyValue> aColumnProps(1);
PropertyValue* pColumnProps = aColumnProps.getArray();
// the label
pColumnProps->Name = FM_PROP_LABEL;
pColumnProps->Value <<= getLabelName(xCurrentModelSet);
++pColumnProps;
// for all other props : transfer them
Reference< XPropertySetInfo> xControlModelInfo( xCurrentModelSet->getPropertySetInfo());
DBG_ASSERT(xControlModelInfo.is(), "FmXFormShell::CreateExternalView : the control model has no property info ! This will crash !");
aProps = xControlModelInfo->getProperties();
const Property* pProps = aProps.getConstArray();
// realloc the control description sequence
sal_Int32 nExistentDescs = pColumnProps - aColumnProps.getArray();
aColumnProps.realloc(nExistentDescs + aProps.getLength());
pColumnProps = aColumnProps.getArray() + nExistentDescs;
for (sal_Int32 i=0; i<aProps.getLength(); ++i, ++pProps)
{
if (pProps->Name.equals(FM_PROP_LABEL))
// already set
continue;
if (pProps->Name.equals(FM_PROP_DEFAULTCONTROL))
// allow the column's own "default control"
continue;
if (pProps->Attributes & PropertyAttribute::READONLY)
// assume that properties which are readonly for the control are ro for the column to be created, too
continue;
pColumnProps->Name = pProps->Name;
pColumnProps->Value = xCurrentModelSet->getPropertyValue(pProps->Name);
++pColumnProps;
}
aColumnProps.realloc(pColumnProps - aColumnProps.getArray());
// columns props are a dispatch argument
pDispatchArgs->Name = ::rtl::OUString::createFromAscii("ColumnProperties"); // TODO : fmurl.*
pDispatchArgs->Value = makeAny(aColumnProps);
++pDispatchArgs;
DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
"FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
// dispatch the "add column"
xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
++nAddedColumns;
}
// now for the radio button handling
sal_Int16 nOffset(0);
// properties describing the "direct" column properties
const sal_Int16 nListBoxDescription = 6;
Sequence< PropertyValue> aListBoxDescription(nListBoxDescription);
for ( ConstFmMapUString2UStringIterator aCtrlSource = aRadioControlSources.begin();
aCtrlSource != aRadioControlSources.end();
++aCtrlSource, ++nOffset
)
{
PropertyValue* pListBoxDescription = aListBoxDescription.getArray();
// label
pListBoxDescription->Name = FM_PROP_LABEL;
pListBoxDescription->Value <<= (*aCtrlSource).first;
++pListBoxDescription;
// control source
pListBoxDescription->Name = FM_PROP_CONTROLSOURCE;
pListBoxDescription->Value <<= (*aCtrlSource).second;
++pListBoxDescription;
// bound column
pListBoxDescription->Name = FM_PROP_BOUNDCOLUMN;
pListBoxDescription->Value <<= (sal_Int16)1;
++pListBoxDescription;
// content type
pListBoxDescription->Name = FM_PROP_LISTSOURCETYPE;
ListSourceType eType = ListSourceType_VALUELIST;
pListBoxDescription->Value = makeAny(eType);
++pListBoxDescription;
// list source
MapUString2UstringSeq::const_iterator aCurrentListSource = aRadioListSources.find((*aCtrlSource).first);
DBG_ASSERT(aCurrentListSource != aRadioListSources.end(),
"FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
pListBoxDescription->Name = FM_PROP_LISTSOURCE;
pListBoxDescription->Value = makeAny((*aCurrentListSource).second);
++pListBoxDescription;
// value list
MapUString2UstringSeq::const_iterator aCurrentValueList = aRadioValueLists.find((*aCtrlSource).first);
DBG_ASSERT(aCurrentValueList != aRadioValueLists.end(),
"FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
pListBoxDescription->Name = FM_PROP_STRINGITEMLIST;
pListBoxDescription->Value = makeAny(((*aCurrentValueList).second));
++pListBoxDescription;
DBG_ASSERT(nListBoxDescription == (pListBoxDescription - aListBoxDescription.getConstArray()),
"FmXFormShell::CreateExternalView : forgot to adjust nListBoxDescription ?");
// properties describing the column "meta data"
const sal_Int16 nDispatchArgs = 3;
Sequence< PropertyValue> aDispatchArgs(nDispatchArgs);
PropertyValue* pDispatchArgs = aDispatchArgs.getArray();
// column type : listbox
pDispatchArgs->Name = FMARG_ADDCOL_COLUMNTYPE;
::rtl::OUString fColName = FM_COL_LISTBOX;
pDispatchArgs->Value <<= fColName;
// pDispatchArgs->Value <<= (::rtl::OUString)FM_COL_LISTBOX;
++pDispatchArgs;
// column position
pDispatchArgs->Name = FMARG_ADDCOL_COLUMNPOS;
FmMapUString2Int16::const_iterator aOffset = aRadioPositions.find((*aCtrlSource).first);
DBG_ASSERT(aOffset != aRadioPositions.end(),
"FmXFormShell::CreateExternalView : inconsistent radio descriptions !");
sal_Int16 nPosition = (*aOffset).second;
nPosition += nOffset;
// we alread inserted nOffset additinal columns ....
pDispatchArgs->Value <<= nPosition;
++pDispatchArgs;
// the
pDispatchArgs->Name = ::rtl::OUString::createFromAscii("ColumnProperties"); // TODO : fmurl.*
pDispatchArgs->Value = makeAny(aListBoxDescription);
++pDispatchArgs;
DBG_ASSERT(nDispatchArgs == (pDispatchArgs - aDispatchArgs.getConstArray()),
"FmXFormShell::CreateExternalView : forgot to adjust nDispatchArgs ?");
// dispatch the "add column"
xAddColumnDispatch->dispatch(aAddColumnURL, aDispatchArgs);
++nAddedColumns;
}
DBG_ASSERT(nAddedColumns > 0, "FmXFormShell::CreateExternalView : no controls (inconsistent) !");
// we should have checked if we have any usable controls (see above).
// "load" the "form" of the external view
PropertyValue aArg;
aArg.Name = FMARG_ATTACHTO_MASTERFORM;
Reference< XResultSet> xForm(xCurrentNavController->getModel(), UNO_QUERY);
aArg.Value <<= xForm;
m_xExternalDisplayedForm = Reference< XResultSet>(xForm, UNO_QUERY);
// do this before dispatching the "attach" command, as the atach may result in a call to our queryDispatch (for the FormSlots)
// whichs needs the m_xExternalDisplayedForm
xAttachDispatch->dispatch(aAttachURL, Sequence< PropertyValue>(&aArg, 1));
m_xExtViewTriggerController = xCurrentNavController;
// we want to know modifications done in the external view
// if the external controller is a XFormController we can use all our default handlings for it
Reference< XFormController> xFormController(m_xExternalViewController, UNO_QUERY);
if (xFormController.is())
xFormController->addActivateListener((XFormControllerListener*)this);
// finally, do an update for all dispatchers of the form which we has displayed in the external
// browser
//
// This is a slight hack. The timeline when dispatching and loading this external form
// is somewhat bad, it results in a grid in this form which has invalid status information
// for the slots we're intercepting (moveNext and such).
// Instead of creating complex workarounds (which I cannot imagine at the moment), we
// force an update of the dispatchers here.
//
// 94525 - 2002-10-14 - fs@openoffice.org
//
::rtl::OUString sDisplayFormAccessPath = GetAccessPathFromForm( m_xExternalDisplayedForm, GetPageId( m_xExternalDisplayedForm ) );
SingleFormDispatchers& rDispatchers = m_aNavigationDispatcher[ sDisplayFormAccessPath ];
// loop through all the dispatchers for this form
for ( SingleFormDispatchers::const_iterator aDisp = rDispatchers.begin();
aDisp != rDispatchers.end();
++aDisp
)
{
(*aDisp)->BroadcastCurrentState( );
}
}
}
#ifdef DBG_UTIL
else
{
DBG_ERROR("FmXFormShell::CreateExternalView : could not create the external form view !");
}
#endif
InvalidateSlot(SID_FM_VIEW_AS_GRID, sal_True, sal_False);
}
//------------------------------------------------------------------------
void FmXFormShell::implAdjustConfigCache()
{
// get (cache) the wizard usage flag
Sequence< ::rtl::OUString > aNames(1);
aNames[0] = ::rtl::OUString::createFromAscii("FormControlPilotsEnabled");
Sequence< Any > aFlags = GetProperties(aNames);
if (1 == aFlags.getLength())
m_bUseWizards = ::cppu::any2bool(aFlags[0]);
}
//------------------------------------------------------------------------
void FmXFormShell::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& _rPropertyNames)
{
const ::rtl::OUString* pSearch = _rPropertyNames.getConstArray();
const ::rtl::OUString* pSearchTil = pSearch + _rPropertyNames.getLength();
for (;pSearch < pSearchTil; ++pSearch)
if (0 == pSearch->compareToAscii("FormControlPilotsEnabled"))
{
implAdjustConfigCache();
InvalidateSlot(SID_FM_USE_WIZARDS, sal_True, sal_True);
}
}
//------------------------------------------------------------------------
void FmXFormShell::SetWizardUsing(sal_Bool _bUseThem)
{
m_bUseWizards = _bUseThem;
Sequence< ::rtl::OUString > aNames(1);
aNames[0] = ::rtl::OUString::createFromAscii("FormControlPilotsEnabled");
Sequence< Any > aValues(1);
aValues[0] = ::cppu::bool2any(m_bUseWizards);
PutProperties(aNames, aValues);
}
//------------------------------------------------------------------------
void FmXFormShell::viewDeactivated( FmFormView* _pCurrentView, sal_Bool _bDeactivateController /* = sal_True */ )
{
// deactivate our view if we are deactivated ourself
// FS - 30.06.99 - 67308
if ( _pCurrentView )
{
// deactivate the controls on this page
if ( _pCurrentView->GetImpl() && !_pCurrentView->IsDesignMode() )
{
_pCurrentView->GetImpl()->Deactivate( _bDeactivateController );
}
// if we have an async load operation pending for the 0-th page for this view,
// we need to cancel this
// 103727 - 2002-09-26 - fs@openoffice.org
const SdrPageView* pCurPageView = _pCurrentView->GetPageViewPvNum( 0 );
const FmFormPage* pPage = pCurPageView ? PTR_CAST( FmFormPage, pCurPageView->GetPage() ) : NULL;
if ( pPage )
{
// move all events from our queue to a new one, omit the events for the deactivated
// page
::std::queue< FmLoadAction > aNewEvents;
while ( m_aLoadingPages.size() )
{
FmLoadAction aAction = m_aLoadingPages.front();
m_aLoadingPages.pop();
if ( pPage != aAction.pPage )
{
aNewEvents.push( aAction );
}
else
{
Application::RemoveUserEvent( aAction.nEventId );
}
}
m_aLoadingPages = aNewEvents;
}
}
}
//------------------------------------------------------------------------
void FmXFormShell::viewActivated( FmFormView* _pCurrentView, sal_Bool _bSyncAction /* = sal_False */ )
{
// activate our view if we are activated ourself
// FS - 30.06.99 - 67308
if ( _pCurrentView && _pCurrentView->GetImpl() && !_pCurrentView->IsDesignMode() )
{
// load forms for the page the current view belongs to
SdrPageView* pCurPageView = _pCurrentView->GetPageViewPvNum( 0 );
FmFormPage* pPage = pCurPageView ? PTR_CAST( FmFormPage, pCurPageView->GetPage() ) : NULL;
if ( pPage )
{
if ( !pPage->GetImpl()->hasEverBeenActivated() )
loadForms( pPage, FORMS_LOAD | ( _bSyncAction ? FORMS_SYNC : FORMS_ASYNC ) );
pPage->GetImpl()->setHasBeenActivated( );
}
// first-time initializations for the views
if ( !_pCurrentView->GetImpl()->hasEverBeenActivated( ) )
{
_pCurrentView->GetImpl()->onFirstViewActivation( PTR_CAST( FmFormModel, _pCurrentView->GetModel() ) );
_pCurrentView->GetImpl()->setHasBeenActivated( );
}
// activate the current view
_pCurrentView->GetImpl()->Activate( _bSyncAction );
}
}
//------------------------------------------------------------------------------
void FmXFormShell::smartControlReset( const Reference< XIndexAccess >& _rxModels )
{
if (!_rxModels.is())
{
DBG_ERROR("FmXFormShell::smartControlReset: invalid container!");
return;
}
static const ::rtl::OUString sClassIdPropertyName = FM_PROP_CLASSID;
static const ::rtl::OUString sBoundFieldPropertyName = FM_PROP_BOUNDFIELD;
sal_Int32 nCount = _rxModels->getCount();
Reference< XPropertySet > xCurrent;
Reference< XPropertySetInfo > xCurrentInfo;
Reference< XPropertySet > xBoundField;
for (sal_Int32 i=0; i<nCount; ++i)
{
_rxModels->getByIndex(i) >>= xCurrent;
if (xCurrent.is())
xCurrentInfo = xCurrent->getPropertySetInfo();
else
xCurrentInfo.clear();
if (!xCurrentInfo.is())
continue;
if (xCurrentInfo->hasPropertyByName(sClassIdPropertyName))
{ // it's a control model
// check if this control is bound to a living database field
if (xCurrentInfo->hasPropertyByName(sBoundFieldPropertyName))
xCurrent->getPropertyValue(sBoundFieldPropertyName) >>= xBoundField;
else
xBoundField.clear();
if (!xBoundField.is())
{ // no, not valid bound -> reset it
Reference< XReset > xControlReset(xCurrent, UNO_QUERY);
if (xControlReset.is())
xControlReset->reset();
}
}
else
{
Reference< XIndexAccess > xContainer(xCurrent, UNO_QUERY);
if (xContainer.is())
smartControlReset(xContainer);
}
}
}
//------------------------------------------------------------------------
IMPL_LINK( FmXFormShell, OnLoadForms, FmFormPage*, _pPage )
{
FmLoadAction aAction = m_aLoadingPages.front();
m_aLoadingPages.pop();
loadForms( aAction.pPage, aAction.nFlags & ~FORMS_ASYNC );
return 0L;
}
//------------------------------------------------------------------------
void FmXFormShell::loadForms( FmFormPage* _pPage, const sal_uInt16 _nBehaviour /* FORMS_LOAD | FORMS_SYNC */ )
{
DBG_ASSERT( ( _nBehaviour & ( FORMS_ASYNC | FORMS_UNLOAD ) ) != ( FORMS_ASYNC | FORMS_UNLOAD ),
"FmXFormShell::loadForms: async loading not supported - this will heavily fail!" );
if ( _nBehaviour & FORMS_ASYNC )
{
m_aLoadingPages.push( FmLoadAction(
_pPage,
_nBehaviour,
Application::PostUserEvent( LINK( this, FmXFormShell, OnLoadForms ), _pPage )
) );
return;
}
DBG_ASSERT( _pPage, "FmXFormShell::loadForms: invalid page!" );
if ( _pPage )
{
// lock the undo env so the forms can change non-transient properties while loading
// (without this my doc's modified flag would be set)
FmFormModel* pModel = PTR_CAST( FmFormModel, _pPage->GetModel() );
DBG_ASSERT( pModel, "FmXFormShell::loadForms: invalid model!" );
if ( pModel )
pModel->GetUndoEnv().Lock();
// load all forms
Reference< XIndexAccess > xForms;
xForms = xForms.query( _pPage->GetForms() );
DBG_ASSERT( xForms.is(), "FmXFormShell::loadForms: invalid forms collection!" );
if ( xForms.is() )
{
Reference< XLoadable > xForm;
for ( sal_Int32 j = 0, nCount = xForms->getCount(); j < nCount; ++j )
{
xForms->getByIndex( j ) >>= xForm;
// a database form must be loaded for
if ( 0 == ( _nBehaviour & FORMS_UNLOAD ) )
{
if ( ::isLoadable( xForm ) && !xForm->isLoaded() )
xForm->load();
if ( _nBehaviour & FORMS_RESET )
{
Reference< XIndexAccess > xContainer( xForm, UNO_QUERY );
DBG_ASSERT( xContainer.is(), "FmXFormShell::loadForms: the form is no container!" );
if ( xContainer.is() )
smartControlReset( xContainer );
}
}
else
{
if ( xForm->isLoaded() )
xForm->unload();
if ( _nBehaviour & FORMS_RESET )
{
Reference< XReset > xReset( xForm, UNO_QUERY );
DBG_ASSERT( xReset.is(), "FmXFormShell::loadForms: the form cannot be resets!" );
if ( xReset.is() )
xReset->reset();
}
}
}
}
if ( pModel )
// unlock the environment
pModel->GetUndoEnv().UnLock();
}
}
//==============================================================================
//==============================================================================
SearchableControlIterator::SearchableControlIterator(Reference< XInterface> xStartingPoint)
:IndexAccessIterator(xStartingPoint)
{
}
//------------------------------------------------------------------------------
sal_Bool SearchableControlIterator::ShouldHandleElement(const Reference< XInterface>& xElement)
{
// wenn das Ding eine ControlSource und einen BoundField-Property hat
Reference< XPropertySet> xProperties(xElement, UNO_QUERY);
if (::comphelper::hasProperty(FM_PROP_CONTROLSOURCE, xProperties) && ::comphelper::hasProperty(FM_PROP_BOUNDFIELD, xProperties))
{
// und das BoundField gueltig ist
Reference< XPropertySet> xField;
xProperties->getPropertyValue(FM_PROP_BOUNDFIELD) >>= xField;
if (xField.is())
{
// nehmen wir's
m_sCurrentValue = ::comphelper::getString(xProperties->getPropertyValue(FM_PROP_CONTROLSOURCE));
return sal_True;
}
}
// wenn es ein Grid-Control ist
if (::comphelper::hasProperty(FM_PROP_CLASSID, xProperties))
{
Any aClassId( xProperties->getPropertyValue(FM_PROP_CLASSID) );
if (::comphelper::getINT16(aClassId) == FormComponentType::GRIDCONTROL)
{
m_sCurrentValue = ::rtl::OUString();
return sal_True;
}
}
return sal_False;
}
//------------------------------------------------------------------------------
sal_Bool SearchableControlIterator::ShouldStepInto(const Reference< XInterface>& xContainer) const
{
return sal_True;
}
//==============================================================================
//==============================================================================
SV_IMPL_PTRARR(StatusForwarderArray, SfxStatusForwarder*)
SFX_IMPL_MENU_CONTROL(ControlConversionMenuController, SfxBoolItem);
//------------------------------------------------------------------------------
ControlConversionMenuController::ControlConversionMenuController(sal_uInt16 nId, Menu &rMenu, SfxBindings &rBindings)
:SfxMenuControl(nId, rBindings)
,m_pMainMenu(&rMenu)
,m_pConversionMenu(NULL)
{
if (nId == SID_FM_CHANGECONTROLTYPE)
{
m_pConversionMenu = FmXFormShell::GetConversionMenu();
rMenu.SetPopupMenu(nId, m_pConversionMenu);
for (sal_Int16 i=0; i<m_pConversionMenu->GetItemCount(); ++i)
{
rBindings.Invalidate(m_pConversionMenu->GetItemId(i));
SfxStatusForwarder* pForwarder = new SfxStatusForwarder(m_pConversionMenu->GetItemId(i), *this);
m_aStatusForwarders.C40_INSERT(SfxStatusForwarder, pForwarder, m_aStatusForwarders.Count());
}
}
}
//------------------------------------------------------------------------------
ControlConversionMenuController::~ControlConversionMenuController()
{
m_pMainMenu->SetPopupMenu(SID_FM_CHANGECONTROLTYPE, NULL);
delete m_pConversionMenu;
}
//------------------------------------------------------------------------------
void ControlConversionMenuController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState)
{
if (nSID == GetId())
SfxMenuControl::StateChanged(nSID, eState, pState);
else if (FmXFormShell::IsControlConversionSlot(nSID))
{
if ((m_pConversionMenu->GetItemPos(nSID) != MENU_ITEM_NOTFOUND) && (eState == SFX_ITEM_DISABLED))
{
m_pConversionMenu->RemoveItem(m_pConversionMenu->GetItemPos(nSID));
}
else if ((m_pConversionMenu->GetItemPos(nSID) == MENU_ITEM_NOTFOUND) && (eState != SFX_ITEM_DISABLED))
{
// We can't simply re-insert the item because we have a clear order for all the our items.
// So first we have to determine the position of the item to insert.
PopupMenu* pSource = FmXFormShell::GetConversionMenu();
sal_Int16 nSourcePos = pSource->GetItemPos(nSID);
DBG_ASSERT(nSourcePos != MENU_ITEM_NOTFOUND, "ControlConversionMenuController::StateChanged : FmXFormShell supplied an invalid menu !");
sal_Int16 nPrevInSource = nSourcePos;
sal_Int16 nPrevInConversion = MENU_ITEM_NOTFOUND;
while (nPrevInSource>0)
{
sal_Int16 nPrevId = pSource->GetItemId(--nPrevInSource);
// do we have the source's predecessor in our conversion menu, too ?
nPrevInConversion = m_pConversionMenu->GetItemPos(nPrevId);
if (nPrevInConversion != MENU_ITEM_NOTFOUND)
break;
}
if (MENU_ITEM_NOTFOUND == nPrevInConversion)
// none of the items which precede the nSID-slot in the source menu are present in our conversion menu
nPrevInConversion = 0 - 1; // put the item at the first position
m_pConversionMenu->InsertItem(nSID, pSource->GetItemText(nSID), pSource->GetItemBits(nSID), ++nPrevInConversion);
m_pConversionMenu->SetItemImage(nSID, pSource->GetItemImage(nSID));
m_pConversionMenu->SetHelpId(nSID, pSource->GetHelpId(nSID));
delete pSource;
}
m_pMainMenu->EnableItem(SID_FM_CHANGECONTROLTYPE, m_pConversionMenu->GetItemCount() > 0);
}
else
{
DBG_ERROR("ControlConversionMenuController::StateChanged : unknown id !");
}
}
//==================================================================
FmCursorActionThread::FmCursorActionThread(const Reference< XResultSet>& _xDataSource, const UniString& _rStopperCaption,
const UniString& _rPath)
:m_xDataSource(_xDataSource)
,m_sStopperCaption(_rStopperCaption)
,m_bCanceled(sal_False)
,m_bDeleteMyself(sal_False)
,m_bDisposeCursor(sal_False)
,m_bTerminated(sal_False)
,m_bRunFailed(sal_False)
,m_sAccessPath(_rPath)
{
DBG_ASSERT(m_xDataSource.is() && Reference< XCancellable>(m_xDataSource, UNO_QUERY).is(),
"FmCursorActionThread::FmCursorActionThread : invalid cursor !");
}
//------------------------------------------------------------------------------
void FmCursorActionThread::run()
{
// On instantiation of a SfxCancellable the application is notified and 'switches on' the red stop button.
// Unfortunally this is conditioned with the acquirement of the solar mutex, and the application tries
// only once and ignores the notification if it fails.
// To prevent that we get the solar mutex and _block_ 'til we got it.
// As we are in the 'top level execution' of this thread (with a rather small stack and no other mutexes locked)
// we shouldn't experience problems with deadlocks ...
::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
ThreadStopper* pStopper = new ThreadStopper(this, m_sStopperCaption);
aSolarGuard.clear();
// we're not canceled yet
::osl::ClearableMutexGuard aInitGuard(m_aAccessSafety);
m_bCanceled = sal_False;
m_bRunFailed = sal_False;
aInitGuard.clear();
// start it
try
{
RunImpl();
}
catch(SQLException e)
{
::osl::MutexGuard aErrorGuard(m_aAccessSafety);
m_bRunFailed = sal_True;
m_aRunException = e;
}
catch(Exception&)
{
DBG_ERROR("FmCursorActionThread::run : catched a non-database exception !");
}
sal_Bool bReallyCanceled;
::osl::ClearableMutexGuard aEvalGuard(m_aAccessSafety);
bReallyCanceled = m_bCanceled;
aEvalGuard.clear();
pStopper->OwnerTerminated();
// this will cause the stopper to delete itself (in the main thread) so we don't have to care of the
// solar mutex
}
//------------------------------------------------------------------------------
void FmCursorActionThread::onTerminated()
{
::osl::ClearableMutexGuard aResetGuard(m_aAccessSafety);
if (m_aTerminationHandler.IsSet())
m_aTerminationHandler.Call(this);
if (IsCursorDisposeEnabled())
{
Reference< ::com::sun::star::lang::XComponent> xDataSourceComponent(m_xDataSource, UNO_QUERY);
if (xDataSourceComponent.is())
xDataSourceComponent->dispose();
}
aResetGuard.clear();
// with this StopItWait has a chance to do it's Terminated()
::osl::MutexGuard aGuard(m_aFinalExitControl);
// Terminated() in StopItWait still returns sal_False
m_bTerminated = sal_True;
// Terminated() now returns sal_True, but StopItWait can't exit until this method exits (because of the guarded m_aFinalExitControl)
if (IsSelfDeleteEnabled())
delete this;
}
//------------------------------------------------------------------------------
void FmCursorActionThread::StopIt()
{
::osl::MutexGuard aGuard(m_aAccessSafety);
m_bCanceled = sal_True;
Reference< XCancellable> xCancel(m_xDataSource, UNO_QUERY);
DBG_ASSERT(xCancel.is(), "FmCursorActionThread::StopIt : invalid cursor !");
xCancel->cancel();
}
//------------------------------------------------------------------------------
void FmCursorActionThread::StopItWait()
{
StopIt();
while (!Terminated())
;
// OnTerminated has been called, but we can't simply exit : Suppose the caller want's to delete the thread object
// immediately after returning from StopItWait. With the following guard we ensure that we exit this method
// only after onTerminated has exited.
::osl::ClearableMutexGuard aGuard(m_aFinalExitControl);
// now onTerminated has exited, so we can leave, too
}
//------------------------------------------------------------------------------
FmCursorActionThread::ThreadStopper::ThreadStopper(FmCursorActionThread* pOwner, const UniString& rTitle)
:SfxCancellable(SFX_APP()->GetCancelManager(), rTitle)
,m_pOwner(pOwner)
{
}
//------------------------------------------------------------------------------
void FmCursorActionThread::ThreadStopper::Cancel()
{
if (!m_pOwner) // the owner is already terminated and we're waiting for the OnDeleteInMainThread event
return;
::osl::MutexGuard aGuard(m_pOwner->m_aAccessSafety);
if (IsCancelled())
// we already did pass this to our owner
return;
SfxCancellable::Cancel();
m_pOwner->StopIt();
}
//------------------------------------------------------------------------------
void FmCursorActionThread::ThreadStopper::OwnerTerminated()
{
m_pOwner = NULL;
Application::PostUserEvent(LINK(this, FmCursorActionThread::ThreadStopper, OnDeleteInMainThread), this);
}
//------------------------------------------------------------------------------
IMPL_LINK(FmCursorActionThread::ThreadStopper, OnDeleteInMainThread, FmCursorActionThread::ThreadStopper*, pThis)
{
delete pThis;
return 0L;
}
//==============================================================================
//==============================================================================
//------------------------------------------------------------------------------
FmFormNavigationDispatcher::FmFormNavigationDispatcher(const URL& _rUrl, sal_Int16 _nSlotId, SfxBindings& _rBindings, const Reference< XResultSet>& _xForm, const UniString& _rAccessPath)
:FmSlotDispatch(_rUrl, _nSlotId, _rBindings)
,m_bActive(sal_False)
,m_xCursor(_xForm)
,m_sAccessPath(_rAccessPath)
{
}
//------------------------------------------------------------------------------
void FmFormNavigationDispatcher::SetActive(sal_Bool bEnable)
{
if (m_bActive == bEnable)
return;
m_bActive = bEnable;
// broadcast the initial state
if (bEnable)
{
SfxPoolItem* pState = NULL;
SfxItemState eInitialState = GetBindings().QueryState(m_nSlot, pState);
NotifyState(eInitialState, pState);
delete pState;
}
}
//------------------------------------------------------------------------------
void FmFormNavigationDispatcher::SetStatus(SfxItemState eState, const SfxPoolItem* pState)
{
m_aNonActiveState = BuildEvent(eState, pState);
NOTIFY_LISTENERS(m_aStatusListeners, ::com::sun::star::frame::XStatusListener, statusChanged, m_aNonActiveState);
}
//------------------------------------------------------------------------------
void FmFormNavigationDispatcher::StateChanged(USHORT nSID, SfxItemState eState, const SfxPoolItem* pState)
{
if (IsActive())
FmSlotDispatch::StateChanged(nSID, eState, pState);
}
//------------------------------------------------------------------------------
void FmFormNavigationDispatcher::NotifyState(SfxItemState eState, const SfxPoolItem* pState, const Reference< ::com::sun::star::frame::XStatusListener>& rListener)
{
if (IsActive())
FmSlotDispatch::NotifyState(eState, pState, rListener);
else
if (rListener.is())
rListener->statusChanged(m_aNonActiveState);
else
NOTIFY_LISTENERS(m_aStatusListeners, ::com::sun::star::frame::XStatusListener, statusChanged, m_aNonActiveState);
}
//------------------------------------------------------------------------------
void FmFormNavigationDispatcher::dispose(void) throw( RuntimeException )
{
m_aNonActiveState.Source = NULL;
// the Source is a reference to myself, so we would never be deleted without this
FmSlotDispatch::dispose();
}
//==============================================================================
|