X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=OSX%2FXScreenSaverConfigSheet.m;h=5a6484366df0ca2bb7ca0bd1b5d22ac0c72f9e96;hb=7edd66e6bd3209013ee059819747b10b5835635b;hp=46b73dee9a1a6e56ccfcab3321d43018e0a71476;hpb=019de959b265701cd0c3fccbb61f2b69f06bf9ee;p=xscreensaver diff --git a/OSX/XScreenSaverConfigSheet.m b/OSX/XScreenSaverConfigSheet.m index 46b73dee..5a648436 100644 --- a/OSX/XScreenSaverConfigSheet.m +++ b/OSX/XScreenSaverConfigSheet.m @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2006-2013 Jamie Zawinski +/* xscreensaver, Copyright (c) 2006-2014 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -228,10 +228,13 @@ typedef enum { SimpleXMLCommentKind, webView = [[UIWebView alloc] init]; webView.delegate = self; webView.dataDetectorTypes = UIDataDetectorTypeNone; - self. autoresizingMask = (UIViewAutoresizingFlexibleWidth | - UIViewAutoresizingFlexibleHeight); - webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | - UIViewAutoresizingFlexibleHeight); + self. autoresizingMask = UIViewAutoresizingNone; // we do it manually + webView.autoresizingMask = UIViewAutoresizingNone; + webView.scrollView.scrollEnabled = NO; + webView.scrollView.bounces = NO; + webView.opaque = NO; + [webView setBackgroundColor:[UIColor clearColor]]; + [self addSubview: webView]; [self setHTML: h]; return self; @@ -270,6 +273,7 @@ typedef enum { SimpleXMLCommentKind, " font-family: \"%@\";" " font-size: %.4fpx;" // Must be "px", not "pt"! " line-height: %.4fpx;" // And no spaces before it. + " -webkit-text-size-adjust: none;" "}" "\n//-->\n" "" @@ -282,6 +286,7 @@ typedef enum { SimpleXMLCommentKind, [font pointSize], [font lineHeight], h]; + [webView stopLoading]; [webView loadHTMLString:h2 baseURL:[NSURL URLWithString:@""]]; } @@ -290,6 +295,8 @@ static char *anchorize (const char *url); - (void) setText: (NSString *)t { + t = [t stringByTrimmingCharactersInSet:[NSCharacterSet + whitespaceCharacterSet]]; t = [t stringByReplacingOccurrencesOfString:@"&" withString:@"&"]; t = [t stringByReplacingOccurrencesOfString:@"<" withString:@"<"]; t = [t stringByReplacingOccurrencesOfString:@">" withString:@">"]; @@ -313,6 +320,12 @@ static char *anchorize (const char *url); } h = [NSString stringWithFormat: @"%@ %@", h, s]; } + + h = [h stringByReplacingOccurrencesOfString:@"

" withString:@"

"]; + h = [h stringByReplacingOccurrencesOfString:@"

" withString:@"

"]; + h = [h stringByTrimmingCharactersInSet:[NSCharacterSet + whitespaceAndNewlineCharacterSet]]; + [self setHTML: h]; } @@ -336,8 +349,6 @@ static char *anchorize (const char *url); r.origin.x = 0; r.origin.y = 0; [webView setFrame: r]; - [self setHTML: html]; - [webView reload]; } @@ -345,6 +356,7 @@ static char *anchorize (const char *url); { NSString *result = @""; + // Add newlines. str = [str stringByReplacingOccurrencesOfString:@"

" withString:@"

" options:NSCaseInsensitiveSearch @@ -354,12 +366,25 @@ static char *anchorize (const char *url); options:NSCaseInsensitiveSearch range:NSMakeRange(0, [str length])]; + // Remove HREFs. for (NSString *s in [str componentsSeparatedByString: @"<"]) { NSRange r = [s rangeOfString:@">"]; if (r.length > 0) s = [s substringFromIndex: r.location + r.length]; result = [result stringByAppendingString: s]; } + + // Compress internal horizontal whitespace. + str = result; + result = @""; + for (NSString *s in [str componentsSeparatedByCharactersInSet: + [NSCharacterSet whitespaceCharacterSet]]) { + if ([result length] == 0) + result = s; + else if ([s length] > 0) + result = [NSString stringWithFormat: @"%@ %@", result, s]; + } + return result; } @@ -370,8 +395,15 @@ static char *anchorize (const char *url); /* It would be sensible to just ask the UIWebView how tall the page is, instead of hoping that NSString and UIWebView measure fonts and do - wrapping in exactly the same way, but I can't make that work. - Maybe because it loads async? + wrapping in exactly the same way, but since UIWebView is asynchronous, + we'd have to wait for the document to load first, e.g.: + + - Start the document loading; + - return a default height to use for the UITableViewCell; + - wait for the webViewDidFinishLoad delegate method to fire; + - then force the UITableView to reload, to pick up the new height. + + But I couldn't make that work. */ # if 0 r.size.height = [[webView @@ -385,11 +417,6 @@ static char *anchorize (const char *url); s = [text sizeWithFont: font constrainedToSize: s lineBreakMode:NSLineBreakByWordWrapping]; - - // GAAAH. Add one more line, or the UIWebView is still scrollable! - // The text is sized right, but it lets you scroll it up anyway. - s.height += [font pointSize]; - r.size.height = s.height; # endif @@ -796,9 +823,8 @@ unwrap (NSString *text) // Unwrap lines: delete \n but do not delete \n\n. // NSArray *lines = [text componentsSeparatedByString:@"\n"]; - int nlines = [lines count]; + NSUInteger i, nlines = [lines count]; BOOL eolp = YES; - int i; text = @"\n"; // start with one blank line @@ -1034,7 +1060,7 @@ hreffify (NSText *nstext) - (void) parseAttrs:(NSMutableDictionary *)dict node:(NSXMLNode *)node { NSArray *attrs = [(NSXMLElement *) node attributes]; - int n = [attrs count]; + NSUInteger n = [attrs count]; int i; // For each key in the dictionary, fill in the dict with the corresponding @@ -1330,6 +1356,8 @@ hreffify (NSText *nstext) [self placeChild:lab on:parent]; # else // USE_IPHONE [lab setTextAlignment: NSTextAlignmentRight]; + // Sometimes rotation screws up truncation. + [lab setLineBreakMode:NSLineBreakByClipping]; [self placeChild:lab on:parent right:(label ? YES : NO)]; # endif // USE_IPHONE @@ -1364,6 +1392,10 @@ hreffify (NSText *nstext) // Make right label be same height as slider. rect.size.height = [slider frame].size.height; [lab setFrame:rect]; +# ifdef USE_IPHONE + // Sometimes rotation screws up truncation. + [lab setLineBreakMode:NSLineBreakByClipping]; +# endif [self placeChild:lab on:parent right:YES]; [lab release]; } @@ -1495,7 +1527,7 @@ set_menu_item_object (NSMenuItem *item, NSObject *obj) - (void) makeOptionMenu:(NSXMLNode *)node on:(NSView *)parent { NSArray *children = [node children]; - int i, count = [children count]; + NSUInteger i, count = [children count]; if (count <= 0) { NSAssert1 (0, @"no menu items in \"%@\"", [node name]); @@ -1678,7 +1710,7 @@ set_menu_item_object (NSMenuItem *item, NSObject *obj) // Store the items for this picker in the picker_values array. // This is so fucking stupid. - int menu_number = [pref_keys count] - 1; + unsigned long menu_number = [pref_keys count] - 1; if (! picker_values) picker_values = [[NSMutableArray arrayWithCapacity:menu_number] retain]; while ([picker_values count] <= menu_number) @@ -1691,8 +1723,8 @@ set_menu_item_object (NSMenuItem *item, NSObject *obj) [self placeSeparator]; i = 0; - for (NSArray *item in items) { - RadioButton *b = [[RadioButton alloc] initWithIndex:i + for (__attribute__((unused)) NSArray *item in items) { + RadioButton *b = [[RadioButton alloc] initWithIndex: (int)i items:items]; [b setLineBreakMode:NSLineBreakByTruncatingHead]; [b setFont:[NSFont boldSystemFontOfSize: FONT_SIZE]]; @@ -1715,7 +1747,7 @@ set_menu_item_object (NSMenuItem *item, NSObject *obj) { NSString *text = nil; NSArray *children = [node children]; - int i, count = [children count]; + NSUInteger i, count = [children count]; for (i = 0; i < count; i++) { NSXMLNode *child = [children objectAtIndex:i]; @@ -2432,6 +2464,9 @@ find_text_field_of_button (NSButton *button) [self placeChild:box on:parent]; + [group release]; + [box release]; + # endif // !USE_IPHONE } @@ -2486,7 +2521,25 @@ last_child (NSView *parent) # else // USE_IPHONE - // Controls is an array of arrays of the controls, divided into sections. + /* Controls is an array of arrays of the controls, divided into sections. + Each hgroup / vgroup gets a nested array, too, e.g.: + + [ [ [