Mercurial > dwindows
comparison android/dw.cpp @ 2517:d746323f2841
Android: Implement most of the dw_listbox_*() functions for ComboBoxes.
Eliminate some kotlin code warnings.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 08 May 2021 08:11:51 +0000 |
parents | 211044d98e86 |
children | c4e90a623437 |
comparison
equal
deleted
inserted
replaced
2516:8f5d064b7054 | 2517:d746323f2841 |
---|---|
421 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; | 421 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; |
422 | 422 |
423 _dw_event_handler(obj1, params, message); | 423 _dw_event_handler(obj1, params, message); |
424 } | 424 } |
425 | 425 |
426 JNIEXPORT void JNICALL | |
427 Java_org_dbsoft_dwindows_DWComboBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message, | |
428 jint inta, jint intb, jint intc, jint intd) { | |
429 void *params[8] = { NULL, NULL, NULL, | |
430 DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), | |
431 DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; | |
432 | |
433 _dw_event_handler(obj, params, message); | |
434 } | |
435 | |
426 /* Handler for Timer events */ | 436 /* Handler for Timer events */ |
427 JNIEXPORT jint JNICALL | 437 JNIEXPORT jint JNICALL |
428 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { | 438 Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { |
429 int (*timerfunc)(void *) = (int (* API)(void *))sigfunc; | 439 int (*timerfunc)(void *) = (int (* API)(void *))sigfunc; |
430 | 440 |
1541 * text: Text to insert into listbox. | 1551 * text: Text to insert into listbox. |
1542 * pos: 0-based position to insert text | 1552 * pos: 0-based position to insert text |
1543 */ | 1553 */ |
1544 void API dw_listbox_insert(HWND handle, const char *text, int pos) | 1554 void API dw_listbox_insert(HWND handle, const char *text, int pos) |
1545 { | 1555 { |
1556 JNIEnv *env; | |
1557 | |
1558 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1559 { | |
1560 // Construct a String | |
1561 jstring jstr = env->NewStringUTF(text); | |
1562 // First get the class that contains the method you need to call | |
1563 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1564 // Get the method that you want to call | |
1565 jmethodID listOrComboBoxInsert = env->GetMethodID(clazz, "listOrComboBoxInsert", | |
1566 "(Landroid/view/View;Ljava/lang/String;I)V"); | |
1567 // Call the method on the object | |
1568 env->CallVoidMethod(_dw_obj, listOrComboBoxInsert, handle, jstr, pos); | |
1569 } | |
1546 } | 1570 } |
1547 | 1571 |
1548 /* | 1572 /* |
1549 * Appends the specified text items to the listbox's (or combobox) entry list. | 1573 * Appends the specified text items to the listbox's (or combobox) entry list. |
1550 * Parameters: | 1574 * Parameters: |
1552 * text: Text strings to append into listbox. | 1576 * text: Text strings to append into listbox. |
1553 * count: Number of text strings to append | 1577 * count: Number of text strings to append |
1554 */ | 1578 */ |
1555 void API dw_listbox_list_append(HWND handle, char **text, int count) | 1579 void API dw_listbox_list_append(HWND handle, char **text, int count) |
1556 { | 1580 { |
1581 int x; | |
1582 | |
1583 /* TODO: this would be more efficient passing in an array */ | |
1584 for(x=0;x<count;x++) | |
1585 dw_listbox_append(handle, text[x]); | |
1557 } | 1586 } |
1558 | 1587 |
1559 /* | 1588 /* |
1560 * Clears the listbox's (or combobox) list of all entries. | 1589 * Clears the listbox's (or combobox) list of all entries. |
1561 * Parameters: | 1590 * Parameters: |
1562 * handle: Handle to the listbox to be cleared. | 1591 * handle: Handle to the listbox to be cleared. |
1563 */ | 1592 */ |
1564 void API dw_listbox_clear(HWND handle) | 1593 void API dw_listbox_clear(HWND handle) |
1565 { | 1594 { |
1595 JNIEnv *env; | |
1596 | |
1597 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1598 { | |
1599 // First get the class that contains the method you need to call | |
1600 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1601 // Get the method that you want to call | |
1602 jmethodID listOrComboBoxClear = env->GetMethodID(clazz, "listOrComboBoxClear", | |
1603 "(Landroid/view/View;)V"); | |
1604 // Call the method on the object | |
1605 env->CallVoidMethod(_dw_obj, listOrComboBoxClear, handle); | |
1606 } | |
1566 } | 1607 } |
1567 | 1608 |
1568 /* | 1609 /* |
1569 * Returns the listbox's item count. | 1610 * Returns the listbox's item count. |
1570 * Parameters: | 1611 * Parameters: |
1572 * Returns: | 1613 * Returns: |
1573 * The number of items in the listbox. | 1614 * The number of items in the listbox. |
1574 */ | 1615 */ |
1575 int API dw_listbox_count(HWND handle) | 1616 int API dw_listbox_count(HWND handle) |
1576 { | 1617 { |
1577 return 0; | 1618 JNIEnv *env; |
1619 int retval = 0; | |
1620 | |
1621 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1622 { | |
1623 // First get the class that contains the method you need to call | |
1624 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1625 // Get the method that you want to call | |
1626 jmethodID listOrComboBoxCount = env->GetMethodID(clazz, "listOrComboBoxCount", | |
1627 "(Landroid/view/View;)I"); | |
1628 // Call the method on the object | |
1629 retval = env->CallIntMethod(_dw_obj, listOrComboBoxCount, handle); | |
1630 } | |
1631 return retval; | |
1578 } | 1632 } |
1579 | 1633 |
1580 /* | 1634 /* |
1581 * Sets the topmost item in the viewport. | 1635 * Sets the topmost item in the viewport. |
1582 * Parameters: | 1636 * Parameters: |
1595 * buffer: Buffer where text will be copied. | 1649 * buffer: Buffer where text will be copied. |
1596 * length: Length of the buffer (including NULL). | 1650 * length: Length of the buffer (including NULL). |
1597 */ | 1651 */ |
1598 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) | 1652 void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) |
1599 { | 1653 { |
1654 JNIEnv *env; | |
1655 | |
1656 if(buffer && length > 0 && handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1657 { | |
1658 // First get the class that contains the method you need to call | |
1659 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1660 // Get the method that you want to call | |
1661 jmethodID listOrComboBoxGetText = env->GetMethodID(clazz, "listOrComboBoxGetText", | |
1662 "(Landroid/view/View;)ILjava/lang/String;"); | |
1663 // Call the method on the object | |
1664 jstring result = (jstring)env->CallObjectMethod(_dw_obj, listOrComboBoxGetText, handle, index); | |
1665 // Get the UTF8 string result | |
1666 if(result) | |
1667 { | |
1668 const char *utf8 = env->GetStringUTFChars(result, 0); | |
1669 | |
1670 strncpy(buffer, utf8, length); | |
1671 } | |
1672 } | |
1600 } | 1673 } |
1601 | 1674 |
1602 /* | 1675 /* |
1603 * Sets the text of a given listbox entry. | 1676 * Sets the text of a given listbox entry. |
1604 * Parameters: | 1677 * Parameters: |
1606 * index: Index into the list to be queried. | 1679 * index: Index into the list to be queried. |
1607 * buffer: Buffer where text will be copied. | 1680 * buffer: Buffer where text will be copied. |
1608 */ | 1681 */ |
1609 void API dw_listbox_set_text(HWND handle, unsigned int index, const char *buffer) | 1682 void API dw_listbox_set_text(HWND handle, unsigned int index, const char *buffer) |
1610 { | 1683 { |
1684 JNIEnv *env; | |
1685 | |
1686 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1687 { | |
1688 // Construct a String | |
1689 jstring jstr = env->NewStringUTF(buffer); | |
1690 // First get the class that contains the method you need to call | |
1691 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1692 // Get the method that you want to call | |
1693 jmethodID listOrComboBoxSetText = env->GetMethodID(clazz, "listOrComboBoxSetText", | |
1694 "(Landroid/view/View;ILjava/lang/String;)V"); | |
1695 // Call the method on the object | |
1696 env->CallVoidMethod(_dw_obj, listOrComboBoxSetText, handle, index, jstr); | |
1697 } | |
1611 } | 1698 } |
1612 | 1699 |
1613 /* | 1700 /* |
1614 * Returns the index to the item in the list currently selected. | 1701 * Returns the index to the item in the list currently selected. |
1615 * Parameters: | 1702 * Parameters: |
1617 * Returns: | 1704 * Returns: |
1618 * The selected item index or DW_ERROR_UNKNOWN (-1) on error. | 1705 * The selected item index or DW_ERROR_UNKNOWN (-1) on error. |
1619 */ | 1706 */ |
1620 int API dw_listbox_selected(HWND handle) | 1707 int API dw_listbox_selected(HWND handle) |
1621 { | 1708 { |
1622 return DW_ERROR_UNKNOWN; | 1709 JNIEnv *env; |
1710 int retval = DW_ERROR_UNKNOWN; | |
1711 | |
1712 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1713 { | |
1714 // First get the class that contains the method you need to call | |
1715 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1716 // Get the method that you want to call | |
1717 jmethodID listOrComboBoxGetSelected = env->GetMethodID(clazz, "listOrComboBoxGetSelected", | |
1718 "(Landroid/view/View;)I"); | |
1719 // Call the method on the object | |
1720 retval = env->CallIntMethod(_dw_obj, listOrComboBoxGetSelected, handle); | |
1721 } | |
1722 return retval; | |
1623 } | 1723 } |
1624 | 1724 |
1625 /* | 1725 /* |
1626 * Returns the index to the current selected item or -1 when done. | 1726 * Returns the index to the current selected item or -1 when done. |
1627 * Parameters: | 1727 * Parameters: |
1642 * index: Item index. | 1742 * index: Item index. |
1643 * state: TRUE if selected FALSE if unselected. | 1743 * state: TRUE if selected FALSE if unselected. |
1644 */ | 1744 */ |
1645 void API dw_listbox_select(HWND handle, int index, int state) | 1745 void API dw_listbox_select(HWND handle, int index, int state) |
1646 { | 1746 { |
1747 JNIEnv *env; | |
1748 | |
1749 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1750 { | |
1751 // First get the class that contains the method you need to call | |
1752 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1753 // Get the method that you want to call | |
1754 jmethodID listOrComboBoxSelect = env->GetMethodID(clazz, "listOrComboBoxSelect", | |
1755 "(Landroid/view/View;II)V"); | |
1756 // Call the method on the object | |
1757 env->CallVoidMethod(_dw_obj, listOrComboBoxSelect, handle, index, state); | |
1758 } | |
1647 } | 1759 } |
1648 | 1760 |
1649 /* | 1761 /* |
1650 * Deletes the item with given index from the list. | 1762 * Deletes the item with given index from the list. |
1651 * Parameters: | 1763 * Parameters: |
1652 * handle: Handle to the listbox to be set. | 1764 * handle: Handle to the listbox to be set. |
1653 * index: Item index. | 1765 * index: Item index. |
1654 */ | 1766 */ |
1655 void API dw_listbox_delete(HWND handle, int index) | 1767 void API dw_listbox_delete(HWND handle, int index) |
1656 { | 1768 { |
1769 JNIEnv *env; | |
1770 | |
1771 if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) | |
1772 { | |
1773 // First get the class that contains the method you need to call | |
1774 jclass clazz = _dw_find_class(env, DW_CLASS_NAME); | |
1775 // Get the method that you want to call | |
1776 jmethodID listOrComboBoxDelete = env->GetMethodID(clazz, "listOrComboBoxDelete", | |
1777 "(Landroid/view/View;I)V"); | |
1778 // Call the method on the object | |
1779 env->CallVoidMethod(_dw_obj, listOrComboBoxDelete, handle, index); | |
1780 } | |
1657 } | 1781 } |
1658 | 1782 |
1659 /* | 1783 /* |
1660 * Create a new Combobox window (widget) to be packed. | 1784 * Create a new Combobox window (widget) to be packed. |
1661 * Parameters: | 1785 * Parameters: |