diff ios/dw.m @ 2850:2934b2fdcd8e

Mac/iOS: Add return value to dw_window_set_bitmap(_from_data) in resource refactoring. They now return DW_ERROR_NONE on success, DW_ERROR_UNKNOWN on invalid parameters and DW_ERROR_GENERAL when failing to load the bitmap. This change came when I discovered Xcode UI does not allow subfolders in the copied resources. dwtest has been modified to function in either way... from a compiled app bundle or from the build directory. The API change should not affect apps, but may require changes to other language bindings. Follow ups for the other platforms will be coming shortly.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Mon, 14 Nov 2022 20:38:19 +0000
parents 1df137a1a4b9
children 86286f528adf
line wrap: on
line diff
--- a/ios/dw.m	Sun Nov 13 19:54:17 2022 +0000
+++ b/ios/dw.m	Mon Nov 14 20:38:19 2022 +0000
@@ -10014,10 +10014,15 @@
  *       filename: a path to a file (Bitmap on OS/2 or
  *                 Windows and a pixmap on Unix, pass
  *                 NULL if you use the id param)
- */
-void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, const char *data, int len)
+ * Returns:
+ *        DW_ERROR_NONE on success.
+ *        DW_ERROR_UNKNOWN if the parameters were invalid.
+ *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
+ */
+int API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, const char *data, int len)
 {
     id object = handle;
+    int retval = DW_ERROR_UNKNOWN;
 
     if([object isKindOfClass:[UIImageView class]] || [object isMemberOfClass:[DWButton class]])
     {
@@ -10039,22 +10044,26 @@
                     UIImageView *iv = object;
                     [iv setImage:pixmap];
                 }
-            }
-            /* If we changed the bitmap... */
-            Item *item = _dw_box_item(handle);
-
-            /* Check to see if any of the sizes need to be recalculated */
-            if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO))
-            {
-                _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL);
-                /* Queue a redraw on the top-level window */
-                _dw_redraw([object window], TRUE);
-            }
+                /* If we changed the bitmap... */
+                Item *item = _dw_box_item(handle);
+
+                /* Check to see if any of the sizes need to be recalculated */
+                if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO))
+                {
+                    _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL);
+                    /* Queue a redraw on the top-level window */
+                    _dw_redraw([object window], TRUE);
+                }
+                retval = DW_ERROR_NONE;
+            }
+            else
+                retval = DW_ERROR_GENERAL;
             DW_LOCAL_POOL_OUT;
         }
         else
-            dw_window_set_bitmap(handle, cid, NULL);
-    }
+            return dw_window_set_bitmap(handle, cid, NULL);
+    }
+    return retval;
 }
 
 /*
@@ -10066,10 +10075,15 @@
  *       filename: a path to a file (Bitmap on OS/2 or
  *                 Windows and a pixmap on Unix, pass
  *                 NULL if you use the id param)
- */
-void API dw_window_set_bitmap(HWND handle, unsigned long resid, const char *filename)
+ * Returns:
+ *        DW_ERROR_NONE on success.
+ *        DW_ERROR_UNKNOWN if the parameters were invalid.
+ *        DW_ERROR_GENERAL if the bitmap was unable to be loaded.
+ */
+int API dw_window_set_bitmap(HWND handle, unsigned long resid, const char *filename)
 {
     id object = handle;
+    int retval = DW_ERROR_UNKNOWN;
     DW_LOCAL_POOL_IN;
 
     if([object isKindOfClass:[UIImageView class]] || [object isMemberOfClass:[DWButton class]])
@@ -10088,10 +10102,14 @@
                 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
                 bitmap = [[UIImage alloc] initWithContentsOfFile:nstr];
             }
+            if(!bitmap)
+                retval = DW_ERROR_GENERAL;
         }
         if(!bitmap && resid > 0 && resid < 65536)
         {
             bitmap = _dw_icon_load(resid);
+            if(!bitmap)
+                retval = DW_ERROR_GENERAL;
         }
 
         if(bitmap)
@@ -10117,9 +10135,11 @@
                 /* Queue a redraw on the top-level window */
                 _dw_redraw([object window], TRUE);
             }
+            retval = DW_ERROR_NONE;
         }
     }
     DW_LOCAL_POOL_OUT;
+    return retval;
 }
 
 /*