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
|
//------------------------------------------------------------------------------
// <copyright file="Wizard.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Web.UI.WebControls {
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Drawing.Design;
using System.Globalization;
using System.Linq;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.Util;
[
Bindable(false),
DefaultEvent("FinishButtonClick"),
Designer("System.Web.UI.Design.WebControls.WizardDesigner, " + AssemblyRef.SystemDesign),
ToolboxData("<{0}:Wizard runat=\"server\"> <WizardSteps> <asp:WizardStep title=\"Step 1\" runat=\"server\"></asp:WizardStep> <asp:WizardStep title=\"Step 2\" runat=\"server\"></asp:WizardStep> </WizardSteps> </{0}:Wizard>")
]
public class Wizard : CompositeControl {
private ITemplate _finishNavigationTemplate;
private ITemplate _headerTemplate;
private ITemplate _layoutTemplate;
private ITemplate _startNavigationTemplate;
private ITemplate _stepNavigationTemplate;
private ITemplate _sideBarTemplate;
private MultiView _multiView;
private static readonly object _eventActiveStepChanged = new object();
private static readonly object _eventFinishButtonClick = new object();
private static readonly object _eventNextButtonClick = new object();
private static readonly object _eventPreviousButtonClick = new object();
private static readonly object _eventSideBarButtonClick = new object();
private static readonly object _eventCancelButtonClick = new object();
//
public static readonly string HeaderPlaceholderId = "headerPlaceholder";
public static readonly string NavigationPlaceholderId = "navigationPlaceholder";
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", MessageId = "SideBar", Justification = "The casing has already been established in the context of Wizard")]
public static readonly string SideBarPlaceholderId = "sideBarPlaceholder";
public static readonly string WizardStepPlaceholderId = "wizardStepPlaceholder";
public static readonly string CancelCommandName = "Cancel";
public static readonly string MoveNextCommandName = "MoveNext";
public static readonly string MovePreviousCommandName = "MovePrevious";
public static readonly string MoveToCommandName = "Move";
public static readonly string MoveCompleteCommandName = "MoveComplete";
protected static readonly string CancelButtonID = "CancelButton";
protected static readonly string StartNextButtonID = "StartNextButton";
protected static readonly string StepPreviousButtonID = "StepPreviousButton";
protected static readonly string StepNextButtonID = "StepNextButton";
protected static readonly string FinishButtonID = "FinishButton";
protected static readonly string FinishPreviousButtonID = "FinishPreviousButton";
protected static readonly string CustomPreviousButtonID = "CustomPreviousButton";
protected static readonly string CustomNextButtonID = "CustomNextButton";
protected static readonly string CustomFinishButtonID = "CustomFinishButton";
protected static readonly string DataListID = "SideBarList";
protected static readonly string SideBarButtonID = "SideBarButton";
internal const string _customNavigationControls = "CustomNavigationControls";
private const string _templatedStepsID = "TemplatedWizardSteps";
private const string _multiViewID = "WizardMultiView";
private const string _customNavigationContainerIdPrefix = "__CustomNav";
private TableCell _sideBarTableCell;
private IWizardSideBarListControl _sideBarList;
private IButtonControl _commandSender;
private Dictionary<WizardStepBase, BaseNavigationTemplateContainer> _customNavigationContainers;
private IDictionary _designModeState;
private Stack<int> _historyStack;
private List<TemplatedWizardStep> _templatedSteps;
private WizardStepCollection _wizardStepCollection;
private WizardRenderingBase _rendering;
private bool _activeStepIndexSet;
private bool _displaySideBarDefault;
private bool _displaySideBar;
private bool? _isMacIE;
private bool _renderSideBarDataList;
private Style _cancelButtonStyle;
private Style _finishCompleteButtonStyle;
private Style _finishPreviousButtonStyle;
private Style _navigationButtonStyle;
private Style _sideBarButtonStyle;
private Style _startNextButtonStyle;
private Style _stepNextButtonStyle;
private Style _stepPreviousButtonStyle;
private TableItemStyle _headerStyle;
private TableItemStyle _navigationStyle;
private TableItemStyle _sideBarStyle;
private TableItemStyle _stepStyle;
private const bool _displaySideBarDefaultValue = true; /* default to true */
private const int _viewStateArrayLength = 15;
public Wizard()
: this(_displaySideBarDefaultValue) {
}
internal Wizard(bool displaySideBarDefault) {
_displaySideBarDefault = displaySideBarDefault;
_displaySideBar = displaySideBarDefault;
}
#region Public Properties
[
Browsable(false),
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),
WebSysDescription(SR.Wizard_ActiveStep)
]
public WizardStepBase ActiveStep {
get {
if (ActiveStepIndex < -1 || ActiveStepIndex >= WizardSteps.Count) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_ActiveStepIndex_out_of_range));
}
return MultiView.GetActiveView() as WizardStepBase;
}
}
[
DefaultValue(-1),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Wizard_ActiveStepIndex),
]
public virtual int ActiveStepIndex {
get {
return MultiView.ActiveViewIndex;
}
set {
if (value < -1 ||
(value >= WizardSteps.Count && ControlState >= ControlState.FrameworkInitialized)) {
throw new ArgumentOutOfRangeException("value",
SR.GetString(SR.Wizard_ActiveStepIndex_out_of_range));
}
if (MultiView.ActiveViewIndex != value) {
MultiView.ActiveViewIndex = value;
_activeStepIndexSet = true;
// Need to rebind the DataList control if the active step is changed.
// This is necessary since custom sidebar template might have different
// itemtemplates defined.
if (_sideBarList != null && SideBarTemplate != null) {
_sideBarList.SelectedIndex = ActiveStepIndex;
_sideBarList.DataBind();
}
}
}
}
/// <devdoc>
/// Gets or sets the URL of an image to be displayed for the cancel button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_CancelButtonImageUrl),
UrlProperty(),
]
public virtual string CancelButtonImageUrl {
get {
object obj = ViewState["CancelButtonImageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["CancelButtonImageUrl"] = value;
}
}
/// <devdoc>
/// Gets the style of the cancel buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_CancelButtonStyle)
]
public Style CancelButtonStyle {
get {
if (_cancelButtonStyle == null) {
_cancelButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_cancelButtonStyle).TrackViewState();
}
}
return _cancelButtonStyle;
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_CancelButtonText),
WebSysDescription(SR.Wizard_CancelButtonText)
]
public virtual String CancelButtonText {
get {
string s = ViewState["CancelButtonText"] as String;
return s == null ? SR.GetString(SR.Wizard_Default_CancelButtonText) : s;
}
set {
if (value != CancelButtonText) {
ViewState["CancelButtonText"] = value;
}
}
}
[
DefaultValue(ButtonType.Button),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_CancelButtonType)
]
public virtual ButtonType CancelButtonType {
get {
object obj = ViewState["CancelButtonType"];
return (obj == null) ? ButtonType.Button : (ButtonType)obj;
}
set {
ValidateButtonType(value);
ViewState["CancelButtonType"] = value;
}
}
[
DefaultValue(""),
Editor("System.Web.UI.Design.UrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Wizard_CancelDestinationPageUrl),
UrlProperty(),
]
public virtual String CancelDestinationPageUrl {
get {
string s = ViewState["CancelDestinationPageUrl"] as String;
return s == null ? String.Empty : s;
}
set {
ViewState["CancelDestinationPageUrl"] = value;
}
}
[
WebCategory("Layout"),
DefaultValue(0),
WebSysDescription(SR.Wizard_CellPadding)
]
public virtual int CellPadding {
get {
if (ControlStyleCreated == false) {
return 0;
}
return ((TableStyle)ControlStyle).CellPadding;
}
set {
((TableStyle)ControlStyle).CellPadding = value;
}
}
[
WebCategory("Layout"),
DefaultValue(0),
WebSysDescription(SR.Wizard_CellSpacing)
]
public virtual int CellSpacing {
get {
if (ControlStyleCreated == false) {
return 0;
}
return ((TableStyle)ControlStyle).CellSpacing;
}
set {
((TableStyle)ControlStyle).CellSpacing = value;
}
}
[
DefaultValue(false),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Wizard_DisplayCancelButton),
]
public virtual bool DisplayCancelButton {
get {
object o = ViewState["DisplayCancelButton"];
return o == null ? false : (bool)o;
}
set {
ViewState["DisplayCancelButton"] = value;
}
}
[
DefaultValue(true),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Wizard_DisplaySideBar),
]
public virtual bool DisplaySideBar {
get {
return _displaySideBar;
}
set {
if (value != _displaySideBar) {
_displaySideBar = value;
_sideBarTableCell = null;
RequiresControlsRecreation();
}
}
}
/// <devdoc>
/// Gets or sets the URL of an image to be displayed for the finish button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_FinishCompleteButtonImageUrl),
UrlProperty(),
]
public virtual string FinishCompleteButtonImageUrl {
get {
object obj = ViewState["FinishCompleteButtonImageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["FinishCompleteButtonImageUrl"] = value;
}
}
/// <devdoc>
/// Gets the style of the finishStep buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_FinishCompleteButtonStyle)
]
public Style FinishCompleteButtonStyle {
get {
if (_finishCompleteButtonStyle == null) {
_finishCompleteButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_finishCompleteButtonStyle).TrackViewState();
}
}
return _finishCompleteButtonStyle;
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_FinishButtonText),
WebSysDescription(SR.Wizard_FinishCompleteButtonText)
]
public virtual String FinishCompleteButtonText {
get {
string s = ViewState["FinishCompleteButtonText"] as String;
return s == null ? SR.GetString(SR.Wizard_Default_FinishButtonText) : s;
}
set {
ViewState["FinishCompleteButtonText"] = value;
}
}
[
WebCategory("Appearance"),
DefaultValue(ButtonType.Button),
WebSysDescription(SR.Wizard_FinishCompleteButtonType)
]
public virtual ButtonType FinishCompleteButtonType {
get {
object obj = ViewState["FinishCompleteButtonType"];
return (obj == null) ? ButtonType.Button : (ButtonType)obj;
}
set {
ValidateButtonType(value);
ViewState["FinishCompleteButtonType"] = value;
}
}
/// <devdoc>
/// Gets or sets the URL for the continue button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.UrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
Themeable(false),
WebCategory("Behavior"),
WebSysDescription(SR.Wizard_FinishDestinationPageUrl),
UrlProperty(),
]
public virtual string FinishDestinationPageUrl {
get {
object obj = ViewState["FinishDestinationPageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["FinishDestinationPageUrl"] = value;
}
}
/// <devdoc>
/// Gets or sets the URL of an image to be displayed for the finish step's previous button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_FinishPreviousButtonImageUrl),
UrlProperty(),
]
public virtual string FinishPreviousButtonImageUrl {
get {
object obj = ViewState["FinishPreviousButtonImageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["FinishPreviousButtonImageUrl"] = value;
}
}
/// <devdoc>
/// Gets the style of the navigation buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_FinishPreviousButtonStyle)
]
public Style FinishPreviousButtonStyle {
get {
if (_finishPreviousButtonStyle == null) {
_finishPreviousButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_finishPreviousButtonStyle).TrackViewState();
}
}
return _finishPreviousButtonStyle;
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_StepPreviousButtonText),
WebSysDescription(SR.Wizard_FinishPreviousButtonText)
]
public virtual String FinishPreviousButtonText {
get {
string s = ViewState["FinishPreviousButtonText"] as String;
return s == null ? SR.GetString(SR.Wizard_Default_StepPreviousButtonText) : s;
}
set {
ViewState["FinishPreviousButtonText"] = value;
}
}
[
WebCategory("Appearance"),
DefaultValue(ButtonType.Button),
WebSysDescription(SR.Wizard_FinishPreviousButtonType)
]
public virtual ButtonType FinishPreviousButtonType {
get {
object obj = ViewState["FinishPreviousButtonType"];
return (obj == null) ? ButtonType.Button : (ButtonType)obj;
}
set {
ValidateButtonType(value);
ViewState["FinishPreviousButtonType"] = value;
}
}
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(Wizard)),
WebSysDescription(SR.Wizard_FinishNavigationTemplate)
]
public virtual ITemplate FinishNavigationTemplate {
get {
return _finishNavigationTemplate;
}
set {
_finishNavigationTemplate = value;
RequiresControlsRecreation();
}
}
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.WebControl_HeaderStyle)
]
public TableItemStyle HeaderStyle {
get {
if (_headerStyle == null) {
_headerStyle = new TableItemStyle();
if (IsTrackingViewState)
((IStateManager)_headerStyle).TrackViewState();
}
return _headerStyle;
}
}
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(Wizard)),
WebSysDescription(SR.WebControl_HeaderTemplate)
]
public virtual ITemplate HeaderTemplate {
get {
return _headerTemplate;
}
set {
_headerTemplate = value;
RequiresControlsRecreation();
}
}
[
DefaultValue(""),
Localizable(true),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_HeaderText)
]
public virtual string HeaderText {
get {
string s = ViewState["HeaderText"] as String;
return s == null ? String.Empty : s;
}
set {
ViewState["HeaderText"] = value;
}
}
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(Wizard)),
WebSysDescription(SR.Wizard_LayoutTemplate)
]
public virtual ITemplate LayoutTemplate {
get {
return _layoutTemplate;
}
set {
_layoutTemplate = value;
RequiresControlsRecreation();
}
}
/// <devdoc>
/// Gets the style of the navigation buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_NavigationButtonStyle)
]
public Style NavigationButtonStyle {
get {
if (_navigationButtonStyle == null) {
_navigationButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_navigationButtonStyle).TrackViewState();
}
}
return _navigationButtonStyle;
}
}
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_NavigationStyle)
]
public TableItemStyle NavigationStyle {
get {
if (_navigationStyle == null) {
_navigationStyle = new TableItemStyle();
if (IsTrackingViewState)
((IStateManager)_navigationStyle).TrackViewState();
}
return _navigationStyle;
}
}
/// <devdoc>
/// Gets or sets the URL of an image to be displayed for the finish step's previous button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_StartNextButtonImageUrl),
UrlProperty(),
]
public virtual string StartNextButtonImageUrl {
get {
object obj = ViewState["StartNextButtonImageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["StartNextButtonImageUrl"] = value;
}
}
/// <devdoc>
/// Gets the style of the navigation buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_StartNextButtonStyle)
]
public Style StartNextButtonStyle {
get {
if (_startNextButtonStyle == null) {
_startNextButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_startNextButtonStyle).TrackViewState();
}
}
return _startNextButtonStyle;
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_StepNextButtonText),
WebSysDescription(SR.Wizard_StartNextButtonText)
]
public virtual String StartNextButtonText {
get {
string s = ViewState["StartNextButtonText"] as String;
return s == null ? SR.GetString(SR.Wizard_Default_StepNextButtonText) : s;
}
set {
ViewState["StartNextButtonText"] = value;
}
}
[
WebCategory("Appearance"),
DefaultValue(ButtonType.Button),
WebSysDescription(SR.Wizard_StartNextButtonType)
]
public virtual ButtonType StartNextButtonType {
get {
object obj = ViewState["StartNextButtonType"];
return (obj == null) ? ButtonType.Button : (ButtonType)obj;
}
set {
ValidateButtonType(value);
ViewState["StartNextButtonType"] = value;
}
}
/// <devdoc>
/// Gets or sets the URL of an image to be displayed for the next button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_StepNextButtonImageUrl),
UrlProperty(),
]
public virtual string StepNextButtonImageUrl {
get {
object obj = ViewState["StepNextButtonImageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["StepNextButtonImageUrl"] = value;
}
}
/// <devdoc>
/// Gets the style of the navigation buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_StepNextButtonStyle)
]
public Style StepNextButtonStyle {
get {
if (_stepNextButtonStyle == null) {
_stepNextButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_stepNextButtonStyle).TrackViewState();
}
}
return _stepNextButtonStyle;
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_StepNextButtonText),
WebSysDescription(SR.Wizard_StepNextButtonText)
]
public virtual String StepNextButtonText {
get {
string s = ViewState["StepNextButtonText"] as String;
return s == null ? SR.GetString(SR.Wizard_Default_StepNextButtonText) : s;
}
set {
ViewState["StepNextButtonText"] = value;
}
}
[
WebCategory("Appearance"),
DefaultValue(ButtonType.Button),
WebSysDescription(SR.Wizard_StepNextButtonType)
]
public virtual ButtonType StepNextButtonType {
get {
object obj = ViewState["StepNextButtonType"];
return (obj == null) ? ButtonType.Button : (ButtonType)obj;
}
set {
ValidateButtonType(value);
ViewState["StepNextButtonType"] = value;
}
}
/// <devdoc>
/// Gets or sets the URL of an image to be displayed for the previous button.
/// </devdoc>
[
DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, " + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
WebCategory("Appearance"),
WebSysDescription(SR.Wizard_StepPreviousButtonImageUrl),
UrlProperty(),
]
public virtual string StepPreviousButtonImageUrl {
get {
object obj = ViewState["StepPreviousButtonImageUrl"];
return (obj == null) ? String.Empty : (string)obj;
}
set {
ViewState["StepPreviousButtonImageUrl"] = value;
}
}
/// <devdoc>
/// Gets the style of the navigation buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_StepPreviousButtonStyle)
]
public Style StepPreviousButtonStyle {
get {
if (_stepPreviousButtonStyle == null) {
_stepPreviousButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_stepPreviousButtonStyle).TrackViewState();
}
}
return _stepPreviousButtonStyle;
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_StepPreviousButtonText),
WebSysDescription(SR.Wizard_StepPreviousButtonText)
]
public virtual String StepPreviousButtonText {
get {
string s = ViewState["StepPreviousButtonText"] as String;
return s == null ? SR.GetString(SR.Wizard_Default_StepPreviousButtonText) : s;
}
set {
ViewState["StepPreviousButtonText"] = value;
}
}
[
WebCategory("Appearance"),
DefaultValue(ButtonType.Button),
WebSysDescription(SR.Wizard_StepPreviousButtonType)
]
public virtual ButtonType StepPreviousButtonType {
get {
object obj = ViewState["StepPreviousButtonType"];
return (obj == null) ? ButtonType.Button : (ButtonType)obj;
}
set {
ValidateButtonType(value);
ViewState["StepPreviousButtonType"] = value;
}
}
/// <devdoc>
/// Gets the style of the side bar buttons.
/// </devdoc>
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_SideBarButtonStyle)
]
public Style SideBarButtonStyle {
get {
if (_sideBarButtonStyle == null) {
_sideBarButtonStyle = new Style();
if (IsTrackingViewState) {
((IStateManager)_sideBarButtonStyle).TrackViewState();
}
}
return _sideBarButtonStyle;
}
}
[
WebCategory("Styles"),
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebSysDescription(SR.Wizard_SideBarStyle)
]
public TableItemStyle SideBarStyle {
get {
if (_sideBarStyle == null) {
_sideBarStyle = new TableItemStyle();
if (IsTrackingViewState)
((IStateManager)_sideBarStyle).TrackViewState();
}
return _sideBarStyle;
}
}
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(Wizard)),
WebSysDescription(SR.Wizard_SideBarTemplate)
]
public virtual ITemplate SideBarTemplate {
get {
return _sideBarTemplate;
}
set {
_sideBarTemplate = value;
_sideBarTableCell = null;
RequiresControlsRecreation();
}
}
[
Localizable(true),
WebCategory("Appearance"),
WebSysDefaultValue(SR.Wizard_Default_SkipToContentText),
WebSysDescription(SR.WebControl_SkipLinkText)
]
public virtual String SkipLinkText {
get {
string s = SkipLinkTextInternal;
return s == null ? SR.GetString(SR.Wizard_Default_SkipToContentText) : s;
}
set {
ViewState["SkipLinkText"] = value;
}
}
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(Wizard)),
WebSysDescription(SR.Wizard_StartNavigationTemplate)
]
public virtual ITemplate StartNavigationTemplate {
get {
return _startNavigationTemplate;
}
set {
_startNavigationTemplate = value;
RequiresControlsRecreation();
}
}
[
Browsable(false),
DefaultValue(null),
PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(Wizard)),
WebSysDescription(SR.Wizard_StepNavigationTemplate)
]
public virtual ITemplate StepNavigationTemplate {
get {
return _stepNavigationTemplate;
}
set {
_stepNavigationTemplate = value;
RequiresControlsRecreation();
}
}
[
DefaultValue(null),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
NotifyParentProperty(true),
PersistenceMode(PersistenceMode.InnerProperty),
WebCategory("Styles"),
WebSysDescription(SR.Wizard_StepStyle)
]
public TableItemStyle StepStyle {
get {
if (_stepStyle == null) {
_stepStyle = new TableItemStyle();
if (IsTrackingViewState)
((IStateManager)_stepStyle).TrackViewState();
}
return _stepStyle;
}
}
//
protected override HtmlTextWriterTag TagKey {
get {
return HtmlTextWriterTag.Table;
}
}
[
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
Editor("System.Web.UI.Design.WebControls.WizardStepCollectionEditor," + AssemblyRef.SystemDesign, typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.InnerProperty),
Themeable(false),
WebSysDescription(SR.Wizard_WizardSteps),
]
public virtual WizardStepCollection WizardSteps {
get {
if (_wizardStepCollection == null) {
_wizardStepCollection = new WizardStepCollection(this);
}
return _wizardStepCollection;
}
}
#endregion
#region Public Events
[
WebCategory("Action"),
WebSysDescription(SR.Wizard_ActiveStepChanged)
]
public event EventHandler ActiveStepChanged {
add {
Events.AddHandler(_eventActiveStepChanged, value);
}
remove {
Events.RemoveHandler(_eventActiveStepChanged, value);
}
}
[
WebCategory("Action"),
WebSysDescription(SR.Wizard_CancelButtonClick)
]
public event EventHandler CancelButtonClick {
add {
Events.AddHandler(_eventCancelButtonClick, value);
}
remove {
Events.RemoveHandler(_eventCancelButtonClick, value);
}
}
[
WebCategory("Action"),
WebSysDescription(SR.Wizard_FinishButtonClick)
]
public event WizardNavigationEventHandler FinishButtonClick {
add {
Events.AddHandler(_eventFinishButtonClick, value);
}
remove {
Events.RemoveHandler(_eventFinishButtonClick, value);
}
}
[
WebCategory("Action"),
WebSysDescription(SR.Wizard_NextButtonClick)
]
public event WizardNavigationEventHandler NextButtonClick {
add {
Events.AddHandler(_eventNextButtonClick, value);
}
remove {
Events.RemoveHandler(_eventNextButtonClick, value);
}
}
[
WebCategory("Action"),
WebSysDescription(SR.Wizard_PreviousButtonClick)
]
public event WizardNavigationEventHandler PreviousButtonClick {
add {
Events.AddHandler(_eventPreviousButtonClick, value);
}
remove {
Events.RemoveHandler(_eventPreviousButtonClick, value);
}
}
[
WebCategory("Action"),
WebSysDescription(SR.Wizard_SideBarButtonClick)
]
public virtual event WizardNavigationEventHandler SideBarButtonClick {
add {
Events.AddHandler(_eventSideBarButtonClick, value);
}
remove {
Events.RemoveHandler(_eventSideBarButtonClick, value);
}
}
#endregion
#region Internal Properties
internal Dictionary<WizardStepBase, BaseNavigationTemplateContainer> CustomNavigationContainers {
get {
if (_customNavigationContainers == null) {
_customNavigationContainers = new Dictionary<WizardStepBase, BaseNavigationTemplateContainer>();
}
return _customNavigationContainers;
}
}
private ITemplate CustomNavigationTemplate {
get {
var templatedActiveStep = ActiveStep as TemplatedWizardStep;
return templatedActiveStep == null ? null : templatedActiveStep.CustomNavigationTemplate;
}
}
private Stack<int> History {
get {
if (_historyStack == null)
_historyStack = new Stack<int>();
return _historyStack;
}
}
private bool IsMacIE5 {
get {
if (!_isMacIE.HasValue && !DesignMode) {
HttpBrowserCapabilities browser = null;
if (Page != null) {
browser = Page.Request.Browser;
} else {
HttpContext context = HttpContext.Current;
// Context could be null if this control is created by the parser at designtime
if (context != null) {
browser = context.Request.Browser;
}
}
_isMacIE = (browser != null && browser.Type == "IE5" && browser.Platform == "MacPPC");
}
return _isMacIE.Value;
}
}
internal MultiView MultiView {
get {
if (_multiView == null) {
_multiView = new MultiView();
_multiView.EnableTheming = true;
_multiView.ID = _multiViewID;
_multiView.ActiveViewChanged += new EventHandler(this.MultiViewActiveViewChanged);
_multiView.IgnoreBubbleEvents();
}
return _multiView;
}
}
internal virtual bool ShowCustomNavigationTemplate {
get {
return CustomNavigationTemplate != null;
}
}
internal bool ShouldRenderChildControl {
get {
if (!DesignMode) {
return true;
}
if (_designModeState == null) {
return true;
}
object o = _designModeState["ShouldRenderWizardSteps"];
return o == null ? true : (bool)o;
}
}
private IWizardSideBarListControl SideBarList {
get { return _sideBarList; }
}
private bool SideBarEnabled {
get {
return _sideBarList != null && DisplaySideBar;
}
}
internal string SkipLinkTextInternal {
get {
return ViewState["SkipLinkText"] as String;
}
}
internal List<TemplatedWizardStep> TemplatedSteps {
get {
if (_templatedSteps == null) {
_templatedSteps = new List<TemplatedWizardStep>();
}
return _templatedSteps;
}
}
#endregion
private void MultiViewActiveViewChanged(object source, EventArgs e) {
OnActiveStepChanged(this, EventArgs.Empty);
}
private void ApplyControlProperties() {
_rendering.ApplyControlProperties();
}
internal BaseNavigationTemplateContainer CreateBaseNavigationTemplateContainer(string id) {
return new BaseNavigationTemplateContainer(this) {
ID = id
};
}
/// <internalonly />
protected internal override void CreateChildControls() {
using (new WizardControlCollectionModifier(this)) {
Controls.Clear();
_customNavigationContainers = null;
}
if (LayoutTemplate == null) {
_rendering = CreateTableRendering();
}
else {
_rendering = CreateLayoutTemplateRendering();
}
CreateControlHierarchy();
ClearChildViewState();
}
internal virtual TableWizardRendering CreateTableRendering() {
return new TableWizardRendering(this);
}
internal virtual LayoutTemplateWizardRendering CreateLayoutTemplateRendering() {
return new LayoutTemplateWizardRendering(this);
}
protected override ControlCollection CreateControlCollection() {
return new WizardControlCollection(this);
}
protected virtual void CreateControlHierarchy() {
_rendering.CreateControlHierarchy();
}
private void SetStepsAndDataBindSideBarList(IWizardSideBarListControl sideBarList) {
if (sideBarList != null) {
sideBarList.DataSource = WizardSteps;
sideBarList.SelectedIndex = ActiveStepIndex;
sideBarList.DataBind();
}
}
internal virtual ITemplate CreateDefaultSideBarTemplate() {
return new DefaultSideBarTemplate(this);
}
internal virtual ITemplate CreateDefaultDataListItemTemplate() {
return new DataListItemTemplate(this);
}
/// <internalonly/>
/// <devdoc>
/// <para>A protected method. Creates a table control style.</para>
/// </devdoc>
protected override Style CreateControlStyle() {
TableStyle controlStyle = new TableStyle();
// initialize defaults that are different from TableStyle
controlStyle.CellSpacing = 0;
controlStyle.CellPadding = 0;
return controlStyle;
}
internal virtual void CreateCustomNavigationTemplates() {
for (int i = 0; i < WizardSteps.Count; ++i) {
TemplatedWizardStep step = WizardSteps[i] as TemplatedWizardStep;
if (step != null) {
RegisterCustomNavigationContainers(step);
}
}
}
internal void RegisterCustomNavigationContainers(TemplatedWizardStep step) {
// Instantiate the step's ContentTemplate
InstantiateStepContentTemplate(step);
if (!CustomNavigationContainers.ContainsKey(step)) {
BaseNavigationTemplateContainer container = null;
string id = GetCustomContainerID(WizardSteps.IndexOf(step));
if (step.CustomNavigationTemplate != null) {
container = CreateBaseNavigationTemplateContainer(id);
step.CustomNavigationTemplate.InstantiateIn(container);
step.CustomNavigationTemplateContainer = container;
container.RegisterButtonCommandEvents();
} else {
container = CreateBaseNavigationTemplateContainer(id);
container.RegisterButtonCommandEvents();
}
CustomNavigationContainers[step] = container;
}
}
internal virtual void DataListItemDataBound(object sender, WizardSideBarListControlItemEventArgs e) {
var dataListItem = e.Item;
// Ignore the item that is not created from DataSource
if (dataListItem.ItemType != ListItemType.Item &&
dataListItem.ItemType != ListItemType.AlternatingItem &&
dataListItem.ItemType != ListItemType.SelectedItem &&
dataListItem.ItemType != ListItemType.EditItem) {
return;
}
IButtonControl button = dataListItem.FindControl(SideBarButtonID) as IButtonControl;
if (button == null) {
if (!DesignMode) {
throw new InvalidOperationException(
SR.GetString(SR.Wizard_SideBar_Button_Not_Found, DataListID, SideBarButtonID));
}
return;
}
var ctrlButton = button as Button;
if (ctrlButton != null) {
// Use javascript submit to use the postdata instead, this is necessarily since the buttons could be recreated during DataBind(). Previously
// registered buttons will lose their parents and events won't bubble up. VSWhidbey 120640.
// For devices that do not support Javascript, fall back to sumit behavior VSWhidbey 154576
ctrlButton.UseSubmitBehavior = false;
}
WebControl webCtrlButton = button as WebControl;
if (webCtrlButton != null) {
webCtrlButton.TabIndex = this.TabIndex;
}
int index = 0;
// Render wizardstep title on the button control.
WizardStepBase step = dataListItem.DataItem as WizardStepBase;
if (step != null) {
// Disable the button if it's a Complete step.
if (GetStepType(step) == WizardStepType.Complete &&
webCtrlButton != null) {
webCtrlButton.Enabled = false;
}
// Need to render the sidebar tablecell.
RegisterSideBarDataListForRender();
// Use the step title if defined, otherwise use ID
if (step.Title.Length > 0) {
button.Text = step.Title;
} else {
button.Text = step.ID;
}
index = WizardSteps.IndexOf(step);
button.CommandName = MoveToCommandName;
button.CommandArgument = index.ToString(NumberFormatInfo.InvariantInfo);
RegisterCommandEvents(button);
}
}
internal void RegisterSideBarDataListForRender() {
_renderSideBarDataList = true;
}
private void DataListItemCommand(object sender, CommandEventArgs e) {
if (!MoveToCommandName.Equals(e.CommandName, StringComparison.OrdinalIgnoreCase)) {
return;
}
int oldIndex = ActiveStepIndex;
int newIndex = Int32.Parse((String)e.CommandArgument, CultureInfo.InvariantCulture);
WizardNavigationEventArgs args = new WizardNavigationEventArgs(oldIndex, newIndex);
// Never cancel the item command at design time.
if (_commandSender != null && !DesignMode && Page != null && !Page.IsValid) {
args.Cancel = true;
}
_activeStepIndexSet = false;
OnSideBarButtonClick(args);
if (!args.Cancel) {
// Honor user's change if activeStepIndex is set explicitely;
if (!_activeStepIndexSet) {
if (AllowNavigationToStep(newIndex)) {
ActiveStepIndex = newIndex;
}
}
} else {
// revert active step if it's cancelled.
ActiveStepIndex = oldIndex;
}
}
internal static string GetCustomContainerID(int index) {
return _customNavigationContainerIdPrefix + index;
}
/// <internalonly/>
[SecurityPermission(SecurityAction.Demand, Unrestricted = true)]
protected override IDictionary GetDesignModeState() {
IDictionary dictionary = base.GetDesignModeState();
Debug.Assert(dictionary != null && DesignMode);
_designModeState = dictionary;
int oldIndex = ActiveStepIndex;
// Set the activestepindex to 0 in designmode if it's -1.
try {
if (oldIndex == -1 && WizardSteps.Count > 0) {
ActiveStepIndex = 0;
}
RequiresControlsRecreation();
EnsureChildControls();
ApplyControlProperties();
_rendering.SetDesignModeState(dictionary);
if (ShowCustomNavigationTemplate) {
BaseNavigationTemplateContainer customContainer = CustomNavigationContainers[ActiveStep];
dictionary[CustomNextButtonID] = customContainer.NextButton;
dictionary[CustomPreviousButtonID] = customContainer.PreviousButton;
dictionary[CustomFinishButtonID] = customContainer.FinishButton;
dictionary[CancelButtonID] = customContainer.CancelButton;
dictionary[_customNavigationControls] = customContainer.Controls;
}
// VSWhidbey 456506. Reset the ItemTemplate so it can be persisted correctly
// based on current SideBarButtonStyle
if (SideBarTemplate == null && _sideBarList != null) {
_sideBarList.ItemTemplate = CreateDefaultDataListItemTemplate();
}
dictionary[DataListID] = _sideBarList;
dictionary[_templatedStepsID] = TemplatedSteps;
} finally {
ActiveStepIndex = oldIndex;
}
return dictionary;
}
public ICollection GetHistory() {
ArrayList list = new ArrayList();
foreach (int index in History) {
list.Add(WizardSteps[index]);
}
return list;
}
internal int GetPreviousStepIndex(bool popStack) {
int previousIndex = -1;
int index = ActiveStepIndex;
if (_historyStack == null || _historyStack.Count == 0) {
return previousIndex;
}
if (popStack) {
previousIndex = _historyStack.Pop();
// Ignore the current step, the current step index is already in the historyStack.
if (previousIndex == index && _historyStack.Count > 0) {
previousIndex = _historyStack.Pop();
}
} else {
previousIndex = _historyStack.Peek();
// Ignore the current step, the current step index is already in the historyStack.
if (previousIndex == index && _historyStack.Count > 1) {
int originalIndex = _historyStack.Pop();
previousIndex = _historyStack.Peek();
_historyStack.Push(originalIndex);
}
}
// Return -1 if the current step is same as previous step
if (previousIndex == index) {
return -1;
}
return previousIndex;
}
private WizardStepType GetStepType(int index) {
Debug.Assert(index > -1 && index < WizardSteps.Count);
WizardStepBase step = WizardSteps[index] as WizardStepBase;
return GetStepType(step, index);
}
private WizardStepType GetStepType(WizardStepBase step) {
int index = WizardSteps.IndexOf(step);
return GetStepType(step, index);
}
public WizardStepType GetStepType(WizardStepBase wizardStep, int index) {
if (wizardStep.StepType == WizardStepType.Auto) {
// If it's the only step or a Complete step is after current step, then make it Finish step
if (WizardSteps.Count == 1 ||
(index < WizardSteps.Count - 1 &&
WizardSteps[index + 1].StepType == WizardStepType.Complete)) {
return WizardStepType.Finish;
}
// First one is the start step
if (index == 0) {
return WizardStepType.Start;
}
// Last one is the finish step
if (index == WizardSteps.Count - 1) {
return WizardStepType.Finish;
}
return WizardStepType.Step;
}
return wizardStep.StepType;
}
/// <devdoc>
/// Instantiates all the content templates for each TemplatedWizardStep
/// </devdoc>
internal virtual void InstantiateStepContentTemplates() {
TemplatedSteps.ForEach(step => InstantiateStepContentTemplate(step));
}
internal void InstantiateStepContentTemplate(TemplatedWizardStep step) {
step.Controls.Clear();
BaseContentTemplateContainer container = new BaseContentTemplateContainer(this, true);
ITemplate contentTemplate = step.ContentTemplate;
if (contentTemplate != null) {
container.SetEnableTheming();
contentTemplate.InstantiateIn(container.InnerCell);
}
step.ContentTemplateContainer = container;
step.Controls.Add(container);
}
/// <devdoc>
/// <para>Loads the control state.</para>
/// </devdoc>
protected internal override void LoadControlState(object state) {
Triplet t = state as Triplet;
if (t != null) {
base.LoadControlState(t.First);
Array collection = t.Second as Array;
if (collection != null) {
Array.Reverse(collection);
_historyStack = new Stack<int>(collection.Cast<int>());
}
ActiveStepIndex = (int)t.Third;
}
}
protected override void LoadViewState(object savedState) {
if (savedState == null) {
base.LoadViewState(null);
} else {
object[] myState = (object[])savedState;
if (myState.Length != _viewStateArrayLength) {
throw new ArgumentException(SR.GetString(SR.ViewState_InvalidViewState));
}
base.LoadViewState(myState[0]);
if (myState[1] != null)
((IStateManager)NavigationButtonStyle).LoadViewState(myState[1]);
if (myState[2] != null)
((IStateManager)SideBarButtonStyle).LoadViewState(myState[2]);
if (myState[3] != null)
((IStateManager)HeaderStyle).LoadViewState(myState[3]);
if (myState[4] != null)
((IStateManager)NavigationStyle).LoadViewState(myState[4]);
if (myState[5] != null)
((IStateManager)SideBarStyle).LoadViewState(myState[5]);
if (myState[6] != null)
((IStateManager)StepStyle).LoadViewState(myState[6]);
if (myState[7] != null)
((IStateManager)StartNextButtonStyle).LoadViewState(myState[7]);
if (myState[8] != null)
((IStateManager)StepNextButtonStyle).LoadViewState(myState[8]);
if (myState[9] != null)
((IStateManager)StepPreviousButtonStyle).LoadViewState(myState[9]);
if (myState[10] != null)
((IStateManager)FinishPreviousButtonStyle).LoadViewState(myState[10]);
if (myState[11] != null)
((IStateManager)FinishCompleteButtonStyle).LoadViewState(myState[11]);
if (myState[12] != null)
((IStateManager)CancelButtonStyle).LoadViewState(myState[12]);
if (myState[13] != null)
((IStateManager)ControlStyle).LoadViewState(myState[13]);
if (myState[14] != null)
DisplaySideBar = (bool)myState[14];
}
}
public void MoveTo(WizardStepBase wizardStep) {
if (wizardStep == null)
throw new ArgumentNullException("wizardStep");
int index = WizardSteps.IndexOf(wizardStep);
if (index == -1) {
throw new ArgumentException(SR.GetString(SR.Wizard_Step_Not_In_Wizard));
}
ActiveStepIndex = index;
}
protected virtual void OnActiveStepChanged(object source, EventArgs e) {
EventHandler handler = (EventHandler)Events[_eventActiveStepChanged];
if (handler != null) handler(this, e);
}
protected override bool OnBubbleEvent(object source, EventArgs e) {
bool handled = false;
CommandEventArgs ce = e as CommandEventArgs;
if (ce != null) {
if (String.Equals(CancelCommandName, ce.CommandName, StringComparison.OrdinalIgnoreCase)) {
OnCancelButtonClick(EventArgs.Empty);
return true;
}
int oldIndex = ActiveStepIndex;
int newIndex = oldIndex;
// Check if we need to validate the bubble commands VSWhidbey 312445
bool verifyEvent = true;
WizardStepType stepType = WizardStepType.Auto;
WizardStepBase step = WizardSteps[oldIndex];
// Don't validate commands if it's a templated wizard step
if (step is TemplatedWizardStep) {
verifyEvent = false;
} else {
stepType = GetStepType(step);
}
WizardNavigationEventArgs args = new WizardNavigationEventArgs(oldIndex, newIndex);
// Do not navigate away from current view if view is not valid.
if (_commandSender != null && Page != null && !Page.IsValid) {
args.Cancel = true;
}
bool previousButtonCommand = false;
_activeStepIndexSet = false;
if (String.Equals(MoveNextCommandName, ce.CommandName, StringComparison.OrdinalIgnoreCase)) {
if (verifyEvent) {
if (stepType != WizardStepType.Start && stepType != WizardStepType.Step) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_InvalidBubbleEvent, MoveNextCommandName));
}
}
if (oldIndex < WizardSteps.Count - 1) {
args.SetNextStepIndex(oldIndex + 1);
}
OnNextButtonClick(args);
handled = true;
} else if (String.Equals(MovePreviousCommandName, ce.CommandName, StringComparison.OrdinalIgnoreCase)) {
if (verifyEvent) {
if (stepType != WizardStepType.Step && stepType != WizardStepType.Finish) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_InvalidBubbleEvent, MovePreviousCommandName));
}
}
previousButtonCommand = true;
int previousIndex = GetPreviousStepIndex(false);
if (previousIndex != -1) {
args.SetNextStepIndex(previousIndex);
}
OnPreviousButtonClick(args);
handled = true;
} else if (String.Equals(MoveCompleteCommandName, ce.CommandName, StringComparison.OrdinalIgnoreCase)) {
if (verifyEvent) {
if (stepType != WizardStepType.Finish) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_InvalidBubbleEvent, MoveCompleteCommandName));
}
}
if (oldIndex < WizardSteps.Count - 1) {
args.SetNextStepIndex(oldIndex + 1);
}
OnFinishButtonClick(args);
handled = true;
} else if (String.Equals(MoveToCommandName, ce.CommandName, StringComparison.OrdinalIgnoreCase)) {
newIndex = Int32.Parse((String)ce.CommandArgument, CultureInfo.InvariantCulture);
args.SetNextStepIndex(newIndex);
handled = true;
}
if (handled) {
if (!args.Cancel) {
// Honor user's change if activeStepIndex is set explicitely;
if (!_activeStepIndexSet) {
// Make sure the next step is valid to navigate to
if (AllowNavigationToStep(args.NextStepIndex)) {
if (previousButtonCommand) {
GetPreviousStepIndex(true);
}
ActiveStepIndex = args.NextStepIndex;
}
}
} else {
// revert active step if it's cancelled.
ActiveStepIndex = oldIndex;
}
}
}
return handled;
}
internal void OnWizardStepsChanged() {
SetStepsAndDataBindSideBarList(_sideBarList);
}
protected virtual bool AllowNavigationToStep(int index) {
if (_historyStack != null && _historyStack.Contains(index)) {
return WizardSteps[index].AllowReturn;
}
return true;
}
protected virtual void OnCancelButtonClick(EventArgs e) {
EventHandler handler = (EventHandler)Events[_eventCancelButtonClick];
if (handler != null) {
handler(this, e);
}
string cancelDestinationUrl = CancelDestinationPageUrl;
if (!String.IsNullOrEmpty(cancelDestinationUrl)) {
Page.Response.Redirect(ResolveClientUrl(cancelDestinationUrl), false);
}
}
private void OnCommand(object sender, CommandEventArgs e) {
Debug.Assert(_commandSender == null);
_commandSender = sender as IButtonControl;
}
protected virtual void OnFinishButtonClick(WizardNavigationEventArgs e) {
WizardNavigationEventHandler handler = (WizardNavigationEventHandler)Events[_eventFinishButtonClick];
if (handler != null) handler(this, e);
string finishPageUrl = FinishDestinationPageUrl;
if (!String.IsNullOrEmpty(finishPageUrl)) {
// Microsoft suggested that we should not terminate execution of current page, to give
// page a chance to cleanup its resources. This may be less performant though.
// Microsoft suggested that we need to call ResolveClientUrl before redirecting.
// Example is this control inside user control, want redirect relative to user control dir.
Page.Response.Redirect(ResolveClientUrl(finishPageUrl), false);
}
}
protected internal override void OnInit(EventArgs e) {
base.OnInit(e);
// Always set the current step to the first step if not specified.
if (ActiveStepIndex == -1 && WizardSteps.Count > 0 && !DesignMode) {
ActiveStepIndex = 0;
}
// Add default control layout during OnInit to track WizardStep viewstate properly.
EnsureChildControls();
if (Page != null) {
Page.RegisterRequiresControlState(this);
}
}
protected virtual void OnNextButtonClick(WizardNavigationEventArgs e) {
WizardNavigationEventHandler handler = (WizardNavigationEventHandler)Events[_eventNextButtonClick];
if (handler != null) handler(this, e);
}
protected virtual void OnPreviousButtonClick(WizardNavigationEventArgs e) {
WizardNavigationEventHandler handler = (WizardNavigationEventHandler)Events[_eventPreviousButtonClick];
if (handler != null) handler(this, e);
}
protected virtual void OnSideBarButtonClick(WizardNavigationEventArgs e) {
WizardNavigationEventHandler handler = (WizardNavigationEventHandler)Events[_eventSideBarButtonClick];
if (handler != null) handler(this, e);
}
internal void RequiresControlsRecreation() {
if (ChildControlsCreated) {
using (new WizardControlCollectionModifier(this)) {
base.ChildControlsCreated = false;
}
_rendering = null;
}
}
protected internal void RegisterCommandEvents(IButtonControl button) {
if (button != null && button.CausesValidation) {
button.Command += new CommandEventHandler(this.OnCommand);
}
}
protected internal override void Render(HtmlTextWriter writer) {
// Make sure we're in runat=server form.
if (Page != null) {
Page.VerifyRenderingInServerForm(this);
}
EnsureChildControls();
ApplyControlProperties();
// Nothing to do if the Wizard is empty;
if (ActiveStepIndex == -1 || WizardSteps.Count == 0) {
return;
}
RenderContents(writer);
}
protected internal override object SaveControlState() {
int activeStepIndex = ActiveStepIndex;
// Save the ActiveStepIndex here so steps dynamically added
// before or during OnPagePreRenderComplete will be tracked
// properly. See VSWhidbey 395312
if (_historyStack == null || _historyStack.Count == 0 ||
_historyStack.Peek() != activeStepIndex) {
// Remember the active step.
History.Push(ActiveStepIndex);
}
object obj = base.SaveControlState();
bool containsHistory = _historyStack != null && _historyStack.Count > 0;
if (obj != null || containsHistory || activeStepIndex != -1) {
object array = containsHistory ? _historyStack.ToArray() : null;
return new Triplet(obj, array, activeStepIndex);
}
return null;
}
protected override object SaveViewState() {
object[] myState = new object[_viewStateArrayLength];
Debug.Assert(_viewStateArrayLength == 15, "Forgot to change array length when adding new item to view state?");
myState[0] = base.SaveViewState();
myState[1] = (_navigationButtonStyle != null) ? ((IStateManager)_navigationButtonStyle).SaveViewState() : null;
myState[2] = (_sideBarButtonStyle != null) ? ((IStateManager)_sideBarButtonStyle).SaveViewState() : null;
myState[3] = (_headerStyle != null) ? ((IStateManager)_headerStyle).SaveViewState() : null;
myState[4] = (_navigationStyle != null) ? ((IStateManager)_navigationStyle).SaveViewState() : null;
myState[5] = (_sideBarStyle != null) ? ((IStateManager)_sideBarStyle).SaveViewState() : null;
myState[6] = (_stepStyle != null) ? ((IStateManager)_stepStyle).SaveViewState() : null;
myState[7] = (_startNextButtonStyle != null) ? ((IStateManager)_startNextButtonStyle).SaveViewState() : null;
myState[8] = (_stepNextButtonStyle != null) ? ((IStateManager)_stepNextButtonStyle).SaveViewState() : null;
myState[9] = (_stepPreviousButtonStyle != null) ? ((IStateManager)_stepPreviousButtonStyle).SaveViewState() : null;
myState[10] = (_finishPreviousButtonStyle != null) ? ((IStateManager)_finishPreviousButtonStyle).SaveViewState() : null;
myState[11] = (_finishCompleteButtonStyle != null) ? ((IStateManager)_finishCompleteButtonStyle).SaveViewState() : null;
myState[12] = (_cancelButtonStyle != null) ? ((IStateManager)_cancelButtonStyle).SaveViewState() : null;
myState[13] = ControlStyleCreated ? ((IStateManager)ControlStyle).SaveViewState() : null;
if (DisplaySideBar != _displaySideBarDefault) {
myState[14] = DisplaySideBar;
}
for (int i = 0; i < _viewStateArrayLength; i++) {
if (myState[i] != null) {
return myState;
}
}
// More performant to return null than an array of null values
return null;
}
private void SetCancelButtonVisibility(BaseNavigationTemplateContainer container) {
// Make the parent TD invisible if possible.
Control c = container.CancelButton as Control;
if (c != null) {
Control parent = c.Parent;
if (parent != null) {
Debug.Assert(parent is TableCell);
parent.Visible = DisplayCancelButton;
}
c.Visible = DisplayCancelButton;
}
}
protected override void TrackViewState() {
base.TrackViewState();
if (_navigationButtonStyle != null)
((IStateManager)_navigationButtonStyle).TrackViewState();
if (_sideBarButtonStyle != null)
((IStateManager)_sideBarButtonStyle).TrackViewState();
if (_headerStyle != null)
((IStateManager)_headerStyle).TrackViewState();
if (_navigationStyle != null)
((IStateManager)_navigationStyle).TrackViewState();
if (_sideBarStyle != null)
((IStateManager)_sideBarStyle).TrackViewState();
if (_stepStyle != null)
((IStateManager)_stepStyle).TrackViewState();
if (_startNextButtonStyle != null)
((IStateManager)_startNextButtonStyle).TrackViewState();
if (_stepPreviousButtonStyle != null)
((IStateManager)_stepPreviousButtonStyle).TrackViewState();
if (_stepNextButtonStyle != null)
((IStateManager)_stepNextButtonStyle).TrackViewState();
if (_finishPreviousButtonStyle != null)
((IStateManager)_finishPreviousButtonStyle).TrackViewState();
if (_finishCompleteButtonStyle != null)
((IStateManager)_finishCompleteButtonStyle).TrackViewState();
if (_cancelButtonStyle != null)
((IStateManager)_cancelButtonStyle).TrackViewState();
if (ControlStyleCreated) {
((IStateManager)ControlStyle).TrackViewState();
}
}
private static void ValidateButtonType(ButtonType value) {
if (value < ButtonType.Button || value > ButtonType.Link) {
throw new ArgumentOutOfRangeException("value");
}
}
#region Rendering Abstractions
internal abstract class WizardRenderingBase {
private const string _startNavigationTemplateContainerID = "StartNavigationTemplateContainerID";
private const string _stepNavigationTemplateContainerID = "StepNavigationTemplateContainerID";
private const string _finishNavigationTemplateContainerID = "FinishNavigationTemplateContainerID";
private NavigationTemplate _defaultStartNavigationTemplate;
private NavigationTemplate _defaultStepNavigationTemplate;
private NavigationTemplate _defaultFinishNavigationTemplate;
protected BaseNavigationTemplateContainer _finishNavigationTemplateContainer;
protected BaseNavigationTemplateContainer _startNavigationTemplateContainer;
protected BaseNavigationTemplateContainer _stepNavigationTemplateContainer;
protected Wizard Owner { get; private set; }
protected WizardRenderingBase(Wizard wizard) {
Owner = wizard;
}
public abstract void ApplyControlProperties();
public abstract void CreateControlHierarchy();
public virtual void SetDesignModeState(IDictionary dictionary) {
if (_startNavigationTemplateContainer != null) {
dictionary[StartNextButtonID] = _startNavigationTemplateContainer.NextButton;
dictionary[CancelButtonID] = _startNavigationTemplateContainer.CancelButton;
}
if (_stepNavigationTemplateContainer != null) {
dictionary[StepNextButtonID] = _stepNavigationTemplateContainer.NextButton;
dictionary[StepPreviousButtonID] = _stepNavigationTemplateContainer.PreviousButton;
dictionary[CancelButtonID] = _stepNavigationTemplateContainer.CancelButton;
}
if (_finishNavigationTemplateContainer != null) {
dictionary[FinishPreviousButtonID] = _finishNavigationTemplateContainer.PreviousButton;
dictionary[FinishButtonID] = _finishNavigationTemplateContainer.FinishButton;
dictionary[CancelButtonID] = _finishNavigationTemplateContainer.CancelButton;
}
}
protected void ApplyControlProperties_Sidebar() {
if (Owner.SideBarEnabled) {
Owner.SetStepsAndDataBindSideBarList(Owner._sideBarList);
// Only apply the styles to the sidebar or sidebar buttons if custom template is not used.
if (Owner.SideBarTemplate == null) {
foreach (Control item in Owner._sideBarList.Items) {
WebControl button = item.FindControl(SideBarButtonID) as WebControl;
if (button != null) {
button.MergeStyle(Owner._sideBarButtonStyle);
}
}
}
}
}
protected void ApplyNavigationTemplateProperties() {
// Do not apply any template properties if the containers are null
// This happens when GetDesignModeState is called before child controls are created.
if (_finishNavigationTemplateContainer == null ||
_startNavigationTemplateContainer == null ||
_stepNavigationTemplateContainer == null) {
return;
}
WizardStepType renderType = WizardStepType.Start;
// Set the active templates based on ActiveStep
// Make sure the activestepindex is valid. // VSWhidbey 376438
if (Owner.ActiveStepIndex >= Owner.WizardSteps.Count || Owner.ActiveStepIndex < 0) {
return;
}
renderType = SetActiveTemplates();
bool requiresFinishPreviousButton =
renderType != WizardStepType.Finish || Owner.ActiveStepIndex != 0 || Owner.ActiveStep.StepType != WizardStepType.Auto;
ApplyDefaultStartNavigationTemplateProperties();
bool showPrevious = true;
int prevStepIndex = Owner.GetPreviousStepIndex(false);
if (prevStepIndex >= 0) {
showPrevious = Owner.WizardSteps[prevStepIndex].AllowReturn;
}
ApplyDefaultFinishNavigationTemplateProperties(showPrevious);
ApplyDefaultStepNavigationTemplateProperties(showPrevious);
// if the first step using auto type is assigned to a finish step, do not render the previous button's container.
if (!requiresFinishPreviousButton) {
Control ctrl = _finishNavigationTemplateContainer.PreviousButton as Control;
if (ctrl != null) {
if (Owner.FinishNavigationTemplate == null) {
ctrl.Parent.Visible = false;
} else {
ctrl.Visible = false;
}
}
}
}
private void ApplyDefaultStepNavigationTemplateProperties(bool previousImageButtonVisible) {
// Only apply properties to the default template (if a custom template has not been specified)
if (Owner.StepNavigationTemplate != null) {
return;
}
var navContainer = _stepNavigationTemplateContainer;
NavigationTemplate defaultTemplate = _defaultStepNavigationTemplate;
if (Owner.DesignMode) {
defaultTemplate.ResetButtonsVisibility();
}
navContainer.PreviousButton = defaultTemplate.FirstButton;
((Control)navContainer.PreviousButton).Visible = true;
navContainer.NextButton = defaultTemplate.SecondButton;
((Control)navContainer.NextButton).Visible = true;
navContainer.CancelButton = defaultTemplate.CancelButton;
ApplyButtonProperties(navContainer.NextButton, Owner.StepNextButtonText, Owner.StepNextButtonImageUrl);
ApplyButtonProperties(navContainer.PreviousButton, Owner.StepPreviousButtonText, Owner.StepPreviousButtonImageUrl, previousImageButtonVisible);
ApplyButtonProperties(navContainer.CancelButton, Owner.CancelButtonText, Owner.CancelButtonImageUrl);
int previousStepIndex = Owner.GetPreviousStepIndex(false);
if (previousStepIndex != -1 && !Owner.WizardSteps[previousStepIndex].AllowReturn) {
((Control)navContainer.PreviousButton).Visible = false;
}
Owner.SetCancelButtonVisibility(navContainer);
navContainer.ApplyButtonStyle(Owner.FinishCompleteButtonStyle, Owner.StepPreviousButtonStyle, Owner.StepNextButtonStyle, Owner.CancelButtonStyle);
}
private void ApplyDefaultFinishNavigationTemplateProperties(bool previousImageButtonVisible) {
// Only apply properties to the default template (if a custom template has not been specified)
if (Owner.FinishNavigationTemplate != null) {
return;
}
var finishContainer = _finishNavigationTemplateContainer;
NavigationTemplate defaultTemplate = _defaultFinishNavigationTemplate;
if (Owner.DesignMode) {
defaultTemplate.ResetButtonsVisibility();
}
finishContainer.PreviousButton = defaultTemplate.FirstButton;
((Control)finishContainer.PreviousButton).Visible = true;
finishContainer.FinishButton = defaultTemplate.SecondButton;
((Control)finishContainer.FinishButton).Visible = true;
finishContainer.CancelButton = defaultTemplate.CancelButton;
finishContainer.FinishButton.CommandName = MoveCompleteCommandName;
ApplyButtonProperties(finishContainer.FinishButton, Owner.FinishCompleteButtonText, Owner.FinishCompleteButtonImageUrl);
ApplyButtonProperties(finishContainer.PreviousButton, Owner.FinishPreviousButtonText, Owner.FinishPreviousButtonImageUrl, previousImageButtonVisible);
ApplyButtonProperties(finishContainer.CancelButton, Owner.CancelButtonText, Owner.CancelButtonImageUrl);
int previousStepIndex = Owner.GetPreviousStepIndex(false);
if (previousStepIndex != -1 && !Owner.WizardSteps[previousStepIndex].AllowReturn) {
((Control)finishContainer.PreviousButton).Visible = false;
}
Owner.SetCancelButtonVisibility(finishContainer);
finishContainer.ApplyButtonStyle(Owner.FinishCompleteButtonStyle, Owner.FinishPreviousButtonStyle, Owner.StepNextButtonStyle, Owner.CancelButtonStyle);
}
private void ApplyDefaultStartNavigationTemplateProperties() {
// Only apply properties to the default template (if a custom template has not been specified)
if (Owner.StartNavigationTemplate != null) {
return;
}
var startContainer = _startNavigationTemplateContainer;
NavigationTemplate defaultStartTemplate = _defaultStartNavigationTemplate;
if (Owner.DesignMode) {
defaultStartTemplate.ResetButtonsVisibility();
}
startContainer.NextButton = defaultStartTemplate.SecondButton;
((Control)startContainer.NextButton).Visible = true;
startContainer.CancelButton = defaultStartTemplate.CancelButton;
ApplyButtonProperties(startContainer.NextButton, Owner.StartNextButtonText, Owner.StartNextButtonImageUrl);
ApplyButtonProperties(startContainer.CancelButton, Owner.CancelButtonText, Owner.CancelButtonImageUrl);
Owner.SetCancelButtonVisibility(startContainer);
startContainer.ApplyButtonStyle(Owner.FinishCompleteButtonStyle, Owner.StepPreviousButtonStyle, Owner.StartNextButtonStyle, Owner.CancelButtonStyle);
}
protected virtual WizardStepType SetActiveTemplates() {
WizardStepType type = Owner.GetStepType(Owner.ActiveStepIndex);
_startNavigationTemplateContainer.Visible = (type == WizardStepType.Start);
_stepNavigationTemplateContainer.Visible = (type == WizardStepType.Step);
_finishNavigationTemplateContainer.Visible = (type == WizardStepType.Finish);
// Do not render header or sidebarlist in complete steps;
if (type == WizardStepType.Complete) {
OnlyShowCompleteStep();
}
return type;
}
private static void ApplyButtonProperties(IButtonControl button, string text, string imageUrl) {
ApplyButtonProperties(button, text, imageUrl, true);
}
private static void ApplyButtonProperties(IButtonControl button, string text, string imageUrl, bool imageButtonVisible) {
if (button == null) {
return;
}
ImageButton imageButton = button as ImageButton;
if (imageButton != null) {
imageButton.ImageUrl = imageUrl;
imageButton.AlternateText = text;
imageButton.Visible = imageButtonVisible;
} else {
button.Text = text;
}
}
public abstract void OnlyShowCompleteStep();
protected void ApplyCustomNavigationTemplateProperties() {
// Make all custom navigation containers invisible
foreach (BaseNavigationTemplateContainer c in Owner.CustomNavigationContainers.Values) {
c.Visible = false;
}
// If we are going to show a custom navigation template, make that one visible
if (Owner.ShowCustomNavigationTemplate) {
BaseNavigationTemplateContainer container = Owner._customNavigationContainers[Owner.ActiveStep];
container.Visible = true;
_startNavigationTemplateContainer.Visible = false;
_stepNavigationTemplateContainer.Visible = false;
_finishNavigationTemplateContainer.Visible = false;
}
}
protected void CreateControlHierarchy_CleanUpOldSideBarList(IWizardSideBarListControl sideBarList) {
// Remove obsolete events from sideBarDataList
if (sideBarList != null) {
sideBarList.ItemCommand -= new CommandEventHandler(Owner.DataListItemCommand);
sideBarList.ItemDataBound -= new EventHandler<WizardSideBarListControlItemEventArgs>(Owner.DataListItemDataBound);
}
}
protected IWizardSideBarListControl CreateControlHierarchy_SetUpSideBarList(Control sideBarContainer) {
var sideBarList = sideBarContainer.FindControl(DataListID) as IWizardSideBarListControl;
if (sideBarList != null) {
sideBarList.ItemCommand += new CommandEventHandler(Owner.DataListItemCommand);
sideBarList.ItemDataBound += new EventHandler<WizardSideBarListControlItemEventArgs>(Owner.DataListItemDataBound);
if (Owner.DesignMode) {
// This line is necessary for ListView to databind correctly to the list of steps when
// viewing the control on the design surface. ListView will not databind automatically when
// it is not a top-level control (as is the case here) unless the flag has a value.
((IControlDesignerAccessor)sideBarList).GetDesignModeState()["EnableDesignTimeDataBinding"] = true;
}
Owner.SetStepsAndDataBindSideBarList(sideBarList);
} else {
// Do not throw at designmode otherwise template will not be persisted correctly.
if (!Owner.DesignMode) {
throw new InvalidOperationException(
SR.GetString(SR.Wizard_DataList_Not_Found, DataListID));
}
}
return sideBarList;
}
// Helper method to create navigation templates.
protected void CreateNavigationControlHierarchy(Control container) {
container.Controls.Clear();
Owner.CustomNavigationContainers.Clear();
Owner.CreateCustomNavigationTemplates();
foreach (BaseNavigationTemplateContainer c in Owner.CustomNavigationContainers.Values) {
container.Controls.Add(c);
}
CreateStartNavigationTemplate(container);
CreateFinishNavigationTemplate(container);
CreateStepNavigationTemplate(container);
}
private void CreateStartNavigationTemplate(Control container) {
// Start navigation template
ITemplate startNavigationTemplate = Owner.StartNavigationTemplate;
_startNavigationTemplateContainer = new StartNavigationTemplateContainer(Owner);
_startNavigationTemplateContainer.ID = _startNavigationTemplateContainerID;
// Use the default template
if (startNavigationTemplate == null) {
_startNavigationTemplateContainer.EnableViewState = false;
_defaultStartNavigationTemplate = NavigationTemplate.GetDefaultStartNavigationTemplate(Owner);
startNavigationTemplate = _defaultStartNavigationTemplate;
} else {
// Custom template is used here.
_startNavigationTemplateContainer.SetEnableTheming();
}
startNavigationTemplate.InstantiateIn(_startNavigationTemplateContainer);
container.Controls.Add(_startNavigationTemplateContainer);
}
private void CreateStepNavigationTemplate(Control container) {
// step navigation template
ITemplate stepNavigationTemplate = Owner.StepNavigationTemplate;
_stepNavigationTemplateContainer = new StepNavigationTemplateContainer(Owner);
_stepNavigationTemplateContainer.ID = _stepNavigationTemplateContainerID;
if (stepNavigationTemplate == null) {
_stepNavigationTemplateContainer.EnableViewState = false;
_defaultStepNavigationTemplate = NavigationTemplate.GetDefaultStepNavigationTemplate(Owner);
stepNavigationTemplate = _defaultStepNavigationTemplate;
} else {
_stepNavigationTemplateContainer.SetEnableTheming();
}
stepNavigationTemplate.InstantiateIn(_stepNavigationTemplateContainer);
container.Controls.Add(_stepNavigationTemplateContainer);
}
private void CreateFinishNavigationTemplate(Control container) {
// finish navigation template
ITemplate finishNavigationTemplate = Owner.FinishNavigationTemplate;
_finishNavigationTemplateContainer = new FinishNavigationTemplateContainer(Owner);
_finishNavigationTemplateContainer.ID = _finishNavigationTemplateContainerID;
if (finishNavigationTemplate == null) {
_finishNavigationTemplateContainer.EnableViewState = false;
_defaultFinishNavigationTemplate = NavigationTemplate.GetDefaultFinishNavigationTemplate(Owner);
finishNavigationTemplate = _defaultFinishNavigationTemplate;
} else {
_finishNavigationTemplateContainer.SetEnableTheming();
}
finishNavigationTemplate.InstantiateIn(_finishNavigationTemplateContainer);
container.Controls.Add(_finishNavigationTemplateContainer);
}
}
internal class LayoutTemplateWizardRendering : WizardRenderingBase {
private Literal _headerLiteral;
private WizardContainer _layoutContainer;
public LayoutTemplateWizardRendering(Wizard wizard)
: base(wizard) {
}
public override void ApplyControlProperties() {
ApplyControlProperties_Header();
ApplyControlProperties_Sidebar();
// nothing interesting to apply to the wizard steps
ApplyControlProperties_Navigation();
}
private void ApplyControlProperties_Navigation() {
ApplyNavigationTemplateProperties();
ApplyCustomNavigationTemplateProperties();
}
private void ApplyControlProperties_Header() {
if (Owner.HeaderTemplate != null) {
// nothing to apply if there is a header template
return;
}
if (_headerLiteral != null) {
// not necessary to set the literal to not visible if the text is empty because a
// literal with empty text does not render anything
_headerLiteral.Text = Owner.HeaderText;
} else if (!String.IsNullOrEmpty(Owner.HeaderText)) {
// only throw if the headertext is set and there is no headerLiteral. This means
// that the layout template did not contain a header placeholder.
throw new InvalidOperationException(SR.GetString(SR.Wizard_Header_Placeholder_Must_Be_Specified_For_HeaderText, Owner.ID, HeaderPlaceholderId));
}
}
public override void OnlyShowCompleteStep() {
_layoutContainer.ControlToRender = Owner.MultiView;
}
public override void CreateControlHierarchy() {
_layoutContainer = new WizardContainer();
Owner.LayoutTemplate.InstantiateIn(_layoutContainer);
using (new WizardControlCollectionModifier(Owner)) {
Owner.Controls.Add(_layoutContainer);
}
CreateControlHierarchy_Header(_layoutContainer);
CreateControlHierarchy_SideBar(_layoutContainer);
CreateControlHierarchy_WizardStep(_layoutContainer);
CreateControlHierarchy_Navigation(_layoutContainer);
}
private void CreateControlHierarchy_Navigation(Control layoutContainer) {
var placeholder = layoutContainer.FindControl(NavigationPlaceholderId);
if (placeholder == null) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_Navigation_Placeholder_Must_Be_Specified, Owner.ID, NavigationPlaceholderId));
}
Control navigationContainer = new Control();
ReplacePlaceholderWithControl(layoutContainer, placeholder, navigationContainer);
CreateNavigationControlHierarchy(navigationContainer);
}
private void CreateControlHierarchy_Header(Control layoutContainer) {
var placeholder = layoutContainer.FindControl(HeaderPlaceholderId);
if (Owner.HeaderTemplate != null) {
if (placeholder == null) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_Header_Placeholder_Must_Be_Specified_For_HeaderTemplate, Owner.ID, HeaderPlaceholderId));
} else {
// just replace the placeholder with the template
ReplacePlaceholderWithTemplateInstance(layoutContainer, placeholder, Owner.HeaderTemplate);
}
} else if (placeholder != null) {
// only create a header literal if the template contains a placeholder
// if the template does not contain a placeholder an exception will be thrown from
// ApplyControlProperties
_headerLiteral = new Literal();
ReplacePlaceholderWithControl(layoutContainer, placeholder, _headerLiteral);
}
}
private void CreateControlHierarchy_SideBar(Control layoutContainer) {
if (!Owner.DisplaySideBar) {
// it's ok to exit here since changing the DisplaySideBar value would
// force a recreation of the control tree.
return;
}
var placeholder = layoutContainer.FindControl(SideBarPlaceholderId);
if (placeholder == null) {
//
throw new InvalidOperationException(SR.GetString(SR.Wizard_Sidebar_Placeholder_Must_Be_Specified, Owner.ID, SideBarPlaceholderId));
}
ITemplate sideBarTemplate = Owner.SideBarTemplate ?? Owner.CreateDefaultSideBarTemplate();
ReplacePlaceholderWithTemplateInstance(layoutContainer, placeholder, sideBarTemplate);
CreateControlHierarchy_CleanUpOldSideBarList(Owner.SideBarList);
Owner._sideBarList = CreateControlHierarchy_SetUpSideBarList(layoutContainer);
}
private void CreateControlHierarchy_WizardStep(Control layoutContainer) {
var placeholder = layoutContainer.FindControl(WizardStepPlaceholderId);
if (placeholder == null) {
throw new InvalidOperationException(SR.GetString(SR.Wizard_Step_Placeholder_Must_Be_Specified, Owner.ID, WizardStepPlaceholderId));
}
ReplacePlaceholderWithControl(layoutContainer, placeholder, Owner.MultiView);
}
private static void ReplacePlaceholderWithTemplateInstance(Control targetContainer, Control placeholder, ITemplate template) {
var templateContainer = new Control();
template.InstantiateIn(templateContainer);
ReplacePlaceholderWithControl(targetContainer, placeholder, templateContainer);
}
private static void ReplacePlaceholderWithControl(Control targetContainer, Control placeholder, Control replacement) {
var placeholderIndex = targetContainer.Controls.IndexOf(placeholder);
targetContainer.Controls.RemoveAt(placeholderIndex);
targetContainer.Controls.AddAt(placeholderIndex, replacement);
}
internal class WizardContainer : WebControl {
internal Control ControlToRender { get; set; }
protected internal override void Render(HtmlTextWriter writer) {
if (ControlToRender == null) {
RenderChildren(writer);
} else {
ControlToRender.Render(writer);
}
}
}
}
internal class TableWizardRendering : WizardRenderingBase {
private const string _headerCellID = "HeaderContainer";
private const string _sideBarCellID = "SideBarContainer";
private const string _stepTableCellID = "StepTableCell";
private TableCell _headerTableCell;
private TableRow _headerTableRow;
private TableRow _navigationRow;
private TableCell _navigationTableCell;
private Table _renderTable;
private TableCell _stepTableCell;
private LiteralControl _titleLiteral;
public TableWizardRendering(Wizard wizard)
: base(wizard) {
}
// Returns the cell which the navigation template container should be added to
private TableCell NavigationTableCell {
get {
if (_navigationTableCell == null) {
_navigationTableCell = new TableCell();
}
return _navigationTableCell;
}
}
public override void ApplyControlProperties() {
// Nothing to do if the Wizard is empty;
// Apply the control properties at designtime so that controls inside templates are styled properly.
if (!Owner.DesignMode &&
(Owner.ActiveStepIndex < 0 || Owner.ActiveStepIndex >= Owner.WizardSteps.Count || Owner.WizardSteps.Count == 0)) {
return;
}
if (Owner.SideBarEnabled && Owner._sideBarStyle != null) {
// Apply Sidebar style on the table cell VSWhidbey 377064
Owner._sideBarTableCell.ApplyStyle(Owner._sideBarStyle);
}
ApplyControlProperties_Header();
ApplyControlProperties_WizardSteps();
ApplyControlProperties_Navigation();
ApplyControlProperties_Sidebar();
if (_renderTable != null) {
// Clear out the accesskey/tab index so it doesn't get applied to the tables in the container
Util.CopyBaseAttributesToInnerControl(Owner, _renderTable);
if (Owner.ControlStyleCreated) {
_renderTable.ApplyStyle(Owner.ControlStyle);
} else {
// initialize defaults that are different from TableStyle
_renderTable.CellSpacing = 0;
_renderTable.CellPadding = 0;
}
// On Mac IE, if height is not set, render height:1px, so the table sizes to contents.
// Otherwise, Mac IE may give the table an arbitrary height (equal to the width of its contents).
if (!Owner.DesignMode && Owner.IsMacIE5 &&
(!Owner.ControlStyleCreated || Owner.ControlStyle.Height == Unit.Empty)) {
_renderTable.ControlStyle.Height = Unit.Pixel(1);
}
}
// On Mac IE, render height:1px of the inner table cell, so the table sizes to contents.
// Otherwise, Mac IE may give the table an arbitrary height (equal to the width of its contents).
if (!Owner.DesignMode && _navigationTableCell != null && Owner.IsMacIE5) {
_navigationTableCell.ControlStyle.Height = Unit.Pixel(1);
}
}
private void ApplyControlProperties_Navigation() {
ApplyNavigationTemplateProperties();
ApplyCustomNavigationTemplateProperties();
if (_navigationTableCell != null) {
NavigationTableCell.HorizontalAlign = HorizontalAlign.Right;
// Copy the styles from the StepStyle property if defined.
if (Owner._navigationStyle != null) {
if (!Owner.DesignMode && Owner.IsMacIE5 && Owner._navigationStyle.Height == Unit.Empty) {
Owner._navigationStyle.Height = Unit.Pixel(1);
}
_navigationTableCell.ApplyStyle(Owner._navigationStyle);
}
}
if (Owner.ShowCustomNavigationTemplate) {
// Make sure the navigation row is visible
_navigationRow.Visible = true;
}
}
private void ApplyControlProperties_WizardSteps() {
// Apply the WizardSteps style
if (_stepTableCell != null) {
// Copy the styles from the StepStyle property if defined.
if (Owner._stepStyle != null) {
if (!Owner.DesignMode && Owner.IsMacIE5 && Owner._stepStyle.Height == Unit.Empty) {
Owner._stepStyle.Height = Unit.Pixel(1);
}
_stepTableCell.ApplyStyle(Owner._stepStyle);
}
}
}
private void ApplyControlProperties_Header() {
if (_headerTableRow != null) {
// If headerTemplate is not defined and headertext is empty, do not render the
// empty table row.
if ((Owner.HeaderTemplate == null) && String.IsNullOrEmpty(Owner.HeaderText)) {
_headerTableRow.Visible = false;
} else {
_headerTableCell.ApplyStyle(Owner._headerStyle);
// if HeaderTemplate is defined.
if (Owner.HeaderTemplate != null) {
if (_titleLiteral != null) {
_titleLiteral.Visible = false;
}
}
// Otherwise HeaderText is defined.
else {
Debug.Assert(Owner.HeaderText != null && Owner.HeaderText.Length > 0);
if (_titleLiteral != null) {
_titleLiteral.Text = Owner.HeaderText;
}
}
}
}
}
protected override WizardStepType SetActiveTemplates() {
WizardStepType type = base.SetActiveTemplates();
if (type != WizardStepType.Complete) {
// Only render sidebartablecell if necessary
if (Owner._sideBarTableCell != null) {
Owner._sideBarTableCell.Visible = Owner.SideBarEnabled && Owner._renderSideBarDataList;
}
}
return type;
}
public override void OnlyShowCompleteStep() {
// Do not render header or sidebarlist in complete steps;
if (_headerTableRow != null) {
_headerTableRow.Visible = false;
}
if (Owner._sideBarTableCell != null) {
Owner._sideBarTableCell.Visible = false;
}
_navigationRow.Visible = false;
}
public override void CreateControlHierarchy() {
// Use the inner table to render header template, step and navigation template
Table mainContentTable = null;
if (Owner.DisplaySideBar) {
mainContentTable = CreateControlHierarchy_CreateLayoutWithSideBar();
} else {
mainContentTable = CreateControlHierarchy_CreateLayoutWithoutSideBar();
}
CreateControlHierarchy_CreateHeaderArea(mainContentTable);
CreateControlHierarchy_CreateStepArea(mainContentTable);
CreateControlHierarchy_CreateNavigationArea(mainContentTable);
}
private void CreateControlHierarchy_CreateNavigationArea(Table mainContentTable) {
_navigationRow = new TableRow();
mainContentTable.Controls.Add(_navigationRow);
_navigationRow.Controls.Add(NavigationTableCell);
CreateNavigationControlHierarchy(NavigationTableCell);
}
private void CreateControlHierarchy_CreateStepArea(Table mainContentTable) {
TableRow stepRow = new TableRow() {
// The step row needs to use the most of the table size.
Height = Unit.Percentage(100)
};
mainContentTable.Controls.Add(stepRow);
_stepTableCell = new TableCell();
stepRow.Controls.Add(_stepTableCell);
_stepTableCell.Controls.Add(Owner.MultiView);
Owner.InstantiateStepContentTemplates();
}
private void CreateControlHierarchy_CreateHeaderArea(Table mainContentTable) {
_headerTableRow = new TableRow();
mainContentTable.Controls.Add(_headerTableRow);
_headerTableCell = new InternalTableCell(Owner) {
ID = _headerCellID
};
if (Owner.HeaderTemplate != null) {
_headerTableCell.EnableTheming = Owner.EnableTheming;
Owner.HeaderTemplate.InstantiateIn(_headerTableCell);
} else {
// Render the title property if HeaderTemplate is not defined.
_titleLiteral = new LiteralControl();
_headerTableCell.Controls.Add(_titleLiteral);
}
_headerTableRow.Controls.Add(_headerTableCell);
}
private Table CreateControlHierarchy_CreateLayoutWithoutSideBar() {
// if sidebar is disabled, add mainContentTable directly into the Wizard control.
var mainContentTable = new WizardChildTable(Owner) {
EnableTheming = false
};
using (new WizardControlCollectionModifier(Owner)) {
Owner.Controls.Add(mainContentTable);
}
_renderTable = mainContentTable;
return mainContentTable;
}
private Table CreateControlHierarchy_CreateLayoutWithSideBar() {
// Create an outer table and make all child controls into the right cell.
// Use the left cell to render the side bar.
Table outerTable = new WizardChildTable(Owner) {
EnableTheming = false
};
TableRow outerRow = new TableRow();
outerTable.Controls.Add(outerRow);
// Use the existing sideBarTableCell if possible.
TableCell outerLeftCell = Owner._sideBarTableCell ?? CreateControlHierarchy_CreateSideBarTableCell();
outerRow.Controls.Add(outerLeftCell);
Owner._sideBarTableCell = outerLeftCell;
Owner._renderSideBarDataList = false;
// Right cell is used for header, step and navigation areas.
TableCell outerRightCell = new TableCell() {
// Maximize the inner default table Whidbey 143409.
Height = Unit.Percentage(100)
};
outerRow.Controls.Add(outerRightCell);
var mainContentTable = new WizardDefaultInnerTable() {
CellSpacing = 0,
Height = Unit.Percentage(100),
Width = Unit.Percentage(100)
};
outerRightCell.Controls.Add(mainContentTable);
// On Mac IE, render height:1px of the inner table cell, so the table sizes to contents.
// Otherwise, Mac IE may give the table an arbitrary height (equal to the width of its contents).
if (!Owner.DesignMode && Owner.IsMacIE5) {
outerRightCell.Height = Unit.Pixel(1);
}
// Add the table into the Wizard control
using (new WizardControlCollectionModifier(Owner)) {
Owner.Controls.Add(outerTable);
}
CreateControlHierarchy_CleanUpOldSideBarList(Owner.SideBarList);
Owner._sideBarList = CreateControlHierarchy_SetUpSideBarList(Owner._sideBarTableCell);
_renderTable = outerTable;
return mainContentTable;
}
private TableCell CreateControlHierarchy_CreateSideBarTableCell() {
// Left cell is used for SideBar
TableCell outerLeftCell = new AccessibleTableCell(Owner) {
ID = _sideBarCellID,
// Left cell should expand to all height if sidebar is displayed.
Height = Unit.Percentage(100)
};
ITemplate sideBarTemplate = Owner.SideBarTemplate;
if (sideBarTemplate == null) {
outerLeftCell.EnableViewState = false;
sideBarTemplate = Owner.CreateDefaultSideBarTemplate();
} else {
outerLeftCell.EnableTheming = Owner.EnableTheming;
}
sideBarTemplate.InstantiateIn(outerLeftCell);
return outerLeftCell;
}
public override void SetDesignModeState(IDictionary dictionary) {
base.SetDesignModeState(dictionary);
dictionary[_stepTableCellID] = _stepTableCell;
}
}
#endregion
private class WizardControlCollection : ControlCollection {
public WizardControlCollection(Wizard wizard)
: base(wizard) {
if (!wizard.DesignMode)
SetCollectionReadOnly(SR.Wizard_Cannot_Modify_ControlCollection);
}
}
private class WizardControlCollectionModifier : IDisposable {
Wizard _wizard;
ControlCollection _controls;
String _originalError;
public WizardControlCollectionModifier(Wizard wizard) {
_wizard = wizard;
if (!_wizard.DesignMode) {
// Remember the ControlCollection so we don't need to access the
// Controls property by GC during Dispose. Accessing this property has the
// side-effect of creating the entire child controls on CompositeControl.
_controls = _wizard.Controls;
_originalError = _controls.SetCollectionReadOnly(null);
}
}
void IDisposable.Dispose() {
if (!_wizard.DesignMode) {
_controls.SetCollectionReadOnly(_originalError);
}
}
}
[SupportsEventValidation]
private class WizardChildTable : ChildTable {
private Wizard _owner;
internal WizardChildTable(Wizard owner) {
_owner = owner;
}
protected override bool OnBubbleEvent(object source, EventArgs args) {
return _owner.OnBubbleEvent(source, args);
}
}
private enum WizardTemplateType {
StartNavigationTemplate = 0,
StepNavigationTemplate = 1,
FinishNavigationTemplate = 2,
}
private sealed class NavigationTemplate : ITemplate {
private Wizard _wizard;
private WizardTemplateType _templateType;
private String _button1ID;
private String _button2ID;
private String _button3ID;
private const string _startNextButtonID = "StartNext";
private const string _stepNextButtonID = "StepNext";
private const string _stepPreviousButtonID = "StepPrevious";
private const string _finishPreviousButtonID = "FinishPrevious";
private const string _finishButtonID = "Finish";
private const string _cancelButtonID = "Cancel";
private TableRow _row;
private IButtonControl[][] _buttons;
private bool _button1CausesValidation;
internal static NavigationTemplate GetDefaultStartNavigationTemplate(Wizard wizard) {
return new NavigationTemplate(wizard, WizardTemplateType.StartNavigationTemplate,
true, null, _startNextButtonID, _cancelButtonID);
}
internal static NavigationTemplate GetDefaultStepNavigationTemplate(Wizard wizard) {
return new NavigationTemplate(wizard, WizardTemplateType.StepNavigationTemplate,
false, _stepPreviousButtonID, _stepNextButtonID, _cancelButtonID);
}
internal static NavigationTemplate GetDefaultFinishNavigationTemplate(Wizard wizard) {
return new NavigationTemplate(wizard, WizardTemplateType.FinishNavigationTemplate,
false, _finishPreviousButtonID, _finishButtonID, _cancelButtonID);
}
internal void ResetButtonsVisibility() {
Debug.Assert(_wizard.DesignMode);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Control c = _buttons[i][j] as Control;
if (c != null) c.Visible = false;
}
}
}
private NavigationTemplate(Wizard wizard, WizardTemplateType templateType, bool button1CausesValidation,
String label1ID, String label2ID, String label3ID) {
_wizard = wizard;
_button1ID = label1ID;
_button2ID = label2ID;
_button3ID = label3ID;
_templateType = templateType;
_buttons = new IButtonControl[3][];
_buttons[0] = new IButtonControl[3];
_buttons[1] = new IButtonControl[3];
_buttons[2] = new IButtonControl[3];
_button1CausesValidation = button1CausesValidation;
}
void ITemplate.InstantiateIn(Control container) {
Table table = new WizardDefaultInnerTable();
// Increase the default space and padding so the layout
// of the buttons look good. Also, to make custom border
// visible. VSWhidbey 377069
table.CellSpacing = 5;
table.CellPadding = 5;
container.Controls.Add(table);
_row = new TableRow();
table.Rows.Add(_row);
if (_button1ID != null) {
CreateButtonControl(_buttons[0], _button1ID, _button1CausesValidation,
MovePreviousCommandName);
}
if (_button2ID != null) {
CreateButtonControl(_buttons[1], _button2ID, true /* causesValidation */,
_templateType == WizardTemplateType.FinishNavigationTemplate ? MoveCompleteCommandName : MoveNextCommandName);
}
CreateButtonControl(_buttons[2], _button3ID, false /* causesValidation */, CancelCommandName);
}
private void OnPreRender(object source, EventArgs e) {
((ImageButton)source).Visible = false;
}
private void CreateButtonControl(IButtonControl[] buttons, String id, bool causesValidation, string commandName) {
LinkButton linkButton = new LinkButton();
linkButton.CausesValidation = causesValidation;
linkButton.ID = id + "LinkButton";
linkButton.Visible = false;
linkButton.CommandName = commandName;
linkButton.TabIndex = _wizard.TabIndex;
_wizard.RegisterCommandEvents(linkButton);
buttons[0] = linkButton;
ImageButton imageButton = new ImageButton();
imageButton.CausesValidation = causesValidation;
imageButton.ID = id + "ImageButton";
imageButton.Visible = true;
imageButton.CommandName = commandName;
imageButton.TabIndex = _wizard.TabIndex;
_wizard.RegisterCommandEvents(imageButton);
imageButton.PreRender += new EventHandler(OnPreRender);
buttons[1] = imageButton;
Button button = new Button();
button.CausesValidation = causesValidation;
button.ID = id + "Button";
button.Visible = false;
button.CommandName = commandName;
button.TabIndex = _wizard.TabIndex;
_wizard.RegisterCommandEvents(button);
buttons[2] = button;
TableCell tableCell = new TableCell();
tableCell.HorizontalAlign = HorizontalAlign.Right;
_row.Cells.Add(tableCell);
tableCell.Controls.Add(linkButton);
tableCell.Controls.Add(imageButton);
tableCell.Controls.Add(button);
}
internal IButtonControl FirstButton {
get {
ButtonType buttonType = ButtonType.Button;
switch (_templateType) {
case WizardTemplateType.StartNavigationTemplate:
Debug.Fail("Invalid template/button type");
break;
case WizardTemplateType.StepNavigationTemplate:
buttonType = _wizard.StepPreviousButtonType;
break;
case WizardTemplateType.FinishNavigationTemplate:
default:
buttonType = _wizard.FinishPreviousButtonType;
break;
}
return GetButtonBasedOnType(0, buttonType);
}
}
internal IButtonControl SecondButton {
get {
ButtonType buttonType = ButtonType.Button;
switch (_templateType) {
case WizardTemplateType.StartNavigationTemplate:
buttonType = _wizard.StartNextButtonType;
break;
case WizardTemplateType.StepNavigationTemplate:
buttonType = _wizard.StepNextButtonType;
break;
case WizardTemplateType.FinishNavigationTemplate:
default:
buttonType = _wizard.FinishCompleteButtonType;
break;
}
return GetButtonBasedOnType(1, buttonType);
}
}
internal IButtonControl CancelButton {
get {
ButtonType buttonType = _wizard.CancelButtonType;
return GetButtonBasedOnType(2, buttonType);
}
}
private IButtonControl GetButtonBasedOnType(int pos, ButtonType type) {
switch (type) {
case ButtonType.Button:
return _buttons[pos][2];
case ButtonType.Image:
return _buttons[pos][1];
case ButtonType.Link:
return _buttons[pos][0];
}
return null;
}
}
private class DataListItemTemplate : ITemplate {
Wizard _owner;
internal DataListItemTemplate(Wizard owner) {
_owner = owner;
}
public void InstantiateIn(Control container) {
LinkButton linkButton = new LinkButton();
container.Controls.Add(linkButton);
linkButton.ID = SideBarButtonID;
if (_owner.DesignMode) {
linkButton.MergeStyle(_owner.SideBarButtonStyle);
}
}
}
private class DefaultSideBarTemplate : ITemplate {
private Wizard _owner;
internal DefaultSideBarTemplate(Wizard owner) {
_owner = owner;
}
public void InstantiateIn(Control container) {
Control sideBarListControl = null;
if (_owner.SideBarList == null) {
var dataList = new DataList();
dataList.ID = Wizard.DataListID;
dataList.SelectedItemStyle.Font.Bold = true;
dataList.ItemTemplate = _owner.CreateDefaultDataListItemTemplate();
sideBarListControl = dataList;
} else {
sideBarListControl = (Control)_owner.SideBarList;
}
container.Controls.Add(sideBarListControl);
}
}
// Internally use an empty table (with a row and a cell) to render the content.
internal abstract class BlockControl : WebControl, INamingContainer, INonBindingContainer {
private Table _table;
internal TableCell _cell;
internal Wizard _owner;
internal BlockControl(Wizard owner) {
Debug.Assert(owner != null);
_owner = owner;
_table = new WizardDefaultInnerTable();
_table.EnableTheming = false;
Controls.Add(_table);
TableRow row = new TableRow();
_table.Controls.Add(row);
_cell = new TableCell();
_cell.Height = Unit.Percentage(100);
_cell.Width = Unit.Percentage(100);
row.Controls.Add(_cell);
HandleMacIECellHeight();
PreventAutoID();
}
protected Table Table {
get { return _table; }
}
internal TableCell InnerCell {
get { return _cell; }
}
protected override Style CreateControlStyle() {
return new TableItemStyle(ViewState);
}
public override void Focus() {
throw new NotSupportedException(SR.GetString(SR.NoFocusSupport, this.GetType().Name));
}
internal void HandleMacIECellHeight() {
// On Mac IE, render height:1px of the inner table cell, so the table sizes to contents.
// Otherwise, Mac IE may give the table an arbitrary height (equal to the width of its contents).
if (!_owner.DesignMode && _owner.IsMacIE5) {
_cell.Height = Unit.Pixel(1);
}
}
// Renders the inner control only
protected internal override void Render(HtmlTextWriter writer) {
RenderContents(writer);
}
internal void SetEnableTheming() {
_cell.EnableTheming = _owner.EnableTheming;
}
}
private class InternalTableCell : TableCell, INamingContainer, INonBindingContainer {
protected Wizard _owner;
internal InternalTableCell(Wizard owner) {
_owner = owner;
}
// Do not render any attributes other than Style on this cell.
protected override void AddAttributesToRender(HtmlTextWriter writer) {
if (ControlStyleCreated && !ControlStyle.IsEmpty) {
// let the style add attributes
ControlStyle.AddAttributesToRender(writer, this);
}
}
}
private class AccessibleTableCell : InternalTableCell {
internal AccessibleTableCell(Wizard owner)
: base(owner) {
}
protected internal override void RenderChildren(HtmlTextWriter writer) {
ControlRenderingHelper.WriteSkipLinkStart(writer, RenderingCompatibility, _owner.DesignMode, _owner.SkipLinkText, SpacerImageUrl, _owner.ClientID);
base.RenderChildren(writer);
ControlRenderingHelper.WriteSkipLinkEnd(writer, _owner.DesignMode, _owner.SkipLinkText, _owner.ClientID);
}
}
internal class BaseContentTemplateContainer : BlockControl {
private bool _useInnerTable;
internal BaseContentTemplateContainer(Wizard owner, bool useInnerTable)
: base(owner) {
_useInnerTable = useInnerTable;
if (useInnerTable) {
// Set the table width to 100% so the table within each
// row will have the same width. VSWhidbey 377182
Table.Width = Unit.Percentage(100);
Table.Height = Unit.Percentage(100);
}
else {
// remove nested table from Control tree
Controls.Clear();
}
}
internal void AddChildControl(Control c) {
Container.Controls.Add(c);
}
internal Control Container {
get {
return _useInnerTable ? InnerCell : (Control)this;
}
}
}
#region Navigation Template Containers
internal class BaseNavigationTemplateContainer : WebControl, INamingContainer, INonBindingContainer {
private IButtonControl _finishButton;
private IButtonControl _previousButton;
private IButtonControl _nextButton;
private IButtonControl _cancelButton;
private Wizard _owner;
internal BaseNavigationTemplateContainer(Wizard owner) {
_owner = owner;
}
internal Wizard Owner {
get {
return _owner;
}
}
internal void ApplyButtonStyle(Style finishStyle, Style prevStyle, Style nextStyle, Style cancelStyle) {
if (FinishButton != null) ApplyButtonStyleInternal(FinishButton, finishStyle);
if (PreviousButton != null) ApplyButtonStyleInternal(PreviousButton, prevStyle);
if (NextButton != null) ApplyButtonStyleInternal(NextButton, nextStyle);
if (CancelButton != null) ApplyButtonStyleInternal(CancelButton, cancelStyle);
}
protected void ApplyButtonStyleInternal(IButtonControl control, Style buttonStyle) {
WebControl webCtrl = control as WebControl;
if (webCtrl != null) {
webCtrl.ApplyStyle(buttonStyle);
webCtrl.ControlStyle.MergeWith(Owner.NavigationButtonStyle);
}
}
public override void Focus() {
throw new NotSupportedException(SR.GetString(SR.NoFocusSupport, this.GetType().Name));
}
internal void RegisterButtonCommandEvents() {
Owner.RegisterCommandEvents(NextButton);
Owner.RegisterCommandEvents(FinishButton);
Owner.RegisterCommandEvents(PreviousButton);
Owner.RegisterCommandEvents(CancelButton);
}
internal IButtonControl CancelButton {
get {
if (_cancelButton != null) {
return _cancelButton;
}
_cancelButton = FindControl(Wizard.CancelButtonID) as IButtonControl;
return _cancelButton;
}
set {
_cancelButton = value;
}
}
internal virtual IButtonControl NextButton {
get {
if (_nextButton != null) {
return _nextButton;
}
_nextButton = FindControl(Wizard.StepNextButtonID) as IButtonControl;
return _nextButton;
}
set {
_nextButton = value;
}
}
internal virtual IButtonControl PreviousButton {
get {
if (_previousButton != null) {
return _previousButton;
}
_previousButton = FindControl(Wizard.StepPreviousButtonID) as IButtonControl;
return _previousButton;
}
set {
_previousButton = value;
}
}
internal IButtonControl FinishButton {
get {
if (_finishButton != null) {
return _finishButton;
}
_finishButton = FindControl(Wizard.FinishButtonID) as IButtonControl;
return _finishButton;
}
set {
_finishButton = value;
}
}
internal void SetEnableTheming() {
this.EnableTheming = _owner.EnableTheming;
}
// Renders the inner control only
protected internal override void Render(HtmlTextWriter writer) {
RenderContents(writer);
}
}
private class FinishNavigationTemplateContainer : BaseNavigationTemplateContainer {
private IButtonControl _previousButton;
internal FinishNavigationTemplateContainer(Wizard owner)
: base(owner) {
}
internal override IButtonControl PreviousButton {
get {
if (_previousButton != null) {
return _previousButton;
}
_previousButton = FindControl(Wizard.FinishPreviousButtonID) as IButtonControl;
return _previousButton;
}
set {
_previousButton = value;
}
}
}
private class StartNavigationTemplateContainer : BaseNavigationTemplateContainer {
private IButtonControl _nextButton;
internal StartNavigationTemplateContainer(Wizard owner)
: base(owner) {
}
internal override IButtonControl NextButton {
get {
if (_nextButton != null) {
return _nextButton;
}
_nextButton = FindControl(Wizard.StartNextButtonID) as IButtonControl;
return _nextButton;
}
set {
_nextButton = value;
}
}
}
private class StepNavigationTemplateContainer : BaseNavigationTemplateContainer {
internal StepNavigationTemplateContainer(Wizard owner)
: base(owner) {
}
}
#endregion
}
public sealed class WizardStepCollection : IList {
private Wizard _wizard;
internal WizardStepCollection(Wizard wizard) {
this._wizard = wizard;
wizard.TemplatedSteps.Clear();
}
public int Count {
get {
return Views.Count;
}
}
public bool IsReadOnly {
get {
return Views.IsReadOnly;
}
}
public bool IsSynchronized {
get {
return false;
}
}
public object SyncRoot {
get {
return this;
}
}
private ViewCollection Views {
get {
return _wizard.MultiView.Views;
}
}
public WizardStepBase this[int index] {
get {
return (WizardStepBase)Views[index];
}
}
public void Add(WizardStepBase wizardStep) {
//
if (wizardStep == null) {
throw new ArgumentNullException("wizardStep");
}
wizardStep.PreventAutoID();
RemoveIfAlreadyExistsInWizard(wizardStep);
wizardStep.Owner = _wizard;
Views.Add(wizardStep);
AddTemplatedWizardStep(wizardStep);
NotifyWizardStepsChanged();
}
public void AddAt(int index, WizardStepBase wizardStep) {
if (wizardStep == null) {
throw new ArgumentNullException("wizardStep");
}
RemoveIfAlreadyExistsInWizard(wizardStep);
wizardStep.PreventAutoID();
wizardStep.Owner = _wizard;
Views.AddAt(index, wizardStep);
AddTemplatedWizardStep(wizardStep);
NotifyWizardStepsChanged();
}
private void AddTemplatedWizardStep(WizardStepBase wizardStep) {
var templatedWizardStep = wizardStep as TemplatedWizardStep;
if (templatedWizardStep != null) {
_wizard.TemplatedSteps.Add(templatedWizardStep);
_wizard.RegisterCustomNavigationContainers(templatedWizardStep);
}
}
public void Clear() {
Views.Clear();
_wizard.TemplatedSteps.Clear();
NotifyWizardStepsChanged();
}
public bool Contains(WizardStepBase wizardStep) {
if (wizardStep == null) {
throw new ArgumentNullException("wizardStep");
}
return Views.Contains(wizardStep);
}
public void CopyTo(WizardStepBase[] array, int index) {
Views.CopyTo(array, index);
}
public IEnumerator GetEnumerator() {
return Views.GetEnumerator();
}
public int IndexOf(WizardStepBase wizardStep) {
if (wizardStep == null) {
throw new ArgumentNullException("wizardStep");
}
return Views.IndexOf(wizardStep);
}
public void Insert(int index, WizardStepBase wizardStep) {
AddAt(index, wizardStep);
}
internal void NotifyWizardStepsChanged() {
_wizard.OnWizardStepsChanged();
}
public void Remove(WizardStepBase wizardStep) {
if (wizardStep == null) {
throw new ArgumentNullException("wizardStep");
}
Views.Remove(wizardStep);
wizardStep.Owner = null;
var templatedWizardStep = wizardStep as TemplatedWizardStep;
if (templatedWizardStep != null) {
_wizard.TemplatedSteps.Remove(templatedWizardStep);
}
NotifyWizardStepsChanged();
}
public void RemoveAt(int index) {
WizardStepBase wizardStep = Views[index] as WizardStepBase;
if (wizardStep != null) {
wizardStep.Owner = null;
var templatedWizardStep = wizardStep as TemplatedWizardStep;
if (templatedWizardStep != null) {
_wizard.TemplatedSteps.Remove(templatedWizardStep);
}
}
Views.RemoveAt(index);
NotifyWizardStepsChanged();
}
private static void RemoveIfAlreadyExistsInWizard(WizardStepBase wizardStep) {
if (wizardStep.Owner != null) {
wizardStep.Owner.WizardSteps.Remove(wizardStep);
}
}
private static WizardStepBase GetStepAndVerify(object value) {
WizardStepBase step = value as WizardStepBase;
if (step == null)
throw new ArgumentException(SR.GetString(SR.Wizard_WizardStepOnly));
return step;
}
#region ICollection implementation
/// <internalonly/>
void ICollection.CopyTo(Array array, int index) {
Views.CopyTo(array, index);
}
#endregion //ICollection implementation
#region IList implementation
/// <internalonly/>
bool IList.IsFixedSize {
get {
return false;
}
}
/// <internalonly/>
object IList.this[int index] {
get {
return Views[index];
}
set {
RemoveAt(index);
AddAt(index, GetStepAndVerify(value));
}
}
/// <internalonly/>
int IList.Add(object value) {
WizardStepBase step = GetStepAndVerify(value);
step.PreventAutoID();
Add(step);
return IndexOf(step);
}
/// <internalonly/>
bool IList.Contains(object value) {
return Contains(GetStepAndVerify(value));
}
/// <internalonly/>
int IList.IndexOf(object value) {
return IndexOf(GetStepAndVerify(value));
}
/// <internalonly/>
void IList.Insert(int index, object value) {
AddAt(index, GetStepAndVerify(value));
}
/// <internalonly/>
void IList.Remove(object value) {
Remove(GetStepAndVerify(value));
}
#endregion // IList implementation
}
[SupportsEventValidation]
internal class WizardDefaultInnerTable : Table {
internal WizardDefaultInnerTable() {
PreventAutoID();
// cell padding and spacing should be 0 since these tables are for internal layout only.
CellPadding = 0;
CellSpacing = 0;
}
}
public class WizardNavigationEventArgs : EventArgs {
private int _currentStepIndex;
private int _nextStepIndex;
private bool _cancel;
public WizardNavigationEventArgs(int currentStepIndex, int nextStepIndex) {
_currentStepIndex = currentStepIndex;
_nextStepIndex = nextStepIndex;
}
public bool Cancel {
get {
return _cancel;
}
set {
_cancel = value;
}
}
public int CurrentStepIndex {
get {
return _currentStepIndex;
}
}
public int NextStepIndex {
get {
return _nextStepIndex;
}
}
internal void SetNextStepIndex(int nextStepIndex) {
_nextStepIndex = nextStepIndex;
}
}
public delegate void WizardNavigationEventHandler(object sender, WizardNavigationEventArgs e);
}
|