changeset 2739:02c53dd5e21d

iOS: I used to save the user data on the DWView subview of a DWWindow... Not sure what my thinking on that was, but sometimes it isn't possible to get the DWView from the subviews... so make it so DWWindow can store userdata as well in those cases. May want to just remove the code to save the data on the DWView altogether, but will have to evaluate why I did that in the first place.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 18 Dec 2021 19:31:57 +0000
parents c2387166a414
children 9be24001d288
files ios/dw.m
diffstat 1 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ios/dw.m	Fri Dec 17 12:47:28 2021 +0000
+++ b/ios/dw.m	Sat Dec 18 19:31:57 2021 +0000
@@ -797,6 +797,7 @@
     DWMenu *windowmenu, *popupmenu;
     int redraw;
     int shown;
+    void *userdata;
 }
 -(void)sendEvent:(UIEvent *)theEvent;
 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4));
@@ -809,6 +810,8 @@
 -(void)setPopupMenu:(DWMenu *)input;
 -(DWMenu *)menu;
 -(DWMenu *)popupMenu;
+-(void *)userdata;
+-(void)setUserdata:(void *)input;
 @end
 
 @implementation DWWindow
@@ -839,6 +842,8 @@
 }
 -(void)dealloc
 {
+    UserData *root = userdata;
+    _dw_remove_userdata(&root, NULL, TRUE);
     if(windowmenu)
         [windowmenu release];
     if(popupmenu)
@@ -846,6 +851,8 @@
     dw_signal_disconnect_by_window(self);
     [super dealloc];
 }
+-(void *)userdata { return userdata; }
+-(void)setUserdata:(void *)input { userdata = input; }
 @end
 
 @interface DWImage : NSObject
@@ -9581,7 +9588,14 @@
     {
         UIWindow *win = window;
         NSArray *subviews = [win subviews];
-        object = [subviews firstObject];
+        for(id obj in subviews)
+        {
+            if([obj isMemberOfClass:[DWView class]])
+            {
+                object = obj;
+                break;
+            }
+        }
     }
     else if([object isMemberOfClass:[UIScrollView class]])
     {
@@ -9631,7 +9645,14 @@
     {
         UIWindow *win = window;
         NSArray *subviews = [win subviews];
-        object = [subviews firstObject];
+        for(id obj in subviews)
+        {
+            if([obj isMemberOfClass:[DWView class]])
+            {
+                object = obj;
+                break;
+            }
+        }
     }
     else if([object isMemberOfClass:[UIScrollView class]])
     {