vmeditor.c 82.4 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
/*****************************************************************************
 *  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:
 * ---------
 *  vmeditor.c
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  Inline editor implement file.
 *
 * 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!
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *==============================================================================
 *******************************************************************************/

/* include vmswitch.h in order to check whether __MRE_LIB_EDITOR__ is defined */
#include "vmswitch.h"
#ifdef __MRE_LIB_EDITOR__

/* native header file */
#include "gui.h"
#include "wgui.h"
#include "wgui_editor.h"

/* MRE header file */
#include "vmeditor.h"
#include "vmgraph.h"
#include "vmpromng.h"

/* APIs implemented in other files. */
extern void vm_reg_key_handler(void);
extern mmi_imm_input_mode_enum vm_editor_input_mode_mapping_func(
    vm_input_mode_enum vm_input_mode);
extern VMINT vm_graphic_is_gif_file(VMUINT8 *img_data);
extern VMINT vm_graphic_is_bmp_file(VMUINT8 *img_data);
extern VMINT vm_graphic_is_png_file(VMUINT8 *img_data);
extern VMINT vm_graphic_is_jpeg_file(VMUINT8 *img_data);

extern void vm_graphic_async_blt_stop(void);
extern void vm_graphic_async_blt_start(void);

/* MRE editor struct, each editor has one instance. */
typedef struct
{
    wgui_editor_struct                      *wgui_editor_ptr;
    U8                                      *history_ptr;

    /* 
     * user provided callback function, in which VM_EDITOR_MESSAGE_xxx will be 
     * be handled. 
     */
    vm_editor_message_funcptr               ime_callback;

    /* 
     * user provided callback function, when the text in editor is changed, this
     * callback function will be called. Please note that the callback function
     * will be invoked before editor redraw.
     */
    vm_update_text_funcptr                  update_text_callback;

    /*
     * user provided callback function, when the text in editor is changed, this
     * callback function will be called. Please note that the callback function
     * will be invoked after editor redraw.
     */
    vm_update_text_with_cursor_rect_funcptr update_text_with_cursor_rect_callback;

    /*
     * user provided callback function, when left softkey, right softkey or 
     * center softkey is pressed, the corresponding callback function will be
     * called.
     */
    vm_soft_key_handle_funcptr              lsk_callback;
    vm_soft_key_handle_funcptr              rsk_callback;
    vm_soft_key_handle_funcptr              csk_callback;
} vm_editor_struct;

/*
 * a pointer to the current active editor, and NULL means there is no active 
 * editor now. 
 */
static vm_editor_struct *g_vm_cur_active_editor = NULL;

/* 
 * The current pcb handle, and NULL means there is no active process now. 
 * when editor is activated, g_vm_cur_active_pcb is set to be current process
 * handle. and when editor is deactivated, it is set to be NULL. 
 */
static VM_P_HANDLE g_vm_cur_active_pcb = NULL;

/* 
 * a pointer to the callback function which is reponsible for drawing IMUI's
 * background. When redraw IMUI's background, if this pointer isn't NULL, we 
 * will call user provided callback function, otherwise, we will flush the 
 * IMUI's background to white color.
 */
static vm_draw_imui_background_funcptr g_vm_draw_imui_background_callback;

/* 
 * It means how many editors have been created now.
 * when the 1st editor is being created, we will disable async blt. and when the 
 * last editor has been closed, we will enable async blt again.
 */
static VMINT created_editor_number = 0;

/*****************************************************************************
 * FUNCTION
 *  vm_editor_create
 * DESCRIPTION
 *  Creates an editor, it will use some application's heap memory.
 *  For single line editor, it will malloc 550Byte; 
 *  For multiple line editor, it will malloc xxxByte.
 * PARAMETERS
 *  editor_type             [IN]        Is the editor type
 *  x                       [IN]        Is the left-top corner (x coordinate)
 *  y                       [IN]        Is the left-top corner (y coordinate)
 *  width                   [IN]        Is the width of the editor
 *  height                  [IN]        Is the height of the editor
 *  text_buffer             [IN]        Is the text buffer the editor should use
 *                                      (pre-allocated).
 *  text_buffer_size        [IN]        Is the text buffer size in Bytes
 *  is_disable_softkey      [IN]        Disable softkey or not
 *  layer_handle            [IN]        Is the layer handle
 * RETURNS
 *  If create editor successfully, return the editor handle.
 *  Otherwise, return NULL.
 *****************************************************************************/
VMINT32 vm_editor_create(
    VM_EDITOR_TYPE editor_type,
    VMINT32        x,
    VMINT32        y,
    VMINT32        width,
    VMINT32        height,
    VMUWSTR        text_buffer,
    VMINT32        text_buffer_size,
    VMBOOL         is_disable_softkey,
    VM_GDI_HANDLE  layer_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WGUI_EDITOR_TYPE    wgui_editor_type;
    U32                 wgui_editor_buffer_size;
    U32                 history_buffer_size;
    wgui_editor_struct  *wgui_editor_ptr            = NULL;
    U8                  *history_ptr                = NULL;
    vm_editor_struct    *editor_ptr                 = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    /* Check parameter */
    if (text_buffer == NULL)
    {
        return NULL;
    }

    switch (editor_type)
    {
    case VM_EDITOR_SINGLELINE:
        wgui_editor_type = WGUI_EDITOR_SINGLELINE;
        break;

    case VM_EDITOR_MULTILINE:
        wgui_editor_type = WGUI_EDITOR_MULTILINE;
        break;

    default:
        return NULL;
    }

    wgui_editor_buffer_size = wgui_editor_get_memory_size(wgui_editor_type);
    history_buffer_size = sizeof(wgui_editor_history_struct);
    wgui_editor_ptr = (wgui_editor_struct*) vm_calloc(wgui_editor_buffer_size);
    history_ptr = (U8*) vm_calloc(history_buffer_size);
    editor_ptr = (vm_editor_struct*) vm_calloc(sizeof(vm_editor_struct));

    if (wgui_editor_ptr == NULL || history_ptr == NULL || editor_ptr == NULL)
    {
        if (wgui_editor_ptr != NULL)
        {
            vm_free(wgui_editor_ptr);
        }

        if (history_ptr != NULL)
        {
            vm_free(history_ptr);
        }

        if (editor_ptr != NULL)
        {
            vm_free(editor_ptr);
        }

        return NULL;
    }

    editor_ptr->wgui_editor_ptr = wgui_editor_ptr;
    editor_ptr->history_ptr = history_ptr;

    /*
     * before the 1st editor being created, we should stop async blt to prevent
     * problem caused by async blt and gdi draw.
     */
    vm_graphic_async_blt_stop();

    wgui_editor_create(
        wgui_editor_ptr,
        wgui_editor_type,
        x,
        y,
        width,
        height,
        text_buffer,
        text_buffer_size,
        (MMI_BOOL) is_disable_softkey,
        layer_handle);

    /* when an editor has been created, add 1 to created_editor_number. */
    created_editor_number++;

    /* Singleline editor will select fit font auto. */
    if (editor_type == VM_EDITOR_SINGLELINE)
    {
        wgui_editor_set_fit_text_font(wgui_editor_ptr);
    }

    /*
     * if app didn't provide a IMUI's background filler,
     * then we use the default one.
     */
    if (g_vm_draw_imui_background_callback == NULL)
    {
        vm_editor_set_imui_background_filler(
            (vm_draw_imui_background_funcptr) NULL);
    }

    return (VMINT32) editor_ptr;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_close
 * DESCRIPTION
 *  Close the editor, it will free the editor's memory in this API.
 * PARAMETERS
 *  editor_handle    :   [IN]    the editor handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_close(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_close((wgui_editor_struct*) editor_ptr->wgui_editor_ptr);

    /* Free memory */
    if (editor_ptr->wgui_editor_ptr != NULL)
    {
        vm_free(editor_ptr->wgui_editor_ptr);
        editor_ptr->wgui_editor_ptr = NULL;
    }

    if (editor_ptr->history_ptr != NULL)
    {
        vm_free(editor_ptr->history_ptr);
        editor_ptr->history_ptr = NULL;
    }

    if (editor_ptr != NULL)
    {
        vm_free(editor_ptr);
        if (g_vm_cur_active_editor == editor_ptr)
        {
            g_vm_cur_active_editor = NULL;
        }
    }

    /*
     * when the last editor has been closed, we should enable async blt again. 
     */
    created_editor_number--;
    if (created_editor_number == 0)
    {
        vm_graphic_async_blt_start();
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_IME_call_back
 * DESCRIPTION
 *  this function is the ime_callback for wgui editor.
 *  when editor's status changes, wgui editor will pass some events to mre 
 *  inline editor. we transfer these events from MMI_IMC_MESSAGE_xxx to 
 *  VM_EDITOR_MESSAGE_xxx, then call user provided ime_callback to handle the
 *  events.
 * PARAMETERS
 *  input_box_handle        [IN]
 *  msg_ptr                 [IN]        
 * RETURNS
 *  
 *****************************************************************************/
static VMUINT32 vm_editor_set_IME_call_back(
    void                        *input_box_handle, 
    mmi_imc_message_struct_p    msg_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    U32 lresult = 0;
    vm_editor_message_struct app_msg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    memset(&app_msg, 0, sizeof(vm_editor_message_struct));

    switch (msg_ptr->message_id)
    {
    /*
     * VM_EDITOR_MESSAGE_REDRAW_FLOATING_UI means floating UI's position or size
     * is changed, the new position and size is stored in app_msg.rect. We will 
     * call user provided ime_callback to handle this event, and user should be
     * responsible for redraw app's screen. after app redraws its screen, the 
     * floating UI will be redrawed again. 
     */
    case MMI_IMC_MESSAGE_REDRAW:
        if (msg_ptr->param_0 == 0)
        {
            return 0;
        }
        app_msg.message_id = VM_EDITOR_MESSAGE_REDRAW_FLOATING_UI;
        memcpy(
            &(app_msg.rect), 
            (const void*) msg_ptr->param_1, 
            sizeof(vm_editor_rect));
        break;

    /*
     * use vm_transfer_sys_2_mre_qwerty_key to handle key events.
     * firstly, we will call wgui editor to handle the key events, if it handles
     * these events, then we will do nothing else. but if wgui editor doesn't 
     * handle these key events, we will call vm_pmng_deal_key_event to handle
     * them.
     */
    case MMI_IMC_MESSAGE_SET_KEY:
        vm_reg_key_handler();
        return lresult;

    /*
     * when app calls vm_editor_activate, the activate event will happen.
     * we will call user provided ime_callback to handle this event, and app
     * should be responsible for redraw its screen.
     */
    case MMI_IMC_MESSAGE_ACTIVATE:
        app_msg.message_id = VM_EDITOR_MESSAGE_ACTIVATE;
        break;

    /*
     * when app calls vm_editor_deactivate, the deactivate event will happen.
     * we will call user provided ime_callback to handle this event, and app
     * should be responsible for redraw its screen.
     */
    case MMI_IMC_MESSAGE_DEACTIVATE:
        app_msg.message_id = VM_EDITOR_MESSAGE_DEACTIVATE;
        break;

    /*
     * when IMUI's display or hide, or its height changes, this event will 
     * happen. we will call user provided ime_callback to handle this event, and
     * app should be responsible for re-arrange its layout and redraw app's 
     * screen.
     */
    case MMI_IMC_MESSAGE_IMUI_RECTANGLE_IS_UPDATED:
        app_msg.message_id = VM_EDITOR_MESSAGE_REDRAW_IMUI_RECTANGLE;
        memcpy(
            &(app_msg.rect), 
            (const void*) msg_ptr->param_1, 
            sizeof(vm_editor_rect));
        break;

    /*
     * for other events, we will NOT handle them, and will NOT transfer them to
     * app's ime_callback.
     */
    default:
        return lresult;
    }

    /*
     * for VM_EDITOR_MESSAGE_ACTIVATE, VM_EDITOR_MESSAGE_DEACTIVATE, 
     * VM_EDITOR_MESSAGE_REDRAW_IMUI_RECTANGLE, 
     * VM_EDITOR_MESSAGE_REDRAW_FLOATING_UI, we will call app's ime_callback
     * to handle them. App may need to redraw its screen in the handler.
     */
    if (g_vm_cur_active_editor && g_vm_cur_active_editor->ime_callback)
    {
        if (vm_pmng_set_ctx(g_vm_cur_active_pcb) == VM_PMNG_OP_OK)
        {
            g_vm_cur_active_editor->ime_callback(
                (VMINT32) g_vm_cur_active_editor, 
                &app_msg);

            vm_pmng_reset_ctx();
        }
    }

    /* no matter what happens, the return value should always be 0. */
    return lresult;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_IME
 * DESCRIPTION
 *  To set IME input type, input mode and callback function.
 * PARAMETERS
 *  editor_handle      [IN] the editor handle.
 *  input_type         [IN] the input type, refer to vm_input_type_enum.
 *  input_mode_array   [IN] the input mode set, can pass null to use default 
 *                          mode set.
 *                          If want to use user defined input mode list, 
 *                            1. You need to set input_type as 
 *                               VM_INPUT_TYPE_USER_SPECIFIC.
 *                            2. Application need to use global array variable 
 *                               and end with VM_INPUT_MODE_NONE.
 *                            3. The max length of the array can not more than 10.
 *                          Example:
 *                          static vm_input_mode_enum my_input_modes_lower_first[]
 *                          {
 *                              VM_INPUT_MODE_MULTITAP_LOWERCASE_ABC,
 *                              VM_INPUT_MODE_MULTITAP_UPPERCASE_ABC,
 *                              VM_INPUT_MODE_123,
 *                              VM_INPUT_MODE_SM_PINYIN,
 *                              VM_INPUT_MODE_NONE
 *                          };
 *  default_input_mode [IN]  the default input mode.
 *  ime_callback       [IN]  the ime callback function, app should handle
 *                           VM_EDITOR_MESSAGE_xxx in this callback function.
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_IME(
    VMINT32                     editor_handle,
    VMUINT32                    input_type,
    vm_input_mode_enum          *input_mode_array,
    vm_input_mode_enum          default_input_mode,
    vm_editor_message_funcptr   ime_callback)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;
    mmi_imm_input_mode_enum mmi_imm_input_mode;
    mmi_imm_input_mode_enum mmi_imm_input_mode_list[11];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL 
        && input_type == VM_INPUT_TYPE_USER_SPECIFIC 
        && input_mode_array == NULL)
    {
        return;
    }

    mmi_imm_input_mode = vm_editor_input_mode_mapping_func(default_input_mode);
    editor_ptr->ime_callback = ime_callback;
    memset(
        mmi_imm_input_mode_list, 
        IMM_INPUT_MODE_NONE, 
        sizeof(mmi_imm_input_mode_list));

    if (input_type == VM_INPUT_TYPE_USER_SPECIFIC)
    {
        S32 i;
        for (i = 0; i < 11 && input_mode_array[i] != IMM_INPUT_MODE_NONE; i++)
        {
            mmi_imm_input_mode_list[i] 
                = vm_editor_input_mode_mapping_func(input_mode_array[i]);
        }
    }

    wgui_editor_set_IME(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        (mmi_imm_input_type_enum) input_type,
        0,  /* no use */
        mmi_imm_input_mode_list,
        mmi_imm_input_mode,
        (mmi_imc_message_funcptr) vm_editor_set_IME_call_back);
}

/******************************************************************************
 * FUNCTION
 *  vm_editor_set_softkey_callback_internal
 * DESCRIPTION
 *  this function is help to call the user provided callback function when
 *  softkey is pressed. It is only a helper, and it will be called in
 *  vm_editor_set_softkey_lsk_cb, vm_editor_set_softkey_rsk_cb and
 *  vm_editor_set_softkey_csk_cb.
 * PARAMETERS
 *  softkey_type    :   [IN]    the value is VM_LEFT_SOFTKEY, VM_RIGHT_SOFTKEY
 *                              or VM_CENTER_SOFTKEY.
 * RETURNS
 *  void.
 ******************************************************************************/
static void vm_editor_set_softkey_callback_internal(VMINT softkey_type)
{
    vm_soft_key_handle_funcptr softkey_callback = NULL;

    /* check which callback function should be called. */
    if (softkey_type == VM_LEFT_SOFTKEY)
    {
        softkey_callback = g_vm_cur_active_editor->lsk_callback;
    }
    else if (softkey_type == VM_RIGHT_SOFTKEY)
    {
        softkey_callback = g_vm_cur_active_editor->rsk_callback;
    }
    else
    {
        softkey_callback = g_vm_cur_active_editor->csk_callback;
    }

    /* try to call user provided callback function to handle softkey events. */
    if (g_vm_cur_active_editor && softkey_callback)
    {
        if (vm_pmng_set_ctx(g_vm_cur_active_pcb) == VM_PMNG_OP_OK)
        {
            softkey_callback();
            vm_pmng_reset_ctx();
        }
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_softkey_lsk_cb
 * DESCRIPTION
 *  this is the callback function that we registered in wgui_editor_struct.
 *  when left softkey is pressed, wgui_editor will call this function, and in
 *  this function, we will try to call user provided callback to handle softkey
 *  events.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void vm_editor_set_softkey_lsk_cb(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    vm_editor_set_softkey_callback_internal(VM_LEFT_SOFTKEY);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_softkey_rsk_cb
 * DESCRIPTION
 *  this is the callback function that we registered in wgui_editor_struct.
 *  when right softkey is pressed, this function will be called by wgui_editor,
 *  and in this function, we will try to call user provided callback function to
 *  handle softkey events.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void vm_editor_set_softkey_rsk_cb(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    vm_editor_set_softkey_callback_internal(VM_RIGHT_SOFTKEY);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_softkey_csk_cb
 * DESCRIPTION
 *  this is the callback function that we registered in wgui_editor_struct.
 *  when center softkey is pressed, this function will be called by wgui editor,
 *  and in this function, we will try to call user provided callback function to
 *  handle softkey events.
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
static void vm_editor_set_softkey_csk_cb(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    vm_editor_set_softkey_callback_internal(VM_CENTER_SOFTKEY);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_softkey
 * DESCRIPTION
 *  Set editor's softkey handler. 
 *  Only send key press event to application, other key event will be discarded.
 *  when softkey is pressed, corresponding event will be passed to app's softkey
 *  handler, and app should handle the event.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  s                   [IN]        Is the label
 *  key                 [IN]        Is softkey type
 *  f                   [IN]        Is the softkey handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_softkey(
    VMINT32                     editor_handle, 
    VMUWSTR                     s, 
    VM_SOFTKEY_ENUM             key, 
    vm_soft_key_handle_funcptr  f)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    WGUI_SOFTKEY_ENUM   wgui_key;
    vm_editor_struct    *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    switch (key)
    {
    /* 
     * use vm_editor_set_softkey_lsk_cb to handle the event when left softkey
     * is pressed. and in the handler, we will do nothing but call app's left
     * softkey handler.
     */
    case VM_LEFT_SOFTKEY:
        wgui_key = MMI_LEFT_SOFTKEY;
        editor_ptr->lsk_callback = f;
        wgui_editor_set_softkey(
            (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
            s,
            NULL,
            wgui_key,
            vm_editor_set_softkey_lsk_cb);
        break;

    /*
     * use vm_editor_set_softkey_rsk_cb to handle the event when right softkey
     * is pressed. and in the handler, we will do nothing but call app's right
     * softkey handler.
     */
    case VM_RIGHT_SOFTKEY:
        wgui_key = MMI_RIGHT_SOFTKEY;
        editor_ptr->rsk_callback = f;
        wgui_editor_set_softkey(
            (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
            s,
            NULL,
            wgui_key,
            vm_editor_set_softkey_rsk_cb);
        break;

    /*
     * use vm_editor_set_softkey_csk_cb to handle the event when center softkey
     * is pressed. and in the handler, we will do nothing but call app's center
     * softkey handler.
     */
    case VM_CENTER_SOFTKEY:
        wgui_key = MMI_CENTER_SOFTKEY;
        editor_ptr->csk_callback = f;
        wgui_editor_set_softkey(
            (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
            s,
            NULL,
            wgui_key,
            vm_editor_set_softkey_csk_cb);
        break;
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_softkey_height
 * DESCRIPTION
 *  get the height of softkey area.  
 * PARAMETERS
 *  void
 * RETURNS
 *  Soft key's height in pixel.
 *****************************************************************************/
VMUINT32 vm_editor_get_softkey_height(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return MMI_SOFTKEY_HEIGHT;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_show
 * DESCRIPTION
 *  Display the editor (not flush to screen).
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_show(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    /* 
     * before show editor, we should disable async blt, otherwise some problems
     * may happen.
     */
    vm_graphic_async_blt_stop();

    wgui_editor_show((wgui_editor_struct*) editor_ptr->wgui_editor_ptr);
}

/******************************************************************************
 * FUNCTION
 *  vm_editor_select_font_size
 * DESCRIPTION
 *  this function can help to get the suitable font size. please note that the
 *  function is internal, and it can be used only in this file.
 *      VM_SMALL_FONT  --> SMALL_FONT
 *      VM_MEDIUM_FONT --> MEDIUM_FONT
 *      VM_LARGE_FONT  --> LARGE_FONT
 *      OTHER          --> FONT_PIXEL_SIZE(size_wanted) (for vector font)
 *                     --> MEDIUM_FONT (for non-vector font)
 * PARAMETERS
 *  size_wanted :   [IN]    the font size that user wanted.
 * RETRUNS
 *  the suitable font size.
 ******************************************************************************/
static VMUINT8 vm_editor_select_font_size(VMUINT8 size_wanted)
{
    VMUINT8 default_font_size;

    if (vm_graphic_is_use_vector_font())
    {
        default_font_size = FONT_PIXEL_SIZE(size_wanted);
    }
    else
    {
        default_font_size = MEDIUM_FONT;
    }

    switch (size_wanted)
    {
    case VM_SMALL_FONT:
        return SMALL_FONT;

    case VM_MEDIUM_FONT:
        return MEDIUM_FONT;

    case VM_LARGE_FONT:
        return LARGE_FONT;

    default:
        return default_font_size;
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_multiline_text_font
 * DESCRIPTION
 *  Set multi line editor input text font. 
 *  Recommended that use font_size_t type to define size.
 *  If use number directly, you need to check if the phone support vector font.
 * PARAMETERS
 *  editor_handle    :   [IN]    the editor handle
 *  text_font        :   [IN]    the text font
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_multiline_text_font(
    VMINT32                     editor_handle, 
    vm_editor_font_attribute    text_font)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct    *editor_ptr;
    stFontAttribute     wgui_text_font;
    U8                  default_font_size;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;
    memset(&wgui_text_font, 0, sizeof(wgui_text_font));

    /*
     * only multi-line editor can use this function. if it is a single-line
     * editor, call this function will cause nothing to happen.
     */
    if (editor_ptr == NULL 
        || editor_ptr->wgui_editor_ptr->editor_type != WGUI_EDITOR_MULTILINE)
    {
        return;
    }

    wgui_text_font.size = vm_editor_select_font_size(text_font.size);
    wgui_text_font.bold = text_font.bold;
    wgui_text_font.italic = text_font.italic;
    wgui_text_font.underline = text_font.underline;

    wgui_editor_set_text_font(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        (UI_font_type) &wgui_text_font);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_font_attribute
 * DESCRIPTION
 *  Get editor's font attribute.
 * PARAMETERS
 *  editor_handle    :   [IN]     the editor handle
 *  text_font        :   [OUT]    the text font
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_get_font_attribute(
    VMINT32                     editor_handle, 
    vm_editor_font_attribute    *text_font)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct    *editor_ptr;
    stFontAttribute     *p_font;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;
    p_font = &(editor_ptr->wgui_editor_ptr->text_font);

    /* Check parameter */
    if (editor_ptr == NULL || text_font == NULL)
    {
        return;
    }

    text_font->bold         =   p_font->bold;
    text_font->italic       =   p_font->italic;
    text_font->underline    =   p_font->underline;
    text_font->size         =   p_font->size;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_bg_image
 * DESCRIPTION
 *  Set the normal and focuss image pointers for image background
 *  (there are two styles of background: image background and rectangle background)
 * PARAMETERS
 *  editor_handle           [IN]        Is the editor handle
 *  focus_image             [IN]        Is the focuss image
 *  normal_image            [IN]        Is the normal image
 *  focus_image_size        [IN]        Is the focuss image size
 *  normal_image_size       [IN]        Is the normal image size
 * RETURNS
 *  0 : If successful.
 *  -1 : Parameter error.
 *  -2 : Focus image type error.
 *  -3 : Normal image type error.
 *****************************************************************************/
VMINT32 vm_editor_set_bg_image(
    VMINT32    editor_handle,
    VMUINT8    *focus_image,
    VMUINT8    *normal_image,
    VMINT32    focus_image_size,
    VMINT32    normal_image_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct    *editor_ptr;
    U8                  focus_image_type;
    U8                  normal_image_type;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL || focus_image == NULL || normal_image == NULL)
    {
        return -1;
    }

    /* Get focus image type */
    if (vm_graphic_is_gif_file(focus_image))
    {
        focus_image_type = GDI_IMAGE_TYPE_GIF;
    }
    else if (vm_graphic_is_bmp_file(focus_image))
    {
        focus_image_type = GDI_IMAGE_TYPE_BMP;
    }
    else if (vm_graphic_is_png_file(focus_image))
    {
        focus_image_type = GDI_IMAGE_TYPE_PNG;
    }
    else if (vm_graphic_is_jpeg_file(focus_image))
    {
        focus_image_type = GDI_IMAGE_TYPE_JPG;
    }
    else
    {
        return -2;
    }

    /* Get normal image type */
    if (vm_graphic_is_gif_file(normal_image))
    {
        normal_image_type = GDI_IMAGE_TYPE_GIF;
    }
    else if (vm_graphic_is_bmp_file(normal_image))
    {
        normal_image_type = GDI_IMAGE_TYPE_BMP;
    }
    else if (vm_graphic_is_png_file(normal_image))
    {
        normal_image_type = GDI_IMAGE_TYPE_PNG;
    }
    else if (vm_graphic_is_jpeg_file(normal_image))
    {
        normal_image_type = GDI_IMAGE_TYPE_JPG;
    }
    else
    {
        return -3;
    }

    wgui_editor_set_bg_image_from_memory(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        focus_image,
        normal_image,
        focus_image_size,
        normal_image_size,
        focus_image_type,
        normal_image_type);

    return 0;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_bg_border_style
 * DESCRIPTION
 *  Set border style for rectangle background
 *  (there are two styles of background: image background and rectangle background)
 * PARAMETERS
 *  editor_handle           [IN]        Is the editor handle
 *  border_width            [IN]        Is the border width
 *                                      (no border/single border/double border)
 *  border_normal_color     [IN]        Is the border color of normal style
 *  border_focuss_color     [IN]        Is the border color of focuss style
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_bg_border_style(
    VMINT32                 editor_handle,
    VM_EDITOR_BORDER_TYPE   border_width,
    VMUINT16                border_normal_color,
    VMUINT16                border_focuss_color)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct        *editor_ptr;
    WGUI_EDITOR_BORDER_TYPE wgui_border_width;
    color                   wgui_border_normal_color;
    color                   wgui_border_focus_color;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    switch (border_width)
    {
    case VM_EDITOR_NO_BORDER:
        wgui_border_width = WGUI_EDITOR_NO_BORDER;
        break;

    case VM_EDITOR_SINGLE_BORDER:
        wgui_border_width = WGUI_EDITOR_SINGLE_BORDER;
        break;

    case VM_EDITOR_DOUBLE_BORDER:
        wgui_border_width = WGUI_EDITOR_DOUBLE_BORDER;
        break;
    
    case VM_EDITOR_BORDER_END:
        wgui_border_width = WGUI_EDITOR_BORDER_END;
        break;
    
    default:
        wgui_border_width = WGUI_EDITOR_NO_BORDER;
        break;
    }

    wgui_border_normal_color = gui_color(
        VM_COLOR_GET_RED(border_normal_color),
        VM_COLOR_GET_GREEN(border_normal_color),
        VM_COLOR_GET_BLUE(border_normal_color));

    wgui_border_focus_color = gui_color(
        VM_COLOR_GET_RED(border_focuss_color),
        VM_COLOR_GET_GREEN(border_focuss_color),
        VM_COLOR_GET_BLUE(border_focuss_color));

    wgui_editor_set_bg_border_style(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        wgui_border_width,
        wgui_border_normal_color,
        wgui_border_focus_color);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_margin
 * DESCRIPTION
 *  Set margin for editor
 *  (for singleline, align center along y direction, so no need to set top/down 
 *  margin)
 * PARAMETERS
 *  editor_handle       [IN]    Is the editor handle
 *  top                 [IN]    Top >0: set new value; -1: use default value
 *  down                [IN]    Down >0: set new value; -1: use default value
 *  left                [IN]    Left >0: set new value; -1: use default value
 *  right               [IN]    Right >0: set new value; -1: use default value
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_margin(
    VMINT32 editor_handle, 
    VMINT32 top, 
    VMINT32 down, 
    VMINT32 left, 
    VMINT32 right)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    // TODO: check for top/down/left/right

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_margin(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        top, 
        down, 
        left, 
        right);

    /* Singleline editor will select fit font auto. */
    if (editor_ptr->wgui_editor_ptr->editor_type == VM_EDITOR_SINGLELINE)
    {
        wgui_editor_set_fit_text_font(editor_ptr->wgui_editor_ptr);
    }
}


/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_layer_handle
 * DESCRIPTION
 *  Set editor layer handle
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  layer_handle        [IN]        Is the layer handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_layer_handle(
    VMINT32         editor_handle, 
    VM_GDI_HANDLE   layer_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_layer_handle(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        layer_handle);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_update_text_callback_cb
 * DESCRIPTION
 *  
 * PARAMETERS
 *  text            [IN]        
 *  cursor          [IN]        
 *  text_length     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
static void vm_editor_set_update_text_callback_cb(
    UI_buffer_type  text, 
    UI_buffer_type  cursor, 
    S32             text_length)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_vm_cur_active_editor && g_vm_cur_active_editor->update_text_callback)
    {
        if (vm_pmng_set_ctx(g_vm_cur_active_pcb) == VM_PMNG_OP_OK)
        {
            g_vm_cur_active_editor->update_text_callback(
                text, 
                cursor, 
                text_length);

            vm_pmng_reset_ctx();
        }
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_update_text_callback
 * DESCRIPTION
 *  Set update text call back
 * PARAMETERS
 *  editor_handle               [IN]        Is the editor handle
 *  update_text_callback        [IN]        Is update text callback
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_update_text_callback(
    VMINT32                 editor_handle, 
    vm_update_text_funcptr  update_text_callback)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    editor_ptr->update_text_callback = update_text_callback;

    wgui_editor_set_update_text_callback(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        vm_editor_set_update_text_callback_cb);
}

/*****************************************************************************
 * FUNCTION
 *   vm_editor_set_update_text_with_cursor_rect_callback_cb
 * DESCRIPTION
 *   this is the callback function provided by mre editor which will be set to
 *   wgui editor.
 * PARAMETERS
 *   text    :               [IN]    point to the begin of the input string.
 *   cursor  :               [IN]    point to the current cursor position.
 *   text_length :           [IN]    length of the input string.
 *   cursor_rect_points  :   [IN]    rect of cursor.
 * RETURNS
 *   void
 *****************************************************************************/
static void vm_editor_set_update_text_with_cursor_rect_callback_cb(
    UI_buffer_type              text,
    UI_buffer_type              cursor,
    S32                         text_length,
    wgui_editor_rect_points_p   cursor_rect_points)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_vm_cur_active_editor 
        && g_vm_cur_active_editor->update_text_with_cursor_rect_callback) 
    {
        if (vm_pmng_set_ctx(g_vm_cur_active_pcb) == VM_PMNG_OP_OK)
        {
            g_vm_cur_active_editor->update_text_with_cursor_rect_callback(
                text, 
                cursor, 
                text_length, 
                (vm_editor_rect_points_p) cursor_rect_points);

            vm_pmng_reset_ctx();
        }
    }
}

/*****************************************************************************
 * FUNCTION
 *   vm_editor_set_update_text_with_cursor_rect_callback
 * DESCRIPTION
 *   set update text with cursor rect callback
 * PARAMETERS
 *   editor_handle                           :   [IN] the editor handle
 *   update_text_with_cursor_rect_callback   :   [IN] callback provided by app
 *****************************************************************************/
void vm_editor_set_update_text_with_cursor_rect_callback(
    VMINT32                                 editor_handle, 
    vm_update_text_with_cursor_rect_funcptr update_text_with_cursor_rect_callback)
{
    /*---------------------------------------------------------------*/
    /* Local Variables                                               */
    /*---------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*---------------------------------------------------------------*/
    /* Code Body                                                     */
    /*---------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    editor_ptr->update_text_with_cursor_rect_callback 
        = update_text_with_cursor_rect_callback;

    wgui_editor_set_update_text_with_cursor_rect_callback(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        vm_editor_set_update_text_with_cursor_rect_callback_cb);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_pos
 * DESCRIPTION
 *  Move the editor and show.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  x                   [IN]        Is the left-top corner
 *  y                   [IN]        Is the left-top corner
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_pos(VMINT32 editor_handle, VMINT32 x, VMINT32 y)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_pos(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        x, 
        y);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_pos
 * DESCRIPTION
 *  Get editor position.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  x                   [OUT]       Is the left-top corner
 *  y                   [OUT]       Is the left-top corner
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_get_pos(VMINT32 editor_handle, VMINT32 *x, VMINT32 *y)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_get_pos(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        (S32*) x, 
        (S32*) y);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_size
 * DESCRIPTION
 *  Resize the editor and show.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  width               [IN]        Is the width of the editor
 *  height              [IN]        Is the height of the editor
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_size(VMINT32 editor_handle, VMINT32 width, VMINT32 height)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_size(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        width, 
        height);

    /* Singleline editor will select fit font auto. */
    if (editor_ptr->wgui_editor_ptr->editor_type == VM_EDITOR_SINGLELINE)
    {
        wgui_editor_set_fit_text_font(editor_ptr->wgui_editor_ptr);
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_size
 * DESCRIPTION
 *  Get the editor size.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  width               [OUT]       Is the width of the editor
 *  height              [OUT]       Is the height of the editor
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_get_size(VMINT32 editor_handle, VMINT32 *width, VMINT32 *height)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_get_size(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        (S32*) width, 
        (S32*) height);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_text
 * DESCRIPTION
 *  Set the text show in the editor.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  text_buffer         [IN]        Is the text buffer
 *  text_size           [IN]        Is the text buffer size(byte)
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_text(
    VMINT32 editor_handle, 
    VMUWSTR text_buffer, 
    VMINT32 text_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_text(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        text_buffer, 
        text_size);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_text
 * DESCRIPTION
 *  Get the input text of the editor.
 * PARAMETERS
 *  editor_handle       [IN]            Is the editor handle
 *  text_buffer         [IN/OUT]        Is the text buffer
 *  text_size           [IN]            Is the text buffer size(byte)
 * RETURNS
 *  VMINT32: text length
 *****************************************************************************/
VMINT32 vm_editor_get_text(
    VMINT32 editor_handle, 
    VMUWSTR text_buffer, 
    VMINT32 text_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct    *editor_ptr;
    VMINT32             length;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return 0;
    }

    length = wgui_editor_get_text(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        text_buffer, 
        text_size);

    return length;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_text_color
 * DESCRIPTION
 *  set text color
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  text_color          [IN]        Is the text color
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_text_color(VMINT32 editor_handle, VMUINT16 text_color)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct    *editor_ptr;
    color               wgui_text_color;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }


    wgui_text_color = gui_color(
        VM_COLOR_GET_RED(text_color),
        VM_COLOR_GET_GREEN(text_color),
        VM_COLOR_GET_BLUE(text_color));

    wgui_editor_set_text_color(editor_ptr->wgui_editor_ptr, wgui_text_color);
}

/*****************************************************************************
 * FUNCTION
 *  wgui_editor_set_cursor_color
 * DESCRIPTION
 *  set cursor color
 * PARAMETERS
 *  editor_handle       [IN]            Is the editor handle
 *   cursor_color    [IN]        Is the cursor color
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_cursor_color(VMINT32 editor_handle, VMUINT16 cursor_color)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct    *editor_ptr;
    color               wgui_cursor_color;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_cursor_color = gui_color(
        VM_COLOR_GET_RED(cursor_color),
        VM_COLOR_GET_GREEN(cursor_color),
        VM_COLOR_GET_BLUE(cursor_color));

    wgui_editor_set_cursor_color(
        editor_ptr->wgui_editor_ptr, 
        wgui_cursor_color);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_activate
 * DESCRIPTION
 *  Activate the editor.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 *  is_vk_default_on    [IN]        If TRUE, the VK will be on when active the editor; 
 *                                  If FALSE, the VK will be not on when active the editor, you need extra tap to show VK.
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_activate(VMINT32 editor_handle, VMBOOL is_vk_default_on)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;
    BOOL lcd_freeze = gdi_lcd_get_freeze();

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL || g_vm_cur_active_editor == editor_ptr)
    {
        return;
    }

    gdi_lcd_freeze(MMI_TRUE);
    if (g_vm_cur_active_editor != editor_ptr && g_vm_cur_active_editor != NULL)
    {
        vm_editor_deactivate((VMINT32) g_vm_cur_active_editor);
    }

    g_vm_cur_active_pcb = vm_pmng_get_current_handle();
    g_vm_cur_active_editor = editor_ptr;

    vm_graphic_async_blt_stop();

    wgui_editor_activate(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        (MMI_BOOL) is_vk_default_on);
    gdi_lcd_freeze(lcd_freeze);
    gdi_lcd_repaint_all();
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_deactivate
 * DESCRIPTION
 *  Deactivate the editor.
 *  If application state switch to inactive/background/unload, must call this API.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_deactivate(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_deactivate((wgui_editor_struct*) editor_ptr->wgui_editor_ptr);

    g_vm_cur_active_editor = NULL;
    g_vm_cur_active_pcb = NULL;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_active_editor
 * DESCRIPTION
 *  Get current active editor.
 * PARAMETERS
 *  void
 * RETURNS
 *  The active editor handle.
 *****************************************************************************/
VMINT32 vm_editor_get_active_editor(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    wgui_editor_struct *wgui_editor_ptr = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_editor_get_active_editor((wgui_editor_struct **) (&wgui_editor_ptr));
    if (g_vm_cur_active_editor && wgui_editor_ptr)
    {
        ASSERT(g_vm_cur_active_editor->wgui_editor_ptr == wgui_editor_ptr);
    }

    return (VMINT32) g_vm_cur_active_editor;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_fit_height
 * DESCRIPTION
 *  Get the fit editor height. This API only used to calculate single line editor
 *  height.
 *  For text_font_size, you can use font_size_t type to define the size or use 
 *  number directly.
 * PARAMETERS
 *  vertical_margin_size        [IN]        Is the vertical margin size
 *  text_font_size              [IN]        Is the text font size
 * RETURNS
 *  editor height.
 *****************************************************************************/
VMINT32 vm_editor_get_fit_height(
    VMUINT8 vertical_margin_size, 
    VMUINT8 text_font_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    VMUINT8 wgui_text_font_size;
    VMINT32 fit_height;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_text_font_size = vm_editor_select_font_size(text_font_size);
    fit_height = wgui_editor_get_fit_height(
        (S32) vertical_margin_size, 
        wgui_text_font_size);

    return fit_height;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_indicator_height
 * DESCRIPTION
 *  Get indicator height.
 * PARAMETERS
 *  void
 * RETURNS
 *  Indicator height.
 *****************************************************************************/
VMINT32 vm_editor_get_indicator_height(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    return 0;
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_save
 * DESCRIPTION
 *  Save the history info of the editor.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_save(VMINT32 editor_handle)      // TODO: when to use this API
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_save(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        editor_ptr->history_ptr);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_restore
 * DESCRIPTION
 *  Restore the history info to the editor.
 * PARAMETERS
 *  editor_handle       [IN]        Is the editor handle
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_restore(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_restore(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr, 
        editor_ptr->history_ptr);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_is_draw_floating_indicator
 * DESCRIPTION
 *  Set if draw ime floating indicator.
 * PARAMETERS
 *  is_draw_floating_indicator        [IN]        if draw ime floating indicator
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_is_draw_floating_indicator(VMBOOL is_draw_floating_indicator)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_editor_set_is_draw_ime_floating_indicator(
        (MMI_BOOL) is_draw_floating_indicator);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_redraw_floating_ui_within_rect
 * DESCRIPTION
 *  Redraw ime floating ui within given rectangle area.
 * PARAMETERS
 *  rect               [IN]        Is the given rectangle area
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_redraw_floating_ui_within_rect(vm_editor_rect rect)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    mmi_imc_rect wgui_rect;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_rect.x = rect.x;
    wgui_rect.y = rect.y;
    wgui_rect.height = rect.height;
    wgui_rect.width = rect.width;

    wgui_editor_redraw_ime_floating_ui_within_rect((mmi_imc_rect_p) &wgui_rect);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_redraw_ime_screen
 * DESCRIPTION
 *  Redraw ime UIs(floating ui and fixed ui).
 * PARAMETERS
 *  void
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_redraw_ime_screen(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_editor_redraw_ime_screen();
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_extra_imui_layer_handler
 * DESCRIPTION
 *  get extra imui layer handler (like handwriting drawn layer).
 * PARAMETERS
 *  void
 * RETURNS
 *  Layer handle.
 *****************************************************************************/
VM_GDI_HANDLE vm_editor_get_extra_imui_layer_handler(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    GDI_HANDLE wgui_layer_hdl;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    wgui_layer_hdl = wgui_editor_get_extra_imui_layer_handler();

    return wgui_layer_hdl;
}

/*****************************************************************************
 * FUNCTION
 *   vm_editor_draw_imui_background_callback
 * DESCRIPTION
 *   callback function provided by mre editor to redraw imui background.
 *   It will call the app's callback directly.
 * PARAMETERS
 *   x1  :   [IN]    x-coordination of top-left point.
 *   y1  :   [IN]    y-coordination of top-left point.
 *   x2  :   [IN]    x-coordination of down-right point.
 *   y2  :   [IN]    y-coordination of down-right point.
 * RETURNS
 *   void
 *****************************************************************************/
static void vm_editor_draw_imui_background_callback(
    S32 x1, 
    S32 y1, 
    S32 x2, 
    S32 y2)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (g_vm_draw_imui_background_callback)
    {
        if (vm_pmng_set_ctx(g_vm_cur_active_pcb) == VM_PMNG_OP_OK)
        {
            g_vm_draw_imui_background_callback(x1, y1, x2, y2);

            vm_pmng_reset_ctx();
        }
    }
    else
    {
        extern VMINT vm_graphic_get_active_layer(void);
        if (vm_pmng_set_ctx(g_vm_cur_active_pcb) == VM_PMNG_OP_OK)
        {
            vm_graphic_color color;

            color.vm_color_565 = VM_COLOR_WHITE;
            vm_graphic_setcolor(&color);

            vm_graphic_fill_rect_ex(
                vm_graphic_get_active_layer(),
                x1,
                y1,
                x2 - x1,
                y2 - y1);

            vm_pmng_reset_ctx();
        }
    }
}

/*****************************************************************************
 * FUNCTION
 *   vm_editor_set_imui_background_filler
 * DESCRIPTION
 *   set the callback function to draw imui background.
 *   this function should be called before activate any mre editor.
 * PARAMETERS
 *   draw_imui_background_callback   :   [IN]    the callback to draw imui background.
 * RETURNS
 *   void
 *****************************************************************************/
void vm_editor_set_imui_background_filler(
    vm_draw_imui_background_funcptr draw_imui_background_callback)
{
    g_vm_draw_imui_background_callback = draw_imui_background_callback;

    wgui_editor_set_imui_background_filler(
        vm_editor_draw_imui_background_callback);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_insert_string
 * DESCRIPTION
 *  insert string.
 * PARAMETERS
 *  editor_handle   :   [IN]    the handle of editor.
 *  str :   [IN]    string to be inserted.
 *  len :   [IN]    length of string.
 * RETURNS
 *  the length of string actually inserted.
 *****************************************************************************/
VMINT32 vm_editor_insert_string(VMINT32 editor_handle, VMUWSTR str, VMINT32 len)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return 0;
    }

    return wgui_editor_insert_string(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        (UI_string_type) str,
        (U32) len);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_set_cursor_index
 * DESCRIPTION
 *  set editor cursor index
 * PARAMETERS
 *  editor_handle   :   [IN]    the handle of editor.
 *  cursor_index    :   [IN]    the cursor index
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_set_cursor_index(VMINT32 editor_handle, VMINT32 cursor_index)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_cursor_index(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        (U32) cursor_index);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_get_cursor_index
 * DESCRIPTION
 *  get editor cursor index
 * PARAMETERS
 *  editor_handle   :   [IN]    the handle of editor.
 * RETURNS
 *  the cursor index.
 *****************************************************************************/
VMINT32 vm_editor_get_cursor_index(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    return wgui_editor_get_cursor_index(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr);
}

/*****************************************************************************
 * FUNCTION
 *   vm_editor_set_default_text
 * DESCRIPTION
 *   set default text.
 * PARAMETERS
 *   editor_handle   :   [IN]    the handle of editor.
 *   default_text_buffer :   [IN]    the buffer that stores default text.
 * RETURNS
 *   void
 *****************************************************************************/
void vm_editor_set_default_text(
    VMINT32 editor_handle, 
    VMUWSTR default_text_buffer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    /* Check parameter */
    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_set_default_text(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr,
        (UI_string_type) default_text_buffer);
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_show_from_first_line
 * DESCRIPTION
 *  jump to start to show from the first line of multiline editor.
 * PARAMETERS
 *  editor_handle    :   [IN]    handle of the editor.
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_show_from_first_line(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    if (editor_ptr != NULL 
        && ((wgui_editor_struct*) editor_ptr)->editor_type
        == WGUI_EDITOR_MULTILINE)
    {
        wgui_editor_show_from_start(
            (wgui_editor_struct*) editor_ptr->wgui_editor_ptr);
    }
}

/*****************************************************************************
 * FUNCTION
 *  vm_editor_show_from_start
 * DESCRIPTION
 *  for multi-line editor, show from the first line.
 *  for single-line editor, show from the first charactor.
 * PARAMETERS
 *  editor_handle    :   [IN]    handle of the editor.
 * RETURNS
 *  void
 *****************************************************************************/
void vm_editor_show_from_start(VMINT32 editor_handle)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    vm_editor_struct *editor_ptr;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    editor_ptr = (vm_editor_struct*) editor_handle;

    if (editor_ptr == NULL)
    {
        return;
    }

    wgui_editor_show_from_start(
        (wgui_editor_struct*) editor_ptr->wgui_editor_ptr);
}

#endif /* __MRE_LIB_EDITOR__ */