HexWindow text boxes now synchro-scroll.

This commit is contained in:
Nicholas Shanks 2002-02-11 22:03:20 +00:00
parent e8c270d59d
commit 25ffdd2023
4 changed files with 51 additions and 16 deletions

View File

@ -16,12 +16,14 @@
id resource;
}
- (void)resourceDidChange:(NSNotification *)notification;
- (void)refreshData:(NSData *)data;
// conform to the ResKnifePluginProtocol with the inclusion of these methods
- (id)initWithResource:(id)newResource;
// normal methods
- (void)resourceDidChange:(NSNotification *)notification;
- (void)viewDidScroll:(NSNotification *)notification;
- (void)refreshData:(NSData *)data;
// accessors
- (id)resource;
- (NSData *)data;

View File

@ -13,12 +13,13 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
- (id)initWithResource:(id)newResource
{
self = [self initWithWindowNibName:@"HexWindow"];
if( self ) [self setWindowFrameAutosaveName:@"Hexadecimal Editor"];
if( !self ) return self;
// one instance of your principal class will be created for every resource the user wants to edit (similar to Windows apps)
resource = [newResource retain];
// load the window
[self setWindowFrameAutosaveName:@"Hexadecimal Editor"];
// [self setShouldCascadeWindows:YES];
[self window];
return self;
@ -38,6 +39,11 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
// we don't want this notification until we have a window!
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDidChange:) name:ResourceChangedNotification object:nil];
// put other notifications here too, just for togetherness
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[offset enclosingScrollView] contentView]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[hex enclosingScrollView] contentView]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:[[ascii enclosingScrollView] contentView]];
// insert the resources' data into the text fields
[self refreshData:[(id <ResKnifeResourceProtocol>)resource data]];
@ -52,6 +58,45 @@ NSString *ResourceChangedNotification = @"ResourceChangedNotification";
[self refreshData:[(id <ResKnifeResourceProtocol>)resource data]];
}
- (void)viewDidScroll:(NSNotification *)notification
{
// get object refs for increased speed
NSClipView *object = (NSClipView *) [notification object];
NSClipView *offsetClip = [[offset enclosingScrollView] contentView];
NSClipView *hexClip = [[hex enclosingScrollView] contentView];
NSClipView *asciiClip = [[ascii enclosingScrollView] contentView];
// due to a bug in -[NSView setPostsBoundsChangedNotifications:] (it basically doesn't work), I am having to work around it by removing myself from the notification center and restoring things later on!
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSViewBoundsDidChangeNotification object:nil];
// when a view scrolls, update the other two
if( object != offsetClip )
{
// [offsetClip setPostsBoundsChangedNotifications:NO];
[offsetClip setBoundsOrigin:[object bounds].origin];
// [offsetClip setPostsBoundsChangedNotifications:YES];
}
if( object != hexClip )
{
// [hexClip setPostsBoundsChangedNotifications:NO];
[hexClip setBoundsOrigin:[object bounds].origin];
// [hexClip setPostsBoundsChangedNotifications:YES];
}
if( object != asciiClip )
{
// [asciiClip setPostsBoundsChangedNotifications:NO];
[asciiClip setBoundsOrigin:[object bounds].origin];
// [asciiClip setPostsBoundsChangedNotifications:YES];
}
// restore notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:offsetClip];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:hexClip];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewDidScroll:) name:NSViewBoundsDidChangeNotification object:asciiClip];
}
- (void)refreshData:(NSData *)data;
{
// clear delegates (see HexEditorDelegate class for explanation of why)

View File

@ -2409,8 +2409,6 @@
F5EF83A1020C08E601A80001,
F5EF83A2020C08E601A80001,
F5EF83A3020C08E601A80001,
F5EF83A4020C08E601A80001,
F5EF83A5020C08E601A80001,
F5EF83A7020C08E601A80001,
F5EF83A8020C08E601A80001,
F5EF83C7020C20D701A80001,
@ -2441,16 +2439,6 @@
path = HexTextView.m;
refType = 4;
};
F5EF83A4020C08E601A80001 = {
isa = PBXFileReference;
path = HexWindow.h;
refType = 4;
};
F5EF83A5020C08E601A80001 = {
isa = PBXFileReference;
path = HexWindow.m;
refType = 4;
};
F5EF83A7020C08E601A80001 = {
isa = PBXFileReference;
path = HexWindowController.h;