Enage and Select
[1/6] from: mattsmac::hotmail::com at: 17-Sep-2003 9:09
OK, so it looks like then that when I make an engage function locally, it
takes precidence over the global one. Isn't there a way to extend the area
object to include the functionality that I need and not totally reject the
original functions? Isn't that the whole idea behind OOP?
Matt
_________________________________________________________________
Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.
[2/6] from: rotenca:telvia:it at: 17-Sep-2003 16:10
Try:
l: layout [b: button "test" [print "action code"]]
b/feel: make b/feel [
old-engage: :engage
engage: func [face action event][
print action
old-engage face action event
]
]
view l
You can also make it a style (a new reusable object):
l: layout [
style new-button button feel [
old-engage: :engage
engage: func [face action event][
print action
old-engage face action event
]
]
new-button "test1" [print "action code 1"]
new-button "test2" [print "action code 2"]
]
view l
---
Ciao
Romano
[3/6] from: mattsmac:h:otmail at: 17-Sep-2003 10:36
But what if I want to extend the functionality of a specific handler?
for instance, if I wanna keep the highlighting functionality, and also have
auto-scroll when the user clicks and drags off the face? Both would be
handled by the over and away actions. If I'm reading the last responce to
this correctly, the idea is to copy the old engage function into a new
function, then make a new engage function. Then call the appropriate engage
function based on the action you are trying to handle. Am I right? Is this
possible, or am I just asking too much?
Matt
_________________________________________________________________
Get 10MB of e-mail storage! Sign up for Hotmail Extra Storage.
[4/6] from: greggirwin:mindspring at: 17-Sep-2003 9:44
Hi Matt,
MM> But what if I want to extend the functionality of a specific handler?
MM> for instance, if I wanna keep the highlighting functionality, and also have
MM> auto-scroll when the user clicks and drags off the face? Both would be
MM> handled by the over and away actions. If I'm reading the last responce to
MM> this correctly, the idea is to copy the old engage function into a new
MM> function, then make a new engage function. Then call the appropriate engage
MM> function based on the action you are trying to handle. Am I right? Is this
MM> possible, or am I just asking too much?
What Romano posted shows how you can create your own and then "pass
along" events to the original handler by calling it from your
function.
Depending on what you're doing, there may be issues with that approach.
This is not a REBOL thing, but applies to any system where you try to
inherit and extend functionality. The original code has no idea what
you're doing, so it expects things to be as they were. For example,
the swiping/highlighting code may expect the start position to be
visible on the screen, but if you drag down and auto-scroll, it isn't
anymore. There may be interactions that you have to account for
between your new stuff and what's there already. There may also be
times where you need to call the base function before or after your
code, but not always one or the other. That is, depending on what
you're doing, you may need to decide whether to do the work first, or
call the base function first and then do your work.
Of course, you can always try it and see what happens. Sometimes
things just magically seem to do what you want. :)
-- Gregg
[5/6] from: greggirwin:mindspring at: 17-Sep-2003 9:51
Hi Matt,
As an addendum, because of the way REBOL works, you can actually
access the code for the base function at runtime and modify it if you
want. i.e. if you use SECOND on a function, you get the body of the
function, which you can treat as data.
>> f: get in ctx-text/edit 'engage
>> b: second :f
== [
switch act [
down [
either not-equal? face view*/focal-face [
focus face
...
>> b/act/over
== [
if not-equal? view*/caret offset-to-caret face event/offset [
if not view*/highlight-start [view*/highlight-start:...
REBOL will let you do almost anything you want. This amount of
flexibility means you sometimes need to think about how you really
want to do things, because there is not just one way in most cases.
-- Gregg
[6/6] from: mattsmac:h:otmail at: 17-Sep-2003 11:56
Thanks Gregg, I think that'll do it, the first method.
Matt
_________________________________________________________________
Fast, faster, fastest: Upgrade to Cable or DSL today!