[zephyrchat-cvs] zchat/zChat AKStackedView.m,1.4,1.5 NSAttributedStringAdditions.h,1.6,1.7 NSAttribu
Status: Alpha
Brought to you by:
akosut
Update of /cvsroot/zephyrchat/zchat/zChat
In directory sc8-pr-cvs1:/tmp/cvs-serv11686
Modified Files:
AKStackedView.m NSAttributedStringAdditions.h
NSAttributedStringAdditions.m ZCChatWindowController.h
ZCChatWindowController.mm ZChatAppController.h
ZChatAppController.mm ZChatFriendInfoController.h
ZChatFriendInfoController.mm ZChatPrefsController.h
ZChatPrefsController.mm
Log Message:
Custom text color support.
Index: AKStackedView.m
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/AKStackedView.m,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- AKStackedView.m 29 Mar 2003 16:37:34 -0000 1.4
+++ AKStackedView.m 29 Mar 2003 19:21:37 -0000 1.5
@@ -70,7 +70,7 @@
- (void)mouseUp:(NSEvent *)event {
if ([event clickCount] == 2 && [_delegate respondsToSelector:@selector(selectViewAction:)]) {
- [self doubleAction:nil];
+ [_delegate selectViewAction:self];
}
}
Index: NSAttributedStringAdditions.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/NSAttributedStringAdditions.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- NSAttributedStringAdditions.h 27 Mar 2003 17:48:27 -0000 1.6
+++ NSAttributedStringAdditions.h 29 Mar 2003 19:21:37 -0000 1.7
@@ -13,8 +13,8 @@
@interface NSAttributedString (ZChatAttributedStringAdditions)
-+ (NSMutableAttributedString *)attributedStringWithZWGCString:(NSString *)zwgcString;
-+ (NSMutableAttributedString *)attributedStringWithZWGCString:(NSString *)zwgcString defaultFont:(NSFont *)defaultFont;
++ (NSMutableAttributedString *)attributedStringWithZWGCString:(NSString *)zwgcString
+ defaultAttributes:(NSDictionary *)defaultAttrs;
- (NSString *)zwgcString;
/*!
Index: NSAttributedStringAdditions.m
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/NSAttributedStringAdditions.m,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- NSAttributedStringAdditions.m 27 Mar 2003 17:48:29 -0000 1.14
+++ NSAttributedStringAdditions.m 29 Mar 2003 19:21:38 -0000 1.15
@@ -27,21 +27,23 @@
@implementation NSAttributedString (ZChatAttributedStringAdditions)
-+ (NSMutableAttributedString *)attributedStringWithZWGCString:(NSString *)zwgcString {
- return [self attributedStringWithZWGCString:zwgcString
- defaultFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
-}
-
+ (NSMutableAttributedString *)attributedStringWithZWGCString:(NSString *)zwgcString
- defaultFont:(NSFont *)defaultFont {
+ defaultAttributes:(NSDictionary *)defaultAttrs {
NSMutableAttributedString *result = [[NSMutableAttributedString new] autorelease];
NSMutableArray *stack; /* Stack of NSMutableDictionary representing the current state */
NSScanner *scanner;
NSCharacterSet *stopSet, *cmdSet;
BOOL beeped = FALSE;
- /* Start with font set to default (otherwise bold/etc doesn't seem to work right), no other attributes */
- stack = [NSMutableArray arrayWithObject:[NSMutableDictionary dictionaryWithObject:defaultFont forKey:NSFontAttributeName]];
+ /* Useful values */
+ NSFontManager *fontManager = [NSFontManager sharedFontManager];
+ NSFont *defaultFont = [defaultAttrs objectForKey:NSFontAttributeName];
+
+ /* Must provide a default font */
+ NSParameterAssert(defaultFont != nil);
+
+ /* Start with default attributes */
+ stack = [NSMutableArray arrayWithObject:[defaultAttrs mutableCopy]];
scanner = [NSScanner scannerWithString:zwgcString];
[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithRange:NSMakeRange(0, 0)]];
@@ -85,8 +87,7 @@
cmd = @"";
leftBracket = [[scanner string] characterAtIndex:[scanner scanLocation]];
- /* Many parameters deal with the current font and the font manager */
- NSFontManager *fontManager = [NSFontManager sharedFontManager];
+ /* Many parameters deal with the current font */
NSFont *currentFont = [attrs objectForKey:NSFontAttributeName];
if (currentFont == nil) currentFont = defaultFont;
Index: ZCChatWindowController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZCChatWindowController.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- ZCChatWindowController.h 27 Mar 2003 20:03:59 -0000 1.13
+++ ZCChatWindowController.h 29 Mar 2003 19:21:38 -0000 1.14
@@ -82,8 +82,8 @@
* timestamp).
*/
- (NSRange)appendMessage:(NSAttributedString *)message from:(NSString *)sender color:(NSColor *)bgColor
- alignment:(NSTextAlignment)alignment;
-- (NSAttributedString *)pingMessage;
+ textColor:(NSColor *)fgColor alignment:(NSTextAlignment)alignment;
+- (NSAttributedString *)pingMessageWithColor:(NSColor *)textColor;
- (IBAction)sendMessage:(id)sender;
- (void)sendSuccess;
Index: ZCChatWindowController.mm
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZCChatWindowController.mm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ZCChatWindowController.mm 27 Mar 2003 20:03:59 -0000 1.19
+++ ZCChatWindowController.mm 29 Mar 2003 19:21:38 -0000 1.20
@@ -335,9 +335,10 @@
if (_myDisplayedPing.length == 0
|| NSMaxRange(_myDisplayedPing) != [[_output textStorage] length]) {
[self removeMyPing];
- _myDisplayedPing = [self appendMessage:[self pingMessage]
+ _myDisplayedPing = [self appendMessage:[self pingMessageWithColor:[ZChatApp textColorForMe]]
from:[ZChatApp mySignature]
color:[ZChatApp colorForMe]
+ textColor:[ZChatApp textColorForMe]
alignment:NSNaturalTextAlignment];
}
} else {
@@ -356,9 +357,11 @@
}
}
-- (NSAttributedString *)pingMessage {
+- (NSAttributedString *)pingMessageWithColor:(NSColor *)textColor {
return [[[NSAttributedString alloc] initWithString:NSLocalizedString(@"PING_MESSAGE", nil)
- attributes:nil] autorelease];
+ attributes:
+ [NSDictionary dictionaryWithObject:textColor
+ forKey:NSForegroundColorAttributeName]] autorelease];
}
- (void)sendSuccess {
@@ -368,6 +371,7 @@
[self removeMyPing];
[self appendMessage:[_input attributedStringValue] from:[ZChatApp mySignature]
color:[ZChatApp colorForMe]
+ textColor:[ZChatApp textColorForMe]
alignment:NSNaturalTextAlignment];
[_input setStringValue:@""];
@@ -459,9 +463,10 @@
NSString *senderString = [NSString stringWithSTLString:sender];
[self removePingFrom:senderString];
- NSRange pingRange = [self appendMessage:[self pingMessage]
+ NSRange pingRange = [self appendMessage:[self pingMessageWithColor:[ZChatApp textColorFor:senderString]]
from:[self displayNameFor:senderString]
color:[ZChatApp colorFor:senderString]
+ textColor:[ZChatApp textColorFor:senderString]
alignment:NSNaturalTextAlignment];
[_displayedPings setObject:[NSValue valueWithRange:pingRange] forKey:senderString];
@@ -486,7 +491,10 @@
NSAttributedString *formattedMessage
= [[NSAttributedString attributedStringWithZWGCString:
[NSString stringWithSTLString:message.GetMessage()]
- defaultFont:[NSFont userFontOfSize:12.0]]
+ defaultAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSFont userFontOfSize:12.0], NSFontAttributeName,
+ [ZChatApp textColorFor:sender], NSForegroundColorAttributeName,
+ nil]]
unflowWithDefaultFont:[NSFont userFontOfSize:12.0]
fixedFont:[NSFont userFixedPitchFontOfSize:10.0]];
@@ -508,6 +516,7 @@
[self appendMessage:formattedMessage
from:displayName
color:[ZChatApp colorFor:sender]
+ textColor:[ZChatApp textColorFor:sender]
alignment:NSNaturalTextAlignment];
}
}
@@ -538,7 +547,7 @@
}
- (NSRange)appendMessage:(NSAttributedString *)message from:(NSString *)sender color:(NSColor *)bgColor
- alignment:(NSTextAlignment)alignment {
+ textColor:(NSColor *)fgColor alignment:(NSTextAlignment)alignment {
NSTextStorage *text = [_output textStorage];
bool shouldScroll = [[[_output enclosingScrollView] verticalScroller] floatValue] == 1.0;
@@ -575,9 +584,9 @@
range.location = [text length];
/* Add the sender */
- [text appendString:sender attributes:
- [NSDictionary dictionaryWithObject:[NSFont boldSystemFontOfSize:[NSFont systemFontSize]]
- forKey:NSFontAttributeName]];
+ [text appendString:sender attributes:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSFont boldSystemFontOfSize:[NSFont systemFontSize]], NSFontAttributeName,
+ fgColor, NSForegroundColorAttributeName, nil]];
/* Add some space: If the message is multi-line, add a newline, otherwise just a space */
NSRange lineRange = [[message string] lineRangeForRange:NSMakeRange(0, 0)];
Index: ZChatAppController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatAppController.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- ZChatAppController.h 26 Mar 2003 17:45:03 -0000 1.13
+++ ZChatAppController.h 29 Mar 2003 19:21:38 -0000 1.14
@@ -4,6 +4,7 @@
extern NSString * const kZChatAddressBookProperty;
extern NSString * const kZChatAddressBookColorProperty;
+extern NSString * const kZChatAddressBookTextColorProperty;
extern NSString * const ZChatLoginNotification;
extern NSString * const ZChatLogoutNotification;
@@ -96,6 +97,9 @@
* Returns the background color for the current user.
*/
- (NSColor *)colorForMe;
+
+- (NSColor *)textColorFor:(NSString *)username;
+- (NSColor *)textColorForMe;
- (NSString *)localizedZephyrStatus:(zephyrlib::ZephyrStatus)status;
Index: ZChatAppController.mm
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatAppController.mm,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- ZChatAppController.mm 26 Mar 2003 17:45:03 -0000 1.16
+++ ZChatAppController.mm 29 Mar 2003 19:21:38 -0000 1.17
@@ -14,6 +14,7 @@
NSString * const kZChatAddressBookProperty = @"edu.stanford.akosut.zchat.ZephyrInstant";
NSString * const kZChatAddressBookColorProperty = @"edu.stanford.akosut.zchat.ZephyrInstant.Color";
+NSString * const kZChatAddressBookTextColorProperty = @"edu.stanford.akosut.zchat.ZephyrInstant.TextColor";
NSString * const ZChatLoginNotification = @"ZChatLoginNotification";
NSString * const ZChatLogoutNotification = @"ZChatLogoutNotification";
@@ -55,6 +56,7 @@
[NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:kABStringProperty], kZChatAddressBookProperty,
[NSNumber numberWithInt:kABDataProperty], kZChatAddressBookColorProperty,
+ [NSNumber numberWithInt:kABDataProperty], kZChatAddressBookTextColorProperty,
nil]];
}
@@ -490,6 +492,39 @@
// Use default color
return [NSColor colorWithCalibratedWhite:0.7 alpha:1.0];
+}
+
+- (NSColor *)textColorFor:(NSString *)username {
+ if (username != nil) {
+ ABPerson *person = [self personForUser:username];
+
+ if (person != nil) {
+ NSData *encoded = [person valueForProperty:kZChatAddressBookTextColorProperty];
+ if (encoded != nil && [encoded length] > 0) {
+ return [NSKeyedUnarchiver unarchiveObjectWithData:encoded];
+ }
+ }
+ }
+
+ // Use color stored in preferences
+ NSData *stored = [[NSUserDefaults standardUserDefaults] objectForKey:@"SenderTextColor"];
+ if (stored != nil) {
+ return [NSKeyedUnarchiver unarchiveObjectWithData:stored];
+ }
+
+ // Use default color
+ return [NSColor textColor];
+}
+
+- (NSColor *)textColorForMe {
+ // Use color stored in preferences
+ NSData *stored = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyTextColor"];
+ if (stored != nil) {
+ return [NSKeyedUnarchiver unarchiveObjectWithData:stored];
+ }
+
+ // Use default color
+ return [NSColor textColor];
}
- (IBAction)showPrefsPanel:(id)sender {
Index: ZChatFriendInfoController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatFriendInfoController.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- ZChatFriendInfoController.h 26 Mar 2003 22:09:24 -0000 1.1
+++ ZChatFriendInfoController.h 29 Mar 2003 19:21:38 -0000 1.2
@@ -19,7 +19,9 @@
IBOutlet NSButton *_colorCheckbox;
IBOutlet NSTextField *_bgColorLabel;
- IBOutlet NSColorWell *_bgColorWell;
+ IBOutlet NSColorWell *_bgColorWell;
+ IBOutlet NSTextField *_fgColorLabel;
+ IBOutlet NSColorWell *_fgColorWell;
NSString *_user;
ABPerson *_person;
Index: ZChatFriendInfoController.mm
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatFriendInfoController.mm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ZChatFriendInfoController.mm 27 Mar 2003 20:04:01 -0000 1.3
+++ ZChatFriendInfoController.mm 29 Mar 2003 19:21:38 -0000 1.4
@@ -37,6 +37,7 @@
- (void)windowDidLoad {
[_usernameField setStringValue:ZephyrUtils::RemoveRealm(_user)];
[_bgColorWell setColor:[ZChatApp colorFor:_user]];
+ [_fgColorWell setColor:[ZChatApp textColorFor:_user]];
if (_person != nil) {
[_detachButton setEnabled:YES];
@@ -47,14 +48,19 @@
if ([_person valueForProperty:kABLastNameProperty] != nil)
[_lastNameField setStringValue:[_person valueForProperty:kABLastNameProperty]];
- if ([_person valueForProperty:kZChatAddressBookColorProperty] != nil) {
+ if ([_person valueForProperty:kZChatAddressBookColorProperty] != nil
+ || [_person valueForProperty:kZChatAddressBookTextColorProperty] != nil) {
[_colorCheckbox setState:NSOnState];
[_bgColorLabel setTextColor:[NSColor textColor]];
[_bgColorWell setEnabled:YES];
+ [_fgColorLabel setTextColor:[NSColor textColor]];
+ [_fgColorWell setEnabled:YES];
} else {
[_colorCheckbox setState:NSOffState];
[_bgColorLabel setTextColor:[NSColor textBackgroundColor]];
[_bgColorWell setEnabled:NO];
+ [_fgColorLabel setTextColor:[NSColor textBackgroundColor]];
+ [_fgColorWell setEnabled:NO];
}
}
}
@@ -104,17 +110,22 @@
- (IBAction)updateColor:(id)sender {
BOOL custom = [_colorCheckbox state] == NSOnState;
[_bgColorLabel setTextColor:custom ? [NSColor textColor] : [NSColor textBackgroundColor]];
+ [_fgColorLabel setTextColor:custom ? [NSColor textColor] : [NSColor textBackgroundColor]];
[_bgColorWell setEnabled:custom];
+ [_fgColorWell setEnabled:custom];
if (custom) {
[self createPersonIfNecessary];
[_person setValue:[NSKeyedArchiver archivedDataWithRootObject:[_bgColorWell color]]
forProperty:kZChatAddressBookColorProperty];
+ [_person setValue:[NSKeyedArchiver archivedDataWithRootObject:[_fgColorWell color]]
+ forProperty:kZChatAddressBookTextColorProperty];
[[ABAddressBook sharedAddressBook] save];
} else {
[_person removeValueForProperty:kZChatAddressBookColorProperty];
+ [_person removeValueForProperty:kZChatAddressBookTextColorProperty];
}
}
@@ -144,7 +155,9 @@
[_colorCheckbox setState:NSOffState];
[_bgColorLabel setTextColor:[NSColor textBackgroundColor]];
+ [_fgColorLabel setTextColor:[NSColor textBackgroundColor]];
[_bgColorWell setEnabled:NO];
+ [_fgColorWell setEnabled:NO];
[_detachButton setEnabled:NO];
[_openABButton setEnabled:NO];
Index: ZChatPrefsController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatPrefsController.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- ZChatPrefsController.h 9 Mar 2003 02:42:38 -0000 1.3
+++ ZChatPrefsController.h 29 Mar 2003 19:21:38 -0000 1.4
@@ -20,6 +20,8 @@
IBOutlet NSView *_appearanceView;
IBOutlet NSColorWell *_myColor;
IBOutlet NSColorWell *_senderColor;
+ IBOutlet NSColorWell *_myTextColor;
+ IBOutlet NSColorWell *_senderTextColor;
NSUserDefaults *_defs;
NSDictionary *_sites;
@@ -45,5 +47,7 @@
/* Color */
- (IBAction)changeMyColor:(id)sender;
- (IBAction)changeSenderColor:(id)sender;
+- (IBAction)changeMyTextColor:(id)sender;
+- (IBAction)changeSenderTextColor:(id)sender;
@end
Index: ZChatPrefsController.mm
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatPrefsController.mm,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- ZChatPrefsController.mm 26 Mar 2003 16:52:09 -0000 1.7
+++ ZChatPrefsController.mm 29 Mar 2003 19:21:38 -0000 1.8
@@ -116,7 +116,9 @@
- (IBAction)goMessages:(id)sender {
/* Colors */
[_myColor setColor:[ZChatApp colorForMe]];
+ [_myTextColor setColor:[ZChatApp textColorForMe]];
[_senderColor setColor:[ZChatApp colorFor:nil]];
+ [_senderTextColor setColor:[ZChatApp textColorFor:nil]];
[self switchToView:_appearanceView title:NSLocalizedString(@"PREFS_MESSAGES", nil)];
}
@@ -223,6 +225,14 @@
- (IBAction)changeSenderColor:(id)sender {
[_defs setObject:[NSKeyedArchiver archivedDataWithRootObject:[sender color]] forKey:@"SenderColor"];
+}
+
+- (IBAction)changeMyTextColor:(id)sender {
+ [_defs setObject:[NSKeyedArchiver archivedDataWithRootObject:[sender color]] forKey:@"MyTextColor"];
+}
+
+- (IBAction)changeSenderTextColor:(id)sender {
+ [_defs setObject:[NSKeyedArchiver archivedDataWithRootObject:[sender color]] forKey:@"SenderTextColor"];
}
|