Inherits from: NSObject
Conforms to: NSCopying
NSObject (NSObject)
Declared in: AppKit/NSRulerMarker.h
An NSRulerMarker displays a symbol on an NSRulerView, indicating a location for whatever graphic element it represents in the client of the NSRulerView (for example, a margin or tab setting, or the edges of a graphic on the page). A ruler marker comprises three primary attributes: the image it displays on the NSRulerView, the location of that image, and the object it represents. The setImage:, setMarkerLocation: and setRepresentedObject: methods set each of these attributes, respectively. In addition, a ruler marker records an offset for the image, allowing it to be placed relative to the marker location much in the way a cursor's hot spot relates a cursor image to the mouse location; the setImageOrigin: method establishes this offset.
Most of these attributes are set upon initialization by the initWithRulerView:markerLocation:image:imageOrigin:method. New ruler markers don't have represented objects; the client typically establishes the represented object in its rulerView:didAddMarker: method. A new NSRulerMarker can be moved around in its NSRulerView, but not removed from it. The setMovable: and setRemovable: methods alter these default settings.
Represented objects allow the NSRulerView's client to distinguish among different attributes of the selection. In the NSRulerView client methods, the client can retrieve the marker's represented object to determine what attribute to alter. Generic attributes can be represented by string or other value objects, such as the edge names "Left", "Right", "Top", and "Bottom". Attributes already implemented as objects can be represented by those objects. For example, the text system records tab stops as NSTextTab objects, which include the tab location and its alignment. When an NSTextView is the client view of a ruler, it simply makes the NSTextTabs the represented objects of the ruler markers.
- NSCopying
- - copyWithZone:
- Creating instances
- - initWithRulerView:markerLocation:image:imageOrigin:
- Getting the ruler view
- - ruler
- Setting the image
- - setImage:
- - image
- - setImageOrigin:
- - imageOrigin
- - imageRectInRuler
- - thicknessRequiredInRuler
- Setting movability
- - setMovable:
- - isMovable
- - setRemovable:
- - isRemovable
- Setting the location
- - setMarkerLocation:
- - markerLocation
- Setting the represented object
- - setRepresentedObject:
- - representedObject
- Drawing and event handling
- - drawRect:
- - isDragging
- - trackMouse:adding:
- (void)drawRect:(NSRect)aRect
See Also: - imageRectInRuler
- (NSImage *)image
See Also: - setImage:
- (NSPoint)imageOrigin
For a horizontal ruler, the x coordinate of the image origin is aligned with the location of the marker, and the y coordinate lies on the baseline of the ruler. For vertical rulers, the y coordinate of the image origin is the location, and the x coordinate lies on the baseline.
See Also: - setImageOrigin:, - imageRectInRuler
- (NSRect)imageRectInRuler
See Also: - drawRect:, - thicknessRequiredInRuler
- (id)initWithRulerView:(NSRulerView
*)aRulerView markerLocation:(float)location image:(NSImage
*)anImage imageOrigin:(NSPoint)imageOrigin
nil
.The image used to draw the marker must be appropriate for the orientation of the ruler. Markers may need to look different on a horizontal ruler than on a vertical ruler, and the NSRulerView neither scales nor rotates the images.
To add the new ruler marker to aRulerView, use either of NSRulerView's addMarker: or trackMarker:withMouseEvent: methods. addMarker: immediately puts the marker on the ruler, while trackMarker:withMousEvent: allows the client view to intercede in the addition and placement of the marker.
A new ruler marker can be moved on its NSRulerView, but not removed. Use setMovable: and setRemovable: to change these attributes. The new ruler marker also has no represented object; use setRepresentedObject: to provide or change it.
This method retains anImage, since it's an essential part of the ruler marker, but doesn't retain aRulerView (the NSRulerView instead retains the new marker when it's added). This method is the designated initializer for the NSRulerMarker class. Returns self.
See Also: - setMarkerLocation:, - setImage:, - setImageOrigin:
- (BOOL)isDragging
YES
if
the receiver is being dragged, NO otherwise.See Also: - trackMouse:adding:
- (BOOL)isMovable
YES
if
the user can move the receiver on its NSRulerView, NO
otherwise. NSRulerMarkers
are by default movable.See Also: - setMovable:, - isRemovable
- (BOOL)isRemovable
YES
if
the user can remove the receiver from its NSRulerView, NO
otherwise. NSRulerMarkers
cannot by default be removed from their NSRulerViews.See Also: - setRemovable:, - isMovable
- (float)makerLocation
See Also: - setMarkerLocation:
- (id <NSCopying>)representedObject
See Also: - setRepresentedObject:
- (NSRulerView *)ruler
See Also: - addMarker: (NSRulerView)
- (void)setImage:(NSImage
*)anImage
See Also: - image, - setImageOrigin:
- (void)setImageOrigin:(NSPoint)aPoint
For a horizontal ruler, the x coordinate of the image origin is aligned with the location of the marker, and the y coordinate lies on the baseline of the ruler. For vertical rulers, the y coordinate of the image origin is the location, and the x coordinate lies on the baseline.
See Also: - imageOrigin, - setImage:, - setMarkerLocation:
- (void)setMarkerLocation:(float)location
See Also: - markerLocation, - setImageOrigin:
- (void)setMovable:(BOOL)flag
YES
,
the user can drag the marker image in the ruler. If flag is NO
,
the receiver is immovable. NSRulerMarkers are by default movable.See Also: - isMovable, - setRemovable:
- (void)setRemovable:(BOOL)flag
YES
,
the user can drag the marker image off of the ruler. If flag is NO
, the
receiver can't be removed. NSRulerMarkers are by default not removable.See Also: - isRemovable, - setMovable:
- (void)setRepresentedObject:(id
<NSCopying>)anObject
See Also: - representedObject
- (float)thicknessRequiredInRuler
See Also: - imageOrigin
- (BOOL)trackMouse:(NSEvent
*)theEvent adding:(BOOL)flag
If flag is YES
,
the receiver is a new marker being added to its NSRulerView. Before
the receiver actually adds itself to the NSRulerView, it queries
the NSRulerView's client view using rulerView:shouldAddMarker:.
If the client view responds to this method and returns NO
,
this method immediately returns NO
and
the new marker isn't added.
If flag is NO
,
this method attempts to move or remove an existing marker, once again
based on responses from the NSRulerView's client view. If the
receiver is neither movable nor removable, this method immediately
returns NO. Further, if the NSRulerView's client responds to rulerView:shouldMoveMarker: and
returns NO
, this method returns NO
,
indicating the receiver can't be moved.
If the receiver is being added or moved, this method queries the client view using rulerView:willAddMarker:atLocation: or rulerView:willMoveMarker:toLocation:, respectively. If the client responds to the method, the return value is used as the receiver's location. These methods are invoked repeatedly as the receiver is dragged within the NSRulerView.
If
the receiver is an existing marker being removed (dragged off the
ruler), this method queries the client view using rulerView:shouldRemoveMarker:.
If the client responds to this method and returns NO
,
the marker is pinned to the NSRulerView's baseline (following
the mouse on the baseline if it's movable).
When the
user releases the mouse, this method informs the client view of
the marker's new status using rulerView:didAddMarker:, rulerView:didMoveMarker:,
or rulerView:didRemoveMarker: as appropriate. The
client view can use this notification to set the marker's represented
object, modify its state and redisplay (for example, adjusting text
layout around a new tab stop), or take whatever other action it
might need. If flag is YES
and
the user dragged the new marker away from the ruler, the marker
isn't added, no message is sent, and this method returns NO
.
See the NSRulerView class description for more information on these client methods.
See Also: - isMovable, - isRemovable