This is ActionLine.m in view mode; [Download] [Up]
/*--------------------------------------------------------------------------------- An abstract class for lines. HISTORY 22Mar93 DM Works with colors, sort of. 9mar93 DM New ---------------------------------------------------------------------------------*/ #import <dpsclient/wraps.h> #import <appkit/ActionCell.h> #import <objc/List.h> #import "ActionLine.h" #import "line.h" // really line.psw @implementation ActionLine + initialize; { PSInit(); // fire up some ps things for line drawing return self; } -initFrame:(NXRect*)theFrame title:(const char *)aString tag:(int)anInt target:anObject action:(SEL)aSelector key:(unsigned short)charCode enabled:(BOOL)flag; { /*--------------------------------------------------------------------------------- Designated initializer. Get everything set up as we want it. ---------------------------------------------------------------------------------*/ self = [super initFrame:theFrame title:aString tag:anInt target:anObject action:aSelector key:charCode enabled:flag]; lineWidth = 2.0; enabledColor = NX_COLORBLACK; disabledColor = NX_COLORDKGRAY; startArrow = NO; endArrow = NO; [self setTransparent:YES]; return self; } - (const char*)inspectorName { /*--------------------------------------------------------------------------------- The name of the class that is our inspector. Used by IB to figure out what to load when we're inspected. ---------------------------------------------------------------------------------*/ return "LinesInspector"; } - setLineWidth:(float)pLineWidth; { lineWidth = pLineWidth; return self; } - setEnabledColor:(NXColor)pLineColor; { enabledColor = pLineColor; return self; } - setDisabledColor:(NXColor)pLineColor; { disabledColor = pLineColor; return self; } - setEndArrow:(BOOL)pOn; {endArrow = pOn; return self; } - setStartArrow:(BOOL)pOn; {startArrow = pOn; return self; } - (float)lineWidth; { return lineWidth;} - (NXColor)enabledColor; {return enabledColor; } - (NXColor)disabledColor; {return disabledColor; } - (BOOL)endArrow; { return endArrow; } - (BOOL)startArrow; { return startArrow; } - passOnEvent:(NXEvent*)theEvent; // Pass on the event if the mouseDown missed the line { /*-------------------------------------------------------------------------------- The event missed the lines in the view. This is potenitially serious; eg, we might have a diagonal line. If we miss the line but still hit the (always rectangular) view, we might unintentionally catch and not release events intended for UI objects people can see underneath us. So the button would never click. Just lateralling to the next responder isn't cool, since it's probably a content view and just terminates in the window object. Probably wouldn't find a mouseDown: interesting anyway. This gets the superview, then takes a trip trough the subview list looking for (1) something that isn't us, and (2) something that has a frame rectangle within the mouseDown. Not foolproof, but OK. --------------------------------------------------------------------------------*/ View *ourSuperview, *siblingView; // our superview, one of our brother subviews List *brotherViews; // No, not a quaker. the subviews of our superview NXPoint hitPoint; // mouse down location in our superview's coord system NXRect siblingFrame; int i; BOOL foundSibling = NO; ourSuperview = [self superview]; brotherViews = (List*)[ourSuperview subviews]; for(i = 0; i < [brotherViews count]; i++) { siblingView = [brotherViews objectAt:i]; if(siblingView == self) // Not me, nope continue; // event location originally in window base coords; convert it to our // super view's coords. hitPoint = theEvent->location; [ourSuperview convertPoint:&hitPoint fromView:nil]; [siblingView getFrame:&siblingFrame]; if(NXMouseInRect(&hitPoint, &siblingFrame, NO)) { [siblingView mouseDown:theEvent]; // Found another subview under us? try sending to it. foundSibling = YES; break; } } // end of loop thru subviews if(!foundSibling) // didn't find it? send it on the the superview, most likely [nextResponder mouseDown:theEvent]; return self; } - read:(NXTypedStream*)stream; // Need these to get draw & drop from IB working { [super read:stream]; NXReadType(stream, "f", &lineWidth); enabledColor = NXReadColor(stream); disabledColor = NXReadColor(stream); NXReadType(stream, "c", &endArrow); NXReadType(stream, "c", &startArrow); return self; } - write:(NXTypedStream*)stream; { [super write:stream]; NXWriteType(stream, "f", &lineWidth); NXWriteColor(stream, enabledColor); NXWriteColor(stream, disabledColor); NXWriteType(stream, "c", &endArrow); NXWriteType(stream, "c", &startArrow); return self; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.