mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
A few copy/paste fixes
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@8466 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2b9210fc47
commit
a6a81013c4
2 changed files with 92 additions and 65 deletions
|
@ -56,32 +56,35 @@ static NSMutableSet* fontsUsed = nil;
|
|||
/* Fonts that are preferred by the application */
|
||||
NSArray *_preferredFonts;
|
||||
|
||||
/* Class for fonts */
|
||||
static Class NSFontClass = 0;
|
||||
|
||||
static NSUserDefaults *defaults = nil;
|
||||
|
||||
NSFont*
|
||||
getNSFont(NSString* key, NSString* defaultFontName, float fontSize)
|
||||
{
|
||||
NSString* fontName;
|
||||
|
||||
fontName = [[NSUserDefaults standardUserDefaults] objectForKey: key];
|
||||
fontName = [defaults objectForKey: key];
|
||||
if (fontName == nil)
|
||||
fontName = defaultFontName;
|
||||
|
||||
if (fontSize == 0)
|
||||
{
|
||||
fontSize = [[NSUserDefaults standardUserDefaults]
|
||||
floatForKey: [NSString stringWithFormat: @"%@Size", key]];
|
||||
fontSize = [defaults floatForKey:
|
||||
[NSString stringWithFormat: @"%@Size", key]];
|
||||
if (fontSize == 0)
|
||||
fontSize = 12;
|
||||
}
|
||||
|
||||
return [NSFont fontWithName: fontName size: fontSize];
|
||||
return [NSFontClass fontWithName: fontName size: fontSize];
|
||||
}
|
||||
|
||||
void
|
||||
setNSFont(NSString* key, NSFont* font)
|
||||
{
|
||||
NSUserDefaults* standardDefaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
[standardDefaults setObject: [font fontName] forKey: key];
|
||||
[defaults setObject: [font fontName] forKey: key];
|
||||
|
||||
systemCacheNeedsRecomputing = YES;
|
||||
boldSystemCacheNeedsRecomputing = YES;
|
||||
|
@ -89,7 +92,7 @@ setNSFont(NSString* key, NSFont* font)
|
|||
userFixedCacheNeedsRecomputing = YES;
|
||||
|
||||
/* Don't care about errors*/
|
||||
[standardDefaults synchronize];
|
||||
[defaults synchronize];
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -97,12 +100,17 @@ setNSFont(NSString* key, NSFont* font)
|
|||
//
|
||||
+ (void) initialize
|
||||
{
|
||||
static BOOL initialized = NO;
|
||||
|
||||
if (!initialized)
|
||||
if (self == [NSFont class])
|
||||
{
|
||||
initialized = YES;
|
||||
fontsUsed = [NSMutableSet new];
|
||||
NSFontClass = self;
|
||||
if (fontsUsed == nil)
|
||||
{
|
||||
fontsUsed = [NSMutableSet new];
|
||||
}
|
||||
if (defaults == nil)
|
||||
{
|
||||
defaults = RETAIN([NSUserDefaults standardUserDefaults]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -328,17 +336,19 @@ setNSFont(NSString* key, NSFont* font)
|
|||
|
||||
- (id) initWithName: (NSString*)name matrix: (const float*)fontMatrix
|
||||
{
|
||||
[fontsUsed addObject: name];
|
||||
fontName = RETAIN(name);
|
||||
fontName = [name copy];
|
||||
[fontsUsed addObject: fontName];
|
||||
memcpy(matrix, fontMatrix, sizeof(matrix));
|
||||
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: name matrix: fontMatrix]);
|
||||
fontInfo = RETAIN([GSFontInfo fontInfoForFontName: fontName
|
||||
matrix: fontMatrix]);
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (NSFont*) fontWithName: (NSString*)name
|
||||
matrix: (const float*)fontMatrix
|
||||
{
|
||||
return AUTORELEASE([[NSFont alloc] initWithName: name matrix: fontMatrix]);
|
||||
return AUTORELEASE([[NSFontClass alloc] initWithName: name
|
||||
matrix: fontMatrix]);
|
||||
}
|
||||
|
||||
+ (NSFont*) fontWithName: (NSString*)name
|
||||
|
@ -573,6 +583,11 @@ setNSFont(NSString* key, NSFont* font)
|
|||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (Class) classForCoder
|
||||
{
|
||||
return NSFontClass;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeObject: fontName];
|
||||
|
|
|
@ -446,9 +446,11 @@ static NSNotificationCenter *nc;
|
|||
{
|
||||
if ([_textStorage length] > 0)
|
||||
{
|
||||
NSFont *font = [_textStorage attribute: NSFontAttributeName
|
||||
atIndex: 0
|
||||
effectiveRange: NULL];
|
||||
NSFont *font;
|
||||
|
||||
font = [_textStorage attribute: NSFontAttributeName
|
||||
atIndex: 0
|
||||
effectiveRange: NULL];
|
||||
if (font != nil)
|
||||
{
|
||||
return font;
|
||||
|
@ -575,15 +577,19 @@ static NSNotificationCenter *nc;
|
|||
*/
|
||||
- (NSColor*) textColor
|
||||
{
|
||||
/* FIXME */
|
||||
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||
if ([_textStorage length] > 0)
|
||||
{
|
||||
NSColor *color;
|
||||
|
||||
if (aRange.location != NSNotFound)
|
||||
return [_textStorage attribute: NSForegroundColorAttributeName
|
||||
atIndex: aRange.location
|
||||
effectiveRange: NULL];
|
||||
else
|
||||
return [_typingAttributes objectForKey: NSForegroundColorAttributeName];
|
||||
color = [_textStorage attribute: NSForegroundColorAttributeName
|
||||
atIndex: 0
|
||||
effectiveRange: NULL];
|
||||
if (color != nil)
|
||||
{
|
||||
return color;
|
||||
}
|
||||
}
|
||||
return [_typingAttributes objectForKey: NSForegroundColorAttributeName];
|
||||
}
|
||||
|
||||
- (void) setTextColor: (NSColor*)color
|
||||
|
@ -1567,6 +1573,8 @@ static NSNotificationCenter *nc;
|
|||
{
|
||||
ASSIGN (_typingAttributes, (NSMutableDictionary*)dict);
|
||||
}
|
||||
[self updateFontPanel];
|
||||
[self updateRuler];
|
||||
}
|
||||
|
||||
- (NSDictionary*) typingAttributes
|
||||
|
@ -1784,13 +1792,13 @@ replacing the selection.
|
|||
- (void) pasteAsPlainText: (id)sender
|
||||
{
|
||||
[self readSelectionFromPasteboard: [NSPasteboard generalPasteboard]
|
||||
type: NSStringPboardType];
|
||||
type: NSStringPboardType];
|
||||
}
|
||||
|
||||
- (void) pasteAsRichText: (id)sender
|
||||
{
|
||||
[self readSelectionFromPasteboard: [NSPasteboard generalPasteboard]
|
||||
type: NSRTFPboardType];
|
||||
type: NSRTFPboardType];
|
||||
}
|
||||
|
||||
- (void) updateFontPanel
|
||||
|
@ -1813,21 +1821,7 @@ replacing the selection.
|
|||
}
|
||||
else /* Just Insertion Point. */
|
||||
{
|
||||
unsigned location;
|
||||
|
||||
if (_selected_range.location > 0)
|
||||
{
|
||||
/* Use the font before the insertion point... */
|
||||
location = _selected_range.location - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ...or at location 0 if at the beginning of text*/
|
||||
location = _selected_range.location;
|
||||
}
|
||||
currentFont = [_textStorage attribute: NSFontAttributeName
|
||||
atIndex: location
|
||||
effectiveRange: NULL];
|
||||
currentFont = [_typingAttributes objectForKey: NSFontAttributeName];
|
||||
[fm setSelectedFont: currentFont isMultiple: NO];
|
||||
}
|
||||
}
|
||||
|
@ -2780,9 +2774,16 @@ container, returning the modified location. */
|
|||
{
|
||||
NSColor *color = [NSColor colorFromPasteboard: pboard];
|
||||
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||
NSMutableDictionary *d = [[self typingAttributes] mutableCopy];
|
||||
|
||||
[d setObject: color forKey: NSForegroundColorAttributeName];
|
||||
[self setTypingAttributes: d];
|
||||
RELEASE(d);
|
||||
|
||||
if (aRange.location != NSNotFound)
|
||||
[self setTextColor: color range: aRange];
|
||||
{
|
||||
[self setTextColor: color range: aRange];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
@ -2790,18 +2791,22 @@ container, returning the modified location. */
|
|||
// font pasting
|
||||
if ([type isEqualToString: NSFontPboardType])
|
||||
{
|
||||
// FIXME - This should use a serializer. To get that working a
|
||||
// helper object is needed that implements the
|
||||
// NSObjCTypeSerializationCallBack protocol. We should add this
|
||||
// later, currently the NSArchiver is used. Thanks to Richard,
|
||||
// for pointing this out.
|
||||
NSData *data = [pboard dataForType: NSFontPboardType];
|
||||
NSDictionary *dict = [NSUnarchiver unarchiveObjectWithData: data];
|
||||
|
||||
if (dict != nil)
|
||||
{
|
||||
[self setAttributes: dict
|
||||
range: [self rangeForUserCharacterAttributeChange]];
|
||||
NSRange aRange = [self rangeForUserCharacterAttributeChange];
|
||||
NSMutableDictionary *d;
|
||||
|
||||
if (aRange.location != NSNotFound)
|
||||
{
|
||||
[self setAttributes: dict range: aRange];
|
||||
}
|
||||
d = [[self typingAttributes] mutableCopy];
|
||||
[d addEntriesFromDictionary: dict];
|
||||
[self setTypingAttributes: d];
|
||||
RELEASE(d);
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
|
@ -2810,14 +2815,22 @@ container, returning the modified location. */
|
|||
// ruler pasting
|
||||
if ([type isEqualToString: NSRulerPboardType])
|
||||
{
|
||||
// FIXME: see NSFontPboardType above
|
||||
NSData *data = [pboard dataForType: NSRulerPboardType];
|
||||
NSDictionary *dict = [NSUnarchiver unarchiveObjectWithData: data];
|
||||
|
||||
if (dict != nil)
|
||||
{
|
||||
[self setAttributes: dict
|
||||
range: [self rangeForUserParagraphAttributeChange]];
|
||||
NSRange aRange = [self rangeForUserParagraphAttributeChange];
|
||||
NSMutableDictionary *d;
|
||||
|
||||
if (aRange.location != NSNotFound)
|
||||
{
|
||||
[self setAttributes: dict range: aRange];
|
||||
}
|
||||
d = [[self typingAttributes] mutableCopy];
|
||||
[d addEntriesFromDictionary: dict];
|
||||
[self setTypingAttributes: d];
|
||||
RELEASE(d);
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
|
@ -2884,6 +2897,8 @@ other than copy/paste or dragging. */
|
|||
|
||||
if (types == nil)
|
||||
return NO;
|
||||
if (_selected_range.location == NSNotFound)
|
||||
return NO;
|
||||
|
||||
[pboard declareTypes: types owner: self];
|
||||
|
||||
|
@ -2910,8 +2925,11 @@ other than copy/paste or dragging. */
|
|||
|
||||
if ([type isEqualToString: NSColorPboardType])
|
||||
{
|
||||
NSColor *color = [self textColor];
|
||||
NSColor *color;
|
||||
|
||||
color = [_textStorage attribute: NSForegroundColorAttributeName
|
||||
atIndex: _selected_range.location
|
||||
effectiveRange: 0];
|
||||
if (color != nil)
|
||||
{
|
||||
[color writeToPasteboard: pboard];
|
||||
|
@ -2921,16 +2939,11 @@ other than copy/paste or dragging. */
|
|||
|
||||
if ([type isEqualToString: NSFontPboardType])
|
||||
{
|
||||
NSDictionary *dict;
|
||||
NSDictionary *dict;
|
||||
|
||||
dict = [_textStorage fontAttributesInRange: _selected_range];
|
||||
if (dict != nil)
|
||||
{
|
||||
// FIXME - This should use a serializer. To get that
|
||||
// working a helper object is needed that implements the
|
||||
// NSObjCTypeSerializationCallBack protocol. We should
|
||||
// add this later, currently the NSArchiver is used.
|
||||
// Thanks to Richard, for pointing this out.
|
||||
[pboard setData: [NSArchiver archivedDataWithRootObject: dict]
|
||||
forType: NSFontPboardType];
|
||||
ret = YES;
|
||||
|
@ -2939,12 +2952,11 @@ other than copy/paste or dragging. */
|
|||
|
||||
if ([type isEqualToString: NSRulerPboardType])
|
||||
{
|
||||
NSDictionary *dict;
|
||||
NSDictionary *dict;
|
||||
|
||||
dict = [_textStorage rulerAttributesInRange: _selected_range];
|
||||
if (dict != nil)
|
||||
{
|
||||
//FIXME: see NSFontPboardType above
|
||||
[pboard setData: [NSArchiver archivedDataWithRootObject: dict]
|
||||
forType: NSRulerPboardType];
|
||||
ret = YES;
|
||||
|
|
Loading…
Reference in a new issue