summaryrefslogtreecommitdiff
path: root/iup/srclua3/il_matrix.c
blob: 21bb8ceefffbad93c985d9203043e731923d8086 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/** \file
 * \brief Bindig of iupmatrix to Lua 3.
 *
 * See Copyright Notice in "iup.h"
 */
 
#include <stdlib.h>

#include "iup.h"
#include "iupcontrols.h"

#include <cd.h>

#include <lua.h>

#include <cdlua.h>

#include "iuplua.h"
#include "il.h"
#include "il_controls.h"


static int MATRIX_draw(Ihandle *handle, int lin, int col, 
                                        int x1, int x2, int y1, int y2, cdCanvas* cnv)
{
  iuplua_call_start(handle, "draw");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushnumber(x1);
  lua_pushnumber(x2);
  lua_pushnumber(y1);
  lua_pushnumber(y2);
  cdlua_pushcanvas(cnv);
  return iuplua_call();
}

static int MATRIX_action (Ihandle *handle, int c, int lin, int col, int active, char *after)
{
  iuplua_call_start(handle, "action");
  lua_pushnumber(c);
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushnumber(active);
  lua_pushstring(after);
  return iuplua_call();
}

static int MATRIX_edition (Ihandle *handle, int lin, int col, int modo, int update)
{
  iuplua_call_start(handle, "edition");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushnumber(modo);
  lua_pushnumber(update);
  return iuplua_call();
}

static int MATRIX_dropcheck (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "dropcheck");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_markedit_cb (Ihandle *handle, int lin, int col, int marked)
{
  iuplua_call_start(handle, "markedit_cb");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushnumber(marked);
  return iuplua_call();
}

static int MATRIX_mark_cb (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "mark_cb");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_drop (Ihandle *handle, Ihandle *drop, int lin, int col)
{
  iuplua_regihandle(drop);
  iuplua_call_start(handle, "drop");
  iuplua_pushihandle_cb(drop);
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_dropselect (Ihandle *handle, int lin, int col,
                              Ihandle *list, char *t, int i, int v)
{
  iuplua_regihandle(list);
  iuplua_call_start(handle, "dropselect");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  iuplua_pushihandle_cb(list);
  lua_pushstring(t);
  lua_pushnumber(i);
  lua_pushnumber(v);
  return iuplua_call();
}

static int MATRIX_enteritem (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "enteritem");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_leaveitem (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "leaveitem");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_mousemove (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "mousemove");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_click (Ihandle *handle, int lin, int col, char *r)
{
  iuplua_call_start(handle, "click");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushstring(r);
  return iuplua_call();
}

static int MATRIX_release_cb (Ihandle *handle, int lin, int col, char *r)
{
  iuplua_call_start(handle, "release_cb");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushstring(r);
  return iuplua_call();
}

static int MATRIX_scrolltop (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "scrolltop");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call();
}

static int MATRIX_color(Ihandle *handle, char* name, int lin, int col, unsigned int *red, unsigned int *green, unsigned int *blue)
{
  lua_Object obj;
  iuplua_call_start(handle, name);
  lua_pushnumber(lin);
  lua_pushnumber(col);
  if (lua_call ("iupCallMethod"))
  {
    lua_endblock ();
    return IUP_IGNORE;
  }
  obj = lua_getresult (1);
  if (obj == LUA_NOOBJECT)
  {
    lua_endblock ();
    return IUP_IGNORE;
  }
  else if (lua_isnumber (obj))
  {
    int ret;
    *red = (unsigned int)lua_getnumber (obj);

    obj = lua_getresult (2);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_IGNORE;
    }
    *green = (unsigned int)lua_getnumber (obj);

    obj = lua_getresult (3);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_IGNORE;
    }
    *blue = (unsigned int)lua_getnumber (obj);

    obj = lua_getresult (4);
    if (obj == LUA_NOOBJECT || !lua_isnumber (obj))
    {
      lua_endblock ();
      return IUP_DEFAULT;
    }
    ret = (int)lua_getnumber (obj);
    lua_endblock ();
    return ret;
  }

  lua_endblock ();
  return IUP_IGNORE;
}

