Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!snorkelwacker.mit.edu!mit-eddie!uw-beaver!ubc-cs!majka From: majka@cs.ubc.ca (Marc Majka) Newsgroups: comp.sys.next Subject: Re: Customizing a ScrolView Message-ID: <1991Feb4.181319.4410@cs.ubc.ca> Date: 4 Feb 91 18:13:19 GMT References: Sender: news@cs.ubc.ca (Usenet News) Distribution: na Organization: UBC Department of Computer Science, Vancouver, B.C., Canada Lines: 56 scott@sage.uchicago.edu (Scott Deerwester) writes: >I wonder if anybody out there can help me with a problem. I'm trying >to customize a ScrollView so that when I hit the mouse inside, it >selects an entire line (something like the summary window of the Mail >application) rather than characters within the line. So I wrote a >class called Lines and overrode the - setSel method thus: I solved this problem by subclassing Text. My custom text object gets attached as the ScrollView's DocView. (Actually, it is the ScrollView's ClipViews's DocView, but let's not get technical, shall we :-). Anyway, the idea is this: My text object redefines mouseDown: as shown - mouseDown:(NXEvent *)event { NXPoint myPt = event->location; [super mouseDown :event]; [self convertPoint :&myPt fromView :nil]; [TheWatcher mouseSelected :&myPt]; return self; } TheWatcher is the object that is doing all the work. It catches appDidInit (it is the Application's delegate), and sends my text object its id with the message [TheText setWatcher :self]. The text object's method is just: - setWatcher:sender { TheWatcher = sender; return self; } Anyway, whenever the DocView gets a mouseDown, it tells my Watcher where it hit. The Watcher selects the line with something like the method below. It determines the location of the selected line by dividing the y location of the mouseDown by the line height of the text. Since my application is managing fixed length lines, it just multiplies by line length to determine the text position. You will need to do something different if your line lengths vary. - mouseSelected:(NXPoint *)pt { int line, locn; line = pt->y / [TheText lineHeight]; locn = line * LINELENGTH; [TheText setSel :locn :(locn + LINELENGTH)]; return self; } Hope this helps! --- Marc Majka System Manager - UBC Computer Science