comparison ios/dw.m @ 2606:6c30fcc79402

iOS: Implement context menus on DWRender widgets. Also implement dw_pointer_query_pos() using the last touch event location.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 15 Jul 2021 21:22:59 +0000
parents d60a44a27d70
children da51be036599
comparison
equal deleted inserted replaced
2605:d60a44a27d70 2606:6c30fcc79402
236 pthread_key_t _dw_bg_color_key; 236 pthread_key_t _dw_bg_color_key;
237 static int DWOSMajor, DWOSMinor, DWOSBuild; 237 static int DWOSMajor, DWOSMinor, DWOSBuild;
238 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; 238 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
239 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; 239 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
240 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED; 240 static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED;
241 static CGPoint _dw_event_point = {0};
241 242
242 /* Create a default colors for a thread */ 243 /* Create a default colors for a thread */
243 void _dw_init_colors(void) 244 void _dw_init_colors(void)
244 { 245 {
245 UIColor *fgcolor = [[UIColor grayColor] retain]; 246 UIColor *fgcolor = [[UIColor grayColor] retain];
407 case 3: 408 case 3:
408 case 4: 409 case 4:
409 { 410 {
410 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 411 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
411 int button = 1; 412 int button = 1;
412 CGPoint p = {0}; 413 CGPoint p = _dw_event_point;
413 414
414 if([event isMemberOfClass:[UIEvent class]]) 415 if(event && [event isMemberOfClass:[UIEvent class]])
415 { 416 {
416 UITouch *touch = [[event allTouches] anyObject]; 417 UITouch *touch = [[event allTouches] anyObject];
417 418
418 p = [touch locationInView:[touch view]]; 419 p = [touch locationInView:[touch view]];
419 420
791 -(CGContextRef)cgcontext; 792 -(CGContextRef)cgcontext;
792 -(void)dealloc; 793 -(void)dealloc;
793 @end 794 @end
794 795
795 /* Subclass for a render area type */ 796 /* Subclass for a render area type */
796 @interface DWRender : UIView 797 @interface DWRender : UIView <UIContextMenuInteractionDelegate>
797 { 798 {
798 void *userdata; 799 void *userdata;
799 UIFont *font; 800 UIFont *font;
800 CGSize size; 801 CGSize size;
801 DWImage *cachedImage; 802 DWImage *cachedImage;
806 -(UIFont *)font; 807 -(UIFont *)font;
807 -(void)setSize:(CGSize)input; 808 -(void)setSize:(CGSize)input;
808 -(CGSize)size; 809 -(CGSize)size;
809 -(DWImage *)cachedImage; 810 -(DWImage *)cachedImage;
810 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)); 811 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4));
812 -(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location;
811 @end 813 @end
812 814
813 @implementation DWRender 815 @implementation DWRender
814 -(void *)userdata { return userdata; } 816 -(void *)userdata { return userdata; }
815 -(void)setUserdata:(void *)input { userdata = input; } 817 -(void)setUserdata:(void *)input { userdata = input; }
855 [_DWDirtyDrawables removeObject:self]; 857 [_DWDirtyDrawables removeObject:self];
856 [self setNeedsDisplay]; 858 [self setNeedsDisplay];
857 } 859 }
858 } 860 }
859 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)){ _dw_event_handler(self, key, 2); } 861 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)){ _dw_event_handler(self, key, 2); }
862 -(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location
863 {
864 DWWindow *window = (DWWindow *)[self window];
865 UIContextMenuConfiguration *config = nil;
866
867 _dw_event_point = location;
868 _dw_event_handler(self, nil, 3);
869
870 if(window && [window popupMenu])
871 {
872 __block UIMenu *popupmenu = [[[window popupMenu] menu] retain];
873 config = [UIContextMenuConfiguration configurationWithIdentifier:nil
874 previewProvider:nil
875 actionProvider:^(NSArray* suggestedAction){return popupmenu;}];
876 [window setPopupMenu:nil];
877 }
878 return config;
879 }
860 -(void)dealloc { 880 -(void)dealloc {
861 UserData *root = userdata; 881 UserData *root = userdata;
862 _dw_remove_userdata(&root, NULL, TRUE); 882 _dw_remove_userdata(&root, NULL, TRUE);
863 [font release]; 883 [font release];
864 dw_signal_disconnect_by_window(self); 884 dw_signal_disconnect_by_window(self);
2106 params[0] = [self getRowTitle:(int)indexPath.row]; 2126 params[0] = [self getRowTitle:(int)indexPath.row];
2107 params[1] = [self getRowData:(int)indexPath.row]; 2127 params[1] = [self getRowData:(int)indexPath.row];
2108 params[2] = DW_INT_TO_POINTER((int)point.x); 2128 params[2] = DW_INT_TO_POINTER((int)point.x);
2109 params[3] = DW_INT_TO_POINTER((int)point.y); 2129 params[3] = DW_INT_TO_POINTER((int)point.y);
2110 2130
2131 _dw_event_point = point;
2111 _dw_event_handler(self, (id)params, 10); 2132 _dw_event_handler(self, (id)params, 10);
2112 2133
2113 if(window && [window popupMenu]) 2134 if(window && [window popupMenu])
2114 { 2135 {
2115 __block UIMenu *popupmenu = [[[window popupMenu] menu] retain]; 2136 __block UIMenu *popupmenu = [[[window popupMenu] menu] retain];
5353 DW_FUNCTION_ADD_PARAM1(cid) 5374 DW_FUNCTION_ADD_PARAM1(cid)
5354 DW_FUNCTION_RETURN(dw_render_new, HWND) 5375 DW_FUNCTION_RETURN(dw_render_new, HWND)
5355 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) 5376 DW_FUNCTION_RESTORE_PARAM1(cid, ULONG)
5356 { 5377 {
5357 DWRender *render = [[[DWRender alloc] init] retain]; 5378 DWRender *render = [[[DWRender alloc] init] retain];
5379 UIContextMenuInteraction *interaction = [[UIContextMenuInteraction alloc] initWithDelegate:render];
5358 [render setTag:cid]; 5380 [render setTag:cid];
5381 [render addInteraction:interaction];
5359 DW_FUNCTION_RETURN_THIS(render); 5382 DW_FUNCTION_RETURN_THIS(render);
5360 } 5383 }
5361 5384
5362 /* 5385 /*
5363 * Invalidate the render widget triggering an expose event. 5386 * Invalidate the render widget triggering an expose event.
7517 */ 7540 */
7518 void API dw_pointer_query_pos(long *x, long *y) 7541 void API dw_pointer_query_pos(long *x, long *y)
7519 { 7542 {
7520 if(x) 7543 if(x)
7521 { 7544 {
7522 *x = 0; 7545 *x = (long)_dw_event_point.x;
7523 } 7546 }
7524 if(y) 7547 if(y)
7525 { 7548 {
7526 *y = 0; 7549 *y = (long)_dw_event_point.y;
7527 } 7550 }
7528 } 7551 }
7529 7552
7530 /* 7553 /*
7531 * Sets the X and Y coordinates of the mouse pointer. 7554 * Sets the X and Y coordinates of the mouse pointer.