Merge pull request #154 from gnustep/NSTableCellView_branch

Implement view based cells in NSTableView
This commit is contained in:
Gregory Casamento 2024-04-24 15:57:25 -04:00 committed by GitHub
commit d0db2dd2ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
24 changed files with 1172 additions and 196 deletions

View file

@ -249,10 +249,12 @@
@class NSColorWell;
@class NSImage;
@class NSMenuItemCell;
@class NSOutlineView;
@class NSPopUpButtonCell;
@class NSMenuView;
@class NSProgressIndicator;
@class NSTableHeaderCell;
@class NSTableView;
@class NSTabViewItem;
@class NSPathControl;
@class NSPathComponentCell;
@ -1337,7 +1339,15 @@ APPKIT_EXPORT_CLASS
- (void) drawTableViewRow: (NSInteger)rowIndex
clipRect: (NSRect)clipRect
inView: (NSView *)view;
inView: (NSTableView *)view;
- (void) drawCellViewRow: (NSInteger)rowIndex
clipRect: (NSRect)clipRect
inView: (NSTableView *)v;
- (void) drawOutlineViewRow: (NSInteger)rowIndex
clipRect: (NSRect)clipRect
inView: (NSOutlineView *)view;
- (BOOL) isBoxOpaque: (NSBox *)box;

View file

@ -243,10 +243,13 @@
#import <AppKit/NSSwitch.h>
#import <AppKit/NSSplitViewController.h>
#import <AppKit/NSSplitViewItem.h>
#import <AppKit/NSTableCellView.h>
#import <AppKit/NSTableColumn.h>
#import <AppKit/NSTableHeaderCell.h>
#import <AppKit/NSTableHeaderView.h>
#import <AppKit/NSTableRowView.h>
#import <AppKit/NSTableView.h>
#import <AppKit/NSTableViewRowAction.h>
#import <AppKit/NSTabView.h>
#import <AppKit/NSTabViewController.h>
#import <AppKit/NSTabViewItem.h>

View file

@ -64,6 +64,9 @@ APPKIT_EXPORT_CLASS
- (BOOL)allowsCutCopyPaste;
- (void)setAllowsCutCopyPaste:(BOOL)flag;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_12, GS_API_LATEST)
+ (instancetype) imageViewWithImage: (NSImage *)image;
#endif
@end

View file

@ -297,6 +297,23 @@ willDisplayOutlineCell: (id)cell
didClickTableColumn: (NSTableColumn *)aTableColumn;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
- (NSView *) outlineView: (NSOutlineView *)outlineView
viewForTableColumn: (NSTableColumn *)aTableColumn
item: (id)item;
- (NSTableRowView *) outlineView: (NSOutlineView *)outlineView
rowViewForItem: (id)item;
- (void) outlineView: (NSOutlineView *)outlineView
didAddRowView: (NSTableRowView *)rowView
forRow: (NSInteger)rowIndex;
- (void) outlineView: (NSOutlineView *)outlineView
didRemoveRowView: (NSTableRowView *)rowView
forRow: (NSInteger)rowIndex;
#endif
@end
#endif /* _GNUstep_H_NSOutlineView */

View file

@ -0,0 +1,83 @@
/* Definition of class NSTableCellView
Copyright (C) 2022 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: 03-09-2022
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.
*/
#ifndef _NSTableCellView_h_GNUSTEP_GUI_INCLUDE
#define _NSTableCellView_h_GNUSTEP_GUI_INCLUDE
#import <AppKit/NSView.h>
#import <AppKit/NSCell.h>
#import <AppKit/NSTableView.h>
#import <AppKit/NSNibDeclarations.h>
#import <AppKit/AppKitDefines.h>
#import <AppKit/NSTableView.h>
#import <AppKit/NSNibDeclarations.h>
#import <AppKit/AppKitDefines.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
#if defined(__cplusplus)
extern "C" {
#endif
@class NSImageView, NSTextField, NSArray;
APPKIT_EXPORT_CLASS
@interface NSTableCellView : NSView
{
id _objectValue;
IBOutlet NSImageView *_imageView;
IBOutlet NSTextField *_textField;
NSArray *_draggingImageComponents;
NSBackgroundStyle _backgroundStyle;
NSTableViewRowSizeStyle _rowSizeStyle;
}
- (id) objectValue;
- (void) setObjectValue: (id)objectValue;
- (NSImageView *) imageView;
- (void) setImageView: (NSImageView *)imageView;
- (NSTextField *) textField;
- (void) setTextField: (NSTextField *)textField;
- (NSBackgroundStyle) backgroundStyle;
- (void) setBackgroundStyle: (NSBackgroundStyle)backgroundStyle;
- (NSTableViewRowSizeStyle) rowSizeStyle;
- (void) setRowSizeStyle: (NSTableViewRowSizeStyle) rowSizeStyle;
- (NSArray *) draggingImageComponents;
- (void) setDraggingImageComponents: (NSArray *)draggingImageComponents;
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSTableCellView_h_GNUSTEP_GUI_INCLUDE */

View file

@ -37,6 +37,7 @@
@class NSSortDescriptor;
@class NSCell;
@class NSTableView;
@class NSMutableArray;
// TODO: Finish to implement hidden, header tool tip and resizing mask
// and update the archiving code to support them.
@ -72,6 +73,7 @@ APPKIT_EXPORT_CLASS
NSCell *_dataCell;
NSString *_headerToolTip;
NSSortDescriptor *_sortDescriptorPrototype;
NSMutableArray *_prototypeCellViews;
}
/*
* Initializing an NSTableColumn instance
@ -131,6 +133,13 @@ APPKIT_EXPORT_CLASS
- (void) setSortDescriptorPrototype: (NSSortDescriptor *)aSortDescriptor;
- (NSSortDescriptor *) sortDescriptorPrototype;
#endif
/*
* Title
*/
#if OS_API_VERSION(MAC_OS_X_VERSION_10_10, GS_API_LATEST)
- (void) setTitle: (NSString *)title;
- (NSString *) title;
#endif
@end
/* Notifications */

View file

