This is MiscSearcher.m in view mode; [Download] [Up]
//
// Hugh Ashton - hugh@furuike.twics.com - Feb 95
// Copyright under the terms and conditions of the MiscKit
// Version 1.1. All rights reserved.
//
// This notice may not be removed from this source code.
//
// This object is included in the MiscKit by permission from the author
// and its use is governed by the MiscKit license, found in the file
// "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
// for a list of all applicable permissions and restrictions.
//
// This object allows a search to take place in more than one Text object
// simultaneously. It also allows searching without having to press the
// Return key after each search string.
//
// It is inited with the initWithField:anObject andTarget:anotherObject
// method, where anObject is Text (not a TextField) and anotherObject is
// a List of Text objects.
//
// Added dynamic sizing to the original[Start|End] arrays, minor tweaks
// -- Don Yacktman 4/13/95
//
#import <misckit/MiscSearcher.h>
@implementation MiscSearcher
- initWithField:anObject andList:anotherObject
{
int i;
[super init];
theSearcher=anObject;
[theSearcher setDelegate:self];
theList=anotherObject;
if (![theList isKindOfClassNamed:"List"] ||
![theSearcher isKindOfClassNamed:"Text"]) {
[self free];
return nil;
}
areWeSearching=NO;
if (originalStart) free(originalStart);
if (originalEnd) free(originalEnd);
originalStart = (int *)malloc(sizeof(int) * [theList count]);
originalEnd = (int *)malloc(sizeof(int) * [theList count]);
for (i=0;i<=[theList count];i++) {
originalStart[i]=0;
originalEnd[i]=0;
}
return self;
}
// delegate methods for theSearcher
- textDidGetKeys:sender isEmpty:(BOOL)flag
{
int i;
NXSelPt start,end;
char theString[MAXPATHLEN-1]="";
areWeSearching=YES;
for(i=0;i<=[theList count];i++)
{
theTarget=[theList objectAt:i];
if(flag)
{
[theTarget setSel:originalStart[i] :originalEnd[i]];
[theTarget setSelGray:NX_BLACK];
[theSearcher setSel:[theSearcher byteLength] :[theSearcher byteLength]];
areWeSearching=NO;
return self;
}
[theSearcher getSubstring:theString start:0 length:[theSearcher byteLength]];
if([theTarget findText:theString ignoreCase:NO backwards:NO wrap:YES])
{
[theTarget getSel:&start :&end];
[theTarget setSel:originalStart[i] :originalEnd[i]];
[theTarget setSelGray:NX_BLACK];
[theTarget setSel:start.cp :end.cp];
[theTarget setSelGray:NX_DKGRAY];
originalStart[i]=start.cp;
originalEnd[i]=end.cp;
[theTarget setSel:originalStart[i] :originalEnd[i]];
}
[theSearcher setSel:[theSearcher byteLength] :[theSearcher byteLength]];
}
areWeSearching=NO;
return self;
}
- forward:sender
{
int i;
NXSelPt start,end;
char theString[MAXPATHLEN-1]="";
areWeSearching=YES;
[theSearcher getSubstring:theString start:0 length:[theSearcher byteLength]];
for(i=0;i<=[theList count];i++)
{
theTarget=[theList objectAt:i];
if((strlen(theString))==0)
{
[theTarget setSel:originalStart[i] :originalEnd[i]];
[theTarget setSelGray:NX_BLACK];
[theSearcher setSel:[theSearcher byteLength] :[theSearcher byteLength]];
areWeSearching=NO;
return self;
}
[theTarget setSel:originalEnd[i] :originalEnd[i]];
if([theTarget findText:theString ignoreCase:NO backwards:NO wrap:YES])
{
[theTarget getSel:&start :&end];
[theTarget setSel:originalStart[i] :originalEnd[i]];
[theTarget setSelGray:NX_BLACK];
[theTarget setSel:start.cp :end.cp];
[theTarget setSelGray:NX_DKGRAY];
originalStart[i]=start.cp;
originalEnd[i]=end.cp;
[theTarget setSel:end.cp :end.cp];
}
[theSearcher setSel:[theSearcher byteLength] :[theSearcher byteLength]];
}
areWeSearching=NO;
return self;
}
- textDidEnd:sender endChar:(unsigned short)theChar
{
int i;
if(!areWeSearching)
{
[theSearcher setDelegate:nil];
// this stops us being interrupted while we clean up the target
for(i=0;i<=[theList count];i++)
{
theTarget=[theList objectAt:i];
[theTarget setSel:originalStart[i] :originalEnd[i]];
[theTarget setSelGray:NX_BLACK];
[theTarget setSel:originalStart[i]:originalEnd[i]];
}
// go back to being a good delegate
[theSearcher setDelegate:self];
// NXRunAlertPanel("We've set the SEL",NULL,"OK",NULL,NULL);
areWeSearching=YES;
}
return self;
}
- setTheField:anObject
{
theSearcher=anObject;
if(![theSearcher isKindOfClassNamed:"Text"])
{
return nil;
}
[theSearcher setDelegate:self];
areWeSearching=NO;
return self;
}
- setTheList:anObject
{
int i;
if(![theList isKindOfClassNamed:"List"])
{
return nil;
}
theList=anObject;
if (originalStart) free(originalStart);
if (originalEnd) free(originalEnd);
originalStart = (int *)malloc(sizeof(int) * [theList count]);
originalEnd = (int *)malloc(sizeof(int) * [theList count]);
for(i=0;i<=[theList count];i++)
{
originalStart[i]=0;
originalEnd[i]=0;
}
areWeSearching=NO;
return self;
}
// wrapper methods
- theList
{
return theList;
}
- theField
{
return theSearcher;
}
@end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.