static int MATRIX_fgcolor(Ihandle *handle, int lin, int col, unsigned int *red, unsigned int *green, unsigned int *blue)
{
  return MATRIX_color(handle, "fgcolorcb", lin, col, red, green, blue);
}

static int MATRIX_bgcolor(Ihandle *handle, int lin, int col, unsigned int *red, unsigned int *green, unsigned int *blue)
{
  return MATRIX_color(handle, "bgcolorcb", lin, col, red, green, blue);
}

static char* MATRIX_value (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "valuecb");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call_rs();
}

static int MATRIX_value_edit (Ihandle *handle, int lin, int col, char* val)
{
  iuplua_call_start(handle, "value_edit");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  lua_pushstring(val);
  return iuplua_call();
}

static char* MATRIX_font_cb (Ihandle *handle, int lin, int col)
{
  iuplua_call_start(handle, "font_cb");
  lua_pushnumber(lin);
  lua_pushnumber(col);
  return iuplua_call_rs();
}

static void CreateMatrix(void)
{
  int tag = (int)lua_getnumber(lua_getglobal("iuplua_tag"));
  lua_pushusertag(IupMatrix(NULL), tag);
}

int matrixlua_open(void)
{
  struct AssocList {
    char *name;
    lua_CFunction func;
  } MatAssocList [] = {
    {"iup_mat_action_cb", (lua_CFunction)MATRIX_action},
    {"iup_mat_edition_cb", (lua_CFunction)MATRIX_edition},
    {"iup_mat_enteritem_cb", (lua_CFunction)MATRIX_enteritem},
    {"iup_mat_drop_cb", (lua_CFunction)MATRIX_drop},
    {"iup_mat_dropselect_cb", (lua_CFunction)MATRIX_dropselect},
    {"iup_mat_leaveitem_cb", (lua_CFunction)MATRIX_leaveitem},
    {"iup_mat_click_cb", (lua_CFunction)MATRIX_click},
    {"iup_mat_release_cb", (lua_CFunction)MATRIX_release_cb},
    {"iup_mat_mousemove_cb", (lua_CFunction)MATRIX_mousemove},
    {"iup_mat_scrolltop_cb", (lua_CFunction)MATRIX_scrolltop},
    {"iup_mat_fgcolor_cb", (lua_CFunction)MATRIX_fgcolor},
    {"iup_mat_bgcolor_cb", (lua_CFunction)MATRIX_bgcolor},
    {"iup_mat_draw_cb", (lua_CFunction)MATRIX_draw},
    {"iup_mat_dropcheck_cb", (lua_CFunction)MATRIX_dropcheck},
    {"iup_mat_font_cb", (lua_CFunction)MATRIX_font_cb},
    {"iup_mat_value_cb", (lua_CFunction)MATRIX_value},
    {"iup_mat_value_edit_cb", (lua_CFunction)MATRIX_value_edit},
    {"iup_mat_mark_cb", (lua_CFunction)MATRIX_mark_cb},
    {"iup_mat_markedit_cb", (lua_CFunction)MATRIX_markedit_cb}
  };
  int SizeMatAssocList = (sizeof(MatAssocList)/sizeof(struct AssocList));
  int i;

  lua_register("iupCreateMatrix", CreateMatrix);

  for (i = 0; i < SizeMatAssocList; i++)
    lua_register(MatAssocList[i].name, MatAssocList[i].func);

#ifdef IUPLUA_USELOH
#ifdef TEC_BIGENDIAN
#ifdef TEC_64
#include "loh/matrix_be64.loh"
#else
#include "loh/matrix_be32.loh"
#endif  
#else
#ifdef TEC_64
#ifdef WIN64
#include "loh/matrix_le64w.loh"
#else
#include "loh/matrix_le64.loh"
#endif  
#else
#include "loh/matrix.loh"
#endif  
#endif  
#else
  iuplua_dofile("luamatrix.lua");
#endif

  return 1;
}