mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 03:11:18 +00:00
NSTabView fixes to bring in line w/os x behavior for display update and zero-tabs case; NSColorList capability added to read text color files, and corrected interp of arg to -initWithNameFromFile
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20334 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
aa6f4087a1
commit
409e8d2388
4 changed files with 169 additions and 10 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
2004-11-09 Adrian Robert <arobert@cogsci.ucsd.edu>
|
||||
|
||||
* Source/NSTabView.m (-insertTabViewItem:): Update display.
|
||||
(-removeTabViewItem:): Same.
|
||||
(-selectTabViewItem:): Fix erroneous comment.
|
||||
(-selectTabViewItemAtIndex:) Check index in range.
|
||||
(-drawRect:) Don't try to select first tab if there are no tabs.
|
||||
* Source/NSColorList.m (-initWithNameFromFile:) Treat filename
|
||||
given as full path, not directory (but support this previous
|
||||
behavior in case apps are relying on it). Also, if fail to read
|
||||
file as an archive, try text format.
|
||||
(+loadAvavailableColorLists:) Adjust code for change to
|
||||
-initWithName:fromFile:.
|
||||
(-_readTextColorFile:) New utility method to support
|
||||
-initWithNameFromFile:.
|
||||
* Headers/AppKit/NSColorList.h: Document above changes.
|
||||
|
||||
2004-11-09 22:36 Alexander Malmberg <alexander@malmberg.org>
|
||||
|
||||
* Source/GSInfoPanel.m (_value_from_info_plist_for_key): Rename to
|
||||
|
|
|
@ -62,7 +62,30 @@
|
|||
//
|
||||
// Initializing an NSColorList
|
||||
//
|
||||
/**
|
||||
* Initializes a new, empty color list registered under given name.
|
||||
*/
|
||||
- (id)initWithName:(NSString *)name;
|
||||
|
||||
/**
|
||||
* <p>Initializes a new color list registered under given name, taking
|
||||
* contents from the file specified in path. (Path should include the
|
||||
* filename with extension (usually ".clr"), and by convention name should be
|
||||
* the same as filename <em>without</em> the extension.)</p>
|
||||
*
|
||||
* <p>The format of the file can be either an archive of an NSColorList
|
||||
* or an ASCII format. ASCII files follow this format:</p>
|
||||
*
|
||||
* <p>first line = [#/colors] <br/>
|
||||
* each subsequent line describes a color as [int float+ string] <br/>
|
||||
* the first int describes the method (RGBA, etc.), the floats
|
||||
* provide its arguments (e.g., r, g, b, alpha), and string is name.</p>
|
||||
*
|
||||
* <p>The <em>method</em> corresponds to one of the [NSColor] initializers.
|
||||
* We are looking for documentation of the exact correspondence on OpenStep;
|
||||
* for now the only supported method is "0", which is an RGBA format with
|
||||
* the arguments in order R,G,B, A.</p>
|
||||
*/
|
||||
- (id)initWithName:(NSString *)name
|
||||
fromFile:(NSString *)path;
|
||||
|
||||
|
|
|
@ -32,9 +32,11 @@
|
|||
#include <Foundation/NSLock.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSScanner.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
#include "AppKit/NSColorList.h"
|
||||
|
@ -104,9 +106,9 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
{
|
||||
if ([[file pathExtension] isEqualToString: @"clr"])
|
||||
{
|
||||
file = [file stringByDeletingPathExtension];
|
||||
newList = [[NSColorList alloc] initWithName: file
|
||||
fromFile: dir];
|
||||
NSString *name = [file stringByDeletingPathExtension];
|
||||
newList = [[NSColorList alloc] initWithName: name
|
||||
fromFile: [dir stringByAppendingPathComponent: file]];
|
||||
[_gnustep_available_color_lists addObject: newList];
|
||||
RELEASE(newList);
|
||||
}
|
||||
|
@ -171,9 +173,78 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
return nil;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Instance methods
|
||||
*/
|
||||
|
||||
/*
|
||||
* Private method for reading text color list files, with following format:
|
||||
* first line = <#/colors>
|
||||
* each subsequent line describes a color as <int float+ string>
|
||||
* the first int describes the method (ARGB, etc.), the floats
|
||||
* provide its arguments (e.g., r, g, b, alpha), and string is name.
|
||||
*/
|
||||
- (BOOL) _readTextColorFile: (NSString *) filepath
|
||||
{
|
||||
int nColors;
|
||||
int method;
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float alpha;
|
||||
NSString *cname;
|
||||
int i;
|
||||
BOOL st;
|
||||
NSColor *color;
|
||||
NSCharacterSet *newlineSet =
|
||||
[NSCharacterSet characterSetWithCharactersInString: @"\n"];
|
||||
NSScanner *scanner =
|
||||
[NSScanner scannerWithString:
|
||||
[NSString stringWithContentsOfFile: _fullFileName]];
|
||||
|
||||
if ([scanner scanInt: &nColors] == NO)
|
||||
{
|
||||
NSLog(@"Unable to read color file at \"%@\" -- unknown format.",
|
||||
_fullFileName);
|
||||
return NO;
|
||||
}
|
||||
|
||||
for (i = 0; i < nColors; i++)
|
||||
{
|
||||
if ([scanner scanInt: &method] == NO)
|
||||
{
|
||||
NSLog(@"Unable to read color file at \"%@\" -- unknown format.",
|
||||
_fullFileName);
|
||||
break;
|
||||
}
|
||||
//FIXME- replace this by switch on method to different
|
||||
// NSColor initializers
|
||||
if (method != 0)
|
||||
{
|
||||
NSLog(@"Unable to read color file at \"%@\" -- only RGBA form "
|
||||
@"supported.", _fullFileName);
|
||||
break;
|
||||
}
|
||||
st = [scanner scanFloat: &r];
|
||||
st = st && [scanner scanFloat: &g];
|
||||
st = st && [scanner scanFloat: &b];
|
||||
st = st && [scanner scanFloat: &alpha];
|
||||
st = st && [scanner scanUpToCharactersFromSet: newlineSet
|
||||
intoString: &cname];
|
||||
if (st == NO)
|
||||
{
|
||||
NSLog(@"Unable to read color file at \"%@\" -- unknown format.",
|
||||
_fullFileName);
|
||||
break;
|
||||
}
|
||||
color = [NSColor colorWithCalibratedRed: r green: g blue: b alpha: alpha];
|
||||
[self insertColor: color key: cname atIndex: i];
|
||||
}
|
||||
|
||||
return i == nColors;
|
||||
}
|
||||
|
||||
- (id) initWithName: (NSString *)name
|
||||
{
|
||||
return [self initWithName: name
|
||||
|
@ -190,16 +261,38 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
|
||||
if (path != nil)
|
||||
{
|
||||
ASSIGN (_fullFileName, [[path stringByAppendingPathComponent: name]
|
||||
stringByAppendingPathExtension: @"clr"]);
|
||||
BOOL isDir = NO;
|
||||
// previously impl wrongly expected directory containing color file
|
||||
// rather than color file; we support this for apps that rely on it
|
||||
if (([[NSFileManager defaultManager] fileExistsAtPath: path
|
||||
isDirectory: &isDir] == NO)
|
||||
|| (isDir == YES))
|
||||
{
|
||||
NSLog(@"NSColorList -initWithName:fromFile: warning: excluding "
|
||||
@"filename from path (%@) is deprecated.", path);
|
||||
ASSIGN (_fullFileName, [[path stringByAppendingPathComponent: name]
|
||||
stringByAppendingPathExtension: @"clr"]);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSIGN (_fullFileName, path);
|
||||
}
|
||||
|
||||
// Unarchive the color list
|
||||
|
||||
// TODO [Optm]: Rewrite to initialize directly without unarchiving
|
||||
// in another object
|
||||
NS_DURING
|
||||
{
|
||||
cl =
|
||||
(NSColorList*)[NSUnarchiver unarchiveObjectWithFile: _fullFileName];
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
cl = nil;
|
||||
}
|
||||
NS_ENDHANDLER ;
|
||||
|
||||
cl = (NSColorList*)[NSUnarchiver unarchiveObjectWithFile: _fullFileName];
|
||||
|
||||
if (cl && [cl isKindOfClass: [NSColorList class]])
|
||||
{
|
||||
could_load = YES;
|
||||
|
@ -213,6 +306,24 @@ static NSLock *_gnustep_color_list_lock = nil;
|
|||
ASSIGN(_orderedColorKeys, [NSMutableArray
|
||||
arrayWithArray: cl->_orderedColorKeys]);
|
||||
}
|
||||
else if ([[NSFileManager defaultManager] fileExistsAtPath: path])
|
||||
{
|
||||
_colorDictionary = [[NSMutableDictionary alloc] init];
|
||||
_orderedColorKeys = [[NSMutableArray alloc] init];
|
||||
_is_editable = YES;
|
||||
|
||||
if ([self _readTextColorFile: _fullFileName])
|
||||
{
|
||||
could_load = YES;
|
||||
_is_editable = [[NSFileManager defaultManager]
|
||||
isWritableFileAtPath: _fullFileName];
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASE (_colorDictionary);
|
||||
RELEASE (_orderedColorKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (could_load == NO)
|
||||
|
|
|
@ -77,6 +77,9 @@
|
|||
{
|
||||
[_delegate tabViewDidChangeNumberOfTabViewItems: self];
|
||||
}
|
||||
|
||||
/* TODO (Optimize) - just mark the tabs rect as needing redisplay */
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (void) removeTabViewItem: (NSTabViewItem*)tabViewItem
|
||||
|
@ -88,6 +91,7 @@
|
|||
|
||||
if ([tabViewItem isEqual: _selected])
|
||||
{
|
||||
[[_selected view] removeFromSuperview];
|
||||
_selected = nil;
|
||||
}
|
||||
|
||||
|
@ -98,6 +102,10 @@
|
|||
{
|
||||
[_delegate tabViewDidChangeNumberOfTabViewItems: self];
|
||||
}
|
||||
|
||||
/* TODO (Optimize) - just mark the tabs rect as needing redisplay unless
|
||||
removed tab was selected */
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (int) indexOfTabViewItem: (NSTabViewItem*)tabViewItem
|
||||
|
@ -209,7 +217,7 @@
|
|||
[_window makeFirstResponder: [_selected initialFirstResponder]];
|
||||
}
|
||||
|
||||
/* FIXME - only mark the contentRect as needing redisplay! */
|
||||
/* Will need to redraw tabs and content area. */
|
||||
[self setNeedsDisplay: YES];
|
||||
|
||||
if ([_delegate respondsToSelector:
|
||||
|
@ -222,7 +230,7 @@
|
|||
|
||||
- (void) selectTabViewItemAtIndex: (int)index
|
||||
{
|
||||
if (index < 0)
|
||||
if (index < 0 || index >= [_items count])
|
||||
[self selectTabViewItem: nil];
|
||||
else
|
||||
[self selectTabViewItem: [_items objectAtIndex: index]];
|
||||
|
@ -383,7 +391,7 @@
|
|||
break;
|
||||
}
|
||||
|
||||
if (!_selected)
|
||||
if (!_selected && howMany > 0)
|
||||
[self selectFirstTabViewItem: nil];
|
||||
|
||||
if (_type == NSNoTabsBezelBorder || _type == NSNoTabsLineBorder)
|
||||
|
|
Loading…
Reference in a new issue