ncurses 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,1447 @@
1
+ /*
2
+ * This is a curses forms wrapper as part of ncurses-ruby
3
+ * Contributed by Simon Kaczor <skaczor@cox.net>
4
+ * Prognosoft Inc. <http://www.prognosoft.biz>
5
+ * Copyright 2004
6
+ *
7
+ * (C) 2004 Tobias Peters
8
+ *
9
+ * This module is free software; you can redistribute it and/or
10
+ * modify it under the terms of the GNU Lesser General Public
11
+ * License as published by the Free Software Foundation; either
12
+ * version 2 of the License, or (at your option) any later version.
13
+ *
14
+ * This module is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ * Lesser General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU Lesser General Public
20
+ * License along with this module; if not, write to the Free Software
21
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ *
23
+ */
24
+
25
+
26
+ #ifdef HAVE_FORM_H
27
+
28
+ #include "form_wrap.h"
29
+ #include "ncurses_wrap.h"
30
+
31
+ VALUE mForm;
32
+ VALUE cFIELD;
33
+ VALUE cFIELDTYPE;
34
+ VALUE cFORM;
35
+
36
+ void init_err_codes()
37
+ {
38
+ /* The routine succeeded. */
39
+ FORM_DEF_CONST(E_OK);
40
+ /* The field is already connected to a form. */
41
+ FORM_DEF_CONST(E_CONNECTED);
42
+ /* System error occurred (see errno). */
43
+ FORM_DEF_CONST(E_SYSTEM_ERROR);
44
+ /* Routine detected an incorrect or out-of-range argument. */
45
+ FORM_DEF_CONST(E_BAD_ARGUMENT);
46
+ /* The form is already posted. */
47
+ FORM_DEF_CONST(E_POSTED);
48
+ /* Routine was called from an initialization or termination function. */
49
+ FORM_DEF_CONST(E_BAD_STATE);
50
+ /* Form is too large for its window. */
51
+ FORM_DEF_CONST(E_NO_ROOM);
52
+ /* The form has not been posted. */
53
+ FORM_DEF_CONST(E_NOT_POSTED);
54
+ /* The form driver code saw an unknown request code. */
55
+ FORM_DEF_CONST(E_UNKNOWN_COMMAND);
56
+ /* Contents of a field are not valid. */
57
+ FORM_DEF_CONST(E_INVALID_FIELD);
58
+ /* No fields are connected to the form. */
59
+ FORM_DEF_CONST(E_NOT_CONNECTED);
60
+ /* The form driver could not process the request.} */
61
+ FORM_DEF_CONST(E_REQUEST_DENIED);
62
+ }
63
+
64
+ /*
65
+ * Form driver request characters listed in form_driver(3x) man page
66
+ */
67
+ void init_req_constants() {
68
+ /* Move to the next page */
69
+ FORM_DEF_CONST(REQ_NEXT_PAGE);
70
+ /* Move to the previous page. */
71
+ FORM_DEF_CONST(REQ_PREV_PAGE);
72
+ /* Move to the first page. */
73
+ FORM_DEF_CONST(REQ_FIRST_PAGE);
74
+ /* Move to the last field. */
75
+ FORM_DEF_CONST(REQ_LAST_PAGE);
76
+ /* Move to the next field. */
77
+ FORM_DEF_CONST(REQ_NEXT_FIELD);
78
+ /* Move to the previous field. */
79
+ FORM_DEF_CONST(REQ_PREV_FIELD);
80
+ /* Move to the first field. */
81
+ FORM_DEF_CONST(REQ_FIRST_FIELD);
82
+ /* Move to the last field. */
83
+ FORM_DEF_CONST(REQ_LAST_FIELD);
84
+ /* Move to the sorted next field. */
85
+ FORM_DEF_CONST(REQ_SNEXT_FIELD);
86
+ /* Move to the sorted previous field. */
87
+ FORM_DEF_CONST(REQ_SPREV_FIELD);
88
+ /* Move to the sorted first field. */
89
+ FORM_DEF_CONST(REQ_SFIRST_FIELD);
90
+ /* Move to the sorted last field. */
91
+ FORM_DEF_CONST(REQ_SLAST_FIELD);
92
+ /* Move left to a field. */
93
+ FORM_DEF_CONST(REQ_LEFT_FIELD);
94
+ /* Move right to a field. */
95
+ FORM_DEF_CONST(REQ_RIGHT_FIELD);
96
+ /* Move up to a field. */
97
+ FORM_DEF_CONST(REQ_UP_FIELD);
98
+ /* Move down to a field. */
99
+ FORM_DEF_CONST(REQ_DOWN_FIELD);
100
+ /* Move to the next char. */
101
+ FORM_DEF_CONST(REQ_NEXT_CHAR);
102
+ /* Move to the previous char. */
103
+ FORM_DEF_CONST(REQ_PREV_CHAR);
104
+ /* Move to the next line. */
105
+ FORM_DEF_CONST(REQ_NEXT_LINE);
106
+ /* Move to the previous line. */
107
+ FORM_DEF_CONST(REQ_PREV_LINE);
108
+ /* Move to the next word. */
109
+ FORM_DEF_CONST(REQ_NEXT_WORD);
110
+ /* Move to the previous word. */
111
+ FORM_DEF_CONST(REQ_PREV_WORD);
112
+ /* Move to the beginning of the field. */
113
+ FORM_DEF_CONST(REQ_BEG_FIELD);
114
+ /* Move to the end of the field. */
115
+ FORM_DEF_CONST(REQ_END_FIELD);
116
+ /* Move to the beginning of the line. */
117
+ FORM_DEF_CONST(REQ_BEG_LINE);
118
+ /* Move to the end of the line. */
119
+ FORM_DEF_CONST(REQ_END_LINE);
120
+ /* Move left in the field. */
121
+ FORM_DEF_CONST(REQ_LEFT_CHAR);
122
+ /* Move right in the field. */
123
+ FORM_DEF_CONST(REQ_RIGHT_CHAR);
124
+ /* Move up in the field. */
125
+ FORM_DEF_CONST(REQ_UP_CHAR);
126
+ /* Move down in the field. */
127
+ FORM_DEF_CONST(REQ_DOWN_CHAR);
128
+ /* Insert or overlay a new line. */
129
+ FORM_DEF_CONST(REQ_NEW_LINE);
130
+ /* Insert a blank at the cursor. */
131
+ FORM_DEF_CONST(REQ_INS_CHAR);
132
+ /* Insert a blank line at the cursor. */
133
+ FORM_DEF_CONST(REQ_INS_LINE);
134
+ /* Delete character at the cursor. */
135
+ FORM_DEF_CONST(REQ_DEL_CHAR);
136
+ /* Delete character before the cursor. */
137
+ FORM_DEF_CONST(REQ_DEL_PREV);
138
+ /* Delete line at the cursor. */
139
+ FORM_DEF_CONST(REQ_DEL_LINE);
140
+ /* Delete blank-delimited word at the cursor. */
141
+ FORM_DEF_CONST(REQ_DEL_WORD);
142
+ /* Clear to end of line from cursor. */
143
+ FORM_DEF_CONST(REQ_CLR_EOL);
144
+ /* Clear to end of field from cursor. */
145
+ FORM_DEF_CONST(REQ_CLR_EOF);
146
+ /* Clear the entire field. */
147
+ FORM_DEF_CONST(REQ_CLR_FIELD);
148
+ /* Enter overlay mode. */
149
+ FORM_DEF_CONST(REQ_OVL_MODE);
150
+ /* Enter insert mode. */
151
+ FORM_DEF_CONST(REQ_INS_MODE);
152
+ /* Scroll the field forward a line. */
153
+ FORM_DEF_CONST(REQ_SCR_FLINE);
154
+ /* Scroll the field backward a line. */
155
+ FORM_DEF_CONST(REQ_SCR_BLINE);
156
+ /* Scroll the field forward a page. */
157
+ FORM_DEF_CONST(REQ_SCR_FPAGE);
158
+ /* Scroll the field backward a page. */
159
+ FORM_DEF_CONST(REQ_SCR_BPAGE);
160
+ /* Scroll the field forward half a page. */
161
+ FORM_DEF_CONST(REQ_SCR_FHPAGE);
162
+ /* Scroll the field backward half a page. */
163
+ FORM_DEF_CONST(REQ_SCR_BHPAGE);
164
+ /* Scroll the field forward a character. */
165
+ FORM_DEF_CONST(REQ_SCR_FCHAR);
166
+ /* Scroll the field backward a character. */
167
+ FORM_DEF_CONST(REQ_SCR_BCHAR);
168
+ /* Horizontal scroll the field forward a line. */
169
+ FORM_DEF_CONST(REQ_SCR_HFLINE);
170
+ /* Horizontal scroll the field backward a line. */
171
+ FORM_DEF_CONST(REQ_SCR_HBLINE);
172
+ /* Horizontal scroll the field forward half a line. */
173
+ FORM_DEF_CONST(REQ_SCR_HFHALF);
174
+ /* Horizontal scroll the field backward half a line. */
175
+ FORM_DEF_CONST(REQ_SCR_HBHALF);
176
+ /* Validate field. */
177
+ FORM_DEF_CONST(REQ_VALIDATION);
178
+ /* Display next field choice. */
179
+ FORM_DEF_CONST(REQ_NEXT_CHOICE);
180
+ /* Display previous field choice. */
181
+ FORM_DEF_CONST(REQ_PREV_CHOICE);
182
+ }
183
+
184
+ /*
185
+ * field justification constants
186
+ */
187
+ void init_just_constants() {
188
+ FORM_DEF_CONST(NO_JUSTIFICATION);
189
+ FORM_DEF_CONST(JUSTIFY_RIGHT);
190
+ FORM_DEF_CONST(JUSTIFY_LEFT);
191
+ FORM_DEF_CONST(JUSTIFY_CENTER);
192
+ }
193
+
194
+ /*
195
+ * field options constants
196
+ */
197
+ void init_opts_constants() {
198
+ FORM_DEF_CONST(O_VISIBLE);
199
+ FORM_DEF_CONST(O_ACTIVE);
200
+ FORM_DEF_CONST(O_PUBLIC);
201
+ FORM_DEF_CONST(O_EDIT);
202
+ FORM_DEF_CONST(O_WRAP);
203
+ FORM_DEF_CONST(O_BLANK);
204
+ FORM_DEF_CONST(O_AUTOSKIP);
205
+ FORM_DEF_CONST(O_NULLOK);
206
+ FORM_DEF_CONST(O_STATIC);
207
+ FORM_DEF_CONST(O_PASSOK);
208
+ }
209
+
210
+ void init_form_opts_constants() {
211
+ FORM_DEF_CONST(O_NL_OVERLOAD);
212
+ FORM_DEF_CONST(O_BS_OVERLOAD);
213
+ }
214
+
215
+ /*
216
+ * _PAGE wrapper
217
+ */
218
+ /* static VALUE wrap_page(_PAGE* page) */
219
+ /* { */
220
+ /* if (page == 0) return Qnil; */
221
+ /* { */
222
+ /* VALUE pages_hash = rb_iv_get(mForm, "@pages_hash"); */
223
+ /* VALUE page_adress = INT2NUM((long)(page)); */
224
+ /* VALUE rb_page = rb_hash_aref(pages_hash, page_adress); */
225
+ /* if (rb_page == Qnil) { */
226
+ /* rb_page = Data_Wrap_Struct(cPAGE, 0, 0, page); */
227
+ /* rb_iv_set(rb_page, "@destroyed", Qfalse); */
228
+ /* rb_hash_aset(pages_hash, page_adress, rb_page); */
229
+ /* } */
230
+ /* return rb_page; */
231
+ /* } */
232
+ /* } */
233
+ /* static _PAGE* get_page(VALUE rb_page) */
234
+ /* { */
235
+ /* _PAGE* page; */
236
+ /* if (rb_page == Qnil) return 0; */
237
+ /* if (rb_iv_get(rb_page, "@destroyed") == Qtrue) { */
238
+ /* rb_raise(rb_eRuntimeError, "Attempt to access a destroyed page"); */
239
+ /* return 0; */
240
+ /* } */
241
+ /* Data_Get_Struct(rb_page, _PAGE, page); */
242
+ /* return page; */
243
+ /* } */
244
+
245
+ /*
246
+ * FIELD wrapper
247
+ */
248
+ static VALUE wrap_field(FIELD* field)
249
+ {
250
+ if (field == 0) return Qnil;
251
+ {
252
+ VALUE fields_hash = rb_iv_get(mForm, "@fields_hash");
253
+ VALUE field_adress = INT2NUM((long)(field));
254
+ VALUE rb_field = rb_hash_aref(fields_hash, field_adress);
255
+ if (rb_field == Qnil) {
256
+ rb_field = Data_Wrap_Struct(cFIELD, 0, 0, field);
257
+ rb_iv_set(rb_field, "@destroyed", Qfalse);
258
+ rb_hash_aset(fields_hash, field_adress, rb_field);
259
+ }
260
+ return rb_field;
261
+ }
262
+ }
263
+ static FIELD* get_field(VALUE rb_field)
264
+ {
265
+ FIELD* field;
266
+ if (rb_field == Qnil) return 0;
267
+ if (rb_iv_get(rb_field, "@destroyed") == Qtrue) {
268
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed field");
269
+ return 0;
270
+ }
271
+ Data_Get_Struct(rb_field, FIELD, field);
272
+ return field;
273
+ }
274
+
275
+ /*
276
+ * FIELDTYPE wrapper
277
+ */
278
+ static VALUE wrap_fieldtype(FIELDTYPE* fieldtype)
279
+ {
280
+ if (fieldtype == NULL) return Qnil;
281
+ {
282
+ VALUE fieldtypes_hash = rb_iv_get(mForm, "@fieldtypes_hash");
283
+ VALUE fieldtype_adress = INT2NUM((long)(fieldtype));
284
+ VALUE rb_fieldtype = rb_hash_aref(fieldtypes_hash, fieldtype_adress);
285
+ if (rb_fieldtype == Qnil) {
286
+ rb_fieldtype = Data_Wrap_Struct(cFIELDTYPE, 0, 0, fieldtype);
287
+ rb_iv_set(rb_fieldtype, "@destroyed", Qfalse);
288
+ rb_hash_aset(fieldtypes_hash, fieldtype_adress, rb_fieldtype);
289
+ }
290
+ return rb_fieldtype;
291
+ }
292
+ }
293
+ static FIELDTYPE* get_fieldtype(VALUE rb_fieldtype)
294
+ {
295
+ FIELDTYPE* fieldtype;
296
+ if (rb_fieldtype == Qnil) return 0;
297
+ if (rb_iv_get(rb_fieldtype, "@destroyed") == Qtrue) {
298
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed fieldtype");
299
+ return 0;
300
+ }
301
+ Data_Get_Struct(rb_fieldtype, FIELDTYPE, fieldtype);
302
+ return fieldtype;
303
+ }
304
+
305
+ /*
306
+ * FORM wrapper
307
+ */
308
+ static VALUE wrap_form(FORM* form)
309
+ {
310
+ if (form == 0) return Qnil;
311
+ {
312
+ VALUE forms_hash = rb_iv_get(mForm, "@forms_hash");
313
+ VALUE form_adress = INT2NUM((long)(form));
314
+ VALUE rb_form = rb_hash_aref(forms_hash, form_adress);
315
+ if (rb_form == Qnil) {
316
+ rb_form = Data_Wrap_Struct(cFORM, 0, 0, form);
317
+ rb_iv_set(rb_form, "@destroyed", Qfalse);
318
+ rb_hash_aset(forms_hash, form_adress, rb_form);
319
+ }
320
+ return rb_form;
321
+ }
322
+ }
323
+ static FORM* get_form(VALUE rb_form)
324
+ {
325
+ FORM* form;
326
+ if (rb_form == Qnil) return 0;
327
+ if (rb_iv_get(rb_form, "@destroyed") == Qtrue) {
328
+ rb_raise(rb_eRuntimeError, "Attempt to access a destroyed form");
329
+ return 0;
330
+ }
331
+ Data_Get_Struct(rb_form, FORM, form);
332
+ return form;
333
+ }
334
+
335
+ /*
336
+ * Proc objects are registered using hashes (one for each type of hook)
337
+ * The key in the hash is the address of the ncurses "object" and the value is
338
+ * the Proc object.
339
+ */
340
+ #define FIELD_INIT_HOOK 0
341
+ #define FIELD_TERM_HOOK 1
342
+ #define FORM_INIT_HOOK 2
343
+ #define FORM_TERM_HOOK 3
344
+ #define FIELDTYPE_FIELD_CHECK_HOOK 4
345
+ #define FIELDTYPE_CHAR_CHECK_HOOK 5
346
+ #define FIELDTYPE_NEXT_CHOICE_HOOK 6
347
+ #define FIELDTYPE_PREV_CHOICE_HOOK 7
348
+ #define FIELDTYPE_ARGS 8
349
+ #define PROC_HASHES_COUNT 9
350
+ static VALUE get_proc_hash(int hook) {
351
+ VALUE arr = rb_iv_get(mForm, "@proc_hashes");
352
+ VALUE hash = rb_ary_entry(arr, (long)hook);
353
+ if (hash == Qnil) {
354
+ rb_raise(rb_eRuntimeError, "Invalid proc hash.");
355
+ }
356
+ return hash;
357
+ }
358
+
359
+ /*
360
+ * Returns an existing Ruby Proc for a given owning "object" and hook type.
361
+ * Qnil will be returned if no Proc was associated with the owner
362
+ */
363
+ static VALUE get_proc(void* owner, int hook) {
364
+ if (owner == 0) return Qnil;
365
+ {
366
+ VALUE owner_adress = INT2NUM((long)(owner));
367
+ VALUE proc_hash = get_proc_hash(hook);
368
+ VALUE proc = rb_hash_aref(proc_hash, owner_adress);
369
+ return proc;
370
+ }
371
+ }
372
+ /*
373
+ * Registers the Proc object with a given owner "object" and hook type.
374
+ * If proc is Qnil, the hook is unregistered instead.
375
+ */
376
+ static void reg_proc(void* owner, int hook, VALUE proc) {
377
+ if (owner == NULL) return;
378
+ {
379
+ VALUE proc_hash = get_proc_hash(hook);
380
+ VALUE owner_address = INT2NUM((long)(owner));
381
+ if (proc == Qnil) {
382
+ rb_hash_delete(proc_hash, owner_address);
383
+ }
384
+ else {
385
+ rb_hash_aset(proc_hash, owner_address, proc);
386
+ }
387
+ }
388
+ }
389
+
390
+ /*
391
+ * Form creation/destruction functions
392
+ */
393
+ static VALUE rbncurs_m_new_form(VALUE dummy, VALUE rb_field_array)
394
+ {
395
+ long n = RARRAY(rb_field_array)->len;
396
+ /* Will ncurses free this array? If not, must do it after calling free_form(). */
397
+ FIELD** fields = ALLOC_N(FIELD*, (n+1));
398
+ long i;
399
+ for (i=0; i<n; i++){
400
+ fields[i] = get_field(rb_ary_entry(rb_field_array, i));
401
+ }
402
+ fields[n] = NULL;
403
+ return wrap_form(new_form(fields));
404
+ }
405
+
406
+ static VALUE rbncurs_c_free_form(VALUE rb_form) {
407
+ VALUE forms_hash = rb_iv_get(mForm, "@forms_hash");
408
+ FORM* form = get_form(rb_form);
409
+ VALUE form_adress = INT2NUM((long)(form));
410
+ rb_funcall(forms_hash, rb_intern("delete"), 1, form_adress);
411
+ rb_iv_set(rb_form, "@destroyed", Qtrue);
412
+ return INT2NUM(free_form(form));
413
+ }
414
+ static VALUE rbncurs_m_free_form(VALUE dummy, VALUE rb_form)
415
+ { return rbncurs_c_free_form(rb_form); }
416
+
417
+ /*
418
+ * form_post
419
+ */
420
+ static VALUE rbncurs_c_post_form(VALUE rb_form) {
421
+ FORM* form = get_form(rb_form);
422
+ return INT2NUM(post_form(form));
423
+ }
424
+ static VALUE rbncurs_m_post_form(VALUE dummy, VALUE rb_form)
425
+ { return rbncurs_c_post_form(rb_form); }
426
+
427
+ static VALUE rbncurs_c_unpost_form(VALUE rb_form) {
428
+ FORM* form = get_form(rb_form);
429
+ return INT2NUM(unpost_form(form));
430
+ }
431
+ static VALUE rbncurs_m_unpost_form(VALUE dummy, VALUE rb_form)
432
+ { return rbncurs_c_unpost_form(rb_form); }
433
+
434
+ /*
435
+ * Form driver
436
+ */
437
+ static VALUE rbncurs_c_form_driver(VALUE rb_form, VALUE c) {
438
+ FORM* form = get_form(rb_form);
439
+ return INT2NUM(form_driver(form, NUM2INT(c)));
440
+ }
441
+ static VALUE rbncurs_m_form_driver(VALUE dummy, VALUE rb_form, VALUE c)
442
+ { return rbncurs_c_form_driver(rb_form, c); }
443
+
444
+ /*
445
+ * form_page(3x)
446
+ */
447
+ static VALUE rbncurs_c_set_current_field(VALUE rb_form, VALUE rb_field) {
448
+ FORM* form = get_form(rb_form);
449
+ FIELD* field = get_field(rb_field);
450
+ return INT2NUM(set_current_field(form, field));
451
+ }
452
+ static VALUE rbncurs_m_set_current_field(VALUE dummy, VALUE rb_form, VALUE rb_field)
453
+ { return rbncurs_c_set_current_field(rb_form, rb_field); }
454
+
455
+ static VALUE rbncurs_c_current_field(VALUE rb_form) {
456
+ FORM* form = get_form(rb_form);
457
+ return wrap_field(current_field(form));
458
+ }
459
+ static VALUE rbncurs_m_current_field(VALUE dummy, VALUE rb_form)
460
+ { return rbncurs_c_current_field(rb_form); }
461
+
462
+ static VALUE rbncurs_c_set_form_page(VALUE rb_form, VALUE n) {
463
+ FORM* form = get_form(rb_form);
464
+ return INT2NUM(set_form_page(form, NUM2INT(n)));
465
+ }
466
+ static VALUE rbncurs_m_set_form_page(VALUE dummy, VALUE rb_form, VALUE n)
467
+ { return rbncurs_c_set_form_page(rb_form, n); }
468
+
469
+ static VALUE rbncurs_c_form_page(VALUE rb_form) {
470
+ FORM* form = get_form(rb_form);
471
+ return INT2NUM(form_page(form));
472
+ }
473
+ static VALUE rbncurs_m_form_page(VALUE dummy, VALUE rb_form)
474
+ { return rbncurs_c_form_page(rb_form); }
475
+
476
+ static VALUE rbncurs_c_field_index(VALUE rb_field) {
477
+ FIELD* field = get_field(rb_field);
478
+ return INT2NUM(field_index(field));
479
+ }
480
+ static VALUE rbncurs_m_field_index(VALUE dummy, VALUE rb_field)
481
+ { return rbncurs_c_field_index(rb_field); }
482
+
483
+ /*
484
+ * form_data(3x)
485
+ */
486
+ static VALUE rbncurs_c_data_ahead(VALUE rb_form) {
487
+ FORM* form = get_form(rb_form);
488
+ return (data_ahead(form)) ? Qtrue: Qfalse;
489
+ }
490
+ static VALUE rbncurs_m_data_ahead(VALUE dummy, VALUE rb_form)
491
+ { return rbncurs_c_data_ahead(rb_form); }
492
+
493
+ static VALUE rbncurs_c_data_behind(VALUE rb_form) {
494
+ FORM* form = get_form(rb_form);
495
+ return (data_behind(form)) ? Qtrue: Qfalse;
496
+ }
497
+ static VALUE rbncurs_m_data_behind(VALUE dummy, VALUE rb_form)
498
+ { return rbncurs_c_data_behind(rb_form); }
499
+
500
+
501
+
502
+ /*
503
+ * Field functions (form_field_new(3x))
504
+ */
505
+ static VALUE rbncurs_m_new_field(VALUE dummy,
506
+ VALUE height, VALUE width,
507
+ VALUE toprow, VALUE leftcol,
508
+ VALUE offscreen, VALUE nbuffers) {
509
+ return wrap_field(new_field(NUM2INT(height), NUM2INT(width),
510
+ NUM2INT(toprow), NUM2INT(leftcol),
511
+ NUM2INT(offscreen), NUM2INT(nbuffers)));
512
+ }
513
+
514
+ static VALUE rbncurs_c_dup_field(VALUE rb_field, VALUE toprow, VALUE leftcol) {
515
+ FIELD* field = get_field(rb_field);
516
+ return wrap_field(dup_field(field, NUM2INT(toprow),NUM2INT(leftcol)));
517
+ }
518
+ static VALUE rbncurs_m_dup_field(VALUE dummy, VALUE rb_field, VALUE toprow, VALUE leftcol)
519
+ { return rbncurs_c_dup_field(rb_field, toprow, leftcol); }
520
+
521
+ static VALUE rbncurs_c_link_field(VALUE rb_field, VALUE toprow, VALUE leftcol) {
522
+ FIELD* field = get_field(rb_field);
523
+ return wrap_field(link_field(field, NUM2INT(toprow),NUM2INT(leftcol)));
524
+ }
525
+ static VALUE rbncurs_m_link_field(VALUE dummy, VALUE rb_field, VALUE toprow, VALUE leftcol)
526
+ { return rbncurs_c_link_field(rb_field, toprow, leftcol); }
527
+
528
+ static VALUE rbncurs_c_free_field(VALUE rb_field) {
529
+ VALUE fields_hash = rb_iv_get(mForm, "@fields_hash");
530
+ FIELD* field = get_field(rb_field);
531
+ VALUE field_adress = INT2NUM((long)(field));
532
+ rb_funcall(fields_hash, rb_intern("delete"), 1, field_adress);
533
+ rb_iv_set(rb_field, "@destroyed", Qtrue);
534
+ return INT2NUM(free_field(field));
535
+ }
536
+ static VALUE rbncurs_m_free_field(VALUE dummy, VALUE rb_field)
537
+ { return rbncurs_c_free_field(rb_field); }
538
+
539
+
540
+ /*
541
+ * form_field_info(3x)
542
+ */
543
+ static VALUE rbncurs_c_field_info(VALUE rb_field, VALUE rows, VALUE cols,
544
+ VALUE frow, VALUE fcol, VALUE nrow, VALUE nbuf) {
545
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
546
+ || rb_obj_is_instance_of(cols, rb_cArray) != Qtrue
547
+ || rb_obj_is_instance_of(frow, rb_cArray) != Qtrue
548
+ || rb_obj_is_instance_of(fcol, rb_cArray) != Qtrue
549
+ || rb_obj_is_instance_of(nrow, rb_cArray) != Qtrue
550
+ || rb_obj_is_instance_of(nbuf, rb_cArray) != Qtrue) {
551
+ rb_raise(rb_eArgError,
552
+ "rows, cols, frow, fcol, nrow and nbuf arguments must be empty Arrays");
553
+ return Qnil;
554
+ }
555
+ else {
556
+ FIELD* field = get_field(rb_field);
557
+ int vals[6] = {0,0,0,0,0,0};
558
+
559
+ int result = field_info(field, &vals[0],&vals[1],&vals[2],&vals[3],&vals[4],&vals[5]);
560
+ rb_ary_push(rows, INT2NUM(vals[0]));
561
+ rb_ary_push(cols, INT2NUM(vals[1]));
562
+ rb_ary_push(frow, INT2NUM(vals[2]));
563
+ rb_ary_push(fcol, INT2NUM(vals[3]));
564
+ rb_ary_push(nrow, INT2NUM(vals[4]));
565
+ rb_ary_push(nbuf, INT2NUM(vals[5]));
566
+ return INT2NUM(result);
567
+ }
568
+ }
569
+ static VALUE rbncurs_m_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
570
+ VALUE frow, VALUE fcol, VALUE nrow, VALUE nbuf)
571
+ { return rbncurs_c_field_info(rb_field, rows, cols, frow, fcol, nrow, nbuf); }
572
+
573
+ static VALUE rbncurs_c_dynamic_field_info(VALUE rb_field, VALUE rows, VALUE cols,
574
+ VALUE max) {
575
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
576
+ || rb_obj_is_instance_of(cols, rb_cArray) != Qtrue
577
+ || rb_obj_is_instance_of(max, rb_cArray) != Qtrue) {
578
+ rb_raise(rb_eArgError,
579
+ "rows, cols and max arguments must be empty Arrays");
580
+ return Qnil;
581
+ }
582
+ else {
583
+ FIELD* field = get_field(rb_field);
584
+ int vals[3] = {0,0,0};
585
+
586
+ int result = dynamic_field_info(field, &vals[0],&vals[1],&vals[2]);
587
+ rb_ary_push(rows, INT2NUM(vals[0]));
588
+ rb_ary_push(cols, INT2NUM(vals[1]));
589
+ rb_ary_push(max, INT2NUM(vals[2]));
590
+ return INT2NUM(result);
591
+ }
592
+ }
593
+ static VALUE rbncurs_m_dynamic_field_info(VALUE dummy, VALUE rb_field, VALUE rows, VALUE cols,
594
+ VALUE max)
595
+ { return rbncurs_c_dynamic_field_info(rb_field, rows, cols, max); }
596
+ /*
597
+ * field_validation
598
+ */
599
+ static VALUE rbncurs_c_set_field_type(int argc, VALUE* argv, VALUE rb_field) {
600
+ VALUE rb_fieldtype, arg3, arg4, arg5;
601
+ FIELD* field = get_field(rb_field);
602
+ FIELDTYPE* ftype = NULL;
603
+
604
+ rb_scan_args(argc, argv, "13", &rb_fieldtype, &arg3, &arg4, &arg5);
605
+ ftype = get_fieldtype(rb_fieldtype);
606
+
607
+ if (ftype == TYPE_ALNUM ||
608
+ ftype == TYPE_ALPHA) {
609
+ if (argc != 2)
610
+ rb_raise(rb_eArgError, "TYPE_ALNUM and TYPE_ALPHA require one additional argument");
611
+ return INT2NUM(set_field_type(field, ftype,
612
+ NUM2INT(arg3)));
613
+ }
614
+ if (ftype == TYPE_ENUM) {
615
+ if (argc != 4) {
616
+ rb_raise(rb_eArgError, "TYPE_ENUM requires three additional arguments");
617
+ }
618
+ else {
619
+ int n = RARRAY(arg3)->len;
620
+ /* Will ncurses free this array of strings in free_field()? */
621
+ char** list = ALLOC_N(char*, n+1);
622
+ int i;
623
+ for (i = 0; i < n; i++) {
624
+ list[i] = STR2CSTR(rb_ary_entry(arg3, (long)i));
625
+ }
626
+ list[n] = NULL;
627
+ return INT2NUM(set_field_type(field, ftype,
628
+ list,
629
+ RTEST(arg4),
630
+ RTEST(arg5)));
631
+ }
632
+ }
633
+ else if (ftype == TYPE_INTEGER) {
634
+ if (argc != 4)
635
+ rb_raise(rb_eArgError, "TYPE_INTEGER requires three additional arguments");
636
+ return INT2NUM(set_field_type(field, ftype,
637
+ NUM2INT(arg3),
638
+ NUM2LONG(arg4),
639
+ NUM2LONG(arg5)));
640
+ }
641
+ else if (ftype == TYPE_NUMERIC) {
642
+ if (argc != 4)
643
+ rb_raise(rb_eArgError, "TYPE_NUMERIC requires three additional arguments");
644
+ return INT2NUM(set_field_type(field, ftype,
645
+ NUM2INT(arg3),
646
+ NUM2DBL(arg4),
647
+ NUM2DBL(arg5)));
648
+ }
649
+ else if (ftype == TYPE_REGEXP){
650
+ if (argc != 2)
651
+ rb_raise(rb_eArgError, "TYPE_REGEXP requires one additional argument");
652
+ return INT2NUM(set_field_type(field, ftype,
653
+ STR2CSTR(arg3)));
654
+ }
655
+ else if (ftype == TYPE_IPV4){
656
+ if (argc != 1)
657
+ rb_raise(rb_eArgError, "TYPE_IPV4 has no additional arguments");
658
+ return INT2NUM(set_field_type(field, ftype));
659
+ }
660
+ else {
661
+ /* It is a user-defined field type. */
662
+ /* Will store the arguments associated with this field */
663
+ /* for use in the callback function. */
664
+ VALUE rest;
665
+ rb_scan_args(argc, argv, "1*", &rb_fieldtype, &rest);
666
+ reg_proc(field, FIELDTYPE_ARGS, rest);
667
+ /* Pass field as an optional parameter so that make_arg can create */
668
+ /* the block-argument used in finding the appropriate Ruby Proc */
669
+ return INT2NUM(set_field_type(field, ftype, field));
670
+ }
671
+
672
+ }
673
+ static VALUE rbncurs_m_set_field_type(int argc, VALUE* argv, VALUE dummy)
674
+ { return rbncurs_c_set_field_type(argc-1, argv+1, argv[0]); }
675
+
676
+ static VALUE rbncurs_c_field_type(VALUE rb_field) {
677
+ FIELD* field = get_field(rb_field);
678
+ return wrap_fieldtype(field_type(field));
679
+ }
680
+ static VALUE rbncurs_m_field_type(VALUE dummy, VALUE rb_field)
681
+ { return rbncurs_c_field_type(rb_field); }
682
+ /* What is this function doing??? */
683
+ static VALUE rbncurs_c_field_arg(VALUE rb_field) {
684
+ FIELD* field = get_field(rb_field);
685
+ field_arg(field);
686
+ return Qfalse;
687
+ }
688
+ static VALUE rbncurs_m_field_arg(VALUE dummy, VALUE rb_field)
689
+ { return rbncurs_c_field_arg(rb_field); }
690
+
691
+ /*
692
+ * field_attributes
693
+ */
694
+ static VALUE rbncurs_c_set_field_fore(VALUE rb_field, VALUE attr) {
695
+ FIELD* field = get_field(rb_field);
696
+ return INT2NUM(set_field_fore(field, NUM2ULONG(attr)));
697
+ }
698
+ static VALUE rbncurs_m_set_field_fore(VALUE dummy, VALUE rb_field, VALUE attr)
699
+ { return rbncurs_c_set_field_fore(rb_field, attr); }
700
+
701
+ static VALUE rbncurs_c_field_fore(VALUE rb_field) {
702
+ FIELD* field = get_field(rb_field);
703
+ return ULONG2NUM(field_fore(field));
704
+ }
705
+ static VALUE rbncurs_m_field_fore(VALUE dummy, VALUE rb_field)
706
+ { return rbncurs_c_field_fore(rb_field); }
707
+
708
+ static VALUE rbncurs_c_set_field_back(VALUE rb_field, VALUE attr) {
709
+ FIELD* field = get_field(rb_field);
710
+ return INT2NUM(set_field_back(field, NUM2ULONG(attr)));
711
+ }
712
+ static VALUE rbncurs_m_set_field_back(VALUE dummy, VALUE rb_field, VALUE attr)
713
+ { return rbncurs_c_set_field_back(rb_field, attr); }
714
+
715
+ static VALUE rbncurs_c_field_back(VALUE rb_field) {
716
+ FIELD* field = get_field(rb_field);
717
+ return ULONG2NUM(field_back(field));
718
+ }
719
+ static VALUE rbncurs_m_field_back(VALUE dummy, VALUE rb_field)
720
+ { return rbncurs_c_field_back(rb_field); }
721
+
722
+ static VALUE rbncurs_c_set_field_pad(VALUE rb_field, VALUE pad) {
723
+ FIELD* field = get_field(rb_field);
724
+ return INT2NUM(set_field_pad(field, NUM2INT(pad)));
725
+ }
726
+ static VALUE rbncurs_m_set_field_pad(VALUE dummy, VALUE rb_field, VALUE pad)
727
+ { return rbncurs_c_set_field_pad(rb_field, pad); }
728
+
729
+ static VALUE rbncurs_c_field_pad(VALUE rb_field) {
730
+ FIELD* field = get_field(rb_field);
731
+ return INT2NUM(field_pad(field));
732
+ }
733
+ static VALUE rbncurs_m_field_pad(VALUE dummy, VALUE rb_field)
734
+ { return rbncurs_c_field_pad(rb_field); }
735
+
736
+ /*
737
+ * field_buffer
738
+ */
739
+ static VALUE rbncurs_c_set_field_buffer(VALUE rb_field, VALUE buf, VALUE value) {
740
+ FIELD* field = get_field(rb_field);
741
+ return INT2NUM(set_field_buffer(field, NUM2INT(buf), STR2CSTR(value)));
742
+ }
743
+ static VALUE rbncurs_m_set_field_buffer(VALUE dummy, VALUE rb_field, VALUE buf, VALUE value)
744
+ { return rbncurs_c_set_field_buffer(rb_field, buf, value); }
745
+
746
+ static VALUE rbncurs_c_field_buffer(VALUE rb_field, VALUE buffer) {
747
+ FIELD* field = get_field(rb_field);
748
+ return rb_str_new2(field_buffer(field, NUM2INT(buffer)));
749
+ }
750
+ static VALUE rbncurs_m_field_buffer(VALUE dummy, VALUE rb_field, VALUE buffer)
751
+ { return rbncurs_c_field_buffer(rb_field, buffer); }
752
+
753
+ static VALUE rbncurs_c_set_field_status(VALUE rb_field, VALUE status) {
754
+ FIELD* field = get_field(rb_field);
755
+ return INT2NUM(set_field_status(field, RTEST(status)));
756
+ }
757
+ static VALUE rbncurs_m_set_field_status(VALUE dummy, VALUE rb_field, VALUE status)
758
+ { return rbncurs_c_set_field_status(rb_field, status); }
759
+
760
+ static VALUE rbncurs_c_field_status(VALUE rb_field) {
761
+ FIELD* field = get_field(rb_field);
762
+ return (field_status(field)) ? Qtrue: Qfalse;
763
+ }
764
+ static VALUE rbncurs_m_field_status(VALUE dummy, VALUE rb_field)
765
+ { return rbncurs_c_field_status(rb_field); }
766
+
767
+ static VALUE rbncurs_c_set_max_field(VALUE rb_field, VALUE max) {
768
+ FIELD* field = get_field(rb_field);
769
+ return INT2NUM(set_max_field(field, NUM2INT(max)));
770
+ }
771
+ static VALUE rbncurs_m_set_max_field(VALUE dummy, VALUE rb_field, VALUE max)
772
+ { return rbncurs_c_set_max_field(rb_field, max); }
773
+
774
+ /*
775
+ * form_field
776
+ */
777
+ static VALUE rbncurs_c_set_form_fields(VALUE rb_form, VALUE rb_field_array) {
778
+ long n = RARRAY(rb_field_array)->len;
779
+ /* If ncurses does not free memory used by the previous array of strings, */
780
+ /* we will have to do it now. */
781
+ FIELD** fields = ALLOC_N(FIELD*, (n+1));
782
+ long i;
783
+ FORM* form = NULL;
784
+ for (i=0; i<n; i++){
785
+ fields[i] = get_field(rb_ary_entry(rb_field_array, i));
786
+ }
787
+ fields[n] = NULL;
788
+ form = get_form(rb_form);
789
+ return INT2NUM(set_form_fields(form, fields));
790
+ }
791
+ static VALUE rbncurs_m_set_form_fields(VALUE dummy, VALUE rb_form, VALUE rb_field_array)
792
+ { return rbncurs_c_set_form_fields(rb_form, rb_field_array); }
793
+
794
+ static VALUE rbncurs_c_form_fields(VALUE rb_form) {
795
+ FORM* form = get_form(rb_form);
796
+ FIELD** fields = form_fields(form);
797
+ VALUE arr = Qundef;
798
+ int i;
799
+ if (fields == NULL)
800
+ rb_raise(rb_eRuntimeError, "Error retrieving form fields");
801
+ arr = rb_ary_new();
802
+ i=0;
803
+ while (fields[i] != NULL)
804
+ {
805
+ rb_ary_push(arr, wrap_field(fields[i++]));
806
+ }
807
+ return arr;
808
+ }
809
+ static VALUE rbncurs_m_form_fields(VALUE dummy, VALUE rb_form)
810
+ { return rbncurs_c_form_fields(rb_form); }
811
+
812
+ static VALUE rbncurs_c_field_count(VALUE rb_form) {
813
+ FORM* form = get_form(rb_form);
814
+ return INT2NUM(field_count(form));
815
+ }
816
+ static VALUE rbncurs_m_field_count(VALUE dummy, VALUE rb_form)
817
+ { return rbncurs_c_field_count(rb_form); }
818
+
819
+ static VALUE rbncurs_c_move_field(VALUE rb_field, VALUE frow, VALUE fcol) {
820
+ FIELD* field = get_field(rb_field);
821
+ return INT2NUM(move_field(field, NUM2INT(frow), NUM2INT(fcol)));
822
+ }
823
+ static VALUE rbncurs_m_move_field(VALUE dummy, VALUE rb_field, VALUE frow, VALUE fcol)
824
+ { return rbncurs_c_move_field(rb_field, frow, fcol); }
825
+
826
+
827
+ /*
828
+ * form_hook
829
+ */
830
+ static void field_init_hook(FORM* form) {
831
+ /* Find the Proc object associated with this form */
832
+ VALUE proc = get_proc(form, FIELD_INIT_HOOK);
833
+ if (proc != Qnil) {
834
+ VALUE rb_form = wrap_form(form);
835
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
836
+ }
837
+ }
838
+ static VALUE rbncurs_c_set_field_init(VALUE rb_form, VALUE proc) {
839
+ FORM* form = NULL;
840
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
841
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
842
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
843
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
844
+ form = get_form(rb_form);
845
+ reg_proc(form, FIELD_INIT_HOOK, proc);
846
+ if (proc != Qnil) {
847
+ return INT2NUM(set_field_init(form, field_init_hook));
848
+ }
849
+ else {
850
+ return INT2NUM(set_field_init(form, NULL));
851
+ }
852
+ }
853
+ static VALUE rbncurs_m_set_field_init(VALUE dummy, VALUE rb_form, VALUE proc)
854
+ { return rbncurs_c_set_field_init(rb_form, proc); }
855
+
856
+ static VALUE rbncurs_c_field_init(VALUE rb_form) {
857
+ FORM* form = get_form(rb_form);
858
+ return get_proc(form, FIELD_INIT_HOOK);
859
+ }
860
+ static VALUE rbncurs_m_field_init(VALUE dummy, VALUE rb_form)
861
+ { return rbncurs_c_field_init(rb_form); }
862
+
863
+ static void field_term_hook(FORM* form) {
864
+ /* Find the Proc object associated with this form */
865
+ VALUE proc = get_proc(form, FIELD_TERM_HOOK);
866
+ if (proc != Qnil) {
867
+ VALUE rb_form = wrap_form(form);
868
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
869
+ }
870
+ }
871
+ static VALUE rbncurs_c_set_field_term(VALUE rb_form, VALUE proc) {
872
+ FORM * form = NULL;
873
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
874
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
875
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
876
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
877
+ form = get_form(rb_form);
878
+ reg_proc(form, FIELD_TERM_HOOK, proc);
879
+ if (proc != Qnil) {
880
+ return INT2NUM(set_field_term(form, field_term_hook));
881
+ }
882
+ else {
883
+ return INT2NUM(set_field_term(form, NULL));
884
+ }
885
+ }
886
+ static VALUE rbncurs_m_set_field_term(VALUE dummy, VALUE rb_form, VALUE proc)
887
+ { return rbncurs_c_set_field_term(rb_form, proc); }
888
+
889
+ static VALUE rbncurs_c_field_term(VALUE rb_form) {
890
+ FORM* form = get_form(rb_form);
891
+ return get_proc(form, FIELD_TERM_HOOK);
892
+ }
893
+ static VALUE rbncurs_m_field_term(VALUE dummy, VALUE rb_form)
894
+ { return rbncurs_c_field_term(rb_form); }
895
+
896
+ static void form_init_hook(FORM* form) {
897
+ /* Find the Proc object associated with this form */
898
+ VALUE proc = get_proc(form, FORM_INIT_HOOK);
899
+ if (proc != Qnil) {
900
+ VALUE rb_form = wrap_form(form);
901
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
902
+ }
903
+ }
904
+ static VALUE rbncurs_c_set_form_init(VALUE rb_form, VALUE proc) {
905
+ FORM * form = NULL;
906
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
907
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
908
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
909
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
910
+ form = get_form(rb_form);
911
+ reg_proc(form, FORM_INIT_HOOK, proc);
912
+ if (proc != Qnil) {
913
+ return INT2NUM(set_form_init(form, form_init_hook));
914
+ }
915
+ else {
916
+ return INT2NUM(set_form_init(form, NULL));
917
+ }
918
+ }
919
+ static VALUE rbncurs_m_set_form_init(VALUE dummy, VALUE rb_form, VALUE proc)
920
+ { return rbncurs_c_set_form_init(rb_form, proc); }
921
+
922
+ static VALUE rbncurs_c_form_init(VALUE rb_form) {
923
+ FORM* form = get_form(rb_form);
924
+ return get_proc(form, FORM_INIT_HOOK);
925
+ }
926
+ static VALUE rbncurs_m_form_init(VALUE dummy, VALUE rb_form)
927
+ { return rbncurs_c_form_init(rb_form); }
928
+
929
+ static void form_term_hook(FORM* form) {
930
+ /* Find the Proc object associated with this form */
931
+ VALUE proc = get_proc(form, FORM_TERM_HOOK);
932
+ if (proc != Qnil) {
933
+ VALUE rb_form = wrap_form(form);
934
+ rb_funcall(proc, rb_intern("call"), 1, rb_form);
935
+ }
936
+ }
937
+ static VALUE rbncurs_c_set_form_term(VALUE rb_form, VALUE proc) {
938
+ FORM * form = NULL;
939
+ if (!rb_obj_is_kind_of(rb_form, cFORM))
940
+ rb_raise(rb_eArgError, "arg1 must be a FORM object");
941
+ if (!rb_obj_is_kind_of(proc, rb_cProc))
942
+ rb_raise(rb_eArgError, "arg2 must be a Proc object");
943
+ form = get_form(rb_form);
944
+ reg_proc(form, FORM_TERM_HOOK, proc);
945
+ if (proc != Qnil) {
946
+ return INT2NUM(set_form_term(form, form_term_hook));
947
+ }
948
+ else {
949
+ return INT2NUM(set_form_term(form, NULL));
950
+ }
951
+ }
952
+ static VALUE rbncurs_m_set_form_term(VALUE dummy, VALUE rb_form, VALUE proc)
953
+ { return rbncurs_c_set_form_term(rb_form, proc); }
954
+
955
+ static VALUE rbncurs_c_form_term(VALUE rb_form) {
956
+ FORM* form = get_form(rb_form);
957
+ return get_proc(form, FORM_TERM_HOOK);
958
+ }
959
+ static VALUE rbncurs_m_form_term(VALUE dummy, VALUE rb_form)
960
+ { return rbncurs_c_form_term(rb_form); }
961
+
962
+ /*
963
+ * form_field_just
964
+ */
965
+ static VALUE rbncurs_c_set_field_just(VALUE rb_field, VALUE justification) {
966
+ FIELD* field = get_field(rb_field);
967
+ return INT2NUM(set_field_just(field, NUM2INT(justification)));
968
+ }
969
+ static VALUE rbncurs_m_set_field_just(VALUE dummy, VALUE rb_field, VALUE justification)
970
+ { return rbncurs_c_set_field_just(rb_field, justification); }
971
+
972
+ static VALUE rbncurs_c_field_just(VALUE rb_field) {
973
+ FIELD* field = get_field(rb_field);
974
+ return INT2NUM(field_just(field));
975
+ }
976
+ static VALUE rbncurs_m_field_just(VALUE dummy, VALUE rb_field)
977
+ { return rbncurs_c_field_just(rb_field); }
978
+
979
+ /*
980
+ * form_field_opts
981
+ */
982
+ static VALUE rbncurs_c_set_field_opts(VALUE rb_field, VALUE opts) {
983
+ FIELD* field = get_field(rb_field);
984
+ return INT2NUM(set_field_opts(field, NUM2INT(opts)));
985
+ }
986
+ static VALUE rbncurs_m_set_field_opts(VALUE dummy, VALUE rb_field, VALUE opts)
987
+ { return rbncurs_c_set_field_opts(rb_field, opts); }
988
+
989
+ static VALUE rbncurs_c_field_opts_on(VALUE rb_field, VALUE opts) {
990
+ FIELD* field = get_field(rb_field);
991
+ return INT2NUM(field_opts_on(field, NUM2INT(opts)));
992
+ }
993
+ static VALUE rbncurs_m_field_opts_on(VALUE dummy, VALUE rb_field, VALUE opts)
994
+ { return rbncurs_c_field_opts_on(rb_field, opts); }
995
+
996
+ static VALUE rbncurs_c_field_opts_off(VALUE rb_field, VALUE opts) {
997
+ FIELD* field = get_field(rb_field);
998
+ return INT2NUM(field_opts_off(field, NUM2INT(opts)));
999
+ }
1000
+ static VALUE rbncurs_m_field_opts_off(VALUE dummy, VALUE rb_field, VALUE opts)
1001
+ { return rbncurs_c_field_opts_off(rb_field, opts); }
1002
+
1003
+ static VALUE rbncurs_c_field_opts(VALUE rb_field) {
1004
+ FIELD* field = get_field(rb_field);
1005
+ return INT2NUM(field_opts(field));
1006
+ }
1007
+ static VALUE rbncurs_m_field_opts(VALUE dummy, VALUE rb_field)
1008
+ { return rbncurs_c_field_opts(rb_field); }
1009
+
1010
+ /*
1011
+ * form_opts
1012
+ */
1013
+ static VALUE rbncurs_c_set_form_opts(VALUE rb_form, VALUE opts) {
1014
+ FORM* form = get_form(rb_form);
1015
+ return INT2NUM(set_form_opts(form, NUM2INT(opts)));
1016
+ }
1017
+ static VALUE rbncurs_m_set_form_opts(VALUE dummy, VALUE rb_form, VALUE opts)
1018
+ { return rbncurs_c_set_form_opts(rb_form, opts); }
1019
+
1020
+ static VALUE rbncurs_c_form_opts_on(VALUE rb_form, VALUE opts) {
1021
+ FORM* form = get_form(rb_form);
1022
+ return INT2NUM(form_opts_on(form, NUM2INT(opts)));
1023
+ }
1024
+ static VALUE rbncurs_m_form_opts_on(VALUE dummy, VALUE rb_form, VALUE opts)
1025
+ { return rbncurs_c_form_opts_on(rb_form, opts); }
1026
+
1027
+ static VALUE rbncurs_c_form_opts_off(VALUE rb_form, VALUE opts) {
1028
+ FORM* form = get_form(rb_form);
1029
+ return INT2NUM(form_opts_off(form, NUM2INT(opts)));
1030
+ }
1031
+ static VALUE rbncurs_m_form_opts_off(VALUE dummy, VALUE rb_form, VALUE opts)
1032
+ { return rbncurs_c_form_opts_off(rb_form, opts); }
1033
+
1034
+ static VALUE rbncurs_c_form_opts(VALUE rb_form) {
1035
+ FORM* form = get_form(rb_form);
1036
+ return INT2NUM(form_opts(form));
1037
+ }
1038
+ static VALUE rbncurs_m_form_opts(VALUE dummy, VALUE rb_form)
1039
+ { return rbncurs_c_form_opts(rb_form); }
1040
+
1041
+ /*
1042
+ * form_requestname
1043
+ */
1044
+ static VALUE rbncurs_c_form_request_name(VALUE request) {
1045
+ return rb_str_new2(form_request_name(NUM2INT(request)));
1046
+ }
1047
+ static VALUE rbncurs_m_form_request_name(VALUE dummy, VALUE request)
1048
+ { return rbncurs_c_form_request_name(request); }
1049
+
1050
+ static VALUE rbncurs_c_form_request_by_name(VALUE name) {
1051
+ return INT2NUM(form_request_by_name(STR2CSTR(name)));
1052
+ }
1053
+ static VALUE rbncurs_m_form_request_by_name(VALUE dummy, VALUE name)
1054
+ { return rbncurs_c_form_request_by_name(name); }
1055
+
1056
+ /*
1057
+ * form_win
1058
+ */
1059
+ static VALUE rbncurs_c_set_form_win(VALUE rb_form, VALUE rb_win) {
1060
+ FORM* form = get_form(rb_form);
1061
+ WINDOW* win = get_window(rb_win);
1062
+ return INT2NUM(set_form_win(form, win));
1063
+ }
1064
+ static VALUE rbncurs_m_set_form_win(VALUE dummy, VALUE rb_form, VALUE rb_win)
1065
+ { return rbncurs_c_set_form_win(rb_form, rb_win); }
1066
+
1067
+ static VALUE rbncurs_c_form_win(VALUE rb_form) {
1068
+ FORM* form = get_form(rb_form);
1069
+ return wrap_window(form_win(form));
1070
+ }
1071
+ static VALUE rbncurs_m_form_win(VALUE dummy, VALUE rb_form)
1072
+ { return rbncurs_c_form_win(rb_form); }
1073
+
1074
+ static VALUE rbncurs_c_set_form_sub(VALUE rb_form, VALUE rb_sub) {
1075
+ FORM* form = get_form(rb_form);
1076
+ WINDOW* win = get_window(rb_sub);
1077
+ return INT2NUM(set_form_sub(form, win));
1078
+ }
1079
+ static VALUE rbncurs_m_set_form_sub(VALUE dummy, VALUE rb_form, VALUE rb_sub)
1080
+ { return rbncurs_c_set_form_sub(rb_form, rb_sub); }
1081
+
1082
+ static VALUE rbncurs_c_form_sub(VALUE rb_form) {
1083
+ FORM* form = get_form(rb_form);
1084
+ return wrap_window(form_sub(form));
1085
+ }
1086
+ static VALUE rbncurs_m_form_sub(VALUE dummy, VALUE rb_form)
1087
+ { return rbncurs_c_form_sub(rb_form); }
1088
+
1089
+ static VALUE rbncurs_c_scale_form(VALUE rb_form, VALUE rows, VALUE columns) {
1090
+ FORM* form = get_form(rb_form);
1091
+ if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
1092
+ || rb_obj_is_instance_of(columns, rb_cArray) != Qtrue) {
1093
+ rb_raise(rb_eArgError,
1094
+ "rows and columns arguments must be empty Arrays");
1095
+ return Qnil;
1096
+ }
1097
+ else {
1098
+ int vals[2] = {0,0};
1099
+ int result = scale_form(form, &vals[0],&vals[1]);
1100
+ rb_ary_push(rows, INT2NUM(vals[0]));
1101
+ rb_ary_push(columns, INT2NUM(vals[1]));
1102
+ return INT2NUM(result);
1103
+ }
1104
+ }
1105
+ static VALUE rbncurs_m_scale_form(VALUE dummy, VALUE rb_form, VALUE rows, VALUE columns)
1106
+ { return rbncurs_c_scale_form(rb_form, rows, columns); }
1107
+
1108
+ /*
1109
+ * form_fieldtype
1110
+ */
1111
+ static void* make_arg(va_list* ap) {
1112
+ /* This method creates a list of arguments to be passed */
1113
+ /* to the validation functions (char_check and field_check). */
1114
+ FIELD* field = va_arg(*ap, FIELD*);
1115
+ FIELDTYPE* fieldtype = field_type(field);
1116
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
1117
+ if (proc == Qnil) {
1118
+ proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
1119
+ }
1120
+
1121
+ /* Compare number of arguments in Ruby Proc with that of set_field_type */
1122
+ if (proc != Qnil) {
1123
+ VALUE argc = rb_funcall(proc, rb_intern("arity"),0);
1124
+ VALUE args = get_proc(field, FIELDTYPE_ARGS);
1125
+ if (args != Qnil) {
1126
+ if (NUM2INT(argc)-1 != RARRAY(args)->len) {
1127
+ char msg[500];
1128
+ snprintf(msg, 500, "The validation functions for this field type need %d additional arguments.",NUM2INT(argc)-1);
1129
+ msg[499]=0;
1130
+ rb_raise(rb_eArgError, msg);
1131
+ }
1132
+ }
1133
+ }
1134
+ /* field will be the only argument in field_check/char_check callback */
1135
+ /* and will be used to locate the appropriate Ruby Proc */
1136
+ return field;
1137
+ }
1138
+ static bool field_check(FIELD* field, const void* argblock) {
1139
+ FIELDTYPE* fieldtype = field_type(field);
1140
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
1141
+ if (proc != Qnil)
1142
+ {
1143
+ VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
1144
+ rb_ary_unshift(args, wrap_field(field));
1145
+ return RTEST(rb_apply(proc, rb_intern("call"), args));
1146
+ }
1147
+ return true;
1148
+ }
1149
+ static bool char_check(int c, const void* argblock) {
1150
+ FIELD* field = (FIELD*)argblock;
1151
+ FIELDTYPE* fieldtype = field_type(field);
1152
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
1153
+ if (proc != Qnil) {
1154
+ VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
1155
+ char str[2];
1156
+ str[0] = c;
1157
+ str[1] = 0;
1158
+ rb_ary_unshift(args, rb_str_new2(str));
1159
+ return RTEST(rb_apply(proc, rb_intern("call"), args));
1160
+ }
1161
+ return true;
1162
+ }
1163
+ static VALUE rbncurs_m_new_fieldtype(VALUE dummy, VALUE field_check_proc, VALUE char_check_proc)
1164
+ {
1165
+ FIELDTYPE* fieldtype = new_fieldtype(field_check_proc == Qnil ? NULL : field_check,
1166
+ char_check_proc == Qnil ? NULL : char_check);
1167
+ set_fieldtype_arg(fieldtype, make_arg, NULL, NULL);
1168
+ if (field_check_proc != Qnil) {
1169
+ reg_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK, field_check_proc);
1170
+ }
1171
+ if (char_check_proc != Qnil) {
1172
+ reg_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK, char_check_proc);
1173
+ }
1174
+
1175
+ return wrap_fieldtype(fieldtype);
1176
+ }
1177
+
1178
+ static VALUE rbncurs_c_free_fieldtype(VALUE rb_fieldtype) {
1179
+ FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
1180
+ return INT2NUM(free_fieldtype(fieldtype));
1181
+ }
1182
+ static VALUE rbncurs_m_free_fieldtype(VALUE dummy, VALUE rb_field)
1183
+ { return rbncurs_c_free_fieldtype(rb_field); }
1184
+
1185
+ static bool next_choice(FIELD* field, const void* argblock) {
1186
+ FIELDTYPE* fieldtype = field_type(field);
1187
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK);
1188
+ if (proc != Qnil) {
1189
+ /* Need to find out what exactly is argblock about... */
1190
+ return RTEST(rb_funcall(proc, rb_intern("call"), 1, wrap_field(field)));
1191
+ }
1192
+ return true;
1193
+ }
1194
+ static bool prev_choice(FIELD* field, const void* argblock) {
1195
+ FIELDTYPE* fieldtype = field_type(field);
1196
+ VALUE proc = get_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK);
1197
+ if (proc != Qnil) {
1198
+ /* Need to find out what exactly is argblock about... */
1199
+ return RTEST(rb_funcall(proc, rb_intern("call"), 1, wrap_field(field)));
1200
+ }
1201
+ return true;
1202
+ }
1203
+
1204
+ static VALUE rbncurs_c_set_fieldtype_choice(VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc) {
1205
+ FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
1206
+ int result = set_fieldtype_choice(fieldtype,
1207
+ next_choice_proc == Qnil ? NULL : next_choice,
1208
+ prev_choice_proc == Qnil ? NULL : prev_choice);
1209
+ if (next_choice_proc != Qnil)
1210
+ reg_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK, next_choice_proc);
1211
+ if (prev_choice_proc != Qnil)
1212
+ reg_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK, prev_choice_proc);
1213
+ return INT2NUM(result);
1214
+ }
1215
+ static VALUE rbncurs_m_set_fieldtype_choice(VALUE dummy, VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc)
1216
+ { return rbncurs_c_set_fieldtype_choice(rb_fieldtype, next_choice_proc, prev_choice_proc); }
1217
+
1218
+ static VALUE rbncurs_c_link_fieldtype(VALUE rb_fieldtype1, VALUE rb_fieldtype2) {
1219
+ FIELDTYPE* fieldtype1 = get_fieldtype(rb_fieldtype1);
1220
+ FIELDTYPE* fieldtype2 = get_fieldtype(rb_fieldtype2);
1221
+ return wrap_fieldtype(link_fieldtype(fieldtype1, fieldtype2));
1222
+ }
1223
+ static VALUE rbncurs_m_link_fieldtype(VALUE dummy, VALUE rb_fieldtype1, VALUE fieldtype2)
1224
+ { return rbncurs_c_link_fieldtype(rb_fieldtype1, fieldtype2); }
1225
+
1226
+ static VALUE rbncurs_c_set_new_page(VALUE rb_field, VALUE new_page_flag) {
1227
+ FIELD* field = get_field(rb_field);
1228
+ return INT2NUM(set_new_page(field, RTEST(new_page_flag)));
1229
+ }
1230
+ static VALUE rbncurs_m_set_new_page(VALUE dummy, VALUE rb_field, VALUE new_page_flag)
1231
+ { return rbncurs_c_set_new_page(rb_field, new_page_flag); }
1232
+
1233
+ static VALUE rbncurs_c_new_page(VALUE rb_field) {
1234
+ FIELD* field = get_field(rb_field);
1235
+ return (new_page(field))? Qtrue : Qfalse;
1236
+ }
1237
+ static VALUE rbncurs_m_new_page(VALUE dummy, VALUE rb_field)
1238
+ { return rbncurs_c_new_page(rb_field); }
1239
+
1240
+ /*
1241
+ * form_cursor
1242
+ */
1243
+ static VALUE rbncurs_c_pos_form_cursor(VALUE rb_form) {
1244
+ FORM* form = get_form(rb_form);
1245
+ return INT2NUM(pos_form_cursor(form));
1246
+ }
1247
+ static VALUE rbncurs_m_pos_form_cursor(VALUE dummy, VALUE rb_form)
1248
+ { return rbncurs_c_pos_form_cursor(rb_form); }
1249
+
1250
+ void init_form(void)
1251
+ {
1252
+
1253
+ mForm = rb_define_module_under(mNcurses, "Form");
1254
+
1255
+ FORM_SNG_FUNC(current_field,1);
1256
+ FORM_SNG_FUNC(data_ahead,1);
1257
+ FORM_SNG_FUNC(data_behind,1);
1258
+ FORM_SNG_FUNC(dup_field,3);
1259
+ FORM_SNG_FUNC(dynamic_field_info,3);
1260
+ FORM_SNG_FUNC(field_arg,1);
1261
+ FORM_SNG_FUNC(field_back,2);
1262
+ FORM_SNG_FUNC(field_buffer,2);
1263
+ FORM_SNG_FUNC(field_count,1);
1264
+ FORM_SNG_FUNC(field_fore,2);
1265
+ FORM_SNG_FUNC(field_index,1);
1266
+ FORM_SNG_FUNC(field_info,7);
1267
+ FORM_SNG_FUNC(field_init,1);
1268
+ FORM_SNG_FUNC(field_just,1);
1269
+ FORM_SNG_FUNC(field_opts,1);
1270
+ FORM_SNG_FUNC(field_opts_off,2);
1271
+ FORM_SNG_FUNC(field_opts_on,2);
1272
+ FORM_SNG_FUNC(field_pad,2);
1273
+ FORM_SNG_FUNC(field_status,1);
1274
+ FORM_SNG_FUNC(field_term,1);
1275
+ FORM_SNG_FUNC(field_type,1);
1276
+ /* FORM_SNG_FUNC(field_userptr,1); */
1277
+ FORM_SNG_FUNC(form_driver,2);
1278
+ FORM_SNG_FUNC(form_fields,1);
1279
+ FORM_SNG_FUNC(form_init,1);
1280
+ FORM_SNG_FUNC(form_opts,1);
1281
+ FORM_SNG_FUNC(form_opts_off,2);
1282
+ FORM_SNG_FUNC(form_opts_on,2);
1283
+ FORM_SNG_FUNC(form_page,1);
1284
+ FORM_SNG_FUNC(form_request_by_name,1);
1285
+ FORM_SNG_FUNC(form_request_name,1);
1286
+ FORM_SNG_FUNC(form_sub,1);
1287
+ FORM_SNG_FUNC(form_term,1);
1288
+ /* FORM_SNG_FUNC(form_userptr,1); */
1289
+ FORM_SNG_FUNC(form_win,1);
1290
+ FORM_SNG_FUNC(free_field,1);
1291
+ FORM_SNG_FUNC(free_fieldtype,1);
1292
+ FORM_SNG_FUNC(free_form,1);
1293
+ FORM_SNG_FUNC(link_field,3);
1294
+ FORM_SNG_FUNC(link_fieldtype,2);
1295
+ FORM_SNG_FUNC(move_field,3);
1296
+ FORM_SNG_FUNC(new_field,6);
1297
+ FORM_SNG_FUNC(new_fieldtype,2);
1298
+ FORM_SNG_FUNC(new_form,1);
1299
+ FORM_SNG_FUNC(new_page,1);
1300
+ FORM_SNG_FUNC(pos_form_cursor,1);
1301
+ FORM_SNG_FUNC(post_form,1);
1302
+ FORM_SNG_FUNC(scale_form,3);
1303
+ FORM_SNG_FUNC(set_current_field,2);
1304
+ FORM_SNG_FUNC(set_field_back,2);
1305
+ FORM_SNG_FUNC(set_field_buffer,3);
1306
+ FORM_SNG_FUNC(set_field_fore,2);
1307
+ FORM_SNG_FUNC(set_field_init,2);
1308
+ FORM_SNG_FUNC(set_field_just,2);
1309
+ FORM_SNG_FUNC(set_field_opts,2);
1310
+ FORM_SNG_FUNC(set_field_pad,2);
1311
+ FORM_SNG_FUNC(set_field_status,2);
1312
+ FORM_SNG_FUNC(set_field_term,2);
1313
+ FORM_SNG_FUNC(set_field_type,-1);
1314
+ /* FORM_SNG_FUNC(set_field_userptr,2); */
1315
+ FORM_SNG_FUNC(set_fieldtype_choice,3);
1316
+ FORM_SNG_FUNC(set_form_fields,2);
1317
+ FORM_SNG_FUNC(set_form_init,2);
1318
+ FORM_SNG_FUNC(set_form_opts,2);
1319
+ FORM_SNG_FUNC(set_form_page,2);
1320
+ FORM_SNG_FUNC(set_form_sub,2);
1321
+ FORM_SNG_FUNC(set_form_term,2);
1322
+ /* FORM_SNG_FUNC(set_form_userptr,2); */
1323
+ FORM_SNG_FUNC(set_form_win,2);
1324
+ FORM_SNG_FUNC(set_max_field,2);
1325
+ FORM_SNG_FUNC(set_new_page,2);
1326
+ FORM_SNG_FUNC(unpost_form,1);
1327
+
1328
+ init_err_codes();
1329
+ init_req_constants();
1330
+ init_opts_constants();
1331
+ init_just_constants();
1332
+ init_form_opts_constants();
1333
+
1334
+ /* Hashes to store registered blocks (Proc) */
1335
+ {
1336
+ VALUE hashes = rb_iv_set(mForm, "@proc_hashes", rb_ary_new());
1337
+ int i;
1338
+ for (i = 0; i < PROC_HASHES_COUNT; i++)
1339
+ {
1340
+ rb_ary_push(hashes, rb_hash_new());
1341
+ }
1342
+ }
1343
+
1344
+ /* Forms */
1345
+ rb_iv_set(mForm, "@forms_hash", rb_hash_new());
1346
+ cFORM = rb_define_class_under(mForm, "FORM", rb_cObject);
1347
+ rb_define_singleton_method(cFORM, "new",
1348
+ (&rbncurs_m_new_form),
1349
+ 1);
1350
+ RB_CLASS_METH(cFORM, current_field,0);
1351
+ RB_CLASS_METH(cFORM, data_ahead,0);
1352
+ RB_CLASS_METH(cFORM, data_behind,0);
1353
+ RB_CLASS_METH(cFORM, dup_field,2);
1354
+ RB_CLASS_METH(cFORM, field_count,0);
1355
+ RB_CLASS_METH(cFORM, field_init,0);
1356
+ RB_CLASS_METH(cFORM, field_term,0);
1357
+ RB_CLASS_METH(cFORM, form_driver,1);
1358
+ RB_CLASS_METH(cFORM, form_fields,0);
1359
+ RB_CLASS_METH(cFORM, form_init,0);
1360
+ RB_CLASS_METH(cFORM, form_opts,0);
1361
+ RB_CLASS_METH(cFORM, form_opts_off,1);
1362
+ RB_CLASS_METH(cFORM, form_opts_on,1);
1363
+ RB_CLASS_METH(cFORM, form_page,0);
1364
+ RB_CLASS_METH(cFORM, form_sub,0);
1365
+ RB_CLASS_METH(cFORM, form_term,0);
1366
+ /* RB_CLASS_METH(cFORM, form_userptr,0); */
1367
+ RB_CLASS_METH(cFORM, form_win,0);
1368
+ RB_CLASS_METH(cFORM, free_form,0);
1369
+ RB_CLASS_METH(cFORM, pos_form_cursor,0);
1370
+ RB_CLASS_METH(cFORM, post_form,0);
1371
+ RB_CLASS_METH(cFORM, scale_form,2);
1372
+ RB_CLASS_METH(cFORM, set_current_field,1);
1373
+ RB_CLASS_METH(cFORM, set_field_init,1);
1374
+ RB_CLASS_METH(cFORM, set_field_term,1);
1375
+ RB_CLASS_METH(cFORM, set_form_fields,1);
1376
+ RB_CLASS_METH(cFORM, set_form_init,1);
1377
+ RB_CLASS_METH(cFORM, set_form_opts,1);
1378
+ RB_CLASS_METH(cFORM, set_form_page,1);
1379
+ RB_CLASS_METH(cFORM, set_form_sub,1);
1380
+ RB_CLASS_METH(cFORM, set_form_term,1);
1381
+ /* RB_CLASS_METH(cFORM, set_form_userptr,1); */
1382
+ RB_CLASS_METH(cFORM, set_form_win,1);
1383
+ RB_CLASS_METH(cFORM, unpost_form,0);
1384
+
1385
+ /* Fields */
1386
+ rb_iv_set(mForm, "@fields_hash", rb_hash_new());
1387
+ cFIELD = rb_define_class_under(mForm, "FIELD", rb_cObject);
1388
+ rb_define_singleton_method(cFIELD, "new",
1389
+ (&rbncurs_m_new_field),
1390
+ 6);
1391
+ RB_CLASS_METH(cFIELD, dup_field,2);
1392
+ RB_CLASS_METH(cFIELD, dynamic_field_info,2);
1393
+ RB_CLASS_METH(cFIELD, field_arg,0);
1394
+ RB_CLASS_METH(cFIELD, field_back,1);
1395
+ RB_CLASS_METH(cFIELD, field_buffer,1);
1396
+ RB_CLASS_METH(cFIELD, field_fore,1);
1397
+ RB_CLASS_METH(cFIELD, field_index,0);
1398
+ RB_CLASS_METH(cFIELD, field_info,6);
1399
+ RB_CLASS_METH(cFIELD, field_just,0);
1400
+ RB_CLASS_METH(cFIELD, field_opts,0);
1401
+ RB_CLASS_METH(cFIELD, field_opts_off,1);
1402
+ RB_CLASS_METH(cFIELD, field_opts_on,1);
1403
+ RB_CLASS_METH(cFIELD, field_pad,1);
1404
+ RB_CLASS_METH(cFIELD, field_status,0);
1405
+ RB_CLASS_METH(cFIELD, field_type,0);
1406
+ /* RB_CLASS_METH(cFIELD, field_userptr,0); */
1407
+ RB_CLASS_METH(cFIELD, free_field,0);
1408
+ RB_CLASS_METH(cFIELD, link_field,2);
1409
+ RB_CLASS_METH(cFIELD, move_field,2);
1410
+ RB_CLASS_METH(cFIELD, new_page,0);
1411
+ RB_CLASS_METH(cFIELD, set_field_back,1);
1412
+ RB_CLASS_METH(cFIELD, set_field_buffer,2);
1413
+ RB_CLASS_METH(cFIELD, set_field_fore,1);
1414
+ RB_CLASS_METH(cFIELD, set_field_just,1);
1415
+ RB_CLASS_METH(cFIELD, set_field_opts,1);
1416
+ RB_CLASS_METH(cFIELD, set_field_pad,1);
1417
+ RB_CLASS_METH(cFIELD, set_field_status,1);
1418
+ RB_CLASS_METH(cFIELD, set_field_type,-1);
1419
+ /* RB_CLASS_METH(cFIELD, set_field_userptr,1); */
1420
+ RB_CLASS_METH(cFIELD, set_max_field,1);
1421
+ RB_CLASS_METH(cFIELD, set_new_page,1);
1422
+
1423
+
1424
+
1425
+
1426
+ /* Field types */
1427
+ rb_iv_set(mForm, "@fieldtypes_hash", rb_hash_new());
1428
+ cFIELDTYPE = rb_define_class_under(mForm, "FIELDTYPE", rb_cObject);
1429
+ rb_define_singleton_method(cFIELDTYPE, "new",
1430
+ (&rbncurs_m_new_fieldtype),
1431
+ 2);
1432
+ RB_CLASS_METH(cFIELDTYPE, free_fieldtype,0);
1433
+ RB_CLASS_METH(cFIELDTYPE, link_fieldtype,1);
1434
+ RB_CLASS_METH(cFIELDTYPE, set_fieldtype_choice,2);
1435
+
1436
+ /* Create predefined types */
1437
+ rb_define_const(mForm, "TYPE_ALNUM", wrap_fieldtype(TYPE_ALNUM));
1438
+ rb_define_const(mForm, "TYPE_ALPHA", wrap_fieldtype(TYPE_ALPHA));
1439
+ rb_define_const(mForm, "TYPE_ENUM", wrap_fieldtype(TYPE_ENUM));
1440
+ rb_define_const(mForm, "TYPE_INTEGER", wrap_fieldtype(TYPE_INTEGER));
1441
+ rb_define_const(mForm, "TYPE_NUMERIC", wrap_fieldtype(TYPE_NUMERIC));
1442
+ rb_define_const(mForm, "TYPE_REGEXP", wrap_fieldtype(TYPE_REGEXP));
1443
+ rb_define_const(mForm, "TYPE_IPV4", wrap_fieldtype(TYPE_IPV4));
1444
+
1445
+ }
1446
+
1447
+ #endif