File: gap_mov_dialog.c

package info (click to toggle)
gimp-gap 2.6.0%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 19,656 kB
  • ctags: 7,358
  • sloc: ansic: 119,801; sh: 3,890; makefile: 932; lisp: 97; pascal: 55
file content (5435 lines) | stat: -rwxr-xr-x 190,989 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
/* gap_mov_dialog.c
 *   by hof (Wolfgang Hofer)
 *
 * GAP ... Gimp Animation Plugins
 *
 * Dialog Window for Move Path (gap_mov)
 *
 */

/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* revision history:
 * gimp    2.1.0b;  2004/11/04  hof: replaced deprecated option_menu by combo box
 * gimp    2.1.0b;  2004/08/14  hof: feature: point navigation + SHIFT ==> mov_follow_keyframe
 * gimp    2.1.0b;  2004/08/10  hof: bugfix save/load Pathpoints work again.
 * gimp    2.1.0a;  2004/06/26  hof: #144649 use NULL for the default cursor as active_cursor
 * gimp    2.0.1a;  2004/05/01  hof: proc: mov_dialog init mgp->drawable with temporary image (pvals->tmp_image_id)
 *                                   this shows a valid copy of the dest frames at startup
 *                                   (from where the move path  plug-in was invoked)
 * gimp    2.1.0a;  2004/04/18  hof: gtk_window_present(GTK_WINDOW(filesel)) on attempt
 *                                   to open an already open filesel dialog window
 * gimp    1.3.21d; 2003/10/29  hof: removed deprecated calls to gtk_window_set_policy
 * gimp    1.3.20d; 2003/10/14  hof: added bluebox filter effect
 * gimp    1.3.20d; 2003/10/05  hof: use gimp_image_undo_disable for internal temporary images
 *                                   (for better performance and less resources)
 *                                   defaults for anim preview subdialog
 *                                   dynamic preview resize on window resize
 * gimp    1.3.20c; 2003/09/29  hof: new features:  instant_apply, perspective transformation,
 *                                   - tween_layer and trace_layer
 *                                   - changed opacity, rotation and resize from int to gdouble
 * gimp    1.3.17b; 2003/07/31  hof: message text fixes for translators (# 118392)
 * gimp    1.3.16c; 2003/07/12  hof: removed deprecated GtkKPreview widget (replaced by drawing_area based gap_pview_da calls)
 *                                   cursor crosslines ar now switchable (show_cursor flag)
 * gimp    1.3.15a; 2003/06/21  hof: attempt to remove some deprecated calls (no success)
 * gimp    1.3.14b; 2003/06/03  hof: added gap_stock_init
 *                                   replaced mov_gtk_button_new_with_pixmap  by  gtk_button_new_from_stock
 * gimp    1.3.14a; 2003/05/24  hof: moved render procedures to module gap_mov_render
 *                                   placed OK button right.
 *                                   added pixmaps (thanks to Jakub Steiner for providing the pixmaps)
 *                              sven:  replaced _gimp_help_init by gimp_ui_init
 * gimp    1.3.12a; 2003/05/03  hof: merge into CVS-gimp-gap project, replace gimp_help_init by _gimp_help_init
 * gimp    1.3.4b;  2002/03/15  hof: temp. reverted setting of preview widget size.
 * gimp    1.3.4;   2002/03/12  hof: ported to gtk+-2.0.0
 *                                   still needs GTK_DISABLE_DEPRECATED (port is not complete)
 * gimp    1.1.29b; 2000/11/30  hof: new feature: FRAME based Stepmodes, changes for NONINTERACTIVE mode
 * gimp    1.1.23a; 2000/06/04  hof: new button: rotation follow path
 * gimp    1.1.20a; 2000/04/25  hof: support for keyframes, anim_preview (suggested by jakub steiner)
 * gimp    1.1.17b; 2000/02/23  hof: bugfix: dont flatten the preview, just merge visible layers
 *                                   bugfix: for current frame never use diskfile for the preview
 *                                           (to avoid inconsitencies, and to speed up a little)
 *                                   added "Show Path", pick and drag Controlpoints
 * gimp    1.1.17a; 2000/02/20  hof: use gimp_help_set_help_data for tooltips
 *                                   added spinbuttons, and more layout cosmetics.
 * gimp    1.1.15a; 2000/01/26  hof: removed gimp 1.0.x support
 * gimp    1.1.13b; 1999/12/04  hof: some cosmetic gtk fixes
 *                                   changed border_width spacing and Buttons in action area
 *                                   to same style as used in dialogs of the gimp 1.1.13 main dialogs
 * gimp   1.1.8a;   1999/08/31  hof: accept video framenames without underscore '_'
 * gimp   1.1.5a;   1999/05/08  hof: call fileselect in gtk+1.2 style
 * version 0.99.00; 1999.03.03  hof: bugfix: update of the preview (did'nt work with gimp1.1.2)
 * version 0.98.00; 1998.11.28  hof: Port to GIMP 1.1: replaced buildmenu.h, apply layermask (before rotate)
 *                                   mov_imglayer_constrain must check for drawable_id -1
 * version 0.97.00; 1998.10.19  hof: Set window title to "Move Path"
 * version 0.96.02; 1998.07.30  hof: added clip to frame option and tooltips
 * version 0.96.00; 1998.07.09  hof: bugfix (filesel did not reopen after cancel)
 * version 0.95.00; 1998.05.12  hof: added rotatation capabilities
 * version 0.94.00; 1998.04.25  hof: use only one point as default
 *                                   bugfix: initial value for src_paintmode
 *                                           fixes the problem reported in gap_layer_copy_to_dest_image (can't get new layer)
 * version 0.90.00; 1997.12.14  hof: 1.st (pre) release
 */


#include "config.h"

#define MOVE_PATH_LAYOUT_BIG_PREVIEW
/* if defined MOVE_PATH_LAYOUT_BIG_PREVIEW use layout with bigger initial preview size
 * and with frame range selection widget group at right side of the preview
 *
 * the other layout variante has the range selection widget group under the preview
 * (maybe this will be a configure option later)
 */


/* SYTEM (UNIX) includes */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <time.h>

/* GIMP includes */
#include "gtk/gtk.h"
#include "gap-intl.h"
#include "libgimp/gimp.h"
#include "libgimp/gimpui.h"

/* GAP includes */
#include "gap_libgapbase.h"
#include "gap_layer_copy.h"
#include "gap_lib.h"
#include "gap_image.h"
#include "gap_mov_exec.h"
#include "gap_mov_dialog.h"
#include "gap_mov_render.h"
#include "gap_pdb_calls.h"
#include "gap_vin.h"
#include "gap_arr_dialog.h"

#include "gap_pview_da.h"
#include "gap_stock.h"


extern      int gap_debug; /* ==0  ... dont print debug infos */

/* Some useful defines and  macros */
#define GAP_MOVE_PATH_HELP_ID             "plug-in-gap-move-path"

#define ENTRY_WIDTH 60
#define SPINBUTTON_WIDTH 60
#define SCALE_WIDTH 125

/* instant apply is implemented via timer, configured to fire 10 times per second (100 msec)
 * this collects instant_apply_requests set by other widget callbacks and events
 * and then update only once.
 * The timer is completely removed, when instant_apply is OFF
 * instant_apply requires much CPU and IO power especially on big images
 * and images with many layers
 */
#define INSTANT_TIMERINTERVAL_MILLISEC  100


#ifdef MOVE_PATH_LAYOUT_BIG_PREVIEW
#define PREVIEW_SIZE 340
#else
#define PREVIEW_SIZE 256
#endif

#define RADIUS           3

#define PREVIEW       0x1
#define CURSOR        0x2
#define PATH_LINE     0x4
#define ALL           0xf

#define GAP_MOV_CHECK_SIZE 8

/*  event masks for the preview widget */
#define PREVIEW_MASK   GDK_EXPOSURE_MASK | \
                       GDK_BUTTON_PRESS_MASK |\
                       GDK_BUTTON_RELEASE_MASK |\
                       GDK_BUTTON_MOTION_MASK


#define POINT_INDEX_LABEL_LENGTH 256

typedef struct {
  gint run;
} t_mov_interface;

typedef struct
{
  GimpDrawable  *drawable;
  gint          dwidth, dheight;
  gint          bpp;
  GapPView       *pv_ptr;
  GimpPixelRgn   src_rgn;
  gint           show_path;
  gint           show_cursor;
  gint           show_grid;
  gint           instant_apply;
  gboolean       instant_apply_request;
  gint32         instant_timertag;
  gint           startup;

  gint          pwidth, pheight;
  gint          curx, cury;              /* x,y of cursor in preview */

  GtkWidget     *filesel;
  GtkAdjustment *x_adj;
  GtkAdjustment *y_adj;
  GtkAdjustment *wres_adj;
  GtkAdjustment *hres_adj;
  GtkAdjustment *opacity_adj;
  GtkAdjustment *rotation_adj;
  GtkAdjustment *keyframe_adj;
  GtkAdjustment *preview_frame_nr_adj;

  GtkWidget     *src_layer_combo;
  GtkWidget     *constrain;       /* scale width/height keeps ratio constant */
  GtkAdjustment *ttlx_adj;
  GtkAdjustment *ttly_adj;
  GtkAdjustment *ttrx_adj;
  GtkAdjustment *ttry_adj;
  GtkAdjustment *tblx_adj;
  GtkAdjustment *tbly_adj;
  GtkAdjustment *tbrx_adj;
  GtkAdjustment *tbry_adj;
  GtkAdjustment *sel_feather_radius_adj;
  GtkAdjustment *step_speed_factor_adj;
  GtkAdjustment *tween_opacity_initial_adj;
  GtkAdjustment *tween_opacity_desc_adj;
  GtkAdjustment *trace_opacity_initial_adj;
  GtkAdjustment *trace_opacity_desc_adj;
  GtkAdjustment *tween_steps_adj;

  gchar          point_index_text[POINT_INDEX_LABEL_LENGTH];
  GtkWidget     *point_index_frame;
  gint           p_x, p_y;
  gdouble        opacity;
  gdouble        w_resize;
  gdouble        h_resize;
  gdouble        rotation;
  gdouble        ttlx;     /* 0.0 upto 10.0 transform x top left */
  gdouble        ttly;     /* 0.0 upto 10.0 transform y top left */
  gdouble        ttrx;     /* 0.0 upto 10.0 transform x top right */
  gdouble        ttry;     /* 0.0 upto 10.0 transform y top right */
  gdouble        tblx;     /* 0.0 upto 10.0 transform x bot left */
  gdouble        tbly;     /* 0.0 upto 10.0 transform y bot left */
  gdouble        tbrx;     /* 0.0 upto 10.0 transform x bot right */
  gdouble        tbry;     /* 0.0 upto 10.0 transform y bot right */
  gdouble        sel_feather_radius;

  gint           keyframe_abs;
  gint           max_frame;


  gint           preview_frame_nr;      /* default: current frame */
  gint           old_preview_frame_nr;
  GapAnimInfo   *ainfo_ptr;

  gint          in_call;
  char         *pointfile_name;

  gint                first_nr;
  gint                last_nr;
  GtkWidget          *shell;
  gint                shell_initial_width;
  gint                shell_initial_height;
  GtkWidget          *master_vbox;
  GdkCursor     *cursor_wait;
  GdkCursor     *cursor_acitve;
  GimpRGB               pathcolor;
} t_mov_gui_stuff;


/* Declare a local function.
 */

       long        gap_mov_dlg_move_dialog             (GapMovData *mov_ptr);
static void        p_update_point_index_text (t_mov_gui_stuff *mgp);
static void        p_points_from_tab         (t_mov_gui_stuff *mgp);
static void        p_points_to_tab           (t_mov_gui_stuff *mgp);
static void        p_point_refresh           (t_mov_gui_stuff *mgp);
static void        p_pick_nearest_point      (gint px, gint py);
static void        p_reset_points            ();
static void        p_clear_one_point         (gint idx);
static void        p_mix_one_point(gint idx, gint ref1, gint ref2, gdouble mix_factor);
static void        p_load_points             (char *filename);
static void        p_save_points             (char *filename, t_mov_gui_stuff *mgp);

static GimpDrawable * p_get_flattened_drawable (gint32 image_id);
static GimpDrawable * p_get_prevw_drawable (t_mov_gui_stuff *mgp);

static gint        mov_dialog ( GimpDrawable *drawable, t_mov_gui_stuff *mgp,
                                gint min, gint max);
static GtkWidget * mov_modify_tab_create (t_mov_gui_stuff *mgp);
static GtkWidget * mov_trans_tab_create  (t_mov_gui_stuff *mgp);
static GtkWidget * mov_selection_handling_tab_create (t_mov_gui_stuff *mgp);

static void        mov_path_prevw_create ( GimpDrawable *drawable,
                                           t_mov_gui_stuff *mgp,
                                           gboolean vertical_layout);
static void        mov_refresh_src_layer_menu(t_mov_gui_stuff *mgp);
static GtkWidget * mov_src_sel_create (t_mov_gui_stuff *mgp);
static GtkWidget * mov_advanced_tab_create(t_mov_gui_stuff *mgp);
static GtkWidget * mov_edit_button_box_create (t_mov_gui_stuff *mgp);
static GtkWidget * mov_path_framerange_box_create(t_mov_gui_stuff *mgp,
                                                  gboolean vertical_layout
                                                  );
static void        mov_path_prevw_preview_init ( t_mov_gui_stuff *mgp );
static void        mov_path_prevw_draw ( t_mov_gui_stuff *mgp, gint update );
static void        mov_instant_int_adjustment_update (GtkObject *obj, gpointer val);
static void        mov_instant_double_adjustment_update (GtkObject *obj, gpointer val);
static void        mov_path_colorbutton_update ( GimpColorButton *widget, t_mov_gui_stuff *mgp);
static void        mov_path_keycolorbutton_clicked ( GimpColorButton *widget, t_mov_gui_stuff *mgp);
static void        mov_path_keycolorbutton_changed ( GimpColorButton *widget, t_mov_gui_stuff *mgp);
static void        mov_path_x_adjustment_update ( GtkWidget *widget, gpointer data );
static void        mov_path_y_adjustment_update ( GtkWidget *widget, gpointer data );
static void        mov_path_tfactor_adjustment_update( GtkWidget *widget, gdouble *val);
static void        mov_path_feather_adjustment_update( GtkWidget *widget, gdouble *val );
static void        mov_selmode_menu_callback (GtkWidget *widget, t_mov_gui_stuff *mgp);


static void        mov_path_resize_adjustment_update( GtkObject *obj, gdouble *val);
static void        mov_path_tween_steps_adjustment_update( GtkObject *obj, gint *val);
static void        mov_path_prevw_cursor_update ( t_mov_gui_stuff *mgp );
static gint        mov_path_prevw_preview_expose ( GtkWidget *widget, GdkEvent *event );
static gint        mov_path_prevw_preview_events ( GtkWidget *widget, GdkEvent *event );
static gint        p_chk_keyframes(t_mov_gui_stuff *mgp);

static void        mov_grab_bezier_path(t_mov_gui_stuff *mgp
                         , gint32 vectors_id
                         , gint32 stroke_id
                         , const char *vectorname
                         );
static void        mov_grab_anchorpoints_path(t_mov_gui_stuff *mgp
                                             ,gint num_path_point_details
                                             ,gdouble *points_details
                                             );


static void     mov_padd_callback        (GtkWidget *widget,gpointer data);
static void     mov_pgrab_callback       (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_pins_callback        (GtkWidget *widget,gpointer data);
static void     mov_pdel_callback        (GtkWidget *widget,gpointer data);
static void     mov_follow_keyframe      (t_mov_gui_stuff *mgp);
static void     mov_pnext_callback       (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_pprev_callback       (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_pfirst_callback      (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_plast_callback       (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_pdel_all_callback    (GtkWidget *widget,gpointer data);
static void     mov_pclr_callback        (GtkWidget *widget,gpointer data);
static void     mov_pclr_all_callback    (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_prot_follow_callback (GtkWidget *widget,GdkEventButton *bevent,gpointer data);
static void     mov_pload_callback       (GtkWidget *widget,gpointer data);
static void     mov_psave_callback       (GtkWidget *widget,gpointer data);
static void     p_points_load_from_file  (GtkWidget *widget,t_mov_gui_stuff *mgp);
static void     p_points_save_to_file    (GtkWidget *widget,t_mov_gui_stuff *mgp);

static gboolean mov_check_valid_src_layer(t_mov_gui_stuff   *mgp);
static void     mov_help_callback        (GtkWidget *widget, t_mov_gui_stuff *mgp);
static void     mov_close_callback       (GtkWidget *widget, t_mov_gui_stuff *mgp);
static void     mov_ok_callback          (GtkWidget *widget, t_mov_gui_stuff *mgp);
static void     mov_upvw_callback        (GtkWidget *widget, t_mov_gui_stuff *mgp);
static void     mov_apv_callback         (GtkWidget *widget,gpointer data);
static void     p_filesel_close_cb       (GtkWidget *widget, t_mov_gui_stuff *mgp);

static gint mov_imglayer_constrain      (gint32 image_id, gint32 drawable_id, gpointer data);
static void mov_imglayer_menu_callback  (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_paintmode_menu_callback (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_handmode_menu_callback  (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_stepmode_menu_callback  (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_tweenlayer_sensitivity(t_mov_gui_stuff *mgp);
static void mov_tracelayer_sensitivity(t_mov_gui_stuff *mgp);
static void mov_gint_toggle_callback    (GtkWidget *, gpointer);
static void mov_force_visibility_toggle_callback ( GtkWidget *widget, gpointer data );
static void mov_bluebox_callback        (GtkWidget *, gpointer);
static void mov_tracelayer_callback     (GtkWidget *, gpointer);
static void mov_show_path_or_cursor     (t_mov_gui_stuff *mgp);
static void mov_show_path_callback      (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_show_cursor_callback    (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_show_grid_callback      (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_install_timer           (t_mov_gui_stuff *mgp);
static void mov_remove_timer            (t_mov_gui_stuff *mgp);
static void mov_instant_timer_callback (gpointer   user_data);
static void mov_instant_apply_callback  (GtkWidget *, t_mov_gui_stuff *mgp);
static void mov_set_instant_apply_request(t_mov_gui_stuff *mgp);
static void mov_set_waiting_cursor       (t_mov_gui_stuff *mgp);
static void mov_set_active_cursor        (t_mov_gui_stuff *mgp);

GtkObject *
p_mov_spinbutton_new(GtkTable *table
                    ,gint      col
                    ,gint      row
                    ,gchar    *label_text
                    ,gint      scale_width      /* dummy, not used */
                    ,gint      spinbutton_width
                    ,gdouble   initial_val
                    ,gdouble   lower            /* dummy, not used */
                    ,gdouble   upper            /* dummy, not used */
                    ,gdouble   sstep
                    ,gdouble   pagestep
                    ,gint      digits
                    ,gboolean  constrain
                    ,gdouble   umin
                    ,gdouble   umax
                    ,gchar    *tooltip_text
                    ,gchar    *privatetip
                    );
static void  mov_fit_initial_shell_window(t_mov_gui_stuff *mgp);
static void  mov_shell_window_size_allocate (GtkWidget       *widget,
                                             GtkAllocation   *allocation,
                                             gpointer         user_data);

static void  mov_pview_size_allocate_callback(GtkWidget *widget
                                , GtkAllocation *allocation
                                , t_mov_gui_stuff *mgp
                                );


static GapMovValues *pvals;

static t_mov_interface mov_int =
{
  FALSE     /* run */
};


/* ============================================================================
 **********************
 *                    *
 *  Dialog interface  *
 *                    *
 **********************
 * ============================================================================
 */

long      gap_mov_dlg_move_dialog    (GapMovData *mov_ptr)
{
  GimpDrawable *l_drawable_ptr;
  gint       l_first, l_last;
  char      *l_str;
  t_mov_gui_stuff *mgp;

  if(gap_debug) printf("GAP-DEBUG: START gap_mov_dlg_move_dialog\n");

  mgp = g_new( t_mov_gui_stuff, 1 );
  if(mgp == NULL)
  {
    printf("error can't alloc path_preview structure\n");
    return -1;
  }
  mgp->shell_initial_width = -1;
  mgp->shell_initial_height = -1;
  mgp->show_path = TRUE;
  mgp->show_cursor = TRUE;
  mgp->show_grid = FALSE;
  mgp->instant_apply = FALSE;
  mgp->instant_apply_request = FALSE;
  mgp->instant_timertag = -1;
  mgp->startup = TRUE;
  mgp->keyframe_adj = NULL;
  mgp->preview_frame_nr_adj = NULL;
  mgp->pv_ptr = NULL;
  mgp->cursor_wait = gdk_cursor_new (GDK_WATCH);
  mgp->cursor_acitve = NULL; /* use the default cursor */
  mgp->step_speed_factor_adj = NULL;
  mgp->tween_opacity_initial_adj = NULL;
  mgp->tween_opacity_desc_adj = NULL;
  mgp->trace_opacity_initial_adj = NULL;
  mgp->sel_feather_radius_adj = NULL;

  pvals = mov_ptr->val_ptr;

  l_str = gap_base_strdup_del_underscore(mov_ptr->dst_ainfo_ptr->basename);
  mgp->pointfile_name  = g_strdup_printf("%s.path_points", l_str);
  g_free(l_str);


  l_first = mov_ptr->dst_ainfo_ptr->first_frame_nr;
  l_last  = mov_ptr->dst_ainfo_ptr->last_frame_nr;

  /* init parameter values */
  pvals->dst_image_id = mov_ptr->dst_ainfo_ptr->image_id;
  pvals->tmp_image_id = -1;
  pvals->tmpsel_image_id= -1;
  pvals->tmpsel_channel_id = -1;
  pvals->tmp_alt_image_id = -1;
  pvals->tmp_alt_framenr = -1;
  pvals->tween_image_id = -1;
  pvals->trace_image_id = -1;
  pvals->src_image_id = -1;
  pvals->src_layer_id = -1;
  pvals->src_paintmode = GIMP_NORMAL_MODE;
  pvals->src_handle = GAP_HANDLE_LEFT_TOP;
  pvals->src_stepmode = GAP_STEP_LOOP;
  pvals->src_selmode = GAP_MOV_SEL_IGNORE;
  pvals->src_force_visible  = 1;
  pvals->src_apply_bluebox  = 0;
  pvals->bbp  = NULL;
  pvals->bbp_pv  = NULL;
  pvals->clip_to_img  = 0;

  pvals->step_speed_factor = 1.0;
  pvals->tracelayer_enable = FALSE;
  pvals->trace_opacity_initial = 100.0;
  pvals->trace_opacity_desc = 80.0;
  pvals->tween_steps = 0;
  pvals->tween_opacity_initial = 80.0;
  pvals->tween_opacity_desc = 80.0;

  pvals->apv_mode  = GAP_APV_QUICK;
  pvals->apv_src_frame  = -1;
  pvals->apv_mlayer_image  = -1;
  pvals->apv_gap_paste_buff  = NULL;
  pvals->apv_scalex  = 40.0;
  pvals->apv_scaley  = 40.0;

  pvals->cache_src_image_id  = -1;
  pvals->cache_tmp_image_id  = -1;
  pvals->cache_tmp_layer_id  = -1;
  pvals->cache_frame_number  = -1;
  pvals->cache_ainfo_ptr = NULL;

  p_reset_points();

  /* pvals->point[1].p_x = 100; */  /* default: move from 0/0 to 100/0 */

  pvals->dst_range_start = mov_ptr->dst_ainfo_ptr->curr_frame_nr;
  pvals->dst_range_end   = l_last;
  pvals->dst_layerstack = 0;   /* 0 ... insert layer on top of stack */

  mgp->filesel = NULL;   /* fileselector is not open */
  mgp->ainfo_ptr            = mov_ptr->dst_ainfo_ptr;
  mgp->preview_frame_nr     = mov_ptr->dst_ainfo_ptr->curr_frame_nr;
  mgp->old_preview_frame_nr = mgp->preview_frame_nr;
  mgp->point_index_frame = NULL;

  p_points_from_tab(mgp);
  p_update_point_index_text(mgp);

  /* duplicate the curerent image (for flatten & preview)  */
  pvals->tmp_image_id = gimp_image_duplicate(pvals->dst_image_id);

  /* wanted to disable undo for performance reasons
   * but if this is done here, the initial preview is black
   * and get error (gap_main:######): LibGimp-CRITICAL **: file gimppixelrgn.c: line 268 (gimp_pixel_
   * TODO: findout why, then try disable undo again
   */
  /* gimp_image_undo_disable(pvals->tmp_image_id); */

  /* flatten image, and get the (only) resulting drawable */
  l_drawable_ptr = p_get_prevw_drawable(mgp);

  /* do DIALOG window */
  mov_dialog(l_drawable_ptr, mgp, l_first, l_last);
  p_points_to_tab(mgp);

  /* destroy the tmp image(s) */
  gimp_image_delete(pvals->tmp_image_id);
  if(pvals->tmp_alt_image_id >= 0)
  {
    gimp_image_delete(pvals->tmp_alt_image_id);
  }

  /* delete the temp selection image */
  if(gap_image_is_alive(pvals->tmpsel_image_id))
  {
    gimp_image_delete(pvals->tmpsel_image_id);
  }

  pvals->tmpsel_image_id = -1;
  pvals->tmpsel_channel_id = -1;

  /* remove timer if there is one */
  mov_remove_timer(mgp);

  g_free(mgp);


  if(gap_debug) printf("GAP-DEBUG: END gap_mov_dlg_move_dialog\n");

  if(mov_int.run == TRUE)  return 0;
  else                     return  -1;
}


/* ============================================================================
 *******************
 *                 *
 *   Main Dialog   *
 *                 *
 *******************
 * ============================================================================
 */

static gint
mov_dialog ( GimpDrawable *drawable, t_mov_gui_stuff *mgp,
             gint first_nr, gint last_nr )
{
  GtkWidget *notebook;
  GtkWidget *vbox;
  GtkWidget *hbbox;
  GtkWidget *spc_hbox;
  GtkWidget *dlg;
  GtkWidget *frame;
  GtkWidget *button;
  GtkWidget *label;
  GtkWidget *src_sel_frame;
  GtkWidget *advanced_frame;
  GtkWidget *framerange_table;
  gboolean  vertical_layout;

  if(gap_debug) printf("GAP-DEBUG: START mov_dialog\n");

  gimp_ui_init ("gap_move", FALSE);
  gap_stock_init();

#ifdef MOVE_PATH_LAYOUT_BIG_PREVIEW
  vertical_layout = TRUE;
#else
  vertical_layout = FALSE;
#endif
  /* dialog */
  dlg = gtk_dialog_new ();
  gtk_window_set_type_hint (dlg, GDK_WINDOW_TYPE_HINT_NORMAL);
  mgp->shell = dlg;
  mgp->first_nr = first_nr;
  mgp->last_nr = last_nr;

  gtk_window_set_title (GTK_WINDOW (dlg), _("Move Path"));
  gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
  g_signal_connect (G_OBJECT (dlg), "destroy",
                    G_CALLBACK (mov_close_callback),
                    mgp);
  gtk_window_set_resizable(GTK_WINDOW (mgp->shell), TRUE);

  /*  Action area  */
  gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dlg)->action_area), 2);
  gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dlg)->action_area), FALSE);

  hbbox = gtk_hbutton_box_new ();
  gtk_box_set_spacing (GTK_BOX (hbbox), 2);
  gtk_box_pack_end (GTK_BOX (GTK_DIALOG (dlg)->action_area), hbbox, FALSE, FALSE, 0);
  gtk_widget_show (hbbox);


  /* the HELP button */
  if (gimp_show_help_button ())
    {
      button = gtk_button_new_from_stock ( GTK_STOCK_HELP);
      GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
      gtk_box_pack_end (GTK_BOX (hbbox), button, FALSE, TRUE, 0);
      gtk_widget_show (button);
      g_signal_connect (G_OBJECT (button), "clicked",
                        G_CALLBACK(mov_help_callback),
                        mgp);
    }

  /* the CANCEL button */
  button = gtk_button_new_from_stock ( GTK_STOCK_CANCEL);
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK(mov_close_callback),
                    mgp);

  /* button = gtk_button_new_with_label */
  button = gtk_button_new_from_stock ( GTK_STOCK_REFRESH );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
  gimp_help_set_help_data(button,
                       _("Show preview frame with selected source layer at current controlpoint")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK  (mov_upvw_callback),
                    mgp);

  button = gtk_button_new_from_stock ( GAP_STOCK_ANIM_PREVIEW );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
  gimp_help_set_help_data(button,
                       _("Generate animated preview as multilayer image")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_apv_callback),
                    mgp);


  button = gtk_button_new_from_stock ( GTK_STOCK_OK);
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_box_pack_start (GTK_BOX (hbbox), button, TRUE, TRUE, 0);
  gtk_widget_grab_default (button);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK  (mov_ok_callback),
                    mgp);

  /*  parameter settings  */
  spc_hbox = gtk_hbox_new (FALSE, 0);
  gtk_widget_show (spc_hbox);

  frame = gimp_frame_new ( _("Copy moving source-layer(s) into frames"));
  gtk_widget_show (frame);

  gtk_box_pack_start (GTK_BOX (spc_hbox), frame, TRUE, TRUE, 10);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), spc_hbox, TRUE, TRUE, 2);


  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 3);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
  gtk_container_add (GTK_CONTAINER (frame), vbox);
  gtk_widget_show (vbox);

  /* the notebook */
  notebook = gtk_notebook_new();
  {
    GtkWidget *hbox;

    hbox = gtk_hbox_new (FALSE, 3);
    gtk_widget_show (hbox);
    gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 4);
    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
  }

  /* the source select frame */
  src_sel_frame = mov_src_sel_create (mgp);
  gtk_container_add (GTK_CONTAINER (notebook), src_sel_frame);
  label = gtk_label_new(_("Source Select"));
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0)
                             , label
                             );
  /* the advanced features frame */
  advanced_frame = mov_advanced_tab_create(mgp);
  gtk_container_add (GTK_CONTAINER (notebook), advanced_frame);
  label = gtk_label_new(_("Advanced Settings"));
  gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 1)
                             , label
                             );
  gtk_widget_show (notebook);

  /* the path preview frame (with all the controlpoint widgets) */
  mgp->max_frame = MAX(first_nr, last_nr);
  mgp->master_vbox = vbox;
  mov_path_prevw_create ( drawable, mgp, vertical_layout);

  if(!vertical_layout)
  {
    /* the box with the framerange selection widgets
     * (if we have vertical_layout using the BIG Preview
     *  the framerange_table was already done in the mov_path_prevw_create procedure,
     *  otherwise we have to create it now)
     */
    framerange_table = mov_path_framerange_box_create(mgp, vertical_layout);
    gtk_box_pack_start (GTK_BOX (vbox), framerange_table, FALSE, FALSE, 0);
  }

  gtk_widget_show (dlg);
  gtk_widget_realize(mgp->shell);

  mgp->startup = FALSE;

  gap_pview_set_size(mgp->pv_ptr
                  , mgp->pwidth
                  , mgp->pheight
                  , GAP_MOV_CHECK_SIZE
                  );

   /* init drawable for preview rendering
    * (at startup this is a copy of the frame from where we were invoked)
    */
   if(pvals->tmp_image_id >= 0)
   {
     mgp->drawable = p_get_flattened_drawable(pvals->tmp_image_id);
   }



  mov_path_prevw_preview_init(mgp);
  mov_show_path_or_cursor(mgp);

  g_signal_connect (G_OBJECT (mgp->shell), "size_allocate",
                    G_CALLBACK (mov_shell_window_size_allocate),
                    mgp);

  gtk_main ();
  gdk_flush ();

  if(gap_debug) printf("GAP-DEBUG: END mov_dialog\n");

  return mov_int.run;
}  /* end mov_dialog */

