diff --git a/ChangeLog b/ChangeLog index dcf38bb01..ff9799744 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Dec 5 06:58:51 1996 GNUstep Development + + * Source/NSColorList.m: Fill out implementation. + * Source/NSColorWell.m: Initial implementation. + Thu Dec 05 09:56:25 1996 Scott Christley * Headers/gnustep/gui/NSMenu.h: Newer release of OpenStep diff --git a/Headers/gnustep/gui/NSColorList.h b/Headers/gnustep/gui/NSColorList.h index 5e3c57397..6119abe1b 100644 --- a/Headers/gnustep/gui/NSColorList.h +++ b/Headers/gnustep/gui/NSColorList.h @@ -1,7 +1,7 @@ /* NSColorList.h - Description... + Manage named lists of NSColors. Copyright (C) 1996 Free Software Foundation, Inc. @@ -32,11 +32,19 @@ #include #include #include +#include +#include +#include @interface NSColorList : NSObject { // Attributes + NSString *list_name; + NSString *file_name; + NSMutableDictionary *color_list; + NSMutableArray *color_list_keys; + BOOL is_editable; } // @@ -64,7 +72,7 @@ - (NSColor *)colorWithKey:(NSString *)key; - (void)insertColor:(NSColor *)color key:(NSString *)key -atIndex:(unsigned)location; + atIndex:(unsigned)location; - (void)removeColorWithKey:(NSString *)key; - (void)setColor:(NSColor *)aColor forKey:(NSString *)key; diff --git a/Headers/gnustep/gui/NSColorWell.h b/Headers/gnustep/gui/NSColorWell.h index 13b37886b..318df7431 100644 --- a/Headers/gnustep/gui/NSColorWell.h +++ b/Headers/gnustep/gui/NSColorWell.h @@ -1,7 +1,7 @@ /* NSColorWell.h - Description... + NSControl for selecting and display a single color value. Copyright (C) 1996 Free Software Foundation, Inc. @@ -37,6 +37,9 @@ { // Attributes + NSColor *the_color; + BOOL is_active; + BOOL is_bordered; } // diff --git a/Source/NSColorList.m b/Source/NSColorList.m index 4ad81b86f..29efa834b 100644 --- a/Source/NSColorList.m +++ b/Source/NSColorList.m @@ -1,7 +1,7 @@ /* NSColorList.m - Description... + Manage named lists of NSColors. Copyright (C) 1996 Free Software Foundation, Inc. @@ -27,9 +27,27 @@ */ #include +#include +#include +#include +#include // NSColorList notifications -NSString *NSColorListChangedNotification; +NSString *NSColorListChangedNotification = @"NSColorListChange"; + +// NSColorList exceptions +NSString *NSColorListNotEditableException = @"NSColorListNotEditable"; + +// global variable +static NSMutableArray *gnustep_available_color_lists; +static NSLock *gnustep_color_list_lock; + +@interface NSColorList (GNUstepPrivate) + +- (void)setFileNameFromPath: (NSString *)path; +- (NSDictionary *)colorListDictionary; + +@end @implementation NSColorList @@ -42,6 +60,11 @@ NSString *NSColorListChangedNotification; { // Initial version [self setVersion:1]; + + // Initialize the global array of color lists + gnustep_available_color_lists = [NSMutableArray array]; + // And its access lock + gnustep_color_list_lock = [[NSLock alloc] init]; } } @@ -50,7 +73,15 @@ NSString *NSColorListChangedNotification; // + (NSArray *)availableColorLists { - return nil; + NSArray *a; + + // Serialize access to color list + [gnustep_color_list_lock lock]; + a = [[[NSArray alloc] initWithArray: gnustep_available_color_lists] + autorelease]; + [gnustep_color_list_lock unlock]; + + return a; } // @@ -58,7 +89,26 @@ NSString *NSColorListChangedNotification; // + (NSColorList *)colorListNamed:(NSString *)name { - return nil; + id o, e; + BOOL found = NO; + + // Serialize access to color list + [gnustep_color_list_lock lock]; + e = [gnustep_available_color_lists objectEnumerator]; + o = [e nextObject]; + while ((o) && (!found)) + { + if ([name compare: [o name]] == NSOrderedSame) + found = YES; + else + o = [e nextObject]; + } + [gnustep_color_list_lock unlock]; + + if (found) + return o; + else + return nil; } // @@ -69,13 +119,64 @@ NSString *NSColorListChangedNotification; // - (id)initWithName:(NSString *)name { - return nil; + [super init]; + + // Initialize instance variables + list_name = name; + [list_name retain]; + color_list = [NSMutableDictionary dictionary]; + [color_list retain]; + color_list_keys = [NSMutableArray array]; + [color_list_keys retain]; + is_editable = YES; + file_name = @""; + + // Add to global list of colors + [gnustep_color_list_lock lock]; + [gnustep_available_color_lists addObject: self]; + [gnustep_color_list_lock unlock]; + + return self; } - (id)initWithName:(NSString *)name fromFile:(NSString *)path { - return nil; + id cl; + + [super init]; + + // Initialize instance variables + list_name = name; + [list_name retain]; + [self setFileNameFromPath: path]; + + // Unarchive the color list + cl = [NSUnarchiver unarchiveObjectWithFile: file_name]; + + // Copy the color list elements to self + is_editable = [cl isEditable]; + color_list = [NSMutableDictionary alloc]; + [color_list initWithDictionary: [cl colorListDictionary]]; + color_list_keys = [NSMutableArray alloc]; + [color_list_keys initWithArray: [cl allKeys]]; + + [cl release]; + + // Add to global list of colors + [gnustep_color_list_lock lock]; + [gnustep_available_color_lists addObject: self]; + [gnustep_color_list_lock unlock]; + + return self; +} + +- (void)dealloc +{ + [list_name release]; + [color_list release]; + [color_list_keys release]; + [super dealloc]; } // @@ -83,7 +184,7 @@ NSString *NSColorListChangedNotification; // - (NSString *)name { - return nil; + return list_name; } // @@ -91,32 +192,77 @@ NSString *NSColorListChangedNotification; // - (NSArray *)allKeys { - return nil; + return [[[NSArray alloc] initWithArray: color_list_keys] + autorelease]; } - (NSColor *)colorWithKey:(NSString *)key { - return nil; + return [color_list objectForKey: key]; } - (void)insertColor:(NSColor *)color key:(NSString *)key -atIndex:(unsigned)location -{} + atIndex:(unsigned)location +{ + // Are we even editable? + if (!is_editable) + [NSException raise: NSColorListNotEditableException + format: @"Color list cannot be edited\n"]; + + // add color + [color_list setObject: color forKey: key]; + [color_list_keys removeObject: key]; + [color_list_keys insertObject: key atIndex: location]; + + // post notification + [[NSNotificationCenter defaultCenter] + postNotificationName: NSColorListChangedNotification + object: self]; +} - (void)removeColorWithKey:(NSString *)key -{} +{ + // Are we even editable? + if (!is_editable) + [NSException raise: NSColorListNotEditableException + format: @"Color list cannot be edited\n"]; + + [color_list removeObjectForKey: key]; + [color_list_keys removeObject: key]; + + // post notification + [[NSNotificationCenter defaultCenter] + postNotificationName: NSColorListChangedNotification + object: self]; +} - (void)setColor:(NSColor *)aColor forKey:(NSString *)key -{} +{ + // Are we even editable? + if (!is_editable) + [NSException raise: NSColorListNotEditableException + format: @"Color list cannot be edited\n"]; + + [color_list setObject: aColor forKey: key]; + + // Add to list if doesn't already exist + if (![color_list_keys containsObject: key]) + [color_list_keys addObject: key]; + + // post notification + [[NSNotificationCenter defaultCenter] + postNotificationName: NSColorListChangedNotification + object: self]; +} // // Editing // - (BOOL)isEditable { - return NO; + return is_editable; } // @@ -124,11 +270,21 @@ atIndex:(unsigned)location // - (BOOL)writeToFile:(NSString *)path { - return NO; + [self setFileNameFromPath: path]; + + // Archive to the file + return [NSArchiver archiveRootObject: self toFile: file_name]; } - (void)removeFile -{} +{ + // xxx Tell NSWorkspace to remove the file + + // Remove from global list of colors + [gnustep_color_list_lock lock]; + [gnustep_available_color_lists removeObject: self]; + [gnustep_color_list_lock unlock]; +} // // NSCoding protocol @@ -136,13 +292,43 @@ atIndex:(unsigned)location - (void)encodeWithCoder:aCoder { [super encodeWithCoder:aCoder]; + [aCoder encodeObject: list_name]; + [aCoder encodeObject: color_list]; + [aCoder encodeObject: color_list_keys]; + [aCoder encodeValueOfObjCType:@encode(BOOL) at: &is_editable]; } - initWithCoder:aDecoder { [super initWithCoder:aDecoder]; + list_name = [aDecoder decodeObject]; + color_list = [aDecoder decodeObject]; + color_list_keys = [aDecoder decodeObject]; + [aDecoder decodeValueOfObjCType:@encode(BOOL) at: &is_editable]; return self; } @end + +@implementation NSColorList (GNUstepPrivate) + +- (void)setFileNameFromPath: (NSString *)path +{ + NSMutableString *s = [NSMutableString stringWithCString: ""]; + + // Construct filename + // xxx Need to determine if path already contains filename + [s appendString: path]; + [s appendString: @"/"]; + [s appendString: list_name]; + [s appendString: @".clr"]; + file_name = s; +} + +- (NSDictionary *)colorListDictionary +{ + return color_list; +} + +@end diff --git a/Source/NSColorWell.m b/Source/NSColorWell.m index c99725d7a..b0a20bdeb 100644 --- a/Source/NSColorWell.m +++ b/Source/NSColorWell.m @@ -1,7 +1,7 @@ /* NSColorWell.m - Description... + NSControl for selecting and display a single color value. Copyright (C) 1996 Free Software Foundation, Inc. @@ -49,21 +49,33 @@ // // Drawing // +- (void)drawRect:(NSRect)rect +{ + // xxx Draw border + + [self drawWellInside: rect]; +} + - (void)drawWellInside:(NSRect)insideRect -{} +{ +} // // Activating // - (void)activate:(BOOL)exclusive -{} +{ + is_active = YES; +} - (void)deactivate -{} +{ + is_active = NO; +} - (BOOL)isActive { - return NO; + return is_active; } // @@ -71,25 +83,33 @@ // - (NSColor *)color { - return nil; + return the_color; } - (void)setColor:(NSColor *)color -{} +{ + the_color = color; +} - (void)takeColorFrom:(id)sender -{} +{ + if ([sender respondsToSelector:@selector(color)]) + the_color = [sender color]; +} // // Managing Borders // - (BOOL)isBordered { - return NO; + return is_bordered; } - (void)setBordered:(BOOL)bordered -{} +{ + is_bordered = bordered; + [self display]; +} // // NSCoding protocol @@ -97,11 +117,17 @@ - (void)encodeWithCoder:aCoder { [super encodeWithCoder:aCoder]; + [aCoder encodeObject: the_color]; + [aCoder encodeValueOfObjCType:@encode(BOOL) at: &is_active]; + [aCoder encodeValueOfObjCType:@encode(BOOL) at: &is_bordered]; } - initWithCoder:aDecoder { [super initWithCoder:aDecoder]; + the_color = [aDecoder decodeObject]; + [aDecoder decodeValueOfObjCType:@encode(BOOL) at: &is_active]; + [aDecoder decodeValueOfObjCType:@encode(BOOL) at: &is_bordered]; return self; } diff --git a/Source/NSSliderCell.m b/Source/NSSliderCell.m index e0b7b7c7f..5c6b4eacf 100644 --- a/Source/NSSliderCell.m +++ b/Source/NSSliderCell.m @@ -137,21 +137,44 @@ { double val_range,value; - max_value = aDouble; + // Swap values if new max is less than min + if (aDouble < min_value) + { + max_value = min_value; + min_value = aDouble; + } + else + max_value = aDouble; + val_range = max_value - min_value; if (val_range != 0) - //Lowest position assumed to be 0 - scale_factor = scroll_size/val_range; + { + scale_factor = scroll_size/val_range; + if (scale_factor != 0) + page_value = knob_thickness * (1/scale_factor); + } } - (void)setMinValue:(double)aDouble { double val_range,value; - min_value = aDouble; + // Swap values if new min is greater than max + if (aDouble > max_value) + { + min_value = max_value; + max_value = aDouble; + } + else + min_value = aDouble; + val_range = max_value - min_value; if (val_range != 0) - scale_factor = scroll_size/val_range; + { + scale_factor = scroll_size/val_range; + if (scale_factor != 0) + page_value = knob_thickness * (1/scale_factor); + } } // @@ -174,7 +197,21 @@ - (void)setKnobThickness:(float)aFloat { + int old_scroll = scroll_size; + double val_range; + + // Recalculate the scroll size + scroll_size = old_scroll + knob_thickness; knob_thickness = aFloat; + scroll_size -= knob_thickness; + + val_range = max_value - min_value; + if (val_range != 0) + { + scale_factor = scroll_size/val_range; + if (scale_factor != 0) + page_value = knob_thickness * (1/scale_factor); + } } - (void)setTitle:(NSString *)aString @@ -269,8 +306,6 @@ [aCoder encodeValueOfObjCType: "i" at: &scroll_size]; [aCoder encodeValueOfObjCType: "i" at: &knob_thickness]; [aCoder encodeValueOfObjCType: "d" at: &page_value]; -// [aCoder encodeValuesOfObjCTypes: "dddiid", &max_value, &min_value, -// &scale_factor, &scroll_size, &knob_thickness, &page_value]; [aCoder encodeValueOfObjCType: @encode(BOOL) at: &is_vertical]; } @@ -284,8 +319,6 @@ [aDecoder decodeValueOfObjCType: "i" at: &scroll_size]; [aDecoder decodeValueOfObjCType: "i" at: &knob_thickness]; [aDecoder decodeValueOfObjCType: "d" at: &page_value]; -// [aDecoder decodeValuesOfObjCTypes: "dddiid", &max_value, &min_value, -// &scale_factor, &scroll_size, &knob_thickness, &page_value]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_vertical]; return self; diff --git a/Source/NSTextFieldCell.m b/Source/NSTextFieldCell.m index 772069c06..f5b1747b3 100644 --- a/Source/NSTextFieldCell.m +++ b/Source/NSTextFieldCell.m @@ -76,6 +76,7 @@ background_color = [NSColor whiteColor]; text_color = [NSColor blackColor]; + support = [NSFont systemFontOfSize:12]; return self; }