Merge Headers/AppKit/NSBrowser.h Source/NSBrowser.m Source/NSBrowserCell.m

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@38664 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2015-06-20 21:02:13 +00:00
parent ca87d7eb34
commit a06204c706
3 changed files with 442 additions and 59 deletions

View file

@ -35,8 +35,11 @@
@class NSString; @class NSString;
@class NSArray; @class NSArray;
@class NSIndexPath;
@class NSIndexSet;
@class NSCell; @class NSCell;
@class NSEvent;
@class NSMatrix; @class NSMatrix;
@class NSScroller; @class NSScroller;
//@class NSBox; //@class NSBox;
@ -127,6 +130,17 @@ typedef NSUInteger NSBrowserColumnResizingType;
- (void) setReusesColumns: (BOOL)flag; - (void) setReusesColumns: (BOOL)flag;
- (void) setTakesTitleFromPreviousColumn: (BOOL)flag; - (void) setTakesTitleFromPreviousColumn: (BOOL)flag;
- (BOOL) takesTitleFromPreviousColumn; - (BOOL) takesTitleFromPreviousColumn;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
- (BOOL) autohidesScroller;
- (void) setAutohidesScroller: (BOOL)flag;
- (NSColor *) backgroundColor;
- (void) setBackgroundColor: (NSColor *)backgroundColor;
#endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (BOOL) canDragRowsWithIndexes: (NSIndexSet *)rowIndexes
inColumn: (NSInteger)columnIndex
withEvent: (NSEvent *)dragEvent;
#endif
// //
// Allowing Different Types of Selection // Allowing Different Types of Selection
@ -146,6 +160,11 @@ typedef NSUInteger NSBrowserColumnResizingType;
- (void) setAcceptsArrowKeys: (BOOL)flag; - (void) setAcceptsArrowKeys: (BOOL)flag;
- (void) setSendsActionOnArrowKeys: (BOOL)flag; - (void) setSendsActionOnArrowKeys: (BOOL)flag;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (BOOL) allowsTypeSelect;
- (void) setAllowsTypeSelect: (BOOL)allowsTypeSelection;
#endif
// //
// Showing a Horizontal Scroller // Showing a Horizontal Scroller
// //
@ -186,6 +205,12 @@ typedef NSUInteger NSBrowserColumnResizingType;
- (NSInteger) selectedRowInColumn: (NSInteger)column; - (NSInteger) selectedRowInColumn: (NSInteger)column;
- (void) setLastColumn: (NSInteger)column; - (void) setLastColumn: (NSInteger)column;
- (void) validateVisibleColumns; - (void) validateVisibleColumns;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
- (NSIndexPath *) selectionIndexPath;
- (NSArray *) selectionIndexPaths;
- (void) setSelectionIndexPath: (NSIndexPath *)path;
- (void) setSelectionIndexPaths: (NSArray *)paths;
#endif
// //
// Manipulating Column Titles // Manipulating Column Titles
@ -222,6 +247,10 @@ typedef NSUInteger NSBrowserColumnResizingType;
// //
- (void) doClick: (id)sender; - (void) doClick: (id)sender;
- (void) doDoubleClick: (id)sender; - (void) doDoubleClick: (id)sender;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST)
- (NSInteger) clickedColumn;
- (NSInteger) clickedRow;
#endif
// //
// Getting Matrices and Cells // Getting Matrices and Cells
@ -283,15 +312,16 @@ typedef NSUInteger NSBrowserColumnResizingType;
- (void) setSendsActionOnAlphaNumericalKeys: (BOOL)flag; - (void) setSendsActionOnAlphaNumericalKeys: (BOOL)flag;
@end @end
// Declare the protocol (with no mandatory methods) to support cross compiling
@protocol NSBrowserDelegate
@end
// //
// Methods Implemented by the Delegate // Methods Implemented by the Delegate
// //
@protocol NSBrowserDelegate <NSObject>
#if OS_API_VERSION(MAC_OS_X_VERSION_10_6, GS_API_LATEST) && GS_PROTOCOLS_HAVE_OPTIONAL
@optional
#else
@end
@interface NSObject (NSBrowserDelegate) @interface NSObject (NSBrowserDelegate)
#endif
- (void) browser: (NSBrowser *)sender createRowsForColumn: (NSInteger)column - (void) browser: (NSBrowser *)sender createRowsForColumn: (NSInteger)column
inMatrix: (NSMatrix *)matrix; inMatrix: (NSMatrix *)matrix;
@ -318,6 +348,12 @@ typedef NSUInteger NSBrowserColumnResizingType;
sizeToFitWidthOfColumn: (NSInteger)column; sizeToFitWidthOfColumn: (NSInteger)column;
- (void) browserColumnConfigurationDidChange: (NSNotification *)notification; - (void) browserColumnConfigurationDidChange: (NSNotification *)notification;
#endif #endif
#if OS_API_VERSION(MAC_OS_X_VERSION_10_5, GS_API_LATEST)
- (BOOL) browser: (NSBrowser *)browser
canDragRowsWithIndexes: (NSIndexSet *)rowIndexes
inColumn: (NSInteger)column
withEvent: (NSEvent *)event;
#endif
@end @end
#if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST) #if OS_API_VERSION(MAC_OS_X_VERSION_10_3, GS_API_LATEST)