static gboolean
mov_check_valid_src_layer(t_mov_gui_stuff   *mgp)
{
  if(mgp->startup)
  {
    return(FALSE);
  }

  if(pvals->src_layer_id < 0)
  {
     g_message(_("No source image was selected.\n"
                 "Please open a 2nd image of the same type before opening 'Move Path'"));
     return(FALSE);
  }
  return(TRUE);
}  /* end mov_check_valid_src_layer */

/* ============================================================================
 * implementation of CALLBACK procedures
 * ============================================================================
 */
static void
mov_help_callback (GtkWidget *widget,
                    t_mov_gui_stuff *mgp)
{
  if(gap_debug) printf("mov_help_callback:\n");

  gimp_standard_help_func(GAP_MOVE_PATH_HELP_ID, mgp->shell);
}  /* end mov_help_callback */

static void
mov_close_callback (GtkWidget *widget,
                    t_mov_gui_stuff *mgp)
{
  if(mgp)
  {
    mov_remove_timer(mgp);

    if(mgp->shell)
    {
      GtkWidget *l_shell;

      l_shell = mgp->shell;
      mgp->shell = NULL;

       /* mov_close_callback is the signal handler for the "destroy"
        * signal of the shell window.
        * the gtk_widget_destroy call will immediate reenter this procedure.
        * (for this reason the mgp->shell is set to NULL
        *  before the gtk_widget_destroy call)
        */
      gtk_widget_destroy (l_shell);
    }
  }

  gtk_main_quit ();
}  /* end mov_close_callback */


static void
mov_ok_callback (GtkWidget *widget,
                 t_mov_gui_stuff *mgp)
{
  if(pvals != NULL)
  {
    if(!mov_check_valid_src_layer(mgp))
    {
      return;
    }
  }

  if(!p_chk_keyframes(mgp))
  {
    return;
  }

  mov_int.run = TRUE;

  if(pvals->point_idx_max == 0)
  {
    /* if we have only one point duplicate that point
     * (move algorithm needs at least 2 points)
     */
    mov_padd_callback(NULL, mgp);
  }

  mov_close_callback(mgp->shell, mgp);

}  /* end mov_ok_callback */

/* ---------------------------
 * mov_upvw_callback
 * ---------------------------
 * this callback does completely draw the preview
 */
static void
mov_upvw_callback (GtkWidget *widget,
                  t_mov_gui_stuff *mgp)
{
  char               *l_filename;
  long                l_frame_nr;
  gint32              l_new_tmp_image_id;
  gint32              l_old_tmp_image_id;

  if(gap_debug) printf("mov_upvw_callback nr: %d old_nr: %d\n",
         (int)mgp->preview_frame_nr , (int)mgp->old_preview_frame_nr);

  l_frame_nr = (long)mgp->preview_frame_nr;
  l_filename = gap_lib_alloc_fname(mgp->ainfo_ptr->basename,
                             l_frame_nr,
                             mgp->ainfo_ptr->extension);
  if(l_filename != NULL)
  {
     if(!mgp->instant_apply)
     {
       /* dont show waiting cursor at instant_apply
        * (cursor flickering is boring on fast machines,
        *  and users with slow machines should not touch instant_apply at all)
        */
       mov_set_waiting_cursor(mgp);
     }
     /* replace the temporary image */
     if(mgp->preview_frame_nr  == mgp->ainfo_ptr->curr_frame_nr)
     {
       l_new_tmp_image_id = gimp_image_duplicate(mgp->ainfo_ptr->image_id);
     }
     else
     {
       if((pvals->tmp_alt_image_id >= 0)
       && (pvals->tmp_alt_framenr == l_frame_nr))
       {
         /* we can reuse the cached frame image */
         l_new_tmp_image_id = gimp_image_duplicate(pvals->tmp_alt_image_id);
       }
       else
       {
         if(pvals->tmp_alt_image_id >= 0)
         {
           gimp_image_delete(pvals->tmp_alt_image_id);
           pvals->tmp_alt_image_id = -1;
           pvals->tmp_alt_framenr = -1;
         }
         /* we must load a frame for preview update */
         l_new_tmp_image_id = gap_lib_load_image(l_filename);

         /* keep a copy of the frame to speed up further (instant) updates */
         pvals->tmp_alt_image_id = gimp_image_duplicate(l_new_tmp_image_id);
         pvals->tmp_alt_framenr = l_frame_nr;
       }
     }
     gimp_image_undo_disable(l_new_tmp_image_id);

     g_free(l_filename);
     if (l_new_tmp_image_id >= 0)
     {
        /* use the new loaded temporary image */
        l_old_tmp_image_id  = pvals->tmp_image_id;
        pvals->tmp_image_id = l_new_tmp_image_id;

        /* flatten image, and get the (only) resulting drawable */
        mgp->drawable = p_get_prevw_drawable(mgp);

        /* gimp_display_new(pvals->tmp_image_id); */ /* add a display for debugging only */

        /* re initialize preview image */
        mov_path_prevw_preview_init(mgp);
        p_point_refresh(mgp);

        mgp->old_preview_frame_nr = mgp->preview_frame_nr;

        gtk_widget_queue_draw(mgp->pv_ptr->da_widget);
        mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
        gdk_flush();

        /* destroy the old tmp image */
        gimp_image_delete(l_old_tmp_image_id);

        mgp->instant_apply_request = FALSE;
     }
     mov_set_active_cursor(mgp);
  }
}  /* end mov_upvw_callback */


static void
mov_apv_callback (GtkWidget *widget,
                      gpointer   data)
{
#define ARGC_APV 5
  t_mov_gui_stuff    *mgp;
  GapVinVideoInfo    *vin_ptr;
  static gint         apv_locked = FALSE;
  gint32              l_new_image_id;
  GimpParam          *return_vals;
  int                 nreturn_vals;
  gint                l_rc;

  static GapArrArg  argv[ARGC_APV];
  static char *radio_apv_mode[3] = { N_("Object on empty frames")
                                   , N_("Object on one frame")
                                   , N_("Exact object on frames")
                                   };
  static int gettextize_loop = 0;



  mgp = data;


  if(!p_chk_keyframes(mgp))
  {
    return;
  }

  if(apv_locked)
  {
    return;
  }

  apv_locked = TRUE;

  if(gap_debug) printf("mov_apv_callback preview_frame_nr: %d\n",
         (int)mgp->preview_frame_nr);


  for (;gettextize_loop < 3; gettextize_loop++)
  {
    radio_apv_mode[gettextize_loop] = gettext(radio_apv_mode[gettextize_loop]);
  }

  gap_arr_arg_init(&argv[0], GAP_ARR_WGT_RADIO);
  argv[0].label_txt = _("Anim Preview Mode:");
  argv[0].help_txt  = NULL;
  argv[0].radio_argc  = 3;
  argv[0].radio_argv = radio_apv_mode;
  argv[0].radio_ret  = 0;
  argv[0].has_default = TRUE;
  argv[0].radio_default = 0;
  switch(pvals->apv_mode)
  {
    case GAP_APV_EXACT:
       argv[0].radio_ret  = 2;
      break;
    case GAP_APV_ONE_FRAME:
       argv[0].radio_ret  = 1;
       break;
    default:
       argv[0].radio_ret  = 0;
       break;
  }

  gap_arr_arg_init(&argv[1], GAP_ARR_WGT_FLT_PAIR);
  argv[1].constraint = TRUE;
  argv[1].label_txt = _("Scale Preview:");
  argv[1].help_txt  = _("Scale down size of the generated animated preview (in %)");
  argv[1].flt_min   = 5.0;
  argv[1].flt_max   = 100.0;
  argv[1].flt_step  = 1.0;
  argv[1].flt_ret   = pvals->apv_scalex;
  argv[1].has_default = TRUE;
  argv[1].flt_default = 40;

  gap_arr_arg_init(&argv[2], GAP_ARR_WGT_FLT_PAIR);
  argv[2].constraint = TRUE;
  argv[2].label_txt = _("Framerate:");
  argv[2].help_txt  = _("Framerate to use in the animated preview in frames/sec");
  argv[2].flt_min   = 1.0;
  argv[2].flt_max   = 100.0;
  argv[2].flt_step  = 1.0;
  argv[2].flt_ret   = 24;

  vin_ptr = gap_vin_get_all(mgp->ainfo_ptr->basename);
  if(vin_ptr)
  {
     if(vin_ptr->framerate > 0) argv[2].flt_ret = vin_ptr->framerate;
     g_free(vin_ptr);
   }
  argv[2].has_default = TRUE;
  argv[2].flt_default = argv[2].flt_ret;

  gap_arr_arg_init(&argv[3], GAP_ARR_WGT_TOGGLE);
  argv[3].label_txt = _("Copy to Video Buffer:");
  argv[3].help_txt  = _("Save all single frames of animated preview to video buffer."
                        "(configured in gimprc by video-paste-dir and video-paste-basename)");
  argv[3].int_ret   = 0;
  argv[3].has_default = TRUE;
  argv[3].int_default = 0;

  gap_arr_arg_init(&argv[4], GAP_ARR_WGT_DEFAULT_BUTTON);
  argv[4].label_txt = _("Default");
  argv[4].help_txt  = _("Reset all parameters to default values");

  l_rc = gap_arr_ok_cancel_dialog( _("Move Path Animated Preview"),
                                 _("Options"),
                                  ARGC_APV, argv);

  /* quit if MovePath Mainwindow was closed */
  if(mgp->shell == NULL) { gtk_main_quit(); return; }

  if(l_rc)
  {
      switch(argv[0].radio_ret)
      {
        case 2:
           pvals->apv_mode = GAP_APV_EXACT;
           break;
        case 1:
           pvals->apv_mode = GAP_APV_ONE_FRAME;
           break;
        default:
           pvals->apv_mode = GAP_APV_QUICK;
           break;
      }

      pvals->apv_scalex = argv[1].flt_ret;
      pvals->apv_scaley = argv[1].flt_ret;
      pvals->apv_framerate = argv[2].flt_ret;

      if(argv[3].int_ret)
      {
         pvals->apv_gap_paste_buff = gap_lib_get_video_paste_name();
         gap_vid_edit_clear();
      }
      else
      {
         pvals->apv_gap_paste_buff = NULL;
      }

      if(gap_debug) printf("Generating Animated Preview\n");

        /* TODO: here we should start a thread for calculate and playback of the anim preview,
         * so the move_path main window is not blocked until playback exits
         */
      p_points_to_tab(mgp);
      if(!p_chk_keyframes(mgp))
      {
        return;
      }

      mov_set_waiting_cursor(mgp);

      l_new_image_id = gap_mov_exec_anim_preview(pvals, mgp->ainfo_ptr, mgp->preview_frame_nr);
      if(l_new_image_id < 0)
      {
         gap_arr_msg_win(GIMP_RUN_INTERACTIVE,
         _("Generation of animated preview failed"));
      }
      else
      {
        gint32           dummy_layer_id;
        dummy_layer_id = gap_image_get_any_layer(l_new_image_id);

        mov_set_waiting_cursor(mgp);  /* for refresh */
        return_vals = gimp_run_procedure ("plug_in_animationplay",
                                 &nreturn_vals,
                                 GIMP_PDB_INT32,    GIMP_RUN_NONINTERACTIVE,
                                 GIMP_PDB_IMAGE,    l_new_image_id,
                                 GIMP_PDB_DRAWABLE, dummy_layer_id,
                                 GIMP_PDB_END);
        gimp_destroy_params(return_vals, nreturn_vals);
      }
      pvals->apv_mlayer_image = -1;
      mov_set_active_cursor(mgp);
  }

  apv_locked = FALSE;
}  /* end mov_apv_callback */

