changeset 2542:bb75e64e6138

Android: Implement dw_screen_* and dw_environment_query(). Minor code cleanup in dwtest and ios.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 13 May 2021 07:43:31 +0000
parents 2ee4df2c50bf
children f9367eb9a6e7
files android/DWindows.kt android/dw.cpp dwtest.c ios/dw.m
diffstat 4 files changed, 94 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/android/DWindows.kt	Wed May 12 23:28:59 2021 +0000
+++ b/android/DWindows.kt	Thu May 13 07:43:31 2021 +0000
@@ -1819,6 +1819,12 @@
         return dimensions
     }
 
+    fun screenGetDimensions(): Long
+    {
+        val dm = resources.displayMetrics
+        return dm.widthPixels.toLong() or (dm.heightPixels.toLong() shl 32)
+    }
+
     fun renderNew(cid: Int): DWRender?
     {
         var render: DWRender? = null
@@ -2254,7 +2260,7 @@
         }
     }
 
-    fun dwInit(appid: String, appname: String)
+    fun dwInit(appid: String, appname: String): Int
     {
         waitOnUiThread {
             // Create the notification channel in dw_init()
@@ -2269,6 +2275,12 @@
                 notificationManager.createNotificationChannel(mChannel)
             }
         }
+        return Build.VERSION.SDK_INT
+    }
+
+    fun androidGetRelease(): String
+    {
+        return Build.VERSION.RELEASE
     }
 
     fun notificationNew(title: String, imagepath: String, text: String, appid: String): NotificationCompat.Builder?
--- a/android/dw.cpp	Wed May 12 23:28:59 2021 +0000
+++ b/android/dw.cpp	Thu May 13 07:43:31 2021 +0000
@@ -38,9 +38,11 @@
 
 #define DW_CLASS_NAME "org/dbsoft/dwindows/DWindows"
 
+/* Dynamic Windows internal variables */
 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
 static char _dw_app_name[_DW_APP_ID_SIZE+1]= {0};
 static char _dw_exec_dir[MAX_PATH+1] = {0};
+static int _dw_android_api = 0;
 
 static pthread_key_t _dw_env_key;
 static HEV _dw_main_event;
@@ -3413,7 +3415,7 @@
         jlong dimensions = env->CallLongMethod(_dw_obj, pixmapGetDimensions, pixmap->bitmap);
 
         pixmap->width = dimensions & 0xFFFF;
-        pixmap->height = dimensions >> 32;
+        pixmap->height = (dimensions >> 32) & 0xFFFF;
     }
 }
 
@@ -4730,12 +4732,29 @@
 {
 }
 
