comparison ios/dw.m @ 2390:2613d1533f1a

iOS: Fix initial window display and handle resize/rotation events. Add _dw to internal functions keeping with changes done in the GTK4 port. Remove some left over tree code, there is no tree/outline view in iOS.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 24 Mar 2021 20:11:11 +0000
parents 7b06fc7c8130
children a7bfb97fd80e
comparison
equal deleted inserted replaced
2389:7b06fc7c8130 2390:2613d1533f1a
177 177
178 /* 178 /*
179 * List those icons that have transparency first 179 * List those icons that have transparency first
180 */ 180 */
181 #define NUM_EXTS 8 181 #define NUM_EXTS 8
182 char *image_exts[NUM_EXTS] = 182 char *_dw_image_exts[NUM_EXTS+1] =
183 { 183 {
184 ".png", 184 ".png",
185 ".ico", 185 ".ico",
186 ".icns", 186 ".icns",
187 ".gif", 187 ".gif",
188 ".jpg", 188 ".jpg",
189 ".jpeg", 189 ".jpeg",
190 ".tiff", 190 ".tiff",
191 ".bmp" 191 ".bmp",
192 NULL
192 }; 193 };
193 194
194 char *_dw_get_image_extension(const char *filename) 195 char *_dw_get_image_extension(const char *filename)
195 { 196 {
196 char *file = alloca(strlen(filename) + 6); 197 char *file = alloca(strlen(filename) + 6);
198 199
199 /* Try various extentions */ 200 /* Try various extentions */
200 for ( i = 0; i < NUM_EXTS; i++ ) 201 for ( i = 0; i < NUM_EXTS; i++ )
201 { 202 {
202 strcpy( file, filename ); 203 strcpy( file, filename );
203 strcat( file, image_exts[i] ); 204 strcat( file, _dw_image_exts[i] );
204 if ( access( file, R_OK ) == 0 ) 205 if ( access( file, R_OK ) == 0 )
205 { 206 {
206 found_ext = 1; 207 found_ext = 1;
207 break; 208 break;
208 } 209 }
209 } 210 }
210 if ( found_ext == 1 ) 211 if ( found_ext == 1 )
211 { 212 {
212 return image_exts[i]; 213 return _dw_image_exts[i];
213 } 214 }
214 return NULL; 215 return NULL;
215 } 216 }
216 217
217 /* Return the RGB color regardless if a predefined color was passed */ 218 /* Return the RGB color regardless if a predefined color was passed */
218 unsigned long _get_color(unsigned long thiscolor) 219 unsigned long _dw_get_color(unsigned long thiscolor)
219 { 220 {
220 if(thiscolor & DW_RGB_COLOR) 221 if(thiscolor & DW_RGB_COLOR)
221 { 222 {
222 return thiscolor & ~DW_RGB_COLOR; 223 return thiscolor & ~DW_RGB_COLOR;
223 } 224 }
235 int DWOSMajor, DWOSMinor, DWOSBuild; 236 int DWOSMajor, DWOSMinor, DWOSBuild;
236 static char _dw_bundle_path[PATH_MAX+1] = { 0 }; 237 static char _dw_bundle_path[PATH_MAX+1] = { 0 };
237 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0}; 238 static char _dw_app_id[_DW_APP_ID_SIZE+1]= {0};
238 239
239 /* Create a default colors for a thread */ 240 /* Create a default colors for a thread */
240 void _init_colors(void) 241 void _dw_init_colors(void)
241 { 242 {
242 UIColor *fgcolor = [[UIColor grayColor] retain]; 243 UIColor *fgcolor = [[UIColor grayColor] retain];
243 pthread_setspecific(_dw_fg_color_key, fgcolor); 244 pthread_setspecific(_dw_fg_color_key, fgcolor);
244 pthread_setspecific(_dw_bg_color_key, NULL); 245 pthread_setspecific(_dw_bg_color_key, NULL);
245 } 246 }
258 259
259 SignalHandler *Root = NULL; 260 SignalHandler *Root = NULL;
260 261
261 262
262 /* Some internal prototypes */ 263 /* Some internal prototypes */
263 static void _do_resize(Box *thisbox, int x, int y); 264 static void _dw_do_resize(Box *thisbox, int x, int y);
264 void _handle_resize_events(Box *thisbox); 265 void _dw_handle_resize_events(Box *thisbox);
265 int _remove_userdata(UserData **root, const char *varname, int all); 266 int _dw_remove_userdata(UserData **root, const char *varname, int all);
266 int _dw_main_iteration(NSDate *date); 267 int _dw_main_iteration(NSDate *date);
267 CGContextRef _dw_draw_context(UIImage *image, bool antialias); 268 CGContextRef _dw_draw_context(UIImage *image, bool antialias);
268 typedef id (*DWIMP)(id, SEL, ...); 269 typedef id (*DWIMP)(id, SEL, ...);
269 270
270 /* Internal function to queue a window redraw */ 271 /* Internal function to queue a window redraw */
281 { 282 {
282 dw_window_redraw(redraw); 283 dw_window_redraw(redraw);
283 } 284 }
284 } 285 }
285 286
286 SignalHandler *_get_handler(HWND window, int messageid) 287 SignalHandler *_dw_get_handler(HWND window, int messageid)
287 { 288 {
288 SignalHandler *tmp = Root; 289 SignalHandler *tmp = Root;
289 290
290 /* Find any callbacks for this function */ 291 /* Find any callbacks for this function */
291 while(tmp) 292 while(tmp)
329 { 17, DW_SIGNAL_COLUMN_CLICK }, 330 { 17, DW_SIGNAL_COLUMN_CLICK },
330 { 18, DW_SIGNAL_HTML_RESULT }, 331 { 18, DW_SIGNAL_HTML_RESULT },
331 { 19, DW_SIGNAL_HTML_CHANGED } 332 { 19, DW_SIGNAL_HTML_CHANGED }
332 }; 333 };
333 334
334 int _event_handler1(id object, UIEvent *event, int message) 335 int _dw_event_handler1(id object, UIEvent *event, int message)
335 { 336 {
336 SignalHandler *handler = _get_handler(object, message); 337 SignalHandler *handler = _dw_get_handler(object, message);
337 /* NSLog(@"Event handler - type %d\n", message); */ 338 /* NSLog(@"Event handler - type %d\n", message); */
338 339
339 if(handler) 340 if(handler)
340 { 341 {
341 switch(message) 342 switch(message)
538 } 539 }
539 return -1; 540 return -1;
540 } 541 }
541 542
542 /* Sub function to handle redraws */ 543 /* Sub function to handle redraws */
543 int _event_handler(id object, UIEvent *event, int message) 544 int _dw_event_handler(id object, UIEvent *event, int message)
544 { 545 {
545 int ret = _event_handler1(object, event, message); 546 int ret = _dw_event_handler1(object, event, message);
546 if(ret != -1) 547 if(ret != -1)
547 _dw_redraw(nil, FALSE); 548 _dw_redraw(nil, FALSE);
548 return ret; 549 return ret;
549 } 550 }
550 551
552 @interface DWTimerHandler : NSObject { } 553 @interface DWTimerHandler : NSObject { }
553 -(void)runTimer:(id)sender; 554 -(void)runTimer:(id)sender;
554 @end 555 @end
555 556
556 @implementation DWTimerHandler 557 @implementation DWTimerHandler
557 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); } 558 -(void)runTimer:(id)sender { _dw_event_handler(sender, nil, 0); }
558 @end 559 @end
559 560
560 UIApplication *DWApp = nil; 561 UIApplication *DWApp = nil;
561 UIFont *DWDefaultFont; 562 UIFont *DWDefaultFont;
562 DWTimerHandler *DWHandler; 563 DWTimerHandler *DWHandler;
671 { 672 {
672 UserData *root = userdata; 673 UserData *root = userdata;
673 if(box->items) 674 if(box->items)
674 free(box->items); 675 free(box->items);
675 free(box); 676 free(box);
676 _remove_userdata(&root, NULL, TRUE); 677 _dw_remove_userdata(&root, NULL, TRUE);
677 dw_signal_disconnect_by_window(self); 678 dw_signal_disconnect_by_window(self);
678 [super dealloc]; 679 [super dealloc];
679 } 680 }
680 -(Box *)box { return box; } 681 -(Box *)box { return box; }
681 -(id)contentView { return self; } 682 -(id)contentView { return self; }
688 [bgcolor set]; 689 [bgcolor set];
689 UIRectFill([self bounds]); 690 UIRectFill([self bounds]);
690 } 691 }
691 } 692 }
692 -(BOOL)isFlipped { return YES; } 693 -(BOOL)isFlipped { return YES; }
693 -(void)mouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)1, 3); } 694 -(void)mouseDown:(UIEvent *)theEvent { _dw_event_handler(self, (void *)1, 3); }
694 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)1, 4); } 695 -(void)mouseUp:(UIEvent *)theEvent { _dw_event_handler(self, (void *)1, 4); }
695 -(DWMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, (void *)2, 3); return nil; } 696 -(DWMenu *)menuForEvent:(UIEvent *)theEvent { _dw_event_handler(self, (void *)2, 3); return nil; }
696 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)2, 4); } 697 -(void)rightMouseUp:(UIEvent *)theEvent { _dw_event_handler(self, (void *)2, 4); }
697 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)3, 3); } 698 -(void)otherMouseDown:(UIEvent *)theEvent { _dw_event_handler(self, (void *)3, 3); }
698 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)3, 4); } 699 -(void)otherMouseUp:(UIEvent *)theEvent { _dw_event_handler(self, (void *)3, 4); }
699 -(void)keyDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 2); } 700 -(void)keyDown:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 2); }
700 -(void)setColor:(unsigned long)input 701 -(void)setColor:(unsigned long)input
701 { 702 {
702 id orig = bgcolor; 703 id orig = bgcolor;
703 704
704 if(input == _colors[DW_CLR_DEFAULT]) 705 if(input == _colors[DW_CLR_DEFAULT])
737 -(void)sendEvent:(UIEvent *)theEvent 738 -(void)sendEvent:(UIEvent *)theEvent
738 { 739 {
739 int rcode = -1; 740 int rcode = -1;
740 if([theEvent type] == UIEventTypePresses) 741 if([theEvent type] == UIEventTypePresses)
741 { 742 {
742 rcode = _event_handler(self, theEvent, 2); 743 rcode = _dw_event_handler(self, theEvent, 2);
743 } 744 }
744 if ( rcode != TRUE ) 745 if ( rcode != TRUE )
745 [super sendEvent:theEvent]; 746 [super sendEvent:theEvent];
746 } 747 }
747 -(void)keyDown:(UIEvent *)theEvent { } 748 -(void)keyDown:(UIEvent *)theEvent { }
748 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); } 749 -(void)mouseDragged:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 5); }
749 -(int)redraw { return redraw; } 750 -(int)redraw { return redraw; }
750 -(void)setRedraw:(int)val { redraw = val; } 751 -(void)setRedraw:(int)val { redraw = val; }
751 -(int)shown { return shown; } 752 -(int)shown { return shown; }
752 -(void)setShown:(int)val { shown = val; } 753 -(void)setShown:(int)val { shown = val; }
753 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; } 754 -(void)dealloc { dw_signal_disconnect_by_window(self); [super dealloc]; }
813 return cachedDrawingRep; 814 return cachedDrawingRep;
814 } 815 }
815 -(void)mouseDown:(UIEvent *)theEvent 816 -(void)mouseDown:(UIEvent *)theEvent
816 { 817 {
817 if(![theEvent isMemberOfClass:[UIEvent class]]) 818 if(![theEvent isMemberOfClass:[UIEvent class]])
818 _event_handler(self, theEvent, 3); 819 _dw_event_handler(self, theEvent, 3);
819 } 820 }
820 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } 821 -(void)mouseUp:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 4); }
821 -(DWMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } 822 -(DWMenu *)menuForEvent:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 3); return nil; }
822 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } 823 -(void)rightMouseUp:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 4); }
823 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); } 824 -(void)otherMouseDown:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 3); }
824 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } 825 -(void)otherMouseUp:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 4); }
825 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); } 826 -(void)mouseDragged:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 5); }
826 -(void)drawRect:(CGRect)rect { 827 -(void)drawRect:(CGRect)rect {
827 _event_handler(self, nil, 7); 828 _dw_event_handler(self, nil, 7);
828 if (cachedDrawingRep) 829 if (cachedDrawingRep)
829 { 830 {
830 [cachedDrawingRep drawInRect:self.bounds]; 831 [cachedDrawingRep drawInRect:self.bounds];
831 [_DWDirtyDrawables removeObject:self]; 832 [_DWDirtyDrawables removeObject:self];
832 [self setNeedsDisplay]; 833 [self setNeedsDisplay];
833 } 834 }
834 } 835 }
835 -(void)keyDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 2); } 836 -(void)keyDown:(UIEvent *)theEvent { _dw_event_handler(self, theEvent, 2); }
836 -(BOOL)isFlipped { return YES; } 837 -(BOOL)isFlipped { return YES; }
837 -(void)dealloc { 838 -(void)dealloc {
838 UserData *root = userdata; 839 UserData *root = userdata;
839 _remove_userdata(&root, NULL, TRUE); 840 _dw_remove_userdata(&root, NULL, TRUE);
840 [font release]; 841 [font release];
841 dw_signal_disconnect_by_window(self); 842 dw_signal_disconnect_by_window(self);
842 [cachedDrawingRep release]; 843 [cachedDrawingRep release];
843 [_DWDirtyDrawables removeObject:self]; 844 [_DWDirtyDrawables removeObject:self];
844 [super dealloc]; 845 [super dealloc];
856 return [super init]; 857 return [super init];
857 } 858 }
858 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } 859 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
859 -(void)menuHandler:(id)param 860 -(void)menuHandler:(id)param
860 { 861 {
861 _event_handler(param, nil, 8); 862 _dw_event_handler(param, nil, 8);
862 } 863 }
863 -(void)callBack:(NSPointerArray *)params 864 -(void)callBack:(NSPointerArray *)params
864 { 865 {
865 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; 866 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0];
866 if(mycallback) 867 if(mycallback)
992 -(void *)userdata { return userdata; } 993 -(void *)userdata { return userdata; }
993 -(void)setUserdata:(void *)input { userdata = input; } 994 -(void)setUserdata:(void *)input { userdata = input; }
994 -(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation 995 -(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation
995 { 996 {
996 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [[self URL] absoluteString] }; 997 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), [[self URL] absoluteString] };
997 _event_handler(self, (UIEvent *)params, 19); 998 _dw_event_handler(self, (UIEvent *)params, 19);
998 } 999 }
999 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation 1000 -(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
1000 { 1001 {
1001 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [[self URL] absoluteString] }; 1002 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), [[self URL] absoluteString] };
1002 _event_handler(self, (UIEvent *)params, 19); 1003 _dw_event_handler(self, (UIEvent *)params, 19);
1003 } 1004 }
1004 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation 1005 -(void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
1005 { 1006 {
1006 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [[self URL] absoluteString] }; 1007 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), [[self URL] absoluteString] };
1007 _event_handler(self, (UIEvent *)params, 19); 1008 _dw_event_handler(self, (UIEvent *)params, 19);
1008 } 1009 }
1009 -(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation 1010 -(void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation
1010 { 1011 {
1011 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] }; 1012 void *params[2] = { DW_INT_TO_POINTER(DW_HTML_CHANGE_REDIRECT), [[self URL] absoluteString] };
1012 _event_handler(self, (UIEvent *)params, 19); 1013 _dw_event_handler(self, (UIEvent *)params, 19);
1013 } 1014 }
1014 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1015 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1015 @end 1016 @end
1016 1017
1017 /* Subclass for a top-level window */ 1018 /* Subclass for a top-level window */
1018 @interface DWView : DWBox /* <UIWindowDelegate> */ 1019 @interface DWView : DWBox /* <UIWindowDelegate> */
1019 { 1020 {
1027 @end 1028 @end
1028 1029
1029 @implementation DWView 1030 @implementation DWView
1030 -(BOOL)windowShouldClose:(id)sender 1031 -(BOOL)windowShouldClose:(id)sender
1031 { 1032 {
1032 if(_event_handler(sender, nil, 6) > 0) 1033 if(_dw_event_handler(sender, nil, 6) > 0)
1033 return NO; 1034 return NO;
1034 return YES; 1035 return YES;
1035 } 1036 }
1036 -(void)viewDidMoveToWindow 1037 -(void)viewDidMoveToWindow
1037 { 1038 {
1038 #if 0 /* TODO */ 1039 #if 0 /* TODO: Find the correct way to do this on iOS */
1039 [[UINotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:UIWindowDidResizeNotification object:[self window]]; 1040 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification object:[self window]];
1040 [[UINotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:UIWindowDidBecomeMainNotification object:[self window]]; 1041 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:NSWindowDidBecomeMainNotification object:[self window]];
1041 #endif 1042 #endif
1042 } 1043 }
1043 -(void)dealloc 1044 -(void)dealloc
1044 { 1045 {
1045 if(windowmenu) 1046 if(windowmenu)
1048 } 1049 }
1049 [[NSNotificationCenter defaultCenter] removeObserver:self]; 1050 [[NSNotificationCenter defaultCenter] removeObserver:self];
1050 dw_signal_disconnect_by_window(self); 1051 dw_signal_disconnect_by_window(self);
1051 [super dealloc]; 1052 [super dealloc];
1052 } 1053 }
1053 -(void)windowResized:(NSNotification *)notification; 1054 -(void)windowResized:(CGSize)size;
1054 { 1055 {
1055 CGSize size = [self frame].size;
1056
1057 if(oldsize.width != size.width || oldsize.height != size.height) 1056 if(oldsize.width != size.width || oldsize.height != size.height)
1058 { 1057 {
1059 _do_resize(box, size.width, size.height); 1058 _dw_do_resize(box, size.width, size.height);
1060 _event_handler([self window], nil, 1); 1059 _dw_event_handler([self window], nil, 1);
1061 oldsize.width = size.width; 1060 oldsize.width = size.width;
1062 oldsize.height = size.height; 1061 oldsize.height = size.height;
1063 _handle_resize_events(box); 1062 _dw_handle_resize_events(box);
1064 } 1063 }
1065 } 1064 }
1066 -(void)showWindow 1065 -(void)showWindow
1067 { 1066 {
1068 CGSize size = [self frame].size; 1067 CGSize size = [self frame].size;
1069 1068
1070 if(oldsize.width == size.width && oldsize.height == size.height) 1069 if(oldsize.width == size.width && oldsize.height == size.height)
1071 { 1070 {
1072 _do_resize(box, size.width, size.height); 1071 _dw_do_resize(box, size.width, size.height);
1073 _handle_resize_events(box); 1072 _dw_handle_resize_events(box);
1074 } 1073 }
1075 1074
1076 } 1075 }
1077 -(void)windowDidBecomeMain:(id)sender 1076 -(void)windowDidBecomeMain:(id)sender
1078 { 1077 {
1079 _event_handler([self window], nil, 13); 1078 _dw_event_handler([self window], nil, 13);
1080 } 1079 }
1081 -(void)setMenu:(DWMenu *)input { windowmenu = input; [windowmenu retain]; } 1080 -(void)setMenu:(DWMenu *)input { windowmenu = input; [windowmenu retain]; }
1082 -(void)menuHandler:(id)sender 1081 -(void)menuHandler:(id)sender
1083 { 1082 {
1084 [DWObj menuHandler:sender]; 1083 [DWObj menuHandler:sender];
1085 } 1084 }
1086 @end 1085 @end
1086
1087 @interface DWViewController : UIViewController
1088 -(void)viewWillLayoutSubviews;
1089 @end
1090
1091
1092 @implementation DWViewController : UIViewController {}
1093 -(void)viewWillLayoutSubviews
1094 {
1095 DWWindow *window = (DWWindow *)[[self view] window];
1096 NSArray *array = [window subviews];
1097 DWView *view = [array firstObject];
1098 [view setFrame:[window frame]];
1099 [view windowResized:[window frame].size];
1100 }
1101 @end
1102
1087 1103
1088 /* Subclass for a button type */ 1104 /* Subclass for a button type */
1089 @interface DWButton : UIButton 1105 @interface DWButton : UIButton
1090 { 1106 {
1091 void *userdata; 1107 void *userdata;
1103 @implementation DWButton 1119 @implementation DWButton
1104 -(void *)userdata { return userdata; } 1120 -(void *)userdata { return userdata; }
1105 -(void)setUserdata:(void *)input { userdata = input; } 1121 -(void)setUserdata:(void *)input { userdata = input; }
1106 -(void)buttonClicked:(id)sender 1122 -(void)buttonClicked:(id)sender
1107 { 1123 {
1108 _event_handler(self, nil, 8); 1124 _dw_event_handler(self, nil, 8);
1109 } 1125 }
1110 -(UIButtonType)buttonType { return buttonType; } 1126 -(UIButtonType)buttonType { return buttonType; }
1111 -(void)setParent:(DWBox *)input { parent = input; } 1127 -(void)setParent:(DWBox *)input { parent = input; }
1112 -(DWBox *)parent { return parent; } 1128 -(DWBox *)parent { return parent; }
1113 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1129 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1114 @end 1130 @end
1115 1131
1116 /* Subclass for a progress type */ 1132 /* Subclass for a progress type */
1117 @interface DWPercent : UIProgressView 1133 @interface DWPercent : UIProgressView
1118 { 1134 {
1123 @end 1139 @end
1124 1140
1125 @implementation DWPercent 1141 @implementation DWPercent
1126 -(void *)userdata { return userdata; } 1142 -(void *)userdata { return userdata; }
1127 -(void)setUserdata:(void *)input { userdata = input; } 1143 -(void)setUserdata:(void *)input { userdata = input; }
1128 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1144 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1129 @end 1145 @end
1130 1146
1131 /* Subclass for a menu item type */ 1147 /* Subclass for a menu item type */
1132 @implementation DWMenuItem 1148 @implementation DWMenuItem
1133 -(void)setCheck:(int)input { check = input; } 1149 -(void)setCheck:(int)input { check = input; }
1193 @implementation DWScrollBox 1209 @implementation DWScrollBox
1194 -(void *)userdata { return userdata; } 1210 -(void *)userdata { return userdata; }
1195 -(void)setUserdata:(void *)input { userdata = input; } 1211 -(void)setUserdata:(void *)input { userdata = input; }
1196 -(void)setBox:(void *)input { box = input; } 1212 -(void)setBox:(void *)input { box = input; }
1197 -(id)box { return box; } 1213 -(id)box { return box; }
1198 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1214 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1199 @end 1215 @end
1200 1216
1201 @interface DWEntryFieldFormatter : NSFormatter 1217 @interface DWEntryFieldFormatter : NSFormatter
1202 { 1218 {
1203 int maxLength; 1219 int maxLength;
1248 1264
1249 @implementation DWEntryField 1265 @implementation DWEntryField
1250 -(void *)userdata { return userdata; } 1266 -(void *)userdata { return userdata; }
1251 -(void)setUserdata:(void *)input { userdata = input; } 1267 -(void)setUserdata:(void *)input { userdata = input; }
1252 -(void)setClickDefault:(id)input { clickDefault = input; } 1268 -(void)setClickDefault:(id)input { clickDefault = input; }
1253 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1269 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1254 @end 1270 @end
1255 1271
1256 /* Subclass for a text and status text type */ 1272 /* Subclass for a text and status text type */
1257 @interface DWText : UILabel 1273 @interface DWText : UILabel
1258 { 1274 {
1264 @end 1280 @end
1265 1281
1266 @implementation DWText 1282 @implementation DWText
1267 -(void *)userdata { return userdata; } 1283 -(void *)userdata { return userdata; }
1268 -(void)setUserdata:(void *)input { userdata = input; } 1284 -(void)setUserdata:(void *)input { userdata = input; }
1269 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); [super dealloc]; } 1285 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); [super dealloc]; }
1270 @end 1286 @end
1271 1287
1272 /* Subclass for a Notebook page type */ 1288 /* Subclass for a Notebook page type */
1273 @interface DWNotebookPage : UIView 1289 @interface DWNotebookPage : UIView
1274 { 1290 {
1311 if([object isMemberOfClass:[DWBox class]]) 1327 if([object isMemberOfClass:[DWBox class]])
1312 { 1328 {
1313 DWBox *view = object; 1329 DWBox *view = object;
1314 Box *box = [view box]; 1330 Box *box = [view box];
1315 CGSize size = [view frame].size; 1331 CGSize size = [view frame].size;
1316 _do_resize(box, size.width, size.height); 1332 _dw_do_resize(box, size.width, size.height);
1317 _handle_resize_events(box); 1333 _dw_handle_resize_events(box);
1318 } 1334 }
1319 #endif 1335 #endif
1320 _event_handler(self, DW_INT_TO_POINTER([self selectedSegmentIndex]), 15); 1336 _dw_event_handler(self, DW_INT_TO_POINTER([self selectedSegmentIndex]), 15);
1321 } 1337 }
1322 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1338 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1323 @end 1339 @end
1324 1340
1325 @implementation DWNotebookPage 1341 @implementation DWNotebookPage
1326 -(void *)userdata { return userdata; } 1342 -(void *)userdata { return userdata; }
1327 -(void)setUserdata:(void *)input { userdata = input; } 1343 -(void)setUserdata:(void *)input { userdata = input; }
1328 -(int)pageid { return pageid; } 1344 -(int)pageid { return pageid; }
1329 -(void)setPageid:(int)input { pageid = input; } 1345 -(void)setPageid:(int)input { pageid = input; }
1330 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1346 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1331 @end 1347 @end
1332 1348
1333 /* Subclass for a splitbar type */ 1349 /* Subclass for a splitbar type */
1334 @interface DWSplitBar : UISplitViewController <UISplitViewControllerDelegate> 1350 @interface DWSplitBar : UISplitViewController <UISplitViewControllerDelegate>
1335 { 1351 {
1356 if([object isMemberOfClass:[DWBox class]]) 1372 if([object isMemberOfClass:[DWBox class]])
1357 { 1373 {
1358 DWBox *view = object; 1374 DWBox *view = object;
1359 Box *box = [view box]; 1375 Box *box = [view box];
1360 CGSize size = [view frame].size; 1376 CGSize size = [view frame].size;
1361 _do_resize(box, size.width, size.height); 1377 _dw_do_resize(box, size.width, size.height);
1362 _handle_resize_events(box); 1378 _dw_handle_resize_events(box);
1363 } 1379 }
1364 } 1380 }
1365 } 1381 }
1366 -(void)setTag:(NSInteger)tag { Tag = tag; } 1382 -(void)setTag:(NSInteger)tag { Tag = tag; }
1367 -(void *)userdata { return userdata; } 1383 -(void *)userdata { return userdata; }
1368 -(void)setUserdata:(void *)input { userdata = input; } 1384 -(void)setUserdata:(void *)input { userdata = input; }
1369 -(float)percent { return percent; } 1385 -(float)percent { return percent; }
1370 -(void)setPercent:(float)input { percent = input; } 1386 -(void)setPercent:(float)input { percent = input; }
1371 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1387 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1372 @end 1388 @end
1373 1389
1374 /* Subclass for a slider type */ 1390 /* Subclass for a slider type */
1375 @interface DWSlider : UISlider 1391 @interface DWSlider : UISlider
1376 { 1392 {
1382 @end 1398 @end
1383 1399
1384 @implementation DWSlider 1400 @implementation DWSlider
1385 -(void *)userdata { return userdata; } 1401 -(void *)userdata { return userdata; }
1386 -(void)setUserdata:(void *)input { userdata = input; } 1402 -(void)setUserdata:(void *)input { userdata = input; }
1387 -(void)sliderChanged:(id)sender { int intVal = (int)[self value]; _event_handler(self, DW_INT_TO_POINTER(intVal), 14); } 1403 -(void)sliderChanged:(id)sender { int intVal = (int)[self value]; _dw_event_handler(self, DW_INT_TO_POINTER(intVal), 14); }
1388 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1404 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1389 @end 1405 @end
1390 1406
1391 /* Subclass for a MLE type */ 1407 /* Subclass for a MLE type */
1392 @interface DWMLE : UITextView 1408 @interface DWMLE : UITextView
1393 { 1409 {
1403 @implementation DWMLE 1419 @implementation DWMLE
1404 -(void *)userdata { return userdata; } 1420 -(void *)userdata { return userdata; }
1405 -(void)setUserdata:(void *)input { userdata = input; } 1421 -(void)setUserdata:(void *)input { userdata = input; }
1406 -(id)scrollview { return scrollview; } 1422 -(id)scrollview { return scrollview; }
1407 -(void)setScrollview:(id)input { scrollview = input; } 1423 -(void)setScrollview:(id)input { scrollview = input; }
1408 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1424 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1409 @end 1425 @end
1410 1426
1411 /* TODO: UITableView does not support variable columns... 1427 /* TODO: UITableView does not support variable columns...
1412 * also OutlineView does not exist in iOS. 1428 * also OutlineView does not exist in iOS.
1413 */ 1429 */
1461 id scrollview; 1477 id scrollview;
1462 int filesystem; 1478 int filesystem;
1463 } 1479 }
1464 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section; 1480 -(NSInteger)tableView:(UITableView *)aTable numberOfRowsInSection:(NSInteger)section;
1465 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 1481 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
1466 -(void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath; 1482 -(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath;
1467 -(void)addColumn:(NSString *)input andType:(int)type; 1483 -(void)addColumn:(NSString *)input andType:(int)type;
1468 -(NSString *)getColumn:(int)col; 1484 -(NSString *)getColumn:(int)col;
1469 -(void *)userdata; 1485 -(void *)userdata;
1470 -(void)setUserdata:(void *)input; 1486 -(void)setUserdata:(void *)input;
1471 -(void)setFilesystem:(int)input; 1487 -(void)setFilesystem:(int)input;
1536 /* Return the result */ 1552 /* Return the result */
1537 return result; 1553 return result;
1538 } 1554 }
1539 return nil; 1555 return nil;
1540 } 1556 }
1541 -(void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath 1557 -(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)indexPath
1542 { 1558 {
1543 if(indexPath.row % 2 == 0) 1559 if(indexPath.row % 2 == 0)
1544 { 1560 {
1545 if(evencolor) 1561 if(evencolor)
1546 [cell setBackgroundColor:evencolor]; 1562 [cell setBackgroundColor:evencolor];
1562 -(void)refreshColors 1578 -(void)refreshColors
1563 { 1579 {
1564 UIColor *oldodd = oddcolor; 1580 UIColor *oldodd = oddcolor;
1565 UIColor *oldeven = evencolor; 1581 UIColor *oldeven = evencolor;
1566 unsigned long thisodd = dw_oddcolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_ODD : dw_oddcolor; 1582 unsigned long thisodd = dw_oddcolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_ODD : dw_oddcolor;
1567 unsigned long _odd = _get_color(thisodd); 1583 unsigned long _odd = _dw_get_color(thisodd);
1568 unsigned long thiseven = dw_evencolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_EVEN : dw_evencolor; 1584 unsigned long thiseven = dw_evencolor == DW_CLR_DEFAULT ? _DW_COLOR_ROW_EVEN : dw_evencolor;
1569 unsigned long _even = _get_color(thiseven); 1585 unsigned long _even = _dw_get_color(thiseven);
1570 1586
1571 /* Get the UIColor for non-default colors */ 1587 /* Get the UIColor for non-default colors */
1572 if(thisodd != DW_RGB_TRANSPARENT) 1588 if(thisodd != DW_RGB_TRANSPARENT)
1573 oddcolor = [[UIColor colorWithRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain]; 1589 oddcolor = [[UIColor colorWithRed: DW_RED_VALUE(_odd)/255.0 green: DW_GREEN_VALUE(_odd)/255.0 blue: DW_BLUE_VALUE(_odd)/255.0 alpha: 1] retain];
1574 else 1590 else
1818 1834
1819 params[0] = (void *)[self getRowTitle:(int)[self indexPathForSelectedRow].row]; 1835 params[0] = (void *)[self getRowTitle:(int)[self indexPathForSelectedRow].row];
1820 params[1] = (void *)[self getRowData:(int)[self indexPathForSelectedRow].row]; 1836 params[1] = (void *)[self getRowData:(int)[self indexPathForSelectedRow].row];
1821 1837
1822 /* Handler for container class */ 1838 /* Handler for container class */
1823 _event_handler(self, (UIEvent *)params, 9); 1839 _dw_event_handler(self, (UIEvent *)params, 9);
1824 } 1840 }
1825 -(void)selectionChanged:(id)sender 1841 -(void)selectionChanged:(id)sender
1826 { 1842 {
1827 void *params[2]; 1843 void *params[2];
1828 1844
1829 params[0] = (void *)[self getRowTitle:(int)[self indexPathForSelectedRow].row]; 1845 params[0] = (void *)[self getRowTitle:(int)[self indexPathForSelectedRow].row];
1830 params[1] = (void *)[self getRowData:(int)[self indexPathForSelectedRow].row]; 1846 params[1] = (void *)[self getRowData:(int)[self indexPathForSelectedRow].row];
1831 1847
1832 /* Handler for container class */ 1848 /* Handler for container class */
1833 _event_handler(self, (UIEvent *)params, 12); 1849 _dw_event_handler(self, (UIEvent *)params, 12);
1834 /* Handler for listbox class */ 1850 /* Handler for listbox class */
1835 _event_handler(self, DW_INT_TO_POINTER((int)[self indexPathForSelectedRow].row), 11); 1851 _dw_event_handler(self, DW_INT_TO_POINTER((int)[self indexPathForSelectedRow].row), 11);
1836 } 1852 }
1837 -(DWMenu *)menuForEvent:(UIEvent *)event 1853 -(DWMenu *)menuForEvent:(UIEvent *)event
1838 { 1854 {
1839 #if 0 /* TODO: Fix this */ 1855 #if 0 /* TODO: Fix this */
1840 int row; 1856 int row;
1841 CGPoint where = [self convertPoint:[event locationInWindow] fromView:nil]; 1857 CGPoint where = [self convertPoint:[event locationInWindow] fromView:nil];
1842 row = (int)[self rowAtPoint:where]; 1858 row = (int)[self rowAtPoint:where];
1843 _event_handler(self, (UIEvent *)[self getRowTitle:row], 10); 1859 _dw_event_handler(self, (UIEvent *)[self getRowTitle:row], 10);
1844 #endif 1860 #endif
1845 return nil; 1861 return nil;
1846 } 1862 }
1847 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1863 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1848 @end 1864 @end
1849
1850 /* Dive into the tree freeing all desired child nodes */
1851 void _free_tree_recurse(NSMutableArray *node, NSMutableArray *item)
1852 {
1853 if(node && ([node isKindOfClass:[NSArray class]]))
1854 {
1855 int count = (int)[node count];
1856 NSInteger index = -1;
1857 int z;
1858
1859 if(item)
1860 index = [node indexOfObject:item];
1861
1862 for(z=0;z<count;z++)
1863 {
1864 NSMutableArray *pnt = [node objectAtIndex:z];
1865 NSMutableArray *children = nil;
1866
1867 if(pnt && [pnt isKindOfClass:[NSArray class]])
1868 {
1869 children = (NSMutableArray *)[pnt objectAtIndex:3];
1870 }
1871
1872 if(z == index)
1873 {
1874 _free_tree_recurse(children, NULL);
1875 [node removeObjectAtIndex:z];
1876 count = (int)[node count];
1877 index = -1;
1878 z--;
1879 }
1880 else if(item == NULL)
1881 {
1882 NSString *oldstr = [pnt objectAtIndex:1];
1883 [oldstr release];
1884 _free_tree_recurse(children, item);
1885 }
1886 else
1887 _free_tree_recurse(children, item);
1888 }
1889 }
1890 if(!item)
1891 {
1892 [node release];
1893 }
1894 }
1895
1896 1865
1897 /* Subclass for a Calendar type */ 1866 /* Subclass for a Calendar type */
1898 @interface DWCalendar : UIDatePicker 1867 @interface DWCalendar : UIDatePicker
1899 { 1868 {
1900 void *userdata; 1869 void *userdata;
1904 @end 1873 @end
1905 1874
1906 @implementation DWCalendar 1875 @implementation DWCalendar
1907 -(void *)userdata { return userdata; } 1876 -(void *)userdata { return userdata; }
1908 -(void)setUserdata:(void *)input { userdata = input; } 1877 -(void)setUserdata:(void *)input { userdata = input; }
1909 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1878 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1910 @end 1879 @end
1911 1880
1912 /* Subclass for a stepper component of the spinbutton type */ 1881 /* Subclass for a stepper component of the spinbutton type */
1913 /* This is a bad way of doing this... but I can't get the other methods to work */ 1882 /* This is a bad way of doing this... but I can't get the other methods to work */
1914 @interface DWStepper : UIStepper 1883 @interface DWStepper : UIStepper
1970 -(UIStepper *)stepper { return stepper; } 1939 -(UIStepper *)stepper { return stepper; }
1971 -(void)controlTextDidChange:(NSNotification *)aNotification 1940 -(void)controlTextDidChange:(NSNotification *)aNotification
1972 { 1941 {
1973 long val = [[textfield text] intValue]; 1942 long val = [[textfield text] intValue];
1974 [stepper setValue:(float)val]; 1943 [stepper setValue:(float)val];
1975 _event_handler(self, DW_INT_TO_POINTER(val), 14); 1944 _dw_event_handler(self, DW_INT_TO_POINTER(val), 14);
1976 } 1945 }
1977 -(void)setClickDefault:(id)input { clickDefault = input; } 1946 -(void)setClickDefault:(id)input { clickDefault = input; }
1978 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1947 -(void)dealloc { UserData *root = userdata; _dw_remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1979 @end 1948 @end
1980 1949
1981 API_AVAILABLE(ios(10.0)) 1950 API_AVAILABLE(ios(10.0))
1982 @interface DWUserNotificationCenterDelegate : NSObject <UNUserNotificationCenterDelegate> 1951 @interface DWUserNotificationCenterDelegate : NSObject <UNUserNotificationCenterDelegate>
1983 @end 1952 @end
2006 dw_signal_disconnect_by_window(notification); 1975 dw_signal_disconnect_by_window(notification);
2007 } 1976 }
2008 else if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier]) 1977 else if ([response.actionIdentifier isEqualToString:UNNotificationDefaultActionIdentifier])
2009 { 1978 {
2010 /* The user launched the app. */ 1979 /* The user launched the app. */
2011 _event_handler(notification, nil, 8); 1980 _dw_event_handler(notification, nil, 8);
2012 dw_signal_disconnect_by_window(notification); 1981 dw_signal_disconnect_by_window(notification);
2013 } 1982 }
2014 completionHandler(); 1983 completionHandler();
2015 } 1984 }
2016 @end 1985 @end
2025 @implementation DWMDI 1994 @implementation DWMDI
2026 @end 1995 @end
2027 1996
2028 /* This function adds a signal handler callback into the linked list. 1997 /* This function adds a signal handler callback into the linked list.
2029 */ 1998 */
2030 void _new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *discfunc, void *data) 1999 void _dw_new_signal(ULONG message, HWND window, int msgid, void *signalfunction, void *discfunc, void *data)
2031 { 2000 {
2032 SignalHandler *new = malloc(sizeof(SignalHandler)); 2001 SignalHandler *new = malloc(sizeof(SignalHandler));
2033 2002
2034 new->message = message; 2003 new->message = message;
2035 new->window = window; 2004 new->window = window;
2064 Root = new; 2033 Root = new;
2065 } 2034 }
2066 } 2035 }
2067 2036
2068 /* Finds the message number for a given signal name */ 2037 /* Finds the message number for a given signal name */
2069 ULONG _findsigmessage(const char *signame) 2038 ULONG _dw_findsigmessage(const char *signame)
2070 { 2039 {
2071 int z; 2040 int z;
2072 2041
2073 for(z=0;z<SIGNALMAX;z++) 2042 for(z=0;z<SIGNALMAX;z++)
2074 { 2043 {
2078 return 0L; 2047 return 0L;
2079 } 2048 }
2080 2049
2081 unsigned long _foreground = 0xAAAAAA, _background = 0; 2050 unsigned long _foreground = 0xAAAAAA, _background = 0;
2082 2051
2083 void _handle_resize_events(Box *thisbox) 2052 void _dw_handle_resize_events(Box *thisbox)
2084 { 2053 {
2085 int z; 2054 int z;
2086 2055
2087 for(z=0;z<thisbox->count;z++) 2056 for(z=0;z<thisbox->count;z++)
2088 { 2057 {
2092 { 2061 {
2093 Box *tmp = (Box *)[handle box]; 2062 Box *tmp = (Box *)[handle box];
2094 2063
2095 if(tmp) 2064 if(tmp)
2096 { 2065 {
2097 _handle_resize_events(tmp); 2066 _dw_handle_resize_events(tmp);
2098 } 2067 }
2099 } 2068 }
2100 else 2069 else
2101 { 2070 {
2102 if([handle isMemberOfClass:[DWRender class]]) 2071 if([handle isMemberOfClass:[DWRender class]])
2109 if(oldsize.width != newsize.width || oldsize.height != newsize.height) 2078 if(oldsize.width != newsize.width || oldsize.height != newsize.height)
2110 { 2079 {
2111 if(newsize.width > 0 && newsize.height > 0) 2080 if(newsize.width > 0 && newsize.height > 0)
2112 { 2081 {
2113 [render setSize:newsize]; 2082 [render setSize:newsize];
2114 _event_handler(handle, nil, 1); 2083 _dw_event_handler(handle, nil, 1);
2115 } 2084 }
2116 } 2085 }
2117 } 2086 }
2118 /* Special handling for notebook controls */ 2087 /* Special handling for notebook controls */
2119 #if 0 /* TODO: Segmented control might not have subviews */ 2088 #if 0 /* TODO: Segmented control might not have subviews */
2124 id view = [notepage view]; 2093 id view = [notepage view];
2125 2094
2126 if([view isMemberOfClass:[DWBox class]]) 2095 if([view isMemberOfClass:[DWBox class]])
2127 { 2096 {
2128 Box *box = (Box *)[view box]; 2097 Box *box = (Box *)[view box];
2129 _handle_resize_events(box); 2098 _dw_handle_resize_events(box);
2130 } 2099 }
2131 } 2100 }
2132 #endif 2101 #endif
2133 /* Handle laying out scrollviews... if required space is less 2102 /* Handle laying out scrollviews... if required space is less
2134 * than available space, then expand. Otherwise use required space. 2103 * than available space, then expand. Otherwise use required space.
2139 NSArray *subviews = [scrollbox subviews]; 2108 NSArray *subviews = [scrollbox subviews];
2140 DWBox *contentbox = [subviews firstObject]; 2109 DWBox *contentbox = [subviews firstObject];
2141 Box *thisbox = [contentbox box]; 2110 Box *thisbox = [contentbox box];
2142 2111
2143 /* Get the required space for the box */ 2112 /* Get the required space for the box */
2144 _handle_resize_events(thisbox); 2113 _dw_handle_resize_events(thisbox);
2145 } 2114 }
2146 } 2115 }
2147 } 2116 }
2148 } 2117 }
2149 2118
2150 /* This function calculates how much space the widgets and boxes require 2119 /* This function calculates how much space the widgets and boxes require
2151 * and does expansion as necessary. 2120 * and does expansion as necessary.
2152 */ 2121 */
2153 static void _resize_box(Box *thisbox, int *depth, int x, int y, int pass) 2122 static void _dw_resize_box(Box *thisbox, int *depth, int x, int y, int pass)
2154 { 2123 {
2155 /* Current item position */ 2124 /* Current item position */
2156 int z, currentx = thisbox->pad, currenty = thisbox->pad; 2125 int z, currentx = thisbox->pad, currenty = thisbox->pad;
2157 /* Used x, y and padding maximum values... 2126 /* Used x, y and padding maximum values...
2158 * These will be used to find the widest or 2127 * These will be used to find the widest or
2180 if(pass == 1) 2149 if(pass == 1)
2181 { 2150 {
2182 (*depth)++; 2151 (*depth)++;
2183 2152
2184 /* Save the newly calculated values on the box */ 2153 /* Save the newly calculated values on the box */
2185 _resize_box(tmp, depth, x, y, pass); 2154 _dw_resize_box(tmp, depth, x, y, pass);
2186 2155
2187 /* Duplicate the values in the item list for use below */ 2156 /* Duplicate the values in the item list for use below */
2188 thisbox->items[z].width = tmp->minwidth; 2157 thisbox->items[z].width = tmp->minwidth;
2189 thisbox->items[z].height = tmp->minheight; 2158 thisbox->items[z].height = tmp->minheight;
2190 2159
2312 Box *tmp = (Box *)[box box]; 2281 Box *tmp = (Box *)[box box];
2313 2282
2314 if(tmp) 2283 if(tmp)
2315 { 2284 {
2316 (*depth)++; 2285 (*depth)++;
2317 _resize_box(tmp, depth, width, height, pass); 2286 _dw_resize_box(tmp, depth, width, height, pass);
2318 (*depth)--; 2287 (*depth)--;
2319 } 2288 }
2320 } 2289 }
2321 2290
2322 #if 0 /* TODO: Segemented control may not have subviews */ 2291 #if 0 /* TODO: Segemented control may not have subviews */
2329 2298
2330 if([view isMemberOfClass:[DWBox class]]) 2299 if([view isMemberOfClass:[DWBox class]])
2331 { 2300 {
2332 Box *box = (Box *)[view box]; 2301 Box *box = (Box *)[view box];
2333 CGSize size = [view frame].size; 2302 CGSize size = [view frame].size;
2334 _do_resize(box, size.width, size.height); 2303 _dw_do_resize(box, size.width, size.height);
2335 _handle_resize_events(box); 2304 _dw_handle_resize_events(box);
2336 } 2305 }
2337 } 2306 }
2338 #endif 2307 #endif
2339 /* Handle laying out scrollviews... if required space is less 2308 /* Handle laying out scrollviews... if required space is less
2340 * than available space, then expand. Otherwise use required space. 2309 * than available space, then expand. Otherwise use required space.
2348 Box *thisbox = [contentbox box]; 2317 Box *thisbox = [contentbox box];
2349 CGSize contentsize = [scrollbox contentSize]; 2318 CGSize contentsize = [scrollbox contentSize];
2350 CGRect frame = [contentbox frame]; 2319 CGRect frame = [contentbox frame];
2351 2320
2352 /* Get the required space for the box */ 2321 /* Get the required space for the box */
2353 _resize_box(thisbox, &depth, x, y, 1); 2322 _dw_resize_box(thisbox, &depth, x, y, 1);
2354 2323
2355 if(contentsize.width < thisbox->minwidth) 2324 if(contentsize.width < thisbox->minwidth)
2356 { 2325 {
2357 contentsize.width = thisbox->minwidth; 2326 contentsize.width = thisbox->minwidth;
2358 } 2327 }
2362 } 2331 }
2363 frame.size = contentsize; 2332 frame.size = contentsize;
2364 [contentbox setFrame:frame]; 2333 [contentbox setFrame:frame];
2365 2334
2366 /* Layout the content of the scrollbox */ 2335 /* Layout the content of the scrollbox */
2367 _do_resize(thisbox, contentsize.width, contentsize.height); 2336 _dw_do_resize(thisbox, contentsize.width, contentsize.height);
2368 _handle_resize_events(thisbox); 2337 _dw_handle_resize_events(thisbox);
2369 } 2338 }
2370 /* Special handling for spinbutton controls */ 2339 /* Special handling for spinbutton controls */
2371 else if([handle isMemberOfClass:[DWSpinButton class]]) 2340 else if([handle isMemberOfClass:[DWSpinButton class]])
2372 { 2341 {
2373 DWSpinButton *spinbutton = (DWSpinButton *)handle; 2342 DWSpinButton *spinbutton = (DWSpinButton *)handle;
2397 } 2366 }
2398 } 2367 }
2399 } 2368 }
2400 } 2369 }
2401 2370
2402 static void _do_resize(Box *thisbox, int x, int y) 2371 static void _dw_do_resize(Box *thisbox, int x, int y)
2403 { 2372 {
2404 if(x > 0 && y > 0) 2373 if(x > 0 && y > 0)
2405 { 2374 {
2406 if(thisbox) 2375 if(thisbox)
2407 { 2376 {
2408 int depth = 0; 2377 int depth = 0;
2409 2378
2410 /* Calculate space requirements */ 2379 /* Calculate space requirements */
2411 _resize_box(thisbox, &depth, x, y, 1); 2380 _dw_resize_box(thisbox, &depth, x, y, 1);
2412 2381
2413 /* Finally place all the boxes and controls */ 2382 /* Finally place all the boxes and controls */
2414 _resize_box(thisbox, &depth, x, y, 2); 2383 _dw_resize_box(thisbox, &depth, x, y, 2);
2415 } 2384 }
2416 } 2385 }
2417 } 2386 }
2418 2387
2419 /* 2388 /*
4527 { 4496 {
4528 UIColor *oldcolor = pthread_getspecific(_dw_fg_color_key); 4497 UIColor *oldcolor = pthread_getspecific(_dw_fg_color_key);
4529 UIColor *newcolor; 4498 UIColor *newcolor;
4530 DW_LOCAL_POOL_IN; 4499 DW_LOCAL_POOL_IN;
4531 4500
4532 _foreground = _get_color(value); 4501 _foreground = _dw_get_color(value);
4533 4502
4534 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_foreground)/255.0 green: 4503 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_foreground)/255.0 green:
4535 DW_GREEN_VALUE(_foreground)/255.0 blue: 4504 DW_GREEN_VALUE(_foreground)/255.0 blue:
4536 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain]; 4505 DW_BLUE_VALUE(_foreground)/255.0 alpha: 1] retain];
4537 pthread_setspecific(_dw_fg_color_key, newcolor); 4506 pthread_setspecific(_dw_fg_color_key, newcolor);
4555 { 4524 {
4556 pthread_setspecific(_dw_bg_color_key, NULL); 4525 pthread_setspecific(_dw_bg_color_key, NULL);
4557 } 4526 }
4558 else 4527 else
4559 { 4528 {
4560 _background = _get_color(value); 4529 _background = _dw_get_color(value);
4561 4530
4562 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_background)/255.0 green: 4531 newcolor = [[UIColor colorWithRed: DW_RED_VALUE(_background)/255.0 green:
4563 DW_GREEN_VALUE(_background)/255.0 blue: 4532 DW_GREEN_VALUE(_background)/255.0 blue:
4564 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain]; 4533 DW_BLUE_VALUE(_background)/255.0 alpha: 1] retain];
4565 pthread_setspecific(_dw_bg_color_key, newcolor); 4534 pthread_setspecific(_dw_bg_color_key, newcolor);
4598 { 4567 {
4599 DW_LOCAL_POOL_OUT; 4568 DW_LOCAL_POOL_OUT;
4600 return value; 4569 return value;
4601 } 4570 }
4602 4571
4603 unsigned long tempcol = _get_color(value); 4572 unsigned long tempcol = _dw_get_color(value);
4604 UIColor *color = [[UIColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain]; 4573 UIColor *color = [[UIColor colorWithDeviceRed: DW_RED_VALUE(tempcol)/255.0 green: DW_GREEN_VALUE(tempcol)/255.0 blue: DW_BLUE_VALUE(tempcol)/255.0 alpha: 1] retain];
4605 [colorDlg setColor:color]; 4574 [colorDlg setColor:color];
4606 4575
4607 dialog = dw_dialog_new(colorDlg); 4576 dialog = dw_dialog_new(colorDlg);
4608 [colorDlg setDialog:dialog]; 4577 [colorDlg setDialog:dialog];
6759 DW_LOCAL_POOL_IN; 6728 DW_LOCAL_POOL_IN;
6760 6729
6761 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:^(NSString *result, NSError *error) 6730 [html evaluateJavaScript:[NSString stringWithUTF8String:script] completionHandler:^(NSString *result, NSError *error)
6762 { 6731 {
6763 void *params[2] = { result, scriptdata }; 6732 void *params[2] = { result, scriptdata };
6764 _event_handler(html, (UIEvent *)params, 18); 6733 _dw_event_handler(html, (UIEvent *)params, 18);
6765 }]; 6734 }];
6766 DW_LOCAL_POOL_OUT; 6735 DW_LOCAL_POOL_OUT;
6767 return DW_ERROR_NONE; 6736 return DW_ERROR_NONE;
6768 } 6737 }
6769 6738
7247 DW_FUNCTION_ADD_PARAM3(hwndOwner, title, flStyle) 7216 DW_FUNCTION_ADD_PARAM3(hwndOwner, title, flStyle)
7248 DW_FUNCTION_RETURN(dw_window_new, HWND) 7217 DW_FUNCTION_RETURN(dw_window_new, HWND)
7249 DW_FUNCTION_RESTORE_PARAM3(hwndOwner, HWND, title, char *, flStyle, ULONG) 7218 DW_FUNCTION_RESTORE_PARAM3(hwndOwner, HWND, title, char *, flStyle, ULONG)
7250 { 7219 {
7251 DW_FUNCTION_INIT; 7220 DW_FUNCTION_INIT;
7252 DWWindow *window = [[DWWindow alloc] init]; 7221 DWWindow *window = [[DWWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
7253 DWView *view = [[DWView alloc] init]; 7222 DWView *view = [[DWView alloc] init];
7223 window.rootViewController = [[DWViewController alloc] init];
7254 7224
7255 [window addSubview:view]; 7225 [window addSubview:view];
7256 7226
7257 /* TODO: Handle style flags */ 7227 /* TODO: Handle style flags */
7258 if(@available(iOS 13.0, *)) { 7228 if(@available(iOS 13.0, *)) {
7312 { 7282 {
7313 /* Determine the contents size */ 7283 /* Determine the contents size */
7314 dw_window_set_size(handle, 0, 0); 7284 dw_window_set_size(handle, 0, 0);
7315 } 7285 }
7316 if(![window shown]) 7286 if(![window shown])
7287 {
7288 [window makeKeyAndVisible];
7317 [window setShown:YES]; 7289 [window setShown:YES];
7290 }
7318 } 7291 }
7319 return 0; 7292 return 0;
7320 } 7293 }
7321 7294
7322 /* 7295 /*
7345 * back: Background color in DW_RGB format or a default color index. 7318 * back: Background color in DW_RGB format or a default color index.
7346 */ 7319 */
7347 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back) 7320 int API dw_window_set_color(HWND handle, ULONG fore, ULONG back)
7348 { 7321 {
7349 id object = handle; 7322 id object = handle;
7350 unsigned long _fore = _get_color(fore); 7323 unsigned long _fore = _dw_get_color(fore);
7351 unsigned long _back = _get_color(back); 7324 unsigned long _back = _dw_get_color(back);
7352 UIColor *fg = NULL; 7325 UIColor *fg = NULL;
7353 UIColor *bg = NULL; 7326 UIColor *bg = NULL;
7354 7327
7355 /* Get the UIColor for non-default colors */ 7328 /* Get the UIColor for non-default colors */
7356 if(fore != DW_CLR_DEFAULT) 7329 if(fore != DW_CLR_DEFAULT)
8124 if((thisbox = (Box *)[object box])) 8097 if((thisbox = (Box *)[object box]))
8125 { 8098 {
8126 int depth = 0; 8099 int depth = 0;
8127 8100
8128 /* Calculate space requirements */ 8101 /* Calculate space requirements */
8129 _resize_box(thisbox, &depth, 0, 0, 1); 8102 _dw_resize_box(thisbox, &depth, 0, 0, 1);
8130 8103
8131 /* Return what was requested */ 8104 /* Return what was requested */
8132 if(width) *width = thisbox->minwidth; 8105 if(width) *width = thisbox->minwidth;
8133 if(height) *height = thisbox->minheight; 8106 if(height) *height = thisbox->minheight;
8134 } 8107 }
8432 } 8405 }
8433 } 8406 }
8434 return FALSE; 8407 return FALSE;
8435 } 8408 }
8436 8409
8437 int _remove_userdata(UserData **root, const char *varname, int all) 8410 int _dw_remove_userdata(UserData **root, const char *varname, int all)
8438 { 8411 {
8439 UserData *prev = NULL, *tmp = *root; 8412 UserData *prev = NULL, *tmp = *root;
8440 8413
8441 while(tmp) 8414 while(tmp)
8442 { 8415 {
8507 if(data) 8480 if(data)
8508 _new_userdata(&(blah->root), dataname, data); 8481 _new_userdata(&(blah->root), dataname, data);
8509 else 8482 else
8510 { 8483 {
8511 if(dataname) 8484 if(dataname)
8512 _remove_userdata(&(blah->root), dataname, FALSE); 8485 _dw_remove_userdata(&(blah->root), dataname, FALSE);
8513 else 8486 else
8514 _remove_userdata(&(blah->root), NULL, TRUE); 8487 _dw_remove_userdata(&(blah->root), NULL, TRUE);
8515 } 8488 }
8516 } 8489 }
8517 8490
8518 /* 8491 /*
8519 * Gets a named user data item to a window handle. 8492 * Gets a named user data item to a window handle.
8574 8547
8575 if(sigfunc && !DWTimers[z]) 8548 if(sigfunc && !DWTimers[z])
8576 { 8549 {
8577 NSTimeInterval seconds = (double)interval / 1000.0; 8550 NSTimeInterval seconds = (double)interval / 1000.0;
8578 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES]; 8551 NSTimer *thistimer = DWTimers[z] = [NSTimer scheduledTimerWithTimeInterval:seconds target:DWHandler selector:@selector(runTimer:) userInfo:nil repeats:YES];
8579 _new_signal(0, thistimer, z+1, sigfunc, NULL, data); 8552 _dw_new_signal(0, thistimer, z+1, sigfunc, NULL, data);
8580 return z+1; 8553 return z+1;
8581 } 8554 }
8582 return 0; 8555 return 0;
8583 } 8556 }
8584 8557
8658 window = DWApp; 8631 window = DWApp;
8659 } 8632 }
8660 8633
8661 if(window && signame && sigfunc) 8634 if(window && signame && sigfunc)
8662 { 8635 {
8663 if((message = _findsigmessage(signame)) != 0) 8636 if((message = _dw_findsigmessage(signame)) != 0)
8664 { 8637 {
8665 _new_signal(message, window, (int)msgid, sigfunc, discfunc, data); 8638 _dw_new_signal(message, window, (int)msgid, sigfunc, discfunc, data);
8666 } 8639 }
8667 } 8640 }
8668 } 8641 }
8669 8642
8670 /* 8643 /*
8675 void API dw_signal_disconnect_by_name(HWND window, const char *signame) 8648 void API dw_signal_disconnect_by_name(HWND window, const char *signame)
8676 { 8649 {
8677 SignalHandler *prev = NULL, *tmp = Root; 8650 SignalHandler *prev = NULL, *tmp = Root;
8678 ULONG message; 8651 ULONG message;
8679 8652
8680 if(!window || !signame || (message = _findsigmessage(signame)) == 0) 8653 if(!window || !signame || (message = _dw_findsigmessage(signame)) == 0)
8681 return; 8654 return;
8682 8655
8683 while(tmp) 8656 while(tmp)
8684 { 8657 {
8685 if(tmp->window == window && tmp->message == message) 8658 if(tmp->window == window && tmp->message == message)
9456 void API _dw_init_thread(void) 9429 void API _dw_init_thread(void)
9457 { 9430 {
9458 /* If we aren't using garbage collection we need autorelease pools */ 9431 /* If we aren't using garbage collection we need autorelease pools */
9459 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 9432 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
9460 pthread_setspecific(_dw_pool_key, pool); 9433 pthread_setspecific(_dw_pool_key, pool);
9461 _init_colors(); 9434 _dw_init_colors();
9462 } 9435 }
9463 9436
9464 /* 9437 /*
9465 * Generally an internal function called from a terminating 9438 * Generally an internal function called from a terminating
9466 * thread to cleanup the Dynamic Windows environment for the thread. 9439 * thread to cleanup the Dynamic Windows environment for the thread.
9595 pthread_key_create(&_dw_pool_key, NULL); 9568 pthread_key_create(&_dw_pool_key, NULL);
9596 pool = [[NSAutoreleasePool alloc] init]; 9569 pool = [[NSAutoreleasePool alloc] init];
9597 pthread_setspecific(_dw_pool_key, pool); 9570 pthread_setspecific(_dw_pool_key, pool);
9598 pthread_key_create(&_dw_fg_color_key, NULL); 9571 pthread_key_create(&_dw_fg_color_key, NULL);
9599 pthread_key_create(&_dw_bg_color_key, NULL); 9572 pthread_key_create(&_dw_bg_color_key, NULL);
9600 _init_colors(); 9573 _dw_init_colors();
9601 DWObj = [[DWObject alloc] init]; 9574 DWObj = [[DWObject alloc] init];
9602 DWDefaultFont = nil; 9575 DWDefaultFont = nil;
9603 if (@available(iOS 10.0, *)) 9576 if (@available(iOS 10.0, *))
9604 { 9577 {
9605 if([[NSBundle mainBundle] bundleIdentifier] != nil) 9578 if([[NSBundle mainBundle] bundleIdentifier] != nil)