@ -0,0 +1,46 @@
/* Definition of class NSTableRowView
Copyright (C) 2022 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: 03-09-2022
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.
*/
#ifndef _NSTableRowView_h_GNUSTEP_GUI_INCLUDE
#define _NSTableRowView_h_GNUSTEP_GUI_INCLUDE
#import <AppKit/NSView.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
#if defined(__cplusplus)
extern "C" {
#endif
@interface NSTableRowView : NSView
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSTableRowView_h_GNUSTEP_GUI_INCLUDE */

View file

@ -33,15 +33,18 @@
#import <AppKit/NSControl.h>
#import <AppKit/NSDragging.h>
#import <AppKit/NSUserInterfaceValidation.h>
#import <AppKit/NSUserInterfaceItemIdentification.h>
@class NSArray;
@class NSIndexSet;
@class NSMutableIndexSet;
@class NSTableColumn;
@class NSTableHeaderView;
@class NSTableRowView;
@class NSText;
@class NSImage;
@class NSURL;
@class NSNib;
typedef enum _NSTableViewDropOperation {
NSTableViewDropOn,
@ -88,6 +91,15 @@ typedef enum _NSTableViewAnimationOptions
NSTableViewAnimationSlideLeft = 0x30,
NSTableViewAnimationSlideRight = 0x40,
} NSTableViewAnimationOptions;
typedef enum _NSTableViewRowSizeStyle
{
NSTableViewRowSizeStyleDefault = -1,
NSTableViewRowSizeStyleCustom = 0,
NSTableViewRowSizeStyleSmall = 1,
NSTableViewRowSizeStyleMedium = 2,
NSTableViewRowSizeStyleLarge = 3,
} NSTableViewRowSizeStyle;
#endif
@ -156,7 +168,8 @@ APPKIT_EXPORT_CLASS
* We cache column origins (precisely, the x coordinate of the left
* origin of each column). When a column width is changed through
* [NSTableColumn setWidth:], then [NSTableView tile] gets called,
* which updates the cache. */
* which updates the cache.
*/
CGFloat *_columnOrigins;
/*
@ -175,6 +188,13 @@ APPKIT_EXPORT_CLASS
NSDragOperation _draggingSourceOperationMaskForRemote;
NSInteger _beginEndUpdates;
/* Supporting ivars for view based tables */
BOOL _viewBased;
NSMapTable *_renderedViewPaths;
NSMapTable *_pathsToViews;
NSMutableDictionary *_registeredNibs;
NSMutableDictionary *_registeredViews;
}
/* Data Source */
@ -381,6 +401,13 @@ APPKIT_EXPORT_CLASS
- (void) insertRowsAtIndexes: (NSIndexSet*)indexes withAnimation: (NSTableViewAnimationOptions)animationOptions;
- (void) removeRowsAtIndexes: (NSIndexSet*)indexes withAnimation: (NSTableViewAnimationOptions)animationOptions;
- (NSInteger) rowForView: (NSView*)view;
- (NSView *) makeViewWithIdentifier: (NSUserInterfaceItemIdentifier)identifier owner: (id)owner;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_8, GS_API_LATEST)
- (void) registerNib: (NSNib *)nib
forIdentifier: (NSUserInterfaceItemIdentifier)identifier;
- (NSDictionary *) registeredNibsByIdentifier;
#endif
@end /* interface of NSTableView */
@ -498,6 +525,24 @@ dataCellForTableColumn: (NSTableColumn *)aTableColumn
row: (NSInteger)row
mouseLocation: (NSPoint)mouse;
#endif
// NSTableCellView based table methods...
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)
- (NSView *) tableView: (NSTableView *)tableView
viewForTableColumn: (NSTableColumn *)aTableColumn
row: (NSInteger)rowIndex;
- (NSTableRowView *) tableView: (NSTableView *)tableView
rowViewForRow: (NSInteger)rowIndex;
- (void) tableView: (NSTableView *)tableView
didAddRowView: (NSTableRowView *)rowView
forRow: (NSInteger)rowIndex;
- (void) tableView: (NSTableView *)tableView
didRemoveRowView: (NSTableRowView *)rowView
forRow: (NSInteger)rowIndex;
#endif
@end
#endif /* _GNUstep_H_NSTableView */

View file

@ -0,0 +1,47 @@
/* Interface of class NSTableViewRowAction
Copyright (C) 2022 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: 04-09-2022
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.
*/
#ifndef _NSTableViewRowAction_h_GNUSTEP_GUI_INCLUDE
#define _NSTableViewRowAction_h_GNUSTEP_GUI_INCLUDE
#import <Foundation/NSObject.h>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_0, GS_API_LATEST)
#if defined(__cplusplus)
extern "C" {
#endif
@interface NSTableViewRowAction : NSObject
@end
#if defined(__cplusplus)
}
#endif
#endif /* GS_API_MACOSX */
#endif /* _NSTableViewRowAction_h_GNUSTEP_GUI_INCLUDE */

View file

