ComposeRingToneMainScreen.c 161 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*******************************************************************************
* Filename:
* ---------
*  RingtoneComposerMainScreen.c
*
* Project:
* --------
*   MAUI
*
* Description:
* ------------
*   Ringtone Composer main screen
*
* Author:
* -------
 * -------
*
*============================================================================
*             HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
 * removed!
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*============================================================================
****************************************************************************/


#include "MMI_features.h"

#if defined(__MMI_RING_COMPOSER__) && defined(__MMI_IMELODY_SUPPORT__)

/* RHR */
#include "CustThemesRes.h"
#include "gui_data_types.h"
#include "MMIDataType.h"
#include "ComposeRingToneTypes.h"
#include "gdi_const.h"
#include "gdi_datatype.h"
#include "gui_theme_struct.h"
#include "gui_themes.h"
#include "mmi_frm_input_gprot.h"
#include "gui_switch.h"
#include "lcd_sw_inc.h"
#include "Gui_Setting.h"
#include "wgui.h"
//#include "kal_general_types.h"
#include "gdi_include.h"
#include "wgui_include.h"
#include "wgui_categories_util.h"
#include "GlobalResDef.h"
#include "mmi_frm_scenario_gprot.h"
#include "gui_config.h"
#include "ScreenRotationGprot.h"
#include "wgui_inputs.h"
#include "CustDataRes.h"
#include "mmi_frm_mem_gprot.h"
//#include "kal_public_api.h"
#include "DebugInitDef_Int.h"
#include "string.h"
#include "CustMenuRes.h"
#include "gui_fixed_menuitems.h"
#include "TimerEvents.h"
#include "mmi_frm_timer_gprot.h"
#include "GlobalConstants.h"

//#include "operator_gui.h"
#include "kal_general_types.h"
#include "kal_public_api.h"

/* RHR */

//#include "mmi_include.h"
#include "ComposeRingToneEngineProts.h"
#include "ComposeRingToneEngineDefs.h"
//#include "Asciiprot.h"
#include "ComposeRingToneDefs.h"
//#include "SettingProfile.h"
//#include "CustDataProts.h"
#include "ComposeRingToneProts.h"
#include "mmi_rp_app_ringtonecomposer_def.h"
#include "ComposeRingToneMainScreenProts.h"
//#include "gpioInc.h"
//#include "ProfileGprots.h"
//#include "mdi_datatype.h"
//#include "mdi_audio.h"
//#include "FileManagerDef.h"
//#include "FileManagerGprot.h"
//#include "CommonScreens.h"
//#include "fs_type.h"
//#include "FS_Func.h"
//#include "fs_errcode.h"
#include "gui_font_size.h"
#include "Gui.h" /* for MMI_title_height */
#include "Gui_typedef.h" /* for UI_device_width, UI_device_height, r2lMMIFlag */
#include "gui_horizontal_selector.h"

#ifdef __MMI_TOUCH_RING_COMPOSER__
//#include "wgui_softkeys.h"
#endif /* __MMI_TOUCH_RING_COMPOSER__ */ 

#ifdef __DRM_SUPPORT__
//#include "drm_gprot.h"
#endif /* __DRM_SUPPORT__ */

#if defined(__MMI_BACKGROUND_CALL__)
//#include "UCMGProt.h"
#endif



/* To draw the background color behind the remaining number of notes */
const UI_filled_area lightblue_color_dialog_background = {UI_FILLED_AREA_TYPE_COLOR,
    UI_NULL_IMAGE,
    NULL,
    {108, 182, 255, 100},
    {0, 0, 0, 0},
    {0, 0, 0, 100},
    {50, 50, 50, 100},
    0
};

/* Background color behind the instrument bar */
#ifdef RNGC_HAS_INST_RECTANGLE
const UI_filled_area rngc_instrument_select_background = {UI_FILLED_AREA_TYPE_COLOR,
    UI_NULL_IMAGE,
    NULL,
#if (defined(__MMI_MAINLCD_320X240__) || defined(__MMI_MAINLCD_240X400__))
    {56, 70, 82, 100},
#elif (defined(__MMI_MAINLCD_320X480__))
    {52, 52, 52, 100},
#else
    {215, 215, 215, 100}, 
#endif
    {0, 0, 0, 0},
    {0, 0, 0, 100},
    {0, 0, 0, 0},
    0
};
#endif /* RNGC_HAS_INST_RECTANGLE*/ 

#if defined(RNGC_SUPPORT_INSTR_STYLE1)
const U8 CurrentInstrument[] = 
{
    INSTR_PIANO,
    INSTR_GUITAR,                    
    INSTR_VIOLIN,                    
    INSTR_SPHONE,                    
    INSTR_SDRUMS,
    INSTR_FLUTE,
    INSTR_HARMONICA,
    INSTR_TRUMPET
};
#elif defined(RNGC_SUPPORT_INSTR_STYLE2)
const U8 CurrentInstrument[] = 
{
    INSTR_GUITAR,
    INSTR_VIOLIN,
    INSTR_FLUTE,
    INSTR_TRUMPET
};
#else
const U8 CurrentInstrument[] = 
{
    INSTR_PIANO,
    INSTR_GUITAR,
    INSTR_VIOLIN,
    INSTR_SPHONE,
    INSTR_SDRUMS,
    INSTR_FLUTE,
    INSTR_HARMONICA,
    INSTR_TRUMPET,
    INSTR_MUSICBOX,
    INSTR_XYLOPHONE
};
#endif

rngc_skin_layout_struct g_rngc_skin_layout;
extern rngc_context_struct g_rngc_cntx;  
extern rngc_engine_context_struct *g_rngc_eng_cntx;  

#ifdef __MMI_TOUCH_RING_COMPOSER__
touch_rngc_struct touch_rngc_context;
rngc_selection_area_layout_struct const *selection_area_context;
S32 rngc_pen_event_on_object;
extern S32 touch_ring_comp_mem;
#endif /* __MMI_TOUCH_RING_COMPOSER__ */ 

#ifdef __GDI_MEMORY_PROFILE_2__
GDI_HANDLE rngc_osd_layer;
GDI_HANDLE rngc_skin_layer;
GDI_HANDLE rngc_old_alpha_blending_src_layer;
BOOL is_rngc_skin_layer_drawn = FALSE;
#endif /* __GDI_MEMORY_PROFILE_2__ */ 

#ifdef RNGC_HAS_INST_RECTANGLE
gui_horizontal_select_item_struct MMI_rngc_instrument_select_items[ENUM_TOTAL_INSTR];
gui_horizontal_select_struct MMI_rngc_instrument_select_menu;
UI_horizontal_select_theme MMI_rngc_instrument_select_theme =
{
    (UI_filled_area*)&rngc_instrument_select_background,
    (PU8)NULL,
    (PU8)NULL,
    (PU8)NULL,
    (PU8)NULL,
    (UI_filled_area*)NULL,
    (UI_filled_area*)NULL,
    (PU8)NULL,
    &UI_DEFAULT_FONT,
#if (defined(__MMI_MAINLCD_240X400__)) || (defined(__MMI_MAINLCD_320X480__)) || (defined(__MMI_MAINLCD_320X240__))
    {255, 255, 255 ,100}
#else
    {0, 0, 0, 100}
#endif
};
#endif

#if defined(__MMI_TOUCH_RING_COMPOSER__)
static mmi_pen_point_struct SK_points[4];
static mmi_pen_polygon_area_struct SK_area;
#endif 

