diff android/dw.cpp @ 2686:95f61d3f3d0d

Android: Initial attempt at implmenting dw_window_get_preferred_size(). This function missing was causing layout issues in code using this function. The SeekBar (slider/scrollbar/etc) code seems to be backwards but it works this way.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 27 Oct 2021 22:00:31 +0000
parents a7868380098f
children 42ff9d95e87b
line wrap: on
line diff
--- a/android/dw.cpp	Tue Oct 26 06:17:53 2021 +0000
+++ b/android/dw.cpp	Wed Oct 27 22:00:31 2021 +0000
@@ -5793,6 +5793,34 @@
  */
 void API dw_window_get_preferred_size(HWND handle, int *width, int *height)
 {
+    if(width || height)
+    {
+        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 windowGetPreferredSize = env->GetMethodID(clazz, "windowGetPreferredSize",
+                                                                "(Landroid/view/View;)J");
+            // Call the method on the object
+            jlong dimensions = env->CallLongMethod(_dw_obj, windowGetPreferredSize, handle);
+            if(_dw_jni_check_exception(env))
+                dimensions = 0;
+            if(width)
+                *width = (int)((dimensions >> 32) & 0xFFFF);
+            if(height)
+                *height = (int)(dimensions & 0xFFFF);
+        }
+        else
+        {
+            if(width)
+                *width = 0;
+            if(height)
+                *height = 0;
+        }
+    }
 }
 
 /*