home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / DEV.Z / NSTextStorage.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-09  |  3.4 KB  |  86 lines

  1. /* 
  2.     NSTextStorage.h
  3.     Copyright (c) 1994-1996, NeXT Software, Inc.
  4.     All rights reserved.
  5.  
  6. NSTextStorage is a semi-abstract subclass of NSMutableAttributedString. It implements change management (beginEditing/endEditing), verification of attributes, delegate handling, and layout management notification. The one aspect it does not implement is the actual attributed string storage --- this is left up to the subclassers, which need to override the two NSMutableAttributedString primitives:
  7.  
  8.   - (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str;
  9.   - (void)setAttributes:(NSDictionary *)attrs range:(NSRange)range;
  10.  
  11. These primitives should perform the change then call edited:range:changeInLength: to get everything else to happen.
  12.    
  13. */
  14.  
  15. #ifndef STRICT_OPENSTEP
  16.  
  17. #import <Foundation/Foundation.h>
  18. #import <AppKit/NSAttributedString.h>
  19.  
  20. @class NSLayoutManager;
  21.  
  22. /* These values are or'ed together in notifications to indicate what got changed.
  23. */
  24. enum {
  25.     NSTextStorageEditedAttributes = 1,
  26.     NSTextStorageEditedCharacters = 2
  27. };
  28.  
  29. @interface NSTextStorage : NSMutableAttributedString {
  30.     NSRange _editedRange;
  31.     int _editedDelta;
  32.     struct {
  33.     unsigned int editedMask:8;
  34.         unsigned int :8;
  35.         unsigned int disabled:16;
  36.     } _flags;
  37.     NSMutableArray *_layoutManagers;
  38.     id _delegate;
  39. }
  40.  
  41. /* These methods manage the list of layout managers.
  42. */   
  43. - (void)addLayoutManager:(NSLayoutManager *)obj;     /* Retains & calls setTextStorage: on the item */
  44. - (void)removeLayoutManager:(NSLayoutManager *)obj;
  45. - (NSArray *)layoutManagers;
  46.  
  47. /* If there are no outstanding beginEditing calls, this method calls processEditing to cause post-editing stuff to happen. This method has to be called by the primitives after changes are made. The range argument to edited:... is the range in the original string (before the edit).
  48. */
  49. - (void)edited:(unsigned)editedMask range:(NSRange)range changeInLength:(int)delta;
  50.  
  51. /* This is called from edited:range:changeInLength: or endEditing. This method sends out NSTextStorageWillProcessEditing, then fixes the attributes, then sends out NSTextStorageDidProcessEditing, and finally notifies the layout managers of change with the textStorage:edited:range:changeInLength:invalidatedRange: method.
  52. */
  53. - (void)processEditing;
  54.  
  55. /* These methods return information about the editing status. Especially useful when there are outstanding beginEditing calls or during processEditing... editedRange.location will be NSNotFound if nothing has been edited.
  56. */       
  57. - (unsigned)editedMask;
  58. - (NSRange)editedRange;
  59. - (int)changeInLength;
  60.  
  61. /* Set/get the delegate
  62. */
  63. - (void)setDelegate:(id)delegate;
  64. - (id)delegate;
  65.  
  66. @end
  67.  
  68.  
  69. /****  NSTextStorage delegate methods ****/
  70.  
  71. @interface NSObject (NSTextStorageDelegate)
  72.  
  73. /* These methods are sent during processEditing:. The receiver can use the callback methods editedMask, editedRange, and changeInLength to see what has changed. Although these methods can change the contents of the text storage, it's best if only the delegate did this.
  74. */
  75. - (void)textStorageWillProcessEditing:(NSNotification *)notification;    /* Delegate can change the characters or attributes */
  76. - (void)textStorageDidProcessEditing:(NSNotification *)notification;    /* Delegate can change the attributes */
  77.  
  78. @end
  79.  
  80. /**** Notifications ****/
  81.  
  82. APPKIT_EXTERN NSString *NSTextStorageWillProcessEditingNotification;
  83. APPKIT_EXTERN NSString *NSTextStorageDidProcessEditingNotification;
  84.  
  85. #endif
  86.