summaryrefslogtreecommitdiff
path: root/iup/src/iup_callback.c
blob: e000287fc0b7af2424b1785a8061198c242007ce (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
79
80
81
82
83
84
85
86
87
88
89
90
/** \file
 * \brief get/set callback
 *
 * See Copyright Notice in "iup.h"
 */

#include <stdlib.h> 
#include <stdarg.h>

#include "iup.h"

#include "iup_object.h"
#include "iup_assert.h"


Icallback IupGetCallback(Ihandle *ih, const char *name)
{
  Icallback func = NULL;
  void* value;

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return NULL;

  iupASSERT(name!=NULL);
  if (!name) 
    return NULL;

  func = (Icallback)iupTableGetFunc(ih->attrib, name, &value);

  if (!func && value)
  {
    /* if not a IUPTABLE_FUNCPOINTER then it is an old fashion name */
    func = IupGetFunction((const char*)value);
  }

  return func;
}

Icallback IupSetCallback(Ihandle *ih, const char *name, Icallback func)
{
  Icallback old_func = NULL;

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return NULL;

  iupASSERT(name!=NULL);
  if (!name) 
    return NULL;

  if (!func)
    iupTableRemove(ih->attrib, name);
  else
  {
    void* value;
    old_func = (Icallback)iupTableGetFunc(ih->attrib, name, &value);
    if (!old_func && value)
      old_func = IupGetFunction((const char*)value);

    iupTableSetFunc(ih->attrib, name, (Ifunc)func);
  }

  return old_func;
}

Ihandle* IupSetCallbacks(Ihandle* ih, const char *name, Icallback func, ...)
{
  va_list arglist;

  iupASSERT(iupObjectCheck(ih));
  if (!iupObjectCheck(ih))
    return NULL;

  IupSetCallback(ih, name, func);

  va_start(arglist, func);

  name=va_arg(arglist, const char*);
  while (name)
  {
    func=va_arg(arglist, Icallback);
    IupSetCallback(ih, name, func);

    name=va_arg(arglist, const char*);
  } 

  va_end (arglist);
  return ih;
}