[comp.windows.open-look] Getting focus notification in TNT2.0 Beta

bmacinty@mud.waterloo.edu (Blair MacIntyre) (04/09/91)

I'm writing a window class (subclass of ClassBaseWindow) and I want
to be notified when the window gets/loses the focus.

I've been trying various things for most of the evening (and night)
and cannot seem to get it to work.

From poking around in the classes, I came to the conclusion that 
what I want to do is activate FocusNoticeService (ClassBag) and
override HandleFocusNotice in my class.  I should then get events
of type AcceptFocus, RestoreFocus and LoseFocus. 

So, I tried setting a Class variable FocusNoticeable? to true.
Nothing.

I tried calling setfocusnoticeable with a true parameter.
Nothing.

I know that I'm activating the window (I'm testing things with a 
simple program based on the manual.colors demo) so active in 
ClassBag should be being called, which means the Focus should be
being activated.

The HandleFocusNotice function is just not being called.  Period.

Questions:  am I missing something obvious?  I managed to get
	TrackCrossing events (EnterEvent, ExitEvent) using a similar
	approach.

	    is this the right way to get focus events?  Is there
	another way?  Is there any way?

Help!
-- 
Blair MacIntyre, Computer Graphics Lab
Dept. of Computer Science, University of Waterloo, Waterloo, ON, Canada, N2L3G1
{bmacintyre@{watcgl|violet|watdragon}}.{waterloo.edu|uwaterloo.ca}

bmacinty@mud.waterloo.edu (Blair MacIntyre) (04/10/91)

In article <1991Apr9.062834.19405@watcgl.waterloo.edu>, 
bmacinty@mud.waterloo.edu (Me) wrote:
> I'm writing a window class (subclass of ClassBaseWindow) and I want
> to be notified when the window gets/loses the focus.
> 
> I've been trying various things for most of the evening (and night)
> and cannot seem to get it to work.

I got a number of replies, the first of which came mear hours after
I posted my message.  

From: fritz@triguy.East.Sun.COM (Steve Fritzinger - SE Sun Washington)
------------------
Try using /Keyable? and the Key methods in ClassCanvas.  Take a look
at page 55 in the Beta TNT manual.

Here's a code fragment that works for me.

/FooCanvas ClassCanvas
[]
classbegin
    /Keyable? true def

    % Called whenever canvas gets focus.  Event name is either
    % /AcceptFocus or /RestoreFocus.
    /KeyStart { % event => [/StandardKey] true
        pop
        [/StandardKey] true
    } def

    % Called for each key stroke.  Event name = key pressed.
    /StandardKey { % event => -
        % What ever you want to do with the event.
    } def

    % Called when canvas loses focus.
    /KeyStop { % event => -
        pop
    } def
classend def
------------------

He also replied to my subsequent mail with this piece of advice, which
I'm passing on because I think it may be helpful to others ...

From: fritz@triguy.East.Sun.COM (Steve Fritzinger - SE Sun Washington)
------------------
It takes a little playing around to get used to the way TNT does things.
Basically, TNT works at a much higher and more abstract level
then X toolkits usually do.  This is a perfect example.

You really don't care about TrackCrossing events, or any of the other
underlaying implementation stuff, you just want something to happen
when you get or lose focus.  So when you define /KeyStart you're
telling the server "Do this when I get focus.  Take care of creating
and expressing any events you need to, I don't care.  Don't bother
me with implementation details."

So TNT let's you say what should be done, without worrying about
how to know when to do it.  No more event masks, or interests lists,
just application specific code.

By the way, TNT is out of beta and in now available.  It fixes several
obvious bugs and has some performance improvements.

Also if you haven't yet, you should dissect the rap demo.  That 700
lines of code is a gold mine of great ideas.
------------------
-- 
Blair MacIntyre, Computer Graphics Lab
Dept. of Computer Science, University of Waterloo, Waterloo, ON, Canada, N2L3G1
{bmacintyre@{watcgl|violet|watdragon}}.{waterloo.edu|uwaterloo.ca}