static void
p_copy_point(gint to_idx, gint from_idx)
{
    pvals->point[to_idx].p_x = pvals->point[from_idx].p_x;
    pvals->point[to_idx].p_y = pvals->point[from_idx].p_y;
    pvals->point[to_idx].opacity = pvals->point[from_idx].opacity;
    pvals->point[to_idx].w_resize = pvals->point[from_idx].w_resize;
    pvals->point[to_idx].h_resize = pvals->point[from_idx].h_resize;
    pvals->point[to_idx].rotation = pvals->point[from_idx].rotation;
    pvals->point[to_idx].ttlx = pvals->point[from_idx].ttlx;
    pvals->point[to_idx].ttly = pvals->point[from_idx].ttly;
    pvals->point[to_idx].ttrx = pvals->point[from_idx].ttrx;
    pvals->point[to_idx].ttry = pvals->point[from_idx].ttry;
    pvals->point[to_idx].tblx = pvals->point[from_idx].tblx;
    pvals->point[to_idx].tbly = pvals->point[from_idx].tbly;
    pvals->point[to_idx].tbrx = pvals->point[from_idx].tbrx;
    pvals->point[to_idx].tbry = pvals->point[from_idx].tbry;
    pvals->point[to_idx].sel_feather_radius = pvals->point[from_idx].sel_feather_radius;

    /* do not copy keyframe */
    pvals->point[to_idx].keyframe_abs = 0;
    pvals->point[to_idx].keyframe = 0;
}



/* --------------------------
 * mov_grab_bezier_path
 * --------------------------
 * grab the bezier path divided in
 * straight lines and assign them to N-controlpoints.
 * this procedure uses the number of frames to be handled
 * as the wanted number of contolpoints.
 * (but constrain to the maximum allowed number of contolpoints)
 */
static void
mov_grab_bezier_path(t_mov_gui_stuff *mgp, gint32 vectors_id, gint32 stroke_id, const char *vectorname)
{
  gint32 image_id;
  gint             num_lines;
  gint             num_points;
  gdouble          max_distance;
  gdouble          distance;
  gdouble          step_length;
  gdouble          precision;
  gint             l_ii;

  image_id = mgp->ainfo_ptr->image_id;
  step_length = 1.0;

  num_points = 1 + abs(pvals->dst_range_end - pvals->dst_range_start);
  num_points = MIN((GAP_MOV_MAX_POINT-2), num_points);
  num_lines = num_points -1;

  distance   = 0.0;
  precision = 1.0;  /* shall give 1 pixel precision */

  if(num_lines > 0)
  {
    max_distance = gimp_vectors_stroke_get_length(vectors_id, stroke_id, precision);
    step_length = max_distance / ((gdouble)num_lines);
  }


  for(l_ii=0; l_ii < num_points ; l_ii++)
  {
    gdouble  xdouble;
    gdouble  ydouble;
    gdouble  slope;
    gboolean valid;
    gboolean success;
    

    success = gimp_vectors_stroke_get_point_at_dist(vectors_id
                                         , stroke_id
                                         , distance
                                         , precision
                                         , &xdouble
                                         , &ydouble
                                         , &slope
                                         , &valid
                                         );


    if(gap_debug)
    {
      printf("PATH distance: %.3f, (%.4f / %.4f) X:%03d Y: %03d slope:%.3f valid:%d success:%d\n"
            , (float)distance
            , (float)xdouble
            , (float)ydouble
            , (int)pvals->point[l_ii].p_x
            , (int)pvals->point[l_ii].p_y
            , (float)slope
            , (int)valid
            , (int)success
            );
    }

    if((!valid) || (!success))
    {
       /* stop because we already reached the end of the path.
        * (distance in pixles is greater than number of the frames to handle)
        */
       return;
    }
    pvals->point_idx_max = l_ii;
    p_clear_one_point(l_ii);
    pvals->point[l_ii].p_x = rint(xdouble);
    pvals->point[l_ii].p_y = rint(ydouble);

    distance += step_length;
  }

}  /* end mov_grab_bezier_path */


/* --------------------------
 * mov_grab_anchorpoints_path
 * --------------------------
 * grab the bezier path divided in
 * straight lines and assign them to N-controlpoints.
 * this procedure uses the number of frames to be handled
 * as the wanted number of contolpoints.
 * (but constrain to the maximum allowed number of contolpoints)
 */
static void
mov_grab_anchorpoints_path(t_mov_gui_stuff *mgp,
                           gint num_path_point_details,
                           gdouble *points_details
                           )
{
    gint l_ii;
    gint l_ti;
    gint l_idx;
    gint    point_x;
    gint    point_y;
#define GAP_BEZIER_CTRL1_X_INDEX  0
#define GAP_BEZIER_CTRL1_Y_INDEX  1
#define GAP_BEZIER_ANCHOR_X_INDEX 2
#define GAP_BEZIER_ANCHOR_Y_INDEX 3
#define GAP_BEZIER_CTRL2_X_INDEX  4
#define GAP_BEZIER_CTRL12Y_INDEX  5

    point_x = 0;
    point_y = 0;
    l_ti = 0;
    l_idx = 0;
    l_ii = 0;

    while(l_idx < GAP_MOV_MAX_POINT -2)
    {
      if(gap_debug)
      {
       printf("Point[%03d]: detail: %3.3f\n"
          , (int)l_ii
          , (float)points_details[l_ii]
          );
      }

     /* this implemenatation just fetches the bezier ancor points
      * and ignores bezier control points
      * Each Bezier segment endpoint (anchor, A) has two
      * additional control points (C) associated. They are specified in the
      * order CACCACCAC...
      * where each point consists of 2 flaot values in order x y.
      *
      */
      switch (l_ti)
      {
        case GAP_BEZIER_ANCHOR_X_INDEX:  point_x = (gint)points_details[l_ii]; break; 
        case GAP_BEZIER_ANCHOR_Y_INDEX:  point_y = (gint)points_details[l_ii]; break;
        default:  break;
      }

      l_ti++;
      l_ii++;
      if((l_ti >= 6) || (l_ii == num_path_point_details))
      {
        if(gap_debug)
        {
          printf("\n");
        }

        l_ti=0;

        if(gap_debug)
        {
          printf("ANCHOR x:%d y:%d\n\n"
                               ,(int)point_x
                               ,(int)point_y
                               );
        }

        pvals->point_idx_max = l_idx;
        p_clear_one_point(l_idx);
        pvals->point[l_idx].p_x = point_x;
        pvals->point[l_idx].p_y = point_y;
        l_idx++;
      }
      if (l_ii >= num_path_point_details)
      {
        break;
      }
    }

    if(gap_debug)
    {
      printf("\n");
    }


}  /* end mov_grab_anchorpoints_path */



static void
mov_pgrab_callback (GtkWidget *widget,
                    GdkEventButton *bevent,
                    gpointer data)
{
  t_mov_gui_stuff *mgp = data;
  gint32 image_id;
  gint32 vectors_id;

  if(gap_debug) printf("mov_pgrab_callback\n");

  /* get the image where MovePath was invoked from */
  image_id = mgp->ainfo_ptr->image_id;

  vectors_id = gimp_image_get_active_vectors(image_id);
  if(vectors_id >= 0)
  {
    GimpVectorsStrokeType pathtype;
    gboolean path_closed;
    gint num_path_point_details;
    gdouble *points_details;
    gchar *vectorname;
    gint  num_stroke_ids;
    gint  *stroke_ids;

    vectorname = gimp_vectors_get_name(vectors_id);


    points_details = NULL;
    num_path_point_details = 0;

    if(gap_debug)
    {
      printf("vectorname :%s\n", vectorname);
    }
    
    stroke_ids = gimp_vectors_get_strokes(vectors_id, &num_stroke_ids);

    if(gap_debug)
    {
      printf("num_stroke_ids:%d\n"
            , (int)num_stroke_ids
            );
    }
    
    if (num_stroke_ids < 1)
    {
      g_message(_("No stroke ids found in path:\n"
                  "'%s'\n"
                  "in the Image:\n"
                  "'%s'")
              ,vectorname
              ,mgp->ainfo_ptr->old_filename
              );
      return;
    }

    /* TODO how to handle path that has more than one stroke_id.
     * the current implementation uses only the 1.st stroke_id
     */


    pathtype = gimp_vectors_stroke_get_points(vectors_id
                                             , stroke_ids[0]
                                             , &num_path_point_details
                                             , &points_details
                                             , &path_closed
                                             );




    if(gap_debug)
    {
      printf("pathtype:%d path_closed flag :%d num_points:%d num_stroke_ids:%d\n"
            , (int)pathtype
            , (int)path_closed
            , (int)num_path_point_details
            , (int)num_stroke_ids
            );
    }

    if(pathtype != GIMP_VECTORS_STROKE_TYPE_BEZIER)
    {
      g_message(_("Unsupported pathtype %d found in path:\n"
                  "'%s'\n"
                  "in the Image:\n"
                  "'%s'")
              ,(int)pathtype
              ,vectorname
              ,mgp->ainfo_ptr->old_filename
              );
      return;
    }

    if(num_path_point_details < 1)
    {
      g_message(_("No controlpoints found in path:\n"
                  "'%s'\n"
                  "in the Image:\n"
                  "'%s'")
              ,vectorname
              ,mgp->ainfo_ptr->old_filename
              );
      return;
    }


    if(bevent->state & GDK_SHIFT_MASK)
    {
      /* When SHIFT Key was pressed
       * the path will be divided in n-parts to get
       * one controlpoint per handled frame.
       */
      mov_grab_bezier_path(mgp, vectors_id, stroke_ids[0], vectorname);
    }
    else
    {
      mov_grab_anchorpoints_path(mgp
                                ,num_path_point_details
                                ,points_details
                                );
    }


    g_free(stroke_ids);
    g_free(points_details);

    pvals->point_idx = 0;
    p_point_refresh(mgp);
    mov_set_instant_apply_request(mgp);
  }
  else
  {
    g_message(_("No path found in the image:\n"
                "'%s'")
              ,mgp->ainfo_ptr->old_filename
              );
  }

}  /* end mov_pgrab_callback */


static void
mov_padd_callback (GtkWidget *widget,
                      gpointer   data)
{
  t_mov_gui_stuff *mgp = data;
  gint l_idx;

  if(gap_debug) printf("mov_padd_callback\n");
  l_idx = pvals->point_idx_max;
  if (l_idx < GAP_MOV_MAX_POINT -2)
  {
    /* advance to next point */
    p_points_to_tab(mgp);
    pvals->point_idx_max++;
    pvals->point_idx = pvals->point_idx_max;

    /* copy values from previous point to current (new) point */
    p_copy_point(pvals->point_idx_max, l_idx);
    p_point_refresh(mgp);
  }
}

static void
mov_pins_callback (GtkWidget *widget,
                      gpointer   data)
{
  t_mov_gui_stuff *mgp = data;
  gint l_idx;

  if(gap_debug) printf("mov_pins_callback\n");
  l_idx = pvals->point_idx_max;
  if (l_idx < GAP_MOV_MAX_POINT -2)
  {
    /* advance to next point */
    p_points_to_tab(mgp);
    pvals->point_idx_max++;

    for(l_idx = pvals->point_idx_max; l_idx >  pvals->point_idx; l_idx--)
    {
      /* copy values from prev point */
      p_copy_point(l_idx, l_idx-1);
    }

    pvals->point_idx++;
    p_point_refresh(mgp);
  }
}

static void
mov_pdel_callback (GtkWidget *widget,
                      gpointer   data)
{
  t_mov_gui_stuff *mgp = data;
  gint l_idx;

  if(gap_debug) printf("mov_pdel_callback\n");

  l_idx = pvals->point_idx_max;
  if(pvals->point_idx_max == 0)
  {
    /* This is the las t point to delete */
    p_reset_points();
  }
  else
  {
    for(l_idx = pvals->point_idx; l_idx <  pvals->point_idx_max; l_idx++)
    {
      /* copy values from next point */
      p_copy_point(l_idx, l_idx+1);
    }
    pvals->point_idx_max--;
    pvals->point_idx = MIN(pvals->point_idx, pvals->point_idx_max);
  }
  p_point_refresh(mgp);
  mov_set_instant_apply_request(mgp);
}

static void
mov_follow_keyframe(t_mov_gui_stuff *mgp)
{
  gint32 keyframe_abs;

  keyframe_abs = mgp->keyframe_abs;
  if(pvals->point_idx <= 0)
  {
    keyframe_abs = mgp->first_nr;
  }
  else
  {
    if(pvals->point_idx  >= pvals->point_idx_max)
    {
      keyframe_abs = mgp->last_nr;
    }
    else
    {
      if(keyframe_abs < 1)
      {
        return;
      }
    }
  }

  if((keyframe_abs >= mgp->first_nr)
  && (keyframe_abs <= mgp->last_nr))
  {
    mgp->preview_frame_nr = keyframe_abs;
    gtk_adjustment_set_value (mgp->preview_frame_nr_adj,
                            (gdouble)keyframe_abs);
  }
}

static void
mov_pnext_callback (GtkWidget *widget,
                         GdkEventButton *bevent,
                         gpointer data)
{
  t_mov_gui_stuff *mgp = data;

  if(gap_debug) printf("mov_pnext_callback\n");
  if (pvals->point_idx < pvals->point_idx_max)
  {
    /* advance to next point */
    p_points_to_tab(mgp);
    pvals->point_idx++;
    p_point_refresh(mgp);
    if (bevent->state & GDK_SHIFT_MASK)
    {
      mov_follow_keyframe(mgp);
    }
    mov_set_instant_apply_request(mgp);
  }
}


static void
mov_pprev_callback (GtkWidget *widget,
                         GdkEventButton *bevent,
                         gpointer data)
{
  t_mov_gui_stuff *mgp = data;

  if(gap_debug) printf("mov_pprev_callback\n");
  if (pvals->point_idx > 0)
  {
    /* advance to next point */
    p_points_to_tab(mgp);
    pvals->point_idx--;
    p_point_refresh(mgp);
    if (bevent->state & GDK_SHIFT_MASK)
    {
      mov_follow_keyframe(mgp);
    }
    mov_set_instant_apply_request(mgp);
  }
}

static void
mov_pfirst_callback (GtkWidget *widget,
                         GdkEventButton *bevent,
                         gpointer data)
{
  t_mov_gui_stuff *mgp = data;

  if(gap_debug) printf("mov_pfirst_callback\n");

  /* advance to first point */
  p_points_to_tab(mgp);
  pvals->point_idx = 0;
  p_point_refresh(mgp);
  if (bevent->state & GDK_SHIFT_MASK)
  {
    mov_follow_keyframe(mgp);
  }
  mov_set_instant_apply_request(mgp);
}


static void
mov_plast_callback (GtkWidget *widget,
                         GdkEventButton *bevent,
                         gpointer data)
{
  t_mov_gui_stuff *mgp = data;

  if(gap_debug) printf("mov_plast_callback\n");

  /* advance to first point */
  p_points_to_tab(mgp);
  pvals->point_idx = pvals->point_idx_max;
  p_point_refresh(mgp);
  if (bevent->state & GDK_SHIFT_MASK)
  {
    mov_follow_keyframe(mgp);
  }
  mov_set_instant_apply_request(mgp);
}


static void
mov_pclr_callback (GtkWidget *widget,
                      gpointer   data)
{
  t_mov_gui_stuff *mgp = data;

  if(gap_debug) printf("mov_pclr_callback\n");
  p_clear_one_point(pvals->point_idx);         /* clear the current point */
  p_point_refresh(mgp);
  mov_set_instant_apply_request(mgp);
}

static void
mov_pdel_all_callback (GtkWidget *widget,
                      gpointer   data)
{
  t_mov_gui_stuff *mgp = data;

  if(gap_debug) printf("mov_pdel_all_callback\n");
  p_reset_points();
  p_point_refresh(mgp);
  mov_set_instant_apply_request(mgp);
}

static void
mov_pclr_all_callback (GtkWidget *widget,
                      GdkEventButton *bevent,
                      gpointer   data)
{
  gint l_idx;
  gint l_ref_idx1;
  gint l_ref_idx2;
  t_mov_gui_stuff *mgp = data;
  gdouble          mix_factor;

  if(gap_debug) printf("mov_pclr_all_callback\n");

  if(bevent->state & GDK_SHIFT_MASK)
  {
    for(l_idx = 1; l_idx <= pvals->point_idx_max; l_idx++)
    {
      mix_factor = 0.0;
      l_ref_idx1 = 0;
      l_ref_idx2 = 0;

      p_mix_one_point(l_idx, l_ref_idx1, l_ref_idx2, mix_factor);
    }
  }
  else
  {
    if(bevent->state & GDK_CONTROL_MASK)
    {
      for(l_idx = 1; l_idx <= pvals->point_idx_max -1; l_idx++)
      {
        mix_factor = (gdouble)l_idx / (gdouble)pvals->point_idx_max;
        l_ref_idx1 = 0;
        l_ref_idx2 = pvals->point_idx_max;

        p_mix_one_point(l_idx, l_ref_idx1, l_ref_idx2, mix_factor);
      }
    }
    else
    {
      for(l_idx = 0; l_idx <= pvals->point_idx_max; l_idx++)
      {
        p_clear_one_point(l_idx);
      }
    }
  }

  p_point_refresh(mgp);
  mov_set_instant_apply_request(mgp);
}


static void
mov_prot_follow_callback (GtkWidget *widget,
                         GdkEventButton *bevent,
                         gpointer data)
{
  gdouble  l_startangle;
  int     key_modifier;

  t_mov_gui_stuff *mgp = data;
  key_modifier = 0;

  if(gap_debug) printf("mov_prot_follow_callback\n");

  /* SHIFT: GDK_SHIFT_MASK,
   * CTRL:  GDK_CONTROL_MASK,
   * ALT:   GDK_MOD1_MASK
   */
  key_modifier = 0;
  if (bevent->state & GDK_SHIFT_MASK)
  {
    key_modifier = 1;       /* SHIFT */
  }

  if(gap_debug)
  {
    printf("key_modifier %d\n", (int)key_modifier);
  }

  if( pvals->point_idx_max > 1)
  {
    l_startangle = 0.0;
    if(key_modifier != 0)
    {
      /* SHIFT */
      p_points_to_tab(mgp);
      l_startangle = pvals->point[0].rotation;
    }
    gap_mov_exec_calculate_rotate_follow(pvals, l_startangle);
  }

  p_point_refresh(mgp);
  mov_set_instant_apply_request(mgp);
}

static void
p_filesel_close_cb(GtkWidget *widget,
                   t_mov_gui_stuff *mgp)
{
  if(mgp->filesel == NULL) return;

  gtk_widget_destroy(GTK_WIDGET(mgp->filesel));
  mgp->filesel = NULL;   /* now filesel is closed */
}

static void
mov_pload_callback (GtkWidget *widget,
                      gpointer   data)
{
  GtkWidget *filesel;
  t_mov_gui_stuff *mgp = data;

  if(mgp->filesel != NULL)
  {
    gtk_window_present(GTK_WINDOW(mgp->filesel));
    return;  /* filesel is already open */
  }

  filesel = gtk_file_selection_new ( _("Load Path Points from File"));
  mgp->filesel = filesel;

  gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);

  g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
                   "clicked",
                    G_CALLBACK (p_points_load_from_file),
                    mgp);

  g_signal_connect(G_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
                  "clicked",
                   G_CALLBACK (p_filesel_close_cb),
                   mgp);

  gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel),
                                   mgp->pointfile_name);

  gtk_widget_show (filesel);
  /* "destroy" has to be the last signal,
   * (otherwise the other callbacks are never called)
   */
  g_signal_connect (G_OBJECT (filesel), "destroy",
                    G_CALLBACK (p_filesel_close_cb),
                    mgp);
}


static void
mov_psave_callback (GtkWidget *widget,
                      gpointer   data)
{
  GtkWidget *filesel;
  t_mov_gui_stuff *mgp = data;

  if(mgp->filesel != NULL)
  {
    gtk_window_present(GTK_WINDOW(mgp->filesel));
    return;  /* filesel is already open */
  }

  filesel = gtk_file_selection_new ( _("Save Path Points to File"));
  mgp->filesel = filesel;

  gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);

  g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
                   "clicked",
                   G_CALLBACK (p_points_save_to_file),
                   mgp);

  g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
                   "clicked",
                    G_CALLBACK (p_filesel_close_cb),
                    mgp);

  gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel),
                                   mgp->pointfile_name);

  gtk_widget_show (filesel);
  /* "destroy" has to be the last signal,
   * (otherwise the other callbacks are never called)
   */
  g_signal_connect (G_OBJECT (filesel), "destroy",
                    G_CALLBACK (p_filesel_close_cb),
                    mgp);
}


static void
p_points_load_from_file (GtkWidget *widget,
                      t_mov_gui_stuff *mgp)
{
  const gchar        *filename;

  if(gap_debug) printf("p_points_load_from_file\n");
  if(mgp->filesel == NULL)
  {
    return;
  }

  filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (mgp->filesel));
  g_free(mgp->pointfile_name);
  mgp->pointfile_name = g_strdup(filename);

  if(gap_debug) printf("p_points_load_from_file %s\n", mgp->pointfile_name);

  gtk_widget_destroy(GTK_WIDGET(mgp->filesel));
  mgp->filesel = NULL;

  p_load_points(mgp->pointfile_name);
  p_point_refresh(mgp);
  mov_set_instant_apply_request(mgp);
}  /* end p_points_load_from_file */


static void
p_points_save_to_file (GtkWidget *widget,
                      t_mov_gui_stuff *mgp)
{
  const gchar        *filename;

  if(gap_debug) printf("p_points_save_to_file\n");
  if(mgp->filesel == NULL)
  {
    return;  /* filesel is already open */
  }

  filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (mgp->filesel));
  g_free(mgp->pointfile_name);
  mgp->pointfile_name = g_strdup(filename);

  if(gap_debug) printf("p_points_save_to_file %s\n", mgp->pointfile_name);

  gtk_widget_destroy(GTK_WIDGET(mgp->filesel));
  mgp->filesel = NULL;

  p_points_to_tab(mgp);
  p_save_points(mgp->pointfile_name, mgp);

  /* quit if MovePath Mainwindow was closed */
  if(mgp->shell == NULL) { gtk_main_quit(); return; }

  p_point_refresh(mgp);

}  /* end p_points_save_to_file */


