Instance Method

trackMouse:adding:

Handles user manipulation of the receiver in its ruler view.

Declaration

- (BOOL)trackMouse:(NSEvent *)mouseDownEvent adding:(BOOL)isAdding;

Parameters

theEvent

The event that represents the user manipulation being attempted on the ruler marker.

flag

YES to indicate that the receiver is a new marker being added to its ruler view, NO otherwise.

Return Value

YES if the user manipulation was allowed, NO if it was not allowed.

Discussion

NSRulerView objects invoke this method automatically to add a new marker or to move or remove an existing marker. You should never need to invoke it directly.

If the receiver is a new marker being added to its ruler view (flag is YES), the receiver queries the ruler view's client before adding itself to the ruler view. If the client responds to rulerView:shouldAddMarker: and that method returns NO, this method immediately returns NO, and the new marker isn’t added.

If the receiver is not a new marker being added to its ruler view (flag is NO), this method attempts to move or remove an existing marker, once again based on responses from the ruler view's client view. If the receiver is neither movable nor removable, this method immediately returns NO. Further, if the ruler view'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 ruler view.

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 ruler view's baseline (following the cursor on the baseline if it’s movable).

When the user releases the mouse button, 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 Ruler and Paragraph Style Programming Topics for more information on these client methods.

See Also

Drawing and event handling

- drawRect:

Draws the receiver’s image that appears in the supplied rectangle.

dragging

A Boolean that indicates whether the receiver is being dragged.