comparison ios/dw.m @ 2822:0adf73d5d8c2

iOS: First steps for implmenting container modes on iOS and eventually Android. Added DW_FEATURE_CONTAINER_MODE with the following possible states on mobile platforms: DW_CONTAINER_MODE_DEFAULT, DW_CONTAINER_MODE_EXTRA and DW_CONTAINER_MODE_MULTI.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 04 Aug 2022 19:12:19 +0000
parents b6ae5b017b28
children 69e144d81f19
comparison
equal deleted inserted replaced
2821:3731f21dd678 2822:0adf73d5d8c2
278 pthread_key_t _dw_bg_color_key; 278 pthread_key_t _dw_bg_color_key;
279 static int DWOSMajor, DWOSMinor, DWOSBuild; 279 static int DWOSMajor, DWOSMinor, DWOSBuild;
280 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; 280 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
281 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; 281 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
282 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED; 282 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED;
283 static int _dw_container_mode = DW_CONTAINER_MODE_DEFAULT;
283 static CGPoint _dw_event_point = {0}; 284 static CGPoint _dw_event_point = {0};
284 static NSMutableArray *_dw_toplevel_windows; 285 static NSMutableArray *_dw_toplevel_windows;
285 286
286 /* Create a default colors for a thread */ 287 /* Create a default colors for a thread */
287 void _dw_init_colors(void) 288 void _dw_init_colors(void)
2327 -(void *)userdata { return userdata; } 2328 -(void *)userdata { return userdata; }
2328 -(void)setUserdata:(void *)input { userdata = input; } 2329 -(void)setUserdata:(void *)input { userdata = input; }
2329 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 2330 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
2330 @end 2331 @end
2331 2332
2332 /* TODO: UITableView does not support variable columns... 2333 /* Subclass UITableViewCell so we can support multiple columns...
2333 * also OutlineView does not exist in iOS. 2334 * Enabled via the DW_FEATURE_CONTAINER_MODE feature setting.
2334 */ 2335 */
2335 UITableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text) 2336 @interface DWTableViewCell : UITableViewCell {}
2336 { 2337 @end
2337 UITableViewCell *browsercell = [[UITableViewCell alloc] init]; 2338
2339 @implementation DWTableViewCell
2340 -(void)dealloc { [super dealloc]; }
2341 @end
2342
2343 /* Create a tableview cell for containers using DW_CONTAINER_MODE_* or listboxes */
2344 DWTableViewCell *_dw_table_cell_view_new(UIImage *icon, NSString *text)
2345 {
2346 DWTableViewCell *browsercell = [[DWTableViewCell alloc] init];
2338 [browsercell setAutoresizesSubviews:YES]; 2347 [browsercell setAutoresizesSubviews:YES];
2339 2348
2340 if(icon) 2349 if(icon)
2341 [[browsercell imageView] setImage:icon]; 2350 [[browsercell imageView] setImage:icon];
2342 if(text) 2351 if(text)
2406 /* Not reusing cell views, so get the cell from our array */ 2415 /* Not reusing cell views, so get the cell from our array */
2407 int index = (int)(indexPath.row * [tvcols count]); 2416 int index = (int)(indexPath.row * [tvcols count]);
2408 id celldata = [data objectAtIndex:index]; 2417 id celldata = [data objectAtIndex:index];
2409 2418
2410 /* The data is already a NSTableCellView so just return that */ 2419 /* The data is already a NSTableCellView so just return that */
2411 if([celldata isMemberOfClass:[UITableViewCell class]]) 2420 if([celldata isMemberOfClass:[DWTableViewCell class]])
2412 { 2421 {
2413 UITableViewCell *result = celldata; 2422 DWTableViewCell *result = celldata;
2414 2423
2415 /* Copy the alignment setting from the column, 2424 /* Copy the alignment setting from the column,
2416 * and set the text color from the container. 2425 * and set the text color from the container.
2417 */ 2426 */
2418 if(fgcolor) 2427 if(fgcolor)
2662 { 2671 {
2663 int x; 2672 int x;
2664 2673
2665 for(x=0;x<rowcount;x++) 2674 for(x=0;x<rowcount;x++)
2666 { 2675 {
2667 UITableViewCell *cell = [data objectAtIndex:(x*colcount)]; 2676 DWTableViewCell *cell = [data objectAtIndex:(x*colcount)];
2668 int thiswidth = 4, thisheight = 0; 2677 int thiswidth = 4, thisheight = 0;
2669 2678
2670 if([cell imageView]) 2679 if([cell imageView])
2671 { 2680 {
2672 thiswidth += [[cell imageView] image].size.width; 2681 thiswidth += [[cell imageView] image].size.width;
5740 { 5749 {
5741 *buffer = '\0'; 5750 *buffer = '\0';
5742 } 5751 }
5743 else 5752 else
5744 { 5753 {
5745 UITableViewCell *cell = [cont getRow:index and:0]; 5754 DWTableViewCell *cell = [cont getRow:index and:0];
5746 NSString *nstr = [[cell textLabel] text]; 5755 NSString *nstr = [[cell textLabel] text];
5747 5756
5748 strncpy(buffer, [nstr UTF8String], length - 1); 5757 strncpy(buffer, [nstr UTF8String], length - 1);
5749 } 5758 }
5750 } 5759 }
5778 int count = (int)[cont numberOfRowsInSection:0]; 5787 int count = (int)[cont numberOfRowsInSection:0];
5779 5788
5780 if(index <= count) 5789 if(index <= count)
5781 { 5790 {
5782 NSString *nstr = [NSString stringWithUTF8String:buffer]; 5791 NSString *nstr = [NSString stringWithUTF8String:buffer];
5783 UITableViewCell *cell = [cont getRow:index and:0]; 5792 DWTableViewCell *cell = [cont getRow:index and:0];
5784 5793
5785 [[cell textLabel] setText:nstr]; 5794 [[cell textLabel] setText:nstr];
5786 [cont reloadData]; 5795 [cont reloadData];
5787 [cont setNeedsDisplay]; 5796 [cont setNeedsDisplay];
5788 } 5797 }
7215 } 7224 }
7216 7225
7217 id object = [cont getRow:(row+lastadd) and:column]; 7226 id object = [cont getRow:(row+lastadd) and:column];
7218 7227
7219 /* If it is a cell, change the content of the cell */ 7228 /* If it is a cell, change the content of the cell */
7220 if([object isMemberOfClass:[UITableViewCell class]]) 7229 if([object isMemberOfClass:[DWTableViewCell class]])
7221 { 7230 {
7222 UITableViewCell *cell = object; 7231 DWTableViewCell *cell = object;
7223 7232
7224 if(icon) 7233 if(icon)
7225 [[cell imageView] setImage:icon]; 7234 [[cell imageView] setImage:icon];
7226 else 7235 else
7227 [[cell textLabel] setText:text]; 7236 [[cell textLabel] setText:text];
7296 lastadd = [cont lastAddPoint]; 7305 lastadd = [cont lastAddPoint];
7297 7306
7298 id object = [cont getRow:(row+lastadd) and:0]; 7307 id object = [cont getRow:(row+lastadd) and:0];
7299 7308
7300 /* If it is a cell, change the content of the cell */ 7309 /* If it is a cell, change the content of the cell */
7301 if([object isMemberOfClass:[UITableViewCell class]]) 7310 if([object isMemberOfClass:[DWTableViewCell class]])
7302 { 7311 {
7303 UITableViewCell *cell = object; 7312 DWTableViewCell *cell = object;
7304 7313
7305 if(icon) 7314 if(icon)
7306 [[cell imageView] setImage:icon]; 7315 [[cell imageView] setImage:icon];
7307 if(text) 7316 if(text)
7308 [[cell textLabel] setText:text]; 7317 [[cell textLabel] setText:text];
11929 case DW_FEATURE_CONTAINER_STRIPE: 11938 case DW_FEATURE_CONTAINER_STRIPE:
11930 case DW_FEATURE_MLE_WORD_WRAP: 11939 case DW_FEATURE_MLE_WORD_WRAP:
11931 case DW_FEATURE_UTF8_UNICODE: 11940 case DW_FEATURE_UTF8_UNICODE:
11932 case DW_FEATURE_TREE: 11941 case DW_FEATURE_TREE:
11933 return DW_FEATURE_ENABLED; 11942 return DW_FEATURE_ENABLED;
11943 case DW_FEATURE_CONTAINER_MODE:
11944 return _dw_container_mode;
11934 case DW_FEATURE_DARK_MODE: 11945 case DW_FEATURE_DARK_MODE:
11935 { 11946 {
11936 if(DWObj) 11947 if(DWObj)
11937 { 11948 {
11938 NSMutableArray *array = [[NSMutableArray alloc] init]; 11949 NSMutableArray *array = [[NSMutableArray alloc] init];
11977 case DW_FEATURE_CONTAINER_STRIPE: 11988 case DW_FEATURE_CONTAINER_STRIPE:
11978 case DW_FEATURE_MLE_WORD_WRAP: 11989 case DW_FEATURE_MLE_WORD_WRAP:
11979 case DW_FEATURE_UTF8_UNICODE: 11990 case DW_FEATURE_UTF8_UNICODE:
11980 case DW_FEATURE_TREE: 11991 case DW_FEATURE_TREE:
11981 return DW_ERROR_GENERAL; 11992 return DW_ERROR_GENERAL;
11993 case DW_FEATURE_CONTAINER_MODE:
11994 {
11995 if(state >= DW_CONTAINER_MODE_DEFAULT && state < DW_CONTAINER_MODE_MAX)
11996 {
11997 _dw_container_mode = state;
11998 return DW_ERROR_NONE;
11999 }
12000 return DW_ERROR_GENERAL;
12001 }
11982 case DW_FEATURE_DARK_MODE: 12002 case DW_FEATURE_DARK_MODE:
11983 { 12003 {
11984 /* Make sure DWObj is initialized */ 12004 /* Make sure DWObj is initialized */
11985 if(DWObj) 12005 if(DWObj)
11986 { 12006 {
11994 else if(state == DW_DARK_MODE_FORCED) 12014 else if(state == DW_DARK_MODE_FORCED)
11995 [DWObj safeCall:@selector(setUserInterfaceStyle:) withObject:[NSNumber numberWithInt:UIUserInterfaceStyleDark]]; 12015 [DWObj safeCall:@selector(setUserInterfaceStyle:) withObject:[NSNumber numberWithInt:UIUserInterfaceStyleDark]];
11996 } 12016 }
11997 else /* Save the requested state for dw_init() */ 12017 else /* Save the requested state for dw_init() */
11998 _dw_dark_mode_state = state; 12018 _dw_dark_mode_state = state;
12019 return DW_ERROR_NONE;
11999 } 12020 }
12000 default: 12021 default:
12001 return DW_FEATURE_UNSUPPORTED; 12022 return DW_FEATURE_UNSUPPORTED;
12002 } 12023 }
12003 } 12024 }