comparison android/dw.cpp @ 2510:f54051c3f2a5

Android: Implement MLE functions. Fix issues with checkboxes and sliders. Started enabling all notebook tabs in the test program... but a number of controls still missing, so functionality is still spotty at this point.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 07 May 2021 09:35:14 +0000
parents a149dabf6a1f
children 0945d0428dfe
comparison
equal deleted inserted replaced
2509:eaac1317b851 2510:f54051c3f2a5
1430 JNIEnv *env; 1430 JNIEnv *env;
1431 1431
1432 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 1432 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1433 { 1433 {
1434 // First get the class that contains the method you need to call 1434 // First get the class that contains the method you need to call
1435 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 1435 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1436 jclass clazz = env->FindClass(DW_CLASS_NAME);
1437 // Get the method that you want to call 1436 // Get the method that you want to call
1438 jmethodID checkOrRadioGetChecked = env->GetMethodID(clazz, "checkOrRadioGetChecked", 1437 jmethodID checkOrRadioGetChecked = env->GetMethodID(clazz, "checkOrRadioGetChecked",
1439 "(Landroid/view/View;)Z"); 1438 "(Landroid/view/View;)Z");
1440 // Call the method on the object 1439 // Call the method on the object
1441 return env->CallBooleanMethod(_dw_obj, checkOrRadioGetChecked, handle); 1440 return env->CallBooleanMethod(_dw_obj, checkOrRadioGetChecked, handle);
1454 JNIEnv *env; 1453 JNIEnv *env;
1455 1454
1456 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) 1455 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1457 { 1456 {
1458 // First get the class that contains the method you need to call 1457 // First get the class that contains the method you need to call
1459 //jclass clazz = _dw_find_class(env, DW_CLASS_NAME); 1458 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1460 jclass clazz = env->FindClass(DW_CLASS_NAME);
1461 // Get the method that you want to call 1459 // Get the method that you want to call
1462 jmethodID checkOrRadioSetChecked = env->GetMethodID(clazz, "checkOrRadioSetChecked", 1460 jmethodID checkOrRadioSetChecked = env->GetMethodID(clazz, "checkOrRadioSetChecked",
1463 "(Landroid/view/View;I)V"); 1461 "(Landroid/view/View;I)V");
1464 // Call the method on the object 1462 // Call the method on the object
1465 env->CallVoidMethod(_dw_obj, checkOrRadioSetChecked, handle, value); 1463 env->CallVoidMethod(_dw_obj, checkOrRadioSetChecked, handle, value);
1631 * Returns: 1629 * Returns:
1632 * A handle to a MLE window or NULL on failure. 1630 * A handle to a MLE window or NULL on failure.
1633 */ 1631 */
1634 HWND API dw_mle_new(ULONG cid) 1632 HWND API dw_mle_new(ULONG cid)
1635 { 1633 {
1634 JNIEnv *env;
1635
1636 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1637 {
1638 // First get the class that contains the method you need to call
1639 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1640 // Get the method that you want to call
1641 jmethodID mleNew = env->GetMethodID(clazz, "mleNew",
1642 "(I)Landroid/widget/EditText;");
1643 // Call the method on the object
1644 jobject result = env->NewWeakGlobalRef(env->CallObjectMethod(_dw_obj, mleNew, (int)cid));
1645 return result;
1646 }
1636 return 0; 1647 return 0;
1637 } 1648 }
1638 1649
1639 /* 1650 /*
1640 * Adds text to an MLE box and returns the current point. 1651 * Adds text to an MLE box and returns the current point.
1645 * Returns: 1656 * Returns:
1646 * Current position in the buffer. 1657 * Current position in the buffer.
1647 */ 1658 */
1648 unsigned int API dw_mle_import(HWND handle, const char *buffer, int startpoint) 1659 unsigned int API dw_mle_import(HWND handle, const char *buffer, int startpoint)
1649 { 1660 {
1650 return 0; 1661 JNIEnv *env;
1662 int retval = 0;
1663
1664 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1665 {
1666 // Construct a String
1667 jstring jstr = env->NewStringUTF(buffer);
1668 // First get the class that contains the method you need to call
1669 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1670 // Get the method that you want to call
1671 jmethodID mleImport = env->GetMethodID(clazz, "mleImport",
1672 "(Landroid/widget/EditText;Ljava/lang/String;I)I");
1673 // Call the method on the object
1674 retval = env->CallIntMethod(_dw_obj, mleImport, handle, jstr, startpoint);
1675 }
1676 return retval;
1651 } 1677 }
1652 1678
1653 /* 1679 /*
1654 * Grabs text from an MLE box. 1680 * Grabs text from an MLE box.
1655 * Parameters: 1681 * Parameters:
1658 * startpoint: Point to start grabbing text. 1684 * startpoint: Point to start grabbing text.
1659 * length: Amount of text to be grabbed. 1685 * length: Amount of text to be grabbed.
1660 */ 1686 */
1661 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length) 1687 void API dw_mle_export(HWND handle, char *buffer, int startpoint, int length)
1662 { 1688 {
1689 if(buffer && length > 0) {
1690 char *text = dw_window_get_text(handle);
1691
1692 if (text) {
1693 int len = strlen(text);
1694
1695 if (startpoint < len)
1696 strncpy(buffer, &text[startpoint], length);
1697 else
1698 buffer[0] = '\0';
1699 free(text);
1700 }
1701 }
1663 } 1702 }
1664 1703
1665 /* 1704 /*
1666 * Obtains information about an MLE box. 1705 * Obtains information about an MLE box.
1667 * Parameters: 1706 * Parameters:
1669 * bytes: A pointer to a variable to return the total bytes. 1708 * bytes: A pointer to a variable to return the total bytes.
1670 * lines: A pointer to a variable to return the number of lines. 1709 * lines: A pointer to a variable to return the number of lines.
1671 */ 1710 */
1672 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines) 1711 void API dw_mle_get_size(HWND handle, unsigned long *bytes, unsigned long *lines)
1673 { 1712 {
1674 if(bytes) 1713 char *text = dw_window_get_text(handle);
1675 *bytes = 0; 1714
1676 if(lines) 1715 if(bytes) {
1677 *lines = 0; 1716 if(text) {
1717 *bytes = strlen(text);
1718 } else {
1719 *bytes = 0;
1720 }
1721 }
1722 if(lines) {
1723 if(text)
1724 {
1725 int count = 0;
1726 char *tmp = text;
1727
1728 while((tmp = strchr(tmp, '\n'))) {
1729 count++;
1730 }
1731 *lines = count;
1732 } else {
1733 *lines = 0;
1734 }
1735 }
1736 if(text)
1737 free(text);
1678 } 1738 }
1679 1739
1680 /* 1740 /*
1681 * Deletes text from an MLE box. 1741 * Deletes text from an MLE box.
1682 * Parameters: 1742 * Parameters:
1693 * Parameters: 1753 * Parameters:
1694 * handle: Handle to the MLE to be cleared. 1754 * handle: Handle to the MLE to be cleared.
1695 */ 1755 */
1696 void API dw_mle_clear(HWND handle) 1756 void API dw_mle_clear(HWND handle)
1697 { 1757 {
1758 JNIEnv *env;
1759
1760 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1761 {
1762 // First get the class that contains the method you need to call
1763 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1764 // Get the method that you want to call
1765 jmethodID mleClear = env->GetMethodID(clazz, "mleClear",
1766 "(Landroid/widget/EditText;)V");
1767 // Call the method on the object
1768 env->CallVoidMethod(_dw_obj, mleClear, handle);
1769 }
1698 } 1770 }
1699 1771
1700 /* 1772 /*
1701 * Sets the visible line of an MLE box. 1773 * Sets the visible line of an MLE box.
1702 * Parameters: 1774 * Parameters:
1713 * handle: Handle to the MLE. 1785 * handle: Handle to the MLE.
1714 * state: TRUE if it can be edited, FALSE for readonly. 1786 * state: TRUE if it can be edited, FALSE for readonly.
1715 */ 1787 */
1716 void API dw_mle_set_editable(HWND handle, int state) 1788 void API dw_mle_set_editable(HWND handle, int state)
1717 { 1789 {
1790 JNIEnv *env;
1791
1792 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1793 {
1794 // First get the class that contains the method you need to call
1795 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1796 // Get the method that you want to call
1797 jmethodID mleSetEditable = env->GetMethodID(clazz, "mleSetEditable",
1798 "(Landroid/widget/EditText;I)V");
1799 // Call the method on the object
1800 env->CallVoidMethod(_dw_obj, mleSetEditable, handle, state);
1801 }
1718 } 1802 }
1719 1803
1720 /* 1804 /*
1721 * Sets the word wrap state of an MLE box. 1805 * Sets the word wrap state of an MLE box.
1722 * Parameters: 1806 * Parameters:
1723 * handle: Handle to the MLE. 1807 * handle: Handle to the MLE.
1724 * state: TRUE if it wraps, FALSE if it doesn't. 1808 * state: TRUE if it wraps, FALSE if it doesn't.
1725 */ 1809 */
1726 void API dw_mle_set_word_wrap(HWND handle, int state) 1810 void API dw_mle_set_word_wrap(HWND handle, int state)
1727 { 1811 {
1812 JNIEnv *env;
1813
1814 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1815 {
1816 // First get the class that contains the method you need to call
1817 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1818 // Get the method that you want to call
1819 jmethodID mleSetWordWrap = env->GetMethodID(clazz, "mleSetWordWrap",
1820 "(Landroid/widget/EditText;I)V");
1821 // Call the method on the object
1822 env->CallVoidMethod(_dw_obj, mleSetWordWrap, handle, state);
1823 }
1728 } 1824 }
1729 1825
1730 /* 1826 /*
1731 * Sets the current cursor position of an MLE box. 1827 * Sets the current cursor position of an MLE box.
1732 * Parameters: 1828 * Parameters:
1733 * handle: Handle to the MLE to be positioned. 1829 * handle: Handle to the MLE to be positioned.
1734 * point: Point to position cursor. 1830 * point: Point to position cursor.
1735 */ 1831 */
1736 void API dw_mle_set_cursor(HWND handle, int point) 1832 void API dw_mle_set_cursor(HWND handle, int point)
1737 { 1833 {
1834 JNIEnv *env;
1835
1836 if((env = (JNIEnv *)pthread_getspecific(_dw_env_key)))
1837 {
1838 // First get the class that contains the method you need to call
1839 jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
1840 // Get the method that you want to call
1841 jmethodID mleSetWordWrap = env->GetMethodID(clazz, "mleSetWordWrap",
1842 "(Landroid/widget/EditText;I)V");
1843 // Call the method on the object
1844 env->CallVoidMethod(_dw_obj, mleSetWordWrap, handle, point);
1845 }
1738 } 1846 }
1739 1847
1740 /* 1848 /*
1741 * Sets the word auto complete state of an MLE box. 1849 * Sets the word auto complete state of an MLE box.
1742 * Parameters: 1850 * Parameters: