1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSBrowserCell.m
|
|
|
|
|
|
|
|
Cell class for the NSBrowser
|
|
|
|
|
1997-10-31 01:24:08 +00:00
|
|
|
Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
1998-11-25 17:16:48 +00:00
|
|
|
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
|
|
|
Date: October 1998
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
This file is part of the GNUstep GUI Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 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
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1998-11-25 17:16:48 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSBrowserCell.h>
|
1997-10-31 01:24:08 +00:00
|
|
|
#include <AppKit/NSTextFieldCell.h>
|
|
|
|
#include <AppKit/NSImage.h>
|
1998-11-25 17:16:48 +00:00
|
|
|
#include <AppKit/NSEvent.h>
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-10-31 01:24:08 +00:00
|
|
|
// Class variables
|
|
|
|
static NSImage *branch_image;
|
|
|
|
static NSImage *highlight_image;
|
|
|
|
|
|
|
|
// Private methods
|
|
|
|
@interface NSBrowserCell (Private)
|
|
|
|
- (void)setBranchImageCell:aCell;
|
|
|
|
- (void)setHighlightBranchImageCell:aCell;
|
|
|
|
- (void)setTextFieldCell:aCell;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSBrowserCell (Private)
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)setBranchImageCell:aCell { _branchImage = aCell; }
|
|
|
|
- (void)setHighlightBranchImageCell:aCell { _highlightBranchImage = aCell; }
|
|
|
|
- (void)setTextFieldCell:aCell { _browserText = aCell; }
|
1997-10-31 01:24:08 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
//
|
|
|
|
// NSBrowserCell implementation
|
|
|
|
//
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSBrowserCell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
if (self == [NSBrowserCell class])
|
|
|
|
{
|
|
|
|
[self setVersion:1];
|
|
|
|
// The default images
|
|
|
|
branch_image = [NSImage imageNamed: @"common_ArrowRight"];
|
|
|
|
highlight_image = [NSImage imageNamed: @"common_ArrowRightH"];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Accessing Graphic Attributes
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
+ (NSImage *)branchImage { return branch_image; }
|
|
|
|
+ (NSImage *)highlightedBranchImage { return highlight_image; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- init
|
|
|
|
{
|
|
|
|
return [self initTextCell: @"aTitle"];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initTextCell:(NSString *)aString
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[super initTextCell: aString];
|
|
|
|
// create image cells
|
|
|
|
_branchImage = [[NSCell alloc] initImageCell: [NSBrowserCell branchImage]];
|
|
|
|
_highlightBranchImage = [[NSCell alloc] initImageCell:
|
|
|
|
[NSBrowserCell highlightedBranchImage]];
|
|
|
|
// create the text cell
|
|
|
|
_browserText = [[NSTextFieldCell alloc] initTextCell: aString];
|
|
|
|
[_browserText setEditable: NO];
|
|
|
|
[_browserText setBordered: NO];
|
|
|
|
[_browserText setDrawsBackground: YES];
|
|
|
|
|
|
|
|
_alternateImage = nil;
|
|
|
|
_isLeaf = NO;
|
|
|
|
_isLoaded = NO;
|
|
|
|
|
|
|
|
[self setEditable: YES];
|
|
|
|
|
|
|
|
return self;
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[_branchImage release];
|
|
|
|
[_highlightBranchImage release];
|
|
|
|
[_alternateImage release];
|
|
|
|
[_browserText release];
|
|
|
|
|
|
|
|
[super dealloc];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)copyWithZone:(NSZone*)zone
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
NSBrowserCell* c = [super copyWithZone:zone];
|
|
|
|
// Copy the image cells
|
|
|
|
[c setBranchImageCell: [_branchImage copy]];
|
|
|
|
[c setHighlightBranchImageCell: [_branchImage copy]];
|
|
|
|
[c setAlternateImage: _alternateImage];
|
|
|
|
|
|
|
|
[c setTextFieldCell: [_browserText copy]]; // Copy the text cell
|
|
|
|
|
|
|
|
[c setLeaf: _isLeaf];
|
|
|
|
[c setLoaded: NO];
|
|
|
|
|
|
|
|
return c;
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Accessing Graphic Attributes
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (NSImage *)alternateImage { return _alternateImage; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setAlternateImage:(NSImage *)anImage
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[anImage retain];
|
|
|
|
[_alternateImage release];
|
|
|
|
_alternateImage = anImage;
|
|
|
|
// Set the image in our
|
|
|
|
if (_alternateImage) // highlight cell
|
|
|
|
[_highlightBranchImage setImage: _alternateImage];
|
|
|
|
else
|
|
|
|
[_highlightBranchImage setImage:[NSBrowserCell highlightedBranchImage]];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Placing in the Browser Hierarchy
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isLeaf { return _isLeaf; }
|
|
|
|
- (void)setLeaf:(BOOL)flag { _isLeaf = flag; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Determining Loaded Status
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isLoaded { return _isLoaded; }
|
|
|
|
- (void)setLoaded:(BOOL)flag { _isLoaded = flag; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Setting State
|
|
|
|
//
|
|
|
|
- (void)reset
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
cell_highlighted = NO;
|
|
|
|
cell_state = NO;
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)set
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
cell_highlighted = YES;
|
|
|
|
cell_state = YES;
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
// Setting and accessing the NSCell's Value
|
1997-10-31 01:24:08 +00:00
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (double)doubleValue { return [_browserText doubleValue]; }
|
|
|
|
- (float)floatValue; { return [_browserText floatValue]; }
|
|
|
|
- (int)intValue { return [_browserText intValue]; }
|
|
|
|
- (NSString *)stringValue { return [_browserText stringValue]; }
|
|
|
|
- (void)setIntValue:(int)anInt { [_browserText setIntValue: anInt]; }
|
|
|
|
|
|
|
|
- (void)setDoubleValue:(double)aDouble
|
|
|
|
{
|
|
|
|
[_browserText setDoubleValue:aDouble];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)setFloatValue:(float)aFloat
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[_browserText setFloatValue: aFloat];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)setStringValue:(NSString *)aString
|
|
|
|
{
|
|
|
|
[_browserText setStringValue: aString];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
//
|
|
|
|
// Displaying
|
|
|
|
//
|
|
|
|
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
NSRect title_rect = cellFrame;
|
|
|
|
NSRect image_rect = cellFrame;
|
|
|
|
NSImage *image = nil;
|
|
|
|
|
|
|
|
control_view = controlView; // remember last view
|
|
|
|
// cell was drawn in
|
|
|
|
if (cell_highlighted || cell_state) // temporary hack FAR FIX ME?
|
|
|
|
{
|
|
|
|
NSColor *white = [NSColor whiteColor];
|
|
|
|
|
|
|
|
[white set];
|
|
|
|
[_browserText setBackgroundColor: white];
|
|
|
|
if (!_isLeaf)
|
|
|
|
{
|
|
|
|
image = [_highlightBranchImage image];
|
|
|
|
image_rect.size.height = cellFrame.size.height;
|
|
|
|
image_rect.size.width = image_rect.size.height;
|
|
|
|
// Right justify
|
|
|
|
image_rect.origin.x += cellFrame.size.width- image_rect.size.width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
image_rect = NSZeroRect;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSColor *backColor = [[controlView window] backgroundColor];
|
|
|
|
|
|
|
|
[backColor set];
|
|
|
|
[_browserText setBackgroundColor:backColor];
|
|
|
|
if (!_isLeaf)
|
|
|
|
{
|
|
|
|
image = [_branchImage image];
|
|
|
|
image_rect.size.height = cellFrame.size.height;
|
|
|
|
image_rect.size.width = image_rect.size.height;
|
|
|
|
// Right justify
|
|
|
|
image_rect.origin.x += cellFrame.size.width- image_rect.size.width;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
image_rect = NSZeroRect;
|
|
|
|
}
|
|
|
|
NSRectFill(cellFrame); // Clear the background
|
|
|
|
|
|
|
|
title_rect.size.width -= image_rect.size.width + 4; // draw the title cell
|
|
|
|
[_browserText drawWithFrame:title_rect inView: controlView];
|
|
|
|
|
|
|
|
if (image) // Draw the image
|
|
|
|
[self _displayImage:image inFrame:image_rect];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
|
|
|
{ // no border so just
|
|
|
|
// draw the interior
|
|
|
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)highlight:(BOOL)lit withFrame:(NSRect)cellFrame // may not be per
|
|
|
|
inView:(NSView *)controlView // spec FIX ME?
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[super highlight: lit withFrame: cellFrame inView: controlView];
|
|
|
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
//
|
|
|
|
// Editing Text
|
|
|
|
//
|
|
|
|
- (void)editWithFrame:(NSRect)aRect
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
editor:(NSText *)textObject
|
|
|
|
delegate:(id)anObject
|
|
|
|
event:(NSEvent *)theEvent
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
NSPoint location = [controlView convertPoint:[theEvent locationInWindow]
|
|
|
|
fromView:nil];
|
|
|
|
|
|
|
|
fprintf(stderr, " NSBrowserCell: editWithFrame --- ");
|
|
|
|
|
|
|
|
[_browserText _setCursorLocation:location];
|
|
|
|
[_browserText _setCursorVisibility: YES];
|
|
|
|
|
|
|
|
if ([[controlView window] makeFirstResponder:controlView])
|
|
|
|
fprintf(stderr, " XRBrowserCell: we are now first responder --- ");
|
|
|
|
|
|
|
|
[self drawInteriorWithFrame: aRect inView: controlView];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)endEditing:(NSText *)textObject
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[_browserText _setCursorVisibility: NO];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)_handleKeyEvent:(NSEvent*)keyEvent
|
1997-10-31 01:24:08 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
fprintf(stderr, " NSBrowserCell: _handleKeyEvent --- ");
|
|
|
|
|
|
|
|
[_browserText _handleKeyEvent:keyEvent];
|
|
|
|
|
|
|
|
// [self drawInteriorWithFrame: aRect inView: controlView];
|
1997-10-31 01:24:08 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[super encodeWithCoder:aCoder];
|
|
|
|
|
|
|
|
[aCoder encodeObject: _browserText];
|
|
|
|
[aCoder encodeObject: _branchImage];
|
|
|
|
[aCoder encodeObject: _highlightBranchImage];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLeaf];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isLoaded];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[super initWithCoder:aDecoder];
|
|
|
|
|
|
|
|
_browserText = [aDecoder decodeObject];
|
|
|
|
_branchImage = [aDecoder decodeObject];
|
|
|
|
_highlightBranchImage = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isLeaf];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isLoaded];
|
|
|
|
|
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|