File: foxhacks.cpp

package info (click to toggle)
xfe 1.32.5-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 16,748 kB
  • sloc: cpp: 40,215; ansic: 17,753; sh: 9,740; makefile: 778; yacc: 289
file content (3529 lines) | stat: -rw-r--r-- 111,265 bytes parent folder | download
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
// This file contains all FOX functions redefinitions (FOX hacks for various purposes)

#include <X11/Xlib.h>
#include <X11/Xutil.h>

#ifdef HAVE_XFT_H
#include <X11/Xft/Xft.h>
#endif

extern FXbool file_tooltips;
extern FXString xdgconfighome;


// Hack to fix issues with drag and drop within, from and to the dirList
#define SELECT_MASK         (TREELIST_SINGLESELECT|TREELIST_BROWSESELECT)

// Remove all siblings from [fm,to]
void FXTreeList::removeItems(FXTreeItem* fm,FXTreeItem* to,FXbool notify)
{
    register FXTreeItem *olditem=currentitem;
    register FXTreeItem *prv;
    register FXTreeItem *nxt;
    register FXTreeItem *par;
    if(fm && to)
    {
        if(fm->parent!=to->parent)
            fxerror("%s::removeItems: arguments have different parent.\n",getClassName());

        // Delete items
        while(1)
        {
            // Scan till end
            while(to->last) to=to->last;
            do
            {
                // Notify item will be deleted
                if(notify && target)
                    target->tryHandle(this,FXSEL(SEL_DELETED,message),(void*)to);

                // Remember hookups
                nxt=to->next;
                prv=to->prev;
                par=to->parent;

                // !!!! Hack to go back to the parent when an item disappeared

                // Adjust pointers; suggested by Alan Ott <ott@acusoft.com>
                //if(anchoritem==to){ anchoritem=par; if(prv) anchoritem=prv; if(nxt) anchoritem=nxt; }
                //if(currentitem==to){ currentitem=par; if(prv) currentitem=prv; if(nxt) currentitem=nxt; }
                //if(extentitem==to){ extentitem=par; if(prv) extentitem=prv; if(nxt) extentitem=nxt; }
                //if(viewableitem==to){ viewableitem=par; if(prv) viewableitem=prv; if(nxt) viewableitem=nxt; }
                anchoritem=par;
                currentitem=par;
                extentitem=par;
                viewableitem=par;
 
                // !!!! End of hack

                // Remove item from list
                if(prv) prv->next=nxt;
                else if(par) par->first=nxt;
                else firstitem=nxt;
                if(nxt) nxt->prev=prv;
                else if(par) par->last=prv;
                else lastitem=prv;

                // Delete it
                delete to;

                // Was last one?
                if(to==fm) goto x;
                to=par;
            }
            while(!prv);
            to=prv;
        }

        // Current item has changed
x:
        if(olditem!=currentitem)
        {
            if(notify && target)
                target->tryHandle(this,FXSEL(SEL_CHANGED,message),(void*)currentitem);
        }

        // Deleted current item
        if(currentitem && currentitem!=olditem)
        {
            if(hasFocus())
                currentitem->setFocus(TRUE);
            if((options&SELECT_MASK)==TREELIST_BROWSESELECT && currentitem->isEnabled())
                selectItem(currentitem,notify);
        }

        // Redo layout
        recalc();
    }
}


// Hack to display a tooltip with name, size, date, etc.
// We were asked about tip text
long FXTreeList::onQueryTip(FXObject* sender,FXSelector sel,void* ptr)
{
    if (FXWindow::onQueryTip(sender,sel,ptr))
        return 1;

    // File tooltips are optional
    if (file_tooltips)
    {
        if ((flags&FLAG_TIP) && !(options&TREELIST_AUTOSELECT)) // No tip when autoselect!
        {
            FXint x,y;
            FXuint buttons;

            getCursorPosition(x,y,buttons);
            DirItem *item=(DirItem*)getItemAt(x,y);
            if (item)
            {
                // !!!! Hack to display a tooltip with name, size, date, etc.
                FXString string;

                // Root folder
                if (item->getText()==ROOTDIR)
                    string=_("Root directory");

                // Other folders
                else
                {
                    // Get tooltip data                    
                    FXString str=item->getTooltipData();
                    if (str=="")
                    	return 0;

                    // Add name, type, permissions, etc. to the tool tip
                    FXString name=str.section('\t',0);
                    FXString type=str.section('\t',1);
                    FXString date=str.section('\t',2);
                    FXString user=str.section('\t',3);
                    FXString group=str.section('\t',4);
                    FXString perms=str.section('\t',5);
                    FXString deldate=str.section('\t',6);
                    FXString pathname=str.section('\t',7);

                    // Compute root file size
                    unsigned long long dnsize;
                    char dsize[64];
                    dnsize=::dirsize(pathname.text());
                    snprintf(dsize,sizeof(dsize)-1,"%llu",dnsize);
                    FXString size=::hSize(dsize);
                    if (deldate.empty())
                        string=_("Name: ")+name+"\n"+_("Size in root: ")+size+"\n"+_("Type: ")+type
                               +"\n"+_("Modified date: ")+date+"\n"+_("User: ")+user+" - "+_("Group: ")+group
                               +"\n"+_("Permissions: ")+perms;
                    else
                        string=_("Name: ")+name+"\n"+_("Size in root: ")+size+"\n"+_("Type: ")+type
                               +"\n"+_("Modified date: ")+date+"\n"+_("Deletion date: ")+deldate+"\n"+_("User: ")+user+" - "+_("Group: ")+group
                               +"\n"+_("Permissions: ")+perms;
                }
                // !!!! End of hack !!!

                sender->handle(this,FXSEL(SEL_COMMAND,ID_SETSTRINGVALUE),(void*)&string);
                return 1;
            }
        }
    }
    return 0;
}


//
// Hack of FXDCWindow
//

#define DISPLAY(app) ((Display*)((app)->display))
#define FS ((XFontStruct*)(font->font))

#ifndef HAVE_XFT_H
static FXint utf2db(XChar2b *dst,const FXchar *src,FXint n)
{
    register FXint len,p;
    register FXwchar w;
    for (p=len=0; p<n; p+=wclen(src+p),len++)
    {
        w=wc(src+p);
        dst[len].byte1=(w>>8);
        dst[len].byte2=(w&255);
    }
    return len;
}
#endif


// Hack to take into account non UTF-8 strings
void FXDCWindow::drawText(FXint x,FXint y,const FXchar* string,FXuint length)
{
    if (!surface)
        fxerror("FXDCWindow::drawText: DC not connected to drawable.\n");
    if (!font)
        fxerror("FXDCWindow::drawText: no font selected.\n");

#ifdef HAVE_XFT_H
    XftColor color;
    color.pixel=devfg;
    color.color.red=FXREDVAL(fg)*257;
    color.color.green=FXGREENVAL(fg)*257;
    color.color.blue=FXBLUEVAL(fg)*257;
    color.color.alpha=FXALPHAVAL(fg)*257;

    // !!!! Hack to draw string depending on its encoding !!!
    if (isUtf8(string,length))
        XftDrawStringUtf8((XftDraw*)xftDraw,&color,(XftFont*)font->font,x,y,(const FcChar8*)string,length);
    else
        XftDrawString8((XftDraw*)xftDraw,&color,(XftFont*)font->font,x,y,(const FcChar8*)string,length);
    // !!!! End of hack !!!
#else
    register FXint count,escapement,defwidth,ww,size,i;
    register FXdouble ang,ux,uy;
    register FXuchar r,c;
    XChar2b sbuffer[4096];
    count=utf2db(sbuffer,string,FXMIN(length,4096));
    if (font->getAngle())
    {
        ang=font->getAngle()*0.00027270769562411399179;
        defwidth=FS->min_bounds.width;
        ux=cos(ang);
        uy=sin(ang);
        if (FS->per_char)
        {
            r=FS->default_char>>8;
            c=FS->default_char&255;
            size=(FS->max_char_or_byte2-FS->min_char_or_byte2+1);
            if (FS->min_char_or_byte2<=c && c<=FS->max_char_or_byte2 && FS->min_byte1<=r && r<=FS->max_byte1)
                defwidth=FS->per_char[(r-FS->min_byte1)*size+(c-FS->min_char_or_byte2)].width;
            for (i=escapement=0; i<count; i++)
            {
                XDrawString16(DISPLAY(getApp()),surface->id(),(GC)ctx,(FXint)(x+escapement*ux),(FXint)(y-escapement*uy),&sbuffer[i],1);
                r=sbuffer[i].byte1;
                c=sbuffer[i].byte2;
                escapement+=defwidth;
                if (FS->min_char_or_byte2<=c && c<=FS->max_char_or_byte2 && FS->min_byte1<=r && r<=FS->max_byte1)
                    if ((ww=FS->per_char[(r-FS->min_byte1)*size+(c-FS->min_char_or_byte2)].width)!=0) escapement+=ww-defwidth;
            }
        }
        else
        {
            for (i=escapement=0; i<count; i++)
            {
                XDrawString16(DISPLAY(getApp()),surface->id(),(GC)ctx,(FXint)(x+escapement*ux),(FXint)(y-escapement*uy),&sbuffer[i],1);
                escapement+=defwidth;
            }
        }
    }
    else
        XDrawString16(DISPLAY(getApp()),surface->id(),(GC)ctx,x,y,sbuffer,count);
#endif
}


//
// Hack of FXFont
//

// Hack to take into account non UTF-8 strings
FXint FXFont::getTextWidth(const FXchar *string,FXuint length) const
{
    if (!string && length)
        fxerror("%s::getTextWidth: NULL string argument\n",getClassName());

    if (font)
    {
#ifdef HAVE_XFT_H
        XGlyphInfo extents;
        // This returns rotated metrics; FOX likes to work with unrotated metrics, so if angle
        // is not 0, we calculate the unrotated baseline; note however that the calculation is
        // not 100% pixel exact when the angle is not a multiple of 90 degrees.

        // !!!! Hack to evaluate string extent depending on its encoding !!!
        if (isUtf8(string,length))
            XftTextExtentsUtf8(DISPLAY(getApp()),(XftFont*)font,(const FcChar8*)string,length,&extents);
        else
            XftTextExtents8(DISPLAY(getApp()),(XftFont*)font,(const FcChar8*)string,length,&extents);
        // !!!! End of hack !!!

        if (angle)
            return (FXint)(0.5+sqrt(extents.xOff*extents.xOff+extents.yOff*extents.yOff));

        return extents.xOff;
#else
        register const XFontStruct *fs=(XFontStruct*)font;
        register FXint defwidth=fs->min_bounds.width;
        register FXint width=0,ww;
        register FXuint p=0;
        register FXuint s;
        register FXuchar r;
        register FXuchar c;
        register FXwchar w;
        if (fs->per_char)
        {
            r=fs->default_char>>8;
            c=fs->default_char&255;
            s=(fs->max_char_or_byte2-fs->min_char_or_byte2+1);
            if (fs->min_char_or_byte2<=c && c<=fs->max_char_or_byte2 && fs->min_byte1<=r && r<=fs->max_byte1)
                defwidth=fs->per_char[(r-fs->min_byte1)*s+(c-fs->min_char_or_byte2)].width;
            while (p<length)
            {
                w=wc(string+p);
                p+=wclen(string+p);
                r=w>>8;
                c=w&255;
                if (fs->min_char_or_byte2<=c && c<=fs->max_char_or_byte2 && fs->min_byte1<=r && r<=fs->max_byte1)
                {
                    if ((ww=fs->per_char[(r-fs->min_byte1)*s+(c-fs->min_char_or_byte2)].width)!=0)
                    {
                        width+=ww;
                        continue;
                    }
                }
                width+=defwidth;
            }
        }
        else
        {
            while (p<length)
            {
                p+=wclen(string+p);
                width+=defwidth;
            }
        }
        return width;
#endif
    }
    return length;
}


//
// Hack of FXSplitter
//
// NB : - MIN_PANEL_WIDTH is defined in xfedefs.h
//      - Don't use LAYOUT_FIX_WIDTH with this hack because it won't work!
// This function is taken from the FXSplitter class
// and hacked to set a minimum splitter width when moving splitter to right
// It replaces the normal function...
void FXSplitter::moveHSplit(FXint pos)
{
    register FXint smin,smax;
    register FXuint hints;
    FXASSERT(window);
    hints=window->getLayoutHints();
    // !!!! Hack to limit the width to a minimum value !!!
    if (options&SPLITTER_REVERSED)
    {
        smin=barsize;
        smax=window->getX()+window->getWidth();
    }
    else
    {
        smin=window->getX();
        smax=width-barsize;
    }
    smax=smax-MIN_PANEL_WIDTH;
    smin=smin+MIN_PANEL_WIDTH;
    split=pos;
    if (split<smin)
        split=smin;
    if (split>smax)
        split=smax;
    // !!!! End of hack
}

void FXSplitter::moveVSplit(FXint pos)
{
    register FXint smin,smax;
    register FXuint hints;
    FXASSERT(window);
    hints=window->getLayoutHints();
    if (options&SPLITTER_REVERSED)
    {
        smin=barsize;
        smax=window->getY()+window->getHeight();
    }
    else
    {
        smin=window->getY();
        smax=height-barsize;
    }
    smax=smax-MIN_PANEL_WIDTH;
    smin=smin+MIN_PANEL_WIDTH;
    split=pos;
    if (split<smin)
        split=smin;
    if (split>smax)
        split=smax;
}


//
// Hack of FXRegistry
//

// Hack to change the defaults directories for config files and icons
// The vendor key is not used anymore

#define DESKTOP        "xferc"
#define REGISTRYPATH   "/etc:/usr/share:/usr/local/share"

// Read registry
bool FXRegistry::read()
{
    FXString dirname;
    register bool ok=false;

    dirname=FXPath::search(REGISTRYPATH,"xfe");
    if (!dirname.empty())
        ok=readFromDir(dirname,false);

    // Try search along PATH if still not found
    if (!ok)
    {
        dirname=FXPath::search(FXSystem::getExecPath(),"xfe");
        if (!dirname.empty())
            ok=readFromDir(dirname,false);
    }

    // Get path to per-user settings directory
    dirname=xdgconfighome + PATHSEPSTRING XFECONFIGPATH;

    // Then read per-user settings; overriding system-wide ones
    if (readFromDir(dirname,true))
        ok=true;

    return ok;
}