static void
p_point_refresh(t_mov_gui_stuff *mgp)
{
  p_points_from_tab(mgp);
  p_update_point_index_text(mgp);

  if(gap_debug) printf("p_point_refresh:newval in_call=%d\n", mgp->in_call );
  if( !mgp->in_call )
  {
      mov_path_prevw_cursor_update( mgp );
      mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
  }
  mgp->in_call = TRUE;

  gtk_adjustment_set_value (mgp->x_adj,
                            (gdouble)mgp->p_x);
  gtk_adjustment_set_value (mgp->y_adj,
                            (gdouble)mgp->p_y);
  gtk_adjustment_set_value (mgp->wres_adj,
                            (gdouble)mgp->w_resize);
  gtk_adjustment_set_value (mgp->hres_adj,
                            (gdouble)mgp->h_resize);
  gtk_adjustment_set_value (mgp->opacity_adj,
                            (gdouble)mgp->opacity);
  gtk_adjustment_set_value (mgp->rotation_adj,
                            (gdouble)mgp->rotation);
  gtk_adjustment_set_value (mgp->keyframe_adj,
                            (gdouble)mgp->keyframe_abs);
  gtk_adjustment_set_value (mgp->ttlx_adj,
                            (gdouble)mgp->ttlx);
  gtk_adjustment_set_value (mgp->ttly_adj,
                            (gdouble)mgp->ttly);
  gtk_adjustment_set_value (mgp->ttrx_adj,
                            (gdouble)mgp->ttrx);
  gtk_adjustment_set_value (mgp->ttry_adj,
                            (gdouble)mgp->ttry);
  gtk_adjustment_set_value (mgp->tblx_adj,
                            (gdouble)mgp->tblx);
  gtk_adjustment_set_value (mgp->tbly_adj,
                            (gdouble)mgp->tbly);
  gtk_adjustment_set_value (mgp->tbrx_adj,
                            (gdouble)mgp->tbrx);
  gtk_adjustment_set_value (mgp->tbry_adj,
                            (gdouble)mgp->tbry);
  gtk_adjustment_set_value (mgp->sel_feather_radius_adj,
                            (gdouble)mgp->sel_feather_radius);

  mgp->in_call = FALSE;
}       /* end p_point_refresh */

static void
p_pick_nearest_point(gint px, gint py)
{
  gint l_idx;
  gint l_idx_min;
  gdouble l_sq_dist;
  gdouble l_dx, l_dy;
  gdouble l_sq_dist_min;

  l_idx_min = 0;
  l_sq_dist_min = G_MAXDOUBLE;

  if(gap_debug) printf("\np_pick_nearest_point: near to %4d %4d\n", (int)px, (int)py);

  for(l_idx = pvals->point_idx_max; l_idx >= 0; l_idx--)
  {
    /* calculate x and y distance */
    l_dx = pvals->point[l_idx].p_x - px;
    l_dy = pvals->point[l_idx].p_y - py;

    /* calculate square of the distance */
    l_sq_dist = (l_dx * l_dx) + (l_dy * l_dy);
    if(l_sq_dist < l_sq_dist_min)
    {
      l_sq_dist_min = l_sq_dist;
      l_idx_min = l_idx;
    }

    if(gap_debug)
    {
       printf("  [%2d] %4d %4d %f\n",
             (int)l_idx,
             (int)pvals->point[l_idx].p_x,
             (int)pvals->point[l_idx].p_y,
             (float)l_sq_dist
             );
    }
  }
  if(gap_debug) printf("p_pick_nearest_point: selected %d\n", (int)l_idx_min);

  pvals->point_idx = l_idx_min;
  pvals->point[pvals->point_idx].p_x = px;
  pvals->point[pvals->point_idx].p_y = py;
}       /* end p_pick_nearest_point */


static void
mov_imglayer_menu_callback(GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  gint32 l_image_id;
  gint32 id;
  gint value;

  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);
  id = value;

  l_image_id = gimp_drawable_get_image(id);
  if(!gap_image_is_alive(l_image_id))
  {
     if(gap_debug)
     {
       printf("mov_imglayer_menu_callback: NOT ALIVE image_id=%d layer_id=%d\n",
         (int)l_image_id, (int)id);
     }
     return;
  }

  if(id != pvals->src_layer_id)
  {
    if(pvals->tmpsel_image_id >= 0)
    {
      gimp_image_delete(pvals->tmpsel_image_id);
      pvals->tmpsel_image_id = -1;
    }
  }
  pvals->src_layer_id = id;
  pvals->src_image_id = l_image_id;


  if(gap_debug) printf("mov_imglayer_menu_callback: image_id=%d layer_id=%d\n",
         (int)pvals->src_image_id, (int)pvals->src_layer_id);

  mov_set_instant_apply_request(mgp);

} /* end mov_imglayer_menu_callback */

static gint
mov_imglayer_constrain(gint32 image_id, gint32 drawable_id, gpointer data)
{
  if(gap_debug) printf("GAP-DEBUG: mov_imglayer_constrain PROCEDURE image_id:%d drawable_id:%d\n"
                          ,(int)image_id
                          ,(int)drawable_id
                          );

  if(drawable_id < 0)
  {
     /* gimp 1.1 makes a first call of the constraint procedure
      * with drawable_id = -1, and skips the whole image if FALSE is returned
      */
     return(TRUE);
  }

  if(!gap_image_is_alive(image_id))
  {
     return(FALSE);
  }


   /* dont accept layers from within the destination image id
    * or layers within the internal used tmporary images
    * or layers within images of other base types
    * (conversions between different base_types are not supported in this version)
    */
  return((image_id != pvals->dst_image_id) &&
          (image_id != pvals->cache_tmp_image_id) &&
          (image_id != pvals->apv_mlayer_image) &&
          (image_id != pvals->tmp_image_id) &&
          (image_id != pvals->tmp_alt_image_id) &&
          (image_id != pvals->tmpsel_image_id) &&
          (image_id != pvals->tween_image_id) &&
          (image_id != pvals->trace_image_id) &&
          (gimp_image_base_type(image_id) == gimp_image_base_type(pvals->tmp_image_id)) );
} /* end mov_imglayer_constrain */

static void
mov_paintmode_menu_callback (GtkWidget *widget,  t_mov_gui_stuff *mgp)
{
  gint value;

  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);

  pvals->src_paintmode = value;
  mov_set_instant_apply_request(mgp);
}

static void
mov_handmode_menu_callback (GtkWidget *widget,  t_mov_gui_stuff *mgp)
{
  gint value;

  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);
  pvals->src_handle = value;
  if(mgp == NULL) return;

  mov_set_instant_apply_request(mgp);
}

static void
mov_stepmode_menu_callback (GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  gboolean l_sensitive;
  GtkWidget *spinbutton;
  gint       value;

  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);
  pvals->src_stepmode = value;
  if(mgp == NULL) return;

  l_sensitive = TRUE;
  if((pvals->src_stepmode == GAP_STEP_NONE)
  || (pvals->src_stepmode == GAP_STEP_FRAME_NONE))
  {
    l_sensitive = FALSE;
  }

  if(mgp->step_speed_factor_adj)
  {
    spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->step_speed_factor_adj), "spinbutton"));
    if(spinbutton)
    {
      gtk_widget_set_sensitive(spinbutton, l_sensitive);
    }
  }

  mov_set_instant_apply_request(mgp);

}  /* end mov_stepmode_menu_callback */


static void
mov_tweenlayer_sensitivity(t_mov_gui_stuff *mgp)
{
  gboolean l_sensitive;
  GtkWidget *spinbutton;

  l_sensitive = TRUE;
  if(pvals->tween_steps < 1)
  {
    l_sensitive = FALSE;
  }

  if(mgp->tween_opacity_initial_adj)
  {
    spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->tween_opacity_initial_adj), "spinbutton"));
    if(spinbutton)
    {
      gtk_widget_set_sensitive(spinbutton, l_sensitive);
    }
  }

  if(mgp->tween_opacity_desc_adj)
  {
   spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->tween_opacity_desc_adj), "spinbutton"));
   if(spinbutton)
   {
     gtk_widget_set_sensitive(spinbutton, l_sensitive);
   }
  }
}  /* end mov_tweenlayer_sensitivity */

static void
mov_tracelayer_sensitivity(t_mov_gui_stuff *mgp)
{
  gboolean l_sensitive;
  GtkWidget *spinbutton;

  l_sensitive = FALSE;
  if(pvals->tracelayer_enable)
  {
    l_sensitive = TRUE;
  }

  if(mgp->trace_opacity_initial_adj)
  {
    spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->trace_opacity_initial_adj), "spinbutton"));
    if(spinbutton)
    {
      gtk_widget_set_sensitive(spinbutton, l_sensitive);
    }
  }

  if(mgp->trace_opacity_desc_adj)
  {
   spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->trace_opacity_desc_adj), "spinbutton"));
   if(spinbutton)
   {
     gtk_widget_set_sensitive(spinbutton, l_sensitive);
   }
  }
}  /* end mov_tracelayer_sensitivity */



static void
mov_gint_toggle_callback(GtkWidget *w, gpointer   client_data)
{
  gint *data;

  data = (gint*)client_data;

  if (GTK_TOGGLE_BUTTON (w)->active)
  {
    *data = 1;
  }
  else
  {
    *data = 0;
  }
}  /* end mov_gint_toggle_callback */

static void
mov_force_visibility_toggle_callback    (GtkWidget *widget, gpointer client_data)
{
  t_mov_gui_stuff *mgp;

  if((widget == NULL) || (client_data == NULL))
  {
    return;
  }
  mov_gint_toggle_callback(widget, client_data);
  mgp = g_object_get_data( G_OBJECT(widget), "mgp" );
  mov_set_instant_apply_request(mgp);

}  /* end mov_force_visibility_toggle_callback */

static void
mov_bluebox_callback    (GtkWidget *widget, gpointer client_data)
{
  t_mov_gui_stuff *mgp;

  if((widget == NULL) || (client_data == NULL))
  {
    return;
  }
  mov_gint_toggle_callback(widget, client_data);
  mgp = g_object_get_data( G_OBJECT(widget), "mgp" );

  if(mgp)
  {
    mov_set_instant_apply_request(mgp);
  }

}  /* end mov_bluebox_callback */

static void
mov_tracelayer_callback    (GtkWidget *widget, gpointer client_data)
{
  t_mov_gui_stuff *mgp;

  if((widget == NULL) || (client_data == NULL))
  {
    return;
  }
  mov_gint_toggle_callback(widget, client_data);
  mgp = g_object_get_data( G_OBJECT(widget), "mgp" );

  if(mgp)
  {
    mov_tracelayer_sensitivity(mgp);
  }

}  /* end mov_tracelayer_callback */


static void
mov_show_path_or_cursor(t_mov_gui_stuff *mgp)
{
  if(mgp == NULL) return;
  if(mgp->startup) return;
  if(mgp->pv_ptr == NULL) return;
  if(mgp->pv_ptr->da_widget == NULL) return;
  if(mgp->drawable == NULL) return;

  p_point_refresh(mgp);
  mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
  gtk_widget_queue_draw(mgp->pv_ptr->da_widget);
  gdk_flush();
}  /* end mov_show_path_or_cursor */

static void
mov_show_path_callback(GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  mov_gint_toggle_callback(widget, &mgp->show_path);
  mov_show_path_or_cursor(mgp);
}  /* end mov_show_path_callback */

static void
mov_show_cursor_callback(GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  mov_gint_toggle_callback(widget, &mgp->show_cursor);
  mov_show_path_or_cursor(mgp);
}  /* end mov_show_cursor_callback */

static void
mov_show_grid_callback(GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  mov_gint_toggle_callback(widget, &mgp->show_grid);
  mov_show_path_or_cursor(mgp);
  //XX grid rendering and picking not implemented yet !!!
}  /* end mov_show_grid_callback */


/* --------------------------
 * install / remove timer
 * --------------------------
 */
static void
mov_install_timer(t_mov_gui_stuff *mgp)
{
  if(mgp->instant_timertag < 0)
  {
    mgp->instant_timertag = (gint32) g_timeout_add(INSTANT_TIMERINTERVAL_MILLISEC,
                                      (GtkFunction)mov_instant_timer_callback
                                      , mgp);
  }
}  /* end mov_install_timer */

static void
mov_remove_timer(t_mov_gui_stuff *mgp)
{
  if(mgp->instant_timertag >= 0)
  {
    g_source_remove(mgp->instant_timertag);
    mgp->instant_timertag = -1;
  }
}  /* end mov_remove_timer */

/* --------------------------
 * mov_instant_timer_callback
 * --------------------------
 * This procedure is called periodically via timer
 * when the instant_apply checkbox is ON
 */
static void
mov_instant_timer_callback(gpointer   user_data)
{
  t_mov_gui_stuff *mgp;

  mgp = user_data;
  if(mgp == NULL)
  {
    return;
  }

  mov_remove_timer(mgp);

  if(!mov_check_valid_src_layer(mgp))
  {
    return;
  }

  if(mgp->instant_apply_request)
  {
    if(gap_debug) printf("FIRE mov_instant_timer_callback >>>> REQUEST is TRUE\n");
    mov_upvw_callback (NULL, mgp);  /* the request is cleared in this procedure */
  }

  /* restart timer for next cycle */
  if(mgp->instant_apply)
  {
     mov_install_timer(mgp);
  }
}  /* end mov_instant_timer_callback */

static void
mov_instant_apply_callback(GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  mov_gint_toggle_callback(widget, &mgp->instant_apply);
  if(mgp->instant_apply)
  {
    mov_set_instant_apply_request(mgp);
    mov_install_timer(mgp);
  }
  else
  {
    mov_remove_timer(mgp);
  }
}  /* end mov_instant_apply_callback */


/* ============================================================================
 * procedures to handle POINTS - TABLE
 * ============================================================================
 */


static void
p_points_from_tab(t_mov_gui_stuff *mgp)
{
  GtkWidget *scale;
  GtkWidget *spinbutton;

  mgp->p_x      = pvals->point[pvals->point_idx].p_x;
  mgp->p_y      = pvals->point[pvals->point_idx].p_y;
  mgp->opacity  = pvals->point[pvals->point_idx].opacity;
  mgp->w_resize = pvals->point[pvals->point_idx].w_resize;
  mgp->h_resize = pvals->point[pvals->point_idx].h_resize;
  mgp->rotation = pvals->point[pvals->point_idx].rotation;
  mgp->ttlx     = pvals->point[pvals->point_idx].ttlx;
  mgp->ttly     = pvals->point[pvals->point_idx].ttly;
  mgp->ttrx     = pvals->point[pvals->point_idx].ttrx;
  mgp->ttry     = pvals->point[pvals->point_idx].ttry;
  mgp->tblx     = pvals->point[pvals->point_idx].tblx;
  mgp->tbly     = pvals->point[pvals->point_idx].tbly;
  mgp->tbrx     = pvals->point[pvals->point_idx].tbrx;
  mgp->tbry     = pvals->point[pvals->point_idx].tbry;
  mgp->sel_feather_radius  = pvals->point[pvals->point_idx].sel_feather_radius;
  mgp->keyframe_abs = pvals->point[pvals->point_idx].keyframe_abs;

  if(( mgp->keyframe_adj != NULL) && (mgp->startup != TRUE))
  {
   /*   findout the gtk_widgets (scale and spinbutton) connected
    *   to mgp->keyframe_adj
    *   and set_sensitive to TRUE or FALSE
    */
    scale = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->keyframe_adj), "scale"));
    spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->keyframe_adj), "spinbutton"));

    if(spinbutton == NULL)
    {
      return;
    }
    if(gap_debug)
    {
      printf("p_points_from_tab: scale %x spinbutton %x\n",
              (int)scale, (int)spinbutton);
    }
    if((pvals->point_idx == 0) || (pvals->point_idx == pvals->point_idx_max))
    {
      gtk_widget_set_sensitive(spinbutton, FALSE);
      if(scale)
        gtk_widget_set_sensitive(scale, FALSE);
    }
    else
    {
      gtk_widget_set_sensitive(spinbutton, TRUE);
      if(scale)
        gtk_widget_set_sensitive(scale, TRUE);
    }
  }
}

static void
p_points_to_tab(t_mov_gui_stuff *mgp)
{
  if(gap_debug) printf("p_points_to_tab: idx=%d, rotation=%f\n", (int)pvals->point_idx , (float)mgp->rotation);

  pvals->point[pvals->point_idx].p_x       = mgp->p_x;
  pvals->point[pvals->point_idx].p_y       = mgp->p_y;
  pvals->point[pvals->point_idx].opacity   = mgp->opacity;
  pvals->point[pvals->point_idx].w_resize  = mgp->w_resize;
  pvals->point[pvals->point_idx].h_resize  = mgp->h_resize;
  pvals->point[pvals->point_idx].rotation  = mgp->rotation;
  pvals->point[pvals->point_idx].ttlx      = mgp->ttlx;
  pvals->point[pvals->point_idx].ttly      = mgp->ttly;
  pvals->point[pvals->point_idx].ttrx      = mgp->ttrx;
  pvals->point[pvals->point_idx].ttry      = mgp->ttry;
  pvals->point[pvals->point_idx].tblx      = mgp->tblx;
  pvals->point[pvals->point_idx].tbly      = mgp->tbly;
  pvals->point[pvals->point_idx].tbrx      = mgp->tbrx;
  pvals->point[pvals->point_idx].tbry      = mgp->tbry;
  pvals->point[pvals->point_idx].sel_feather_radius  = mgp->sel_feather_radius;
  pvals->point[pvals->point_idx].keyframe_abs  = mgp->keyframe_abs;
  if((mgp->keyframe_abs > 0)
  && (pvals->point_idx != 0)
  && (pvals->point_idx != pvals->point_idx_max))
  {
    pvals->point[pvals->point_idx].keyframe = gap_mov_exec_conv_keyframe_to_rel(mgp->keyframe_abs, pvals);
  }
  else
  {
    pvals->point[pvals->point_idx].keyframe  = 0;
  }
}

void
p_update_point_index_text(t_mov_gui_stuff *mgp)
{
  g_snprintf (&mgp->point_index_text[0], POINT_INDEX_LABEL_LENGTH,
              _("Current Point: [ %3d ] of [ %3d ]"),
              pvals->point_idx + 1, pvals->point_idx_max +1);

  if (mgp->point_index_frame)
    {
      gtk_frame_set_label (GTK_FRAME (mgp->point_index_frame),
                          &mgp->point_index_text[0]);
    }
}


/* ============================================================================
 * p_clear_one_point
 *   Init point table with identical 2 Points
 * ============================================================================
 */
void
p_clear_one_point(gint idx)
{
  if((idx >= 0) && (idx <= pvals->point_idx_max))
  {
    pvals->point[idx].opacity  = 100.0; /* 100 percent (no transparecy) */
    pvals->point[idx].w_resize = 100.0; /* 100%  no resizize (1:1) */
    pvals->point[idx].h_resize = 100.0; /* 100%  no resizize (1:1) */
    pvals->point[idx].rotation = 0.0;   /* no rotation (0 degree) */
    /* 1.0 for all perspective transform factors (== no perspective transformation) */
    pvals->point[idx].ttlx      = 1.0;
    pvals->point[idx].ttly      = 1.0;
    pvals->point[idx].ttrx      = 1.0;
    pvals->point[idx].ttry      = 1.0;
    pvals->point[idx].tblx      = 1.0;
    pvals->point[idx].tbly      = 1.0;
    pvals->point[idx].tbrx      = 1.0;
    pvals->point[idx].tbry      = 1.0;
    pvals->point[idx].sel_feather_radius = 0.0;
    pvals->point[idx].keyframe = 0;   /* 0: controlpoint is not fixed to keyframe */
    pvals->point[idx].keyframe_abs = 0;   /* 0: controlpoint is not fixed to keyframe */
  }
}       /* end p_clear_one_point */


/* --------------------------
 * p_mix_one_point
 * --------------------------
 * calculate settings for one point by mixing
 * the settings of 2 reference points.
 * All settings EXCEPT the position are affected
 */
void
p_mix_one_point(gint idx, gint ref1, gint ref2, gdouble mix_factor)
{
#define MIX_VALUE(factor, a, b) ((a * (1.0 - factor)) +  (b * factor))

  if((idx >= 0)
  && (idx <= pvals->point_idx_max)
  && (ref1 >= 0)
  && (ref1 <= pvals->point_idx_max)
  && (ref2 >= 0)
  && (ref2 <= pvals->point_idx_max)
  )
  {
    pvals->point[idx].opacity  = MIX_VALUE(mix_factor, pvals->point[ref1].opacity,   pvals->point[ref2].opacity);
    pvals->point[idx].w_resize = MIX_VALUE(mix_factor, pvals->point[ref1].w_resize,  pvals->point[ref2].w_resize);
    pvals->point[idx].h_resize = MIX_VALUE(mix_factor, pvals->point[ref1].h_resize,  pvals->point[ref2].h_resize);
    pvals->point[idx].rotation = MIX_VALUE(mix_factor, pvals->point[ref1].rotation,  pvals->point[ref2].rotation);

    pvals->point[idx].ttlx      = MIX_VALUE(mix_factor, pvals->point[ref1].ttlx,  pvals->point[ref2].ttlx);
    pvals->point[idx].ttly      = MIX_VALUE(mix_factor, pvals->point[ref1].ttly,  pvals->point[ref2].ttly);
    pvals->point[idx].ttrx      = MIX_VALUE(mix_factor, pvals->point[ref1].ttrx,  pvals->point[ref2].ttrx);
    pvals->point[idx].ttry      = MIX_VALUE(mix_factor, pvals->point[ref1].ttry,  pvals->point[ref2].ttry);
    pvals->point[idx].tblx      = MIX_VALUE(mix_factor, pvals->point[ref1].tblx,  pvals->point[ref2].tblx);
    pvals->point[idx].tbly      = MIX_VALUE(mix_factor, pvals->point[ref1].tbly,  pvals->point[ref2].tbly);
    pvals->point[idx].tbrx      = MIX_VALUE(mix_factor, pvals->point[ref1].tbrx,  pvals->point[ref2].tbrx);
    pvals->point[idx].tbry      = MIX_VALUE(mix_factor, pvals->point[ref1].tbry,  pvals->point[ref2].tbry);

    pvals->point[idx].sel_feather_radius = MIX_VALUE(mix_factor, pvals->point[ref1].sel_feather_radius,  pvals->point[ref2].sel_feather_radius);

    pvals->point[idx].keyframe = 0;   /* 0: controlpoint is not fixed to keyframe */
    pvals->point[idx].keyframe_abs = 0;   /* 0: controlpoint is not fixed to keyframe */
  }
}       /* end p_mix_one_point */


