Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!fas-news.harvard.edu!newspump.wustl.edu!news.ecn.bgu.edu!vixen.cso.uiuc.edu!howland.reston.ans.net!ix.netcom.com!netcom.com!sehyo
From: sehyo@netcom.com (Sehyo Chang)
Subject: Re: [VW2] Detect mouse moving over a widget
Message-ID: <sehyoDFDoBK.3qK@netcom.com>
Organization: NETCOM On-line Communication Services (408 261-4700 guest)
X-Newsreader: TIN [version 1.2 PL1]
References: <43uqv7$ake@vixen.cso.uiuc.edu> <DFC5n4.Cpn@cunews.carleton.ca>
Date: Sat, 23 Sep 1995 21:42:55 GMT
Lines: 78
Sender: sehyo@netcom20.netcom.com

Dave Buck (dbuck@superior.carleton.ca) wrote:
: In article <43uqv7$ake@vixen.cso.uiuc.edu>, longdj  <longdj@aol.com> wrote:
: >Hello,
: >
: >Does anyone have an idea on how to detect if the mouse pointer has moved over
: >a widget?  I want to be able to detect that the user has moved the mouse to a
: >pushbutton (but hasn't pushed it yet) so I can display some help on a status line
: >or wherever.
: >
: >Is this possible?  Any help/pointers would be appreciated.

: In VisualWorks, anything is possible.  You just have to decide how
: much work you want to go through to do it.

: In response to your question, you could try something like this:

: 1) Create a new instance variable.  Here, I've called it
: statusLinePoller.

: 2) In a postOpenWith method, create a block to run at background
: priority.  This block scans through all the views on this window to
: see if they contain the cursorPoint.  If so, it writes some text into
: the status line.  In this example, I just wrote the label of the
: widget into a static label on the window:

: postOpenWith: aBuilder
:     statusLinePoller := [
:         [true] whileTrue: [  | point viewSpecWrapper string |
:             self builder window isActive ifTrue: [
:                 point := self builder window sensor cursorPoint.
:                 viewSpecWrapper := self builder namedComponents
:                     detect: [:wrapper | wrapper containsPoint: point]
:                     ifNone: [nil].
:                 viewSpecWrapper isNil
:                     ifTrue: [string := '']
:                     ifFalse: [string := view spec name asString].
:                 (self builder componentAt: #labelID) labelString: string]]]
:         forkAt: Processor userBackgroundPriority

: 3) You need to terminate the process you started.  As far as I know,
: you can do this by implemeting a noticeOfWindowClose: method for the
: ApplicationModel subclass you are creating:

:  noticeOfWindowClose: aWindow 
:      statusLinePoller terminate.

: This technique could be cleaned up by putting the stuff inside the
: block into a separate method.  You should also keep track of the
: string that's currently in the status line and not change it if it
: doesn't need to be changed.

: This technique can also be extended to map the label strings to real
: help strings.  I'll leave that as an exercise to the reader :-).

: If anybody else has a better way to do this or takes objection to my
: use of builders and spec wrappers, I'd love to hear your alternatives
: (no sarcasm intended).

Here's solution #2:

Subclass ApplicationStandardSystemController ;
override controlActivity replace with method similar to above to
detect widgets. You may have to fiddles with keyboard processor.

In your application model;

postOpenWith: aBuilder

	super postOpenWidth: aBuilder.
	aBuilder window controller: (UserAplicationStdardSystemController new).


pluses:	no processes to manage.
minuses: additional classes 

-- sehyo chang


