|
|
1.1 ! root 1: /* ! 2: CommandScroll.m ! 3: by Joe Freeman ! 4: Subprocess Example, Release 2.0 ! 5: NeXT Computer, Inc. ! 6: ! 7: You may freely copy, distribute and reuse the code in this example. ! 8: NeXT disclaims any warranty of any kind, expressed or implied, as to ! 9: its fitness for any particular use. ! 10: */ ! 11: ! 12: #import "CommandScroll.h" ! 13: #import <appkit/nextstd.h> ! 14: #import <appkit/Font.h> ! 15: #import <appkit/Text.h> ! 16: ! 17: @implementation CommandScroll ! 18: ! 19: - initFrame:(const NXRect *)frameRect ! 20: { ! 21: [super initFrame:frameRect]; ! 22: [self setVertScrollerRequired: YES]; ! 23: [self setBackgroundGray: NX_WHITE]; ! 24: [self awake]; ! 25: return self; ! 26: } ! 27: ! 28: - awake ! 29: // these initializations implemented here so that this object can be ! 30: // made an IB palatte more easily ! 31: { ! 32: NXRect textRect; ! 33: id theText; ! 34: ! 35: textRect.origin.x = textRect.origin.y = 0.0; ! 36: [self getContentSize: &(textRect.size)]; ! 37: theText = ! 38: [[Text alloc] ! 39: initFrame: &textRect text:NULL alignment: NX_LEFTALIGNED]; ! 40: [theText notifyAncestorWhenFrameChanged:YES]; ! 41: [theText setHorizResizable:NO]; ! 42: [theText setVertResizable:YES]; ! 43: ! 44: textRect.size.width = 0.0; ! 45: [theText setMinSize:&(textRect.size)]; ! 46: [self getContentSize: &(textRect.size)]; ! 47: textRect.size.height = 1000000; ! 48: [theText setMaxSize:&(textRect.size)]; ! 49: ! 50: [[theText superview] setAutoresizeSubviews:YES]; ! 51: [[theText superview] setAutosizing: NX_HEIGHTSIZABLE | NX_WIDTHSIZABLE]; ! 52: ! 53: [theText setCharFilter: NXFieldFilter]; ! 54: [theText setMonoFont:FALSE]; ! 55: [self setDocView: theText]; ! 56: machineFont = [Font newFont:"Ohlfs" size:12]; ! 57: userFont = [Font newFont:"Courier-Bold" size:13]; ! 58: return self; ! 59: } ! 60: ! 61: - setDocView:anObject ! 62: { ! 63: [super setDocView:anObject]; ! 64: docView = anObject; ! 65: [docView setDelegate:self]; ! 66: return self; ! 67: } ! 68: ! 69: /*========================================================== ! 70: * ! 71: * New method for subclass ! 72: * ! 73: *==========================================================*/ ! 74: ! 75: - appendString:(char *)buffer ! 76: // append the buffer to the end of the text object ! 77: { ! 78: [docView setSel:[docView textLength] :0]; ! 79: [docView setSelFont:machineFont]; ! 80: [docView replaceSel:buffer]; ! 81: [docView scrollSelToVisible]; ! 82: lastTextCount = [docView textLength]; ! 83: return self; ! 84: } ! 85: ! 86: /*========================================================== ! 87: * ! 88: * Text Object Delegation ! 89: * ! 90: *==========================================================*/ ! 91: ! 92: - (BOOL)textWillChange:textObject ! 93: // moving the selection to the end before the change means the keys ! 94: // the user hits will always appear at the end of the scroll view ! 95: { ! 96: [docView setSel:[docView textLength] :0]; ! 97: [docView setSelFont:userFont]; ! 98: [docView scrollSelToVisible]; ! 99: return NO; ! 100: } ! 101: ! 102: - textDidEnd:textObject endChar:(unsigned short)whyEnd ! 103: // Get this on every Return if using NXFieldFilter ! 104: // really simplistic. Assumes user does not type ahead ! 105: { ! 106: [docView setSel:[docView textLength] :0]; ! 107: [docView replaceSel: "\n"]; ! 108: lastTextCount = [docView textLength]; ! 109: if (delegate && [delegate respondsTo:@selector(userEntered:)]) ! 110: [delegate perform:@selector(userEntered:) with:(void *)"\n"]; ! 111: return self; ! 112: } ! 113: ! 114: - textDidGetKeys:textObject isEmpty:(BOOL)flag ! 115: // Send each character as it is entered. ! 116: // The delta calculation is in case the user has backspaced. ! 117: { ! 118: int delta; // the difference in this length from previous ! 119: int theLength; // current length of text object ! 120: char *theText, miniBuffer[2]; ! 121: BOOL mallocedTheText = NO; ! 122: ! 123: theLength = [docView textLength]; ! 124: delta = theLength - lastTextCount; ! 125: if (delta > 0) ! 126: { ! 127: theText = (char *)malloc(delta + 1); ! 128: mallocedTheText = YES; ! 129: [docView ! 130: getSubstring:theText ! 131: start:([docView textLength]-delta) ! 132: length:delta]; ! 133: theText[delta] = '\0'; ! 134: } ! 135: else ! 136: { ! 137: theText = miniBuffer; ! 138: strcpy(theText,"\177"); ! 139: } ! 140: if (delegate && [delegate respondsTo:@selector(userEntered:)]) ! 141: [delegate perform:@selector(userEntered:) with:(void *)theText]; ! 142: lastTextCount = theLength; ! 143: ! 144: if (mallocedTheText) { ! 145: free(theText); ! 146: } ! 147: ! 148: return self; ! 149: } ! 150: ! 151: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.