/* ============================================================================
 * p_reset_points
 *   Init point table with identical 2 Points
 * ============================================================================
 */
void p_reset_points()
{
  pvals->point_idx = 0;        /* 0 == current point */
  pvals->point_idx_max = 0;    /* 0 == there is only one valid point */
  p_clear_one_point(0);
  pvals->point[0].p_x = 0;
  pvals->point[0].p_y = 0;
}       /* end p_reset_points */

/* ============================================================================
 * p_load_points
 *   load point table (from named file into global pvals)
 *   (reset points if load failed)
 * ============================================================================
 */

void
p_load_points(char *filename)
{
  gint l_rc;
  gint l_errno;

  l_rc = gap_mov_exec_gap_load_pointfile(filename, pvals);
  l_errno = errno;

  if (l_rc < -1)
  {
    p_reset_points();
  }
  if (l_rc != 0)
  {
    if(l_errno != 0)
    {
      g_message(_("ERROR: Could not open controlpoints\n"
                "filename: '%s'\n%s")
               ,filename, g_strerror (l_errno));
    }
    else
    {
      g_message(_("ERROR: Could not read controlpoints\n"
                "filename: '%s'\n(Is not a valid controlpoint file)")
               ,filename);
    }
  }
}  /* end p_load_points */

/* ============================================================================
 * p_save_points
 *   save point table (from global pvals into named file)
 * ============================================================================
 */
static void
p_save_points(char *filename, t_mov_gui_stuff *mgp)
{
  gint l_rc;
  gint l_errno;
  gboolean l_wr_permission;

  l_wr_permission = gap_arr_overwrite_file_dialog(filename);

  /* quit if MovePath Mainwindow was closed */
  if(mgp->shell == NULL) { gtk_main_quit (); return; }

  if(l_wr_permission)
  {
    l_rc = gap_mov_exec_gap_save_pointfile(filename, pvals);
    l_errno = errno;

    if(l_rc != 0)
    {
        g_message (_("Failed to write controlpointfile\n"
                      "filename: '%s':\n%s"),
                   filename, g_strerror (l_errno));
    }
  }
}       /* end p_save_points */

/* ============================================================================
 * mov_refresh_src_layer_menu
 * ============================================================================
 */
static void
mov_refresh_src_layer_menu(t_mov_gui_stuff *mgp)
{
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (mgp->src_layer_combo),
                              pvals->src_layer_id,                      /* initial value */
                              G_CALLBACK (mov_imglayer_menu_callback),
                              mgp);

}  /* end mov_refresh_src_layer_menu */


/* ============================================================================
 * Create new source selection table Frame, and return it.
 *   A frame that contains:
 *   - 2x2 menus (src_image/layer, handle, stepmode, paintmode)
 * ============================================================================
 */

static GtkWidget *
mov_src_sel_create(t_mov_gui_stuff *mgp)
{
  GtkWidget *table;
  GtkWidget *sub_table;
  GtkWidget *combo;
  GtkWidget *label;
  GtkObject      *adj;


  /* the table */
  table = gtk_table_new (2, 4, FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (table), 2);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);

  /* Source Layer menu */
  label = gtk_label_new( _("Source Image/Layer:"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, 0, 4, 0);
  gtk_widget_show(label);

  combo = gimp_layer_combo_box_new (mov_imglayer_constrain, NULL);
  gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 0, 1,
                   GTK_EXPAND | GTK_FILL, 0, 0, 0);

  gimp_help_set_help_data(combo,
                       _("Source object to insert into destination frames of the specified range")
                       , NULL);

  gtk_widget_show(combo);
  mgp->src_layer_combo = combo;
  mov_refresh_src_layer_menu(mgp);
  gtk_widget_show(combo);


  /* Paintmode combo (menu) */

  label = gtk_label_new( _("Mode:"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0, 1, GTK_FILL, 0, 4, 0);
  gtk_widget_show(label);

  combo = gimp_int_combo_box_new (_("Normal"),         GIMP_NORMAL_MODE,
                                  _("Dissolve"),       GIMP_DISSOLVE_MODE,
                                  _("Multiply"),       GIMP_MULTIPLY_MODE,
                                  _("Divide"),         GIMP_DIVIDE_MODE,
                                  _("Screen"),         GIMP_SCREEN_MODE,
                                  _("Overlay"),        GIMP_OVERLAY_MODE,
                                  _("Dodge"),          GIMP_DODGE_MODE,
                                  _("Burn"),           GIMP_BURN_MODE,
                                  _("Hard Light"),     GIMP_HARDLIGHT_MODE,
                                  _("Soft Light"),     GIMP_SOFTLIGHT_MODE,
                                  _("Grain Extract"),  GIMP_GRAIN_EXTRACT_MODE,
                                  _("Grain Merge"),    GIMP_GRAIN_MERGE_MODE,
                                  _("Difference"),     GIMP_DIFFERENCE_MODE,
                                  _("Addition"),       GIMP_ADDITION_MODE,
                                  _("Subtract"),       GIMP_SUBTRACT_MODE,
                                  _("Darken Only"),    GIMP_DARKEN_ONLY_MODE,
                                  _("Lighten Only"),   GIMP_LIGHTEN_ONLY_MODE,
                                  _("Hue"),            GIMP_HUE_MODE,
                                  _("Saturation"),     GIMP_SATURATION_MODE,
                                  _("Color"),          GIMP_COLOR_MODE,
                                  _("Value"),          GIMP_VALUE_MODE,
                                  _("Keep Paintmode"), GAP_MOV_KEEP_SRC_PAINTMODE,
                                  NULL);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              GIMP_NORMAL_MODE,              /* initial int value */
                              G_CALLBACK (mov_paintmode_menu_callback),
                              mgp);
  gtk_table_attach(GTK_TABLE(table), combo, 3, 4, 0, 1,
                   GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gimp_help_set_help_data(combo,
                       _("Paintmode")
                       , NULL);
  gtk_widget_show(combo);



  /* Loop Stepmode menu (Label) */

  label = gtk_label_new( _("Stepmode:"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, 0, 4, 0);
  gtk_widget_show(label);

  /* the sub_table (1 row) */
  sub_table = gtk_table_new (1, 3, FALSE);
  gtk_widget_show(sub_table);
  gtk_container_set_border_width (GTK_CONTAINER (sub_table), 2);
  gtk_table_set_row_spacings (GTK_TABLE (sub_table), 0);
  gtk_table_set_col_spacings (GTK_TABLE (sub_table), 2);

  gtk_table_attach(GTK_TABLE(table), sub_table, 1, 2, 1, 2,
                   GTK_EXPAND | GTK_FILL, 0, 0, 0);



  /* StepSpeedFactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (sub_table), 1, 0,    /* table col, row */
                          _("SpeedFactor:"),                  /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)pvals->step_speed_factor,  /* initial value */
                          (gdouble)0.0, (gdouble)50.0,        /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0.0, (gdouble)50.0,        /* lower, upper (unconstrained) */
                          _("Source and target frames step synchronized at value 1.0. "
                            "A value of 0.5 will step the source half time slower. "
                            "One source step is done only at every 2nd target frame."),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_double_adjustment_update),
                    &pvals->step_speed_factor);
  mgp->step_speed_factor_adj = GTK_ADJUSTMENT(adj);



  /* Loop Stepmode combo  */
  combo = gimp_int_combo_box_new (_("Loop"),                 GAP_STEP_LOOP,
                                  _("Loop Reverse"),         GAP_STEP_LOOP_REV,
                                  _("Once"),                 GAP_STEP_ONCE,
                                  _("Once Reverse"),         GAP_STEP_ONCE_REV,
                                  _("Ping Pong"),            GAP_STEP_PING_PONG,
                                  _("None"),                 GAP_STEP_NONE,
                                  _("Frame Loop"),           GAP_STEP_FRAME_LOOP,
                                  _("Frame Loop Reverse"),   GAP_STEP_FRAME_LOOP_REV,
                                  _("Frame Once"),           GAP_STEP_FRAME_ONCE,
                                  _("Frame Once Reverse"),   GAP_STEP_FRAME_ONCE_REV,
                                  _("Frame Ping Pong"),      GAP_STEP_FRAME_PING_PONG,
                                  _("Frame None"),           GAP_STEP_FRAME_NONE,
                                  NULL);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              GAP_STEP_LOOP,              /* initial int value */
                              G_CALLBACK (mov_stepmode_menu_callback),
                              mgp);

  gtk_table_attach(GTK_TABLE(sub_table), combo, 0, 1, 0, 1,
                   GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gimp_help_set_help_data(combo,
                       _("How to fetch the next source layer at the next handled frame")
                       , NULL);
  gtk_widget_show(combo);


  /* Source Image Handle menu */

  label = gtk_label_new( _("Handle:"));
  gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
  gtk_table_attach(GTK_TABLE(table), label, 2, 3, 1, 2, GTK_FILL, 0, 4, 0);
  gtk_widget_show(label);

  combo = gimp_int_combo_box_new (_("Left  Top"),     GAP_HANDLE_LEFT_TOP,
                                  _("Left  Bottom"),  GAP_HANDLE_LEFT_BOT,
                                  _("Right Top"),     GAP_HANDLE_RIGHT_TOP,
                                  _("Right Bottom"),  GAP_HANDLE_RIGHT_BOT,
                                  _("Center"),        GAP_HANDLE_CENTER,
                                  NULL);

  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              GAP_HANDLE_LEFT_TOP,              /* initial int value */
                              G_CALLBACK (mov_handmode_menu_callback),
                              mgp);


  gtk_table_attach(GTK_TABLE(table), combo, 3, 4, 1, 2,
                   GTK_EXPAND | GTK_FILL, 0, 0, 0);
  gimp_help_set_help_data(combo,
                       _("How to place the Source layer at controlpoint coordinates")
                       , NULL);
  gtk_widget_show(combo);

  gtk_widget_show( table );

  return table;
}       /* end mov_src_sel_create */


/* ============================================================================
 * Create set of widgets for the advanced Move Path features
 *   A frame that contains:
 *   in the 1.st row
 *   - 3x spionbutton  for tween_steps, tween_opacity_init, tween_opacity_desc
 *   in the 2.nd row
 *   - checkbutton  make_tracelayer
 *   - 2x spinbutton   for trace_opacity_initial, trace_opacity_desc
 * ============================================================================
 */

static GtkWidget *
mov_advanced_tab_create(t_mov_gui_stuff *mgp)
{
  GtkWidget      *table;
  GtkWidget      *check_button;
  GtkObject      *adj;
  guint          row;
  guint          col;


  /* the table (2 rows) */
  table = gtk_table_new (2, 8, FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (table), 2);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);


  row = 0;
  col = 0;

  /* the bluebox widgets */
  {
    GtkWidget    *check_button;
    GtkWidget    *label;
    GtkWidget    *color_button;

    /* toggle bluebox */
    check_button = gtk_check_button_new_with_label ( _("Bluebox"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                  pvals->src_apply_bluebox);
    gimp_help_set_help_data(check_button,
                         _("Apply the bluebox filter on the moving object(s). "
                           "The bluebox filter makes the keycolor transparent.")
                         , NULL);
    gtk_widget_show (check_button);
    gtk_table_attach(GTK_TABLE(table), check_button, col, col+1, row, row+1
                  ,0 , 0, 0, 0);
    g_object_set_data(G_OBJECT(check_button), "mgp", mgp);
    g_signal_connect (G_OBJECT (check_button), "toggled",
                      G_CALLBACK  (mov_bluebox_callback),
                      &pvals->src_apply_bluebox);

    /* keycolor label */
    label = gtk_label_new( _("Keycolor:"));
    gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
    gtk_table_attach(GTK_TABLE(table), label, col, col+1, row+1, row+2
                    , 0, 0, 0, 0);
    gtk_widget_show(label);

    if(pvals->bbp_pv == NULL)
    {
      pvals->bbp_pv = gap_bluebox_bbp_new(-1);
    }

    /* keycolor button */
    color_button = gimp_color_button_new (_("Move Path Bluebox Keycolor"),
                                  25, 12,                     /* WIDTH, HEIGHT, */
                                  &pvals->bbp_pv->vals.keycolor,
                                  GIMP_COLOR_AREA_FLAT);

    /* dont know if it is possible to remove the signal handler for the "clicked" signal
     * on the gimp_color_button.
     * WORKAROUND:
     *   destroy the unwanted standard dialog in my private handler
     *   mov_path_keycolorbutton_clicked
     */

    gtk_table_attach(GTK_TABLE(table), color_button, col+1, col+2, row+1, row+2
                    , 0, 0, 0, 0);
    gtk_widget_show (color_button);
    gimp_help_set_help_data(color_button,
                         _("Open dialog window to set "
                           "parameters and keycolor for the bluebox filter")
                         , NULL);

    g_signal_connect (color_button, "clicked",
                    G_CALLBACK (mov_path_keycolorbutton_clicked),
                    mgp);

    g_signal_connect (color_button, "color_changed",
                    G_CALLBACK (mov_path_keycolorbutton_changed),
                    mgp);

  }

  row = 0;
  col = 2;

  /* toggle Tracelayer */
  check_button = gtk_check_button_new_with_label ( _("Tracelayer"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                  pvals->tracelayer_enable);
  gimp_help_set_help_data(check_button,
                         _("Create an additional trace layer in all handled frames")
                         , NULL);
  gtk_widget_show (check_button);
  gtk_table_attach(GTK_TABLE(table), check_button, col, col+1, row, row+1
                  ,0 , 0, 0, 0);
  g_object_set_data(G_OBJECT(check_button), "mgp", mgp);
  g_signal_connect (G_OBJECT (check_button), "toggled",
                      G_CALLBACK  (mov_tracelayer_callback),
                      &pvals->tracelayer_enable);

  /* TraceOpacityInitial */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), col+2, row,    /* table col, row */
                          _("TraceOpacity1:"),                  /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->trace_opacity_initial,  /* initial value */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper */
                          1, 10,                                /* step, page */
                          1,                                    /* digits */
                          FALSE,                                /* constrain */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper (unconstrained) */
                          _("Initial opacity of the trace layer"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_double_adjustment_update),
                    &pvals->trace_opacity_initial);
  mgp->trace_opacity_initial_adj = GTK_ADJUSTMENT(adj);


  /* TraceOpacityDescending */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), col+4, row,    /* table col, row */
                          _("TraceOpacity2:"),                  /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->trace_opacity_desc,     /* initial value */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper */
                          1, 10,                                /* step, page */
                          1,                                    /* digits */
                          FALSE,                                /* constrain */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper (unconstrained) */
                          _("Descending opacity of the trace layer"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_double_adjustment_update),
                    &pvals->trace_opacity_desc);
  mgp->trace_opacity_desc_adj = GTK_ADJUSTMENT(adj);

  row = 1;
  col = 2;

  /* TweenSteps */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), col, row,      /* table col, row */
                          _("Tweensteps:"),                     /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->tween_steps,          /* initial value */
                          (gdouble)0, (gdouble)50,              /* lower, upper */
                          1, 2,                                 /* step, page */
                          0,                                    /* digits */
                          FALSE,                                /* constrain */
                          (gdouble)0, (gdouble)50,              /* lower, upper (unconstrained) */
                          _("Calculate n steps between 2 frames. "
                            "The rendered tween steps are collected in a tween layer "
                            "that will be added to the handled destination frames. "
                            "If the tween step value is 0, no tweens are calculated "
                            "and no tween layers are created"),
                          NULL);    /* tooltip privatetip */
  mgp->tween_steps_adj = GTK_ADJUSTMENT(adj);
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tween_steps_adjustment_update),
                    &pvals->tween_steps);


  /* TweenOpacityInitial */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), col+2, row,    /* table col, row */
                          _("TweenOpacity1:"),                  /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->tween_opacity_initial,  /* initial value */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper */
                          1, 10,                                /* step, page */
                          1,                                    /* digits */
                          FALSE,                                /* constrain */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper (unconstrained) */
                          _("Initial opacity of the tween layer"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_double_adjustment_update),
                    &pvals->tween_opacity_initial);
  mgp->tween_opacity_initial_adj = GTK_ADJUSTMENT(adj);

  /* TweenOpacityDescending */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), col+4, row,    /* table col, row */
                          _("TweenOpacity2:"),                  /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->tween_opacity_desc,   /* initial value */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper */
                          1, 10,                                /* step, page */
                          1,                                    /* digits */
                          FALSE,                                /* constrain */
                          (gdouble)0.0, (gdouble)100,           /* lower, upper (unconstrained) */
                          _("Descending opacity of the tween layer"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_double_adjustment_update),
                    &pvals->tween_opacity_desc);
  mgp->tween_opacity_desc_adj = GTK_ADJUSTMENT(adj);

  /* set initial sensitivity */
  mov_tweenlayer_sensitivity(mgp);
  mov_tracelayer_sensitivity(mgp);

  gtk_widget_show( table );

  return table;
}       /* end mov_advanced_tab_create */

/* ============================================================================
 * Create new EditCtrlPoint Frame
 * ============================================================================
 */
static GtkWidget *
mov_edit_button_box_create (t_mov_gui_stuff *mgp)
{
  GtkWidget      *vbox;
  GtkWidget      *hbox;
  GtkWidget      *frame;
  GtkWidget      *button_table;
  GtkWidget      *button;
  gint           row;

  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 3);
  gtk_widget_show (vbox);

  /* the frame */
  frame = gimp_frame_new (_("Edit Controlpoints"));
  gtk_container_set_border_width( GTK_CONTAINER( frame ), 2 );


  /* button_table 7 rows */
  button_table = gtk_table_new (7, 2, TRUE);
  gtk_table_set_row_spacings (GTK_TABLE (button_table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (button_table), 2);
  gtk_widget_show (button_table);

  row = 0;

  /* Add Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_ADD_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Add controlpoint at end. The last controlpoint is duplicated.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK  (mov_padd_callback),
                    mgp);

  /* Grab Path (Controlpoints from current GIMP Path)  */
  button = gtk_button_new_from_stock ( GAP_STOCK_GRAB_POINTS );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Delete all controlpoints, and replace them with "
                         "a copy of all anchorpoints of the current path "
                         "from the image from which 'MovePath' was invoked. "
                         "Hold down the Shift key to create controlpoints for each handled frame, "
                         "following the Bezier path.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK  (mov_pgrab_callback),
                    mgp);

  row++;

  /* Insert Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_INSERT_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Insert controlpoint. The current controlpoint is duplicated.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_pins_callback),
                    mgp);

  /* Delete Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_DELETE_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Delete current controlpoint")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_pdel_callback),
                    mgp);

  row++;

  /* Previous Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_PREV_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Show previous controlpoint. Hold down the shift key to follow keyframes.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (mov_pprev_callback),
                    mgp);

  /* Next Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_NEXT_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Show next controlpoint. Hold down the shift key to follow keyframes.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (mov_pnext_callback),
                    mgp);

  row++;

  /* First Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_FIRST_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Show first controlpoint. Hold down the shift key to follow keyframes.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (mov_pfirst_callback),
                    mgp);

  /* Last Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_LAST_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Show last controlpoint. Hold down the shift key to follow keyframes.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (mov_plast_callback),
                    mgp);

  row++;

  /* Reset Controlpoint */
  button = gtk_button_new_from_stock ( GAP_STOCK_RESET_POINT );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Reset the current controlpoint to default values")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_pclr_callback),
                    mgp);

  /* Reset All Controlpoints */
  button = gtk_button_new_from_stock ( GAP_STOCK_RESET_ALL_POINTS );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Reset all controlpoints to default values "
                         "but dont change the path (X/Y values). "
                         "Hold down the shift key to copy settings "
                         "of point1 into all other points. "
                         "Holding down the ctrl key spreads a mix of "
                         "the settings of point1 and the last point "
                         "into the other points inbetween.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (mov_pclr_all_callback),
                    mgp);

  row++;

  /* Rotate Follow */
  button = gtk_button_new_from_stock ( GAP_STOCK_ROTATE_FOLLOW );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Set rotation for all controlpoints "
                         "to follow the shape of the path. "
                         "Hold down the shift key to use rotation of contolpoint 1 as offset.")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "button_press_event",
                    G_CALLBACK (mov_prot_follow_callback),
                    mgp);

  /* Delete All Controlpoints */
  button = gtk_button_new_from_stock ( GAP_STOCK_DELETE_ALL_POINTS );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Delete all controlpoints")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_pdel_all_callback),
                    mgp);


  row++;

  /* Load Controlpoints */
  button = gtk_button_new_from_stock (GTK_STOCK_OPEN );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 0, 1, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Load controlpoints from file")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_pload_callback),
                    mgp);

  /* Save Controlpoints */
  button = gtk_button_new_from_stock ( GTK_STOCK_SAVE );
  GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
  gtk_table_attach( GTK_TABLE(button_table), button, 1, 2, row, row+1,
                    GTK_FILL, 0, 0, 0 );
  gimp_help_set_help_data(button,
                       _("Save controlpoints to file")
                       , NULL);
  gtk_widget_show (button);
  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (mov_psave_callback),
                    mgp);

  row++;

  gtk_widget_show(button_table);
  gtk_widget_show(frame);

  /* the hbox */
  hbox = gtk_hbox_new (FALSE, 3);
  gtk_widget_show (hbox);

  gtk_box_pack_start (GTK_BOX (hbox), button_table, FALSE, FALSE, 4);
  gtk_container_add (GTK_CONTAINER (frame), hbox);

  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 4);
  return vbox;
}  /* end mov_edit_button_box_create */

