Listening to events


What is gtkD
sourceforge Page


gtkD Windows
gtkD Linux


Diffs to GTK
Class Hierarchy
Class Index
Class List


Site pages

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:
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);
onClick is another way of adding a delegate to the button click event
     button = new Button(Stock.CANCEL);
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:

  • mouse buttons
    • (EventButton) OnMouseButtonPress addOnMouseButtonPress
    • (EventButton) OnMouseButtonRelease;
  • scroll
    • (EventScroll) OnScroll;
  • motion
    • (EventMotion) OnMotionNotify;
  • delete
    • (Event) OnDelete;
    • (Event) OnDestroy;
  • expose
    • (EventExpose) OnExpose;
  • key
    • (EventKey) OnKeyPress;
    • (EventKey) OnKeyRelease;
  • enter
    • (EventCrossing) OnEnterNotify;
    • (EventCrossing) OnLeaveNotify;
  • configure
    • (EventConfigure) OnConfigure;
  • focus
    • (EventFocus) OnFocusIn;
    • (EventFocus) OnFocusOut;
  • map
    • (Event) OnMap;
    • (Event) OnUnmap;
  • realize
    • (Event) OnRealize;
    • (Event) OnUnrealize;
  • property
    • (EventProperty) OnPropertyNotify;
  • selection
    • (EventSelection) OnSelectionClear;
    • (EventSelection) OnSelectionRequest;
    • (EventSelection) OnSelectionNotify;
  • proximity
    • (EventProximity) OnProximityIn;
    • (EventProximity) OnProximityOut;
  • visibility
    • (EventVisibility) OnVisibilityNotify;
  • cliente
    • (EventClient) OnClient;
  • no expose
    • (Event) OnNoExpose;
  • window state
    • (EventWindowState) OnWindowState; Logo Logo Logo