DWT event handling
Bill Baxter
dnewsgroup at billbaxter.com
Sun May 18 16:58:03 PDT 2008
BLS wrote:
> Frank Benoit schrieb:
>> I added the template function Bill suggested once to the
>> dwt.widgets.Listener module.
>>
>> http://www.dsource.org/projects/dwt-linux/browser/dwt/widgets/Listener.d?rev=243%3A84629474b5ec
>>
>>
>> You can see that in action in this snippet
>> http://www.dsource.org/projects/dwt-samples/browser/snippets/treeeditor/Snippet111.d?rev=85%3Afa286c85e7b8
>>
>>
>> See lines: 102..106
>>
>> Thanks Bill for the snippets and for this cool template function
>> suggestion.
>>
>> Frank
>
> Hi Frank, thanks for the update !
>
> I still try to figure out how this code could fit ...
>
> template MessageMap(Mappings ...) {
> void addListener(uint uID) {
> foreach(mapping; Mappings) {
> if(mapping.matches(uID)) // DWTxxxx
> mapping.executeAction();
> }
> }
> }
>
> //maybe we need template specialisation here ???
>
>
> struct OnClose(alias fn) {
> alias fn executeAction;
> static bool matches(uint uid) { return uid == 5; }
> }
>
> struct OnRange(uint a, uint b, alias fn) {
> alias fn executeAction;
> static bool matches(uint uid) { return uid >= a && uid <= b; }
> }
>
>
> class Foo {
> void foo() {
> writefln("foo called");
> }
> void bar() {
> writefln("bar called");
> }
>
> mixin MessageMap!(
> OnClose!(foo),
> OnRange!(1, 3, bar)
> );
>
> }
>
> void main() {
> auto f = new Foo;
> f.addListener(5);
> f.addListener(2);
> }
>
> At least it looks simpler (to me) Ideas ? Bjoern
I don't get it. What's 5?
--bb
More information about the Digitalmars-d-dwt
mailing list