# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1620461511 0 # Node ID d746323f2841b471b9af65c3759d88359519d760 # Parent 8f5d064b70546a75add4e86a4d7e795885359166 Android: Implement most of the dw_listbox_*() functions for ComboBoxes. Eliminate some kotlin code warnings. diff -r 8f5d064b7054 -r d746323f2841 android/DWindows.kt --- a/android/DWindows.kt Sat May 08 01:54:52 2021 +0000 +++ b/android/DWindows.kt Sat May 08 08:11:51 2021 +0000 @@ -87,6 +87,7 @@ class DWComboBox(context: Context) : AppCompatEditText(context), OnTouchListener, OnItemClickListener { var lpw: ListPopupWindow? = null var list = mutableListOf() + var selected: Int = -1 init { setCompoundDrawablesWithIntrinsicBounds(0, 0, android.R.drawable.arrow_down_float, 0); @@ -105,8 +106,10 @@ override fun onItemClick(parent: AdapterView<*>?, view: View, position: Int, id: Long) { val item = list[position] + selected = position setText(item) lpw!!.dismiss() + eventHandlerInt(11, position, 0, 0, 0) } override fun onTouch(v: View, event: MotionEvent): Boolean { @@ -121,6 +124,14 @@ } return false } + + external fun eventHandlerInt( + message: Int, + inta: Int, + intb: Int, + intc: Int, + intd: Int + ) } class DWindows : AppCompatActivity() { @@ -366,7 +377,7 @@ // Handle scrollboxes by pulling the LinearLayout // out of the ScrollView to pack into if (boxview is LinearLayout) { - box = boxview as LinearLayout + box = boxview } else if (boxview is ScrollView) { var sv: ScrollView = boxview @@ -615,9 +626,9 @@ { waitOnUiThread { if (state != 0) { - mle!!.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) + mle.inputType = (InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_FLAG_MULTI_LINE) } else { - mle!!.inputType = InputType.TYPE_NULL + mle.inputType = InputType.TYPE_NULL } } } @@ -1031,6 +1042,7 @@ combobox = DWComboBox(this) combobox!!.tag = dataArrayMap combobox!!.id = cid + combobox!!.setText(text) } return combobox } @@ -1039,13 +1051,117 @@ { waitOnUiThread { if(window is DWComboBox) { - val combobox = window as DWComboBox + val combobox = window combobox.list.add(text) } } } + fun listOrComboBoxInsert(window: View, text: String, pos: Int) + { + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + combobox.list.add(pos, text) + } + } + } + + fun listOrComboBoxClear(window: View) + { + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + combobox.list.clear() + } + } + } + + fun listOrComboBoxCount(window: View): Int + { + var retval: Int = 0 + + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + retval = combobox.list.count() + } + } + return retval + } + + fun listOrComboBoxSetText(window: View, index: Int, text: String) + { + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + if(index < combobox.list.count()) + combobox.list[index] = text + } + } + } + + fun listOrComboBoxGetText(window: View, index: Int): String? + { + var retval: String? = null + + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + if(index < combobox.list.count()) + retval = combobox.list[index] + } + } + return retval + } + + fun listOrComboBoxGetSelected(window: View): Int + { + var retval: Int = -1 + + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + retval = combobox.selected + } + } + return retval + } + + fun listOrComboBoxSelect(window: View, index: Int, state: Int) + { + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + if(index < combobox.list.count() && state != 0) { + combobox.selected = index + combobox.setText(combobox.list[index]) + } + } + } + } + + fun listOrComboBoxDelete(window: View, index: Int) + { + waitOnUiThread { + if(window is DWComboBox) { + val combobox = window + + if(index < combobox.list.count()) { + combobox.list.removeAt(index) + } + } + } + } + fun timerConnect(interval: Long, sigfunc: Long, data: Long): Timer { // creating timer task, timer diff -r 8f5d064b7054 -r d746323f2841 android/dw.cpp --- a/android/dw.cpp Sat May 08 01:54:52 2021 +0000 +++ b/android/dw.cpp Sat May 08 08:11:51 2021 +0000 @@ -423,6 +423,16 @@ _dw_event_handler(obj1, params, message); } +JNIEXPORT void JNICALL +Java_org_dbsoft_dwindows_DWComboBox_eventHandlerInt(JNIEnv* env, jobject obj, jint message, + jint inta, jint intb, jint intc, jint intd) { + void *params[8] = { NULL, NULL, NULL, + DW_INT_TO_POINTER(inta), DW_INT_TO_POINTER(intb), + DW_INT_TO_POINTER(intc), DW_INT_TO_POINTER(intd), NULL }; + + _dw_event_handler(obj, params, message); +} + /* Handler for Timer events */ JNIEXPORT jint JNICALL Java_org_dbsoft_dwindows_DWindows_eventHandlerTimer(JNIEnv* env, jobject obj, jlong sigfunc, jlong data) { @@ -1543,6 +1553,20 @@ */ void API dw_listbox_insert(HWND handle, const char *text, int pos) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // Construct a String + jstring jstr = env->NewStringUTF(text); + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxInsert = env->GetMethodID(clazz, "listOrComboBoxInsert", + "(Landroid/view/View;Ljava/lang/String;I)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, listOrComboBoxInsert, handle, jstr, pos); + } } /* @@ -1554,6 +1578,11 @@ */ void API dw_listbox_list_append(HWND handle, char **text, int count) { + int x; + + /* TODO: this would be more efficient passing in an array */ + for(x=0;xGetMethodID(clazz, "listOrComboBoxClear", + "(Landroid/view/View;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, listOrComboBoxClear, handle); + } } /* @@ -1574,7 +1615,20 @@ */ int API dw_listbox_count(HWND handle) { - return 0; + JNIEnv *env; + int retval = 0; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxCount = env->GetMethodID(clazz, "listOrComboBoxCount", + "(Landroid/view/View;)I"); + // Call the method on the object + retval = env->CallIntMethod(_dw_obj, listOrComboBoxCount, handle); + } + return retval; } /* @@ -1597,6 +1651,25 @@ */ void API dw_listbox_get_text(HWND handle, unsigned int index, char *buffer, unsigned int length) { + JNIEnv *env; + + if(buffer && length > 0 && handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxGetText = env->GetMethodID(clazz, "listOrComboBoxGetText", + "(Landroid/view/View;)ILjava/lang/String;"); + // Call the method on the object + jstring result = (jstring)env->CallObjectMethod(_dw_obj, listOrComboBoxGetText, handle, index); + // Get the UTF8 string result + if(result) + { + const char *utf8 = env->GetStringUTFChars(result, 0); + + strncpy(buffer, utf8, length); + } + } } /* @@ -1608,6 +1681,20 @@ */ void API dw_listbox_set_text(HWND handle, unsigned int index, const char *buffer) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // Construct a String + jstring jstr = env->NewStringUTF(buffer); + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxSetText = env->GetMethodID(clazz, "listOrComboBoxSetText", + "(Landroid/view/View;ILjava/lang/String;)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, listOrComboBoxSetText, handle, index, jstr); + } } /* @@ -1619,7 +1706,20 @@ */ int API dw_listbox_selected(HWND handle) { - return DW_ERROR_UNKNOWN; + JNIEnv *env; + int retval = DW_ERROR_UNKNOWN; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxGetSelected = env->GetMethodID(clazz, "listOrComboBoxGetSelected", + "(Landroid/view/View;)I"); + // Call the method on the object + retval = env->CallIntMethod(_dw_obj, listOrComboBoxGetSelected, handle); + } + return retval; } /* @@ -1644,6 +1744,18 @@ */ void API dw_listbox_select(HWND handle, int index, int state) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxSelect = env->GetMethodID(clazz, "listOrComboBoxSelect", + "(Landroid/view/View;II)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, listOrComboBoxSelect, handle, index, state); + } } /* @@ -1654,6 +1766,18 @@ */ void API dw_listbox_delete(HWND handle, int index) { + JNIEnv *env; + + if(handle && (env = (JNIEnv *)pthread_getspecific(_dw_env_key))) + { + // First get the class that contains the method you need to call + jclass clazz = _dw_find_class(env, DW_CLASS_NAME); + // Get the method that you want to call + jmethodID listOrComboBoxDelete = env->GetMethodID(clazz, "listOrComboBoxDelete", + "(Landroid/view/View;I)V"); + // Call the method on the object + env->CallVoidMethod(_dw_obj, listOrComboBoxDelete, handle, index); + } } /*