comparison ios/dw.m @ 2705:ddcbed595a84

iOS: Implement HICN resizing and text/label vertical centering. Working throught some of the TODO list. Remove some dead code.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 18 Nov 2021 12:04:40 +0000
parents ae846e9f1ead
children 00e42b9c9ebc
comparison
equal deleted inserted replaced
2704:ae846e9f1ead 2705:ddcbed595a84
3420 3420
3421 va_start(args, format); 3421 va_start(args, format);
3422 mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease]; 3422 mtext = [[[NSString alloc] initWithFormat:[NSString stringWithUTF8String:format] arguments:args] autorelease];
3423 va_end(args); 3423 va_end(args);
3424 3424
3425 #if 0 /* TODO: If we want to use this style it requires a rectangle...
3426 * However the alert style looks pretty good to me...
3427 */
3428 if(flags & DW_MB_INFORMATION)
3429 mstyle = UIAlertControllerStyleActionSheet;
3430 #endif
3431
3432 params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil]; 3425 params = [NSMutableArray arrayWithObjects:mtitle, mtext, [NSNumber numberWithInteger:mstyle], button1, button2, button3, nil];
3433 [DWObj safeCall:@selector(messageBox:) withObject:params]; 3426 [DWObj safeCall:@selector(messageBox:) withObject:params];
3434 iResponse = [[params lastObject] integerValue]; 3427 iResponse = [[params lastObject] integerValue];
3435 3428
3436 switch(iResponse) 3429 switch(iResponse)
6898 void API dw_taskbar_delete(HWND handle, HICN icon) 6891 void API dw_taskbar_delete(HWND handle, HICN icon)
6899 { 6892 {
6900 } 6893 }
6901 6894
6902 /* Internal function to keep HICNs from getting too big */ 6895 /* Internal function to keep HICNs from getting too big */
6903 void _dw_icon_resize(UIImage *image) 6896 UIImage *_dw_icon_resize(UIImage *image)
6904 { 6897 {
6905 if(image) 6898 if(image)
6906 { 6899 {
6907 CGSize size = [image size]; 6900 CGSize size = [image size];
6908 if(size.width > 24 || size.height > 24) 6901 if(size.width > 24 || size.height > 24)
6909 { 6902 {
6910 if(size.width > 24) 6903 if(size.width > 24)
6911 size.width = 24; 6904 size.width = 24;
6912 if(size.height > 24) 6905 if(size.height > 24)
6913 size.height = 24; 6906 size.height = 24;
6914 #if 0 /* TODO: UIImage is immutable, duplicate? */ 6907 // Pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
6915 [image setSize:size]; 6908 // Pass 1.0 to force exact pixel size.
6916 #endif 6909 UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
6917 } 6910 [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
6918 } 6911 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
6912 UIGraphicsEndImageContext();
6913 return newImage;
6914 }
6915 }
6916 return image;
6919 } 6917 }
6920 6918
6921 /* Internal version that does not resize the image */ 6919 /* Internal version that does not resize the image */
6922 HICN _dw_icon_load(unsigned long resid) 6920 HICN _dw_icon_load(unsigned long resid)
6923 { 6921 {
6937 * to an embedded XPM. 6935 * to an embedded XPM.
6938 */ 6936 */
6939 HICN API dw_icon_load(unsigned long module, unsigned long resid) 6937 HICN API dw_icon_load(unsigned long module, unsigned long resid)
6940 { 6938 {
6941 UIImage *image = _dw_icon_load(resid); 6939 UIImage *image = _dw_icon_load(resid);
6942 _dw_icon_resize(image); 6940 return _dw_icon_resize(image);
6943 return image;
6944 } 6941 }
6945 6942
6946 /* 6943 /*
6947 * Obtains an icon from a file. 6944 * Obtains an icon from a file.
6948 * Parameters: 6945 * Parameters:
6959 if(!image && ext) 6956 if(!image && ext)
6960 { 6957 {
6961 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; 6958 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]];
6962 image = [[UIImage alloc] initWithContentsOfFile:nstr]; 6959 image = [[UIImage alloc] initWithContentsOfFile:nstr];
6963 } 6960 }
6964 _dw_icon_resize(image); 6961 return _dw_icon_resize(image);
6965 return image;
6966 } 6962 }
6967 6963
6968 /* 6964 /*
6969 * Obtains an icon from data 6965 * Obtains an icon from data
6970 * Parameters: 6966 * Parameters:
6974 */ 6970 */
6975 HICN API dw_icon_load_from_data(const char *data, int len) 6971 HICN API dw_icon_load_from_data(const char *data, int len)
6976 { 6972 {
6977 NSData *thisdata = [NSData dataWithBytes:data length:len]; 6973 NSData *thisdata = [NSData dataWithBytes:data length:len];
6978 UIImage *image = [[UIImage alloc] initWithData:thisdata]; 6974 UIImage *image = [[UIImage alloc] initWithData:thisdata];
6979 _dw_icon_resize(image); 6975 return _dw_icon_resize(image);
6980 return image;
6981 } 6976 }
6982 6977
6983 /* 6978 /*
6984 * Frees a loaded resource in OS/2 and Windows. 6979 * Frees a loaded resource in OS/2 and Windows.
6985 * Parameters: 6980 * Parameters:
8329 if([object isKindOfClass:[UILabel class]]) 8324 if([object isKindOfClass:[UILabel class]])
8330 { 8325 {
8331 UILabel *label = object; 8326 UILabel *label = object;
8332 8327
8333 [label setTextAlignment:(style & 0xF)]; 8328 [label setTextAlignment:(style & 0xF)];
8334 #if 0 /* TODO: Implement vertical centering */
8335 if(mask & DW_DT_VCENTER) 8329 if(mask & DW_DT_VCENTER)
8336 { 8330 [label setBaselineAdjustment:(style & DW_DT_VCENTER ? UIBaselineAdjustmentAlignCenters : UIBaselineAdjustmentNone)];
8337 [cell setVCenter:(style & DW_DT_VCENTER ? YES : NO)];
8338 }
8339 #endif
8340 if(mask & DW_DT_WORDBREAK) 8331 if(mask & DW_DT_WORDBREAK)
8341 { 8332 {
8342 if(style & DW_DT_WORDBREAK) 8333 if(style & DW_DT_WORDBREAK)
8343 [label setLineBreakMode:NSLineBreakByWordWrapping]; 8334 [label setLineBreakMode:NSLineBreakByWordWrapping];
8344 else 8335 else