@ -37,6 +37,7 @@
#import <AppKit/NSAppearance.h>
#import <AppKit/NSGraphicsContext.h>
#import <AppKit/NSResponder.h>
#import <AppKit/NSUserInterfaceItemIdentification.h>
#import <AppKit/NSUserInterfaceLayout.h>
#import <AppKit/NSLayoutConstraint.h>
@ -130,7 +131,7 @@ extern const CGFloat NSViewNoInstrinsicMetric;
extern const CGFloat NSViewNoIntrinsicMetric;
APPKIT_EXPORT_CLASS
@interface NSView : NSResponder <NSAppearanceCustomization>
@interface NSView : NSResponder <NSAppearanceCustomization, NSUserInterfaceItemIdentification>
{
NSRect _frame;
NSRect _bounds;
@ -197,6 +198,7 @@ PACKAGE_SCOPE
NSRect _autoresizingFrameError;
NSShadow *_shadow;
NSAppearance* _appearance;
NSUserInterfaceItemIdentifier _identifier;
}
/*

View file

@ -9,9 +9,6 @@ MISSING HEADERS ( * = difficult, - = quick, + = placeholder, x = won't do )
> NSItemProvider.h +
> NSMenuToolbarItem.h -
> NSOpenGLLayer.h +
> NSTableCellView.h *
> NSTableRowView.h *
> NSTableViewRowAction.h *
> NSTypesetter.h +
> NSUserActivity.h -
> NSWindowTab.h +

View file

@ -261,10 +261,13 @@ NSStatusItem.m \
NSTabView.m \
NSTabViewController.m \
NSTabViewItem.m \
NSTableCellView.m \
NSTableColumn.m \
NSTableHeaderView.m \
NSTableHeaderCell.m \
NSTableView.m \
NSTableViewRowAction.m \
NSTableRowView.m \
NSText.m \
NSTextAlternatives.m \
NSTextAttachment.m \
@ -580,10 +583,13 @@ NSSwitch.h \
NSTabView.h \
NSTabViewController.h \
NSTabViewItem.h \
NSTableCellView.h \
NSTableColumn.h \
NSTableHeaderCell.h \
NSTableHeaderView.h \
NSTableView.h \
NSTableViewRowAction.h \
NSTableRowView.h \
NSText.h \
NSTextAlternatives.h \
NSTextAttachment.h \

View file

@ -43,8 +43,10 @@
#import "AppKit/NSColorWell.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSImageView.h"
#import "AppKit/NSMenuView.h"
#import "AppKit/NSMenuItemCell.h"
#import "AppKit/NSOutlineView.h"
#import "AppKit/NSParagraphStyle.h"
#import "AppKit/NSPopUpButtonCell.h"
#import "AppKit/NSProgressIndicator.h"
@ -52,9 +54,11 @@
#import "AppKit/NSScrollView.h"
#import "AppKit/NSStringDrawing.h"
#import "AppKit/NSTableView.h"
#import "AppKit/NSTableCellView.h"
#import "AppKit/NSTableColumn.h"
#import "AppKit/NSTableHeaderCell.h"
#import "AppKit/NSTableHeaderView.h"
#import "AppKit/NSTableView.h"
#import "AppKit/NSView.h"
#import "AppKit/NSTabView.h"
#import "AppKit/NSTabViewItem.h"
@ -63,6 +67,7 @@
#import "AppKit/NSPathCell.h"
#import "AppKit/NSPathControl.h"
#import "AppKit/NSPathComponentCell.h"
#import "GNUstepGUI/GSToolbarView.h"
#import "GNUstepGUI/GSTitleView.h"
@ -77,6 +82,12 @@
row: (NSInteger)index;
- (id)_objectValueForTableColumn: (NSTableColumn *)tb
row: (NSInteger)index;
- (NSView *) _renderedViewForPath: (NSIndexPath *)path;
- (void) _setRenderedView: (NSView *)view forPath: (NSIndexPath *)path;
@end
@interface NSTableColumn (Private)
- (NSArray *) _prototypeCellViews;
@end
@interface NSCell (Private)
@ -3299,7 +3310,6 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
NSInteger numberOfColumns = [tableView numberOfColumns];
NSIndexSet *selectedRows = [tableView selectedRowIndexes];
NSIndexSet *selectedColumns = [tableView selectedColumnIndexes];
NSColor *backgroundColor = [tableView backgroundColor];
// Set the fill color
{
@ -3376,9 +3386,8 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
- (void) drawTableViewRow: (NSInteger)rowIndex
clipRect: (NSRect)clipRect
inView: (NSView *)view
inView: (NSTableView *)tableView
{
NSTableView *tableView = (NSTableView *)view;
// NSInteger numberOfRows = [tableView numberOfRows];
NSInteger numberOfColumns = [tableView numberOfColumns];
// NSIndexSet *selectedRows = [tableView selectedRowIndexes];
@ -3475,16 +3484,352 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
}
}
- (void) drawOutlineViewRow: (NSInteger)rowIndex
clipRect: (NSRect)clipRect
inView: (NSOutlineView *)outlineView
{
NSInteger numberOfColumns = [outlineView numberOfColumns];
CGFloat *columnOrigins = [outlineView _columnOrigins];
NSInteger editedRow = [outlineView editedRow];
NSInteger editedColumn = [outlineView editedColumn];
NSArray *tableColumns = [outlineView tableColumns];
CGFloat indentationPerLevel = [outlineView indentationPerLevel];
NSInteger numberOfRows = [outlineView numberOfRows];
NSInteger startingColumn;
NSInteger endingColumn;
NSRect drawingRect;
NSCell *imageCell = nil;
NSRect imageRect;
NSInteger i;
CGFloat x_pos;
id dataSource = [outlineView dataSource];
id delegate = [outlineView delegate];
NSTableColumn *outlineTableColumn = [outlineView outlineTableColumn];
if (dataSource == nil)
{
return;
}
/* Using columnAtPoint: here would make it called twice per row per drawn
rect - so we avoid it and do it natively */
if (rowIndex >= numberOfRows)
{
return;
}
/* Determine starting column as fast as possible */
x_pos = NSMinX (clipRect);
i = 0;
while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
{
i++;
}
startingColumn = (i - 1);
if (startingColumn == -1)
startingColumn = 0;
/* Determine ending column as fast as possible */
x_pos = NSMaxX (clipRect);
// Nota Bene: we do *not* reset i
while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
{
i++;
}
endingColumn = (i - 1);
if (endingColumn == -1)
endingColumn = numberOfColumns - 1;
/* Draw the row between startingColumn and endingColumn */
for (i = startingColumn; i <= endingColumn; i++)
{
id item = [outlineView itemAtRow: rowIndex];
NSTableColumn *tb = [tableColumns objectAtIndex: i];
NSCell *cell = [outlineView preparedCellAtColumn: i row: rowIndex];
[outlineView _willDisplayCell: cell
forTableColumn: tb
row: rowIndex];
if (i == editedColumn && rowIndex == editedRow)
{
[cell _setInEditing: YES];
[cell setShowsFirstResponder: YES];
}
else
{
[cell setObjectValue: [dataSource outlineView: outlineView
objectValueForTableColumn: tb
byItem: item]];
}
drawingRect = [outlineView frameOfCellAtColumn: i
row: rowIndex];
if (tb == outlineTableColumn)
{
NSImage *image = nil;
NSInteger level = 0;
CGFloat indentationFactor = 0.0;
// display the correct arrow...
if ([outlineView isItemExpanded: item])
{
image = [NSImage imageNamed: @"common_ArrowDownH"];
}
else
{
image = [NSImage imageNamed: @"common_ArrowRightH"];
}
if (![outlineView isExpandable: item])
{
image = AUTORELEASE([[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]);
}
level = [outlineView levelForItem: item];
indentationFactor = indentationPerLevel * level;
imageCell = [[NSCell alloc] initImageCell: image];
imageRect = [outlineView frameOfOutlineCellAtRow: rowIndex];
if ([delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
{
[delegate outlineView: outlineView
willDisplayOutlineCell: imageCell
forTableColumn: tb
item: item];
}
/* Do not indent if the delegate set the image to nil. */
if ([imageCell image])
{
imageRect.size.width = [image size].width;
imageRect.size.height = [image size].height;
[imageCell drawWithFrame: imageRect inView: outlineView];
drawingRect.origin.x
+= indentationFactor + imageRect.size.width + 5;
drawingRect.size.width
-= indentationFactor + imageRect.size.width + 5;
}
else
{
drawingRect.origin.x += indentationFactor;
drawingRect.size.width -= indentationFactor;
}
RELEASE(imageCell);
}
[cell drawWithFrame: drawingRect inView: outlineView];
if (i == editedColumn && rowIndex == editedRow)
{
[cell _setInEditing: NO];
[cell setShowsFirstResponder: NO];
}
}
}
- (void) drawCellViewRow: (NSInteger)rowIndex
clipRect: (NSRect)clipRect
inView: (NSTableView *)v
{
NSInteger numberOfColumns = [v numberOfColumns];
CGFloat *columnOrigins = [v _columnOrigins];
NSArray *tableColumns = [v tableColumns];
NSInteger numberOfRows = [v numberOfRows];
NSInteger startingColumn;
NSInteger endingColumn;
NSInteger i;
CGFloat x_pos;
id dataSource = [v dataSource];
id delegate = [v delegate];
BOOL hasMethod = NO;
NSTableColumn *outlineTableColumn = nil;
NSOutlineView *ov = nil;
// If we have no data source, there is nothing to do...
if (dataSource == nil)
{
return;
}
// If the rowIndex is greater than the numberOfRows, done...
if (rowIndex >= numberOfRows)
{
return;
}
// Check the delegate method...
hasMethod = [delegate respondsToSelector: @selector(outlineView:viewForTableColumn:item:)];
if (hasMethod)
{
ov = (NSOutlineView *)v;
outlineTableColumn = [ov outlineTableColumn];
}
else
{
hasMethod = [delegate respondsToSelector: @selector(tableView:viewForTableColumn:row:)];
}
/* Determine starting column as fast as possible */
x_pos = NSMinX (clipRect);
i = 0;
while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
{
i++;
}
startingColumn = (i - 1);
if (startingColumn == -1)
startingColumn = 0;
/* Determine ending column as fast as possible */
x_pos = NSMaxX (clipRect);
while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
{
i++;
}
endingColumn = (i - 1);
if (endingColumn == -1)
endingColumn = numberOfColumns - 1;
/* Draw the row between startingColumn and endingColumn */
for (i = startingColumn; i <= endingColumn; i++)
{
NSRect drawingRect = [v frameOfCellAtColumn: i
row: rowIndex];
NSTableColumn *tb = [tableColumns objectAtIndex: i];
NSIndexPath *path = [NSIndexPath indexPathForItem: i
inSection: rowIndex];
NSView *view = [v _renderedViewForPath: path];
if (ov != nil)
{
id item = [ov itemAtRow: rowIndex];
CGFloat indentationPerLevel = [ov indentationPerLevel];
if (tb == outlineTableColumn)
{
NSImage *image = nil;
NSInteger level = 0;
CGFloat indentationFactor = 0.0;
NSImageView *imageView = nil;
NSRect imageRect = NSZeroRect;
// display the correct arrow...
if ([ov isItemExpanded: item])
{
image = [NSImage imageNamed: @"common_ArrowDownH"];
}
else
{
image = [NSImage imageNamed: @"common_ArrowRightH"];
}
if (![ov isExpandable: item])
{
image = AUTORELEASE([[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]);
}
level = [ov levelForItem: item];
indentationFactor = indentationPerLevel * level;
imageView = [[NSImageView alloc] init];
[imageView setImage: image];
imageRect = [ov frameOfOutlineCellAtRow: rowIndex];
/* Do not indent if the delegate set the image to nil. */
if ([imageView image])
{
imageRect.size.width = [image size].width;
imageRect.size.height = [ov rowHeight];
// Place the image...
[imageView setFrame: imageRect];
[ov addSubview: imageView];
drawingRect.origin.x
+= indentationFactor + imageRect.size.width + 5;
drawingRect.size.width
-= indentationFactor + imageRect.size.width + 5;
}
else
{
drawingRect.origin.x += indentationFactor;
drawingRect.size.width -= indentationFactor;
}
RELEASE(imageView);
}
if (view == nil)
{
if (hasMethod && ov != nil)
{
view = [delegate outlineView: ov
viewForTableColumn: tb
item: item];
}
else
{
NSArray *protoCellViews = [tb _prototypeCellViews];
// it seems there is always one prototype...
if ([protoCellViews count] > 0)
{
view = [protoCellViews objectAtIndex: 0];
view = [view copy]; // instantiate the prototype...
}
}
[ov _setRenderedView: view forPath: path];
[ov addSubview: view];
}
}
else
{
// If the view has been stored use it, if not
// then grab it.
if (view == nil)
{
if (hasMethod)
{
view = [delegate tableView: v
viewForTableColumn: tb
row: rowIndex];
}
else
{
NSArray *protoCellViews = [tb _prototypeCellViews];
// it seems there is always one prototype...
if ([protoCellViews count] > 0)
{
view = [protoCellViews objectAtIndex: 0];
view = [view copy]; // instantiate the prototype...
}
}
// Store the object...
[v _setRenderedView: view forPath: path];
[v addSubview: view];
}
}
// Place the view...
[view setFrame: drawingRect];
}
}
- (BOOL) isBoxOpaque: (NSBox *)box
{
if ([box boxType] == NSBoxCustom)
{
return ![box isTransparent];
}
else
{
return YES;
}
return YES;
}
- (void) drawBoxInClipRect: (NSRect)clipRect

View file

@ -26,7 +26,9 @@
Boston, MA 02110-1301, USA.
*/
#import <Foundation/Foundation.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSDictionary.h>
#import "GNUstepGUI/GSXibKeyedUnarchiver.h"
@class GSXibElement;

View file

@ -169,6 +169,7 @@ static NSString *ApplicationClass = nil;
@implementation GSXib5KeyedUnarchiver
// Singleton dictionary that holds any cached XIB data... cells, etc.
static NSDictionary *XmlTagToObjectClassMap = nil;
static NSArray *XmlTagsNotStacked = nil;
static NSArray *XmlTagsToSkip = nil;
@ -206,7 +207,7 @@ static NSArray *XmlBoolDefaultYes = nil;
@"NSMutableArray", @"resources",
@"NSMutableArray", @"segments",
@"NSMutableArray", @"objectValues",
@"NSMutableArray", @"prototypeCellViews",
@"NSMutableArray", @"prototypeCellViews",
@"NSMutableArray", @"allowedToolbarItems",
@"NSMutableArray", @"defaultToolbarItems",
@"NSMutableArray", @"rowTemplates",
@ -221,7 +222,6 @@ static NSArray *XmlBoolDefaultYes = nil;
@"IBActionConnection", @"action",
@"NSNibBindingConnector", @"binding",
@"NSWindowTemplate", @"window",
@"NSView", @"tableCellView",
@"IBUserDefinedRuntimeAttribute5", @"userDefinedRuntimeAttribute",
@"NSURL", @"url",
@"NSLayoutConstraint", @"constraint",

View file

@ -69,6 +69,18 @@ static Class imageCellClass;
usedCellClass = factoryId ? factoryId : imageCellClass;
}
+ (instancetype) imageViewWithImage: (NSImage *)image
{
NSImageView *imageView = AUTORELEASE([[NSImageView alloc] init]);
[imageView setImage: image];
return imageView;
}
//
// Instance methods
//
- (id) initWithFrame: (NSRect)aFrame
{

View file

@ -39,8 +39,8 @@
*/
#import "config.h"
#import <Foundation/NSArray.h>
#import <Foundation/NSArchiver.h>
#import <Foundation/NSArray.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSData.h>
#import <Foundation/NSDebug.h>

View file

@ -62,6 +62,7 @@
#import "AppKit/NSTextFieldCell.h"
#import "AppKit/NSWindow.h"
#import "GNUstepGUI/GSTheme.h"
#import "GSGuiPrivate.h"
#include <math.h>
@ -297,6 +298,12 @@ static NSImage *unexpandable = nil;
// Should only mark the rect below the closed item for redraw
[self setNeedsDisplay: YES];
// If it is view based, then refresh the outline view...
if (_viewBased)
{
[self reloadData];
}
}
}
@ -374,6 +381,12 @@ static NSImage *unexpandable = nil;
// Should only mark the rect below the expanded item for redraw
[self setNeedsDisplay: YES];
// If it is view based, then refresh the outline view...
if (_viewBased)
{
[self reloadData];
}
}
}
@ -688,7 +701,9 @@ static NSImage *unexpandable = nil;
CHECK_REQUIRED_METHOD(outlineView:child:ofItem:);
CHECK_REQUIRED_METHOD(outlineView:isItemExpandable:);
CHECK_REQUIRED_METHOD(outlineView:numberOfChildrenOfItem:);
CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
// This method is @optional in NSOutlineViewDataSource as of macOS10.0
// CHECK_REQUIRED_METHOD(outlineView:objectValueForTableColumn:byItem:);
// Is the data source editable?
_dataSource_editable = [anObject respondsToSelector:
@ -705,6 +720,18 @@ static NSImage *unexpandable = nil;
*/
- (void) reloadData
{
// Refresh the views if it is view based...
if (_viewBased)
{
NSEnumerator *en = [[self subviews] objectEnumerator];
NSView *v = nil;
while ((v = [en nextObject]) != nil)
{
[v removeFromSuperview];
}
}
// release the old array
if (_items != nil)
{
@ -830,7 +857,7 @@ static NSImage *unexpandable = nil;
{
NSImage *image;
id item = [self itemAtRow:_clickedRow];
id item = [self itemAtRow: _clickedRow];
NSInteger level = [self levelForRow: _clickedRow];
NSInteger position = 0;
@ -852,7 +879,7 @@ static NSImage *unexpandable = nil;
if ([self isExpandable:item]
&& location.x >= position
&& location.x <= position + [image size].width)
&& location.x <= position + [image size].width + 5)
{
BOOL withChildren =
([theEvent modifierFlags] & NSAlternateKeyMask) ? YES : NO;
@ -922,136 +949,17 @@ static NSImage *unexpandable = nil;
*/
- (void) drawRow: (NSInteger)rowIndex clipRect: (NSRect)aRect
{
NSInteger startingColumn;
NSInteger endingColumn;
NSRect drawingRect;
NSCell *imageCell = nil;
NSRect imageRect;
NSInteger i;
CGFloat x_pos;
if (_dataSource == nil)
if (_viewBased)
{
return;
[[GSTheme theme] drawCellViewRow: rowIndex
clipRect: aRect
inView: self];
}
/* Using columnAtPoint: here would make it called twice per row per drawn
rect - so we avoid it and do it natively */
if (rowIndex >= _numberOfRows)
else
{
return;
}
/* Determine starting column as fast as possible */
x_pos = NSMinX (aRect);
i = 0;
while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
{
i++;
}
startingColumn = (i - 1);
if (startingColumn == -1)
startingColumn = 0;
/* Determine ending column as fast as possible */
x_pos = NSMaxX (aRect);
// Nota Bene: we do *not* reset i
while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i]))
{
i++;
}
endingColumn = (i - 1);
if (endingColumn == -1)
endingColumn = _numberOfColumns - 1;
/* Draw the row between startingColumn and endingColumn */
for (i = startingColumn; i <= endingColumn; i++)
{
id item = [self itemAtRow: rowIndex];
NSTableColumn *tb = [_tableColumns objectAtIndex: i];
NSCell *cell = [self preparedCellAtColumn: i row: rowIndex];
[self _willDisplayCell: cell
forTableColumn: tb
row: rowIndex];
if (i == _editedColumn && rowIndex == _editedRow)
{
[cell _setInEditing: YES];
[cell setShowsFirstResponder: YES];
}
else
{
[cell setObjectValue: [_dataSource outlineView: self
objectValueForTableColumn: tb
byItem: item]];
}
drawingRect = [self frameOfCellAtColumn: i
row: rowIndex];
if (tb == _outlineTableColumn)
{
NSImage *image = nil;
NSInteger level = 0;
CGFloat indentationFactor = 0.0;
// float originalWidth = drawingRect.size.width;
// display the correct arrow...
if ([self isItemExpanded: item])
{
image = expanded;
}
else
{
image = collapsed;
}
if (![self isExpandable: item])
{
image = unexpandable;
}
level = [self levelForItem: item];
indentationFactor = _indentationPerLevel * level;
imageCell = [[NSCell alloc] initImageCell: image];
imageRect = [self frameOfOutlineCellAtRow: rowIndex];
if ([_delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)])
{
[_delegate outlineView: self
willDisplayOutlineCell: imageCell
forTableColumn: tb
item: item];
}
/* Do not indent if the delegate set the image to nil. */
if ([imageCell image])
{
imageRect.size.width = [image size].width;
imageRect.size.height = [image size].height;
[imageCell drawWithFrame: imageRect inView: self];
drawingRect.origin.x
+= indentationFactor + imageRect.size.width + 5;
drawingRect.size.width
-= indentationFactor + imageRect.size.width + 5;
}
else
{
drawingRect.origin.x += indentationFactor;
drawingRect.size.width -= indentationFactor;
}
RELEASE(imageCell);
}
[cell drawWithFrame: drawingRect inView: self];
if (i == _editedColumn && rowIndex == _editedRow)
{
[cell _setInEditing: NO];
[cell setShowsFirstResponder: NO];
}
[[GSTheme theme] drawOutlineViewRow: rowIndex
clipRect: aRect
inView: self];
}
}
@ -1804,9 +1712,9 @@ Also returns the child index relative to this parent. */
- (BOOL) _shouldSelectionChange
{
if ([_delegate respondsToSelector:
@selector (selectionShouldChangeInTableView:)] == YES)
@selector (selectionShouldChangeInOutlineView:)] == YES)
{
if ([_delegate selectionShouldChangeInTableView: self] == NO)
if ([_delegate selectionShouldChangeInOutlineView: self] == NO)
{
return NO;
}
@ -2273,19 +2181,24 @@ Also returns the child index relative to this parent. */
- (NSCell *) preparedCellAtColumn: (NSInteger)columnIndex row: (NSInteger)rowIndex
{
NSCell *cell = nil;
NSTableColumn *tb = [_tableColumns objectAtIndex: columnIndex];
if ([_delegate respondsToSelector:
@selector(outlineView:dataCellForTableColumn:item:)])
if (_viewBased == NO)
{
id item = [self itemAtRow: rowIndex];
cell = [_delegate outlineView: self dataCellForTableColumn: tb
item: item];
}
if (cell == nil)
{
cell = [tb dataCellForRow: rowIndex];
NSTableColumn *tb = [_tableColumns objectAtIndex: columnIndex];
if ([_delegate respondsToSelector:
@selector(outlineView:dataCellForTableColumn:item:)])
{
id item = [self itemAtRow: rowIndex];
cell = [_delegate outlineView: self dataCellForTableColumn: tb
item: item];
}
if (cell == nil)
{
cell = [tb dataCellForRow: rowIndex];
}
}
return cell;
}

216
Source/NSTableCellView.m Normal file
View file

@ -0,0 +1,216 @@
/* Implementation of class NSTableCellView
Copyright (C) 2022 Free Software Foundation, Inc.
By: Gregory John Casamento <greg.casamento@gmail.com>
Date: 12-12-2022
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.
*/
#import "AppKit/NSTableCellView.h"
#import "AppKit/NSImageView.h"
#import "AppKit/NSTextField.h"
@implementation NSTableCellView
- (instancetype) initWithFrame: (NSRect)frame
{
self = [super initWithFrame: frame];
if (self != nil)
{
_rowSizeStyle = NSTableViewRowSizeStyleDefault;
_backgroundStyle = NSBackgroundStyleLight;
}
return self;
}
- (instancetype) init
{
return [self initWithFrame: NSZeroRect];
}
- (void) dealloc
{
RELEASE(_objectValue);
RELEASE(_imageView);
RELEASE(_textField);
RELEASE(_draggingImageComponents);
[super dealloc];
}
- (id) objectValue
{
return _objectValue;
}
- (void) setObjectValue: (id)objectValue
{
ASSIGN(_objectValue, objectValue);
}
- (NSImageView *) imageView
{
return _imageView;
}
- (void) setImageView: (NSImageView *)imageView
{
ASSIGN(_imageView, imageView);
}
- (NSTextField *) textField
{
return _textField;
}
- (void) setTextField: (NSTextField *)textField
{
ASSIGN(_textField, textField);
}
- (NSBackgroundStyle) backgroundStyle
{
return _backgroundStyle;
}
- (void) setBackgroundStyle: (NSBackgroundStyle)backgroundStyle
{
_backgroundStyle = backgroundStyle;
}
- (NSTableViewRowSizeStyle) rowSizeStyle
{
return _rowSizeStyle;
}
- (void) setRowSizeStyle: (NSTableViewRowSizeStyle)rowSizeStyle
{
_rowSizeStyle = rowSizeStyle;
}
- (NSArray *) draggingImageComponents
{
return _draggingImageComponents;
}
- (void) setDraggingImageComponents: (NSArray *)draggingImageComponents
{
ASSIGNCOPY(_draggingImageComponents, draggingImageComponents);
}
- (void) encodeWithCoder: (NSCoder *)coder
{
[super encodeWithCoder: coder];
if ([coder allowsKeyedCoding])
{
[coder encodeObject: [self objectValue]
forKey: @"NSObjectValue"];
[coder encodeObject: [self imageView]
forKey: @"NSImageView"];
[coder encodeObject: [self textField]
forKey: @"NSTextField"];
[coder encodeInt: [self backgroundStyle]
forKey: @"NSBackgroundStyle"];
[coder encodeInt: [self rowSizeStyle]
forKey: @"NSTableViewRowSizeStyle"];
[coder encodeObject: [self draggingImageComponents]
forKey: @"NSDraggingImageComponents"];
}
else
{
[coder encodeObject: _objectValue];
[coder encodeObject: _imageView];
[coder encodeObject: _textField];
[coder encodeObject: _draggingImageComponents];
[coder encodeValueOfObjCType: @encode(NSBackgroundStyle)
at: &_backgroundStyle];
[coder encodeValueOfObjCType: @encode(NSTableViewRowSizeStyle)
at: &_rowSizeStyle];
}
}
- (id) initWithCoder: (NSCoder *)coder
{
self = [super initWithCoder: coder];
if (self != nil)
{
if ([coder allowsKeyedCoding])
{
if ([coder containsValueForKey: @"NSObjectValue"])
{
[self setObjectValue: [coder decodeObjectForKey: @"NSObjectValue"]];
}
if ([coder containsValueForKey: @"NSImageView"])
{
[self setImageView: [coder decodeObjectForKey: @"NSImageView"]];
}
if ([coder containsValueForKey: @"NSTextField"])
{
[self setTextField: [coder decodeObjectForKey: @"NSTextField"]];
}
if ([coder containsValueForKey: @"NSBackgroundStyle"])
{
[self setBackgroundStyle: [coder decodeIntForKey: @"NSBackgroundStyle"]];
}
if ([coder containsValueForKey: @"NSTableViewRowSizeStyle"])
{
[self setRowSizeStyle: [coder decodeIntForKey: @"NSTableViewRowSizeStyle"]];
}
if ([coder containsValueForKey: @"NSDraggingImageComponents"])
{
[self setDraggingImageComponents: [coder decodeObjectForKey: @"NSDraggingImageComponents"]];
}
}
else
{
[self setObjectValue: [coder decodeObject]];
[self setImageView: [coder decodeObject]];
[self setTextField: [coder decodeObject]];
[self setDraggingImageComponents: [coder decodeObject]];
[coder decodeValueOfObjCType: @encode(NSBackgroundStyle)
at: &_backgroundStyle];
[coder decodeValueOfObjCType: @encode(NSTableViewRowSizeStyle)
at: &_rowSizeStyle];
}
}
return self;
}
- (id) copyWithZone: (NSZone *)zone
{
NSTableCellView *copy = [[NSTableCellView allocWithZone: zone] init];
[copy setObjectValue: [self objectValue]];
[copy setImageView: [self imageView]];
[copy setTextField: [self textField]];
[copy setDraggingImageComponents: [self draggingImageComponents]];
[copy setBackgroundStyle: [self backgroundStyle]];
[copy setRowSizeStyle: [self rowSizeStyle]];
return copy;
}
@end

View file

@ -73,6 +73,7 @@
#import "AppKit/NSTableView.h"
#import "GSBindingHelpers.h"
/**
<p>
NSTableColumn objects represent columns in NSTableViews.
@ -89,7 +90,7 @@
{
if (self == [NSTableColumn class])
{
[self setVersion: 3];
[self setVersion: 4];
[self exposeBinding: NSValueBinding];
[self exposeBinding: NSEnabledBinding];
}
@ -127,8 +128,9 @@
_headerToolTip = nil;
_sortDescriptorPrototype = nil;
ASSIGN (_identifier, anObject);
_prototypeCellViews = nil;
ASSIGN (_identifier, anObject);
return self;
}
@ -141,6 +143,7 @@
RELEASE(_headerToolTip);
RELEASE(_dataCell);
RELEASE(_sortDescriptorPrototype);
RELEASE(_prototypeCellViews);
TEST_RELEASE(_identifier);
[super dealloc];
}
@ -491,6 +494,7 @@ to YES. */
[aCoder encodeObject: _headerToolTip forKey: @"NSHeaderToolTip"];
[aCoder encodeBool: _is_hidden forKey: @"NSHidden"];
[aCoder encodeObject: _tableView forKey: @"NSTableView"];
[aCoder encodeObject: _prototypeCellViews forKey: @"NSPrototypeCellViews"];
}
else
{
@ -506,6 +510,7 @@ to YES. */
[aCoder encodeObject: _dataCell];
[aCoder encodeObject: _sortDescriptorPrototype];
[aCoder encodeObject: _prototypeCellViews];
}
}
@ -572,6 +577,10 @@ to YES. */
{
[self setTableView: [aDecoder decodeObjectForKey: @"NSTableView"]];
}
if ([aDecoder containsValueForKey: @"NSPrototypeCellViews"])
{
ASSIGN(_prototypeCellViews, [aDecoder decodeObjectForKey: @"NSPrototypeCellViews"]);
}
}
else
{
@ -597,6 +606,11 @@ to YES. */
{
_sortDescriptorPrototype = RETAIN([aDecoder decodeObject]);
}
if (version >= 4)
{
_prototypeCellViews = RETAIN([aDecoder decodeObject]);
}
}
else
{
@ -613,6 +627,21 @@ to YES. */
return self;
}
- (NSArray *) _prototypeCellViews
{
return _prototypeCellViews;
}
- (void) setTitle: (NSString *)title
{
[_headerCell setStringValue: title];
}
- (NSString *) title
{
return [_headerCell stringValue];
}
- (void) setValue: (id)anObject forKey: (NSString*)aKey
{
if ([aKey isEqual: NSValueBinding])

30
Source/NSTableRowView.m Normal file
View file

@ -0,0 +1,30 @@
/* Implementation of class NSTableRowView
Copyright (C) 2022 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: 03-09-2022
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.
*/
#import "AppKit/NSTableRowView.h"
@implementation NSTableRowView
@end

View file

@ -54,6 +54,7 @@
#import "AppKit/NSImage.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSKeyValueBinding.h"
#import "AppKit/NSNib.h"
#import "AppKit/NSScroller.h"
#import "AppKit/NSScrollView.h"
#import "AppKit/NSTableColumn.h"
@ -66,13 +67,15 @@
#import "AppKit/NSPasteboard.h"
#import "AppKit/NSDragging.h"
#import "AppKit/NSCustomImageRep.h"
#import "GNUstepGUI/GSTheme.h"
#import "GSBindingHelpers.h"
#include <math.h>
static NSNotificationCenter *nc = nil;
static const int currentVersion = 5;
static const int currentVersion = 6;
static NSRect oldDraggingRect;
static NSInteger oldDropRow;
@ -2043,6 +2046,11 @@ static void computeNewSelection
| NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate;
_draggingSourceOperationMaskForRemote = NSDragOperationNone;
ASSIGN(_sortDescriptors, [NSArray array]);
_viewBased = NO;
_renderedViewPaths = RETAIN([NSMapTable strongToWeakObjectsMapTable]);
_pathsToViews = RETAIN([NSMapTable weakToStrongObjectsMapTable]);
_registeredNibs = [[NSMutableDictionary alloc] init];
_registeredViews = [[NSMutableDictionary alloc] init];
}
- (id) initWithFrame: (NSRect)frameRect
@ -2074,6 +2082,10 @@ static void computeNewSelection
RELEASE (_selectedColumns);
RELEASE (_selectedRows);
RELEASE (_sortDescriptors);
RELEASE (_renderedViewPaths);
RELEASE (_pathsToViews);
RELEASE (_registeredNibs);
RELEASE (_registeredViews);
TEST_RELEASE (_headerView);
TEST_RELEASE (_cornerView);
if (_autosaveTableColumns == YES)
@ -2354,6 +2366,12 @@ static void computeNewSelection
- (void) reloadData
{
if (_viewBased)
{
[_renderedViewPaths removeAllObjects];
[_pathsToViews removeAllObjects];
}
[self noteNumberOfRowsChanged];
[self setNeedsDisplay: YES];
}
@ -3216,18 +3234,23 @@ byExtendingSelection: (BOOL)flag
- (NSCell *) preparedCellAtColumn: (NSInteger)columnIndex row: (NSInteger)rowIndex
{
NSCell *cell = nil;
NSTableColumn *tb = [_tableColumns objectAtIndex: columnIndex];
if ([_delegate respondsToSelector:
@selector(tableView:dataCellForTableColumn:row:)])
{
cell = [_delegate tableView: self dataCellForTableColumn: tb
row: rowIndex];
}
if (cell == nil)
{
cell = [tb dataCellForRow: rowIndex];
if (_viewBased == NO)
{
NSTableColumn *tb = [_tableColumns objectAtIndex: columnIndex];
if ([_delegate respondsToSelector:
@selector(tableView:dataCellForTableColumn:row:)])
{
cell = [_delegate tableView: self dataCellForTableColumn: tb
row: rowIndex];
}
if (cell == nil)
{
cell = [tb dataCellForRow: rowIndex];
}
}
return cell;
}
@ -3851,26 +3874,27 @@ if (currentRow >= 0 && currentRow < _numberOfRows) \
* so they need to track in mouse up.
*/
NSCell *cell = [self preparedCellAtColumn: _clickedColumn
row: _clickedRow];
row: _clickedRow];
[self _trackCellAtColumn: _clickedColumn
row: _clickedRow
withEvent: theEvent];
row: _clickedRow
withEvent: theEvent];
didTrackCell = YES;
if ([[cell class] prefersTrackingUntilMouseUp])
{
/* the mouse could have gone up outside of the cell
* avoid selecting the row under mouse cursor */
{
/* the mouse could have gone up outside of the cell
* avoid selecting the row under mouse cursor */
sendAction = YES;
done = YES;
}
}
/*
* Since we may have tracked a cell which may have caused
* a change to the currentEvent we may need to loop over
* the current event
*/
*/
getNextEvent = (lastEvent == [NSApp currentEvent]);
}
else
@ -5030,9 +5054,18 @@ This method is deprecated, use -columnIndexesInRect:. */
- (void) drawRow: (NSInteger)rowIndex clipRect: (NSRect)clipRect
{
[[GSTheme theme] drawTableViewRow: rowIndex
clipRect: clipRect
inView: self];
if (_viewBased)
{
[[GSTheme theme] drawCellViewRow: rowIndex
clipRect: clipRect
inView: self];
}
else
{
[[GSTheme theme] drawTableViewRow: rowIndex
clipRect: clipRect
inView: self];
}
}
- (void) noteHeightOfRowsWithIndexesChanged: (NSIndexSet*)indexes
@ -5306,7 +5339,8 @@ This method is deprecated, use -columnIndexesInRect:. */
- (void) setDelegate: (id)anObject
{
const SEL sel = @selector(tableView:willDisplayCell:forTableColumn:row:);
const SEL vbsel = @selector(tableView:viewForTableColumn:row:);
if (_delegate)
[nc removeObserver: _delegate name: nil object: self];
_delegate = anObject;
@ -5324,6 +5358,9 @@ This method is deprecated, use -columnIndexesInRect:. */
/* Cache */
_del_responds = [_delegate respondsToSelector: sel];
/* Test to see if it is view based */
_viewBased = [_delegate respondsToSelector: vbsel];
}
- (id) delegate
@ -5512,6 +5549,9 @@ This method is deprecated, use -columnIndexesInRect:. */
// encode..
[aCoder encodeInt: vFlags forKey: @"NSTvFlags"];
// Encode that the table is view based...
[aCoder encodeBool: _viewBased forKey: @"NSViewBased"];
}
else
{
@ -5547,6 +5587,7 @@ This method is deprecated, use -columnIndexesInRect:. */
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
[aCoder encodeObject: _sortDescriptors];
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_viewBased];
}
}
@ -5695,6 +5736,11 @@ This method is deprecated, use -columnIndexesInRect:. */
[self setUsesAlternatingRowBackgroundColors: tableViewFlags.alternatingRowBackgroundColors];
}
if ([aDecoder containsValueForKey: @"NSViewBased"])
{
_viewBased = [aDecoder decodeBoolForKey: @"NSViewBased"];
}
// get the table columns...
columns = [aDecoder decodeObjectForKey: @"NSTableColumns"];
e = [columns objectEnumerator];
@ -5744,10 +5790,12 @@ This method is deprecated, use -columnIndexesInRect:. */
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsEmptySelection];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnSelection];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
if (version >= 3)
{
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnReordering];
}
if (version >= 2)
{
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_autoresizesAllColumnsToFit];
@ -5757,10 +5805,16 @@ This method is deprecated, use -columnIndexesInRect:. */
{
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
}
if (version >= 5)
{
ASSIGN(_sortDescriptors, [aDecoder decodeObject]);
}
if (version >= 6)
{
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_viewBased];
}
if (_numberOfColumns > 0)
{
@ -6692,20 +6746,20 @@ For a more detailed explanation, -setSortDescriptors:. */
GSKeyValueBinding *theBinding;
theBinding = [GSKeyValueBinding getBinding: NSValueBinding
forObject: tb];
forObject: tb];
if (theBinding != nil)
{
return [(NSArray *)[theBinding destinationValue]
objectAtIndex: index];
objectAtIndex: index];
}
else if ([_dataSource respondsToSelector:
@selector(tableView:objectValueForTableColumn:row:)])
@selector(tableView:objectValueForTableColumn:row:)])
{
result = [_dataSource tableView: self
objectValueForTableColumn: tb
row: index];
row: index];
}
return result;
}
@ -6714,12 +6768,12 @@ For a more detailed explanation, -setSortDescriptors:. */
row: (NSInteger) index
{
if ([_dataSource respondsToSelector:
@selector(tableView:setObjectValue:forTableColumn:row:)])
@selector(tableView:setObjectValue:forTableColumn:row:)])
{
[_dataSource tableView: self
setObjectValue: value
forTableColumn: tb
row: index];
setObjectValue: value
forTableColumn: tb
row: index];
}
}
@ -6822,7 +6876,8 @@ For a more detailed explanation, -setSortDescriptors:. */
- (NSInteger) columnForView: (NSView*)view
{
return NSNotFound;
NSIndexPath *path = [_pathsToViews objectForKey: view];
return [path item];
}
- (void) insertRowsAtIndexes: (NSIndexSet*)indexes
@ -6837,7 +6892,62 @@ For a more detailed explanation, -setSortDescriptors:. */
- (NSInteger) rowForView: (NSView*)view
{
return NSNotFound;
NSIndexPath *path = [_pathsToViews objectForKey: view];
return [path section];
}
- (NSView *) makeViewWithIdentifier: (NSUserInterfaceItemIdentifier)identifier owner: (id)owner
{
NSView *view = [_registeredViews objectForKey: identifier];
if (view != nil)
{
view = [view copy];
// [owner awakeFromNib];
}
else
{
NSNib *nib = [_registeredNibs objectForKey: identifier];
if (nib != nil)
{
NSArray *tlo = nil;
BOOL loaded = [nib instantiateWithOwner: owner
topLevelObjects: &tlo];
if (loaded)
{
NSEnumerator *en = [tlo objectEnumerator];
id o = nil;
while ((o = [en nextObject]) != nil)
{
if ([o isKindOfClass: [NSView class]])
{
view = o;
break;
}
}
}
else
{
NSLog(@"Failed to load model for identifier %@, in %@", identifier, self);
}
}
}
return view;
}
- (void) registerNib: (NSNib *)nib
forIdentifier: (NSUserInterfaceItemIdentifier)identifier
{
[_registeredNibs setObject: nib
forKey: identifier];
}
- (NSDictionary *) registeredNibsByIdentifier
{
return [_registeredNibs copy];
}
@end /* implementation of NSTableView */
@ -7028,4 +7138,15 @@ For a more detailed explanation, -setSortDescriptors:. */
}
}
- (NSView *) _renderedViewForPath: (NSIndexPath *)path
{
return [_renderedViewPaths objectForKey: path];
}
- (void) _setRenderedView: (NSView *)view forPath: (NSIndexPath *)path
{
[_renderedViewPaths setObject: view forKey: path];
[_pathsToViews setObject: path forKey: view];
}
@end

View file

@ -0,0 +1,30 @@
/* Implementation of class NSTableViewRowAction
Copyright (C) 2022 Free Software Foundation, Inc.
By: Gregory John Casamento
Date: 04-09-2022
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.
*/
#import "AppKit/NSTableViewRowAction.h"
@implementation NSTableViewRowAction
@end

View file

@ -5281,6 +5281,16 @@ static NSView* findByTag(NSView *view, NSInteger aTag, NSUInteger *level)
}
}
- (void) setIdentifier: (NSUserInterfaceItemIdentifier) identifier
{
ASSIGN(_identifier, identifier);
}
- (NSUserInterfaceItemIdentifier) identifier
{
return _identifier;
}
@end
#if OS_API_VERSION(MAC_OS_X_VERSION_10_7, GS_API_LATEST)