Listening to events


DUI
D GTK+ binding

Welcome

What is DUI
Screenshots
sourceforge Page
Contacts

Downloads

DUI Windows
DUI Linux

Developers

Windows Tools
dool Impact
Tutorial
Diffs to GTK
Events
Class Hierarchy
Class Index
Class List
OpenGL

To do

roadmap
To do
Known Problems

Links

Site pages
Links
Acknowledgments

See the old (and still more complete) way of listening to events at
Old Listener interfaces

Warning:
Not all events are implemented.
Listening to Combo, Entry component for the second time will segfault the application.
Note:
DUITests still uses the listener interfaces to listen to events on most of it's examples
leds uses exclusivly delegates to listen to events.

Listening to events

You can now add a delegate to a widget to process the events on that widget.
Every widget class inherits the events from it's parent class.

To add a delegate to an event callback:
add<eventName>(delegate);
There is no way to remove a listener yet
on the future do remove<eventName>(delegate);

for instance a button has the events:

  • OnClick
  • OnButtonClicked
  • OnButtonPressed
  • OnButtonReleased
  • OnButtonEnter
  • OnButtonLeave
  • OnButtonActivate
  • plus the Bin events (none implemented)
  • plus the Container events (none implemented)
  • plus the Widget events (most implemented)

to add a delegate to these events:

  • button.addOnClick(&delegate);
  • button.addOnButtonClicked(&delegate);
  • button.addOnButtonPressed(&delegate);
  • button.addOnButtonReleased(&delegate);
  • button.addOnButtonEnter(&delegate);
  • button.addOnButtonLeave(&delegate);
  • button.addOnButtonActivate(&delegate);

all the delegates are:
void delegate(Button);
except for OnClick that is
void delegate()
(onClick and OnButtonClicked are callbacks to the same event)

OnClick special case
OnClick is a higher level callback to onButtonClicked
and has a more convenient usage:

  • buttons and menu items can be created with the onCLick delegate:
    • new Button(Stock.OK, &onOKClickDelegate);
    • new MenuItem("Stock.Exit, &onExitClickDelegate);
  • onClick is public so that it can be used like:
    • button.onClick +=
    • menuItem.onClick +=

here is an example for the common button click:

 void someFunction()
 {
     Button button;
     button = new Button(Stock.OK);
     buttonOK.addOnButtonClicked(&doOK);
onClick is another way of adding a delegate to the button click event
     button = new Button(Stock.CANCEL);
     button.addOnClick(&doCancel);
the onClick is public and can be used:
     button.onClick += doCancel;
the event delegate can be passed to the button constructor
     new Button("My Button", myButtonClicked);
     
 }
the OnButtonClicked delegate
 void doOK(Button button)
 {
     printf("button OK was clicked\n");
 }
the OnClick delegate
notice no parameters for the onCLick event
 void doCancel()
 {
     printf("button CANCEL was clicked\n");
 }

 void myButtonClicked()
 {
     printf("myButton was clicked\n");
 }

DUI events follow the GTK events
The implemented widget events are:


SourceForge.net Logo DSource.org Logo digitalmars.com Logo