summaryrefslogtreecommitdiff
path: root/iup/src/iup_func.c
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2009-11-04 11:56:41 -0800
committerPixel <pixel@nobis-crew.org>2009-11-04 11:59:33 -0800
commitd577d991b97ae2b5ee1af23641bcffc3f83af5b2 (patch)
tree590639d50205d1bcfaff2a7d2dc6ebf3f373c7ed /iup/src/iup_func.c
Initial import. Contains the im, cd and iup librairies, and a "working" Makefile for them under linux.
Diffstat (limited to 'iup/src/iup_func.c')
-rwxr-xr-xiup/src/iup_func.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/iup/src/iup_func.c b/iup/src/iup_func.c
new file mode 100755
index 0000000..76683c7
--- /dev/null
+++ b/iup/src/iup_func.c
@@ -0,0 +1,78 @@
+/** \file
+ * \brief function table manager
+ *
+ * See Copyright Notice in "iup.h"
+ */
+
+#include <stdlib.h>
+
+#include "iup.h"
+
+#include "iup_str.h"
+#include "iup_table.h"
+#include "iup_func.h"
+#include "iup_drv.h"
+#include "iup_assert.h"
+
+
+static Itable *ifunc_table = NULL; /* the function hast table indexed by the name string */
+static const char *ifunc_action_name = NULL; /* name of the action being retrieved in IupGetFunction */
+
+void iupFuncInit(void)
+{
+ ifunc_table = iupTableCreate(IUPTABLE_STRINGINDEXED);
+}
+
+void iupFuncFinish(void)
+{
+ iupTableDestroy(ifunc_table);
+ ifunc_table = NULL;
+}
+
+const char *IupGetActionName(void)
+{
+ return ifunc_action_name;
+}
+
+Icallback IupGetFunction(const char *name)
+{
+ void* value;
+ Icallback func;
+
+ iupASSERT(name!=NULL);
+ if (!name)
+ return NULL;
+
+ ifunc_action_name = name; /* store the retrieved name */
+
+ func = (Icallback)iupTableGetFunc(ifunc_table, name, &value);
+
+ /* if not defined and not the idle, then check for the DEFAULT_ACTION */
+ if (!func && !iupStrEqual(name, "IDLE_ACTION"))
+ func = (Icallback)iupTableGetFunc(ifunc_table, "DEFAULT_ACTION", &value);
+
+ return func;
+}
+
+Icallback IupSetFunction(const char *name, Icallback func)
+{
+ void* value;
+ Icallback old_func;
+
+ iupASSERT(name!=NULL);
+ if (!name)
+ return NULL;
+
+ old_func = (Icallback)iupTableGetFunc(ifunc_table, name, &value);
+
+ if (!func)
+ iupTableRemove(ifunc_table, name);
+ else
+ iupTableSetFunc(ifunc_table, name, (Ifunc)func);
+
+ /* notifies the driver if changing the Idle */
+ if (iupStrEqual(name, "IDLE_ACTION"))
+ iupdrvSetIdleFunction(func);
+
+ return old_func;
+}