libs-gui/Source/NSGridView.m

971 lines
24 KiB
Mathematica
Raw Normal View History

/* Implementation of class NSGridView
Copyright (C) 2020 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: 08-08-2020
This file is part of the GNUstep Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110 USA.
*/
2020-08-23 08:12:38 +00:00
#import <Foundation/NSArray.h>
#import "AppKit/NSGridView.h"
2020-08-23 08:12:38 +00:00
#import "GSFastEnumeration.h"
2021-01-16 15:55:01 +00:00
@interface NSGridRow (Private)
- (void) _addCell: (NSGridCell *)c;
@end
@interface NSGridColumn (Private)
- (void) _addCell: (NSGridCell *)c;
@end
@implementation NSGridView
+ (void) initialize
{
if (self == [NSGridView class])
{
[self setVersion: 1];
}
}
- (void) _refreshCells
{
NSUInteger r = 0, c = 0;
2021-01-16 15:55:01 +00:00
2021-01-16 15:58:34 +00:00
NSDebugLog(@"Refresh cells in NSGridView");
2021-01-16 15:55:01 +00:00
for (r = 0; r < [self numberOfRows]; r++)
{
2021-01-16 15:55:01 +00:00
for (c = 0; c < [self numberOfColumns]; c++)
{
2021-01-16 15:55:01 +00:00
NSGridCell *cell = [self cellAtColumnIndex: c
rowIndex: r];
if (cell != nil)
{
2021-01-16 15:55:01 +00:00
NSView *v = [cell contentView];
if (v != nil)
{
2021-01-16 15:58:34 +00:00
NSDebugLog(@"v = %@", v);
2021-01-16 15:55:01 +00:00
if ([v superview] == nil)
{
NSDebugLog(@"Add to view");
[self addSubview: v];
}
}
else
{
2021-01-16 15:58:34 +00:00
NSDebugLog(@"No view");
}
}
2021-01-16 15:55:01 +00:00
else
{
2021-01-16 15:58:34 +00:00
NSDebugLog(@"No cell");
2021-01-16 15:55:01 +00:00
}
}
}
}
2020-08-09 03:00:26 +00:00
- (instancetype) initWithFrame: (NSRect)frameRect
{
2020-08-23 04:57:29 +00:00
self = [super initWithFrame: frameRect];
2021-01-14 13:21:31 +00:00
2020-08-23 04:57:29 +00:00
if (self != nil)
{
_rows = [[NSMutableArray alloc] initWithCapacity: 10];
2021-01-14 13:21:31 +00:00
_columns = [[NSMutableArray alloc] initWithCapacity: 10];
_cells = [[NSMutableArray alloc] initWithCapacity: 10];
2020-08-23 04:57:29 +00:00
}
2021-01-14 13:21:31 +00:00
[self _refreshCells];
2020-08-23 04:57:29 +00:00
return self;
2020-08-09 03:00:26 +00:00
}
2020-08-23 08:12:38 +00:00
- (instancetype) initWithViews: (NSArray *)rows
{
self = [self initWithFrame: NSZeroRect];
2021-01-14 13:21:31 +00:00
2020-08-23 08:12:38 +00:00
if (self != nil)
{
FOR_IN(NSMutableArray*, row, rows)
2020-08-23 08:12:38 +00:00
{
}
2020-11-15 05:15:11 +00:00
END_FOR_IN(rows);
2020-08-23 08:12:38 +00:00
}
[self _refreshCells];
2020-08-23 08:12:38 +00:00
return self;
}
2020-08-09 03:00:26 +00:00
+ (instancetype) gridViewWithNumberOfColumns: (NSInteger)columnCount rows: (NSInteger)rowCount
{
2020-08-23 04:57:29 +00:00
NSUInteger r = 0;
NSUInteger c = 0;
NSMutableArray *rows = [[NSMutableArray alloc] initWithCapacity: rowCount];
for (r = 0; r < rowCount; r++)
{
NSMutableArray *col = [NSMutableArray arrayWithCapacity: columnCount];
for (c = 0; c < columnCount; c++)
{
NSGridCell *gc = [[NSGridCell alloc] init];
[col addObject: gc];
RELEASE(gc);
}
[rows addObject: col];
}
return AUTORELEASE([self gridViewWithViews: rows]);
2020-08-09 03:00:26 +00:00
}
+ (instancetype) gridViewWithViews: (NSArray *)rows
{
2020-08-23 08:12:38 +00:00
return [[self alloc] initWithViews: rows];
2020-08-09 03:00:26 +00:00
}
- (NSInteger) numberOfRows
{
2020-08-23 04:57:29 +00:00
return [_rows count];
2020-08-09 03:00:26 +00:00
}
- (NSInteger) numberOfColumns
{
2020-11-15 07:33:40 +00:00
return [_columns count];
2020-08-09 03:00:26 +00:00
}
- (NSGridRow *) rowAtIndex: (NSInteger)index
{
2021-01-14 11:55:11 +00:00
return [_rows objectAtIndex: index];
2020-08-09 03:00:26 +00:00
}
- (NSInteger) indexOfRow: (NSGridRow *)row
{
2021-01-14 11:55:11 +00:00
return [_rows indexOfObject: row];
2020-08-09 03:00:26 +00:00
}
- (NSGridColumn *) columnAtIndex: (NSInteger)index
{
2021-01-14 11:55:11 +00:00
return [_columns objectAtIndex: index];
2020-08-09 03:00:26 +00:00
}
- (NSInteger) indexOfColumn: (NSGridColumn *)column
{
2021-01-14 11:55:11 +00:00
return [_columns indexOfObject: column];
2020-08-09 03:00:26 +00:00
}
- (NSGridCell *) cellAtColumnIndex: (NSInteger)columnIndex rowIndex: (NSInteger)rowIndex
{
2021-01-14 13:21:31 +00:00
NSGridColumn *col = [_columns objectAtIndex: columnIndex];
NSGridCell *c = [col cellAtIndex: rowIndex];
return c;
2020-08-09 03:00:26 +00:00
}
- (NSGridCell *) cellForView: (NSView*)view
{
return nil;
}
- (NSGridRow *) addRowWithViews: (NSArray *)views
{
2021-01-14 11:55:11 +00:00
return [self insertRowAtIndex: [_rows count]
withViews: views];
2020-08-09 03:00:26 +00:00
}
- (NSGridRow *) insertRowAtIndex: (NSInteger)index withViews: (NSArray *)views
{
NSGridRow *gr = [[NSGridRow alloc] init];
2021-01-17 01:39:14 +00:00
2021-01-17 01:49:54 +00:00
// Insert the row and release...
2021-01-17 01:39:14 +00:00
[_rows insertObject: gr atIndex: index];
RELEASE(gr);
2021-01-17 01:49:54 +00:00
// Insert views...
2021-01-17 01:39:14 +00:00
FOR_IN(NSView*, v, views)
{
NSGridCell *c = [[NSGridCell alloc] init];
[c setContentView: v];
RELEASE(v);
[gr _addCell: c];
}
END_FOR_IN(views);
2021-01-17 01:49:54 +00:00
// Refresh...
[self _refreshCells];
return gr;
2020-08-09 03:00:26 +00:00
}
- (void) moveRowAtIndex: (NSInteger)fromIndex toIndex: (NSInteger)toIndex
{
[self _refreshCells];
2020-08-09 03:00:26 +00:00
}
- (void) removeRowAtIndex: (NSInteger)index
{
2021-01-14 11:55:11 +00:00
[_rows removeObjectAtIndex: index];
[self _refreshCells];
2020-08-09 03:00:26 +00:00
}
- (NSGridColumn *) addColumnWithViews: (NSArray*)views
{
2021-01-14 11:55:11 +00:00
return [self insertColumnAtIndex: [_columns count]
withViews: views];
2020-08-09 03:00:26 +00:00
}
- (NSGridColumn *) insertColumnAtIndex: (NSInteger)index withViews: (NSArray *)views
{
NSGridColumn *gc = [[NSGridColumn alloc] init];
[self _refreshCells];
return gc;
2020-08-09 03:00:26 +00:00
}
- (void) moveColumnAtIndex: (NSInteger)fromIndex toIndex: (NSInteger)toIndex
{
[self _refreshCells];
2020-08-09 03:00:26 +00:00
}
- (void) removeColumnAtIndex: (NSInteger)index
{
2021-01-14 11:55:11 +00:00
[_columns removeObjectAtIndex: index];
[self _refreshCells];
2020-08-09 03:00:26 +00:00
}
- (NSGridCellPlacement) xPlacement
{
2020-11-14 20:52:35 +00:00
return _xPlacement;
2020-08-09 03:00:26 +00:00
}
- (void) setXPlacement: (NSGridCellPlacement)x;
{
2020-11-14 20:52:35 +00:00
_xPlacement = x;
2020-08-09 03:00:26 +00:00
}
- (NSGridCellPlacement) yPlacement;
{
2020-11-14 20:52:35 +00:00
return _yPlacement;
2020-08-09 03:00:26 +00:00
}
- (void) setYPlacement: (NSGridCellPlacement)y;
{
2020-11-14 20:52:35 +00:00
_yPlacement = y;
2020-08-09 03:00:26 +00:00
}
- (NSGridRowAlignment) rowAlignment;
{
2020-11-14 20:52:35 +00:00
return _rowAlignment;
2020-08-09 03:00:26 +00:00
}
- (void) setRowAlignment: (NSGridRowAlignment)a;
{
2020-11-14 20:52:35 +00:00
_rowAlignment = a;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) rowSpacing
{
2020-11-14 20:52:35 +00:00
return _rowSpacing;
2020-08-09 03:00:26 +00:00
}
- (void) setRowSpacing: (CGFloat)f
{
2020-11-14 20:52:35 +00:00
_rowSpacing = f;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) columnSpacing
{
2020-11-14 20:52:35 +00:00
return _columnSpacing;
2020-08-09 03:00:26 +00:00
}
- (void) setColumnSpacing: (CGFloat)f
{
2020-11-14 20:52:35 +00:00
_columnSpacing = f;
2020-08-09 03:00:26 +00:00
}
- (void) mergeCellsInHorizontalRange: (NSRange)hRange verticalRange: (NSRange)vRange
{
[self _refreshCells];
2020-08-09 03:00:26 +00:00
}
// coding
- (void) encodeWithCoder: (NSCoder *)coder
{
2020-11-16 21:25:23 +00:00
[super encodeWithCoder: coder];
2021-01-14 13:21:31 +00:00
if ([coder allowsKeyedCoding])
{
[coder encodeInteger: _rowAlignment
forKey: @"NSGrid_alignment"];
[coder encodeFloat: _columnSpacing
forKey: @"NSGrid_columnSpacing"];
[coder encodeObject: _columns
forKey: @"NSGrid_columns"];
[coder encodeFloat: _rowSpacing
forKey: @"NSGrid_rowSpacing"];
[coder encodeObject: _rows
forKey: @"NSGrid_rows"];
[coder encodeInteger: _xPlacement
forKey: @"NSGrid_xPlacement"];
[coder encodeInteger: _yPlacement forKey: @"NSGrid_yPlacement"];
[coder encodeObject: _cells
forKey: @"NSGrid_cells"];
}
else
{
[coder encodeValueOfObjCType:@encode(NSUInteger)
at:&_rowAlignment];
[coder encodeValueOfObjCType:@encode(CGFloat)
at:&_columnSpacing];
[coder encodeObject: _columns];
[coder encodeValueOfObjCType:@encode(CGFloat)
at:&_rowSpacing];
[coder encodeObject: _rows];
[coder encodeValueOfObjCType:@encode(NSUInteger)
at:&_xPlacement];
[coder encodeValueOfObjCType:@encode(NSUInteger)
at:&_yPlacement];
[coder encodeObject: _cells];
}
2020-08-09 03:00:26 +00:00
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
2020-11-16 21:25:23 +00:00
self = [super initWithCoder: coder];
if (self != nil)
2020-11-14 20:52:35 +00:00
{
NSDebugLog(@"%@ %@",NSStringFromClass([self class]), NSStringFromSelector(_cmd));
if ([coder allowsKeyedCoding])
2020-11-14 20:52:35 +00:00
{
if ([coder containsValueForKey: @"NSGrid_alignment"])
{
_rowAlignment = [coder decodeIntegerForKey: @"NSGrid_alignment"];
}
if ([coder containsValueForKey: @"NSGrid_columnSpacing"])
{
_columnSpacing = [coder decodeFloatForKey: @"NSGrid_columnSpacing"];
}
if ([coder containsValueForKey: @"NSGrid_columns"])
{
ASSIGN(_columns, [coder decodeObjectForKey: @"NSGrid_columns"]);
// NSDebugLog(@"_columns = %@", _columns);
}
if ([coder containsValueForKey: @"NSGrid_rowSpacing"])
{
_rowSpacing = [coder decodeFloatForKey: @"NSGrid_rowSpacing"];
}
if ([coder containsValueForKey: @"NSGrid_rows"])
{
ASSIGN(_rows, [coder decodeObjectForKey: @"NSGrid_rows"]);
// NSDebugLog(@"_rows = %@", _rows);
}
if ([coder containsValueForKey: @"NSGrid_xPlacement"])
{
_xPlacement = [coder decodeIntegerForKey: @"NSGrid_xPlacement"];
}
if ([coder containsValueForKey: @"NSGrid_yPlacement"])
{
_yPlacement = [coder decodeIntegerForKey: @"NSGrid_yPlacement"];
}
if ([coder containsValueForKey: @"NSGrid_cells"])
{
ASSIGN(_cells, [coder decodeObjectForKey: @"NSGrid_cells"]);
}
2020-11-14 20:52:35 +00:00
}
else
2020-11-14 20:52:35 +00:00
{
[coder decodeValueOfObjCType:@encode(NSUInteger)
at:&_rowAlignment];
[coder decodeValueOfObjCType:@encode(CGFloat)
at:&_columnSpacing];
ASSIGN(_columns, [coder decodeObject]);
[coder decodeValueOfObjCType:@encode(CGFloat)
at:&_rowSpacing];
ASSIGN(_rows, [coder decodeObject]);
[coder decodeValueOfObjCType:@encode(NSUInteger)
at:&_xPlacement];
[coder decodeValueOfObjCType:@encode(NSUInteger)
at:&_yPlacement];
ASSIGN(_cells, [coder decodeObject]);
2020-11-14 20:52:35 +00:00
}
}
[self _refreshCells];
2020-08-09 03:00:26 +00:00
return self;
}
2021-01-14 11:55:11 +00:00
- (void) dealloc
{
RELEASE(_columns);
RELEASE(_rows);
RELEASE(_cells);
[super dealloc];
}
2020-08-09 03:00:26 +00:00
@end
/// Cell ///
@implementation NSGridCell
+ (void) initialize
{
if (self == [NSGridCell class])
{
[self setVersion: 1];
}
}
2020-08-09 03:00:26 +00:00
- (NSView *) contentView
{
2020-08-23 08:12:38 +00:00
return _contentView;
2020-08-09 03:00:26 +00:00
}
- (void) setContentView: (NSView *)v
{
2020-08-23 08:12:38 +00:00
ASSIGN(_contentView, v);
2020-08-09 03:00:26 +00:00
}
+ (NSView *) emptyContentView
{
2020-08-23 04:57:29 +00:00
return AUTORELEASE([[NSView alloc] initWithFrame: NSZeroRect]);
2020-08-09 03:00:26 +00:00
}
// Weak references to row/column
- (NSGridRow *) row
{
2020-11-23 05:44:08 +00:00
return _owningRow;
2020-08-09 03:00:26 +00:00
}
- (NSGridColumn *) column
{
2020-11-23 05:44:08 +00:00
return _owningColumn;
2020-08-09 03:00:26 +00:00
}
// Placement
- (NSGridCellPlacement) xPlacement
{
2020-11-23 05:44:08 +00:00
return _xPlacement;
2020-08-09 03:00:26 +00:00
}
- (void) setXPlacement: (NSGridCellPlacement)x
{
2020-11-23 05:44:08 +00:00
_xPlacement = x;
2020-08-09 03:00:26 +00:00
}
- (NSGridCellPlacement) yPlacement
{
2020-11-23 05:44:08 +00:00
return _yPlacement;
2020-08-09 03:00:26 +00:00
}
- (void) setYPlacement: (NSGridCellPlacement)y
{
2020-11-23 05:44:08 +00:00
_yPlacement = y;
2020-08-09 03:00:26 +00:00
}
- (NSGridRowAlignment) rowAlignment
{
2020-11-23 05:44:08 +00:00
return _rowAlignment;
2020-08-09 03:00:26 +00:00
}
- (void) setRowAlignment: (NSGridRowAlignment)a
{
2020-11-23 05:44:08 +00:00
_rowAlignment = a;
2020-08-09 03:00:26 +00:00
}
// Constraints
- (NSArray *) customPlacementConstraints
{
return nil;
}
// coding
- (void) encodeWithCoder: (NSCoder *)coder
{
2020-11-14 20:52:35 +00:00
if ([coder allowsKeyedCoding])
{
[coder encodeObject: _contentView
forKey: @"NSGrid_content"];
[coder encodeObject: _mergeHead
forKey: @"NSGrid_mergeHead"];
[coder encodeObject: _owningRow
forKey: @"NSGrid_owningRow"]; // weak
[coder encodeObject: _owningColumn
forKey: @"NSGrid_owningColumn"]; // weak
[coder encodeInteger: _xPlacement
forKey: @"NSGrid_xPlacement"];
[coder encodeInteger: _yPlacement
forKey: @"NSGrid_yPlacement"];
[coder encodeInteger: _rowAlignment
forKey: @"NSGrid_alignment"];
2020-11-14 20:52:35 +00:00
}
else
{
[coder encodeObject: [self contentView]];
[coder encodeObject: _mergeHead];
[coder encodeObject: _owningRow];
[coder encodeObject: _owningColumn];
[coder encodeValueOfObjCType:@encode(NSInteger)
at: &_xPlacement];
[coder encodeValueOfObjCType:@encode(NSInteger)
at: &_yPlacement];
[coder encodeValueOfObjCType:@encode(NSInteger)
at: &_rowAlignment];
2020-11-14 20:52:35 +00:00
}
2020-08-09 03:00:26 +00:00
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super init];
if (self != nil)
2020-11-14 20:52:35 +00:00
{
NSDebugLog(@"%@ %@",NSStringFromClass([self class]), NSStringFromSelector(_cmd));
if ([coder allowsKeyedCoding])
2020-11-15 06:34:04 +00:00
{
if ([coder containsValueForKey: @"NSGrid_content"])
{
[self setContentView: [coder decodeObjectForKey: @"NSGrid_content"]];
2021-01-16 15:58:34 +00:00
// NSDebugLog(@"contentView = %@", [self contentView]);
}
if ([coder containsValueForKey: @"NSGrid_mergeHead"])
{
_mergeHead = [coder decodeObjectForKey: @"NSGrid_mergeHead"];
}
if ([coder containsValueForKey: @"NSGrid_owningRow"])
{
_owningRow = [coder decodeObjectForKey: @"NSGrid_owningRow"]; // weak
2021-01-16 15:55:01 +00:00
NSDebugLog(@"_owningRow = %@", _owningRow);
[_owningRow _addCell: self];
}
if ([coder containsValueForKey: @"NSGrid_owningColumn"])
{
_owningColumn = [coder decodeObjectForKey: @"NSGrid_owningColumn"]; // weak
2021-01-16 15:55:01 +00:00
NSDebugLog(@"_owningColumn = %@", _owningColumn);
[_owningColumn _addCell: self];
}
if ([coder containsValueForKey: @"NSGrid_xPlacement"])
{
_xPlacement = [coder decodeIntegerForKey: @"NSGrid_xPlacement"];
}
if ([coder containsValueForKey: @"NSGrid_yPlacement"])
{
_yPlacement = [coder decodeIntegerForKey: @"NSGrid_yPlacement"];
}
if ([coder containsValueForKey: @"NSGrid_alignment"])
{
_rowAlignment = [coder decodeIntegerForKey: @"NSGrid_alignment"];
}
2020-11-15 06:34:04 +00:00
}
else
2020-11-15 06:34:04 +00:00
{
[self setContentView: [coder decodeObject]];
ASSIGN(_mergeHead, [coder decodeObject]);
_owningRow = [coder decodeObject]; // weak
2021-01-16 15:55:01 +00:00
[_owningRow _addCell: self];
_owningColumn = [coder decodeObject]; // weak
2021-01-16 15:55:01 +00:00
[_owningRow _addCell: self];
[coder decodeValueOfObjCType: @encode(NSInteger)
at: &_xPlacement];
[coder decodeValueOfObjCType:@encode(NSInteger)
at: &_yPlacement];
[coder decodeValueOfObjCType:@encode(NSInteger)
at: &_rowAlignment];
2020-11-15 06:34:04 +00:00
}
2020-11-14 20:52:35 +00:00
}
2020-08-09 03:00:26 +00:00
return self;
}
2021-01-14 11:55:11 +00:00
- (void) dealloc
{
RELEASE(_mergeHead);
[super dealloc];
}
@end
2020-08-09 03:00:26 +00:00
/// Column ///
@implementation NSGridColumn
+ (void) initialize
{
if (self == [NSGridColumn class])
{
[self setVersion: 1];
}
}
2021-01-16 15:55:01 +00:00
- (void) _addCell: (NSGridCell *)c
{
[_cells addObject: c];
}
2020-08-09 03:00:26 +00:00
- (NSGridView *) gridView
{
2020-11-15 05:04:02 +00:00
return _gridView;
2020-08-09 03:00:26 +00:00
}
- (NSInteger) numberOfCells
{
2021-01-16 15:55:01 +00:00
return [_cells count];
2020-08-09 03:00:26 +00:00
}
- (NSGridCell *) cellAtIndex:(NSInteger)index
{
2021-01-16 15:55:01 +00:00
return [_cells objectAtIndex: index];
2020-08-09 03:00:26 +00:00
}
- (NSGridCellPlacement) xPlacement
{
2020-11-15 05:04:02 +00:00
return _xPlacement;
2020-08-09 03:00:26 +00:00
}
- (void) setXPlacement: (NSGridCellPlacement)x
{
2020-11-15 05:04:02 +00:00
_xPlacement = x;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) width
{
2020-11-15 05:04:02 +00:00
return _width;
2020-08-09 03:00:26 +00:00
}
- (void) setWidth: (CGFloat)f
{
2020-11-15 05:04:02 +00:00
_width = f;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) leadingPadding
{
2020-11-15 05:04:02 +00:00
return _leadingPadding;
2020-08-09 03:00:26 +00:00
}
- (void) setLeadingPadding: (CGFloat)f
{
2020-11-15 05:04:02 +00:00
_leadingPadding = f;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) trailingPadding
{
2020-11-15 05:04:02 +00:00
return _trailingPadding;
2020-08-09 03:00:26 +00:00
}
- (void) setTrailingPadding: (CGFloat)f
{
2020-11-15 05:04:02 +00:00
_trailingPadding = f;
2020-08-09 03:00:26 +00:00
}
- (BOOL) isHidden
{
2020-11-15 05:04:02 +00:00
return _isHidden;
2020-08-09 03:00:26 +00:00
}
- (void) mergeCellsInRange: (NSRange)range
{
}
// coding
- (void) encodeWithCoder: (NSCoder *)coder
{
2020-11-16 21:25:23 +00:00
if ([coder allowsKeyedCoding])
{
[coder encodeBool: _isHidden
forKey: @"NSGrid_hidden"];
[coder encodeFloat: _leadingPadding
forKey: @"NSGrid_leadingPadding"];
[coder encodeObject: _gridView
forKey: @"NSGrid_owningGrid"]; // weak
[coder encodeFloat: _trailingPadding
forKey: @"NSGrid_trailingPadding"];
[coder encodeFloat: _width
forKey: @"NSGrid_width"];
[coder encodeInteger: _xPlacement
forKey: @"NSGrid_xPlacement"];
2020-11-16 21:25:23 +00:00
}
else
{
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_isHidden];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_leadingPadding];
2021-01-11 13:24:19 +00:00
[coder encodeObject: _gridView];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_trailingPadding];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_width];
[coder encodeValueOfObjCType: @encode(NSInteger)
at: &_xPlacement];
2020-11-16 21:25:23 +00:00
}
2020-08-09 03:00:26 +00:00
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super init];
if (self != nil)
2020-11-15 04:59:22 +00:00
{
NSDebugLog(@"%@ %@",NSStringFromClass([self class]), NSStringFromSelector(_cmd));
2021-01-16 15:55:01 +00:00
_cells = [[NSMutableArray alloc] initWithCapacity: 10];
if ([coder allowsKeyedCoding])
2020-11-15 04:59:22 +00:00
{
if ([coder containsValueForKey: @"NSGrid_hidden"])
{
_isHidden = [coder decodeBoolForKey: @"NSGrid_hidden"];
}
if ([coder containsValueForKey: @"NSGrid_leadingPadding"])
{
_leadingPadding = [coder decodeFloatForKey: @"NSGrid_leadingPadding"];
}
if ([coder containsValueForKey: @"NSGrid_owningGrid"])
{
_gridView = [coder decodeObjectForKey: @"NSGrid_owningGrid"]; // weak
}
if ([coder containsValueForKey: @"NSGrid_trailingPadding"])
{
_trailingPadding = [coder decodeFloatForKey: @"NSGrid_trailingPadding"];
}
if ([coder containsValueForKey: @"NSGrid_width"])
{
_width = [coder decodeFloatForKey: @"NSGrid_width"];
2021-01-16 15:58:34 +00:00
NSDebugLog(@"_width = %f", _width);
}
if ([coder containsValueForKey: @"NSGrid_xPlacement"])
{
_xPlacement = [coder decodeIntegerForKey: @"NSGrid_xPlacement"];
}
2020-11-15 04:59:22 +00:00
}
else
2020-11-15 04:59:22 +00:00
{
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_isHidden];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_leadingPadding];
_gridView = [coder decodeObject];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_trailingPadding];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_width];
[coder decodeValueOfObjCType: @encode(NSInteger)
at: &_xPlacement];
2020-11-15 04:59:22 +00:00
}
}
2020-08-09 03:00:26 +00:00
return self;
}
2021-01-16 15:55:01 +00:00
- (instancetype) init
{
self = [super init];
if (self != nil)
{
_cells = [[NSMutableArray alloc] initWithCapacity: 10];
}
return self;
}
- (void) dealloc
{
RELEASE(_cells);
[super dealloc];
}
2020-08-09 03:00:26 +00:00
@end
/// Row ///
@implementation NSGridRow
+ (void) initialize
2020-08-23 08:12:38 +00:00
{
if (self == [NSGridRow class])
{
[self setVersion: 1];
}
2020-08-23 08:12:38 +00:00
}
2021-01-16 15:55:01 +00:00
- (void) _addCell: (NSGridCell *)c
{
[_cells addObject: c];
}
2020-08-23 08:12:38 +00:00
- (void) setGridView: (NSGridView *)gridView
{
_gridView = gridView; // weak reference...
}
2020-08-09 03:00:26 +00:00
- (NSGridView *) gridView
{
2020-08-23 08:12:38 +00:00
return _gridView;
2020-08-09 03:00:26 +00:00
}
- (NSInteger) numberOfCells
{
2021-01-16 15:55:01 +00:00
return [_cells count];
2020-08-09 03:00:26 +00:00
}
- (NSGridCell *) cellAtIndex:(NSInteger)index
{
2021-01-16 15:55:01 +00:00
return [_cells objectAtIndex: index];
2020-08-09 03:00:26 +00:00
}
- (NSGridCellPlacement) yPlacement
{
2020-08-23 08:12:38 +00:00
return _yPlacement;
2020-08-09 03:00:26 +00:00
}
2020-08-23 08:12:38 +00:00
- (void) setYPlacement: (NSGridCellPlacement)y
2020-08-09 03:00:26 +00:00
{
2020-08-23 08:12:38 +00:00
_yPlacement = y;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) height
{
2020-08-23 08:12:38 +00:00
return _height;
2020-08-09 03:00:26 +00:00
}
- (void) setHeight: (CGFloat)f
{
2020-08-23 08:12:38 +00:00
_height = f;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) topPadding
{
2020-08-23 08:12:38 +00:00
return _topPadding;
2020-08-09 03:00:26 +00:00
}
- (void) setTopPadding: (CGFloat)f
{
2020-08-23 08:12:38 +00:00
_topPadding = f;
2020-08-09 03:00:26 +00:00
}
- (CGFloat) bottomPadding
{
2020-08-23 08:12:38 +00:00
return _bottomPadding;
2020-08-09 03:00:26 +00:00
}
- (void) setBottomPadding: (CGFloat)f
{
2020-08-23 08:12:38 +00:00
_bottomPadding = f;
2020-08-09 03:00:26 +00:00
}
- (BOOL) isHidden
{
2020-08-23 08:12:38 +00:00
return _isHidden;
}
- (void) setHidden: (BOOL)flag
{
_isHidden = flag;
2020-08-09 03:00:26 +00:00
}
- (void) mergeCellsInRange: (NSRange)range
{
}
// coding
- (void) encodeWithCoder: (NSCoder *)coder
{
2020-11-16 20:49:25 +00:00
if ([coder allowsKeyedCoding])
{
[coder encodeBool: _isHidden forKey: @"NSGrid_hidden"];
[coder encodeFloat: _bottomPadding forKey: @"NSGrid_bottomPadding"];
[coder encodeObject: _gridView forKey: @"NSGrid_owningGrid"];
[coder encodeFloat: _topPadding forKey: @"NSGrid_topPadding"];
[coder encodeFloat: _height forKey: @"NSGrid_height"];
[coder encodeFloat: _yPlacement forKey: @"NSGrid_yPlacement"];
}
else
{
[coder encodeValueOfObjCType: @encode(BOOL)
at: &_isHidden];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_bottomPadding];
2021-01-11 14:19:40 +00:00
[coder encodeObject: _gridView];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_topPadding];
[coder encodeValueOfObjCType: @encode(CGFloat)
at: &_height];
[coder encodeValueOfObjCType: @encode(NSInteger)
at: &_yPlacement];
2020-11-16 20:49:25 +00:00
}
2020-08-09 03:00:26 +00:00
}
- (instancetype) initWithCoder: (NSCoder *)coder
{
self = [super init];
if (self != nil)
2020-11-15 06:34:04 +00:00
{
NSDebugLog(@"%@ %@",NSStringFromClass([self class]), NSStringFromSelector(_cmd));
2021-01-16 15:55:01 +00:00
_cells = [[NSMutableArray alloc] initWithCapacity: 10];
if ([coder allowsKeyedCoding])
2020-11-15 06:34:04 +00:00
{
if ([coder containsValueForKey: @"NSGrid_hidden"])
{
_isHidden = [coder decodeBoolForKey: @"NSGrid_hidden"];
}
if ([coder containsValueForKey: @"NSGrid_bottomPadding"])
{
_bottomPadding = [coder decodeFloatForKey: @"NSGrid_bottomPadding"];
}
if ([coder containsValueForKey: @"NSGrid_owningGrid"])
{
_gridView = [coder decodeObjectForKey: @"NSGrid_owningGrid"];
}
if ([coder containsValueForKey: @"NSGrid_topPadding"])
{
_topPadding = [coder decodeFloatForKey: @"NSGrid_topPadding"];
}
if ([coder containsValueForKey: @"NSGrid_height"])
{
_height = [coder decodeFloatForKey: @"NSGrid_height"];
2021-01-16 15:58:34 +00:00
NSDebugLog(@"_height = %f", _height);
}
if ([coder containsValueForKey: @"NSGrid_yPlacement"])
{
_yPlacement = [coder decodeFloatForKey: @"NSGrid_yPlacement"];
}
2020-11-15 06:34:04 +00:00
}
else
2020-11-15 06:34:04 +00:00
{
[coder decodeValueOfObjCType: @encode(BOOL)
at: &_isHidden];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_bottomPadding];
_gridView = [coder decodeObject];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_topPadding];
[coder decodeValueOfObjCType: @encode(CGFloat)
at: &_height];
[coder decodeValueOfObjCType: @encode(NSInteger)
at: &_yPlacement];
2020-11-15 06:34:04 +00:00
}
}
2020-08-09 03:00:26 +00:00
return self;
}
2021-01-16 15:55:01 +00:00
- (instancetype) init
{
self = [super init];
if (self != nil)
{
_cells = [[NSMutableArray alloc] initWithCapacity: 10];
}
return self;
}
- (void) dealloc
{
RELEASE(_cells);
[super dealloc];
}
2020-08-09 03:00:26 +00:00
@end