home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2 / Openstep-4.2-Intel-Developer.iso / NextLibrary / Frameworks / AppKit.framework / Versions / B / Headers / NSRulerView.h < prev    next >
Text File  |  1996-11-26  |  13KB  |  174 lines

  1. /*
  2.         NSRulerView.h
  3.         Application Kit
  4.         Copyright (c) 1994-1996, NeXT Software, Inc.
  5.         All rights reserved.
  6. */
  7.  
  8. #ifndef STRICT_OPENSTEP
  9.  
  10. #import <AppKit/NSView.h>
  11.  
  12. @class NSScrollView;
  13. @class NSRulerMarker;
  14.  
  15. typedef enum {
  16.     NSHorizontalRuler,
  17.     NSVerticalRuler,
  18. } NSRulerOrientation;
  19.  
  20. @interface NSRulerView : NSView {
  21.   @private
  22.     NSScrollView *_scrollView;
  23.     NSRulerOrientation _orientation;
  24.  
  25.     NSString *_units;
  26.     float _originOffset;
  27.  
  28.     float _ruleThickness;
  29.     float _thicknessForMarkers;
  30.     float _thicknessForAccessoryView;
  31.  
  32.     NSView *_clientView;
  33.     NSMutableArray *_markers;
  34.     NSView *_accessoryView;
  35.  
  36.     // Hash dict related caching
  37.     NSDictionary *_cachedHashDict;
  38.     float _cachedDocViewToRulerConversion;
  39.  
  40.     // Scroll optimization related caching
  41.     NSPoint _cachedContentBoundsOrigin;
  42.  
  43.     // Dragging related caching
  44.     NSRulerMarker *_draggingMarker;
  45.  
  46.     void *_reservedRulerView1;
  47. }
  48.  
  49. /************************* Registering new units *************************/
  50.  
  51. + (void)registerUnitWithName:(NSString *)unitName abbreviation:(NSString *)abbreviation unitToPointsConversionFactor:(float)conversionFactor stepUpCycle:(NSArray *)stepUpCycle stepDownCycle:(NSArray *)stepDownCycle;
  52.  
  53. /**************************** Initialization ****************************/
  54.  
  55. - (id)initWithScrollView:(NSScrollView *)scrollView orientation:(NSRulerOrientation)orientation;
  56.     // The designated initializer.  A ruler's size is controlled by its NSScrollView. initWithFrame: is overridden to call this.  The view is initialized with an unrealisticly small default frame which will be reset in due time by the NSScrollView.
  57.  
  58. /**************************** Basic setup ****************************/
  59.  
  60. - (void)setScrollView:(NSScrollView *)scrollView;
  61. - (NSScrollView *)scrollView;
  62.     // A ruler uses its scrollView to finds it's document view to see whether it should be flipped.  The set method is generally called only by the scroll view itself.  You should not have to set this.
  63.  
  64. - (void)setOrientation:(NSRulerOrientation)orientation;
  65. - (NSRulerOrientation)orientation;
  66.     // Either NSHorizontalRuler or NSVerticalRuler.  The set method is generally called by the ruler's scroll view.  You should not have to set this.
  67.  
  68.  
  69. /**************************** Ruler geometry ****************************/
  70.  
  71. - (float)baselineLocation;
  72.     // Returns the location of the baseline.  The location is a y position for horizontal rulers and an x position for vertical ones.  The value is based on the sizes of the various areas of the ruler, some of which can be set below.
  73.  
  74. - (float)requiredThickness;
  75.     // The required height for a horizontal ruler or the required width for a vertical ruler.  Used by the scrollview when tiling.  The value is based on the sizes of the various areas of the ruler, some of which can be set below.
  76.  
  77. - (void)setRuleThickness:(float)thickness;
  78. - (float)ruleThickness;
  79.     // The rule size is the height of the area used to draw the ruler hash-marks in a horizontal ruler or the width of that area in a vertical ruler.  This value will be interpretted in the coordinate system of the ruler's superview (like the ruler's frame).
  80.  
  81. - (void)setReservedThicknessForMarkers:(float)thickness;
  82. - (float)reservedThicknessForMarkers;
  83.     // This indicates to the ruler how much room it should leave for objects which sit above or to the left of the rule (such as tab stops, margins, etc...).  Default is 15.0.  If you expect that no view in your document view will ever put objects on the ruler, you can set this to 0.0.  If objects are ever set on the ruler, and not enough space was reserved for them, the ruler grows itself and retiles the scroll view.
  84.  
  85. - (void)setReservedThicknessForAccessoryView:(float)thickness;
  86. - (float)reservedThicknessForAccessoryView;
  87.     // This indicates to the ruler how much room it should leave for the accessory view.  Default is 0.0.  If you expect that a view in your document view will put an accessory view in the ruler, you can set this to make room fror it from the start.  If an accessory view is ever set for the ruler, and space was not reserved for it or it is bigger than the space reserved, the ruler grows the reserved space to be big enough and retiles the scroll view.  If you know that several different accessory views will be used it is best to set this to the height of the tallest one for horizontal rulers or the width of the widest one for vertical rulers.  If the reserved thickness is larger than an actual accessory view set into the ruler, the accessory view is centered in the thickness.
  88.  
  89. /**************************** Rule configuration ****************************/
  90.  
  91. - (void)setMeasurementUnits:(NSString *)unitName;
  92. - (NSString *)measurementUnits;
  93.     // The units of the ruler start out with the user's preferred measurement.  They can be changed if desired.  The units set must be registered with the ruler factory.  By default Inches, Centimeters, Picas, and Points are supported.
  94.  
  95. - (void)setOriginOffset:(float)offset;
  96. - (float)originOffset;
  97.     // How far to offset the ruler's zero hashmark (and label) from the document view's bounds origin.
  98.  
  99. /**************************** Client view setup ****************************/
  100.  
  101. - (void)setClientView:(NSView *)client;
  102. - (NSView *)clientView;
  103.  
  104. - (void)setMarkers:(NSArray *)markers;
  105. - (void)addMarker:(NSRulerMarker *)marker;
  106. - (void)removeMarker:(NSRulerMarker *)marker;
  107. - (NSArray *)markers;
  108.     // Ruler objects sit on the ruler at a specific location.  They can be manipulatable by the user, and if they are manipulated the current client is informed of the change.  Once a bunch of objects has been set, objects can be added or removed individually.
  109.  
  110. - (BOOL)trackMarker:(NSRulerMarker *)marker withMouseEvent:(NSEvent *)event;
  111.     // Given a ruler object and a mouse event (either MouseDown or MouseDragged) this will take over the tracking of the mouse until MouseUp.  While tracking it will snap to the baseline of the ruler when it gets within a certain distance.  At that point it becomes stuck to the baseline (this may happen immediately) and won't come off below (or to the right of) the ruler.  It may still be dragged off the baseline upward (or leftward) if its removable.  It is strongly recommended that any ruler object that acan be added to the ruler should be removable as well and it must be movable.  When the mouse goes up, if the object is currently stuck to the baseline it is added to the ruler (and the client object is notified), if its not stuck on the baseline, it is not added.
  112.  
  113. - (void)setAccessoryView:(NSView *)accessory;
  114. - (NSView *)accessoryView;
  115.     // A rulers accessory view is drawn below or to the right of the rule.  It can contain arbitrary controls.
  116.  
  117. - (void)moveRulerlineFromLocation:(float)oldLocation toLocation:(float)newLocation;
  118. // This method can be used to draw temporary lines in the rule.  NSRulerMarkers use this during dragging to draw the part of the line they draw from themselves across the scroll views contents which appears in the rule area.  You can use this method to draw ticks in the ruler (for example) to show the position or extent of an object while it is being dragged in the document.  oldLocation is the last position that the line was at or -1.0 if this is the first time it is being drawn.  newLocation is where the line should be or -1.0 if you are just trying to get an old line erased. 
  119.  
  120. /*********************** Drawing and hash invalidation ***********************/
  121.  
  122. - (void)invalidateHashMarks;
  123.     // Forces recalculation of the hash mark dictionary next time any display is done.  You should not generally have to call this method.
  124.  
  125. - (void)drawHashMarksAndLabelsInRect:(NSRect)rect;
  126.     // You should never need to call this, but you might want to override it.  This method is called by -drawRect: to draw the actual hash-marks and labels on the ruler.  If you want to do custom hash-marks and labels you should first look at doing it with a delegate.  You can do whatever kind of custom hash-marks you want through delegation as long as the hash-marks and labels are evenly spaced.  But if you need to do hash-marks or labels that are not evenly spaced you will need to override this.
  127.  
  128. - (void)drawMarkersInRect:(NSRect)rect;
  129.     // You should never need to call this, but you might want to override it.  This method is called by -drawRect: to draw the ruler objects on the ruler.  If you want to do something different you can override this.
  130.  
  131. /**************************** Key overrides ****************************/
  132.  
  133. - (BOOL)isFlipped;
  134.     // A vertical ruler mimics the flippedness of the documentView of it's scrollView.  A horizontal ruler is always flipped (for ease of drawing).
  135.  
  136. @end
  137.  
  138. // This informal protocol defines the communication between a ruler and its client view during mouse tracking.
  139. @interface NSView (NSRulerMarkerClientViewDelegation)
  140.  
  141. - (BOOL)rulerView:(NSRulerView *)ruler shouldMoveMarker:(NSRulerMarker *)marker;
  142.     // This is sent when a drag operation is just beginning for a ruler marker already on the ruler.  If the ruler object should be allowed to either move or remove, return YES.  If you return NO, all tracking is abandoned and nothing happens.
  143.  
  144. - (float)rulerView:(NSRulerView *)ruler willMoveMarker:(NSRulerMarker *)marker toLocation:(float)location;
  145.     // This is sent continuously while the mouse is being dragged.  The client can constrian the movement by returning a different location.  Receipt of one or more of these messages does not guarantee that the corresponding "did" method will be called.  Only movable objects will send this message.
  146.  
  147. - (void)rulerView:(NSRulerView *)ruler didMoveMarker:(NSRulerMarker *)marker;
  148.     // This is called if the NSRulerMarker actually ended up with a different location than it started with after the drag completes.  It is not called if the object gets removed, or if the object gets dragged around and dropped right where it was.  Only movable objects will send this message.
  149.  
  150. - (BOOL)rulerView:(NSRulerView *)ruler shouldRemoveMarker:(NSRulerMarker *)marker;
  151.     // This is sent each time the object is dragged off the baseline enough that if it were dropped, it would be removed.  It can be sent multiple times in the course of a drag.  Return YES if it's OK to remove the object, NO if not.  Receipt of this message does not guarantee that the corresponding "did" method will be called.  Only removable objects will send this message.
  152.  
  153. - (void)rulerView:(NSRulerView *)ruler didRemoveMarker:(NSRulerMarker *)marker;
  154.     // This is sent if the object is actually removed.  The object has been removed from the ruler when this message is sent.
  155.  
  156. - (BOOL)rulerView:(NSRulerView *)ruler shouldAddMarker:(NSRulerMarker *)marker;
  157.     // This is sent when a drag operation is just beginning for a ruler marker that is being added.  If the ruler object should be allowed to add, return YES.  If you return NO, all tracking is abandoned and nothing happens.
  158.  
  159. - (float)rulerView:(NSRulerView *)ruler willAddMarker:(NSRulerMarker *)marker atLocation:(float)location;
  160.     // This is sent continuously while the mouse is being dragged during an add operation and the new bject is stuck on the baseline.  The client can constrian the movement by returning a different location.  Receipt of one or more of these messages does not guarantee that the corresponding "did" method will be called.  Any object sending these messages is not yet added to the ruler it is being dragged on.
  161.  
  162. - (void)rulerView:(NSRulerView *)ruler didAddMarker:(NSRulerMarker *)marker;
  163.     // This is sent if the object is actually added during through NSRulerView's acceptMarker:withMouseEvent:.  The object has been added to the ruler when this message is sent.
  164.  
  165. - (void)rulerView:(NSRulerView *)ruler handleMouseDown:(NSEvent *)event;
  166.     // This is sent when the user clicks in the rule area of the ruler.  The "rule" area is the area below the baseline where the hash marks and labels are drawn.  A common use for this method would be to make clicking in the rule be a shortcut for adding the most common type of ruler object for a particuar client.  NSTextView will use this to insert a new left tab (as a short cut to dragging one out of the well in the accessory view).
  167.  
  168. - (void)rulerView:(NSRulerView *)ruler willSetClientView:(NSView *)newClient;
  169.     // This is sent to the existing client before it is replaced by the new client.  The existing client can catch this to clean up any cached state it keeps while it is the client of a ruler.
  170.  
  171. @end
  172.  
  173. #endif
  174.