source: releases/F-Script Anywhere/1.1.2a1/Source/NSString-NJRExtensions.m@ 339

Last change on this file since 339 was 7, checked in by Nicholas Riley, 22 years ago

F-Script Anywhere 1.1.2a1

File size: 2.1 KB
Line 
1//
2// NSString-NJRExtensions.m
3// HostLauncher
4//
5// Created by nicholas on Wed Oct 31 2001.
6// Copyright (c) 2001 Nicholas Riley. All rights reserved.
7//
8
9// This is a reduced version of the version I use in HostLauncher, for use in F-Script Anywhere.
10// It removes methods that rely on OmniFoundation.
11// Don't forget to apply changes forward!
12
13#import <Carbon/Carbon.h>
14#import "NSString-NJRExtensions.h"
15
16@implementation NSString (NJRExtensions)
17
18- (NSAttributedString *)asAttributedStringTruncatedToWidth:(float)width {
19 NSMutableString *text = [self mutableCopy];
20 NSAttributedString *s = [NSAttributedString alloc];
21 NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
22 OSStatus err;
23 /*
24 NSString *fs;
25 Str255 font;
26 SInt16 size; // label font is 10, pushbutton font 13, views font is 12!
27 err = GetThemeFont(kThemeViewsFont, smUnicodeScript, font, &size, NULL);
28 fs = CFStringCreateWithPascalString(kCFAllocatorDefault, font, CFStringGetSystemEncoding());
29 NSLog(@"Theme font: %@ %d", fs, size);
30 */
31 err = TruncateThemeText((CFMutableStringRef) text, kThemeViewsFont,
32 kThemeStateActive, width, truncMiddle, NULL);
33 /* // There's a workaround for a 10.1 bug in Connections' awakeFromNib: the initial
34 // column size is wrong, until you resize the window. Here's how to demonstrate the bug:
35 { static float lastWidth = 0; // XXX debug
36 if (lastWidth != width) {
37 lastWidth = width;
38 NSLog(@"Got width %f", width);
39 }
40 }
41 */
42 if (err != noErr) FSALog(@"-[NSString asAttributedStringTruncatedToWidth:]: TruncateThemeText failed with error %d", err);
43 // XXX Should be able to skip the above by using NSLineBreakByTruncatingMiddle,
44 // XXX but OS X 10.1 doesn't implement it yet.
45 [ps setLineBreakMode: NSLineBreakByClipping];
46 s = [s initWithString: text attributes:
47 [NSDictionary dictionaryWithObjectsAndKeys: ps, NSParagraphStyleAttributeName, nil]];
48 [text release];
49 [ps release];
50 return [s autorelease];
51}
52
53@end
Note: See TracBrowser for help on using the repository browser.