From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver] / OSX / XScreenSaverConfigSheet.m
index 51c13af4c6ca1fd7842e13469bc63635cef2dff9..eaa5add13cb4da1e07cf56c3f84c5763a4b5379b 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 2006-2016 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 2006-2017 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -457,9 +457,10 @@ static char *anchorize (const char *url);
   NSString *text = [self stripTags: html];
   CGSize s = r.size;
   s.height = 999999;
-  s = [text sizeWithFont: font
-            constrainedToSize: s
-            lineBreakMode:NSLineBreakByWordWrapping];
+  s = [text boundingRectWithSize:s
+                         options:NSStringDrawingUsesLineFragmentOrigin
+                      attributes:@{NSFontAttributeName: font}
+                         context:nil].size;
   r.size.height = s.height;
 # endif
 
@@ -921,6 +922,7 @@ unwrap (NSString *text)
       eolp = YES;
     } else if ([s characterAtIndex:0] == ' ' ||
                [s hasPrefix:@"Copyright "] ||
+               [s hasPrefix:@"https://"] ||
                [s hasPrefix:@"http://"]) {
       // don't unwrap if the following line begins with whitespace,
       // or with the word "Copyright", or if it begins with a URL.
@@ -966,12 +968,16 @@ boldify (NSText *nstext)
 static char *
 anchorize (const char *url)
 {
-  const char *wiki = "http://en.wikipedia.org/wiki/";
-  const char *math = "http://mathworld.wolfram.com/";
-  if (!strncmp (wiki, url, strlen(wiki))) {
+  const char *wiki1 =  "http://en.wikipedia.org/wiki/";
+  const char *wiki2 = "https://en.wikipedia.org/wiki/";
+  const char *math1 =  "http://mathworld.wolfram.com/";
+  const char *math2 = "https://mathworld.wolfram.com/";
+  if (!strncmp (wiki1, url, strlen(wiki1)) ||
+      !strncmp (wiki2, url, strlen(wiki2))) {
     char *anchor = (char *) malloc (strlen(url) * 3 + 10);
     strcpy (anchor, "Wikipedia: \"");
-    const char *in = url + strlen(wiki);
+    const char *in = url + strlen(!strncmp (wiki1, url, strlen(wiki1))
+                                  ? wiki1 : wiki2);
     char *out = anchor + strlen(anchor);
     while (*in) {
       if (*in == '_') {
@@ -997,10 +1003,12 @@ anchorize (const char *url)
     *out = 0;
     return anchor;
 
-  } else if (!strncmp (math, url, strlen(math))) {
+  } else if (!strncmp (math1, url, strlen(math1)) ||
+             !strncmp (math2, url, strlen(math2))) {
     char *anchor = (char *) malloc (strlen(url) * 3 + 10);
     strcpy (anchor, "MathWorld: \"");
-    const char *start = url + strlen(wiki);
+    const char *start = url + strlen(!strncmp (math1, url, strlen(math1))
+                                     ? math1 : math2);
     const char *in = start;
     char *out = anchor + strlen(anchor);
     while (*in) {
@@ -1040,7 +1048,7 @@ hreffify (NSText *nstext)
   NSString *text = [nstext text];
 # endif
 
-  int L = [text length];
+  NSUInteger L = [text length];
   NSRange start;               // range is start-of-search to end-of-string
   start.location = 0;
   start.length = L;
@@ -1048,7 +1056,14 @@ hreffify (NSText *nstext)
 
     // Find the beginning of a URL...
     //
-    NSRange r2 = [text rangeOfString:@"http://" options:0 range:start];
+    NSRange r2 = [text rangeOfString: @"http://" options:0 range:start];
+    NSRange r3 = [text rangeOfString:@"https://" options:0 range:start];
+    if ((r2.location == NSNotFound &&
+         r3.location != NSNotFound) ||
+        (r2.location != NSNotFound &&
+         r3.location != NSNotFound &&
+         r3.location < r2.location))
+      r2 = r3;
     if (r2.location == NSNotFound)
       break;
 
@@ -1058,9 +1073,9 @@ hreffify (NSText *nstext)
 
     // Find the end of a URL (whitespace or EOF)...
     //
-    NSRange r3 = [text rangeOfCharacterFromSet:
-                         [NSCharacterSet whitespaceAndNewlineCharacterSet]
-                       options:0 range:start];
+    r3 = [text rangeOfCharacterFromSet:
+                 [NSCharacterSet whitespaceAndNewlineCharacterSet]
+               options:0 range:start];
     if (r3.location == NSNotFound)    // EOF
       r3.location = L, r3.length = 0;
 
@@ -1101,7 +1116,7 @@ hreffify (NSText *nstext)
 
     free (anchor);
 
-    int L2 = [text length];  // might have changed
+    NSUInteger L2 = [text length];  // might have changed
     start.location -= (L - L2);
     L = L2;
   }
@@ -2058,7 +2073,7 @@ do_file_selector (NSTextField *txt, BOOL dirs_p)
   [panel setCanChooseFiles:!dirs_p];
   [panel setCanChooseDirectories:dirs_p];
 
-  int result = [panel runModal];
+  NSInteger result = [panel runModal];
   if (result == NSOKButton) {
     NSArray *files = [panel URLs];
     NSString *file = ([files count] > 0 ? [[files objectAtIndex:0] path] : @"");
@@ -2085,7 +2100,7 @@ find_text_field_of_button (NSButton *button)
 {
   NSView *parent = [button superview];
   NSArray *kids = [parent subviews];
-  int nkids = [kids count];
+  NSUInteger nkids = [kids count];
   int i;
   NSTextField *f = 0;
   for (i = 0; i < nkids; i++) {
@@ -2544,7 +2559,7 @@ static NSView *
 last_child (NSView *parent)
 {
   NSArray *kids = [parent subviews];
-  int nkids = [kids count];
+  NSUInteger nkids = [kids count];
   if (nkids == 0)
     return 0;
   else
@@ -2694,8 +2709,8 @@ static void
 layout_group (NSView *group, BOOL horiz_p)
 {
   NSArray *kids = [group subviews];
-  int nkids = [kids count];
-  int i;
+  NSUInteger nkids = [kids count];
+  NSUInteger i;
   double maxx = 0, miny = 0;
   for (i = 0; i < nkids; i++) {
     NSView *kid = [kids objectAtIndex:i];
@@ -2826,10 +2841,10 @@ fix_contentview_size (NSView *parent)
 {
   NSRect f;
   NSArray *kids = [parent subviews];
-  int nkids = [kids count];
+  NSUInteger nkids = [kids count];
   NSView *text = 0;  // the NSText at the bottom of the window
   double maxx = 0, miny = 0;
-  int i;
+  NSUInteger i;
 
   /* Find the size of the rectangle taken up by each of the children
      except the final "NSText" child.
@@ -3214,6 +3229,7 @@ wrap_with_buttons (NSWindow *window, NSView *panel)
   CGFloat max = 0;
   for (NSArray *a2 in a) {
     NSString *s = [a2 objectAtIndex:0];
+    // #### sizeWithFont deprecated as of iOS 7; use boundingRectWithSize.
     CGSize r = [s sizeWithFont:f];
     if (r.width > max) max = r.width;
   }
@@ -3252,7 +3268,7 @@ wrap_with_buttons (NSWindow *window, NSView *panel)
   [[self navigationItem] 
     setRightBarButtonItem: [[UIBarButtonItem alloc]
                              initWithTitle: @"Reset to Defaults"
-                             style: UIBarButtonItemStyleBordered
+                             style: UIBarButtonItemStylePlain
                              target:self
                              action:@selector(resetAction:)]];
   NSString *s = saver_name;
@@ -3524,14 +3540,15 @@ wrap_with_buttons (NSWindow *window, NSView *panel)
         [mid setFrame:r];
 
         if (top) {
-          r.size = [[top text] sizeWithFont:[top font]
-                               constrainedToSize:
-                                 CGSizeMake (ww - LEFT_MARGIN*2, 100000)
-                               lineBreakMode:[top lineBreakMode]];
 # ifdef LABEL_ABOVE_SLIDER
           // Top label goes above, flush center/top.
           r.origin.x = (ww - r.size.width) / 2;
           r.origin.y = 4;
+          // #### sizeWithFont deprecated as of iOS 7; use boundingRectWithSize.
+          r.size = [[top text] sizeWithFont:[top font]
+                               constrainedToSize:
+                                 CGSizeMake (ww - LEFT_MARGIN*2, 100000)
+                               lineBreakMode:[top lineBreakMode]];
 # else  // !LABEL_ABOVE_SLIDER
           // Label goes on the left.
           r.origin.x = LEFT_MARGIN;
@@ -3543,24 +3560,21 @@ wrap_with_buttons (NSWindow *window, NSView *panel)
         }
 
         // Left label goes under control, flush left/bottom.
-        r.size = [[left text] sizeWithFont:[left font]
-                              constrainedToSize:
-                                CGSizeMake(ww - LEFT_MARGIN*2, 100000)
-                              lineBreakMode:[left lineBreakMode]];
-        r.origin.x = [mid frame].origin.x;
-        r.origin.y = hh - r.size.height - 4;
-        [left setFrame:r];
+        left.frame = CGRectMake([mid frame].origin.x, hh - 4,
+                                ww - LEFT_MARGIN*2, 100000);
+        [left sizeToFit];
+        r = left.frame;
+        r.origin.y -= r.size.height;
+        left.frame = r;
 
         // Right label goes under control, flush right/bottom.
-        r = [right frame];
-        r.size = [[right text] sizeWithFont:[right font]
-                               constrainedToSize:
-                                 CGSizeMake(ww - LEFT_MARGIN*2, 1000000)
-                               lineBreakMode:[right lineBreakMode]];
-        r.origin.x = ([mid frame].origin.x + [mid frame].size.width -
-                      r.size.width);
-        r.origin.y = [left frame].origin.y;
-        [right setFrame:r];
+        right.frame =
+          CGRectMake([mid frame].origin.x + [mid frame].size.width,
+                     [left frame].origin.y, ww - LEFT_MARGIN*2, 1000000);
+        [right sizeToFit];
+        r = right.frame;
+        r.origin.x -= r.size.width;
+        right.frame = r;
 
         // Make a box and put the labels and slider into it.
         r.origin.x = 0;