Mercurial > dwindows
comparison ios/dw.m @ 2414:5e5fab842901
iOS: Implement dw_font_choose() and dw_color_choose().
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 02 Apr 2021 00:44:17 +0000 |
parents | 8727ad1a19c3 |
children | f33a81fa29e9 |
comparison
equal
deleted
inserted
replaced
2413:8727ad1a19c3 | 2414:5e5fab842901 |
---|---|
866 [super dealloc]; | 866 [super dealloc]; |
867 } | 867 } |
868 -(BOOL)acceptsFirstResponder { return YES; } | 868 -(BOOL)acceptsFirstResponder { return YES; } |
869 @end | 869 @end |
870 | 870 |
871 @interface DWFontPickerDelegate : UIResponder <UIFontPickerViewControllerDelegate> | |
872 { | |
873 DWDialog *dialog; | |
874 } | |
875 -(void)fontPickerViewControllerDidPickFont:(UIFontPickerViewController *)viewController; | |
876 -(void)fontPickerViewControllerDidCancel:(UIFontPickerViewController *)viewController; | |
877 -(void)setDialog:(DWDialog *)newdialog; | |
878 @end | |
879 | |
880 @implementation DWFontPickerDelegate | |
881 -(void)fontPickerViewControllerDidPickFont:(UIFontPickerViewController *)viewController | |
882 { | |
883 if(viewController.selectedFontDescriptor) | |
884 { | |
885 UIFont *font = [UIFont fontWithDescriptor:viewController.selectedFontDescriptor size:9]; | |
886 dw_dialog_dismiss(dialog, font); | |
887 } | |
888 else | |
889 dw_dialog_dismiss(dialog, NULL); | |
890 } | |
891 -(void)fontPickerViewControllerDidCancel:(UIFontPickerViewController *)viewController | |
892 { | |
893 dw_dialog_dismiss(dialog, NULL); | |
894 } | |
895 -(void)setDialog:(DWDialog *)newdialog { dialog = newdialog; } | |
896 @end | |
897 | |
898 @interface DWColorPickerDelegate : UIResponder <UIColorPickerViewControllerDelegate> | |
899 { | |
900 DWDialog *dialog; | |
901 } | |
902 -(void)colorPickerViewControllerDidSelectColor:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)); | |
903 -(void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)); | |
904 -(void)setDialog:(DWDialog *)newdialog; | |
905 @end | |
906 | |
907 @implementation DWColorPickerDelegate | |
908 -(void)colorPickerViewControllerDidSelectColor:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)) | |
909 { | |
910 if([viewController selectedColor]) | |
911 { | |
912 CGFloat red, green, blue; | |
913 [[viewController selectedColor] getRed:&red green:&green blue:&blue alpha:NULL]; | |
914 dw_dialog_dismiss(dialog, DW_UINT_TO_POINTER(DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)))); | |
915 } | |
916 else | |
917 dw_dialog_dismiss(dialog, NULL); | |
918 } | |
919 -(void)colorPickerViewControllerDidFinish:(UIColorPickerViewController *)viewController API_AVAILABLE(ios(14.0)) | |
920 { | |
921 dw_dialog_dismiss(dialog, NULL); | |
922 } | |
923 -(void)setDialog:(DWDialog *)newdialog { dialog = newdialog; } | |
924 @end | |
925 | |
871 @implementation DWObject | 926 @implementation DWObject |
872 -(id)init | 927 -(id)init |
873 { | 928 { |
874 self = [super init]; | 929 self = [super init]; |
875 /* This previously had the code in delayedIinit: */ | 930 /* This previously had the code in delayedIinit: */ |
894 -(void)callBack:(NSPointerArray *)params | 949 -(void)callBack:(NSPointerArray *)params |
895 { | 950 { |
896 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; | 951 void (*mycallback)(NSPointerArray *) = [params pointerAtIndex:0]; |
897 if(mycallback) | 952 if(mycallback) |
898 mycallback(params); | 953 mycallback(params); |
954 } | |
955 -(void)colorPicker:(NSMutableArray *)params | |
956 { | |
957 if (@available(iOS 14.0, *)) | |
958 { | |
959 DWDialog *dialog = dw_dialog_new(NULL); | |
960 UIColorPickerViewController *picker = [[UIColorPickerViewController alloc] init]; | |
961 DWColorPickerDelegate *delegate = [[DWColorPickerDelegate alloc] init]; | |
962 | |
963 /* Unhide our hidden window and make it key */ | |
964 [hiddenWindow setHidden:NO]; | |
965 [hiddenWindow makeKeyAndVisible]; | |
966 [delegate setDialog:dialog]; | |
967 [picker setDelegate:delegate]; | |
968 /* Wait for them to pick a color */ | |
969 [[hiddenWindow rootViewController] presentViewController:picker animated:YES completion:nil]; | |
970 [params addObject:[NSNumber numberWithUnsignedLong:DW_POINTER_TO_UINT(dw_dialog_wait(dialog))]]; | |
971 /* Once the dialog is gone we can rehide our window */ | |
972 [hiddenWindow resignKeyWindow]; | |
973 [hiddenWindow setHidden:YES]; | |
974 [picker release]; | |
975 [delegate release]; | |
976 } else { | |
977 // Fallback on earlier versions | |
978 }; | |
979 } | |
980 | |
981 -(void)fontPicker:(NSPointerArray *)params | |
982 { | |
983 DWDialog *dialog = dw_dialog_new(NULL); | |
984 UIFontPickerViewController *picker = [[UIFontPickerViewController alloc] init]; | |
985 DWFontPickerDelegate *delegate = [[DWFontPickerDelegate alloc] init]; | |
986 UIFont *font; | |
987 | |
988 /* Unhide our hidden window and make it key */ | |
989 [hiddenWindow setHidden:NO]; | |
990 [hiddenWindow makeKeyAndVisible]; | |
991 [delegate setDialog:dialog]; | |
992 [picker setDelegate:delegate]; | |
993 /* Wait for them to pick a color */ | |
994 [[hiddenWindow rootViewController] presentViewController:picker animated:YES completion:nil]; | |
995 font = dw_dialog_wait(dialog); | |
996 /* Once the dialog is gone we can rehide our window */ | |
997 [hiddenWindow resignKeyWindow]; | |
998 [hiddenWindow setHidden:YES]; | |
999 | |
1000 if(font) | |
1001 { | |
1002 NSString *fontname = [font fontName]; | |
1003 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; | |
1004 [params addPointer:strdup([output UTF8String])]; | |
1005 } | |
1006 else | |
1007 [params addPointer:NULL]; | |
1008 [picker release]; | |
1009 [delegate release]; | |
899 } | 1010 } |
900 -(void)messageBox:(NSMutableArray *)params | 1011 -(void)messageBox:(NSMutableArray *)params |
901 { | 1012 { |
902 __block DWDialog *dialog = dw_dialog_new(NULL); | 1013 __block DWDialog *dialog = dw_dialog_new(NULL); |
903 NSInteger iResponse; | 1014 NSInteger iResponse; |
4712 * Returns: | 4823 * Returns: |
4713 * The selected color or the current color if cancelled. | 4824 * The selected color or the current color if cancelled. |
4714 */ | 4825 */ |
4715 unsigned long API dw_color_choose(unsigned long value) | 4826 unsigned long API dw_color_choose(unsigned long value) |
4716 { | 4827 { |
4717 #if 0 /* TODO: Implement this with UIColorPickerViewController */ | 4828 NSMutableArray *params = [NSMutableArray arrayWithObject:[NSNumber numberWithUnsignedLong:value]]; |
4718 /* Create the Color Chooser Dialog class. */ | 4829 unsigned long newcolor = value; |
4719 DWColorChoose *colorDlg; | 4830 |
4720 DWDialog *dialog; | 4831 [DWObj safeCall:@selector(colorPicker:) withObject:params]; |
4721 DW_LOCAL_POOL_IN; | 4832 if([params count] > 1) |
4722 | 4833 newcolor = [[params lastObject] unsignedLongValue]; |
4723 if(![DWColorChoose sharedColorPanelExists]) | 4834 |
4724 { | 4835 return newcolor; |
4725 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | |
4726 /* Set defaults for the dialog. */ | |
4727 [colorDlg setContinuous:NO]; | |
4728 [colorDlg setTarget:colorDlg]; | |
4729 [colorDlg setAction:@selector(changeColor:)]; | |
4730 } | |
4731 else | |
4732 colorDlg = (DWColorChoose *)[DWColorChoose sharedColorPanel]; | |
4733 | |
4734 /* If someone is already waiting just return */ | |
4735 if([colorDlg dialog]) | |
4736 { | |
4737 DW_LOCAL_POOL_OUT; | |
4738 return value; | |
4739 } | |
4740 | |
4741 unsigned long tempcol = _dw_get_color(value); | |
4742 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]; | |
4743 [colorDlg setColor:color]; | |
4744 | |
4745 dialog = dw_dialog_new(colorDlg); | |
4746 [colorDlg setDialog:dialog]; | |
4747 [colorDlg makeKeyAndOrderFront:nil]; | |
4748 | |
4749 /* Wait for them to pick a color */ | |
4750 color = (UIColor *)dw_dialog_wait(dialog); | |
4751 | |
4752 /* Figure out the value of what they returned */ | |
4753 CGFloat red, green, blue; | |
4754 [color getRed:&red green:&green blue:&blue alpha:NULL]; | |
4755 value = DW_RGB((int)(red * 255), (int)(green *255), (int)(blue *255)); | |
4756 DW_LOCAL_POOL_OUT; | |
4757 #endif | |
4758 return value; | |
4759 } | 4836 } |
4760 | 4837 |
4761 CGContextRef _dw_draw_context(UIImage *image, bool antialiased) | 4838 CGContextRef _dw_draw_context(UIImage *image, bool antialiased) |
4762 { | 4839 { |
4763 CGContextRef context; | 4840 CGContextRef context; |
6298 * However we will make floating windows that hide | 6375 * However we will make floating windows that hide |
6299 * when the application is deactivated to simulate | 6376 * when the application is deactivated to simulate |
6300 * similar behavior. | 6377 * similar behavior. |
6301 */ | 6378 */ |
6302 DWMDI *mdi = [[[DWMDI alloc] init] retain]; | 6379 DWMDI *mdi = [[[DWMDI alloc] init] retain]; |
6303 /* [mdi setTag:cid]; Why doesn't this work? */ | 6380 [mdi setTag:cid]; |
6304 return mdi; | 6381 return mdi; |
6305 } | 6382 } |
6306 | 6383 |
6307 /* | 6384 /* |
6308 * Creates a splitbar window (widget) with given parameters. | 6385 * Creates a splitbar window (widget) with given parameters. |
6944 DW_FUNCTION_RESTORE_PARAM1(DW_UNUSED(cid), ULONG) | 7021 DW_FUNCTION_RESTORE_PARAM1(DW_UNUSED(cid), ULONG) |
6945 { | 7022 { |
6946 DW_FUNCTION_INIT; | 7023 DW_FUNCTION_INIT; |
6947 DWWebView *web = [[[DWWebView alloc] init] retain]; | 7024 DWWebView *web = [[[DWWebView alloc] init] retain]; |
6948 web.navigationDelegate = web; | 7025 web.navigationDelegate = web; |
6949 /* [web setTag:cid]; Why doesn't this work? */ | 7026 [web setTag:cid]; |
6950 DW_FUNCTION_RETURN_THIS(web); | 7027 DW_FUNCTION_RETURN_THIS(web); |
6951 } | 7028 } |
6952 | 7029 |
6953 /* | 7030 /* |
6954 * Returns the current X and Y coordinates of the mouse pointer. | 7031 * Returns the current X and Y coordinates of the mouse pointer. |
7610 else if([object isMemberOfClass:[DWBox class]]) | 7687 else if([object isMemberOfClass:[DWBox class]]) |
7611 { | 7688 { |
7612 DWBox *box = object; | 7689 DWBox *box = object; |
7613 | 7690 |
7614 [box setColor:_back]; | 7691 [box setColor:_back]; |
7692 [box setBackgroundColor:bg]; | |
7615 } | 7693 } |
7616 else if([object isKindOfClass:[UITableView class]]) | 7694 else if([object isKindOfClass:[UITableView class]]) |
7617 { | 7695 { |
7618 DWContainer *cont = handle; | 7696 DWContainer *cont = handle; |
7619 | 7697 |
7787 * Returns: | 7865 * Returns: |
7788 * A malloced buffer with the selected font or NULL on error. | 7866 * A malloced buffer with the selected font or NULL on error. |
7789 */ | 7867 */ |
7790 char * API dw_font_choose(const char *currfont) | 7868 char * API dw_font_choose(const char *currfont) |
7791 { | 7869 { |
7792 __block UIFont *font = nil; | 7870 NSPointerArray *params = [[NSPointerArray pointerArrayWithOptions:NSPointerFunctionsOpaqueMemory] retain]; |
7793 UIFontPickerViewController* picker = [[UIFontPickerViewController alloc] init]; | 7871 char *font = NULL; |
7794 /*TODO: Add handler for accepting the font fontPickerViewControllerDidPickFont */ | 7872 |
7795 /* Wait for them to pick a color */ | 7873 [params addPointer:(void *)currfont]; |
7796 [picker presentViewController:picker animated:YES completion:nil]; | 7874 [DWObj safeCall:@selector(fontPicker:) withObject:params]; |
7797 [picker release]; | 7875 if([params count] > 1) |
7798 | 7876 font = [params pointerAtIndex:1]; |
7799 if(font) | 7877 |
7800 { | 7878 return font; |
7801 NSString *fontname = [font fontName]; | |
7802 NSString *output = [NSString stringWithFormat:@"%d.%s", (int)[font pointSize], [fontname UTF8String]]; | |
7803 return strdup([output UTF8String]); | |
7804 } | |
7805 return NULL; | |
7806 } | 7879 } |
7807 | 7880 |
7808 /* Internal function to return a pointer to an item struct | 7881 /* Internal function to return a pointer to an item struct |
7809 * with information about the packing information regarding object. | 7882 * with information about the packing information regarding object. |
7810 */ | 7883 */ |