changeset 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 eb488c379969
files mac/dw.m
diffstat 1 files changed, 74 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/mac/dw.m	Fri Jul 20 03:10:44 2018 +0000
+++ b/mac/dw.m	Thu Jun 20 21:15:15 2019 +0000
@@ -55,14 +55,47 @@
 /* Handle deprecation of several constants in 10.10...
  * the replacements are not available in earlier versions.
  */
-#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))
+#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))
 #define DWModalResponseOK NSModalResponseOK
 #define DWModalResponseCancel NSModalResponseCancel
 #define DWPaperOrientationPortrait NSPaperOrientationPortrait
+#define DWWebView WKWebView
+#define BUILDING_FOR_YOSEMITE
 #else
 #define DWModalResponseOK NSOKButton
 #define DWModalResponseCancel NSCancelButton
 #define DWPaperOrientationPortrait NSPortraitOrientation
+#define DWWebView WebView
+#endif
+
+/* Handle deprecation of several constants in 10.12...
+ * the replacements are not available in earlier versions.
+ */
+#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))
+#define DWButtonTypeSwitch NSButtonTypeSwitch
+#define DWButtonTypeRadio NSButtonTypeRadio
+#define DWButtonTypeMomentaryPushIn NSButtonTypeMomentaryPushIn
+#define DWBezelStyleRegularSquare NSBezelStyleRegularSquare
+#define DWBezelStyleRounded NSBezelStyleRounded
+#define BUILDING_FOR_SIERRA
+#else
+#define DWButtonTypeSwitch NSSwitchButton
+#define DWButtonTypeRadio NSRadioButton
+#define DWButtonTypeMomentaryPushIn NSMomentaryPushInButton
+#define DWBezelStyleRegularSquare NSRegularSquareBezelStyle
+#define DWBezelStyleRounded NSRoundedBezelStyle
+#endif
+
+/* Handle deprecation of several constants in 10.13...
+ * the replacements are not available in earlier versions.
+ */
+#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))
+#define DWControlStateValueOff NSControlStateValueOff
+#define DWControlStateValueOn NSControlStateValueOn
+#define BUILDING_FOR_HIGH_SIERRA
+#else
+#define DWControlStateValueOff NSOffState
+#define DWControlStateValueOn NSOnState
 #endif
 
 unsigned long _colors[] =
@@ -596,10 +629,10 @@
     DWMenuItem *item = param;
     if([item check])
     {
-        if([item state] == NSOnState)
-            [item setState:NSOffState];
+        if([item state] == DWControlStateValueOn)
+            [item setState:DWControlStateValueOff];
         else
-            [item setState:NSOnState];
+            [item setState:DWControlStateValueOn];
     }
     _event_handler(param, nil, 8);
 }
