comparison mac/dw.m @ 1936:ebde5ef666a6

Fixes many deprecation warnings building for MacOS 10.14.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 20 Jun 2019 21:15:15 +0000
parents 994e2360dbb2
children 5a88fff43d99
comparison
equal deleted inserted replaced
1935:994e2360dbb2 1936:ebde5ef666a6
53 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain]; 53 #define DW_LOCAL_POOL_OUT if(localpool) [localpool drain];
54 54
55 /* Handle deprecation of several constants in 10.10... 55 /* Handle deprecation of several constants in 10.10...
56 * the replacements are not available in earlier versions. 56 * the replacements are not available in earlier versions.
57 */ 57 */
58 #if defined(MAC_OS_X_VERSION_10_9) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_9) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED)) 58 #if defined(MAC_OS_X_VERSION_10_10) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_10) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED))
59 #define DWModalResponseOK NSModalResponseOK 59 #define DWModalResponseOK NSModalResponseOK
60 #define DWModalResponseCancel NSModalResponseCancel 60 #define DWModalResponseCancel NSModalResponseCancel
61 #define DWPaperOrientationPortrait NSPaperOrientationPortrait 61 #define DWPaperOrientationPortrait NSPaperOrientationPortrait
62 #define DWWebView WKWebView
63 #define BUILDING_FOR_YOSEMITE
62 #else 64 #else
63 #define DWModalResponseOK NSOKButton 65 #define DWModalResponseOK NSOKButton
64 #define DWModalResponseCancel NSCancelButton 66 #define DWModalResponseCancel NSCancelButton
65 #define DWPaperOrientationPortrait NSPortraitOrientation 67 #define DWPaperOrientationPortrait NSPortraitOrientation
68 #define DWWebView WebView
69 #endif
70
71 /* Handle deprecation of several constants in 10.12...
72 * the replacements are not available in earlier versions.
73 */
74 #if defined(MAC_OS_X_VERSION_10_12) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED))
75 #define DWButtonTypeSwitch NSButtonTypeSwitch
76 #define DWButtonTypeRadio NSButtonTypeRadio
77 #define DWButtonTypeMomentaryPushIn NSButtonTypeMomentaryPushIn
78 #define DWBezelStyleRegularSquare NSBezelStyleRegularSquare
79 #define DWBezelStyleRounded NSBezelStyleRounded
80 #define BUILDING_FOR_SIERRA
81 #else
82 #define DWButtonTypeSwitch NSSwitchButton
83 #define DWButtonTypeRadio NSRadioButton
84 #define DWButtonTypeMomentaryPushIn NSMomentaryPushInButton
85 #define DWBezelStyleRegularSquare NSRegularSquareBezelStyle
86 #define DWBezelStyleRounded NSRoundedBezelStyle
87 #endif
88
89 /* Handle deprecation of several constants in 10.13...
90 * the replacements are not available in earlier versions.
91 */
92 #if defined(MAC_OS_X_VERSION_10_13) && ((defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_13) || !defined(MAC_OS_X_VERSION_MAX_ALLOWED))
93 #define DWControlStateValueOff NSControlStateValueOff
94 #define DWControlStateValueOn NSControlStateValueOn
95 #define BUILDING_FOR_HIGH_SIERRA
96 #else
97 #define DWControlStateValueOff NSOffState
98 #define DWControlStateValueOn NSOnState
66 #endif 99 #endif
67 100
68 unsigned long _colors[] = 101 unsigned long _colors[] =
69 { 102 {
70 0x00000000, /* 0 black */ 103 0x00000000, /* 0 black */
594 -(void)menuHandler:(id)param 627 -(void)menuHandler:(id)param
595 { 628 {
596 DWMenuItem *item = param; 629 DWMenuItem *item = param;
597 if([item check]) 630 if([item check])
598 { 631 {
599 if([item state] == NSOnState) 632 if([item state] == DWControlStateValueOn)
600 [item setState:NSOffState]; 633 [item setState:DWControlStateValueOff];
601 else 634 else
602 [item setState:NSOnState]; 635 [item setState:DWControlStateValueOn];
603 } 636 }
604 _event_handler(param, nil, 8); 637 _event_handler(param, nil, 8);
605 } 638 }
606 -(void)doBitBlt:(id)param 639 -(void)doBitBlt:(id)param
607 { 640 {
1067 -(void *)userdata { return userdata; } 1100 -(void *)userdata { return userdata; }
1068 -(void)setUserdata:(void *)input { userdata = input; } 1101 -(void)setUserdata:(void *)input { userdata = input; }
1069 -(void)buttonClicked:(id)sender 1102 -(void)buttonClicked:(id)sender
1070 { 1103 {
1071 _event_handler(self, nil, 8); 1104 _event_handler(self, nil, 8);
1072 if([self buttonType] == NSRadioButton) 1105 if([self buttonType] == DWButtonTypeRadio)
1073 { 1106 {
1074 DWBox *viewbox = [self parent]; 1107 DWBox *viewbox = [self parent];
1075 Box *thisbox = [viewbox box]; 1108 Box *thisbox = [viewbox box];
1076 int z; 1109 int z;
1077 1110
1083 1116
1084 if([object isMemberOfClass:[DWButton class]]) 1117 if([object isMemberOfClass:[DWButton class]])
1085 { 1118 {
1086 DWButton *button = object; 1119 DWButton *button = object;
1087 1120
1088 if(button != self && [button buttonType] == NSRadioButton) 1121 if(button != self && [button buttonType] == DWButtonTypeRadio)
1089 { 1122 {
1090 [button setState:NSOffState]; 1123 [button setState:NSOffState];
1091 } 1124 }
1092 } 1125 }
1093 } 1126 }
1126 -(void)keyDown:(NSEvent *)theEvent 1159 -(void)keyDown:(NSEvent *)theEvent
1127 { 1160 {
1128 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0]; 1161 unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
1129 if(vk == VK_RETURN || vk == VK_SPACE) 1162 if(vk == VK_RETURN || vk == VK_SPACE)
1130 { 1163 {
1131 if(buttonType == NSSwitchButton) 1164 if(buttonType == DWButtonTypeSwitch)
1132 [self setState:([self state] ? NSOffState : NSOnState)]; 1165 [self setState:([self state] ? DWControlStateValueOff : DWControlStateValueOn)];
1133 else if(buttonType == NSRadioButton) 1166 else if(buttonType == DWButtonTypeRadio)
1134 [self setState:NSOnState]; 1167 [self setState:DWControlStateValueOn];
1135 [self buttonClicked:self]; 1168 [self buttonClicked:self];
1136 } 1169 }
1137 else 1170 else
1138 { 1171 {
1139 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]]; 1172 [self interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
3714 * be converted to text. 3747 * be converted to text.
3715 */ 3748 */
3716 char *dw_clipboard_get_text() 3749 char *dw_clipboard_get_text()
3717 { 3750 {
3718 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; 3751 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
3719 NSString *str = [pasteboard stringForType:NSStringPboardType]; 3752 NSString *str = [pasteboard stringForType:NSPasteboardTypeString];
3720 if(str != nil) 3753 if(str != nil)
3721 { 3754 {
3722 return strdup([ str UTF8String ]); 3755 return strdup([ str UTF8String ]);
3723 } 3756 }
3724 return NULL; 3757 return NULL;
3738 { 3771 {
3739 IMP icc = [pasteboard methodForSelector:scc]; 3772 IMP icc = [pasteboard methodForSelector:scc];
3740 icc(pasteboard, scc); 3773 icc(pasteboard, scc);
3741 } 3774 }
3742 3775
3743 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType]; 3776 [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSPasteboardTypeString];
3744 } 3777 }
3745 3778
3746 3779
3747 /* 3780 /*
3748 * Allocates and initializes a dialog struct. 3781 * Allocates and initializes a dialog struct.
3958 /* Handle all the different button types */ 3991 /* Handle all the different button types */
3959 if([ object isKindOfClass:[ NSButton class ] ]) 3992 if([ object isKindOfClass:[ NSButton class ] ])
3960 { 3993 {
3961 switch([object buttonType]) 3994 switch([object buttonType])
3962 { 3995 {
3963 case NSSwitchButton: 3996 case DWButtonTypeSwitch:
3964 case NSRadioButton: 3997 case DWButtonTypeRadio:
3965 extrawidth = 24; 3998 extrawidth = 24;
3966 extraheight = 4; 3999 extraheight = 4;
3967 nsstr = [object title]; 4000 nsstr = [object title];
3968 break; 4001 break;
3969 default: 4002 default:
4513 [button setTitle:[ NSString stringWithUTF8String:text ]]; 4546 [button setTitle:[ NSString stringWithUTF8String:text ]];
4514 } 4547 }
4515 [button setTarget:button]; 4548 [button setTarget:button];
4516 [button setAction:@selector(buttonClicked:)]; 4549 [button setAction:@selector(buttonClicked:)];
4517 [button setTag:cid]; 4550 [button setTag:cid];
4518 [button setButtonType:NSMomentaryPushInButton]; 4551 [button setButtonType:DWButtonTypeMomentaryPushIn];
4519 #ifdef MAC_OS_X_VERSION_10_12 4552 #ifdef MAC_OS_X_VERSION_10_12
4520 [button setBezelStyle:NSBezelStyleRegularSquare]; 4553 [button setBezelStyle:NSBezelStyleRegularSquare];
4521 #else 4554 #else
4522 [button setBezelStyle:NSThickerSquareBezelStyle]; 4555 [button setBezelStyle:NSThickerSquareBezelStyle];
4523 #endif 4556 #endif
4537 * id: An ID to be used with dw_window_from_id() or 0L. 4570 * id: An ID to be used with dw_window_from_id() or 0L.
4538 */ 4571 */
4539 HWND API dw_button_new(char *text, ULONG cid) 4572 HWND API dw_button_new(char *text, ULONG cid)
4540 { 4573 {
4541 DWButton *button = _button_new(text, cid); 4574 DWButton *button = _button_new(text, cid);
4542 [button setButtonType:NSMomentaryPushInButton]; 4575 [button setButtonType:DWButtonTypeMomentaryPushIn];
4543 [button setBezelStyle:NSRoundedBezelStyle]; 4576 [button setBezelStyle:DWBezelStyleRounded];
4544 [button setImagePosition:NSNoImage]; 4577 [button setImagePosition:NSNoImage];
4545 #ifdef MAC_OS_X_VERSION_10_12 4578 #ifdef MAC_OS_X_VERSION_10_12
4546 [button setAlignment:NSTextAlignmentCenter]; 4579 [button setAlignment:NSTextAlignmentCenter];
4547 #else 4580 #else
4548 [button setAlignment:NSCenterTextAlignment]; 4581 [button setAlignment:NSCenterTextAlignment];
4746 * id: An ID to be used with dw_window_from_id() or 0L. 4779 * id: An ID to be used with dw_window_from_id() or 0L.
4747 */ 4780 */
4748 HWND API dw_radiobutton_new(char *text, ULONG cid) 4781 HWND API dw_radiobutton_new(char *text, ULONG cid)
4749 { 4782 {
4750 DWButton *button = _button_new(text, cid); 4783 DWButton *button = _button_new(text, cid);
4751 [button setButtonType:NSRadioButton]; 4784 [button setButtonType:DWButtonTypeRadio];
4752 return button; 4785 return button;
4753 } 4786 }
4754 4787
4755 /* 4788 /*
4756 * Create a new slider window (widget) to be packed. 4789 * Create a new slider window (widget) to be packed.
4921 * id: An ID to be used with dw_window_from_id() or 0L. 4954 * id: An ID to be used with dw_window_from_id() or 0L.
4922 */ 4955 */
4923 HWND API dw_checkbox_new(char *text, ULONG cid) 4956 HWND API dw_checkbox_new(char *text, ULONG cid)
4924 { 4957 {
4925 DWButton *button = _button_new(text, cid); 4958 DWButton *button = _button_new(text, cid);
4926 [button setButtonType:NSSwitchButton]; 4959 [button setButtonType:DWButtonTypeSwitch];
4927 [button setBezelStyle:NSRegularSquareBezelStyle]; 4960 [button setBezelStyle:DWBezelStyleRegularSquare];
4928 return button; 4961 return button;
4929 } 4962 }
4930 4963
4931 /* 4964 /*
4932 * Returns the state of the checkbox. 4965 * Returns the state of the checkbox.
4952 void API dw_checkbox_set(HWND handle, int value) 4985 void API dw_checkbox_set(HWND handle, int value)
4953 { 4986 {
4954 DWButton *button = handle; 4987 DWButton *button = handle;
4955 if(value) 4988 if(value)
4956 { 4989 {
4957 [button setState:NSOnState]; 4990 [button setState:DWControlStateValueOn];
4958 } 4991 }
4959 else 4992 else
4960 { 4993 {
4961 [button setState:NSOffState]; 4994 [button setState:DWControlStateValueOff];
4962 } 4995 }
4963 4996
4964 } 4997 }
4965 4998
4966 /* Common code for containers and listboxes */ 4999 /* Common code for containers and listboxes */
8098 * handle: Handle to the window. 8131 * handle: Handle to the window.
8099 * action: One of the DW_HTML_* constants. 8132 * action: One of the DW_HTML_* constants.
8100 */ 8133 */
8101 void API dw_html_action(HWND handle, int action) 8134 void API dw_html_action(HWND handle, int action)
8102 { 8135 {
8103 WebView *html = handle; 8136 DWWebView *html = handle;
8104 switch(action) 8137 switch(action)
8105 { 8138 {
8106 case DW_HTML_GOBACK: 8139 case DW_HTML_GOBACK:
8107 [html goBack]; 8140 [html goBack];
8108 break; 8141 break;
8133 * Returns: 8166 * Returns:
8134 * 0 on success. 8167 * 0 on success.
8135 */ 8168 */
8136 int API dw_html_raw(HWND handle, char *string) 8169 int API dw_html_raw(HWND handle, char *string)
8137 { 8170 {
8138 WebView *html = handle; 8171 DWWebView *html = handle;
8172 #ifdef BUILDING_FOR_YOSEMITE
8173 [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
8174 #else
8139 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil]; 8175 [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
8176 #endif
8140 return 0; 8177 return 0;
8141 } 8178 }
8142 8179
8143 /* 8180 /*
8144 * Render file or web page in the embedded HTML widget.. 8181 * Render file or web page in the embedded HTML widget..
8149 * Returns: 8186 * Returns:
8150 * 0 on success. 8187 * 0 on success.
8151 */ 8188 */
8152 int API dw_html_url(HWND handle, char *url) 8189 int API dw_html_url(HWND handle, char *url)
8153 { 8190 {
8154 WebView *html = handle; 8191 DWWebView *html = handle;
8192 #ifdef BUILDING_FOR_YOSEMITE
8193 [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
8194 #else
8155 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]]; 8195 [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
8196 #endif
8156 return 0; 8197 return 0;
8157 } 8198 }
8158 8199
8159 /* 8200 /*
8160 * Create a new HTML window (widget) to be packed. 8201 * Create a new HTML window (widget) to be packed.
8165 */ 8206 */
8166 HWND API dw_html_new(unsigned long cid) 8207 HWND API dw_html_new(unsigned long cid)
8167 { 8208 {
8168 int _locked_by_me = FALSE; 8209 int _locked_by_me = FALSE;
8169 DW_MUTEX_LOCK; 8210 DW_MUTEX_LOCK;
8170 WebView *web = [[WebView alloc] init]; 8211 DWWebView *web = [[DWWebView alloc] init];
8171 /* [web setTag:cid]; Why doesn't this work? */ 8212 /* [web setTag:cid]; Why doesn't this work? */
8172 DW_MUTEX_UNLOCK; 8213 DW_MUTEX_UNLOCK;
8173 return web; 8214 return web;
8174 } 8215 }
8175 8216
8368 if(check) 8409 if(check)
8369 { 8410 {
8370 [item setCheck:YES]; 8411 [item setCheck:YES];
8371 if(flags & DW_MIS_CHECKED) 8412 if(flags & DW_MIS_CHECKED)
8372 { 8413 {
8373 [item setState:NSOnState]; 8414 [item setState:DWControlStateValueOn];
8374 } 8415 }
8375 } 8416 }
8376 if(flags & DW_MIS_DISABLED) 8417 if(flags & DW_MIS_DISABLED)
8377 { 8418 {
8378 [item setEnabled:NO]; 8419 [item setEnabled:NO];
8403 8444
8404 if(menuitem != nil) 8445 if(menuitem != nil)
8405 { 8446 {
8406 if(check) 8447 if(check)
8407 { 8448 {
8408 [menuitem setState:NSOnState]; 8449 [menuitem setState:DWControlStateValueOn];
8409 } 8450 }
8410 else 8451 else
8411 { 8452 {
8412 [menuitem setState:NSOffState]; 8453 [menuitem setState:DWControlStateValueOff];
8413 } 8454 }
8414 } 8455 }
8415 } 8456 }
8416 8457
8417 /* 8458 /*
8450 8491
8451 if(menuitem != nil) 8492 if(menuitem != nil)
8452 { 8493 {
8453 if(state & DW_MIS_CHECKED) 8494 if(state & DW_MIS_CHECKED)
8454 { 8495 {
8455 [menuitem setState:NSOnState]; 8496 [menuitem setState:DWControlStateValueOn];
8456 } 8497 }
8457 else if(state & DW_MIS_UNCHECKED) 8498 else if(state & DW_MIS_UNCHECKED)
8458 { 8499 {
8459 [menuitem setState:NSOffState]; 8500 [menuitem setState:DWControlStateValueOff];
8460 } 8501 }
8461 if(state & DW_MIS_ENABLED) 8502 if(state & DW_MIS_ENABLED)
8462 { 8503 {
8463 [menuitem setEnabled:YES]; 8504 [menuitem setEnabled:YES];
8464 } 8505 }
8967 else if([object isMemberOfClass:[DWMenuItem class]]) 9008 else if([object isMemberOfClass:[DWMenuItem class]])
8968 { 9009 {
8969 if(mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED)) 9010 if(mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED))
8970 { 9011 {
8971 if(style & DW_MIS_CHECKED) 9012 if(style & DW_MIS_CHECKED)
8972 [object setState:NSOnState]; 9013 [object setState:DWControlStateValueOn];
8973 else if(style & DW_MIS_UNCHECKED) 9014 else if(style & DW_MIS_UNCHECKED)
8974 [object setState:NSOffState]; 9015 [object setState:DWControlStateValueOff];
8975 } 9016 }
8976 if(mask & (DW_MIS_ENABLED | DW_MIS_DISABLED)) 9017 if(mask & (DW_MIS_ENABLED | DW_MIS_DISABLED))
8977 { 9018 {
8978 if(style & DW_MIS_ENABLED) 9019 if(style & DW_MIS_ENABLED)
8979 [object setEnabled:YES]; 9020 [object setEnabled:YES];