changeset 2706:4e9eba7f7226

Android: Implement dw_scrollbox_get_range() and dw_scrollbox_get_pos().
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 19 Nov 2021 02:20:11 +0000
parents ddcbed595a84
children a3f6ca621453
files android/DWindows.kt android/dw.cpp
diffstat 2 files changed, 61 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Thu Nov 18 12:04:40 2021 +0000
+++ b/android/DWindows.kt	Fri Nov 19 02:20:11 2021 +0000
@@ -1693,7 +1693,7 @@
         return box
     }
 
-    fun scrollBoxNew(type: Int, pad: Int) : ScrollView? {
+    fun scrollBoxNew(type: Int, pad: Int): ScrollView? {
         var scrollBox: ScrollView? = null
 
         waitOnUiThread {
@@ -1720,6 +1720,34 @@
         return scrollBox
     }
 
+    fun scrollBoxGetPos(scrollBox: ScrollView, orient: Int): Int {
+        var retval: Int = -1
+
+        waitOnUiThread {
+            // DW_VERT 1
+            if(orient == 1) {
+                retval = scrollBox.scrollY
+            } else {
+                retval = scrollBox.scrollX
+            }
+        }
+        return retval
+    }
+
+    fun scrollBoxGetRange(scrollBox: ScrollView, orient: Int): Int {
+        var retval: Int = -1
+
+        waitOnUiThread {
+            // DW_VERT 1
+            if(orient == 1) {
+                retval = scrollBox.getChildAt(0).height
+            } else {
+                retval = scrollBox.getChildAt(0).width
+            }
+        }
+        return retval
+    }
+
     // Update the layoutParams of a box after a change
     private fun boxUpdate(box: LinearLayout)
     {
--- a/android/dw.cpp	Thu Nov 18 12:04:40 2021 +0000
+++ b/android/dw.cpp	Fri Nov 19 02:20:11 2021 +0000
@@ -1424,7 +1424,22 @@
  */
 int API dw_scrollbox_get_pos(HWND handle, int orient)
 {
-    return 0;
+    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 scrollBoxGetPos = env->GetMethodID(clazz, "scrollBoxGetPos",
+                                                     "(Landroid/widget/ScrollView;I)I");
+        // Call the method on the object
+        retval = env->CallIntMethod(_dw_obj, scrollBoxGetPos, handle, orient);
+        if(_dw_jni_check_exception(env))
+            retval = DW_ERROR_UNKNOWN;
+    }
+    return retval;
 }
 
 /*
@@ -1437,7 +1452,22 @@
  */
 int API dw_scrollbox_get_range(HWND handle, int orient)
 {
-    return 0;
+    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 scrollBoxGetRange = env->GetMethodID(clazz, "scrollBoxGetRange",
+                                                       "(Landroid/widget/ScrollView;I)I");
+        // Call the method on the object
+        retval = env->CallIntMethod(_dw_obj, scrollBoxGetRange, handle, orient);
+        if(_dw_jni_check_exception(env))
+            retval = DW_ERROR_UNKNOWN;
+    }
+    return retval;
 }
 
 /* Internal box packing function called by the other 3 functions */