Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Event datatype

From: gscottjones:mchsi at: 29-Aug-2002 10:35

Hi, Carl, From: "Carl Read"
> On 29-Aug-02, G. Scott Jones wrote: > > If you have not found your answer, can you give > > more detail, like are you looking to modify the event/key for a > > widget like "field"? > > Yes, something like that. I'm intercepting an event before it reaches > a function that normally gets it so I can do some stuff first based > on whatever the event is. I then pass it on to that function, or not > if because of the event it doesn't need to be called. But that's the > only choice I have - either send the event as is, or not send it. In > some cases I'd like to be able to modify the key value in event and > send that on, but it seems there's no way to do this. There's a > convoluted way I can get around this, but it'd be so much simplier to > just do something like... > > event/key: #"Z" > event-function face event action > > It's not a show-stopper though...
That is some neat stuff that Cyphre uncovered. I wasn't able to take it any further than he did. Previously, I developed a way to screen events to a specific widget, like used to restrict key stroke types. It sounds like you need something at the more global level. I, too, have found no "easy" way to do this, but I did expand a concept developed by Brett last year. Here is an example to play with: REBOL [] query-before-passing-on: func [face event][ switch/default event/type [ close [ either not within? system/view/focal-face/offset win-offset? f f/size [ print "no way can you exit unless focus is on first field" return none ][ remove-event-func :query-before-passing-on event ] ] key [ either not within? system/view/focal-face/offset win-offset? f f/size [ print "only taking key presses in first field" return none ][ event ] ] ] [event] ] view layout [ text "Close button only works while focus is on first field" text "Key presses only accepted in first field" f: field field do [insert-event-func :query-before-passing-on ] ] This may happen to be just the sort of convoluted thing you hoped to avoid, but it (mostly) works. Maybe with a little tuning it could work well! The key to this structure is that it keeps passing the event on, if the chain is not interrupted. What I haven't been able to do is to alter the event and then pass it on. Side Moan: I really miss binding to events like as is done in other languages, like Tcl. --Scott Jones