#if defined(__MMI_MAINLCD_176X220__) && defined(__MMI_TOUCH_RING_COMPOSER__)
static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
{
    {1, 185, 34, 14, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
    {36, 185, 45, 14, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
    {82, 185, 45, 14, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
    {128, 185, 23, 14, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
    {152, 185, 23, 14, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
};

#ifdef __MMI_RING_COMPOSER_REPEAT__
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {131, 151, 18, 23, TOUCH_IMG_REPEAT_START, REPEAT_START},
    {134, 175, 18, 23, TOUCH_IMG_REPEAT_END, REPEAT_END},
#if !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__)
    {153, 151, 22, 23, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */    
    {153, 151, 22, 23, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#endif /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */
    {153, 175, 22, 23, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {134, 151, 18, 23, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
    {153, 151, 22, 23, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {134, 175, 41, 23, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	

#elif defined(__MMI_MAINLCD_240X320__)
#ifdef __MMI_TOUCH_RING_COMPOSER__
	static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
	{
	    {1, NORMAL_TOOLBAR_IMAGE_Y + 1, 57, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
	    {59, NORMAL_TOOLBAR_IMAGE_Y + 1, 52, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
	    {112, NORMAL_TOOLBAR_IMAGE_Y + 1, 59, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
	    {172, NORMAL_TOOLBAR_IMAGE_Y + 1, 33, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
	    {206, NORMAL_TOOLBAR_IMAGE_Y + 1, 33, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
	};
	/* Notice: If you want to change the button size, please remember to modify the memory size defined in ScrMemMgr.h */
#ifdef __MMI_RING_COMPOSER_REPEAT__
	static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
	{
	    {173, NOTE_SELECTION_IMAGE_Y + 1, 24, 31, TOUCH_IMG_REPEAT_START, REPEAT_START},
	    {176, NOTE_SELECTION_IMAGE_Y + 34, 24, 31, TOUCH_IMG_REPEAT_END, REPEAT_END},
#if !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__)
	    {201, NOTE_SELECTION_IMAGE_Y + 1, 38, 31, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */    
	    {201, NOTE_SELECTION_IMAGE_Y + 1, 34, 31, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#endif /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */
	    {201, NOTE_SELECTION_IMAGE_Y + 34, 38, 31, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
	};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {176, NOTE_SELECTION_IMAGE_Y + 1, 24, 31, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {201, NOTE_SELECTION_IMAGE_Y + 1, 38, 31, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
    {176, NOTE_SELECTION_IMAGE_Y + 34, 63, 31, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	
#endif /*__MMI_TOUCH_RING_COMPOSER__*/

#elif defined(__MMI_MAINLCD_320X240__)
#ifdef __MMI_TOUCH_RING_COMPOSER__
	static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
	{
	    {19, NORMAL_TOOLBAR_IMAGE_Y, 65, NORMAL_TOOLBAR_HEIGHT - 1, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
	    {84, NORMAL_TOOLBAR_IMAGE_Y, 65, NORMAL_TOOLBAR_HEIGHT - 1, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
	    {149, NORMAL_TOOLBAR_IMAGE_Y, 65, NORMAL_TOOLBAR_HEIGHT - 1, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
	    {216, NORMAL_TOOLBAR_IMAGE_Y, 41, NORMAL_TOOLBAR_HEIGHT - 1, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
	    {257, NORMAL_TOOLBAR_IMAGE_Y , 41, NORMAL_TOOLBAR_HEIGHT - 1, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
	};

#ifdef __MMI_RING_COMPOSER_REPEAT__
	static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
	{
	    {236, NOTE_SELECTION_IMAGE_Y + 1, 30, 24, TOUCH_IMG_REPEAT_START, REPEAT_START},
	    {236, NOTE_SELECTION_IMAGE_Y + 24, 30, 24, TOUCH_IMG_REPEAT_END, REPEAT_END},
#if !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__)
	    {264, NOTE_SELECTION_IMAGE_Y + 1, 30, 24, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */    
	    {267, NOTE_SELECTION_IMAGE_Y + 1, 30, 24, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#endif /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */
	    {267, NOTE_SELECTION_IMAGE_Y + 24, 30, 24, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
	};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {236, NOTE_SELECTION_IMAGE_Y + 1, 30, 24, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {267, NOTE_SELECTION_IMAGE_Y + 1, 30, 24, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
    {236, NOTE_SELECTION_IMAGE_Y + 24, 62, 24, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	
#endif /*__MMI_TOUCH_RING_COMPOSER__*/

#elif defined(__MMI_MAINLCD_240X400__)
#ifdef __MMI_TOUCH_RING_COMPOSER__
	static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
	{
	    {2, NORMAL_TOOLBAR_IMAGE_Y + 3, 55, NORMAL_TOOLBAR_HEIGHT - 7, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
	    {58, NORMAL_TOOLBAR_IMAGE_Y + 3, 52, NORMAL_TOOLBAR_HEIGHT - 7, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
	    {112, NORMAL_TOOLBAR_IMAGE_Y + 3, 58, NORMAL_TOOLBAR_HEIGHT - 7, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
	    {172, NORMAL_TOOLBAR_IMAGE_Y + 3, 32, NORMAL_TOOLBAR_HEIGHT - 7, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
	    {206, NORMAL_TOOLBAR_IMAGE_Y + 3, 32, NORMAL_TOOLBAR_HEIGHT - 7, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
	};
#ifdef __MMI_RING_COMPOSER_REPEAT__
	static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
	{
	    {176, NOTE_SELECTION_IMAGE_Y + 3, 24, 30, TOUCH_IMG_REPEAT_START, REPEAT_START},
	    {176, NOTE_SELECTION_IMAGE_Y + 37, 24, 30, TOUCH_IMG_REPEAT_END, REPEAT_END},
#if !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__)
	    {202, NOTE_SELECTION_IMAGE_Y + 3, 36, 31, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */    
	    {202, NOTE_SELECTION_IMAGE_Y + 3, 36, 31, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#endif /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */
	    {202, NOTE_SELECTION_IMAGE_Y + 36, 36, 31, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
	};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {177, NOTE_SELECTION_IMAGE_Y + 3, 24, 30, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {202, NOTE_SELECTION_IMAGE_Y + 3, 36, 31, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
    {177, NOTE_SELECTION_IMAGE_Y + 36, 61, 31, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	
#endif /*__MMI_TOUCH_RING_COMPOSER__*/

#elif defined(__MMI_MAINLCD_320X480__)
#ifdef __MMI_TOUCH_RING_COMPOSER__
	static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
	{
	    {3, NORMAL_TOOLBAR_IMAGE_Y + 5, 72, NORMAL_TOOLBAR_HEIGHT - 10, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
	    {79, NORMAL_TOOLBAR_IMAGE_Y + 5, 67, NORMAL_TOOLBAR_HEIGHT - 10, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
	    {150, NORMAL_TOOLBAR_IMAGE_Y + 5, 76, NORMAL_TOOLBAR_HEIGHT - 10, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
	    {230, NORMAL_TOOLBAR_IMAGE_Y + 5, 41, NORMAL_TOOLBAR_HEIGHT - 10, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
	    {276, NORMAL_TOOLBAR_IMAGE_Y + 5, 40, NORMAL_TOOLBAR_HEIGHT - 10, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
	};

#ifdef __MMI_RING_COMPOSER_REPEAT__
	static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
	{
	    {230, NOTE_SELECTION_IMAGE_Y + 5, 30, 34, TOUCH_IMG_REPEAT_START, REPEAT_START},
	    {236, NOTE_SELECTION_IMAGE_Y + 46, 30, 34, TOUCH_IMG_REPEAT_END, REPEAT_END},
#if !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__)
	    {264, NOTE_SELECTION_IMAGE_Y + 5, 50, 34, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */    
	    {267, NOTE_SELECTION_IMAGE_Y + 5, 50, 34, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#endif /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */
	    {267, NOTE_SELECTION_IMAGE_Y + 46, 50, 34, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
	};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {234, NOTE_SELECTION_IMAGE_Y + 5, 30, 34, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {267, NOTE_SELECTION_IMAGE_Y + 5, 50, 34, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
    {234, NOTE_SELECTION_IMAGE_Y + 46, 83, 34, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	
#endif /*__MMI_TOUCH_RING_COMPOSER__*/

#elif defined(__MMI_MAINLCD_128X160__)
#ifdef __MMI_TOUCH_RING_COMPOSER__
	static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
	{
	    {0, NORMAL_TOOLBAR_IMAGE_Y + 1, 25, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
	    {27, NORMAL_TOOLBAR_IMAGE_Y + 1, 33, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
	    {60, NORMAL_TOOLBAR_IMAGE_Y + 1, 33, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
	    {93, NORMAL_TOOLBAR_IMAGE_Y + 1, 17, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
	    {110, NORMAL_TOOLBAR_IMAGE_Y + 1, 17, NORMAL_TOOLBAR_HEIGHT - 2, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
	};

#ifdef __MMI_RING_COMPOSER_REPEAT__
	static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
	{
	    {99, NOTE_SELECTION_IMAGE_Y + 1, 14, 16, TOUCH_IMG_REPEAT_START, REPEAT_START},
	    {99, NOTE_SELECTION_IMAGE_Y + 19, 14, 16, TOUCH_IMG_REPEAT_END, REPEAT_END},
#ifdef __MMI_RNGC_ENABLE_INS_LED_NOTE__
	    {110, NOTE_SELECTION_IMAGE_Y + 1, 14, 16, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#else 
	    {113, NOTE_SELECTION_IMAGE_Y + 1, 14, 16, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#endif /*__MMI_RNGC_ENABLE_INS_LED_NOTE__*/
	    {113, NOTE_SELECTION_IMAGE_Y + 19, 14, 16, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
	};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
#ifdef __MMI_RNGC_ENABLE_INS_LED_NOTE__
    {99, NOTE_SELECTION_IMAGE_Y + 1, 14, 16, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {113, NOTE_SELECTION_IMAGE_Y + 1, 14, 16, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else 
    {127, NOTE_SELECTION_IMAGE_Y + 1, 1, 1, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {99, NOTE_SELECTION_IMAGE_Y + 1, 28, 16, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#endif /*__MMI_RNGC_ENABLE_INS_LED_NOTE__*/
    {99, NOTE_SELECTION_IMAGE_Y + 19, 28, 16, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	
#endif /*__MMI_TOUCH_RING_COMPOSER__*/

#else 
#ifdef __MMI_TOUCH_RING_COMPOSER__
	static const rngc_custom_key_layout_struct normal_toolbar_custom_layout[] = 
	{
	    {1, 185, 34, 14, IMG_TOUCH_RING_EDIT, GUI_RNGC_KEY_EDIT},
	    {36, 185, 45, 14, IMG_TOUCH_RING_INSERT, GUI_RNGC_KEY_INSERT},
	    {82, 185, 45, 14, IMG_TOUCH_RING_PLAY, GUI_RNGC_KEY_PLAY},
	    {128, 185, 23, 14, IMG_TOUCH_RING_PREV, GUI_RNGC_KEY_PREV},
	    {152, 185, 23, 14, IMG_TOUCH_RING_NEXT, GUI_RNGC_KEY_NEXT}
	};

#ifdef __MMI_RING_COMPOSER_REPEAT__
	static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
	{
	    {134, 152, 18, 23, TOUCH_IMG_REPEAT_START, REPEAT_START},
	    {134, 176, 18, 23, TOUCH_IMG_REPEAT_END, REPEAT_END},
#if !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__)
	    {150, 152, 22, 23, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
#else /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */    
	    {153, 152, 22, 23, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
#endif /* !defined(__MMI_RNGC_ENABLE_INS_LED_NOTE__) */
	    {153, 176, 22, 23, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
	};
#else /* __MMI_RING_COMPOSER_REPEAT__ */
static rngc_custom_key_layout_struct note_selection_custom_layout[] = 
{
    {134, 152, 18, 23, IMG_RING_EVENTLED_ON, NOTE_LED_ON},
    {153, 152, 22, 23, IMG_RING_EVENTBL_ON, NOTE_BACKLIGHT_ON},
    {134, 176, 41, 23, IMG_TOUCH_RING_DOWN, GUI_RNGC_KEY_OK},
};
#endif /* __MMI_RING_COMPOSER_REPEAT__ */	
#endif /*__MMI_TOUCH_RING_COMPOSER__*/
#endif /*defined(__MMI_MAINLCD_176X220__) && defined(__MMI_TOUCH_RING_COMPOSER__)*/

#ifdef __MMI_TOUCH_RING_COMPOSER__
static const rngc_matrix_key_layout_struct normal_toolbar_matrix_layout = 
{
    RNGC_TOOL_BAR_LEFT_OFFSET, RNGC_TOOL_BAR_TOP_OFFSET,
    2, 7,
    RNGC_NOTE_SELECT_MATRIX_WIDTH, RNGC_NOTE_SELECT_MATRIX_HEIGHT,
    RNGC_MATRIX_KEY_WIDTH, RNGC_MATRIX_KEY_HEIGHT,
    {
     {IMG_TOUCH_RING_UP, TOUCH_IMG_1_OCT_L_M_N, TOUCH_IMG_1BY2_OCT_L_M_N, TOUCH_IMG_1BY4_OCT_L_M_N,
      TOUCH_IMG_1BY8_OCT_L_M_N, TOUCH_IMG_1BY16_OCT_L_M_N, IMG_RING_EVENTVIB_ON},
     {IMG_TOUCH_RING_DOWN, TOUCH_IMG_1BY4_OCT_L_M, TOUCH_IMG_1BY8_OCT_L_M, TOUCH_IMG_1BY16_OCT_L_M, IMG_TOUCH_RNGC_HASH,
      IMG_TOUCH_RING_P, IMG_TOUCH_RING_DOT},
     },
    {
     {GUI_RNGC_OCTAVE_UP, GUI_RNGC_KEY_NOTE1, GUI_RNGC_KEY_NOTE2, GUI_RNGC_KEY_NOTE3, GUI_RNGC_KEY_NOTE4,
      GUI_RNGC_KEY_NOTE5, NOTE_VIBRATION_ON},
     {GUI_RNGC_OCTAVE_DOWN, GUI_RNGC_KEY_NOTE6, GUI_RNGC_KEY_NOTE7, GUI_RNGC_KEY_NOTE8, GUI_RNGC_KEY_SHARP,
      GUI_RNGC_KEY_FLAT, GUI_RNGC_KEY_DOT},
     }
};

const static rngc_selection_area_layout_struct normal_toolbar_layout = 
{
    0,
    5,
    NORMAL_TOOLBAR_IMAGE_X,
    NORMAL_TOOLBAR_IMAGE_Y,
    (rngc_matrix_key_layout_struct *) & normal_toolbar_matrix_layout,
    (rngc_custom_key_layout_struct *) normal_toolbar_custom_layout,
    1,
    0,
    IMG_TOUCH_RING_NORMAL
};

const static rngc_matrix_key_layout_struct note_selection_matrix_layout = 
{
    RNGC_TOOL_BAR_LEFT_OFFSET, RNGC_TOOL_BAR_TOP_OFFSET,
    2, 7,
    RNGC_NOTE_SELECT_MATRIX_WIDTH, RNGC_NOTE_SELECT_MATRIX_HEIGHT,
    RNGC_MATRIX_KEY_WIDTH, RNGC_MATRIX_KEY_HEIGHT,
    {
     {IMG_TOUCH_RING_UP, TOUCH_IMG_1_OCT_L_M_N, TOUCH_IMG_1BY2_OCT_L_M_N, TOUCH_IMG_1BY4_OCT_L_M_N,
      TOUCH_IMG_1BY8_OCT_L_M_N, TOUCH_IMG_1BY16_OCT_L_M_N, IMG_RING_EVENTVIB_ON},
     {IMG_TOUCH_RING_DOWN, TOUCH_IMG_1BY4_OCT_L_M, TOUCH_IMG_1BY8_OCT_L_M, TOUCH_IMG_1BY16_OCT_L_M, IMG_TOUCH_RNGC_HASH,
      IMG_TOUCH_RING_P, IMG_TOUCH_RING_DOT},
     },
    {
     {GUI_RNGC_OCTAVE_UP, GUI_RNGC_KEY_NOTE1, GUI_RNGC_KEY_NOTE2, GUI_RNGC_KEY_NOTE3, GUI_RNGC_KEY_NOTE4,
      GUI_RNGC_KEY_NOTE5, NOTE_VIBRATION_ON},
     {GUI_RNGC_OCTAVE_DOWN, GUI_RNGC_KEY_NOTE6, GUI_RNGC_KEY_NOTE7, GUI_RNGC_KEY_NOTE8, GUI_RNGC_KEY_SHARP,
      GUI_RNGC_KEY_FLAT, GUI_RNGC_KEY_DOT},
     }
};

static const rngc_selection_area_layout_struct note_selection_layout = 
{
    14,
#ifdef __MMI_RING_COMPOSER_REPEAT__
    4,
#else /* __MMI_RING_COMPOSER_REPEAT__ */
    3,
#endif /* __MMI_RING_COMPOSER_REPEAT__ */
    NOTE_SELECTION_IMAGE_X,
    NOTE_SELECTION_IMAGE_Y,
    (rngc_matrix_key_layout_struct *) & note_selection_matrix_layout,
    (rngc_custom_key_layout_struct *) note_selection_custom_layout,
    RNGC_NOTE_SELECTION_HORZ_GAP,
    RNGC_NOTE_SELECTION_VERTICAL_GAP,
    IMG_TOUCH_RING_SELECTION
};

const UI_filled_area touch_rngc_color_key_filler = {UI_FILLED_AREA_TYPE_COLOR | UI_FILLED_AREA_SHADOW,
    UI_NULL_IMAGE,
    NULL,
#if (defined(__MMI_MAINLCD_320X480__))
    {146, 28, 255, 100},
#else
    {128, 255, 255, 100},
#endif
    {0, 0, 0, 0},
    {0, 0, 0, 100},
    {50, 50, 50, 100},
    0
};

#endif /* __MMI_TOUCH_RING_COMPOSER__ */
#define BACK_START_Y1 24

extern MMI_BOOL g_current_insert_mode;
/*****************************************************************************
* FUNCTION
*  mmi_rngc_show_composer
* DESCRIPTION
*  Show ringtone composer screen
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_show_composer(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __GDI_MEMORY_PROFILE_2__
    gdi_layer_multi_layer_enable();
    
    /* get base layer as skin layer */
    gdi_layer_get_base_handle(&rngc_osd_layer);
    gdi_layer_clear_background(GDI_COLOR_TRANSPARENT);
    gdi_layer_set_source_key(TRUE, GDI_COLOR_TRANSPARENT);
    gdi_layer_create(0, 0, UI_device_width, UI_device_height, &rngc_skin_layer);
    gdi_layer_set_blt_layer(rngc_skin_layer, rngc_osd_layer, 0, 0);
    gdi_get_alpha_blending_source_layer(&rngc_old_alpha_blending_src_layer);
    gdi_set_alpha_blending_source_layer(rngc_skin_layer);
    is_rngc_skin_layer_drawn = FALSE;
#endif 
    
    clear_key_handlers();
    clear_left_softkey();
    clear_right_softkey();
    
    /* associate functions */
    RedrawCategoryFunction = mmi_rngc_redraw_main_screen;
    GetCategoryHistory = dummy_get_history;
    GetCategoryHistorySize = dummy_get_history_size;
    
    /* draw screen */
    mmi_rngc_redraw_main_screen();
}


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_LSK
* DESCRIPTION
*  Changes the text of LSK 
* PARAMETERS
*  bPressed  [IN] Checks whether up(0) or down(1)
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_LSK(BOOL bPressed)
{
    mmi_rngc_redraw_SK(bPressed, MMI_LEFT_SOFTKEY, STR_GLOBAL_OPTIONS);
}


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_RSK
* DESCRIPTION
*  Changes the text of RSK 
* PARAMETERS
*  bPressed  [IN] Checks whether up(0) or down(1)
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_RSK(BOOL bPressed)
{
    if (g_rngc_eng_cntx->TotalNotes == 0)	
    {
        mmi_rngc_redraw_SK(bPressed, MMI_RIGHT_SOFTKEY, STR_GLOBAL_BACK);      
        change_right_softkey(STR_GLOBAL_BACK, IMG_GLOBAL_BACK);
    }
    else
    {
        mmi_rngc_redraw_SK(bPressed, MMI_RIGHT_SOFTKEY, STR_GLOBAL_CLEAR);
        change_right_softkey(STR_GLOBAL_CLEAR, IMG_GLOBAL_CLEAR);
    }
}
extern UI_filled_area* dm_get_current_scr_bg_filler(void);
/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_SK
* DESCRIPTION
*  Changes the text of SK 
* PARAMETERS
*  bPressed  [IN] Checks whether up(0) or down(1)
*  softkey   [IN] MMI_RIGHT_SOFTKEY or MMI_LEFT_SOFTKEY
*  softkey_text [IN] 
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_SK(BOOL bPressed, WGUI_SOFTKEY_ENUM key, U16 softkey_text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 str_w, str_h;
    S32 x1, y1, x2, y2;
    S32 clip_x1 = 0, clip_x2 = 0;
    MMI_BOOL truncated = MMI_FALSE;
    S32 truncated_width;
    UI_string_type text = 0;
    color c;
    UI_filled_area  *bg_image_filler;
    S32 image_bg_h = 0, image_bg_w = 0; 
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
	if(mmi_frm_scrn_get_active_id()!= SCR_COMPOSER_ENGINE)
	{
		return;
	}
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif 
    bg_image_filler = dm_get_current_scr_bg_filler();
    gdi_layer_push_clip();
    gui_push_text_clip();
    gui_set_font(gui_font_get_type(GUI_FONT_SIZE_BUTTON));
    if (key == MMI_LEFT_SOFTKEY)
    {
    	wgui_clear_left_softkey();
        if (bPressed)
        {
            gui_set_text_color(*(current_MMI_theme->LSK_down_text_color));  
        }
        else
        {
            gui_set_text_color(*(current_MMI_theme->LSK_up_text_color));  
        }
        clip_x1 = 0;
        clip_x2 = UI_device_width/2;
    }        
    else if (key == MMI_RIGHT_SOFTKEY)
    {
        wgui_clear_right_softkey();
        if (bPressed)
        {
            gui_set_text_color(*(current_MMI_theme->RSK_down_text_color));  
        }
        else
        {
            gui_set_text_color(*(current_MMI_theme->RSK_up_text_color));  
        }
        clip_x1 = UI_device_width/2;
        clip_x2 = UI_device_width - 1;
    }

    gui_set_text_border_color(*(current_MMI_theme->softkey_text_border_color));
    if (softkey_text == 0)
    {
        x1 = 0;
        x2 = UI_device_width/2;
        y1 = UI_device_height - MMI_BUTTON_BAR_HEIGHT;
        y2 = UI_device_height;
    }
    else
    {
        text = get_string(softkey_text);
        truncated = wgui_softkey_get_offset(
                        text,
                        &x1,
                        &y1,
                        &truncated_width,
                        key,
                        mmi_frm_get_screen_rotate());

        gui_measure_string(text, &str_w, &str_h);
        if (truncated == MMI_TRUE)
        {
            str_w = truncated_width; /* only need to display truncated string */
        }
        if(r2lMMIFlag)
        {
            x2 = x1 + 1;
            x1 = x1 - str_w;
        }
        else
        {
            x2 = x1 + str_w + 1;
        }
        y2 = y1 + str_h + 1;

        if (bPressed)
        {
            x1++;
            y1++;
        }
    #ifdef __MMI_TOUCH_RING_COMPOSER__
        SK_area.num = 4;
        SK_area.points = (mmi_pen_point_struct*) SK_points;
        SK_points[0].y = SK_points[1].y = y1;
        SK_points[2].y = SK_points[3].y = y2 + 1;
        if (r2lMMIFlag)
        {
            SK_points[0].x = SK_points[3].x = x2;
            SK_points[1].x = SK_points[2].x = x1 + 1;
        }
        else
        {
            SK_points[0].x = SK_points[3].x = x1;
            SK_points[1].x = SK_points[2].x = x2 + 1;
        }
    #endif /* __MMI_TOUCH_RING_COMPOSER__ */
    }    
#ifdef __GDI_MEMORY_PROFILE_2__
gdi_layer_push_and_set_active(rngc_skin_layer);
#endif
#if defined(__MMI_MAINLCD_128X160__)
    gui_measure_image((PU8) GetImage(g_rngc_skin_layout.main_bg_img_id), (S32*) &image_bg_w, (S32*) &image_bg_h);
    gdi_layer_set_clip(clip_x1, BKG_IMG_Y1 + image_bg_h, clip_x2 , UI_device_height);
#else
    gdi_layer_set_clip(clip_x1, UI_device_height - MMI_BUTTON_BAR_HEIGHT - 1, clip_x2 , UI_device_height);
#endif
#ifdef __GDI_MEMORY_PROFILE_2__
    #if defined(__MMI_MAINLCD_128X160__)
	gdi_draw_solid_rect(clip_x1, BKG_IMG_Y1 + image_bg_h, clip_x2 , UI_device_height, GDI_COLOR_TRANSPARENT);
    #else
        gdi_draw_solid_rect(clip_x1, UI_device_height - MMI_BUTTON_BAR_HEIGHT - 1 , clip_x2 , UI_device_height, GDI_COLOR_TRANSPARENT);
    #endif
    #if (defined(__MMI_MAINLCD_128X160__)) 
	gui_draw_filled_area(clip_x1, BKG_IMG_Y1 + image_bg_h, clip_x2, UI_device_height, bg_image_filler);
    #endif
	gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
#else 
    gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
#endif
#ifdef __GDI_MEMORY_PROFILE_2__
	     gdi_layer_pop_and_restore_active();
#endif
    if (softkey_text != 0)
    {
        gui_set_text_clip(x1-1, y1 - 1, x2, y2);
        if (r2lMMIFlag)
        {
            gui_move_text_cursor(x1 + str_w, y1);
        }
        else
        {
            gui_move_text_cursor(x1, y1);
        }
        #ifdef __GDI_MEMORY_PROFILE_2__
	        gdi_draw_solid_rect(x1 -4, y1 -1, x2 , y2, GDI_COLOR_TRANSPARENT);
        #else   
            gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
        #endif

        if (truncated)
        {
            gui_print_truncated_borderd_text(x1, y1, truncated_width, text);
        }
        else
        {
            gui_print_bordered_text(text);
        }
    }
	else
	{
		        gui_set_text_clip(x1-1, y1 - 1, x2, y2);
        #ifdef __GDI_MEMORY_PROFILE_2__
	        gdi_draw_solid_rect(x1 -4, y1 -1, x2 , y2, GDI_COLOR_TRANSPARENT);
        #else   
            gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
        #endif

	}
    gui_pop_text_clip();
    gdi_layer_pop_clip();
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(clip_x1, UI_device_height - MMI_BUTTON_BAR_HEIGHT, clip_x2, UI_device_height);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
}


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_main_screen
* DESCRIPTION
*  Redraws the main screen of the composer 
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_main_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif 

    gui_push_clip();
    
#ifdef __GDI_MEMORY_PROFILE_2__
    if (!is_rngc_skin_layer_drawn)
    {
        S32 y2;
        
        /* background image on skin layer */
    #ifdef __MMI_TOUCH_RING_COMPOSER__
        if (touch_rngc_context.area_type == GUI_RNGC_NORMAL_TOOLBAR)
        {
            y2 = g_rngc_skin_layout.main_bg_img_area_y2 - NORMAL_TOOLBAR_HEIGHT;
        }
        else if (touch_rngc_context.area_type == GUI_RNGC_NOTE_SELECTION)
        {
            y2 = g_rngc_skin_layout.main_bg_img_area_y2 - NOTE_SELECTION_HEIGHT;
        }
    #else /* __MMI_TOUCH_RING_COMPOSER__ */ 
        y2 = g_rngc_skin_layout.main_bg_img_area_y2;
    #endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
        
        gdi_layer_push_and_set_active(rngc_skin_layer);
#endif /* __GDI_MEMORY_PROFILE_2__ */ 
    
        gui_set_clip(0, g_rngc_skin_layout.main_bg_img_area_y1, UI_device_width - 1, UI_device_height - 1);
        gui_show_image(0, g_rngc_skin_layout.main_bg_img_area_y1, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
#ifdef __GDI_MEMORY_PROFILE_2__
        is_rngc_skin_layer_drawn = TRUE;
        gdi_layer_pop_and_restore_active();
    }
#endif /* __GDI_MEMORY_PROFILE_2__ */ 

    gui_pop_clip();
    
    mmi_rngc_draw_status_icons();
    mmi_rngc_redraw_stave();
    mmi_rngc_redraw_remaining_notes();
    /* Also invokes redraw_instrument so no need to explicitly call */    	
    mmi_rngc_redraw_title();
    mmi_rngc_redraw_touch_screen();
    
#ifdef __MMI_TOUCH_RING_COMPOSER__
    if (touch_rngc_context.area_type != GUI_RNGC_NOTE_SELECTION)
    {
        mmi_rngc_redraw_LSK(0);
    }
#else /* __MMI_TOUCH_RING_COMPOSER__ */ 
    mmi_rngc_redraw_LSK(0);
#endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
    mmi_rngc_redraw_RSK(0);

#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(0, 0, UI_device_width - 1, UI_device_height - 1);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
}

/*****************************************************************************
* FUNCTION
*  mmi_rngc_draw_status_icons
* DESCRIPTION
*  redraw rngc status icons
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_draw_status_icons(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /*if show title status area*/
#ifndef RNGC_STATUS_BAR_TRANSPANT_BG
#ifdef GUI_COMMON_SHOW_STATUS_ICON
    show_title_status_icon();
    wgui_status_icon_bar_update();
#endif  /*GUI_COMMON_SHOW_STATUS_ICON*/
#else /* RNGC_STATUS_BAR_TRANSPANT_BG */
    wgui_status_icon_bar_register_hide_callback(
        WGUI_STATUS_ICON_BAR_H_BAR, 
        mmi_rngc_redraw_statusbar_bg_callback);
    wgui_status_icon_bar_set_display(WGUI_STATUS_ICON_BAR_H_BAR);
    wgui_status_icon_bar_update();
#endif /*RNGC_STATUS_BAR_TRANSPANT_BG*/
}    

/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_stave
* DESCRIPTION
*  Draws the current stave list
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_stave(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 width = 0, index = 0;
    S32 img_width, img_height;
    color c;
            
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif 
    gui_push_clip();
    gui_set_clip(RNGC_X_POS_BASED, g_rngc_skin_layout.stave_rectangle_y1, UI_device_width, 
                g_rngc_skin_layout.stave_rectangle_y2);
#ifdef __GDI_MEMORY_PROFILE_2__
    gdi_draw_solid_rect(RNGC_X_POS_BASED, g_rngc_skin_layout.stave_rectangle_y1, UI_device_width, 
                g_rngc_skin_layout.stave_rectangle_y2, GDI_COLOR_TRANSPARENT);
#else 
    gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
#endif
    width = g_rngc_eng_cntx->CursorWidth;
    for (index = 0; index < NUM_NOTES_IN_STAVE; index++)
    {
        if ((g_rngc_eng_cntx->ImageList[index] != NULL))
        {
            gui_measure_image(g_rngc_eng_cntx->ImageList[index], (S32*) & img_width, (S32*) & img_height);
            gui_show_transparent_image(
                (RNGC_X_POS_BASED + index * RNGC_X_POS_OFFSET + ((width - img_width) >> 1)),
                g_rngc_eng_cntx->YPos[index],
                g_rngc_eng_cntx->ImageList[index],
                gui_transparent_color(255, 255, 255));
        }
    }
    
    /*Begin: draw rectangle around the stave */
    c = gui_color(0, 0, 240);
    width = g_rngc_eng_cntx->CursorWidth;
    
#ifdef __MMI_TOUCH_RING_COMPOSER__
    if (touch_rngc_context.mode == GUI_RNGC_EDIT || touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
    {
        c = gui_color(255, 0, 0);
    }
#endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
    gui_draw_rectangle(
        (RNGC_X_POS_BASED + g_rngc_eng_cntx->CurrUIPos * RNGC_X_POS_OFFSET),
        g_rngc_skin_layout.stave_rectangle_y1,
        (RNGC_X_POS_BASED + g_rngc_eng_cntx->CurrUIPos * RNGC_X_POS_OFFSET + width + 1),
        g_rngc_skin_layout.stave_rectangle_y2,
        c);
    /*End: draw rectangle around stave*/
    gui_pop_clip();
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(RNGC_X_POS_BASED, g_rngc_skin_layout.stave_rectangle_y1, 
                        UI_device_width, g_rngc_skin_layout.stave_rectangle_y2);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
}    


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_remaining_notes
* DESCRIPTION
*  redraw remaining number of notes
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_remaining_notes(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 y1, y2, x1;
    S32 temp_height = 0, temp_width = 0;
    UI_character_type string_conv[6], max_string[6];
    color c;
#if (!defined(__MMI_MAINLCD_240X400__)) && (!defined(__MMI_MAINLCD_320X480__))
    color text_color = gui_color(0, 0, 0);
    color text_border_color = gui_color(255, 255, 255);
#else
    color text_color = gui_color(255, 255, 255);
    color text_border_color = gui_color(0, 0, 0);
#endif
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif 
    gui_push_clip();
    /*Begin: draw remaining notes number rectangle*/
    y1 = g_rngc_skin_layout.remain_notes_rect_y1;
    y2 = g_rngc_skin_layout.remain_notes_rect_y1 + g_rngc_skin_layout.remain_notes_rect_height;

    /* remaining number of notes */
    c = gui_color(0, 0, 0);
    gui_set_font(&MMI_small_font);
    gui_set_text_color(text_color); 
    gui_set_text_border_color(text_border_color);
    gui_itoa((S32) (MAX_NOTES - g_rngc_eng_cntx->TotalNotes), string_conv, 10);
    /* Character 4 requires MAX width */
    gui_itoa((S32) (MAX_NOTES - 6), max_string, 10);
    gui_measure_string((UI_string_type) max_string, &temp_width, &temp_height);
    
    if(g_rngc_skin_layout.is_draw_notes_rect_bg_color)
    {
        x1 = 0;
    }
    else
    {
        x1 = UI_device_width - temp_width - RNGC_NUM_RIGHT_ALIGN_OFFSET;
    }
    gui_set_clip(x1, y1-1, UI_device_width, y2);
#ifdef __GDI_MEMORY_PROFILE_2__
    gdi_draw_solid_rect(x1, y1-1, UI_device_width, y2, GDI_COLOR_TRANSPARENT);
#else 
    gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
#endif

    /*in some LCD size, need draw background rectangle color*/
    /*in some other LCD size, draw text on main background image directly*/
    /*draw background rectangle color*/
    if(g_rngc_skin_layout.is_draw_notes_rect_bg_color)
    {
        gui_draw_filled_area(x1, y1-1, UI_device_width, y2, (UI_filled_area*)&lightblue_color_dialog_background);     
    }
    
    if (r2lMMIFlag)
    {
        gui_move_text_cursor(UI_device_width - RNGC_NUM_RIGHT_ALIGN_OFFSET, y1 + NOTE_BAR_HEIGHT - temp_height);
    }
    else
    {
        gui_move_text_cursor(UI_device_width - temp_width - RNGC_NUM_RIGHT_ALIGN_OFFSET, y1 + NOTE_BAR_HEIGHT - temp_height);
    }

    gui_print_bordered_text((UI_string_type) string_conv);
    gui_set_font(&MMI_default_font);
    /*End : drawing remaining notes number rectangle*/
    gui_pop_clip();
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(x1, y1-1, UI_device_width, y2);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */   
}    


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_instrument
* DESCRIPTION
*  redraw the instrument
*  void
* RETURNS
*  The width of the instrument image
*****************************************************************************/
S32 mmi_rngc_redraw_instrument(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 img_width, img_height;
    S32 x1, y1, x2, y2;
    PU8 MMI_title_icon_ring_comp = NULL;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    
     if(mmi_frm_scrn_get_active_id()!= SCR_COMPOSER_ENGINE)
     {
	return;
     }
    
    /* In some LCD size, has a rectangle for instrument select and implemented 
    /* by GUI interfaces in some other LCD size, do not has instrument select 
    /* rectangle but show instrument image on title area right side           */
    MMI_title_icon_ring_comp = (PU8) get_image(GetInstrumentImage(g_rngc_cntx.CurrInstr));
    gui_measure_image(MMI_title_icon_ring_comp, (S32*) & img_width, (S32*) & img_height);
    
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif 
    gui_push_clip();
    /*if show instrument horizontal select rectangle */
#ifdef RNGC_HAS_INST_RECTANGLE
    x1 = 0;
    y1 = g_rngc_skin_layout.instr_sel_rect_y1;
    x2 = UI_device_width;
    y2 = g_rngc_skin_layout.instr_sel_rect_y2;

    gui_set_clip(x1, y1, x2, y2);    
    gui_draw_filled_area(x1, y1, x2, y2, 
        (UI_filled_area*)&rngc_instrument_select_background);
    gui_show_image(
        g_rngc_skin_layout.instr_img_x1, y1 + ((y2 - y1 - img_height) >> 1),
        MMI_title_icon_ring_comp);    
    gui_horizontal_select_show(&MMI_rngc_instrument_select_menu);
#else /*RNGC_HAS_INST_RECTANGLE*/
    x1 = UI_device_width - 1 - img_width;
    y1 = g_rngc_skin_layout.title_rect_y1 + 
        ((g_rngc_skin_layout.title_rect_height - img_height) >> 1);
    x2 = UI_device_width;
    y2 = (g_rngc_skin_layout.title_rect_y1 + g_rngc_skin_layout.title_rect_height) - 1;

    gui_set_clip(x1, y1, x2, y2);
    gui_show_image(x1, y1, MMI_title_icon_ring_comp);
    img_width = 0;    
#endif /*RNGC_HAS_INST_RECTANGLE*/    
    
    gui_pop_clip();    
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(x1, y1, x2, y2);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */
    return img_width;
}    


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_main_title_background
* DESCRIPTION
*  redraw rngc main title background
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_main_title_background(S32 x1, S32 y1, S32 x2, S32 y2)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    color c;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    c = gui_color(255, 255, 255);
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif   
    gui_push_clip();
    gui_set_clip(x1, y1, x2, y2);
#if !(defined(__MMI_MAINLCD_320X240__) || defined(__MMI_MAINLCD_240X400__) || defined(__MMI_MAINLCD_320X480__))
    gui_fill_rectangle(x1, y1, x2, y2, c);
    gui_draw_filled_area(x1, y1, x2, y2,
#ifdef GUI_COMMON_USE_THICK_TITLE
        current_UI_theme->thick_title_theme->active_filler);
#else /* GUI_COMMON_USE_THICK_TITLE */
        current_UI_theme->window_title_theme->active_filler);
#endif /* GUI_COMMON_USE_THICK_TITLE */
#endif /* !defined(__MMI_MAINLCD_320X240__) ||... */

    gui_pop_clip();    
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(x1, y1, x2, y2);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
}


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_title
* DESCRIPTION
*  redraw rngc main title 'Stave'
*  Invokes redraw_instrument 
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_title(void)
{        

    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 x1, y1, x2, y2;
    S32 width = 0, width_title, height_title;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    x1 = 0;
    y1 = g_rngc_skin_layout.title_rect_y1;
    x2 = UI_device_width - 1;
    y2 = y1 + g_rngc_skin_layout.title_rect_height - 1;
    
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
#endif 
      
    mmi_rngc_redraw_main_title_background(x1, y1, x2, y2);
#ifndef RNGC_HAS_INST_RECTANGLE   
    width = mmi_rngc_redraw_instrument();
#else
    mmi_rngc_redraw_instrument();
#endif /*RNGC_HAS_INST_RECTANGLE*/

    gui_push_clip();
    gui_set_text_color(*(current_MMI_theme->title_text_color));  
    gui_set_text_border_color(*(current_MMI_theme->title_text_border_color));
    gui_measure_string((UI_string_type) get_string(STR_RING_COMPOSE_TITLE), &width_title, &height_title);

    if (r2lMMIFlag)
    {
        gui_move_text_cursor((((UI_device_width - 1 - width) >> 1) - (width_title >> 1)) + width_title,
            g_rngc_skin_layout.title_rect_y1 + ((g_rngc_skin_layout.title_rect_height - height_title) >> 1));
    }
    else
    {
        gui_move_text_cursor((((UI_device_width - 1 - width) >> 1) - (width_title >> 1)),
            g_rngc_skin_layout.title_rect_y1 + ((g_rngc_skin_layout.title_rect_height - height_title) >> 1));
    }
    gui_set_clip(x1, y1, x2, y2);    
    gui_print_bordered_text((UI_string_type) get_string(STR_RING_COMPOSE_TITLE));
    gui_pop_clip();
    
#if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(x1, y1, x2, y2);
#endif /* (UI_DOUBLE_BUFFER_SUPPORT) */ 
}


/*****************************************************************************
* FUNCTION
*  mmi_rngc_redraw_touch_screen
* DESCRIPTION
*  redraw rngc touch screen
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_redraw_touch_screen(void)
{   
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef __MMI_TOUCH_RING_COMPOSER__
    if ((touch_rngc_context.flag & RNGC_SELECTION_AREA_REDRAW) == RNGC_SELECTION_AREA_REDRAW)
    {
        show_touch_rngc_selection_area();
    }
#endif /* __MMI_TOUCH_RING_COMPOSER__ */     
}


/*****************************************************************************
* FUNCTION
*  mmi_rngc_exit_mainscreen
* DESCRIPTION
*  exit ring composer main screen
*  Frees the memory allocated
*  Flatten to base the various layers
* PARAMETERS
*  void
* RETURNS
*  void
*****************************************************************************/
void mmi_rngc_exit_mainscreen(void)
{
#ifdef __GDI_MEMORY_PROFILE_2__
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
 #ifdef __MMI_TOUCH_RING_COMPOSER__
    if (selection_area_context == &note_selection_layout)
    {
        selection_area_context->custom_keys[selection_area_context->n_custom_keys-1].key_image = IMG_TOUCH_RING_DOWN;
    }
    selection_area_context = &normal_toolbar_layout;
    touch_rngc_context.area_type = GUI_RNGC_NORMAL_TOOLBAR;

    if (touch_rngc_context.selected_key_bitmap.buf_ptr)
    {
        mmi_frm_scrmem_free((void*)touch_rngc_context.selected_key_bitmap.buf_ptr);
        touch_rngc_context.selected_key_bitmap.buf_ptr = NULL;
    }
#endif /* __MMI_TOUCH_RING_COMPOSER__ */ 
 
    gdi_set_alpha_blending_source_layer(rngc_old_alpha_blending_src_layer);
    gdi_layer_flatten_to_base(rngc_skin_layer, rngc_osd_layer, 0, 0);
    gdi_layer_free(rngc_skin_layer);
    gdi_layer_multi_layer_disable();
    
    /* restore blt layer as base layer only */
    gdi_layer_set_blt_layer(rngc_osd_layer, 0, 0, 0);
#endif /* __GDI_MEMORY_PROFILE_2__ */ 

#ifdef RNGC_HAS_INST_RECTANGLE
    gui_horizontal_select_close(&MMI_rngc_instrument_select_menu);      
#endif /*RNGC_HAS_INST_RECTANGLE*/

}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_initialize_skinlayout
 * DESCRIPTION
 *  Initializes the variables of g_rngc_skin_layout
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_initialize_skinlayout(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 title_bar_y1, title_bar_height;
    
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/ 
#ifdef GUI_COMMON_USE_THICK_TITLE
    title_bar_y1 = 0;
    title_bar_height = MMI_THICK_TITLE_HEIGHT;
#else /*GUI_COMMON_USE_THICK_TITLE*/
    title_bar_y1 = MMI_title_y;
    title_bar_height = MMI_title_height;
#endif /*GUI_COMMON_USE_THICK_TITLE*/
/* 240X320 begin */
#if  defined(__MMI_MAINLCD_240X320__)
    /*main background image*/
    g_rngc_skin_layout.main_bg_img_id = IMG_RING_COMPOSER_BACKGROUND;
    g_rngc_skin_layout.main_bg_img_area_y1 = 0;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT;

    /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = title_bar_y1 + title_bar_height + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT + RNGC_INSTR_SELECT_MARGIN * 2 + NOTE_BAR_HEIGHT + 5;
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 4;

    g_rngc_skin_layout.stave_rectangle_y2 -= NOTE_SELECTION_HEIGHT;

    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_FALSE;
    g_rngc_skin_layout.remain_notes_rect_y1 = title_bar_y1 + title_bar_height + RNGC_INSTR_SELECT_MARGIN * 2 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;

    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = title_bar_y1 + title_bar_height + 2;
    g_rngc_skin_layout.instr_sel_rect_y2 = g_rngc_skin_layout.instr_sel_rect_y1 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT;
    g_rngc_skin_layout.instr_img_x1 = RNGC_INSTR_SELECT_X_OFFSET*2;

    g_rngc_skin_layout.title_rect_y1 = title_bar_y1;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
/* 240 X 320 end */    
#elif defined(__MMI_MAINLCD_320X240__)
/* 320 X240 begin */
    title_bar_height = 31;
    /*main background image*/
    g_rngc_skin_layout.main_bg_img_id = IMG_RING_COMPOSER_BACKGROUND;
    g_rngc_skin_layout.main_bg_img_area_y1 = 0;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 1;
    
    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_FALSE;
    g_rngc_skin_layout.remain_notes_rect_y1 =  title_bar_height + RNGC_INSTR_SELECT_MARGIN * 2 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT + 5;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;

    /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = g_rngc_skin_layout.remain_notes_rect_y1 + NOTE_BAR_HEIGHT - 3;
    
#if defined ( __MMI_TOUCH_RING_COMPOSER__)
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - NOTE_SELECTION_HEIGHT - 4;
#else /*because the new background image has the edge rect, should not overlape the line*/
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 16;
#endif

    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = title_bar_height + RNGC_INSTR_SELECT_MARGIN;
    g_rngc_skin_layout.instr_sel_rect_y2 = g_rngc_skin_layout.instr_sel_rect_y1 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT;
    g_rngc_skin_layout.instr_img_x1 = RNGC_INSTR_SELECT_X_OFFSET*2;

    g_rngc_skin_layout.title_rect_y1 = 0;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
/* 320 X 240 end */
#elif defined(__MMI_MAINLCD_240X400__)
/* 240 X 400 begin */
    title_bar_height = 45;
    /*main background image*/
    g_rngc_skin_layout.main_bg_img_id = IMG_RING_COMPOSER_BACKGROUND;
    g_rngc_skin_layout.main_bg_img_area_y1 = 0;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 2;
 
    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_FALSE;
    g_rngc_skin_layout.remain_notes_rect_y1 =  title_bar_y1 + title_bar_height + RNGC_INSTR_SELECT_MARGIN * 2 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT + 5;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;

     /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = title_bar_y1 + g_rngc_skin_layout.remain_notes_rect_y1 + NOTE_BAR_HEIGHT - 1;
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 30;

#ifdef __MMI_TOUCH_RING_COMPOSER__
    g_rngc_skin_layout.stave_rectangle_y2 -= NOTE_SELECTION_HEIGHT;
#endif 

    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = title_bar_y1 + title_bar_height + RNGC_INSTR_SELECT_MARGIN;
    g_rngc_skin_layout.instr_sel_rect_y2 = g_rngc_skin_layout.instr_sel_rect_y1 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT;
    g_rngc_skin_layout.instr_img_x1 = RNGC_INSTR_SELECT_X_OFFSET*2;

    g_rngc_skin_layout.title_rect_y1 = title_bar_y1;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
    
/* 240 X 400 end */    

#elif defined(__MMI_MAINLCD_320X480__)
/* 320 X 480 begin */
    title_bar_height = 45;
    /*main background image*/
    g_rngc_skin_layout.main_bg_img_id = IMG_TOUCH_RING_COMPOSER_BACKGROUND;
    g_rngc_skin_layout.main_bg_img_area_y1 = 0;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 2;
 
    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_FALSE;
    g_rngc_skin_layout.remain_notes_rect_y1 =  title_bar_y1 + title_bar_height + RNGC_INSTR_SELECT_MARGIN * 2 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT + 5;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;

     /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = title_bar_y1 + g_rngc_skin_layout.remain_notes_rect_y1 + NOTE_BAR_HEIGHT - 1;
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 25;

#ifdef __MMI_TOUCH_RING_COMPOSER__
    g_rngc_skin_layout.stave_rectangle_y2 -= NOTE_SELECTION_HEIGHT;
#endif 

    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = title_bar_y1 + title_bar_height + RNGC_INSTR_SELECT_MARGIN;
    g_rngc_skin_layout.instr_sel_rect_y2 = g_rngc_skin_layout.instr_sel_rect_y1 + MMI_RNGC_INSTRUMENT_SELECT_HEIGHT;
    g_rngc_skin_layout.instr_img_x1 = RNGC_INSTR_SELECT_X_OFFSET*2;

    g_rngc_skin_layout.title_rect_y1 = title_bar_y1;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
/* 320 X 480 end */  

#elif defined(__MMI_MAINLCD_128X160__)
/* 128X160 begin */
    g_rngc_skin_layout.main_bg_img_id = IMG_RING_COMPOSER_BACKGROUND;
    g_rngc_skin_layout.main_bg_img_area_y1 = BKG_IMG_Y1;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 2;
    
    /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = (title_bar_y1 + title_bar_height) + NOTE_BAR_HEIGHT + 2;
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 4;

    g_rngc_skin_layout.stave_rectangle_y2 -= NOTE_SELECTION_HEIGHT;
    
    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_TRUE;
    g_rngc_skin_layout.remain_notes_rect_y1 = title_bar_y1 + title_bar_height + 1;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;
    
    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = 0;
    g_rngc_skin_layout.instr_sel_rect_y2 = 0;
    g_rngc_skin_layout.instr_img_x1 = 0;
    
    g_rngc_skin_layout.title_rect_y1 = title_bar_y1;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
/* 128x160 end */
#elif defined(__MMI_MAINLCD_176X220__)
/* 176x220 begin */
    /*main background image*/
    g_rngc_skin_layout.main_bg_img_id = IMG_TOUCH_RING_COMPOSER_BACKGROUND;
    g_rngc_skin_layout.main_bg_img_area_y1 = 0;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT;

    /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = (title_bar_y1 + title_bar_height) + NOTE_BAR_HEIGHT + 2;
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 2;
 
   g_rngc_skin_layout.stave_rectangle_y2 -= NOTE_SELECTION_HEIGHT;
    
    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_TRUE;
    g_rngc_skin_layout.remain_notes_rect_y1 = title_bar_y1 + title_bar_height + 1;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;
    
    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = 0;
    g_rngc_skin_layout.instr_sel_rect_y2 = 0;
    g_rngc_skin_layout.instr_img_x1 = 0;

    g_rngc_skin_layout.title_rect_y1 = title_bar_y1;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
/* 176x220 end */
#else
/* 128x128 begin */
    /*main background image*/
    g_rngc_skin_layout.main_bg_img_id = IMG_RING_COMPOSER_BACKGROUND;

    g_rngc_skin_layout.main_bg_img_area_y1 = BACK_START_Y1;
    g_rngc_skin_layout.main_bg_img_area_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT;

    /*the rectangle around stave coordinate*/
    g_rngc_skin_layout.stave_rectangle_y1 = (title_bar_y1 + title_bar_height) + NOTE_BAR_HEIGHT + 2;
    g_rngc_skin_layout.stave_rectangle_y2 = UI_device_height - MMI_BUTTON_BAR_HEIGHT - 2;
    
    /*if draw background rectangle for indicating remaining notes number*/
    g_rngc_skin_layout.is_draw_notes_rect_bg_color = MMI_TRUE;
    g_rngc_skin_layout.remain_notes_rect_y1 = title_bar_y1 + title_bar_height;
    g_rngc_skin_layout.remain_notes_rect_height = NOTE_BAR_HEIGHT;
    
    /*if draw instrument select rectangle */
    g_rngc_skin_layout.instr_sel_rect_y1 = 0;
    g_rngc_skin_layout.instr_sel_rect_y2 = 0;
    g_rngc_skin_layout.instr_img_x1 = 0;

    g_rngc_skin_layout.title_rect_y1 = title_bar_y1;
    g_rngc_skin_layout.title_rect_height = title_bar_height;
/* 128x128 end */
#endif /*defined(__MMI_MAINLCD_240X320__) */

}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_initialize_composer
 * DESCRIPTION
 *  This function is to clear stave, speed, instrument and get cursor width
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_initialize_composer(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    RngcInitCursor();
    RngcClearStave();
    g_rngc_cntx.CurrSpeed = NORMAL_SPEED;
    g_rngc_cntx.CurrInstr = RNGC_DEFAULT_FIRST_INSTR;
//#ifdef __MMI_RING_COMPOSER_STYLE__
    g_rngc_cntx.CurrStyle = NORMAL_STYLE;
//#endif    
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_redraw_notes
 * DESCRIPTION
 *  RedrawNotes (old name)
 *  This function is to redraw the stave
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
MMI_BOOL mmi_rngc_redraw_notes(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 nFirstNoteIndex;
    S16 nEndNote;
    U16 nTemp;
    U16 nImageId = 0;
    U16 nCount = 0;
    U16 nYVal = 0;
    DisplayInfo sDisplayInfo[NUM_NOTES_IN_STAVE];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* get the first note to be drawed */
    nFirstNoteIndex = g_rngc_eng_cntx->CurrNoteIndex - g_rngc_eng_cntx->CurrUIPos;
    if (nFirstNoteIndex < 0)
    {
        nFirstNoteIndex = 0;
    }

    /* get the last note to be drawed */
    if (nFirstNoteIndex + NUM_NOTES_IN_STAVE >= g_rngc_eng_cntx->TotalNotes)    /* tail */
    {
        nEndNote = g_rngc_eng_cntx->TotalNotes - 1;
    }
    else
    {
        nEndNote = (nFirstNoteIndex + NUM_NOTES_IN_STAVE) - 1;
    }

    for (nTemp = nFirstNoteIndex; nTemp <= nEndNote; ++nTemp)
    {
        if (!GetIndexInList(g_rngc_eng_cntx->NotesList[nTemp], &nImageId, &nYVal))
        {
            return MMI_FALSE;
        }
        sDisplayInfo[nCount].nImageId = nImageId;
        sDisplayInfo[nCount].nXPos = (U8) nTemp;
        sDisplayInfo[nCount].nYPos = nYVal;
        ++nCount;
    }

    mmi_rngc_refresh_notes_list(nCount, (DisplayInfo*) sDisplayInfo);
    return MMI_TRUE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_refresh_notes_list
 * DESCRIPTION
 *  RefreshNotesList (old name)
 *  Update position and image of note list to be displayed
 * PARAMETERS
 *  TotalNotes          [IN]        Total number of notes to be displyed
 *  psDisplayInfo       [IN]        List of display information
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_refresh_notes_list(U16 TotalNotes, DisplayInfo *psDisplayInfo)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    DisplayInfo *ptmpDisplayInfo = NULL;
    S32 index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!psDisplayInfo)
    {
        return;
    }

    for (index = 0; index < NUM_NOTES_IN_STAVE; index++)
    {
        g_rngc_eng_cntx->ImageList[index] = NULL;
    }

    ptmpDisplayInfo = psDisplayInfo;

    for (index = 0; index < TotalNotes; index++)
    {
        g_rngc_eng_cntx->YPos[index] = ptmpDisplayInfo->nYPos;
        g_rngc_eng_cntx->ImageList[index] = (PU8) GetImage(ptmpDisplayInfo->nImageId);
        ptmpDisplayInfo++;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_show_note
 * DESCRIPTION
 *  ShowNote (old name) 
 *  Display current modified note
 * PARAMETERS
 *  nNote       [IN]        Musical note
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_show_note(U16 nNote)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 nImageId = 0;
    U16 nYPos = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    GetIndexInList(nNote, &nImageId, &nYPos);

    g_rngc_eng_cntx->YPos[g_rngc_eng_cntx->CurrUIPos] = nYPos;
    /* flag_shown[g_rngc_eng_cntx->CurrUIPos] = SHOW_IMG; */
    g_rngc_eng_cntx->ImageList[g_rngc_eng_cntx->CurrUIPos] = (PU8) GetImage(nImageId);
    mmi_rngc_redraw_stave();
#if defined(__MMI_MAINLCD_320X240__)
    mmi_rngc_redraw_remaining_notes();
#endif
}


#ifdef RNGC_HAS_INST_RECTANGLE
/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_instrument_menu_clear_background_callback
 * DESCRIPTION
 *  used by horizontal select to clear the background.
 * PARAMETERS
 *  x1  [IN]    the leftmost x coordinate
 *  y1  [IN]    the topmost y coordinate
 *  x2  [IN]    the rightmost x coordinate
 *  y2  [IN]    the bottom y coordinate
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_instrument_menu_clear_background_callback(S32 x1, S32 y1, S32 x2, S32 y2)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    gui_push_clip();
    gui_set_clip(x1, y1, x2, y2);
    gui_draw_filled_area(
        x1,
        y1,
        x2,
        y2,
        (UI_filled_area*)&rngc_instrument_select_background);
    gui_pop_clip();
}

/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_initialize_instrument_select_menu_items
 * DESCRIPTION
 *  
 * PARAMETERS
 *  x                       [IN]        
 *  y                       [IN]        
 *  width                   [IN]        
 *  height                  [IN]        
 *  list_of_items           [IN]        
 *  highlighted_item        [?]         
 *  f                       [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_initialize_instrument_select_menu_items(
        S32 x,
        S32 y,
        S32 width,
        S32 height,
        U8 **list_of_items,
        S32 *highlighted_item,
        void (*f) (S32 item_index))
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    for (i = 0; i < ENUM_TOTAL_INSTR; i++)
    {
        MMI_rngc_instrument_select_items[i].text = (UI_string_type) list_of_items[i];
    }
#if (defined(__MMI_MAINLCD_240X320__) || defined(__MMI_MAINLCD_320X240__) || defined(__MMI_MAINLCD_240X400__) || defined(__MMI_MAINLCD_320X480__))

#ifdef __MMI_TOUCH_RING_COMPOSER__
    MMI_rngc_instrument_select_theme.left_arrow_image =(PU8)GetImage(IMG_RING_INSTRU_LEFT_ARROW_UP);
    MMI_rngc_instrument_select_theme.left_arrow_clicked_image = (PU8)GetImage(IMG_RING_INSTRU_LEFT_ARROW_UP);
    MMI_rngc_instrument_select_theme.right_arrow_image = (PU8)GetImage(IMG_RING_INSTRU_RIGHT_ARROW_UP);
    MMI_rngc_instrument_select_theme.right_arrow_clicked_image = (PU8)GetImage(IMG_RING_INSTRU_RIGHT_ARROW_UP);
#else

    MMI_rngc_instrument_select_theme.left_arrow_image = NULL;
    MMI_rngc_instrument_select_theme.left_arrow_clicked_image = NULL;
    MMI_rngc_instrument_select_theme.right_arrow_image = NULL;
    MMI_rngc_instrument_select_theme.right_arrow_clicked_image = NULL;
#endif/*__MMI_TOUCH_RING_COMPOSER__*/

#endif

    gui_horizontal_select_create(
        &MMI_rngc_instrument_select_menu, 
        x, 
        y, 
        width,
        height,
        UI_HORIZONTAL_SELECT_FOCUSED_STATE | UI_HORIZONTAL_SELECT_LOOP,
        *highlighted_item,
        f,
        MMI_rngc_instrument_select_items,
        ENUM_TOTAL_INSTR);
    gui_horizontal_select_set_theme(&MMI_rngc_instrument_select_menu, &MMI_rngc_instrument_select_theme);
    
    gui_horizontal_select_register_hide_callback(
        &MMI_rngc_instrument_select_menu, 
        mmi_rngc_instrument_menu_clear_background_callback);
}
#endif /*RNGC_HAS_INST_RECTANGLE */ 


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_change_instrument
 * DESCRIPTION
 *   Changes the instrument name 
 * PARAMETERS
 *  selected_instrument     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_change_instrument(S32 selected_instrument)    /* PMT MANISH   20050616 */
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 current_instrument = GetCurrIndexCompRingToneInst();

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    MMI_DBG_ASSERT((RNGC_PREVIOUS_INSTR == selected_instrument) || (RNGC_NEXT_INSTR == selected_instrument));

    if (RNGC_PREVIOUS_INSTR == selected_instrument)
    {
        if (RNGC_DEFAULT_FIRST_INSTR == CurrentInstrument[current_instrument])
        {
            current_instrument = ENUM_TOTAL_INSTR - 1;
        }
        else
        {
            current_instrument--;
        }
    }
    else if (RNGC_NEXT_INSTR == selected_instrument)
    {
        if ((ENUM_TOTAL_INSTR - 1) == current_instrument)
        {
            current_instrument = 0;
        }
        else
        {
            current_instrument++;
        }
    }
    g_rngc_cntx.CurrInstr = CurrentInstrument[current_instrument];
    mmi_rngc_redraw_instrument();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_select_previous_instrument
 * DESCRIPTION
 *  Selects the previous instrument on pressing the volume up button 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_select_previous_instrument(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef RNGC_HAS_INST_RECTANGLE
   /* gui_horizontal_select_goto_previous_item(&MMI_rngc_instrument_select_menu);*/
    mmi_rngc_change_instrument(RNGC_PREVIOUS_INSTR);
    gui_horizontal_select_show(&MMI_rngc_instrument_select_menu);
    gui_BLT_double_buffer(
        MMI_rngc_instrument_select_menu.x,
        MMI_rngc_instrument_select_menu.y,
        MMI_rngc_instrument_select_menu.x + MMI_rngc_instrument_select_menu.width - 1,
        MMI_rngc_instrument_select_menu.y + MMI_rngc_instrument_select_menu.height - 1);
#else/*RNGC_HAS_INST_RECTANGLE*/
    mmi_rngc_change_instrument(RNGC_PREVIOUS_INSTR);
#endif/*RNGC_HAS_INST_RECTANGLE*/
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_select_previous_instrument_down
 * DESCRIPTION
 *  Selects the previous instrument on pressing the volume up button 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_select_previous_instrument_down(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef RNGC_HAS_INST_RECTANGLE
    gui_horizontal_select_struct *m = &MMI_rngc_instrument_select_menu;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    gui_horizontal_select_left_key_down_handler(m);
#endif/*RNGC_HAS_INST_RECTANGLE*/
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_select_next_instrument_down
 * DESCRIPTION
 *  Selects the previous instrument on pressing the volume up button 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_select_next_instrument_down(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef RNGC_HAS_INST_RECTANGLE
    gui_horizontal_select_struct *m = &MMI_rngc_instrument_select_menu;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    gui_horizontal_select_right_key_down_handler(m);
#endif/*RNGC_HAS_INST_RECTANGLE*/
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_select_previous_instrument_up
 * DESCRIPTION
 *  Selects the previous instrument on pressing the volume up button 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_select_previous_instrument_up(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef RNGC_HAS_INST_RECTANGLE
    gui_horizontal_select_struct *m = &MMI_rngc_instrument_select_menu;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
   if(mmi_frm_scrn_get_active_id()!= SCR_COMPOSER_ENGINE)
   {
	return;
   }
    gui_horizontal_select_left_key_up_handler(m);
#endif/*RNGC_HAS_INST_RECTANGLE*/
    mmi_rngc_select_previous_instrument();
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_select_next_instrument_up
 * DESCRIPTION
 *  Selects the previous instrument on pressing the volume up button 
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_select_next_instrument_up(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
#ifdef RNGC_HAS_INST_RECTANGLE
    gui_horizontal_select_struct *m = &MMI_rngc_instrument_select_menu;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
     if(mmi_frm_scrn_get_active_id()!= SCR_COMPOSER_ENGINE)
     {
	return;
     }
    gui_horizontal_select_right_key_up_handler(m);
#endif/*RNGC_HAS_INST_RECTANGLE*/
    mmi_rngc_select_next_instrument();
}


/*****************************************************************************
 * FUNCTION
 *  rngc_select_next_instrument
 * DESCRIPTION
 *  Selects the next instrument on pressing the volume down button  
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_select_next_instrument(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifdef RNGC_HAS_INST_RECTANGLE
  /* gui_horizontal_select_goto_next_item(&MMI_rngc_instrument_select_menu);*/
    mmi_rngc_change_instrument(RNGC_NEXT_INSTR);
    gui_horizontal_select_show(&MMI_rngc_instrument_select_menu);
    gui_BLT_double_buffer(
        MMI_rngc_instrument_select_menu.x,
        MMI_rngc_instrument_select_menu.y,
        MMI_rngc_instrument_select_menu.x + MMI_rngc_instrument_select_menu.width - 1,
        MMI_rngc_instrument_select_menu.y + MMI_rngc_instrument_select_menu.height - 1);
#else /*RNGC_HAS_INST_RECTANGLE*/
    mmi_rngc_change_instrument(RNGC_NEXT_INSTR);
#endif /*RNGC_HAS_INST_RECTANGLE*/
}


#ifdef RNGC_STATUS_BAR_TRANSPANT_BG
/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_redraw_statusbar_bg_callback
 * DESCRIPTION
 *    
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_redraw_statusbar_bg_callback(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 x1 = 0, y1 = 0;
    S32 x2 = 0, y2 = 0; 
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
    wgui_status_icon_bar_get_clip(WGUI_STATUS_ICON_BAR_H_BAR, &x1, &y1, &x2, &y2);
    gdi_layer_push_clip();
    gdi_layer_set_clip(x1, y1, x2, y2);
    gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
    gdi_layer_pop_clip();
}
#endif /*RNGC_STATUS_BAR_TRANSPANT_BG*/


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_set_ring_composer
 * DESCRIPTION
 *  Initialize defalut UI variables of stave
 * PARAMETERS
 *  title_id                [IN]        String id of title
 *  left_softkey            [IN]        String id if LSK
 *  left_softkey_icon       [IN]        Image id of LSK
 *  right_softkey           [IN]        String id of RSK
 *  right_softkey_icon      [IN]        Image id of RSK
 *  instru_type             [IN]        Instrument index
 *  value                   [IN]        Number of remaining notes
 *  history_buffer          [IN]        Pointer of history buffer
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_set_ring_composer(
        U16 title_id,
        U16 left_softkey,
        U16 left_softkey_icon,
        U16 right_softkey,
        U16 right_softkey_icon)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U8 i;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    clear_category_screen_key_handlers();

    for (i = 0; i < NUM_NOTES_IN_STAVE; i++)
    {
        g_rngc_eng_cntx->YPos[i] = 0;
        g_rngc_eng_cntx->ImageList[i] = NULL;
    }

    if (g_rngc_eng_cntx->TotalNotes == 0)   /* start vijay 20050707...new change */
    {
        memset(g_rngc_eng_cntx->NotesList, 0xFFFF, MAX_NOTES * sizeof(g_rngc_eng_cntx->NotesList[0]));
    }

#ifdef __MMI_TOUCH_RING_COMPOSER__
    mmi_touch_rngc_setup(&touch_rngc_context);
    mmi_pen_register_down_handler(mmi_rngc_pen_down_hdlr);
    mmi_pen_register_up_handler(mmi_rngc_pen_up_hdlr);
    mmi_pen_register_move_handler(mmi_rngc_pen_move_hdlr);
    mmi_pen_register_repeat_handler(mmi_rngc_pen_repeat_hdlr);
    mmi_pen_register_long_tap_handler(mmi_rngc_pen_longtap_hdlr);
#endif /* __MMI_TOUCH_RING_COMPOSER__ */ 


    /* Instrument toolbar */
#ifdef RNGC_HAS_INST_RECTANGLE
    {
        U8 *ItemList[ENUM_TOTAL_INSTR];     
        U16 StringList[ENUM_TOTAL_INSTR];   
        S32 img_height, img_width, instrument;
        PU8 ring_comp_icon;
        
        GetSequenceStringIds(MENU_COMP_RINGTONE_COMP_SEL_INST, StringList);
        for (i = 0; i < ENUM_TOTAL_INSTR; i++)
        {
            ItemList[i] = (U8*) GetString(StringList[i]);   
        }
        
        for (instrument = 0; instrument < ENUM_TOTAL_INSTR; instrument++)
        {
            if ((U8) g_rngc_cntx.CurrInstr == CurrentInstrument[instrument])
            {
                break;
            }
        }
        MMI_DBG_ASSERT(instrument < ENUM_TOTAL_INSTR);
        
        /* get image size */
        ring_comp_icon = (PU8) get_image(GetInstrumentImage(g_rngc_cntx.CurrInstr));
        gui_measure_image(ring_comp_icon, (S32*) & img_width, (S32*) & img_height);
        mmi_rngc_initialize_instrument_select_menu_items(
            RNGC_INSTR_SELECT_X_OFFSET * 3 + img_width,
            g_rngc_skin_layout.instr_sel_rect_y1,
#if (defined(__MMI_MAINLCD_320X480__))
            (UI_device_width - 2 * img_width - RNGC_INSTR_SELECT_X_OFFSET * 3),
#else
            (UI_device_width - 2 * img_width - RNGC_INSTR_SELECT_X_OFFSET),
#endif
            MMI_RNGC_INSTRUMENT_SELECT_HEIGHT,
            ItemList,
            &instrument,
            UI_dummy_function_s32);
        
#ifdef __MMI_UI_LIST_HIGHLIGHT_EFFECTS__
        gui_block_list_effect();
#endif 
    }
#endif /*RNGC_HAS_INST_RECTANGLE*/

    /* Initialization of the softkeys */
    change_left_softkey(left_softkey, left_softkey_icon);
    change_right_softkey(right_softkey, right_softkey_icon);
    clear_left_softkey();
    clear_right_softkey();
    register_left_softkey_handler();
    register_right_softkey_handler();
    register_default_hide_softkeys();

    RedrawCategoryFunction = mmi_rngc_show_composer;
}

#ifdef __MMI_TOUCH_RING_COMPOSER__
/*****************************************************************************
 * FUNCTION
 *  mmi_touch_rngc_setup
 * DESCRIPTION
 *  Sets the default values to the context structure
 *  Sets the play mode to  RNGC_PLAY
 * PARAMETERS
 *  touch_rngc_context      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_touch_rngc_setup(touch_rngc_struct *touch_rngc_context)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    touch_rngc_context->flag = 0;
    touch_rngc_context->flag |= RNGC_SELECTION_AREA_REDRAW;
    touch_rngc_context->mode = GUI_RNGC_VIEW;
    if (touch_rngc_context->play_mode != RNGC_PAUSE)
    {
        selection_area_context = &normal_toolbar_layout;
        touch_rngc_context->area_type = GUI_RNGC_NORMAL_TOOLBAR;
    }
    touch_rngc_context->play_mode = RNGC_PLAY;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_finish_insert_editing
 * DESCRIPTION
 *  Sets mode to insert and changes the image to down
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_finish_insert_editing(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 width = 0, index = 0, y1 = 0, y2 = 0, imgw = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    touch_rngc_context.mode = GUI_RNGC_INSERT;
    selection_area_context->custom_keys[selection_area_context->n_custom_keys-1].key_image = IMG_TOUCH_RING_DOWN;
    show_touch_rngc_selection_area();
    mmi_rngc_redraw_stave();    
#if defined(__MMI_MAINLCD_320X240__)
    mmi_rngc_redraw_remaining_notes();
#endif
}


/*****************************************************************************
 * FUNCTION
 *  show_touch_rngc_selection_area
 * DESCRIPTION
 *  Resets the flag from SELECTION_AREA_REDRAW 
 *  Shows the touch panel of the melody composer, normal toolbar and note selection
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void show_touch_rngc_selection_area(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    //static S32 note_x1, note_y1, note_x2, note_y2;
    S32 n_matrix_keys, n_custom_keys;
    S32 matrix_key_width, matrix_key_height;
    S32 n_matrix_rows, n_matrix_columns;
    S32 width, height;
    S32 horizontal_gap, vertical_gap;
    S32 x1, y1, x2, y2;
    S32 i, j;
    S32 key_x, key_y;
    S32 current_key_x, current_key_y, temp_x, temp_y;   /* [~PMT  MANISH   20050616 */
    S32 custom_key_x, custom_key_y;
    S32 custom_key_width, custom_key_height;
    MMI_ID_TYPE image_id;
    MMI_ID_TYPE *key_image;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    gui_lock_double_buffer();
    touch_rngc_context.flag &= ~RNGC_SELECTION_AREA_REDRAW;
    n_matrix_keys = selection_area_context->n_matrix_keys;
    n_custom_keys = selection_area_context->n_custom_keys;
    n_matrix_rows = selection_area_context->matrix_layout->n_matrix_rows;
    n_matrix_columns = selection_area_context->matrix_layout->n_matrix_columns;
    matrix_key_width = selection_area_context->matrix_layout->key_width;
    matrix_key_height = selection_area_context->matrix_layout->key_height;
    horizontal_gap = selection_area_context->horizontal_gap;
    vertical_gap = selection_area_context->vertical_gap;
    image_id = selection_area_context->imageid;
    gui_measure_image(get_image(image_id), &width, &height);
    x1 = selection_area_context->image_x;
    y1 = selection_area_context->image_y;
    x2 = x1 + width - 1;
    y2 = y1 + height - 1;

    gui_push_clip();
    gui_set_clip(0, g_rngc_skin_layout.main_bg_img_area_y2 - NOTE_SELECTION_HEIGHT, UI_device_width - 1, g_rngc_skin_layout.main_bg_img_area_y2 - 1);
#ifdef __GDI_MEMORY_PROFILE_2__
        gdi_draw_solid_rect(0, g_rngc_skin_layout.main_bg_img_area_y2 - NOTE_SELECTION_HEIGHT, UI_device_width - 1, UI_device_height - 1, GDI_COLOR_TRANSPARENT);
    {
        gdi_draw_solid_rect(x1, y1, x2, y2, GDI_COLOR_TRANSPARENT);
    }
#else 
    gdi_image_draw(0, 0, (PU8)GetImage(g_rngc_skin_layout.main_bg_img_id));
#endif

    gui_show_image(x1, y1, get_image(image_id));
    if (n_matrix_keys)
    {
        key_x = selection_area_context->image_x + selection_area_context->matrix_layout->matrix_x;
        key_y = selection_area_context->image_y + selection_area_context->matrix_layout->matrix_y;
        current_key_x = key_x;
        current_key_y = key_y;
        for (i = 0; i < n_matrix_rows; i++)
        {
            key_image = selection_area_context->matrix_layout->key_image[i];
            for (j = 0; j < n_matrix_columns; j++)
            {
                image_id = key_image[j];
                gui_measure_image(get_image(image_id), &width, &height);
                temp_x = current_key_x + ((matrix_key_width - width) >> 1);     /* PMT MANISH   20050614 */
                temp_y = current_key_y + ((matrix_key_height - height) >> 1);   /* PMT MANISH   20050614 */
                gui_show_image(temp_x, temp_y, get_image(image_id));    /* PMT MANISH   20050614 */
                current_key_x = current_key_x + matrix_key_width + horizontal_gap;
            }
            current_key_x = key_x;
            current_key_y = key_y + matrix_key_height + vertical_gap;
        }
    }
    for (i = 0; i < n_custom_keys; i++)
    {
        custom_key_x = selection_area_context->custom_keys[i].x;
        custom_key_y = selection_area_context->custom_keys[i].y;
        custom_key_width = selection_area_context->custom_keys[i].key_width;
        custom_key_height = selection_area_context->custom_keys[i].key_height;

        image_id = selection_area_context->custom_keys[i].key_image;

    #ifndef __MMI_RNGC_ENABLE_INS_LED_NOTE__
        if (IMG_RING_EVENTLED_ON == image_id || IMG_RING_EVENTLED_OFF == image_id)
        {
            continue;
        }
    #endif /* __MMI_RNGC_ENABLE_INS_LED_NOTE__ */
        gui_measure_image(get_image(image_id), &width, &height);
        custom_key_x = custom_key_x + ((custom_key_width >> 1) - (width >> 1));
        custom_key_y = custom_key_y + ((custom_key_height >> 1) - (height >> 1));
        gui_show_image(custom_key_x, custom_key_y, get_image(image_id));
    }
    gui_pop_clip();
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(
        0, g_rngc_skin_layout.main_bg_img_area_y2 - NOTE_SELECTION_HEIGHT, UI_device_width - 1, UI_device_height - MMI_BUTTON_BAR_HEIGHT - 1);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_down_selection_area
 * DESCRIPTION
 *  Notifies the touch screen button pressed on the selection area (normal or note selection)
 * PARAMETERS
 *  touch_rngc_context      [?]         
 *  pos                     [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_rngc_pen_down_selection_area(touch_rngc_struct *touch_rngc_context, mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 n_matrix_keys, n_custom_keys;
    S32 matrix_layout_x, matrix_layout_y;
    S32 matrix_width, matrix_height;
    S32 matrix_key_width, matrix_key_height;
    S32 n_matrix_rows, n_matrix_cloumns;
    S32 vertical_gap, horizontal_gap;
    S32 total_matrix_width = 0, total_matrix_height = 0;
    S32 current_key_x, current_key_y;
    S32 current_key_width, current_key_height;
    S32 i, j;
    MMI_BOOL ret = FALSE;   /* new */
    S32 pos_x, pos_y;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    pos_x = pos.x;
    pos_y = pos.y;

    n_matrix_keys = selection_area_context->n_matrix_keys;
    n_custom_keys = selection_area_context->n_custom_keys;

    if (n_matrix_keys)
    {
        matrix_layout_x = selection_area_context->image_x + selection_area_context->matrix_layout->matrix_x;
        matrix_layout_y = selection_area_context->image_y + selection_area_context->matrix_layout->matrix_y;
        matrix_width = selection_area_context->matrix_layout->matrix_width;
        matrix_height = selection_area_context->matrix_layout->matrix_height;
        n_matrix_rows = selection_area_context->matrix_layout->n_matrix_rows;
        n_matrix_cloumns = selection_area_context->matrix_layout->n_matrix_columns;
        matrix_key_width = selection_area_context->matrix_layout->key_width;
        matrix_key_height = selection_area_context->matrix_layout->key_height;
        horizontal_gap = selection_area_context->horizontal_gap;
        vertical_gap = selection_area_context->vertical_gap;
        total_matrix_height = matrix_layout_y;
        total_matrix_width = matrix_layout_x;
        if (pos_x >= matrix_layout_x && pos_x <= (matrix_layout_x + matrix_width - 1) && pos_y >= matrix_layout_y &&
            pos_y <= (matrix_layout_y + matrix_height - 1))
        {
            for (i = 0; i < n_matrix_rows; i++)
            {
                total_matrix_height += matrix_key_height;
                if (total_matrix_height > pos_y)
                {
                    total_matrix_width = matrix_layout_x;
                    for (j = 0; j < n_matrix_cloumns; j++)
                    {
                        total_matrix_width += matrix_key_width;
                        if (total_matrix_width > pos_x)
                        {
                            touch_rngc_context->key_note_type = selection_area_context->matrix_layout->key_note[i][j];
                            touch_rngc_context->selected_key_x =
                                matrix_layout_x + j * (matrix_key_width + horizontal_gap);
                            touch_rngc_context->selected_key_y =
                                matrix_layout_y + i * (matrix_key_height + vertical_gap);
                            touch_rngc_context->key_width = selection_area_context->matrix_layout->key_width;
                            touch_rngc_context->key_height = selection_area_context->matrix_layout->key_height;
                            touch_rngc_context->selected_key_image =
                                selection_area_context->matrix_layout->key_image[i][j];
                            ret = TRUE;
                            break;
                        }
                        else
                        {
                            total_matrix_width += horizontal_gap;
                            if (total_matrix_width > pos_x)
                            {
                                ret = FALSE;
                                return ret;
                            }
                        }
                    }
                    break;
                }
                else
                {
                    total_matrix_height += vertical_gap;
                    if (total_matrix_height > pos_y)
                    {
                        ret = FALSE;
                        return ret;
                    }
                }
            }
        }
    }
    for (i = 0; i < n_custom_keys; i++)
    {
        current_key_x = selection_area_context->custom_keys[i].x;
        current_key_y = selection_area_context->custom_keys[i].y;
        current_key_width = selection_area_context->custom_keys[i].key_width;
        current_key_height = selection_area_context->custom_keys[i].key_height;
        if (pos_x >= current_key_x && pos_x <= (current_key_x + current_key_width - 1) && pos_y >= current_key_y &&
            pos_y <= (current_key_y + current_key_height - 1))
        {
        #ifndef __MMI_RNGC_ENABLE_INS_LED_NOTE__
            if (selection_area_context->custom_keys[i].key_note == NOTE_LED_ON)
            {
                ret = FALSE;
                return ret;
            }
        #endif /* __MMI_RNGC_ENABLE_INS_LED_NOTE__ */ 
            touch_rngc_context->key_note_type = selection_area_context->custom_keys[i].key_note;
            touch_rngc_context->selected_key_x = current_key_x;
            touch_rngc_context->selected_key_y = current_key_y;
            touch_rngc_context->key_width = current_key_width;
            touch_rngc_context->key_height = current_key_height;
            touch_rngc_context->selected_key_image = selection_area_context->custom_keys[i].key_image;
            ret = TRUE;
            break;
        }
    }
    return ret;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_down_on_stave
 * DESCRIPTION
 *  Checks the position of the pen on the stave
 * PARAMETERS
 *  pos             [IN]        
 *  item_index      [?]         
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_rngc_pen_down_on_stave(mmi_pen_point_struct pos, S32 *item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 x1, y1, x2, y2;
    S32 i;
    S32 total_width = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    *item_index = 0;
    x1 = RNGC_X_POS_BASED;
    y1 = g_rngc_skin_layout.stave_rectangle_y1;
    x2 = x1 + NUM_NOTES_IN_STAVE * RNGC_X_POS_OFFSET;
    y2 = g_rngc_skin_layout.stave_rectangle_y2;

    if (pos.x >= x1 && pos.x <= x2 && pos.y >= y1 && pos.y <= y2)
    {
        total_width = x1;
        for (i = 0; i < NUM_NOTES_IN_STAVE; i++)
        {
            total_width += RNGC_X_POS_OFFSET;
            if (total_width >= pos.x)
            {
                *item_index = i;
                break;
            }
        }
        return TRUE;
    }
    else if (pos.x > x2 && pos.y >= y1 && pos.y <= y2 && *item_index <= NUM_NOTES_IN_STAVE)
    {
        *item_index = g_rngc_eng_cntx->CurrUIPos + 1;
    }
    else if (pos.x < x1 && pos.y >= y1 && pos.y <= y2)
    {
        *item_index = -1;
    }
    return FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_down_on_MOVE_area
 * DESCRIPTION
 *  Checls the position of the pen on the stave area
 * PARAMETERS
 *  pos             [IN]        
 *  item_index      [?]         
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_rngc_pen_down_on_MOVE_area(mmi_pen_point_struct pos, S32 *item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 x1, y1, x2, y2;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    x1 = 0;
    y1 = g_rngc_skin_layout.stave_rectangle_y1;
    x2 = RNGC_X_POS_BASED;
    y2 = g_rngc_skin_layout.stave_rectangle_y2;
    
    if (pos.x >= x1 && pos.x <= x2 && pos.y >= y1 && pos.y <= y2)
    {
        *item_index = RNGC_PEN_LEFT_MOVE_AREA;
        return TRUE;
    }

    x1 = RNGC_X_POS_BASED + NUM_NOTES_IN_STAVE * RNGC_X_POS_OFFSET;
    x2 = UI_device_width - 1;

    if (pos.x >= x1 && pos.x <= x2 && pos.y >= y1 && pos.y <= y2)
    {
        *item_index = RNGC_PEN_RIGHT_MOVE_AREA;
        return TRUE;
    }

    return FALSE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_down_instrument
 * DESCRIPTION
 *  Checks whether the instrument bar has been pressed
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  
 *****************************************************************************/
MMI_BOOL mmi_rngc_pen_down_instrument(mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 pos_x, pos_y;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    pos_x = pos.x;
    pos_y = pos.y;
    if (PEN_CHECK_BOUND
        (pos_x, pos_y, RNGC_INSTRUMENT_X, RNGC_INSTRUMENT_Y, RNGC_INSTRUMENT_WIDTH, RNGC_INSTRUMENT_HEIGHT))
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_set_note_type
 * DESCRIPTION
 *  Sets the note type
 * PARAMETERS
 *  note_type_to_set        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_set_note_type(S32 note_type_to_set)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 nValue;
    U32 nNoteType;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_rngc_eng_cntx->TotalNotes > MAX_NOTES)
    {
        return;
    }

    if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
    {
        return;
    }
    StopTimer(NOTE_MULTITAP_TIMER);
    nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
    nNoteType = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTETYPE_MASK;

    switch (nValue)
    {
        case NOTE_C:
        case NOTE_F:
            if (nNoteType == NORMAL && note_type_to_set == SHARP)
                SetNoteType(SHARP)
                else
            if (nNoteType == SHARP && note_type_to_set == SHARP)
                SetNoteType(NORMAL) break;
        case NOTE_D:
        case NOTE_G:
        case NOTE_A:
            if (nNoteType == NORMAL)
                SetNoteType(note_type_to_set)
                else
            if (nNoteType == FLAT && note_type_to_set == FLAT)
                SetNoteType(NORMAL)
                else
            if (nNoteType == SHARP && note_type_to_set == SHARP)
                SetNoteType(NORMAL) break;
        case NOTE_B:
        case NOTE_E:
            if (nNoteType == NORMAL && note_type_to_set == FLAT)
                SetNoteType(FLAT)
                else
            if (note_type_to_set == FLAT)
                SetNoteType(NORMAL) break;

        case NOTE_VIBRATION_ON:
        case NOTE_VIBRATION_OFF:
        case NOTE_LED_ON:
        case NOTE_LED_OFF:
        case NOTE_BACKLIGHT_ON:
        case NOTE_BACKLIGHT_OFF:
            /* don't vib/led/backlight if adjusting sharp/flat on a vibration note */            
            if (note_type_to_set == FLAT || note_type_to_set == SHARP)
            {
                return;
            }        
            
        default:    /* other notes, pound key does not effect */
            break;
    }
    if (nValue |= 0 && nNoteType != 0)
    {
        PlayCurrentNode();
        mmi_rngc_show_note(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_set_note_beat
 * DESCRIPTION
 *  Sets the note beat
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_set_note_beat(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 nValue;
    S32 nDuration;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_rngc_eng_cntx->TotalNotes > MAX_NOTES)
    {
        return;
    }
    /* highlighted on empty position */
    if (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF)
    {
        return;
    }
    StopTimer(NOTE_MULTITAP_TIMER);

    nValue = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
    if (nValue >= NOTE_VIBRATION_ON && nValue <= NOTE_BACKLIGHT_OFF)
	{
	    return;     /* don't vib/led/backlight if it's a vib/led/backlight note */
	}	    
    nDuration = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & DURATION_MASK;
    switch (nDuration)
    {
        case DURATION_3BY2:
            IncrementNoteBeat();
            break;
        case DURATION_1:
            TouchRngcDecrementNoteBeat();
            break;
        case DURATION_3BY4:
            IncrementNoteBeat();
            break;
        case DURATION_1BY2:
            TouchRngcDecrementNoteBeat();
            break;
        case DURATION_3BY8:
            IncrementNoteBeat();
            break;
        case DURATION_1BY4:
            TouchRngcDecrementNoteBeat();
            break;
        case DURATION_3BY16:
            IncrementNoteBeat();
            break;
        case DURATION_1BY8:
            TouchRngcDecrementNoteBeat();
            break;
        case DURATION_3BY32:
            IncrementNoteBeat();
            break;
        case DURATION_1BY16:
            TouchRngcDecrementNoteBeat();
            break;
        default:
            break;
    }

    if (nValue |= 0 && nDuration != 0)
    {
        PlayCurrentNode();
        mmi_rngc_show_note(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_key_select
 * DESCRIPTION
 *  Effect on pressing the key down on the touch screen
 * PARAMETERS
 *  touch_rngc_context      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_key_select(touch_rngc_struct *touch_rngc_context)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 x1, y1, x2, y2;
    S32 width, height;
    MMI_ID_TYPE image_id;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    touch_rngc_context->flag &= ~RNGC_PEN_EVENT_UP;
    gui_lock_double_buffer();
    x1 = touch_rngc_context->selected_key_x;
    y1 = touch_rngc_context->selected_key_y;

    x2 = x1 + touch_rngc_context->key_width - 1;
    y2 = y1 + touch_rngc_context->key_height - 1;
    if (touch_rngc_context->selected_key_bitmap.buf_ptr)
    {
        mmi_frm_scrmem_free((void*)touch_rngc_context->selected_key_bitmap.buf_ptr);
        touch_rngc_context->selected_key_bitmap.buf_ptr = NULL;
    }
    touch_rngc_context->selected_key_bitmap.buf_ptr = (U8*) mmi_frm_scrmem_alloc(touch_ring_comp_mem);
    memset(
        touch_rngc_context->selected_key_bitmap.buf_ptr,
        0,
        (touch_rngc_context->key_width) * (touch_rngc_context->key_height) * 2);
    gdi_layer_push_clip();
    gdi_layer_set_clip(x1, y1, x2, y2);
    gdi_image_cache_bmp_get(x1, y1, x2, y2, &touch_rngc_context->selected_key_bitmap);
    gdi_layer_pop_clip();

    gdi_layer_push_clip();
    gdi_layer_set_clip(x1, y1, x2 - 1, y2 - 1);
    {
        gui_draw_filled_area(x1 + 1, y1 + 1, x2 - 1, y2 - 1, (UI_filled_area*)&touch_rngc_color_key_filler);
        image_id = touch_rngc_context->selected_key_image;
    }
    gui_measure_image(get_image(image_id), &width, &height);
    x1 = x1 + ((touch_rngc_context->key_width >> 1) - (width >> 1));
    y1 = y1 + ((touch_rngc_context->key_height >> 1) - (height >> 1));
    gui_show_image(x1, y1, get_image(image_id));
    gdi_layer_pop_clip();
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(0, g_rngc_skin_layout.main_bg_img_area_y2 - NOTE_SELECTION_HEIGHT, UI_device_width - 1, UI_device_height - MMI_BUTTON_BAR_HEIGHT - 1);
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_key_unselect
 * DESCRIPTION
 *  Releases the pressed down effect
 * PARAMETERS
 *  touch_rngc_context      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_key_unselect(touch_rngc_struct *touch_rngc_context)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S16 x1, x2, y1, y2;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (touch_rngc_context->flag & RNGC_PEN_EVENT_UP)
    {
        return;
    }

    gui_lock_double_buffer();
    x1 = touch_rngc_context->selected_key_x;
    y1 = touch_rngc_context->selected_key_y;
    x2 = x1 + touch_rngc_context->key_width - 1;
    y2 = y1 + touch_rngc_context->key_height - 1;

    gdi_layer_push_clip();
    gdi_layer_set_clip(x1, y1, x2, y2);
    if (touch_rngc_context->selected_key_bitmap.buf_ptr)
    {
        gdi_image_cache_bmp_draw(x1, y1, &touch_rngc_context->selected_key_bitmap);
        mmi_frm_scrmem_free((void*)touch_rngc_context->selected_key_bitmap.buf_ptr);
        touch_rngc_context->selected_key_bitmap.buf_ptr = NULL;
    }
    gdi_layer_pop_clip();
    gui_unlock_double_buffer();
    gui_BLT_double_buffer(0, g_rngc_skin_layout.main_bg_img_area_y2 - NOTE_SELECTION_HEIGHT, UI_device_width - 1, UI_device_height - MMI_BUTTON_BAR_HEIGHT - 1);
    touch_rngc_context->selected_key_x = 0;
    touch_rngc_context->selected_key_y = 0;
    touch_rngc_context->key_width = 0;
    touch_rngc_context->key_height = 0;
    touch_rngc_context->flag |= RNGC_PEN_EVENT_UP;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_change_stave_notes
 * DESCRIPTION
 *  Changes the notes, move to the right or to the left
 * PARAMETERS
 *  touch_rngc_context      [?]         
 *  item_index              [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_change_stave_notes(touch_rngc_struct *touch_rngc_context, S32 item_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 current_notes_in_stave = 100;
    U16 nImageId = 0;
    U16 nYPos = 0;
    U16 original_UI_pos = 0;
    U16 original_note_index = 0;
    S16 offset = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_rngc_eng_cntx->CurrUIPos == item_index)
    {
        return;
    }
    if (item_index <= current_notes_in_stave /* || item_index<=g_rngc_eng_cntx->TotalNotes */ )
    {
        original_note_index = g_rngc_eng_cntx->CurrNoteIndex;
        original_UI_pos = g_rngc_eng_cntx->CurrUIPos;
        touch_rngc_context->original_key_note = g_rngc_eng_cntx->NotesList[original_note_index];
        offset = original_UI_pos - item_index;
        g_rngc_eng_cntx->CurrUIPos = item_index;
        g_rngc_eng_cntx->CurrNoteIndex = original_note_index - offset;  /* g_rngc_eng_cntx->TotalNotes-(current_notes_in_stave-item_index); */
        if (g_rngc_eng_cntx->CurrNoteIndex >= g_rngc_eng_cntx->TotalNotes)
        {
            g_rngc_eng_cntx->CurrUIPos -= (g_rngc_eng_cntx->CurrNoteIndex - g_rngc_eng_cntx->TotalNotes);
            g_rngc_eng_cntx->CurrNoteIndex = g_rngc_eng_cntx->TotalNotes;
        }
        GetIndexInList(touch_rngc_context->original_key_note, &nImageId, &nYPos);
        g_rngc_eng_cntx->NotesList[original_note_index] = touch_rngc_context->original_key_note;
        g_rngc_eng_cntx->ImageList[original_UI_pos] = (PU8) GetImage(nImageId);
        if (item_index >= g_rngc_eng_cntx->CurrUIPos && 
            (touch_rngc_context->mode == GUI_RNGC_EDIT) && 
            (g_rngc_eng_cntx->CurrNoteIndex >= g_rngc_eng_cntx->TotalNotes))
        {
             mmi_rngc_reset_toolbar();
        }
        else
        {
            if ((touch_rngc_context->mode == GUI_RNGC_INSERT_EDIT) &&
                (original_note_index != g_rngc_eng_cntx->CurrNoteIndex))
            {
                touch_rngc_context->mode = GUI_RNGC_INSERT;
            }

        }
        mmi_rngc_redraw_stave();
#if defined(__MMI_MAINLCD_320X240__)
    mmi_rngc_redraw_remaining_notes();
#endif
    }
    /* start vijay 20050617..changes done to vanish the note selection area on cliking outside note are */
    else
    {
        HandleKey_RIGHT();
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_normal_toolbar
 * DESCRIPTION
 *  Selection of normal toolbar buttons
 * PARAMETERS
 *  touch_rngc_context      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_normal_toolbar(touch_rngc_struct *touch_rngc_context)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (touch_rngc_context->key_note_type == GUI_RNGC_KEY_EDIT
        || touch_rngc_context->key_note_type == GUI_RNGC_KEY_PLAY
        || touch_rngc_context->key_note_type == GUI_RNGC_KEY_NEXT
        || touch_rngc_context->key_note_type == GUI_RNGC_KEY_PREV)
    {
        /*when the last note press NEXT key*/
        if((touch_rngc_context->key_note_type == GUI_RNGC_KEY_NEXT))
        {
            if ((g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF) 
                ||(g_rngc_eng_cntx->CurrNoteIndex + 1 >= MAX_NOTES))
            {
                rngc_pen_event_on_object = RNGC_PEN_NONE;
                return;
            }
        }
        /*the last empty note press EDIT key*/
        if((touch_rngc_context->key_note_type == GUI_RNGC_KEY_EDIT)
            && (g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] == 0xFFFF))
        {
            rngc_pen_event_on_object = RNGC_PEN_NONE;
            return;
        }
        /*the first note when press PREV key*/
        if((touch_rngc_context->key_note_type == GUI_RNGC_KEY_PREV)
            && (g_rngc_eng_cntx->CurrNoteIndex == 0))
        {
            rngc_pen_event_on_object = RNGC_PEN_NONE;
            return;
        }
        
        if (g_rngc_eng_cntx->TotalNotes > 0)
        {
            mmi_rngc_key_select(touch_rngc_context);
            rngc_pen_event_on_object = RNGC_PEN_NORMAL_TOOLBAR;
        }
        else
        {
            rngc_pen_event_on_object = RNGC_PEN_NONE;
        }
    }
    else
    {
        if (touch_rngc_context->key_note_type == GUI_RNGC_KEY_INSERT)
    {
        if (g_rngc_eng_cntx->TotalNotes >= MAX_NOTES)
        {
            rngc_pen_event_on_object = RNGC_PEN_NONE;
            return;
        }
    }
        mmi_rngc_key_select(touch_rngc_context);
        rngc_pen_event_on_object = RNGC_PEN_NORMAL_TOOLBAR;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_note_selection
 * DESCRIPTION
 *  Selection of note selection buttons
 * PARAMETERS
 *  touch_rngc_context      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_note_selection(touch_rngc_struct *touch_rngc_context)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U16 current_note_val = 0, current_octave_val = 0, prev_note_val = 0;
    U16 current_note_duration = 0, current_note = 0, current_note_type = 0;
#ifdef __MMI_RING_COMPOSER_REPEAT__
    U16 current_repeat_val = 0;	
#endif
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
#ifndef __MMI_RNGC_ENABLE_INS_LED_NOTE__
    if (touch_rngc_context->key_note_type == NOTE_LED_ON)
    {
        return;
    }
#endif /* __MMI_RNGC_ENABLE_INS_LED_NOTE__ */ 
    current_note_val = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
    current_octave_val = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & OCTAVE_MASK;
#ifdef __MMI_RING_COMPOSER_REPEAT__
    current_repeat_val = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & REPEAT_MASK;
#endif
    current_note = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex];

    mmi_rngc_key_select(touch_rngc_context);
    switch (touch_rngc_context->key_note_type)
    {
        case GUI_RNGC_KEY_SHARP:
            if (touch_rngc_context->mode != GUI_RNGC_INSERT)
            {
                mmi_rngc_set_note_type(GUI_RNGC_KEY_SHARP);
            }
            break;

        case GUI_RNGC_KEY_FLAT:
            if (touch_rngc_context->mode != GUI_RNGC_INSERT)
            {
                mmi_rngc_set_note_type(GUI_RNGC_KEY_FLAT);
            }
            break;

        case GUI_RNGC_KEY_DOT:
            if (touch_rngc_context->mode != GUI_RNGC_INSERT)
            {
                mmi_rngc_set_note_beat();
            }
            break;

        case GUI_RNGC_OCTAVE_UP:
            if ((touch_rngc_context->mode != GUI_RNGC_INSERT)
                && (g_rngc_eng_cntx->CurrNoteIndex < g_rngc_eng_cntx->TotalNotes))
            {
        #ifdef __MMI_RING_COMPOSER_REPEAT__
                if (current_repeat_val)
                {
                    IncrementRepeatCount();
                    mmi_rngc_show_note(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
                }
                else 
        #endif                
                if (current_note_val > NOTE_B)
                {
                    return;
                }
                else if (current_note_val == NOTE_B)
                {
                    switch (current_note_val)
                    {
                        case NOTE_B:
                            if (current_octave_val == OCTAVE_3)
                            {
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= NOTE_C;
                                SetOctave(OCTAVE_4);
                            }
                            else if (current_octave_val == OCTAVE_4)
                            {
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= NOTE_C;
                                SetOctave(OCTAVE_5);
                            }
                            else if (current_octave_val == OCTAVE_5)
                            {
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= NOTE_C;;
                                SetOctave(OCTAVE_3);
                            }
                            break;
                    }
                }
                else
                {
                    ++current_note_val;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= current_note_val;
                }
                if (current_note_val != 0)
                {
                    current_note_type = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTETYPE_MASK;
                    SetNoteType(NORMAL) mmi_rngc_set_note_type(current_note_type);
                }
            }
            break;

        case GUI_RNGC_OCTAVE_DOWN:
            if ((touch_rngc_context->mode != GUI_RNGC_INSERT)
                && (g_rngc_eng_cntx->CurrNoteIndex < g_rngc_eng_cntx->TotalNotes))
            {
        #ifdef __MMI_RING_COMPOSER_REPEAT__
                if (current_repeat_val)
                {
                    DecrementRepeatCount();
                    mmi_rngc_show_note(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
                }
                else 
        #endif                
                if (current_note_val > NOTE_B)
                {
                    return;
                }
                else if (current_note_val == NOTE_C || current_note_val > NOTE_B)       /* last note */
                {
                    switch (current_note_val)
                    {
                        case NOTE_C:
                        {
                            if (current_octave_val == OCTAVE_3)
                            {
                                SetOctave(OCTAVE_5);
                                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= NOTE_B;
                            }
                            else if (current_octave_val == OCTAVE_4)
                            {
                                SetOctave(OCTAVE_3);
                                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= NOTE_B;
                            }
                            else if (current_octave_val == OCTAVE_5)
                            {
                                SetOctave(OCTAVE_4);
                                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                                g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= NOTE_B;
                            }
                            break;
                        }
                        default:
                            break;
                    }
                }
                else if (current_note_val != 0)
                {
                    --current_note_val;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= current_note_val;
                }

                if (current_note_val != 0)
                {
                    current_note_type = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTETYPE_MASK;
                    SetNoteType(NORMAL) mmi_rngc_set_note_type(current_note_type);
                }
            }
            break;
        case GUI_RNGC_KEY_OK:
            break;

        default:
            if ((current_note != 0xFFFF) &&
                (touch_rngc_context->mode == GUI_RNGC_EDIT || touch_rngc_context->mode == GUI_RNGC_INSERT_EDIT))
            {
              /*  if (current_note_val == NOTE_REST || current_note == 0 ||
                    (touch_rngc_context->key_note_type & NOTE_MASK) == NOTE_REST)
                {
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] = touch_rngc_context->key_note_type;
                }
                else
                {
                    /*current_note_duration = touch_rngc_context->key_note_type & DURATION_MASK;
                    current_note_type = touch_rngc_context->key_note_type & NOTETYPE_MASK;
                    prev_note_val = g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] & NOTE_MASK;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_DURATION_MASK;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTE_MASK;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] &= CLEAR_NOTETYPE_MASK;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= current_note_duration;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= current_note_type;
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] |= prev_note_val;
                    if (current_octave_val)
                    {
                        SetOctave(current_octave_val);
                    }*/
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] = touch_rngc_context->key_note_type;
               /* }
        #ifdef __MMI_RING_COMPOSER_REPEAT__
                if (current_note >= REPEAT_START && current_note <= REPEAT_END)
                {
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] = touch_rngc_context->key_note_type;
                }
        #endif*/
                switch (current_note)
                {
                    case NOTE_LED_OFF:
                    #ifdef __MMI_RNGC_ENABLE_INS_LED_NOTE__
                        if (touch_rngc_context->key_note_type == NOTE_LED_ON)
                        {
                            SetLEDOn();
                        }
                        else
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                    #endif /* __MMI_RNGC_ENABLE_INS_LED_NOTE__ */
                        break;
                    case NOTE_BACKLIGHT_OFF:
                        if (touch_rngc_context->key_note_type == NOTE_BACKLIGHT_ON)
                        {
                            SetBackLightOn();
                        }
                        else
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                        break;
                    case NOTE_VIBRATION_OFF:
                        if (touch_rngc_context->key_note_type == NOTE_VIBRATION_ON)
                        {
                            SetVibrationOn();
                        }
                        else
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                        break;
                    case NOTE_LED_ON:
                    #ifdef __MMI_RNGC_ENABLE_INS_LED_NOTE__
                        if (touch_rngc_context->key_note_type == NOTE_LED_ON)
                        {
                            SetLEDOff();
                            PlayCurrentNode();
                        }
                        else
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                    #endif /* __MMI_RNGC_ENABLE_INS_LED_NOTE__ */
                        break;
                    case NOTE_BACKLIGHT_ON:
                        if (touch_rngc_context->key_note_type == NOTE_BACKLIGHT_ON)
                        {
                            SetBackLightOff();
                        }
                        else
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                        break;
                    case NOTE_VIBRATION_ON:
                        if (touch_rngc_context->key_note_type == NOTE_VIBRATION_ON)
                        {
                            SetVibrationOff();
                        }
                        else
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                        break;
                    case 0xFFFF:
                        break;
                    default:
                        if (touch_rngc_context->key_note_type == NOTE_VIBRATION_ON ||
                            touch_rngc_context->key_note_type == NOTE_BACKLIGHT_ON ||
                            touch_rngc_context->key_note_type == NOTE_LED_ON
                        #ifdef __MMI_RING_COMPOSER_REPEAT__
                             ||(touch_rngc_context->key_note_type >= REPEAT_START &&
                            touch_rngc_context->key_note_type <= REPEAT_END)
                        #endif
                            )
                        {
                            g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] =
                                touch_rngc_context->key_note_type;
                        }
                        break;
                }
                PlayCurrentNode();
                mmi_rngc_show_note(g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex]);
            }
            else if (touch_rngc_context->mode == GUI_RNGC_INSERT)
            {
                if (g_rngc_eng_cntx->TotalNotes < MAX_NOTES)
                {
                    touch_rngc_context->mode = GUI_RNGC_INSERT_EDIT;
                    InsertNote(touch_rngc_context->key_note_type);
                    selection_area_context->custom_keys[selection_area_context->n_custom_keys-1].key_image = IMG_TOUCH_RING_OK;
                    show_touch_rngc_selection_area();
                }
            }
            break;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_down_hdlr
 * DESCRIPTION
 *  Handler for the pen down event
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_pen_down_hdlr(mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    S32 item_index;
    gui_button_pen_enum button_event;
    MMI_BOOL ret = MMI_FALSE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/  
#ifdef RNGC_HAS_INST_RECTANGLE
    {
        gui_horizontal_select_pen_enum select_event; 
        ret = gui_horizontal_select_translate_pen_event(
            &MMI_rngc_instrument_select_menu,
            MMI_PEN_EVENT_DOWN,
            pos.x,
            pos.y,
            &select_event);
        if (ret)
        {
            rngc_pen_event_on_object = RNGC_PEN_INSTRUMENT;
            return;
        }
    }    
#else /*RNGC_HAS_INST_RECTANGLE*/
    ret = mmi_rngc_pen_down_instrument(pos);
    if (ret)
    {
        rngc_pen_event_on_object = RNGC_PEN_INSTRUMENT;   
        mmi_rngc_change_instrument(RNGC_NEXT_INSTR);    
        return;
    }
#endif /*RNGC_HAS_INST_RECTANGLE*/

    ret = mmi_rngc_pen_down_on_stave(pos, &item_index);
    if (ret) 
    {
        rngc_pen_event_on_object = RNGC_PEN_STAVE;
        if (g_rngc_eng_cntx->CurrUIPos != item_index)
        {
            mmi_rngc_change_stave_notes(&touch_rngc_context, item_index);
            if (selection_area_context->custom_keys[selection_area_context->n_custom_keys-1].key_image == IMG_TOUCH_RING_OK)
            {
                selection_area_context->custom_keys[selection_area_context->n_custom_keys-1].key_image = IMG_TOUCH_RING_DOWN;
                show_touch_rngc_selection_area();
            }
        }
        return;
    }
    ret = mmi_rngc_pen_down_selection_area(&touch_rngc_context, pos);
    if (ret)
    {
        switch (touch_rngc_context.area_type)
        {
            case GUI_RNGC_NORMAL_TOOLBAR:
                mmi_rngc_normal_toolbar(&touch_rngc_context);
                break;
            case GUI_RNGC_NOTE_SELECTION:
                rngc_pen_event_on_object = RNGC_PEN_NOTE_SELECTION;
                mmi_rngc_note_selection(&touch_rngc_context);
                break;
            default:
                break;
        }
        return;
    }

    if (touch_rngc_context.area_type != GUI_RNGC_NOTE_SELECTION)
    {
        #if(UI_DOUBLE_BUFFER_SUPPORT)
        gui_lock_double_buffer();
        #endif 
        ret = translate_softkey_pen_event(MMI_LEFT_SOFTKEY, MMI_PEN_EVENT_DOWN, pos.x, pos.y, &button_event);
        #if(UI_DOUBLE_BUFFER_SUPPORT)
        gui_unlock_double_buffer();
        #endif 
        if (ret)
        {
            rngc_pen_event_on_object = TOUCH_RNGC_PEN_LSK;
            if (button_event == GUI_BUTTON_PEN_DOWN && touch_rngc_context.area_type == GUI_RNGC_NORMAL_TOOLBAR)
            {
                RngcComposerLSKDownHandler();
            }
            return;
        }
    }
    #if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_lock_double_buffer();
    #endif 
    ret = translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_DOWN, pos.x, pos.y, &button_event);
    #if(UI_DOUBLE_BUFFER_SUPPORT)
    gui_unlock_double_buffer();
    #endif 
    if (ret)
    {
        rngc_pen_event_on_object = TOUCH_RNGC_PEN_RSK;
        if (button_event == GUI_BUTTON_PEN_DOWN)
        {
            RngcComposerRSKDownHandler();
        }
        return;
    }

    switch (touch_rngc_context.area_type)
    {
        case GUI_RNGC_NORMAL_TOOLBAR:
            if (PEN_CHECK_BOUND
                (pos.x, pos.y, NORMAL_TOOLBAR_IMAGE_X, NORMAL_TOOLBAR_IMAGE_Y, NORMAL_TOOLBAR_WIDTH,
                 NORMAL_TOOLBAR_HEIGHT))
            {
                return;
            }
            break;
        case GUI_RNGC_NOTE_SELECTION:
            if (PEN_CHECK_BOUND
                (pos.x, pos.y, NOTE_SELECTION_IMAGE_X, NOTE_SELECTION_IMAGE_Y, NOTE_SELECTION_WIDTH,
                 NOTE_SELECTION_HEIGHT))
            {
                return;
            }
            break;
    }
    /*If touch leftmost or rightmost, handle move the cursor*/
    ret = mmi_rngc_pen_down_on_MOVE_area(pos, &item_index);
    if(ret)
    {
        rngc_pen_event_on_object = RNGC_PEN_NONE;
        if(RNGC_PEN_LEFT_MOVE_AREA == item_index)
        {
            HandleKey_LEFT();
        }
        else if(RNGC_PEN_RIGHT_MOVE_AREA == item_index)
        {
            HandleKey_RIGHT();
        }
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_longtap_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_pen_longtap_hdlr(mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    gui_button_pen_enum button_event;
    MMI_BOOL ret = MMI_FALSE;
    S32 item_index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (rngc_pen_event_on_object == RNGC_PEN_STAVE)
    {
        mmi_rngc_pen_down_on_stave(pos, &item_index);
        if (item_index > g_rngc_eng_cntx->CurrUIPos)
        {
            HandleKey_RIGHT();
        }
        else if (item_index == -1)
        {
            if (g_rngc_eng_cntx->CurrNoteIndex > 0)
            {
                HandleKey_LEFT();
            }
        }
    }
    ret = translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_LONG_TAP, pos.x, pos.y, &button_event);

    if (ret)
    {
        if (button_event == GUI_BUTTON_PEN_LONGTAP && rngc_pen_event_on_object == TOUCH_RNGC_PEN_RSK)
        {
            if (g_rngc_eng_cntx->IsRskLP == RSK_DOWN)
            {
                rngc_pen_event_on_object = RNGC_PEN_NONE;
                HandleKey_CLEARLONG();
                mmi_rngc_redraw_RSK(0);
            }
        }
        return;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_repeat_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_pen_repeat_hdlr(mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    /*gui_button_pen_enum button_event;
    MMI_BOOL ret = MMI_FALSE;*/
    S32 item_index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (rngc_pen_event_on_object == RNGC_PEN_STAVE)
    {
        mmi_rngc_pen_down_on_stave(pos, &item_index);
        if (item_index > g_rngc_eng_cntx->CurrUIPos)
        {
        //    HandleKey_RIGHT();
        }
        else if (item_index == -1)
        {
            if (g_rngc_eng_cntx->CurrNoteIndex >= 0)
            {
                HandleKey_LEFT();
            }
        }
    }
}



/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_up_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_pen_up_hdlr(mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    gui_button_pen_enum button_event;
    MMI_BOOL ret = MMI_FALSE;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (rngc_pen_event_on_object)
    {
        case TOUCH_RNGC_PEN_LSK:
            #if(UI_DOUBLE_BUFFER_SUPPORT)
            gui_lock_double_buffer();
            #endif 
            ret = translate_softkey_pen_event(MMI_LEFT_SOFTKEY, MMI_PEN_EVENT_UP, pos.x, pos.y, &button_event);
            #if(UI_DOUBLE_BUFFER_SUPPORT)
            gui_unlock_double_buffer();
            #endif
            if (button_event == GUI_BUTTON_PEN_UP_INSIDE && touch_rngc_context.area_type == GUI_RNGC_NORMAL_TOOLBAR)
            {
                mmi_rngc_redraw_LSK(0);
                EntryRngcCompToneOptList();
                touch_rngc_context.play_mode = RNGC_PAUSE;
            }
            break;
        case TOUCH_RNGC_PEN_RSK:
            #if(UI_DOUBLE_BUFFER_SUPPORT)
            gui_lock_double_buffer();
            #endif 
            translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_UP, pos.x, pos.y, &button_event);
            #if(UI_DOUBLE_BUFFER_SUPPORT)
            gui_unlock_double_buffer();
            #endif
            if (button_event == GUI_BUTTON_PEN_UP_INSIDE)
            {
                mmi_rngc_redraw_RSK(0);
                RngcComposerRSKUpHandler();
                if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
                {
                    touch_rngc_context.mode = GUI_RNGC_INSERT;
                }
            }
            break;
        case RNGC_PEN_INSTRUMENT:
#ifdef RNGC_HAS_INST_RECTANGLE
            {
                gui_horizontal_select_pen_enum select_event;
                
                ret = gui_horizontal_select_translate_pen_event(
                    &MMI_rngc_instrument_select_menu,
                    MMI_PEN_EVENT_UP,
                    pos.x,
                    pos.y,
                    &select_event);
                if (ret)
                { 
                    switch (select_event)
                    {
                    case GUI_HORIZONTAL_SELECT_PEN_NONE:
                        /* Do nothing */
                        break;
                    case GUI_HORIZONTAL_SELECT_PEN_PREV:
                        mmi_rngc_select_previous_instrument();
                        break;
                    case GUI_HORIZONTAL_SELECT_PEN_NEXT:
                        mmi_rngc_select_next_instrument();
                        break;
                    default:
                        MMI_DBG_ASSERT(0);
                    }
                }
            }
#endif /*RNGC_HAS_INST_RECTANGLE*/
            break;
        case RNGC_PEN_STAVE:
            break;
        case RNGC_PEN_NORMAL_TOOLBAR:
            if (PEN_CHECK_BOUND
                (pos.x, pos.y, touch_rngc_context.selected_key_x, touch_rngc_context.selected_key_y,
                 touch_rngc_context.key_width, touch_rngc_context.key_height))
                switch (touch_rngc_context.key_note_type)
                {
                    case GUI_RNGC_KEY_EDIT:
                        if (g_rngc_eng_cntx->TotalNotes > 0)
                        {
                            if (touch_rngc_context.play_mode != RNGC_PAUSE)
                            {
                                mmi_rngc_key_unselect(&touch_rngc_context);
                                touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                                if (g_rngc_eng_cntx->CurrNoteIndex < g_rngc_eng_cntx->TotalNotes)
                                {
                                    touch_rngc_context.area_type = GUI_RNGC_NOTE_SELECTION;
                                    selection_area_context =
                                        (rngc_selection_area_layout_struct*) & note_selection_layout;
                                    touch_rngc_context.mode = GUI_RNGC_EDIT;
                                    touch_rngc_context.play_mode = RNGC_PAUSE;
                                    touch_rngc_context.flag &= ~RNGC_NOTE_SELECTION_FINAL;
                                    touch_rngc_context.flag |= RNGC_SELECTION_AREA_REDRAW;
                                    show_touch_rngc_selection_area();
                                    mmi_rngc_redraw_stave();
                                #if defined(__MMI_MAINLCD_320X240__)
                                    mmi_rngc_redraw_remaining_notes();
                                #endif
									clear_softkey_handler(MMI_LEFT_SOFTKEY);
                                    mmi_rngc_redraw_SK(0, MMI_LEFT_SOFTKEY, 0);
				    g_current_insert_mode = MMI_TRUE;
                                }
                            }
                        }
                        break;
                    case GUI_RNGC_KEY_INSERT:
                        if (touch_rngc_context.play_mode != RNGC_PAUSE && g_rngc_eng_cntx->TotalNotes <= MAX_NOTES)
                        {
                            mmi_rngc_key_unselect(&touch_rngc_context);
                            touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                            touch_rngc_context.area_type = GUI_RNGC_NOTE_SELECTION;
                            selection_area_context = (rngc_selection_area_layout_struct*) & note_selection_layout;
                            touch_rngc_context.mode = GUI_RNGC_INSERT;
                            touch_rngc_context.play_mode = RNGC_PAUSE;
                            touch_rngc_context.flag &= ~RNGC_NOTE_SELECTION_FINAL;
                            touch_rngc_context.flag |= RNGC_SELECTION_AREA_REDRAW;
                            show_touch_rngc_selection_area();
                            clear_softkey_handler(MMI_LEFT_SOFTKEY);
                            mmi_rngc_redraw_SK(0, MMI_LEFT_SOFTKEY, 0);
			    g_current_insert_mode = MMI_TRUE;
                        }
                        break;
                    case GUI_RNGC_KEY_PLAY:
                        if (g_rngc_eng_cntx->TotalNotes > 0)
                        {
                            if (touch_rngc_context.play_mode == RNGC_PLAY)
                            {
                                g_rngc_cntx.CurrHiliteItem = ENUM_ADD_TONE_OPT_PLAY;
                                mmi_rngc_key_unselect(&touch_rngc_context);
                                RngcGotoSelectedCompToneOpt(ENUM_ADD_TONE_OPT_PLAY);
                                touch_rngc_context.play_mode = RNGC_PAUSE;
                            }
                            else if (touch_rngc_context.play_mode == RNGC_PAUSE)
                            {
                                ExitRngcPlayTone();
                                /* stop the playing melody */
                                touch_rngc_context.play_mode = RNGC_PLAY;
                            }
                        }
                        break;
                    case GUI_RNGC_KEY_NEXT:
                        if (g_rngc_eng_cntx->TotalNotes > 0)
                        {
                            if (touch_rngc_context.play_mode != RNGC_PAUSE)
                            {
                                mmi_rngc_key_unselect(&touch_rngc_context);
                                touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                                HandleKey_RIGHT();
                            }
                        }
                        break;
                    case GUI_RNGC_KEY_PREV:
                        if (g_rngc_eng_cntx->TotalNotes > 0)
                        {
                            if (touch_rngc_context.play_mode != RNGC_PAUSE)
                            {
                                mmi_rngc_key_unselect(&touch_rngc_context);
                                touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                                HandleKey_LEFT();
                            }
                        }
                        break;
                }
            break;
        case RNGC_PEN_NOTE_SELECTION:
            if (PEN_CHECK_BOUND
                (pos.x, pos.y, touch_rngc_context.selected_key_x, touch_rngc_context.selected_key_y,
                 touch_rngc_context.key_width, touch_rngc_context.key_height))
            {
                mmi_rngc_key_unselect(&touch_rngc_context);
                touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                if (touch_rngc_context.key_note_type == GUI_RNGC_KEY_OK)
                {
                    if (selection_area_context->custom_keys[selection_area_context->n_custom_keys-1].key_image == IMG_TOUCH_RING_DOWN)
                    {
                        if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT ||
                            touch_rngc_context.mode == GUI_RNGC_INSERT || touch_rngc_context.mode == GUI_RNGC_EDIT)
                        {
                            touch_rngc_context.area_type = GUI_RNGC_NORMAL_TOOLBAR;
                            selection_area_context = &normal_toolbar_layout;
                            touch_rngc_context.mode = GUI_RNGC_VIEW;
                            touch_rngc_context.play_mode = RNGC_PLAY;
                            touch_rngc_context.flag |= RNGC_SELECTION_AREA_REDRAW;
                            mmi_rngc_redraw_stave();
                        #if defined(__MMI_MAINLCD_320X240__)
                            mmi_rngc_redraw_remaining_notes();
                        #endif

                            show_touch_rngc_selection_area();
                            rngc_pen_event_on_object = RNGC_PEN_NONE;
			    if(g_current_insert_mode)
			        g_current_insert_mode = MMI_FALSE;

                            SetKeyHandler(RngcComposerLSKDownHandler, KEY_LSK, KEY_EVENT_DOWN);
                            SetKeyHandler(RngcComposerLSKUpHandler, KEY_LSK, KEY_EVENT_UP);
                            mmi_rngc_redraw_LSK(0);
                        }
                        return;
                    }

                    if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT)
                    {
                        mmi_rngc_finish_insert_editing();
                    }
                }
            }
            else
            {
                mmi_rngc_key_unselect(&touch_rngc_context);
            }
            break;
    }
    rngc_pen_event_on_object = RNGC_PEN_NONE;
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_pen_move_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_pen_move_hdlr(mmi_pen_point_struct pos)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    gui_button_pen_enum button_event;
    S32 item_index = 0;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (rngc_pen_event_on_object)
    {
        case RNGC_PEN_INSTRUMENT:
#ifdef RNGC_HAS_INST_RECTANGLE
            {
                gui_horizontal_select_pen_enum select_event;
                
                gui_horizontal_select_translate_pen_event(
                    &MMI_rngc_instrument_select_menu,
                    MMI_PEN_EVENT_MOVE,
                    pos.x,
                    pos.y,
                    &select_event);
            }
#endif /*RNGC_HAS_INST_RECTANGLE*/
            break;
        case RNGC_PEN_STAVE:
            if (mmi_rngc_pen_down_on_stave(pos, &item_index))
            {
                if (item_index > g_rngc_eng_cntx->CurrUIPos && 
                    g_rngc_eng_cntx->NotesList[g_rngc_eng_cntx->CurrNoteIndex] != 0xFFFF)
                {
                        HandleKey_RIGHT();
                }
                else if (item_index == -1)
                {
                    if (g_rngc_eng_cntx->CurrNoteIndex > 0)
                    {
                        HandleKey_LEFT();
                    }
                }
                else if (item_index < g_rngc_eng_cntx->CurrUIPos)
                {
                    /* mmi_rngc_change_stave_notes(&touch_rngc_context, item_index);*/
                    HandleKey_LEFT();
                }
                if (touch_rngc_context.mode == GUI_RNGC_INSERT_EDIT && item_index != g_rngc_eng_cntx->CurrUIPos)
                {
                    mmi_rngc_finish_insert_editing();
                }
            }
            break;

        case RNGC_PEN_NORMAL_TOOLBAR:
            if (PEN_CHECK_BOUND
                (pos.x, pos.y, selection_area_context->image_x + selection_area_context->matrix_layout->matrix_x,
                 selection_area_context->image_y + selection_area_context->matrix_layout->matrix_y,
                 NORMAL_TOOLBAR_WIDTH, NORMAL_TOOLBAR_HEIGHT))
            {
                if ((!PEN_CHECK_BOUND
                     (pos.x, pos.y, touch_rngc_context.selected_key_x, touch_rngc_context.selected_key_y,
                      touch_rngc_context.key_width - 1, touch_rngc_context.key_height - 1)))
                {
                    if (touch_rngc_context.key_note_type == GUI_RNGC_KEY_PLAY)
                    {
                        if (g_rngc_eng_cntx->TotalNotes > 0)
                        {
                            mmi_rngc_key_unselect(&touch_rngc_context);
                        }
                    }
                    else
                    {
                        mmi_rngc_key_unselect(&touch_rngc_context);
                    }
                    touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                }
            }
            /* START VIJAY PMT 20050719 */
            else    /* move outside note selection bar */
            {
                mmi_rngc_key_unselect(&touch_rngc_context);
            }
            /* END VIJAY */
            break;
        case RNGC_PEN_NOTE_SELECTION:
            if (PEN_CHECK_BOUND
                (pos.x, pos.y, selection_area_context->image_x + selection_area_context->matrix_layout->matrix_x,
                 selection_area_context->image_y + selection_area_context->matrix_layout->matrix_y,
                 NOTE_SELECTION_WIDTH, NOTE_SELECTION_HEIGHT))
            {
                if ((!PEN_CHECK_BOUND
                     (pos.x, pos.y, touch_rngc_context.selected_key_x, touch_rngc_context.selected_key_y,
                      touch_rngc_context.key_width, touch_rngc_context.key_height)))
                {
                    mmi_rngc_key_unselect(&touch_rngc_context);
                    touch_rngc_context.flag |= RNGC_PEN_EVENT_UP;
                }
            }
            else    /* move outside note selection bar */
            {
                mmi_rngc_key_unselect(&touch_rngc_context);
            }
            break;
        case TOUCH_RNGC_PEN_LSK:
            translate_softkey_pen_event(MMI_LEFT_SOFTKEY, MMI_PEN_EVENT_MOVE, pos.x, pos.y, &button_event);
            if (mmi_pen_check_inside_polygon(&SK_area, pos))
            {
                mmi_rngc_redraw_LSK(1);
            }
            else
            {
                mmi_rngc_redraw_LSK(0);
            }
            break;
        case TOUCH_RNGC_PEN_RSK:
            translate_softkey_pen_event(MMI_RIGHT_SOFTKEY, MMI_PEN_EVENT_MOVE, pos.x, pos.y, &button_event);
            if (mmi_pen_check_inside_polygon(&SK_area, pos))
            {
                mmi_rngc_redraw_RSK(1);
            }
            else
            {
                mmi_rngc_redraw_RSK(0);
            }
            break;
    }
}


/*****************************************************************************
 * FUNCTION
 *  mmi_rngc_reset_toolbar
 * DESCRIPTION
 *  Exported to ComposeRingtoneEngine 
 * PARAMETERS
 *  pos     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void mmi_rngc_reset_toolbar(void)
{
        touch_rngc_context.area_type = GUI_RNGC_NORMAL_TOOLBAR;
        selection_area_context = &normal_toolbar_layout;
        touch_rngc_context.mode = GUI_RNGC_VIEW;
        touch_rngc_context.play_mode = RNGC_PLAY;
        touch_rngc_context.flag |= RNGC_SELECTION_AREA_REDRAW;
        mmi_rngc_redraw_stave();
#if defined(__MMI_MAINLCD_320X240__)
    mmi_rngc_redraw_remaining_notes();
#endif
    mmi_rngc_redraw_LSK(0);
    SetKeyHandler(RngcComposerLSKDownHandler, KEY_LSK, KEY_EVENT_DOWN);
    SetKeyHandler(EntryRngcCompToneOptList, KEY_LSK, KEY_EVENT_UP);
    show_touch_rngc_selection_area();
}
#endif /* __MMI_TOUCH_RING_COMPOSER__ */

#endif /* __MMI_RING_COMPOSER__ */