+static jlong _dw_screen_dimensions = 0;
+
 /*
  * Returns the width of the screen.
  */
 int API dw_screen_width(void)
 {
-    return 0;
+    if(!_dw_screen_dimensions)
+    {
+        JNIEnv *env;
+
+        if((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 screenGetDimensions = env->GetMethodID(clazz, "screenGetDimensions",
+                                                             "()J");
+            // Call the method on the object
+            _dw_screen_dimensions = env->CallLongMethod(_dw_obj, screenGetDimensions);
+        }
+    }
+    return _dw_screen_dimensions & 0xFFFF;
 }
 
 /*
@@ -4743,7 +4762,22 @@
  */
 int API dw_screen_height(void)
 {
-    return 0;
+    if(!_dw_screen_dimensions)
+    {
+        JNIEnv *env;
+
+        if((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 screenGetDimensions = env->GetMethodID(clazz, "screenGetDimensions",
+                                                             "()J");
+            // Call the method on the object
+            _dw_screen_dimensions = env->CallLongMethod(_dw_obj, screenGetDimensions);
+        }
+    }
+    return (_dw_screen_dimensions >> 32) & 0xFFFF;
 }
 
 /* This should return the current color depth. */
@@ -4759,18 +4793,44 @@
  */
 void API dw_environment_query(DWEnv *env)
 {
-    strcpy(env->osName, "Android");
-
-    strcpy(env->buildDate, __DATE__);
-    strcpy(env->buildTime, __TIME__);
+    static char osName[_DW_ENV_STRING_SIZE+1] = { 0 };
+
+    if(!osName[0])
+    {
+        JNIEnv *env;
+        const char *release = nullptr;
+
+        if((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);
+            jclass clazz = env->FindClass(DW_CLASS_NAME);
+            // Get the method that you want to call
+            jmethodID androidGetRelease = env->GetMethodID(clazz, "androidGetRelease",
+                                                           "()Ljava/lang/String;");
+            // Call the method on the object
+            jstring jstr = (jstring)env->CallObjectMethod(_dw_obj, androidGetRelease);
+
+            if(jstr)
+                release = env->GetStringUTFChars(jstr, 0);
+        }
+        snprintf(osName, _DW_ENV_STRING_SIZE-1, "Android%s%s",
+                 release ? " " : "", release ? release : "");
+    }
+    memset(env, '\0', sizeof(DWEnv));
+
+    strncpy(env->osName, osName, sizeof(env->osName)-1);
+    strncpy(env->buildDate, __DATE__, sizeof(env->buildDate)-1);
+    strncpy(env->buildTime, __TIME__, sizeof(env->buildTime)-1);
+    strncpy(env->htmlEngine, "CHROME", sizeof(env->htmlEngine)-1);
     env->DWMajorVersion = DW_MAJOR_VERSION;
     env->DWMinorVersion = DW_MINOR_VERSION;
     env->DWSubVersion = DW_SUB_VERSION;
 
-    env->MajorVersion = 0; /* Operating system major */
-    env->MinorVersion = 0; /* Operating system minor */
-    env->MajorBuild = 0; /* Build versions... if available */
-    env->MinorBuild = 0;
+    /* Operating system major */
+    env->MajorVersion = _dw_android_api;
+    /* Operating system minor */
+    env->MinorVersion = 0;
 }
 
 /*
@@ -5948,9 +6008,9 @@
         jclass clazz = _dw_find_class(env, DW_CLASS_NAME);
         // Get the method that you want to call
         jmethodID dwInit = env->GetMethodID(clazz, "dwInit",
-                                            "(Ljava/lang/String;Ljava/lang/String;)V");
+                                            "(Ljava/lang/String;Ljava/lang/String;)I");
         // Call the method on the object
-        env->CallVoidMethod(_dw_obj, dwInit, appid, appname);
+        _dw_android_api = env->CallIntMethod(_dw_obj, dwInit, appid, appname);
     }
     return DW_ERROR_NONE;
 }
--- a/dwtest.c	Wed May 12 23:28:59 2021 +0000
+++ b/dwtest.c	Thu May 13 07:43:31 2021 +0000
@@ -583,11 +583,12 @@
     DWEnv env;
 
     dw_environment_query(&env);
-    dw_messagebox("About dwindows", DW_MB_OK | DW_MB_INFORMATION, "dwindows test\n\nOS: %s %s %s Version: %d.%d.%d.%d HTML: %s\n\ndwindows Version: %d.%d.%d",
+    dw_messagebox("About dwindows", DW_MB_OK | DW_MB_INFORMATION, "dwindows test\n\nOS: %s %s %s Version: %d.%d.%d.%d\n\nHTML: %s\n\ndwindows Version: %d.%d.%d\n\nScreen: %dx%d %dbpp",
                    env.osName, env.buildDate, env.buildTime,
                    env.MajorVersion, env.MinorVersion, env.MajorBuild, env.MinorBuild,
                    env.htmlEngine,
-                   env.DWMajorVersion, env.DWMinorVersion, env.DWSubVersion);
+                   env.DWMajorVersion, env.DWMinorVersion, env.DWSubVersion,
+                   dw_screen_width(), dw_screen_height(), dw_color_depth_get());
     return 0;
 }
 
@@ -1154,7 +1155,7 @@
         hscrollbarheight = 8;
 
     /* create render box for number pixmap */
-    textbox1 = dw_render_new( 100 );
+    textbox1 = dw_render_new(100);
     dw_window_set_font(textbox1, FIXEDFONT);
     dw_font_text_extents_get(textbox1, NULL, "(g", &font_width, &font_height);
     font_width = font_width / 2;
@@ -1171,7 +1172,7 @@
     dw_box_pack_start(pagebox, textboxA, 0, 0, TRUE, TRUE, 0);
 
     /* create render box for filecontents pixmap */
-    textbox2 = dw_render_new( 101 );
+    textbox2 = dw_render_new(101);
     dw_box_pack_start(textboxA, textbox2, 10, 10, TRUE, TRUE, 0);
     dw_window_set_font(textbox2, FIXEDFONT);
     /* create horizonal scrollbar */
--- a/ios/dw.m	Wed May 12 23:28:59 2021 +0000
+++ b/ios/dw.m	Thu May 13 07:43:31 2021 +0000
@@ -8942,7 +8942,7 @@
 {
     NSObject *object = handle;
 
-    if([ object isKindOfClass:[ UIWindow class ] ])
+    if([object isKindOfClass:[UIWindow class]])
     {
         UIWindow *window = handle;
         CGRect rect = [window frame];
@@ -8956,7 +8956,7 @@
             *height = rect.size.height;
         return;
     }
-    else if([ object isKindOfClass:[ UIControl class ] ])
+    else if([object isKindOfClass:[UIControl class]])
     {
         UIControl *control = handle;
         CGRect rect = [control frame];
@@ -9098,7 +9098,7 @@
 
     strncpy(env->buildDate, __DATE__, sizeof(env->buildDate)-1);
     strncpy(env->buildTime, __TIME__, sizeof(env->buildTime)-1);
-   strncpy(env->htmlEngine, "WEBKIT", sizeof(env->htmlEngine)-1);
+    strncpy(env->htmlEngine, "WEBKIT", sizeof(env->htmlEngine)-1);
     env->DWMajorVersion = DW_MAJOR_VERSION;
     env->DWMinorVersion = DW_MINOR_VERSION;
 #ifdef VER_REV