/* ============================================================================
 * Create set of widgets for the framerange and layerstack widgets
 * ============================================================================
 * vertical_layout == FALSE
 *   +-master_table-------------------------+----------------------+
 *   |  +-----------+--------+------------+ | +-vcbox-----------+  |
 *   |  | FromFrame | scale  | spinbutton | | |                 |  |
 *   |  +-----------+--------+------------+ | | ForceVisibility |  |
 *   |  | ToFrame   | scale  | spinbutton | | |                 |  |
 *   |  +-----------+--------+------------+ | | Clip To Frame   |  |
 *   |  | Layerstack| scale  | spinbutton | | |                 |  |
 *   |  +-----------+--------+------------+ | +-----------------+  |
 *   +--------------------------------------+----------------------+
 *
 * vertical_layout == TRUE
 *
 *   +-master_table-------------------------+
 *   |  +-vcbox---------------------------+ |
 *   |  | ForceVisibility                 | |
 *   |  | Clip To Frame                   | |
 *   |  +---------------------------------+ |
 *   +--------------------------------------+
 *   |  +-----------+--------+------------+ +
 *   |  | FromFrame | scale  | spinbutton | |
 *   |  +-----------+--------+------------+ |
 *   |  | ToFrame   | scale  | spinbutton | |
 *   |  +-----------+--------+------------+ |
 *   |  | Layerstack| scale  | spinbutton | |
 *   |  +-----------+--------+------------+ |
 *   +--------------------------------------+
 */
GtkWidget *
mov_path_framerange_box_create(t_mov_gui_stuff *mgp
                              ,gboolean vertical_layout
                              )
{
  GtkWidget *vcbox;
  GtkWidget *master_table;
  GtkWidget *table;
  GtkObject *adj;
  GtkWidget *check_button;
  gint  master_rows;
  gint  master_cols;
  gint  tabcol, tabrow, boxcol, boxrow;

  if(vertical_layout)
  {
    master_rows = 2;
    master_cols = 1;
    tabcol = 0;
    tabrow = 1;
    boxcol = 0;
    boxrow = 0;
  }
  else
  {
    master_rows = 1;
    master_cols = 2;
    tabcol = 0;
    tabrow = 0;
    boxcol = 1;
    boxrow = 0;
  }

  /* the master_table (1 row) */
  master_table = gtk_table_new (master_rows, master_cols, FALSE);
  gtk_widget_show (master_table);

  /* table with 3 rows */
  table = gtk_table_new (3, 3, FALSE);
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_table_attach(GTK_TABLE(master_table), table, tabcol, tabcol+1, tabrow, tabrow+1
                  , GTK_FILL|GTK_EXPAND, GTK_FILL, 4, 0);
  gtk_widget_show (table);

  /* the start frame scale_entry */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 0, 0,          /* table col, row */
                          _("From Frame:"),                     /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->dst_range_start,      /* value */
                          (gdouble)mgp->first_nr,               /* lower */
                          (gdouble)mgp->last_nr,                /* upper */
                          1, 10,                                /* step, page */
                          0,                                    /* digits */
                          TRUE,                                 /* constrain */
                          (gdouble)mgp->first_nr,               /* lower, (unconstrained) */
                          (gdouble)mgp->last_nr,                /* upper (unconstrained) */
                          _("First handled destination frame"), NULL);      /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_int_adjustment_update),
                    &pvals->dst_range_start);

  /* the end frame scale_entry */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 0, 1,          /* table col, row */
                          _("To Frame:"),                       /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->dst_range_end,        /* value */
                          (gdouble)mgp->first_nr,               /* lower */
                          (gdouble)mgp->last_nr,                /* upper */
                          1, 10,                                /* step, page */
                          0,                                    /* digits */
                          TRUE,                                 /* constrain */
                          (gdouble)mgp->first_nr,               /* lower, (unconstrained) */
                          (gdouble)mgp->last_nr,                /* upper (unconstrained) */
                          _("Last handled destination frame"), NULL);       /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_int_adjustment_update),
                    &pvals->dst_range_end);

  /* the Layerstack scale_entry */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 0, 2,          /* table col, row */
                          _("Layerstack:"),                     /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)pvals->dst_layerstack,       /* value */
                          0.0, 99.0,                            /* lower, upper */
                          1, 10,                                /* step, page */
                          0,                                    /* digits */
                          FALSE,                                /* constrain */
                          0.0, 999999.0,                        /* lower, upper (unconstrained) */
                          _("How to insert source layer into the "
                            "layerstack of the destination frames. "
                            "layerstack 0 means on top i.e. in front"),
                          NULL);                              /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_instant_int_adjustment_update),
                    &pvals->dst_layerstack);

  /* the vbox for checkbuttons */
  vcbox = gtk_vbox_new (FALSE, 3);
  gtk_widget_show (vcbox);


  /* toggle force visibility  */
  check_button = gtk_check_button_new_with_label ( _("Force Visibility"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                pvals->src_force_visible);
  gimp_help_set_help_data(check_button,
                       _("Force visibility for all copied source layers")
                       , NULL);
  gtk_widget_show (check_button);
  g_object_set_data(G_OBJECT(check_button), "mgp", mgp);
  g_signal_connect (G_OBJECT (check_button), "toggled",
                    G_CALLBACK  (mov_force_visibility_toggle_callback),
                    &pvals->src_force_visible);
  gtk_box_pack_start (GTK_BOX (vcbox), check_button, TRUE, TRUE, 0);

  /* toggle clip_to_image */
  check_button = gtk_check_button_new_with_label ( _("Clip To Frame"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                pvals->clip_to_img);
  gimp_help_set_help_data(check_button,
                       _("Clip all copied source layers at destination frame boundaries")
                       , NULL);
  gtk_widget_show (check_button);
  g_signal_connect (G_OBJECT (check_button), "toggled",
                    G_CALLBACK (mov_gint_toggle_callback),
                    &pvals->clip_to_img);
  gtk_box_pack_start (GTK_BOX (vcbox), check_button, TRUE, TRUE, 0);

  gtk_table_attach(GTK_TABLE(master_table), vcbox, boxcol, boxcol+1, boxrow, boxrow+1
                  , GTK_FILL, GTK_FILL, 4, 0);

  return(master_table);
}  /* end mov_path_framerange_box_create */



/* ============================================================================
 * Create  VBox with
 *   The VBox contains
 *   - Resize    2x spinbutton   (for resizing Width + Height in percent)
 *                  chainbutton  (for constrain both resize widgets)
 *   - Opacity      spinbutton   (0.0 upto 100.0 %)
 *   - Rotation     spinbutton   (-360.0 to 360.0 degrees)
 * ============================================================================
 */
static GtkWidget*
mov_modify_tab_create(t_mov_gui_stuff *mgp)
{
  GtkWidget      *vbox;
  GtkWidget      *table;
  GtkObject      *adj;

  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 3);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);

  /* the table (2 rows) */
  table = gtk_table_new ( 2, 6, FALSE );
  gtk_container_set_border_width (GTK_CONTAINER (table), 2 );
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);


  /* Width Scale */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 0, 0,        /* table col, row */
                          _("Width:"),                        /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->w_resize,             /* value */
                          (gdouble)1, (gdouble)200,           /* lower, upper */
                          1, 10,                              /* step, page */
                          1,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)1, (gdouble)1000,          /* lower, upper (unconstrained) */
                          _("Scale source layer's width in percent"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_resize_adjustment_update),
                    &mgp->w_resize);
  mgp->wres_adj = GTK_ADJUSTMENT(adj);

  /* Height Scale */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 0, 1,        /* table col, row */
                          _("Height:"),                       /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->h_resize,             /* value */
                          (gdouble)1, (gdouble)200,           /* lower, upper */
                          1, 10,                              /* step, page */
                          1,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)1, (gdouble)1000,          /* lower, upper (unconstrained) */
                          _("Scale source layer's height in percent"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_resize_adjustment_update),
                    &mgp->h_resize);
  mgp->hres_adj = GTK_ADJUSTMENT(adj);


  /*  the constrain ratio chainbutton  */
  mgp->constrain = gimp_chain_button_new (GIMP_CHAIN_RIGHT);
  gimp_chain_button_set_active (GIMP_CHAIN_BUTTON (mgp->constrain), TRUE);
  gtk_table_attach (GTK_TABLE (table), mgp->constrain, 2, 3, 0, 2
                   , 0,0,0,0);
  gtk_widget_show (mgp->constrain);

  gimp_help_set_help_data (GIMP_CHAIN_BUTTON (mgp->constrain)->button,
                           _("Constrain aspect ratio"), NULL);

  /* the state of the contrain ratio chainbutton is checked in other callbacks (where needed)
   * there is no need for the chainbutton to have its own callback procedure
   */


  /* Opacity */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 3, 0,        /* table col, row */
                          _("Opacity:"),                      /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->opacity,              /* value */
                          (gdouble)0, (gdouble)100,           /* lower, upper */
                          1, 10,                              /* step, page */
                          1,                                  /* digits */
                          TRUE,                               /* constrain */
                          (gdouble)0, (gdouble)100,           /* lower, upper (unconstrained) */
                          _("Set the source layer's opacity in percent"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_instant_double_adjustment_update),
                    &mgp->opacity);
  mgp->opacity_adj = GTK_ADJUSTMENT(adj);

  /* Rotation */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 3, 1,        /* table col, row */
                          _("Rotate:"),                       /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->rotation,             /* value */
                          (gdouble)-360, (gdouble)360,        /* lower, upper */
                          1, 45,                              /* step, page */
                          1,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)-3600, (gdouble)3600,      /* lower, upper (unconstrained) */
                          _("Rotate source layer (in degrees)"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_instant_double_adjustment_update),
                    &mgp->rotation);
  mgp->rotation_adj = GTK_ADJUSTMENT(adj);


  gtk_widget_show (table);
  gtk_widget_show (vbox);

  /* copile without MOVE_PATH_LAYOUT_frame needs less space */
  return vbox;

}  /* end mov_modify_tab_create */


/* ============================================================================
 * Create  VBox with the 8 transformation factors and return it.
 *   The VBox contains
 *   - Transform 8x spinbutton   (0.01 upto 10.0) 4-point perspective transformation
 * ============================================================================
 */
static GtkWidget *
mov_trans_tab_create (t_mov_gui_stuff *mgp)
{
  GtkWidget      *vbox;
  GtkWidget      *table;
  GtkObject      *adj;


  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 3);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);

  /* the table (2 rows) */
  table = gtk_table_new ( 2, 8, FALSE );
  gtk_container_set_border_width (GTK_CONTAINER (table), 2 );
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);


  /* ttlx transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 0, 0,        /* table col, row */
                          _("x1:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->ttlx,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for upper left corner X coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->ttlx);
  mgp->ttlx_adj = GTK_ADJUSTMENT(adj);


  /* ttly transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 2, 0,        /* table col, row */
                          _("y1:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->ttly,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for upper left corner Y coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->ttly);
  mgp->ttly_adj = GTK_ADJUSTMENT(adj);


  /* ttrx transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 4, 0,        /* table col, row */
                          _("x2:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->ttrx,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for upper right corner X coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->ttrx);
  mgp->ttrx_adj = GTK_ADJUSTMENT(adj);

  /* ttry transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 6, 0,        /* table col, row */
                          _("y2:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->ttry,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for upper right corner Y coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->ttry);
  mgp->ttry_adj = GTK_ADJUSTMENT(adj);

  /* tblx transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 0, 1,        /* table col, row */
                          _("x3:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->tblx,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for lower left corner X coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->tblx);
  mgp->tblx_adj = GTK_ADJUSTMENT(adj);

  /* tbly transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 2, 1,        /* table col, row */
                          _("y3:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->tbly,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for lower left corner Y coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->tbly);
  mgp->tbly_adj = GTK_ADJUSTMENT(adj);

  /* tbrx transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 4, 1,        /* table col, row */
                          _("x4:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->tbrx,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for lower right corner X coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->tbrx);
  mgp->tbrx_adj = GTK_ADJUSTMENT(adj);

  /* tbry transformfactor */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 6, 1,        /* table col, row */
                          _("y4:"),                           /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->tbry,                 /* initial value */
                          (gdouble)0, (gdouble)10,            /* lower, upper */
                          0.1, 1,                             /* step, page */
                          3,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)10,            /* lower, upper (unconstrained) */
                          _("Transformfactor for lower right corner Y coordinate"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_tfactor_adjustment_update),
                    &mgp->tbry);
  mgp->tbry_adj = GTK_ADJUSTMENT(adj);

  gtk_widget_show(table);
  gtk_widget_show(vbox);

  return vbox;
}  /* end mov_trans_tab_create */


/* ============================================================================
 * Create  VBox with the selection handling widgets and return it.
 * ============================================================================
 */
static GtkWidget *
mov_selection_handling_tab_create (t_mov_gui_stuff *mgp)
{
  GtkWidget      *combo;
  GtkWidget      *vbox;
  GtkWidget      *table;
  GtkObject      *adj;

  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 3);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);

  /* the table (2 rows) */
  table = gtk_table_new ( 2, 3, FALSE );
  gtk_container_set_border_width (GTK_CONTAINER (table), 2 );
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_box_pack_start (GTK_BOX (vbox), table, TRUE, TRUE, 0);

  /* Selection combo */
  combo = gimp_int_combo_box_new (_("Ignore selection (in all source images)"),    GAP_MOV_SEL_IGNORE,
                                  _("Use selection (from initial source image)"),  GAP_MOV_SEL_INITIAL,
                                  _("Use selections (from all source images)"),    GAP_MOV_SEL_FRAME_SPECIFIC,
                                  NULL);
  gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
                              GAP_MOV_SEL_IGNORE,              /* initial int value */
                              G_CALLBACK (mov_selmode_menu_callback),
                              mgp);
  gtk_table_attach(GTK_TABLE(table), combo, 0, 3, 0, 1,
                   0, 0, 0, 0);
  gimp_help_set_help_data(combo,
                       _("How to handle selections in the source image")
                       , NULL);
  gtk_widget_show(combo);

  /* ttlx transformfactor */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 0, 1,        /* table col, row */
                          _("Selection Feather Radius:"),     /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,           /* scalesize spinsize */
                          (gdouble)mgp->sel_feather_radius,   /* initial value */
                          (gdouble)0, (gdouble)100,           /* lower, upper */
                          1.0, 10.0,                          /* step, page */
                          1,                                  /* digits */
                          FALSE,                              /* constrain */
                          (gdouble)0, (gdouble)1000,          /* lower, upper (unconstrained) */
                          _("Feather radius in pixels (for smoothing selection(s))"),
                          NULL);    /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_feather_adjustment_update),
                    &mgp->sel_feather_radius);
  mgp->sel_feather_radius_adj = GTK_ADJUSTMENT(adj);

  /* for initial sensitivity */
  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), pvals->src_selmode);


  gtk_widget_show(table);
  gtk_widget_show(vbox);

  return vbox;
}  /* end mov_selection_handling_tab_create */

/* ============================================================================
 * Create all Widget Blocks that represent
 *   - The current contolpoint settings
 *   - The Preview
 *   - The Buttonbox for Editing Controlpoints
 *   and attach those Blocks to the mgp->master_vbox Widget.
 *
 *   One "ControlPoint" has:
 *   - 2 spinbuttons X/Y, used for positioning
 *   - Keyframe     spinbutton integer (0 to max_frame)
 *   - Notebook  with following sub tables:
 *      - transform SubTable  4-point perspective transformation
 *      - modify    SubTable  for Resize(Scaling), Opacity and Rotation
 * ============================================================================
 */
