comparison ios/dw.m @ 2377:6393d8c10569

iOS: More progress on converting Mac to iOS.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 19 Mar 2021 00:27:36 +0000
parents 8d6ab1f46a29
children cc858be0cb81
comparison
equal deleted inserted replaced
2376:e6449653a30b 2377:6393d8c10569
250 250
251 } SignalHandler; 251 } SignalHandler;
252 252
253 SignalHandler *Root = NULL; 253 SignalHandler *Root = NULL;
254 254
255
255 /* Some internal prototypes */ 256 /* Some internal prototypes */
256 static void _do_resize(Box *thisbox, int x, int y); 257 static void _do_resize(Box *thisbox, int x, int y);
257 void _handle_resize_events(Box *thisbox); 258 void _handle_resize_events(Box *thisbox);
258 int _remove_userdata(UserData **root, const char *varname, int all); 259 int _remove_userdata(UserData **root, const char *varname, int all);
259 int _dw_main_iteration(NSDate *date); 260 int _dw_main_iteration(NSDate *date);
260 CGContextRef _dw_draw_context(NSBitmapImageRep *image); 261 CGContextRef _dw_draw_context(UIImage *image);
261 typedef id (*DWIMP)(id, SEL, ...); 262 typedef id (*DWIMP)(id, SEL, ...);
262 263
263 /* Internal function to queue a window redraw */ 264 /* Internal function to queue a window redraw */
264 void _dw_redraw(id window, int skip) 265 void _dw_redraw(id window, int skip)
265 { 266 {
349 CGSize size; 350 CGSize size;
350 351
351 if([object isKindOfClass:[UIWindow class]]) 352 if([object isKindOfClass:[UIWindow class]])
352 { 353 {
353 UIWindow *window = object; 354 UIWindow *window = object;
354 size = [[window contentView] frame].size; 355 size = [window frame].size;
355 } 356 }
356 else 357 else
357 { 358 {
358 UIView *view = object; 359 UIView *view = object;
359 size = [view frame].size; 360 size = [view frame].size;
366 return 0; 367 return 0;
367 } 368 }
368 case 2: 369 case 2:
369 { 370 {
370 int (*keypressfunc)(HWND, char, int, int, void *, char *) = handler->signalfunction; 371 int (*keypressfunc)(HWND, char, int, int, void *, char *) = handler->signalfunction;
371 NSString *nchar = [event charactersIgnoringModifiers]; 372 NSString *nchar = @""; /* [event charactersIgnoringModifiers]; */
372 int special = (int)[event modifierFlags];
373 unichar vk = [nchar characterAtIndex:0]; 373 unichar vk = [nchar characterAtIndex:0];
374 char *utf8 = NULL, ch = '\0'; 374 char *utf8 = NULL, ch = '\0';
375 int special = 0;
376
377 if(@available(iOS 13.4, *))
378 {
379 special = (int)[event modifierFlags];
380 }
375 381
376 /* Handle a valid key */ 382 /* Handle a valid key */
377 if([nchar length] == 1) 383 if([nchar length] == 1)
378 { 384 {
379 char *tmp = (char *)[nchar UTF8String]; 385 char *tmp = (char *)[nchar UTF8String];
389 /* Button press and release event */ 395 /* Button press and release event */
390 case 3: 396 case 3:
391 case 4: 397 case 4:
392 { 398 {
393 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 399 int (* API buttonfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
394 CGPoint p = [UIEvent mouseLocation];
395 int button = 1; 400 int button = 1;
401 CGPoint p = {0};
396 402
397 if([event isMemberOfClass:[UIEvent class]]) 403 if([event isMemberOfClass:[UIEvent class]])
398 { 404 {
399 id view = [[[event window] contentView] superview]; 405 UITouch *touch = [[event allTouches] anyObject];
400 UIEventType type = [event type]; 406
401 407 p = [touch locationInView:[touch view]];
402 p = [view convertPoint:[event locationInWindow] toView:object]; 408
403 409 if(@available(ios 13.4, *))
404 if(type == DWEventTypeRightMouseDown || type == DWEventTypeRightMouseUp)
405 { 410 {
406 button = 2; 411 if([event buttonMask] & UIEventButtonMaskSecondary)
407 } 412 button = 2;
408 else if(type == DWEventTypeOtherMouseDown || type == DWEventTypeOtherMouseUp)
409 {
410 button = 3;
411 }
412 else if([event modifierFlags] & DWEventModifierFlagControl)
413 {
414 button = 2;
415 } 413 }
416 } 414 }
417 415
418 return buttonfunc(object, (int)p.x, (int)p.y, button, handler->data); 416 return buttonfunc(object, (int)p.x, (int)p.y, button, handler->data);
419 } 417 }
420 /* Motion notify event */ 418 /* Motion notify event */
419 #if 0 /* Not sure if motion notify applies */
421 case 5: 420 case 5:
422 { 421 {
423 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction; 422 int (* API motionfunc)(HWND, int, int, int, void *) = (int (* API)(HWND, int, int, int, void *))handler->signalfunction;
424 id view = [[[event window] contentView] superview];
425 CGPoint p = [view convertPoint:[event locationInWindow] toView:object];
426 SEL spmb = NSSelectorFromString(@"pressedMouseButtons");
427 DWIMP ipmb = [[UIEvent class] respondsToSelector:spmb] ? (DWIMP)[[UIEvent class] methodForSelector:spmb] : 0;
428 NSUInteger buttonmask = ipmb ? (NSUInteger)ipmb([UIEvent class], spmb) : (1 << [event buttonNumber]);
429 423
430 return motionfunc(object, (int)p.x, (int)p.y, (int)buttonmask, handler->data); 424 return motionfunc(object, (int)p.x, (int)p.y, (int)buttonmask, handler->data);
431 } 425 }
426 #endif
432 /* Window close event */ 427 /* Window close event */
433 case 6: 428 case 6:
434 { 429 {
435 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; 430 int (* API closefunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction;
436 return closefunc(object, handler->data); 431 return closefunc(object, handler->data);
470 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction; 465 int (* API containercontextfunc)(HWND, char *, int, int, void *, void *) = (int (* API)(HWND, char *, int, int, void *, void *))handler->signalfunction;
471 char *text = (char *)event; 466 char *text = (char *)event;
472 void *user = NULL; 467 void *user = NULL;
473 LONG x,y; 468 LONG x,y;
474 469
475 /* Fill in both items for the tree */
476 if([object isKindOfClass:[NSOutlineView class]])
477 {
478 id item = event;
479 NSString *nstr = [item objectAtIndex:1];
480 text = (char *)[nstr UTF8String];
481 NSValue *value = [item objectAtIndex:2];
482 if(value && [value isKindOfClass:[NSValue class]])
483 {
484 user = [value pointerValue];
485 }
486 }
487
488 dw_pointer_query_pos(&x, &y); 470 dw_pointer_query_pos(&x, &y);
489 471
490 return containercontextfunc(handler->window, text, (int)x, (int)y, handler->data, user); 472 return containercontextfunc(handler->window, text, (int)x, (int)y, handler->data, user);
491 } 473 }
492 /* Generic selection changed event for several classes */ 474 /* Generic selection changed event for several classes */
496 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction; 478 int (* API valuechangedfunc)(HWND, int, void *) = (int (* API)(HWND, int, void *))handler->signalfunction;
497 int selected = DW_POINTER_TO_INT(event); 479 int selected = DW_POINTER_TO_INT(event);
498 480
499 return valuechangedfunc(handler->window, selected, handler->data);; 481 return valuechangedfunc(handler->window, selected, handler->data);;
500 } 482 }
501 /* Tree class selection event */
502 case 12:
503 {
504 int (* API treeselectfunc)(HWND, HTREEITEM, char *, void *, void *) = (int (* API)(HWND, HTREEITEM, char *, void *, void *))handler->signalfunction;
505 char *text = NULL;
506 void *user = NULL;
507 id item = nil;
508
509 if([object isKindOfClass:[NSOutlineView class]])
510 {
511 item = (id)event;
512 NSString *nstr = [item objectAtIndex:1];
513
514 if(nstr)
515 {
516 text = strdup([nstr UTF8String]);
517 }
518
519 NSValue *value = [item objectAtIndex:2];
520 if(value && [value isKindOfClass:[NSValue class]])
521 {
522 user = [value pointerValue];
523 }
524 int result = treeselectfunc(handler->window, item, text, handler->data, user);
525 if(text)
526 {
527 free(text);
528 }
529 return result;
530 }
531 else if(event)
532 {
533 void **params = (void **)event;
534
535 text = params[0];
536 user = params[1];
537 }
538
539 return treeselectfunc(handler->window, item, text, handler->data, user);
540 }
541 /* Set Focus event */ 483 /* Set Focus event */
542 case 13: 484 case 13:
543 { 485 {
544 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction; 486 int (* API setfocusfunc)(HWND, void *) = (int (* API)(HWND, void *))handler->signalfunction;
545 487
608 @implementation DWTimerHandler 550 @implementation DWTimerHandler
609 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); } 551 -(void)runTimer:(id)sender { _event_handler(sender, nil, 0); }
610 @end 552 @end
611 553
612 UIApplication *DWApp = nil; 554 UIApplication *DWApp = nil;
613 UIFontManager *DWFontManager = nil;
614 UIFont *DWDefaultFont; 555 UIFont *DWDefaultFont;
615 DWTimerHandler *DWHandler; 556 DWTimerHandler *DWHandler;
616 NSAutoreleasePool *pool; 557 NSAutoreleasePool *pool;
617 NSMutableArray *_DWDirtyDrawables; 558 NSMutableArray *_DWDirtyDrawables;
618 DWTID DWThread = (DWTID)-1; 559 DWTID DWThread = (DWTID)-1;
619
620 /* Send fake event to make sure the loop isn't stuck */
621 void _dw_wakeup_app()
622 {
623 [DWApp postEvent:[UIEvent otherEventWithType:DWEventTypeApplicationDefined
624 location:NSMakePoint(0, 0)
625 modifierFlags:0
626 timestamp:0
627 windowNumber:0
628 context:NULL
629 subtype:0
630 data1:0
631 data2:0]
632 atStart:NO];
633 }
634 560
635 /* Used for doing bitblts from the main thread */ 561 /* Used for doing bitblts from the main thread */
636 typedef struct _bitbltinfo 562 typedef struct _bitbltinfo
637 { 563 {
638 id src; 564 id src;
729 -(void)drawRect:(CGRect)rect 655 -(void)drawRect:(CGRect)rect
730 { 656 {
731 if(bgcolor) 657 if(bgcolor)
732 { 658 {
733 [bgcolor set]; 659 [bgcolor set];
734 CGRectFill([self bounds]); 660 UIRectFill([self bounds]);
735 } 661 }
736 } 662 }
737 -(BOOL)isFlipped { return YES; } 663 -(BOOL)isFlipped { return YES; }
738 -(void)mouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)1, 3); } 664 -(void)mouseDown:(UIEvent *)theEvent { _event_handler(self, (void *)1, 3); }
739 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)1, 4); } 665 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, (void *)1, 4); }
750 { 676 {
751 bgcolor = nil; 677 bgcolor = nil;
752 } 678 }
753 else 679 else
754 { 680 {
755 bgcolor = [[UIColor colorWithDeviceRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1] retain]; 681 bgcolor = [[UIColor colorWithRed: DW_RED_VALUE(input)/255.0 green: DW_GREEN_VALUE(input)/255.0 blue: DW_BLUE_VALUE(input)/255.0 alpha: 1] retain];
756 if(UIGraphicsGetCurrentContext()) 682 if(UIGraphicsGetCurrentContext())
757 { 683 {
758 [bgcolor set]; 684 [bgcolor set];
759 CGRectFill([self bounds]); 685 UIRectFill([self bounds]);
760 } 686 }
761 } 687 }
762 [self setNeedsDisplay:YES]; 688 [self setNeedsDisplay];
763 [orig release]; 689 [orig release];
764 } 690 }
765 @end
766
767 /* Subclass for a group box type */
768 @interface DWGroupBox : UIView
769 {
770 void *userdata;
771 UIColor *bgcolor;
772 CGSize borderSize;
773 NSString *title;
774 }
775 -(Box *)box;
776 -(void *)userdata;
777 -(void)setUserdata:(void *)input;
778 -(void)setTitle:(NSString *)newtitle;
779 @end
780
781 @implementation DWGroupBox
782 -(Box *)box { return [[self contentView] box]; }
783 -(void *)userdata { return userdata; }
784 -(CGSize)borderSize { return borderSize; }
785 -(CGSize)initBorder
786 {
787 CGSize frameSize = [self frame].size;
788
789 if(frameSize.height < 20 || frameSize.width < 20)
790 {
791 frameSize.width = frameSize.height = 100;
792 [self setFrameSize:frameSize];
793 }
794 CGSize contentSize = [[self contentView] frame].size;
795 CGSize titleSize = [self titleRect].size;
796
797 borderSize.width = 100-contentSize.width;
798 borderSize.height = (100-contentSize.height)-titleSize.height;
799 return borderSize;
800 }
801 -(void)setUserdata:(void *)input { userdata = input; }
802 -(void)setTitle:(NSString *)newtitle { [title release]; title = newtitle; [title retain]; }
803 @end 691 @end
804 692
805 @interface DWWindow : UIWindow 693 @interface DWWindow : UIWindow
806 { 694 {
807 int redraw; 695 int redraw;
818 706
819 @implementation DWWindow 707 @implementation DWWindow
820 -(void)sendEvent:(UIEvent *)theEvent 708 -(void)sendEvent:(UIEvent *)theEvent
821 { 709 {
822 int rcode = -1; 710 int rcode = -1;
823 if([theEvent type] == DWEventTypeKeyDown) 711 if([theEvent type] == UIEventTypePresses)
824 { 712 {
825 rcode = _event_handler(self, theEvent, 2); 713 rcode = _event_handler(self, theEvent, 2);
826 } 714 }
827 if ( rcode != TRUE ) 715 if ( rcode != TRUE )
828 [super sendEvent:theEvent]; 716 [super sendEvent:theEvent];
840 @interface DWRender : UIControl 728 @interface DWRender : UIControl
841 { 729 {
842 void *userdata; 730 void *userdata;
843 UIFont *font; 731 UIFont *font;
844 CGSize size; 732 CGSize size;
845 NSBitmapImageRep *cachedDrawingRep; 733 UIImage *cachedDrawingRep;
846 } 734 }
847 -(void *)userdata; 735 -(void *)userdata;
848 -(void)setUserdata:(void *)input; 736 -(void)setUserdata:(void *)input;
849 -(void)setFont:(UIFont *)input; 737 -(void)setFont:(UIFont *)input;
850 -(UIFont *)font; 738 -(UIFont *)font;
851 -(void)setSize:(CGSize)input; 739 -(void)setSize:(CGSize)input;
852 -(CGSize)size; 740 -(CGSize)size;
853 -(NSBitmapImageRep *)cachedDrawingRep; 741 -(UIImage *)cachedDrawingRep;
854 -(void)mouseDown:(UIEvent *)theEvent; 742 -(void)mouseDown:(UIEvent *)theEvent;
855 -(void)mouseUp:(UIEvent *)theEvent; 743 -(void)mouseUp:(UIEvent *)theEvent;
856 -(UIMenu *)menuForEvent:(UIEvent *)theEvent; 744 -(UIMenu *)menuForEvent:(UIEvent *)theEvent;
857 -(void)rightMouseUp:(UIEvent *)theEvent; 745 -(void)rightMouseUp:(UIEvent *)theEvent;
858 -(void)otherMouseDown:(UIEvent *)theEvent; 746 -(void)otherMouseDown:(UIEvent *)theEvent;
869 -(UIFont *)font { return font; } 757 -(UIFont *)font { return font; }
870 -(void)setSize:(CGSize)input { 758 -(void)setSize:(CGSize)input {
871 size = input; 759 size = input;
872 if(cachedDrawingRep) 760 if(cachedDrawingRep)
873 { 761 {
874 NSBitmapImageRep *oldrep = cachedDrawingRep; 762 UIImage *oldrep = cachedDrawingRep;
875 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds]; 763 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
876 [cachedDrawingRep retain]; 764 [cachedDrawingRep retain];
877 [oldrep release]; 765 [oldrep release];
878 } 766 }
879 } 767 }
880 -(CGSize)size { return size; } 768 -(CGSize)size { return size; }
881 -(NSBitmapImageRep *)cachedDrawingRep { 769 -(UIImage *)cachedDrawingRep {
882 if(!cachedDrawingRep) 770 if(!cachedDrawingRep)
883 { 771 {
884 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds]; 772 cachedDrawingRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
885 [cachedDrawingRep retain]; 773 [cachedDrawingRep retain];
886 } 774 }
889 [_DWDirtyDrawables addObject:self]; 777 [_DWDirtyDrawables addObject:self];
890 return cachedDrawingRep; 778 return cachedDrawingRep;
891 } 779 }
892 -(void)mouseDown:(UIEvent *)theEvent 780 -(void)mouseDown:(UIEvent *)theEvent
893 { 781 {
894 if(![theEvent isMemberOfClass:[UIEvent class]] || !([theEvent modifierFlags] & DWEventModifierFlagControl)) 782 if(![theEvent isMemberOfClass:[UIEvent class]])
895 _event_handler(self, theEvent, 3); 783 _event_handler(self, theEvent, 3);
896 } 784 }
897 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } 785 -(void)mouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); }
898 -(UIMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; } 786 -(UIMenu *)menuForEvent:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); return nil; }
899 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } 787 -(void)rightMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); }
900 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); } 788 -(void)otherMouseDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 3); }
901 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); } 789 -(void)otherMouseUp:(UIEvent *)theEvent { _event_handler(self, theEvent, 4); }
902 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); } 790 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); }
903 -(void)delayedNeedsDisplay { [self setNeedsDisplay:YES]; }
904 -(void)drawRect:(CGRect)rect { 791 -(void)drawRect:(CGRect)rect {
905 _event_handler(self, nil, 7); 792 _event_handler(self, nil, 7);
906 if (cachedDrawingRep) 793 if (cachedDrawingRep)
907 { 794 {
908 [cachedDrawingRep drawInRect:self.bounds]; 795 [cachedDrawingRep drawInRect:self.bounds];
909 [_DWDirtyDrawables removeObject:self]; 796 [_DWDirtyDrawables removeObject:self];
910 /* Work around a bug in Mojave 10.14 by delaying the setNeedsDisplay */ 797 [self setNeedsDisplay];
911 if(DWOSMinor != 14)
912 [self setNeedsDisplay:YES];
913 else
914 [self performSelector:@selector(delayedNeedsDisplay) withObject:nil afterDelay:0];
915 } 798 }
916 } 799 }
917 -(void)keyDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 2); } 800 -(void)keyDown:(UIEvent *)theEvent { _event_handler(self, theEvent, 2); }
918 -(BOOL)isFlipped { return YES; } 801 -(BOOL)isFlipped { return YES; }
919 -(void)dealloc { 802 -(void)dealloc {
930 813
931 @implementation DWObject 814 @implementation DWObject
932 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ } 815 -(void)uselessThread:(id)sender { /* Thread only to initialize threading */ }
933 -(void)menuHandler:(id)param 816 -(void)menuHandler:(id)param
934 { 817 {
935 DWMenuItem *item = param;
936 if([item check])
937 {
938 if([item state] == DWControlStateValueOn)
939 [item setState:DWControlStateValueOff];
940 else
941 [item setState:DWControlStateValueOn];
942 }
943 _event_handler(param, nil, 8); 818 _event_handler(param, nil, 8);
944 } 819 }
945 -(void)callBack:(NSPointerArray *)params 820 -(void)callBack:(NSPointerArray *)params
946 { 821 {
947 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; 822 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0];
948 if(mycallback) 823 if(mycallback)
949 mycallback(params); 824 mycallback(params);
950 } 825 }
951 -(void)messageBox:(NSMutableArray *)params 826 -(void)messageBox:(NSMutableArray *)params
952 { 827 {
953 NSInteger iResponse; 828 __block NSInteger iResponse = 0;
954 NSAlert *alert = [[NSAlert alloc] init]; 829 UIAlertController* alert = [UIAlertController alertControllerWithTitle:[params objectAtIndex:0]
955 [alert setMessageText:[params objectAtIndex:0]]; 830 message:[params objectAtIndex:1]
956 [alert setInformativeText:[params objectAtIndex:1]]; 831 preferredStyle:[[params objectAtIndex:2] integerValue]];
957 [alert addButtonWithTitle:[params objectAtIndex:3]]; 832
833 UIAlertAction* action = [UIAlertAction actionWithTitle:[params objectAtIndex:3] style:UIAlertActionStyleDefault
834 handler:^(UIAlertAction * action) { iResponse = 0; }];
835 [alert addAction:action];
958 if([params count] > 4) 836 if([params count] > 4)
959 [alert addButtonWithTitle:[params objectAtIndex:4]]; 837 action = [UIAlertAction actionWithTitle:[params objectAtIndex:4] style:UIAlertActionStyleDefault
838 handler:^(UIAlertAction * action) { iResponse = 1; }];
960 if([params count] > 5) 839 if([params count] > 5)
961 [alert addButtonWithTitle:[params objectAtIndex:5]]; 840 action = [UIAlertAction actionWithTitle:[params objectAtIndex:5] style:UIAlertActionStyleDefault
962 [alert setAlertStyle:[[params objectAtIndex:2] integerValue]]; 841 handler:^(UIAlertAction * action) { iResponse = 2; }];
963 iResponse = [alert runModal]; 842
843 [alert presentViewController:alert animated:YES completion:nil];
964 [alert release]; 844 [alert release];
965 [params addObject:[NSNumber numberWithInteger:iResponse]]; 845 [params addObject:[NSNumber numberWithInteger:iResponse]];
966 } 846 }
967 -(void)safeCall:(SEL)sel withObject:(id)param 847 -(void)safeCall:(SEL)sel withObject:(id)param
968 { 848 {
969 if([self respondsToSelector:sel]) 849 if([self respondsToSelector:sel])
970 { 850 {
971 DWTID curr = pthread_self(); 851 DWTID curr = pthread_self();
972 852
973 if(DWThread == (DWTID)-1 || DWThread == curr) 853 if(DWThread == (DWTID)-1 || DWThread == curr)
974 { 854 [self performSelector:sel withObject:param];
975 DWIMP imp = (DWIMP)[self methodForSelector:sel];
976
977 if(imp)
978 imp(self, sel, param);
979 }
980 else 855 else
981 [self performSelectorOnMainThread:sel withObject:param waitUntilDone:YES]; 856 [self performSelectorOnMainThread:sel withObject:param waitUntilDone:YES];
982 } 857 }
983 } 858 }
984 -(void)doBitBlt:(id)param 859 -(void)doBitBlt:(id)param
992 { 867 {
993 DWRender *render = bltdest; 868 DWRender *render = bltdest;
994 869
995 bltdest = [render cachedDrawingRep]; 870 bltdest = [render cachedDrawingRep];
996 } 871 }
997 if([bltdest isMemberOfClass:[NSBitmapImageRep class]]) 872 if([bltdest isMemberOfClass:[UIImage class]])
998 { 873 {
999 UIGraphicsPushContext(_dw_draw_context(bltdest)); 874 UIGraphicsPushContext(_dw_draw_context(bltdest));
1000 [[[NSDictionary alloc] initWithObjectsAndKeys:bltdest, NSGraphicsContextDestinationAttributeName, nil] autorelease]; 875 }
1001 } 876 if(bltdest && [bltsrc isMemberOfClass:[UIImage class]])
1002 if(bltdest && [bltsrc isMemberOfClass:[NSBitmapImageRep class]]) 877 {
1003 { 878 UIImage *rep = bltsrc;
1004 NSBitmapImageRep *rep = bltsrc; 879 UIImage *image = [[UIImage alloc] initWithCGImage:[rep CGImage]];
1005 UIImage *image = [UIImage alloc]; 880 CGBlendMode op = kCGBlendModeNormal;
1006 SEL siwc = NSSelectorFromString(@"initWithCGImage"); 881
1007 NSCompositingOperation op = DWCompositingOperationSourceOver; 882 if(bltinfo->srcwidth != -1)
1008 883 {
1009 if([image respondsToSelector:siwc]) 884 [image drawInRect:CGRectMake(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height)
1010 { 885 /*fromRect:CGRectMake(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight)*/
1011 DWIMP iiwc = (DWIMP)[image methodForSelector:siwc]; 886 blendMode:op alpha:1.0];
1012 image = iiwc(image, siwc, [rep CGImage], NSZeroSize);
1013 } 887 }
1014 else 888 else
1015 { 889 {
1016 image = [image initWithSize:[rep size]]; 890 [image drawAtPoint:CGPointMake(bltinfo->xdest, bltinfo->ydest)
1017 [image addRepresentation:rep]; 891 /*fromRect:CGRectMake(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height)*/
1018 } 892 blendMode:op alpha:1.0];
1019 if(bltinfo->srcwidth != -1)
1020 {
1021 [image drawInRect:NSMakeRect(bltinfo->xdest, bltinfo->ydest, bltinfo->width, bltinfo->height)
1022 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->srcwidth, bltinfo->srcheight)
1023 operation:op fraction:1.0];
1024 }
1025 else
1026 {
1027 [image drawAtPoint:NSMakePoint(bltinfo->xdest, bltinfo->ydest)
1028 fromRect:NSMakeRect(bltinfo->xsrc, bltinfo->ysrc, bltinfo->width, bltinfo->height)
1029 operation:op fraction:1.0];
1030 } 893 }
1031 [bltsrc release]; 894 [bltsrc release];
1032 [image release]; 895 [image release];
1033 } 896 }
1034 if([bltdest isMemberOfClass:[NSBitmapImageRep class]]) 897 if([bltdest isMemberOfClass:[UIImage class]])
1035 { 898 {
1036 UIGraphicsPopContext(); 899 UIGraphicsPopContext();
1037 } 900 }
1038 free(bltinfo); 901 free(bltinfo);
1039 } 902 }
1041 { 904 {
1042 NSEnumerator *enumerator = [_DWDirtyDrawables objectEnumerator]; 905 NSEnumerator *enumerator = [_DWDirtyDrawables objectEnumerator];
1043 DWRender *rend; 906 DWRender *rend;
1044 907
1045 while (rend = [enumerator nextObject]) 908 while (rend = [enumerator nextObject])
1046 [rend setNeedsDisplay:YES]; 909 [rend setNeedsDisplay];
1047 [_DWDirtyDrawables removeAllObjects]; 910 [_DWDirtyDrawables removeAllObjects];
1048 } 911 }
1049 -(void)doWindowFunc:(id)param 912 -(void)doWindowFunc:(id)param
1050 { 913 {
1051 NSValue *v = (NSValue *)param; 914 NSValue *v = (NSValue *)param;
1062 } 925 }
1063 } 926 }
1064 @end 927 @end
1065 928
1066 DWObject *DWObj; 929 DWObject *DWObj;
1067
1068 /* Subclass for the application class */
1069 @interface DWAppDel : NSObject <UIApplicationDelegate>
1070 {
1071 }
1072 -(UIApplicationTerminateReply)applicationShouldTerminate:(UIApplication *)sender;
1073 @end
1074 930
1075 @interface DWWebView : WKWebView <WKNavigationDelegate> 931 @interface DWWebView : WKWebView <WKNavigationDelegate>
1076 { 932 {
1077 void *userdata; 933 void *userdata;
1078 } 934 }
1108 _event_handler(self, (UIEvent *)params, 19); 964 _event_handler(self, (UIEvent *)params, 19);
1109 } 965 }
1110 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 966 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1111 @end 967 @end
1112 968
1113 @implementation DWAppDel
1114 -(UIApplicationTerminateReply)applicationShouldTerminate:(UIApplication *)sender
1115 {
1116 if(_event_handler(sender, nil, 6) > 0)
1117 return NSTerminateCancel;
1118 return NSTerminateNow;
1119 }
1120 @end
1121
1122 /* Subclass for a top-level window */ 969 /* Subclass for a top-level window */
1123 @interface DWView : DWBox <UIWindowDelegate> 970 @interface DWView : DWBox <UIWindowDelegate>
1124 { 971 {
1125 UIMenu *windowmenu; 972 UIMenu *windowmenu;
1126 CGSize oldsize; 973 CGSize oldsize;
1139 return NO; 986 return NO;
1140 return YES; 987 return YES;
1141 } 988 }
1142 -(void)viewDidMoveToWindow 989 -(void)viewDidMoveToWindow
1143 { 990 {
1144 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:UIWindowDidResizeNotification object:[self window]]; 991 [[UINotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:UIWindowDidResizeNotification object:[self window]];
1145 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:UIWindowDidBecomeMainNotification object:[self window]]; 992 [[UINotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeMain:) name:UIWindowDidBecomeMainNotification object:[self window]];
1146 } 993 }
1147 -(void)dealloc 994 -(void)dealloc
1148 { 995 {
1149 if(windowmenu) 996 if(windowmenu)
1150 { 997 {
1178 } 1025 }
1179 1026
1180 } 1027 }
1181 -(void)windowDidBecomeMain:(id)sender 1028 -(void)windowDidBecomeMain:(id)sender
1182 { 1029 {
1183 if(windowmenu)
1184 {
1185 [DWApp setMainMenu:windowmenu];
1186 }
1187 else
1188 {
1189 [DWApp setMainMenu:DWMainMenu];
1190 }
1191 _event_handler([self window], nil, 13); 1030 _event_handler([self window], nil, 13);
1192 } 1031 }
1193 -(void)setMenu:(UIMenu *)input { windowmenu = input; [windowmenu retain]; } 1032 -(void)setMenu:(UIMenu *)input { windowmenu = input; [windowmenu retain]; }
1194 -(void)menuHandler:(id)sender 1033 -(void)menuHandler:(id)sender
1195 { 1034 {
1204 /* Only perform the delay if this item is a child of the main menu */ 1043 /* Only perform the delay if this item is a child of the main menu */
1205 if([DWApp mainMenu] == menu) 1044 if([DWApp mainMenu] == menu)
1206 [DWObj performSelector:@selector(menuHandler:) withObject:sender afterDelay:0]; 1045 [DWObj performSelector:@selector(menuHandler:) withObject:sender afterDelay:0];
1207 else 1046 else
1208 [DWObj menuHandler:sender]; 1047 [DWObj menuHandler:sender];
1209 _dw_wakeup_app();
1210 } 1048 }
1211 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); } 1049 -(void)mouseDragged:(UIEvent *)theEvent { _event_handler(self, theEvent, 5); }
1212 -(void)mouseMoved:(UIEvent *)theEvent 1050 -(void)mouseMoved:(UIEvent *)theEvent
1213 { 1051 {
1214 id hit = [self hitTest:[theEvent locationInWindow]]; 1052 id hit = [self hitTest:[theEvent locationInWindow]];
1638 -(void *)userdata { return userdata; } 1476 -(void *)userdata { return userdata; }
1639 -(void)setUserdata:(void *)input { userdata = input; } 1477 -(void)setUserdata:(void *)input { userdata = input; }
1640 -(int)pageid { return pageid; } 1478 -(int)pageid { return pageid; }
1641 -(void)setPageid:(int)input { pageid = input; } 1479 -(void)setPageid:(int)input { pageid = input; }
1642 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; } 1480 -(void)dealloc { UserData *root = userdata; _remove_userdata(&root, NULL, TRUE); dw_signal_disconnect_by_window(self); [super dealloc]; }
1643 @end
1644
1645 /* Subclass for a color chooser type */
1646 @interface DWColorChoose : UIColorPanel
1647 {
1648 DWDialog *dialog;
1649 UIColor *pickedcolor;
1650 }
1651 -(void)changeColor:(id)sender;
1652 -(void)setDialog:(DWDialog *)input;
1653 -(DWDialog *)dialog;
1654 @end
1655
1656 @implementation DWColorChoose
1657 -(void)changeColor:(id)sender
1658 {
1659 if(!dialog)
1660 [self close];
1661 else
1662 pickedcolor = [self color];
1663 }
1664 -(BOOL)windowShouldClose:(id)window
1665 {
1666 if(dialog)
1667 {
1668 DWDialog *d = dialog;
1669 dialog = nil;
1670 dw_dialog_dismiss(d, pickedcolor);
1671 }
1672 [self close];
1673 return NO;
1674 }
1675 -(void)setDialog:(DWDialog *)input { dialog = input; }
1676 -(DWDialog *)dialog { return dialog; }
1677 @end
1678
1679 /* Subclass for a font chooser type */
1680 @interface DWFontChoose : UIFontPanel
1681 {
1682 DWDialog *dialog;
1683 }
1684 -(void)setDialog:(DWDialog *)input;
1685 -(DWDialog *)dialog;
1686 @end
1687
1688 @implementation DWFontChoose
1689 -(BOOL)windowShouldClose:(id)window
1690 {
1691 DWDialog *d = dialog; dialog = nil;
1692 UIFont *pickedfont = [DWFontManager selectedFont];
1693 dw_dialog_dismiss(d, pickedfont);
1694 [window orderOut:nil];
1695 return NO;
1696 }
1697 -(void)setDialog:(DWDialog *)input { dialog = input; }
1698 -(DWDialog *)dialog { return dialog; }
1699 @end 1481 @end
1700 1482
1701 /* Subclass for a splitbar type */ 1483 /* Subclass for a splitbar type */
1702 @interface DWSplitBar : NSSplitView <NSSplitViewDelegate> 1484 @interface DWSplitBar : NSSplitView <NSSplitViewDelegate>
1703 { 1485 {
1920 [super drawRect:rect]; 1702 [super drawRect:rect];
1921 1703
1922 if(shouldDrawFocusRing) 1704 if(shouldDrawFocusRing)
1923 { 1705 {
1924 NSSetFocusRingStyle(NSFocusRingOnly); 1706 NSSetFocusRingStyle(NSFocusRingOnly);
1925 CGRectFill(rect); 1707 UIRectFill(rect);
1926 } 1708 }
1927 } 1709 }
1928 @end 1710 @end
1929 1711
1930 /* Subclass for a Container/List type */ 1712 /* Subclass for a Container/List type */
3050 int upymax = 0, upxmax = 0; 2832 int upymax = 0, upxmax = 0;
3051 2833
3052 /* Reset the box sizes */ 2834 /* Reset the box sizes */
3053 thisbox->minwidth = thisbox->minheight = thisbox->usedpadx = thisbox->usedpady = thisbox->pad * 2; 2835 thisbox->minwidth = thisbox->minheight = thisbox->usedpadx = thisbox->usedpady = thisbox->pad * 2;
3054 2836
3055 /* Handle special groupbox case */
3056 if(thisbox->grouphwnd)
3057 {
3058 /* Only calculate the size on the first pass...
3059 * use the cached values on second.
3060 */
3061 if(pass == 1)
3062 {
3063 DWGroupBox *groupbox = thisbox->grouphwnd;
3064 CGSize borderSize = [groupbox borderSize];
3065 CGRect titleRect;
3066
3067 if(borderSize.width == 0 || borderSize.height == 0)
3068 {
3069 borderSize = [groupbox initBorder];
3070 }
3071 /* Get the title size for a more accurate groupbox padding size */
3072 titleRect = [groupbox titleRect];
3073
3074 thisbox->grouppadx = borderSize.width;
3075 thisbox->grouppady = borderSize.height + titleRect.size.height;
3076 }
3077
3078 thisbox->minwidth += thisbox->grouppadx;
3079 thisbox->usedpadx += thisbox->grouppadx;
3080 thisbox->minheight += thisbox->grouppady;
3081 thisbox->usedpady += thisbox->grouppady;
3082 }
3083
3084 /* Count up all the space for all items in the box */ 2837 /* Count up all the space for all items in the box */
3085 for(z=0;z<thisbox->count;z++) 2838 for(z=0;z<thisbox->count;z++)
3086 { 2839 {
3087 int itempad, itemwidth, itemheight; 2840 int itempad, itemwidth, itemheight;
3088 2841
3898 * pad: Number of pixels to pad around the box. 3651 * pad: Number of pixels to pad around the box.
3899 * title: Text to be displayined in the group outline. 3652 * title: Text to be displayined in the group outline.
3900 */ 3653 */
3901 HWND API dw_groupbox_new(int type, int pad, const char *title) 3654 HWND API dw_groupbox_new(int type, int pad, const char *title)
3902 { 3655 {
3903 DWGroupBox *groupbox = [[DWGroupBox alloc] init]; 3656 return dw_box_new(type, pad);
3904 DWBox *thisbox = dw_box_new(type, pad);
3905 Box *box = [thisbox box];
3906
3907 [groupbox setTitle:[NSString stringWithUTF8String:title]];
3908 box->grouphwnd = groupbox;
3909 [groupbox setContentView:thisbox];
3910 [thisbox autorelease];
3911 return groupbox;
3912 } 3657 }
3913 3658
3914 /* 3659 /*
3915 * Create a new scrollable Box to be packed. 3660 * Create a new scrollable Box to be packed.
3916 * Parameters: 3661 * Parameters:
4314 height = 1; 4059 height = 1;
4315 if(hsize && !width) 4060 if(hsize && !width)
4316 width = 1; 4061 width = 1;
4317 4062
4318 /* Fill in the item data appropriately */ 4063 /* Fill in the item data appropriately */
4319 if([object isKindOfClass:[DWBox class]] || [object isMemberOfClass:[DWGroupBox class]]) 4064 if([object isKindOfClass:[DWBox class]])
4320 tmpitem[index].type = TYPEBOX; 4065 tmpitem[index].type = TYPEBOX;
4321 else 4066 else
4322 { 4067 {
4323 if ( width == 0 && hsize == FALSE ) 4068 if ( width == 0 && hsize == FALSE )
4324 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item); 4069 dw_messagebox(funcname, DW_MB_OK|DW_MB_ERROR, "Width and expand Horizonal both unset for box: %x item: %x",box,item);
4397 { 4142 {
4398 object = [parent superview]; 4143 object = [parent superview];
4399 parent = (DWBox *)[object superview]; 4144 parent = (DWBox *)[object superview];
4400 } 4145 }
4401 4146
4402 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) 4147 if([parent isKindOfClass:[DWBox class]])
4403 { 4148 {
4404 id window = [object window]; 4149 id window = [object window];
4405 Box *thisbox = [parent box]; 4150 Box *thisbox = [parent box];
4406 int z, index = -1; 4151 int z, index = -1;
4407 Item *tmpitem = NULL, *thisitem = thisbox->items; 4152 Item *tmpitem = NULL, *thisitem = thisbox->items;
4469 DW_FUNCTION_INIT; 4214 DW_FUNCTION_INIT;
4470 DW_LOCAL_POOL_IN; 4215 DW_LOCAL_POOL_IN;
4471 DWBox *parent = (DWBox *)box; 4216 DWBox *parent = (DWBox *)box;
4472 id object = nil; 4217 id object = nil;
4473 4218
4474 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) 4219 if([parent isKindOfClass:[DWBox class]])
4475 { 4220 {
4476 id window = [parent window]; 4221 id window = [parent window];
4477 Box *thisbox = [parent box]; 4222 Box *thisbox = [parent box];
4478 4223
4479 if(thisbox && index > -1 && index < thisbox->count) 4224 if(thisbox && index > -1 && index < thisbox->count)
5098 NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)]; 4843 NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)];
5099 4844
5100 [cont addRow:newrow]; 4845 [cont addRow:newrow];
5101 [cont reloadData]; 4846 [cont reloadData];
5102 [cont optimize]; 4847 [cont optimize];
5103 [cont setNeedsDisplay:YES]; 4848 [cont setNeedsDisplay];
5104 } 4849 }
5105 DW_FUNCTION_RETURN_NOTHING; 4850 DW_FUNCTION_RETURN_NOTHING;
5106 } 4851 }
5107 4852
5108 /* 4853 /*
5133 NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)]; 4878 NSArray *newrow = [NSArray arrayWithObject:_dw_table_cell_view_new(nil, nstr)];
5134 4879
5135 [cont insertRow:newrow at:pos]; 4880 [cont insertRow:newrow at:pos];
5136 [cont reloadData]; 4881 [cont reloadData];
5137 [cont optimize]; 4882 [cont optimize];
5138 [cont setNeedsDisplay:YES]; 4883 [cont setNeedsDisplay];
5139 } 4884 }
5140 DW_FUNCTION_RETURN_NOTHING; 4885 DW_FUNCTION_RETURN_NOTHING;
5141 } 4886 }
5142 4887
5143 /* 4888 /*
5177 4922
5178 [cont addRow:newrow]; 4923 [cont addRow:newrow];
5179 } 4924 }
5180 [cont reloadData]; 4925 [cont reloadData];
5181 [cont optimize]; 4926 [cont optimize];
5182 [cont setNeedsDisplay:YES]; 4927 [cont setNeedsDisplay];
5183 } 4928 }
5184 DW_FUNCTION_RETURN_NOTHING; 4929 DW_FUNCTION_RETURN_NOTHING;
5185 } 4930 }
5186 4931
5187 /* 4932 /*
5207 { 4952 {
5208 DWContainer *cont = handle; 4953 DWContainer *cont = handle;
5209 4954
5210 [cont clear]; 4955 [cont clear];
5211 [cont reloadData]; 4956 [cont reloadData];
5212 [cont setNeedsDisplay:YES]; 4957 [cont setNeedsDisplay];
5213 } 4958 }
5214 DW_FUNCTION_RETURN_NOTHING; 4959 DW_FUNCTION_RETURN_NOTHING;
5215 } 4960 }
5216 4961
5217 /* 4962 /*
5359 NSTableCellView *cell = [cont getRow:index and:0]; 5104 NSTableCellView *cell = [cont getRow:index and:0];
5360 5105
5361 [[cell textField] setStringValue:nstr]; 5106 [[cell textField] setStringValue:nstr];
5362 [cont reloadData]; 5107 [cont reloadData];
5363 [cont optimize]; 5108 [cont optimize];
5364 [cont setNeedsDisplay:YES]; 5109 [cont setNeedsDisplay];
5365 } 5110 }
5366 } 5111 }
5367 DW_FUNCTION_RETURN_NOTHING; 5112 DW_FUNCTION_RETURN_NOTHING;
5368 } 5113 }
5369 5114
5485 { 5230 {
5486 DWContainer *cont = handle; 5231 DWContainer *cont = handle;
5487 5232
5488 [cont removeRow:index]; 5233 [cont removeRow:index];
5489 [cont reloadData]; 5234 [cont reloadData];
5490 [cont setNeedsDisplay:YES]; 5235 [cont setNeedsDisplay];
5491 } 5236 }
5492 DW_FUNCTION_RETURN_NOTHING; 5237 DW_FUNCTION_RETURN_NOTHING;
5493 } 5238 }
5494 5239
5495 /* 5240 /*
5907 DW_FUNCTION_RESTORE_PARAM1(handle, HWND) 5652 DW_FUNCTION_RESTORE_PARAM1(handle, HWND)
5908 { 5653 {
5909 DW_FUNCTION_INIT; 5654 DW_FUNCTION_INIT;
5910 DWRender *render = (DWRender *)handle; 5655 DWRender *render = (DWRender *)handle;
5911 5656
5912 [render setNeedsDisplay:YES]; 5657 [render setNeedsDisplay];
5913 DW_FUNCTION_RETURN_NOTHING; 5658 DW_FUNCTION_RETURN_NOTHING;
5914 } 5659 }
5915 5660
5916 /* Sets the current foreground drawing color. 5661 /* Sets the current foreground drawing color.
5917 * Parameters: 5662 * Parameters:
6012 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); 5757 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255));
6013 DW_LOCAL_POOL_OUT; 5758 DW_LOCAL_POOL_OUT;
6014 return value; 5759 return value;
6015 } 5760 }
6016 5761
6017 CGContextRef _dw_draw_context(NSBitmapImageRep *image) 5762 CGContextRef _dw_draw_context(UIImage *image)
6018 { 5763 {
6019 return [NSGraphicsContext graphicsContextWithCGContext:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext] flipped:YES]; 5764 return [NSGraphicsContext graphicsContextWithCGContext:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] CGContext] flipped:YES];
6020 } 5765 }
6021 5766
6022 /* Draw a point on a window (preferably a render window). 5767 /* Draw a point on a window (preferably a render window).
6032 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, pixmap, HPIXMAP, x, int, y, int) 5777 DW_FUNCTION_RESTORE_PARAM4(handle, HWND, pixmap, HPIXMAP, x, int, y, int)
6033 { 5778 {
6034 DW_FUNCTION_INIT; 5779 DW_FUNCTION_INIT;
6035 DW_LOCAL_POOL_IN; 5780 DW_LOCAL_POOL_IN;
6036 id image = handle; 5781 id image = handle;
6037 NSBitmapImageRep *bi = nil; 5782 UIImage *bi = nil;
6038 bool bCanDraw = YES; 5783 bool bCanDraw = YES;
6039 5784
6040 if(pixmap) 5785 if(pixmap)
6041 bi = image = (id)pixmap->image; 5786 bi = image = (id)pixmap->image;
6042 else 5787 else
6084 DW_FUNCTION_RESTORE_PARAM6(handle, HWND, pixmap, HPIXMAP, x1, int, y1, int, x2, int, y2, int) 5829 DW_FUNCTION_RESTORE_PARAM6(handle, HWND, pixmap, HPIXMAP, x1, int, y1, int, x2, int, y2, int)
6085 { 5830 {
6086 DW_FUNCTION_INIT; 5831 DW_FUNCTION_INIT;
6087 DW_LOCAL_POOL_IN; 5832 DW_LOCAL_POOL_IN;
6088 id image = handle; 5833 id image = handle;
6089 NSBitmapImageRep *bi = nil; 5834 UIImage *bi = nil;
6090 bool bCanDraw = YES; 5835 bool bCanDraw = YES;
6091 5836
6092 if(pixmap) 5837 if(pixmap)
6093 bi = image = (id)pixmap->image; 5838 bi = image = (id)pixmap->image;
6094 else 5839 else
6137 { 5882 {
6138 DW_FUNCTION_INIT; 5883 DW_FUNCTION_INIT;
6139 DW_LOCAL_POOL_IN; 5884 DW_LOCAL_POOL_IN;
6140 id image = handle; 5885 id image = handle;
6141 NSString *nstr = [ NSString stringWithUTF8String:text ]; 5886 NSString *nstr = [ NSString stringWithUTF8String:text ];
6142 NSBitmapImageRep *bi = nil; 5887 UIImage *bi = nil;
6143 UIFont *font = nil; 5888 UIFont *font = nil;
6144 DWRender *render; 5889 DWRender *render;
6145 bool bCanDraw = YES; 5890 bool bCanDraw = YES;
6146 5891
6147 if(pixmap) 5892 if(pixmap)
6263 DW_FUNCTION_RESTORE_PARAM6(handle, HWND, pixmap, HPIXMAP, flags, int, npoints, int, x, int *, y, int *) 6008 DW_FUNCTION_RESTORE_PARAM6(handle, HWND, pixmap, HPIXMAP, flags, int, npoints, int, x, int *, y, int *)
6264 { 6009 {
6265 DW_FUNCTION_INIT; 6010 DW_FUNCTION_INIT;
6266 DW_LOCAL_POOL_IN; 6011 DW_LOCAL_POOL_IN;
6267 id image = handle; 6012 id image = handle;
6268 NSBitmapImageRep *bi = nil; 6013 UIImage *bi = nil;
6269 bool bCanDraw = YES; 6014 bool bCanDraw = YES;
6270 int z; 6015 int z;
6271 6016
6272 if(pixmap) 6017 if(pixmap)
6273 bi = image = (id)pixmap->image; 6018 bi = image = (id)pixmap->image;
6328 DW_FUNCTION_RESTORE_PARAM7(handle, HWND, pixmap, HPIXMAP, flags, int, x, int, y, int, width, int, height, int) 6073 DW_FUNCTION_RESTORE_PARAM7(handle, HWND, pixmap, HPIXMAP, flags, int, x, int, y, int, width, int, height, int)
6329 { 6074 {
6330 DW_FUNCTION_INIT; 6075 DW_FUNCTION_INIT;
6331 DW_LOCAL_POOL_IN; 6076 DW_LOCAL_POOL_IN;
6332 id image = handle; 6077 id image = handle;
6333 NSBitmapImageRep *bi = nil; 6078 UIImage *bi = nil;
6334 bool bCanDraw = YES; 6079 bool bCanDraw = YES;
6335 6080
6336 if(pixmap) 6081 if(pixmap)
6337 bi = image = (id)pixmap->image; 6082 bi = image = (id)pixmap->image;
6338 else 6083 else
6387 DW_FUNCTION_RESTORE_PARAM9(handle, HWND, pixmap, HPIXMAP, flags, int, xorigin, int, yorigin, int, x1, int, y1, int, x2, int, y2, int) 6132 DW_FUNCTION_RESTORE_PARAM9(handle, HWND, pixmap, HPIXMAP, flags, int, xorigin, int, yorigin, int, x1, int, y1, int, x2, int, y2, int)
6388 { 6133 {
6389 DW_FUNCTION_INIT; 6134 DW_FUNCTION_INIT;
6390 DW_LOCAL_POOL_IN; 6135 DW_LOCAL_POOL_IN;
6391 id image = handle; 6136 id image = handle;
6392 NSBitmapImageRep *bi = nil; 6137 UIImage *bi = nil;
6393 bool bCanDraw = YES; 6138 bool bCanDraw = YES;
6394 6139
6395 if(pixmap) 6140 if(pixmap)
6396 bi = image = (id)pixmap->image; 6141 bi = image = (id)pixmap->image;
6397 else 6142 else
6942 else 6687 else
6943 [[cell textField] setStringValue:text]; 6688 [[cell textField] setStringValue:text];
6944 } 6689 }
6945 else /* Otherwise replace it with a new cell */ 6690 else /* Otherwise replace it with a new cell */
6946 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:column]; 6691 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:column];
6947 [cont setNeedsDisplay:YES]; 6692 [cont setNeedsDisplay];
6948 DW_FUNCTION_RETURN_NOTHING; 6693 DW_FUNCTION_RETURN_NOTHING;
6949 } 6694 }
6950 6695
6951 /* 6696 /*
6952 * Changes an existing item in specified row and column to the given data. 6697 * Changes an existing item in specified row and column to the given data.
7023 if(text) 6768 if(text)
7024 [[cell textField] setStringValue:text]; 6769 [[cell textField] setStringValue:text];
7025 } 6770 }
7026 else /* Otherwise replace it with a new cell */ 6771 else /* Otherwise replace it with a new cell */
7027 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:0]; 6772 [cont editCell:_dw_table_cell_view_new(icon, text) at:(row+lastadd) and:0];
7028 [cont setNeedsDisplay:YES]; 6773 [cont setNeedsDisplay];
7029 DW_FUNCTION_RETURN_NOTHING; 6774 DW_FUNCTION_RETURN_NOTHING;
7030 } 6775 }
7031 6776
7032 /* 6777 /*
7033 * Sets an item in specified row and column to the given data. 6778 * Sets an item in specified row and column to the given data.
7850 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) 7595 if(!(pixmap = calloc(1,sizeof(struct _hpixmap))))
7851 return NULL; 7596 return NULL;
7852 pixmap->width = width; 7597 pixmap->width = width;
7853 pixmap->height = height; 7598 pixmap->height = height;
7854 pixmap->handle = handle; 7599 pixmap->handle = handle;
7855 pixmap->image = [[NSBitmapImageRep alloc] 7600 pixmap->image = [[UIImage alloc]
7856 initWithBitmapDataPlanes:NULL 7601 initWithBitmapDataPlanes:NULL
7857 pixelsWide:width 7602 pixelsWide:width
7858 pixelsHigh:height 7603 pixelsHigh:height
7859 bitsPerSample:8 7604 bitsPerSample:8
7860 samplesPerPixel:4 7605 samplesPerPixel:4
7864 bytesPerRow:0 7609 bytesPerRow:0
7865 bitsPerPixel:0]; 7610 bitsPerPixel:0];
7866 return pixmap; 7611 return pixmap;
7867 } 7612 }
7868 7613
7869 /* Function takes an UIImage and copies it into a flipped NSBitmapImageRep */
7870 void _flip_image(UIImage *tmpimage, NSBitmapImageRep *image, CGSize size)
7871 {
7872 NSCompositingOperation op = DWCompositingOperationSourceOver;
7873 [NSGraphicsContext saveGraphicsState];
7874 [NSGraphicsContext setCurrentContext:_dw_draw_context(image)];
7875 [[[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil] autorelease];
7876 /* Make a new transform */
7877 NSAffineTransform *t = [NSAffineTransform transform];
7878
7879 /* By scaling Y negatively, we effectively flip the image */
7880 [t scaleXBy:1.0 yBy:-1.0];
7881
7882 /* But we also have to translate it back by its height */
7883 [t translateXBy:0.0 yBy:-size.height];
7884
7885 /* Apply the transform */
7886 [t concat];
7887 [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height)
7888 operation:op fraction:1.0];
7889 [NSGraphicsContext restoreGraphicsState];
7890 }
7891
7892 /* 7614 /*
7893 * Creates a pixmap from a file. 7615 * Creates a pixmap from a file.
7894 * Parameters: 7616 * Parameters:
7895 * handle: Window handle the pixmap is associated with. 7617 * handle: Window handle the pixmap is associated with.
7896 * filename: Name of the file, omit extention to have 7618 * filename: Name of the file, omit extention to have
7920 if(!tmpimage) 7642 if(!tmpimage)
7921 { 7643 {
7922 DW_LOCAL_POOL_OUT; 7644 DW_LOCAL_POOL_OUT;
7923 return NULL; 7645 return NULL;
7924 } 7646 }
7925 CGSize size = [tmpimage size]; 7647 pixmap->width = [tmpimage size].width;
7926 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] 7648 pixmap->height = [tmpimage size]size.height;
7927 initWithBitmapDataPlanes:NULL 7649 pixmap->image = tmpimage;
7928 pixelsWide:size.width
7929 pixelsHigh:size.height
7930 bitsPerSample:8
7931 samplesPerPixel:4
7932 hasAlpha:YES
7933 isPlanar:NO
7934 colorSpaceName:NSDeviceRGBColorSpace
7935 bytesPerRow:0
7936 bitsPerPixel:0];
7937 _flip_image(tmpimage, image, size);
7938 pixmap->width = size.width;
7939 pixmap->height = size.height;
7940 pixmap->image = image;
7941 pixmap->handle = handle; 7650 pixmap->handle = handle;
7942 DW_LOCAL_POOL_OUT; 7651 DW_LOCAL_POOL_OUT;
7943 return pixmap; 7652 return pixmap;
7944 } 7653 }
7945 7654
7968 if(!tmpimage) 7677 if(!tmpimage)
7969 { 7678 {
7970 DW_LOCAL_POOL_OUT; 7679 DW_LOCAL_POOL_OUT;
7971 return NULL; 7680 return NULL;
7972 } 7681 }
7973 CGSize size = [tmpimage size]; 7682 pixmap->width = [tmpimage size].width;
7974 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] 7683 pixmap->height = [tmpimage size].height;
7975 initWithBitmapDataPlanes:NULL 7684 pixmap->image = tmpimage;
7976 pixelsWide:size.width
7977 pixelsHigh:size.height
7978 bitsPerSample:8
7979 samplesPerPixel:4
7980 hasAlpha:YES
7981 isPlanar:NO
7982 colorSpaceName:NSDeviceRGBColorSpace
7983 bytesPerRow:0
7984 bitsPerPixel:0];
7985 _flip_image(tmpimage, image, size);
7986 pixmap->width = size.width;
7987 pixmap->height = size.height;
7988 pixmap->image = image;
7989 pixmap->handle = handle; 7685 pixmap->handle = handle;
7990 DW_LOCAL_POOL_OUT; 7686 DW_LOCAL_POOL_OUT;
7991 return pixmap; 7687 return pixmap;
7992 } 7688 }
7993 7689
8025 } 7721 }
8026 7722
8027 NSBundle *bundle = [NSBundle mainBundle]; 7723 NSBundle *bundle = [NSBundle mainBundle];
8028 NSString *respath = [bundle resourcePath]; 7724 NSString *respath = [bundle resourcePath];
8029 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid]; 7725 NSString *filepath = [respath stringByAppendingFormat:@"/%lu.png", resid];
8030 UIImage *temp = [[UIImage alloc] initWithContentsOfFile:filepath]; 7726 UIImage *tmpimage = [[UIImage alloc] initWithContentsOfFile:filepath];
8031 7727
8032 if(temp) 7728 if(temp)
8033 { 7729 {
8034 CGSize size = [temp size]; 7730 pixmap->width = [tmpimage size].width;
8035 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] 7731 pixmap->height = [tmpimage size].height;
8036 initWithBitmapDataPlanes:NULL 7732 pixmap->image = tmpimage;
8037 pixelsWide:size.width
8038 pixelsHigh:size.height
8039 bitsPerSample:8
8040 samplesPerPixel:4
8041 hasAlpha:YES
8042 isPlanar:NO
8043 colorSpaceName:NSDeviceRGBColorSpace
8044 bytesPerRow:0
8045 bitsPerPixel:0];
8046 _flip_image(temp, image, size);
8047 pixmap->width = size.width;
8048 pixmap->height = size.height;
8049 pixmap->image = image;
8050 pixmap->handle = handle; 7733 pixmap->handle = handle;
8051 [temp release];
8052 return pixmap; 7734 return pixmap;
8053 } 7735 }
8054 free(pixmap); 7736 free(pixmap);
8055 DW_LOCAL_POOL_OUT; 7737 DW_LOCAL_POOL_OUT;
8056 return NULL; 7738 return NULL;
8096 */ 7778 */
8097 void API dw_pixmap_destroy(HPIXMAP pixmap) 7779 void API dw_pixmap_destroy(HPIXMAP pixmap)
8098 { 7780 {
8099 if(pixmap) 7781 if(pixmap)
8100 { 7782 {
8101 NSBitmapImageRep *image = (NSBitmapImageRep *)pixmap->image; 7783 UIImage *image = (UIImage *)pixmap->image;
8102 UIFont *font = pixmap->font; 7784 UIFont *font = pixmap->font;
8103 DW_LOCAL_POOL_IN; 7785 DW_LOCAL_POOL_IN;
8104 [image release]; 7786 [image release];
8105 [font release]; 7787 [font release];
8106 free(pixmap); 7788 free(pixmap);
9337 * with information about the packing information regarding object. 9019 * with information about the packing information regarding object.
9338 */ 9020 */
9339 Item *_box_item(id object) 9021 Item *_box_item(id object)
9340 { 9022 {
9341 /* Find the item within the box it is packed into */ 9023 /* Find the item within the box it is packed into */
9342 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[DWGroupBox class]] || [object isKindOfClass:[UIControl class]]) 9024 if([object isKindOfClass:[DWBox class]] || [object isKindOfClass:[UIControl class]])
9343 { 9025 {
9344 DWBox *parent = (DWBox *)[object superview]; 9026 DWBox *parent = (DWBox *)[object superview];
9345 9027
9346 /* Some controls are embedded in scrollviews... 9028 /* Some controls are embedded in scrollviews...
9347 * so get the parent of the scrollview in that case. 9029 * so get the parent of the scrollview in that case.
9350 { 9032 {
9351 object = [parent superview]; 9033 object = [parent superview];
9352 parent = (DWBox *)[object superview]; 9034 parent = (DWBox *)[object superview];
9353 } 9035 }
9354 9036
9355 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) 9037 if([parent isKindOfClass:[DWBox class]])
9356 { 9038 {
9357 Box *thisbox = [parent box]; 9039 Box *thisbox = [parent box];
9358 Item *thisitem = thisbox->items; 9040 Item *thisitem = thisbox->items;
9359 int z; 9041 int z;
9360 9042
9386 { 9068 {
9387 [object lockFocus]; 9069 [object lockFocus];
9388 [font set]; 9070 [font set];
9389 [object unlockFocus]; 9071 [object unlockFocus];
9390 } 9072 }
9391 if([object isMemberOfClass:[DWGroupBox class]])
9392 {
9393 [object setTitleFont:font];
9394 }
9395 else if([object isMemberOfClass:[DWMLE class]]) 9073 else if([object isMemberOfClass:[DWMLE class]])
9396 { 9074 {
9397 DWMLE *mle = object; 9075 DWMLE *mle = object;
9398 9076
9399 [[mle textStorage] setFont:font]; 9077 [[mle textStorage] setFont:font];
9434 char * API dw_window_get_font(HWND handle) 9112 char * API dw_window_get_font(HWND handle)
9435 { 9113 {
9436 id object = _text_handle(handle); 9114 id object = _text_handle(handle);
9437 UIFont *font = nil; 9115 UIFont *font = nil;
9438 9116
9439 if([object isMemberOfClass:[DWGroupBox class]]) 9117 if([object isKindOfClass:[UIControl class]] || [object isMemberOfClass:[DWRender class]])
9440 {
9441 font = [object titleFont];
9442 }
9443 else if([object isKindOfClass:[UIControl class]] || [object isMemberOfClass:[DWRender class]])
9444 { 9118 {
9445 font = [object font]; 9119 font = [object font];
9446 } 9120 }
9447 if(font) 9121 if(font)
9448 { 9122 {
9494 { 9168 {
9495 object = [parent superview]; 9169 object = [parent superview];
9496 parent = (DWBox *)[object superview]; 9170 parent = (DWBox *)[object superview];
9497 } 9171 }
9498 9172
9499 if([parent isKindOfClass:[DWBox class]] || [parent isKindOfClass:[DWGroupBox class]]) 9173 if([parent isKindOfClass:[DWBox class]])
9500 { 9174 {
9501 id window = [object window]; 9175 id window = [object window];
9502 Box *thisbox = [parent box]; 9176 Box *thisbox = [parent box];
9503 int z, index = -1; 9177 int z, index = -1;
9504 Item *tmpitem = NULL, *thisitem = thisbox->items; 9178 Item *tmpitem = NULL, *thisitem = thisbox->items;
9599 [object setTitle:[ NSString stringWithUTF8String:text ]]; 9273 [object setTitle:[ NSString stringWithUTF8String:text ]];
9600 else if([ object isKindOfClass:[ UIControl class ] ]) 9274 else if([ object isKindOfClass:[ UIControl class ] ])
9601 { 9275 {
9602 UIControl *control = object; 9276 UIControl *control = object;
9603 [control setStringValue:[ NSString stringWithUTF8String:text ]]; 9277 [control setStringValue:[ NSString stringWithUTF8String:text ]];
9604 }
9605 else if([object isMemberOfClass:[DWGroupBox class]])
9606 {
9607 DWGroupBox *groupbox = object;
9608 [groupbox setTitle:[NSString stringWithUTF8String:text]];
9609 } 9278 }
9610 else 9279 else
9611 return; 9280 return;
9612 /* If we changed the text... */ 9281 /* If we changed the text... */
9613 Item *item = _box_item(handle); 9282 Item *item = _box_item(handle);
11449 11118
11450 /* If DWApp is uninitialized, initialize it */ 11119 /* If DWApp is uninitialized, initialize it */
11451 void _dw_app_init(void) 11120 void _dw_app_init(void)
11452 { 11121 {
11453 if(!DWApp) 11122 if(!DWApp)
11454 {
11455 DWApp = [UIApplication sharedApplication]; 11123 DWApp = [UIApplication sharedApplication];
11456 DWAppDel *del = [[DWAppDel alloc] init];
11457 [DWApp setDelegate:del];
11458 }
11459 } 11124 }
11460 11125
11461 /* 11126 /*
11462 * Initializes the Dynamic Windows engine. 11127 * Initializes the Dynamic Windows engine.
11463 * Parameters: 11128 * Parameters:
11883 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success. 11548 * DW_ERROR_UNKNOWN on error or DW_ERROR_NONE on success.
11884 */ 11549 */
11885 int API dw_print_run(HPRINT print, unsigned long flags) 11550 int API dw_print_run(HPRINT print, unsigned long flags)
11886 { 11551 {
11887 DWPrint *p = print; 11552 DWPrint *p = print;
11888 NSBitmapImageRep *rep, *rep2; 11553 UIImage *rep, *rep2;
11889 NSPrintInfo *pi; 11554 NSPrintInfo *pi;
11890 NSPrintOperation *po; 11555 NSPrintOperation *po;
11891 HPIXMAP pixmap, pixmap2; 11556 HPIXMAP pixmap, pixmap2;
11892 UIImage *image, *flipped; 11557 UIImage *image, *flipped;
11893 UIImageView *iv; 11558 UIImageView *iv;