Add binding implementation.

Clean up table view decoding.
Move image draw code to back.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25602 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-11-22 12:15:50 +00:00
parent b7699665db
commit e2f2a194e6
4 changed files with 233 additions and 132 deletions

View file

@ -1,3 +1,13 @@
2007-11-22 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSNibBindingConnector.m: Completed implementation.
* Source/NSTableView.m (-_initDefaults): New method for shared
default settings.
* Source/NSTableView.m (-initWithFrame:, initWithCoder:): Use this
new method.
* Source/NSGraphicsContext.m (-GSDrawImage::): Moved implemenation
to back.
2007-11-22 Fred Kiefer <FredKiefer@gmx.de> 2007-11-22 Fred Kiefer <FredKiefer@gmx.de>
* Headers/AppKit/NSGraphics.h: Make NSDrawBitmap a real function. * Headers/AppKit/NSGraphics.h: Make NSDrawBitmap a real function.

View file

@ -1465,16 +1465,7 @@ NSGraphicsContext *GSCurrentContext(void)
been implemented yet, so it should not be used anywhere. */ been implemented yet, so it should not be used anywhere. */
- (void) GSDrawImage: (NSRect)rect: (void *)imageref - (void) GSDrawImage: (NSRect)rect: (void *)imageref
{ {
NSBitmapImageRep *bitmap; [self subclassResponsibility: _cmd];
const unsigned char *data[5];
bitmap = (NSBitmapImageRep*)imageref;
[bitmap getBitmapDataPlanes: &data];
[self NSDrawBitmap: rect : [bitmap pixelsWide] : [bitmap pixelsHigh]
: [bitmap bitsPerSample] : [bitmap samplesPerPixel]
: [bitmap bitsPerPixel] : [bitmap bytesPerRow] : [bitmap isPlanar]
: [bitmap hasAlpha] : [bitmap colorSpaceName]
: data];
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */

View file

@ -1,4 +1,4 @@
/** <title>NSNibAXAttributeConnector</title> /** <title>NSNibBindingConnector</title>
<abstract> <abstract>
</abstract> </abstract>
@ -7,6 +7,8 @@
Author: Gregory John Casamento Author: Gregory John Casamento
Date: 2007 Date: 2007
Author: Fred Kiefer <fredkiefer@gmx.de>
Date: Nov 2007
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
@ -30,8 +32,18 @@
#import <GNUstepGUI/GSNibCompatibility.h> #import <GNUstepGUI/GSNibCompatibility.h>
#import <Foundation/NSString.h> #import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h> #import <Foundation/NSDictionary.h>
#import <AppKit/NSKeyValueBinding.h>
@implementation NSNibBindingConnector @implementation NSNibBindingConnector
- (void) dealloc
{
RELEASE(_binding);
RELEASE(_keyPath);
RELEASE(_options);
[super dealloc];
}
- (NSString *) binding - (NSString *) binding
{ {
return _binding; return _binding;
@ -61,4 +73,102 @@
{ {
ASSIGN(_options, options); ASSIGN(_options, options);
} }
- (void) replaceObject: (id)anObject withObject: (id)anotherObject
{
if (_binding == anObject)
{
ASSIGN(_binding, anotherObject);
}
if (_keyPath == anObject)
{
ASSIGN(_keyPath, anotherObject);
}
if (_options == anObject)
{
ASSIGN(_options, anotherObject);
}
[super replaceObject: anObject withObject: anotherObject];
}
- (void) establishConnection
{
[_dst bind: _binding
toObject: _src
withKeyPath: _keyPath
options: _options];
}
- (void) encodeWithCoder: (NSCoder*)aCoder
{
if ([aCoder allowsKeyedCoding])
{
if (_binding != nil)
{
[aCoder encodeObject: _binding forKey: @"NSBinding"];
}
if (_keyPath != nil)
{
[aCoder encodeObject: _keyPath forKey: @"NSKeyPath"];
}
if (_options != nil)
{
[aCoder encodeObject: _options forKey: @"NSOptions"];
}
}
else
{
[aCoder encodeObject: _binding];
[aCoder encodeObject: _keyPath];
[aCoder encodeObject: _options];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
if (!(self = [super initWithCoder: aDecoder]))
{
return nil;
}
if ([aDecoder allowsKeyedCoding])
{
if ([aDecoder decodeIntForKey: @"NSNibBindingConnectorVersion"] != 2)
{
RELEASE(self);
return nil;
}
if ([aDecoder containsValueForKey: @"NSBinding"])
{
ASSIGN(_binding, [aDecoder decodeObjectForKey: @"NSBinding"]);
}
if ([aDecoder containsValueForKey: @"NSKeyPath"])
{
ASSIGN(_keyPath, [aDecoder decodeObjectForKey: @"NSKeyPath"]);
}
if ([aDecoder containsValueForKey: @"NSOptions"])
{
ASSIGN(_options, [aDecoder decodeObjectForKey: @"NSOptions"]);
}
}
else
{
[aDecoder decodeValueOfObjCType: @encode(id) at: &_binding];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_keyPath];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_options];
}
return self;
}
- (NSString *) description
{
return [NSString stringWithFormat: @"<%@ binding=%@ keypath=%@ options=%@>",
[super description],
[self binding],
[self keyPath],
[self options]];
}
@end @end

View file

@ -1979,28 +1979,41 @@ static void computeNewSelection
* Initializing/Releasing * Initializing/Releasing
*/ */
- (id) initWithFrame: (NSRect)frameRect - (void) _initDefaults
{ {
self = [super initWithFrame: frameRect];
_drawsGrid = YES; _drawsGrid = YES;
_rowHeight = 16.0; _rowHeight = 16.0;
_intercellSpacing = NSMakeSize (5.0, 2.0); _intercellSpacing = NSMakeSize (5.0, 2.0);
ASSIGN (_gridColor, [NSColor gridColor]); ASSIGN(_selectedColumns, [NSMutableIndexSet indexSet]);
ASSIGN (_backgroundColor, [NSColor controlBackgroundColor]); ASSIGN(_selectedRows, [NSMutableIndexSet indexSet]);
ASSIGN (_tableColumns, [NSMutableArray array]);
ASSIGN (_selectedColumns, [NSMutableIndexSet indexSet]);
ASSIGN (_selectedRows, [NSMutableIndexSet indexSet]);
_allowsEmptySelection = YES; _allowsEmptySelection = YES;
_allowsMultipleSelection = NO; _allowsMultipleSelection = NO;
_allowsColumnSelection = YES; _allowsColumnSelection = YES;
_allowsColumnResizing = YES; _allowsColumnResizing = YES;
_allowsColumnReordering = YES; _allowsColumnReordering = YES;
_autoresizesAllColumnsToFit = NO; _autoresizesAllColumnsToFit = NO;
_selectingColumns = NO;
_verticalMotionDrag = NO;
_editedColumn = -1; _editedColumn = -1;
_editedRow = -1; _editedRow = -1;
_clickedRow = -1;
_clickedColumn = -1;
_selectedColumn = -1; _selectedColumn = -1;
_selectedRow = -1; _selectedRow = -1;
_highlightedTableColumn = nil; _highlightedTableColumn = nil;
}
- (id) initWithFrame: (NSRect)frameRect
{
self = [super initWithFrame: frameRect];
if (!self)
return self;
[self _initDefaults];
ASSIGN(_gridColor, [NSColor gridColor]);
ASSIGN(_backgroundColor, [NSColor controlBackgroundColor]);
ASSIGN(_tableColumns, [NSMutableArray array]);
_headerView = [NSTableHeaderView new]; _headerView = [NSTableHeaderView new];
[_headerView setFrameSize: NSMakeSize (frameRect.size.width, 22.0)]; [_headerView setFrameSize: NSMakeSize (frameRect.size.width, 22.0)];
[_headerView setTableView: self]; [_headerView setTableView: self];
@ -5563,13 +5576,13 @@ static BOOL selectContiguousRegion(NSTableView *self,
[aCoder encodeObject: [self tableColumns] forKey: @"NSTableColumns"]; [aCoder encodeObject: [self tableColumns] forKey: @"NSTableColumns"];
if (_headerView) if (_headerView)
{ {
[aCoder encodeObject: _headerView forKey: @"NSHeaderView"]; [aCoder encodeObject: _headerView forKey: @"NSHeaderView"];
} }
if (_cornerView) if (_cornerView)
{ {
[aCoder encodeObject: _cornerView forKey: @"NSCornerView"]; [aCoder encodeObject: _cornerView forKey: @"NSCornerView"];
} }
tableViewFlags.columnSelection = [self allowsColumnSelection]; tableViewFlags.columnSelection = [self allowsColumnSelection];
tableViewFlags.multipleSelection = [self allowsMultipleSelection]; tableViewFlags.multipleSelection = [self allowsMultipleSelection];
@ -5616,140 +5629,128 @@ static BOOL selectContiguousRegion(NSTableView *self,
- (id) initWithCoder: (NSCoder*)aDecoder - (id) initWithCoder: (NSCoder*)aDecoder
{ {
self = [super initWithCoder: aDecoder]; self = [super initWithCoder: aDecoder];
if (!self)
return self;
if ([aDecoder allowsKeyedCoding]) if ([aDecoder allowsKeyedCoding])
{ {
NSSize intercellSpacing = [self intercellSpacing]; NSSize intercellSpacing;
NSArray *columns; NSArray *columns;
NSEnumerator *e; NSEnumerator *e;
NSTableColumn *col; NSTableColumn *col;
// assign defaults, so that there's color in case none is specified // assign defaults, so that there's color in case none is specified
ASSIGN (_gridColor, [NSColor gridColor]); [self _initDefaults];
ASSIGN (_backgroundColor, [NSColor controlBackgroundColor]); ASSIGN(_gridColor, [NSColor gridColor]);
ASSIGN (_tableColumns, [NSMutableArray array]); ASSIGN(_backgroundColor, [NSColor controlBackgroundColor]);
ASSIGN (_selectedColumns, [NSMutableIndexSet indexSet]); ASSIGN(_tableColumns, [NSMutableArray array]);
ASSIGN (_selectedRows, [NSMutableIndexSet indexSet]);
_autoresizesAllColumnsToFit = NO;
_clickedRow = -1;
_clickedColumn = -1;
_drawsGrid = YES;
_editedColumn = -1;
_editedRow = -1;
_highlightedTableColumn = nil;
_intercellSpacing = NSMakeSize (5.0, 2.0);
_rowHeight = 16.0;
_selectedColumn = -1;
_selectedRow = -1;
_selectingColumns = NO;
/*
_headerView = [NSTableHeaderView new];
[_headerView setFrameSize: NSMakeSize (_frame.size.width, 22.0)];
[_headerView setTableView: self];
*/
[(NSKeyedUnarchiver *)aDecoder setClass: [GSTableCornerView class] forClassName: @"_NSCornerView"];
if ([aDecoder containsValueForKey: @"NSDataSource"]) if ([aDecoder containsValueForKey: @"NSDataSource"])
{ {
[self setDataSource: [aDecoder decodeObjectForKey: @"NSDataSource"]]; [self setDataSource: [aDecoder decodeObjectForKey: @"NSDataSource"]];
} }
if ([aDecoder containsValueForKey: @"NSDelegate"]) if ([aDecoder containsValueForKey: @"NSDelegate"])
{ {
[self setDelegate: [aDecoder decodeObjectForKey: @"NSDelegate"]]; [self setDelegate: [aDecoder decodeObjectForKey: @"NSDelegate"]];
} }
if ([aDecoder containsValueForKey: @"NSTarget"]) if ([aDecoder containsValueForKey: @"NSTarget"])
{ {
[self setTarget: [aDecoder decodeObjectForKey: @"NSTarget"]]; [self setTarget: [aDecoder decodeObjectForKey: @"NSTarget"]];
} }
if ([aDecoder containsValueForKey: @"NSAction"]) if ([aDecoder containsValueForKey: @"NSAction"])
{ {
NSString *action = [aDecoder decodeObjectForKey: @"NSAction"]; NSString *action = [aDecoder decodeObjectForKey: @"NSAction"];
[self setAction: NSSelectorFromString(action)]; [self setAction: NSSelectorFromString(action)];
} }
if ([aDecoder containsValueForKey: @"NSBackgroundColor"]) if ([aDecoder containsValueForKey: @"NSBackgroundColor"])
{ {
[self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBackgroundColor"]]; [self setBackgroundColor: [aDecoder decodeObjectForKey: @"NSBackgroundColor"]];
} }
if ([aDecoder containsValueForKey: @"NSGridColor"]) if ([aDecoder containsValueForKey: @"NSGridColor"])
{ {
[self setGridColor: [aDecoder decodeObjectForKey: @"NSGridColor"]]; [self setGridColor: [aDecoder decodeObjectForKey: @"NSGridColor"]];
} }
intercellSpacing = [self intercellSpacing];
if ([aDecoder containsValueForKey: @"NSIntercellSpacingHeight"]) if ([aDecoder containsValueForKey: @"NSIntercellSpacingHeight"])
{ {
intercellSpacing.height = [aDecoder decodeFloatForKey: @"NSIntercellSpacingHeight"]; intercellSpacing.height = [aDecoder decodeFloatForKey: @"NSIntercellSpacingHeight"];
} }
if ([aDecoder containsValueForKey: @"NSIntercellSpacingWidth"]) if ([aDecoder containsValueForKey: @"NSIntercellSpacingWidth"])
{ {
intercellSpacing.width = [aDecoder decodeFloatForKey: @"NSIntercellSpacingWidth"]; intercellSpacing.width = [aDecoder decodeFloatForKey: @"NSIntercellSpacingWidth"];
} }
[self setIntercellSpacing: intercellSpacing]; [self setIntercellSpacing: intercellSpacing];
if ([aDecoder containsValueForKey: @"NSRowHeight"]) if ([aDecoder containsValueForKey: @"NSRowHeight"])
{ {
[self setRowHeight: [aDecoder decodeFloatForKey: @"NSRowHeight"]]; [self setRowHeight: [aDecoder decodeFloatForKey: @"NSRowHeight"]];
} }
[(NSKeyedUnarchiver *)aDecoder setClass: [GSTableCornerView class]
forClassName: @"_NSCornerView"];
if ([aDecoder containsValueForKey: @"NSCornerView"]) if ([aDecoder containsValueForKey: @"NSCornerView"])
{ {
NSRect viewFrame; NSRect viewFrame;
float rowHeight = [self rowHeight]; float rowHeight = [self rowHeight];
[self setCornerView: [aDecoder decodeObjectForKey: @"NSCornerView"]]; [self setCornerView: [aDecoder decodeObjectForKey: @"NSCornerView"]];
viewFrame = [[self cornerView] frame]; viewFrame = [[self cornerView] frame];
viewFrame.size.height = rowHeight; viewFrame.size.height = rowHeight;
[[self cornerView] setFrame: viewFrame]; [[self cornerView] setFrame: viewFrame];
} }
else
{
_cornerView = [GSTableCornerView new];
}
if ([aDecoder containsValueForKey: @"NSHeaderView"]) // if ([aDecoder containsValueForKey: @"NSHeaderView"])
{ {
NSRect viewFrame = [self frame]; NSRect viewFrame = [self frame];
float rowHeight = [self rowHeight]; float rowHeight = [self rowHeight];
_headerView = [[NSTableHeaderView alloc] init]; _headerView = [[NSTableHeaderView alloc] init];
[_headerView setFrameSize: NSMakeSize(viewFrame.size.width, rowHeight)]; [_headerView setFrameSize: NSMakeSize(viewFrame.size.width, rowHeight)];
[_headerView setTableView: self]; [_headerView setTableView: self];
} }
if ([aDecoder containsValueForKey: @"NSTvFlags"])
{
unsigned long flags = [aDecoder decodeIntForKey: @"NSTvFlags"];
GSTableViewFlags tableViewFlags;
memcpy((void *)&tableViewFlags,(void *)&flags,sizeof(struct _tableViewFlags));
[self setAllowsColumnSelection: tableViewFlags.columnSelection];
[self setAllowsMultipleSelection: tableViewFlags.multipleSelection];
[self setAllowsEmptySelection: tableViewFlags.emptySelection];
[self setDrawsGrid: tableViewFlags.drawsGrid];
[self setAllowsColumnResizing: tableViewFlags.columnResizing];
[self setAllowsColumnReordering: tableViewFlags.columnOrdering];
}
// get the table columns... // get the table columns...
columns = [aDecoder decodeObjectForKey: @"NSTableColumns"]; columns = [aDecoder decodeObjectForKey: @"NSTableColumns"];
e = [columns objectEnumerator]; e = [columns objectEnumerator];
while ((col = [e nextObject]) != nil) while ((col = [e nextObject]) != nil)
{ {
[self addTableColumn: col]; [self addTableColumn: col];
[col setTableView: self]; [col setTableView: self];
} }
if ([aDecoder containsValueForKey: @"NSTvFlags"])
{
unsigned long flags = [aDecoder decodeIntForKey: @"NSTvFlags"];
GSTableViewFlags tableViewFlags;
memcpy((void *)&tableViewFlags,(void *)&flags,sizeof(struct _tableViewFlags));
[self setAllowsColumnSelection: tableViewFlags.columnSelection];
[self setAllowsMultipleSelection: tableViewFlags.multipleSelection];
[self setAllowsEmptySelection: tableViewFlags.emptySelection];
[self setDrawsGrid: tableViewFlags.drawsGrid];
[self setAllowsColumnResizing: tableViewFlags.columnResizing];
[self setAllowsColumnReordering: tableViewFlags.columnOrdering];
}
_numberOfColumns = [columns count]; _numberOfColumns = [columns count];
ASSIGN (_selectedColumns, [NSMutableIndexSet indexSet]);
ASSIGN (_selectedRows, [NSMutableIndexSet indexSet]);
if (_numberOfColumns) if (_numberOfColumns)
_columnOrigins = NSZoneMalloc (NSDefaultMallocZone (), _columnOrigins = NSZoneMalloc(NSDefaultMallocZone (),
sizeof(float) * _numberOfColumns); sizeof(float) * _numberOfColumns);
[self tile]; [self tile];
} }
else else
{ {
int version = [aDecoder versionForClassName: int version = [aDecoder versionForClassName:
@"NSTableView"]; @"NSTableView"];
id aDelegate; id aDelegate;
_verticalMotionDrag = NO;
[self _initDefaults];
_dataSource = [aDecoder decodeObject]; _dataSource = [aDecoder decodeObject];
_tableColumns = RETAIN([aDecoder decodeObject]); _tableColumns = RETAIN([aDecoder decodeObject]);
_gridColor = RETAIN([aDecoder decodeObject]); _gridColor = RETAIN([aDecoder decodeObject]);
@ -5762,7 +5763,7 @@ static BOOL selectContiguousRegion(NSTableView *self,
[self setDelegate: aDelegate]; [self setDelegate: aDelegate];
[_headerView setTableView: self]; [_headerView setTableView: self];
[_tableColumns makeObjectsPerformSelector: @selector(setTableView:) [_tableColumns makeObjectsPerformSelector: @selector(setTableView:)
withObject: self]; withObject: self];
[aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfRows]; [aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfRows];
[aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfColumns]; [aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfColumns];
@ -5777,37 +5778,26 @@ static BOOL selectContiguousRegion(NSTableView *self,
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
if (version >= 3) if (version >= 3)
{ {
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering];
} }
if (version >= 2) if (version >= 2)
{ {
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
} }
if (version >= 4) if (version >= 4)
{ {
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag]; [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
} }
ASSIGN (_selectedColumns, [NSMutableIndexSet indexSet]);
ASSIGN (_selectedRows, [NSMutableIndexSet indexSet]);
if (_numberOfColumns) if (_numberOfColumns)
_columnOrigins = NSZoneMalloc (NSDefaultMallocZone (), _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (),
sizeof(float) * _numberOfColumns); sizeof(float) * _numberOfColumns);
_clickedRow = -1;
_clickedColumn = -1;
_selectingColumns = NO;
_selectedColumn = -1;
_selectedRow = -1;
_editedColumn = -1;
_editedRow = -1;
if (version == 2) if (version == 2)
{ {
[self tile]; [self tile];
} }
} }
return self; return self;