mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-03 17:10:43 +00:00
Removed unused ivar _numberOfRows from NSBrowserColumn.
Made GSBrowserTitleCell a subclass of NSTableHeaderCell. Corrected [scrollColumnToVisible:], so that the column becomes visible but not always last. Adopted [scrollViaScroller:] to this change. Inlined most private methods and optimized the code. Reorganized [_performLoadOfColumn:] to remove code duplication. Set the title of a column here and not each time when drawing. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14513 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d01649dcc9
commit
84dc37bfb4
1 changed files with 207 additions and 333 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
<abstract>Control to display and select from hierarchal lists</abstract>
|
<abstract>Control to display and select from hierarchal lists</abstract>
|
||||||
|
|
||||||
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Author: Scott Christley <scottc@net-community.com>
|
Author: Scott Christley <scottc@net-community.com>
|
||||||
Date: 1996
|
Date: 1996
|
||||||
|
@ -12,6 +12,8 @@
|
||||||
Date: November 1999
|
Date: November 1999
|
||||||
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
||||||
Date: September 2000
|
Date: September 2000
|
||||||
|
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
Date: September 2002
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -46,8 +48,7 @@
|
||||||
#include <AppKit/NSScrollView.h>
|
#include <AppKit/NSScrollView.h>
|
||||||
#include <AppKit/NSGraphics.h>
|
#include <AppKit/NSGraphics.h>
|
||||||
#include <AppKit/NSMatrix.h>
|
#include <AppKit/NSMatrix.h>
|
||||||
#include <AppKit/NSTextFieldCell.h>
|
#include <AppKit/NSTableHeaderCell.h>
|
||||||
#include <AppKit/PSOperators.h>
|
|
||||||
#include <AppKit/NSEvent.h>
|
#include <AppKit/NSEvent.h>
|
||||||
#include <AppKit/NSWindow.h>
|
#include <AppKit/NSWindow.h>
|
||||||
|
|
||||||
|
@ -72,7 +73,6 @@ static NSTextFieldCell *titleCell;
|
||||||
BOOL _isLoaded;
|
BOOL _isLoaded;
|
||||||
id _columnScrollView;
|
id _columnScrollView;
|
||||||
id _columnMatrix;
|
id _columnMatrix;
|
||||||
int _numberOfRows;
|
|
||||||
NSString *_columnTitle;
|
NSString *_columnTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,8 +82,6 @@ static NSTextFieldCell *titleCell;
|
||||||
- (id) columnScrollView;
|
- (id) columnScrollView;
|
||||||
- (void) setColumnMatrix: (id)aMatrix;
|
- (void) setColumnMatrix: (id)aMatrix;
|
||||||
- (id) columnMatrix;
|
- (id) columnMatrix;
|
||||||
- (void) setNumberOfRows: (int)num;
|
|
||||||
- (int) numberOfRows;
|
|
||||||
- (void) setColumnTitle: (NSString *)aString;
|
- (void) setColumnTitle: (NSString *)aString;
|
||||||
- (NSString *) columnTitle;
|
- (NSString *) columnTitle;
|
||||||
@end
|
@end
|
||||||
|
@ -137,16 +135,6 @@ static NSTextFieldCell *titleCell;
|
||||||
return _columnMatrix;
|
return _columnMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setNumberOfRows: (int)num
|
|
||||||
{
|
|
||||||
_numberOfRows = num;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (int) numberOfRows
|
|
||||||
{
|
|
||||||
return _numberOfRows;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) setColumnTitle: (NSString *)aString
|
- (void) setColumnTitle: (NSString *)aString
|
||||||
{
|
{
|
||||||
if (!aString)
|
if (!aString)
|
||||||
|
@ -162,15 +150,19 @@ static NSTextFieldCell *titleCell;
|
||||||
|
|
||||||
- (void) encodeWithCoder: (NSCoder *)aCoder
|
- (void) encodeWithCoder: (NSCoder *)aCoder
|
||||||
{
|
{
|
||||||
|
int dummy = 0;
|
||||||
|
|
||||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded];
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded];
|
||||||
[aCoder encodeObject: _columnScrollView];
|
[aCoder encodeObject: _columnScrollView];
|
||||||
[aCoder encodeObject: _columnMatrix];
|
[aCoder encodeObject: _columnMatrix];
|
||||||
[aCoder encodeValueOfObjCType: @encode(int) at:&_numberOfRows];
|
[aCoder encodeValueOfObjCType: @encode(int) at: &dummy];
|
||||||
[aCoder encodeObject: _columnTitle];
|
[aCoder encodeObject: _columnTitle];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder *)aDecoder
|
- (id) initWithCoder: (NSCoder *)aDecoder
|
||||||
{
|
{
|
||||||
|
int dummy = 0;
|
||||||
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isLoaded];
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isLoaded];
|
||||||
_columnScrollView = [aDecoder decodeObject];
|
_columnScrollView = [aDecoder decodeObject];
|
||||||
if (_columnScrollView)
|
if (_columnScrollView)
|
||||||
|
@ -178,7 +170,7 @@ static NSTextFieldCell *titleCell;
|
||||||
_columnMatrix = [aDecoder decodeObject];
|
_columnMatrix = [aDecoder decodeObject];
|
||||||
if (_columnMatrix)
|
if (_columnMatrix)
|
||||||
RETAIN(_columnMatrix);
|
RETAIN(_columnMatrix);
|
||||||
[aDecoder decodeValueOfObjCType: @encode(int) at: &_numberOfRows];
|
[aDecoder decodeValueOfObjCType: @encode(int) at: &dummy];
|
||||||
_columnTitle = [aDecoder decodeObject];
|
_columnTitle = [aDecoder decodeObject];
|
||||||
if (_columnTitle)
|
if (_columnTitle)
|
||||||
RETAIN(_columnTitle);
|
RETAIN(_columnTitle);
|
||||||
|
@ -188,25 +180,10 @@ static NSTextFieldCell *titleCell;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// NB: this is used in the NSFontPanel too
|
// NB: this is used in the NSFontPanel too
|
||||||
@interface GSBrowserTitleCell: NSTextFieldCell
|
@interface GSBrowserTitleCell: NSTableHeaderCell
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation GSBrowserTitleCell
|
@implementation GSBrowserTitleCell
|
||||||
- (id) initTextCell: (NSString *)aString
|
|
||||||
{
|
|
||||||
[super initTextCell: aString];
|
|
||||||
|
|
||||||
[self setTextColor: [NSColor windowFrameTextColor]];
|
|
||||||
[self setBackgroundColor: [NSColor controlShadowColor]];
|
|
||||||
[self setFont: [NSFont titleBarFontOfSize: 0]];
|
|
||||||
[self setAlignment: NSCenterTextAlignment];
|
|
||||||
_cell.is_editable = NO;
|
|
||||||
_cell.is_bezeled = YES;
|
|
||||||
_textfieldcell_draws_background = YES;
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
if (NSIsEmptyRect (cellFrame) || ![controlView window])
|
if (NSIsEmptyRect (cellFrame) || ![controlView window])
|
||||||
|
@ -227,10 +204,7 @@ static NSTextFieldCell *titleCell;
|
||||||
@interface NSBrowser (Private)
|
@interface NSBrowser (Private)
|
||||||
- (NSString *) _getTitleOfColumn: (int)column;
|
- (NSString *) _getTitleOfColumn: (int)column;
|
||||||
- (void) _performLoadOfColumn: (int)column;
|
- (void) _performLoadOfColumn: (int)column;
|
||||||
- (void) _unloadFromColumn: (int)column;
|
|
||||||
- (void) _remapColumnSubviews: (BOOL)flag;
|
- (void) _remapColumnSubviews: (BOOL)flag;
|
||||||
- (void) _adjustMatrixOfColumn: (int)column;
|
|
||||||
- (void) _setColumnSubviewsNeedDisplay;
|
|
||||||
- (void) _setColumnTitlesNeedDisplay;
|
- (void) _setColumnTitlesNeedDisplay;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -776,11 +750,8 @@ static NSTextFieldCell *titleCell;
|
||||||
// Update and display title of column
|
// Update and display title of column
|
||||||
if (_isTitled)
|
if (_isTitled)
|
||||||
{
|
{
|
||||||
NSString *title = [self _getTitleOfColumn: column];
|
[self drawTitleOfColumn: column
|
||||||
[self setTitle: title ofColumn: column];
|
inRect: [self titleFrameOfColumn: column]];
|
||||||
[self drawTitle: title
|
|
||||||
inRect: [self titleFrameOfColumn: column]
|
|
||||||
ofColumn: column];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display column
|
// Display column
|
||||||
|
@ -835,15 +806,57 @@ static NSTextFieldCell *titleCell;
|
||||||
/** Sets the last column to column. */
|
/** Sets the last column to column. */
|
||||||
- (void) setLastColumn: (int)column
|
- (void) setLastColumn: (int)column
|
||||||
{
|
{
|
||||||
if (column < -1)
|
int i, count, num;
|
||||||
|
id bc, sc;
|
||||||
|
|
||||||
|
if (column <= -1)
|
||||||
{
|
{
|
||||||
column = -1;
|
column = -1;
|
||||||
|
_isLoaded = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lastColumnLoaded = column;
|
_lastColumnLoaded = column;
|
||||||
[self _unloadFromColumn: column + 1];
|
// Unloads columns.
|
||||||
|
count = [_browserColumns count];
|
||||||
|
num = [self numberOfVisibleColumns];
|
||||||
|
|
||||||
|
for (i = column + 1; i < count; ++i)
|
||||||
|
{
|
||||||
|
bc = [_browserColumns objectAtIndex: i];
|
||||||
|
sc = [bc columnScrollView];
|
||||||
|
|
||||||
|
if ([bc isLoaded])
|
||||||
|
{
|
||||||
|
// Make the column appear empty by removing the matrix
|
||||||
|
if (sc)
|
||||||
|
{
|
||||||
|
[sc setDocumentView: nil];
|
||||||
|
[sc setNeedsDisplay: YES];
|
||||||
|
}
|
||||||
|
[bc setIsLoaded: NO];
|
||||||
|
[bc setColumnTitle: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_reusesColumns && i >= num)
|
||||||
|
{
|
||||||
|
[sc removeFromSuperview];
|
||||||
|
[_browserColumns removeObject: bc];
|
||||||
|
count--;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scroll if needed.
|
||||||
|
if ((column < _lastVisibleColumn) && (_firstVisibleColumn > 0))
|
||||||
|
{
|
||||||
|
[self scrollColumnsLeftBy: _lastVisibleColumn - column];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[self updateScroller];
|
||||||
[self _setColumnTitlesNeedDisplay];
|
[self _setColumnTitlesNeedDisplay];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Returns the index of the first visible column. */
|
/** Returns the index of the first visible column. */
|
||||||
- (int) firstVisibleColumn
|
- (int) firstVisibleColumn
|
||||||
|
@ -947,6 +960,8 @@ static NSTextFieldCell *titleCell;
|
||||||
|
|
||||||
// Perform the data load
|
// Perform the data load
|
||||||
[self _performLoadOfColumn: column];
|
[self _performLoadOfColumn: column];
|
||||||
|
// set last column loaded
|
||||||
|
[self setLastColumn: column];
|
||||||
|
|
||||||
// Restore the selected cells
|
// Restore the selected cells
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
|
@ -965,9 +980,6 @@ static NSTextFieldCell *titleCell;
|
||||||
}
|
}
|
||||||
NSZoneFree (NSDefaultMallocZone (), selectedIndexes);
|
NSZoneFree (NSDefaultMallocZone (), selectedIndexes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set last column loaded
|
|
||||||
[self setLastColumn: column];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1117,18 +1129,18 @@ static NSTextFieldCell *titleCell;
|
||||||
/** Returns the title displayed for the column at index column. */
|
/** Returns the title displayed for the column at index column. */
|
||||||
- (NSString *) titleOfColumn: (int)column
|
- (NSString *) titleOfColumn: (int)column
|
||||||
{
|
{
|
||||||
id bc;
|
NSBrowserColumn *bc;
|
||||||
|
|
||||||
bc = [_browserColumns objectAtIndex: column];
|
bc = [_browserColumns objectAtIndex: column];
|
||||||
|
|
||||||
return [bc columnTitle];
|
return bc->_columnTitle;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the title of the column at index column to aString. */
|
/** Sets the title of the column at index column to aString. */
|
||||||
- (void) setTitle: (NSString *)aString
|
- (void) setTitle: (NSString *)aString
|
||||||
ofColumn: (int)column
|
ofColumn: (int)column
|
||||||
{
|
{
|
||||||
id bc;
|
NSBrowserColumn *bc;
|
||||||
|
|
||||||
bc = [_browserColumns objectAtIndex: column];
|
bc = [_browserColumns objectAtIndex: column];
|
||||||
|
|
||||||
|
@ -1235,22 +1247,20 @@ static NSTextFieldCell *titleCell;
|
||||||
/** Scrolls to make the column at index column visible. */
|
/** Scrolls to make the column at index column visible. */
|
||||||
- (void) scrollColumnToVisible: (int)column
|
- (void) scrollColumnToVisible: (int)column
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
// If its the last visible column then we are there already
|
|
||||||
if (_lastVisibleColumn == column)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// If there are not enough columns to scroll with
|
// If there are not enough columns to scroll with
|
||||||
// then the column must be visible
|
// then the column must be visible
|
||||||
if (_lastColumnLoaded + 1 <= [self numberOfVisibleColumns])
|
if (_lastColumnLoaded + 1 <= [self numberOfVisibleColumns])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
i = _lastVisibleColumn - column;
|
// If its the last visible column then we are there already
|
||||||
if (i > 0)
|
if (_lastVisibleColumn < column)
|
||||||
[self scrollColumnsLeftBy: i];
|
{
|
||||||
else
|
[self scrollColumnsRightBy: (column - _lastVisibleColumn)];
|
||||||
[self scrollColumnsRightBy: (-i)];
|
}
|
||||||
|
else if (_firstVisibleColumn > column)
|
||||||
|
{
|
||||||
|
[self scrollColumnsLeftBy: (_firstVisibleColumn - column)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Scrolls columns left by shiftAmount columns. */
|
/** Scrolls columns left by shiftAmount columns. */
|
||||||
|
@ -1375,12 +1385,10 @@ static NSTextFieldCell *titleCell;
|
||||||
case NSScrollerKnob:
|
case NSScrollerKnob:
|
||||||
case NSScrollerKnobSlot:
|
case NSScrollerKnobSlot:
|
||||||
{
|
{
|
||||||
int num = [self numberOfVisibleColumns];
|
|
||||||
float f = [sender floatValue];
|
float f = [sender floatValue];
|
||||||
float n = _lastColumnLoaded + 1 - num;
|
|
||||||
|
|
||||||
_skipUpdateScroller = YES;
|
_skipUpdateScroller = YES;
|
||||||
[self scrollColumnToVisible: rintf(f * n) + num - 1];
|
[self scrollColumnToVisible: rintf(f * _lastColumnLoaded)];
|
||||||
_skipUpdateScroller = NO;
|
_skipUpdateScroller = NO;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1518,7 +1526,6 @@ static NSTextFieldCell *titleCell;
|
||||||
{
|
{
|
||||||
NSSize bs = _sizeForBorderType (NSBezelBorder);
|
NSSize bs = _sizeForBorderType (NSBezelBorder);
|
||||||
int i, num, columnCount, delta;
|
int i, num, columnCount, delta;
|
||||||
id bc, sc;
|
|
||||||
|
|
||||||
_columnSize.height = _frame.size.height;
|
_columnSize.height = _frame.size.height;
|
||||||
|
|
||||||
|
@ -1606,6 +1613,9 @@ static NSTextFieldCell *titleCell;
|
||||||
|
|
||||||
for (i = _firstVisibleColumn; i <= _lastVisibleColumn; i++)
|
for (i = _firstVisibleColumn; i <= _lastVisibleColumn; i++)
|
||||||
{
|
{
|
||||||
|
id bc, sc;
|
||||||
|
id matrix;
|
||||||
|
|
||||||
bc = [_browserColumns objectAtIndex: i];
|
bc = [_browserColumns objectAtIndex: i];
|
||||||
|
|
||||||
if (!(sc = [bc columnScrollView]))
|
if (!(sc = [bc columnScrollView]))
|
||||||
|
@ -1615,7 +1625,19 @@ static NSTextFieldCell *titleCell;
|
||||||
}
|
}
|
||||||
|
|
||||||
[sc setFrame: [self frameOfColumn: i]];
|
[sc setFrame: [self frameOfColumn: i]];
|
||||||
[self _adjustMatrixOfColumn: i];
|
matrix = [bc columnMatrix];
|
||||||
|
|
||||||
|
// Adjust matrix to fit in scrollview if column has been loaded
|
||||||
|
if (matrix && [bc isLoaded])
|
||||||
|
{
|
||||||
|
NSSize cs, ms;
|
||||||
|
|
||||||
|
cs = [sc contentSize];
|
||||||
|
ms = [matrix cellSize];
|
||||||
|
ms.width = cs.width;
|
||||||
|
[matrix setCellSize: ms];
|
||||||
|
[sc setDocumentView: matrix];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (columnCount != num)
|
if (columnCount != num)
|
||||||
|
@ -1646,13 +1668,17 @@ static NSTextFieldCell *titleCell;
|
||||||
- (void) setDelegate: (id)anObject
|
- (void) setDelegate: (id)anObject
|
||||||
{
|
{
|
||||||
BOOL flag = NO;
|
BOOL flag = NO;
|
||||||
BOOL both = NO;
|
|
||||||
|
|
||||||
if ([anObject respondsToSelector:
|
if ([anObject respondsToSelector:
|
||||||
@selector(browser:numberOfRowsInColumn:)])
|
@selector(browser:numberOfRowsInColumn:)])
|
||||||
{
|
{
|
||||||
_passiveDelegate = YES;
|
_passiveDelegate = YES;
|
||||||
flag = YES;
|
flag = YES;
|
||||||
|
if (![anObject respondsToSelector:
|
||||||
|
@selector(browser:willDisplayCell:atRow:column:)])
|
||||||
|
[NSException raise: NSBrowserIllegalDelegateException
|
||||||
|
format: @"(Passive) Delegate does not respond to %s\n",
|
||||||
|
"browser: willDisplayCell: atRow: column: "];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([anObject respondsToSelector:
|
if ([anObject respondsToSelector:
|
||||||
|
@ -1663,29 +1689,22 @@ static NSTextFieldCell *titleCell;
|
||||||
// If flag is already set
|
// If flag is already set
|
||||||
// then delegate must respond to both methods
|
// then delegate must respond to both methods
|
||||||
if (flag)
|
if (flag)
|
||||||
both = YES;
|
{
|
||||||
|
[NSException raise: NSBrowserIllegalDelegateException
|
||||||
|
format: @"Delegate responds to both %s and %s\n",
|
||||||
|
"browser: numberOfRowsInColumn: ",
|
||||||
|
"browser: createRowsForColumn: inMatrix: "];
|
||||||
|
}
|
||||||
|
|
||||||
flag = YES;
|
flag = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_passiveDelegate && ![anObject respondsToSelector:
|
|
||||||
@selector(browser:willDisplayCell:atRow:column:)])
|
|
||||||
[NSException raise: NSBrowserIllegalDelegateException
|
|
||||||
format: @"(Passive) Delegate does not respond to %s\n",
|
|
||||||
"browser: willDisplayCell: atRow: column: "];
|
|
||||||
|
|
||||||
if (!flag)
|
if (!flag)
|
||||||
[NSException raise: NSBrowserIllegalDelegateException
|
[NSException raise: NSBrowserIllegalDelegateException
|
||||||
format: @"Delegate does not respond to %s or %s\n",
|
format: @"Delegate does not respond to %s or %s\n",
|
||||||
"browser: numberOfRowsInColumn: ",
|
"browser: numberOfRowsInColumn: ",
|
||||||
"browser: createRowsForColumn: inMatrix: "];
|
"browser: createRowsForColumn: inMatrix: "];
|
||||||
|
|
||||||
if (both)
|
|
||||||
[NSException raise: NSBrowserIllegalDelegateException
|
|
||||||
format: @"Delegate responds to both %s and %s\n",
|
|
||||||
"browser: numberOfRowsInColumn: ",
|
|
||||||
"browser: createRowsForColumn: inMatrix: "];
|
|
||||||
|
|
||||||
_browserDelegate = anObject;
|
_browserDelegate = anObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1825,9 +1844,6 @@ static NSTextFieldCell *titleCell;
|
||||||
// Send the action to target
|
// Send the action to target
|
||||||
[self sendAction];
|
[self sendAction];
|
||||||
|
|
||||||
// Marks titles band as needing display.
|
|
||||||
[self _setColumnTitlesNeedDisplay];
|
|
||||||
|
|
||||||
RELEASE(selectedCells);
|
RELEASE(selectedCells);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1984,11 +2000,8 @@ static NSTextFieldCell *titleCell;
|
||||||
NSRect titleRect = [self titleFrameOfColumn: i];
|
NSRect titleRect = [self titleFrameOfColumn: i];
|
||||||
if (NSIntersectsRect (titleRect, rect) == YES)
|
if (NSIntersectsRect (titleRect, rect) == YES)
|
||||||
{
|
{
|
||||||
NSString *title;
|
[self drawTitleOfColumn: i
|
||||||
|
inRect: titleRect];
|
||||||
title = [self _getTitleOfColumn: i];
|
|
||||||
[self setTitle: title ofColumn: i];
|
|
||||||
[self drawTitle: title inRect: titleRect ofColumn: i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2416,56 +2429,6 @@ static NSTextFieldCell *titleCell;
|
||||||
*/
|
*/
|
||||||
@implementation NSBrowser (Private)
|
@implementation NSBrowser (Private)
|
||||||
|
|
||||||
- (void)_adjustMatrixOfColumn: (int)column
|
|
||||||
{
|
|
||||||
NSBrowserColumn *bc;
|
|
||||||
NSScrollView *sc;
|
|
||||||
id matrix;
|
|
||||||
NSSize cs, ms;
|
|
||||||
|
|
||||||
if (column >= (int)[_browserColumns count])
|
|
||||||
return;
|
|
||||||
|
|
||||||
bc = [_browserColumns objectAtIndex: column];
|
|
||||||
|
|
||||||
sc = [bc columnScrollView];
|
|
||||||
matrix = [bc columnMatrix];
|
|
||||||
|
|
||||||
// Adjust matrix to fit in scrollview if column has been loaded
|
|
||||||
if (sc && matrix && [bc isLoaded])
|
|
||||||
{
|
|
||||||
cs = [sc contentSize];
|
|
||||||
ms = [matrix cellSize];
|
|
||||||
ms.width = cs.width;
|
|
||||||
[matrix setCellSize: ms];
|
|
||||||
[sc setDocumentView: matrix];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
- (void)_adjustScrollerFrameOfColumn: (int)column force: (BOOL)flag
|
|
||||||
{
|
|
||||||
// Only if we've loaded the first column
|
|
||||||
if ((_isLoaded) || (flag))
|
|
||||||
{
|
|
||||||
NSBrowserColumn *bc;
|
|
||||||
NSScrollView *sc;
|
|
||||||
|
|
||||||
if (column >= (int)[_browserColumns count])
|
|
||||||
return;
|
|
||||||
|
|
||||||
bc = [_browserColumns objectAtIndex: column];
|
|
||||||
sc = [bc columnScrollView];
|
|
||||||
|
|
||||||
// Set the scrollview frame
|
|
||||||
// Only set before the column has been loaded
|
|
||||||
// Or we are being forced
|
|
||||||
if (sc && ((![bc isLoaded]) || flag))
|
|
||||||
[sc setFrame: [self frameOfInsideOfColumn: column]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
- (void) _remapColumnSubviews: (BOOL)fromFirst
|
- (void) _remapColumnSubviews: (BOOL)fromFirst
|
||||||
{
|
{
|
||||||
id bc, sc;
|
id bc, sc;
|
||||||
|
@ -2546,8 +2509,19 @@ static NSTextFieldCell *titleCell;
|
||||||
- (void) _performLoadOfColumn: (int)column
|
- (void) _performLoadOfColumn: (int)column
|
||||||
{
|
{
|
||||||
id bc, sc, matrix;
|
id bc, sc, matrix;
|
||||||
NSRect matrixRect = {{0, 0}, {100, 100}};
|
int i, rows, cols;
|
||||||
NSSize matrixIntercellSpace = {0, 0};
|
|
||||||
|
if (_passiveDelegate)
|
||||||
|
{
|
||||||
|
// Ask the delegate for the number of rows
|
||||||
|
rows = [_browserDelegate browser: self numberOfRowsInColumn: column];
|
||||||
|
cols = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rows = 0;
|
||||||
|
cols = 0;
|
||||||
|
}
|
||||||
|
|
||||||
bc = [_browserColumns objectAtIndex: column];
|
bc = [_browserColumns objectAtIndex: column];
|
||||||
|
|
||||||
|
@ -2556,32 +2530,28 @@ static NSTextFieldCell *titleCell;
|
||||||
|
|
||||||
matrix = [bc columnMatrix];
|
matrix = [bc columnMatrix];
|
||||||
|
|
||||||
// Loading is different based upon passive/active delegate
|
|
||||||
if (_passiveDelegate)
|
|
||||||
{
|
|
||||||
// Ask the delegate for the number of rows
|
|
||||||
int i, n = [_browserDelegate browser: self numberOfRowsInColumn: column];
|
|
||||||
|
|
||||||
if (_reusesColumns && matrix)
|
if (_reusesColumns && matrix)
|
||||||
{
|
{
|
||||||
[matrix renewRows: n columns: 1];
|
[matrix renewRows: rows columns: cols];
|
||||||
[sc setDocumentView: matrix];
|
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
// Mark all the cells as unloaded
|
||||||
|
for (i = 0; i < rows; i++)
|
||||||
{
|
{
|
||||||
[[matrix cellAtRow: i column: 0] setLoaded: NO];
|
[[matrix cellAtRow: i column: 0] setLoaded: NO];
|
||||||
[self loadedCellAtRow: i column: column];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
NSRect matrixRect = {{0, 0}, {100, 100}};
|
||||||
|
NSSize matrixIntercellSpace = {0, 0};
|
||||||
|
|
||||||
// create a new col matrix
|
// create a new col matrix
|
||||||
matrix = [[_browserMatrixClass alloc]
|
matrix = [[_browserMatrixClass alloc]
|
||||||
initWithFrame: matrixRect
|
initWithFrame: matrixRect
|
||||||
mode: NSListModeMatrix
|
mode: NSListModeMatrix
|
||||||
prototype: _browserCellPrototype
|
prototype: _browserCellPrototype
|
||||||
numberOfRows: n
|
numberOfRows: rows
|
||||||
numberOfColumns: 1];
|
numberOfColumns: cols];
|
||||||
[matrix setIntercellSpacing: matrixIntercellSpace];
|
[matrix setIntercellSpacing: matrixIntercellSpace];
|
||||||
[matrix setAllowsEmptySelection: _allowsEmptySelection];
|
[matrix setAllowsEmptySelection: _allowsEmptySelection];
|
||||||
[matrix setAutoscroll: YES];
|
[matrix setAutoscroll: YES];
|
||||||
|
@ -2596,23 +2566,20 @@ static NSTextFieldCell *titleCell;
|
||||||
// set new col matrix and release old
|
// set new col matrix and release old
|
||||||
[bc setColumnMatrix: matrix];
|
[bc setColumnMatrix: matrix];
|
||||||
RELEASE (matrix);
|
RELEASE (matrix);
|
||||||
|
}
|
||||||
[sc setDocumentView: matrix];
|
[sc setDocumentView: matrix];
|
||||||
|
|
||||||
|
// Loading is different based upon passive/active delegate
|
||||||
|
if (_passiveDelegate)
|
||||||
|
{
|
||||||
// Now loop through the cells and load each one
|
// Now loop through the cells and load each one
|
||||||
{
|
|
||||||
NSBrowserColumn *bc;
|
|
||||||
id matrix;
|
|
||||||
id aCell;
|
id aCell;
|
||||||
bc = [_browserColumns objectAtIndex: column];
|
|
||||||
matrix = [bc columnMatrix];
|
|
||||||
if (_passiveDelegate || [_browserDelegate respondsToSelector:
|
|
||||||
@selector(browser:willDisplayCell:atRow:column:)])
|
|
||||||
{
|
|
||||||
SEL sel1 = @selector(browser:willDisplayCell:atRow:column:);
|
SEL sel1 = @selector(browser:willDisplayCell:atRow:column:);
|
||||||
IMP imp1 = [_browserDelegate methodForSelector: sel1];
|
IMP imp1 = [_browserDelegate methodForSelector: sel1];
|
||||||
SEL sel2 = @selector(cellAtRow:column:);
|
SEL sel2 = @selector(cellAtRow:column:);
|
||||||
IMP imp2 = [matrix methodForSelector: sel2];
|
IMP imp2 = [matrix methodForSelector: sel2];
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
|
for (i = 0; i < rows; i++)
|
||||||
{
|
{
|
||||||
aCell = (*imp2)(matrix, sel2, i, 0);
|
aCell = (*imp2)(matrix, sel2, i, 0);
|
||||||
if (![aCell isLoaded])
|
if (![aCell isLoaded])
|
||||||
|
@ -2623,136 +2590,43 @@ static NSTextFieldCell *titleCell;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_reusesColumns && matrix)
|
|
||||||
{
|
|
||||||
[matrix renewRows: 0 columns: 1];
|
|
||||||
[sc setDocumentView: matrix];
|
|
||||||
|
|
||||||
[_browserDelegate browser: self
|
|
||||||
createRowsForColumn: column
|
|
||||||
inMatrix: matrix];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// create a new col matrix
|
|
||||||
matrix = [[_browserMatrixClass alloc]
|
|
||||||
initWithFrame: matrixRect
|
|
||||||
mode: NSRadioModeMatrix
|
|
||||||
prototype: _browserCellPrototype
|
|
||||||
numberOfRows: 0
|
|
||||||
numberOfColumns: 0];
|
|
||||||
[matrix setIntercellSpacing:matrixIntercellSpace];
|
|
||||||
[matrix setAllowsEmptySelection: _allowsEmptySelection];
|
|
||||||
[matrix setAutoscroll: YES];
|
|
||||||
if (_allowsMultipleSelection)
|
|
||||||
{
|
|
||||||
[matrix setMode: NSListModeMatrix];
|
|
||||||
}
|
|
||||||
[matrix setTarget: self];
|
|
||||||
[matrix setAction: @selector(doClick:)];
|
|
||||||
[matrix setDoubleAction: @selector(doDoubleClick:)];
|
|
||||||
|
|
||||||
// set new col matrix and release old
|
|
||||||
[bc setColumnMatrix: matrix];
|
|
||||||
RELEASE (matrix);
|
|
||||||
[sc setDocumentView: matrix];
|
|
||||||
|
|
||||||
// Tell the delegate to create the rows
|
// Tell the delegate to create the rows
|
||||||
[_browserDelegate browser: self
|
[_browserDelegate browser: self
|
||||||
createRowsForColumn: column
|
createRowsForColumn: column
|
||||||
inMatrix: matrix];
|
inMatrix: matrix];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[sc setNeedsDisplay: YES];
|
||||||
|
[bc setIsLoaded: YES];
|
||||||
|
|
||||||
/* Determine the height of a cell in the matrix, and set that as the
|
/* Determine the height of a cell in the matrix, and set that as the
|
||||||
cellSize of the matrix. */
|
cellSize of the matrix. */
|
||||||
{
|
{
|
||||||
|
NSSize cs, ms;
|
||||||
NSBrowserCell *b = [matrix cellAtRow: 0 column: 0];
|
NSBrowserCell *b = [matrix cellAtRow: 0 column: 0];
|
||||||
|
|
||||||
if (b != nil)
|
if (b != nil)
|
||||||
{
|
{
|
||||||
[matrix setCellSize: [b cellSize]];
|
ms = [b cellSize];
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
|
||||||
[sc setNeedsDisplay: YES];
|
|
||||||
[bc setIsLoaded: YES];
|
|
||||||
[self _adjustMatrixOfColumn: column];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Unloads all columns from and including 'column'. */
|
|
||||||
- (void)_unloadFromColumn: (int)column
|
|
||||||
{
|
{
|
||||||
int i, count, num;
|
ms = [matrix cellSize];
|
||||||
id bc, sc;
|
|
||||||
|
|
||||||
// Unloads columns.
|
|
||||||
count = [_browserColumns count];
|
|
||||||
num = [self numberOfVisibleColumns];
|
|
||||||
|
|
||||||
for (i = column; i < count; ++i)
|
|
||||||
{
|
|
||||||
bc = [_browserColumns objectAtIndex: i];
|
|
||||||
sc = [bc columnScrollView];
|
|
||||||
|
|
||||||
if ([bc isLoaded])
|
|
||||||
{
|
|
||||||
// Make the column appear empty by removing the matrix
|
|
||||||
if (sc)
|
|
||||||
{
|
|
||||||
[sc setDocumentView: nil];
|
|
||||||
[sc setNeedsDisplay: YES];
|
|
||||||
}
|
}
|
||||||
[bc setIsLoaded: NO];
|
cs = [sc contentSize];
|
||||||
|
ms.width = cs.width;
|
||||||
|
[matrix setCellSize: ms];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_reusesColumns && i >= num)
|
// Get the title even when untiteled, as this may change later.
|
||||||
{
|
[self setTitle: [self _getTitleOfColumn: column] ofColumn: column];
|
||||||
[sc removeFromSuperview];
|
|
||||||
[_browserColumns removeObject: bc];
|
|
||||||
count--;
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column == 0)
|
/* Get the title of a column. */
|
||||||
{
|
|
||||||
_isLoaded = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Scrolls if needed.
|
|
||||||
if (column <= _lastVisibleColumn)
|
|
||||||
{
|
|
||||||
[self scrollColumnsLeftBy: _lastVisibleColumn - column + 1];
|
|
||||||
}
|
|
||||||
[self updateScroller];
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Marks all visible columns as needing to be redrawn. */
|
|
||||||
- (void)_setColumnSubviewsNeedDisplay
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = _firstVisibleColumn; i <= _lastVisibleColumn; i++)
|
|
||||||
{
|
|
||||||
[[[_browserColumns objectAtIndex:i] columnScrollView]
|
|
||||||
setNeedsDisplay:YES];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Marks all titles as needing to be redrawn. */
|
|
||||||
- (NSString *) _getTitleOfColumn: (int)column
|
- (NSString *) _getTitleOfColumn: (int)column
|
||||||
{
|
{
|
||||||
// If not visible then nothing to display
|
|
||||||
if ((column < _firstVisibleColumn) || (column > _lastVisibleColumn))
|
|
||||||
return @"";
|
|
||||||
|
|
||||||
// Ask the delegate for the column title
|
// Ask the delegate for the column title
|
||||||
if ([_browserDelegate respondsToSelector:
|
if ([_browserDelegate respondsToSelector:
|
||||||
@selector(browser:titleOfColumn:)])
|
@selector(browser:titleOfColumn:)])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue