source: trunk/Cocoa/F-Script Anywhere/Source/NSString-NJRExtensions.m@ 646

Last change on this file since 646 was 153, checked in by Nicholas Riley, 21 years ago

Integrates SCPatch and mach_inject; unfinished, buggy.

File size: 1.6 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#ifndef NSAppKitVersionNumber10_2
17#define NSAppKitVersionNumber10_2 663
18#endif
19
20@implementation NSString (NJRExtensions)
21
22- (NSAttributedString *)asAttributedStringTruncatedToWidth:(float)width {
23 NSMutableString *text = [self mutableCopy];
24 NSAttributedString *s = [NSAttributedString alloc];
25 NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
26 if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_2) {
27 [ps setLineBreakMode: NSLineBreakByTruncatingMiddle];
28 } else {
29 // Mac OS X versions earlier than 10.3 don't implement NSLineBreakByTruncatingMiddle; fake it
30 OSStatus err;
31 err = TruncateThemeText((CFMutableStringRef) text, kThemeViewsFont,
32 kThemeStateActive, width, truncMiddle, NULL);
33 if (err != noErr) FSALog(@"-[NSString asAttributedStringTruncatedToWidth:]: TruncateThemeText failed with error %d", err);
34 [ps setLineBreakMode: NSLineBreakByClipping];
35 }
36 s = [s initWithString: text attributes:
37 [NSDictionary dictionaryWithObjectsAndKeys: ps, NSParagraphStyleAttributeName, nil]];
38 [text release];
39 [ps release];
40 return [s autorelease];
41}
42
43@end
Note: See TracBrowser for help on using the repository browser.