# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1626384179 0 # Node ID 6c30fcc79402b571d370ccc4a775e868d95b901d # Parent d60a44a27d70e26184c076df5422284c0e6e9ee9 iOS: Implement context menus on DWRender widgets. Also implement dw_pointer_query_pos() using the last touch event location. diff -r d60a44a27d70 -r 6c30fcc79402 ios/dw.m --- a/ios/dw.m Tue Jul 13 08:51:22 2021 +0000 +++ b/ios/dw.m Thu Jul 15 21:22:59 2021 +0000 @@ -238,6 +238,7 @@ static char _dw_bundle_path[PATH_MAX+1] = { 0 }; static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; static int _dw_dark_mode_state = DW_FEATURE_UNSUPPORTED; +static CGPoint _dw_event_point = {0}; /* Create a default colors for a thread */ void _dw_init_colors(void) @@ -409,9 +410,9 @@ { int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; int button = 1; - CGPoint p = {0}; - - if([event isMemberOfClass:[UIEvent class]]) + CGPoint p = _dw_event_point; + + if(event && [event isMemberOfClass:[UIEvent class]]) { UITouch *touch = [[event allTouches] anyObject]; @@ -793,7 +794,7 @@ @end /* Subclass for a render area type */ -@interface DWRender : UIView +@interface DWRender : UIView { void *userdata; UIFont *font; @@ -808,6 +809,7 @@ -(CGSize)size; -(DWImage *)cachedImage; -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)); +-(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location; @end @implementation DWRender @@ -857,6 +859,24 @@ } } -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)){ _dw_event_handler(self, key, 2); } +-(UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location +{ + DWWindow *window = (DWWindow *)[self window]; + UIContextMenuConfiguration *config = nil; + + _dw_event_point = location; + _dw_event_handler(self, nil, 3); + + if(window && [window popupMenu]) + { + __block UIMenu *popupmenu = [[[window popupMenu] menu] retain]; + config = [UIContextMenuConfiguration configurationWithIdentifier:nil + previewProvider:nil + actionProvider:^(NSArray* suggestedAction){return popupmenu;}]; + [window setPopupMenu:nil]; + } + return config; +} -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); @@ -2108,6 +2128,7 @@ params[2] = DW_INT_TO_POINTER((int)point.x); params[3] = DW_INT_TO_POINTER((int)point.y); + _dw_event_point = point; _dw_event_handler(self, (id)params, 10); if(window && [window popupMenu]) @@ -5355,7 +5376,9 @@ DW_FUNCTION_RESTORE_PARAM1(cid, ULONG) { DWRender *render = [[[DWRender alloc] init] retain]; + UIContextMenuInteraction *interaction = [[UIContextMenuInteraction alloc] initWithDelegate:render]; [render setTag:cid]; + [render addInteraction:interaction]; DW_FUNCTION_RETURN_THIS(render); } @@ -7519,11 +7542,11 @@ { if(x) { - *x = 0; + *x = (long)_dw_event_point.x; } if(y) { - *y = 0; + *y = (long)_dw_event_point.y; } }