static void
mov_path_prevw_create ( GimpDrawable *drawable, t_mov_gui_stuff *mgp, gboolean vertical_layout)
{
  GtkWidget      *cpt_frame;
  GtkWidget      *pv_frame;
  GtkWidget      *wrap_box;
  GtkWidget      *vbox;
  GtkWidget      *hbox;
  GtkWidget      *notebook;
  GtkWidget      *table;
  GtkWidget      *label;
  GtkWidget      *aspect_frame;
  GtkWidget      *da_widget;
  GtkWidget      *pv_table;
  GtkWidget      *pv_sub_table;
  GtkWidget      *check_button;
  GtkObject      *adj;
  GtkWidget      *framerange_table;
  GtkWidget      *edit_buttons;

  mgp->drawable = drawable;
  mgp->dwidth   = gimp_drawable_width(drawable->drawable_id );
  mgp->dheight  = gimp_drawable_height(drawable->drawable_id );
  mgp->bpp      = gimp_drawable_bpp(drawable->drawable_id);
  if ( gimp_drawable_has_alpha(drawable->drawable_id) )
    mgp->bpp--;
  mgp->curx = 0;
  mgp->cury = 0;
  mgp->in_call = TRUE;  /* to avoid side effects while initialization */


  /* the vbox */
  vbox = gtk_vbox_new (FALSE, 3);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 2);
  gtk_widget_show (vbox);
  gtk_box_pack_start (GTK_BOX (mgp->master_vbox), vbox, TRUE, TRUE, 0);

  /* the cpt_frame */
  cpt_frame = gimp_frame_new (" ");  /* text "Current Point: [ %3d ] of [ %3d ]"
                                 * is set later in procedure p_update_point_index_text
                                 */
  gtk_container_set_border_width( GTK_CONTAINER( cpt_frame ), 2 );
  mgp->point_index_frame = cpt_frame;
  p_update_point_index_text(mgp);

  gtk_box_pack_start (GTK_BOX (vbox), cpt_frame, FALSE, FALSE, 0);
  gtk_widget_show( mgp->master_vbox );
  gtk_widget_show( cpt_frame );



  /* the table (3 rows) for other controlpoint specific settings */
  table = gtk_table_new ( 3, 4, FALSE );
  gtk_container_set_border_width (GTK_CONTAINER (table), 2 );
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (table), 4);
  gtk_container_add (GTK_CONTAINER (cpt_frame), table);


  /* X */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 0, 0,            /* table col, row */
                          _("X:"),                                /* label text */
                          SCALE_WIDTH, SPINBUTTON_WIDTH,          /* scalesize spinsize */
                          (gdouble)mgp->p_x,                      /* value */
                          (gdouble)0, (gdouble)mgp->dwidth,       /* lower, upper */
                          1, 10,                                  /* step, page */
                          0,                                      /* digits */
                          FALSE,                                  /* constrain */
                          (gdouble)(-GIMP_MAX_IMAGE_SIZE),
                          (gdouble)GIMP_MAX_IMAGE_SIZE,           /* lower, upper (unconstrained) */
                          _("X coordinate"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_x_adjustment_update),
                    mgp);
  mgp->x_adj = GTK_ADJUSTMENT(adj);

  /* Y */
  adj = gimp_scale_entry_new( GTK_TABLE (table), 0, 1,            /* table col, row */
                          _("Y:"),                                /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,               /* scalesize spinsize */
                          (gdouble)mgp->p_y,                      /* value */
                          (gdouble)0, (gdouble)mgp->dheight,      /* lower, upper */
                          1, 10,                                  /* step, page */
                          0,                                      /* digits */
                          FALSE,                                  /* constrain */
                          (gdouble)(-GIMP_MAX_IMAGE_SIZE),
                          (gdouble)GIMP_MAX_IMAGE_SIZE,           /* lower, upper (unconstrained) */
                          _("Y coordinate"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_path_y_adjustment_update),
                    mgp);
  mgp->y_adj = GTK_ADJUSTMENT(adj);

  /* Keyframe */
  adj = p_mov_spinbutton_new( GTK_TABLE (table), 1, 2,          /* table col, row */
                          _("Keyframe:"),                       /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)mgp->keyframe_abs,           /* value */
                          (gdouble)0, (gdouble)mgp->max_frame,  /* lower, upper */
                          1, 10,                                /* step, page */
                          0,                                    /* digits */
                          TRUE,                                 /* constrain */
                          (gdouble)0, (gdouble)mgp->max_frame,  /* lower, upper (unconstrained) */
                          _("Fix controlpoint to keyframe number where 0 == no keyframe"),
                          NULL);    /* tooltip privatetip */
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (gimp_int_adjustment_update),
                    &mgp->keyframe_abs);
  mgp->keyframe_adj = GTK_ADJUSTMENT(adj);


  /* the notebook */
  notebook = gtk_notebook_new();

  {
    GtkWidget *modify_table;
    GtkWidget *transform_table;
    GtkWidget *selhandling_table;

    /* set of modifier widgets for the current controlpoint */
    modify_table = mov_modify_tab_create(mgp);

    /* set of perspective transformation widgets for the current controlpoint */
    transform_table = mov_trans_tab_create(mgp);

    /* set of perspective transformation widgets for the current controlpoint */
    selhandling_table = mov_selection_handling_tab_create(mgp);

    gtk_container_add (GTK_CONTAINER (notebook), modify_table);
    label = gtk_label_new(_("Scale and Modify"));
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 0)
                             , label
                             );
    gtk_container_add (GTK_CONTAINER (notebook), transform_table);
    label = gtk_label_new(_("Perspective"));
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 1)
                             , label
                             );

    gtk_container_add (GTK_CONTAINER (notebook), selhandling_table);
    label = gtk_label_new(_("Selection Handling"));
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (notebook)
                             , gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), 2)
                             , label
                             );
  }
  gtk_table_attach(GTK_TABLE(table), notebook, 3, 4          /* column */
                                             , 0, 3          /* all rows */
                                             , 0, 0, 0, 0);

  gtk_widget_show (notebook);
  gtk_widget_show( table );



  /* the hbox (for preview table and Edit Controlpoint Frame) */
  hbox = gtk_hbox_new (FALSE, 3);
  gtk_widget_show (hbox);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);

  /* the preview frame */
  pv_frame = gimp_frame_new ( _("Preview"));
  gtk_container_set_border_width (GTK_CONTAINER (pv_frame), 2);
  gtk_box_pack_start (GTK_BOX (hbox), pv_frame, TRUE, TRUE, 0);
  gtk_widget_show (pv_frame);

  /* the preview table (3 rows) */
  pv_table = gtk_table_new ( 3, 1, FALSE );
  gtk_container_set_border_width (GTK_CONTAINER (pv_table), 2 );
  gtk_table_set_row_spacings (GTK_TABLE (pv_table), 2);
  gtk_table_set_col_spacings (GTK_TABLE (pv_table), 4);
  gtk_container_add (GTK_CONTAINER (pv_frame), pv_table);
  gtk_widget_show( pv_table );


  /*
   * Resize the greater one of dwidth and dheight to PREVIEW_SIZE
   */
  if ( mgp->dwidth > mgp->dheight )
  {
    mgp->pheight = mgp->dheight * PREVIEW_SIZE / mgp->dwidth;
    mgp->pheight = MAX (1, mgp->pheight);
    mgp->pwidth  = PREVIEW_SIZE;
  }
  else
  {
    mgp->pwidth  = mgp->dwidth * PREVIEW_SIZE / mgp->dheight;
    mgp->pwidth  = MAX (1, mgp->pwidth);
    mgp->pheight = PREVIEW_SIZE;
  }


  /* preview dummy widgets */
  {
    GtkWidget *table11;
    GtkWidget *dummy;

    gint ix;
    gint iy;
    /* aspect_frame is the CONTAINER for the preview drawing area */
    aspect_frame = gtk_aspect_frame_new (NULL   /* without label */
                                      , 0.5   /* xalign center */
                                      , 0.5   /* yalign center */
                                      , mgp->pwidth / mgp->pheight     /* ratio */
                                      , TRUE  /* obey_child */
                                      );


    /* table11 is used to center aspect_frame */
    table11 = gtk_table_new (3, 3, FALSE);
    gtk_widget_show (table11);
    for(ix = 0; ix < 3; ix++)
    {
      for(iy = 0; iy < 3; iy++)
      {
        if((ix == 1) && (iy == 1))
        {
           gtk_table_attach (GTK_TABLE (table11), aspect_frame, ix, ix+1, iy, iy+1,
                            (GtkAttachOptions) (GTK_FILL | GTK_SHRINK | GTK_EXPAND),
                            (GtkAttachOptions) (GTK_FILL | GTK_SHRINK | GTK_EXPAND),
                            0, 0);
        }
        else
        {
          /* dummy widgets to fill up table11  */
          dummy = gtk_vbox_new (FALSE,3);
          gtk_widget_show (dummy);
          gtk_table_attach (GTK_TABLE (table11), dummy, ix, ix+1, iy, iy+1,
                            (GtkAttachOptions) (GTK_FILL | GTK_SHRINK | GTK_EXPAND),
                            (GtkAttachOptions) (GTK_FILL | GTK_SHRINK | GTK_EXPAND),
                            0, 0);
        }
      }
    }

    wrap_box = gtk_vbox_new (FALSE,3);
    gtk_box_pack_start (GTK_BOX (wrap_box), table11, FALSE, FALSE, 0);
    gtk_widget_show(wrap_box);
    gtk_table_attach (GTK_TABLE (pv_table), wrap_box, 0, 1, 0, 1,
                    (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL),
                    (GtkAttachOptions) (GTK_EXPAND | GTK_SHRINK | GTK_FILL), 0, 0);

  }


  /* hbox_show block */
  {
    GtkWidget *hbox_show;


    hbox_show = gtk_hbox_new (FALSE, 3);
    gtk_widget_show (hbox_show);

    /* pathclor selction button */
    {
      GtkWidget      *color_button;

      gimp_rgb_set(&mgp->pathcolor, 1.0, 0.1, 0.1); /* startup with RED pathline color */
      gimp_rgb_set_alpha(&mgp->pathcolor, 1.0);
      color_button = gimp_color_button_new (_("Pathline Color Picker"),
                                  25, 12,                     /* WIDTH, HEIGHT, */
                                  &mgp->pathcolor,
                                  GIMP_COLOR_AREA_FLAT);
      gtk_box_pack_start (GTK_BOX (hbox_show), color_button, TRUE, TRUE, 4);
      gtk_widget_show (color_button);
      gimp_help_set_help_data(color_button,
                         _("Select the color that is used to "
                           "draw pathlines in the preview")
                         , NULL);

      g_signal_connect (color_button, "color_changed",
                    G_CALLBACK (mov_path_colorbutton_update),
                    mgp);

    }


    /* toggle Show path */
    check_button = gtk_check_button_new_with_label ( _("Path"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                  mgp->show_path);
    gimp_help_set_help_data(check_button,
                         _("Show path lines and enable "
                           "pick/drag with left button "
                           "or move with right button")
                         , NULL);
    gtk_widget_show (check_button);
    gtk_box_pack_start (GTK_BOX (hbox_show), check_button, TRUE, TRUE, 0);

    g_signal_connect (G_OBJECT (check_button), "toggled",
                      G_CALLBACK  (mov_show_path_callback),
                      mgp);



    /* toggle Show cursor */
    check_button = gtk_check_button_new_with_label ( _("Cursor"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                  mgp->show_cursor);
    gimp_help_set_help_data(check_button,
                         _("Show cursor crosslines")
                         , NULL);
    gtk_widget_show (check_button);
    gtk_box_pack_start (GTK_BOX (hbox_show), check_button, TRUE, TRUE, 0);

    g_signal_connect (G_OBJECT (check_button), "toggled",
                      G_CALLBACK  (mov_show_cursor_callback),
                      mgp);


    /* toggle Show Grid */
    check_button = gtk_check_button_new_with_label ( _("Grid"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                  mgp->show_grid);
    gimp_help_set_help_data(check_button,
                         _("Show source layer as gridlines")
                         , NULL);
    //XX gtk_widget_show (check_button);
    gtk_box_pack_start (GTK_BOX (hbox_show), check_button, TRUE, TRUE, 0);

    g_signal_connect (G_OBJECT (check_button), "toggled",
                      G_CALLBACK  (mov_show_grid_callback),
                      mgp);

    /* toggle Instant Apply */
    check_button = gtk_check_button_new_with_label ( _("Instant Apply"));
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                  mgp->instant_apply);
    gimp_help_set_help_data(check_button,
                         _("Update the preview automatically")
                         , NULL);
    gtk_widget_show (check_button);
    gtk_box_pack_start (GTK_BOX (hbox_show), check_button, TRUE, TRUE, 0);

    g_signal_connect (G_OBJECT (check_button), "toggled",
                      G_CALLBACK  (mov_instant_apply_callback),
                      mgp);


    gtk_table_attach(GTK_TABLE(pv_table), hbox_show, 0, 1, 1, 2,
                     0, 0, 16, 0);
  }

  /* the preview sub table (1 row) */
  pv_sub_table = gtk_table_new ( 1, 3, FALSE );

  /* the Preview Frame Number  */
  adj = gimp_scale_entry_new( GTK_TABLE (pv_sub_table), 0, 1,   /* table col, row */
                          _("Frame:"),                          /* label text */
                          SCALE_WIDTH, ENTRY_WIDTH,             /* scalesize spinsize */
                          (gdouble)mgp->preview_frame_nr,       /* value */
                          (gdouble)mgp->first_nr,               /* lower */
                          (gdouble)mgp->last_nr,                /* upper */
                          1, 10,                                /* step, page */
                          0,                                    /* digits */
                          TRUE,                                 /* constrain */
                          (gdouble)mgp->first_nr,               /* lower (unconstrained)*/
                          (gdouble)mgp->last_nr,                /* upper (unconstrained)*/
                          _("Frame to show when 'Refresh' button is pressed"),
                          NULL);                                /* tooltip privatetip */
  g_object_set_data(G_OBJECT(adj), "mgp", mgp);
  g_signal_connect (G_OBJECT (adj), "value_changed",
                    G_CALLBACK (mov_instant_int_adjustment_update),
                    &mgp->preview_frame_nr);
  mgp->preview_frame_nr_adj = GTK_ADJUSTMENT(adj);


  gtk_table_attach( GTK_TABLE(pv_table), pv_sub_table, 0, 1, 2, 3,
                    GTK_FILL|GTK_EXPAND, 0, 0, 0 );
  gtk_widget_show (pv_sub_table);


  /* PREVIEW DRAWING AREA */
  mgp->pv_ptr = gap_pview_new(mgp->pwidth
                                , mgp->pheight
                                , GAP_MOV_CHECK_SIZE
                                , aspect_frame
                                );
  da_widget = mgp->pv_ptr->da_widget;

  g_object_set_data( G_OBJECT(da_widget), "mgp", mgp);
  gtk_widget_set_events( GTK_WIDGET(da_widget), PREVIEW_MASK );
  g_signal_connect_after( G_OBJECT(da_widget), "expose_event",
                          G_CALLBACK (mov_path_prevw_preview_expose),
                          mgp );
  g_signal_connect( G_OBJECT(da_widget), "event",
                    G_CALLBACK  (mov_path_prevw_preview_events),
                    mgp );
  gtk_container_add( GTK_CONTAINER( aspect_frame ), da_widget);
  gtk_widget_show(da_widget);
  gtk_widget_show(aspect_frame);

  /* keep track of resizing events of the preview
   * for automatic preview scale when more or less layoutspace is available.
   */

  g_signal_connect_after (G_OBJECT (wrap_box), "size_allocate",
                      G_CALLBACK (mov_pview_size_allocate_callback),
                      mgp);

  /* Draw the contents of preview, that is saved in the preview widget */
  mov_path_prevw_preview_init( mgp );


  /* edit buttons table */
  edit_buttons = mov_edit_button_box_create(mgp);
  if(vertical_layout)
  {
    GtkWidget *vvbox;

    vvbox = gtk_vbox_new(FALSE, 3);
    gtk_widget_show (vvbox);
    framerange_table = mov_path_framerange_box_create(mgp, vertical_layout);

    gtk_box_pack_start (GTK_BOX (vvbox), edit_buttons, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (vvbox), framerange_table, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX (hbox), vvbox, FALSE, FALSE, 0);
  }
  else
  {
    gtk_box_pack_start (GTK_BOX (hbox), edit_buttons, FALSE, FALSE, 0);
  }


  mov_path_prevw_cursor_update( mgp );

  mgp->in_call = FALSE;   /* End of initialization */
  if(gap_debug) printf("pvals mgp=%d,%d\n", mgp->p_x, mgp->p_y );
  if(gap_debug) printf("mgp cur=%d,%d\n", mgp->curx, mgp->cury );

}  /* end mov_path_prevw_create */


/* ============================================================================
 *  mov_path_prevw_preview_init
 *    Initialize preview
 *    Draw the contents into the internal buffer of the preview widget
 * ============================================================================
 */

static void
mov_path_prevw_preview_init ( t_mov_gui_stuff *mgp )
{
  gint32  image_id;


  if(gap_debug) printf ("mov_path_prevw_preview_init:  START\n");

  if(mgp->pv_ptr)
  {
    if(gap_debug) printf ("mov_path_prevw_preview_init:"
                          " before gap_pview_render_from_image drawable_id:%d\n"
                          , (int)mgp->drawable->drawable_id);
    image_id = gimp_drawable_get_image(mgp->drawable->drawable_id);
    if(gap_debug) printf ("mov_path_prevw_preview_init:"
                          " after gap_pview_render_from_image drawable_id:%d image_id:%d\n"
                          , (int)mgp->drawable->drawable_id
                          , (int)image_id
                          );
    gap_pview_render_from_image(mgp->pv_ptr, image_id);
  }
}

/* ============================================================================
 * mov_path_prevw_draw
 *   Preview Rendering Util routine End
 *     if update & PATH_LINE, draw the path lines
 *     if update & CURSOR,  draw cross cursor
 * ============================================================================
 */

static void
mov_path_prevw_draw ( t_mov_gui_stuff *mgp, gint update )
{
  gint     l_idx;
  GdkColor fg;
  GdkColormap *cmap;
  guchar   l_red, l_green, l_blue;

  if(gap_debug) printf("mov_path_prevw_draw: START update:%d\n", (int)update);

  if(mgp->pv_ptr == NULL)
  {
    return;
  }
  if(mgp->pv_ptr->da_widget==NULL)
  {
    return;
  }

  if(gap_debug) printf("mov_path_prevw_draw: gap_pview_repaint\n");
  gap_pview_repaint(mgp->pv_ptr);

  /* alternate cross cursor OR path graph */

  if((mgp->show_path)
  && ( pvals != NULL )
  && (update & PATH_LINE))
  {
      /* redraw the preview
       * (to clear path lines and cross cursor)
       */
      gimp_rgb_get_uchar (&mgp->pathcolor, &l_red, &l_green, &l_blue);

      cmap = gtk_widget_get_colormap(mgp->pv_ptr->da_widget);
      fg.red   = (l_red   << 8) | l_red;
      fg.green = (l_green << 8) | l_green;
      fg.blue  = (l_blue  << 8) | l_blue;

      /*if(gap_debug) printf ("fg.r/g/b (%d %d %d)\n", (int)fg.red ,(int)fg.green, (int)fg.blue); */

      if(cmap)
      {
         gdk_colormap_alloc_color(cmap
                              , &fg
                              , FALSE   /* writeable */
                              , TRUE   /* best_match */
                              );
      }
      /*if(gap_debug) printf ("fg.pixel (%d)\n", (int)fg.pixel); */


      gdk_gc_set_foreground (mgp->pv_ptr->da_widget->style->black_gc, &fg);

      p_points_to_tab(mgp);
      for(l_idx = 0; l_idx < pvals->point_idx_max; l_idx++)
        {
           /* draw the path line(s) */
           gdk_draw_line (mgp->pv_ptr->da_widget->window,
                          mgp->pv_ptr->da_widget->style->black_gc,
                          (pvals->point[l_idx].p_x    * mgp->pwidth) / mgp->dwidth,
                          (pvals->point[l_idx].p_y    * mgp->pheight) / mgp->dheight,
                          (pvals->point[l_idx +1].p_x * mgp->pwidth) / mgp->dwidth,
                          (pvals->point[l_idx +1].p_y * mgp->pheight) / mgp->dheight
                          );
           /* draw the path point(s) */
           gdk_draw_arc (mgp->pv_ptr->da_widget->window, mgp->pv_ptr->da_widget->style->black_gc, TRUE,
                            (pvals->point[l_idx +1].p_x  * mgp->pwidth / mgp->dwidth) -RADIUS,
                            (pvals->point[l_idx +1].p_y  * mgp->pheight / mgp->dheight) -RADIUS,
                            RADIUS * 2, RADIUS * 2, 0, 23040);
        }
        /* draw the start point */
        gdk_draw_arc (mgp->pv_ptr->da_widget->window, mgp->pv_ptr->da_widget->style->black_gc, TRUE,
                     (pvals->point[0].p_x * mgp->pwidth / mgp->dwidth) -RADIUS,
                     (pvals->point[0].p_y * mgp->pheight / mgp->dheight) -RADIUS,
                     RADIUS * 2, RADIUS * 2, 0, 23040);

        /* restore black gc */
        fg.red   = 0;
        fg.green = 0;
        fg.blue  = 0;
        if(cmap)
        {
          gdk_colormap_alloc_color(cmap
                                , &fg
                                , FALSE   /* writeable */
                                , TRUE   /* best_match */
                                );
        }

        gdk_gc_set_foreground (mgp->pv_ptr->da_widget->style->black_gc, &fg);
  }

  /* draw CURSOR */
  if(mgp->show_cursor)
  {
      if(gap_debug) printf("mov_path_prevw_draw: draw-cursor cur=%d,%d\n"
             , mgp->curx
             , mgp->cury
             );
      gdk_gc_set_function ( mgp->pv_ptr->da_widget->style->black_gc, GDK_INVERT);

      gdk_draw_line ( mgp->pv_ptr->da_widget->window,
                      mgp->pv_ptr->da_widget->style->black_gc,
                      mgp->curx, 1, mgp->curx, mgp->pheight-1 );
      gdk_draw_line ( mgp->pv_ptr->da_widget->window,
                      mgp->pv_ptr->da_widget->style->black_gc,
                      1, mgp->cury, mgp->pwidth-1, mgp->cury );
      /* current position of cursor is updated */
      gdk_gc_set_function ( mgp->pv_ptr->da_widget->style->black_gc, GDK_COPY);
  }
}

/* Adjustment Update Callbacks (with instant_update request) */

static void
mov_instant_int_adjustment_update(GtkObject *obj, gpointer val)
{
  t_mov_gui_stuff *mgp;

  gimp_int_adjustment_update(GTK_ADJUSTMENT(obj), val);


  mgp = g_object_get_data( G_OBJECT(obj), "mgp" );
  mov_set_instant_apply_request(mgp);
}  /* end mov_instant_int_adjustment_update */

static void
mov_instant_double_adjustment_update(GtkObject *obj, gpointer val)
{
  t_mov_gui_stuff *mgp;

  gimp_double_adjustment_update(GTK_ADJUSTMENT(obj), val);

  mgp = g_object_get_data( G_OBJECT(obj), "mgp" );
  mov_set_instant_apply_request(mgp);
}  /* end mov_instant_double_adjustment_update */


static void
mov_path_colorbutton_update( GimpColorButton *widget,
                             t_mov_gui_stuff *mgp )
{
  if(mgp)
  {
    gimp_color_button_get_color(widget, &mgp->pathcolor);
    mov_path_prevw_cursor_update( mgp );
    mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
  }
}  /* end mov_path_colorbutton_update */

static void
mov_path_keycolorbutton_clicked( GimpColorButton *widget,
                             t_mov_gui_stuff *mgp )
{
  if(widget->dialog)
  {
    /* WORKAROUND:
     *  we dont need the coloresction dialog for the keycolor_button,
     *  because only the Bluebox Dioalog Window should open
     *  when the keycolor_button is clicked.
     *  The coloresction dialog is opened by
     *  the standard "clicked" signal handler of the GimpColorButton Widget.
     *  that fires always before this private signal handler.
     *
     *  because i have no idea how to remove the standard signal handler
     *  i used this Workaround, that simply destroys the unwanted dialog
     *  immediate after its creation.
     *  (this works fine, but the coloresction dialog may filcker up for a very short time)
     */
    gtk_widget_destroy(widget->dialog);
    widget->dialog = NULL;
  }

  if(mgp)
  {
    if((pvals->bbp_pv)
    && (pvals->src_layer_id >= 0)
    && (pvals->src_image_id >= 0))
    {
      /* use the current source layer for The Blubox Dialog
       * but do not perform changes here.
       */

      pvals->bbp_pv->image_id = pvals->src_image_id;
      pvals->bbp_pv->drawable_id = pvals->src_layer_id;
      pvals->bbp_pv->layer_id = pvals->src_layer_id;
      pvals->bbp_pv->run_flag = FALSE;
      pvals->bbp_pv->run_mode = GIMP_RUN_INTERACTIVE;

      gap_bluebox_dialog(pvals->bbp_pv);

      if(mgp->shell == NULL)
      {
        /* the MovePath Main Window was closed
         * quit gtk main loop and return immediate
         * without touching any data structures and widgets
         * (could be freed or invalid at this point)
         * the only task that is left to do is to destroy
         * the bluebox dialog shell if it is still there
         */
        if(pvals->bbp_pv->shell)
        {
          gtk_widget_destroy(pvals->bbp_pv->shell);
        }
        gtk_main_quit();
        return;
      }

      if(pvals->bbp == NULL)
      {
        pvals->bbp = gap_bluebox_bbp_new(-1);
        if(pvals->bbp == NULL)
        {
          return;
        }
      }

      /* if Blubox dialog was left with OK button get values for rendering */
      if(pvals->bbp_pv->run_flag)
      {
        memcpy(&pvals->bbp->vals, &pvals->bbp_pv->vals, sizeof(GapBlueboxVals));
      }

      gimp_color_button_set_color(widget, &pvals->bbp->vals.keycolor);
      mov_set_instant_apply_request(mgp);

    }
  }
}  /* end mov_path_keycolorbutton_clicked */


static void
mov_path_keycolorbutton_changed( GimpColorButton *widget,
                             t_mov_gui_stuff *mgp )
{
  if(mgp)
  {
    gimp_color_button_get_color(widget, &pvals->bbp_pv->vals.keycolor);

    if(pvals->bbp == NULL)
    {
      pvals->bbp = gap_bluebox_bbp_new(-1);
      if(pvals->bbp == NULL)
      {
        return;
      }
    }

    memcpy(&pvals->bbp->vals.keycolor, &pvals->bbp_pv->vals.keycolor, sizeof(GimpRGB));
    mov_set_instant_apply_request(mgp);
  }
}  /* end mov_path_keycolorbutton_changed */

/*
 *  mov_path_xy_adjustment_update
 */

static void
mov_path_x_adjustment_update( GtkWidget *widget,
                              gpointer data )
{
  t_mov_gui_stuff *mgp;
  gint old_val;

  mgp = (t_mov_gui_stuff *)data;
  if(mgp == NULL) return;

  old_val = mgp->p_x;
  gimp_int_adjustment_update(GTK_ADJUSTMENT(widget), &mgp->p_x);
  if( old_val != mgp->p_x )
  {
      if( !mgp->in_call )
      {
          mov_path_prevw_cursor_update( mgp );
          mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
          mov_set_instant_apply_request(mgp);
      }
  }
}

static void
mov_path_y_adjustment_update( GtkWidget *widget,
                              gpointer data )
{
  t_mov_gui_stuff *mgp;
  gint old_val;

  mgp = (t_mov_gui_stuff *)data;
  if(mgp == NULL) return;

  old_val = mgp->p_y;
  gimp_int_adjustment_update(GTK_ADJUSTMENT(widget), &mgp->p_y);
  if( old_val != mgp->p_y )
  {
      if( !mgp->in_call )
      {
          mov_path_prevw_cursor_update( mgp );
          mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
          mov_set_instant_apply_request(mgp);
      }
  }
}

static void
mov_path_tfactor_adjustment_update( GtkWidget *widget,
                            gdouble *val )
{
  gdouble old_val;
  t_mov_gui_stuff *mgp;

  mgp = g_object_get_data( G_OBJECT(widget), "mgp" );

  if(mgp == NULL) return;
  old_val = *val;
  gimp_double_adjustment_update(GTK_ADJUSTMENT(widget), (gpointer)val);
  if( old_val != *val )
  {
      mov_set_instant_apply_request(mgp);
      if( !mgp->in_call )
      {
          mov_path_prevw_cursor_update( mgp );
          mov_path_prevw_draw ( mgp, CURSOR | PATH_LINE );
          //XXX check if we need an additional GRID flag for the preview
      }
  }
}  /* end mov_path_tfactor_adjustment_update */

static void
mov_path_feather_adjustment_update( GtkWidget *widget,
                            gdouble *val )
{
  gdouble old_val;
  t_mov_gui_stuff *mgp;

  mgp = g_object_get_data( G_OBJECT(widget), "mgp" );

  if(mgp == NULL) return;
  old_val = *val;
  gimp_double_adjustment_update(GTK_ADJUSTMENT(widget), (gpointer)val);
  if( old_val != *val )
  {
      mov_set_instant_apply_request(mgp);
  }
}  /* end mov_path_feather_adjustment_update */

static void
mov_selmode_menu_callback (GtkWidget *widget, t_mov_gui_stuff *mgp)
{
  gboolean l_sensitive;
  GtkWidget *spinbutton;
  gint value;

  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value);
  pvals->src_selmode = value;

  if(mgp == NULL) return;

  l_sensitive = TRUE;
  if(pvals->src_selmode == GAP_MOV_SEL_IGNORE)
  {
    l_sensitive = FALSE;
  }

  if(mgp->sel_feather_radius_adj)
  {
    spinbutton = GTK_WIDGET(g_object_get_data (G_OBJECT (mgp->sel_feather_radius_adj), "spinbutton"));
    if(spinbutton)
    {
      gtk_widget_set_sensitive(spinbutton, l_sensitive);
    }
  }
  mov_set_instant_apply_request(mgp);
}  /* end mov_selmode_menu_callback */


static void
mov_path_resize_adjustment_update( GtkObject *obj, gdouble *val)
{
  gdouble old_val;
  t_mov_gui_stuff *mgp;

  mgp = g_object_get_data( G_OBJECT(obj), "mgp" );

  if(mgp == NULL) return;
  old_val = *val;
  gimp_double_adjustment_update(GTK_ADJUSTMENT(obj), (gpointer)val);
  if( old_val != *val )
  {
    mov_set_instant_apply_request(mgp);
    if (gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (mgp->constrain)))
    {
      /* in the constrain mode we propagate the value
       * for with and height resize factors to the other one
       * this constrains both spinbuttons to the same factor
       * and keeps the original src layer proportions
       */
      if(GTK_ADJUSTMENT(obj) == mgp->wres_adj)
      {
        gtk_adjustment_set_value(mgp->hres_adj, (gfloat)*val);
      }
      else
      {
        gtk_adjustment_set_value(mgp->wres_adj, (gfloat)*val);
      }
    }
  }
}  /* end mov_path_resize_adjustment_update */

static void
mov_path_tween_steps_adjustment_update ( GtkObject *obj, gint *val)
{
  t_mov_gui_stuff *mgp;

  if((obj == NULL) || (val == NULL))
  {
    return;
  }
  gimp_int_adjustment_update(GTK_ADJUSTMENT(obj), val);
  mgp = g_object_get_data( G_OBJECT(obj), "mgp" );
  if(mgp)
  {
    mov_tweenlayer_sensitivity(mgp);
  }

}  /* end mov_path_tween_steps_adjustment_update */


/*
 *  Update the cross cursor's  coordinates accoding to pvals->[xy]path_prevw
 *  but not redraw it
 */

static void
mov_path_prevw_cursor_update ( t_mov_gui_stuff *mgp )
{
  mgp->curx = mgp->p_x * mgp->pwidth / mgp->dwidth;
  mgp->cury = mgp->p_y * mgp->pheight / mgp->dheight;

  if( mgp->curx < 0 )                  mgp->curx = 0;
  else if( mgp->curx >= mgp->pwidth )  mgp->curx = mgp->pwidth-1;
  if( mgp->cury < 0 )                  mgp->cury = 0;
  else if( mgp->cury >= mgp->pheight)  mgp->cury = mgp->pheight-1;

}

/*
 *    Handle the expose event on the preview
 */
static gint
mov_path_prevw_preview_expose( GtkWidget *widget,
                            GdkEvent *event )
{
  t_mov_gui_stuff *mgp;

  mgp = g_object_get_data( G_OBJECT(widget), "mgp" );

  if((mgp->pv_ptr == NULL)
  || (mgp->in_call))
  {
       return FALSE;
  }

  if(mgp->pv_ptr->da_widget == NULL)
  {
       return FALSE;
  }

  mgp->in_call = TRUE;
  mov_path_prevw_draw( mgp, ALL );
  mgp->in_call = FALSE;
  return FALSE;
}


/*
 *    Handle other events on the preview
 */

static gint
mov_path_prevw_preview_events ( GtkWidget *widget,
                             GdkEvent *event )
{
  t_mov_gui_stuff *mgp;
  GdkEventButton *bevent;
  GdkEventMotion *mevent;
  gint upd_flag;
  gint mouse_button;

  mgp = g_object_get_data ( G_OBJECT(widget), "mgp" );

 /* HINT:
  * smooth update of both CURSOR and PATH_LINE
  * on every mousemove works fine on machines with 300MHz.
  * for slower machines it once was better to paint just the cross cursor,
  * and refresh the path lines only at
  * button press and release events.
  * 2003.07.12 hof:
  *    since we use a drawing_area that is repainted at each expose
  *    event, we MUST force painting of the PATH_LINE.
  *    (if we dont, the pathline disappears completely until the mouse
  *     button is released)
  *    The gap_pview_da repaint is faster than the old render_preview procedure
  *    so it may work even for slower machines now.
  */
  upd_flag = CURSOR | PATH_LINE;
  /* upd_flag = CURSOR; */

  mouse_button = 0;

  switch (event->type)
    {
    case GDK_EXPOSE:
      break;

    case GDK_BUTTON_RELEASE:
      bevent = (GdkEventButton *) event;
      mouse_button = 0 - bevent->button;
      mov_set_instant_apply_request(mgp);
      goto mbuttons;
    case GDK_BUTTON_PRESS:
      bevent = (GdkEventButton *) event;
      mouse_button = bevent->button;
    mbuttons:
      mgp->curx = bevent->x;
      mgp->cury = bevent->y;
      upd_flag = CURSOR | PATH_LINE;
      goto mouse;

    case GDK_MOTION_NOTIFY:
      mevent = (GdkEventMotion *) event;
      if ( !mevent->state ) break;
      mgp->curx = mevent->x;
      mgp->cury = mevent->y;
      mov_set_instant_apply_request(mgp);
    mouse:
      if((mouse_button == 1)
      && (mgp->show_path))
      {
         /* Picking of pathpoints is done only if
          *   the left mousebutton goes down (mouse_button == 1)
          *   and only if Path is visible
          */
         p_points_to_tab(mgp);
         mgp->p_x = mgp->curx * mgp->dwidth / mgp->pwidth;
         mgp->p_y = mgp->cury * mgp->dheight / mgp->pheight;
         p_pick_nearest_point(mgp->p_x, mgp->p_y);
         p_point_refresh(mgp);
      }
      else
      {
         mgp->p_x = mgp->curx * mgp->dwidth / mgp->pwidth;
         mgp->p_y = mgp->cury * mgp->dheight / mgp->pheight;
         p_points_to_tab(mgp);
         mov_path_prevw_cursor_update( mgp );
      }
      mov_path_prevw_draw( mgp, upd_flag);
      mgp->in_call = TRUE;
      gtk_adjustment_set_value (mgp->x_adj,
                                (gfloat)mgp->p_x);
      gtk_adjustment_set_value (mgp->y_adj,
                                (gfloat)mgp->p_y);

      mgp->in_call = FALSE;
      break;

    default:
      break;
    }

  return FALSE;
}


/* ============================================================================
 * p_chk_keyframes
 *   check if controlpoints and keyframe settings are OK
 *   return TRUE if OK,
 *   Pop Up error Dialog window and return FALSE if NOT.
 * ============================================================================
 */

static gint
p_chk_keyframes(t_mov_gui_stuff *mgp)
{
  gchar *l_err_lbltext;

  p_points_to_tab(mgp);

  l_err_lbltext = gap_mov_exec_chk_keyframes(pvals);

  if(*l_err_lbltext != '\0')
  {
    g_message(_("Can't operate with current controlpoint\n"
                "or keyframe settings.\n\n"
                "Error List:\n"
                "%s")
             ,l_err_lbltext );
    g_free(l_err_lbltext);
    return(FALSE);

  }
  g_free(l_err_lbltext);
  return(TRUE);
}       /* end p_chk_keyframes */

/* ============================================================================
 * p_get_flattened_drawable
 *   flatten the given image and return pointer to the
 *   (only) remaining drawable.
 * ============================================================================
 */
GimpDrawable *
p_get_flattened_drawable(gint32 image_id)
{
  GimpDrawable *l_drawable_ptr ;

  l_drawable_ptr = gimp_drawable_get (gap_image_merge_visible_layers(image_id, GIMP_CLIP_TO_IMAGE));
  return l_drawable_ptr;
}       /* end p_get_flattened_drawable */



/* ============================================================================
 *   add the selected source layer to the temp. preview image
 *   (modified accordung to current settings)
 *   then flatten the temporary preview image,
 *   and return pointer to the (only) remaining drawable.
 * ============================================================================
 */

GimpDrawable *
p_get_prevw_drawable (t_mov_gui_stuff *mgp)
{
  GapMovCurrent l_curr;
  gint      l_nlayers;


  /* check if we have a source layer (to add to the preview) */
  if((pvals->src_layer_id >= 0) && (pvals->src_image_id >= 0))
  {
    p_points_to_tab(mgp);

    if(!gap_image_is_alive(pvals->src_image_id))
    {
      mov_refresh_src_layer_menu(mgp);
    }

    /* calculate current settings */
    l_curr.dst_frame_nr    = 0;

    l_curr.currX         = (gdouble)mgp->p_x;
    l_curr.currY         = (gdouble)mgp->p_y;
    l_curr.currOpacity   = (gdouble)mgp->opacity;
    l_curr.currWidth     = (gdouble)mgp->w_resize;
    l_curr.currHeight    = (gdouble)mgp->h_resize;
    l_curr.currRotation  = (gdouble)mgp->rotation;
    l_curr.currTTLX      = (gdouble)mgp->ttlx;
    l_curr.currTTLY      = (gdouble)mgp->ttly;
    l_curr.currTTRX      = (gdouble)mgp->ttrx;
    l_curr.currTTRY      = (gdouble)mgp->ttry;
    l_curr.currTBLX      = (gdouble)mgp->tblx;
    l_curr.currTBLY      = (gdouble)mgp->tbly;
    l_curr.currTBRX      = (gdouble)mgp->tbrx;
    l_curr.currTBRY      = (gdouble)mgp->tbry;
    l_curr.currSelFeatherRadius = (gdouble)mgp->sel_feather_radius;

    l_curr.src_layer_idx   = 0;
    l_curr.src_layers      = gimp_image_get_layers (pvals->src_image_id, &l_nlayers);

    if((l_curr.src_layers != NULL) && (l_nlayers > 0))
    {
      l_curr.src_last_layer  = l_nlayers -1;
      /* findout index of src_layer_id */
      for(l_curr.src_layer_idx = 0;
          l_curr.src_layer_idx  < l_nlayers;
          l_curr.src_layer_idx++)
      {
         if(l_curr.src_layers[l_curr.src_layer_idx] == pvals->src_layer_id)
            break;
      }
    }
    if(pvals->src_stepmode >= GAP_STEP_FRAME)
    {
      gap_mov_render_fetch_src_frame (pvals, -1);  /* negative value fetches the selected frame number */
    }
    else
    {
     if(pvals->src_selmode != GAP_MOV_SEL_IGNORE)
     {
       gint32        l_sel_channel_id;
       gboolean      l_all_empty;

       l_all_empty = FALSE;
       if(gimp_selection_is_empty(pvals->src_image_id))
       {
         l_all_empty = TRUE;
       }
       l_sel_channel_id = gimp_image_get_selection(pvals->src_image_id);
       gap_mov_render_create_or_replace_tempsel_image(l_sel_channel_id, pvals, l_all_empty);
     }
    }


    /* set offsets (in cur_ptr)
     *  according to handle_mode and src_img dimension (pvals)
     */
    gap_mov_exec_set_handle_offsets(pvals,  &l_curr);

    /* render: add source layer to (temporary) preview image */
    gap_mov_render_render(pvals->tmp_image_id, pvals, &l_curr);

    if(l_curr.src_layers != NULL) g_free(l_curr.src_layers);
    l_curr.src_layers = NULL;
  }

  mov_check_valid_src_layer(mgp);

  /* flatten image, and get the (only) resulting drawable */
  return(p_get_flattened_drawable(pvals->tmp_image_id));

}       /* end p_get_prevw_drawable */


/* ---------------------------------
 * mov_set_instant_apply_request
 * ---------------------------------
 */
static void
mov_set_instant_apply_request(t_mov_gui_stuff *mgp)
{
  if(mgp)
  {
    mgp->instant_apply_request = TRUE; /* request is handled by timer */
  }
}  /* end mov_set_instant_apply_request */

/* ---------------------------------
 * mov_set_waiting_cursor
 * ---------------------------------
 */
static void
mov_set_waiting_cursor(t_mov_gui_stuff *mgp)
{
  if(mgp == NULL) return;

  gdk_window_set_cursor(GTK_WIDGET(mgp->shell)->window, mgp->cursor_wait);
  gdk_flush();

  /* g_main_context_iteration makes sure that waiting cursor is displayed */
  while(g_main_context_iteration(NULL, FALSE));

  gdk_flush();
}  /* end mov_set_waiting_cursor */

/* ---------------------------------
 * mov_set_active_cursor
 * ---------------------------------
 */
static void
mov_set_active_cursor(t_mov_gui_stuff *mgp)
{
  if(mgp == NULL) return;

  gdk_window_set_cursor(GTK_WIDGET(mgp->shell)->window, mgp->cursor_acitve);
  gdk_flush();
}  /* end mov_set_active_cursor */


/* ----------------------------------
 * p_mov_spinbutton_new
 * ----------------------------------
 * create label and spinbutton and add to table
 * return the adjustment of the spinbutton
 * (for compatible parameters to gimp_scale_entry_new
 *  there are some unused dummy parameters)
 */
GtkObject *
p_mov_spinbutton_new(GtkTable *table
                    ,gint      col
                    ,gint      row
                    ,gchar    *label_text
                    ,gint      scale_width      /* dummy, not used */
                    ,gint      spinbutton_width
                    ,gdouble   initial_val
                    ,gdouble   lower            /* dummy, not used */
                    ,gdouble   upper            /* dummy, not used */
                    ,gdouble   sstep
                    ,gdouble   pagestep
                    ,gint      digits
                    ,gboolean  constrain
                    ,gdouble   umin
                    ,gdouble   umax
                    ,gchar    *tooltip_text
                    ,gchar    *privatetip
                    )
{
  GtkObject      *adj;
  GtkWidget      *spinbutton;
  GtkWidget      *label;

  label = gtk_label_new (label_text);
  gtk_misc_set_alignment( GTK_MISC(label), 0.0, 0.5 );
  gtk_table_attach( GTK_TABLE(table), label, col, col+1, row, row+1,
                    GTK_FILL, 0, 4, 0 );
  gtk_widget_show(label);

  spinbutton = gimp_spin_button_new (&adj  /* return value */
                , initial_val
                , umin
                , umax
                , sstep
                , pagestep
                , 0.0                 /* page_size */
                , 1.0                 /* climb_rate */
                , digits
                );
  gtk_widget_set_size_request(spinbutton, spinbutton_width, -1);
  gtk_widget_show (spinbutton);
  gtk_table_attach (GTK_TABLE (table), spinbutton, col+1, col+2, row, row+1,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);
  gimp_help_set_help_data (spinbutton, tooltip_text, privatetip);

  g_object_set_data (G_OBJECT (adj), "label", label);
  g_object_set_data (G_OBJECT (adj), "spinbutton", spinbutton);

  return(adj);
}  /* end p_mov_spinbutton_new */


/* --------------------------
 * mov_fit_initial_shell_window
 * --------------------------
 */
static void
mov_fit_initial_shell_window(t_mov_gui_stuff *mgp)
{
  gint width;
  gint height;

  if(mgp == NULL)                   { return; }
  if(mgp->shell_initial_width < 0)  { return; }

  width = mgp->shell_initial_width;
  height = mgp->shell_initial_height;

  gtk_widget_set_size_request (mgp->shell, width, height);  /* shrink shell window */
  gtk_window_set_default_size(GTK_WINDOW(mgp->shell), width, height);  /* shrink shell window */
  gtk_window_resize (GTK_WINDOW(mgp->shell), width, height);  /* shrink shell window */
}  /* end mov_fit_initial_shell_window */

/* -----------------------------
 * mov_shell_window_size_allocate
 * -----------------------------
 */
static void
mov_shell_window_size_allocate (GtkWidget       *widget,
                                GtkAllocation   *allocation,
                                gpointer         user_data)
{
   t_mov_gui_stuff *mgp;

   mgp = (t_mov_gui_stuff*)user_data;
   if((mgp == NULL) || (allocation == NULL))
   {
     return;
   }

   if(gap_debug) printf("mov_shell_window_size_allocate: START  shell_alloc: w:%d h:%d \n"
                           , (int)allocation->width
                           , (int)allocation->height
                           );

   if(mgp->shell_initial_width < 0)
   {
     mgp->shell_initial_width = allocation->width;
     mgp->shell_initial_height = allocation->height;
     mov_fit_initial_shell_window(mgp);  /* for setting window default size */
   }
   else
   {
     if((allocation->width < mgp->shell_initial_width)
     || (allocation->height < mgp->shell_initial_height))
     {
       /* dont allow shrink below initial size */
       mov_fit_initial_shell_window(mgp);
     }
   }
}  /* end mov_shell_window_size_allocate */

/* --------------------------------
 * mov_pview_size_allocate_callback
 * --------------------------------
 */
static void
mov_pview_size_allocate_callback(GtkWidget *widget
                                , GtkAllocation *allocation
                                , t_mov_gui_stuff *mgp
                                )
{
  gint actual_check_size;
  gint pwidth;
  gint pheight;
  gint psize;
  gboolean fit_initial;

  static gint ignore_inital_cnt = 2;

#define PREVIEW_BORDER_X  18
#define PREVIEW_BORDER_Y  18

  fit_initial = FALSE;

  if(ignore_inital_cnt > 0)
  {
    if(gap_debug) printf("\n\n === countdown: %d\n\n", (int)ignore_inital_cnt );
    ignore_inital_cnt--;
    return;
  }

  if((mgp == NULL) || (allocation == NULL))    { return; }
  if(mgp->startup)                             { return; }
  if(mgp->pv_ptr->da_widget == NULL)           { return; }
  if(mgp->pv_ptr->da_widget->window == NULL)   { return; }


  /* fit preview into allocated width and adjust the height */
  pwidth = allocation->width - PREVIEW_BORDER_X;
  pheight =  (pwidth * mgp->dheight) / MAX(mgp->dwidth,1);

  if(pheight + PREVIEW_BORDER_Y > allocation->height)
  {
    /* fit preview into allocated height and adjust the width */
    pheight = allocation->height - PREVIEW_BORDER_Y;
    pwidth = (pheight * mgp->dwidth) / MAX(mgp->dheight,1);
  }

  psize = MAX(pwidth, pheight);

  if ((allocation->width - PREVIEW_BORDER_X < PREVIEW_SIZE)
  ||  (allocation->height - PREVIEW_BORDER_Y < PREVIEW_SIZE)
  ||  (pwidth < mgp->pwidth)    /* TOTAL SHRINK WORKAROUND */
  ||  (pheight < mgp->pheight)  /* TOTAL SHRINK WORKAROUND */
  )
  {
    /* do not allow shrinks smaller than PREVIEW_SIZE */
    if ( mgp->dwidth > mgp->dheight )
    {
      pheight = mgp->dheight * PREVIEW_SIZE / mgp->dwidth;
      pheight = MAX (1, pheight);
      pwidth  = PREVIEW_SIZE;
    }
    else
    {
      pwidth  = mgp->dwidth * PREVIEW_SIZE / mgp->dheight;
      pwidth  = MAX (1, pwidth);
      pheight = PREVIEW_SIZE;
    }
    psize = PREVIEW_SIZE;
    ignore_inital_cnt = 1;
    fit_initial = TRUE;
  }

  actual_check_size = (GAP_MOV_CHECK_SIZE * psize) / PREVIEW_SIZE;

  if(gap_debug)
  {
    printf("allocation w:%d  h:%d  pwidth:%d  pheight:%d   preview: w:%d  h:%d   psize MAX:%d\n"
                      , (int)allocation->width
                      , (int)allocation->height
                      , (int)pwidth
                      , (int)pheight
                      , (int)mgp->pwidth
                      , (int)mgp->pheight
                      , (int)psize
                      );
  }

  if(((pheight / 6) == (mgp->pheight / 6))
  && ((pwidth / 6)  == (mgp->pwidth / 6)))
  {
    /* skip resize if equal size or no significant change (< 6 pixel) */
    if(gap_debug) printf("RET\n");
    return;
  }

  mgp->pwidth = pwidth;
  mgp->pheight = pheight;

  gap_pview_set_size(mgp->pv_ptr
                  , mgp->pwidth
                  , mgp->pheight
                  , actual_check_size
                  );
  mov_upvw_callback (NULL, mgp);

  if(fit_initial)
  {
    mov_fit_initial_shell_window(mgp);
  }

}  /* end mov_pview_size_allocate_callback */