Listening to events


Welcome

What is gtkD
Screenshots
sourceforge Page
Contacts

Downloads

gtkD Windows
gtkD Linux

Developers

Tutorial
Diffs to GTK
Events
Class Hierarchy
Class Index
Class List
OpenGL

Links

Site pages
Links
Acknowledgments

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:

  • 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;


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