ncurses-ruby 1.2.1
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/README +351 -0
- data/THANKS +15 -0
- data/TODO +15 -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/ext/ncurses/extconf.rb +139 -0
- data/ext/ncurses/form_wrap.c +1450 -0
- data/ext/ncurses/form_wrap.h +61 -0
- data/ext/ncurses/menu_wrap.c +1141 -0
- data/ext/ncurses/menu_wrap.h +49 -0
- data/ext/ncurses/ncurses_wrap.c +2739 -0
- data/ext/ncurses/ncurses_wrap.h +100 -0
- data/ext/ncurses/panel_wrap.c +256 -0
- data/ext/ncurses/panel_wrap.h +32 -0
- data/lib/ncurses-ruby/version.rb +5 -0
- data/lib/ncurses.rb +344 -0
- metadata +96 -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]}")
|
@@ -0,0 +1,139 @@
|
|
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
|
+
# Add paths for NetBSD.
|
29
|
+
$CFLAGS += " -I/usr/pkg/include"
|
30
|
+
$LDFLAGS += " -L/usr/pkg/lib"
|
31
|
+
|
32
|
+
have_header("unistd.h")
|
33
|
+
if have_header("ncurses.h")
|
34
|
+
curses_header = "ncurses.h"
|
35
|
+
elsif have_header("ncurses/curses.h")
|
36
|
+
curses_header = "ncurses/curses.h"
|
37
|
+
elsif have_header("curses.h")
|
38
|
+
curses_header = "curses.h"
|
39
|
+
else
|
40
|
+
raise "ncurses header file not found"
|
41
|
+
end
|
42
|
+
|
43
|
+
if have_library("ncurses", "wmove")
|
44
|
+
curses_lib = "ncurses"
|
45
|
+
elsif have_library("pdcurses", "wmove")
|
46
|
+
curses_lib = "pdcurses"
|
47
|
+
else
|
48
|
+
raise "ncurses library not found"
|
49
|
+
end
|
50
|
+
|
51
|
+
have_func("newscr")
|
52
|
+
have_func("TABSIZE")
|
53
|
+
have_func("ESCDELAY")
|
54
|
+
have_func("keybound")
|
55
|
+
have_func("curses_version")
|
56
|
+
have_func("tigetstr")
|
57
|
+
have_func("getwin")
|
58
|
+
have_func("putwin")
|
59
|
+
have_func("ungetmouse")
|
60
|
+
have_func("mousemask")
|
61
|
+
have_func("wenclose")
|
62
|
+
have_func("mouseinterval")
|
63
|
+
have_func("wmouse_trafo")
|
64
|
+
have_func("mcprint")
|
65
|
+
have_func("has_key")
|
66
|
+
|
67
|
+
have_func("delscreen")
|
68
|
+
have_func("define_key")
|
69
|
+
have_func("keyok")
|
70
|
+
have_func("resizeterm")
|
71
|
+
have_func("use_default_colors")
|
72
|
+
have_func("use_extended_names")
|
73
|
+
have_func("wresize")
|
74
|
+
have_func("attr_on")
|
75
|
+
have_func("attr_off")
|
76
|
+
have_func("attr_set")
|
77
|
+
have_func("chgat")
|
78
|
+
have_func("color_set")
|
79
|
+
have_func("filter")
|
80
|
+
have_func("intrflush")
|
81
|
+
have_func("mvchgat")
|
82
|
+
have_func("mvhline")
|
83
|
+
have_func("mvvline")
|
84
|
+
have_func("mvwchgat")
|
85
|
+
have_func("mvwhline")
|
86
|
+
have_func("mvwvline")
|
87
|
+
have_func("noqiflush")
|
88
|
+
have_func("putp")
|
89
|
+
have_func("qiflush")
|
90
|
+
have_func("scr_dump")
|
91
|
+
have_func("scr_init")
|
92
|
+
have_func("scr_restore")
|
93
|
+
have_func("scr_set")
|
94
|
+
have_func("slk_attr_off")
|
95
|
+
have_func("slk_attr_on")
|
96
|
+
have_func("slk_attr")
|
97
|
+
have_func("slk_attr_set")
|
98
|
+
have_func("slk_color")
|
99
|
+
have_func("tigetflag")
|
100
|
+
have_func("tigetnum")
|
101
|
+
have_func("use_env")
|
102
|
+
have_func("vidattr")
|
103
|
+
have_func("vid_attr")
|
104
|
+
have_func("wattr_on")
|
105
|
+
have_func("wattr_off")
|
106
|
+
have_func("wattr_set")
|
107
|
+
have_func("wchgat")
|
108
|
+
have_func("wcolor_set")
|
109
|
+
have_func("getattrs")
|
110
|
+
|
111
|
+
puts "checking which debugging functions to wrap..."
|
112
|
+
have_func("_tracef")
|
113
|
+
have_func("_tracedump")
|
114
|
+
have_func("_nc_tracebits")
|
115
|
+
have_func("_traceattr")
|
116
|
+
have_func("_traceattr2")
|
117
|
+
have_func("_tracechar")
|
118
|
+
have_func("_tracechtype")
|
119
|
+
have_func("_tracechtype2")
|
120
|
+
have_func("_tracemouse")
|
121
|
+
|
122
|
+
puts "checking for other functions that appeared after ncurses version 5.0..."
|
123
|
+
have_func("assume_default_colors")
|
124
|
+
have_func("attr_get")
|
125
|
+
|
126
|
+
puts "checking for the panel library..."
|
127
|
+
if have_header("panel.h")
|
128
|
+
have_library("panel", "panel_hidden")
|
129
|
+
end
|
130
|
+
puts "checking for the form library..."
|
131
|
+
if have_header("form.h")
|
132
|
+
have_library("form", "new_form")
|
133
|
+
end
|
134
|
+
puts "checking for the menu library..."
|
135
|
+
if have_header("menu.h")
|
136
|
+
have_library("menu", "new_menu")
|
137
|
+
end
|
138
|
+
|
139
|
+
create_makefile('ncurses')
|
@@ -0,0 +1,1450 @@
|
|
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
|
+
VALUE tmp = rb_ary_entry(arg3, (long)i);
|
627
|
+
list[i] = StringValuePtr(tmp);
|
628
|
+
}
|
629
|
+
list[n] = NULL;
|
630
|
+
return INT2NUM(set_field_type(field, ftype,
|
631
|
+
list,
|
632
|
+
RTEST(arg4),
|
633
|
+
RTEST(arg5)));
|
634
|
+
}
|
635
|
+
}
|
636
|
+
else if (ftype == TYPE_INTEGER) {
|
637
|
+
if (argc != 4)
|
638
|
+
rb_raise(rb_eArgError, "TYPE_INTEGER requires three additional arguments");
|
639
|
+
return INT2NUM(set_field_type(field, ftype,
|
640
|
+
NUM2INT(arg3),
|
641
|
+
NUM2LONG(arg4),
|
642
|
+
NUM2LONG(arg5)));
|
643
|
+
}
|
644
|
+
else if (ftype == TYPE_NUMERIC) {
|
645
|
+
if (argc != 4)
|
646
|
+
rb_raise(rb_eArgError, "TYPE_NUMERIC requires three additional arguments");
|
647
|
+
return INT2NUM(set_field_type(field, ftype,
|
648
|
+
NUM2INT(arg3),
|
649
|
+
NUM2DBL(arg4),
|
650
|
+
NUM2DBL(arg5)));
|
651
|
+
}
|
652
|
+
else if (ftype == TYPE_REGEXP){
|
653
|
+
if (argc != 2)
|
654
|
+
rb_raise(rb_eArgError, "TYPE_REGEXP requires one additional argument");
|
655
|
+
return INT2NUM(set_field_type(field, ftype,
|
656
|
+
StringValuePtr(arg3)));
|
657
|
+
}
|
658
|
+
else if (ftype == TYPE_IPV4){
|
659
|
+
if (argc != 1)
|
660
|
+
rb_raise(rb_eArgError, "TYPE_IPV4 has no additional arguments");
|
661
|
+
return INT2NUM(set_field_type(field, ftype));
|
662
|
+
}
|
663
|
+
else {
|
664
|
+
/* It is a user-defined field type. */
|
665
|
+
/* Will store the arguments associated with this field */
|
666
|
+
/* for use in the callback function. */
|
667
|
+
VALUE rest;
|
668
|
+
rb_scan_args(argc, argv, "1*", &rb_fieldtype, &rest);
|
669
|
+
reg_proc(field, FIELDTYPE_ARGS, rest);
|
670
|
+
/* Pass field as an optional parameter so that make_arg can create */
|
671
|
+
/* the block-argument used in finding the appropriate Ruby Proc */
|
672
|
+
return INT2NUM(set_field_type(field, ftype, field));
|
673
|
+
}
|
674
|
+
|
675
|
+
}
|
676
|
+
static VALUE rbncurs_m_set_field_type(int argc, VALUE* argv, VALUE dummy)
|
677
|
+
{ return rbncurs_c_set_field_type(argc-1, argv+1, argv[0]); }
|
678
|
+
|
679
|
+
static VALUE rbncurs_c_field_type(VALUE rb_field) {
|
680
|
+
FIELD* field = get_field(rb_field);
|
681
|
+
return wrap_fieldtype(field_type(field));
|
682
|
+
}
|
683
|
+
static VALUE rbncurs_m_field_type(VALUE dummy, VALUE rb_field)
|
684
|
+
{ return rbncurs_c_field_type(rb_field); }
|
685
|
+
/* What is this function doing??? */
|
686
|
+
static VALUE rbncurs_c_field_arg(VALUE rb_field) {
|
687
|
+
FIELD* field = get_field(rb_field);
|
688
|
+
field_arg(field);
|
689
|
+
return Qfalse;
|
690
|
+
}
|
691
|
+
static VALUE rbncurs_m_field_arg(VALUE dummy, VALUE rb_field)
|
692
|
+
{ return rbncurs_c_field_arg(rb_field); }
|
693
|
+
|
694
|
+
/*
|
695
|
+
* field_attributes
|
696
|
+
*/
|
697
|
+
static VALUE rbncurs_c_set_field_fore(VALUE rb_field, VALUE attr) {
|
698
|
+
FIELD* field = get_field(rb_field);
|
699
|
+
return INT2NUM(set_field_fore(field, NUM2ULONG(attr)));
|
700
|
+
}
|
701
|
+
static VALUE rbncurs_m_set_field_fore(VALUE dummy, VALUE rb_field, VALUE attr)
|
702
|
+
{ return rbncurs_c_set_field_fore(rb_field, attr); }
|
703
|
+
|
704
|
+
static VALUE rbncurs_c_field_fore(VALUE rb_field) {
|
705
|
+
FIELD* field = get_field(rb_field);
|
706
|
+
return ULONG2NUM(field_fore(field));
|
707
|
+
}
|
708
|
+
static VALUE rbncurs_m_field_fore(VALUE dummy, VALUE rb_field)
|
709
|
+
{ return rbncurs_c_field_fore(rb_field); }
|
710
|
+
|
711
|
+
static VALUE rbncurs_c_set_field_back(VALUE rb_field, VALUE attr) {
|
712
|
+
FIELD* field = get_field(rb_field);
|
713
|
+
return INT2NUM(set_field_back(field, NUM2ULONG(attr)));
|
714
|
+
}
|
715
|
+
static VALUE rbncurs_m_set_field_back(VALUE dummy, VALUE rb_field, VALUE attr)
|
716
|
+
{ return rbncurs_c_set_field_back(rb_field, attr); }
|
717
|
+
|
718
|
+
static VALUE rbncurs_c_field_back(VALUE rb_field) {
|
719
|
+
FIELD* field = get_field(rb_field);
|
720
|
+
return ULONG2NUM(field_back(field));
|
721
|
+
}
|
722
|
+
static VALUE rbncurs_m_field_back(VALUE dummy, VALUE rb_field)
|
723
|
+
{ return rbncurs_c_field_back(rb_field); }
|
724
|
+
|
725
|
+
static VALUE rbncurs_c_set_field_pad(VALUE rb_field, VALUE pad) {
|
726
|
+
FIELD* field = get_field(rb_field);
|
727
|
+
return INT2NUM(set_field_pad(field, NUM2INT(pad)));
|
728
|
+
}
|
729
|
+
static VALUE rbncurs_m_set_field_pad(VALUE dummy, VALUE rb_field, VALUE pad)
|
730
|
+
{ return rbncurs_c_set_field_pad(rb_field, pad); }
|
731
|
+
|
732
|
+
static VALUE rbncurs_c_field_pad(VALUE rb_field) {
|
733
|
+
FIELD* field = get_field(rb_field);
|
734
|
+
return INT2NUM(field_pad(field));
|
735
|
+
}
|
736
|
+
static VALUE rbncurs_m_field_pad(VALUE dummy, VALUE rb_field)
|
737
|
+
{ return rbncurs_c_field_pad(rb_field); }
|
738
|
+
|
739
|
+
/*
|
740
|
+
* field_buffer
|
741
|
+
*/
|
742
|
+
static VALUE rbncurs_c_set_field_buffer(VALUE rb_field, VALUE buf, VALUE value) {
|
743
|
+
FIELD* field = get_field(rb_field);
|
744
|
+
return INT2NUM(set_field_buffer(field, NUM2INT(buf), StringValuePtr(value)));
|
745
|
+
}
|
746
|
+
static VALUE rbncurs_m_set_field_buffer(VALUE dummy, VALUE rb_field, VALUE buf, VALUE value)
|
747
|
+
{ return rbncurs_c_set_field_buffer(rb_field, buf, value); }
|
748
|
+
|
749
|
+
static VALUE rbncurs_c_field_buffer(VALUE rb_field, VALUE buffer) {
|
750
|
+
FIELD* field = get_field(rb_field);
|
751
|
+
return rb_str_new2(field_buffer(field, NUM2INT(buffer)));
|
752
|
+
}
|
753
|
+
static VALUE rbncurs_m_field_buffer(VALUE dummy, VALUE rb_field, VALUE buffer)
|
754
|
+
{ return rbncurs_c_field_buffer(rb_field, buffer); }
|
755
|
+
|
756
|
+
static VALUE rbncurs_c_set_field_status(VALUE rb_field, VALUE status) {
|
757
|
+
FIELD* field = get_field(rb_field);
|
758
|
+
return INT2NUM(set_field_status(field, RTEST(status)));
|
759
|
+
}
|
760
|
+
static VALUE rbncurs_m_set_field_status(VALUE dummy, VALUE rb_field, VALUE status)
|
761
|
+
{ return rbncurs_c_set_field_status(rb_field, status); }
|
762
|
+
|
763
|
+
static VALUE rbncurs_c_field_status(VALUE rb_field) {
|
764
|
+
FIELD* field = get_field(rb_field);
|
765
|
+
return (field_status(field)) ? Qtrue: Qfalse;
|
766
|
+
}
|
767
|
+
static VALUE rbncurs_m_field_status(VALUE dummy, VALUE rb_field)
|
768
|
+
{ return rbncurs_c_field_status(rb_field); }
|
769
|
+
|
770
|
+
static VALUE rbncurs_c_set_max_field(VALUE rb_field, VALUE max) {
|
771
|
+
FIELD* field = get_field(rb_field);
|
772
|
+
return INT2NUM(set_max_field(field, NUM2INT(max)));
|
773
|
+
}
|
774
|
+
static VALUE rbncurs_m_set_max_field(VALUE dummy, VALUE rb_field, VALUE max)
|
775
|
+
{ return rbncurs_c_set_max_field(rb_field, max); }
|
776
|
+
|
777
|
+
/*
|
778
|
+
* form_field
|
779
|
+
*/
|
780
|
+
static VALUE rbncurs_c_set_form_fields(VALUE rb_form, VALUE rb_field_array) {
|
781
|
+
long n = RARRAY_LEN(rb_field_array);
|
782
|
+
/* If ncurses does not free memory used by the previous array of strings, */
|
783
|
+
/* we will have to do it now. */
|
784
|
+
FIELD** fields = ALLOC_N(FIELD*, (n+1));
|
785
|
+
long i;
|
786
|
+
FORM* form = NULL;
|
787
|
+
for (i=0; i<n; i++){
|
788
|
+
fields[i] = get_field(rb_ary_entry(rb_field_array, i));
|
789
|
+
}
|
790
|
+
fields[n] = NULL;
|
791
|
+
form = get_form(rb_form);
|
792
|
+
return INT2NUM(set_form_fields(form, fields));
|
793
|
+
}
|
794
|
+
static VALUE rbncurs_m_set_form_fields(VALUE dummy, VALUE rb_form, VALUE rb_field_array)
|
795
|
+
{ return rbncurs_c_set_form_fields(rb_form, rb_field_array); }
|
796
|
+
|
797
|
+
static VALUE rbncurs_c_form_fields(VALUE rb_form) {
|
798
|
+
FORM* form = get_form(rb_form);
|
799
|
+
FIELD** fields = form_fields(form);
|
800
|
+
VALUE arr = Qundef;
|
801
|
+
int i;
|
802
|
+
if (fields == NULL)
|
803
|
+
rb_raise(rb_eRuntimeError, "Error retrieving form fields");
|
804
|
+
arr = rb_ary_new();
|
805
|
+
i=0;
|
806
|
+
while (fields[i] != NULL)
|
807
|
+
{
|
808
|
+
rb_ary_push(arr, wrap_field(fields[i++]));
|
809
|
+
}
|
810
|
+
return arr;
|
811
|
+
}
|
812
|
+
static VALUE rbncurs_m_form_fields(VALUE dummy, VALUE rb_form)
|
813
|
+
{ return rbncurs_c_form_fields(rb_form); }
|
814
|
+
|
815
|
+
static VALUE rbncurs_c_field_count(VALUE rb_form) {
|
816
|
+
FORM* form = get_form(rb_form);
|
817
|
+
return INT2NUM(field_count(form));
|
818
|
+
}
|
819
|
+
static VALUE rbncurs_m_field_count(VALUE dummy, VALUE rb_form)
|
820
|
+
{ return rbncurs_c_field_count(rb_form); }
|
821
|
+
|
822
|
+
static VALUE rbncurs_c_move_field(VALUE rb_field, VALUE frow, VALUE fcol) {
|
823
|
+
FIELD* field = get_field(rb_field);
|
824
|
+
return INT2NUM(move_field(field, NUM2INT(frow), NUM2INT(fcol)));
|
825
|
+
}
|
826
|
+
static VALUE rbncurs_m_move_field(VALUE dummy, VALUE rb_field, VALUE frow, VALUE fcol)
|
827
|
+
{ return rbncurs_c_move_field(rb_field, frow, fcol); }
|
828
|
+
|
829
|
+
|
830
|
+
/*
|
831
|
+
* form_hook
|
832
|
+
*/
|
833
|
+
static void field_init_hook(FORM* form) {
|
834
|
+
/* Find the Proc object associated with this form */
|
835
|
+
VALUE proc = get_proc(form, FIELD_INIT_HOOK);
|
836
|
+
if (proc != Qnil) {
|
837
|
+
VALUE rb_form = wrap_form(form);
|
838
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_form);
|
839
|
+
}
|
840
|
+
}
|
841
|
+
static VALUE rbncurs_c_set_field_init(VALUE rb_form, VALUE proc) {
|
842
|
+
FORM* form = NULL;
|
843
|
+
if (!rb_obj_is_kind_of(rb_form, cFORM))
|
844
|
+
rb_raise(rb_eArgError, "arg1 must be a FORM object");
|
845
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
846
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
847
|
+
form = get_form(rb_form);
|
848
|
+
reg_proc(form, FIELD_INIT_HOOK, proc);
|
849
|
+
if (proc != Qnil) {
|
850
|
+
return INT2NUM(set_field_init(form, field_init_hook));
|
851
|
+
}
|
852
|
+
else {
|
853
|
+
return INT2NUM(set_field_init(form, NULL));
|
854
|
+
}
|
855
|
+
}
|
856
|
+
static VALUE rbncurs_m_set_field_init(VALUE dummy, VALUE rb_form, VALUE proc)
|
857
|
+
{ return rbncurs_c_set_field_init(rb_form, proc); }
|
858
|
+
|
859
|
+
static VALUE rbncurs_c_field_init(VALUE rb_form) {
|
860
|
+
FORM* form = get_form(rb_form);
|
861
|
+
return get_proc(form, FIELD_INIT_HOOK);
|
862
|
+
}
|
863
|
+
static VALUE rbncurs_m_field_init(VALUE dummy, VALUE rb_form)
|
864
|
+
{ return rbncurs_c_field_init(rb_form); }
|
865
|
+
|
866
|
+
static void field_term_hook(FORM* form) {
|
867
|
+
/* Find the Proc object associated with this form */
|
868
|
+
VALUE proc = get_proc(form, FIELD_TERM_HOOK);
|
869
|
+
if (proc != Qnil) {
|
870
|
+
VALUE rb_form = wrap_form(form);
|
871
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_form);
|
872
|
+
}
|
873
|
+
}
|
874
|
+
static VALUE rbncurs_c_set_field_term(VALUE rb_form, VALUE proc) {
|
875
|
+
FORM * form = NULL;
|
876
|
+
if (!rb_obj_is_kind_of(rb_form, cFORM))
|
877
|
+
rb_raise(rb_eArgError, "arg1 must be a FORM object");
|
878
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
879
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
880
|
+
form = get_form(rb_form);
|
881
|
+
reg_proc(form, FIELD_TERM_HOOK, proc);
|
882
|
+
if (proc != Qnil) {
|
883
|
+
return INT2NUM(set_field_term(form, field_term_hook));
|
884
|
+
}
|
885
|
+
else {
|
886
|
+
return INT2NUM(set_field_term(form, NULL));
|
887
|
+
}
|
888
|
+
}
|
889
|
+
static VALUE rbncurs_m_set_field_term(VALUE dummy, VALUE rb_form, VALUE proc)
|
890
|
+
{ return rbncurs_c_set_field_term(rb_form, proc); }
|
891
|
+
|
892
|
+
static VALUE rbncurs_c_field_term(VALUE rb_form) {
|
893
|
+
FORM* form = get_form(rb_form);
|
894
|
+
return get_proc(form, FIELD_TERM_HOOK);
|
895
|
+
}
|
896
|
+
static VALUE rbncurs_m_field_term(VALUE dummy, VALUE rb_form)
|
897
|
+
{ return rbncurs_c_field_term(rb_form); }
|
898
|
+
|
899
|
+
static void form_init_hook(FORM* form) {
|
900
|
+
/* Find the Proc object associated with this form */
|
901
|
+
VALUE proc = get_proc(form, FORM_INIT_HOOK);
|
902
|
+
if (proc != Qnil) {
|
903
|
+
VALUE rb_form = wrap_form(form);
|
904
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_form);
|
905
|
+
}
|
906
|
+
}
|
907
|
+
static VALUE rbncurs_c_set_form_init(VALUE rb_form, VALUE proc) {
|
908
|
+
FORM * form = NULL;
|
909
|
+
if (!rb_obj_is_kind_of(rb_form, cFORM))
|
910
|
+
rb_raise(rb_eArgError, "arg1 must be a FORM object");
|
911
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
912
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
913
|
+
form = get_form(rb_form);
|
914
|
+
reg_proc(form, FORM_INIT_HOOK, proc);
|
915
|
+
if (proc != Qnil) {
|
916
|
+
return INT2NUM(set_form_init(form, form_init_hook));
|
917
|
+
}
|
918
|
+
else {
|
919
|
+
return INT2NUM(set_form_init(form, NULL));
|
920
|
+
}
|
921
|
+
}
|
922
|
+
static VALUE rbncurs_m_set_form_init(VALUE dummy, VALUE rb_form, VALUE proc)
|
923
|
+
{ return rbncurs_c_set_form_init(rb_form, proc); }
|
924
|
+
|
925
|
+
static VALUE rbncurs_c_form_init(VALUE rb_form) {
|
926
|
+
FORM* form = get_form(rb_form);
|
927
|
+
return get_proc(form, FORM_INIT_HOOK);
|
928
|
+
}
|
929
|
+
static VALUE rbncurs_m_form_init(VALUE dummy, VALUE rb_form)
|
930
|
+
{ return rbncurs_c_form_init(rb_form); }
|
931
|
+
|
932
|
+
static void form_term_hook(FORM* form) {
|
933
|
+
/* Find the Proc object associated with this form */
|
934
|
+
VALUE proc = get_proc(form, FORM_TERM_HOOK);
|
935
|
+
if (proc != Qnil) {
|
936
|
+
VALUE rb_form = wrap_form(form);
|
937
|
+
rb_funcall(proc, rb_intern("call"), 1, rb_form);
|
938
|
+
}
|
939
|
+
}
|
940
|
+
static VALUE rbncurs_c_set_form_term(VALUE rb_form, VALUE proc) {
|
941
|
+
FORM * form = NULL;
|
942
|
+
if (!rb_obj_is_kind_of(rb_form, cFORM))
|
943
|
+
rb_raise(rb_eArgError, "arg1 must be a FORM object");
|
944
|
+
if (!rb_obj_is_kind_of(proc, rb_cProc))
|
945
|
+
rb_raise(rb_eArgError, "arg2 must be a Proc object");
|
946
|
+
form = get_form(rb_form);
|
947
|
+
reg_proc(form, FORM_TERM_HOOK, proc);
|
948
|
+
if (proc != Qnil) {
|
949
|
+
return INT2NUM(set_form_term(form, form_term_hook));
|
950
|
+
}
|
951
|
+
else {
|
952
|
+
return INT2NUM(set_form_term(form, NULL));
|
953
|
+
}
|
954
|
+
}
|
955
|
+
static VALUE rbncurs_m_set_form_term(VALUE dummy, VALUE rb_form, VALUE proc)
|
956
|
+
{ return rbncurs_c_set_form_term(rb_form, proc); }
|
957
|
+
|
958
|
+
static VALUE rbncurs_c_form_term(VALUE rb_form) {
|
959
|
+
FORM* form = get_form(rb_form);
|
960
|
+
return get_proc(form, FORM_TERM_HOOK);
|
961
|
+
}
|
962
|
+
static VALUE rbncurs_m_form_term(VALUE dummy, VALUE rb_form)
|
963
|
+
{ return rbncurs_c_form_term(rb_form); }
|
964
|
+
|
965
|
+
/*
|
966
|
+
* form_field_just
|
967
|
+
*/
|
968
|
+
static VALUE rbncurs_c_set_field_just(VALUE rb_field, VALUE justification) {
|
969
|
+
FIELD* field = get_field(rb_field);
|
970
|
+
return INT2NUM(set_field_just(field, NUM2INT(justification)));
|
971
|
+
}
|
972
|
+
static VALUE rbncurs_m_set_field_just(VALUE dummy, VALUE rb_field, VALUE justification)
|
973
|
+
{ return rbncurs_c_set_field_just(rb_field, justification); }
|
974
|
+
|
975
|
+
static VALUE rbncurs_c_field_just(VALUE rb_field) {
|
976
|
+
FIELD* field = get_field(rb_field);
|
977
|
+
return INT2NUM(field_just(field));
|
978
|
+
}
|
979
|
+
static VALUE rbncurs_m_field_just(VALUE dummy, VALUE rb_field)
|
980
|
+
{ return rbncurs_c_field_just(rb_field); }
|
981
|
+
|
982
|
+
/*
|
983
|
+
* form_field_opts
|
984
|
+
*/
|
985
|
+
static VALUE rbncurs_c_set_field_opts(VALUE rb_field, VALUE opts) {
|
986
|
+
FIELD* field = get_field(rb_field);
|
987
|
+
return INT2NUM(set_field_opts(field, NUM2INT(opts)));
|
988
|
+
}
|
989
|
+
static VALUE rbncurs_m_set_field_opts(VALUE dummy, VALUE rb_field, VALUE opts)
|
990
|
+
{ return rbncurs_c_set_field_opts(rb_field, opts); }
|
991
|
+
|
992
|
+
static VALUE rbncurs_c_field_opts_on(VALUE rb_field, VALUE opts) {
|
993
|
+
FIELD* field = get_field(rb_field);
|
994
|
+
return INT2NUM(field_opts_on(field, NUM2INT(opts)));
|
995
|
+
}
|
996
|
+
static VALUE rbncurs_m_field_opts_on(VALUE dummy, VALUE rb_field, VALUE opts)
|
997
|
+
{ return rbncurs_c_field_opts_on(rb_field, opts); }
|
998
|
+
|
999
|
+
static VALUE rbncurs_c_field_opts_off(VALUE rb_field, VALUE opts) {
|
1000
|
+
FIELD* field = get_field(rb_field);
|
1001
|
+
return INT2NUM(field_opts_off(field, NUM2INT(opts)));
|
1002
|
+
}
|
1003
|
+
static VALUE rbncurs_m_field_opts_off(VALUE dummy, VALUE rb_field, VALUE opts)
|
1004
|
+
{ return rbncurs_c_field_opts_off(rb_field, opts); }
|
1005
|
+
|
1006
|
+
static VALUE rbncurs_c_field_opts(VALUE rb_field) {
|
1007
|
+
FIELD* field = get_field(rb_field);
|
1008
|
+
return INT2NUM(field_opts(field));
|
1009
|
+
}
|
1010
|
+
static VALUE rbncurs_m_field_opts(VALUE dummy, VALUE rb_field)
|
1011
|
+
{ return rbncurs_c_field_opts(rb_field); }
|
1012
|
+
|
1013
|
+
/*
|
1014
|
+
* form_opts
|
1015
|
+
*/
|
1016
|
+
static VALUE rbncurs_c_set_form_opts(VALUE rb_form, VALUE opts) {
|
1017
|
+
FORM* form = get_form(rb_form);
|
1018
|
+
return INT2NUM(set_form_opts(form, NUM2INT(opts)));
|
1019
|
+
}
|
1020
|
+
static VALUE rbncurs_m_set_form_opts(VALUE dummy, VALUE rb_form, VALUE opts)
|
1021
|
+
{ return rbncurs_c_set_form_opts(rb_form, opts); }
|
1022
|
+
|
1023
|
+
static VALUE rbncurs_c_form_opts_on(VALUE rb_form, VALUE opts) {
|
1024
|
+
FORM* form = get_form(rb_form);
|
1025
|
+
return INT2NUM(form_opts_on(form, NUM2INT(opts)));
|
1026
|
+
}
|
1027
|
+
static VALUE rbncurs_m_form_opts_on(VALUE dummy, VALUE rb_form, VALUE opts)
|
1028
|
+
{ return rbncurs_c_form_opts_on(rb_form, opts); }
|
1029
|
+
|
1030
|
+
static VALUE rbncurs_c_form_opts_off(VALUE rb_form, VALUE opts) {
|
1031
|
+
FORM* form = get_form(rb_form);
|
1032
|
+
return INT2NUM(form_opts_off(form, NUM2INT(opts)));
|
1033
|
+
}
|
1034
|
+
static VALUE rbncurs_m_form_opts_off(VALUE dummy, VALUE rb_form, VALUE opts)
|
1035
|
+
{ return rbncurs_c_form_opts_off(rb_form, opts); }
|
1036
|
+
|
1037
|
+
static VALUE rbncurs_c_form_opts(VALUE rb_form) {
|
1038
|
+
FORM* form = get_form(rb_form);
|
1039
|
+
return INT2NUM(form_opts(form));
|
1040
|
+
}
|
1041
|
+
static VALUE rbncurs_m_form_opts(VALUE dummy, VALUE rb_form)
|
1042
|
+
{ return rbncurs_c_form_opts(rb_form); }
|
1043
|
+
|
1044
|
+
/*
|
1045
|
+
* form_requestname
|
1046
|
+
*/
|
1047
|
+
static VALUE rbncurs_c_form_request_name(VALUE request) {
|
1048
|
+
return rb_str_new2(form_request_name(NUM2INT(request)));
|
1049
|
+
}
|
1050
|
+
static VALUE rbncurs_m_form_request_name(VALUE dummy, VALUE request)
|
1051
|
+
{ return rbncurs_c_form_request_name(request); }
|
1052
|
+
|
1053
|
+
static VALUE rbncurs_c_form_request_by_name(VALUE name) {
|
1054
|
+
return INT2NUM(form_request_by_name(StringValuePtr(name)));
|
1055
|
+
}
|
1056
|
+
static VALUE rbncurs_m_form_request_by_name(VALUE dummy, VALUE name)
|
1057
|
+
{ return rbncurs_c_form_request_by_name(name); }
|
1058
|
+
|
1059
|
+
/*
|
1060
|
+
* form_win
|
1061
|
+
*/
|
1062
|
+
static VALUE rbncurs_c_set_form_win(VALUE rb_form, VALUE rb_win) {
|
1063
|
+
FORM* form = get_form(rb_form);
|
1064
|
+
WINDOW* win = get_window(rb_win);
|
1065
|
+
return INT2NUM(set_form_win(form, win));
|
1066
|
+
}
|
1067
|
+
static VALUE rbncurs_m_set_form_win(VALUE dummy, VALUE rb_form, VALUE rb_win)
|
1068
|
+
{ return rbncurs_c_set_form_win(rb_form, rb_win); }
|
1069
|
+
|
1070
|
+
static VALUE rbncurs_c_form_win(VALUE rb_form) {
|
1071
|
+
FORM* form = get_form(rb_form);
|
1072
|
+
return wrap_window(form_win(form));
|
1073
|
+
}
|
1074
|
+
static VALUE rbncurs_m_form_win(VALUE dummy, VALUE rb_form)
|
1075
|
+
{ return rbncurs_c_form_win(rb_form); }
|
1076
|
+
|
1077
|
+
static VALUE rbncurs_c_set_form_sub(VALUE rb_form, VALUE rb_sub) {
|
1078
|
+
FORM* form = get_form(rb_form);
|
1079
|
+
WINDOW* win = get_window(rb_sub);
|
1080
|
+
return INT2NUM(set_form_sub(form, win));
|
1081
|
+
}
|
1082
|
+
static VALUE rbncurs_m_set_form_sub(VALUE dummy, VALUE rb_form, VALUE rb_sub)
|
1083
|
+
{ return rbncurs_c_set_form_sub(rb_form, rb_sub); }
|
1084
|
+
|
1085
|
+
static VALUE rbncurs_c_form_sub(VALUE rb_form) {
|
1086
|
+
FORM* form = get_form(rb_form);
|
1087
|
+
return wrap_window(form_sub(form));
|
1088
|
+
}
|
1089
|
+
static VALUE rbncurs_m_form_sub(VALUE dummy, VALUE rb_form)
|
1090
|
+
{ return rbncurs_c_form_sub(rb_form); }
|
1091
|
+
|
1092
|
+
static VALUE rbncurs_c_scale_form(VALUE rb_form, VALUE rows, VALUE columns) {
|
1093
|
+
FORM* form = get_form(rb_form);
|
1094
|
+
if (rb_obj_is_instance_of(rows, rb_cArray) != Qtrue
|
1095
|
+
|| rb_obj_is_instance_of(columns, rb_cArray) != Qtrue) {
|
1096
|
+
rb_raise(rb_eArgError,
|
1097
|
+
"rows and columns arguments must be empty Arrays");
|
1098
|
+
return Qnil;
|
1099
|
+
}
|
1100
|
+
else {
|
1101
|
+
int vals[2] = {0,0};
|
1102
|
+
int result = scale_form(form, &vals[0],&vals[1]);
|
1103
|
+
rb_ary_push(rows, INT2NUM(vals[0]));
|
1104
|
+
rb_ary_push(columns, INT2NUM(vals[1]));
|
1105
|
+
return INT2NUM(result);
|
1106
|
+
}
|
1107
|
+
}
|
1108
|
+
static VALUE rbncurs_m_scale_form(VALUE dummy, VALUE rb_form, VALUE rows, VALUE columns)
|
1109
|
+
{ return rbncurs_c_scale_form(rb_form, rows, columns); }
|
1110
|
+
|
1111
|
+
/*
|
1112
|
+
* form_fieldtype
|
1113
|
+
*/
|
1114
|
+
static void* make_arg(va_list* ap) {
|
1115
|
+
/* This method creates a list of arguments to be passed */
|
1116
|
+
/* to the validation functions (char_check and field_check). */
|
1117
|
+
FIELD* field = va_arg(*ap, FIELD*);
|
1118
|
+
FIELDTYPE* fieldtype = field_type(field);
|
1119
|
+
VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
|
1120
|
+
if (proc == Qnil) {
|
1121
|
+
proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
|
1122
|
+
}
|
1123
|
+
|
1124
|
+
/* Compare number of arguments in Ruby Proc with that of set_field_type */
|
1125
|
+
if (proc != Qnil) {
|
1126
|
+
VALUE argc = rb_funcall(proc, rb_intern("arity"),0);
|
1127
|
+
VALUE args = get_proc(field, FIELDTYPE_ARGS);
|
1128
|
+
if (args != Qnil) {
|
1129
|
+
if (NUM2INT(argc)-1 != RARRAY_LEN(args)) {
|
1130
|
+
char msg[500];
|
1131
|
+
snprintf(msg, 500, "The validation functions for this field type need %d additional arguments.",NUM2INT(argc)-1);
|
1132
|
+
msg[499]=0;
|
1133
|
+
rb_raise(rb_eArgError, msg);
|
1134
|
+
}
|
1135
|
+
}
|
1136
|
+
}
|
1137
|
+
/* field will be the only argument in field_check/char_check callback */
|
1138
|
+
/* and will be used to locate the appropriate Ruby Proc */
|
1139
|
+
return field;
|
1140
|
+
}
|
1141
|
+
static bool field_check(FIELD* field, const void* argblock) {
|
1142
|
+
FIELDTYPE* fieldtype = field_type(field);
|
1143
|
+
VALUE proc = get_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK);
|
1144
|
+
if (proc != Qnil)
|
1145
|
+
{
|
1146
|
+
VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
|
1147
|
+
rb_ary_unshift(args, wrap_field(field));
|
1148
|
+
return RTEST(rb_apply(proc, rb_intern("call"), args));
|
1149
|
+
}
|
1150
|
+
return 1;
|
1151
|
+
}
|
1152
|
+
static bool char_check(int c, const void* argblock) {
|
1153
|
+
FIELD* field = (FIELD*)argblock;
|
1154
|
+
FIELDTYPE* fieldtype = field_type(field);
|
1155
|
+
VALUE proc = get_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK);
|
1156
|
+
if (proc != Qnil) {
|
1157
|
+
VALUE args = rb_ary_dup(get_proc(field, FIELDTYPE_ARGS));
|
1158
|
+
char str[2];
|
1159
|
+
str[0] = c;
|
1160
|
+
str[1] = 0;
|
1161
|
+
rb_ary_unshift(args, rb_str_new2(str));
|
1162
|
+
return RTEST(rb_apply(proc, rb_intern("call"), args));
|
1163
|
+
}
|
1164
|
+
return 1;
|
1165
|
+
}
|
1166
|
+
static VALUE rbncurs_m_new_fieldtype(VALUE dummy, VALUE field_check_proc, VALUE char_check_proc)
|
1167
|
+
{
|
1168
|
+
FIELDTYPE* fieldtype = new_fieldtype(field_check_proc == Qnil ? NULL : field_check,
|
1169
|
+
char_check_proc == Qnil ? NULL : char_check);
|
1170
|
+
set_fieldtype_arg(fieldtype, make_arg, NULL, NULL);
|
1171
|
+
if (field_check_proc != Qnil) {
|
1172
|
+
reg_proc(fieldtype, FIELDTYPE_FIELD_CHECK_HOOK, field_check_proc);
|
1173
|
+
}
|
1174
|
+
if (char_check_proc != Qnil) {
|
1175
|
+
reg_proc(fieldtype, FIELDTYPE_CHAR_CHECK_HOOK, char_check_proc);
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
return wrap_fieldtype(fieldtype);
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
static VALUE rbncurs_c_free_fieldtype(VALUE rb_fieldtype) {
|
1182
|
+
FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
|
1183
|
+
return INT2NUM(free_fieldtype(fieldtype));
|
1184
|
+
}
|
1185
|
+
static VALUE rbncurs_m_free_fieldtype(VALUE dummy, VALUE rb_field)
|
1186
|
+
{ return rbncurs_c_free_fieldtype(rb_field); }
|
1187
|
+
|
1188
|
+
static bool next_choice(FIELD* field, const void* argblock) {
|
1189
|
+
FIELDTYPE* fieldtype = field_type(field);
|
1190
|
+
VALUE proc = get_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK);
|
1191
|
+
if (proc != Qnil) {
|
1192
|
+
/* Need to find out what exactly is argblock about... */
|
1193
|
+
return RTEST(rb_funcall(proc, rb_intern("call"), 1, wrap_field(field)));
|
1194
|
+
}
|
1195
|
+
return 1;
|
1196
|
+
}
|
1197
|
+
static bool prev_choice(FIELD* field, const void* argblock) {
|
1198
|
+
FIELDTYPE* fieldtype = field_type(field);
|
1199
|
+
VALUE proc = get_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK);
|
1200
|
+
if (proc != Qnil) {
|
1201
|
+
/* Need to find out what exactly is argblock about... */
|
1202
|
+
return RTEST(rb_funcall(proc, rb_intern("call"), 1, wrap_field(field)));
|
1203
|
+
}
|
1204
|
+
return 1;
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
static VALUE rbncurs_c_set_fieldtype_choice(VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc) {
|
1208
|
+
FIELDTYPE* fieldtype = get_fieldtype(rb_fieldtype);
|
1209
|
+
int result = set_fieldtype_choice(fieldtype,
|
1210
|
+
next_choice_proc == Qnil ? NULL : next_choice,
|
1211
|
+
prev_choice_proc == Qnil ? NULL : prev_choice);
|
1212
|
+
if (next_choice_proc != Qnil)
|
1213
|
+
reg_proc(fieldtype, FIELDTYPE_NEXT_CHOICE_HOOK, next_choice_proc);
|
1214
|
+
if (prev_choice_proc != Qnil)
|
1215
|
+
reg_proc(fieldtype, FIELDTYPE_PREV_CHOICE_HOOK, prev_choice_proc);
|
1216
|
+
return INT2NUM(result);
|
1217
|
+
}
|
1218
|
+
static VALUE rbncurs_m_set_fieldtype_choice(VALUE dummy, VALUE rb_fieldtype, VALUE next_choice_proc, VALUE prev_choice_proc)
|
1219
|
+
{ return rbncurs_c_set_fieldtype_choice(rb_fieldtype, next_choice_proc, prev_choice_proc); }
|
1220
|
+
|
1221
|
+
static VALUE rbncurs_c_link_fieldtype(VALUE rb_fieldtype1, VALUE rb_fieldtype2) {
|
1222
|
+
FIELDTYPE* fieldtype1 = get_fieldtype(rb_fieldtype1);
|
1223
|
+
FIELDTYPE* fieldtype2 = get_fieldtype(rb_fieldtype2);
|
1224
|
+
return wrap_fieldtype(link_fieldtype(fieldtype1, fieldtype2));
|
1225
|
+
}
|
1226
|
+
static VALUE rbncurs_m_link_fieldtype(VALUE dummy, VALUE rb_fieldtype1, VALUE fieldtype2)
|
1227
|
+
{ return rbncurs_c_link_fieldtype(rb_fieldtype1, fieldtype2); }
|
1228
|
+
|
1229
|
+
static VALUE rbncurs_c_set_new_page(VALUE rb_field, VALUE new_page_flag) {
|
1230
|
+
FIELD* field = get_field(rb_field);
|
1231
|
+
return INT2NUM(set_new_page(field, RTEST(new_page_flag)));
|
1232
|
+
}
|
1233
|
+
static VALUE rbncurs_m_set_new_page(VALUE dummy, VALUE rb_field, VALUE new_page_flag)
|
1234
|
+
{ return rbncurs_c_set_new_page(rb_field, new_page_flag); }
|
1235
|
+
|
1236
|
+
static VALUE rbncurs_c_new_page(VALUE rb_field) {
|
1237
|
+
FIELD* field = get_field(rb_field);
|
1238
|
+
return (new_page(field))? Qtrue : Qfalse;
|
1239
|
+
}
|
1240
|
+
static VALUE rbncurs_m_new_page(VALUE dummy, VALUE rb_field)
|
1241
|
+
{ return rbncurs_c_new_page(rb_field); }
|
1242
|
+
|
1243
|
+
/*
|
1244
|
+
* form_cursor
|
1245
|
+
*/
|
1246
|
+
static VALUE rbncurs_c_pos_form_cursor(VALUE rb_form) {
|
1247
|
+
FORM* form = get_form(rb_form);
|
1248
|
+
return INT2NUM(pos_form_cursor(form));
|
1249
|
+
}
|
1250
|
+
static VALUE rbncurs_m_pos_form_cursor(VALUE dummy, VALUE rb_form)
|
1251
|
+
{ return rbncurs_c_pos_form_cursor(rb_form); }
|
1252
|
+
|
1253
|
+
void init_form(void)
|
1254
|
+
{
|
1255
|
+
|
1256
|
+
mForm = rb_define_module_under(mNcurses, "Form");
|
1257
|
+
|
1258
|
+
FORM_SNG_FUNC(current_field,1);
|
1259
|
+
FORM_SNG_FUNC(data_ahead,1);
|
1260
|
+
FORM_SNG_FUNC(data_behind,1);
|
1261
|
+
FORM_SNG_FUNC(dup_field,3);
|
1262
|
+
FORM_SNG_FUNC(dynamic_field_info,4);
|
1263
|
+
FORM_SNG_FUNC(field_arg,1);
|
1264
|
+
FORM_SNG_FUNC(field_back,1);
|
1265
|
+
FORM_SNG_FUNC(field_buffer,2);
|
1266
|
+
FORM_SNG_FUNC(field_count,1);
|
1267
|
+
FORM_SNG_FUNC(field_fore,1);
|
1268
|
+
FORM_SNG_FUNC(field_index,1);
|
1269
|
+
FORM_SNG_FUNC(field_info,7);
|
1270
|
+
FORM_SNG_FUNC(field_init,1);
|
1271
|
+
FORM_SNG_FUNC(field_just,1);
|
1272
|
+
FORM_SNG_FUNC(field_opts,1);
|
1273
|
+
FORM_SNG_FUNC(field_opts_off,2);
|
1274
|
+
FORM_SNG_FUNC(field_opts_on,2);
|
1275
|
+
FORM_SNG_FUNC(field_pad,1);
|
1276
|
+
FORM_SNG_FUNC(field_status,1);
|
1277
|
+
FORM_SNG_FUNC(field_term,1);
|
1278
|
+
FORM_SNG_FUNC(field_type,1);
|
1279
|
+
/* FORM_SNG_FUNC(field_userptr,1); */
|
1280
|
+
FORM_SNG_FUNC(form_driver,2);
|
1281
|
+
FORM_SNG_FUNC(form_fields,1);
|
1282
|
+
FORM_SNG_FUNC(form_init,1);
|
1283
|
+
FORM_SNG_FUNC(form_opts,1);
|
1284
|
+
FORM_SNG_FUNC(form_opts_off,2);
|
1285
|
+
FORM_SNG_FUNC(form_opts_on,2);
|
1286
|
+
FORM_SNG_FUNC(form_page,1);
|
1287
|
+
FORM_SNG_FUNC(form_request_by_name,1);
|
1288
|
+
FORM_SNG_FUNC(form_request_name,1);
|
1289
|
+
FORM_SNG_FUNC(form_sub,1);
|
1290
|
+
FORM_SNG_FUNC(form_term,1);
|
1291
|
+
/* FORM_SNG_FUNC(form_userptr,1); */
|
1292
|
+
FORM_SNG_FUNC(form_win,1);
|
1293
|
+
FORM_SNG_FUNC(free_field,1);
|
1294
|
+
FORM_SNG_FUNC(free_fieldtype,1);
|
1295
|
+
FORM_SNG_FUNC(free_form,1);
|
1296
|
+
FORM_SNG_FUNC(link_field,3);
|
1297
|
+
FORM_SNG_FUNC(link_fieldtype,2);
|
1298
|
+
FORM_SNG_FUNC(move_field,3);
|
1299
|
+
FORM_SNG_FUNC(new_field,6);
|
1300
|
+
FORM_SNG_FUNC(new_fieldtype,2);
|
1301
|
+
FORM_SNG_FUNC(new_form,1);
|
1302
|
+
FORM_SNG_FUNC(new_page,1);
|
1303
|
+
FORM_SNG_FUNC(pos_form_cursor,1);
|
1304
|
+
FORM_SNG_FUNC(post_form,1);
|
1305
|
+
FORM_SNG_FUNC(scale_form,3);
|
1306
|
+
FORM_SNG_FUNC(set_current_field,2);
|
1307
|
+
FORM_SNG_FUNC(set_field_back,2);
|
1308
|
+
FORM_SNG_FUNC(set_field_buffer,3);
|
1309
|
+
FORM_SNG_FUNC(set_field_fore,2);
|
1310
|
+
FORM_SNG_FUNC(set_field_init,2);
|
1311
|
+
FORM_SNG_FUNC(set_field_just,2);
|
1312
|
+
FORM_SNG_FUNC(set_field_opts,2);
|
1313
|
+
FORM_SNG_FUNC(set_field_pad,2);
|
1314
|
+
FORM_SNG_FUNC(set_field_status,2);
|
1315
|
+
FORM_SNG_FUNC(set_field_term,2);
|
1316
|
+
FORM_SNG_FUNC(set_field_type,-1);
|
1317
|
+
/* FORM_SNG_FUNC(set_field_userptr,2); */
|
1318
|
+
FORM_SNG_FUNC(set_fieldtype_choice,3);
|
1319
|
+
FORM_SNG_FUNC(set_form_fields,2);
|
1320
|
+
FORM_SNG_FUNC(set_form_init,2);
|
1321
|
+
FORM_SNG_FUNC(set_form_opts,2);
|
1322
|
+
FORM_SNG_FUNC(set_form_page,2);
|
1323
|
+
FORM_SNG_FUNC(set_form_sub,2);
|
1324
|
+
FORM_SNG_FUNC(set_form_term,2);
|
1325
|
+
/* FORM_SNG_FUNC(set_form_userptr,2); */
|
1326
|
+
FORM_SNG_FUNC(set_form_win,2);
|
1327
|
+
FORM_SNG_FUNC(set_max_field,2);
|
1328
|
+
FORM_SNG_FUNC(set_new_page,2);
|
1329
|
+
FORM_SNG_FUNC(unpost_form,1);
|
1330
|
+
|
1331
|
+
init_err_codes();
|
1332
|
+
init_req_constants();
|
1333
|
+
init_opts_constants();
|
1334
|
+
init_just_constants();
|
1335
|
+
init_form_opts_constants();
|
1336
|
+
|
1337
|
+
/* Hashes to store registered blocks (Proc) */
|
1338
|
+
{
|
1339
|
+
VALUE hashes = rb_iv_set(mForm, "@proc_hashes", rb_ary_new());
|
1340
|
+
int i;
|
1341
|
+
for (i = 0; i < PROC_HASHES_COUNT; i++)
|
1342
|
+
{
|
1343
|
+
rb_ary_push(hashes, rb_hash_new());
|
1344
|
+
}
|
1345
|
+
}
|
1346
|
+
|
1347
|
+
/* Forms */
|
1348
|
+
rb_iv_set(mForm, "@forms_hash", rb_hash_new());
|
1349
|
+
cFORM = rb_define_class_under(mForm, "FORM", rb_cObject);
|
1350
|
+
rb_define_singleton_method(cFORM, "new",
|
1351
|
+
(&rbncurs_m_new_form),
|
1352
|
+
1);
|
1353
|
+
RB_CLASS_METH(cFORM, NULL, current_field,0);
|
1354
|
+
RB_CLASS_METH(cFORM, NULL, data_ahead,0);
|
1355
|
+
RB_CLASS_METH(cFORM, NULL, data_behind,0);
|
1356
|
+
RB_CLASS_METH(cFORM, NULL, dup_field,2);
|
1357
|
+
RB_CLASS_METH(cFORM, NULL, field_count,0);
|
1358
|
+
RB_CLASS_METH(cFORM, NULL, field_init,0);
|
1359
|
+
RB_CLASS_METH(cFORM, NULL, field_term,0);
|
1360
|
+
RB_CLASS_METH(cFORM, "driver", form_driver,1);
|
1361
|
+
RB_CLASS_METH(cFORM, "fields", form_fields,0);
|
1362
|
+
RB_CLASS_METH(cFORM, "init", form_init,0);
|
1363
|
+
RB_CLASS_METH(cFORM, "opts", form_opts,0);
|
1364
|
+
RB_CLASS_METH(cFORM, "opts_off", form_opts_off,1);
|
1365
|
+
RB_CLASS_METH(cFORM, "opts_on", form_opts_on,1);
|
1366
|
+
RB_CLASS_METH(cFORM, "page", form_page,0);
|
1367
|
+
RB_CLASS_METH(cFORM, "sub", form_sub,0);
|
1368
|
+
RB_CLASS_METH(cFORM, "term", form_term,0);
|
1369
|
+
/* RB_CLASS_METH(cFORM, "userptr", form_userptr,0); */
|
1370
|
+
RB_CLASS_METH(cFORM, "win", form_win,0);
|
1371
|
+
RB_CLASS_METH(cFORM, "free", free_form,0);
|
1372
|
+
RB_CLASS_METH(cFORM, "pos_cursor", pos_form_cursor,0);
|
1373
|
+
RB_CLASS_METH(cFORM, "post", post_form,0);
|
1374
|
+
RB_CLASS_METH(cFORM, "scale", scale_form,2);
|
1375
|
+
RB_CLASS_METH(cFORM, "current_field=", set_current_field,1);
|
1376
|
+
RB_CLASS_METH(cFORM, "field_init=", set_field_init,1);
|
1377
|
+
RB_CLASS_METH(cFORM, "field_term=", set_field_term,1);
|
1378
|
+
RB_CLASS_METH(cFORM, "fields=", set_form_fields,1);
|
1379
|
+
RB_CLASS_METH(cFORM, "init=", set_form_init,1);
|
1380
|
+
RB_CLASS_METH(cFORM, "opts=", set_form_opts,1);
|
1381
|
+
RB_CLASS_METH(cFORM, "page=", set_form_page,1);
|
1382
|
+
RB_CLASS_METH(cFORM, "sub=", set_form_sub,1);
|
1383
|
+
RB_CLASS_METH(cFORM, "term=", set_form_term,1);
|
1384
|
+
/* RB_CLASS_METH(cFORM, "userptr=", set_form_userptr,1); */
|
1385
|
+
RB_CLASS_METH(cFORM, "win=", set_form_win,1);
|
1386
|
+
RB_CLASS_METH(cFORM, "unpost", unpost_form,0);
|
1387
|
+
|
1388
|
+
/* Fields */
|
1389
|
+
rb_iv_set(mForm, "@fields_hash", rb_hash_new());
|
1390
|
+
cFIELD = rb_define_class_under(mForm, "FIELD", rb_cObject);
|
1391
|
+
rb_define_singleton_method(cFIELD, "new",
|
1392
|
+
(&rbncurs_m_new_field),
|
1393
|
+
6);
|
1394
|
+
RB_CLASS_METH(cFIELD, "dup", dup_field,2);
|
1395
|
+
RB_CLASS_METH(cFIELD, "dynamic_info", dynamic_field_info,3);
|
1396
|
+
RB_CLASS_METH(cFIELD, "arg", field_arg,0);
|
1397
|
+
RB_CLASS_METH(cFIELD, "back", field_back,1);
|
1398
|
+
RB_CLASS_METH(cFIELD, "buffer", field_buffer,1);
|
1399
|
+
RB_CLASS_METH(cFIELD, "fore", field_fore,1);
|
1400
|
+
RB_CLASS_METH(cFIELD, "index", field_index,0);
|
1401
|
+
RB_CLASS_METH(cFIELD, "info", field_info,6);
|
1402
|
+
RB_CLASS_METH(cFIELD, "just", field_just,0);
|
1403
|
+
RB_CLASS_METH(cFIELD, "opts", field_opts,0);
|
1404
|
+
RB_CLASS_METH(cFIELD, "opts_off", field_opts_off,1);
|
1405
|
+
RB_CLASS_METH(cFIELD, "opts_on", field_opts_on,1);
|
1406
|
+
RB_CLASS_METH(cFIELD, "pad", field_pad,1);
|
1407
|
+
RB_CLASS_METH(cFIELD, "status", field_status,0);
|
1408
|
+
RB_CLASS_METH(cFIELD, "type", field_type,0);
|
1409
|
+
/* RB_CLASS_METH(cFIELD, "userptr", field_userptr,0); */
|
1410
|
+
RB_CLASS_METH(cFIELD, "free", free_field,0);
|
1411
|
+
RB_CLASS_METH(cFIELD, "link", link_field,2);
|
1412
|
+
RB_CLASS_METH(cFIELD, "move", move_field,2);
|
1413
|
+
RB_CLASS_METH(cFIELD, NULL, new_page,0);
|
1414
|
+
RB_CLASS_METH(cFIELD, "back=", set_field_back,1);
|
1415
|
+
RB_CLASS_METH(cFIELD, "set_buffer", set_field_buffer,2);
|
1416
|
+
RB_CLASS_METH(cFIELD, "fore=", set_field_fore,1);
|
1417
|
+
RB_CLASS_METH(cFIELD, "just=", set_field_just,1);
|
1418
|
+
RB_CLASS_METH(cFIELD, "opts=", set_field_opts,1);
|
1419
|
+
RB_CLASS_METH(cFIELD, "pad=", set_field_pad,1);
|
1420
|
+
RB_CLASS_METH(cFIELD, "status=", set_field_status,1);
|
1421
|
+
RB_CLASS_METH(cFIELD, "set_type", set_field_type,-1);
|
1422
|
+
/* RB_CLASS_METH(cFIELD, "userptr=", set_field_userptr,1); */
|
1423
|
+
RB_CLASS_METH(cFIELD, "max_field=", set_max_field,1);
|
1424
|
+
RB_CLASS_METH(cFIELD, "new_page=", set_new_page,1);
|
1425
|
+
|
1426
|
+
|
1427
|
+
|
1428
|
+
|
1429
|
+
/* Field types */
|
1430
|
+
rb_iv_set(mForm, "@fieldtypes_hash", rb_hash_new());
|
1431
|
+
cFIELDTYPE = rb_define_class_under(mForm, "FIELDTYPE", rb_cObject);
|
1432
|
+
rb_define_singleton_method(cFIELDTYPE, "new",
|
1433
|
+
(&rbncurs_m_new_fieldtype),
|
1434
|
+
2);
|
1435
|
+
RB_CLASS_METH(cFIELDTYPE, "free", free_fieldtype,0);
|
1436
|
+
RB_CLASS_METH(cFIELDTYPE, "link", link_fieldtype,1);
|
1437
|
+
RB_CLASS_METH(cFIELDTYPE, "set_choice", set_fieldtype_choice,2);
|
1438
|
+
|
1439
|
+
/* Create predefined types */
|
1440
|
+
rb_define_const(mForm, "TYPE_ALNUM", wrap_fieldtype(TYPE_ALNUM));
|
1441
|
+
rb_define_const(mForm, "TYPE_ALPHA", wrap_fieldtype(TYPE_ALPHA));
|
1442
|
+
rb_define_const(mForm, "TYPE_ENUM", wrap_fieldtype(TYPE_ENUM));
|
1443
|
+
rb_define_const(mForm, "TYPE_INTEGER", wrap_fieldtype(TYPE_INTEGER));
|
1444
|
+
rb_define_const(mForm, "TYPE_NUMERIC", wrap_fieldtype(TYPE_NUMERIC));
|
1445
|
+
rb_define_const(mForm, "TYPE_REGEXP", wrap_fieldtype(TYPE_REGEXP));
|
1446
|
+
rb_define_const(mForm, "TYPE_IPV4", wrap_fieldtype(TYPE_IPV4));
|
1447
|
+
|
1448
|
+
}
|
1449
|
+
|
1450
|
+
#endif
|