Make it possible to get and set the user-data of event handlers.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5786 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
b8d25a33e2
commit
0440da3f48
|
@ -89,6 +89,35 @@ static bool widgetHasMouse(widget *self, point location)
|
|||
return hasMouse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a pointer to the event handler with an id of id. Should id be invalid
|
||||
* then NULL is returned.
|
||||
*
|
||||
* @param self The widget whose event handler table to search.
|
||||
* @param id The id of the desired event handler.
|
||||
* @return A pointer to the event handler, or NULL if id is invalid.
|
||||
*/
|
||||
static eventTableEntry *widgetGetEventHandlerById(widget *self, int id)
|
||||
{
|
||||
int i;
|
||||
eventTableEntry *entry = NULL;
|
||||
|
||||
// Search the event handler table
|
||||
for (i = 0; i < vectorSize(self->eventVtbl); i++)
|
||||
{
|
||||
eventTableEntry *currEntry = vectorAt(self->eventVtbl, id);
|
||||
|
||||
// See if the id matches
|
||||
if (currEntry->id == id)
|
||||
{
|
||||
entry = currEntry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
bool widgetIsA(widget *self, const classInfo *instanceOf)
|
||||
{
|
||||
const classInfo *widgetClass;
|
||||
|
@ -376,6 +405,28 @@ widget *widgetFindById(widget *self, const char *id)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *widgetGetEventHandlerUserData(widget *self, int id)
|
||||
{
|
||||
eventTableEntry *entry = widgetGetEventHandlerById(self, id);
|
||||
|
||||
// Make sure we found something
|
||||
assert(entry != NULL);
|
||||
|
||||
// Return the user-data
|
||||
return entry->userData;
|
||||
}
|
||||
|
||||
void widgetSetEventHandlerUserData(widget *self, int id, void *userData)
|
||||
{
|
||||
eventTableEntry *entry = widgetGetEventHandlerById(self, id);
|
||||
|
||||
// Make sure we found something
|
||||
assert(entry != NULL);
|
||||
|
||||
// Set the user-data
|
||||
entry->userData = userData;
|
||||
}
|
||||
|
||||
bool widgetAddChildImpl(widget *self, widget *child)
|
||||
{
|
||||
// Make sure the id of the child is unquie
|
||||
|
|
|
@ -537,6 +537,26 @@ int widgetAddTimerEventHandler(widget *self, eventType type, int interval,
|
|||
*/
|
||||
void widgetRemoveEventHandler(widget *self, int id);
|
||||
|
||||
/**
|
||||
* Returns the user-data for the event whose id is id.
|
||||
*
|
||||
* @param self The widget to whom the event handler is registered to.
|
||||
* @param id The id of the event handler to fetch the user-data for.
|
||||
* @returm The user-data for the event handler, or NULL if the eventId is
|
||||
* invalid.
|
||||
*/
|
||||
void *widgetGetEventHandlerUserData(widget *self, int id);
|
||||
|
||||
/**
|
||||
* Sets the user-data for the event handler with an id of id registered to self
|
||||
* to userData.
|
||||
*
|
||||
* @param self The widget to whom the event handler is registered to.
|
||||
* @param id The id of the widget to set the user-data for.
|
||||
* @param userData The new user-data for the event handler
|
||||
*/
|
||||
void widgetSetEventHandlerUserData(widget *self, int id, void *userData);
|
||||
|
||||
/**
|
||||
* Enables the current widget along with all of its child widgets. If the
|
||||
* widget is currently enabled but one or more of its child widgets are not
|
||||
|
|
Loading…
Reference in New Issue