1999-02-12 14:18:15 +00:00
|
|
|
/*
|
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
|
1998-08-30 16:06:47 +00:00
|
|
|
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
|
|
|
Date: August 1998
|
1999-02-12 14:18:15 +00:00
|
|
|
|
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.
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
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.
|
1999-02-12 14:18:15 +00:00
|
|
|
*/
|
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>
|
1998-12-15 16:20:22 +00:00
|
|
|
#include <Foundation/NSException.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>
|
1999-02-15 12:50:49 +00:00
|
|
|
#include <AppKit/NSColor.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSCell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
if (self == [NSCell class])
|
1996-05-30 20:03:15 +00:00
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (BOOL)prefersTrackingUntilMouseUp
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return NO;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1997-04-22 18:23:58 +00:00
|
|
|
- _init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
cell_type = NSNullCellType;
|
|
|
|
cell_image = nil;
|
|
|
|
cell_font = nil;
|
|
|
|
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;
|
|
|
|
action_mask = NSLeftMouseUpMask;
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-04-22 18:23:58 +00:00
|
|
|
- init
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return [self initTextCell:@""];
|
1997-04-22 18:23:58 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
- (id)initImageCell:(NSImage *)anImage
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
[super init];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
[self _init];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
if (![anImage isKindOfClass:[NSImage class]]) // image must be an
|
|
|
|
return nil; // NSImage
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
cell_type = NSImageCellType;
|
|
|
|
cell_image = [anImage retain];
|
|
|
|
image_position = NSImageOnly;
|
|
|
|
cell_font = [[NSFont userFontOfSize:0] retain];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initTextCell:(NSString *)aString
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
[super init];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
[self _init];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
cell_font = [[NSFont userFontOfSize:0] retain];
|
|
|
|
contents = [aString retain];
|
|
|
|
cell_type = NSTextCellType;
|
|
|
|
text_align = NSCenterTextAlignment;
|
|
|
|
cell_float_autorange = YES;
|
|
|
|
cell_float_right = 6;
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
1999-02-12 14:18:15 +00:00
|
|
|
if (contents)
|
1998-12-16 11:48:33 +00:00
|
|
|
[contents release];
|
1999-02-12 14:18:15 +00:00
|
|
|
if (cell_image)
|
1998-12-16 11:48:33 +00:00
|
|
|
[cell_image release];
|
|
|
|
[cell_font release];
|
1999-02-12 14:18:15 +00:00
|
|
|
if (represented_object)
|
1998-12-16 11:48:33 +00:00
|
|
|
[represented_object release];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
[super dealloc];
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Determining Component Sizes
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
- (void)calcDrawInfo:(NSRect)aRect
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (NSSize)cellSize
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return NSZeroSize;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSSize)cellSizeForBounds:(NSRect)aRect
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return NSZeroSize;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)drawingRectForBounds:(NSRect)theRect
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return NSZeroRect;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)imageRectForBounds:(NSRect)theRect
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return NSZeroRect;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)titleRectForBounds:(NSRect)theRect
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return NSZeroRect;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Setting the NSCell's Type
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-16 11:48:33 +00:00
|
|
|
- (void)setType:(NSCellType)aType { cell_type = aType; }
|
|
|
|
- (NSCellType)type { return cell_type; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Setting the NSCell's State
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-16 11:48:33 +00:00
|
|
|
- (void)setState:(int)value { cell_state = value; }
|
|
|
|
- (int)state { return cell_state; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Enabling and Disabling the NSCell
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-16 11:48:33 +00:00
|
|
|
- (BOOL)isEnabled { return cell_enabled; }
|
|
|
|
- (void)setEnabled:(BOOL)flag { cell_enabled = flag; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
//
|
|
|
|
// Determining the first responder
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
- (BOOL)acceptsFirstResponder { return cell_enabled; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Setting the Image
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-16 11:48:33 +00:00
|
|
|
- (NSImage *)image { return cell_image; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setImage:(NSImage *)anImage
|
1999-02-12 14:18:15 +00:00
|
|
|
{
|
|
|
|
if (![anImage isKindOfClass:[NSImage class]]) // set the image only
|
|
|
|
return; // if it's an NSImage
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
ASSIGN(cell_image, anImage);
|
1998-12-16 11:48:33 +00:00
|
|
|
[self setType:NSImageCellType];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Setting the NSCell's Value
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-16 11:48:33 +00:00
|
|
|
- (double)doubleValue { return [contents doubleValue]; }
|
|
|
|
- (float)floatValue; { return [contents floatValue]; }
|
|
|
|
- (int)intValue { return [contents intValue]; }
|
|
|
|
- (NSString *)stringValue { return contents; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setDoubleValue:(double)aDouble
|
|
|
|
{
|
1998-08-30 16:06:47 +00:00
|
|
|
NSString* number_string = [[NSNumber numberWithDouble:aDouble] stringValue];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
ASSIGN(contents, number_string);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFloatValue:(float)aFloat
|
|
|
|
{
|
1998-08-30 16:06:47 +00:00
|
|
|
NSString* number_string = [[NSNumber numberWithFloat:aFloat] stringValue];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
ASSIGN(contents, number_string);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIntValue:(int)anInt
|
|
|
|
{
|
1998-08-30 16:06:47 +00:00
|
|
|
NSString* number_string = [[NSNumber numberWithInt:anInt] stringValue];
|
1997-02-18 00:29:25 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
ASSIGN(contents, number_string);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStringValue:(NSString *)aString
|
|
|
|
{
|
1999-02-15 12:50:49 +00:00
|
|
|
NSString* _string;
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
if (!aString)
|
|
|
|
_string = @"";
|
|
|
|
else
|
|
|
|
_string = [[aString copy] autorelease];
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
ASSIGN(contents, _string);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Interacting with Other NSCells
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
- (void)takeDoubleValueFrom:(id)sender
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
[self setDoubleValue:[sender doubleValue]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)takeFloatValueFrom:(id)sender
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
[self setFloatValue:[sender floatValue]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)takeIntValueFrom:(id)sender
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
[self setIntValue:[sender intValue]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)takeStringValueFrom:(id)sender
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
[self setStringValue:[sender stringValue]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Modifying Text Attributes
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-16 11:48:33 +00:00
|
|
|
- (NSTextAlignment)alignment { return text_align; }
|
|
|
|
- (NSFont *)font { return cell_font; }
|
|
|
|
- (BOOL)isEditable { return cell_editable; }
|
|
|
|
- (BOOL)isSelectable { return cell_selectable; }
|
|
|
|
- (BOOL)isScrollable { return cell_scrollable; }
|
|
|
|
- (void)setAlignment:(NSTextAlignment)mode { text_align = mode; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setEditable:(BOOL)flag
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
cell_editable = flag;
|
|
|
|
|
|
|
|
if (flag) // If cell is not
|
|
|
|
cell_selectable = flag; // selectable then it's
|
|
|
|
} // not editable
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setFont:(NSFont *)fontObject
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
if (![fontObject isKindOfClass:[NSFont class]]) // set the font only
|
|
|
|
return; // if it's an NSFont
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
ASSIGN(cell_font, fontObject);
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setSelectable:(BOOL)flag
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
cell_selectable = flag;
|
1999-02-12 14:18:15 +00:00
|
|
|
|
|
|
|
if (!flag) // If cell is not
|
|
|
|
cell_editable = NO; // selectable then it's
|
1998-12-16 11:48:33 +00:00
|
|
|
} // not editable
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
- (void)setScrollable:(BOOL)flag { cell_scrollable = flag; }
|
|
|
|
- (void)setWraps:(BOOL)flag {}
|
|
|
|
- (BOOL)wraps { return NO; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-16 11:48:33 +00:00
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Editing Text
|
1998-12-16 11:48:33 +00:00
|
|
|
//
|
1996-05-30 20:03:15 +00:00
|
|
|
- (NSText *)setUpFieldEditorAttributes:(NSText *)textObject
|
|
|
|
{
|
1998-12-16 11:48:33 +00:00
|
|
|
return nil;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
- (void)editWithFrame:(NSRect)aRect
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
editor:(NSText *)textObject
|
|
|
|
delegate:(id)anObject
|
1998-12-16 11:48:33 +00:00
|
|
|
event:(NSEvent *)theEvent
|
* NSWindow.m renmae captureMouse: to _captureMouse: (designate as non OS),
various methods add fieldEditor support.
* GSContext.m/GSContext.h revert to previous code as solution discussed
with Adam Fedor regarding backends had problems I had not forseen.
* NSBrowserCell.h/.m specify text subcell as an NSCell, eliminate image
cell, copyWithZone: optimize and eliminate use of ASSIGN (fixes serious
dealloc bug), highlight: eliminate method (fixes dup display bug).
* NSButtonCell.m copyWithZone: optimize and eliminate use of ASSIGN
* NSStringDrawing.h/.m remove unimplemented draw methods from Category
(these are backend specific, can't be defined twice and are already
implemented in xraw).
* NSApplication.h redefine initialize_gnustep_backend () per Adam's
redefinition in the backend.
* Functions.m/.h remove initialize_gnustep_backend()
* NSCell.m preliminary implementation of fieldEditor mechanism,
copyWithZone: optimize and eliminate use of ASSIGN
* NSControl.m rename cell class global to _NSCONTROL_CELL_CLASS
* NSMatrix.m implement NSControl's updateCell: to prevent unecessary
matrix drawing if possible.
* NSView.m -resizeWithOldSuperviewSize reverted code to my own once more
(fewer lines and no if/else logic), changed code to use view frame instead
of bounds per 3.3/4.2 docs, optimize to avoid floating point math and scale
adjustment unless view has been scaled.
* NSScrollView.m define as externs various PS* functions for use in
drawing, polish drawing, move all backend code to front.
* Tools/dummy.m define dummy PS* functions employed in gui.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3454 72102866-910b-0410-8b05-ffd578937521
1998-12-14 09:54:38 +00:00
|
|
|
{
|
1999-02-12 14:18:15 +00:00
|
|
|
if (cell_type != NSTextCellType)
|
1998-12-16 11:48:33 +00:00
|
|
|
return;
|
|
|
|
|
* NSWindow.m renmae captureMouse: to _captureMouse: (designate as non OS),
various methods add fieldEditor support.
* GSContext.m/GSContext.h revert to previous code as solution discussed
with Adam Fedor regarding backends had problems I had not forseen.
* NSBrowserCell.h/.m specify text subcell as an NSCell, eliminate image
cell, copyWithZone: optimize and eliminate use of ASSIGN (fixes serious
dealloc bug), highlight: eliminate method (fixes dup display bug).
* NSButtonCell.m copyWithZone: optimize and eliminate use of ASSIGN
* NSStringDrawing.h/.m remove unimplemented draw methods from Category
(these are backend specific, can't be defined twice and are already
implemented in xraw).
* NSApplication.h redefine initialize_gnustep_backend () per Adam's
redefinition in the backend.
* Functions.m/.h remove initialize_gnustep_backend()
* NSCell.m preliminary implementation of fieldEditor mechanism,
copyWithZone: optimize and eliminate use of ASSIGN
* NSControl.m rename cell class global to _NSCONTROL_CELL_CLASS
* NSMatrix.m implement NSControl's updateCell: to prevent unecessary
matrix drawing if possible.
* NSView.m -resizeWithOldSuperviewSize reverted code to my own once more
(fewer lines and no if/else logic), changed code to use view frame instead
of bounds per 3.3/4.2 docs, optimize to avoid floating point math and scale
adjustment unless view has been scaled.
* NSScrollView.m define as externs various PS* functions for use in
drawing, polish drawing, move all backend code to front.
* Tools/dummy.m define dummy PS* functions employed in gui.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3454 72102866-910b-0410-8b05-ffd578937521
1998-12-14 09:54:38 +00:00
|
|
|
[[controlView window] makeFirstResponder:textObject];
|
|
|
|
|
|
|
|
[textObject setFrame:aRect];
|
|
|
|
[textObject setText:[self stringValue]];
|
|
|
|
[textObject setDelegate:anObject];
|
|
|
|
[controlView addSubview:textObject];
|
1998-12-16 11:48:33 +00:00
|
|
|
[controlView lockFocus];
|
* NSWindow.m renmae captureMouse: to _captureMouse: (designate as non OS),
various methods add fieldEditor support.
* GSContext.m/GSContext.h revert to previous code as solution discussed
with Adam Fedor regarding backends had problems I had not forseen.
* NSBrowserCell.h/.m specify text subcell as an NSCell, eliminate image
cell, copyWithZone: optimize and eliminate use of ASSIGN (fixes serious
dealloc bug), highlight: eliminate method (fixes dup display bug).
* NSButtonCell.m copyWithZone: optimize and eliminate use of ASSIGN
* NSStringDrawing.h/.m remove unimplemented draw methods from Category
(these are backend specific, can't be defined twice and are already
implemented in xraw).
* NSApplication.h redefine initialize_gnustep_backend () per Adam's
redefinition in the backend.
* Functions.m/.h remove initialize_gnustep_backend()
* NSCell.m preliminary implementation of fieldEditor mechanism,
copyWithZone: optimize and eliminate use of ASSIGN
* NSControl.m rename cell class global to _NSCONTROL_CELL_CLASS
* NSMatrix.m implement NSControl's updateCell: to prevent unecessary
matrix drawing if possible.
* NSView.m -resizeWithOldSuperviewSize reverted code to my own once more
(fewer lines and no if/else logic), changed code to use view frame instead
of bounds per 3.3/4.2 docs, optimize to avoid floating point math and scale
adjustment unless view has been scaled.
* NSScrollView.m define as externs various PS* functions for use in
drawing, polish drawing, move all backend code to front.
* Tools/dummy.m define dummy PS* functions employed in gui.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3454 72102866-910b-0410-8b05-ffd578937521
1998-12-14 09:54:38 +00:00
|
|
|
NSEraseRect(aRect);
|
1998-12-16 11:48:33 +00:00
|
|
|
[controlView unlockFocus];
|
* NSWindow.m renmae captureMouse: to _captureMouse: (designate as non OS),
various methods add fieldEditor support.
* GSContext.m/GSContext.h revert to previous code as solution discussed
with Adam Fedor regarding backends had problems I had not forseen.
* NSBrowserCell.h/.m specify text subcell as an NSCell, eliminate image
cell, copyWithZone: optimize and eliminate use of ASSIGN (fixes serious
dealloc bug), highlight: eliminate method (fixes dup display bug).
* NSButtonCell.m copyWithZone: optimize and eliminate use of ASSIGN
* NSStringDrawing.h/.m remove unimplemented draw methods from Category
(these are backend specific, can't be defined twice and are already
implemented in xraw).
* NSApplication.h redefine initialize_gnustep_backend () per Adam's
redefinition in the backend.
* Functions.m/.h remove initialize_gnustep_backend()
* NSCell.m preliminary implementation of fieldEditor mechanism,
copyWithZone: optimize and eliminate use of ASSIGN
* NSControl.m rename cell class global to _NSCONTROL_CELL_CLASS
* NSMatrix.m implement NSControl's updateCell: to prevent unecessary
matrix drawing if possible.
* NSView.m -resizeWithOldSuperviewSize reverted code to my own once more
(fewer lines and no if/else logic), changed code to use view frame instead
of bounds per 3.3/4.2 docs, optimize to avoid floating point math and scale
adjustment unless view has been scaled.
* NSScrollView.m define as externs various PS* functions for use in
drawing, polish drawing, move all backend code to front.
* Tools/dummy.m define dummy PS* functions employed in gui.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3454 72102866-910b-0410-8b05-ffd578937521
1998-12-14 09:54:38 +00:00
|
|
|
[textObject display];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-01-06 22:16:22 +00:00
|
|
|
/*
|
|
|
|
* editing is complete, remove the text obj acting as the field
|
1999-02-12 14:18:15 +00:00
|
|
|
* editor from window's view heirarchy, set our contents from it
|
1999-01-06 22:16:22 +00:00
|
|
|
*/
|
1999-02-12 14:18:15 +00:00
|
|
|
- (void)endEditing:(NSText *)textObject
|
1999-01-06 22:16:22 +00:00
|
|
|
{
|
|
|
|
[textObject setDelegate:nil];
|
|
|
|
[textObject removeFromSuperview];
|
|
|
|
[self setStringValue: [textObject text]];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)selectWithFrame:(NSRect)aRect
|
1999-02-12 14:18:15 +00:00
|
|
|
inView:(NSView *)controlView
|
|
|
|
editor:(NSText *)textObject
|
|
|
|
delegate:(id)anObject
|
|
|
|
start:(int)selStart
|
1998-12-16 11:48:33 +00:00
|
|
|
length:(int)selLength
|
|
|
|
{ // preliminary FIX ME
|
1999-02-12 14:18:15 +00:00
|
|
|
if (!controlView || !textObject || !cell_font ||
|
1998-12-16 11:48:33 +00:00
|
|
|
(cell_type != NSTextCellType))
|
|
|
|
return;
|
|
|
|
|
|
|
|
[[controlView window] makeFirstResponder:textObject];
|
|
|
|
|
|
|
|
[textObject setFrame:aRect];
|
|
|
|
[textObject setText:[self stringValue]];
|
|
|
|
[textObject setDelegate:anObject];
|
|
|
|
[controlView addSubview:textObject];
|
|
|
|
NSEraseRect(aRect);
|
|
|
|
[textObject display];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Validating Input
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (int)entryType { return entry_type; }
|
|
|
|
- (BOOL)isEntryAcceptable:(NSString *)aString { return YES; }
|
|
|
|
- (void)setEntryType:(int)aType { entry_type = aType; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Formatting Data
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
- (void)setFloatingPointFormat:(BOOL)autoRange
|
1998-11-25 17:16:48 +00:00
|
|
|
left:(unsigned int)leftDigits
|
|
|
|
right:(unsigned int)rightDigits
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
cell_float_autorange = autoRange;
|
|
|
|
cell_float_left = leftDigits;
|
|
|
|
cell_float_right = rightDigits;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Modifying Graphic Attributes
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isBezeled { return cell_bezeled; }
|
|
|
|
- (BOOL)isBordered { return cell_bordered; }
|
|
|
|
- (BOOL)isOpaque { return cell_bezeled; }
|
|
|
|
- (void)setBezeled:(BOOL)flag { cell_bezeled = flag; }
|
|
|
|
- (void)setBordered:(BOOL)flag { cell_bordered = flag; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Setting Parameters
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
- (int)cellAttribute:(NSCellAttribute)aParameter
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
return 0;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)setCellAttribute:(NSCellAttribute)aParameter to:(int)value
|
|
|
|
{
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Displaying
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (NSView *)controlView { return control_view; }
|
|
|
|
- (void)setControlView:(NSView*)view { control_view = view; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
- (NSColor *)textColor
|
|
|
|
{
|
|
|
|
if ([self isEnabled])
|
|
|
|
return [NSColor blackColor];
|
|
|
|
else
|
|
|
|
return [NSColor darkGrayColor];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _drawText: (NSString *) title inFrame: (NSRect) cellFrame
|
|
|
|
{
|
|
|
|
NSColor *textColor;
|
|
|
|
NSFont *font;
|
|
|
|
float titleWidth;
|
|
|
|
float titleHeight;
|
|
|
|
|
|
|
|
if (!title)
|
|
|
|
return;
|
|
|
|
|
|
|
|
textColor = [self textColor];
|
|
|
|
|
|
|
|
font = [self font];
|
|
|
|
if (!font)
|
|
|
|
[NSException raise:NSInvalidArgumentException
|
|
|
|
format:@"Request to draw a text cell but no font specified!"];
|
|
|
|
titleWidth = [font widthOfString: title];
|
|
|
|
titleHeight = [font pointSize];
|
|
|
|
|
|
|
|
// Determine the y position of the text
|
|
|
|
cellFrame.origin.y = NSMidY (cellFrame) - titleHeight / 2;
|
|
|
|
cellFrame.size.height = titleHeight;
|
|
|
|
|
|
|
|
// Determine the x position of text
|
|
|
|
switch ([self alignment])
|
|
|
|
{
|
|
|
|
// ignore the justified and natural alignments
|
|
|
|
case NSLeftTextAlignment:
|
|
|
|
case NSJustifiedTextAlignment:
|
|
|
|
case NSNaturalTextAlignment:
|
|
|
|
break;
|
|
|
|
case NSRightTextAlignment:
|
|
|
|
if (titleWidth < NSWidth (cellFrame))
|
|
|
|
{
|
|
|
|
float shift = NSWidth (cellFrame) - titleWidth;
|
|
|
|
cellFrame.origin.x += shift;
|
|
|
|
cellFrame.size.width -= shift;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NSCenterTextAlignment:
|
|
|
|
if (titleWidth < NSWidth (cellFrame))
|
|
|
|
{
|
|
|
|
float shift = (NSWidth (cellFrame) - titleWidth) / 2;
|
|
|
|
cellFrame.origin.x += shift;
|
|
|
|
cellFrame.size.width -= shift;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[font set];
|
|
|
|
[textColor set];
|
|
|
|
[title drawInRect:cellFrame withAttributes: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw image centered in frame.
|
|
|
|
- (void) _drawImage: (NSImage *) image inFrame: (NSRect) cellFrame
|
|
|
|
{
|
|
|
|
NSSize size;
|
|
|
|
NSPoint position;
|
|
|
|
|
|
|
|
if (!image)
|
|
|
|
return;
|
|
|
|
|
|
|
|
size = [image size];
|
|
|
|
position.x = NSMidX (cellFrame) - size.width / 2;
|
|
|
|
position.y = NSMidY (cellFrame) - size.height / 2;
|
|
|
|
[image compositeToPoint: position operation: NSCompositeCopy];
|
|
|
|
}
|
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
1997-10-09 22:55:31 +00:00
|
|
|
{
|
1999-02-15 12:50:49 +00:00
|
|
|
cellFrame = NSInsetRect (cellFrame, xDist, yDist);
|
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
switch ([self type])
|
|
|
|
{
|
|
|
|
case NSTextCellType:
|
1999-02-15 12:50:49 +00:00
|
|
|
[self _drawText: [self stringValue] inFrame: cellFrame];
|
|
|
|
break;
|
1999-02-12 14:18:15 +00:00
|
|
|
case NSImageCellType:
|
1999-02-15 12:50:49 +00:00
|
|
|
[self _drawImage: [self image] inFrame: cellFrame];
|
|
|
|
break;
|
1999-02-12 14:18:15 +00:00
|
|
|
case NSNullCellType:
|
|
|
|
break;
|
|
|
|
}
|
1997-10-09 22:55:31 +00:00
|
|
|
}
|
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
- (void)drawWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
|
|
|
|
{
|
|
|
|
NSDebugLog (@"NSCell drawWithFrame:inView:");
|
|
|
|
|
|
|
|
// We apply a clipping rectangle so save the graphics state
|
|
|
|
PSgsave ();
|
|
|
|
|
|
|
|
// Save last view drawn to
|
|
|
|
[self setControlView: controlView];
|
|
|
|
|
|
|
|
// Clear the cell frame
|
|
|
|
if ([self isOpaque])
|
|
|
|
{
|
|
|
|
[[NSColor lightGrayColor] set];
|
|
|
|
NSRectFill(cellFrame);
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw the border if needed
|
|
|
|
if ([self isBordered])
|
|
|
|
{
|
|
|
|
if ([self isBezeled])
|
|
|
|
{
|
|
|
|
NSDrawWhiteBezel (cellFrame, cellFrame);
|
|
|
|
cellFrame = NSInsetRect (cellFrame, 2, 2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSFrameRect (cellFrame);
|
|
|
|
cellFrame = NSInsetRect (cellFrame, 1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NSRectClip (cellFrame);
|
|
|
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
|
|
|
|
|
|
|
PSgrestore ();
|
1999-02-12 14:18:15 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isHighlighted { return cell_highlighted; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)highlight:(BOOL)lit withFrame:(NSRect)cellFrame // Not per OS spec
|
|
|
|
inView:(NSView *)controlView // FIX ME
|
1999-02-12 14:18:15 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
cell_highlighted = lit;
|
|
|
|
[self drawWithFrame:cellFrame inView:controlView]; // draw cell
|
1999-02-12 14:18:15 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Target and Action
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (SEL)action { return NULL; }
|
1998-12-10 18:07:24 +00:00
|
|
|
- (void)setAction:(SEL)aSelector {}
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isContinuous { return cell_continuous; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (int)sendActionOn:(int)mask
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
unsigned int previousMask = action_mask;
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
action_mask = mask;
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
return previousMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setContinuous:(BOOL)flag
|
|
|
|
{
|
1998-12-10 18:07:24 +00:00
|
|
|
cell_continuous = flag;
|
|
|
|
[self sendActionOn:(NSLeftMouseUpMask|NSPeriodicMask)];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1998-12-10 18:07:24 +00:00
|
|
|
- (void)setTarget:(id)anObject {}
|
|
|
|
- (id)target { return nil; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-15 16:20:22 +00:00
|
|
|
- (void) performClick: (id)sender
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
1999-02-12 14:18:15 +00:00
|
|
|
NSView *cv = [self controlView];
|
|
|
|
|
1998-12-15 16:20:22 +00:00
|
|
|
[self highlight: YES withFrame: [cv frame] inView: cv];
|
|
|
|
if ([self action] && [self target])
|
|
|
|
{
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
[(NSControl*)cv sendAction: [self action] to: [self target]];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
|
|
|
[self highlight: NO withFrame: [cv frame] inView: cv];
|
|
|
|
[localException raise];
|
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
}
|
|
|
|
[self highlight: NO withFrame: [cv frame] inView: cv];
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Assigning a Tag
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-10 18:07:24 +00:00
|
|
|
- (void)setTag:(int)anInt {}
|
|
|
|
- (int)tag { return -1; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Handling Keyboard Alternatives
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-10 18:07:24 +00:00
|
|
|
- (NSString *)keyEquivalent { return nil; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Tracking the Mouse
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
- (BOOL)continueTracking:(NSPoint)lastPoint
|
1998-11-25 17:16:48 +00:00
|
|
|
at:(NSPoint)currentPoint
|
|
|
|
inView:(NSView *)controlView
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)mouseDownFlags
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
return 0;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)getPeriodicDelay:(float *)delay interval:(float *)interval
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
*delay = 0.05;
|
|
|
|
*interval = 0.05;
|
1997-08-05 21:50:10 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView
|
1999-02-12 14:18:15 +00:00
|
|
|
{ // If the point is in the view
|
1998-11-25 17:16:48 +00:00
|
|
|
// then yes start tracking
|
|
|
|
if ([controlView mouse: startPoint inRect: [controlView bounds]])
|
|
|
|
return YES;
|
1996-05-30 20:03:15 +00:00
|
|
|
else
|
1998-11-25 17:16:48 +00:00
|
|
|
return NO;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)stopTracking:(NSPoint)lastPoint
|
1998-11-20 02:14:22 +00:00
|
|
|
at:(NSPoint)stopPoint
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
mouseIsUp:(BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)trackMouse:(NSEvent *)theEvent
|
1998-11-25 17:16:48 +00:00
|
|
|
inRect:(NSRect)cellFrame
|
|
|
|
ofView:(NSView *)controlView
|
|
|
|
untilMouseUp:(BOOL)flag
|
|
|
|
{
|
|
|
|
NSApplication *theApp = [NSApplication sharedApplication];
|
|
|
|
unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask |
|
1999-02-12 14:18:15 +00:00
|
|
|
NSMouseMovedMask | NSLeftMouseDraggedMask |
|
1998-12-10 18:07:24 +00:00
|
|
|
NSRightMouseDraggedMask;
|
1998-11-25 17:16:48 +00:00
|
|
|
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;
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1998-12-10 18:07:24 +00:00
|
|
|
NSDebugLog(@"NSCell start tracking\n");
|
1999-02-12 14:18:15 +00:00
|
|
|
NSDebugLog(@"NSCell tracking in rect %f %f %f %f\n",
|
1998-12-10 18:07:24 +00:00
|
|
|
cellFrame.origin.x, cellFrame.origin.y,
|
|
|
|
cellFrame.size.width, cellFrame.size.height);
|
|
|
|
NSDebugLog(@"NSCell initial point %f %f\n", point.x, point.y);
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1998-12-10 18:07:24 +00:00
|
|
|
if (![self startTrackingAt: point inView: controlView])
|
|
|
|
return NO;
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
if (![controlView mouse: point inRect: cellFrame])
|
1998-12-10 18:07:24 +00:00
|
|
|
return NO; // point is not in cell
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
if ([theEvent type] == NSLeftMouseDown &&
|
1998-12-10 18:07:24 +00:00
|
|
|
(action_mask & NSLeftMouseDownMask))
|
|
|
|
[(NSControl*)controlView sendAction:action to:target];
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
if (cell_continuous)
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
[self getPeriodicDelay:&delay interval:&interval];
|
|
|
|
[NSEvent startPeriodicEventsAfterDelay:delay withPeriod:interval];
|
|
|
|
event_mask |= NSPeriodicMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSDebugLog(@"NSCell get mouse events\n");
|
|
|
|
mouseWentUp = NO;
|
|
|
|
done = NO;
|
1999-02-12 14:18:15 +00:00
|
|
|
while (!done) // Get next mouse
|
1998-12-10 18:07:24 +00:00
|
|
|
{ // event until a mouse
|
|
|
|
NSEventType eventType; // up is obtained
|
|
|
|
BOOL pointIsInCell;
|
|
|
|
|
|
|
|
last_point = point;
|
1999-02-12 14:18:15 +00:00
|
|
|
theEvent = [theApp nextEventMatchingMask:event_mask
|
|
|
|
untilDate:nil
|
|
|
|
inMode:NSEventTrackingRunLoopMode
|
1998-12-10 18:07:24 +00:00
|
|
|
dequeue:YES];
|
|
|
|
eventType = [theEvent type];
|
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
if (eventType != NSPeriodic)
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
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
|
1999-02-12 14:18:15 +00:00
|
|
|
if (![controlView mouse: point inRect: cellFrame])
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
NSDebugLog(@"NSCell point not in cell frame\n");
|
|
|
|
|
1999-02-12 14:18:15 +00:00
|
|
|
pointIsInCell = NO; // Do we return now or
|
1998-12-10 18:07:24 +00:00
|
|
|
// keep tracking?
|
1999-02-12 14:18:15 +00:00
|
|
|
if (![[self class] prefersTrackingUntilMouseUp] && flag)
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
NSDebugLog(@"NSCell return immediately\n");
|
|
|
|
done = YES;
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 14:18:15 +00:00
|
|
|
else
|
1998-12-10 18:07:24 +00:00
|
|
|
pointIsInCell = YES; // Point is in cell
|
|
|
|
|
|
|
|
if (!done && ![self continueTracking:last_point // should continue
|
|
|
|
at:point // tracking?
|
1999-02-12 14:18:15 +00:00
|
|
|
inView:controlView])
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
NSDebugLog(@"NSCell stop tracking\n");
|
|
|
|
done = YES;
|
|
|
|
}
|
|
|
|
// Did the mouse go up?
|
1999-02-12 14:18:15 +00:00
|
|
|
if (eventType == NSLeftMouseUp)
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
NSDebugLog(@"NSCell mouse went up\n");
|
|
|
|
mouseWentUp = YES;
|
|
|
|
done = YES;
|
|
|
|
if ((action_mask & NSLeftMouseUpMask))
|
|
|
|
[(NSControl*)controlView sendAction:action to:target];
|
|
|
|
}
|
1999-02-12 14:18:15 +00:00
|
|
|
else
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
if (pointIsInCell && ((eventType == NSLeftMouseDragged
|
|
|
|
&& (action_mask & NSLeftMouseDraggedMask))
|
|
|
|
|| ((eventType == NSPeriodic)
|
|
|
|
&& (action_mask & NSPeriodicMask))))
|
|
|
|
[(NSControl*)controlView sendAction:action to:target];
|
|
|
|
}
|
|
|
|
}
|
1999-02-12 14:18:15 +00:00
|
|
|
// Tell ourselves to
|
1998-12-10 18:07:24 +00:00
|
|
|
[self stopTracking:last_point // stop tracking
|
|
|
|
at:point
|
1999-02-12 14:18:15 +00:00
|
|
|
inView:controlView
|
1998-12-10 18:07:24 +00:00
|
|
|
mouseIsUp:mouseWentUp];
|
|
|
|
|
|
|
|
if (cell_continuous)
|
|
|
|
[NSEvent stopPeriodicEvents];
|
1999-02-12 14:18:15 +00:00
|
|
|
// Return YES only if the mouse
|
1998-12-10 18:07:24 +00:00
|
|
|
// went up within the cell
|
1999-02-12 14:18:15 +00:00
|
|
|
if (mouseWentUp && [controlView mouse: point inRect: cellFrame])
|
1998-12-10 18:07:24 +00:00
|
|
|
{
|
|
|
|
NSDebugLog(@"NSCell mouse went up in cell\n");
|
|
|
|
return YES;
|
|
|
|
}
|
1997-08-05 21:50:10 +00:00
|
|
|
|
1997-10-09 22:55:31 +00:00
|
|
|
#if 1
|
|
|
|
[controlView setNeedsDisplayInRect:cellFrame];
|
|
|
|
#endif
|
|
|
|
|
1998-12-10 18:07:24 +00:00
|
|
|
NSDebugLog(@"NSCell mouse did not go up in cell\n");
|
|
|
|
return NO; // Otherwise return NO
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Managing the Cursor
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-10 18:07:24 +00:00
|
|
|
- (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView
|
|
|
|
{
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-02-12 14:18:15 +00:00
|
|
|
// Comparing to Another NSCell
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
- (NSComparisonResult)compare:(id)otherCell
|
|
|
|
{
|
1998-12-10 18:07:24 +00:00
|
|
|
return 0;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Using the NSCell to Represent an Object
|
|
|
|
//
|
1998-12-10 18:07:24 +00:00
|
|
|
- (id)representedObject { return represented_object; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setRepresentedObject:(id)anObject
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
1998-12-10 18:07:24 +00:00
|
|
|
ASSIGN(represented_object, anObject);
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-04-22 18:23:58 +00:00
|
|
|
- (id)copyWithZone:(NSZone*)zone
|
|
|
|
{
|
1998-12-10 18:07:24 +00:00
|
|
|
NSCell* c = [[isa allocWithZone: zone] init];
|
|
|
|
|
1999-02-10 11:26:41 +00:00
|
|
|
c->contents = [contents copy];
|
|
|
|
ASSIGN(c->cell_image, cell_image);
|
|
|
|
ASSIGN(c->cell_font, cell_font);
|
1998-12-10 18:07:24 +00:00
|
|
|
c->cell_state = cell_state;
|
|
|
|
c->cell_highlighted = cell_highlighted;
|
|
|
|
c->cell_enabled = cell_enabled;
|
|
|
|
c->cell_editable = cell_editable;
|
|
|
|
c->cell_bordered = cell_bordered;
|
|
|
|
c->cell_bezeled = cell_bezeled;
|
|
|
|
c->cell_scrollable = cell_scrollable;
|
|
|
|
c->cell_selectable = cell_selectable;
|
|
|
|
[c setContinuous:cell_continuous];
|
|
|
|
c->cell_float_autorange = cell_float_autorange;
|
|
|
|
c->cell_float_left = cell_float_left;
|
|
|
|
c->cell_float_right = cell_float_right;
|
|
|
|
c->image_position = image_position;
|
|
|
|
c->cell_type = cell_type;
|
|
|
|
c->text_align = text_align;
|
|
|
|
c->entry_type = entry_type;
|
|
|
|
c->control_view = control_view;
|
|
|
|
c->cell_size = cell_size;
|
|
|
|
[c setRepresentedObject:represented_object];
|
1999-02-12 14:18:15 +00:00
|
|
|
|
1998-12-10 18:07:24 +00:00
|
|
|
return c;
|
1997-04-22 18:23:58 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
[aCoder encodeConditionalObject:control_view];
|
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
|
|
|
control_view = [aDecoder decodeObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
1997-10-20 22:01:25 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Methods the backend should implement
|
|
|
|
//
|
|
|
|
@implementation NSCell (GNUstepBackend)
|
|
|
|
|
|
|
|
+ (NSSize)sizeForBorderType:(NSBorderType)aType
|
1999-02-15 12:50:49 +00:00
|
|
|
{
|
|
|
|
// Returns the size of a border
|
|
|
|
switch (aType)
|
|
|
|
{
|
|
|
|
case NSLineBorder:
|
|
|
|
return NSMakeSize(1, 1);
|
|
|
|
case NSGrooveBorder:
|
|
|
|
case NSBezelBorder:
|
|
|
|
return NSMakeSize(2, 2);
|
|
|
|
case NSNoBorder:
|
|
|
|
default:
|
|
|
|
return NSZeroSize;
|
|
|
|
}
|
1997-10-20 22:01:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|