comparison 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
comparison
equal deleted inserted replaced
2849:de56f1d265b3 2850:2934b2fdcd8e
10012 * id: An ID to be used to specify the icon, 10012 * id: An ID to be used to specify the icon,
10013 * (pass 0 if you use the filename param) 10013 * (pass 0 if you use the filename param)
10014 * filename: a path to a file (Bitmap on OS/2 or 10014 * filename: a path to a file (Bitmap on OS/2 or
10015 * Windows and a pixmap on Unix, pass 10015 * Windows and a pixmap on Unix, pass
10016 * NULL if you use the id param) 10016 * NULL if you use the id param)
10017 */ 10017 * Returns:
10018 void API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, const char *data, int len) 10018 * DW_ERROR_NONE on success.
10019 * DW_ERROR_UNKNOWN if the parameters were invalid.
10020 * DW_ERROR_GENERAL if the bitmap was unable to be loaded.
10021 */
10022 int API dw_window_set_bitmap_from_data(HWND handle, unsigned long cid, const char *data, int len)
10019 { 10023 {
10020 id object = handle; 10024 id object = handle;
10025 int retval = DW_ERROR_UNKNOWN;
10021 10026
10022 if([object isKindOfClass:[UIImageView class]] || [object isMemberOfClass:[DWButton class]]) 10027 if([object isKindOfClass:[UIImageView class]] || [object isMemberOfClass:[DWButton class]])
10023 { 10028 {
10024 if(data) 10029 if(data)
10025 { 10030 {
10037 else 10042 else
10038 { 10043 {
10039 UIImageView *iv = object; 10044 UIImageView *iv = object;
10040 [iv setImage:pixmap]; 10045 [iv setImage:pixmap];
10041 } 10046 }
10047 /* If we changed the bitmap... */
10048 Item *item = _dw_box_item(handle);
10049
10050 /* Check to see if any of the sizes need to be recalculated */
10051 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO))
10052 {
10053 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL);
10054 /* Queue a redraw on the top-level window */
10055 _dw_redraw([object window], TRUE);
10056 }
10057 retval = DW_ERROR_NONE;
10042 } 10058 }
10043 /* If we changed the bitmap... */ 10059 else
10044 Item *item = _dw_box_item(handle); 10060 retval = DW_ERROR_GENERAL;
10045
10046 /* Check to see if any of the sizes need to be recalculated */
10047 if(item && (item->origwidth == DW_SIZE_AUTO || item->origheight == DW_SIZE_AUTO))
10048 {
10049 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL);
10050 /* Queue a redraw on the top-level window */
10051 _dw_redraw([object window], TRUE);
10052 }
10053 DW_LOCAL_POOL_OUT; 10061 DW_LOCAL_POOL_OUT;
10054 } 10062 }
10055 else 10063 else
10056 dw_window_set_bitmap(handle, cid, NULL); 10064 return dw_window_set_bitmap(handle, cid, NULL);
10057 } 10065 }
10066 return retval;
10058 } 10067 }
10059 10068
10060 /* 10069 /*
10061 * Sets the bitmap used for a given static window. 10070 * Sets the bitmap used for a given static window.
10062 * Parameters: 10071 * Parameters:
10064 * id: An ID to be used to specify the icon, 10073 * id: An ID to be used to specify the icon,
10065 * (pass 0 if you use the filename param) 10074 * (pass 0 if you use the filename param)
10066 * filename: a path to a file (Bitmap on OS/2 or 10075 * filename: a path to a file (Bitmap on OS/2 or
10067 * Windows and a pixmap on Unix, pass 10076 * Windows and a pixmap on Unix, pass
10068 * NULL if you use the id param) 10077 * NULL if you use the id param)
10069 */ 10078 * Returns:
10070 void API dw_window_set_bitmap(HWND handle, unsigned long resid, const char *filename) 10079 * DW_ERROR_NONE on success.
10080 * DW_ERROR_UNKNOWN if the parameters were invalid.
10081 * DW_ERROR_GENERAL if the bitmap was unable to be loaded.
10082 */
10083 int API dw_window_set_bitmap(HWND handle, unsigned long resid, const char *filename)
10071 { 10084 {
10072 id object = handle; 10085 id object = handle;
10086 int retval = DW_ERROR_UNKNOWN;
10073 DW_LOCAL_POOL_IN; 10087 DW_LOCAL_POOL_IN;
10074 10088
10075 if([object isKindOfClass:[UIImageView class]] || [object isMemberOfClass:[DWButton class]]) 10089 if([object isKindOfClass:[UIImageView class]] || [object isMemberOfClass:[DWButton class]])
10076 { 10090 {
10077 UIImage *bitmap = nil; 10091 UIImage *bitmap = nil;
10086 if(!bitmap && ext) 10100 if(!bitmap && ext)
10087 { 10101 {
10088 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; 10102 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
10089 bitmap = [[UIImage alloc] initWithContentsOfFile:nstr]; 10103 bitmap = [[UIImage alloc] initWithContentsOfFile:nstr];
10090 } 10104 }
10105 if(!bitmap)
10106 retval = DW_ERROR_GENERAL;
10091 } 10107 }
10092 if(!bitmap && resid > 0 && resid < 65536) 10108 if(!bitmap && resid > 0 && resid < 65536)
10093 { 10109 {
10094 bitmap = _dw_icon_load(resid); 10110 bitmap = _dw_icon_load(resid);
10111 if(!bitmap)
10112 retval = DW_ERROR_GENERAL;
10095 } 10113 }
10096 10114
10097 if(bitmap) 10115 if(bitmap)
10098 { 10116 {
10099 if([object isMemberOfClass:[DWButton class]]) 10117 if([object isMemberOfClass:[DWButton class]])
10115 { 10133 {
10116 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL); 10134 _dw_control_size(handle, item->origwidth == DW_SIZE_AUTO ? &item->width : NULL, item->origheight == DW_SIZE_AUTO ? &item->height : NULL);
10117 /* Queue a redraw on the top-level window */ 10135 /* Queue a redraw on the top-level window */
10118 _dw_redraw([object window], TRUE); 10136 _dw_redraw([object window], TRUE);
10119 } 10137 }
10138 retval = DW_ERROR_NONE;
10120 } 10139 }
10121 } 10140 }
10122 DW_LOCAL_POOL_OUT; 10141 DW_LOCAL_POOL_OUT;
10142 return retval;
10123 } 10143 }
10124 10144
10125 /* 10145 /*
10126 * Sets the icon used for a given window. 10146 * Sets the icon used for a given window.
10127 * Parameters: 10147 * Parameters: