changeset 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 de56f1d265b3
children fdd21139c07f
files dw.h dwtest.c ios/dw.m mac/dw.m mac/finishup.sh
diffstat 5 files changed, 122 insertions(+), 68 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Sun Nov 13 19:54:17 2022 +0000
+++ b/dw.h	Mon Nov 14 20:38:19 2022 +0000
@@ -2029,8 +2029,8 @@
 void API dw_window_set_gravity(HWND handle, int horz, int vert);
 void API dw_window_set_style(HWND handle, unsigned long style, unsigned long mask);
 void API dw_window_set_icon(HWND handle, HICN icon);
-void API dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename);
-void API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len);
+int API dw_window_set_bitmap(HWND handle, unsigned long id, const char *filename);
+int API dw_window_set_bitmap_from_data(HWND handle, unsigned long id, const char *data, int len);
 char * API dw_window_get_text(HWND handle);
 void API dw_window_set_text(HWND handle, const char *text);
 void API dw_window_set_tooltip(HWND handle, const char *bubbletext);
--- a/dwtest.c	Sun Nov 13 19:54:17 2022 +0000
+++ b/dwtest.c	Mon Nov 14 20:38:19 2022 +0000
@@ -20,34 +20,27 @@
 /* Select a fixed width font for our platform */
 #ifdef __OS2__
 #define FIXEDFONT "5.System VIO"
-#define FOLDER_ICON_NAME "os2\\folder"
-#define FILE_ICON_NAME "os2\\file"
+#define PLATFORMFOLDER "os2\\"
 #elif defined(__WIN32__)
 #define FIXEDFONT "10.Lucida Console"
-#define FOLDER_ICON_NAME "win\\folder"
-#define FILE_ICON_NAME "win\\file"
+#define PLATFORMFOLDER "win\\"
 #elif defined(__MAC__)
 #define FIXEDFONT "9.Monaco"
-#define FOLDER_ICON_NAME "mac/folder"
-#define FILE_ICON_NAME "mac/file"
+#define PLATFORMFOLDER "mac/"
 #elif defined(__IOS__)
 #define FIXEDFONT "9.Monaco"
-#define FOLDER_ICON_NAME "folder"
-#define FILE_ICON_NAME "file"
 #elif defined(__ANDROID__)
 #define FIXEDFONT "10.Monospace"
-#define FOLDER_ICON_NAME "folder"
-#define FILE_ICON_NAME "file"
 #elif GTK_MAJOR_VERSION > 1
 #define FIXEDFONT "10.monospace"
-#define FOLDER_ICON_NAME "gtk/folder"
-#define FILE_ICON_NAME "gtk/file"
+#define PLATFORMFOLDER "gtk/"
 #else
 #define FIXEDFONT "fixed"
-#define FOLDER_ICON_NAME "gtk/folder"
-#define FILE_ICON_NAME "gtk/file"
 #endif
 
+char fileiconpath[1025] = "file";
+char foldericonpath[1025] = "folder";
+
 #define MAX_WIDGETS 20
 
 unsigned long flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
@@ -698,15 +691,15 @@
 
     if(isfoldericon)
     {
-       isfoldericon = 0;
-       dw_window_set_bitmap(window, 0, FILE_ICON_NAME);
-       dw_window_set_tooltip(window, "File Icon");
+        isfoldericon = 0;
+        dw_window_set_bitmap(window, 0, fileiconpath);
+        dw_window_set_tooltip(window, "File Icon");
     }
     else
     {
-       isfoldericon = 1;
-       dw_window_set_bitmap_from_data(window, 0, folder_ico, sizeof(folder_ico));
-       dw_window_set_tooltip(window, "Folder Icon");
+        isfoldericon = 1;
+        dw_window_set_bitmap_from_data(window, 0, folder_ico, sizeof(folder_ico));
+        dw_window_set_tooltip(window, "Folder Icon");
     }
     return 0;
 }
@@ -1648,7 +1641,7 @@
     buttonboxperm = dw_box_new(DW_VERT, 0);
     dw_box_pack_start(buttonsbox, buttonboxperm, 25, 0, FALSE, TRUE, 2);
     dw_window_set_color(buttonboxperm, DW_CLR_WHITE, DW_CLR_WHITE);
-    abutton1 = dw_bitmapbutton_new_from_file("Top Button", 0, FILE_ICON_NAME);
+    abutton1 = dw_bitmapbutton_new_from_file("Top Button", 0, fileiconpath);
     dw_box_pack_start(buttonboxperm, abutton1, 100, 30, FALSE, FALSE, 0 );
     dw_signal_connect(abutton1, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(button_callback), NULL);
     dw_box_pack_start(buttonboxperm, 0, 25, 5, FALSE, FALSE, 0);
@@ -2224,9 +2217,27 @@
     notebookbox = dw_box_new(DW_VERT, 5);
     dw_box_pack_start(mainwindow, notebookbox, 0, 0, TRUE, TRUE, 0);
 
-    foldericon = dw_icon_load_from_file(FOLDER_ICON_NAME);
-    fileicon = dw_icon_load_from_file(FILE_ICON_NAME);
-    
+    /* First try the current directory */
+    foldericon = dw_icon_load_from_file(foldericonpath);
+    fileicon = dw_icon_load_from_file(fileiconpath);
+
+#ifdef PLATFORMFOLDER
+    /* In case we are running from the build directory...
+     * also check the appropriate platform subfolder
+     */
+    if(!foldericon)
+    {
+        strncpy(foldericonpath, PLATFORMFOLDER "folder", 1024);
+        foldericon = dw_icon_load_from_file(foldericonpath);
+    }
+    if(!fileicon)
+    {
+        strncpy(foldericonpath, PLATFORMFOLDER "file", 1024);
+        fileicon = dw_icon_load_from_file(fileiconpath);
+    }
+#endif
+
+    /* Finally try from the platform application directory */
     if(!foldericon && !fileicon)
     {
         char *appdir = dw_app_dir();
@@ -2236,10 +2247,14 @@
         strncpy(pathbuff, appdir, 1024);
         pathbuff[pos] = DW_DIR_SEPARATOR;
         pos++;
-        strncpy(&pathbuff[pos], FOLDER_ICON_NAME, 1024-pos);
+        strncpy(&pathbuff[pos], "folder", 1024-pos);
         foldericon = dw_icon_load_from_file(pathbuff);
-        strncpy(&pathbuff[pos], FILE_ICON_NAME, 1024-pos);
+        if(foldericon)
+            strncpy(foldericonpath, pathbuff, 1024);
+        strncpy(&pathbuff[pos], "file", 1024-pos);
         fileicon = dw_icon_load_from_file(pathbuff);
+        if(fileicon)
+            strncpy(fileiconpath, pathbuff, 1024);
     }
 
     notebook = dw_notebook_new(1, TRUE);
--- 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;
 }
 
 /*
--- a/mac/dw.m	Sun Nov 13 19:54:17 2022 +0000
+++ b/mac/dw.m	Mon Nov 14 20:38:19 2022 +0000
@@ -10830,12 +10830,17 @@
  *       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;
-
-    if([ object isKindOfClass:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]])
+    int retval = DW_ERROR_UNKNOWN;
+
+    if([object isKindOfClass:[NSImageView class]] || [object isKindOfClass:[NSButton class]])
     {
         if(data)
         {
@@ -10846,22 +10851,26 @@
             if(pixmap)
             {
                 [object 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;
 }
 
 /*
@@ -10873,13 +10882,18 @@
  *       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:[ NSImageView class ] ] || [ object isKindOfClass:[ NSButton class ]])
+    if([object isKindOfClass:[NSImageView class]] || [object isKindOfClass:[NSButton class]])
     {
         NSImage *bitmap = nil;
 
@@ -10895,10 +10909,14 @@
                 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
                 bitmap = [[[NSImage alloc] initWithContentsOfFile:nstr] autorelease];
             }
+            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)
@@ -10915,9 +10933,11 @@
                 /* Queue a redraw on the top-level window */
                 _dw_redraw([object window], TRUE);
             }
+            retval = DW_ERROR_NONE;
         }
     }
     DW_LOCAL_POOL_OUT;
+    return retval;
 }
 
 /*
--- a/mac/finishup.sh	Sun Nov 13 19:54:17 2022 +0000
+++ b/mac/finishup.sh	Mon Nov 14 20:38:19 2022 +0000
@@ -5,12 +5,11 @@
 then
     mkdir -p dwtest.app/Contents/MacOS
     mkdir -p dwtest.app/Contents/Resources
-    mkdir -p dwtest.app/Contents/Resources/mac
 
     cp -f $1/mac/Info.plist dwtest.app/Contents
     cp -f $1/mac/PkgInfo dwtest.app/Contents 
-    cp -f $1/mac/file.png dwtest.app/Contents/Resources/mac
-    cp -f $1/mac/folder.png dwtest.app/Contents/Resources/mac
+    cp -f $1/mac/file.png dwtest.app/Contents/Resources
+    cp -f $1/mac/folder.png dwtest.app/Contents/Resources
     cp -f $1/image/test.png dwtest.app/Contents/Resources
     cp -f dwtest dwtest.app/Contents/MacOS
     # Check if there is a certificate to sign with...