2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSScroller</title>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
1997-08-05 21:50:10 +00:00
|
|
|
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
|
|
|
A completely rewritten version of the original source by Scott Christley.
|
|
|
|
Date: July 1997
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
1998-08-30 16:06:47 +00:00
|
|
|
Date: August 1998
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
1999-03-14 10:58:59 +00:00
|
|
|
Date: Mar 1999 - Use flipped views and make conform to spec
|
1999-02-03 21:53:29 +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
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1996-05-30 20:03:15 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2007-10-29 21:16:17 +00:00
|
|
|
version 3 of the License, or (at your option) any later version.
|
1999-02-03 21:53:29 +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
|
2007-10-29 21:16:17 +00:00
|
|
|
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.
|
1997-08-05 21:50:10 +00:00
|
|
|
*/
|
|
|
|
|
1998-12-09 01:26:37 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
1997-08-05 21:50:10 +00:00
|
|
|
#include <Foundation/NSDate.h>
|
|
|
|
#include <Foundation/NSRunLoop.h>
|
2002-04-11 23:17:42 +00:00
|
|
|
#include <Foundation/NSDebug.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSApplication.h"
|
2007-09-09 12:19:01 +00:00
|
|
|
#include "AppKit/NSButtonCell.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSColor.h"
|
2007-09-09 12:19:01 +00:00
|
|
|
#include "AppKit/NSEvent.h"
|
|
|
|
#include "AppKit/NSImage.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSGraphics.h"
|
2007-09-09 12:19:01 +00:00
|
|
|
#include "AppKit/NSScroller.h"
|
|
|
|
#include "AppKit/NSScrollView.h"
|
|
|
|
#include "AppKit/NSWindow.h"
|
1997-03-05 01:11:17 +00:00
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>TODO Description</p>
|
|
|
|
*/
|
1998-11-25 17:16:48 +00:00
|
|
|
@implementation NSScroller
|
1997-03-05 01:11:17 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* Class variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* button cells used by scroller instances to draw scroller buttons and knob. */
|
|
|
|
static NSButtonCell* upCell = nil;
|
|
|
|
static NSButtonCell* downCell = nil;
|
|
|
|
static NSButtonCell* leftCell = nil;
|
|
|
|
static NSButtonCell* rightCell = nil;
|
1997-08-05 21:50:10 +00:00
|
|
|
static NSButtonCell* knobCell = nil;
|
1997-03-05 01:11:17 +00:00
|
|
|
|
1999-03-16 16:38:26 +00:00
|
|
|
static const float scrollerWidth = 18;
|
2005-03-05 16:08:30 +00:00
|
|
|
static const float buttonsOffset = 2; // buttonsWidth = sw - buttonsOffset
|
1998-11-25 17:16:48 +00:00
|
|
|
|
2000-09-03 19:30:19 +00:00
|
|
|
static NSColor *scrollBarColor = nil;
|
1998-11-25 17:16:48 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* Class methods
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSScroller class])
|
2000-09-03 19:30:19 +00:00
|
|
|
{
|
|
|
|
[self setVersion: 1];
|
|
|
|
ASSIGN (scrollBarColor, [NSColor scrollBarColor]);
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
1998-12-09 01:26:37 +00:00
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>Returns the NSScroller's width. By default 18.</p>
|
|
|
|
<p>Subclasses can override this to provide different scrollbar width. But
|
|
|
|
you may need to also override -drawParts .</p>
|
2005-03-05 16:08:30 +00:00
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
+ (float) scrollerWidth
|
|
|
|
{
|
|
|
|
return scrollerWidth;
|
|
|
|
}
|
1998-12-09 01:26:37 +00:00
|
|
|
|
1999-03-14 10:58:59 +00:00
|
|
|
- (BOOL) isFlipped
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
1999-03-24 11:31:06 +00:00
|
|
|
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2003-05-01 19:50:20 +00:00
|
|
|
- (BOOL) acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/** <p>Returns the position of the NSScroller's arrows used for scrolling
|
|
|
|
By default the arrow position is set to <ref type="type"
|
|
|
|
id="NSScrollArrowPosition">NSScrollerArrowsMinEnd</ref> if the
|
|
|
|
scrolletr is a horizontal scroller and <ref type="type"
|
|
|
|
id="NSScrollArrowPosition">NSScrollerArrowsMaxEnd</ref> if the scroller
|
|
|
|
is a vertical scroller. See <ref type="type" id="NSScrollArrowPosition">
|
|
|
|
NSScrollArrowPosition</ref> for more informations.</p>
|
|
|
|
<p>See Also: -arrowsPosition</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (NSScrollArrowPosition) arrowsPosition
|
|
|
|
{
|
|
|
|
return _arrowsPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUsableScrollerParts) usableParts
|
|
|
|
{
|
|
|
|
return _usableParts;
|
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>Returns a float value ( between 0.0 and 1.0 ) indicating the ratio
|
|
|
|
between the NSScroller length and the knob length</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (float) knobProportion
|
|
|
|
{
|
|
|
|
return _knobProportion;
|
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>Returns the part of the NSScroller that have been hit ( mouse down )
|
|
|
|
See <ref type="type" id="NSScrollerPart">NSScrollerPart</ref> for more
|
|
|
|
information </p><p>See Also: -highlight: [NSResponder-mouseDown:]</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (NSScrollerPart) hitPart
|
|
|
|
{
|
|
|
|
return _hitPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) floatValue
|
|
|
|
{
|
|
|
|
return _floatValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setAction: (SEL)action
|
|
|
|
{
|
|
|
|
_action = action;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SEL) action
|
|
|
|
{
|
|
|
|
return _action;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTarget: (id)target
|
|
|
|
{
|
2001-01-08 01:04:58 +00:00
|
|
|
_target = target;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) target
|
|
|
|
{
|
|
|
|
return _target;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2000-09-04 22:59:23 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
|
|
|
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(unsigned int) at: &_arrowsPosition];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_isEnabled];
|
|
|
|
[aCoder encodeConditionalObject: _target];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
|
|
/* We do not save float value, knob proportion. */
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
|
|
{
|
2000-09-04 22:59:23 +00:00
|
|
|
self = [super initWithCoder: aDecoder];
|
|
|
|
|
2004-01-30 19:49:00 +00:00
|
|
|
if ([aDecoder allowsKeyedCoding])
|
2000-09-04 22:59:23 +00:00
|
|
|
{
|
2004-01-30 19:49:00 +00:00
|
|
|
NSString *action = [aDecoder decodeObjectForKey: @"NSAction"];
|
|
|
|
id target = [aDecoder decodeObjectForKey: @"NSTarget"];
|
|
|
|
float value = 0.0;
|
|
|
|
float percent = 0.0;
|
|
|
|
int flags;
|
2006-05-20 22:12:46 +00:00
|
|
|
|
|
|
|
if (_frame.size.width > _frame.size.height)
|
|
|
|
{
|
|
|
|
_isHorizontal = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isHorizontal = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_isHorizontal)
|
|
|
|
{
|
|
|
|
_floatValue = 0.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_floatValue = 1.0;
|
|
|
|
}
|
|
|
|
|
2004-01-30 19:49:00 +00:00
|
|
|
if (action != nil)
|
|
|
|
{
|
|
|
|
[self setAction: NSSelectorFromString(action)];
|
|
|
|
}
|
|
|
|
[self setTarget: target];
|
|
|
|
|
|
|
|
if ([aDecoder containsValueForKey: @"NSCurValue"])
|
|
|
|
{
|
|
|
|
value = [aDecoder decodeFloatForKey: @"NSCurValue"];
|
|
|
|
}
|
|
|
|
if ([aDecoder containsValueForKey: @"NSPercent"])
|
|
|
|
{
|
|
|
|
percent = [aDecoder decodeFloatForKey: @"NSPercent"];
|
|
|
|
}
|
|
|
|
[self setFloatValue: value knobProportion: percent];
|
|
|
|
|
|
|
|
if ([aDecoder containsValueForKey: @"NSsFlags"])
|
|
|
|
{
|
|
|
|
flags = [aDecoder decodeIntForKey: @"NSsFlags"];
|
2006-05-20 22:12:46 +00:00
|
|
|
// is horiz is set above...
|
|
|
|
|
2004-01-30 19:49:00 +00:00
|
|
|
}
|
2006-05-20 22:12:46 +00:00
|
|
|
|
|
|
|
// setup...
|
|
|
|
_hitPart = NSScrollerNoPart;
|
|
|
|
|
|
|
|
[self drawParts];
|
|
|
|
[self checkSpaceForParts];
|
2000-09-04 22:59:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-30 19:49:00 +00:00
|
|
|
if (_frame.size.width > _frame.size.height)
|
|
|
|
{
|
|
|
|
_isHorizontal = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isHorizontal = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_isHorizontal)
|
|
|
|
{
|
|
|
|
_floatValue = 0.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_floatValue = 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_hitPart = NSScrollerNoPart;
|
|
|
|
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(unsigned int) at: &_arrowsPosition];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_isEnabled];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_target];
|
|
|
|
// Undo RETAIN by decoder
|
|
|
|
TEST_RELEASE(_target);
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
|
|
|
|
|
|
[self drawParts];
|
|
|
|
[self checkSpaceForParts];
|
2000-09-04 22:59:23 +00:00
|
|
|
}
|
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isOpaque
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
|
|
|
{
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* determine the orientation of the scroller and adjust it's size accordingly
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
if (frameRect.size.width > frameRect.size.height)
|
|
|
|
{
|
|
|
|
_isHorizontal = YES;
|
|
|
|
frameRect.size.height = [isa scrollerWidth];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isHorizontal = NO;
|
|
|
|
frameRect.size.width = [isa scrollerWidth];
|
|
|
|
}
|
|
|
|
|
|
|
|
[super initWithFrame: frameRect];
|
|
|
|
|
|
|
|
if (_isHorizontal)
|
1999-03-14 10:58:59 +00:00
|
|
|
{
|
|
|
|
_arrowsPosition = NSScrollerArrowsMinEnd;
|
|
|
|
_floatValue = 0.0;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else
|
1999-03-14 10:58:59 +00:00
|
|
|
{
|
|
|
|
_arrowsPosition = NSScrollerArrowsMaxEnd;
|
|
|
|
_floatValue = 1.0;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
_hitPart = NSScrollerNoPart;
|
|
|
|
[self drawParts];
|
|
|
|
[self setEnabled: NO];
|
|
|
|
[self checkSpaceForParts];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
return [self initWithFrame: NSZeroRect];
|
|
|
|
}
|
|
|
|
|
2005-03-05 16:08:30 +00:00
|
|
|
/**
|
|
|
|
* Cache images for scroll arrows and knob. If you override +scrollerWidth
|
|
|
|
* you may need to override this as well (to provide images for the new
|
|
|
|
* width). However, if you do so, you must currently also override
|
|
|
|
* -drawArrow:highlight: and -drawKnob: .
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) drawParts
|
|
|
|
{
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* Create the class variable button cells if they do not yet exist.
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
if (knobCell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
upCell = [NSButtonCell new];
|
2004-07-07 21:49:08 +00:00
|
|
|
[upCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask];
|
1999-02-03 21:53:29 +00:00
|
|
|
[upCell setImage: [NSImage imageNamed: @"common_ArrowUp"]];
|
2004-07-07 21:49:08 +00:00
|
|
|
[upCell setAlternateImage: [NSImage imageNamed: @"common_ArrowUpH"]];
|
1999-02-03 21:53:29 +00:00
|
|
|
[upCell setImagePosition: NSImageOnly];
|
|
|
|
[upCell setContinuous: YES];
|
2002-03-21 21:47:15 +00:00
|
|
|
[upCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
|
2003-04-13 23:45:39 +00:00
|
|
|
[upCell setPeriodicDelay: 0.3 interval: 0.03];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
downCell = [NSButtonCell new];
|
2004-07-07 21:49:08 +00:00
|
|
|
[downCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask];
|
1999-02-03 21:53:29 +00:00
|
|
|
[downCell setImage: [NSImage imageNamed: @"common_ArrowDown"]];
|
2004-07-07 21:49:08 +00:00
|
|
|
[downCell setAlternateImage: [NSImage imageNamed: @"common_ArrowDownH"]];
|
1999-02-03 21:53:29 +00:00
|
|
|
[downCell setImagePosition: NSImageOnly];
|
|
|
|
[downCell setContinuous: YES];
|
2002-03-21 21:47:15 +00:00
|
|
|
[downCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
|
2003-04-13 23:45:39 +00:00
|
|
|
[downCell setPeriodicDelay: 0.3 interval: 0.03];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
leftCell = [NSButtonCell new];
|
2004-07-07 21:49:08 +00:00
|
|
|
[leftCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask];
|
1999-02-03 21:53:29 +00:00
|
|
|
[leftCell setImage: [NSImage imageNamed: @"common_ArrowLeft"]];
|
2004-07-07 21:49:08 +00:00
|
|
|
[leftCell setAlternateImage: [NSImage imageNamed: @"common_ArrowLeftH"]];
|
1999-02-03 21:53:29 +00:00
|
|
|
[leftCell setImagePosition: NSImageOnly];
|
|
|
|
[leftCell setContinuous: YES];
|
2002-03-21 21:47:15 +00:00
|
|
|
[leftCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
|
2003-04-13 23:45:39 +00:00
|
|
|
[leftCell setPeriodicDelay: 0.3 interval: 0.03];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
rightCell = [NSButtonCell new];
|
2004-07-07 21:49:08 +00:00
|
|
|
[rightCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask];
|
1999-02-03 21:53:29 +00:00
|
|
|
[rightCell setImage: [NSImage imageNamed: @"common_ArrowRight"]];
|
2004-07-07 21:49:08 +00:00
|
|
|
[rightCell setAlternateImage: [NSImage imageNamed: @"common_ArrowRightH"]];
|
1999-02-03 21:53:29 +00:00
|
|
|
[rightCell setImagePosition: NSImageOnly];
|
|
|
|
[rightCell setContinuous: YES];
|
2002-03-21 21:47:15 +00:00
|
|
|
[rightCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)];
|
2003-04-13 23:45:39 +00:00
|
|
|
[rightCell setPeriodicDelay: 0.3 interval: 0.03];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
knobCell = [NSButtonCell new];
|
|
|
|
[knobCell setButtonType: NSMomentaryChangeButton];
|
|
|
|
[knobCell setImage: [NSImage imageNamed: @"common_Dimple"]];
|
|
|
|
[knobCell setImagePosition: NSImageOnly];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setTargetAndActionToCells
|
|
|
|
{
|
|
|
|
[upCell setTarget: _target];
|
|
|
|
[upCell setAction: _action];
|
|
|
|
|
|
|
|
[downCell setTarget: _target];
|
|
|
|
[downCell setAction: _action];
|
|
|
|
|
|
|
|
[leftCell setTarget: _target];
|
|
|
|
[leftCell setAction: _action];
|
|
|
|
|
|
|
|
[rightCell setTarget: _target];
|
|
|
|
[rightCell setAction: _action];
|
|
|
|
|
|
|
|
[knobCell setTarget: _target];
|
|
|
|
[knobCell setAction: _action];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) checkSpaceForParts
|
|
|
|
{
|
2000-01-10 02:14:02 +00:00
|
|
|
NSSize frameSize = _frame.size;
|
1999-03-14 10:58:59 +00:00
|
|
|
float size = (_isHorizontal ? frameSize.width : frameSize.height);
|
2005-03-05 16:08:30 +00:00
|
|
|
int buttonsWidth = [isa scrollerWidth] - buttonsOffset;
|
1999-02-03 21:53:29 +00:00
|
|
|
|
1999-03-14 10:58:59 +00:00
|
|
|
if (_arrowsPosition == NSScrollerArrowsNone)
|
|
|
|
{
|
2003-02-10 14:29:31 +00:00
|
|
|
if (size >= buttonsWidth + 3)
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
_usableParts = NSAllScrollerParts;
|
|
|
|
}
|
1999-03-14 10:58:59 +00:00
|
|
|
else
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
_usableParts = NSNoScrollerParts;
|
|
|
|
}
|
1999-03-14 10:58:59 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else
|
1999-03-14 10:58:59 +00:00
|
|
|
{
|
2003-02-10 14:29:31 +00:00
|
|
|
if (size >= 4 /* spacing */ + 1 /* min. scroll area */ + buttonsWidth * 3)
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
_usableParts = NSAllScrollerParts;
|
|
|
|
}
|
2003-02-10 14:29:31 +00:00
|
|
|
else if (size >= 3 /* spacing */ + buttonsWidth * 2)
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
_usableParts = NSOnlyScrollerArrows;
|
|
|
|
}
|
1999-03-14 10:58:59 +00:00
|
|
|
else
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
_usableParts = NSNoScrollerParts;
|
|
|
|
}
|
1999-03-14 10:58:59 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setEnabled: (BOOL)flag
|
|
|
|
{
|
|
|
|
if (_isEnabled == flag)
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2004-06-28 13:21:06 +00:00
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
_isEnabled = flag;
|
2000-09-03 19:30:19 +00:00
|
|
|
_cacheValid = NO;
|
1999-02-03 21:53:29 +00:00
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/** <p>Sets the position of the NSScroller arrows used for scrolling to
|
|
|
|
<var>where</var> and marks self for display. By default the arrow position
|
|
|
|
is set to <ref type="type" id="NSScrollArrowPosition">
|
|
|
|
NSScrollerArrowsMinEnd</ref> if the scroller is a horizontal scroller
|
|
|
|
and <ref type="type" id="NSScrollArrowPosition">NSScrollerArrowsMaxEnd
|
|
|
|
</ref> if the scroller is a vertical scroller. See <ref type="type"
|
|
|
|
id="NSScrollArrowPosition">NSScrollArrowPosition</ref> for more
|
|
|
|
informations.</p><p>See Also: -arrowsPosition</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) setArrowsPosition: (NSScrollArrowPosition)where
|
|
|
|
{
|
|
|
|
if (_arrowsPosition == where)
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
_arrowsPosition = where;
|
2000-09-03 19:30:19 +00:00
|
|
|
_cacheValid = NO;
|
1999-02-03 21:53:29 +00:00
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFloatValue: (float)aFloat
|
|
|
|
{
|
2002-02-25 17:39:11 +00:00
|
|
|
if (_floatValue == aFloat)
|
|
|
|
{
|
|
|
|
/* Most likely our trackKnob method initiated this via NSScrollView */
|
|
|
|
return;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
if (aFloat < 0)
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
|
|
|
_floatValue = 0;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else if (aFloat > 1)
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
|
|
|
_floatValue = 1;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
|
|
|
_floatValue = aFloat;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
[self setNeedsDisplayInRect: [self rectForPart: NSScrollerKnobSlot]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFloatValue: (float)aFloat knobProportion: (float)ratio
|
|
|
|
{
|
2002-02-25 17:39:11 +00:00
|
|
|
if (_floatValue == aFloat && _knobProportion == ratio)
|
|
|
|
{
|
|
|
|
/* Most likely our trackKnob method initiated this via NSScrollView */
|
|
|
|
return;
|
|
|
|
}
|
2004-06-28 13:21:06 +00:00
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
if (ratio < 0)
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
2004-06-28 13:21:06 +00:00
|
|
|
_pendingKnobProportion = 0;
|
2001-01-21 14:55:07 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else if (ratio > 1)
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
2004-06-28 13:21:06 +00:00
|
|
|
_pendingKnobProportion = 1;
|
2001-01-21 14:55:07 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
2004-06-28 13:21:06 +00:00
|
|
|
_pendingKnobProportion = ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_hitPart == NSScrollerNoPart)
|
|
|
|
{
|
|
|
|
_knobProportion = _pendingKnobProportion;
|
|
|
|
_pendingKnobProportion = 0;
|
2001-01-21 14:55:07 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2004-06-28 13:21:06 +00:00
|
|
|
// Handle the case when parts should disappear
|
|
|
|
if (_knobProportion == 1)
|
|
|
|
{
|
|
|
|
[self setEnabled: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setEnabled: YES];
|
|
|
|
}
|
2002-04-09 23:39:21 +00:00
|
|
|
|
2004-06-28 13:21:06 +00:00
|
|
|
// Don't set float value if knob is being dragged
|
|
|
|
if (_hitPart != NSScrollerKnobSlot && _hitPart != NSScrollerKnob)
|
|
|
|
{
|
|
|
|
/* Make sure we mark ourselves as needing redisplay. */
|
|
|
|
_floatValue = -1;
|
|
|
|
|
|
|
|
[self setFloatValue: aFloat];
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFrame: (NSRect)frameRect
|
|
|
|
{
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* determine the orientation of the scroller and adjust it's size accordingly
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
if (frameRect.size.width > frameRect.size.height)
|
|
|
|
{
|
|
|
|
_isHorizontal = YES;
|
|
|
|
frameRect.size.height = [isa scrollerWidth];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_isHorizontal = NO;
|
|
|
|
frameRect.size.width = [isa scrollerWidth];
|
|
|
|
}
|
|
|
|
|
|
|
|
[super setFrame: frameRect];
|
|
|
|
|
2002-06-06 09:40:56 +00:00
|
|
|
if (_arrowsPosition != NSScrollerArrowsNone)
|
2002-06-06 09:38:11 +00:00
|
|
|
{
|
2002-06-06 09:40:56 +00:00
|
|
|
if (_isHorizontal)
|
|
|
|
{
|
|
|
|
_arrowsPosition = NSScrollerArrowsMinEnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_arrowsPosition = NSScrollerArrowsMaxEnd;
|
|
|
|
}
|
2002-06-06 09:38:11 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
|
|
|
_hitPart = NSScrollerNoPart;
|
2000-09-03 19:30:19 +00:00
|
|
|
_cacheValid = NO;
|
1999-02-03 21:53:29 +00:00
|
|
|
[self checkSpaceForParts];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFrameSize: (NSSize)size
|
|
|
|
{
|
|
|
|
[super setFrameSize: size];
|
|
|
|
[self checkSpaceForParts];
|
2000-09-03 19:30:19 +00:00
|
|
|
_cacheValid = NO;
|
1999-02-03 21:53:29 +00:00
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>Returns the NSScroller's part under the point <var>thePoint</var>.
|
|
|
|
See <ref type="type" id="NSScrollerPart">NSScrollerPart</ref> for more
|
|
|
|
informations</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (NSScrollerPart)testPart: (NSPoint)thePoint
|
|
|
|
{
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* return what part of the scroller the mouse hit
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
NSRect rect;
|
|
|
|
|
2003-01-27 02:54:00 +00:00
|
|
|
/* thePoint is in window's coordinate system; convert it to
|
|
|
|
* our own coordinate system. */
|
|
|
|
thePoint = [self convertPoint: thePoint fromView: nil];
|
|
|
|
|
2000-01-10 02:14:02 +00:00
|
|
|
if (thePoint.x <= 0 || thePoint.x >= _frame.size.width
|
|
|
|
|| thePoint.y <= 0 || thePoint.y >= _frame.size.height)
|
1999-02-03 21:53:29 +00:00
|
|
|
return NSScrollerNoPart;
|
|
|
|
|
|
|
|
rect = [self rectForPart: NSScrollerDecrementLine];
|
|
|
|
if ([self mouse: thePoint inRect: rect])
|
|
|
|
return NSScrollerDecrementLine;
|
|
|
|
|
|
|
|
rect = [self rectForPart: NSScrollerIncrementLine];
|
|
|
|
if ([self mouse: thePoint inRect: rect])
|
|
|
|
return NSScrollerIncrementLine;
|
|
|
|
|
|
|
|
rect = [self rectForPart: NSScrollerKnob];
|
|
|
|
if ([self mouse: thePoint inRect: rect])
|
|
|
|
return NSScrollerKnob;
|
|
|
|
|
|
|
|
rect = [self rectForPart: NSScrollerDecrementPage];
|
|
|
|
if ([self mouse: thePoint inRect: rect])
|
|
|
|
return NSScrollerDecrementPage;
|
|
|
|
|
|
|
|
rect = [self rectForPart: NSScrollerIncrementPage];
|
|
|
|
if ([self mouse: thePoint inRect: rect])
|
|
|
|
return NSScrollerIncrementPage;
|
|
|
|
|
1999-03-14 10:58:59 +00:00
|
|
|
rect = [self rectForPart: NSScrollerKnobSlot];
|
|
|
|
if ([self mouse: thePoint inRect: rect])
|
|
|
|
return NSScrollerKnobSlot;
|
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
return NSScrollerNoPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (float) _floatValueForMousePoint: (NSPoint)point
|
|
|
|
{
|
|
|
|
NSRect knobRect = [self rectForPart: NSScrollerKnob];
|
|
|
|
NSRect slotRect = [self rectForPart: NSScrollerKnobSlot];
|
|
|
|
float position;
|
1999-09-09 02:56:20 +00:00
|
|
|
float min_pos;
|
|
|
|
float max_pos;
|
1999-02-03 21:53:29 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
1999-09-09 02:56:20 +00:00
|
|
|
* Compute limits and mouse position
|
1999-06-06 08:19:19 +00:00
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
if (_isHorizontal)
|
|
|
|
{
|
1999-09-09 02:56:20 +00:00
|
|
|
min_pos = NSMinX(slotRect) + NSWidth(knobRect) / 2;
|
|
|
|
max_pos = NSMaxX(slotRect) - NSWidth(knobRect) / 2;
|
|
|
|
position = point.x;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-09-09 02:56:20 +00:00
|
|
|
min_pos = NSMinY(slotRect) + NSHeight(knobRect) / 2;
|
|
|
|
max_pos = NSMaxY(slotRect) - NSHeight(knobRect) / 2;
|
|
|
|
position = point.y;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
|
1999-09-09 02:56:20 +00:00
|
|
|
/*
|
|
|
|
* Compute float value
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
|
1999-09-09 02:56:20 +00:00
|
|
|
if (position <= min_pos)
|
|
|
|
return 0;
|
|
|
|
if (position >= max_pos)
|
|
|
|
return 1;
|
|
|
|
return (position - min_pos) / (max_pos - min_pos);
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
1998-11-25 17:16:48 +00:00
|
|
|
|
1997-03-05 01:11:17 +00:00
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
1997-03-05 01:11:17 +00:00
|
|
|
{
|
2003-01-27 02:54:00 +00:00
|
|
|
NSPoint location = [theEvent locationInWindow];
|
1999-02-03 21:53:29 +00:00
|
|
|
_hitPart = [self testPart: location];
|
|
|
|
[self _setTargetAndActionToCells];
|
|
|
|
|
|
|
|
switch (_hitPart)
|
|
|
|
{
|
|
|
|
case NSScrollerIncrementLine:
|
|
|
|
case NSScrollerDecrementLine:
|
|
|
|
case NSScrollerIncrementPage:
|
|
|
|
case NSScrollerDecrementPage:
|
|
|
|
[self trackScrollButtons: theEvent];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerKnob:
|
|
|
|
[self trackKnob: theEvent];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerKnobSlot:
|
|
|
|
{
|
2003-01-27 02:54:00 +00:00
|
|
|
float floatValue = [self _floatValueForMousePoint:
|
|
|
|
[self convertPoint: location
|
|
|
|
fromView: nil]];
|
2003-01-27 03:06:34 +00:00
|
|
|
if (floatValue != _floatValue)
|
|
|
|
{
|
|
|
|
[self setFloatValue: floatValue];
|
|
|
|
[self sendAction: _action to: _target];
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
[self trackKnob: theEvent];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NSScrollerNoPart:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_hitPart = NSScrollerNoPart;
|
2004-06-28 13:21:06 +00:00
|
|
|
if (_pendingKnobProportion)
|
|
|
|
{
|
|
|
|
[self setFloatValue: _floatValue knobProportion: _pendingKnobProportion];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
1998-11-25 17:16:48 +00:00
|
|
|
|
1999-02-05 06:44:40 +00:00
|
|
|
- (void) trackKnob: (NSEvent*)theEvent
|
1999-02-03 21:53:29 +00:00
|
|
|
{
|
|
|
|
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
|
2003-04-13 23:45:39 +00:00
|
|
|
| NSLeftMouseDraggedMask | NSFlagsChangedMask;
|
1999-06-06 08:19:19 +00:00
|
|
|
NSPoint point;
|
1999-09-09 02:56:20 +00:00
|
|
|
float lastPosition;
|
|
|
|
float newPosition;
|
1999-06-06 08:19:19 +00:00
|
|
|
float floatValue;
|
1999-09-09 02:56:20 +00:00
|
|
|
float offset;
|
2003-04-13 23:45:39 +00:00
|
|
|
float initialOffset;
|
2004-01-07 13:25:29 +00:00
|
|
|
NSEvent *presentEvent = theEvent;
|
2003-04-13 23:45:39 +00:00
|
|
|
NSEventType eventType = [theEvent type];
|
1999-09-09 02:56:20 +00:00
|
|
|
NSRect knobRect;
|
1999-06-06 08:19:19 +00:00
|
|
|
unsigned flags = [theEvent modifierFlags];
|
1999-02-19 20:19:58 +00:00
|
|
|
|
1999-02-05 06:44:40 +00:00
|
|
|
knobRect = [self rectForPart: NSScrollerKnob];
|
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
point = [self convertPoint: [theEvent locationInWindow] fromView: nil];
|
1999-09-09 02:56:20 +00:00
|
|
|
if (_isHorizontal)
|
1999-02-05 06:44:40 +00:00
|
|
|
{
|
1999-09-09 02:56:20 +00:00
|
|
|
lastPosition = NSMidX(knobRect);
|
|
|
|
offset = lastPosition - point.x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastPosition = NSMidY(knobRect);
|
|
|
|
offset = lastPosition - point.y;
|
1999-02-05 06:44:40 +00:00
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
initialOffset = offset; /* Save the initial offset value */
|
1999-02-03 21:53:29 +00:00
|
|
|
_hitPart = NSScrollerKnob;
|
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
do
|
1999-02-03 21:53:29 +00:00
|
|
|
{
|
2003-04-13 23:45:39 +00:00
|
|
|
/* Inner loop that gets and (quickly) handles all events that have
|
|
|
|
already arrived. */
|
|
|
|
while (theEvent && eventType != NSLeftMouseUp)
|
|
|
|
{
|
|
|
|
/* Note the event here. Don't do any expensive handling. */
|
|
|
|
if (eventType == NSFlagsChanged)
|
|
|
|
flags = [theEvent modifierFlags];
|
|
|
|
presentEvent = theEvent;
|
|
|
|
|
|
|
|
theEvent = [NSApp nextEventMatchingMask: eventMask
|
|
|
|
untilDate: [NSDate distantPast] /* Only get events that have already arrived. */
|
|
|
|
inMode: NSEventTrackingRunLoopMode
|
|
|
|
dequeue: YES];
|
|
|
|
eventType = [theEvent type];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No more events right now. Do expensive handling, like drawing,
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
point = [self convertPoint: [presentEvent locationInWindow]
|
|
|
|
fromView: nil];
|
|
|
|
|
|
|
|
if (_isHorizontal)
|
|
|
|
newPosition = point.x + offset;
|
|
|
|
else
|
|
|
|
newPosition = point.y + offset;
|
|
|
|
|
|
|
|
if (newPosition != lastPosition)
|
|
|
|
{
|
|
|
|
if (flags & NSAlternateKeyMask)
|
|
|
|
{
|
|
|
|
float diff;
|
|
|
|
|
|
|
|
diff = newPosition - lastPosition;
|
|
|
|
diff = diff * 3 / 4;
|
|
|
|
offset -= diff;
|
|
|
|
newPosition -= diff;
|
|
|
|
}
|
|
|
|
else /* Ok, we are no longer doing slow scrolling, lets go back
|
|
|
|
to our original offset. */
|
|
|
|
{
|
|
|
|
offset = initialOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only one coordinate (X or Y) is used to compute floatValue.
|
|
|
|
point = NSMakePoint(newPosition, newPosition);
|
|
|
|
floatValue = [self _floatValueForMousePoint: point];
|
|
|
|
|
|
|
|
if (floatValue != _floatValue)
|
|
|
|
{
|
|
|
|
[self setFloatValue: floatValue];
|
|
|
|
[self sendAction: _action to: _target];
|
|
|
|
}
|
2003-01-27 03:06:34 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
lastPosition = newPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If our current event is actually the mouse up (perhaps the inner
|
|
|
|
* loop got to this point) we want to update with the last info and
|
|
|
|
* then quit.
|
|
|
|
*/
|
|
|
|
if (eventType == NSLeftMouseUp)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Get the next event, blocking if necessary. */
|
|
|
|
theEvent = [NSApp nextEventMatchingMask: eventMask
|
|
|
|
untilDate: nil /* No limit, block until we get an event. */
|
|
|
|
inMode: NSEventTrackingRunLoopMode
|
|
|
|
dequeue: YES];
|
|
|
|
eventType = [theEvent type];
|
|
|
|
} while (eventType != NSLeftMouseUp);
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
1998-11-25 17:16:48 +00:00
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) trackScrollButtons: (NSEvent*)theEvent
|
|
|
|
{
|
1999-06-06 08:19:19 +00:00
|
|
|
id theCell = nil;
|
|
|
|
NSRect rect;
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-02-01 05:10:00 +00:00
|
|
|
[self lockFocus];
|
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
NSDebugLog (@"trackScrollButtons");
|
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
_hitPart = [self testPart: [theEvent locationInWindow]];
|
|
|
|
rect = [self rectForPart: _hitPart];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
/*
|
|
|
|
* A hit on a scroller button should be a page movement
|
|
|
|
* if the alt key is pressed.
|
|
|
|
*/
|
|
|
|
switch (_hitPart)
|
|
|
|
{
|
|
|
|
case NSScrollerIncrementLine:
|
|
|
|
if ([theEvent modifierFlags] & NSAlternateKeyMask)
|
|
|
|
{
|
|
|
|
_hitPart = NSScrollerIncrementPage;
|
|
|
|
}
|
|
|
|
/* Fall through to next case */
|
|
|
|
case NSScrollerIncrementPage:
|
|
|
|
theCell = (_isHorizontal ? rightCell : downCell);
|
|
|
|
break;
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
case NSScrollerDecrementLine:
|
|
|
|
if ([theEvent modifierFlags] & NSAlternateKeyMask)
|
|
|
|
{
|
|
|
|
_hitPart = NSScrollerDecrementPage;
|
|
|
|
}
|
|
|
|
/* Fall through to next case */
|
|
|
|
case NSScrollerDecrementPage:
|
|
|
|
theCell = (_isHorizontal ? leftCell : upCell);
|
|
|
|
break;
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
default:
|
|
|
|
theCell = nil;
|
|
|
|
break;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
/*
|
|
|
|
* If we don't find a cell this has been all for naught, but we
|
|
|
|
* shouldn't ever be in that situation.
|
|
|
|
*/
|
|
|
|
if (theCell)
|
|
|
|
{
|
|
|
|
[theCell highlight: YES withFrame: rect inView: self];
|
|
|
|
[_window flushWindow];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
NSDebugLog (@"tracking cell %x", theCell);
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
/*
|
|
|
|
* The "tracking" in this method actually takes place within
|
|
|
|
* NSCell's trackMouse: method.
|
|
|
|
*/
|
|
|
|
[theCell trackMouse: theEvent
|
|
|
|
inRect: rect
|
|
|
|
ofView: self
|
|
|
|
untilMouseUp: YES];
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2003-04-13 23:45:39 +00:00
|
|
|
[theCell highlight: NO withFrame: rect inView: self];
|
|
|
|
[_window flushWindow];
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
2003-02-01 05:10:00 +00:00
|
|
|
[self unlockFocus];
|
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
NSDebugLog (@"return from trackScrollButtons");
|
|
|
|
}
|
1998-10-19 06:10:49 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* draw the scroller
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) drawRect: (NSRect)rect
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
2000-09-03 19:30:19 +00:00
|
|
|
static NSRect rectForPartIncrementLine;
|
|
|
|
static NSRect rectForPartDecrementLine;
|
|
|
|
static NSRect rectForPartKnobSlot;
|
2004-06-28 13:21:06 +00:00
|
|
|
|
2000-09-03 19:30:19 +00:00
|
|
|
if (_cacheValid == NO)
|
|
|
|
{
|
|
|
|
rectForPartIncrementLine = [self rectForPart: NSScrollerIncrementLine];
|
|
|
|
rectForPartDecrementLine = [self rectForPart: NSScrollerDecrementLine];
|
|
|
|
rectForPartKnobSlot = [self rectForPart: NSScrollerKnobSlot];
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
2000-01-10 02:14:02 +00:00
|
|
|
[[_window backgroundColor] set];
|
2000-09-03 19:30:19 +00:00
|
|
|
NSRectFill (rect);
|
1999-12-16 03:15:41 +00:00
|
|
|
|
2000-09-03 19:30:19 +00:00
|
|
|
if (NSIntersectsRect (rect, rectForPartKnobSlot) == YES)
|
|
|
|
{
|
|
|
|
[self drawKnobSlot];
|
|
|
|
[self drawKnob];
|
|
|
|
}
|
1999-03-14 18:10:42 +00:00
|
|
|
|
2000-09-03 19:30:19 +00:00
|
|
|
if (NSIntersectsRect (rect, rectForPartDecrementLine) == YES)
|
|
|
|
{
|
|
|
|
[self drawArrow: NSScrollerDecrementArrow highlight: NO];
|
|
|
|
}
|
|
|
|
if (NSIntersectsRect (rect, rectForPartIncrementLine) == YES)
|
|
|
|
{
|
|
|
|
[self drawArrow: NSScrollerIncrementArrow highlight: NO];
|
|
|
|
}
|
1997-03-05 01:11:17 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>(Un)Highlight the button specified by <var>whichButton</var>.
|
|
|
|
<var>whichButton</var> should be <ref type="type" id="NSScrollerArrow">
|
|
|
|
NSScrollerDecrementArrow</ref> or <ref type="type" id="NSScrollerArrow">
|
|
|
|
NSScrollerIncrementArrow</ref></p>
|
|
|
|
<p>See Also: [NSCell-setHighlighted:] [NSCell-drawWithFrame:inView:]</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) drawArrow: (NSScrollerArrow)whichButton highlight: (BOOL)flag
|
1997-03-05 01:11:17 +00:00
|
|
|
{
|
1999-02-03 21:53:29 +00:00
|
|
|
NSRect rect = [self rectForPart: (whichButton == NSScrollerIncrementArrow
|
|
|
|
? NSScrollerIncrementLine : NSScrollerDecrementLine)];
|
|
|
|
id theCell = nil;
|
|
|
|
|
2002-11-12 21:31:11 +00:00
|
|
|
NSDebugLLog (@"NSScroller", @"position of %s cell is (%f, %f)",
|
1999-02-03 21:53:29 +00:00
|
|
|
(whichButton == NSScrollerIncrementArrow ? "increment" : "decrement"),
|
|
|
|
rect.origin.x, rect.origin.y);
|
|
|
|
|
|
|
|
switch (whichButton)
|
|
|
|
{
|
|
|
|
case NSScrollerDecrementArrow:
|
1999-03-14 10:58:59 +00:00
|
|
|
theCell = (_isHorizontal ? leftCell : upCell);
|
1999-02-03 21:53:29 +00:00
|
|
|
break;
|
|
|
|
case NSScrollerIncrementArrow:
|
1999-03-14 10:58:59 +00:00
|
|
|
theCell = (_isHorizontal ? rightCell : downCell);
|
1999-02-03 21:53:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-01-27 02:54:00 +00:00
|
|
|
[theCell setHighlighted: flag];
|
|
|
|
[theCell drawWithFrame: rect inView: self];
|
1997-03-05 01:11:17 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>Draws the knob</p>
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) drawKnob
|
1997-03-05 01:11:17 +00:00
|
|
|
{
|
1999-02-03 21:53:29 +00:00
|
|
|
[knobCell drawWithFrame: [self rectForPart: NSScrollerKnob] inView: self];
|
1997-03-05 01:11:17 +00:00
|
|
|
}
|
|
|
|
|
1999-02-03 21:53:29 +00:00
|
|
|
- (void) drawKnobSlot
|
1997-03-05 01:11:17 +00:00
|
|
|
{
|
2000-09-03 19:30:19 +00:00
|
|
|
static NSRect rect;
|
1998-11-25 17:16:48 +00:00
|
|
|
|
2000-09-03 19:30:19 +00:00
|
|
|
if (_cacheValid == NO)
|
|
|
|
{
|
|
|
|
rect = [self rectForPart: NSScrollerKnobSlot];
|
|
|
|
}
|
1998-11-25 17:16:48 +00:00
|
|
|
|
2004-06-28 13:21:06 +00:00
|
|
|
[scrollBarColor set];
|
2000-09-03 19:30:19 +00:00
|
|
|
NSRectFill (rect);
|
1997-03-05 01:11:17 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**<p>Highlights the button whose under the mouse. Does nothing if the mouse
|
|
|
|
is not under a button</p><p>See Also: -drawArrow:highlight:</p>
|
|
|
|
*/
|
1999-03-14 10:58:59 +00:00
|
|
|
- (void) highlight: (BOOL)flag
|
|
|
|
{
|
|
|
|
switch (_hitPart)
|
|
|
|
{
|
|
|
|
case NSScrollerIncrementLine:
|
|
|
|
case NSScrollerIncrementPage:
|
|
|
|
[self drawArrow: NSScrollerIncrementArrow highlight: flag];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerDecrementLine:
|
|
|
|
case NSScrollerDecrementPage:
|
|
|
|
[self drawArrow: NSScrollerDecrementArrow highlight: flag];
|
|
|
|
break;
|
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
default: /* No button currently hit for highlighting. */
|
1999-03-14 10:58:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-24 15:57:01 +00:00
|
|
|
/**
|
|
|
|
*/
|
1999-02-05 06:44:40 +00:00
|
|
|
- (NSRect) rectForPart: (NSScrollerPart)partCode
|
1998-09-08 14:56:29 +00:00
|
|
|
{
|
2000-01-10 02:14:02 +00:00
|
|
|
NSRect scrollerFrame = _frame;
|
1999-03-16 16:38:26 +00:00
|
|
|
float x = 1, y = 1;
|
1999-03-14 10:58:59 +00:00
|
|
|
float width, height;
|
2005-03-05 16:08:30 +00:00
|
|
|
float buttonsWidth = ([isa scrollerWidth] - buttonsOffset);
|
1999-03-16 16:38:26 +00:00
|
|
|
float buttonsSize = 2 * buttonsWidth + 2;
|
1999-02-03 21:53:29 +00:00
|
|
|
NSUsableScrollerParts usableParts;
|
2003-02-10 14:29:31 +00:00
|
|
|
/*
|
1999-06-06 08:19:19 +00:00
|
|
|
* If the scroller is disabled then the scroller buttons and the
|
|
|
|
* knob are not displayed at all.
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
if (!_isEnabled)
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
|
|
|
usableParts = NSNoScrollerParts;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else
|
2001-01-21 14:55:07 +00:00
|
|
|
{
|
|
|
|
usableParts = _usableParts;
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* Assign to `width' and `height' values describing
|
|
|
|
* the width and height of the scroller regardless
|
|
|
|
* of its orientation.
|
|
|
|
* but keeps track of the scroller's orientation.
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
if (_isHorizontal)
|
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
width = scrollerFrame.size.height - 2;
|
|
|
|
height = scrollerFrame.size.width - 2;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
width = scrollerFrame.size.width - 2;
|
|
|
|
height = scrollerFrame.size.height - 2;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
1999-03-14 10:58:59 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* The x, y, width and height values are computed below for the vertical
|
|
|
|
* scroller. The height of the scroll buttons is assumed to be equal to
|
|
|
|
* the width.
|
|
|
|
*/
|
1999-02-03 21:53:29 +00:00
|
|
|
switch (partCode)
|
|
|
|
{
|
|
|
|
case NSScrollerKnob:
|
|
|
|
{
|
|
|
|
float knobHeight, knobPosition, slotHeight;
|
1999-06-06 08:19:19 +00:00
|
|
|
|
|
|
|
if (usableParts == NSNoScrollerParts
|
|
|
|
|| usableParts == NSOnlyScrollerArrows)
|
2004-06-28 13:21:06 +00:00
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
1999-06-06 08:19:19 +00:00
|
|
|
|
|
|
|
/* calc the slot Height */
|
|
|
|
slotHeight = height - (_arrowsPosition == NSScrollerArrowsNone
|
2002-06-06 09:38:11 +00:00
|
|
|
? 0 : buttonsSize);
|
1999-02-03 21:53:29 +00:00
|
|
|
knobHeight = _knobProportion * slotHeight;
|
1999-09-09 02:56:20 +00:00
|
|
|
knobHeight = (float)floor(knobHeight);
|
1999-02-03 21:53:29 +00:00
|
|
|
if (knobHeight < buttonsWidth)
|
|
|
|
knobHeight = buttonsWidth;
|
1999-06-06 08:19:19 +00:00
|
|
|
|
|
|
|
/* calc knob's position */
|
1999-03-14 10:58:59 +00:00
|
|
|
knobPosition = _floatValue * (slotHeight - knobHeight);
|
2004-07-19 23:28:33 +00:00
|
|
|
knobPosition = floor(knobPosition);
|
2004-06-28 13:21:06 +00:00
|
|
|
|
1999-06-06 08:19:19 +00:00
|
|
|
|
|
|
|
/* calc actual position */
|
2004-06-28 13:21:06 +00:00
|
|
|
y += knobPosition + ((_arrowsPosition == NSScrollerArrowsMaxEnd
|
|
|
|
|| _arrowsPosition == NSScrollerArrowsNone)
|
2002-06-06 09:38:11 +00:00
|
|
|
? 0 : buttonsSize);
|
1999-02-03 21:53:29 +00:00
|
|
|
height = knobHeight;
|
|
|
|
width = buttonsWidth;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case NSScrollerKnobSlot:
|
1999-06-06 08:19:19 +00:00
|
|
|
/*
|
|
|
|
* if the scroller does not have buttons the slot completely
|
|
|
|
* fills the scroller.
|
|
|
|
*/
|
1999-03-16 16:38:26 +00:00
|
|
|
if (usableParts == NSNoScrollerParts
|
|
|
|
|| _arrowsPosition == NSScrollerArrowsNone)
|
1999-02-03 21:53:29 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
1999-03-16 16:38:26 +00:00
|
|
|
height -= buttonsSize;
|
|
|
|
if (_arrowsPosition == NSScrollerArrowsMinEnd)
|
1999-02-03 21:53:29 +00:00
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
y += buttonsSize;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerDecrementLine:
|
|
|
|
case NSScrollerDecrementPage:
|
1999-03-16 16:38:26 +00:00
|
|
|
if (usableParts == NSNoScrollerParts
|
|
|
|
|| _arrowsPosition == NSScrollerArrowsNone)
|
1999-02-03 21:53:29 +00:00
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
return NSZeroRect;
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
1999-03-16 16:38:26 +00:00
|
|
|
else if (_arrowsPosition == NSScrollerArrowsMaxEnd)
|
1999-03-14 10:58:59 +00:00
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
y += (height - buttonsSize + 1);
|
1999-03-14 10:58:59 +00:00
|
|
|
}
|
|
|
|
width = buttonsWidth;
|
1999-02-03 21:53:29 +00:00
|
|
|
height = buttonsWidth;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerIncrementLine:
|
|
|
|
case NSScrollerIncrementPage:
|
1999-03-16 16:38:26 +00:00
|
|
|
if (usableParts == NSNoScrollerParts
|
|
|
|
|| _arrowsPosition == NSScrollerArrowsNone)
|
|
|
|
{
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
else if (_arrowsPosition == NSScrollerArrowsMaxEnd)
|
1999-03-14 10:58:59 +00:00
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
y += (height - buttonsWidth);
|
1999-03-14 10:58:59 +00:00
|
|
|
}
|
|
|
|
else if (_arrowsPosition == NSScrollerArrowsMinEnd)
|
1999-02-03 21:53:29 +00:00
|
|
|
{
|
1999-03-16 16:38:26 +00:00
|
|
|
y += (buttonsWidth + 1);
|
1999-02-03 21:53:29 +00:00
|
|
|
}
|
|
|
|
height = buttonsWidth;
|
1999-03-14 10:58:59 +00:00
|
|
|
width = buttonsWidth;
|
1999-02-03 21:53:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NSScrollerNoPart:
|
|
|
|
return NSZeroRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_isHorizontal)
|
2001-01-28 20:26:55 +00:00
|
|
|
{
|
|
|
|
return NSMakeRect (y, x, height, width);
|
|
|
|
}
|
1999-02-03 21:53:29 +00:00
|
|
|
else
|
2001-01-28 20:26:55 +00:00
|
|
|
{
|
|
|
|
return NSMakeRect (x, y, width, height);
|
|
|
|
}
|
1998-09-08 14:56:29 +00:00
|
|
|
}
|
1997-08-05 21:50:10 +00:00
|
|
|
|
2001-10-21 23:30:26 +00:00
|
|
|
+ (float) scrollerWidthForControlSize: (NSControlSize)controlSize
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return scrollerWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setControlSize: (NSControlSize)controlSize
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSControlSize) controlSize
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return NSRegularControlSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setControlTint: (NSControlTint)controlTint
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSControlTint) controlTint
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return NSDefaultControlTint;
|
|
|
|
}
|
|
|
|
|
1997-03-05 01:11:17 +00:00
|
|
|
@end
|