WID comments
[Lilanci.git] / widget.c
blobca83adc6150403653f89a38ba719a94effd386c5
1 #include "widget.h"
2 #include <string.h>
5 int HandleEvent(TWidget *widget, char event[EVENT_LENGHT], void *data){
6 TEventHandler *eh;
8 eh = widget->handlers;
9 while(eh != 0){
10 if(strncmp(event, eh->event, EVENT_LENGHT) == 0)
11 return eh->handler(widget, data, eh->userdata);
12 eh = eh->next;
15 return 0;
18 void AddHandler(TWidget *widget char event[EVENT_LENGHT], int (*handler)(TWidget *widget, void *data, void *userdata), void *userdata){
19 TEventHandler *eh;
21 eh = malloc(sizeof(TEventHandler));
22 memset(eh, 0, sizeof(TEventHandler)); //TODO:check if this is valid for eh->event
23 strncpy(eh->event, event, EVENT_LENGHT);
24 eh->userdata = userdata;
25 eh->next = widget->handlers;
26 eh->handler = handler;
27 widget->handlers = eh;