Inherits From:
NSControl : NSView : NSResponder : NSObject
Conforms To:
NSCoding (NSResponder)
NSObject (NSObject)
Declared In:
AppKit/NSScroller.h
Interface Builder | |
- initWithFrame: | Initializes the NSScroller. |
- hitPart | Indicates where the user clicked the NSScroller. |
- floatValue (NSControl) | Returns the position of the NSScroller's knob. |
- setFloatValue:knobProportion: | Sets the position and size of the NSScroller's knob. |
Interface Builder automatically associates NSScrollers with an NSScrollView, allowing you to configure most aspects of scrolling behavior without programming. If you create one programmatically using initWithFrame:
the new NSScroller automatically collapses the shorter of its two dimensions to the standard scroller width, as returned by the scrollerWidth
class method. In this manner a tall, narrow frame results in a vertical NSScroller and a short, wide frame results in a horizontal NSScroller.
As an NSScroller tracks the mouse, it sends an action message to its target with itself as the argument. The target then performs the scrolling operation based on these things:
hitPart
method returns this information, described in more detail below.
floatValue
method provides this information, which the target should interpret relative to the size of the document view's frame minus the size of the container view's bounds.
hitPart
message, which indicates the various parts of an NSScroller in terms of their intended result (not in terms of their location or appearance):
Value | How to Scroll |
---|---|
NSScrollerKnob | Directly to the NSScroller's value, as given by floatValue
|
NSScrollerKnobSlot | Directly to the NSScroller's value, as given by floatValue
|
NSScrollerDecrementLine | Up or left by a small amount |
NSScrollerDecrementPage | Up or left by a large amount |
NSScrollerIncrementLine | Down or right by a small amount |
NSScrollerIncrementPage | Down or right by a large amount |
NSScrollerNoPart | Don't scroll at all |
hitPart
, rectForPart:
, and testPart:
for details.
The four decrement/increment values require the target to calculate an appropriate amount to scroll by. Line and page amounts are up to the target or the container view to define. NSScrollView, for example, allows you to set these in Interface Builder or with its setLineScroll:
and setPageScroll:
methods. Once the target has scrolled the document view by a decrement or increment, it should update the NSScroller's position using setFloatValue:
.
The container view or target should also keep tabs on its size and on the size and position of its document view. Any time these change it should update its NSScrollers using setFloatValue:knobProportion:
. NSClipView, for example, overrides most of NSView's setBounds...
and setFrame...
methods to perform this updating.
scrollerWidth
Returns the width of instances. NSScrollView uses this value to lay out its components. Subclasses that use a different width should override this method.
arrowsPosition
Returns the location of the scroll buttons within the receiver, as described under setArrowsPosition:
.
checkSpaceForParts
Checks to see if there is enough room in the receiver to display the knob and buttons. usableParts
returns the state calculated by this method. You should never need to invoke this method; it's invoked automatically whenever the NSScroller's size changes.
drawArrow:
(NSScrollerArrow)arrow highlight:
(BOOL)flag
Draws the scroll button indicated by arrow, which is either NSScrollerIncrementArrow (the down or right scroll button) or NSScrollerDecrementArrow (up or left). If flag is YES, the button is drawn highlighted, otherwise it's drawn normally. You should never need to invoke this method directly, but may wish to override it to customize the appearance of scroll buttons.
See also:
- drawKnob
, - rectForPart:
drawKnob
Draws the knob. You should never need to invoke this method directly, but may wish to override it to customize the appearance of the knob.
See also:
- drawArrow:highlight:
, - rectForPart:
drawParts
Caches images for the scroll buttons and knob. It's invoked only once when the NSScroller is created. You may want to override this method if you alter the look of the NSScroller, but you should never invoke it directly.
highlight:
(BOOL)flag
Highlights or unhighlights the scroll button that the user clicked. The receiver invokes this method while tracking the mouse; you should not invoke it directly. If flag is YES, the appropriate part is drawn highlighted, otherwise it's drawn normally.
See also:
- drawArrow:highlight:
, - rectForPart:
hitPart
Returns a part code indicating the manner in which the scrolling should be performed:
Value | How to Scroll |
---|---|
NSScrollerKnob | Directly to the NSScroller's value, as given by floatValue
|
NSScrollerKnobSlot | Directly to the NSScroller's value, as given by floatValue
|
NSScrollerDecrementLine | Up or left by a small amount |
NSScrollerDecrementPage | Up or left by a large amount |
NSScrollerIncrementLine | Down or right by a small amount |
NSScrollerIncrementPage | Down or right by a large amount |
NSScrollerNoPart | Don't scroll at all |
This method is typically invoked by an NSScrollView to determine how to scroll its document view when it receives an action message from the NSScroller.
initWithFrame:
(NSRect)frameRect
Initializes the receiver as normal, but collapsing frameRect's narrower dimension to the value returned by the scrollerWidth
method. This enforces the appearance of vertical and horizontal NSScrollers. This is the designated initializer for the NSScroller class. Returns self
.
knobProportion
Returns the portion of the knob slot that the knob should fill, as a floating-point value from 0.0 (minimal size) to 1.0 (fills the slot).
rectForPart:
(NSScrollerPart)aPart
Returns the rectangle occupied by aPart, which for this method is interpreted literally rather than as an indicator of scrolling direction:
Value | Part |
---|---|
NSScrollerKnob | The knob itself |
NSScrollerKnobSlot | The slot that the knob moves in |
NSScrollerDecrementLine | The up or left scroll button |
NSScrollerDecrementPage | The region of the slot above or to the left of the knob |
NSScrollerIncrementLine | The down or right scroll button |
NSScrollerIncrementPage | The region of the slot below or to the right of the knob |
Note the interpretations of NSScrollerDecrementPage and NSScrollerIncrementPage. The actual part of an NSScroller that causes page-by-page scrolling varies from platform to platform, so as a convenience these part codes refer to useful parts different from the scroll buttons.
Returns NSZeroRect if the part requested isn't present on the receiver.
See also:
- hitPart
, - testPart:
, - usableParts
setArrowsPosition:
(NSScrollArrowPosition)location
Sets the location of the scroll buttons within the Scroller to location, or inhibits their display, as follows:
Value | Meaning |
---|---|
NSScrollerArrowsMaxEnd | Buttons at bottom or right |
NSScrollerArrowsMinEnd | Buttons at top or left |
NSScrollerArrowsNone | No buttons |
- arrowsPosition
setFloatValue:
(float)aFloat knobProportion:
(float)knobProp
Sets the position of the knob to aFloat, which is a value between 0.0 (indicating the top or left end) and 1.0 (the bottom or right end). Also sets the proportion of the knob slot filled by the knob to knobProp, also a value between 0.0 (minimal size) and 1.0 (fills the slot).
See also:
- floatValue
(NSControl), - knobProportion
testPart:
(NSPoint)aPoint
Returns the part that would be hit by a mouse-down event at aPoint (expressed in the receiver's coordinate system):
Return Value | Part Identified |
---|---|
NSScrollerKnob | The knob itself |
NSScrollerKnobSlot | The slot that the knob moves in (returned only if there's no knob) |
NSScrollerDecrementLine | The up or left scroll button |
NSScrollerDecrementPage | The region of the slot above or to the left of the knob |
NSScrollerIncrementLine | The down or right scroll button |
NSScrollerIncrementPage | The region of the slot below or to the right of the knob |
NSScrollerNoPart | (aPoint isn't in the NSScroller) |
Note the interpretations of NSScrollerDecrementPage and NSScrollerIncrementPage. The actual part of an NSScroller that causes page-by-page scrolling varies from platform to platform, so as a convenience these part codes refer to useful parts different from the scroll buttons.
See also:
- hitPart
, - rectForPart:
trackKnob:
(NSEvent *)theEvent
Tracks the knob and sends action messages to the receiver's target. This method is invoked automatically when the NSScroller receives a mouse-down event in the knob; you should not invoke it directly.
trackScrollButtons:
(NSEvent *)theEvent
Tracks the scroll buttons and sends action messages to the receiver's target. This method is invoked automatically when the NSScroller receives a mouse-down event in a scroll button; you should not invoke this method directly.
usableParts
Returns a value indicating which parts of the receiver are displayed and usable. This is one of:
Value | Meaning |
---|---|
NSNoScro |