@@ -1069,7 +1102,7 @@
 -(void)buttonClicked:(id)sender
 {
     _event_handler(self, nil, 8);
-    if([self buttonType] == NSRadioButton)
+    if([self buttonType] == DWButtonTypeRadio)
     {
         DWBox *viewbox = [self parent];
         Box *thisbox = [viewbox box];
@@ -1085,7 +1118,7 @@
                 {
                     DWButton *button = object;
 
-                    if(button != self && [button buttonType] == NSRadioButton)
+                    if(button != self && [button buttonType] == DWButtonTypeRadio)
                     {
                         [button setState:NSOffState];
                     }
@@ -1128,10 +1161,10 @@
     unichar vk = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
     if(vk == VK_RETURN || vk == VK_SPACE)
     {
-        if(buttonType == NSSwitchButton)
-            [self setState:([self state] ? NSOffState : NSOnState)];
-        else if(buttonType == NSRadioButton)
-            [self setState:NSOnState];
+        if(buttonType == DWButtonTypeSwitch)
+            [self setState:([self state] ? DWControlStateValueOff : DWControlStateValueOn)];
+        else if(buttonType == DWButtonTypeRadio)
+            [self setState:DWControlStateValueOn];
         [self buttonClicked:self];
     }
     else
@@ -3716,7 +3749,7 @@
 char *dw_clipboard_get_text()
 {
     NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
-    NSString *str = [pasteboard stringForType:NSStringPboardType];
+    NSString *str = [pasteboard stringForType:NSPasteboardTypeString];
     if(str != nil)
     {
         return strdup([ str UTF8String ]);
@@ -3740,7 +3773,7 @@
         icc(pasteboard, scc);
     }
 
-    [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSStringPboardType];
+    [pasteboard setString:[ NSString stringWithUTF8String:str ] forType:NSPasteboardTypeString];
 }
 
 
@@ -3960,8 +3993,8 @@
     {
         switch([object buttonType])
         {
-            case NSSwitchButton:
-            case NSRadioButton:
+            case DWButtonTypeSwitch:
+            case DWButtonTypeRadio:
                 extrawidth = 24;
                 extraheight = 4;
                 nsstr = [object title];
@@ -4515,7 +4548,7 @@
     [button setTarget:button];
     [button setAction:@selector(buttonClicked:)];
     [button setTag:cid];
-    [button setButtonType:NSMomentaryPushInButton];
+    [button setButtonType:DWButtonTypeMomentaryPushIn];
 #ifdef MAC_OS_X_VERSION_10_12
     [button setBezelStyle:NSBezelStyleRegularSquare];
 #else
@@ -4539,8 +4572,8 @@
 HWND API dw_button_new(char *text, ULONG cid)
 {
     DWButton *button = _button_new(text, cid);
-    [button setButtonType:NSMomentaryPushInButton];
-    [button setBezelStyle:NSRoundedBezelStyle];
+    [button setButtonType:DWButtonTypeMomentaryPushIn];
+    [button setBezelStyle:DWBezelStyleRounded];
     [button setImagePosition:NSNoImage];
 #ifdef MAC_OS_X_VERSION_10_12
     [button setAlignment:NSTextAlignmentCenter];
@@ -4748,7 +4781,7 @@
 HWND API dw_radiobutton_new(char *text, ULONG cid)
 {
     DWButton *button = _button_new(text, cid);
-    [button setButtonType:NSRadioButton];
+    [button setButtonType:DWButtonTypeRadio];
     return button;
 }
 
@@ -4923,8 +4956,8 @@
 HWND API dw_checkbox_new(char *text, ULONG cid)
 {
     DWButton *button = _button_new(text, cid);
-    [button setButtonType:NSSwitchButton];
-    [button setBezelStyle:NSRegularSquareBezelStyle];
+    [button setButtonType:DWButtonTypeSwitch];
+    [button setBezelStyle:DWBezelStyleRegularSquare];
     return button;
 }
 
@@ -4954,11 +4987,11 @@
     DWButton *button = handle;
     if(value)
     {
-        [button setState:NSOnState];
+        [button setState:DWControlStateValueOn];
     }
     else
     {
-        [button setState:NSOffState];
+        [button setState:DWControlStateValueOff];
     }
 
 }
@@ -8100,7 +8133,7 @@
  */
 void API dw_html_action(HWND handle, int action)
 {
-    WebView *html = handle;
+    DWWebView *html = handle;
     switch(action)
     {
         case DW_HTML_GOBACK:
@@ -8135,8 +8168,12 @@
  */
 int API dw_html_raw(HWND handle, char *string)
 {
-    WebView *html = handle;
+    DWWebView *html = handle;
+#ifdef BUILDING_FOR_YOSEMITE
+    [html loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
+#else
     [[html mainFrame] loadHTMLString:[ NSString stringWithUTF8String:string ] baseURL:nil];
+#endif
     return 0;
 }
 
@@ -8151,8 +8188,12 @@
  */
 int API dw_html_url(HWND handle, char *url)
 {
-    WebView *html = handle;
+    DWWebView *html = handle;
+#ifdef BUILDING_FOR_YOSEMITE
+    [html loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
+#else
     [[html mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[ NSString stringWithUTF8String:url ]]]];
+#endif
     return 0;
 }
 
@@ -8167,7 +8208,7 @@
 {
     int _locked_by_me = FALSE;
     DW_MUTEX_LOCK;
-    WebView *web = [[WebView alloc] init];
+    DWWebView *web = [[DWWebView alloc] init];
     /* [web setTag:cid]; Why doesn't this work? */
     DW_MUTEX_UNLOCK;
     return web;
@@ -8370,7 +8411,7 @@
             [item setCheck:YES];
             if(flags & DW_MIS_CHECKED)
             {
-                [item setState:NSOnState];
+                [item setState:DWControlStateValueOn];
             }
         }
         if(flags & DW_MIS_DISABLED)
@@ -8405,11 +8446,11 @@
     {
         if(check)
         {
-            [menuitem setState:NSOnState];
+            [menuitem setState:DWControlStateValueOn];
         }
         else
         {
-            [menuitem setState:NSOffState];
+            [menuitem setState:DWControlStateValueOff];
         }
     }
 }
@@ -8452,11 +8493,11 @@
     {
         if(state & DW_MIS_CHECKED)
         {
-            [menuitem setState:NSOnState];
+            [menuitem setState:DWControlStateValueOn];
         }
         else if(state & DW_MIS_UNCHECKED)
         {
-            [menuitem setState:NSOffState];
+            [menuitem setState:DWControlStateValueOff];
         }
         if(state & DW_MIS_ENABLED)
         {
@@ -8969,9 +9010,9 @@
         if(mask & (DW_MIS_CHECKED | DW_MIS_UNCHECKED))
         {
             if(style & DW_MIS_CHECKED)
-                [object setState:NSOnState];
+                [object setState:DWControlStateValueOn];
             else if(style & DW_MIS_UNCHECKED)
-                [object setState:NSOffState];
+                [object setState:DWControlStateValueOff];
         }
         if(mask & (DW_MIS_ENABLED | DW_MIS_DISABLED))
         {