libs-gui/Source/NSBrowserCell.m

378 lines
8.7 KiB
Mathematica
Raw Normal View History

/** <title>NSBrowserCell</title>
<abstract>Cell class for the NSBrowser</abstract>
Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Author: Nicola Pero <n.pero@mi.flashnet.it>
Date: December 1999
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 Lesser 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include <Foundation/NSUserDefaults.h>
#include "AppKit/NSBrowserCell.h"
#include "AppKit/NSColor.h"
#include "AppKit/NSFont.h"
#include "AppKit/NSImage.h"
#include "AppKit/NSGraphics.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSWindow.h"
/*
* Class variables
*/
static NSImage *_branch_image;
static NSImage *_highlight_image;
static Class _colorClass;
// GNUstep user default to have NSBrowserCell in bold if non leaf
static BOOL _gsFontifyCells = NO;
static NSFont *_nonLeafFont;
static NSFont *_leafFont;
* 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
/**<p> TODO Description</p>
*/
@implementation NSBrowserCell
/*
* Class methods
*/
+ (void) initialize
{
if (self == [NSBrowserCell class])
{
[self setVersion: 1];
ASSIGN(_branch_image, [NSImage imageNamed: @"common_3DArrowRight"]);
ASSIGN(_highlight_image, [NSImage imageNamed: @"common_3DArrowRightH"]);
/*
* Cache classes to avoid overheads of poor compiler implementation.
*/
_colorClass = [NSColor class];
// A GNUstep experimental feature
if ([[NSUserDefaults standardUserDefaults]
boolForKey: @"GSBrowserCellFontify"])
{
_gsFontifyCells = YES;
_nonLeafFont = RETAIN ([NSFont boldSystemFontOfSize: 0]);
_leafFont = RETAIN ([NSFont systemFontOfSize: 0]);
}
}
}
/**<p>Returns the default branch image. Currently, it's an arrow. </p>
*<p>See Also: +highlightedBranchImage </p>
*/
+ (NSImage*) branchImage
{
return _branch_image;
}
/**<p>Returns the default hightlited branch image</p>
*<p>See Also: +branchImage</p>
*/
+ (NSImage*) highlightedBranchImage
{
return _highlight_image;
}
/*
* Instance methods
*/
- (id) initTextCell: (NSString *)aString
{
[super initTextCell: aString];
//_alternateImage = nil;
//_browsercell_is_leaf = NO;
//_browsercell_is_loaded = NO;
if (_gsFontifyCells)
[self setFont: _nonLeafFont];
return self;
}
- (id) initImageCell: (NSImage *)anImage
{
[super initImageCell: anImage];
//_alternateImage = nil;
//_browsercell_is_leaf = NO;
//_browsercell_is_loaded = NO;
if (_gsFontifyCells)
[self setFont: _nonLeafFont];
return self;
}
- (void) dealloc
{
TEST_RELEASE (_alternateImage);
[super dealloc];
}
- (id) copyWithZone: (NSZone*)zone
{
NSBrowserCell *c = [super copyWithZone: zone];
TEST_RETAIN (_alternateImage);
//c->_browsercell_is_leaf = _browsercell_is_leaf;
//c->_browsercell_is_loaded = _browsercell_is_loaded;
return c;
}
/**<p>Returns the alternate image in the NSBrowserCell
(used when the cell is highlighted) </p>
<p>See Also: -setAlternateImage:</p>
*/
- (NSImage*) alternateImage
{
return _alternateImage;
}
/**<p>Sets the altenate image (used when the cell is highlighted) to anImage
*</p><p>See Also: -alternateImage</p>
*/
- (void) setAlternateImage: (NSImage *)anImage
{
ASSIGN(_alternateImage, anImage);
}
* configure.in: added /usr/local/include and /usr/local/lib for FreeBSD. Use ADDITIONAL_LIB_DIRS instead of ADDITIONAL_LD_FLAGS. * config.make.in (ADDITIONAL_LIB_DIRS): renamed. * config.guess: new file. * config.sub: new file. * install-sh: new file. * Source/NSSavePanel.m ([NSSavePanel -setDelegate:]): check for -panel: userEnteredFilename:confirmed: ([NSSavePanel -ok:]): call delegate method -panel:userEnteredFilename: confirmed: (MacOS X). Run an alert panel if the filename already exists ([NSSavePanel -browser:selectCellWithString:inColumn:]): removed keyboard handling. * Headers/gnustep/gui/NSSavePanel.h: added ivar. * Source/NSBrowserCell.m ([NSBrowserCell -highlightColorInView:]): return the highlight color of the cell. (Mac OS X) ([NSBrowserCell -drawInteriorWithFrame:inView:]): use highlight color from previous method. * Headers/gnustep/gui/NSBrowserCell.h: added method. * Source/NSMatrix.m ([NSMatrix -_mouseDownNonListMode:]): when tracking the mouse use cell's +prefersTrackingUntilMouseUp ([NSMatrix -_move:]): new private method. Fixed deselection of cells in NSRadioModeMatrix and NSListModeMatrix. ([NSMatrix -moveUp:]): use _move: to reduce maintance. ([NSMatrix -moveDown:]): likewise. ([NSMatrix -moveLeft:]): likewise. ([NSMatrix -moveRight:]): likewise. ([NSMatrix -getRow:column:ofCell:]): if cell does not exist set row and column to -1. ([NSMatrix -mouseDown:]): does not select and highlight a cell at the same time. Ensure that only a cell at a time has the dotted outile. * Source/NSBrowser.m ([NSBrowser -addColumn]): load a column and scroll if necessary. ([NSBrowser -doClick:]): rearranged for the new -addColumn ([NSBrowser -setPath:]): likewise and removed additional redisplay. ([NSBrowser -_createColumn]): method to create a new NSBrowserColumn. ([NSBrowser -setMaxVisibleColumns:]): use _createColumn ([NSBrowser -initWithFrame:]): likewise. ([NSBrowser -doClick:]): fixed selection problems. ([NSBrowser -selectRow:inColumn:]): fixed cell selection and perform load of column if cell is not a leaf. ([NSBrowser -loadColumnZero]): use -addColumn to load column zero. ([NSBrowser -setLastColumn:]): check for min value of column. ([NSBrowser -reloadColumn:]): check with _lastColumnLoaded instead in the column browser. ([NSBrowser -moveLeft:]): fixed an index out of bound exception when it was selected the first column. ([NSBrowser -moveRight:]): does nothing if multiple cells are selected or if the cell is a leaf. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9938 72102866-910b-0410-8b05-ffd578937521
2001-05-13 20:59:21 +00:00
- (NSColor *)highlightColorInView: (NSView *)controlView
{
return [_colorClass selectedControlColor];
}
/**<p>Returns whether the browserCell is a leaf. A leaf cell has usually no
* image. This method is used by NSBrowser in several methods, for example
* to know if a column should be added; when the user selects a browser cell
* (a branch or a leaf)</p>
* <p>See Also: -setLeaf: </p>
*/
- (BOOL) isLeaf
{
return _browsercell_is_leaf;
}
/**<p>Sets whether the cell is a leaf. This method is usally used in the
* NSBrowser's delegate methods</p>
*<p>See Also: -isLeaf</p>
*/
- (void) setLeaf: (BOOL)flag
{
if (_browsercell_is_leaf == flag)
return;
_browsercell_is_leaf = flag;
if (_gsFontifyCells)
{
if (_browsercell_is_leaf)
{
[self setFont: _leafFont];
}
else
{
[self setFont: _nonLeafFont];
}
}
}
/**<p>Returns whether the NSBrowseCell state is set and is ready for
display</p> <p>See Also: -setLoaded:</p>
*/
- (BOOL) isLoaded
{
return _browsercell_is_loaded;
}
/**<p>Sets whether the NSBrowseCell state is set and is ready for display</p>
* <p>See Also: -isLoaded </p>
*/
- (void) setLoaded: (BOOL)flag
{
_browsercell_is_loaded = flag;
}
/**
*<p>Unhighlights the cell and sets the cell's state to NO</p>
*<p>See Also: -set</p>
*/
- (void) reset
{
_cell.is_highlighted = NO;
_cell.state = NO;
}
/**<p>Highlights the cell and sets the cell's state to YES</p>
*<p>See Also: -reset</p>
*/
- (void) set
{
_cell.is_highlighted = YES;
_cell.state = YES;
}
- (void) setType: (NSCellType)aType
{
/* We do nothing here (we match the Mac OS X behavior) because with
* NSBrowserCell GNUstep implementation the cell may contain an image
* and text at the same time.
*/
}
/*
* Displaying
*/
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
NSRect title_rect = cellFrame;
NSImage *branch_image = nil;
NSImage *cell_image = nil;
NSColor *backColor;
NSWindow *cvWin = [controlView window];
if (_cell.is_highlighted || _cell.state)
{
* configure.in: added /usr/local/include and /usr/local/lib for FreeBSD. Use ADDITIONAL_LIB_DIRS instead of ADDITIONAL_LD_FLAGS. * config.make.in (ADDITIONAL_LIB_DIRS): renamed. * config.guess: new file. * config.sub: new file. * install-sh: new file. * Source/NSSavePanel.m ([NSSavePanel -setDelegate:]): check for -panel: userEnteredFilename:confirmed: ([NSSavePanel -ok:]): call delegate method -panel:userEnteredFilename: confirmed: (MacOS X). Run an alert panel if the filename already exists ([NSSavePanel -browser:selectCellWithString:inColumn:]): removed keyboard handling. * Headers/gnustep/gui/NSSavePanel.h: added ivar. * Source/NSBrowserCell.m ([NSBrowserCell -highlightColorInView:]): return the highlight color of the cell. (Mac OS X) ([NSBrowserCell -drawInteriorWithFrame:inView:]): use highlight color from previous method. * Headers/gnustep/gui/NSBrowserCell.h: added method. * Source/NSMatrix.m ([NSMatrix -_mouseDownNonListMode:]): when tracking the mouse use cell's +prefersTrackingUntilMouseUp ([NSMatrix -_move:]): new private method. Fixed deselection of cells in NSRadioModeMatrix and NSListModeMatrix. ([NSMatrix -moveUp:]): use _move: to reduce maintance. ([NSMatrix -moveDown:]): likewise. ([NSMatrix -moveLeft:]): likewise. ([NSMatrix -moveRight:]): likewise. ([NSMatrix -getRow:column:ofCell:]): if cell does not exist set row and column to -1. ([NSMatrix -mouseDown:]): does not select and highlight a cell at the same time. Ensure that only a cell at a time has the dotted outile. * Source/NSBrowser.m ([NSBrowser -addColumn]): load a column and scroll if necessary. ([NSBrowser -doClick:]): rearranged for the new -addColumn ([NSBrowser -setPath:]): likewise and removed additional redisplay. ([NSBrowser -_createColumn]): method to create a new NSBrowserColumn. ([NSBrowser -setMaxVisibleColumns:]): use _createColumn ([NSBrowser -initWithFrame:]): likewise. ([NSBrowser -doClick:]): fixed selection problems. ([NSBrowser -selectRow:inColumn:]): fixed cell selection and perform load of column if cell is not a leaf. ([NSBrowser -loadColumnZero]): use -addColumn to load column zero. ([NSBrowser -setLastColumn:]): check for min value of column. ([NSBrowser -reloadColumn:]): check with _lastColumnLoaded instead in the column browser. ([NSBrowser -moveLeft:]): fixed an index out of bound exception when it was selected the first column. ([NSBrowser -moveRight:]): does nothing if multiple cells are selected or if the cell is a leaf. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9938 72102866-910b-0410-8b05-ffd578937521
2001-05-13 20:59:21 +00:00
backColor = [self highlightColorInView: controlView];
[backColor set];
if (!_browsercell_is_leaf)
branch_image = [isa highlightedBranchImage];
cell_image = [self alternateImage];
}
else
{
backColor = [cvWin backgroundColor];
[backColor set];
if (!_browsercell_is_leaf)
branch_image = [isa branchImage];
cell_image = [self image];
}
// Clear the background
NSRectFill(cellFrame);
// Draw the branch image if there is one
if (branch_image)
{
NSSize size;
NSPoint position;
size = [branch_image size];
position.x = MAX(NSMaxX(title_rect) - size.width - 4.0, 0.);
position.y = MAX(NSMidY(title_rect) - (size.height/2.), 0.);
/*
* Images are always drawn with their bottom-left corner at the origin
* so we must adjust the position to take account of a flipped view.
*/
if ([controlView isFlipped])
position.y += size.height;
[branch_image compositeToPoint: position operation: NSCompositeSourceOver];
title_rect.size.width -= size.width + 8;
}
// Skip 2 points from the left border
title_rect.origin.x += 2;
title_rect.size.width -= 2;
// Draw the cell image if there is one
if (cell_image)
{
NSSize size;
NSPoint position;
size = [cell_image size];
position.x = NSMinX(title_rect);
position.y = MAX(NSMidY(title_rect) - (size.height/2.),0.);
if ([controlView isFlipped])
position.y += size.height;
[cell_image compositeToPoint: position operation: NSCompositeSourceOver];
* Source/NSButtonCell.m ([NSButtonCell -setCellAttribute:to:]): implemented. ([NSButtonCell -cellAttribute:]): implemented. * Source/NSPopUpButton.m ([NSPopUpButton -keyDown:]): implemented keyboard selection. ([NSPopUpButton -resignFirstResponder]): implemented. ([NSPopUpButton -resignKeyWindow]): implemented. * Source/NSPopUpButtonCell.m ([NSPopUpButtonCell -drawInteriorWithFrame:inView:]): from -drawWithFrame:inView: * Source/NSButton.m ([NSButton -becomeFirstResponder]): set cell first responder. ([NSButton -resignFirstResponder]): likewise. ([NSButton -becomeKeyWindow]): likewise. ([NSButton -resignKeyWindow]): likewise. * Source/NSBrowserCell.m ([NSBrowserCell -drawInteriorWithFrame: inView:]): draw correct dotted box. * Source/NSBrowser.m ([NSBrowser -becomeFirstResponder]): make first responder the latest column. ([NSBrowser -acceptsFirstResponder]): accepts first responder status. ([NSBrowser -keyDown:]): handle tabs to select next/previous key view. ([NSBrowser -moveRight:]): make browser column the first responder. ([NSBrowser -moveUp:]): likewise. ([NSBrowser -moveDown:]): likewise. ([NSBrowser -moveLeft:]): likewise. ([NSBrowser -_unloadFromColumn:]): remove columns from superview and array. ([NSBrowser -_remapColumnSubviews:]): set the correct first responder. * Source/NSWindow.m ([NSWindow -sendEvent:]): retain/release first responder for keyUp/keyDown events. Discard NSLeftMouseDown for closed windows. ([NSWindow -dealloc]): release _originalResponder * Source/NSView.m ([NSView -removeSubview:]): remove next responder. * Source/NSCell.m ([NSCell -setUpFieldEditorAttributes:]): clear selected range. ([NSCell -editWithFrame:inView:editor:delegate:event:]): redisplay textObject after invoking mouseDown: ([NSCell -drawInteriorWithFrame:inView:]): draw dotted-line outline when first responder. ([NSCell -setCellAttribute:to:]): implemented. * Source/NSTextView.m ([NSTextView -moveUp:]): don't call _illegalMovement: for the text field editor. ([NSTextView -moveDown:]): likewise. ([NSTextView -moveLeft:]): likewise. ([NSTextView -moveRight:]): likewise. * Source/NSTextField.m ([NSTextField -textDidEndEditing:]): fixed return/tab/backtab text movement code. * Headers/gnustep/gui/NSGraphics.h: added NSDottedFrameRect prototype. * Headers/gnustep/gui/NSMatrix.h: added ivars for dotted frame rect. * Source/NSMatrix.m ([NSMatrix -selectCell:]): implemented. ([NSMatrix -_selectCell:atRow:column:]): new method. ([NSMatrix -selectCellAtRow:column:]): call _selectCell:atRow:column: ([NSMatrix -selectCellWithTag:]): likewise. ([NSMatrix -selectAll:]): Do not select disabled or editable cells. ([NSMatrix -textDidEndEditing:]): fixed return/tab/backtab text movement code. ([NSMatrix -_selectNextSelectableCellAfterRow:column:]): don't select disabled cells. ([NSMatrix -_selectPreviousSelectableCellBeforeRow:column:]): likewise. ([NSMatrix -_privateFrame:mode:numberOfRows:numberOfColumns:]): set dottedRow and dottedColumn. ([NSMatrix -insertRow:withCells:]): likewise. ([NSMatrix -removeColumn:]): likewise. ([NSMatrix -removeRow:]): likewise. ([NSMatrix -mouseDown:]): likewise and discard disabled cells. ([NSMatrix -drawRect:]): set shows cell first responder. ([NSMatrix -becomeFirstResponder]): draw dotted box for cell. ([NSMatrix -resignFirstResponder]): likewise. ([NSMatrix -becomeKeyWindow]): likewise. ([NSMatrix -resignKeyWindow]): likewise. ([NSMatrix -_setNeedsDisplayDottedCell]): likewise. ([NSMatrix -selectTextAtRow:column:]): set shows cell first responder. ([NSMatrix -setState:atRow:column:]): likewise. Deselect previous selected cell in radio mode. * Source/NSSavePanel.m (createRowsForColumn:): use _gsSavePanelCompare: and check extension against _requiredFileType and not "app", "bundle", etc. ([NSString -_gsSavePanelCompare:]): filename compare. ([NSSavePanel -_initWithoutGModel]): set key view for keyboard interaction. ([NSSavePanel -keyDown:]): removed. ([NSSavePanel -controlTextDidEndEditing:]): removed. * Source/NSOpenPanel.m ([NSOpenPanel -_shouldShowExtension:isDir:]): added isDir argument. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@9473 72102866-910b-0410-8b05-ffd578937521
2001-03-22 00:27:37 +00:00
title_rect.origin.x += size.width + 4;
title_rect.size.width -= size.width + 4;
}
// Draw the body of the cell
[self _drawAttributedText: [self attributedStringValue]
inFrame: title_rect];
}
- (BOOL) isOpaque
{
return YES;
}
/*
* NSCoding protocol
*/
- (void) encodeWithCoder: (NSCoder*)aCoder
{
[super encodeWithCoder: aCoder];
if ([aCoder allowsKeyedCoding])
{
// simply encodes prescence...
}
else
{
BOOL tmp;
tmp = _browsercell_is_leaf;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp];
tmp = _browsercell_is_loaded;
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &tmp];
[aCoder encodeObject: _alternateImage];
}
}
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
if ([aDecoder allowsKeyedCoding])
{
// Nothing to decode...
}
else
{
BOOL tmp;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp];
[self setLeaf: tmp];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp];
[self setLoaded: tmp];
[aDecoder decodeValueOfObjCType: @encode(id) at: &_alternateImage];
}
return self;
}
@end