00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 #import <Cocoa/Cocoa.h>
00009 
00010 #import <HexFiend/HFTypes.h>
00011 
00016 @class HFRepresenter, HFByteArray, HFFileReference, HFControllerCoalescedUndo, HFByteRangeAttributeArray;
00017 
00021 enum
00022 {
00023     HFControllerContentValue = 1 << 0,          
00024     HFControllerContentLength = 1 << 1,         
00025     HFControllerDisplayedLineRange = 1 << 2,    
00026     HFControllerSelectedRanges = 1 << 3,        
00027     HFControllerSelectionPulseAmount = 1 << 4,  
00028     HFControllerBytesPerLine = 1 << 5,          
00029     HFControllerBytesPerColumn = 1 << 6,        
00030     HFControllerEditable = 1 << 7,              
00031     HFControllerFont = 1 << 8,                  
00032     HFControllerAntialias = 1 << 9,             
00033     HFControllerLineHeight = 1 << 10,           
00034     HFControllerViewSizeRatios = 1 << 11,       
00035     HFControllerByteRangeAttributes = 1 << 12,  
00036     HFControllerByteGranularity = 1 << 13,       
00037     HFControllerBookmarks = 1 << 14       
00038 };
00039 typedef NSUInteger HFControllerPropertyBits;
00040 
00045 enum
00046 {
00047     HFControllerDirectionLeft,
00048     HFControllerDirectionRight
00049 };
00050 typedef NSInteger HFControllerMovementDirection;
00051 
00056 enum
00057 {
00058     HFControllerDiscardSelection,   
00059     HFControllerShiftSelection,     
00060     HFControllerExtendSelection     
00061 };
00062 typedef NSInteger HFControllerSelectionTransformation;
00063 
00068 enum
00069 {
00070     HFControllerMovementByte, 
00071     HFControllerMovementColumn, 
00072     HFControllerMovementLine, 
00073     HFControllerMovementPage, 
00074     HFControllerMovementDocument 
00075 };
00076 typedef NSInteger HFControllerMovementGranularity;
00077 
00092 @interface HFController : NSObject <NSCoding> {
00093 @private
00094     NSMutableArray *representers;
00095     HFByteArray *byteArray;
00096     NSMutableArray *selectedContentsRanges;
00097     HFRange displayedContentsRange;
00098     HFFPRange displayedLineRange;
00099     NSUInteger bytesPerLine;
00100     NSUInteger bytesPerColumn;
00101     NSFont *font;
00102     CGFloat lineHeight;
00103     
00104     NSUInteger currentPropertyChangeToken;
00105     NSMutableArray *additionalPendingTransactions;
00106     HFControllerPropertyBits propertiesToUpdateInCurrentTransaction;
00107     
00108     NSUndoManager *undoManager;
00109     NSMutableSet *undoOperations;
00110     HFControllerCoalescedUndo *undoCoalescer;
00111     
00112     unsigned long long selectionAnchor;
00113     HFRange selectionAnchorRange;
00114     
00115     CFAbsoluteTime pulseSelectionStartTime, pulseSelectionCurrentTime;
00116     NSTimer *pulseSelectionTimer;
00117     
00118     
00119     HFRange cachedRange;
00120     NSData *cachedData;
00121     NSUInteger cachedGenerationIndex;
00122     
00123     struct  {
00124         unsigned antialias:1;
00125         unsigned overwriteMode:1;
00126         unsigned editable:1;
00127         unsigned selectable:1;
00128         unsigned selectionInProgress:1;
00129         unsigned shiftExtendSelection:1;
00130         unsigned commandExtendSelection:1;
00131         unsigned reserved1:25;
00132         unsigned reserved2:32;
00133     } _hfflags;
00134 }
00135 
00141 - (NSArray *)representers;
00142 
00144 - (void)addRepresenter:(HFRepresenter *)representer;
00145 
00147 - (void)removeRepresenter:(HFRepresenter *)representer;
00148 
00150 
00158 - (NSUInteger)beginPropertyChangeTransaction;
00159 
00161 - (void)endPropertyChangeTransaction:(NSUInteger)token;
00163 
00168 - (void)setByteArray:(HFByteArray *)val;
00169 
00171 - (HFByteArray *)byteArray;
00172 
00174 - (void)replaceByteArray:(HFByteArray *)newArray;
00176 
00182 - (unsigned long long)totalLineCount;
00183 
00185 - (NSUInteger)bytesPerLine;
00186 
00188 - (CGFloat)lineHeight;
00189 
00191 
00195 
00196 
00198 - (void)pulseSelection;
00199 
00201 - (double)selectionPulseAmount;
00203 
00207 
00208 
00210 - (NSArray *)selectedContentsRanges;
00211 
00218 - (void)setSelectedContentsRanges:(NSArray *)selectedRanges;
00219 
00221 - (IBAction)selectAll:(id)sender;
00222 
00224 - (unsigned long long)minimumSelectionLocation;
00225 
00227 - (unsigned long long)maximumSelectionLocation;
00228 
00230 - (HFByteArray *)byteArrayForSelectedContentsRanges;
00232 
00236 
00237 - (void)setBytesPerColumn:(NSUInteger)val;
00238 
00239 
00240 - (NSUInteger)bytesPerColumn;
00242 
00246 
00248 - (BOOL)inOverwriteMode;
00249 
00251 - (void)setInOverwriteMode:(BOOL)val;
00252 
00254 - (BOOL)requiresOverwriteMode;
00255 
00257 
00261 
00267 - (HFFPRange)displayedLineRange;
00268 
00270 - (void)setDisplayedLineRange:(HFFPRange)range;
00271 
00273 - (void)maximizeVisibilityOfContentsRange:(HFRange)range;
00274 
00276 - (void)centerContentsRange:(HFRange)range;
00277 
00279 
00285 - (NSFont *)font;
00286 
00288 - (void)setFont:(NSFont *)font;
00289 
00294 
00296 - (void)setUndoManager:(NSUndoManager *)manager;
00297 
00299 - (NSUndoManager *)undoManager;
00300 
00302 
00308 - (BOOL)editable;
00309 
00311 - (void)setEditable:(BOOL)flag;
00313 
00318 - (BOOL)shouldAntialias;
00319 
00321 - (void)setShouldAntialias:(BOOL)antialias;
00323 
00330 - (void)representer:(HFRepresenter *)rep changedProperties:(HFControllerPropertyBits)properties;
00332 
00337 - (void)beginSelectionWithEvent:(NSEvent *)event forByteIndex:(unsigned long long)byteIndex;
00338 
00340 - (void)continueSelectionWithEvent:(NSEvent *)event forByteIndex:(unsigned long long)byteIndex;
00341 
00343 - (void)endSelectionWithEvent:(NSEvent *)event forByteIndex:(unsigned long long)byteIndex;
00344 
00349 - (void)scrollWithScrollEvent:(NSEvent *)scrollEvent;
00350 
00352 - (void)scrollByLines:(long double)lines;
00353 
00355 
00366 - (void)moveInDirection:(HFControllerMovementDirection)direction byByteCount:(unsigned long long)amountToMove withSelectionTransformation:(HFControllerSelectionTransformation)transformation usingAnchor:(BOOL)useAnchor;
00367 
00369 - (void)moveInDirection:(HFControllerMovementDirection)direction withGranularity:(HFControllerMovementGranularity)granularity andModifySelection:(BOOL)extendSelection;
00370 - (void)moveToLineBoundaryInDirection:(HFControllerMovementDirection)direction andModifySelection:(BOOL)extendSelection;
00371 
00375 
00382 - (BOOL)insertByteArray:(HFByteArray *)byteArray replacingPreviousBytes:(unsigned long long)previousByteCount allowUndoCoalescing:(BOOL)allowUndoCoalescing;
00383 - (BOOL)insertData:(NSData *)data replacingPreviousBytes:(unsigned long long)previousByteCount allowUndoCoalescing:(BOOL)allowUndoCoalescing;
00384 
00386 - (void)deleteSelection;
00387 
00389 - (void)deleteDirection:(HFControllerMovementDirection)direction;
00390 
00392 
00397 - (NSData *)dataForRange:(HFRange)range;
00398 
00400 - (void)copyBytes:(unsigned char *)bytes range:(HFRange)range;
00401 
00403 - (HFByteRangeAttributeArray *)byteRangeAttributeArray;
00404 
00406 - (HFByteRangeAttributeArray *)attributesForBytesInRange:(HFRange)range;
00407 
00409 - (HFRange)rangeForBookmark:(NSInteger)bookmark;
00410 
00412 - (void)setRange:(HFRange)range forBookmark:(NSInteger)bookmark;
00413 
00415 - (NSIndexSet *)bookmarksInRange:(HFRange)range;
00416 
00418 - (unsigned long long)contentsLength;
00419 
00424 + (BOOL)prepareForChangeInFile:(NSURL *)targetFile fromWritingByteArray:(HFByteArray *)array;
00425 
00427 - (BOOL)clearUndoManagerDependenciesOnRanges:(NSArray *)ranges inFile:(HFFileReference *)reference hint:(NSMutableDictionary *)hint;
00429 
00430 @end
00431 
00434 extern NSString * const HFControllerDidChangePropertiesNotification;
00435 
00439 extern NSString * const HFControllerChangedPropertiesKey; 
00440 
00441 
00445 extern NSString * const HFPrepareForChangeInFileNotification;
00446 
00450 extern NSString * const HFChangeInFileByteArrayKey; 
00451 extern NSString * const HFChangeInFileModifiedRangesKey; 
00452 extern NSString * const HFChangeInFileShouldCancelKey; 
00453 extern NSString * const HFChangeInFileHintKey; 
00454