DrawKit
Vector and illustration framework for Mac OS X
Instance Methods | Class Methods | List of all members
DKToolController Class Reference

This object is a view controller that can apply one of a range of tools to the objects in the currently active drawing layer. More...

Inheritance diagram for DKToolController:
Inheritance graph
[legend]

Instance Methods

(BOOL- automaticallyRevertsToSelectionTool
 Whether the tool should automatically "spring back" to the selection tool after each application. More...
 
(BOOL- canSetDrawingTool:
 Check if the tool can be set for the current active layer. More...
 
(void) - closeUndoGroup
 Closes the current undo manager group if one has been opened. More...
 
(DKDrawingTool *) - drawingTool
 Return the current drawing tool. More...
 
(void) - openUndoGroup
 Opens a new undo manager group if one has not already been opened. More...
 
(IBAction) - selectDrawingToolByName:
 Select the tool using its registered name based on the title of a UI control, etc. More...
 
(IBAction) - selectDrawingToolByRepresentedObject:
 Select the tool using the represented object of a UI control, etc. More...
 
(void) - setAutomaticallyRevertsToSelectionTool:
 Set whether the tool should automatically "spring back" to the selection tool after each application. More...
 
(void) - setDrawingTool:
 Sets the current drawing tool. More...
 
(void) - setDrawingToolWithName:
 Select the tool using its registered name. More...
 
(IBAction) - toggleAutoRevertAction:
 Toggle the state of the automatic tool "spring" behaviour. More...
 
(id- undoManager
 
- Instance Methods inherited from DKViewController
(BOOL- activatesLayersAutomatically
 Should a mouse down activate the layer it hits automatically? More...
 
(NSRect- activeCursorRect
 Return the active cursor rect. More...
 
(DKLayer *) - activeLayer
 Return the drawing's current active layer. More...
 
(void) - activeLayerDidChangeToLayer:
 A new layer was activated. More...
 
(id- activeLayerOfClass:
 Return the drawing's current active layer if it matches the given class, else nil. More...
 
(void) - activeLayerWillChangeToLayer:
 A new layer is about to be activated. More...
 
(BOOL- autoActivateLayerWithEvent:
 If layers can be automatically activated, perform that switch. More...
 
(void) - autoscrollTimerCallback:
 
(BOOL- contextualMenusEnabled
 Are the standard contextual menus within DK are enabled or not? More...
 
(IBAction) - copyDrawing:
 
(NSCursor *) - cursor
 Return the cursor to display when the mouse is in the view. More...
 
(DKDrawing *) - drawing
 Return the controller's drawing. More...
 
(void) - drawingDidChangeToSize:
 Notify that the drawing has had its size changed. More...
 
(void) - exitTemporaryTextEditingMode
 Stop any text editing that may be taking place in the view. More...
 
(DKLayer *) - findLayer:
 Which layer did the point hit? More...
 
(void) - flagsChanged:
 Handle the flags changed event. More...
 
(IBAction) - hideInactiveLayers:
 Hides all inactive layers and shows the active layer (if it's hidden) More...
 
(void) - hideViewRulerMarkers
 Hide the view's ruler markers. More...
 
(id- initWithView:
 Initialize the controller. More...
 
(void) - invalidateCursors
 Invalidate the cursor rects for the view. More...
 
(IBAction) - layerBringForward:
 Move the active layer 1 position forward within its group. More...
 
(IBAction) - layerBringToFront:
 Bring the active layer to the front of its group. More...
 
(IBAction) - layerSendBackward:
 Move the active layer 1 position towards the back within its group. More...
 
(IBAction) - layerSendToBack:
 Move the active layer to the back within its group. More...
 
(NSMenu *) - menuForEvent:
 
(void) - mouseDown:
 Handle the mouse down event. More...
 
(void) - mouseDragged:
 Handle the mouse dragged event. More...
 
(void) - mouseMoved:
 Handle the mouse moved event. More...
 
(void) - mouseUp:
 Handle the mouse up event. More...
 
(void) - objectDidNotifyStatusChange:
 An object in the drawing notified a status (rather than visual) change. More...
 
(void) - rulerView:handleMouseDown:
 Respond to a mouse-down in one of the view's rulers. More...
 
(void) - scrollViewToRect:
 Scroll the view so that the given area is visible. More...
 
(void) - setActivatesLayersAutomatically:
 Should a mouse down activate the layer it hits automatically? More...
 
(void) - setContextualMenusEnabled:
 Set whether the standard contextual menus within DK are enabled or not. More...
 
(void) - setDrawing:
 Set the drawing that the controller is attached to. More...
 
(void) - setView:
 Set the view that the controller is associated with. More...
 
(void) - setViewNeedsDisplay:
 Mark the entire view for update. More...
 
(void) - setViewNeedsDisplayInRect:
 Mark part of the view for update. More...
 
(IBAction) - showAllLayers:
 Shows all layers. More...
 
(void) - startAutoscrolling
 Start the autoscroll timer. More...
 
(void) - stopAutoscrolling
 Stop the autoscroll timer. More...
 
(void) - synchronizeViewRulersWithUnits:
 Set the rulers to match the unit string. More...
 
(IBAction) - toggleGridVisible:
 
(IBAction) - toggleGuidesVisible:
 
(IBAction) - toggleSnapToGrid:
 
(IBAction) - toggleSnapToGuides:
 
(void) - updateViewRulerMarkersForRect:
 Set the ruler markers to the given rect. More...
 
(NSView *) - view
 Return the controller's view. More...
 
(CGFloat- viewScale
 Return the current scale of the view. More...
 
- Instance Methods inherited from NSObject
(NSString *) - address
 
(DKStyleRegistry *) - applicationWillReturnStyleRegistry
 
(BOOL- canBeUsedWithSelectionTool
 
(id- categoryManager:shouldReplaceObject:withObject:
 
(Class- classForCoder
 
(NSColor *) - colorValue
 
(NSColor *) - colourValue
 
(id- copy
 
(void) - dealloc
 
(id- deepCopy
 
(NSDictionary *) - dimensionValuesForArrowStroke:
 
(CGFloat- drawing:convertDistanceToExternalCoordinates:
 
(NSPoint) - drawing:convertLocationToExternalCoordinates:
 
(void) - drawing:didDrawRect:inView:
 
(void) - drawing:willDrawRect:inView:
 
(NSString *) - drawing:willReturnAbbreviationForUnit:
 
(NSString *) - drawing:willReturnFormattedCoordinateForDistance:
 
(CGFloat- drawingWillReturnUnitToPointsConversonFactor:
 
(void) - finalize
 
(NSString *) - hexString
 
(void) - hotspot:didEndTrackingWithEvent:inView:
 
(void) - hotspot:isTrackingWithEvent:inView:
 
(void) - hotspot:willBeginTrackingWithEvent:inView:
 
(NSData *) - imageData
 
(NSImage *) - imageResourceNamed:
 
(id- init
 
(id- initWithExpression:
 
(id- instantiateObjectWithShortName:parameters:
 
(BOOL- isLiteralValue
 
(void) - layoutManager:willPlaceGlyphAtIndex:atLocation:pathAngle:yOffset:
 
(void) - menuItem:wasAddedForObject:inCategory:
 
(BOOL- moveObjectTo:position:slope:userInfo:
 
(id- mutableCopy
 
(void) - oneShotComplete
 
(void) - oneShotHasReached:
 
(void) - oneShotWillBegin
 
(void) - path:elementIndex:type:points:subPathIndex:subPathClosed:contextInfo:
 
(id- placeLinkFromPoint:toPoint:onPath:linkNumber:userInfo:
 
(id- placeObjectAtPoint:onPath:position:slope:userInfo:
 
(NSPoint) - point
 
(NSPoint) - pointForTextLayout
 
(DKStyle *) - registry:shouldReplaceStyle:withStyle:
 
(NSBezierPath *) - renderer:willRenderPath:
 
(void) - routeFinder:progressHasReached:
 
(void) - setValue:forNumericParameter:
 
(NSString *) - stringValue
 
(CGFloat- taperFactorAtDistance:onPath:ofLength:
 
(void) - toolDidPerformUndoableAction:
 
(void) - toolWillPerformUndoableAction:
 
(NSURL *) - url
 
- Instance Methods inherited from <NSObject>
(NSString *) - description
 
(NSUInteger- hash
 
(BOOL- isEqual:
 
- Instance Methods inherited from <NSKeyValueBindingCreation>
(void) - bind:toObject:withKeyPath:options:
 
(NSArray *) - exposedBindings
 
(NSDictionary *) - infoForBinding:
 
(NSArray *) - optionDescriptionsForBinding:
 
(void) - unbind:
 
(Class- valueClassForBinding:
 

Class Methods

(DKDrawingToolScope) + drawingToolOperatingScope
 Return the operating scope for tools for this application. More...
 
(void) + setDrawingToolOperatingScope:
 Set the operating scope for tools for this application. More...
 
(void) + setToolsAutoActivateValidLayer:
 Set whether setting a tool will auto-activate a layer appropriate to the tool. More...
 
(BOOL+ toolsAutoActivateValidLayer
 Return whether setting a tool will auto-activate a layer appropriate to the tool. More...
 
- Class Methods inherited from NSObject
(id+ alloc
 
(Class+ class
 
(void) + initialize
 
(void) + load
 
(id+ new
 
- Class Methods inherited from <NSKeyValueBindingCreation>
(void) + exposeBinding:
 

Additional Inherited Members

- Protected Attributes inherited from DKViewController
NSEventmDragEvent
 

Detailed Description

This object is a view controller that can apply one of a range of tools to the objects in the currently active drawing layer.

This object is a view controller that can apply one of a range of tools to the objects in the currently active drawing layer.

==== WHAT IS A TOOL? ====

Users "see" tools often as a button in a palette of tools, and can choose which tool is operative by clicking the button. While your application may certainly implement a user interface for selecting among tools in this way, DK's concept of a tool is more abstract.

In DK, a tool is an object that takes basic mouse events that originate in a view and translates those events into meaningful operations on the data model or other parts of DK. Thus a tool is essentially a translator of mouse events into specific behaviours. Different tools have different behaviours, but all adopt the same basic DKDrawingTool protocol. Tools are part of the controller layer of the M-V-C paradigm.

Not all tools necessarily change the data content of the drawing. For example a user might pick a zoom tool from the same palette that has other drawing tools such as rects or ovals. A zoom tool doesn't change the data content, it only changes the state of the view. The tool protocol permits the controller to determine whether the data content was changed so it can help manage undo and so forth.

Tools may optionally draw something in the view - if so, they are given the opportunity to do so after all other drawing, so tools draw "on top" of any other content. Typically a tool might draw a selection rect or similar.

Tools are responsible for applying their own behaviour to the target object(s), this controller merely calls the tool appropriately.

==== CHOOSING TOOLS ====

This controller permits one tool at a time to be set. This can be applied globally for the whole application, on a per-document (drawing) basis, or individually for the view. Which you use will depend on your needs and the sort of user interface that your application wants to implement for tools. DK provides no UI and makes no assumptions about it - your UI is required to somehow pick a tool and set it.

Tools can be stored in a registry (see DKDrawingTool) using a name. A UI may take advantage of this by using the name to look up the tool and set it. As a convenience, the -selectDrawingToolByName: action method will use the -title property of <sender> as the name and set the tool if one exists in the registry with this name - thus a palette of buttons for example can just set each button title to the tool's name and target first responder with this action.

Method Documentation

- (BOOL) automaticallyRevertsToSelectionTool

Whether the tool should automatically "spring back" to the selection tool after each application.

The default is YES

Returns
YES to spring back, NO to leave the present tool active after each use
- (BOOL) canSetDrawingTool: (DKDrawingTool *)  aTool

Check if the tool can be set for the current active layer.

Can be used to test whether a tool is able to be selected in the current context. There is no requirement to use this - you can set the drawing tool anyway and if an attempt to use it in an invalid layer is made, the tool controller will handle it anyway. A UI might want to use this to prevent the selection of a tool before it gets to that point however.

Parameters
aToolthe propsed drawing tool
Returns
YES if the tool can be applied to the current active layer, NO if not
- (void) closeUndoGroup

Closes the current undo manager group if one has been opened.

When the controller is set up to always open a group, this also deals with the bogus task bug in NSUndoManager, where opening and closig a group creates an empty undo task. If that case is detected, the erroneous task is removed from the stack by invoking undo while temporarily disabling the UM.

- (DKDrawingTool*) drawingTool

Return the current drawing tool.

The tool is set locally, for the drawing or globally according to the current scope.

Returns
the current tool
+ (DKDrawingToolScope) drawingToolOperatingScope

Return the operating scope for tools for this application.

DK allows tools to be set per-view, per-document, or per-application. This is called the operating scope. Generally your app should decide what is appropriate, set it at start up and stick to it. The default is per-document scope.

Returns
the operating scope for tools
- (void) openUndoGroup

Opens a new undo manager group if one has not already been opened.

- (IBAction) selectDrawingToolByName: (id sender

Select the tool using its registered name based on the title of a UI control, etc.

This is a convenience for hooking up a UI for picking a tool. You can set the title of a button to be the tool's name and target first responder using this action, and it will select the tool if it has been registered using the name. This makes UI such as a palette of tools trivial to implement, but doesn't preclude you from using any other UI as you see fit.

Parameters
senderthe sender of the action - it should implement -title (e.g. a button, menu item)
- (IBAction) selectDrawingToolByRepresentedObject: (id sender

Select the tool using the represented object of a UI control, etc.

This is a convenience for hooking up a UI for picking a tool. You can set the rep. object of a button to be the tool and target first responder using this action, and it will set the tool to the button's represented object.

Parameters
senderthe sender of the action - it should implement -representedObject (e.g. a button, menu item)
- (void) setAutomaticallyRevertsToSelectionTool: (BOOL reverts

Set whether the tool should automatically "spring back" to the selection tool after each application.

The default is YES

Parameters
revertsYES to spring back, NO to leave the present tool active after each use
- (void) setDrawingTool: (DKDrawingTool *)  aTool

Sets the current drawing tool.

The tool is set locally, for the drawing or globally according to the current scope.

Parameters
aToolthe tool to set
+ (void) setDrawingToolOperatingScope: (DKDrawingToolScope)  scope

Set the operating scope for tools for this application.

DK allows tools to be set per-view, per-document, or per-application. This is called the operating scope. Generally your app should decide what is appropriate, set it at start up and stick to it. It is not expected that this will be called during the subsequent use of the app - though it is harmless to do so it's very likely to confuse the user.

Parameters
scopethe operating scope for tools
- (void) setDrawingToolWithName: (NSString *)  name

Select the tool using its registered name.

Tools must be registered in the DKDrawingTool registry with the given name before you can use this method to set them, otherwise an exception is thrown.

Parameters
namethe registered name of the required tool
+ (void) setToolsAutoActivateValidLayer: (BOOL autoActivate

Set whether setting a tool will auto-activate a layer appropriate to the tool.

Default is NO. If YES, when a tool is set but the active layer is not valid for the tool, the layers are searched top down until one is found that the tool validates, which is then made active. Layers which are locked, hidden or refuse active status are skipped. Persistent.

Parameters
autoActivateYES to autoactivate, NO otherwise
- (IBAction) toggleAutoRevertAction: (id sender

Toggle the state of the automatic tool "spring" behaviour.

Flips the state of the auto-revert flag. A UI can make use of this to control the flag in order to make a tool "sticky". Often this is done by double-clicking the tool button.

Parameters
senderthe sender of the action
+ (BOOL) toolsAutoActivateValidLayer

Return whether setting a tool will auto-activate a layer appropriate to the tool.

Default is NO. If YES, when a tool is set but the active layer is not valid for the tool, the layers are searched top down until one is found that the tool validates, which is then made active. Layers which are locked, hidden or refuse active status are skipped. Persistent.

Returns
YES if tools auto-activate appropriate layer, NO if not
- (id) undoManager