2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSTableColumn</title>
|
1999-12-02 03:04:37 +00:00
|
|
|
|
|
|
|
Copyright (C) 1999 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Nicola Pero <n.pero@mi.flashnet.it>
|
|
|
|
Date: December 1999
|
|
|
|
Completely Rewritten.
|
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1999-12-02 03:04:37 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
1999-12-02 03:04:37 +00:00
|
|
|
|
|
|
|
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
|
2007-10-29 21:16:17 +00:00
|
|
|
Lesser General Public License for more details.
|
1999-12-02 03:04:37 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1999-12-02 03:04:37 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
1999-12-02 03:04:37 +00:00
|
|
|
|
2002-08-29 10:07:51 +00:00
|
|
|
<chapter>
|
|
|
|
<heading>Overview of NSTableColumn</heading>
|
2001-12-17 16:51:51 +00:00
|
|
|
<section>
|
|
|
|
<heading>The Column Identifier</heading>
|
|
|
|
<p>
|
|
|
|
Each NSTableColumn object is identified by an object, called
|
|
|
|
the column identifier. The reason is that, after a column has been
|
|
|
|
added to a table view, the user might move the columns around, so
|
|
|
|
there is a need to identify the columns regardless of their position
|
|
|
|
in the table.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
The identifier is typically a string describing the column.
|
|
|
|
This identifier object is never displayed to the user !
|
|
|
|
It is only used internally by the program to identify
|
|
|
|
the column - so yes, you may use a funny string for it
|
|
|
|
and nobody will know, except people reading the code.
|
|
|
|
</p>
|
|
|
|
</section>
|
|
|
|
<section>
|
|
|
|
<heading>Information Stored in an NSTableColumn Object</heading>
|
|
|
|
<p>
|
|
|
|
An NSTableColumn object mainly keeps information about the width
|
|
|
|
of the column, its minimum and maximum width; whether the column
|
|
|
|
can be edited or resized; and the cells used to draw the column
|
|
|
|
header and the data in the column. You can change all these
|
|
|
|
attributes of the column by calling the appropriate methods.
|
|
|
|
Please note that the table column does not hold nor has access
|
|
|
|
to the data to be displayed in the column; this data is maintained
|
|
|
|
in the table view's data source, as described in the NSTableView
|
|
|
|
documentation. A last hint: to set the title of a table column,
|
|
|
|
ask the table column for its header cell, and set the string value
|
|
|
|
of this header cell to the desired title.
|
|
|
|
</p>
|
|
|
|
</section>
|
2002-08-29 10:07:51 +00:00
|
|
|
</chapter>
|
2001-12-17 16:51:51 +00:00
|
|
|
*/
|
2002-08-29 10:07:51 +00:00
|
|
|
|
2010-03-31 08:14:50 +00:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2012-03-12 12:24:17 +00:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2009-12-20 23:28:05 +00:00
|
|
|
#import <Foundation/NSNotification.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import <Foundation/NSSortDescriptor.h>
|
2012-03-12 12:24:17 +00:00
|
|
|
#import "AppKit/NSKeyValueBinding.h"
|
2009-12-20 23:28:05 +00:00
|
|
|
#import "AppKit/NSTableHeaderCell.h"
|
|
|
|
#import "AppKit/NSTableColumn.h"
|
|
|
|
#import "AppKit/NSTableView.h"
|
2012-03-12 12:24:17 +00:00
|
|
|
#import "GSBindingHelpers.h"
|
2002-08-29 10:07:51 +00:00
|
|
|
|
2024-04-26 16:40:11 +00:00
|
|
|
@interface NSTableView (__NSTableColumnPrivate__)
|
|
|
|
- (void) _registerPrototypeViews: (NSArray *)prototypeViews;
|
|
|
|
@end
|
|
|
|
|
2024-03-18 04:31:41 +00:00
|
|
|
|
2002-08-29 10:07:51 +00:00
|
|
|
/**
|
|
|
|
<p>
|
|
|
|
NSTableColumn objects represent columns in NSTableViews.
|
|
|
|
</p>
|
|
|
|
*/
|
1999-07-19 19:13:10 +00:00
|
|
|
@implementation NSTableColumn
|
1999-12-02 03:04:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Class methods
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSTableColumn class])
|
2012-03-12 12:24:17 +00:00
|
|
|
{
|
2024-02-11 14:19:40 +00:00
|
|
|
[self setVersion: 4];
|
2012-03-12 12:24:17 +00:00
|
|
|
[self exposeBinding: NSValueBinding];
|
|
|
|
[self exposeBinding: NSEnabledBinding];
|
2024-07-11 16:18:52 +00:00
|
|
|
[self exposeBinding: NSEditableBinding];
|
2024-07-15 10:50:20 +00:00
|
|
|
[self exposeBinding: NSFontBinding];
|
|
|
|
[self exposeBinding: NSFontNameBinding];
|
|
|
|
[self exposeBinding: NSFontSizeBinding];
|
2012-03-12 12:24:17 +00:00
|
|
|
}
|
1999-12-02 03:04:37 +00:00
|
|
|
}
|
1999-07-19 19:13:10 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Instance methods
|
|
|
|
*
|
|
|
|
*/
|
1999-07-19 19:13:10 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Initialize the column. anObject is an object used to identify the
|
|
|
|
column; it is usually a string, but might be any kind of object.
|
|
|
|
anObject is retained. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (id) initWithIdentifier: (id)anObject
|
1999-12-02 03:04:37 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
2008-05-01 19:48:28 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
2008-02-16 16:45:10 +00:00
|
|
|
_width = 100;
|
|
|
|
_min_width = 10;
|
1999-12-02 03:04:37 +00:00
|
|
|
_max_width = 100000;
|
2009-12-08 17:01:01 +00:00
|
|
|
_resizing_mask = NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask;
|
1999-12-02 03:04:37 +00:00
|
|
|
_is_resizable = YES;
|
2000-09-10 14:59:25 +00:00
|
|
|
_is_editable = YES;
|
2009-12-08 17:01:01 +00:00
|
|
|
_is_hidden = NO;
|
1999-12-02 03:04:37 +00:00
|
|
|
_tableView = nil;
|
1999-07-19 19:13:10 +00:00
|
|
|
|
2009-12-20 23:28:05 +00:00
|
|
|
_headerCell = [[NSTableHeaderCell alloc] init];
|
|
|
|
_dataCell = [[NSTextFieldCell alloc] init];
|
2009-12-17 01:49:20 +00:00
|
|
|
[_dataCell setLineBreakMode: NSLineBreakByTruncatingTail];
|
2012-01-15 21:34:40 +00:00
|
|
|
[_dataCell setEditable: YES];
|
2009-12-08 17:01:01 +00:00
|
|
|
_headerToolTip = nil;
|
1999-07-19 19:13:10 +00:00
|
|
|
|
2009-12-08 17:07:25 +00:00
|
|
|
_sortDescriptorPrototype = nil;
|
2024-02-11 14:19:40 +00:00
|
|
|
_prototypeCellViews = nil;
|
|
|
|
|
|
|
|
ASSIGN (_identifier, anObject);
|
1999-07-19 19:13:10 +00:00
|
|
|
return self;
|
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) dealloc
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
2012-03-12 12:24:17 +00:00
|
|
|
// Remove all key value bindings for this view.
|
|
|
|
[GSKeyValueBinding unbindAllForObject: self];
|
|
|
|
|
|
|
|
RELEASE(_headerCell);
|
|
|
|
RELEASE(_headerToolTip);
|
|
|
|
RELEASE(_dataCell);
|
|
|
|
RELEASE(_sortDescriptorPrototype);
|
2024-02-11 14:19:40 +00:00
|
|
|
RELEASE(_prototypeCellViews);
|
2012-03-12 12:24:17 +00:00
|
|
|
TEST_RELEASE(_identifier);
|
1999-12-02 03:04:37 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
/*
|
|
|
|
* Managing the Identifier
|
|
|
|
*/
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the identifier used to identify the table. The old identifier
|
|
|
|
is released, and the new one is retained. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setIdentifier: (id)anObject
|
1999-12-02 03:04:37 +00:00
|
|
|
{
|
|
|
|
ASSIGN (_identifier, anObject);
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return the column identifier, an object used to identify the column.
|
|
|
|
This object is usually a string, but might be any kind of object.
|
|
|
|
*/
|
2009-12-20 23:28:05 +00:00
|
|
|
- (id) identifier
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _identifier;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
1999-12-02 03:04:37 +00:00
|
|
|
/*
|
|
|
|
* Setting the NSTableView
|
|
|
|
*/
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the table view corresponding to this table column. This method
|
|
|
|
is invoked internally by the table view, and you should not call it
|
|
|
|
directly; it is exposed because you may want to override it in
|
|
|
|
subclasses. To use the table column in a table view, you should use
|
|
|
|
NSTableView's addTableColumn: instead. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setTableView: (NSTableView*)aTableView
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
// We do *not* RETAIN aTableView.
|
|
|
|
// On the contrary, aTableView is supposed to RETAIN us.
|
|
|
|
_tableView = aTableView;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return the table view the column belongs to, or nil if the table
|
|
|
|
column was not added to any table view. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (NSTableView *) tableView
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _tableView;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
/*
|
|
|
|
* Controlling size
|
|
|
|
*/
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the width of the table column. Before being resized, the new
|
|
|
|
width is constrained to the table column minimum and maximum width:
|
|
|
|
if newWidth is smaller than the table column's min width, the table
|
|
|
|
column is simply resized to its min width. If newWidth is bigger
|
|
|
|
than the table column's max width, the table column is simply
|
|
|
|
resized to its max width. Otherwise, it is resized to newWidth. If
|
|
|
|
the width of the table was actually changed, the table view (if any)
|
|
|
|
is redisplayed (by calling tile), and the
|
|
|
|
NSTableViewColumnDidResizeNotification is posted on behalf of the
|
|
|
|
table view. */
|
2013-02-17 22:44:47 +00:00
|
|
|
- (void) setWidth: (CGFloat)newWidth
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
2013-02-17 22:44:47 +00:00
|
|
|
CGFloat oldWidth = _width;
|
2000-09-07 20:39:37 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
if (newWidth > _max_width)
|
|
|
|
newWidth = _max_width;
|
|
|
|
else if (newWidth < _min_width)
|
|
|
|
newWidth = _min_width;
|
1999-07-26 06:44:26 +00:00
|
|
|
|
1999-12-03 04:25:42 +00:00
|
|
|
if (_width == newWidth)
|
|
|
|
return;
|
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
_width = newWidth;
|
|
|
|
|
|
|
|
if (_tableView)
|
|
|
|
{
|
2000-03-18 00:27:49 +00:00
|
|
|
// Tiling also marks it as needing redisplay
|
|
|
|
[_tableView tile];
|
1999-12-02 03:04:37 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
postNotificationName: NSTableViewColumnDidResizeNotification
|
2000-09-07 20:39:37 +00:00
|
|
|
object: _tableView
|
|
|
|
userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
|
2007-03-11 17:07:44 +00:00
|
|
|
self, @"NSTableColumn",
|
2000-09-07 20:39:37 +00:00
|
|
|
[NSNumber numberWithFloat: oldWidth],
|
|
|
|
@"NSOldWidth", nil]];
|
1999-12-02 03:04:37 +00:00
|
|
|
}
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2008-02-16 16:45:10 +00:00
|
|
|
/** Return the width of the table column. The
|
|
|
|
default width is 100. */
|
2013-02-17 22:44:47 +00:00
|
|
|
- (CGFloat) width
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _width;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the min width of the table column, eventually adjusting the
|
|
|
|
width of the column if it is smaller than the new min width. In no
|
|
|
|
way a table column can be made smaller than its min width. */
|
2013-02-17 22:44:47 +00:00
|
|
|
- (void) setMinWidth: (CGFloat)minWidth
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
_min_width = minWidth;
|
|
|
|
if (_width < _min_width)
|
|
|
|
[self setWidth: _min_width];
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return the column's min width. The column can in no way be resized
|
|
|
|
to a width smaller than this min width. The default min width is
|
2008-02-16 16:45:10 +00:00
|
|
|
10. */
|
2013-02-17 22:44:47 +00:00
|
|
|
- (CGFloat) minWidth
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _min_width;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the max width of the table column, eventually adjusting the
|
|
|
|
width of the column if it is bigger than the new max width. In no
|
|
|
|
way a table column can be made bigger than its max width. */
|
2013-02-17 22:44:47 +00:00
|
|
|
- (void) setMaxWidth: (CGFloat)maxWidth
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
_max_width = maxWidth;
|
|
|
|
if (_width > _max_width)
|
|
|
|
[self setWidth: _max_width];
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return the column's max width. The column can in no way be resized
|
|
|
|
to a width bigger than this max width. The default max width is
|
|
|
|
100000. */
|
2013-02-17 22:44:47 +00:00
|
|
|
- (CGFloat) maxWidth
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _max_width;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set whether the user can resize the table column by dragging the
|
|
|
|
border of its header with the mouse. The table column can be
|
|
|
|
resized programmatically regardless of this setting. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setResizable: (BOOL)flag
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
_is_resizable = flag;
|
2009-12-08 17:01:01 +00:00
|
|
|
// TODO: To match Cocoa behavior, should be replaced by
|
|
|
|
//if (flag)
|
|
|
|
// {
|
|
|
|
// [self setResizingMask: NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask)];
|
|
|
|
// }
|
|
|
|
//else
|
|
|
|
// {
|
|
|
|
// [self setResizingMask: NSTableColumnNoResizing];
|
|
|
|
// }
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return whether the column might be resized by the user by dragging
|
|
|
|
the column header border. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (BOOL) isResizable
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _is_resizable;
|
2009-12-08 17:01:01 +00:00
|
|
|
// TODO: To match Cocoa behavior, should be replaced by
|
|
|
|
//return (BOOL)[self autoresizingMask];
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2009-12-08 17:01:01 +00:00
|
|
|
/**
|
|
|
|
Return the resizing mask that describes whether the column is resizable and how
|
|
|
|
it resizes. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setResizingMask: (NSUInteger)resizingMask
|
2009-12-08 17:01:01 +00:00
|
|
|
{
|
|
|
|
_resizing_mask = resizingMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set the resizing mask that describes whether the column is resizable and how
|
|
|
|
it resizes. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (NSUInteger) resizingMask
|
2009-12-08 17:01:01 +00:00
|
|
|
{
|
|
|
|
return _resizing_mask;
|
|
|
|
}
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Change the width of the column to be just enough to display its
|
|
|
|
header; change the minimum width and maximum width to allow the
|
|
|
|
column to have this width (if the minimum width is bigger than the
|
|
|
|
column header width, it is reduced to it; if the maximum width is
|
|
|
|
smaller than the column header width, it is increased to it). */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) sizeToFit
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
2013-02-17 22:44:47 +00:00
|
|
|
CGFloat new_width;
|
1999-07-19 19:13:10 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
new_width = [_headerCell cellSize].width;
|
1999-07-19 19:13:10 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
if (new_width > _max_width)
|
|
|
|
_max_width = new_width;
|
1999-07-19 19:13:10 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
if (new_width < _min_width)
|
|
|
|
_min_width = new_width;
|
|
|
|
|
|
|
|
// For easier subclassing we dont do it directly
|
|
|
|
[self setWidth: new_width];
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2009-12-08 17:01:01 +00:00
|
|
|
/**
|
|
|
|
Set whether the column is invisible or not. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setHidden: (BOOL)hidden
|
2009-12-08 17:01:01 +00:00
|
|
|
{
|
|
|
|
_is_hidden = hidden;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return whether the column is invisible or not.
|
|
|
|
|
|
|
|
When the column is hidden, it remains present in the column array returned
|
|
|
|
by -[NSTableView tableColumns]. */
|
|
|
|
- (BOOL) isHidden
|
|
|
|
{
|
|
|
|
return _is_hidden;
|
|
|
|
}
|
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
/*
|
|
|
|
* Controlling editability
|
|
|
|
*/
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set whether data in the column might be edited by the user by
|
|
|
|
double-cliking on them. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setEditable: (BOOL)flag
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
_is_editable = flag;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return whether data displayed in the column can be edited by the
|
|
|
|
user by double-cliking on them. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (BOOL) isEditable
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _is_editable;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
1999-12-02 03:04:37 +00:00
|
|
|
/*
|
|
|
|
* Setting component cells
|
|
|
|
*/
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the cell used to display the column header. aCell can't be nil,
|
|
|
|
otherwise a warning will be generated and the method call ignored.
|
|
|
|
The old cell is released, the new one is retained. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setHeaderCell: (NSCell*)aCell
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
if (aCell == nil)
|
|
|
|
{
|
|
|
|
NSLog (@"Attempt to set a nil headerCell for NSTableColumn");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSIGN (_headerCell, aCell);
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return the cell used to display the column title. The default
|
|
|
|
header cell is an NSTableHeaderCell. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (NSCell*) headerCell
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _headerCell;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2009-12-08 17:01:01 +00:00
|
|
|
/**
|
|
|
|
Set the tool tip text displayed when the pointer is in the header area. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setHeaderToolTip: (NSString *)aString
|
2009-12-08 17:01:01 +00:00
|
|
|
{
|
|
|
|
ASSIGN(_headerToolTip, aString);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the toop tip text displayed when the pointer is in the header area. */
|
|
|
|
- (NSString *) headerToolTip
|
|
|
|
{
|
|
|
|
return _headerToolTip;
|
|
|
|
}
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Set the cell used to display data in the column. aCell can't be
|
|
|
|
nil, otherwise a warning will be generated and the method ignored.
|
|
|
|
The old cell is released, the new one is retained. If you want to
|
|
|
|
change the attributes in which a single row in a column is
|
|
|
|
displayed, you should better use a delegate for your NSTableView
|
|
|
|
implementing tableView:willDisplayCell:forTableColumn:row:. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (void) setDataCell: (NSCell*)aCell
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
if (aCell == nil)
|
|
|
|
{
|
|
|
|
NSLog (@"Attempt to set a nil dataCell for NSTableColumn");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ASSIGN (_dataCell, aCell);
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2000-03-18 00:27:49 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
/**
|
|
|
|
Return the cell used to display data in the column. The default
|
|
|
|
data cell is an NSTextFieldCell. */
|
2009-12-20 23:28:05 +00:00
|
|
|
- (NSCell*) dataCell
|
1999-07-19 19:13:10 +00:00
|
|
|
{
|
1999-12-02 03:04:37 +00:00
|
|
|
return _dataCell;
|
1999-07-19 19:13:10 +00:00
|
|
|
}
|
2001-07-18 03:25:37 +00:00
|
|
|
|
2013-02-17 22:44:47 +00:00
|
|
|
- (NSCell*) dataCellForRow: (NSInteger)row
|
2001-08-21 12:17:37 +00:00
|
|
|
{
|
2001-08-30 09:31:27 +00:00
|
|
|
return [self dataCell];
|
2001-08-21 12:17:37 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 17:01:01 +00:00
|
|
|
/*
|
|
|
|
* Sorting
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the sort descriptor bound to the column. */
|
|
|
|
- (NSSortDescriptor *) sortDescriptorPrototype
|
|
|
|
{
|
|
|
|
return _sortDescriptorPrototype;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the sort descriptor bound to the column.
|
|
|
|
|
|
|
|
This sort descriptor will be added to -[NSTableView sortDescriptors] when you
|
|
|
|
bind a column to another object and NSCreateSortDescriptorBindingOption is set
|
|
|
|
to YES. */
|
|
|
|
- (void) setSortDescriptorPrototype: (NSSortDescriptor *)aSortDescriptor
|
|
|
|
{
|
|
|
|
ASSIGN(_sortDescriptorPrototype, aSortDescriptor);
|
|
|
|
}
|
|
|
|
|
2001-07-18 03:25:37 +00:00
|
|
|
/*
|
|
|
|
* Encoding/Decoding
|
|
|
|
*/
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2006-10-15 08:34:47 +00:00
|
|
|
if ([aCoder allowsKeyedCoding])
|
2006-08-12 22:44:56 +00:00
|
|
|
{
|
|
|
|
[aCoder encodeObject: _identifier forKey: @"NSIdentifier"];
|
|
|
|
[aCoder encodeObject: _dataCell forKey: @"NSDataCell"];
|
|
|
|
[aCoder encodeObject: _headerCell forKey: @"NSHeaderCell"];
|
|
|
|
[aCoder encodeBool: _is_resizable forKey: @"NSIsResizable"];
|
|
|
|
[aCoder encodeBool: _is_editable forKey: @"NSIsEditable"];
|
|
|
|
[aCoder encodeFloat: _max_width forKey: @"NSMaxWidth"];
|
|
|
|
[aCoder encodeFloat: _min_width forKey: @"NSMinWidth"];
|
|
|
|
[aCoder encodeFloat: _width forKey: @"NSWidth"];
|
2009-12-20 23:28:05 +00:00
|
|
|
[aCoder encodeObject: _sortDescriptorPrototype
|
|
|
|
forKey: @"NSSortDescriptorPrototype"];
|
|
|
|
[aCoder encodeInt: _resizing_mask forKey: @"NSResizingMask"];
|
|
|
|
[aCoder encodeObject: _headerToolTip forKey: @"NSHeaderToolTip"];
|
|
|
|
[aCoder encodeBool: _is_hidden forKey: @"NSHidden"];
|
|
|
|
[aCoder encodeObject: _tableView forKey: @"NSTableView"];
|
2024-02-11 14:19:40 +00:00
|
|
|
[aCoder encodeObject: _prototypeCellViews forKey: @"NSPrototypeCellViews"];
|
2006-08-12 22:44:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[aCoder encodeObject: _identifier];
|
|
|
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_width];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_min_width];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(float) at: &_max_width];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_resizable];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_is_editable];
|
|
|
|
|
|
|
|
[aCoder encodeObject: _headerCell];
|
|
|
|
[aCoder encodeObject: _dataCell];
|
2011-10-31 14:45:06 +00:00
|
|
|
|
|
|
|
[aCoder encodeObject: _sortDescriptorPrototype];
|
2024-04-26 16:40:11 +00:00
|
|
|
[aCoder encodeObject: _tableView];
|
2024-02-11 14:19:40 +00:00
|
|
|
[aCoder encodeObject: _prototypeCellViews];
|
2006-08-12 22:44:56 +00:00
|
|
|
}
|
2001-07-18 03:25:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
|
|
{
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder allowsKeyedCoding])
|
2002-03-29 16:04:24 +00:00
|
|
|
{
|
2004-02-06 00:16:54 +00:00
|
|
|
id identifier = [aDecoder decodeObjectForKey: @"NSIdentifier"];
|
|
|
|
|
|
|
|
self = [self initWithIdentifier: identifier];
|
2008-05-01 19:48:28 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSDataCell"])
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
[self setDataCell: [aDecoder decodeObjectForKey: @"NSDataCell"]];
|
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSHeaderCell"])
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
[self setHeaderCell: [aDecoder decodeObjectForKey: @"NSHeaderCell"]];
|
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSIsResizeable"])
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
[self setResizable: [aDecoder decodeBoolForKey: @"NSIsResizeable"]];
|
|
|
|
}
|
2008-05-20 21:49:17 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSIsEditable"])
|
|
|
|
{
|
|
|
|
[self setEditable: [aDecoder decodeBoolForKey: @"NSIsEditable"]];
|
|
|
|
}
|
2013-03-08 11:51:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setEditable: NO];
|
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSWidth"])
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
[self setWidth: [aDecoder decodeFloatForKey: @"NSWidth"]];
|
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSMinWidth"])
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
[self setMinWidth: [aDecoder decodeFloatForKey: @"NSMinWidth"]];
|
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSMaxWidth"])
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
[self setMaxWidth: [aDecoder decodeFloatForKey: @"NSMaxWidth"]];
|
|
|
|
}
|
2009-12-20 23:28:05 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSSortDescriptorPrototype"])
|
|
|
|
{
|
|
|
|
[self setSortDescriptorPrototype:
|
|
|
|
[aDecoder decodeObjectForKey: @"NSSortDescriptorPrototype"]];
|
|
|
|
}
|
|
|
|
if ([aDecoder containsValueForKey: @"NSResizingMask"])
|
|
|
|
{
|
|
|
|
[self setResizingMask: [aDecoder decodeIntForKey: @"NSResizingMask"]];
|
|
|
|
}
|
|
|
|
if ([aDecoder containsValueForKey: @"NSHeaderToolTip"])
|
|
|
|
{
|
|
|
|
[self setHeaderToolTip: [aDecoder decodeObjectForKey: @"NSHeaderToolTip"]];
|
|
|
|
}
|
|
|
|
if ([aDecoder containsValueForKey: @"NSHidden"])
|
|
|
|
{
|
|
|
|
[self setHidden: [aDecoder decodeBoolForKey: @"NSHidden"]];
|
|
|
|
}
|
|
|
|
if ([aDecoder containsValueForKey: @"NSTableView"])
|
|
|
|
{
|
|
|
|
[self setTableView: [aDecoder decodeObjectForKey: @"NSTableView"]];
|
|
|
|
}
|
2024-02-11 14:19:40 +00:00
|
|
|
if ([aDecoder containsValueForKey: @"NSPrototypeCellViews"])
|
|
|
|
{
|
|
|
|
ASSIGN(_prototypeCellViews, [aDecoder decodeObjectForKey: @"NSPrototypeCellViews"]);
|
2024-04-26 16:40:11 +00:00
|
|
|
[_tableView _registerPrototypeViews: _prototypeCellViews];
|
2024-02-17 04:14:36 +00:00
|
|
|
}
|
2002-03-29 16:04:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-02-06 00:16:54 +00:00
|
|
|
int version = [aDecoder versionForClassName:
|
|
|
|
@"NSTableColumn"];
|
2002-03-29 16:04:24 +00:00
|
|
|
|
2004-02-06 00:16:54 +00:00
|
|
|
self = [super init];
|
2008-05-01 19:48:28 +00:00
|
|
|
if (!self)
|
|
|
|
return nil;
|
|
|
|
|
2011-10-31 16:58:27 +00:00
|
|
|
if (version >= 2)
|
2004-02-06 00:16:54 +00:00
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
_identifier = RETAIN([aDecoder decodeObject]);
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_width];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_min_width];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_max_width];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_resizable];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_editable];
|
|
|
|
_headerCell = RETAIN([aDecoder decodeObject]);
|
|
|
|
_dataCell = RETAIN([aDecoder decodeObject]);
|
2011-10-31 16:58:27 +00:00
|
|
|
|
|
|
|
if (version >= 3)
|
|
|
|
{
|
|
|
|
_sortDescriptorPrototype = RETAIN([aDecoder decodeObject]);
|
|
|
|
}
|
2024-02-11 14:19:40 +00:00
|
|
|
|
|
|
|
if (version >= 4)
|
|
|
|
{
|
2024-04-26 16:40:11 +00:00
|
|
|
_tableView = [aDecoder decodeObject]; // not retained, tableView retains us...
|
2024-02-11 14:19:40 +00:00
|
|
|
_prototypeCellViews = RETAIN([aDecoder decodeObject]);
|
2024-04-26 16:40:11 +00:00
|
|
|
[_tableView _registerPrototypeViews: _prototypeCellViews];
|
2024-02-11 14:19:40 +00:00
|
|
|
}
|
2008-05-01 19:48:28 +00:00
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
else
|
|
|
|
{
|
2008-05-01 19:48:28 +00:00
|
|
|
_identifier = RETAIN([aDecoder decodeObject]);
|
|
|
|
_headerCell = RETAIN([aDecoder decodeObject]);
|
|
|
|
_dataCell = RETAIN([aDecoder decodeObject]);
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_width];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_min_width];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_max_width];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_resizable];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_is_editable];
|
|
|
|
}
|
2002-03-29 16:04:24 +00:00
|
|
|
}
|
2004-02-06 00:16:54 +00:00
|
|
|
return self;
|
2001-07-18 03:25:37 +00:00
|
|
|
}
|
|
|
|
|
2024-02-12 00:45:48 +00:00
|
|
|
- (NSArray *) _prototypeCellViews
|
|
|
|
{
|
|
|
|
return _prototypeCellViews;
|
|
|
|
}
|
|
|
|
|
2024-04-18 06:54:03 +00:00
|
|
|
- (void) setTitle: (NSString *)title
|
|
|
|
{
|
|
|
|
[_headerCell setStringValue: title];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) title
|
|
|
|
{
|
|
|
|
return [_headerCell stringValue];
|
|
|
|
}
|
|
|
|
|
2024-08-21 02:53:31 +00:00
|
|
|
- (NSString *) _keyPathForValueBinding
|
|
|
|
{
|
|
|
|
NSString *keyPath = nil;
|
|
|
|
NSDictionary *info = [GSKeyValueBinding infoForBinding: NSValueBinding
|
|
|
|
forObject: self];
|
|
|
|
if (info != nil)
|
|
|
|
{
|
|
|
|
NSString *ikp = [info objectForKey: NSObservedKeyPathKey];
|
|
|
|
NSUInteger location = [ikp rangeOfString: @"."].location;
|
|
|
|
|
|
|
|
keyPath = (location == NSNotFound ? ikp : [ikp substringFromIndex: location + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyPath;
|
|
|
|
}
|
|
|
|
|
2024-08-08 02:55:14 +00:00
|
|
|
- (void) _applyBindingsToCell: (NSCell *)cell
|
|
|
|
atRow: (NSInteger)index
|
|
|
|
{
|
|
|
|
GSKeyValueBinding *theBinding = nil;
|
|
|
|
NSFont *font = nil;
|
|
|
|
|
2024-08-11 20:40:37 +00:00
|
|
|
[cell setEditable: _is_editable];
|
2024-08-08 02:55:14 +00:00
|
|
|
theBinding = [GSKeyValueBinding getBinding: NSEnabledBinding
|
|
|
|
forObject: self];
|
|
|
|
if (theBinding != nil)
|
|
|
|
{
|
|
|
|
id result = nil;
|
|
|
|
BOOL flag = NO;
|
|
|
|
|
|
|
|
result = [(NSArray *)[theBinding destinationValue]
|
|
|
|
objectAtIndex: index];
|
|
|
|
flag = [result boolValue];
|
|
|
|
[cell setEnabled: flag];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Font bindings... According to Apple documentation, if the
|
|
|
|
* font binding is available, then name, size, and other
|
|
|
|
* font related bindings are ignored. Otherwise they are
|
|
|
|
* used
|
|
|
|
*/
|
|
|
|
theBinding = [GSKeyValueBinding getBinding: NSFontBinding
|
|
|
|
forObject: self];
|
|
|
|
if (theBinding != nil)
|
|
|
|
{
|
|
|
|
font = [(NSArray *)[theBinding destinationValue]
|
|
|
|
objectAtIndex: index];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSString *fontName = nil;
|
|
|
|
CGFloat fontSize = 0.0;
|
|
|
|
|
|
|
|
theBinding = [GSKeyValueBinding getBinding: NSFontNameBinding
|
|
|
|
forObject: self];
|
|
|
|
if (theBinding != nil)
|
|
|
|
{
|
|
|
|
fontName = [(NSArray *)[theBinding destinationValue]
|
|
|
|
objectAtIndex: index];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fontName != nil)
|
|
|
|
{
|
|
|
|
theBinding = [GSKeyValueBinding getBinding: NSFontSizeBinding
|
|
|
|
forObject: self];
|
|
|
|
if (theBinding != nil)
|
|
|
|
{
|
|
|
|
id num = [(NSArray *)[theBinding destinationValue]
|
|
|
|
objectAtIndex: index];
|
|
|
|
fontSize = [num doubleValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
font = [NSFont fontWithName: fontName
|
|
|
|
size: fontSize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (font != nil)
|
|
|
|
{
|
|
|
|
[cell setFont: font];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 12:24:17 +00:00
|
|
|
- (void) setValue: (id)anObject forKey: (NSString*)aKey
|
|
|
|
{
|
|
|
|
if ([aKey isEqual: NSValueBinding])
|
|
|
|
{
|
|
|
|
// Reload data
|
2021-01-22 21:48:13 +00:00
|
|
|
[_tableView reloadData];
|
2012-03-12 12:24:17 +00:00
|
|
|
}
|
|
|
|
else if ([aKey isEqual: NSEnabledBinding])
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
}
|
2024-07-11 16:18:52 +00:00
|
|
|
else if ([aKey isEqual: NSEditableBinding])
|
|
|
|
{
|
2024-08-21 04:12:03 +00:00
|
|
|
if ([anObject isKindOfClass: [NSNumber class]])
|
|
|
|
{
|
|
|
|
_is_editable = [anObject boolValue];
|
|
|
|
}
|
2024-07-11 16:18:52 +00:00
|
|
|
}
|
2012-03-12 12:24:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[super setValue: anObject forKey: aKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) valueForKey: (NSString*)aKey
|
|
|
|
{
|
|
|
|
if ([aKey isEqual: NSValueBinding])
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
else if ([aKey isEqual: NSEnabledBinding])
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return [NSNumber numberWithBool: YES];
|
|
|
|
}
|
2024-07-11 16:18:52 +00:00
|
|
|
else if ([aKey isEqual: NSEditableBinding])
|
|
|
|
{
|
2024-08-08 02:55:14 +00:00
|
|
|
return [NSNumber numberWithBool: _is_editable];
|
2024-07-11 16:18:52 +00:00
|
|
|
}
|
2012-03-12 12:24:17 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return [super valueForKey: aKey];
|
|
|
|
}
|
|
|
|
}
|
1999-07-19 19:13:10 +00:00
|
|
|
@end
|