1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSCell.m
|
|
|
|
|
|
|
|
The abstract cell class
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
|
|
|
|
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>
|
1997-08-18 17:10:23 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <Foundation/NSValue.h>
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSApplication.h>
|
1997-03-17 18:43:27 +00:00
|
|
|
#include <AppKit/NSWindow.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSImage.h>
|
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
#include <AppKit/NSView.h>
|
1997-08-05 21:50:10 +00:00
|
|
|
#include <AppKit/NSControl.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSCell.h>
|
|
|
|
#include <AppKit/NSEvent.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
@implementation NSCell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSCell class])
|
|
|
|
{
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tracking the Mouse
|
|
|
|
//
|
|
|
|
+ (BOOL)prefersTrackingUntilMouseUp
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Initializing an NSCell
|
|
|
|
//
|
1997-04-22 18:23:58 +00:00
|
|
|
- _init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
cell_type = NSNullCellType;
|
1997-01-31 13:40:15 +00:00
|
|
|
cell_image = nil;
|
|
|
|
cell_font = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
image_position = NSNoImage;
|
|
|
|
cell_state = NO;
|
|
|
|
cell_highlighted = NO;
|
|
|
|
cell_enabled = YES;
|
|
|
|
cell_editable = NO;
|
|
|
|
cell_bordered = NO;
|
|
|
|
cell_bezeled = NO;
|
|
|
|
cell_scrollable = NO;
|
|
|
|
cell_selectable = NO;
|
|
|
|
cell_continuous = NO;
|
|
|
|
cell_float_autorange = NO;
|
|
|
|
cell_float_left = 0;
|
|
|
|
cell_float_right = 0;
|
1997-08-05 21:50:10 +00:00
|
|
|
action_mask = NSLeftMouseUpMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-04-22 18:23:58 +00:00
|
|
|
- init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
[self _init];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
- (id)initImageCell:(NSImage *)anImage
|
|
|
|
{
|
1997-04-22 18:23:58 +00:00
|
|
|
[self _init];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// Not an image class --then forget it
|
|
|
|
if (![anImage isKindOfClass:[NSImage class]])
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
cell_type = NSImageCellType;
|
1997-03-05 19:46:41 +00:00
|
|
|
cell_image = [anImage retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
image_position = NSImageOnly;
|
1997-03-27 20:36:47 +00:00
|
|
|
cell_font = [[NSFont userFontOfSize:16] retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initTextCell:(NSString *)aString
|
|
|
|
{
|
1997-04-22 18:23:58 +00:00
|
|
|
[self _init];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// Not a string class --then forget it
|
|
|
|
//if (![aString isKindOfClass:[NSString class]])
|
|
|
|
// return nil;
|
|
|
|
|
1997-03-27 20:36:47 +00:00
|
|
|
cell_font = [[NSFont userFontOfSize:16] retain];
|
1997-03-05 19:46:41 +00:00
|
|
|
contents = [aString retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
cell_type = NSTextCellType;
|
1997-02-18 18:45:16 +00:00
|
|
|
text_align = NSCenterTextAlignment;
|
1997-01-31 13:40:15 +00:00
|
|
|
cell_image = nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
image_position = NSNoImage;
|
|
|
|
cell_float_autorange = YES;
|
|
|
|
cell_float_left = 0;
|
|
|
|
cell_float_right = 6;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[contents release];
|
|
|
|
[cell_image release];
|
|
|
|
[cell_font release];
|
1997-07-07 16:56:52 +00:00
|
|
|
[represented_object release];
|
1997-02-18 00:29:25 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Determining Component Sizes
|
|
|
|
//
|
|
|
|
- (void)calcDrawInfo:(NSRect)aRect
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (NSSize)cellSize
|
|
|
|
{
|
|
|
|
return NSZeroSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)cellSizeForBounds:(NSRect)aRect
|
|
|
|
{
|
|
|
|
return NSZeroSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)drawingRectForBounds:(NSRect)theRect
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)imageRectForBounds:(NSRect)theRect
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)titleRectForBounds:(NSRect)theRect
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the NSCell's Type
|
|
|
|
//
|
|
|
|
- (void)setType:(NSCellType)aType
|
|
|
|
{
|
|
|
|
cell_type = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCellType)type
|
|
|
|
{
|
|
|
|
return cell_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the NSCell's State
|
|
|
|
//
|
|
|
|
- (void)setState:(int)value
|
|
|
|
{
|
|
|
|
cell_state = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)state
|
|
|
|
{
|
|
|
|
return cell_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Enabling and Disabling the NSCell
|
|
|
|
//
|
|
|
|
- (BOOL)isEnabled
|
|
|
|
{
|
|
|
|
return cell_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setEnabled:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_enabled = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Image
|
|
|
|
//
|
|
|
|
- (NSImage *)image
|
|
|
|
{
|
1997-01-31 13:40:15 +00:00
|
|
|
return cell_image;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setImage:(NSImage *)anImage
|
|
|
|
{
|
|
|
|
// Not an image class --then forget it
|
|
|
|
if (![anImage isKindOfClass:[NSImage class]])
|
|
|
|
return;
|
|
|
|
|
1997-01-31 13:40:15 +00:00
|
|
|
// Only set the image if we are an image cell
|
1997-03-05 19:46:41 +00:00
|
|
|
[anImage retain];
|
|
|
|
[cell_image release];
|
|
|
|
cell_image = anImage;
|
1997-07-07 16:56:52 +00:00
|
|
|
[self setType:NSImageCellType];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the NSCell's Value
|
|
|
|
//
|
|
|
|
- (double)doubleValue
|
|
|
|
{
|
|
|
|
return [contents doubleValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float)floatValue;
|
|
|
|
{
|
|
|
|
return [contents floatValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)intValue
|
|
|
|
{
|
|
|
|
return [contents intValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)stringValue
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return contents;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setDoubleValue:(double)aDouble
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
NSNumber* number = [NSNumber numberWithDouble:aDouble];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-03-05 19:46:41 +00:00
|
|
|
[contents release];
|
1997-02-18 00:29:25 +00:00
|
|
|
contents = [[number stringValue] retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFloatValue:(float)aFloat
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
NSNumber* number = [NSNumber numberWithFloat:aFloat];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-03-05 19:46:41 +00:00
|
|
|
[contents release];
|
1997-02-18 00:29:25 +00:00
|
|
|
contents = [[number stringValue] retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIntValue:(int)anInt
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
NSNumber* number = [NSNumber numberWithInt:anInt];
|
|
|
|
|
1997-03-05 19:46:41 +00:00
|
|
|
[contents release];
|
1997-02-18 00:29:25 +00:00
|
|
|
contents = [[number stringValue] retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStringValue:(NSString *)aString
|
|
|
|
{
|
1997-03-05 19:46:41 +00:00
|
|
|
aString = [aString copy];
|
|
|
|
[contents release];
|
1997-01-23 18:17:28 +00:00
|
|
|
if (!aString)
|
|
|
|
contents = @"";
|
|
|
|
else
|
1997-03-05 19:46:41 +00:00
|
|
|
contents = aString;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Interacting with Other NSCells
|
|
|
|
//
|
|
|
|
- (void)takeDoubleValueFrom:(id)sender
|
|
|
|
{
|
|
|
|
[self setDoubleValue:[sender doubleValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)takeFloatValueFrom:(id)sender
|
|
|
|
{
|
|
|
|
[self setFloatValue:[sender floatValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)takeIntValueFrom:(id)sender
|
|
|
|
{
|
|
|
|
[self setIntValue:[sender intValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)takeStringValueFrom:(id)sender
|
|
|
|
{
|
|
|
|
[self setStringValue:[sender stringValue]];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Modifying Text Attributes
|
|
|
|
//
|
|
|
|
- (NSTextAlignment)alignment
|
|
|
|
{
|
|
|
|
return text_align;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSFont *)font
|
|
|
|
{
|
1997-01-31 13:40:15 +00:00
|
|
|
return cell_font;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isEditable
|
|
|
|
{
|
|
|
|
return cell_editable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isSelectable
|
|
|
|
{
|
|
|
|
return cell_selectable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isScrollable
|
|
|
|
{
|
|
|
|
return cell_scrollable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlignment:(NSTextAlignment)mode
|
|
|
|
{
|
|
|
|
text_align = mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setEditable:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_editable = flag;
|
|
|
|
// If its editable then its selectable
|
|
|
|
if (flag)
|
|
|
|
cell_selectable = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFont:(NSFont *)fontObject
|
|
|
|
{
|
|
|
|
// Not a font --then forget it
|
|
|
|
if (![fontObject isKindOfClass:[NSFont class]])
|
|
|
|
return;
|
|
|
|
|
1997-03-05 19:46:41 +00:00
|
|
|
[fontObject retain];
|
|
|
|
[cell_font release];
|
|
|
|
cell_font = fontObject;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSelectable:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_selectable = flag;
|
|
|
|
// If its not selectable then its not editable
|
|
|
|
if (!flag)
|
|
|
|
cell_editable = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setScrollable:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_scrollable = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setWraps:(BOOL)flag
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (BOOL)wraps
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Editing Text
|
|
|
|
//
|
|
|
|
- (void)editWithFrame:(NSRect)aRect
|
|
|
|
inView:(NSView *)controlView
|
1996-06-21 15:27:13 +00:00
|
|
|
editor:(NSText *)textObject
|
|
|
|
delegate:(id)anObject
|
|
|
|
event:(NSEvent *)theEvent
|
1996-05-30 20:03:15 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)endEditing:(NSText *)textObject
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)selectWithFrame:(NSRect)aRect
|
|
|
|
inView:(NSView *)controlView
|
1996-06-21 15:27:13 +00:00
|
|
|
editor:(NSText *)textObject
|
|
|
|
delegate:(id)anObject
|
|
|
|
start:(int)selStart
|
1996-05-30 20:03:15 +00:00
|
|
|
length:(int)selLength
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Validating Input
|
|
|
|
//
|
|
|
|
- (int)entryType
|
|
|
|
{
|
|
|
|
return entry_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isEntryAcceptable:(NSString *)aString
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setEntryType:(int)aType
|
|
|
|
{
|
|
|
|
entry_type = aType;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Formatting Data
|
|
|
|
//
|
|
|
|
- (void)setFloatingPointFormat:(BOOL)autoRange
|
|
|
|
left:(unsigned int)leftDigits
|
|
|
|
right:(unsigned int)rightDigits
|
|
|
|
{
|
|
|
|
cell_float_autorange = autoRange;
|
|
|
|
cell_float_left = leftDigits;
|
|
|
|
cell_float_right = rightDigits;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Modifying Graphic Attributes
|
|
|
|
//
|
|
|
|
- (BOOL)isBezeled
|
|
|
|
{
|
|
|
|
return cell_bezeled;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isBordered
|
|
|
|
{
|
|
|
|
return cell_bordered;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBezeled:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_bezeled = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setBordered:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_bordered = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting Parameters
|
|
|
|
//
|
|
|
|
- (int)cellAttribute:(NSCellAttribute)aParameter
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setCellAttribute:(NSCellAttribute)aParameter
|
|
|
|
to:(int)value
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Displaying
|
|
|
|
//
|
|
|
|
- (NSView *)controlView
|
|
|
|
{
|
|
|
|
return control_view;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawInteriorWithFrame:(NSRect)cellFrame
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)highlight:(BOOL)lit
|
|
|
|
withFrame:(NSRect)cellFrame
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{
|
|
|
|
cell_highlighted = lit;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isHighlighted
|
|
|
|
{
|
|
|
|
return cell_highlighted;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Target and Action
|
|
|
|
//
|
|
|
|
- (SEL)action
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isContinuous
|
|
|
|
{
|
|
|
|
return cell_continuous;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)sendActionOn:(int)mask
|
|
|
|
{
|
1997-08-05 21:50:10 +00:00
|
|
|
unsigned int previousMask = action_mask;
|
|
|
|
|
|
|
|
action_mask = mask;
|
|
|
|
|
|
|
|
return previousMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAction:(SEL)aSelector
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)setContinuous:(BOOL)flag
|
|
|
|
{
|
|
|
|
cell_continuous = flag;
|
1997-08-05 21:50:10 +00:00
|
|
|
[self sendActionOn:(NSLeftMouseUpMask|NSPeriodicMask)];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTarget:(id)anObject
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (id)target
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
1997-07-07 16:56:52 +00:00
|
|
|
- (void)performClick:(id)sender
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Assigning a Tag
|
|
|
|
//
|
|
|
|
- (void)setTag:(int)anInt
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (int)tag
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Handling Keyboard Alternatives
|
|
|
|
//
|
|
|
|
- (NSString *)keyEquivalent
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Tracking the Mouse
|
|
|
|
//
|
|
|
|
- (BOOL)continueTracking:(NSPoint)lastPoint
|
|
|
|
at:(NSPoint)currentPoint
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)mouseDownFlags
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)getPeriodicDelay:(float *)delay
|
|
|
|
interval:(float *)interval
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
1997-08-06 20:29:07 +00:00
|
|
|
*delay = 0.05;
|
1997-08-05 21:50:10 +00:00
|
|
|
*interval = 0.05;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (BOOL)startTrackingAt:(NSPoint)startPoint
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{
|
|
|
|
// If the point is in the view then yes start tracking
|
|
|
|
if ([controlView mouse: startPoint inRect: [controlView bounds]])
|
|
|
|
return YES;
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopTracking:(NSPoint)lastPoint
|
|
|
|
at:(NSPoint)stopPoint
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
mouseIsUp:(BOOL)flag
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)trackMouse:(NSEvent *)theEvent
|
|
|
|
inRect:(NSRect)cellFrame
|
|
|
|
ofView:(NSView *)controlView
|
|
|
|
untilMouseUp:(BOOL)flag
|
|
|
|
{
|
1997-08-05 21:50:10 +00:00
|
|
|
NSApplication *theApp = [NSApplication sharedApplication];
|
|
|
|
unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask |
|
|
|
|
NSMouseMovedMask | NSLeftMouseDraggedMask | NSRightMouseDraggedMask;
|
|
|
|
NSPoint location = [theEvent locationInWindow];
|
|
|
|
NSPoint point = [controlView convertPoint: location fromView: nil];
|
|
|
|
float delay, interval;
|
|
|
|
id target = [self target];
|
|
|
|
SEL action = [self action];
|
|
|
|
NSPoint last_point;
|
|
|
|
BOOL done;
|
|
|
|
BOOL mouseWentUp;
|
|
|
|
|
|
|
|
NSDebugLog(@"NSCell start tracking\n");
|
|
|
|
NSDebugLog(@"NSCell tracking in rect %f %f %f %f\n",
|
|
|
|
cellFrame.origin.x, cellFrame.origin.y,
|
|
|
|
cellFrame.size.width, cellFrame.size.height);
|
|
|
|
NSDebugLog(@"NSCell initial point %f %f\n", point.x, point.y);
|
|
|
|
|
|
|
|
if (![self startTrackingAt: point inView: controlView])
|
|
|
|
return NO;
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-08-05 21:50:10 +00:00
|
|
|
// If point is in cellFrame then highlight the cell
|
|
|
|
if ([controlView mouse: point inRect: cellFrame]) {
|
|
|
|
[self highlight:YES withFrame:cellFrame inView:controlView];
|
|
|
|
[[controlView window] flushWindow];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
if ([theEvent type] == NSLeftMouseDown
|
|
|
|
&& (action_mask & NSLeftMouseDownMask))
|
|
|
|
[(NSControl*)controlView sendAction:action to:target];
|
|
|
|
|
|
|
|
if (cell_continuous) {
|
|
|
|
[self getPeriodicDelay:&delay interval:&interval];
|
|
|
|
[NSEvent startPeriodicEventsAfterDelay:delay withPeriod:interval];
|
|
|
|
event_mask |= NSPeriodicMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get next mouse events until a mouse up is obtained
|
|
|
|
NSDebugLog(@"NSCell get mouse events\n");
|
|
|
|
mouseWentUp = NO;
|
|
|
|
done = NO;
|
|
|
|
while (!done) {
|
|
|
|
NSEventType eventType;
|
|
|
|
BOOL pointIsInCell;
|
|
|
|
|
|
|
|
last_point = point;
|
|
|
|
theEvent = [theApp nextEventMatchingMask:event_mask untilDate:nil
|
|
|
|
inMode:NSEventTrackingRunLoopMode dequeue:YES];
|
|
|
|
eventType = [theEvent type];
|
|
|
|
|
|
|
|
if (eventType != NSPeriodic) {
|
|
|
|
location = [theEvent locationInWindow];
|
|
|
|
point = [controlView convertPoint: location fromView: nil];
|
|
|
|
NSDebugLog(@"NSCell location %f %f\n", location.x, location.y);
|
|
|
|
NSDebugLog(@"NSCell point %f %f\n", point.x, point.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NSDebugLog (@"got a periodic event");
|
|
|
|
|
|
|
|
// Point is not in cell
|
|
|
|
if (![controlView mouse: point inRect: cellFrame]) {
|
|
|
|
NSDebugLog(@"NSCell point not in cell frame\n");
|
|
|
|
|
|
|
|
pointIsInCell = NO;
|
|
|
|
|
|
|
|
// unhighlight cell is highlighted
|
|
|
|
if (cell_highlighted) {
|
|
|
|
[self highlight: NO withFrame: cellFrame
|
|
|
|
inView: controlView];
|
|
|
|
[self drawWithFrame: cellFrame inView: controlView];
|
1997-03-17 18:43:27 +00:00
|
|
|
[[controlView window] flushWindow];
|
|
|
|
}
|
1997-08-05 21:50:10 +00:00
|
|
|
|
|
|
|
// Do we now return or keep tracking
|
|
|
|
if (!([[self class] prefersTrackingUntilMouseUp] && flag)) {
|
|
|
|
NSDebugLog(@"NSCell return immediately\n");
|
|
|
|
done = YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Point is in cell
|
|
|
|
pointIsInCell = YES;
|
|
|
|
|
|
|
|
// highlight cell if not highlighted
|
|
|
|
if (!cell_highlighted) {
|
|
|
|
[self highlight: YES withFrame: cellFrame
|
|
|
|
inView: controlView];
|
|
|
|
//[self drawWithFrame: cellFrame inView: controlView];
|
|
|
|
[[controlView window] flushWindow];
|
|
|
|
}
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-08-05 21:50:10 +00:00
|
|
|
// should we continue tracking?
|
1997-08-22 18:38:38 +00:00
|
|
|
if (!done
|
|
|
|
&& ![self continueTracking:last_point at:point inView:controlView]) {
|
1997-08-05 21:50:10 +00:00
|
|
|
NSDebugLog(@"NSCell stop tracking\n");
|
|
|
|
done = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Did the mouse go up?
|
|
|
|
if (eventType == NSLeftMouseUp) {
|
1997-08-06 20:29:07 +00:00
|
|
|
NSDebugLog(@"NSCell mouse went up\n");
|
1997-08-05 21:50:10 +00:00
|
|
|
mouseWentUp = YES;
|
|
|
|
done = YES;
|
|
|
|
if ((action_mask & NSLeftMouseUpMask))
|
|
|
|
[(NSControl*)controlView sendAction:action to:target];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (pointIsInCell
|
|
|
|
&& ((eventType == NSLeftMouseDragged
|
|
|
|
&& (action_mask & NSLeftMouseDraggedMask))
|
|
|
|
|| ((eventType == NSPeriodic)
|
|
|
|
&& (action_mask & NSPeriodicMask))))
|
|
|
|
[(NSControl*)controlView sendAction:action to:target];
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tell ourselves to stop tracking
|
|
|
|
[self stopTracking:last_point at:point
|
|
|
|
inView:controlView mouseIsUp:mouseWentUp];
|
|
|
|
|
|
|
|
if (cell_continuous)
|
|
|
|
[NSEvent stopPeriodicEvents];
|
|
|
|
|
|
|
|
// Return YES only if the mouse went up within the cell
|
|
|
|
if (mouseWentUp && [controlView mouse: point inRect: cellFrame]) {
|
|
|
|
NSDebugLog(@"NSCell mouse went up in cell\n");
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise return NO
|
|
|
|
NSDebugLog(@"NSCell mouse did not go up in cell\n");
|
|
|
|
return NO;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Managing the Cursor
|
|
|
|
//
|
|
|
|
- (void)resetCursorRect:(NSRect)cellFrame
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Comparing to Another NSCell
|
|
|
|
//
|
|
|
|
- (NSComparisonResult)compare:(id)otherCell
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using the NSCell to Represent an Object
|
|
|
|
//
|
|
|
|
- (id)representedObject
|
|
|
|
{
|
1997-07-07 16:56:52 +00:00
|
|
|
return represented_object;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setRepresentedObject:(id)anObject
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
|
|
|
[anObject retain];
|
|
|
|
[represented_object release];
|
|
|
|
represented_object = anObject;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-04-22 18:23:58 +00:00
|
|
|
- (id)copyWithZone:(NSZone*)zone
|
|
|
|
{
|
|
|
|
NSCell* c = NSAllocateObject (isa, 0, zone);
|
|
|
|
|
|
|
|
[c setStringValue:contents];
|
|
|
|
[c setImage:cell_image];
|
|
|
|
[c setFont:cell_font];
|
|
|
|
[c setState:cell_state];
|
|
|
|
c->cell_highlighted = cell_highlighted;
|
|
|
|
[c setEnabled:cell_enabled];
|
|
|
|
[c setEditable:cell_editable];
|
|
|
|
[c setBordered:cell_bordered];
|
|
|
|
[c setBezeled:cell_bezeled];
|
|
|
|
[c setScrollable:cell_scrollable];
|
|
|
|
[c setSelectable:cell_selectable];
|
|
|
|
[c setContinuous:cell_continuous];
|
|
|
|
[c setFloatingPointFormat:cell_float_autorange
|
|
|
|
left:cell_float_left
|
|
|
|
right:cell_float_right];
|
|
|
|
c->image_position = image_position;
|
|
|
|
[c setType:cell_type];
|
|
|
|
[c setAlignment:text_align];
|
|
|
|
[c setEntryType:entry_type];
|
|
|
|
c->control_view = control_view;
|
|
|
|
c->cell_size = cell_size;
|
1997-07-07 16:56:52 +00:00
|
|
|
[c setRepresentedObject:represented_object];
|
1997-04-22 18:23:58 +00:00
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
|
|
|
[aCoder encodeObject: contents];
|
1997-01-31 13:40:15 +00:00
|
|
|
[aCoder encodeObject: cell_image];
|
|
|
|
[aCoder encodeObject: cell_font];
|
1996-05-30 20:03:15 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_state];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_highlighted];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_enabled];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_editable];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_bordered];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_bezeled];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_scrollable];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_selectable];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_continuous];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &cell_float_autorange];
|
|
|
|
[aCoder encodeValueOfObjCType: "I" at: &cell_float_left];
|
|
|
|
[aCoder encodeValueOfObjCType: "I" at: &cell_float_right];
|
|
|
|
[aCoder encodeValueOfObjCType: "I" at: &image_position];
|
|
|
|
[aCoder encodeValueOfObjCType: "i" at: &cell_type];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(NSTextAlignment) at: &text_align];
|
|
|
|
[aCoder encodeValueOfObjCType: "i" at: &entry_type];
|
1997-02-18 00:29:25 +00:00
|
|
|
#if 0
|
1996-05-30 20:03:15 +00:00
|
|
|
[aCoder encodeObjectReference: control_view withName: @"Control view"];
|
1997-02-18 00:29:25 +00:00
|
|
|
#else
|
|
|
|
[aCoder encodeConditionalObject:control_view];
|
|
|
|
#endif
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
|
|
|
contents = [aDecoder decodeObject];
|
1997-01-31 13:40:15 +00:00
|
|
|
cell_image = [aDecoder decodeObject];
|
|
|
|
cell_font = [aDecoder decodeObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_state];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_highlighted];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_enabled];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_editable];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_bordered];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_bezeled];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_scrollable];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_selectable];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_continuous];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &cell_float_autorange];
|
|
|
|
[aDecoder decodeValueOfObjCType: "I" at: &cell_float_left];
|
|
|
|
[aDecoder decodeValueOfObjCType: "I" at: &cell_float_right];
|
|
|
|
[aDecoder decodeValueOfObjCType: "I" at: &image_position];
|
|
|
|
[aDecoder decodeValueOfObjCType: "i" at: &cell_type];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(NSTextAlignment) at: &text_align];
|
|
|
|
[aDecoder decodeValueOfObjCType: "i" at: &entry_type];
|
1997-02-18 00:29:25 +00:00
|
|
|
#if 0
|
1996-05-30 20:03:15 +00:00
|
|
|
[aDecoder decodeObjectAt: &control_view withName: NULL];
|
1997-02-18 00:29:25 +00:00
|
|
|
#else
|
|
|
|
control_view = [aDecoder decodeObject];
|
|
|
|
#endif
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|