// Try read registry from directory
bool FXRegistry::readFromDir(const FXString& dirname,bool mark)
{
    bool ok=false;

    // Directory is empty?
    if (!dirname.empty())
    {
        // First try to load desktop registry
        if (parseFile(dirname+PATHSEPSTRING DESKTOP,false))
        {
            FXString nn=dirname+PATHSEPSTRING DESKTOP;
            ok=true;
        }

        // Have application key
        if (!applicationkey.empty())
        {
            if (parseFile(dirname+PATHSEPSTRING+applicationkey + "rc",mark))
                ok=true;
        }
    }
    return ok;
}


// Write registry
bool FXRegistry::write()
{
    FXString pathname,tempname;

    // Settings have not changed
    if (!isModified()) return true;

    // We can not save if no application key given
    if (!applicationkey.empty())
    {
        // Changes written only in the per-user registry
        pathname=xdgconfighome + PATHSEPSTRING XFECONFIGPATH;

        // If this directory does not exist, make it
        if (!FXStat::exists(pathname))
        {
            if (!FXDir::create(pathname))
                return false;
        }
        else
        {
            if (!FXStat::isDirectory(pathname))
                return false;
        }

        // Add application key
        pathname.append(PATHSEPSTRING+applicationkey+"rc");

        // Construct temp name
        tempname.format("%s_%d",pathname.text(),fxgetpid());

        // Unparse settings into temp file first
        if (unparseFile(tempname))
        {

            // Rename ATOMICALLY to proper name
            if (!FXFile::rename(tempname,pathname))
                return false;

            setModified(false);
            return true;
        }
    }
    return false;
}



//
// Hack of FXPopup
//

// The two functions below are taken from the FXPopup class
// and hacked to allow navigating using the keyboard on popup menus
// They replace the normal functions...

// !!!! Global variable control keyboard scrolling on right click popup menus !!!!
extern FXbool allowPopupScroll;

void FXPopup::setFocus()
{
    FXShell::setFocus();

    // !!!! Hack to allow keyboard scroll on popup dialogs !!!!
    if (allowPopupScroll)
        grabKeyboard();
}

void FXPopup::killFocus()
{
    FXShell::killFocus();

    // !!!! Hack to allow keyboard scroll on popup dialogs !!!!
    if (allowPopupScroll)
    {
        if (prevActive)
            prevActive->setFocus();
        else
            ungrabKeyboard();
    }

}


//
// Hack of FXStatusLine(translation hack)
//

// Status line construct and init
FXStatusLine::FXStatusLine(FXComposite* p,FXObject* tgt,FXSelector sel):
        FXFrame(p,FRAME_SUNKEN|LAYOUT_LEFT|LAYOUT_FILL_Y|LAYOUT_FILL_X,0,0,0,0, 4,4,2,2)
{
    flags|=FLAG_SHOWN;
    status=normal=_("Ready.");
    font=getApp()->getNormalFont();
    textColor=getApp()->getForeColor();
    textHighlightColor=getApp()->getForeColor();
    target=tgt;
    message=sel;
}


//
// Hack of FXReplaceDialog
//

// Taken from the FXReplaceDialog class
// - translation hack
// - small hack for the Clearlooks theme

// Padding for buttons
#define HORZ_PAD      12
#define VERT_PAD      2
#define SEARCH_MASK   (SEARCH_EXACT|SEARCH_IGNORECASE|SEARCH_REGEX)

// File Open Dialog
FXReplaceDialog::FXReplaceDialog(FXWindow* owner,const FXString& caption,FXIcon* ic,FXuint opts,FXint x,FXint y,FXint w,FXint h):
        FXDialogBox(owner,caption,opts|DECOR_TITLE|DECOR_BORDER|DECOR_RESIZE,x,y,w,h,10,10,10,10, 10,10)
{
    FXHorizontalFrame* buttons=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH|PACK_UNIFORM_HEIGHT,0,0,0,0,0,0,0,0);
    accept=new FXButton(buttons,_("&Replace"),NULL,this,ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y|LAYOUT_RIGHT,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
    every=new FXButton(buttons,_("Re&place All"),NULL,this,ID_ALL,BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,0,0,0,0,6,6,VERT_PAD,VERT_PAD);
    cancel=new FXButton(buttons,_("&Cancel"),NULL,this,ID_CANCEL,BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y|LAYOUT_RIGHT,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
    FXHorizontalFrame* pair=new FXHorizontalFrame(buttons,LAYOUT_FILL_Y|LAYOUT_RIGHT,0,0,0,0, 0,0,0,0);
    FXArrowButton* searchlast=new FXArrowButton(pair,this,ID_PREV,ARROW_LEFT|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
    FXArrowButton* searchnext=new FXArrowButton(pair,this,ID_NEXT,ARROW_RIGHT|FRAME_RAISED|FRAME_THICK|LAYOUT_FILL_Y,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
    new FXHorizontalSeparator(this,SEPARATOR_GROOVE|LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X);
    FXHorizontalFrame* toppart=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 10,10);
    new FXLabel(toppart,FXString::null,ic,ICON_BEFORE_TEXT|JUSTIFY_CENTER_X|JUSTIFY_CENTER_Y|LAYOUT_FILL_Y|LAYOUT_FILL_X);
    FXVerticalFrame* entry=new FXVerticalFrame(toppart,LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0);
    searchlabel=new FXLabel(entry,_("Search for:"),NULL,JUSTIFY_LEFT|ICON_BEFORE_TEXT|LAYOUT_TOP|LAYOUT_LEFT|LAYOUT_FILL_X);

    // !!!! Hack to remove the FRAME_THICK option (required for the Clearlooks theme)
    searchbox=new FXHorizontalFrame(entry,FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 0,0);
    searchtext=new FXTextField(searchbox,26,this,ID_SEARCH_TEXT,FRAME_SUNKEN|TEXTFIELD_ENTER_ONLY|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 4,4,4,4);
    // !!!! End of hack

    FXVerticalFrame* searcharrows=new FXVerticalFrame(searchbox,LAYOUT_RIGHT|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);
    FXArrowButton* ar1=new FXArrowButton(searcharrows,this,ID_SEARCH_UP,FRAME_RAISED|FRAME_THICK|ARROW_UP|ARROW_REPEAT|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH, 0,0,16,0, 1,1,1,1);
    FXArrowButton* ar2=new FXArrowButton(searcharrows,this,ID_SEARCH_DN,FRAME_RAISED|FRAME_THICK|ARROW_DOWN|ARROW_REPEAT|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH, 0,0,16,0, 1,1,1,1);
    ar1->setArrowSize(3);
    ar2->setArrowSize(3);
    replacelabel=new FXLabel(entry,_("Replace with:"),NULL,LAYOUT_LEFT);

    // !!!! Hack to remove the FRAME_THICK option (required for the Clearlooks theme)
    replacebox=new FXHorizontalFrame(entry,FRAME_SUNKEN|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 0,0);
    replacetext=new FXTextField(replacebox,26,this,ID_REPLACE_TEXT,FRAME_SUNKEN|TEXTFIELD_ENTER_ONLY|LAYOUT_FILL_X|LAYOUT_FILL_Y,0,0,0,0, 4,4,4,4);
    // !!!! End of hack

    FXVerticalFrame* replacearrows=new FXVerticalFrame(replacebox,LAYOUT_RIGHT|LAYOUT_FILL_Y,0,0,0,0, 0,0,0,0, 0,0);
    FXArrowButton* ar3=new FXArrowButton(replacearrows,this,ID_REPLACE_UP,FRAME_RAISED|FRAME_THICK|ARROW_UP|ARROW_REPEAT|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH, 0,0,16,0, 1,1,1,1);
    FXArrowButton* ar4=new FXArrowButton(replacearrows,this,ID_REPLACE_DN,FRAME_RAISED|FRAME_THICK|ARROW_DOWN|ARROW_REPEAT|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH, 0,0,16,0, 1,1,1,1);
    ar3->setArrowSize(3);
    ar4->setArrowSize(3);
    FXHorizontalFrame* options1=new FXHorizontalFrame(entry,LAYOUT_FILL_X,0,0,0,0, 0,0,0,0);
    new FXRadioButton(options1,_("Ex&act"),this,ID_MODE+SEARCH_EXACT,ICON_BEFORE_TEXT|LAYOUT_CENTER_X);
    new FXRadioButton(options1,_("&Ignore Case"),this,ID_MODE+SEARCH_IGNORECASE,ICON_BEFORE_TEXT|LAYOUT_CENTER_X);
    new FXRadioButton(options1,_("E&xpression"),this,ID_MODE+SEARCH_REGEX,ICON_BEFORE_TEXT|LAYOUT_CENTER_X);
    new FXCheckButton(options1,_("&Backward"),this,ID_DIR,ICON_BEFORE_TEXT|LAYOUT_CENTER_X);
    searchlast->setTipText("Ctrl-B");
    searchnext->setTipText("Ctrl-F");
    searchlast->addHotKey(MKUINT(KEY_b,CONTROLMASK));
    searchnext->addHotKey(MKUINT(KEY_f,CONTROLMASK));
    searchmode=SEARCH_EXACT|SEARCH_FORWARD;
    current=0;
}

//
// Hack of FXSearchDialog (translation hack)
//

// Taken from the FXSearchDialog class
FXSearchDialog::FXSearchDialog(FXWindow* owner,const FXString& caption,FXIcon* ic,FXuint opts,FXint x,FXint y,FXint w,FXint h):
        FXReplaceDialog(owner,caption,ic,opts,x,y,w,h)
{
    accept->setText(_("&Search"));
    every->hide();
    replacelabel->hide();
    replacebox->hide();
}

//
// Hack of FXInputDialog (translation hack)
//

// Taken from the FXInputDialog class
void FXInputDialog::initialize(const FXString& label,FXIcon* icon)
{
    FXuint textopts=TEXTFIELD_ENTER_ONLY|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X;
    FXHorizontalFrame* buttons=new FXHorizontalFrame(this,LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X|PACK_UNIFORM_WIDTH,0,0,0,0,0,0,0,0);
    new FXButton(buttons,_("&OK"),NULL,this,ID_ACCEPT,BUTTON_INITIAL|BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
    new FXButton(buttons,_("&Cancel"),NULL,this,ID_CANCEL,BUTTON_DEFAULT|FRAME_RAISED|FRAME_THICK|LAYOUT_CENTER_Y|LAYOUT_RIGHT,0,0,0,0,HORZ_PAD,HORZ_PAD,VERT_PAD,VERT_PAD);
    new FXHorizontalSeparator(this,SEPARATOR_GROOVE|LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X);
    FXHorizontalFrame* toppart=new FXHorizontalFrame(this,LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0, 10,10);
    new FXLabel(toppart,FXString::null,icon,ICON_BEFORE_TEXT|JUSTIFY_CENTER_X|JUSTIFY_CENTER_Y|LAYOUT_FILL_Y|LAYOUT_FILL_X);
    FXVerticalFrame* entry=new FXVerticalFrame(toppart,LAYOUT_FILL_X|LAYOUT_CENTER_Y,0,0,0,0, 0,0,0,0);
    new FXLabel(entry,label,NULL,JUSTIFY_LEFT|ICON_BEFORE_TEXT|LAYOUT_TOP|LAYOUT_LEFT|LAYOUT_FILL_X);
    if (options&INPUTDIALOG_PASSWORD)
        textopts|=TEXTFIELD_PASSWD;
    if (options&INPUTDIALOG_INTEGER)
        textopts|=TEXTFIELD_INTEGER|JUSTIFY_RIGHT;
    if (options&INPUTDIALOG_REAL)
        textopts|=TEXTFIELD_REAL|JUSTIFY_RIGHT;
    input=new FXTextField(entry,20,this,ID_ACCEPT,textopts,0,0,0,0, 8,8,4,4);
    limlo=1.0;
    limhi=0.0;
}



//
// Hack of fxpriv (clipboard management)
//


// These two functions are hacked to reduce the timeout when the owner app of the clipboard has been closed

// Send request for selection info
Atom fxsendrequest(Display *display,Window window,Atom selection,Atom prop,Atom type,FXuint time)
{
    // !!!! Hack here to reduce timeout !!!!
    FXuint loops=10;
    XEvent ev;
    XConvertSelection(display,selection,type,prop,window,time);
    while (!XCheckTypedWindowEvent(display,window,SelectionNotify,&ev))
    {
        if (loops==0)
        {
            //fxwarning("fxsendrequest:timed out!\n");
            return None;
        }
        FXThread::sleep(10000000);  // Don't burn too much CPU here:- the other guy needs it more....
        loops--;
    }
    return ev.xselection.property;
}


// Wait for event of certain type
static FXbool fxwaitforevent(Display *display,Window window,int type,XEvent& event)
{
    // !!!! Hack here to reduce timeout !!!!
    FXuint loops=10;
    while (!XCheckTypedWindowEvent(display,window,type,&event))
    {
        if (loops==0)
        {
            //fxwarning("fxwaitforevent:timed out!\n");
            return FALSE;
        }
        FXThread::sleep(10000000);  // Don't burn too much CPU here:- the other guy needs it more....
        loops--;
    }
    return TRUE;
}


// The four following functions are not modified but are necessary here because the previous ones are not called directly

// Read property in chunks smaller than maximum transfer length,
// appending to data array; returns amount read from the property.
static FXuint fxrecvprop(Display *display,Window window,Atom prop,Atom& type,FXuchar*& data,FXuint& size)
{
    unsigned long maxtfrsize=XMaxRequestSize(display)*4;
    unsigned long tfroffset,tfrsize,tfrleft;
    unsigned char *ptr;
    int format;
    tfroffset=0;

    // Read next chunk of data from property
    while (XGetWindowProperty(display,window,prop,tfroffset>>2,maxtfrsize>>2,False,AnyPropertyType,&type,&format,&tfrsize,&tfrleft,&ptr)==Success && type!=None)
    {
        tfrsize*=(format>>3);

        // Grow the array to accomodate new data
        if (!FXRESIZE(&data,FXuchar,size+tfrsize+1))
        {
            XFree(ptr);
            break;
        }

        // Append new data at the end, plus the extra 0.
        memcpy(&data[size],ptr,tfrsize+1);
        size+=tfrsize;
        tfroffset+=tfrsize;
        XFree(ptr);
        if (tfrleft==0)
            break;
    }

    // Delete property after we're done
    XDeleteProperty(display,window,prop);
    XFlush(display);
    return tfroffset;
}


// Receive data via property
Atom fxrecvdata(Display *display,Window window,Atom prop,Atom incr,Atom& type,FXuchar*& data,FXuint& size)
{
    unsigned long  tfrsize,tfrleft;
    unsigned char *ptr;
    XEvent ev;
    int format;
    data=NULL;
    size=0;
    if (prop)
    {
        // First, see what we've got
        if (XGetWindowProperty(display,window,prop,0,0,False,AnyPropertyType,&type,&format,&tfrsize,&tfrleft,&ptr)==Success && type!=None)
        {
            XFree(ptr);

            // Incremental transfer
            if (type==incr)
            {
                // Delete the INCR property
                XDeleteProperty(display,window,prop);
                XFlush(display);

                // Wait for the next batch of data
                while (fxwaitforevent(display,window,PropertyNotify,ev))
                {
                    // Wrong type of notify event; perhaps stale event
                    if (ev.xproperty.atom!=prop || ev.xproperty.state!=PropertyNewValue)
                        continue;

                    // See what we've got
                    if (XGetWindowProperty(display,window,prop,0,0,False,AnyPropertyType,&type,&format,&tfrsize,&tfrleft,&ptr)==Success && type!=None)
                    {
                        XFree(ptr);

                        // if empty property, its the last one
                        if (tfrleft==0)
                        {
                            // Delete property so the other side knows we've got the data
                            XDeleteProperty(display,window,prop);
                            XFlush(display);
                            break;
                        }

                        // Read and delete the property
                        fxrecvprop(display,window,prop,type,data,size);
                    }
                }
            }

            // All data in one shot
            else
            {
                // Read and delete the property
                fxrecvprop(display,window,prop,type,data,size);
            }
        }
        return prop;
    }
    return None;
}


// Retrieve CLIPBOARD selection data
void FXApp::clipboardGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size)
{
    FXID answer;
    data=NULL;
    size=0;
    if (clipboardWindow)
    {
        event.type=SEL_CLIPBOARD_REQUEST;
        event.target=type;
        ddeData=NULL;
        ddeSize=0;
        clipboardWindow->handle(this,FXSEL(SEL_CLIPBOARD_REQUEST,0),&event);
        data=ddeData;
        size=ddeSize;
        ddeData=NULL;
        ddeSize=0;
    }
    else
    {
        answer=fxsendrequest((Display*)display,window->id(),xcbSelection,ddeAtom,type,event.time);
        fxrecvdata((Display*)display,window->id(),answer,ddeIncr,type,data,size);
    }
}


// Get dropped data; called in response to DND enter or DND drop
bool FXWindow::getDNDData(FXDNDOrigin origin,FXDragType targettype,FXuchar*& data,FXuint& size) const
{
    if (xid==0)
        fxerror("%s::getDNDData: window has not yet been created.\n",getClassName());

    switch (origin)
    {
    case FROM_DRAGNDROP:
        getApp()->dragdropGetData(this,targettype,data,size);
        break;
    case FROM_CLIPBOARD:
        getApp()->clipboardGetData(this,targettype,data,size);
        break;
    case FROM_SELECTION:
        getApp()->selectionGetData(this,targettype,data,size);
        break;
    }
    return data!=NULL;
}




//
// Hack of FXButton (button with gradient effect and rounded corners)
// Original author : Sander Jansen <sander@knology.net>
//


// Draw rectangle with gradient effect
// Default is vertical gradient
static void drawGradientRectangle(FXDC& dc,FXColor upper,FXColor lower,FXint x,FXint y,FXint w,FXint h, FXbool vert=TRUE)
{
    register FXint rr,gg,bb,dr,dg,db,r1,g1,b1,r2,g2,b2,yl,yh,yy,dy,n,t,ww;
    const FXint MAXSTEPS=128;
    if (0<w && 0<h)
    {
        // Horizontal gradient : exchange w and h
        if (!vert)
        {
            ww=w;
            w=h;
            h=ww;
        }

        dc.setStipple(STIPPLE_NONE);
        dc.setFillStyle(FILL_SOLID);

        r1=FXREDVAL(upper);
        r2=FXREDVAL(lower);
        dr=r2-r1;
        g1=FXGREENVAL(upper);
        g2=FXGREENVAL(lower);
        dg=g2-g1;
        b1=FXBLUEVAL(upper);
        b2=FXBLUEVAL(lower);
        db=b2-b1;

        n=FXABS(dr);
        if ((t=FXABS(dg))>n)
            n=t;
        if ((t=FXABS(db))>n)
            n=t;
        n++;
        if (n>h)
            n=h;
        if (n>MAXSTEPS)
            n=MAXSTEPS;
        rr=(r1<<16)+32767;
        gg=(g1<<16)+32767;
        bb=(b1<<16)+32767;
        yy=32767;

        dr=(dr<<16)/n;
        dg=(dg<<16)/n;
        db=(db<<16)/n;
        dy=(h<<16)/n;

        do
        {
            yl=yy>>16;
            yy+=dy;
            yh=yy>>16;
            dc.setForeground(FXRGB(rr>>16,gg>>16,bb>>16));

            // Vertical gradient
            if (vert)
                dc.fillRectangle(x,y+yl,w,yh-yl);

            // Horizontal gradient
            else
                dc.fillRectangle(x+yl,y,yh-yl,w);

            rr+=dr;
            gg+=dg;
            bb+=db;
        }
        while (yh<h);
    }
}



// Some macros to simplify the code
// They draw a button in Standard or Clearlooks mode, in up or down state


#define DRAW_CLEARLOOKS_BUTTON_UP                                      \
dc.setForeground(backColor);                                           \
dc.drawPoints(basebackground,4);                                       \
                                                                       \
dc.setForeground(bordercolor);                                         \
dc.drawRectangle(2,0,width-5,0);                                       \
dc.drawRectangle(2,height-1,width-5,height-1);                         \
dc.drawRectangle(0,2,0,height-5);                                      \
dc.drawRectangle(width-1,2,0,height-5);                                \
dc.drawPoints(bordercorners,4);                                        \
dc.setForeground(shadecolor);                                          \
dc.drawPoints(bordershade,16);                                         \
                                                                       \
drawGradientRectangle(dc,topcolor,bottomcolor,2,1,width-4,height-2);   \
dc.setForeground(topcolor);                                            \
dc.drawRectangle(1,3,0,height-7);                                      \
dc.setForeground(bottomcolor);                                         \
dc.drawRectangle(width-2,3,0,height-7);


#define DRAW_CLEARLOOKS_BUTTON_DOWN                                    \
dc.setForeground(shadecolor);                                          \
dc.fillRectangle(0,0,width,height);                                    \
                                                                       \
dc.setForeground(backColor);                                           \
dc.drawPoints(basebackground,4);                                       \
                                                                       \
dc.setForeground(bordercolor);                                         \
dc.drawRectangle(2,0,width-5,0);                                       \
dc.drawRectangle(2,height-1,width-5,height-1);                         \
dc.drawRectangle(0,2,0,height-5);                                      \
dc.drawRectangle(width-1,2,0,height-5);                                \
dc.drawPoints(bordercorners,4);                                        \
dc.setForeground(shadecolor);                                          \
dc.drawPoints(bordershade,16);


#define DRAW_STANDARD_BUTTON_UP                                        \
dc.setForeground(backColor);                                           \
dc.fillRectangle(border,border,width-border*2,height-border*2);        \
if (options&FRAME_THICK)                                               \
	drawDoubleRaisedRectangle(dc,0,0,width,height);                    \
else                                                                   \
	drawRaisedRectangle(dc,0,0,width,height);


#define DRAW_STANDARD_BUTTON_DOWN                                      \
dc.setForeground(hiliteColor);                                         \
dc.fillRectangle(border,border,width-border*2,height-border*2);        \
if (options&FRAME_THICK)                                               \
	drawDoubleSunkenRectangle(dc,0,0,width,height);                    \
else                                                                   \
	drawSunkenRectangle(dc,0,0,width,height);


#define INIT_CLEARLOOKS                                                                   \
static FXbool init=TRUE;                                                                  \
static FXbool use_clearlooks=TRUE;                                                        \
static FXColor topcolor, bottomcolor, shadecolor, bordercolor;                            \
                                                                                          \
FXPoint basebackground[4]={FXPoint(0,0),FXPoint(width-1,0),FXPoint(0,height-1),           \
                           FXPoint(width-1,height-1)};                                    \
FXPoint bordershade[16]={FXPoint(0,1),FXPoint(1,0),FXPoint(1,2),FXPoint(2,1),             \
						 FXPoint(width-2,0),FXPoint(width-1,1),FXPoint(width-3,1),        \
						 FXPoint(width-2,2),FXPoint(0,height-2),FXPoint(1,height-1),      \
						 FXPoint(1,height-3),FXPoint(2,height-2),                         \
						 FXPoint(width-1,height-2),FXPoint(width-2,height-1),             \
						 FXPoint(width-2,height-3),FXPoint(width-3,height-2)              \
						};                                                                \
FXPoint bordercorners[4]={FXPoint(1,1),FXPoint(1,height-2),FXPoint(width-2,1),            \
                          FXPoint(width-2,height-2)};                                     \
                                                                                          \
if (init)                                                                                 \
{                                                                                         \
	use_clearlooks=getApp()->reg().readUnsignedEntry("SETTINGS","use_clearlooks",TRUE);   \
                                                                                          \
	if (use_clearlooks)                                                                   \
	{                                                                                     \
		FXuint r=FXREDVAL(backColor);                                                     \
		FXuint g=FXGREENVAL(backColor);                                                   \
		FXuint b=FXBLUEVAL(backColor);                                                    \
                                                                                          \
		topcolor=FXRGB(FXMIN(1.1*r,255),FXMIN(1.1*g,255),FXMIN(1.1*b,255));               \
		bottomcolor=FXRGB(0.9*r,0.9*g,0.9*b);                                             \
		shadecolor=FXRGB(0.9*r,0.9*g,0.9*b);                                              \
		bordercolor=FXRGB(0.5*g,0.5*g,0.5*g);                                             \
	}                                                                                     \
	init=FALSE;                                                                           \
}



// Handle repaint
long FXButton::onPaint(FXObject*,FXSelector,void* ptr)
{
    // Initialise Clearlooks
    INIT_CLEARLOOKS

    FXEvent*ev=(FXEvent*)ptr;
    FXDCWindow dc(this,ev);
    FXint tw=0,th=0,iw=0,ih=0,tx,ty,ix,iy;

    // Button with nice gradient effect and rounded corners (Clearlooks)
    if (use_clearlooks)
    {
        // Enabled and checked
        if (state==STATE_ENGAGED && options&BUTTON_TOOLBAR)
        {
            DRAW_CLEARLOOKS_BUTTON_UP
        }
        else if (options&BUTTON_TOOLBAR && !underCursor())
        {
            dc.setForeground(backColor);
            dc.fillRectangle(0,0,width,height);
        }
        else if (state==STATE_UP && ((options&BUTTON_TOOLBAR)==0 || (options&BUTTON_TOOLBAR && underCursor())))
        {
            DRAW_CLEARLOOKS_BUTTON_UP
        }
        else
        {
            DRAW_CLEARLOOKS_BUTTON_DOWN
        }

    }	// End of gradient painting

    // Normal flat rectangular button
    else
    {
        // Got a border at all?
        if (options&(FRAME_RAISED|FRAME_SUNKEN))
        {
            // Toolbar style
            if (options&BUTTON_TOOLBAR)
            {
                // Enabled and cursor inside, and up
                if (isEnabled() && underCursor() && (state==STATE_UP))
                {
                    DRAW_STANDARD_BUTTON_UP
                }

                // Enabled and cursor inside and down
                else if (isEnabled() && underCursor() && (state==STATE_DOWN))
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Enabled and checked
                else if (isEnabled() && (state==STATE_ENGAGED))
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Disabled or unchecked or not under cursor
                else
                {
                    dc.setForeground(backColor);
                    dc.fillRectangle(0,0,width,height);
                }
            }

            // Normal style
            else
            {
                // Draw in up state if disabled or up
                if (!isEnabled() || (state==STATE_UP))
                {
                    DRAW_STANDARD_BUTTON_UP
                }

                // Draw sunken if enabled and either checked or pressed
                // Caution! This one is different!
                else
                {
                    if (state==STATE_ENGAGED)
                        dc.setForeground(hiliteColor);
                    else
                        dc.setForeground(backColor);
                    dc.fillRectangle(border,border,width-border*2,height-border*2);
                    if (options&FRAME_THICK)
                        drawDoubleSunkenRectangle(dc,0,0,width,height);
                    else
                        drawSunkenRectangle(dc,0,0,width,height);
                }
            }
        }

        // No borders
        else
        {
            if (isEnabled() && (state==STATE_ENGAGED))
            {
                dc.setForeground(hiliteColor);
                dc.fillRectangle(0,0,width,height);
            }
            else
            {
                dc.setForeground(backColor);
                dc.fillRectangle(0,0,width,height);
            }
        }

    }  	// End of normal painting

    // Place text & icon
    if (!label.empty())
    {
        tw=labelWidth(label);
        th=labelHeight(label);
    }
    if (icon)
    {
        iw=icon->getWidth();
        ih=icon->getHeight();
    }

    just_x(tx,ix,tw,iw);
    just_y(ty,iy,th,ih);

    // Shift a bit when pressed
    if (state && (options&(FRAME_RAISED|FRAME_SUNKEN)))
    {
        ++tx;
        ++ty;
        ++ix;
        ++iy;
    }

    // Draw enabled state
    if (isEnabled())
    {
        if (icon)
            dc.drawIcon(icon,ix,iy);
        if (!label.empty())
        {
            dc.setFont(font);
            dc.setForeground(textColor);
            drawLabel(dc,label,hotoff,tx,ty,tw,th);
        }
        if (hasFocus())
            dc.drawFocusRectangle(border+1,border+1,width-2*border-2,height-2*border-2);
    }

    // Draw grayed-out state
    else
    {
        if (icon)
            dc.drawIconSunken(icon,ix,iy);
        if (!label.empty())
        {
            dc.setFont(font);
            dc.setForeground(hiliteColor);
            drawLabel(dc,label,hotoff,tx+1,ty+1,tw,th);
            dc.setForeground(shadowColor);
            drawLabel(dc,label,hotoff,tx,ty,tw,th);
        }
    }

    return 1;
}



//
// Hack of FXTextField
//

// Function taken from the FXTextField class and hacked to get an optional rounded rectangle shape
long FXTextField::onPaint(FXObject*,FXSelector,void* ptr)
{
    // Initialise Clearlooks
    INIT_CLEARLOOKS

    FXEvent *ev=(FXEvent*)ptr;
    FXDCWindow dc(this,ev);

    // Draw frame
    drawFrame(dc,0,0,width,height);

    // Draw background
    dc.setForeground(backColor);
    dc.fillRectangle(border,border,width-(border<<1),height-(border<<1));

    // !!!! Hack to get an optional rounded rectangle shape
    if (use_clearlooks)
    {
        // Outside Background
        dc.setForeground(baseColor);
        dc.fillRectangle(0,0,width,height);
        dc.drawPoints(basebackground,4);

        // Border
        dc.setForeground(bordercolor);
        dc.drawRectangle(2,0,width-5,0);
        dc.drawRectangle(2,height-1,width-5,height-1);
        dc.drawRectangle(0,2,0,height-5);
        dc.drawRectangle(width-1,2,0,height-5);
        dc.drawPoints(bordercorners,4);
        dc.setForeground(shadecolor);
        dc.drawPoints(bordershade,16);
        dc.setForeground(backColor);
        dc.fillRectangle(2,1,width-4,height-2);
    }
    // !!!! End of hack

    // Draw text, clipped against frame interior
    dc.setClipRectangle(border,border,width-(border<<1),height-(border<<1));
    drawTextRange(dc,0,contents.length());

    // Draw caret
    if (flags&FLAG_CARET)
    {
        int xx=coord(cursor)-1;
        dc.setForeground(cursorColor);
        dc.fillRectangle(xx,padtop+border,1,height-padbottom-padtop-(border<<1));
        dc.fillRectangle(xx-2,padtop+border,5,1);
        dc.fillRectangle(xx-2,height-border-padbottom-1,5,1);
    }

    return 1;
}



//
// Hack of FXToggleButton
//

// Hack to optionally display a button with a nice gradient effect (Clearlooks theme)
long FXToggleButton::onPaint(FXObject*,FXSelector,void* ptr)
{
    // Initialise Clearlooks
    INIT_CLEARLOOKS

    FXint tw=0,th=0,iw=0,ih=0,tx,ty,ix,iy;
    FXEvent *ev=(FXEvent*)ptr;
    FXDCWindow dc(this,ev);

    // Button with nice gradient effect and rounded corners (Clearlooks)
    if (use_clearlooks)
    {
        // Button style is toolbar
        if (options&TOGGLEBUTTON_TOOLBAR)
        {
            // Enabled and cursor inside and button down
            if (down || ((options&TOGGLEBUTTON_KEEPSTATE) && state))
            {
                DRAW_CLEARLOOKS_BUTTON_DOWN
            }
            // Enabled and cursor inside but button not down
            else if (isEnabled() && underCursor())
            {
                DRAW_CLEARLOOKS_BUTTON_UP
            }

            // Disabled or unchecked or not under cursor
            else
            {
                dc.setForeground(backColor);
                dc.fillRectangle(0,0,width,height);
            }
        }

        // Button style is normal
        else
        {
            // Button down
            if (down || ((options&TOGGLEBUTTON_KEEPSTATE) && state))
            {
                DRAW_CLEARLOOKS_BUTTON_DOWN
            }

            // Button up
            else
            {
                DRAW_CLEARLOOKS_BUTTON_UP
            }
        }

    }	// End of gradient painting

    // Normal flat rectangular button
    else
    {
        // Got a border at all?
        if (options&(FRAME_RAISED|FRAME_SUNKEN))
        {
            // Button style is normal
            if (options&TOGGLEBUTTON_TOOLBAR)
            {
                // Enabled and cursor inside and down
                if (down || ((options&TOGGLEBUTTON_KEEPSTATE) && state))
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Enabled and cursor inside, and up
                else if (isEnabled() && underCursor())
                {
                    DRAW_STANDARD_BUTTON_UP
                }

                // Disabled or unchecked or not under cursor
                else
                {
                    dc.setForeground(backColor);
                    dc.fillRectangle(0,0,width,height);
                }
            }

            // Button style is normal
            else
            {
                // Draw sunken if pressed
                if (down || ((options&TOGGLEBUTTON_KEEPSTATE) && state))
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Draw raised if not currently pressed down
                else
                {
                    DRAW_STANDARD_BUTTON_UP
                }
            }
        }

        // No borders
        else
        {
            dc.setForeground(backColor);
            dc.fillRectangle(0,0,width,height);
        }

    }  	// End of normal painting

    // Place text & icon
    if (state && !altlabel.empty())
    {
        tw=labelWidth(altlabel);
        th=labelHeight(altlabel);
    }
    else if (!label.empty())
    {
        tw=labelWidth(label);
        th=labelHeight(label);
    }
    if (state && alticon)
    {
        iw=alticon->getWidth();
        ih=alticon->getHeight();
    }
    else if (icon)
    {
        iw=icon->getWidth();
        ih=icon->getHeight();
    }

    just_x(tx,ix,tw,iw);
    just_y(ty,iy,th,ih);

    // Shift a bit when pressed
    if ((down || ((options&TOGGLEBUTTON_KEEPSTATE) && state)) && (options&(FRAME_RAISED|FRAME_SUNKEN)))
    {
        ++tx;
        ++ty;
        ++ix;
        ++iy;
    }

    // Draw enabled state
    if (isEnabled())
    {
        if (state && alticon)
            dc.drawIcon(alticon,ix,iy);
        else if (icon)
            dc.drawIcon(icon,ix,iy);
        if (state && !altlabel.empty())
        {
            dc.setFont(font);
            dc.setForeground(textColor);
            drawLabel(dc,altlabel,althotoff,tx,ty,tw,th);
        }
        else if (!label.empty())
        {
            dc.setFont(font);
            dc.setForeground(textColor);
            drawLabel(dc,label,hotoff,tx,ty,tw,th);
        }
        if (hasFocus())
            dc.drawFocusRectangle(border+1,border+1,width-2*border-2,height-2*border-2);
    }

    // Draw grayed-out state
    else
    {
        if (state && alticon)
            dc.drawIconSunken(alticon,ix,iy);
        else if (icon)
            dc.drawIconSunken(icon,ix,iy);
        if (state && !altlabel.empty())
        {
            dc.setFont(font);
            dc.setForeground(hiliteColor);
            drawLabel(dc,altlabel,althotoff,tx+1,ty+1,tw,th);
            dc.setForeground(shadowColor);
            drawLabel(dc,altlabel,althotoff,tx,ty,tw,th);
        }
        else if (!label.empty())
        {
            dc.setFont(font);
            dc.setForeground(hiliteColor);
            drawLabel(dc,label,hotoff,tx+1,ty+1,tw,th);
            dc.setForeground(shadowColor);
            drawLabel(dc,label,hotoff,tx,ty,tw,th);
        }
    }

    return 1;
}


//
// Hack of FXWindow
//

// This hack fixes a bug in FOX that prevent any character to be input
// when FOX was compiled with the --with-xim option
// The bug is fixed in FOX 1.6.35 and above
// However, the hack is still here because the latest FOX is not necessarily present
// on the user's Linux distribution

#include "FXComposeContext.h"

// Create compose context
void FXWindow::createComposeContext()
{
    if (!composeContext)
    {
        composeContext=new FXComposeContext(getApp(),this,0);

        // !!!! This line was missing !!!!
        composeContext->create();
    }
}



//
// Hack of FXTextField
//

// This hack fixes a bug in FOX that make some input fields crash the application
// when FOX was compiled with the --with-xim option
// The bug is not fixed yet in FOX 1.6.36

// Into focus chain
void FXTextField::setFocus()
{
    FXFrame::setFocus();
    setDefault(TRUE);
    flags&=~FLAG_UPDATE;
    if (getApp()->hasInputMethod() && this->id() )
        createComposeContext();
}


//
// Hack of FXApp
//
// This hack fixes a bug in FOX that prevent to enter composed characters when the mouse pointer
// lies outside the text field
// The bug is not fixed yet in FOX 1.6.36


namespace FX
{

// Callback Record
struct FXCBSpec
{
    FXObject      *target;            // Receiver object
    FXSelector     message;           // Message sent to receiver
};


// Timer record
struct FXTimer
{
    FXTimer       *next;              // Next timeout in list
    FXObject      *target;            // Receiver object
    void          *data;              // User data
    FXSelector     message;           // Message sent to receiver
    FXlong         due;               // When timer is due (ns)
};


// Signal record
struct FXSignal
{
    FXObject      *target;            // Receiver object
    FXSelector     message;           // Message sent to receiver
    FXbool         handlerset;        // Handler was already set
    FXbool         notified;          // Signal has fired
};


// Idle record
struct FXChore
{
    FXChore       *next;              // Next chore in list
    FXObject      *target;            // Receiver object
    void          *data;              // User data
    FXSelector     message;           // Message sent to receiver
};


// Input record
struct FXInput
{
    FXCBSpec       read;              // Callback spec for read
    FXCBSpec       write;             // Callback spec for write
    FXCBSpec       excpt;             // Callback spec for except
};


// A repaint event record
struct FXRepaint
{
    FXRepaint     *next;              // Next repaint in list
    FXID           window;            // Window ID of the dirty window
    FXRectangle    rect;              // Dirty rectangle
    FXint          hint;              // Hint for compositing
    FXbool         synth;             // Synthetic expose event or real one?
};


// Recursive Event Loop Invocation
struct FXInvocation
{
    FXInvocation **invocation;  // Pointer to variable holding pointer to current invocation
    FXInvocation  *upper;       // Invocation above this one
    FXWindow      *window;      // Modal window (if any)
    FXModality     modality;    // Modality mode
    FXint          code;        // Return code
    FXbool         done;        // True if breaking out

    // Enter modal loop
    FXInvocation(FXInvocation** inv,FXModality mode,FXWindow* win):invocation(inv),upper(*inv),window(win),modality(mode),code(0),done(FALSE)
    {
        *invocation=this;
    }

    // Exit modal loop
    ~FXInvocation()
    {
        *invocation=upper;
    }
};

} // namespace FX


// Largest number of signals on this system
#define MAXSIGNALS 64

// Regular define
#define SELECT(n,r,w,e,t)  select(n,r,w,e,t)

// Get an event
bool FXApp::getNextEvent(FXRawEvent& ev,bool blocking)
{
    XEvent e;

    // Set to no-op just in case
    ev.xany.type=0;

    // Handle all past due timers
    if (timers)
        handleTimeouts();

    // Check non-immediate signals that may have fired
    if (nsignals)
    {
        for (FXint sig=0; sig<MAXSIGNALS; sig++)
        {
            if (signals[sig].notified)
            {
                signals[sig].notified=FALSE;
                if (signals[sig].target && signals[sig].target->tryHandle(this,FXSEL(SEL_SIGNAL,signals[sig].message),(void*)(FXival)sig))
                {
                    refresh();
                    return false;
                }
            }
        }
    }

    // Are there no events already queued up?
    if (!initialized || !XEventsQueued((Display*)display,QueuedAfterFlush))
    {
        struct timeval delta;
        fd_set readfds;
        fd_set writefds;
        fd_set exceptfds;
        int maxfds;
        int nfds;

        // Prepare fd's to check
        maxfds=maxinput;
        readfds=*((fd_set*)r_fds);
        writefds=*((fd_set*)w_fds);
        exceptfds=*((fd_set*)e_fds);

        // Add connection to display if its open
        if (initialized)
        {
            FD_SET(ConnectionNumber((Display*)display),&readfds);
            if (ConnectionNumber((Display*)display)>maxfds)
                maxfds=ConnectionNumber((Display*)display);
        }

        delta.tv_usec=0;
        delta.tv_sec=0;

        // Do a quick poll for any ready events or inputs
        nfds=SELECT(maxfds+1,&readfds,&writefds,&exceptfds,&delta);

        // Nothing to do, so perform idle processing
        if (nfds==0)
        {
            // Release the expose events
            if (repaints)
            {
                register FXRepaint *r=repaints;
                ev.xany.type=Expose;
                ev.xexpose.window=r->window;
                ev.xexpose.send_event=r->synth;
                ev.xexpose.x=r->rect.x;
                ev.xexpose.y=r->rect.y;
                ev.xexpose.width=r->rect.w-r->rect.x;
                ev.xexpose.height=r->rect.h-r->rect.y;
                repaints=r->next;
                r->next=repaintrecs;
                repaintrecs=r;
                return true;
            }

            // Do our chores :-)
            if (chores)
            {
                register FXChore *c=chores;
                chores=c->next;
                if (c->target && c->target->tryHandle(this,FXSEL(SEL_CHORE,c->message),c->data))
                    refresh();
                c->next=chorerecs;
                chorerecs=c;
            }

            // GUI updating:- walk the whole widget tree.
            if (refresher)
            {
                refresher->handle(this,FXSEL(SEL_UPDATE,0),NULL);
                if (refresher->getFirst())
                    refresher=refresher->getFirst();
                else
                {
                    while (refresher->getParent())
                    {
                        if (refresher->getNext())
                        {
                            refresher=refresher->getNext();
                            break;
                        }
                        refresher=refresher->getParent();
                    }
                }
                FXASSERT(refresher);
                if (refresher!=refresherstop)
                    return false;
                refresher=refresherstop=NULL;
            }

            // There are more chores to do
            if (chores)
                return false;

            // We're not blocking
            if (!blocking)
                return false;

            // Now, block till timeout, i/o, or event
            maxfds=maxinput;
            readfds=*((fd_set*)r_fds);
            writefds=*((fd_set*)w_fds);
            exceptfds=*((fd_set*)e_fds);

            // Add connection to display if its open
            if (initialized)
            {
                FD_SET(ConnectionNumber((Display*)display),&readfds);
                if (ConnectionNumber((Display*)display)>maxfds)
                    maxfds=ConnectionNumber((Display*)display);
            }

            // If there are timers, we block only for a little while.
            if (timers)
            {
                // All that testing above may have taken some time...
                FXlong interval=timers->due-FXThread::time();

                // Some timers are already due; do them right away!
                if (interval<=0)
                    return false;

                // Compute how long to wait
                delta.tv_usec=(interval/1000)%1000000;
                delta.tv_sec=interval/1000000000;

                // Exit critical section
                appMutex.unlock();

                // Block till timer or event or interrupt
                nfds=SELECT(maxfds+1,&readfds,&writefds,&exceptfds,&delta);

                // Enter critical section
                appMutex.lock();
            }

            // If no timers, we block till event or interrupt
            else
            {
                // Exit critical section
                appMutex.unlock();

                // Block until something happens
                nfds=SELECT(maxfds+1,&readfds,&writefds,&exceptfds,NULL);

                // Enter critical section
                appMutex.lock();
            }
        }

        // Timed out or interrupted
        if (nfds<=0)
        {
            if (nfds<0 && errno!=EAGAIN && errno!=EINTR)
                fxerror("Application terminated: interrupt or lost connection errno=%d\n",errno);
            return false;
        }

        // Any other file descriptors set?
        if (0<=maxinput)
        {
            // Examine I/O file descriptors
            for (FXInputHandle fff=0; fff<=maxinput; fff++)
            {
                // Copy the record as the callbacks may try to change things
                FXInput in=inputs[fff];

                // Skip the display connection, which is treated differently
                if (initialized && (fff==ConnectionNumber((Display*)display)))
                    continue;

                // Check file descriptors
                if (FD_ISSET(fff,&readfds))
                    if (in.read.target && in.read.target->tryHandle(this,FXSEL(SEL_IO_READ,in.read.message),(void*)(FXival)fff))
                        refresh();
                if (FD_ISSET(fff,&writefds))
                    if (in.write.target && in.write.target->tryHandle(this,FXSEL(SEL_IO_WRITE,in.write.message),(void*)(FXival)fff))
                        refresh();
                if (FD_ISSET(fff,&exceptfds))
                    if (in.excpt.target && in.excpt.target->tryHandle(this,FXSEL(SEL_IO_EXCEPT,in.read.message),(void*)(FXival)fff))
                        refresh();
            }
        }

        // If there is no event, we're done
        if (!initialized || !FD_ISSET(ConnectionNumber((Display*)display),&readfds) || !XEventsQueued((Display*)display,QueuedAfterReading))
            return false;
    }

    // Get an event
    XNextEvent((Display*)display,&ev);

    // Filter event through input method context, if any

    // !!!! Hack to fix the bug with composed characters !!!!
    FXWindow* focuswin;
    focuswin=getFocusWindow();
    if (xim && focuswin && XFilterEvent(&ev,(Window)focuswin->id()))
        return false;
    // !!!! End of hack !!!!

    // Save expose events for later...
    if (ev.xany.type==Expose || ev.xany.type==GraphicsExpose)
    {
        addRepaint((FXID)ev.xexpose.window,ev.xexpose.x,ev.xexpose.y,ev.xexpose.width,ev.xexpose.height,0);
        return false;
    }

    // Compress motion events
    if (ev.xany.type==MotionNotify)
    {
        while (XPending((Display*)display))
        {
            XPeekEvent((Display*)display,&e);
            if ((e.xany.type!=MotionNotify) || (ev.xmotion.window!=e.xmotion.window) || (ev.xmotion.state != e.xmotion.state))
                break;
            XNextEvent((Display*)display,&ev);
        }
    }

    // Compress wheel events
    else if ((ev.xany.type==ButtonPress) && (ev.xbutton.button==Button4 || ev.xbutton.button==Button5))
    {
        FXint ticks=1;
        while (XPending((Display*)display))
        {
            XPeekEvent((Display*)display,&e);
            if ((e.xany.type!=ButtonPress && e.xany.type!=ButtonRelease) || (ev.xany.window!=e.xany.window) || (ev.xbutton.button != e.xbutton.button))
                break;
            ticks+=(e.xany.type==ButtonPress);
            XNextEvent((Display*)display,&ev);
        }
        ev.xbutton.subwindow=(Window)ticks;   // Stick it here for later
    }

    // Compress configure events
    else if (ev.xany.type==ConfigureNotify)
    {
        while (XCheckTypedWindowEvent((Display*)display,ev.xconfigure.window,ConfigureNotify,&e))
        {
            ev.xconfigure.width=e.xconfigure.width;
            ev.xconfigure.height=e.xconfigure.height;
            if (e.xconfigure.send_event)
            {
                ev.xconfigure.x=e.xconfigure.x;
                ev.xconfigure.y=e.xconfigure.y;
            }
        }
    }

    // Regular event
    return true;
}


//
// Hack of FXScrollArea
//

// This hack allows to scroll in horizontal mode when we are in row and small/big icons mode of a FileList

// Mouse wheel used for vertical scrolling
long FXScrollArea::onVMouseWheel(FXObject* sender,FXSelector sel,void* ptr)
{
    // !!!! Hack to scroll in horizontal mode !!!!
    if (!(options&ICONLIST_COLUMNS) && options&(ICONLIST_BIG_ICONS|ICONLIST_MINI_ICONS) && streq(this->getClassName(),"FileList") )
        horizontal->handle(sender,sel,ptr);
    else
        // !!!! End of hack !!!!
        vertical->handle(sender,sel,ptr);

    return 1;
}



//
// Hack of FXScrollBar
//

// This hack adds an optional gradient with rounded corner theme to the scrollbar (Clearlooks)


// Draw scrollbar button with gradient effect and nice grip
static void drawGradientScrollButton(FXDCWindow& dc, FXColor topcolor, FXColor bottomcolor, FXColor shadecolor, FXColor lightcolor,
                                     FXuint options, FXint x, FXint y, FXint w, FXint h)
{
    // Fill rectangle with gradient in the right direction (vertical or horizontal)
    FXbool vertical=((options&SCROLLBAR_HORIZONTAL) ? TRUE : FALSE);
    drawGradientRectangle(dc,topcolor,bottomcolor,x,y,w,h,vertical);

    // Draw button borders
    dc.setForeground(lightcolor);
    dc.fillRectangle(x+1,y+1,w-1,1);
    dc.fillRectangle(x+1,y+1,1,h-2);
    dc.setForeground(shadecolor);
    dc.fillRectangle(x,y,w,1);
    dc.fillRectangle(x,y,1,h-1);
    dc.fillRectangle(x,y+h-1,w,1);
    dc.fillRectangle(x+w-1,y,1,h);

    // Draw grip lines for horizontal scrollbar
    if ((options&SCROLLBAR_HORIZONTAL))
    {
        dc.setForeground(shadecolor);
        dc.fillRectangle(x+w/2-3,y+4,1,h-7);
        dc.fillRectangle(x+w/2,y+4,1,h-7);
        dc.fillRectangle(x+w/2+3,y+4,1,h-7);
        dc.setForeground(lightcolor);
        dc.fillRectangle(x+w/2-2,y+4,1,h-7);
        dc.fillRectangle(x+w/2+1,y+4,1,h-7);
        dc.fillRectangle(x+w/2+4,y+4,1,h-7);
    }

    // Draw grip lines for vertical scrollbar
    else
    {
        dc.setForeground(shadecolor);
        dc.fillRectangle(x+4,y+h/2-3,w-7,1);
        dc.fillRectangle(x+4,y+h/2,w-7,1);
        dc.fillRectangle(x+4,y+h/2+3,w-7,1);
        dc.setForeground(lightcolor);
        dc.fillRectangle(x+4,y+h/2-2,w-7,1);
        dc.fillRectangle(x+4,y+h/2+1,w-7,1);
        dc.fillRectangle(x+4,y+h/2+4,w-7,1);
    }
}


// Small hack to set the minimum length of the scrollbar button to barsize*2 instead of barsize/2
void FXScrollBar::setPosition(FXint p)
{
    FXint total,travel,lo,hi,l,h;
    pos=p;
    if (pos<0)
        pos=0;
    if (pos>(range-page))
        pos=range-page;
    lo=thumbpos;
    hi=thumbpos+thumbsize;
    if (options&SCROLLBAR_HORIZONTAL)
    {
        total=width-height-height;
        thumbsize=(total*page)/range;
        // !!!! Hack to change the minimum button size !!!!
        if (thumbsize<(barsize<<1))
            thumbsize=(barsize<<1);
        // !!!! End of hack !!!!
        travel=total-thumbsize;
        if (range>page)
            thumbpos=height+(FXint)((((FXdouble)pos)*travel)/(range-page));
        else
            thumbpos=height;
        l=thumbpos;
        h=thumbpos+thumbsize;
        if (l!=lo || h!=hi)
            update(FXMIN(l,lo),0,FXMAX(h,hi)-FXMIN(l,lo),height);
    }
    else
    {
        total=height-width-width;
        thumbsize=(total*page)/range;
        // !!!! Hack to change the minimum button size !!!!
        if (thumbsize<(barsize<<1))
            thumbsize=(barsize<<1);
        // !!!! End of hack !!!!
        travel=total-thumbsize;
        if (range>page)
            thumbpos=width+(FXint)((((FXdouble)pos)*travel)/(range-page));
        else
            thumbpos=width;
        l=thumbpos;
        h=thumbpos+thumbsize;
        if (l!=lo || h!=hi)
            update(0,FXMIN(l,lo),width,FXMAX(h,hi)-FXMIN(l,lo));
    }
}


// Arrow directions
enum
{
    _ARROW_LEFT,
    _ARROW_RIGHT,
    _ARROW_UP,
    _ARROW_DOWN
};


// Draw arrow button in scrollbar with gradient effect and rounded corners (Clearlooks)
static void drawGradientArrowButton(FXDCWindow& dc, FXColor backcolor, FXColor topcolor, FXColor bottomcolor, FXColor shadecolor,
                                    FXColor lightcolor, FXColor bordercolor, FXColor arrowcolor,
                                    FXuint options, FXint x, FXint y, FXint w, FXint h, FXbool down, FXuint direction)
{
    FXPoint arrowpoints[3];
    FXint xx, yy, ah, ab;

    FXPoint basebackground[2];
    FXPoint bordershade[8];
    FXPoint bordercorners[2];

    // Rounded corner and arrow point coordinates depend on the button direction
    if (direction == _ARROW_UP)
    {
        // Rounded corners
        basebackground[0]=FXPoint(0,0);
        basebackground[1]=FXPoint(w-1,0);
        bordercorners[0]=FXPoint(1,1);
        bordercorners[1]=FXPoint(w-2,1);
        bordershade[0]=FXPoint(0,1);
        bordershade[1]=FXPoint(1,0);
        bordershade[2]=FXPoint(1,2);
        bordershade[3]=FXPoint(2,1);
        bordershade[4]=FXPoint(w-2,0);
        bordershade[5]=FXPoint(w-1,1);
        bordershade[6]=FXPoint(w-3,1);
        bordershade[7]=FXPoint(w-2,2);

        // Arrow points
        ab=(w-7)|1;
        ah=ab>>1;
        xx=x+((w-ab)>>1);
        yy=y+((h-ah)>>1);
        if (down)
        {
            ++xx;
            ++yy;
        }
        arrowpoints[0]=FXPoint(xx+(ab>>1),yy-1);
        arrowpoints[1]=FXPoint(xx,yy+ah);
        arrowpoints[2]=FXPoint(xx+ab,yy+ah);
    }
    else if (direction == _ARROW_DOWN)
    {
        // Rounded corners
        basebackground[0]=FXPoint(x,y+h-1);
        basebackground[1]=FXPoint(x+w-1,y+h-1);
        bordercorners[0]=FXPoint(x+1,y+h-2);
        bordercorners[1]=FXPoint(x+w-2,y+h-2);
        bordershade[0]=FXPoint(x,y+h-2);
        bordershade[1]=FXPoint(x+1,y+h-1);
        bordershade[2]=FXPoint(x+1,y+h-3);
        bordershade[3]=FXPoint(x+2,y+h-2);
        bordershade[4]=FXPoint(x+w-1,y+h-2);
        bordershade[5]=FXPoint(x+w-2,y+h-1);
        bordershade[6]=FXPoint(x+w-2,y+h-3);
        bordershade[7]=FXPoint(x+w-3,y+h-2);

        // Arrow points
        ab=(w-7)|1;
        ah=ab>>1;
        xx=x+((w-ab)>>1);
        yy=y+((h-ah)>>1);
        if (down)
        {
            ++xx;
            ++yy;
        }
        arrowpoints[0]=FXPoint(xx+1,yy);
        arrowpoints[1]=FXPoint(xx+ab-1,yy);
        arrowpoints[2]=FXPoint(xx+(ab>>1),yy+ah);
    }
    else if (direction == _ARROW_LEFT)
    {
        // Rounded corners
        basebackground[0]=FXPoint(0,0);
        basebackground[1]=FXPoint(0,h-1);
        bordercorners[0]=FXPoint(1,1);
        bordercorners[1]=FXPoint(1,h-2);
        bordershade[0]=FXPoint(0,1);
        bordershade[1]=FXPoint(1,0);
        bordershade[2]=FXPoint(1,2);
        bordershade[3]=FXPoint(2,1);
        bordershade[4]=FXPoint(0,h-2);
        bordershade[5]=FXPoint(1,h-1);
        bordershade[6]=FXPoint(1,h-3);
        bordershade[7]=FXPoint(2,h-2);

        // Arrow points
        ab=(h-7)|1;
        ah=ab>>1;
        xx=x+((w-ah)>>1);
        yy=y+((h-ab)>>1);
        if (down)
        {
            ++xx;
            ++yy;
        }
        arrowpoints[0]=FXPoint(xx+ah,yy);
        arrowpoints[1]=FXPoint(xx+ah,yy+ab-1);
        arrowpoints[2]=FXPoint(xx,yy+(ab>>1));
    }
    else // _ARROW_RIGHT
    {
        // Rounded corners
        basebackground[0]=FXPoint(x+w-1,y);
        basebackground[1]=FXPoint(x+w-1,y+h-1);
        bordercorners[0]=FXPoint(x+w-2,y+1);
        bordercorners[1]=FXPoint(x+w-2,y+h-2);
        bordershade[0]=FXPoint(x+w-2,y);
        bordershade[1]=FXPoint(x+w-1,y+1);
        bordershade[2]=FXPoint(x+w-3,y+1);
        bordershade[3]=FXPoint(x+w-2,y+2);
        bordershade[4]=FXPoint(x+w-1,y+h-2);
        bordershade[5]=FXPoint(x+w-2,y+h-1);
        bordershade[6]=FXPoint(x+w-2,y+h-3);
        bordershade[7]=FXPoint(x+w-3,y+h-2);

        // Arrow points
        ab=(h-7)|1;
        ah=ab>>1;
        xx=x+((w-ah)>>1);
        yy=y+((h-ab)>>1);
        if (down)
        {
            ++xx;
            ++yy;
        }
        arrowpoints[0]=FXPoint(xx,yy);
        arrowpoints[1]=FXPoint(xx,yy+ab-1);
        arrowpoints[2]=FXPoint(xx+ah,yy+(ab>>1));
    }

    // Draw button when up
    if (!down)
    {
        // Fill rectangle with gradient in the right direction (vertical or horizontal)
        FXbool vertical=((options&SCROLLBAR_HORIZONTAL) ? TRUE : FALSE);
        drawGradientRectangle(dc,topcolor,bottomcolor,x,y,w,h,vertical);

        // Button borders
        dc.setForeground(lightcolor);
        dc.fillRectangle(x+1,y+1,w-1,1);
        dc.fillRectangle(x+1,y+1,1,h-2);
        dc.setForeground(shadecolor);
        dc.fillRectangle(x,y,w,1);
        dc.fillRectangle(x,y,1,h-1);
        dc.fillRectangle(x,y+h-1,w,1);
        dc.fillRectangle(x+w-1,y,1,h);

        // Rounded corners
        dc.setForeground(backcolor);
        dc.drawPoints(basebackground,2);
        dc.setForeground(shadecolor);
        dc.drawPoints(bordercorners,2);
        dc.setForeground(bordercolor);
        dc.drawPoints(bordershade,8);

        // Arrow
        dc.setForeground(arrowcolor);
        dc.fillPolygon(arrowpoints,3);
    }

    // Draw button when down (pressed)
    else
    {
        // Dark background
        dc.setForeground(bordercolor);
        dc.fillRectangle(x,y,w,h);

        // Button borders
        dc.setForeground(lightcolor);
        dc.fillRectangle(x+1,y+1,w-1,1);
        dc.fillRectangle(x+1,y+1,1,h-2);
        dc.setForeground(shadecolor);
        dc.fillRectangle(x,y,w,1);
        dc.fillRectangle(x,y,1,h-1);
        dc.fillRectangle(x,y+h-1,w,1);
        dc.fillRectangle(x+w-1,y,1,h);

        // Rounded corners
        dc.setForeground(backcolor);
        dc.drawPoints(basebackground,2);
        dc.setForeground(shadecolor);
        dc.drawPoints(bordercorners,2);
        dc.setForeground(bordercolor);
        dc.drawPoints(bordershade,8);

        // Arrow
        dc.setForeground(arrowcolor);
        dc.fillPolygon(arrowpoints,3);
    }
}


// Handle repaint
long FXScrollBar::onPaint(FXObject*,FXSelector,void* ptr)
{
    // Caution! Don't use the macro here because it's slightly different

    static FXbool init=TRUE;
    static FXbool use_clearlooks=TRUE;
    static FXColor topcolor, bottomcolor, shadecolor, bordercolor, lightcolor;

    register FXEvent *ev=(FXEvent*)ptr;
    register int total;
    FXDCWindow dc(this,ev);

    // At first run, select the scrollbar style
    if (init)
    {
        use_clearlooks=getApp()->reg().readUnsignedEntry("SETTINGS","use_clearlooks",TRUE);

        // Compute gradient colors from the base color
        if (use_clearlooks)
        {
            // Decompose the base color
            FXuint r=FXREDVAL(backColor);
            FXuint g=FXGREENVAL(backColor);
            FXuint b=FXBLUEVAL(backColor);

            // Compute the gradient colors from the base color
            topcolor=FXRGB(FXMIN(1.1*r,255),FXMIN(1.1*g,255),FXMIN(1.1*b,255));
            bottomcolor=FXRGB(0.9*r,0.9*g,0.9*b);
            shadecolor=FXRGB(0.8*r,0.8*g,0.8*b);
            bordercolor=FXRGB(0.9*r,0.9*g,0.9*b);
            lightcolor=FXRGB(FXMIN(1.3*r,255),FXMIN(1.3*g,255),FXMIN(1.3*b,255));
        }
        init=FALSE;
    }

    // Nice scrollbar with gradient and rounded corners
    if (use_clearlooks)
    {
        if (options&SCROLLBAR_HORIZONTAL)
        {
            total=width-height-height;
            if (thumbsize<total)                                    // Scrollable
            {
                drawGradientScrollButton(dc,topcolor,bottomcolor,shadecolor,lightcolor,options,thumbpos,0,thumbsize,height);
                dc.setForeground(bordercolor);
                dc.setBackground(backColor);
                dc.fillRectangle(height,0,thumbpos-height,height);
                dc.fillRectangle(thumbpos+thumbsize,0,width-height-thumbpos-thumbsize,height);
            }
            else                                                    // Non-scrollable
            {
                dc.setForeground(bordercolor);
                dc.setBackground(backColor);
                dc.fillRectangle(height,0,total,height);
            }
            drawGradientArrowButton(dc,backColor,topcolor,bottomcolor,shadecolor,lightcolor,bordercolor,arrowColor,options,width-height,0,height,height,(mode==MODE_INC),_ARROW_RIGHT);
            drawGradientArrowButton(dc,backColor,topcolor,bottomcolor,shadecolor,lightcolor,bordercolor,arrowColor,options,0,0,height,height,(mode==MODE_DEC),_ARROW_LEFT);
        }

        // Vertical
        else
        {
            total=height-width-width;
            if (thumbsize<total)                                    // Scrollable
            {
                drawGradientScrollButton(dc,topcolor,bottomcolor,shadecolor,lightcolor,options,0,thumbpos,width,thumbsize);
                dc.setForeground(bordercolor);
                dc.setBackground(backColor);
                dc.fillRectangle(0,width,width,thumbpos-width);
                dc.fillRectangle(0,thumbpos+thumbsize,width,height-width-thumbpos-thumbsize);
            }
            else                                                    // Non-scrollable
            {
                dc.setForeground(bordercolor);
                dc.setBackground(backColor);
                dc.fillRectangle(0,width,width,total);
            }
            drawGradientArrowButton(dc,backColor,topcolor,bottomcolor,shadecolor,lightcolor,bordercolor,arrowColor,options,0,height-width,width,width,(mode==MODE_INC),_ARROW_DOWN);
            drawGradientArrowButton(dc,backColor,topcolor,bottomcolor,shadecolor,lightcolor,bordercolor,arrowColor,options,0,0,width,width,(mode==MODE_DEC),_ARROW_UP);
        }
    }

    // Standard (flat) scrollbar
    else
    {
        if (options&SCROLLBAR_HORIZONTAL)
        {
            total=width-height-height;
            if (thumbsize<total)                                    // Scrollable
            {
                drawButton(dc,thumbpos,0,thumbsize,height,0);
                dc.setStipple(STIPPLE_GRAY);
                dc.setFillStyle(FILL_OPAQUESTIPPLED);
                if (mode==MODE_PAGE_DEC)
                {
                    dc.setForeground(backColor);
                    dc.setBackground(shadowColor);
                }
                else
                {
                    dc.setForeground(hiliteColor);
                    dc.setBackground(backColor);
                }
                dc.fillRectangle(height,0,thumbpos-height,height);
                if (mode==MODE_PAGE_INC)
                {
                    dc.setForeground(backColor);
                    dc.setBackground(shadowColor);
                }
                else
                {
                    dc.setForeground(hiliteColor);
                    dc.setBackground(backColor);
                }
                dc.fillRectangle(thumbpos+thumbsize,0,width-height-thumbpos-thumbsize,height);
            }
            else                                                    // Non-scrollable
            {
                dc.setStipple(STIPPLE_GRAY);
                dc.setFillStyle(FILL_OPAQUESTIPPLED);
                dc.setForeground(hiliteColor);
                dc.setBackground(backColor);
                dc.fillRectangle(height,0,total,height);
            }
            dc.setFillStyle(FILL_SOLID);
            drawButton(dc,width-height,0,height,height,(mode==MODE_INC));
            drawRightArrow(dc,width-height,0,height,height,(mode==MODE_INC));
            drawButton(dc,0,0,height,height,(mode==MODE_DEC));
            drawLeftArrow(dc,0,0,height,height,(mode==MODE_DEC));
        }
        else
        {
            total=height-width-width;
            if (thumbsize<total)                                    // Scrollable
            {
                drawButton(dc,0,thumbpos,width,thumbsize,0);
                dc.setStipple(STIPPLE_GRAY);
                dc.setFillStyle(FILL_OPAQUESTIPPLED);
                if (mode==MODE_PAGE_DEC)
                {
                    dc.setForeground(backColor);
                    dc.setBackground(shadowColor);
                }
                else
                {
                    dc.setForeground(hiliteColor);
                    dc.setBackground(backColor);
                }
                dc.fillRectangle(0,width,width,thumbpos-width);
                if (mode==MODE_PAGE_INC)
                {
                    dc.setForeground(backColor);
                    dc.setBackground(shadowColor);
                }
                else
                {
                    dc.setForeground(hiliteColor);
                    dc.setBackground(backColor);
                }
                dc.fillRectangle(0,thumbpos+thumbsize,width,height-width-thumbpos-thumbsize);
            }
            else                                                    // Non-scrollable
            {
                dc.setStipple(STIPPLE_GRAY);
                dc.setFillStyle(FILL_OPAQUESTIPPLED);
                dc.setForeground(hiliteColor);
                dc.setBackground(backColor);
                dc.fillRectangle(0,width,width,total);
            }
            dc.setFillStyle(FILL_SOLID);
            drawButton(dc,0,height-width,width,width,(mode==MODE_INC));
            drawDownArrow(dc,0,height-width,width,width,(mode==MODE_INC));
            drawButton(dc,0,0,width,width,(mode==MODE_DEC));
            drawUpArrow(dc,0,0,width,width,(mode==MODE_DEC));
        }
    }
    return 1;
}


//
// Hack of FXComboBox
//

// This hack adds an optional gradient with rounded corner theme to the combobox button (Clearlooks)

#define MENUBUTTONARROW_WIDTH   11
#define MENUBUTTONARROW_HEIGHT  5


// Small hack related to the Clearlooks theme
FXComboBox::FXComboBox(FXComposite *p,FXint cols,FXObject* tgt,FXSelector sel,FXuint opts,FXint x,FXint y,FXint w,FXint h,FXint pl,FXint pr,FXint pt,FXint pb):
        FXPacker(p,opts,x,y,w,h, 0,0,0,0, 0,0)
{
    flags|=FLAG_ENABLED;
    target=tgt;
    message=sel;

    // !!!! Hack to set options to TEXTFIELD_NORMAL instead of 0 (used by the Clearlooks theme)
    field=new FXTextField(this,cols,this,FXComboBox::ID_TEXT,TEXTFIELD_NORMAL, 0,0,0,0, pl,pr,pt,pb);
    // !!!! End of hack

    if (options&COMBOBOX_STATIC)
        field->setEditable(FALSE);
    pane=new FXPopup(this,FRAME_LINE);
    list=new FXList(pane,this,FXComboBox::ID_LIST,LIST_BROWSESELECT|LIST_AUTOSELECT|LAYOUT_FILL_X|LAYOUT_FILL_Y|SCROLLERS_TRACK|HSCROLLER_NEVER);
    if (options&COMBOBOX_STATIC)
        list->setScrollStyle(SCROLLERS_TRACK|HSCROLLING_OFF);
    button=new FXMenuButton(this,FXString::null,NULL,pane,FRAME_RAISED|FRAME_THICK|MENUBUTTON_DOWN|MENUBUTTON_ATTACH_RIGHT, 0,0,0,0, 0,0,0,0);
    button->setXOffset(border);
    button->setYOffset(border);

    flags&=~FLAG_UPDATE;  // Never GUI update
}


//
// Hack of FXMenuButton
//

// This hack adds an optional gradient with rounded corner theme to the combobox button (Clearlooks)


// Handle repaint
long FXMenuButton::onPaint(FXObject*,FXSelector,void* ptr)
{
    // Initialise Clearlooks
    INIT_CLEARLOOKS

    FXint tw=0,th=0,iw=0,ih=0,tx,ty,ix,iy;
    FXEvent *ev=(FXEvent*)ptr;
    FXPoint points[3];
    FXDCWindow dc(this,ev);

    // Button with nice gradient effect and rounded corners (Clearlooks)
    if (use_clearlooks)
    {
        // Toolbar style
        if (options&MENUBUTTON_TOOLBAR)
        {
            // Enabled and cursor inside, and not popped up
            if (isEnabled() && underCursor() && !state)
            {
                DRAW_CLEARLOOKS_BUTTON_DOWN
            }

            // Enabled and popped up
            else if (isEnabled() && state)
            {
                DRAW_CLEARLOOKS_BUTTON_UP
            }

            // Disabled or unchecked or not under cursor
            else
            {
                dc.setForeground(backColor);
                dc.fillRectangle(0,0,width,height);
            }
        }

        // Normal style
        else
        {
            // Draw in up state if disabled or up
            if (!isEnabled() || !state)
            {
                DRAW_CLEARLOOKS_BUTTON_UP
            }

            // If enabled and either checked or pressed
            else
            {
                DRAW_CLEARLOOKS_BUTTON_DOWN
            }
        }

    }	// End of gradient painting


    // Normal flat rectangular button
    else
    {
        // Got a border at all?
        if (options&(FRAME_RAISED|FRAME_SUNKEN))
        {
            // Toolbar style
            if (options&MENUBUTTON_TOOLBAR)
            {
                // Enabled and cursor inside, and not popped up
                if (isEnabled() && underCursor() && !state)
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Enabled and popped up
                else if (isEnabled() && state)
                {
                    DRAW_STANDARD_BUTTON_UP
                }

                // Disabled or unchecked or not under cursor
                else
                {
                    dc.setForeground(backColor);
                    dc.fillRectangle(0,0,width,height);
                }
            }

            // Normal style
            else
            {

                // Draw in up state if disabled or up
                if (!isEnabled() || !state)
                {
                    DRAW_STANDARD_BUTTON_UP
                }

                // Draw sunken if enabled and either checked or pressed
                else
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }
            }
        }

        // No borders
        else
        {
            if (isEnabled() && state)
            {
                dc.setForeground(hiliteColor);
                dc.fillRectangle(0,0,width,height);
            }
            else
            {
                dc.setForeground(backColor);
                dc.fillRectangle(0,0,width,height);
            }
        }

    }  	// End of normal painting

    // Position text & icon
    if (!label.empty())
    {
        tw=labelWidth(label);
        th=labelHeight(label);
    }

    // Icon?
    if (icon)
    {
        iw=icon->getWidth();
        ih=icon->getHeight();
    }

    // Arrows?
    else if (!(options&MENUBUTTON_NOARROWS))
    {
        if (options&MENUBUTTON_LEFT)
        {
            ih=MENUBUTTONARROW_WIDTH;
            iw=MENUBUTTONARROW_HEIGHT;
        }
        else
        {
            iw=MENUBUTTONARROW_WIDTH;
            ih=MENUBUTTONARROW_HEIGHT;
        }
    }

    // Keep some room for the arrow!
    just_x(tx,ix,tw,iw);
    just_y(ty,iy,th,ih);

    // Move a bit when pressed
    if (state)
    {
        ++tx;
        ++ty;
        ++ix;
        ++iy;
    }

    // Draw icon
    if (icon)
    {
        if (isEnabled())
            dc.drawIcon(icon,ix,iy);
        else
            dc.drawIconSunken(icon,ix,iy);
    }

    // Draw arrows
    else if (!(options&MENUBUTTON_NOARROWS))
    {
        // Right arrow
        if ((options&MENUBUTTON_RIGHT)==MENUBUTTON_RIGHT)
        {
            if (isEnabled())
                dc.setForeground(textColor);
            else
                dc.setForeground(shadowColor);
            points[0].x=ix;
            points[0].y=iy;
            points[1].x=ix;
            points[1].y=iy+MENUBUTTONARROW_WIDTH-1;
            points[2].x=ix+MENUBUTTONARROW_HEIGHT;
            points[2].y=(FXshort)(iy+(MENUBUTTONARROW_WIDTH>>1));
            dc.fillPolygon(points,3);
        }

        // Left arrow
        else if (options&MENUBUTTON_LEFT)
        {
            if (isEnabled())
                dc.setForeground(textColor);
            else
                dc.setForeground(shadowColor);
            points[0].x=ix+MENUBUTTONARROW_HEIGHT;
            points[0].y=iy;
            points[1].x=ix+MENUBUTTONARROW_HEIGHT;
            points[1].y=iy+MENUBUTTONARROW_WIDTH-1;
            points[2].x=ix;
            points[2].y=(FXshort)(iy+(MENUBUTTONARROW_WIDTH>>1));
            dc.fillPolygon(points,3);
        }

        // Up arrow
        else if (options&MENUBUTTON_UP)
        {
            if (isEnabled())
                dc.setForeground(textColor);
            else
                dc.setForeground(shadowColor);
            points[0].x=(FXshort)(ix+(MENUBUTTONARROW_WIDTH>>1));
            points[0].y=iy-1;
            points[1].x=ix;
            points[1].y=iy+MENUBUTTONARROW_HEIGHT;
            points[2].x=ix+MENUBUTTONARROW_WIDTH;
            points[2].y=iy+MENUBUTTONARROW_HEIGHT;
            dc.fillPolygon(points,3);
        }

        // Down arrow
        else
        {
            if (isEnabled())
                dc.setForeground(textColor);
            else
                dc.setForeground(shadowColor);
            points[0].x=ix+1;
            points[0].y=iy;
            points[2].x=ix+MENUBUTTONARROW_WIDTH-1;
            points[2].y=iy;
            points[1].x=(FXshort)(ix+(MENUBUTTONARROW_WIDTH>>1));
            points[1].y=iy+MENUBUTTONARROW_HEIGHT;
            dc.fillPolygon(points,3);
        }
    }

    // Draw text
    if (!label.empty())
    {
        dc.setFont(font);
        if (isEnabled())
        {
            dc.setForeground(textColor);
            drawLabel(dc,label,hotoff,tx,ty,tw,th);
        }
        else
        {
            dc.setForeground(hiliteColor);
            drawLabel(dc,label,hotoff,tx+1,ty+1,tw,th);
            dc.setForeground(shadowColor);
            drawLabel(dc,label,hotoff,tx,ty,tw,th);
        }
    }

    // Draw focus
    if (hasFocus())
    {
        if (isEnabled())
            dc.drawFocusRectangle(border+1,border+1,width-2*border-2,height-2*border-2);
    }
    return 1;
}



//
// Hack of FXArrowButton
//

// This hack adds an optional gradient with rounded corner theme to the arrow button (Clearlooks)


// Handle repaint
long FXArrowButton::onPaint(FXObject*,FXSelector,void* ptr)
{
    // Initialise Clearlooks
    INIT_CLEARLOOKS

    FXEvent   *ev=(FXEvent*)ptr;
    FXDCWindow dc(this,ev);
    FXPoint    points[3];
    FXint      xx,yy,ww,hh,q;

    // Button with nice gradient effect and rounded corners (Clearlooks)
    if (use_clearlooks)
    {
        // Toolbar style
        if (options&ARROW_TOOLBAR)
        {
            // Enabled and cursor inside, and up
            if (isEnabled() && underCursor() && !state)
            {
                DRAW_CLEARLOOKS_BUTTON_UP
            }

            // Enabled and cursor inside and down
            else if (isEnabled() && state)
            {
                DRAW_CLEARLOOKS_BUTTON_DOWN
            }

            // Disabled or unchecked or not under cursor
            else
            {
                dc.setForeground(backColor);
                dc.fillRectangle(0,0,width,height);
            }
        }

        // Normal style
        else
        {
            // Draw sunken if enabled and pressed
            if (isEnabled() && state)
            {
                DRAW_CLEARLOOKS_BUTTON_DOWN
            }

            // Draw in up state if disabled or up
            else
            {
                DRAW_CLEARLOOKS_BUTTON_UP
            }
        }

    }	// End of gradient painting

    // Normal flat rectangular button
    else
    {
        // With borders
        if (options&(FRAME_RAISED|FRAME_SUNKEN))
        {
            // Toolbar style
            if (options&ARROW_TOOLBAR)
            {
                // Enabled and cursor inside, and up
                if (isEnabled() && underCursor() && !state)
                {
                    DRAW_STANDARD_BUTTON_UP
                }

                // Enabled and cursor inside and down
                else if (isEnabled() && state)
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Disabled or unchecked or not under cursor
                else
                {
                    dc.setForeground(backColor);
                    dc.fillRectangle(0,0,width,height);
                }
            }

            // Normal style
            else
            {
                // Draw sunken if enabled and pressed
                if (isEnabled() && state)
                {
                    DRAW_STANDARD_BUTTON_DOWN
                }

                // Draw in up state if disabled or up
                else
                {
                    DRAW_STANDARD_BUTTON_UP
                }
            }
        }

        // No borders
        else
        {
            if (isEnabled() && state)
            {
                dc.setForeground(hiliteColor);
                dc.fillRectangle(0,0,width,height);
            }
            else
            {
                dc.setForeground(backColor);
                dc.fillRectangle(0,0,width,height);
            }
        }

    }  	// End of normal painting

    // Compute size of the arrows....
    ww=width-padleft-padright-(border<<1);
    hh=height-padtop-padbottom-(border<<1);
    if (options&(ARROW_UP|ARROW_DOWN))
    {
        q=ww|1;
        if (q>(hh<<1)) q=(hh<<1)-1;
        ww=q;
        hh=q>>1;
    }
    else
    {
        q=hh|1;
        if (q>(ww<<1)) q=(ww<<1)-1;
        ww=q>>1;
        hh=q;
    }

    if (options&JUSTIFY_LEFT) xx=padleft+border;
    else if (options&JUSTIFY_RIGHT) xx=width-ww-padright-border;
    else xx=(width-ww)/2;

    if (options&JUSTIFY_TOP) yy=padtop+border;
    else if (options&JUSTIFY_BOTTOM) yy=height-hh-padbottom-border;
    else yy=(height-hh)/2;

    if (state)
    {
        ++xx;
        ++yy;
    }

    if (isEnabled())
        dc.setForeground(arrowColor);
    else
        dc.setForeground(shadowColor);

    // NB Size of arrow should stretch
    if (options&ARROW_UP)
    {
        points[0].x=xx+(ww>>1);
        points[0].y=yy-1;
        points[1].x=xx;
        points[1].y=yy+hh;
        points[2].x=xx+ww;
        points[2].y=yy+hh;
        dc.fillPolygon(points,3);
    }
    else if (options&ARROW_DOWN)
    {
        points[0].x=xx+1;
        points[0].y=yy;
        points[1].x=xx+ww-1;
        points[1].y=yy;
        points[2].x=xx+(ww>>1);
        points[2].y=yy+hh;
        dc.fillPolygon(points,3);
    }
    else if (options&ARROW_LEFT)
    {
        points[0].x=xx+ww;
        points[0].y=yy;
        points[1].x=xx+ww;
        points[1].y=yy+hh-1;
        points[2].x=xx;
        points[2].y=yy+(hh>>1);
        dc.fillPolygon(points,3);
    }
    else if (options&ARROW_RIGHT)
    {
        points[0].x=xx;
        points[0].y=yy;
        points[1].x=xx;
        points[1].y=yy+hh-1;
        points[2].x=xx+ww;
        points[2].y=yy+(hh>>1);
        dc.fillPolygon(points,3);
    }
    return 1;
}



//
// Hack of FXProgressBar
//

// This hack adds an optional gradient theme to the progress bar (Clearlooks)
// Note : not implemented for the dial progress bar!


// Draw only the interior, i.e. the part that changes
void FXProgressBar::drawInterior(FXDCWindow& dc)
{
    static FXbool init=TRUE;
    static FXbool use_clearlooks=TRUE;
    static FXColor topcolor, bottomcolor;

    // Init Clearlooks (don't use the macro because here it's different)
    if (init)
    {
        use_clearlooks=getApp()->reg().readUnsignedEntry("SETTINGS","use_clearlooks",TRUE);

        if (use_clearlooks)
        {
            FXuint r=FXREDVAL(barColor);
            FXuint g=FXGREENVAL(barColor);
            FXuint b=FXBLUEVAL(barColor);

            topcolor=FXRGB(FXMIN(1.2*r,255),FXMIN(1.2*g,255),FXMIN(1.2*b,255));
            bottomcolor=FXRGB(0.9*r,0.9*g,0.9*b);
        }
        init=FALSE;
    }

    FXint percent,barlength,barfilled,tx,ty,tw,th,n,d;
    FXchar numtext[5];

    if (options&PROGRESSBAR_DIAL)
    {
        // If total is 0, it's 100%
        barfilled=23040;
        percent=100;
        if (total!=0)
        {
            barfilled=(FXuint) (((double)progress * (double)23040) / (double)total);
            percent=(FXuint) (((double)progress * 100.0) / (double)total);
        }

        tw=width-(border<<1)-padleft-padright;
        th=height-(border<<1)-padtop-padbottom;
        d=FXMIN(tw,th)-1;

        tx=border+padleft+((tw-d)/2);
        ty=border+padtop+((th-d)/2);

        if (barfilled!=23040)
        {
            dc.setForeground(barBGColor);
            dc.fillArc(tx,ty,d,d,5760,23040-barfilled);
        }
        if (barfilled!=0)
        {
            dc.setForeground(barColor);
            dc.fillArc(tx,ty,d,d,5760,-barfilled);
        }

        // Draw outside circle
        dc.setForeground(borderColor);
        dc.drawArc(tx+1,ty,d,d,90*64,45*64);
        dc.drawArc(tx,ty+1,d,d,135*64,45*64);
        dc.setForeground(baseColor);
        dc.drawArc(tx-1,ty,d,d,270*64,45*64);
        dc.drawArc(tx,ty-1,d,d,315*64,45*64);

        dc.setForeground(shadowColor);
        dc.drawArc(tx,ty,d,d,45*64,180*64);
        dc.setForeground(hiliteColor);
        dc.drawArc(tx,ty,d,d,225*64,180*64);

        // Draw text
        if (options&PROGRESSBAR_PERCENTAGE)
        {
            dc.setFont(font);
            tw=font->getTextWidth("100%",4);
            if (tw>(10*d)/16) return;
            th=font->getFontHeight();
            if (th>d/2) return;
            sprintf(numtext,"%d%%",percent);
            n=strlen(numtext);
            tw=font->getTextWidth(numtext,n);
            th=font->getFontHeight();
            tx=tx+d/2-tw/2;
            ty=ty+d/2+font->getFontAscent()+5;
            //dc.setForeground(textNumColor);
#ifdef HAVE_XFT_H
            dc.setForeground(barBGColor);             // Code for XFT until XFT can use BLT_SRC_XOR_DST
            dc.drawText(tx-1,ty,numtext,n);
            dc.drawText(tx+1,ty,numtext,n);
            dc.drawText(tx,ty-1,numtext,n);
            dc.drawText(tx,ty+1,numtext,n);
            dc.setForeground(textNumColor);
            dc.drawText(tx,ty,numtext,n);
#else
            dc.setForeground(FXRGB(255,255,255));     // Original code
            dc.setFunction(BLT_SRC_XOR_DST);
            dc.drawText(tx,ty,numtext,n);
#endif
        }
    }

    // Vertical bar
    else if (options&PROGRESSBAR_VERTICAL)
    {
        // If total is 0, it's 100%
        barlength=height-border-border;
        barfilled=barlength;
        percent=100;
        if (total!=0)
        {
            barfilled=(FXuint) (((double)progress * (double)barlength) / (double)total);
            percent=(FXuint) (((double)progress * 100.0) / (double)total);
        }

        // Draw completed bar
        if (0<barfilled)
        {
            // Clearlooks (simple gradient)
            if (use_clearlooks)
            {
                dc.setForeground(barColor);
                drawGradientRectangle(dc,topcolor,bottomcolor,border,height-border-barfilled,width-(border<<1),barfilled,FALSE);
            }
            // Standard (flat)
            else
            {
                dc.setForeground(barColor);
                dc.fillRectangle(border,height-border-barfilled,width-(border<<1),barfilled);
            }
        }

        // Draw uncompleted bar
        if (barfilled<barlength)
        {
            dc.setForeground(barBGColor);
            dc.fillRectangle(border,border,width-(border<<1),barlength-barfilled);
        }

        // Draw text
        if (options&PROGRESSBAR_PERCENTAGE)
        {
            dc.setFont(font);
            sprintf(numtext,"%d%%",percent);
            n=strlen(numtext);
            tw=font->getTextWidth(numtext,n);
            th=font->getFontHeight();
            ty=(height-th)/2+font->getFontAscent();
            tx=(width-tw)/2;
            if (height-border-barfilled>ty)           // In upper side
            {
                dc.setForeground(textNumColor);
                dc.setClipRectangle(border,border,width-(border<<1),height-(border<<1));
                dc.drawText(tx,ty,numtext,n);
            }
            else if (ty-th>height-border-barfilled)   // In lower side
            {
                dc.setForeground(textAltColor);
                dc.setClipRectangle(border,border,width-(border<<1),height-(border<<1));
                dc.drawText(tx,ty,numtext,n);
            }
            else                                      // In between!
            {
                dc.setForeground(textAltColor);
                dc.setClipRectangle(border,height-border-barfilled,width-(border<<1),barfilled);
                dc.drawText(tx,ty,numtext,n);
                dc.setForeground(textNumColor);
                dc.setClipRectangle(border,border,width-(border<<1),barlength-barfilled);
                dc.drawText(tx,ty,numtext,n);
                dc.clearClipRectangle();
            }
        }
    }

    // Horizontal bar
    else
    {
        // If total is 0, it's 100%
        barlength=width-border-border;
        barfilled=barlength;
        percent=100;
        if (total!=0)
        {
            barfilled=(FXuint) (((double)progress * (double)barlength) / (double)total);
            percent=(FXuint) (((double)progress * 100.0) / (double)total);
        }

        // Draw completed bar
        if (0<barfilled)
        {
            // Clearlooks (simple gradient)
            if (use_clearlooks)
            {
                dc.setForeground(barColor);
                drawGradientRectangle(dc,topcolor,bottomcolor,border,border,barfilled,height-(border<<1),TRUE);
            }
            // Standard (flat)
            else
            {
                dc.setForeground(barColor);
                dc.fillRectangle(border,border,barfilled,height-(border<<1));
            }
        }

        // Draw uncompleted bar
        if (barfilled<barlength)
        {
            dc.setForeground(barBGColor);
            dc.fillRectangle(border+barfilled,border,barlength-barfilled,height-(border<<1));
        }

        // Draw text
        if (options&PROGRESSBAR_PERCENTAGE)
        {
            dc.setFont(font);
            sprintf(numtext,"%d%%",percent);
            n=strlen(numtext);
            tw=font->getTextWidth(numtext,n);
            th=font->getFontHeight();
            ty=(height-th)/2+font->getFontAscent();
            tx=(width-tw)/2;
            if (border+barfilled<=tx)           // In right side
            {
                dc.setForeground(textNumColor);
                dc.setClipRectangle(border,border,width-(border<<1),height-(border<<1));
                dc.drawText(tx,ty,numtext,n);
            }
            else if (tx+tw<=border+barfilled)   // In left side
            {
                dc.setForeground(textAltColor);
                dc.setClipRectangle(border,border,width-(border<<1),height-(border<<1));
                dc.drawText(tx,ty,numtext,n);
            }
            else                                // In between!
            {
                dc.setForeground(textAltColor);
                dc.setClipRectangle(border,border,barfilled,height);
                dc.drawText(tx,ty,numtext,n);
                dc.setForeground(textNumColor);
                dc.setClipRectangle(border+barfilled,border,barlength-barfilled,height);
                dc.drawText(tx,ty,numtext,n);
                dc.clearClipRectangle();
            }
        }
    }
}


//
// Hack of FXButton
//

// This hack fixes a focus problem on the panels when activating a button which is already activated
// Now, the focus on the active panel is not lost anymore


// Pressed mouse button
long FXButton::onLeftBtnPress(FXObject*,FXSelector,void* ptr)
{
    handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
    flags&=~FLAG_TIP;
    if (isEnabled() && !(flags&FLAG_PRESSED))
    {
        grab();
        if (target && target->tryHandle(this,FXSEL(SEL_LEFTBUTTONPRESS,message),ptr))
            return 1;
        //if(state!=STATE_ENGAGED) // !!!! Hack here
        setState(STATE_DOWN);
        flags|=FLAG_PRESSED;
        flags&=~FLAG_UPDATE;
        return 1;
    }
    return 0;
}

// Hot key combination pressed
long FXButton::onHotKeyPress(FXObject*,FXSelector,void* ptr)
{
    flags&=~FLAG_TIP;
    handle(this,FXSEL(SEL_FOCUS_SELF,0),ptr);
    if (isEnabled() && !(flags&FLAG_PRESSED))
    {
        //if(state!=STATE_ENGAGED)  // !!!! Hack here
        setState(STATE_DOWN);
        flags&=~FLAG_UPDATE;
        flags|=FLAG_PRESSED;
    }
    return 1;
}


//
// Hack of FXTopWindow
//

// This hack fixes a problem with some window managers like Icewm or Openbox
// These WMs do not deal with StaticGravity the same way as e.g. Metacity
// and then the window border can be invisible when launching the applications

// Request for toplevel window resize
void FXTopWindow::resize(FXint w,FXint h)
{
    if ((flags&FLAG_DIRTY) || (w!=width) || (h!=height))
    {
        width=FXMAX(w,1);
        height=FXMAX(h,1);
        if (xid)
        {
            XWindowChanges changes;
            XSizeHints size;
            size.flags=USSize|PSize|PWinGravity|USPosition|PPosition;
            size.x=xpos;
            size.y=ypos;
            size.width=width;
            size.height=height;
            size.min_width=0;
            size.min_height=0;
            size.max_width=0;
            size.max_height=0;
            size.width_inc=0;
            size.height_inc=0;
            size.min_aspect.x=0;
            size.min_aspect.y=0;
            size.max_aspect.x=0;
            size.max_aspect.y=0;
            size.base_width=0;
            size.base_height=0;

            // !!!! Hack here
			size.win_gravity=NorthWestGravity;                      // Tim Alexeevsky <realtim@mail.ru>
      		//size.win_gravity=StaticGravity;                       // Account for border (ICCCM)
            // !!!! End of hack

            if (!(options&DECOR_SHRINKABLE))
            {
                if (!(options&DECOR_STRETCHABLE))                       // Cannot change at all
                {
                    size.flags|=PMinSize|PMaxSize;
                    size.min_width=size.max_width=width;
                    size.min_height=size.max_height=height;
                }
                else                                                    // Cannot get smaller than default
                {
                    size.flags|=PMinSize;
                    size.min_width=getDefaultWidth();
                    size.min_height=getDefaultHeight();
                }
            }
            else if (!(options&DECOR_STRETCHABLE))                      // Cannot get larger than default
            {
                size.flags|=PMaxSize;
                size.max_width=getDefaultWidth();
                size.max_height=getDefaultHeight();
            }
            XSetWMNormalHints(DISPLAY(getApp()),xid,&size);
            changes.x=0;
            changes.y=0;
            changes.width=width;
            changes.height=height;
            changes.border_width=0;
            changes.sibling=None;
            changes.stack_mode=Above;
            XReconfigureWMWindow(DISPLAY(getApp()),xid,DefaultScreen(DISPLAY(getApp())),CWWidth|CWHeight,&changes);
            layout();
        }
    }
}

// Request for toplevel window reposition
void FXTopWindow::position(FXint x,FXint y,FXint w,FXint h)
{
    if ((flags&FLAG_DIRTY) || (x!=xpos) || (y!=ypos) || (w!=width) || (h!=height))
    {
        xpos=x;
        ypos=y;
        width=FXMAX(w,1);
        height=FXMAX(h,1);
        if (xid)
        {
            XWindowChanges changes;
            XSizeHints size;
            size.flags=USSize|PSize|PWinGravity|USPosition|PPosition;
            size.x=xpos;
            size.y=ypos;
            size.width=width;
            size.height=height;
            size.min_width=0;
            size.min_height=0;
            size.max_width=0;
            size.max_height=0;
            size.width_inc=0;
            size.height_inc=0;
            size.min_aspect.x=0;
            size.min_aspect.y=0;
            size.max_aspect.x=0;
            size.max_aspect.y=0;
            size.base_width=0;
            size.base_height=0;

            // !!!! Hack here
			size.win_gravity=NorthWestGravity;                      // Tim Alexeevsky <realtim@mail.ru>
      		//size.win_gravity=StaticGravity;                       // Account for border (ICCCM)
            // !!!! End of hack

            if (!(options&DECOR_SHRINKABLE))
            {
                if (!(options&DECOR_STRETCHABLE))                         // Cannot change at all
                {
                    size.flags|=PMinSize|PMaxSize;
                    size.min_width=size.max_width=width;
                    size.min_height=size.max_height=height;
                }
                else                                                      // Cannot get smaller than default
                {
                    size.flags|=PMinSize;
                    size.min_width=getDefaultWidth();
                    size.min_height=getDefaultHeight();
                }
            }
            else if (!(options&DECOR_STRETCHABLE))                        // Cannot get larger than default
            {
                size.flags|=PMaxSize;
                size.max_width=getDefaultWidth();
                size.max_height=getDefaultHeight();
            }
            XSetWMNormalHints(DISPLAY(getApp()),xid,&size);
            changes.x=xpos;
            changes.y=ypos;
            changes.width=width;
            changes.height=height;
            changes.border_width=0;
            changes.sibling=None;
            changes.stack_mode=Above;
            XReconfigureWMWindow(DISPLAY(getApp()),xid,DefaultScreen(DISPLAY(getApp())),CWX|CWY|CWWidth|CWHeight,&changes);
            layout();
        }
    }
}


// Position the window based on placement
void FXTopWindow::place(FXuint placement)
{
    FXint rx,ry,rw,rh,ox,oy,ow,oh,wx,wy,ww,wh,x,y;
    FXuint state;
    FXWindow *over;

    // Default placement:- leave it where it was
    wx=getX();
    wy=getY();
    ww=getWidth();
    wh=getHeight();

    // Get root window size
    rx=getRoot()->getX();
    ry=getRoot()->getY();
    rw=getRoot()->getWidth();
    rh=getRoot()->getHeight();

    // Placement policy
    switch (placement)
    {

        // Place such that it contains the cursor
    case PLACEMENT_CURSOR:

        // Get dialog location in root coordinates
        translateCoordinatesTo(wx,wy,getRoot(),0,0);

        // Where's the mouse?
        getRoot()->getCursorPosition(x,y,state);

        // Place such that mouse in the middle, placing it as
        // close as possible in the center of the owner window.
        // Don't move the window unless the mouse is not inside.
        
        // !!!! Hack here
		//if (!shown() || x<wx || y<wy || wx+ww<=x || wy+wh<=y)
		if (x<wx || y<wy || wx+ww<=x || wy+wh<=y)
		// !!!! End of hack      
        {

            // Get the owner
            over=getOwner()?getOwner():getRoot();

            // Get owner window size
            ow=over->getWidth();
            oh=over->getHeight();

            // Owner's coordinates to root coordinates
            over->translateCoordinatesTo(ox,oy,getRoot(),0,0);

            // Adjust position
            wx=ox+(ow-ww)/2;
            wy=oy+(oh-wh)/2;

            // Move by the minimal amount
            if (x<wx)
            	wx=x-20;
            else if (wx+ww<=x)
            	wx=x-ww+20;
            if (y<wy)
            	wy=y-20;
            else if (wy+wh<=y)
            	wy=y-wh+20;
        }

        // Adjust so dialog is fully visible
        if (wx<rx)
        	wx=rx+10;
        if (wy<ry)
        	wy=ry+10;
        if (wx+ww>rx+rw)
        	wx=rx+rw-ww-10;
        if (wy+wh>ry+rh)
        	wy=ry+rh-wh-10;
        break;

        // Place centered over the owner
    case PLACEMENT_OWNER:

        // Get the owner
        over=getOwner()?getOwner():getRoot();

        // Get owner window size
        ow=over->getWidth();
        oh=over->getHeight();

        // Owner's coordinates to root coordinates
        over->translateCoordinatesTo(ox,oy,getRoot(),0,0);

        // Adjust position
        wx=ox+(ow-ww)/2;
        wy=oy+(oh-wh)/2;

        // Adjust so dialog is fully visible
        if (wx<rx)
        	wx=rx+10;
        if (wy<ry)
        	wy=ry+10;
        if (wx+ww>rx+rw)
        	wx=rx+rw-ww-10;
        if (wy+wh>ry+rh)
        	wy=ry+rh-wh-10;
        break;

        // Place centered on the screen
    case PLACEMENT_SCREEN:

        // Adjust position
        wx=rx+(rw-ww)/2;
        wy=ry+(rh-wh)/2;
        break;

        // Place to make it fully visible
    case PLACEMENT_VISIBLE:

        // Adjust so dialog is fully visible
        if (wx<rx)
        	wx=rx+10;
        if (wy<ry)
        	wy=ry+10;
        if (wx+ww>rx+rw)
        	wx=rx+rw-ww-10;
        if (wy+wh>ry+rh)
        	wy=ry+rh-wh-10;
        break;

        // Place maximized
    case PLACEMENT_MAXIMIZED:
        wx=rx;
        wy=ry;
        ww=rw;                // Yes, I know:- we should substract the borders;
        wh=rh;                // trouble is, no way to know how big those are....
        break;

        // Default placement
    case PLACEMENT_DEFAULT:
    default:
        break;
    }

    // Place it
    position(wx,wy,ww,wh);
}