View file

@ -39,6 +39,8 @@
#import <Foundation/NSArray.h> #import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h> #import <Foundation/NSDebug.h>
#import <Foundation/NSException.h> #import <Foundation/NSException.h>
#import <Foundation/NSIndexPath.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSUserDefaults.h> #import <Foundation/NSUserDefaults.h>
#import "AppKit/NSBrowser.h" #import "AppKit/NSBrowser.h"
#import "AppKit/NSBrowserCell.h" #import "AppKit/NSBrowserCell.h"
@ -61,9 +63,9 @@
/* Cache */ /* Cache */
static CGFloat scrollerWidth; // == [NSScroller scrollerWidth] static CGFloat scrollerWidth; // == [NSScroller scrollerWidth]
static NSTextFieldCell *titleCell; static NSTextFieldCell *titleCell;
static CGFloat browserColumnSeparation;
#define NSBR_COLUMN_SEP 4 static CGFloat browserVerticalPadding;
#define NSBR_VOFFSET 2 static BOOL browserUseBezels;
#define NSBR_COLUMN_IS_VISIBLE(i) \ #define NSBR_COLUMN_IS_VISIBLE(i) \
(((i)>=_firstVisibleColumn)&&((i)<=_lastVisibleColumn)) (((i)>=_firstVisibleColumn)&&((i)<=_lastVisibleColumn))
@ -204,6 +206,17 @@ static NSTextFieldCell *titleCell;
@implementation GSBrowserTitleCell @implementation GSBrowserTitleCell
// Default appearance of GSBrowserTitleCell
- (id) initTextCell: (NSString *)aString
{
self = [super initTextCell: aString];
if (!self)
return nil;
[self setTextColor: [[GSTheme theme] browserHeaderTextColor]];
return self;
}
- (NSRect) drawingRectForBounds: (NSRect)theRect - (NSRect) drawingRectForBounds: (NSRect)theRect
{ {
// This adjustment must match the drawn border // This adjustment must match the drawn border
@ -234,6 +247,8 @@ static NSTextFieldCell *titleCell;
- (void) _performLoadOfColumn: (NSInteger)column; - (void) _performLoadOfColumn: (NSInteger)column;
- (void) _remapColumnSubviews: (BOOL)flag; - (void) _remapColumnSubviews: (BOOL)flag;
- (void) _setColumnTitlesNeedDisplay; - (void) _setColumnTitlesNeedDisplay;
- (NSBorderType) _resolvedBorderType;
- (void) _themeDidActivate: (NSNotification*)notification;
@end @end
// //
@ -443,6 +458,136 @@ static NSTextFieldCell *titleCell;
} }
} }
/** <p>Returns the index path of the selected item, or nil if there is
no selection.
*/
- (NSIndexPath *) selectionIndexPath
{
NSInteger columnNumber = 0;
NSInteger selectedColumn = [self selectedColumn];
if (selectedColumn > -1)
{
NSUInteger rowIndexes[selectedColumn + 1];
for (columnNumber = 0; columnNumber <= selectedColumn; columnNumber++)
{
rowIndexes[columnNumber] = [self selectedRowInColumn: columnNumber];
}
return [[NSIndexPath alloc] initWithIndexes: rowIndexes
length: selectedColumn + 1];
}
return nil;
}
- (NSArray *) selectionIndexPaths
{
NSInteger selectedColumn = [self selectedColumn];
if (selectedColumn == -1)
{
return nil;
}
else
{
NSMutableArray *paths = AUTORELEASE([[NSMutableArray alloc] init]);
NSMatrix *matrix;
NSArray *selectedCells;
NSUInteger count;
// FIXME: There should be a more efficent way to the the selected row numbers
if (!(matrix = [self matrixInColumn: selectedColumn]))
{
return nil;
}
selectedCells = [matrix selectedCells];
if (selectedCells == nil)
{
return nil;
}
count = [selectedCells count];
NSInteger seletedRows[count];
NSEnumerator *enumerator = [selectedCells objectEnumerator];
NSCell *cell;
int i = 0;
while ((cell = [enumerator nextObject]) != nil)
{
NSInteger row;
NSInteger column;
[matrix getRow: &row
column: &column
ofCell: cell];
seletedRows[i++] = row;
}
if (selectedColumn > 0)
{
NSIndexPath *indexPath;
NSUInteger rowIndexes[selectedColumn];
NSInteger columnNumber = 0;
for (columnNumber = 0; columnNumber < selectedColumn; columnNumber++)
{
rowIndexes[columnNumber] = [self selectedRowInColumn: columnNumber];
}
indexPath = [[NSIndexPath alloc] initWithIndexes: rowIndexes
length: selectedColumn];
for (i = 0; i < count; i++)
{
[paths addObject: [indexPath indexPathByAddingIndex: seletedRows[i]]];
}
}
if (selectedColumn == 0)
{
NSIndexPath *indexPath;
for (i = 0; i < count; i++)
{
indexPath = [[NSIndexPath alloc] initWithIndex: seletedRows[i]];
[paths addObject: indexPath];
RELEASE(indexPath);
}
}
return paths;
}
return nil;
}
- (void) setSelectionIndexPath: (NSIndexPath *)path
{
NSInteger column;
NSUInteger length;
length = [path length];
for (column = 0; column < length; column++)
{
NSInteger row = [path indexAtPosition: column];
[self selectRow: row inColumn: column];
}
}
- (void) setSelectionIndexPaths: (NSArray *)paths
{
NSEnumerator *enumerator = [paths objectEnumerator];
NSIndexPath *path;
while ((path = [enumerator nextObject]) != nil)
{
// FIXME
[self setSelectionIndexPath: path];
}
}
/** Loads if necessary and returns the NSCell at row in column. /** Loads if necessary and returns the NSCell at row in column.
if you change this code, you may want to look at the __performLoadOfColumn: if you change this code, you may want to look at the __performLoadOfColumn:
method in which the following code is integrated (for speed) method in which the following code is integrated (for speed)
@ -593,31 +738,24 @@ static NSTextFieldCell *titleCell;
* specified path is already partially selected. If this is the * specified path is already partially selected. If this is the
* case, we can avoid redrawing those columns. * case, we can avoid redrawing those columns.
*/ */
for (i = 0; i <= _lastColumnLoaded && i < numberOfSubStrings; i++) for (i = 0; i <= _lastColumnLoaded; i++)
{ {
NSString *c = [[self selectedCellInColumn: i] stringValue]; // TESTPLANT-MAL-This merge takes into account Frank LeGrand's 2013-09-04
// change...
if ([c isEqualToString: [subStrings objectAtIndex: i]]) if ((i < numberOfSubStrings) &&
[[[self selectedCellInColumn: i] stringValue]
isEqualToString: [subStrings objectAtIndex: i]])
{ {
column = i; column = i;
} }
else else
{ {
// Frank LeGrand 2013-09-04: Don't understand comment below, // Actually it's always called at 0 column, when string is "/"
// we're never get here at column 0 when path is "/", so we
// will do it after the loop too.
// Actually it's always called at 0 column
[[self matrixInColumn: i] deselectAllCells]; [[self matrixInColumn: i] deselectAllCells];
break; break;
} }
} }
if (i == 0)
{
[[self matrixInColumn: i] deselectAllCells];
}
[self setLastColumn: column]; [self setLastColumn: column];
indexOfSubStrings = column; indexOfSubStrings = column;
} }
@ -782,15 +920,7 @@ static NSTextFieldCell *titleCell;
sc = [[NSScrollView alloc] initWithFrame: rect]; sc = [[NSScrollView alloc] initWithFrame: rect];
[sc setHasHorizontalScroller: NO]; [sc setHasHorizontalScroller: NO];
[sc setHasVerticalScroller: YES]; [sc setHasVerticalScroller: YES];
[sc setBorderType: [self _resolvedBorderType]];
if (_separatesColumns)
{
[sc setBorderType: NSBezelBorder];
}
else
{
[sc setBorderType: NSNoBorder];
}
[bc setColumnScrollView: sc]; [bc setColumnScrollView: sc];
[self addSubview: sc]; [self addSubview: sc];
@ -1252,8 +1382,7 @@ static NSTextFieldCell *titleCell;
sw = scrollerWidth; sw = scrollerWidth;
// Take the border into account // Take the border into account
if (_separatesColumns) sw += 2 * ([[GSTheme theme] sizeForBorderType: [self _resolvedBorderType]]).width;
sw += 2 * ([[GSTheme theme] sizeForBorderType: NSBezelBorder]).width;
// Column width cannot be less than scroller and border // Column width cannot be less than scroller and border
if (columnWidth < sw) if (columnWidth < sw)
@ -1278,15 +1407,18 @@ static NSTextFieldCell *titleCell;
*/ */
- (void) setSeparatesColumns: (BOOL)flag - (void) setSeparatesColumns: (BOOL)flag
{ {
#if 0 // Testplant-MAL-Merge-2015-06-20 - Should this be excluded from merge?
NSBrowserColumn *bc; NSBrowserColumn *bc;
NSScrollView *sc; NSScrollView *sc;
NSBorderType bt; NSBorderType bt;
NSInteger i, columnCount; NSInteger i, columnCount;
#endif
// if this flag already set or browser is titled -- do nothing // if this flag already set or browser is titled -- do nothing
if (_separatesColumns == flag || _isTitled) if (_separatesColumns == flag || _isTitled)
return; return;
#if 0 // Testplant-MAL-Merge-2015-06-20 - Should this be excluded from merge?
columnCount = [_browserColumns count]; columnCount = [_browserColumns count];
bt = flag ? NSBezelBorder : NSNoBorder; bt = flag ? NSBezelBorder : NSNoBorder;
for (i = 0; i < columnCount; i++) for (i = 0; i < columnCount; i++)
@ -1295,6 +1427,7 @@ static NSTextFieldCell *titleCell;
sc = [bc columnScrollView]; sc = [bc columnScrollView];
[sc setBorderType:bt]; [sc setBorderType:bt];
} }
#endif
_separatesColumns = flag; _separatesColumns = flag;
[self tile]; [self tile];
@ -1312,8 +1445,7 @@ static NSTextFieldCell *titleCell;
} }
// Take the border into account // Take the border into account
if (_separatesColumns) cw += 2 * ([[GSTheme theme] sizeForBorderType: [self _resolvedBorderType]]).width;
cw += 2 * ([[GSTheme theme] sizeForBorderType: NSBezelBorder]).width;
return cw; return cw;
} }
@ -1324,8 +1456,7 @@ static NSTextFieldCell *titleCell;
cw = columnWidth; cw = columnWidth;
// Take the border into account // Take the border into account
if (_separatesColumns) cw -= 2 * ([[GSTheme theme] sizeForBorderType: [self _resolvedBorderType]]).width;
cw -= 2 * ([[GSTheme theme] sizeForBorderType: NSBezelBorder]).width;
return cw; return cw;
} }
@ -1393,6 +1524,46 @@ static NSTextFieldCell *titleCell;
} }
} }
- (BOOL) autohidesScroller
{
// FIXME
return NO;
}
- (void) setAutohidesScroller: (BOOL)flag
{
// FIXME
}
- (NSColor *) backgroundColor
{
// FIXME
return [NSColor controlColor];
}
- (void) setBackgroundColor: (NSColor *)backgroundColor
{
// FIXME
}
- (BOOL) canDragRowsWithIndexes: (NSIndexSet *)rowIndexes
inColumn: (NSInteger)columnIndex
withEvent: (NSEvent *)dragEvent
{
if ([_browserDelegate respondsToSelector:
@selector(browser:canDragRowsWithIndexes:inColumn:withEvent:)])
{
return [_browserDelegate browser: self
canDragRowsWithIndexes: rowIndexes
inColumn: columnIndex
withEvent: dragEvent];
}
else
{
// FIXME
return NO;
}
}
/* /*
* Manipulating column titles * Manipulating column titles
@ -1507,7 +1678,7 @@ static NSTextFieldCell *titleCell;
// Calculate origin // Calculate origin
if (_separatesColumns) if (_separatesColumns)
{ {
rect.origin.x = nbColumn * (_columnSize.width + NSBR_COLUMN_SEP); rect.origin.x = nbColumn * (_columnSize.width + browserColumnSeparation);
} }
else else
{ {
@ -1768,6 +1939,17 @@ static NSTextFieldCell *titleCell;
_sendsActionOnArrowKeys = flag; _sendsActionOnArrowKeys = flag;
} }
- (BOOL) allowsTypeSelect
{
// FIXME
return [self acceptsArrowKeys];
}
- (void) setAllowsTypeSelect: (BOOL)allowsTypeSelection
{
// FIXME
[self setAcceptsArrowKeys: allowsTypeSelection];
}
/* /*
* Getting column frames * Getting column frames
@ -1777,9 +1959,12 @@ static NSTextFieldCell *titleCell;
- (NSRect) frameOfColumn: (NSInteger)column - (NSRect) frameOfColumn: (NSInteger)column
{ {
NSRect rect = NSZeroRect; NSRect rect = NSZeroRect;
NSSize bezelBorderSize = [[GSTheme theme] sizeForBorderType: NSBezelBorder]; NSSize bezelBorderSize = NSZeroSize;
NSInteger n; NSInteger n;
if (browserUseBezels)
bezelBorderSize = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
// Number of columns over from the first // Number of columns over from the first
n = column - _firstVisibleColumn; n = column - _firstVisibleColumn;
@ -1789,22 +1974,24 @@ static NSTextFieldCell *titleCell;
if (_separatesColumns) if (_separatesColumns)
{ {
rect.origin.x += n * NSBR_COLUMN_SEP; rect.origin.x += n * browserColumnSeparation;
} }
else else if (!_separatesColumns && browserUseBezels)
{ {
if (column == _firstVisibleColumn) if (column == _firstVisibleColumn)
rect.origin.x = (n * _columnSize.width) + 2; rect.origin.x += 2;
else else
rect.origin.x = (n * _columnSize.width) + (n + 2); rect.origin.x += (n + 2);
} }
// Adjust for horizontal scroller // Adjust for horizontal scroller
if (browserUseBezels)
{
if (_hasHorizontalScroller) if (_hasHorizontalScroller)
{ {
if (_separatesColumns) if (_separatesColumns)
rect.origin.y = (scrollerWidth - 1) + (2 * bezelBorderSize.height) + rect.origin.y = (scrollerWidth - 1) + (2 * bezelBorderSize.height) +
NSBR_VOFFSET; browserVerticalPadding;
else else
rect.origin.y = scrollerWidth + bezelBorderSize.width; rect.origin.y = scrollerWidth + bezelBorderSize.width;
} }
@ -1812,6 +1999,12 @@ static NSTextFieldCell *titleCell;
{ {
rect.origin.y += bezelBorderSize.width; rect.origin.y += bezelBorderSize.width;
} }
}
else
{
if (_hasHorizontalScroller)
rect.origin.y = scrollerWidth;
}
// Padding : _columnSize.width is rounded in "tile" method // Padding : _columnSize.width is rounded in "tile" method
if (column == _lastVisibleColumn) if (column == _lastVisibleColumn)
@ -1821,6 +2014,12 @@ static NSTextFieldCell *titleCell;
else else
rect.size.width = _frame.size.width - rect.size.width = _frame.size.width -
(rect.origin.x + bezelBorderSize.width); (rect.origin.x + bezelBorderSize.width);
// FIXME: Assumes left-side scrollers
if ([[GSTheme theme] scrollViewScrollersOverlapBorders])
{
rect.size.width -= 1;
}
} }
if (rect.size.width < 0) if (rect.size.width < 0)
@ -1870,33 +2069,55 @@ static NSTextFieldCell *titleCell;
*/ */
- (void) tile - (void) tile
{ {
NSSize bezelBorderSize = [[GSTheme theme] sizeForBorderType: NSBezelBorder]; NSSize bezelBorderSize = NSZeroSize;
NSInteger i, num, columnCount, delta; NSInteger i, num, columnCount, delta;
CGFloat frameWidth; CGFloat frameWidth;
const BOOL overlapBorders = [[GSTheme theme] scrollViewScrollersOverlapBorders];
const BOOL useBottomCorner = [[GSTheme theme] scrollViewUseBottomCorner];
if (browserUseBezels)
bezelBorderSize = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
_columnSize.height = _frame.size.height; _columnSize.height = _frame.size.height;
// Titles (there is no real frames to resize) // Titles (there is no real frames to resize)
if (_isTitled) if (_isTitled)
{ {
_columnSize.height -= [self titleHeight] + NSBR_VOFFSET; _columnSize.height -= [self titleHeight] + browserVerticalPadding;
} }
// Horizontal scroller // Horizontal scroller
if (_hasHorizontalScroller) if (_hasHorizontalScroller)
{ {
const CGFloat scrollerHightReduction = browserUseBezels ? 1 : 0;
_scrollerRect.origin.x = bezelBorderSize.width; _scrollerRect.origin.x = bezelBorderSize.width;
_scrollerRect.origin.y = bezelBorderSize.height - 1; _scrollerRect.origin.y = bezelBorderSize.height - scrollerHightReduction;
_scrollerRect.size.width = (_frame.size.width - _scrollerRect.size.width = (_frame.size.width -
(2 * bezelBorderSize.width)); (2 * bezelBorderSize.width));
_scrollerRect.size.height = scrollerWidth; _scrollerRect.size.height = scrollerWidth;
if (_separatesColumns) if (_separatesColumns)
_columnSize.height -= (scrollerWidth - 1) + _columnSize.height -= (scrollerWidth - scrollerHightReduction) +
(2 * bezelBorderSize.height) + NSBR_VOFFSET; (2 * bezelBorderSize.height) + browserVerticalPadding;
else else
_columnSize.height -= scrollerWidth + (2 * bezelBorderSize.height); _columnSize.height -= scrollerWidth + (2 * bezelBorderSize.height);
// "Bottom corner" box
if (!browserUseBezels && !useBottomCorner)
{
_scrollerRect.origin.x += scrollerWidth;
_scrollerRect.size.width -= scrollerWidth;
}
/** Horizontall expand the scroller by GSScrollerKnobOvershoot on the left */
if (overlapBorders)
{
// FIXME: Assumes left scroller
_scrollerRect.origin.x -= 1;
_scrollerRect.size.width += 1;
}
if (!NSEqualRects(_scrollerRect, [_horizontalScroller frame])) if (!NSEqualRects(_scrollerRect, [_horizontalScroller frame]))
{ {
[_horizontalScroller setFrame: _scrollerRect]; [_horizontalScroller setFrame: _scrollerRect];
@ -1915,7 +2136,7 @@ static NSTextFieldCell *titleCell;
CGFloat colWidth = _minColumnWidth + scrollerWidth; CGFloat colWidth = _minColumnWidth + scrollerWidth;
if (_separatesColumns) if (_separatesColumns)
colWidth += NSBR_COLUMN_SEP; colWidth += browserColumnSeparation;
if (_frame.size.width > colWidth) if (_frame.size.width > colWidth)
{ {
@ -1951,7 +2172,7 @@ static NSTextFieldCell *titleCell;
// Columns // Columns
if (_separatesColumns) if (_separatesColumns)
frameWidth = _frame.size.width - ((columnCount - 1) * NSBR_COLUMN_SEP); frameWidth = _frame.size.width - ((columnCount - 1) * browserColumnSeparation);
else else
frameWidth = _frame.size.width - ((columnCount - 1) + frameWidth = _frame.size.width - ((columnCount - 1) +
(2 * bezelBorderSize.width)); (2 * bezelBorderSize.width));
@ -1978,6 +2199,12 @@ static NSTextFieldCell *titleCell;
return; return;
} }
{
NSBorderType bt = _separatesColumns ? NSBezelBorder : NSNoBorder;
[sc setBorderType: bt];
}
[sc setBorderType: [self _resolvedBorderType]];
[sc setFrame: [self frameOfColumn: i]]; [sc setFrame: [self frameOfColumn: i]];
matrix = [bc columnMatrix]; matrix = [bc columnMatrix];
@ -2204,18 +2431,46 @@ static NSTextFieldCell *titleCell;
[self sendAction: _doubleAction to: [self target]]; [self sendAction: _doubleAction to: [self target]];
} }
- (NSInteger) clickedColumn
{
// FIXME: Return column number from doClick:
return -1;
}
- (NSInteger) clickedRow
{
// FIXME: Return row number from doClick:
return -1;
}
+ (void) _themeDidActivate: (NSNotification*)n
{
GSTheme *theme = [GSTheme theme];
scrollerWidth = [NSScroller scrollerWidth];
browserColumnSeparation = [theme browserColumnSeparation];
browserVerticalPadding = [theme browserVerticalPadding];
browserUseBezels = [theme browserUseBezels];
}
+ (void) initialize + (void) initialize
{ {
if (self == [NSBrowser class]) if (self == [NSBrowser class])
{ {
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(_themeDidActivate:)
name: GSThemeDidActivateNotification
object: nil];
// Initial version // Initial version
[self setVersion: 1]; [self setVersion: 1];
scrollerWidth = [NSScroller scrollerWidth];
/* Create the shared titleCell if it hasn't been created already. */ /* Create the shared titleCell if it hasn't been created already. */
if (!titleCell) if (!titleCell)
{ {
titleCell = [GSBrowserTitleCell new]; titleCell = [GSBrowserTitleCell new];
} }
[self _themeDidActivate: nil];
} }
} }
@ -2257,6 +2512,9 @@ static NSTextFieldCell *titleCell;
_browserDelegate = nil; _browserDelegate = nil;
_passiveDelegate = YES; _passiveDelegate = YES;
_doubleAction = NULL; _doubleAction = NULL;
// FIXME: Seems a bit wrong to look at the current theme here
bs = NSZeroSize;
if (browserUseBezels)
bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder]; bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
_minColumnWidth = scrollerWidth + (2 * bs.width); _minColumnWidth = scrollerWidth + (2 * bs.width);
if (_minColumnWidth < 100.0) if (_minColumnWidth < 100.0)
@ -2283,11 +2541,19 @@ static NSTextFieldCell *titleCell;
_maxVisibleColumns = 3; _maxVisibleColumns = 3;
[self _createColumn]; [self _createColumn];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_themeDidActivate:)
name: GSThemeDidActivateNotification
object: nil];
return self; return self;
} }
- (void) dealloc - (void) dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self];
if ([titleCell controlView] == self) if ([titleCell controlView] == self)
{ {
[titleCell setControlView: nil]; [titleCell setControlView: nil];
@ -2709,6 +2975,9 @@ static NSTextFieldCell *titleCell;
_browserDelegate = nil; _browserDelegate = nil;
_passiveDelegate = YES; _passiveDelegate = YES;
_doubleAction = NULL; _doubleAction = NULL;
// FIXME: Seems a bit wrong to look at the current theme here
bs = NSZeroSize;
if (browserUseBezels)
bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder]; bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
_minColumnWidth = scrollerWidth + (2 * bs.width); _minColumnWidth = scrollerWidth + (2 * bs.width);
if (_minColumnWidth < 100.0) if (_minColumnWidth < 100.0)
@ -2848,6 +3117,12 @@ static NSTextFieldCell *titleCell;
_isLoaded = NO; _isLoaded = NO;
[self tile]; [self tile];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_themeDidActivate:)
name: GSThemeDidActivateNotification
object: nil];
return self; return self;
} }
@ -2859,7 +3134,9 @@ static NSTextFieldCell *titleCell;
- (BOOL) isOpaque - (BOOL) isOpaque
{ {
return YES; // See drawRect. // NSBrowser used to be opaque but may not be due to themes;
// e.g. if the header tile images are not opaque.
return NO;
} }
@end @end
@ -3037,7 +3314,7 @@ static NSTextFieldCell *titleCell;
[matrix setAutoscroll: YES]; [matrix setAutoscroll: YES];
// Set up background colors. // Set up background colors.
[matrix setBackgroundColor: [NSColor controlColor]]; [matrix setBackgroundColor: [self backgroundColor]];
[matrix setDrawsBackground: YES]; [matrix setDrawsBackground: YES];
if (!_allowsMultipleSelection) if (!_allowsMultipleSelection)
@ -3202,4 +3479,18 @@ static NSTextFieldCell *titleCell;
[super setNeedsDisplayInRect: invalidRect]; [super setNeedsDisplayInRect: invalidRect];
} }
- (NSBorderType) _resolvedBorderType
{
if (browserUseBezels && _separatesColumns)
{
return NSBezelBorder;
}
return NSNoBorder;
}
- (void) _themeDidActivate: (NSNotification*)notification
{
[self tile];
}
@end @end

