🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.interviews
Article #185

Problem with event processing and ActiveHandler

#185
From: jdf
Date: Thu, 06 Aug 1992 17:44
83 lines
3147 bytes
I have a problem in a container glyph which tries to filter events
sent to subglyphs. Specifically, I want to filter down events and pass
all other events. I have written the following code:

void MLayer::pick(Canvas* c, const Allocation& a, int depth, Hit& h) {
    if (h.event() == nil || h.event()->type() != Event::down) {
	MonoGlyph::pick(c, a, depth, h);
	return;
    }

    Hit hit(h.left(), h.bottom(), h.right(), h.top());
    MonoGlyph::pick(c, a, 0, hit);
    if (hit.any()) {
	h.target(depth, this, 0, impl_);
    }
}

Everything works fine except when I insert an ActiveHandler because it
grabs the events when it receives a move event and ungrabs it only
when the mouse leaves the allocation of the ActiveHandler. Actually,
buttons returned by the WidgetKits are ActiveHandler.

Is there a better way to filter events and to avoid the grabbing?

I realized that the only reason to grab the events is to fake
enter/leave events. I think InterViews should provide a better
solution than grabbing for such stereotyped controls.

I am not sure of the implications but I have thought of a possible way
to fake focus_in/focus_out events which could be implemented easily in
InterViews: add a focus_in and focus_out method to handlers. By
default, it would do nothing. 

class Handler : public Resource {
protected:
    Handler();
    virtual ~Handler();
public:
    virtual boolean event(Event&) = 0;
    virtual boolean focus_in(Event&);
    virtual boolean focus_out(Event&);
};

Then, change the method Event::handle to do something like the
following:

void Event::handle() {
    Handler* h = grabber();
    if (h == nil) {
	h = handler();
    }
    if (h != nil) {
	boolean b = Resource::defer(true);
	Handler* old_h = <get the previous handler from the display>;
	if (old_h != h) {
	    if (old_h != nil) {
		old_h->focus_out(*this);
		old_h->unref();
	    }
	    h->ref();
	    <set the previous handler in the display to h>;
	    h->focus_in(*this);
	}
	// we are sure that the handler is referenced now
	// h->ref(); 
	h->event(*this);
	// h->unref();
	// Resource::flush();
	// Resource::defer(b);
    }
}

This mechanism would allow ActiveHandlers to support focus_in and
focus_out events rather than enter/leave events but without grabbing.

   ___    0  Jean-Daniel Fekete            uucp  : jdf@lri.lri.fr
  /   \  /   LRI - Bat 490                 bitnet: jdf@FRLRI61.bitnet
 /   _/ /    Universite de Paris-Sud       voice : +33 (1) 69 41 65 91
/__   \/     F-91405 ORSAY Cedex                   +33 (1) 69 41 66 29

/^//-\/-\/|  2001 S.A.
 / | || | |  12, Impasse de la Madeleine   voice : +33 (1) 45 46 10 00
/_ \_/\_/ |  F-94230 CACHAN		     fax : +33 (1) 45 46 07 54
Technical Details
Message-ID: <9208061744.AA01523@sun8.lri.fr>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!lri.fr!jdf

Show Full Headers
Complete Article Headers
Newsgroups: comp.windows.interviews
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!lri.fr!jdf
From: jdf@lri.fr
Subject: Problem with event processing and ActiveHandler
Message-ID: <9208061744.AA01523@sun8.lri.fr>
Sender: news@shelby.stanford.edu (USENET News System)
Organization: Internet-USENET Gateway at Stanford University
Date: Thu, 6 Aug 1992 17:44:17 GMT
Lines: 83