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