View file

@ -276,6 +276,55 @@ static NSFont *_leafFont;
*/ */
} }
- (NSRect) titleRectForBounds: (NSRect)theRect
{
NSRect titleRect = [super titleRectForBounds: theRect];
NSImage *branch_image = nil;
NSImage *cell_image = [self image];
if (_cell.is_highlighted || _cell.state)
{
if (!_browsercell_is_leaf)
{
branch_image = [object_getClass(self) highlightedBranchImage];
}
if (nil != [self alternateImage])
{
cell_image = [self alternateImage];
}
}
else
{
if (!_browsercell_is_leaf)
{
branch_image = [object_getClass(self) branchImage];
}
}
if (branch_image)
{
NSRect imgRect;
imgRect.size = [branch_image size];
titleRect.size.width -= imgRect.size.width + 8;
}
if (cell_image)
{
NSRect imgRect;
imgRect.size = [cell_image size];
titleRect.origin.x += imgRect.size.width + 4;
titleRect.size.width -= imgRect.size.width + 4;
}
// Skip 2 points from the left border
titleRect.origin.x += 2;
titleRect.size.width -= 2;
return titleRect;
}
/* /*
* Displaying * Displaying
*/ */
@ -342,9 +391,9 @@ static NSFont *_leafFont;
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.); imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.);
if (controlView != nil) if (controlView != nil)
{ {
imgRect = [controlView centerScanRect: imgRect]; imgRect = [controlView centerScanRect: imgRect];
} }
[cell_image drawInRect: imgRect [cell_image drawInRect: imgRect
fromRect: NSZeroRect fromRect: NSZeroRect
@ -358,8 +407,15 @@ static NSFont *_leafFont;
} }
// Draw the body of the cell // Draw the body of the cell
[self _drawAttributedText: [self attributedStringValue] if (_cell.in_editing)
inFrame: title_rect]; {
[self _drawEditorWithFrame: cellFrame inView: controlView];
}
else
{
[self _drawAttributedText: [self attributedStringValue]
inFrame: title_rect];
}
} }
/* /*