comparison ios/dw.m @ 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
comparison
equal deleted inserted replaced
2738:c2387166a414 2739:02c53dd5e21d
795 @interface DWWindow : UIWindow 795 @interface DWWindow : UIWindow
796 { 796 {
797 DWMenu *windowmenu, *popupmenu; 797 DWMenu *windowmenu, *popupmenu;
798 int redraw; 798 int redraw;
799 int shown; 799 int shown;
800 void *userdata;
800 } 801 }
801 -(void)sendEvent:(UIEvent *)theEvent; 802 -(void)sendEvent:(UIEvent *)theEvent;
802 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4)); 803 -(void)keyDown:(UIKey *)key API_AVAILABLE(ios(13.4));
803 -(int)redraw; 804 -(int)redraw;
804 -(void)setRedraw:(int)val; 805 -(void)setRedraw:(int)val;
807 -(void)layoutSubviews; 808 -(void)layoutSubviews;
808 -(void)setMenu:(DWMenu *)input; 809 -(void)setMenu:(DWMenu *)input;
809 -(void)setPopupMenu:(DWMenu *)input; 810 -(void)setPopupMenu:(DWMenu *)input;
810 -(DWMenu *)menu; 811 -(DWMenu *)menu;
811 -(DWMenu *)popupMenu; 812 -(DWMenu *)popupMenu;
813 -(void *)userdata;
814 -(void)setUserdata:(void *)input;
812 @end 815 @end
813 816
814 @implementation DWWindow 817 @implementation DWWindow
815 -(void)sendEvent:(UIEvent *)theEvent 818 -(void)sendEvent:(UIEvent *)theEvent
816 { 819 {
837 if(_dw_event_handler(self, nil, _DW_EVENT_DELETE) < 1) 840 if(_dw_event_handler(self, nil, _DW_EVENT_DELETE) < 1)
838 dw_window_destroy(self); 841 dw_window_destroy(self);
839 } 842 }
840 -(void)dealloc 843 -(void)dealloc
841 { 844 {
845 UserData *root = userdata;
846 _dw_remove_userdata(&root, NULL, TRUE);
842 if(windowmenu) 847 if(windowmenu)
843 [windowmenu release]; 848 [windowmenu release];
844 if(popupmenu) 849 if(popupmenu)
845 [popupmenu release]; 850 [popupmenu release];
846 dw_signal_disconnect_by_window(self); 851 dw_signal_disconnect_by_window(self);
847 [super dealloc]; 852 [super dealloc];
848 } 853 }
854 -(void *)userdata { return userdata; }
855 -(void)setUserdata:(void *)input { userdata = input; }
849 @end 856 @end
850 857
851 @interface DWImage : NSObject 858 @interface DWImage : NSObject
852 { 859 {
853 UIImage *image; 860 UIImage *image;
9579 id object = window; 9586 id object = window;
9580 if([object isMemberOfClass:[DWWindow class]]) 9587 if([object isMemberOfClass:[DWWindow class]])
9581 { 9588 {
9582 UIWindow *win = window; 9589 UIWindow *win = window;
9583 NSArray *subviews = [win subviews]; 9590 NSArray *subviews = [win subviews];
9584 object = [subviews firstObject]; 9591 for(id obj in subviews)
9592 {
9593 if([obj isMemberOfClass:[DWView class]])
9594 {
9595 object = obj;
9596 break;
9597 }
9598 }
9585 } 9599 }
9586 else if([object isMemberOfClass:[UIScrollView class]]) 9600 else if([object isMemberOfClass:[UIScrollView class]])
9587 { 9601 {
9588 UIScrollView *sv = window; 9602 UIScrollView *sv = window;
9589 NSArray *subviews = [sv subviews]; 9603 NSArray *subviews = [sv subviews];
9629 9643
9630 if([object isMemberOfClass:[DWWindow class]]) 9644 if([object isMemberOfClass:[DWWindow class]])
9631 { 9645 {
9632 UIWindow *win = window; 9646 UIWindow *win = window;
9633 NSArray *subviews = [win subviews]; 9647 NSArray *subviews = [win subviews];
9634 object = [subviews firstObject]; 9648 for(id obj in subviews)
9649 {
9650 if([obj isMemberOfClass:[DWView class]])
9651 {
9652 object = obj;
9653 break;
9654 }
9655 }
9635 } 9656 }
9636 else if([object isMemberOfClass:[UIScrollView class]]) 9657 else if([object isMemberOfClass:[UIScrollView class]])
9637 { 9658 {
9638 UIScrollView *sv = window; 9659 UIScrollView *sv = window;
9639 NSArray *subviews = [sv subviews]; 9660 NSArray *subviews = [sv subviews];