summaryrefslogtreecommitdiff
path: root/iup/src/iup_func.c
blob: 76683c7a131766bf90fcf08879cb12d25cf6805c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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;
}